16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 13:59:19 +02:00

custom sounds for cab controls configurable on per-item basis

This commit is contained in:
tmj-fstate
2017-07-15 19:27:49 +02:00
parent 4f9000ebe2
commit 3a67219e30
15 changed files with 687 additions and 570 deletions

View File

@@ -78,7 +78,8 @@ zwiekszenie nacisku przy duzych predkosciach w hamulcach Oerlikona
*/
#include "dumb3d.h"
using namespace Math3D;
extern int ConversionError;
const double Steel2Steel_friction = 0.15; //tarcie statyczne
const double g = 9.81; //przyspieszenie ziemskie
@@ -996,8 +997,8 @@ public:
double FrictConst2d= 0.0;
double TotalMassxg = 0.0; /*TotalMass*g*/
vector3 vCoulpler[2]; // powtórzenie współrzędnych sprzęgów z DynObj :/
vector3 DimHalf; // połowy rozmiarów do obliczeń geometrycznych
Math3D::vector3 vCoulpler[2]; // powtórzenie współrzędnych sprzęgów z DynObj :/
Math3D::vector3 DimHalf; // połowy rozmiarów do obliczeń geometrycznych
// int WarningSignal; //0: nie trabi, 1,2: trabi syreną o podanym numerze
int WarningSignal = 0; // tymczasowo 8bit, ze względu na funkcje w MTools
double fBrakeCtrlPos = -2.0; // płynna nastawa hamulca zespolonego
@@ -1210,47 +1211,3 @@ private:
};
extern double Distance(TLocation Loc1, TLocation Loc2, TDimension Dim1, TDimension Dim2);
inline
std::string
extract_value( std::string const &Key, std::string const &Input ) {
std::string value;
auto lookup = Input.find( Key + "=" );
if( lookup != std::string::npos ) {
value = Input.substr( Input.find_first_not_of( ' ', lookup + Key.size() + 1 ) );
lookup = value.find( ' ' );
if( lookup != std::string::npos ) {
// trim everything past the value
value.erase( lookup );
}
}
return value;
}
template <typename Type_>
bool
extract_value( Type_ &Variable, std::string const &Key, std::string const &Input, std::string const &Default ) {
auto value = extract_value( Key, Input );
if( false == value.empty() ) {
// set the specified variable to retrieved value
std::stringstream converter;
converter << value;
converter >> Variable;
return true; // located the variable
}
else {
// set the variable to provided default value
if( false == Default.empty() ) {
std::stringstream converter;
converter << Default;
converter >> Variable;
}
return false; // couldn't locate the variable in provided input
}
}
template <>
bool
extract_value( bool &Variable, std::string const &Key, std::string const &Input, std::string const &Default );

View File

