From e4502217e520a693bc000bef622d6a355f03bb00 Mon Sep 17 00:00:00 2001 From: tmj-fstate Date: Sun, 23 Feb 2020 03:44:45 +0100 Subject: [PATCH] build 200222. enhanced memory cell comparison event condition --- EvLaunch.cpp | 8 +- Event.cpp | 157 +++++++++++++++++++++++++--------------- Event.h | 17 +++-- MemCell.cpp | 50 +++++++++++-- MemCell.h | 7 +- Track.cpp | 4 +- comparison.h | 78 ++++++++++++++++++++ maszyna.vcxproj | 1 + maszyna.vcxproj.filters | 3 + simulation.cpp | 6 +- version.h | 2 +- 11 files changed, 249 insertions(+), 84 deletions(-) create mode 100644 comparison.h diff --git a/EvLaunch.cpp b/EvLaunch.cpp index fc411b30..df4119e7 100644 --- a/EvLaunch.cpp +++ b/EvLaunch.cpp @@ -112,7 +112,7 @@ bool TEventLauncher::Load(cParser *parser) *parser >> token; if (token != "*") //*=nie brać wartości 1. pod uwagę { - iCheckMask |= basic_event::flags::value_1; + iCheckMask |= basic_event::flags::value1; fVal1 = atof(token.c_str()); } else @@ -121,7 +121,7 @@ bool TEventLauncher::Load(cParser *parser) *parser >> token; if (token.compare("*") != 0) //*=nie brać wartości 2. pod uwagę { - iCheckMask |= basic_event::flags::value_2; + iCheckMask |= basic_event::flags::value2; fVal2 = atof(token.c_str()); } else @@ -314,8 +314,8 @@ TEventLauncher::export_as_text_( std::ostream &Output ) const { << "condition " << asMemCellName << ' ' << szText << ' ' - << ( ( iCheckMask & basic_event::flags::value_1 ) != 0 ? to_string( fVal1 ) : "*" ) << ' ' - << ( ( iCheckMask & basic_event::flags::value_2 ) != 0 ? to_string( fVal2 ) : "*" ) << ' '; + << ( ( iCheckMask & basic_event::flags::value1 ) != 0 ? to_string( fVal1 ) : "*" ) << ' ' + << ( ( iCheckMask & basic_event::flags::value2 ) != 0 ? to_string( fVal2 ) : "*" ) << ' '; } // footer Output diff --git a/Event.cpp b/Event.cpp index 4a4e0255..4258db4d 100644 --- a/Event.cpp +++ b/Event.cpp @@ -33,7 +33,7 @@ http://mozilla.org/MPL/2.0/. void basic_event::event_conditions::bind( basic_event::node_sequence *Nodes ) { - cells = Nodes; + memcompare_cells = Nodes; } void @@ -42,7 +42,7 @@ basic_event::event_conditions::init() { tracks.clear(); if( flags & ( flags::track_busy | flags::track_free ) ) { - for( auto &target : *cells ) { + for( auto &target : *memcompare_cells ) { tracks.emplace_back( simulation::Paths.find( std::get( target ) ) ); if( tracks.back() == nullptr ) { // legacy compatibility behaviour, instead of disabling the event we disable the memory cell comparison test @@ -63,7 +63,11 @@ basic_event::event_conditions::test() const { // if there's conditions, check them if( flags & flags::probability ) { auto const randomroll { static_cast( Random() ) }; - WriteLog( "Test: Random integer - [" + std::to_string( randomroll ) + "] / [" + std::to_string( probability ) + "]" ); + WriteLog( + "Test: Random integer - [" + + std::to_string( randomroll ) + "] / [" + std::to_string( probability ) + + "] - " + + ( randomroll > probability ? "Pass" : "Fail" ) ); if( randomroll > probability ) { return false; } @@ -82,9 +86,9 @@ basic_event::event_conditions::test() const { } } } - if( flags & ( flags::text | flags::value_1 | flags::value_2 ) ) { + if( flags & ( flags::text | flags::value1 | flags::value2 ) ) { // porównanie wartości - for( auto &cellwrapper : *cells ) { + for( auto &cellwrapper : *memcompare_cells ) { auto *cell { static_cast( std::get( cellwrapper ) ) }; if( cell == nullptr ) { // ErrorLog( "Event " + asName + " trying conditional_memcompare with nonexistent memcell" ); @@ -92,35 +96,38 @@ basic_event::event_conditions::test() const { } auto const comparisonresult = cell->Compare( - match_text, - match_value_1, - match_value_2, - flags ); + memcompare_text, memcompare_value1, memcompare_value2, + flags, + memcompare_text_operator, memcompare_value1_operator, memcompare_value2_operator, + memcompare_pass ); + + auto const combiner { ( + memcompare_pass == comparison_pass::all ? " && " : + memcompare_pass == comparison_pass::any ? " || " : + memcompare_pass == comparison_pass::none ? " !! " : + " ?? " ) }; std::string comparisonlog = "Test: MemCompare - " + cell->name() + " - "; comparisonlog += - "[" + cell->Text() + "]" - + " [" + to_string( cell->Value1(), 2 ) + "]" - + " [" + to_string( cell->Value2(), 2 ) + "]"; + ( TestFlag( flags, flags::text ) ? + "[" + cell->Text() + "] " + to_string( memcompare_text_operator ) + " [" + memcompare_text + "]" : + "[*]" ) + + combiner; - comparisonlog += ( - true == comparisonresult ? - " == " : - " != " ); + comparisonlog += + ( TestFlag( flags, flags::value1 ) ? + "[" + to_string( cell->Value1(), 2 ) + "] " + to_string( memcompare_value1_operator ) + " [" + to_string( memcompare_value1, 2 ) + "]" : + "[*]" ) + + combiner; - comparisonlog += ( - TestFlag( flags, flags::text ) ? - "[" + std::string( match_text ) + "]" : - "[*]" ); - comparisonlog += ( - TestFlag( flags, flags::value_1 ) ? - " [" + to_string( match_value_1, 2 ) + "]" : - " [*]" ); - comparisonlog += ( - TestFlag( flags, flags::value_2 ) ? - " [" + to_string( match_value_2, 2 ) + "]" : - " [*]" ); + comparisonlog += + ( TestFlag( flags, flags::value2 ) ? + "[" + to_string( cell->Value2(), 2 ) + "] " + to_string( memcompare_value2_operator ) + " [" + to_string( memcompare_value2, 2 ) + "]" : + "[*]" ) + + " - "; + + comparisonlog += ( comparisonresult ? "Pass" : "Fail" ); WriteLog( comparisonlog ); @@ -134,7 +141,8 @@ basic_event::event_conditions::test() const { } void -basic_event::event_conditions::deserialize( cParser &Input ) { // przetwarzanie warunków, wspólne dla Multiple i UpdateValues +basic_event::event_conditions::deserialize( cParser &Input ) { + // przetwarzanie warunków, wspólne dla Multiple i UpdateValues std::string token; while( ( true == Input.getTokens() ) @@ -156,20 +164,52 @@ basic_event::event_conditions::deserialize( cParser &Input ) { // przetwarzanie Input.getTokens( 1, false ); // case sensitive if( Input.peek() != "*" ) //"*" - nie brac command pod uwage { // zapamiętanie łańcucha do porównania - Input >> match_text; + Input >> memcompare_text; flags |= flags::text; } Input.getTokens(); if( Input.peek() != "*" ) //"*" - nie brac val1 pod uwage { - Input >> match_value_1; - flags |= flags::value_1; + Input >> memcompare_value1; + flags |= flags::value1; } Input.getTokens(); if( Input.peek() != "*" ) //"*" - nie brac val2 pod uwage { - Input >> match_value_2; - flags |= flags::value_2; + Input >> memcompare_value2; + flags |= flags::value2; + } + } + else if( token == "memcompareex" ) { + memcompare_pass = comparison_pass_from_string( Input.getToken() ); + Input.getTokens(); + if( Input.peek() != "*" ) //"*" - nie brac pod uwage + { // two tokens, operator followed by comparison value + std::string operatorstring; + Input >> operatorstring; + memcompare_text_operator = comparison_operator_from_string( operatorstring ); + Input.getTokens( 1, false ); // case sensitive + Input >> memcompare_text; + flags |= flags::text; + } + Input.getTokens(); + if( Input.peek() != "*" ) //"*" - nie brac val1 pod uwage + { // two tokens, operator followed by comparison value + std::string operatorstring; + Input >> operatorstring; + memcompare_value1_operator = comparison_operator_from_string( operatorstring ); + Input.getTokens(); + Input >> memcompare_value1; + flags |= flags::value1; + } + Input.getTokens(); + { // two tokens, operator followed by comparison value + std::string operatorstring; + Input >> operatorstring; + memcompare_value2_operator = comparison_operator_from_string( operatorstring ); + Input.getTokens(); + Input >> memcompare_value2; + flags |= flags::value1; } } } @@ -192,12 +232,12 @@ basic_event::event_conditions::export_as_text( std::ostream &Output ) const { << "propability " << probability << ' '; } - if( ( flags & ( flags::text | flags::value_1 | flags::value_2 ) ) != 0 ) { + if( ( flags & ( flags::text | flags::value1 | flags::value2 ) ) != 0 ) { Output << "memcompare " - << ( ( flags & flags::text ) == 0 ? "*" : match_text ) << ' ' - << ( ( flags & flags::value_1 ) == 0 ? "*" : to_string( match_value_1 ) ) << ' ' - << ( ( flags & flags::value_2 ) == 0 ? "*" : to_string( match_value_2 ) ) << ' '; + << ( ( flags & flags::text ) == 0 ? "*" : memcompare_text ) << ' ' + << ( ( flags & flags::value1 ) == 0 ? "*" : to_string( memcompare_value1 ) ) << ' ' + << ( ( flags & flags::value2 ) == 0 ? "*" : to_string( memcompare_value2 ) ) << ' '; } } } @@ -404,12 +444,12 @@ updatevalues_event::deserialize_( cParser &Input, scene::scratch_data &Scratchpa Input.getTokens(); if( Input.peek() != "*" ) { //"*" - nie brac val1 pod uwage Input >> m_input.data_value_1; - m_input.flags |= flags::value_1; + m_input.flags |= flags::value1; } Input.getTokens(); if( Input.peek() != "*" ) { //"*" - nie brac val2 pod uwage Input >> m_input.data_value_2; - m_input.flags |= flags::value_2; + m_input.flags |= flags::value2; } Input.getTokens(); // optional blocks @@ -433,8 +473,8 @@ updatevalues_event::run_() { WriteLog( "Type: " + std::string( ( m_input.flags & flags::mode_add ) ? "AddValues" : "UpdateValues" ) + " & Track command - [" + ( ( m_input.flags & flags::text ) ? m_input.data_text : "X" ) + "] [" - + ( ( m_input.flags & flags::value_1 ) ? to_string( m_input.data_value_1, 2 ) : "X" ) + "] [" - + ( ( m_input.flags & flags::value_2 ) ? to_string( m_input.data_value_2, 2 ) : "X" ) + "]" ); + + ( ( m_input.flags & flags::value1 ) ? to_string( m_input.data_value_1, 2 ) : "X" ) + "] [" + + ( ( m_input.flags & flags::value2 ) ? to_string( m_input.data_value_2, 2 ) : "X" ) + "]" ); // TODO: dump status of target cells after the operation for( auto &target : m_targets ) { auto *targetcell { static_cast( std::get( target ) ) }; @@ -460,9 +500,9 @@ void updatevalues_event::export_as_text_( std::ostream &Output ) const { Output - << ( ( m_input.flags & flags::text ) == 0 ? "*" : m_input.data_text ) << ' ' - << ( ( m_input.flags & flags::value_1 ) == 0 ? "*" : to_string( m_input.data_value_1 ) ) << ' ' - << ( ( m_input.flags & flags::value_2 ) == 0 ? "*" : to_string( m_input.data_value_2 ) ) << ' '; + << ( ( m_input.flags & flags::text ) == 0 ? "*" : m_input.data_text ) << ' ' + << ( ( m_input.flags & flags::value1 ) == 0 ? "*" : to_string( m_input.data_value_1 ) ) << ' ' + << ( ( m_input.flags & flags::value2 ) == 0 ? "*" : to_string( m_input.data_value_2 ) ) << ' '; m_conditions.export_as_text( Output ); } @@ -774,7 +814,7 @@ copyvalues_event::type() const { void copyvalues_event::deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) { - m_input.flags = ( flags::text | flags::value_1 | flags::value_2 ); // normalnie trzy + m_input.flags = ( flags::text | flags::value1 | flags::value2 ); // normalnie trzy std::string token; int paramidx { 0 }; @@ -790,7 +830,7 @@ copyvalues_event::deserialize_( cParser &Input, scene::scratch_data &Scratchpad break; } case 2: { // maska wartości - m_input.flags = stol_def( token, ( flags::text | flags::value_1 | flags::value_2 ) ); + m_input.flags = stol_def( token, ( flags::text | flags::value1 | flags::value2 ) ); break; } default: { @@ -812,8 +852,8 @@ copyvalues_event::run_() { WriteLog( "Type: CopyValues - [" + ( ( m_input.flags & flags::text ) ? m_input.data_text : "X" ) + "] [" - + ( ( m_input.flags & flags::value_1 ) ? to_string( m_input.data_value_1, 2 ) : "X" ) + "] [" - + ( ( m_input.flags & flags::value_2 ) ? to_string( m_input.data_value_2, 2 ) : "X" ) + "]" ); + + ( ( m_input.flags & flags::value1 ) ? to_string( m_input.data_value_1, 2 ) : "X" ) + "] [" + + ( ( m_input.flags & flags::value2 ) ? to_string( m_input.data_value_2, 2 ) : "X" ) + "]" ); // TODO: dump status of target cells after the operation for( auto &target : m_targets ) { auto *targetcell { static_cast( std::get( target ) ) }; @@ -843,7 +883,7 @@ copyvalues_event::export_as_text_( std::ostream &Output ) const { << ( datasource != nullptr ? datasource->name() : std::get( m_input.data_source ) ) - << ' ' << ( m_input.flags & ( flags::text | flags::value_1 | flags::value_2 ) ) << ' '; + << ' ' << ( m_input.flags & ( flags::text | flags::value1 | flags::value2 ) ) << ' '; } @@ -866,7 +906,7 @@ whois_event::type() const { void whois_event::deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) { - m_input.flags = ( flags::text | flags::value_1 | flags::value_2 ); // normalnie trzy + m_input.flags = ( flags::text | flags::value1 | flags::value2 ); // normalnie trzy std::string token; int paramidx { 0 }; @@ -878,7 +918,7 @@ whois_event::deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) { Input >> token; switch( ++paramidx ) { case 1: { // maska wartości - m_input.flags = stol_def( token, ( flags::text | flags::value_1 | flags::value_2 ) ); + m_input.flags = stol_def( token, ( flags::text | flags::value1 | flags::value2 ) ); break; } default: { @@ -923,7 +963,7 @@ whois_event::run_() { m_activator->MoverParameters->TypeName, // typ pojazdu consistbrakelevel, collisiondistance, - m_input.flags & ( flags::text | flags::value_1 | flags::value_2 ) ); + m_input.flags & ( flags::text | flags::value1 | flags::value2 ) ); WriteLog( "Type: WhoIs (" + to_string( m_input.flags ) + ") - " @@ -937,7 +977,7 @@ whois_event::run_() { m_activator->MoverParameters->LoadType.name, // nazwa ładunku m_activator->MoverParameters->LoadAmount, // aktualna ilość m_activator->MoverParameters->MaxLoad, // maksymalna ilość - m_input.flags & ( flags::text | flags::value_1 | flags::value_2 ) ); + m_input.flags & ( flags::text | flags::value1 | flags::value2 ) ); WriteLog( "Type: WhoIs (" + to_string( m_input.flags ) + ") - " @@ -952,7 +992,7 @@ whois_event::run_() { m_activator->asDestination, // adres docelowy m_activator->DirectionGet(), // kierunek pojazdu względem czoła składu (1=zgodny,-1=przeciwny) m_activator->MoverParameters->Power, // moc pojazdu silnikowego: 0 dla wagonu - m_input.flags & ( flags::text | flags::value_1 | flags::value_2 ) ); + m_input.flags & ( flags::text | flags::value1 | flags::value2 ) ); WriteLog( "Type: WhoIs (" + to_string( m_input.flags ) + ") - " @@ -984,7 +1024,7 @@ whois_event::run_() { void whois_event::export_as_text_( std::ostream &Output ) const { - Output << ( m_input.flags & ( flags::text | flags::value_1 | flags::value_2 ) ) << ' '; + Output << ( m_input.flags & ( flags::text | flags::value1 | flags::value2 ) ) << ' '; } @@ -1044,12 +1084,12 @@ logvalues_event::export_as_text_( std::ostream &Output ) const { void multi_event::init() { - auto const conditiontchecksmemcell { ( m_conditions.flags & ( flags::text | flags::value_1 | flags::value_2 ) ) != 0 }; + auto const conditiontchecksmemcell { ( m_conditions.flags & ( flags::text | flags::value1 | flags::value2 ) ) != 0 }; // not all multi-events have memory cell checks, for the ones which don't we can keep quiet about it init_targets( simulation::Memory, "memory cell", conditiontchecksmemcell ); if( m_ignored ) { // legacy compatibility behaviour, instead of disabling the event we disable the memory cell comparison test - m_conditions.flags &= ~( flags::text | flags::value_1 | flags::value_2 ); + m_conditions.flags &= ~( flags::text | flags::value1 | flags::value2 ); m_ignored = false; } // conditional data @@ -1087,7 +1127,6 @@ multi_event::deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) { // NOTE: condition block comes last so we can bail out afterwards break; } - else if( token == "else" ) { // zmiana flagi dla słowa "else" m_conditions.has_else = !m_conditions.has_else; diff --git a/Event.h b/Event.h index 06f93899..0bd3a779 100644 --- a/Event.h +++ b/Event.h @@ -13,6 +13,7 @@ http://mozilla.org/MPL/2.0/. #include "scene.h" #include "Names.h" #include "EvLaunch.h" +#include "comparison.h" // common event interface class basic_event { @@ -22,8 +23,8 @@ public: enum flags { // shared values text = 1 << 0, - value_1 = 1 << 1, - value_2 = 1 << 2, + value1 = 1 << 1, + value2 = 1 << 2, // update values mode_add = 1 << 3, // whois @@ -98,10 +99,14 @@ protected: struct event_conditions { unsigned int flags { 0 }; float probability { 0.0 }; // used by conditional_probability - double match_value_1 { 0.0 }; // used by conditional_memcompare - double match_value_2 { 0.0 }; // used by conditional_memcompare - std::string match_text; // used by conditional_memcompare - basic_event::node_sequence *cells; // used by conditional_memcompare + double memcompare_value1 { 0.0 }; // used by conditional_memcompare + double memcompare_value2 { 0.0 }; // used by conditional_memcompare + std::string memcompare_text; // used by conditional_memcompare + comparison_operator memcompare_value1_operator { comparison_operator::eq }; // used by conditional_memcompare + comparison_operator memcompare_value2_operator { comparison_operator::eq }; // used by conditional_memcompare + comparison_operator memcompare_text_operator { comparison_operator::eq }; // used by conditional_memcompare + comparison_pass memcompare_pass { comparison_pass::all }; // used by conditional_memcompare + basic_event::node_sequence *memcompare_cells; // used by conditional_memcompare std::vector tracks; // used by conditional_track bool has_else { false }; diff --git a/MemCell.cpp b/MemCell.cpp index 0fc915a8..44a26cbb 100644 --- a/MemCell.cpp +++ b/MemCell.cpp @@ -31,18 +31,18 @@ void TMemCell::UpdateValues( std::string const &szNewText, double const fNewValu { // dodawanie wartości if( TestFlag( CheckMask, basic_event::flags::text ) ) szText += szNewText; - if (TestFlag(CheckMask, basic_event::flags::value_1)) + if (TestFlag(CheckMask, basic_event::flags::value1)) fValue1 += fNewValue1; - if (TestFlag(CheckMask, basic_event::flags::value_2)) + if (TestFlag(CheckMask, basic_event::flags::value2)) fValue2 += fNewValue2; } else { if( TestFlag( CheckMask, basic_event::flags::text ) ) szText = szNewText; - if (TestFlag(CheckMask, basic_event::flags::value_1)) + if (TestFlag(CheckMask, basic_event::flags::value1)) fValue1 = fNewValue1; - if (TestFlag(CheckMask, basic_event::flags::value_2)) + if (TestFlag(CheckMask, basic_event::flags::value2)) fValue2 = fNewValue2; } if (TestFlag(CheckMask, basic_event::flags::text)) @@ -118,8 +118,11 @@ void TMemCell::PutCommand( TController *Mech, glm::dvec3 const *Loc ) const Mech->PutCommand(szText, fValue1, fValue2, Loc); } -bool TMemCell::Compare( std::string const &szTestText, double const fTestValue1, double const fTestValue2, int const CheckMask ) const { - // porównanie zawartości komórki pamięci z podanymi wartościami +bool TMemCell::Compare( std::string const &szTestText, double const fTestValue1, double const fTestValue2, int const CheckMask, + comparison_operator const TextOperator, comparison_operator const Value1Operator, comparison_operator const Value2Operator, + comparison_pass const Pass ) const { +// porównanie zawartości komórki pamięci z podanymi wartościami +/* if( TestFlag( CheckMask, basic_event::flags::text ) ) { // porównać teksty auto range = szTestText.find( '*' ); @@ -137,8 +140,39 @@ bool TMemCell::Compare( std::string const &szTestText, double const fTestValue1, } } // tekst zgodny, porównać resztę - return ( ( !TestFlag( CheckMask, basic_event::flags::value_1 ) || ( fValue1 == fTestValue1 ) ) - && ( !TestFlag( CheckMask, basic_event::flags::value_2 ) || ( fValue2 == fTestValue2 ) ) ); + return ( ( !TestFlag( CheckMask, basic_event::flags::value1 ) || ( fValue1 == fTestValue1 ) ) + && ( !TestFlag( CheckMask, basic_event::flags::value2 ) || ( fValue2 == fTestValue2 ) ) ); +*/ + bool checkpassed { false }; + bool checkfailed { false }; + + if( TestFlag( CheckMask, basic_event::flags::text ) ) { + // porównać teksty + auto range = szTestText.find( '*' ); + auto const result { ( + range == std::string::npos ? + compare( szText, szTestText, TextOperator ) : + compare( szText.substr( 0, range ), szTestText.substr( 0, range ), TextOperator ) ) }; + checkpassed |= result; + checkfailed |= ( !result ); + } + if( TestFlag( CheckMask, basic_event::flags::value1 ) ) { + auto const result { compare( fValue1, fTestValue1, TextOperator ) }; + checkpassed |= result; + checkfailed |= ( !result ); + } + if( TestFlag( CheckMask, basic_event::flags::value2 ) ) { + auto const result { compare( fValue2, fTestValue2, TextOperator ) }; + checkpassed |= result; + checkfailed |= ( !result ); + } + + switch( Pass ) { + case comparison_pass::all: { return ( checkfailed == false ); } + case comparison_pass::any: { return ( checkpassed == true ); } + case comparison_pass::none: { return ( checkpassed == false ); } + default: { return false; } + } }; bool TMemCell::IsVelocity() const diff --git a/MemCell.h b/MemCell.h index 579bf845..ce05d701 100644 --- a/MemCell.h +++ b/MemCell.h @@ -12,6 +12,7 @@ http://mozilla.org/MPL/2.0/. #include "Classes.h" #include "scenenode.h" #include "Names.h" +#include "comparison.h" class TMemCell : public scene::basic_node { @@ -26,7 +27,11 @@ public: void PutCommand( TController *Mech, glm::dvec3 const *Loc ) const; bool - Compare( std::string const &szTestText, double const fTestValue1, double const fTestValue2, int const CheckMask ) const; + Compare( std::string const &szTestText, double const fTestValue1, double const fTestValue2, int const CheckMask, + comparison_operator const TextOperator = comparison_operator::eq, + comparison_operator const Value1Operator = comparison_operator::eq, + comparison_operator const Value2Operator = comparison_operator::eq, + comparison_pass const Pass = comparison_pass::all ) const; std::string const & Text() const { return szText; } diff --git a/Track.cpp b/Track.cpp index 848bd369..4dc4e733 100644 --- a/Track.cpp +++ b/Track.cpp @@ -129,7 +129,7 @@ void TIsolated::Modify(int i, TDynamicObject *o) multiplayer::WyslijString(asName, 10); // wysłanie pakietu o zwolnieniu if (pMemCell) // w powiązanej komórce pMemCell->UpdateValues( "", 0, int( pMemCell->Value2() ) & ~0xFF, - basic_event::flags::value_2 ); //"zerujemy" ostatnią wartość + basic_event::flags::value2 ); //"zerujemy" ostatnią wartość } } else @@ -142,7 +142,7 @@ void TIsolated::Modify(int i, TDynamicObject *o) if (Global.iMultiplayer) // jeśli multiplayer multiplayer::WyslijString(asName, 11); // wysłanie pakietu o zajęciu if (pMemCell) // w powiązanej komórce - pMemCell->UpdateValues( "", 0, int( pMemCell->Value2() ) | 1, basic_event::flags::value_2 ); // zmieniamy ostatnią wartość na nieparzystą + pMemCell->UpdateValues( "", 0, int( pMemCell->Value2() ) | 1, basic_event::flags::value2 ); // zmieniamy ostatnią wartość na nieparzystą } } // pass the event to the parent diff --git a/comparison.h b/comparison.h new file mode 100644 index 00000000..b363a099 --- /dev/null +++ b/comparison.h @@ -0,0 +1,78 @@ +/* +This Source Code Form is subject to the +terms of the Mozilla Public License, v. +2.0. If a copy of the MPL was not +distributed with this file, You can +obtain one at +http://mozilla.org/MPL/2.0/. +*/ + +#pragma once + +enum class comparison_operator { + eq, // == + not_eq, // != + lt, // < + gt, // > + lt_eq, // <= + gt_eq // >= +}; + +enum class comparison_pass { + all, // && + any, // || + none // ! +}; + +template +bool compare( Type_ const Left, Type_ const Right, comparison_operator const Operator ) { + switch( Operator ) { + case comparison_operator::eq: { return Left == Right; } + case comparison_operator::not_eq: { return Left != Right; } + case comparison_operator::lt: { return Left < Right; } + case comparison_operator::gt: { return Left > Right; } + case comparison_operator::lt_eq: { return Left <= Right; } + case comparison_operator::gt_eq: { return Left >= Right; } + default: { return false; } + } +} + +inline +std::string +to_string( comparison_operator const Operator ) { + switch( Operator ) { + case comparison_operator::eq: { return "=="; } + case comparison_operator::not_eq: { return "!="; } + case comparison_operator::lt: { return "<"; } + case comparison_operator::gt: { return ">"; } + case comparison_operator::lt_eq: { return "<="; } + case comparison_operator::gt_eq: { return ">"; } + default: { return "??"; } + } +} + +inline +comparison_pass +comparison_pass_from_string( std::string const Input ) { + if( Input == "all" ) { return comparison_pass::all; } + else if( Input == "any" ) { return comparison_pass::any; } + else if( Input == "none" ) { return comparison_pass::none; } + + return comparison_pass::all; // legacy default +} + +inline +comparison_operator +comparison_operator_from_string( std::string const Input ) { + if( Input == "==" ) { return comparison_operator::eq; } + else if( Input == "!=" ) { return comparison_operator::not_eq; } + else if( Input == "<" ) { return comparison_operator::lt; } + else if( Input == ">" ) { return comparison_operator::gt; } + else if( Input == "<=" ) { return comparison_operator::lt_eq; } + else if( Input == ">=" ) { return comparison_operator::gt_eq; } + + return comparison_operator::eq; // legacy default +} + +//--------------------------------------------------------------------------- + diff --git a/maszyna.vcxproj b/maszyna.vcxproj index 57ce694a..ff54530e 100644 --- a/maszyna.vcxproj +++ b/maszyna.vcxproj @@ -358,6 +358,7 @@ + diff --git a/maszyna.vcxproj.filters b/maszyna.vcxproj.filters index 946b3115..0a713f73 100644 --- a/maszyna.vcxproj.filters +++ b/maszyna.vcxproj.filters @@ -848,6 +848,9 @@ Header Files\application\network\backend + + Header Files + diff --git a/simulation.cpp b/simulation.cpp index 8e229506..ba1a2bd4 100644 --- a/simulation.cpp +++ b/simulation.cpp @@ -153,19 +153,19 @@ state_manager::update_scripting_interface() { Global.Weather, Global.Overcast, Global.fFogEnd, - basic_event::flags::text | basic_event::flags::value_1 | basic_event::flags::value_2 ); + basic_event::flags::text | basic_event::flags::value1 | basic_event::flags::value2 ); time->UpdateValues( Global.Period, Time.data().wHour, Time.data().wMinute, - basic_event::flags::text | basic_event::flags::value_1 | basic_event::flags::value_2 ); + basic_event::flags::text | basic_event::flags::value1 | basic_event::flags::value2 ); date->UpdateValues( Global.Season, Time.year_day(), 0, - basic_event::flags::text | basic_event::flags::value_1 ); + basic_event::flags::text | basic_event::flags::value1 ); // cache cell state to detect potential script-issued changes on next cycle *m_scriptinginterface.weather = *weather; diff --git a/version.h b/version.h index fa5e2800..85e730d5 100644 --- a/version.h +++ b/version.h @@ -1,5 +1,5 @@ #pragma once #define VERSION_MAJOR 20 -#define VERSION_MINOR 129 +#define VERSION_MINOR 222 #define VERSION_REVISION 0