diff --git a/src/lang/english.txt b/src/lang/english.txt index 059c791..eeff60f 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -4448,6 +4448,9 @@ STR_ERROR_CAN_T_STOP_SHARING_ORDER_LIST :{WHITE}Can't st STR_ERROR_CAN_T_COPY_ORDER_LIST :{WHITE}Can't copy order list... STR_ERROR_TOO_FAR_FROM_PREVIOUS_DESTINATION :{WHITE}... too far from previous destination STR_ERROR_AIRCRAFT_NOT_ENOUGH_RANGE :{WHITE}... aircraft has not enough range +#related to conditional Orders +STR_ERROR_COND_ORDER_ALWAYS_TRUE :{WHITE}Condition of conditional order is always true +STR_ERROR_COND_ORDER_ALWAYS_FALSE :{WHITE}Condition of conditional order is always false # Timetable related errors STR_ERROR_CAN_T_TIMETABLE_VEHICLE :{WHITE}Can't timetable vehicle... diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index 57b29f3..c45524d 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -28,6 +28,7 @@ #include "company_base.h" #include "order_backup.h" #include "cheat_type.h" +#include "error.h" #include "table/strings.h" @@ -1292,6 +1293,7 @@ CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 VehicleID veh = GB(p1, 0, 20); ModifyOrderFlags mof = Extract(p2); uint16 data = GB(p2, 4, 11); + bool cond_order_needs_check = false; //Should get set to true, if a conditional order is modified if (mof >= MOF_END) return CMD_ERROR; @@ -1449,8 +1451,10 @@ CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 } case MOF_COND_VARIABLE: { + cond_order_needs_check = true; order->SetConditionVariable((OrderConditionVariable)data); + OrderConditionComparator occ = order->GetConditionComparator(); switch (order->GetConditionVariable()) { case OCV_UNCONDITIONALLY: @@ -1459,6 +1463,7 @@ CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 break; case OCV_REQUIRES_SERVICE: + cond_order_needs_check = false; if (occ != OCC_IS_TRUE && occ != OCC_IS_FALSE) order->SetConditionComparator(OCC_IS_TRUE); order->SetConditionValue(0); break; @@ -1475,10 +1480,12 @@ CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 } case MOF_COND_COMPARATOR: + cond_order_needs_check = true; order->SetConditionComparator((OrderConditionComparator)data); break; case MOF_COND_VALUE: + cond_order_needs_check = true; order->SetConditionValue(data); break; @@ -1489,6 +1496,49 @@ CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 default: NOT_REACHED(); } + /* Check if a Conditional order is always true or always false */ + if (cond_order_needs_check) { + OrderConditionVariable ocvar = order->GetConditionVariable(); + /* Check True/False Conditions, we don't need to check in this case */ + if (ocvar != OCV_REQUIRES_SERVICE && ocvar !=OCV_UNCONDITIONALLY) { + OrderConditionComparator occ = order->GetConditionComparator(); + const uint16 ocval = order->GetConditionValue(); + + /* >= 0 is always true, since the value is unsigned + * <0 is always false */ + if (ocval == 0) { + switch (occ) { + case OCC_MORE_EQUALS: + ShowErrorMessage(STR_ERROR_COND_ORDER_ALWAYS_TRUE, INVALID_STRING_ID, WL_WARNING); + break; + case OCC_LESS_THAN: + ShowErrorMessage(STR_ERROR_COND_ORDER_ALWAYS_FALSE, INVALID_STRING_ID, WL_WARNING); + break; + default: + break; + } + } + + /* for Percentages, <= 100 is always true + * >100 is always false*/ + if (ocval == 100) { + switch (ocvar) { + case OCV_LOAD_PERCENTAGE: + case OCV_RELIABILITY: + if (occ == OCC_LESS_EQUALS) { + ShowErrorMessage(STR_ERROR_COND_ORDER_ALWAYS_TRUE, INVALID_STRING_ID, WL_WARNING); + } + if (occ == OCC_MORE_THAN) { + ShowErrorMessage(STR_ERROR_COND_ORDER_ALWAYS_FALSE, INVALID_STRING_ID, WL_WARNING); + } + break; + default: + break; + } + } + } + } + /* Update the windows and full load flags, also for vehicles that share the same order list */ Vehicle *u = v->FirstShared(); DeleteOrderWarnings(u);