@@ -13,6 +13,7 @@ http://mozilla.org/MPL/2.0/.
#include "../logs.h"
#include "Oerlikon_ESt.h"
#include "../parser.h"
#include "mctools.h"
//---------------------------------------------------------------------------
// Ra: tu należy przenosić funcje z mover.pas, które nie są z niego wywoływane.
@@ -22,6 +23,8 @@ http://mozilla.org/MPL/2.0/.
const double dEpsilon = 0.01; // 1cm (zależy od typu sprzęgu...)
const double CouplerTune = 0.1; // skalowanie tlumiennosci
int ConversionError = 0;
std::vector<std::string> const TMoverParameters::eimc_labels = {
"dfic: ", "dfmax:", "p: ", "scfu: ", "cim: ", "icif: ", "Uzmax:", "Uzh: ", "DU: ", "I0: ",
"fcfu: ", "F0: ", "a1: ", "Pmax: ", "Fh: ", "Ph: ", "Vh0: ", "Vh1: ", "Imax: ", "abed: ",
@@ -5097,14 +5100,17 @@ bool TMoverParameters::AutoRelayCheck(void)
// IminLo
}
// main bez samoczynnego rozruchu
if( ( MainCtrlActualPos < ( sizeof( RList ) / sizeof( TScheme ) - 1 ) ) // crude guard against running out of current fixed table
&& ( ( RList[ MainCtrlActualPos ].Relay < MainCtrlPos )
|| ( RList[ MainCtrlActualPos + 1 ].Relay == MainCtrlPos )
|| ( ( TrainType == dt_ET22 )
&& ( DelayCtrlFlag ) ) ) ) {
if( ( RList[MainCtrlPos].R == 0 )
&& ( MainCtrlPos > 0 )
&& ( MainCtrlPos != MainCtrlPosNo )
&& ( FastSerialCircuit == 1 ) ) {
if ((RList[MainCtrlActualPos].Relay < MainCtrlPos) ||
(RList[MainCtrlActualPos + 1].Relay == MainCtrlPos) ||
((TrainType == dt_ET22) && (DelayCtrlFlag)))
{
if ((RList[MainCtrlPos].R == 0) && (MainCtrlPos > 0) &&
(!(MainCtrlPos == MainCtrlPosNo)) && (FastSerialCircuit == 1))
{
MainCtrlActualPos++;
// MainCtrlActualPos:=MainCtrlPos; //hunter-111012:
// szybkie wchodzenie na bezoporowa (303E)
@@ -5803,28 +5809,28 @@ std::string TMoverParameters::EngineDescription(int what)
{
if (TestFlag(DamageFlag, dtrain_thinwheel))
if (Power > 0.1)
outstr = "Thin wheel,";
outstr = "Thin wheel";
else
outstr = "Load shifted,";
outstr = "Load shifted";
if (TestFlag(DamageFlag, dtrain_wheelwear))
outstr = "Wheel wear,";
outstr = "Wheel wear";
if (TestFlag(DamageFlag, dtrain_bearing))
outstr = "Bearing damaged,";
outstr = "Bearing damaged";
if (TestFlag(DamageFlag, dtrain_coupling))
outstr = "Coupler broken,";
outstr = "Coupler broken";
if (TestFlag(DamageFlag, dtrain_loaddamage))
if (Power > 0.1)
outstr = "Ventilator damaged,";
outstr = "Ventilator damaged";
else
outstr = "Load damaged,";
outstr = "Load damaged";
if (TestFlag(DamageFlag, dtrain_loaddestroyed))
if (Power > 0.1)
outstr = "Engine damaged,";
outstr = "Engine damaged";
else
outstr = "LOAD DESTROYED,";
outstr = "LOAD DESTROYED";
if (TestFlag(DamageFlag, dtrain_axle))
outstr = "Axle broken,";
outstr = "Axle broken";
if (TestFlag(DamageFlag, dtrain_out))
outstr = "DERAILED";
if (outstr == "")
@@ -6105,7 +6111,7 @@ bool TMoverParameters::readRList( std::string const &Input ) {
return false;
}
auto idx = LISTLINE++;
if( idx >= sizeof( RList ) ) {
if( idx >= sizeof( RList ) / sizeof( TScheme ) ) {
WriteLog( "Read RList: number of entries exceeded capacity of the data table" );
return false;
}
@@ -6127,7 +6133,7 @@ bool TMoverParameters::readDList( std::string const &line ) {
cParser parser( line );
parser.getTokens( 3, false );
auto idx = LISTLINE++;
if( idx >= sizeof( RList ) ) {
if( idx >= sizeof( RList ) / sizeof( TScheme ) ) {
WriteLog( "Read DList: number of entries exceeded capacity of the data table" );
return false;
}
@@ -6147,7 +6153,7 @@ bool TMoverParameters::readFFList( std::string const &line ) {
return false;
}
int idx = LISTLINE++;
if( idx >= sizeof( DElist ) ) {
if( idx >= sizeof( DElist ) / sizeof( TDEScheme ) ) {
WriteLog( "Read FList: number of entries exceeded capacity of the data table" );
return false;
}
@@ -6167,7 +6173,7 @@ bool TMoverParameters::readWWList( std::string const &line ) {
return false;
}
int idx = LISTLINE++;
if( idx >= sizeof( DElist ) ) {
if( idx >= sizeof( DElist ) / sizeof( TDEScheme ) ) {
WriteLog( "Read WWList: number of entries exceeded capacity of the data table" );
return false;
}
@@ -8364,22 +8370,3 @@ double TMoverParameters::ShowCurrentP(int AmpN)
return current;
}
}
template <>
bool
extract_value( bool &Variable, std::string const &Key, std::string const &Input, std::string const &Default ) {
auto value = extract_value( Key, Input );
if( false == value.empty() ) {
// set the specified variable to retrieved value
Variable = ( ToLower( value ) == "yes" );
return true; // located the variable
}
else {
// set the variable to provided default value
if( false == Default.empty() ) {
Variable = ( ToLower( Default ) == "yes" );
}
return false; // couldn't locate the variable in provided input
}
}

View File

@@ -17,41 +17,9 @@ Copyright (C) 2007-2014 Maciej Cierniak
/*================================================*/
int ConversionError = 0;
int LineCount = 0;
bool DebugModeFlag = false;
bool FreeFlyModeFlag = false;
//std::string Ups(std::string s)
//{
// int jatka;
// std::string swy;
//
// swy = "";
// {
// long jatka_end = s.length() + 1;
// for (jatka = 0; jatka < jatka_end; jatka++)
// swy = swy + UpCase(s[jatka]);
// }
// return swy;
//} /*=Ups=*/
int Max0(int x1, int x2)
{
if (x1 > x2)
return x1;
else
return x2;
}
int Min0(int x1, int x2)
{
if (x1 < x2)
return x1;
else
return x2;
}
double Max0R(double x1, double x2)
{
if (x1 > x2)
@@ -87,13 +55,8 @@ bool TestFlag(int Flag, int Value)
return false;
}
bool SetFlag(int &Flag, int Value)
{
return iSetFlag(Flag, Value);
}
bool SetFlag(int &Flag, int Value) {
bool iSetFlag(int &Flag, int Value)
{
if (Value > 0)
{
if ((Flag & Value) == 0)
@@ -263,33 +226,13 @@ std::string to_hex_str( int const Value, int const Width )
return converter.str();
};
int stol_def(const std::string &str, const int &DefaultValue)
{
int stol_def(const std::string &str, const int &DefaultValue) {
int result { DefaultValue };
std::stringstream converter;
converter << str;
converter >> result;
return result;
/*
// this function was developed iteratively on Codereview.stackexchange
// with the assistance of @Corbin
std::size_t len = str.size();
while (std::isspace(str[len - 1]))
len--;
if (len == 0)
return DefaultValue;
errno = 0;
char *s = new char[len + 1];
std::strncpy(s, str.c_str(), len);
char *p;
int result = strtol(s, &p, 0);
delete[] s;
if( ( *p != '\0' ) || ( errno != 0 ) )
{
return DefaultValue;
}
return result;
*/
}
std::string ToLower(std::string const &text)
@@ -321,114 +264,27 @@ win1250_to_ascii( std::string &Input ) {
}
}
void ComputeArc(double X0, double Y0, double Xn, double Yn, double R, double L, double dL,
double &phi, double &Xout, double &Yout)
/*wylicza polozenie Xout Yout i orientacje phi punktu na elemencie dL luku*/
{
double dX;
double dY;
double Xc;
double Yc;
double gamma;
double alfa;
double AbsR;
template <>
bool
extract_value( bool &Variable, std::string const &Key, std::string const &Input, std::string const &Default ) {
if ((R != 0) && (L != 0))
{
AbsR = abs(R);
dX = Xn - X0;
dY = Yn - Y0;
if (dX != 0)
gamma = atan(dY * 1.0 / dX);
else if (dY > 0)
gamma = M_PI * 1.0 / 2;
else
gamma = 3 * M_PI * 1.0 / 2;
alfa = L * 1.0 / R;
phi = gamma - (alfa + M_PI * Round(R * 1.0 / AbsR)) * 1.0 / 2;
Xc = X0 - AbsR * cos(phi);
Yc = Y0 - AbsR * sin(phi);
phi = phi + alfa * dL * 1.0 / L;
Xout = AbsR * cos(phi) + Xc;
Yout = AbsR * sin(phi) + Yc;
auto value = extract_value( Key, Input );
if( false == value.empty() ) {
// set the specified variable to retrieved value
Variable = ( ToLower( value ) == "yes" );
return true; // located the variable
}
else {
// set the variable to provided default value
if( false == Default.empty() ) {
Variable = ( ToLower( Default ) == "yes" );
}
return false; // couldn't locate the variable in provided input
}
}
void ComputeALine(double X0, double Y0, double Xn, double Yn, double L, double R, double &Xout,
double &Yout)
{
double dX;
double dY;
double gamma;
double alfa;
/* pX,pY : real;*/
alfa = 0; // ABu: bo nie bylo zainicjowane
dX = Xn - X0;
dY = Yn - Y0;
if (dX != 0)
gamma = atan(dY * 1.0 / dX);
else if (dY > 0)
gamma = M_PI * 1.0 / 2;
else
gamma = 3 * M_PI * 1.0 / 2;
if (R != 0)
alfa = L * 1.0 / R;
Xout = X0 + L * cos(alfa * 1.0 / 2 - gamma);
Yout = Y0 + L * sin(alfa * 1.0 / 2 - gamma);
}
bool FileExists( std::string const &Filename ) {
std::ifstream file( Filename );
std::ifstream file( Filename );
return( true == file.is_open() );
}
/*
//graficzne:
double Xhor(double h)
{
return h * Hstep + Xmin;
}
double Yver(double v)
{
return (Vsize - v) * Vstep + Ymin;
}
long Horiz(double x)
{
x = (x - Xmin) * 1.0 / Hstep;
if (x > -INT_MAX)
if (x < INT_MAX)
return Round(x);
else
return INT_MAX;
else
return -INT_MAX;
}
long Vert(double Y)
{
Y = (Y - Ymin) * 1.0 / Vstep;
if (Y > -INT_MAX)
if (Y < INT_MAX)
return Vsize - Round(Y);
else
return INT_MAX;
else
return -INT_MAX;
}
*/
// NOTE: this now does nothing.
void ClearPendingExceptions()
// resetuje błędy FPU, wymagane dla Trunc()
{
; /*?*/ /* ASM
FNCLEX
ASM END */
}
// END

View File

@@ -15,48 +15,16 @@ http://mozilla.org/MPL/2.0/.
#include <string>
#include <fstream>
#include <ctime>
#include <sys/stat.h>
#include <vector>
#include <sstream>
/*Ra: te stałe nie są używane...
_FileName = ['a'..'z','A'..'Z',':','\','.','*','?','0'..'9','_','-'];
_RealNum = ['0'..'9','-','+','.','E','e'];
_Integer = ['0'..'9','-']; //Ra: to się gryzie z STLport w Builder 6
_Plus_Int = ['0'..'9'];
_All = [' '..'ţ'];
_Delimiter= [',',';']+_EOL;
_Delimiter_Space=_Delimiter+[' '];
*/
static char _EOL[2] = { (char)13, (char)10 };
static char _Spacesigns[4] = { (char)' ', (char)9, (char)13, (char)10 };
static std::string _spacesigns = " " + (char)9 + (char)13 + (char)10;
static int const CutLeft = -1;
static int const CutRight = 1;
static int const CutBoth = 0; /*Cut_Space*/
extern int ConversionError;
extern int LineCount;
extern bool DebugModeFlag;
extern bool FreeFlyModeFlag;
typedef unsigned long/*?*//*set of: char */ TableChar; /*MCTUTIL*/
/*konwersje*/
/*funkcje matematyczne*/
int Max0(int x1, int x2);
int Min0(int x1, int x2);
double Max0R(double x1, double x2);
double Min0R(double x1, double x2);
inline int Sign(int x)
{
return x >= 0 ? 1 : -1;
}
inline double Sign(double x)
{
return x >= 0 ? 1.0 : -1.0;
@@ -68,7 +36,7 @@ inline long Round(double const f)
//return lround(f);
}
extern double Random(double a, double b);
double Random(double a, double b);
inline double Random()
{
@@ -94,10 +62,9 @@ inline double BorlandTime()
std::string Now();
/*funkcje logiczne*/
extern bool TestFlag(int Flag, int Value);
extern bool SetFlag( int & Flag, int Value);
extern bool iSetFlag( int & Flag, int Value);
extern bool UnSetFlag(int &Flag, int Value);
bool TestFlag(int Flag, int Value);
bool SetFlag( int & Flag, int Value);
bool UnSetFlag(int &Flag, int Value);
bool FuzzyLogic(double Test, double Threshold, double Probability);
/*jesli Test>Threshold to losowanie*/
@@ -139,40 +106,48 @@ std::string ToUpper(std::string const &text);
// replaces polish letters with basic ascii
void win1250_to_ascii( std::string &Input );
/*procedury, zmienne i funkcje graficzne*/
void ComputeArc(double X0, double Y0, double Xn, double Yn, double R, double L, double dL, double & phi, double & Xout, double & Yout);
/*wylicza polozenie Xout Yout i orientacje phi punktu na elemencie dL luku*/
void ComputeALine(double X0, double Y0, double Xn, double Yn, double L, double R, double & Xout, double & Yout);
/*
inline bool fileExists(const std::string &name)
{
struct stat buffer;
return (stat(name.c_str(), &buffer) == 0);
}*/
inline
std::string
extract_value( std::string const &Key, std::string const &Input ) {
std::string value;
auto lookup = Input.find( Key + "=" );
if( lookup != std::string::npos ) {
value = Input.substr( Input.find_first_not_of( ' ', lookup + Key.size() + 1 ) );
lookup = value.find( ' ' );
if( lookup != std::string::npos ) {
// trim everything past the value
value.erase( lookup );
}
}
return value;
}
template <typename Type_>
bool
extract_value( Type_ &Variable, std::string const &Key, std::string const &Input, std::string const &Default ) {
auto value = extract_value( Key, Input );
if( false == value.empty() ) {
// set the specified variable to retrieved value
std::stringstream converter;
converter << value;
converter >> Variable;
return true; // located the variable
}
else {
// set the variable to provided default value
if( false == Default.empty() ) {
std::stringstream converter;
converter << Default;
converter >> Variable;
}
return false; // couldn't locate the variable in provided input
}
}
template <>
bool
extract_value( bool &Variable, std::string const &Key, std::string const &Input, std::string const &Default );
bool FileExists( std::string const &Filename );
/*
extern double Xmin;
extern double Ymin;
extern double Xmax;
extern double Ymax;
extern double Xaspect;
extern double Yaspect;
extern double Hstep;
extern double Vstep;
extern int Vsize;
extern int Hsize;
// Converts horizontal screen coordinate into real X-coordinate.
double Xhor( double h );
// Converts vertical screen coordinate into real Y-coordinate.
double Yver( double v );
long Horiz(double x);
long Vert(double Y);
*/
void ClearPendingExceptions();