mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-18 04:19:19 +02:00
partial replacement of char arrays with std::string; minor updates, fixes and cleanup of mctools
This commit is contained in:
@@ -319,7 +319,7 @@ std::string TSpeedPos::TableText()
|
||||
if (iFlags & spEnabled)
|
||||
{ // o ile pozycja istotna
|
||||
return "Flags=" + to_hex_str(iFlags, 6) + ", Dist=" + to_string(fDist, 1, 7) +
|
||||
", Vel=" + to_string(fVelNext, 1, 5) + ", Name=" + GetName();
|
||||
", Vel=" + (fVelNext == -1.0 ? " * " : to_string(fVelNext, 1, 5)) + ", Name=" + GetName();
|
||||
//if (iFlags & spTrack) // jeśli tor
|
||||
// return "Flags=#" + IntToHex(iFlags, 8) + ", Dist=" + FloatToStrF(fDist, ffFixed, 7, 1) +
|
||||
// ", Vel=" + AnsiString(fVelNext) + ", Track=" + trTrack->NameGet();
|
||||
|
||||
16
EvLaunch.cpp
16
EvLaunch.cpp
@@ -36,19 +36,21 @@ TEventLauncher::TEventLauncher()
|
||||
DeltaTime = -1;
|
||||
UpdatedTime = 0;
|
||||
fVal1 = fVal2 = 0;
|
||||
#ifdef EU07_USE_OLD_TEVENTLAUNCHER_TEXT_ARRAY
|
||||
szText = NULL;
|
||||
#endif
|
||||
iHour = iMinute = -1; // takiego czasu nigdy nie będzie
|
||||
dRadius = 0;
|
||||
Event1 = Event2 = NULL;
|
||||
MemCell = NULL;
|
||||
iCheckMask = 0;
|
||||
}
|
||||
|
||||
#ifdef EU07_USE_OLD_TEVENTLAUNCHER_TEXT_ARRAY
|
||||
TEventLauncher::~TEventLauncher()
|
||||
{
|
||||
SafeDeleteArray(szText);
|
||||
}
|
||||
|
||||
#endif
|
||||
void TEventLauncher::Init()
|
||||
{
|
||||
}
|
||||
@@ -105,17 +107,20 @@ bool TEventLauncher::Load(cParser *parser)
|
||||
asMemCellName = token;
|
||||
parser->getTokens();
|
||||
*parser >> token;
|
||||
#ifdef EU07_USE_OLD_TEVENTLAUNCHER_TEXT_ARRAY
|
||||
SafeDeleteArray(szText);
|
||||
szText = new char[256];
|
||||
strcpy(szText, token.c_str());
|
||||
if (token.compare("*") != 0) //*=nie brać command pod uwagę
|
||||
#else
|
||||
szText = token;
|
||||
#endif
|
||||
if (token != "*") //*=nie brać command pod uwagę
|
||||
iCheckMask |= conditional_memstring;
|
||||
parser->getTokens();
|
||||
*parser >> token;
|
||||
if (token.compare("*") != 0) //*=nie brać wartości 1. pod uwagę
|
||||
if (token != "*") //*=nie brać wartości 1. pod uwagę
|
||||
{
|
||||
iCheckMask |= conditional_memval1;
|
||||
//str = AnsiString(token.c_str());
|
||||
fVal1 = atof(token.c_str());
|
||||
}
|
||||
else
|
||||
@@ -125,7 +130,6 @@ bool TEventLauncher::Load(cParser *parser)
|
||||
if (token.compare("*") != 0) //*=nie brać wartości 2. pod uwagę
|
||||
{
|
||||
iCheckMask |= conditional_memval2;
|
||||
//str = AnsiString(token.c_str());
|
||||
fVal2 = atof(token.c_str());
|
||||
}
|
||||
else
|
||||
|
||||
@@ -21,7 +21,11 @@ class TEventLauncher
|
||||
double UpdatedTime;
|
||||
double fVal1;
|
||||
double fVal2;
|
||||
char *szText;
|
||||
#ifdef EU07_USE_OLD_TEVENTLAUNCHER_TEXT_ARRAY
|
||||
char * szText;
|
||||
#else
|
||||
std::string szText;
|
||||
#endif
|
||||
int iHour, iMinute; // minuta uruchomienia
|
||||
public:
|
||||
double dRadius;
|
||||
@@ -33,7 +37,9 @@ class TEventLauncher
|
||||
TMemCell *MemCell;
|
||||
int iCheckMask;
|
||||
TEventLauncher();
|
||||
#ifdef EU07_USE_OLD_TEVENTLAUNCHER_TEXT_ARRAY
|
||||
~TEventLauncher();
|
||||
#endif
|
||||
void Init();
|
||||
bool Load(cParser *parser);
|
||||
bool Render();
|
||||
|
||||
54
Ground.cpp
54
Ground.cpp
@@ -3998,7 +3998,8 @@ bool TGround::CheckQuery()
|
||||
{
|
||||
case tp_CopyValues: // skopiowanie wartości z innej komórki
|
||||
tmpEvent->Params[5].asMemCell->UpdateValues(
|
||||
tmpEvent->Params[9].asMemCell->Text(), tmpEvent->Params[9].asMemCell->Value1(),
|
||||
tmpEvent->Params[9].asMemCell->Text(),
|
||||
tmpEvent->Params[9].asMemCell->Value1(),
|
||||
tmpEvent->Params[9].asMemCell->Value2(),
|
||||
tmpEvent->iFlags // flagi określają, co ma być skopiowane
|
||||
);
|
||||
@@ -4009,8 +4010,10 @@ bool TGround::CheckQuery()
|
||||
{ // teraz mogą być warunki do tych eventów
|
||||
if (tmpEvent->Type != tp_CopyValues) // dla CopyValues zrobiło się wcześniej
|
||||
tmpEvent->Params[5].asMemCell->UpdateValues(
|
||||
tmpEvent->Params[0].asText, tmpEvent->Params[1].asdouble,
|
||||
tmpEvent->Params[2].asdouble, tmpEvent->iFlags);
|
||||
tmpEvent->Params[0].asText,
|
||||
tmpEvent->Params[1].asdouble,
|
||||
tmpEvent->Params[2].asdouble,
|
||||
tmpEvent->iFlags);
|
||||
if (tmpEvent->Params[6].asTrack)
|
||||
{ // McZapkie-100302 - updatevalues oprocz zmiany wartosci robi putcommand dla
|
||||
// wszystkich 'dynamic' na danym torze
|
||||
@@ -4198,14 +4201,24 @@ bool TGround::CheckQuery()
|
||||
if (tmpEvent->iFlags & update_load)
|
||||
{ // jeśli pytanie o ładunek
|
||||
if (tmpEvent->iFlags & update_memadd) // jeśli typ pojazdu
|
||||
tmpEvent->Params[9].asMemCell->UpdateValues(
|
||||
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
|
||||
tmpEvent->Params[ 9 ].asMemCell->UpdateValues(
|
||||
strdup(tmpEvent->Activator->MoverParameters->TypeName.c_str()), // typ pojazdu
|
||||
0, // na razie nic
|
||||
0, // na razie nic
|
||||
tmpEvent->iFlags &
|
||||
(update_memstring | update_memval1 | update_memval2));
|
||||
#else
|
||||
tmpEvent->Params[ 9 ].asMemCell->UpdateValues(
|
||||
tmpEvent->Activator->MoverParameters->TypeName, // typ pojazdu
|
||||
0, // na razie nic
|
||||
0, // na razie nic
|
||||
tmpEvent->iFlags &
|
||||
(update_memstring | update_memval1 | update_memval2));
|
||||
#endif
|
||||
else // jeśli parametry ładunku
|
||||
tmpEvent->Params[9].asMemCell->UpdateValues(
|
||||
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
|
||||
tmpEvent->Params[ 9 ].asMemCell->UpdateValues(
|
||||
tmpEvent->Activator->MoverParameters->LoadType != "" ?
|
||||
strdup(tmpEvent->Activator->MoverParameters->LoadType.c_str()) :
|
||||
(char*)"none", // nazwa ładunku
|
||||
@@ -4213,21 +4226,38 @@ bool TGround::CheckQuery()
|
||||
tmpEvent->Activator->MoverParameters->MaxLoad, // maksymalna ilość
|
||||
tmpEvent->iFlags &
|
||||
(update_memstring | update_memval1 | update_memval2));
|
||||
#else
|
||||
tmpEvent->Params[ 9 ].asMemCell->UpdateValues(
|
||||
tmpEvent->Activator->MoverParameters->LoadType, // nazwa ładunku
|
||||
tmpEvent->Activator->MoverParameters->Load, // aktualna ilość
|
||||
tmpEvent->Activator->MoverParameters->MaxLoad, // maksymalna ilość
|
||||
tmpEvent->iFlags &
|
||||
(update_memstring | update_memval1 | update_memval2));
|
||||
#endif
|
||||
}
|
||||
else if (tmpEvent->iFlags & update_memadd)
|
||||
{ // jeśli miejsce docelowe pojazdu
|
||||
tmpEvent->Params[9].asMemCell->UpdateValues(
|
||||
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
|
||||
tmpEvent->Params[ 9 ].asMemCell->UpdateValues(
|
||||
strdup(tmpEvent->Activator->asDestination.c_str()), // adres docelowy
|
||||
tmpEvent->Activator->DirectionGet(), // kierunek pojazdu względem czoła
|
||||
// składu (1=zgodny,-1=przeciwny)
|
||||
tmpEvent->Activator->MoverParameters
|
||||
->Power, // moc pojazdu silnikowego: 0 dla wagonu
|
||||
tmpEvent->iFlags & (update_memstring | update_memval1 | update_memval2));
|
||||
#else
|
||||
tmpEvent->Params[ 9 ].asMemCell->UpdateValues(
|
||||
tmpEvent->Activator->asDestination, // adres docelowy
|
||||
tmpEvent->Activator->DirectionGet(), // kierunek pojazdu względem czoła składu (1=zgodny,-1=przeciwny)
|
||||
tmpEvent->Activator->MoverParameters ->Power, // moc pojazdu silnikowego: 0 dla wagonu
|
||||
tmpEvent->iFlags & (update_memstring | update_memval1 | update_memval2));
|
||||
#endif
|
||||
}
|
||||
else if (tmpEvent->Activator->Mechanik)
|
||||
if (tmpEvent->Activator->Mechanik->Primary())
|
||||
{ // tylko jeśli ktoś tam siedzi - nie powinno dotyczyć pasażera!
|
||||
tmpEvent->Params[9].asMemCell->UpdateValues(
|
||||
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
|
||||
tmpEvent->Params[ 9 ].asMemCell->UpdateValues(
|
||||
const_cast<char *>(tmpEvent->Activator->Mechanik->TrainName().c_str()),
|
||||
tmpEvent->Activator->Mechanik->StationCount() -
|
||||
tmpEvent->Activator->Mechanik
|
||||
@@ -4235,6 +4265,16 @@ bool TGround::CheckQuery()
|
||||
tmpEvent->Activator->Mechanik->IsStop() ? 1 :
|
||||
0, // 1, gdy ma tu zatrzymanie
|
||||
tmpEvent->iFlags);
|
||||
#else
|
||||
tmpEvent->Params[ 9 ].asMemCell->UpdateValues(
|
||||
tmpEvent->Activator->Mechanik->TrainName(),
|
||||
tmpEvent->Activator->Mechanik->StationCount() -
|
||||
tmpEvent->Activator->Mechanik
|
||||
->StationIndex(), // ile przystanków do końca
|
||||
tmpEvent->Activator->Mechanik->IsStop() ? 1 :
|
||||
0, // 1, gdy ma tu zatrzymanie
|
||||
tmpEvent->iFlags);
|
||||
#endif
|
||||
WriteLog("Train detected: " + tmpEvent->Activator->Mechanik->TrainName());
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -5836,7 +5836,7 @@ bool TMoverParameters::readDList( std::string const &line ) {
|
||||
++DLISTLINE;
|
||||
int idx = 0;
|
||||
parser >> idx;
|
||||
if( idx >= sizeof( DElist ) ) {
|
||||
if( idx >= sizeof( RList ) ) {
|
||||
WriteLog( "Read DList: number of entries exceeded capacity of the data table" );
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ bool FuzzyLogicAI(double Test, double Threshold, double Probability)
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string ReadWord(std::ifstream& infile)
|
||||
std::string ReadWord(std::ifstream &infile)
|
||||
{
|
||||
std::string s = "";
|
||||
char c;
|
||||
@@ -176,7 +176,7 @@ std::string ReadWord(std::ifstream& infile)
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string TrimSpace(std::string &s, int Just)
|
||||
std::string TrimSpace(std::string &s)
|
||||
{
|
||||
/*int ii;
|
||||
|
||||
@@ -266,41 +266,6 @@ std::string DWE(std::string s) /*Delete After Equal sign*/
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string Ld2Sp(std::string const &s) /*Low dash to Space sign*/
|
||||
{
|
||||
std::string s2( s );
|
||||
char tmp[] = { '_', ' ' };
|
||||
for (int b = 0; b < s2.length(); ++b)
|
||||
if (s2[b] == tmp[0])
|
||||
s2[b] = tmp[1];
|
||||
//{
|
||||
// if (s[b] == tmp[0])
|
||||
// s2 = s2 + " ";
|
||||
// else
|
||||
// s2 = s2 + s[b];
|
||||
//}
|
||||
return s2;
|
||||
}
|
||||
|
||||
std::string Tab2Sp(std::string const &s) /*Tab to Space sign*/
|
||||
{
|
||||
std::string s2 = "";
|
||||
char tmp = (char)9;
|
||||
for (std::size_t b = 0; b < s.length(); ++b)
|
||||
//{
|
||||
// if (s[b] == tmp[0])
|
||||
// s[b] = tmp[1];
|
||||
//}
|
||||
//return s;
|
||||
{
|
||||
if (s[b] == tmp)
|
||||
s2 = s2 + " ";
|
||||
else
|
||||
s2 = s2 + s[b];
|
||||
}
|
||||
return s2;
|
||||
}
|
||||
|
||||
std::string ExchangeCharInString( std::string const &Source, char const &From, char const &To )
|
||||
{
|
||||
std::string replacement; replacement.reserve( Source.size() );
|
||||
@@ -311,22 +276,6 @@ std::string ExchangeCharInString( std::string const &Source, char const &From, c
|
||||
} );
|
||||
|
||||
return replacement;
|
||||
/*
|
||||
int const length = Source.size();
|
||||
std::string replacement; replacement.reserve( length );
|
||||
for( int idx = 0; idx < length; ++idx ) {
|
||||
if( Source[ idx ] != From ) {
|
||||
replacement += Source[ idx ];
|
||||
}
|
||||
else {
|
||||
if( To != NULL ) {
|
||||
replacement += To;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return replacement;
|
||||
*/
|
||||
}
|
||||
|
||||
std::vector<std::string> &Split(const std::string &s, char delim, std::vector<std::string> &elems)
|
||||
@@ -422,9 +371,12 @@ std::string to_hex_str( int const Value, int const Width )
|
||||
|
||||
int stol_def(const std::string &str, const int &DefaultValue)
|
||||
{
|
||||
// NOTE: there's good chance this function is bugged, it produced wrong result on at least one occasion
|
||||
// TODO: rewrite into something more reliable
|
||||
|
||||
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();
|
||||
@@ -443,6 +395,7 @@ int stol_def(const std::string &str, const int &DefaultValue)
|
||||
return DefaultValue;
|
||||
}
|
||||
return result;
|
||||
*/
|
||||
}
|
||||
|
||||
std::string ToLower(std::string const &text)
|
||||
|
||||
@@ -82,16 +82,13 @@ inline double Random(double b)
|
||||
|
||||
inline double BorlandTime()
|
||||
{
|
||||
std::tm epoch;
|
||||
epoch.tm_sec = 0;
|
||||
epoch.tm_min = 0;
|
||||
epoch.tm_hour = 0;
|
||||
epoch.tm_mday = 1;
|
||||
epoch.tm_mon = 0;
|
||||
epoch.tm_year = 0;
|
||||
time_t basetime = mktime(&epoch);
|
||||
time_t raw_t = time(NULL);
|
||||
return (difftime(raw_t, basetime) / 24) + 2;
|
||||
auto timesinceepoch = std::time( nullptr );
|
||||
return timesinceepoch / (24.0 * 60 * 60);
|
||||
/*
|
||||
// std alternative
|
||||
auto timesinceepoch = std::chrono::system_clock::now().time_since_epoch();
|
||||
return std::chrono::duration_cast<std::chrono::seconds>( timesinceepoch ).count() / (24.0 * 60 * 60);
|
||||
*/
|
||||
}
|
||||
|
||||
std::string Now();
|
||||
@@ -110,13 +107,11 @@ bool FuzzyLogicAI(double Test, double Threshold, double Probability);
|
||||
/*operacje na stringach*/
|
||||
std::string ReadWord( std::ifstream& infile); /*czyta slowo z wiersza pliku tekstowego*/
|
||||
//std::string Ups(std::string s);
|
||||
std::string TrimSpace(std::string &s, int Just = CutBoth);
|
||||
std::string TrimSpace(std::string &s);
|
||||
char* TrimAndReduceSpaces(const char* s);
|
||||
std::string ExtractKeyWord(std::string InS, std::string KeyWord); /*wyciaga slowo kluczowe i lancuch do pierwszej spacji*/
|
||||
std::string DUE(std::string s); /*Delete Until Equal sign*/
|
||||
std::string DWE(std::string s); /*Delete While Equal sign*/
|
||||
std::string Ld2Sp(std::string const &s); /*Low dash to Space sign*/
|
||||
std::string Tab2Sp(std::string const &s); /*Tab to Space sign*/
|
||||
std::string ExchangeCharInString(std::string const &s, const char &aim, const char &target); // zamienia jeden znak na drugi
|
||||
std::vector<std::string> &Split(const std::string &s, char delim, std::vector<std::string> &elems);
|
||||
std::vector<std::string> Split(const std::string &s, char delim);
|
||||
|
||||
128
MemCell.cpp
128
MemCell.cpp
@@ -28,29 +28,37 @@ http://mozilla.org/MPL/2.0/.
|
||||
TMemCell::TMemCell(vector3 *p)
|
||||
{
|
||||
fValue1 = fValue2 = 0;
|
||||
szText = new char[256]; // musi być dla automatycznie tworzonych komórek dla odcinków
|
||||
// izolowanych
|
||||
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
|
||||
szText = new char[256]; // musi być dla automatycznie tworzonych komórek dla odcinków izolowanych
|
||||
#endif
|
||||
vPosition =
|
||||
p ? *p : vector3(0, 0, 0); // ustawienie współrzędnych, bo do TGroundNode nie ma dostępu
|
||||
bCommand = false; // komenda wysłana
|
||||
OnSent = NULL;
|
||||
}
|
||||
|
||||
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
|
||||
TMemCell::~TMemCell()
|
||||
{
|
||||
SafeDeleteArray(szText);
|
||||
}
|
||||
|
||||
#endif
|
||||
void TMemCell::Init()
|
||||
{
|
||||
}
|
||||
|
||||
void TMemCell::UpdateValues(char *szNewText, double fNewValue1, double fNewValue2, int CheckMask)
|
||||
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
|
||||
void TMemCell::UpdateValues(char const *szNewText, double const fNewValue1, double const fNewValue2, int const CheckMask)
|
||||
#else
|
||||
void TMemCell::UpdateValues( std::string const &szNewText, double const fNewValue1, double const fNewValue2, int const CheckMask )
|
||||
#endif
|
||||
{
|
||||
if (CheckMask & update_memadd)
|
||||
{ // dodawanie wartości
|
||||
if (TestFlag(CheckMask, update_memstring))
|
||||
strcat(szText, szNewText);
|
||||
if( TestFlag( CheckMask, update_memstring ) )
|
||||
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
|
||||
strcat( szText, szNewText );
|
||||
#else
|
||||
szText += szNewText;
|
||||
#endif
|
||||
if (TestFlag(CheckMask, update_memval1))
|
||||
fValue1 += fNewValue1;
|
||||
if (TestFlag(CheckMask, update_memval2))
|
||||
@@ -58,8 +66,12 @@ void TMemCell::UpdateValues(char *szNewText, double fNewValue1, double fNewValue
|
||||
}
|
||||
else
|
||||
{
|
||||
if (TestFlag(CheckMask, update_memstring))
|
||||
strcpy(szText, szNewText);
|
||||
if( TestFlag( CheckMask, update_memstring ) )
|
||||
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
|
||||
strcpy( szText, szNewText );
|
||||
#else
|
||||
szText = szNewText;
|
||||
#endif
|
||||
if (TestFlag(CheckMask, update_memval1))
|
||||
fValue1 = fNewValue1;
|
||||
if (TestFlag(CheckMask, update_memval2))
|
||||
@@ -71,32 +83,56 @@ void TMemCell::UpdateValues(char *szNewText, double fNewValue1, double fNewValue
|
||||
|
||||
TCommandType TMemCell::CommandCheck()
|
||||
{ // rozpoznanie komendy
|
||||
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
|
||||
if (strcmp(szText, "SetVelocity") == 0) // najpopularniejsze
|
||||
#else
|
||||
if( szText == "SetVelocity" ) // najpopularniejsze
|
||||
#endif
|
||||
{
|
||||
eCommand = cm_SetVelocity;
|
||||
bCommand = false; // ta komenda nie jest wysyłana
|
||||
}
|
||||
else if (strcmp(szText, "ShuntVelocity") == 0) // w tarczach manewrowych
|
||||
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
|
||||
else if( strcmp( szText, "ShuntVelocity" ) == 0 ) // w tarczach manewrowych
|
||||
#else
|
||||
else if( szText == "ShuntVelocity" ) // w tarczach manewrowych
|
||||
#endif
|
||||
{
|
||||
eCommand = cm_ShuntVelocity;
|
||||
bCommand = false; // ta komenda nie jest wysyłana
|
||||
}
|
||||
else if (strcmp(szText, "Change_direction") == 0) // zdarza się
|
||||
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
|
||||
else if( strcmp( szText, "Change_direction" ) == 0 ) // zdarza się
|
||||
#else
|
||||
else if( szText == "Change_direction" ) // zdarza się
|
||||
#endif
|
||||
{
|
||||
eCommand = cm_ChangeDirection;
|
||||
bCommand = true; // do wysłania
|
||||
}
|
||||
else if (strcmp(szText, "OutsideStation") == 0) // zdarza się
|
||||
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
|
||||
else if( strcmp( szText, "OutsideStation" ) == 0 ) // zdarza się
|
||||
#else
|
||||
else if( szText == "OutsideStation" ) // zdarza się
|
||||
#endif
|
||||
{
|
||||
eCommand = cm_OutsideStation;
|
||||
bCommand = false; // tego nie powinno być w komórce
|
||||
}
|
||||
else if (strncmp(szText, "PassengerStopPoint:", 19) == 0) // porównanie początków
|
||||
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
|
||||
else if( strncmp( szText, "PassengerStopPoint:", 19 ) == 0 ) // porównanie początków
|
||||
#else
|
||||
else if( szText.compare( 0, 19, "PassengerStopPoint:" ) == 0 ) // porównanie początków
|
||||
#endif
|
||||
{
|
||||
eCommand = cm_PassengerStopPoint;
|
||||
bCommand = false; // tego nie powinno być w komórce
|
||||
}
|
||||
else if (strcmp(szText, "SetProximityVelocity") == 0) // nie powinno tego być
|
||||
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
|
||||
else if( strcmp( szText, "SetProximityVelocity" ) == 0 ) // nie powinno tego być
|
||||
#else
|
||||
else if( szText == "SetProximityVelocity" ) // nie powinno tego być
|
||||
#endif
|
||||
{
|
||||
eCommand = cm_SetProximityVelocity;
|
||||
bCommand = false; // ta komenda nie jest wysyłana
|
||||
@@ -113,21 +149,25 @@ bool TMemCell::Load(cParser *parser)
|
||||
{
|
||||
std::string token;
|
||||
parser->getTokens(1, false); // case sensitive
|
||||
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
|
||||
*parser >> token;
|
||||
SafeDeleteArray(szText);
|
||||
szText = new char[256]; // musi być bufor do łączenia tekstów
|
||||
strcpy(szText, token.c_str());
|
||||
parser->getTokens();
|
||||
*parser >> fValue1;
|
||||
parser->getTokens();
|
||||
*parser >> fValue2;
|
||||
#else
|
||||
*parser >> szText;
|
||||
#endif
|
||||
parser->getTokens( 2, false );
|
||||
*parser
|
||||
>> fValue1
|
||||
>> fValue2;
|
||||
parser->getTokens();
|
||||
*parser >> token;
|
||||
if (token.compare("none") != 0) // gdy różne od "none"
|
||||
if (token != "none") // gdy różne od "none"
|
||||
asTrackName = token; // sprawdzane przez IsEmpty()
|
||||
parser->getTokens();
|
||||
*parser >> token;
|
||||
if (token.compare("endmemcell") != 0)
|
||||
if (token != "endmemcell")
|
||||
Error("endmemcell statement missing");
|
||||
CommandCheck();
|
||||
return true;
|
||||
@@ -139,35 +179,22 @@ void TMemCell::PutCommand(TController *Mech, vector3 *Loc)
|
||||
Mech->PutCommand(szText, fValue1, fValue2, Loc);
|
||||
}
|
||||
|
||||
bool TMemCell::Compare(char *szTestText, double fTestValue1, double fTestValue2, int CheckMask)
|
||||
bool TMemCell::Compare(char const *szTestText, double const fTestValue1, double const fTestValue2, int const CheckMask)
|
||||
{ // porównanie zawartości komórki pamięci z podanymi wartościami
|
||||
if (TestFlag(CheckMask, conditional_memstring))
|
||||
{ // porównać teksty
|
||||
/* char *pos = std::strstr(szTestText, "*"); // zwraca wskaźnik na pozycję albo NULL
|
||||
if( nullptr != pos ) { // porównanie fragmentu łańcucha
|
||||
int i = pos - szTestText; // ilość porównywanych znaków
|
||||
if( i ) { // jeśli nie jest pierwszym znakiem
|
||||
if( std::string( szTestText ).substr( 0, i ) != std::string( szText ).substr( 0, i ) ) {
|
||||
return false; // początki o długości (i) są różne
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( std::string( szTestText ) != std::string( szText ) ) {
|
||||
return false; //łąńcuchy są różne
|
||||
}
|
||||
*/ std::string
|
||||
source( szText ),
|
||||
std::string
|
||||
match( szTestText );
|
||||
auto range = match.find( '*' );
|
||||
if( range != std::string::npos ) {
|
||||
// compare string parts
|
||||
if( 0 != source.compare( 0, range, match, 0, range ) ) {
|
||||
if( 0 != szText.compare( 0, range, match, 0, range ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// compare full strings
|
||||
if( source != match ) {
|
||||
if( szText != match ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -177,6 +204,31 @@ bool TMemCell::Compare(char *szTestText, double fTestValue1, double fTestValue2,
|
||||
(!TestFlag(CheckMask, conditional_memval2) || (fValue2 == fTestValue2)));
|
||||
};
|
||||
|
||||
#ifndef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
|
||||
bool TMemCell::Compare( std::string const &szTestText, double const fTestValue1, double const fTestValue2, int const CheckMask ) {
|
||||
// porównanie zawartości komórki pamięci z podanymi wartościami
|
||||
if( TestFlag( CheckMask, conditional_memstring ) ) {
|
||||
// porównać teksty
|
||||
auto range = szTestText.find( '*' );
|
||||
if( range != std::string::npos ) {
|
||||
// compare string parts
|
||||
if( 0 != szText.compare( 0, range, szTestText, 0, range ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// compare full strings
|
||||
if( szText != szTestText ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// tekst zgodny, porównać resztę
|
||||
return ( ( !TestFlag( CheckMask, conditional_memval1 ) || ( fValue1 == fTestValue1 ) ) &&
|
||||
( !TestFlag( CheckMask, conditional_memval2 ) || ( fValue2 == fTestValue2 ) ) );
|
||||
};
|
||||
#endif
|
||||
|
||||
bool TMemCell::Render()
|
||||
{
|
||||
return true;
|
||||
|
||||
21
MemCell.h
21
MemCell.h
@@ -19,7 +19,11 @@ class TMemCell
|
||||
{
|
||||
private:
|
||||
vector3 vPosition;
|
||||
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
|
||||
char *szText;
|
||||
#else
|
||||
std::string szText;
|
||||
#endif
|
||||
double fValue1;
|
||||
double fValue2;
|
||||
TCommandType eCommand;
|
||||
@@ -29,17 +33,30 @@ class TMemCell
|
||||
string
|
||||
asTrackName; // McZapkie-100302 - zeby nazwe toru na ktory jest Putcommand wysylane pamietac
|
||||
TMemCell(vector3 *p);
|
||||
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
|
||||
~TMemCell();
|
||||
#endif
|
||||
void Init();
|
||||
void UpdateValues(char *szNewText, double fNewValue1, double fNewValue2, int CheckMask);
|
||||
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
|
||||
void UpdateValues( char const *szNewText, double const fNewValue1, double const fNewValue2, int const CheckMask );
|
||||
#else
|
||||
void UpdateValues( std::string const &szNewText, double const fNewValue1, double const fNewValue2, int const CheckMask );
|
||||
#endif
|
||||
bool Load(cParser *parser);
|
||||
void PutCommand(TController *Mech, vector3 *Loc);
|
||||
bool Compare(char *szTestText, double fTestValue1, double fTestValue2, int CheckMask);
|
||||
bool Compare( char const *szTestText, double const fTestValue1, double const fTestValue2, int const CheckMask );
|
||||
#ifndef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
|
||||
bool Compare( std::string const &szTestText, double const fTestValue1, double const fTestValue2, int const CheckMask );
|
||||
#endif
|
||||
bool Render();
|
||||
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
|
||||
inline char * Text()
|
||||
{
|
||||
return szText;
|
||||
};
|
||||
#else
|
||||
inline std::string const &Text() { return szText; }
|
||||
#endif
|
||||
inline double Value1()
|
||||
{
|
||||
return fValue1;
|
||||
|
||||
26
Track.cpp
26
Track.cpp
@@ -121,8 +121,13 @@ void TIsolated::Modify(int i, TDynamicObject *o)
|
||||
if (Global::iMultiplayer) // jeśli multiplayer
|
||||
Global::pGround->WyslijString(asName, 10); // wysłanie pakietu o zwolnieniu
|
||||
if (pMemCell) // w powiązanej komórce
|
||||
pMemCell->UpdateValues(NULL, 0, int(pMemCell->Value2()) & ~0xFF,
|
||||
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
|
||||
pMemCell->UpdateValues( NULL, 0, int( pMemCell->Value2() ) & ~0xFF,
|
||||
update_memval2); //"zerujemy" ostatnią wartość
|
||||
#else
|
||||
pMemCell->UpdateValues( "", 0, int( pMemCell->Value2() ) & ~0xFF,
|
||||
update_memval2 ); //"zerujemy" ostatnią wartość
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -135,8 +140,12 @@ void TIsolated::Modify(int i, TDynamicObject *o)
|
||||
if (Global::iMultiplayer) // jeśli multiplayer
|
||||
Global::pGround->WyslijString(asName, 11); // wysłanie pakietu o zajęciu
|
||||
if (pMemCell) // w powiązanej komórce
|
||||
pMemCell->UpdateValues(NULL, 0, int(pMemCell->Value2()) | 1,
|
||||
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
|
||||
pMemCell->UpdateValues( NULL, 0, int( pMemCell->Value2() ) | 1,
|
||||
update_memval2); // zmieniamy ostatnią wartość na nieparzystą
|
||||
#else
|
||||
pMemCell->UpdateValues( "", 0, int( pMemCell->Value2() ) | 1, update_memval2 ); // zmieniamy ostatnią wartość na nieparzystą
|
||||
#endif
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1893,7 +1902,7 @@ bool TTrack::RemoveDynamicObject(TDynamicObject *Dynamic)
|
||||
#else
|
||||
bool result = false;
|
||||
if( *Dynamics.begin() == Dynamic ) {
|
||||
// most likely the object getting removed it's at the front...
|
||||
// most likely the object getting removed is at the front...
|
||||
Dynamics.pop_front();
|
||||
result = true;
|
||||
}
|
||||
@@ -1903,12 +1912,15 @@ bool TTrack::RemoveDynamicObject(TDynamicObject *Dynamic)
|
||||
result = true;
|
||||
}
|
||||
else {
|
||||
// ... if these fail, check all objects one by one, just in case
|
||||
// TODO: check if this is ever needed, remove if it isn't.
|
||||
for( auto idx = Dynamics.begin(); idx != Dynamics.end(); ++idx ) {
|
||||
// ... if these fail, check all objects one by one
|
||||
for( auto idx = Dynamics.begin(); idx != Dynamics.end(); /*iterator advancement is inside the loop*/ ) {
|
||||
if( *idx == Dynamic ) {
|
||||
Dynamics.erase( idx );
|
||||
idx = Dynamics.erase( idx );
|
||||
result = true;
|
||||
break; // object are unique, so we can bail out here.
|
||||
}
|
||||
else {
|
||||
++idx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user