mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-18 00:49:19 +02:00
build 200222. enhanced memory cell comparison event condition
This commit is contained in:
@@ -112,7 +112,7 @@ bool TEventLauncher::Load(cParser *parser)
|
|||||||
*parser >> token;
|
*parser >> token;
|
||||||
if (token != "*") //*=nie brać wartości 1. pod uwagę
|
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());
|
fVal1 = atof(token.c_str());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -121,7 +121,7 @@ bool TEventLauncher::Load(cParser *parser)
|
|||||||
*parser >> token;
|
*parser >> token;
|
||||||
if (token.compare("*") != 0) //*=nie brać wartości 2. pod uwagę
|
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());
|
fVal2 = atof(token.c_str());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -314,8 +314,8 @@ TEventLauncher::export_as_text_( std::ostream &Output ) const {
|
|||||||
<< "condition "
|
<< "condition "
|
||||||
<< asMemCellName << ' '
|
<< asMemCellName << ' '
|
||||||
<< szText << ' '
|
<< szText << ' '
|
||||||
<< ( ( iCheckMask & basic_event::flags::value_1 ) != 0 ? to_string( fVal1 ) : "*" ) << ' '
|
<< ( ( iCheckMask & basic_event::flags::value1 ) != 0 ? to_string( fVal1 ) : "*" ) << ' '
|
||||||
<< ( ( iCheckMask & basic_event::flags::value_2 ) != 0 ? to_string( fVal2 ) : "*" ) << ' ';
|
<< ( ( iCheckMask & basic_event::flags::value2 ) != 0 ? to_string( fVal2 ) : "*" ) << ' ';
|
||||||
}
|
}
|
||||||
// footer
|
// footer
|
||||||
Output
|
Output
|
||||||
|
|||||||
157
Event.cpp
157
Event.cpp
@@ -33,7 +33,7 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
void
|
void
|
||||||
basic_event::event_conditions::bind( basic_event::node_sequence *Nodes ) {
|
basic_event::event_conditions::bind( basic_event::node_sequence *Nodes ) {
|
||||||
|
|
||||||
cells = Nodes;
|
memcompare_cells = Nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -42,7 +42,7 @@ basic_event::event_conditions::init() {
|
|||||||
tracks.clear();
|
tracks.clear();
|
||||||
|
|
||||||
if( flags & ( flags::track_busy | flags::track_free ) ) {
|
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<std::string>( target ) ) );
|
tracks.emplace_back( simulation::Paths.find( std::get<std::string>( target ) ) );
|
||||||
if( tracks.back() == nullptr ) {
|
if( tracks.back() == nullptr ) {
|
||||||
// legacy compatibility behaviour, instead of disabling the event we disable the memory cell comparison test
|
// 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 there's conditions, check them
|
||||||
if( flags & flags::probability ) {
|
if( flags & flags::probability ) {
|
||||||
auto const randomroll { static_cast<float>( Random() ) };
|
auto const randomroll { static_cast<float>( 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 ) {
|
if( randomroll > probability ) {
|
||||||
return false;
|
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
|
// porównanie wartości
|
||||||
for( auto &cellwrapper : *cells ) {
|
for( auto &cellwrapper : *memcompare_cells ) {
|
||||||
auto *cell { static_cast<TMemCell *>( std::get<scene::basic_node *>( cellwrapper ) ) };
|
auto *cell { static_cast<TMemCell *>( std::get<scene::basic_node *>( cellwrapper ) ) };
|
||||||
if( cell == nullptr ) {
|
if( cell == nullptr ) {
|
||||||
// ErrorLog( "Event " + asName + " trying conditional_memcompare with nonexistent memcell" );
|
// ErrorLog( "Event " + asName + " trying conditional_memcompare with nonexistent memcell" );
|
||||||
@@ -92,35 +96,38 @@ basic_event::event_conditions::test() const {
|
|||||||
}
|
}
|
||||||
auto const comparisonresult =
|
auto const comparisonresult =
|
||||||
cell->Compare(
|
cell->Compare(
|
||||||
match_text,
|
memcompare_text, memcompare_value1, memcompare_value2,
|
||||||
match_value_1,
|
flags,
|
||||||
match_value_2,
|
memcompare_text_operator, memcompare_value1_operator, memcompare_value2_operator,
|
||||||
flags );
|
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() + " - ";
|
std::string comparisonlog = "Test: MemCompare - " + cell->name() + " - ";
|
||||||
|
|
||||||
comparisonlog +=
|
comparisonlog +=
|
||||||
"[" + cell->Text() + "]"
|
( TestFlag( flags, flags::text ) ?
|
||||||
+ " [" + to_string( cell->Value1(), 2 ) + "]"
|
"[" + cell->Text() + "] " + to_string( memcompare_text_operator ) + " [" + memcompare_text + "]" :
|
||||||
+ " [" + to_string( cell->Value2(), 2 ) + "]";
|
"[*]" )
|
||||||
|
+ combiner;
|
||||||
|
|
||||||
comparisonlog += (
|
comparisonlog +=
|
||||||
true == comparisonresult ?
|
( TestFlag( flags, flags::value1 ) ?
|
||||||
" == " :
|
"[" + to_string( cell->Value1(), 2 ) + "] " + to_string( memcompare_value1_operator ) + " [" + to_string( memcompare_value1, 2 ) + "]" :
|
||||||
" != " );
|
"[*]" )
|
||||||
|
+ combiner;
|
||||||
|
|
||||||
comparisonlog += (
|
comparisonlog +=
|
||||||
TestFlag( flags, flags::text ) ?
|
( TestFlag( flags, flags::value2 ) ?
|
||||||
"[" + std::string( match_text ) + "]" :
|
"[" + to_string( cell->Value2(), 2 ) + "] " + to_string( memcompare_value2_operator ) + " [" + to_string( memcompare_value2, 2 ) + "]" :
|
||||||
"[*]" );
|
"[*]" )
|
||||||
comparisonlog += (
|
+ " - ";
|
||||||
TestFlag( flags, flags::value_1 ) ?
|
|
||||||
" [" + to_string( match_value_1, 2 ) + "]" :
|
comparisonlog += ( comparisonresult ? "Pass" : "Fail" );
|
||||||
" [*]" );
|
|
||||||
comparisonlog += (
|
|
||||||
TestFlag( flags, flags::value_2 ) ?
|
|
||||||
" [" + to_string( match_value_2, 2 ) + "]" :
|
|
||||||
" [*]" );
|
|
||||||
|
|
||||||
WriteLog( comparisonlog );
|
WriteLog( comparisonlog );
|
||||||
|
|
||||||
@@ -134,7 +141,8 @@ basic_event::event_conditions::test() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
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;
|
std::string token;
|
||||||
while( ( true == Input.getTokens() )
|
while( ( true == Input.getTokens() )
|
||||||
@@ -156,20 +164,52 @@ basic_event::event_conditions::deserialize( cParser &Input ) { // przetwarzanie
|
|||||||
Input.getTokens( 1, false ); // case sensitive
|
Input.getTokens( 1, false ); // case sensitive
|
||||||
if( Input.peek() != "*" ) //"*" - nie brac command pod uwage
|
if( Input.peek() != "*" ) //"*" - nie brac command pod uwage
|
||||||
{ // zapamiętanie łańcucha do porównania
|
{ // zapamiętanie łańcucha do porównania
|
||||||
Input >> match_text;
|
Input >> memcompare_text;
|
||||||
flags |= flags::text;
|
flags |= flags::text;
|
||||||
}
|
}
|
||||||
Input.getTokens();
|
Input.getTokens();
|
||||||
if( Input.peek() != "*" ) //"*" - nie brac val1 pod uwage
|
if( Input.peek() != "*" ) //"*" - nie brac val1 pod uwage
|
||||||
{
|
{
|
||||||
Input >> match_value_1;
|
Input >> memcompare_value1;
|
||||||
flags |= flags::value_1;
|
flags |= flags::value1;
|
||||||
}
|
}
|
||||||
Input.getTokens();
|
Input.getTokens();
|
||||||
if( Input.peek() != "*" ) //"*" - nie brac val2 pod uwage
|
if( Input.peek() != "*" ) //"*" - nie brac val2 pod uwage
|
||||||
{
|
{
|
||||||
Input >> match_value_2;
|
Input >> memcompare_value2;
|
||||||
flags |= flags::value_2;
|
flags |= flags::value2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if( token == "memcompareex" ) {
|
||||||
|
memcompare_pass = comparison_pass_from_string( Input.getToken<std::string>() );
|
||||||
|
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 "
|
<< "propability "
|
||||||
<< probability << ' ';
|
<< probability << ' ';
|
||||||
}
|
}
|
||||||
if( ( flags & ( flags::text | flags::value_1 | flags::value_2 ) ) != 0 ) {
|
if( ( flags & ( flags::text | flags::value1 | flags::value2 ) ) != 0 ) {
|
||||||
Output
|
Output
|
||||||
<< "memcompare "
|
<< "memcompare "
|
||||||
<< ( ( flags & flags::text ) == 0 ? "*" : match_text ) << ' '
|
<< ( ( flags & flags::text ) == 0 ? "*" : memcompare_text ) << ' '
|
||||||
<< ( ( flags & flags::value_1 ) == 0 ? "*" : to_string( match_value_1 ) ) << ' '
|
<< ( ( flags & flags::value1 ) == 0 ? "*" : to_string( memcompare_value1 ) ) << ' '
|
||||||
<< ( ( flags & flags::value_2 ) == 0 ? "*" : to_string( match_value_2 ) ) << ' ';
|
<< ( ( flags & flags::value2 ) == 0 ? "*" : to_string( memcompare_value2 ) ) << ' ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -404,12 +444,12 @@ updatevalues_event::deserialize_( cParser &Input, scene::scratch_data &Scratchpa
|
|||||||
Input.getTokens();
|
Input.getTokens();
|
||||||
if( Input.peek() != "*" ) { //"*" - nie brac val1 pod uwage
|
if( Input.peek() != "*" ) { //"*" - nie brac val1 pod uwage
|
||||||
Input >> m_input.data_value_1;
|
Input >> m_input.data_value_1;
|
||||||
m_input.flags |= flags::value_1;
|
m_input.flags |= flags::value1;
|
||||||
}
|
}
|
||||||
Input.getTokens();
|
Input.getTokens();
|
||||||
if( Input.peek() != "*" ) { //"*" - nie brac val2 pod uwage
|
if( Input.peek() != "*" ) { //"*" - nie brac val2 pod uwage
|
||||||
Input >> m_input.data_value_2;
|
Input >> m_input.data_value_2;
|
||||||
m_input.flags |= flags::value_2;
|
m_input.flags |= flags::value2;
|
||||||
}
|
}
|
||||||
Input.getTokens();
|
Input.getTokens();
|
||||||
// optional blocks
|
// optional blocks
|
||||||
@@ -433,8 +473,8 @@ updatevalues_event::run_() {
|
|||||||
|
|
||||||
WriteLog( "Type: " + std::string( ( m_input.flags & flags::mode_add ) ? "AddValues" : "UpdateValues" ) + " & Track command - ["
|
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::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::value1 ) ? 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::value2 ) ? to_string( m_input.data_value_2, 2 ) : "X" ) + "]" );
|
||||||
// TODO: dump status of target cells after the operation
|
// TODO: dump status of target cells after the operation
|
||||||
for( auto &target : m_targets ) {
|
for( auto &target : m_targets ) {
|
||||||
auto *targetcell { static_cast<TMemCell *>( std::get<scene::basic_node *>( target ) ) };
|
auto *targetcell { static_cast<TMemCell *>( std::get<scene::basic_node *>( target ) ) };
|
||||||
@@ -460,9 +500,9 @@ void
|
|||||||
updatevalues_event::export_as_text_( std::ostream &Output ) const {
|
updatevalues_event::export_as_text_( std::ostream &Output ) const {
|
||||||
|
|
||||||
Output
|
Output
|
||||||
<< ( ( m_input.flags & flags::text ) == 0 ? "*" : m_input.data_text ) << ' '
|
<< ( ( 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::value1 ) == 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::value2 ) == 0 ? "*" : to_string( m_input.data_value_2 ) ) << ' ';
|
||||||
|
|
||||||
m_conditions.export_as_text( Output );
|
m_conditions.export_as_text( Output );
|
||||||
}
|
}
|
||||||
@@ -774,7 +814,7 @@ copyvalues_event::type() const {
|
|||||||
void
|
void
|
||||||
copyvalues_event::deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) {
|
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;
|
std::string token;
|
||||||
int paramidx { 0 };
|
int paramidx { 0 };
|
||||||
@@ -790,7 +830,7 @@ copyvalues_event::deserialize_( cParser &Input, scene::scratch_data &Scratchpad
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 2: { // maska wartości
|
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;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
@@ -812,8 +852,8 @@ copyvalues_event::run_() {
|
|||||||
|
|
||||||
WriteLog( "Type: CopyValues - ["
|
WriteLog( "Type: CopyValues - ["
|
||||||
+ ( ( m_input.flags & flags::text ) ? m_input.data_text : "X" ) + "] ["
|
+ ( ( 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::value1 ) ? 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::value2 ) ? to_string( m_input.data_value_2, 2 ) : "X" ) + "]" );
|
||||||
// TODO: dump status of target cells after the operation
|
// TODO: dump status of target cells after the operation
|
||||||
for( auto &target : m_targets ) {
|
for( auto &target : m_targets ) {
|
||||||
auto *targetcell { static_cast<TMemCell *>( std::get<scene::basic_node *>( target ) ) };
|
auto *targetcell { static_cast<TMemCell *>( std::get<scene::basic_node *>( target ) ) };
|
||||||
@@ -843,7 +883,7 @@ copyvalues_event::export_as_text_( std::ostream &Output ) const {
|
|||||||
<< ( datasource != nullptr ?
|
<< ( datasource != nullptr ?
|
||||||
datasource->name() :
|
datasource->name() :
|
||||||
std::get<std::string>( m_input.data_source ) )
|
std::get<std::string>( 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
|
void
|
||||||
whois_event::deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) {
|
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;
|
std::string token;
|
||||||
int paramidx { 0 };
|
int paramidx { 0 };
|
||||||
@@ -878,7 +918,7 @@ whois_event::deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) {
|
|||||||
Input >> token;
|
Input >> token;
|
||||||
switch( ++paramidx ) {
|
switch( ++paramidx ) {
|
||||||
case 1: { // maska wartości
|
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;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
@@ -923,7 +963,7 @@ whois_event::run_() {
|
|||||||
m_activator->MoverParameters->TypeName, // typ pojazdu
|
m_activator->MoverParameters->TypeName, // typ pojazdu
|
||||||
consistbrakelevel,
|
consistbrakelevel,
|
||||||
collisiondistance,
|
collisiondistance,
|
||||||
m_input.flags & ( flags::text | flags::value_1 | flags::value_2 ) );
|
m_input.flags & ( flags::text | flags::value1 | flags::value2 ) );
|
||||||
|
|
||||||
WriteLog(
|
WriteLog(
|
||||||
"Type: WhoIs (" + to_string( m_input.flags ) + ") - "
|
"Type: WhoIs (" + to_string( m_input.flags ) + ") - "
|
||||||
@@ -937,7 +977,7 @@ whois_event::run_() {
|
|||||||
m_activator->MoverParameters->LoadType.name, // nazwa ładunku
|
m_activator->MoverParameters->LoadType.name, // nazwa ładunku
|
||||||
m_activator->MoverParameters->LoadAmount, // aktualna ilość
|
m_activator->MoverParameters->LoadAmount, // aktualna ilość
|
||||||
m_activator->MoverParameters->MaxLoad, // maksymalna 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(
|
WriteLog(
|
||||||
"Type: WhoIs (" + to_string( m_input.flags ) + ") - "
|
"Type: WhoIs (" + to_string( m_input.flags ) + ") - "
|
||||||
@@ -952,7 +992,7 @@ whois_event::run_() {
|
|||||||
m_activator->asDestination, // adres docelowy
|
m_activator->asDestination, // adres docelowy
|
||||||
m_activator->DirectionGet(), // kierunek pojazdu względem czoła składu (1=zgodny,-1=przeciwny)
|
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_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(
|
WriteLog(
|
||||||
"Type: WhoIs (" + to_string( m_input.flags ) + ") - "
|
"Type: WhoIs (" + to_string( m_input.flags ) + ") - "
|
||||||
@@ -984,7 +1024,7 @@ whois_event::run_() {
|
|||||||
void
|
void
|
||||||
whois_event::export_as_text_( std::ostream &Output ) const {
|
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
|
void
|
||||||
multi_event::init() {
|
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
|
// 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 );
|
init_targets( simulation::Memory, "memory cell", conditiontchecksmemcell );
|
||||||
if( m_ignored ) {
|
if( m_ignored ) {
|
||||||
// legacy compatibility behaviour, instead of disabling the event we disable the memory cell comparison test
|
// 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;
|
m_ignored = false;
|
||||||
}
|
}
|
||||||
// conditional data
|
// 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
|
// NOTE: condition block comes last so we can bail out afterwards
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if( token == "else" ) {
|
else if( token == "else" ) {
|
||||||
// zmiana flagi dla słowa "else"
|
// zmiana flagi dla słowa "else"
|
||||||
m_conditions.has_else = !m_conditions.has_else;
|
m_conditions.has_else = !m_conditions.has_else;
|
||||||
|
|||||||
17
Event.h
17
Event.h
@@ -13,6 +13,7 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
#include "scene.h"
|
#include "scene.h"
|
||||||
#include "Names.h"
|
#include "Names.h"
|
||||||
#include "EvLaunch.h"
|
#include "EvLaunch.h"
|
||||||
|
#include "comparison.h"
|
||||||
|
|
||||||
// common event interface
|
// common event interface
|
||||||
class basic_event {
|
class basic_event {
|
||||||
@@ -22,8 +23,8 @@ public:
|
|||||||
enum flags {
|
enum flags {
|
||||||
// shared values
|
// shared values
|
||||||
text = 1 << 0,
|
text = 1 << 0,
|
||||||
value_1 = 1 << 1,
|
value1 = 1 << 1,
|
||||||
value_2 = 1 << 2,
|
value2 = 1 << 2,
|
||||||
// update values
|
// update values
|
||||||
mode_add = 1 << 3,
|
mode_add = 1 << 3,
|
||||||
// whois
|
// whois
|
||||||
@@ -98,10 +99,14 @@ protected:
|
|||||||
struct event_conditions {
|
struct event_conditions {
|
||||||
unsigned int flags { 0 };
|
unsigned int flags { 0 };
|
||||||
float probability { 0.0 }; // used by conditional_probability
|
float probability { 0.0 }; // used by conditional_probability
|
||||||
double match_value_1 { 0.0 }; // used by conditional_memcompare
|
double memcompare_value1 { 0.0 }; // used by conditional_memcompare
|
||||||
double match_value_2 { 0.0 }; // used by conditional_memcompare
|
double memcompare_value2 { 0.0 }; // used by conditional_memcompare
|
||||||
std::string match_text; // used by conditional_memcompare
|
std::string memcompare_text; // used by conditional_memcompare
|
||||||
basic_event::node_sequence *cells; // 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<TTrack *> tracks; // used by conditional_track
|
std::vector<TTrack *> tracks; // used by conditional_track
|
||||||
bool has_else { false };
|
bool has_else { false };
|
||||||
|
|
||||||
|
|||||||
50
MemCell.cpp
50
MemCell.cpp
@@ -31,18 +31,18 @@ void TMemCell::UpdateValues( std::string const &szNewText, double const fNewValu
|
|||||||
{ // dodawanie wartości
|
{ // dodawanie wartości
|
||||||
if( TestFlag( CheckMask, basic_event::flags::text ) )
|
if( TestFlag( CheckMask, basic_event::flags::text ) )
|
||||||
szText += szNewText;
|
szText += szNewText;
|
||||||
if (TestFlag(CheckMask, basic_event::flags::value_1))
|
if (TestFlag(CheckMask, basic_event::flags::value1))
|
||||||
fValue1 += fNewValue1;
|
fValue1 += fNewValue1;
|
||||||
if (TestFlag(CheckMask, basic_event::flags::value_2))
|
if (TestFlag(CheckMask, basic_event::flags::value2))
|
||||||
fValue2 += fNewValue2;
|
fValue2 += fNewValue2;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( TestFlag( CheckMask, basic_event::flags::text ) )
|
if( TestFlag( CheckMask, basic_event::flags::text ) )
|
||||||
szText = szNewText;
|
szText = szNewText;
|
||||||
if (TestFlag(CheckMask, basic_event::flags::value_1))
|
if (TestFlag(CheckMask, basic_event::flags::value1))
|
||||||
fValue1 = fNewValue1;
|
fValue1 = fNewValue1;
|
||||||
if (TestFlag(CheckMask, basic_event::flags::value_2))
|
if (TestFlag(CheckMask, basic_event::flags::value2))
|
||||||
fValue2 = fNewValue2;
|
fValue2 = fNewValue2;
|
||||||
}
|
}
|
||||||
if (TestFlag(CheckMask, basic_event::flags::text))
|
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);
|
Mech->PutCommand(szText, fValue1, fValue2, Loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TMemCell::Compare( std::string const &szTestText, double const fTestValue1, double const fTestValue2, int const CheckMask ) const {
|
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
|
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 ) ) {
|
if( TestFlag( CheckMask, basic_event::flags::text ) ) {
|
||||||
// porównać teksty
|
// porównać teksty
|
||||||
auto range = szTestText.find( '*' );
|
auto range = szTestText.find( '*' );
|
||||||
@@ -137,8 +140,39 @@ bool TMemCell::Compare( std::string const &szTestText, double const fTestValue1,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// tekst zgodny, porównać resztę
|
// tekst zgodny, porównać resztę
|
||||||
return ( ( !TestFlag( CheckMask, basic_event::flags::value_1 ) || ( fValue1 == fTestValue1 ) )
|
return ( ( !TestFlag( CheckMask, basic_event::flags::value1 ) || ( fValue1 == fTestValue1 ) )
|
||||||
&& ( !TestFlag( CheckMask, basic_event::flags::value_2 ) || ( fValue2 == fTestValue2 ) ) );
|
&& ( !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
|
bool TMemCell::IsVelocity() const
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
#include "Classes.h"
|
#include "Classes.h"
|
||||||
#include "scenenode.h"
|
#include "scenenode.h"
|
||||||
#include "Names.h"
|
#include "Names.h"
|
||||||
|
#include "comparison.h"
|
||||||
|
|
||||||
class TMemCell : public scene::basic_node {
|
class TMemCell : public scene::basic_node {
|
||||||
|
|
||||||
@@ -26,7 +27,11 @@ public:
|
|||||||
void
|
void
|
||||||
PutCommand( TController *Mech, glm::dvec3 const *Loc ) const;
|
PutCommand( TController *Mech, glm::dvec3 const *Loc ) const;
|
||||||
bool
|
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 &
|
std::string const &
|
||||||
Text() const {
|
Text() const {
|
||||||
return szText; }
|
return szText; }
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ void TIsolated::Modify(int i, TDynamicObject *o)
|
|||||||
multiplayer::WyslijString(asName, 10); // wysłanie pakietu o zwolnieniu
|
multiplayer::WyslijString(asName, 10); // wysłanie pakietu o zwolnieniu
|
||||||
if (pMemCell) // w powiązanej komórce
|
if (pMemCell) // w powiązanej komórce
|
||||||
pMemCell->UpdateValues( "", 0, int( pMemCell->Value2() ) & ~0xFF,
|
pMemCell->UpdateValues( "", 0, int( pMemCell->Value2() ) & ~0xFF,
|
||||||
basic_event::flags::value_2 ); //"zerujemy" ostatnią wartość
|
basic_event::flags::value2 ); //"zerujemy" ostatnią wartość
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -142,7 +142,7 @@ void TIsolated::Modify(int i, TDynamicObject *o)
|
|||||||
if (Global.iMultiplayer) // jeśli multiplayer
|
if (Global.iMultiplayer) // jeśli multiplayer
|
||||||
multiplayer::WyslijString(asName, 11); // wysłanie pakietu o zajęciu
|
multiplayer::WyslijString(asName, 11); // wysłanie pakietu o zajęciu
|
||||||
if (pMemCell) // w powiązanej komórce
|
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
|
// pass the event to the parent
|
||||||
|
|||||||
78
comparison.h
Normal file
78
comparison.h
Normal file
@@ -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 <typename Type_>
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -358,6 +358,7 @@
|
|||||||
<ClInclude Include="Classes.h" />
|
<ClInclude Include="Classes.h" />
|
||||||
<ClInclude Include="color.h" />
|
<ClInclude Include="color.h" />
|
||||||
<ClInclude Include="command.h" />
|
<ClInclude Include="command.h" />
|
||||||
|
<ClInclude Include="comparison.h" />
|
||||||
<ClInclude Include="Console.h" />
|
<ClInclude Include="Console.h" />
|
||||||
<ClInclude Include="Console\LPT.h" />
|
<ClInclude Include="Console\LPT.h" />
|
||||||
<ClInclude Include="Console\PoKeys55.h" />
|
<ClInclude Include="Console\PoKeys55.h" />
|
||||||
|
|||||||
@@ -848,6 +848,9 @@
|
|||||||
<ClInclude Include="network\backend\asio.h">
|
<ClInclude Include="network\backend\asio.h">
|
||||||
<Filter>Header Files\application\network\backend</Filter>
|
<Filter>Header Files\application\network\backend</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="comparison.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ResourceCompile Include="maszyna.rc">
|
<ResourceCompile Include="maszyna.rc">
|
||||||
|
|||||||
@@ -153,19 +153,19 @@ state_manager::update_scripting_interface() {
|
|||||||
Global.Weather,
|
Global.Weather,
|
||||||
Global.Overcast,
|
Global.Overcast,
|
||||||
Global.fFogEnd,
|
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(
|
time->UpdateValues(
|
||||||
Global.Period,
|
Global.Period,
|
||||||
Time.data().wHour,
|
Time.data().wHour,
|
||||||
Time.data().wMinute,
|
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(
|
date->UpdateValues(
|
||||||
Global.Season,
|
Global.Season,
|
||||||
Time.year_day(),
|
Time.year_day(),
|
||||||
0,
|
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
|
// cache cell state to detect potential script-issued changes on next cycle
|
||||||
*m_scriptinginterface.weather = *weather;
|
*m_scriptinginterface.weather = *weather;
|
||||||
|
|||||||
Reference in New Issue
Block a user