From b5531975da4bce249b72a42c611218d0a4c249fa Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Wed, 29 Jun 2016 22:08:05 +0100 Subject: [PATCH 1/6] Add train weight, power, and max TE tracerestrict conditionals. Minor refactorings. --- src/lang/english.txt | 6 +++ src/strings.cpp | 61 ++++++++++++++++++++++++++++ src/tracerestrict.cpp | 41 ++++++++++++++++++- src/tracerestrict.h | 36 ++++++++++++++++- src/tracerestrict_gui.cpp | 84 ++++++++++++++++++++++++++++++++++----- 5 files changed, 215 insertions(+), 13 deletions(-) diff --git a/src/lang/english.txt b/src/lang/english.txt index 42193939b1..d8e1031e64 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -2396,10 +2396,16 @@ STR_TRACE_RESTRICT_VARIABLE_ENTRY_DIRECTION :entry direction STR_TRACE_RESTRICT_VARIABLE_PBS_ENTRY_SIGNAL :PBS entry signal STR_TRACE_RESTRICT_VARIABLE_PBS_ENTRY_SIGNAL_LONG :entered signal of PBS block STR_TRACE_RESTRICT_VARIABLE_TRAIN_GROUP :train group +STR_TRACE_RESTRICT_VARIABLE_TRAIN_WEIGHT :weight +STR_TRACE_RESTRICT_VARIABLE_TRAIN_POWER :power +STR_TRACE_RESTRICT_VARIABLE_TRAIN_MAX_TE :max T.E. STR_TRACE_RESTRICT_VARIABLE_UNDEFINED :undefined STR_TRACE_RESTRICT_VARIABLE_UNDEFINED_RED :{RED}undefined STR_TRACE_RESTRICT_CONDITIONAL_COMPARE_INTEGER :{STRING} {STRING} {STRING} {COMMA} then STR_TRACE_RESTRICT_CONDITIONAL_COMPARE_SPEED :{STRING} {STRING} {STRING} {VELOCITY} then +STR_TRACE_RESTRICT_CONDITIONAL_COMPARE_WEIGHT :{STRING} {STRING} {STRING} {WEIGHT_SHORT} then +STR_TRACE_RESTRICT_CONDITIONAL_COMPARE_POWER :{STRING} {STRING} {STRING} {POWER} then +STR_TRACE_RESTRICT_CONDITIONAL_COMPARE_FORCE :{STRING} {STRING} {STRING} {FORCE} then STR_TRACE_RESTRICT_CONDITIONAL_ORDER_STATION :{STRING} {STRING} {STRING} {STATION} then STR_TRACE_RESTRICT_CONDITIONAL_ORDER_WAYPOINT :{STRING} {STRING} {STRING} {WAYPOINT} then STR_TRACE_RESTRICT_CONDITIONAL_ORDER_DEPOT :{STRING} {STRING} {STRING} {DEPOT} then diff --git a/src/strings.cpp b/src/strings.cpp index d2ce762b70..d3b04b9afb 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -759,6 +759,67 @@ uint ConvertDisplaySpeedToKmhishSpeed(uint speed) { return _units_velocity[_settings_game.locale.units_velocity].c.FromDisplay(speed * 16, true, 10); } + +/** + * Convert the given internal weight to the display weight. + * @param weight the weight to convert + * @return the converted weight. + */ +uint ConvertWeightToDisplayWeight(uint weight) +{ + return _units_weight[_settings_game.locale.units_weight].c.ToDisplay(weight); +} + +/** + * Convert the given display weight to the (internal) weight. + * @param weight the weight to convert + * @return the converted weight. + */ +uint ConvertDisplayWeightToWeight(uint weight) +{ + return _units_weight[_settings_game.locale.units_weight].c.FromDisplay(weight); +} + +/** + * Convert the given internal power to the display power. + * @param power the power to convert + * @return the converted power. + */ +uint ConvertPowerToDisplayPower(uint power) +{ + return _units_power[_settings_game.locale.units_power].c.ToDisplay(power); +} + +/** + * Convert the given display power to the (internal) power. + * @param power the power to convert + * @return the converted power. + */ +uint ConvertDisplayPowerToPower(uint power) +{ + return _units_power[_settings_game.locale.units_power].c.FromDisplay(power); +} + +/** + * Convert the given internal force to the display force. + * @param force the force to convert + * @return the converted force. + */ +uint ConvertForceToDisplayForce(uint force) +{ + return _units_force[_settings_game.locale.units_force].c.ToDisplay(force); +} + +/** + * Convert the given display force to the (internal) force. + * @param force the force to convert + * @return the converted force. + */ +uint ConvertDisplayForceToForce(uint force) +{ + return _units_force[_settings_game.locale.units_force].c.FromDisplay(force); +} + /** * Parse most format codes within a string and write the result to a buffer. * @param buff The buffer to write the final string to. diff --git a/src/tracerestrict.cpp b/src/tracerestrict.cpp index 9c1396c3c4..7e439a7684 100644 --- a/src/tracerestrict.cpp +++ b/src/tracerestrict.cpp @@ -349,6 +349,27 @@ void TraceRestrictProgram::Execute(const Train* v, const TraceRestrictProgramInp break; } + case TRIT_COND_PHYS_PROP: { + switch (static_cast(GetTraceRestrictAuxField(item))) { + case TRPPCAF_WEIGHT: + result = TestCondition(v->gcache.cached_weight, condop, condvalue); + break; + + case TRPPCAF_POWER: + result = TestCondition(v->gcache.cached_power, condop, condvalue); + break; + + case TRPPCAF_MAX_TE: + result = TestCondition(v->gcache.cached_max_te / 1000, condop, condvalue); + break; + + default: + NOT_REACHED(); + break; + } + break; + } + default: NOT_REACHED(); } @@ -486,6 +507,7 @@ CommandCost TraceRestrictProgram::Validate(const std::vector case TRIT_COND_ENTRY_DIRECTION: case TRIT_COND_PBS_ENTRY_SIGNAL: case TRIT_COND_TRAIN_GROUP: + case TRIT_COND_PHYS_PROP: break; default: @@ -559,6 +581,9 @@ void SetTraceRestrictValueDefault(TraceRestrictItem &item, TraceRestrictValueTyp case TRVT_TILE_INDEX: case TRVT_RESERVE_THROUGH: case TRVT_LONG_RESERVE: + case TRVT_WEIGHT: + case TRVT_POWER: + case TRVT_FORCE: SetTraceRestrictValue(item, 0); SetTraceRestrictAuxField(item, 0); break; @@ -598,7 +623,7 @@ void SetTraceRestrictValueDefault(TraceRestrictItem &item, TraceRestrictValueTyp /** * Set the type field of a TraceRestrictItem, and resets any other fields which are no longer valid/meaningful to sensible defaults */ -void SetTraceRestrictTypeAndNormalise(TraceRestrictItem &item, TraceRestrictItemType type) +void SetTraceRestrictTypeAndNormalise(TraceRestrictItem &item, TraceRestrictItemType type, uint8 aux_data) { if (item != 0) { assert(GetTraceRestrictType(item) != TRIT_NULL); @@ -608,12 +633,26 @@ void SetTraceRestrictTypeAndNormalise(TraceRestrictItem &item, TraceRestrictItem TraceRestrictTypePropertySet old_properties = GetTraceRestrictTypeProperties(item); SetTraceRestrictType(item, type); + bool set_aux_field = false; + if (type == TRIT_COND_PHYS_PROP) { + SetTraceRestrictAuxField(item, aux_data); + set_aux_field = true; + } else { + assert(aux_data == 0); + } TraceRestrictTypePropertySet new_properties = GetTraceRestrictTypeProperties(item); if (old_properties.cond_type != new_properties.cond_type || old_properties.value_type != new_properties.value_type) { SetTraceRestrictCondOp(item, TRCO_IS); SetTraceRestrictValueDefault(item, new_properties.value_type); + if (set_aux_field) { + SetTraceRestrictAuxField(item, aux_data); + } + } + if (GetTraceRestrictType(item) == TRIT_COND_LAST_STATION && GetTraceRestrictAuxField(item) != TROCAF_STATION) { + // if changing type from another order type to last visited station, reset value if not currently a station + SetTraceRestrictValueDefault(item, TRVT_ORDER); } } diff --git a/src/tracerestrict.h b/src/tracerestrict.h index d838681e00..f6e92cd87e 100644 --- a/src/tracerestrict.h +++ b/src/tracerestrict.h @@ -113,6 +113,7 @@ enum TraceRestrictItemType { TRIT_COND_ENTRY_DIRECTION = 16, ///< Test which side of signal/signal tile is being entered from TRIT_COND_PBS_ENTRY_SIGNAL = 17, ///< Test tile and PBS-state of previous signal TRIT_COND_TRAIN_GROUP = 18, ///< Test train group membership + TRIT_COND_PHYS_PROP = 19, ///< Test train physical property //TRIT_COND_TRAIN_OWNER = 24, ///< Test train owner: reserved for future use /* space up to 31 */ }; @@ -172,6 +173,16 @@ enum TraceRestrictOrderCondAuxField { /* space up to 3 */ }; +/** + * TraceRestrictItem auxiliary type field, for physical property type conditionals + */ +enum TraceRestrictPhysPropCondAuxField { + TRPPCAF_WEIGHT = 0, ///< value field is a weight + TRPPCAF_POWER = 1, ///< value field is a power + TRPPCAF_MAX_TE = 2, ///< value field is a tractive effort + /* space up to 3 */ +}; + /** * TraceRestrictItem auxiliary type field, for order type conditionals */ @@ -414,6 +425,9 @@ enum TraceRestrictValueType { TRVT_RESERVE_THROUGH = 10,///< takes a value 0 = reserve through, 1 = cancel previous reserve through TRVT_LONG_RESERVE = 11,///< takes a value 0 = long reserve, 1 = cancel previous long reserve TRVT_GROUP_INDEX = 12,///< takes a GroupID + TRVT_WEIGHT = 13,///< takes a weight + TRVT_POWER = 14,///< takes a power + TRVT_FORCE = 15,///< takes a force }; /** @@ -425,7 +439,7 @@ struct TraceRestrictTypePropertySet { }; void SetTraceRestrictValueDefault(TraceRestrictItem &item, TraceRestrictValueType value_type); -void SetTraceRestrictTypeAndNormalise(TraceRestrictItem &item, TraceRestrictItemType type); +void SetTraceRestrictTypeAndNormalise(TraceRestrictItem &item, TraceRestrictItemType type, uint8 aux_data = 0); /** * Get TraceRestrictTypePropertySet for a given instruction, only looks at value field @@ -480,6 +494,26 @@ static inline TraceRestrictTypePropertySet GetTraceRestrictTypeProperties(TraceR out.cond_type = TRCOT_BINARY; break; + case TRIT_COND_PHYS_PROP: + switch (static_cast(GetTraceRestrictAuxField(item))) { + case TRPPCAF_WEIGHT: + out.value_type = TRVT_WEIGHT; + break; + + case TRPPCAF_POWER: + out.value_type = TRVT_POWER; + break; + + case TRPPCAF_MAX_TE: + out.value_type = TRVT_FORCE; + break; + + default: + NOT_REACHED(); + break; + } + break; + default: NOT_REACHED(); break; diff --git a/src/tracerestrict_gui.cpp b/src/tracerestrict_gui.cpp index a2629e5f4a..5e5e5e902a 100644 --- a/src/tracerestrict_gui.cpp +++ b/src/tracerestrict_gui.cpp @@ -40,6 +40,12 @@ extern uint ConvertSpeedToDisplaySpeed(uint speed); extern uint ConvertDisplaySpeedToSpeed(uint speed); +extern uint ConvertWeightToDisplayWeight(uint weight); +extern uint ConvertDisplayWeightToWeight(uint weight); +extern uint ConvertPowerToDisplayPower(uint power); +extern uint ConvertDisplayPowerToPower(uint power); +extern uint ConvertForceToDisplayForce(uint force); +extern uint ConvertDisplayForceToForce(uint force); /** Widget IDs */ enum TraceRestrictWindowWidgets { @@ -240,10 +246,26 @@ static StringID GetDropDownStringByValue(const TraceRestrictDropDownListSet *lis return list_set->string_array[GetDropDownListIndexByValue(list_set, value, false)]; } +typedef uint TraceRestrictGuiItemType; + +static TraceRestrictGuiItemType GetItemGuiType(TraceRestrictItem item) +{ + TraceRestrictGuiItemType type = GetTraceRestrictType(item); + if (type == TRIT_COND_PHYS_PROP) { + type |= GetTraceRestrictAuxField(item) << 16; + } + return type; +} + +static TraceRestrictItemType ItemTypeFromGuiType(TraceRestrictGuiItemType type) +{ + return static_cast(type & 0xFFFF); +} + /** * Return the appropriate type dropdown TraceRestrictDropDownListSet for the given item type @p type */ -static const TraceRestrictDropDownListSet *GetTypeDropDownListSet(TraceRestrictItemType type) +static const TraceRestrictDropDownListSet *GetTypeDropDownListSet(TraceRestrictGuiItemType type) { static const StringID str_action[] = { STR_TRACE_RESTRICT_PF_DENY, @@ -272,6 +294,9 @@ static const TraceRestrictDropDownListSet *GetTypeDropDownListSet(TraceRestrictI STR_TRACE_RESTRICT_VARIABLE_ENTRY_DIRECTION, STR_TRACE_RESTRICT_VARIABLE_PBS_ENTRY_SIGNAL, STR_TRACE_RESTRICT_VARIABLE_TRAIN_GROUP, + STR_TRACE_RESTRICT_VARIABLE_TRAIN_WEIGHT, + STR_TRACE_RESTRICT_VARIABLE_TRAIN_POWER, + STR_TRACE_RESTRICT_VARIABLE_TRAIN_MAX_TE, STR_TRACE_RESTRICT_VARIABLE_UNDEFINED, INVALID_STRING_ID, }; @@ -285,13 +310,16 @@ static const TraceRestrictDropDownListSet *GetTypeDropDownListSet(TraceRestrictI TRIT_COND_ENTRY_DIRECTION, TRIT_COND_PBS_ENTRY_SIGNAL, TRIT_COND_TRAIN_GROUP, + TRIT_COND_PHYS_PROP | (TRPPCAF_WEIGHT << 16), + TRIT_COND_PHYS_PROP | (TRPPCAF_POWER << 16), + TRIT_COND_PHYS_PROP | (TRPPCAF_MAX_TE << 16), TRIT_COND_UNDEFINED, }; static const TraceRestrictDropDownListSet set_cond = { str_cond, val_cond, }; - return IsTraceRestrictTypeConditional(type) ? &set_cond : &set_action; + return IsTraceRestrictTypeConditional(ItemTypeFromGuiType(type)) ? &set_cond : &set_action; } /** @@ -378,8 +406,9 @@ static StringID GetCargoStringByID(CargoID cargo) /** * Get the StringID for a given item type @p type */ -static StringID GetTypeString(TraceRestrictItemType type) +static StringID GetTypeString(TraceRestrictItem item) { + TraceRestrictGuiItemType type = GetItemGuiType(item); return GetDropDownStringByValue(GetTypeDropDownListSet(type), type); } @@ -446,6 +475,9 @@ static bool IsIntegerValueType(TraceRestrictValueType type) switch (type) { case TRVT_INT: case TRVT_SPEED: + case TRVT_WEIGHT: + case TRVT_POWER: + case TRVT_FORCE: return true; default: @@ -467,6 +499,24 @@ static uint ConvertIntegerValue(TraceRestrictValueType type, uint in, bool to_di ? ConvertSpeedToDisplaySpeed(in) * 10 / 16 : ConvertDisplaySpeedToSpeed(in) * 16 / 10; + case TRVT_WEIGHT: + return to_display + ? ConvertWeightToDisplayWeight(in) + : ConvertDisplayWeightToWeight(in); + break; + + case TRVT_POWER: + return to_display + ? ConvertPowerToDisplayPower(in) + : ConvertDisplayPowerToPower(in); + break; + + case TRVT_FORCE: + return to_display + ? ConvertForceToDisplayForce(in) + : ConvertDisplayForceToForce(in); + break; + case TRVT_PF_PENALTY: return in; @@ -549,7 +599,7 @@ static void DrawInstructionStringConditionalCommon(TraceRestrictItem item, const { assert(GetTraceRestrictCondFlags(item) <= TRCF_OR); SetDParam(0, _program_cond_type[GetTraceRestrictCondFlags(item)]); - SetDParam(1, GetTypeString(GetTraceRestrictType(item))); + SetDParam(1, GetTypeString(item)); SetDParam(2, GetDropDownStringByValue(GetCondOpDropDownListSet(properties), GetTraceRestrictCondOp(item))); } @@ -694,6 +744,21 @@ static void DrawInstructionString(const TraceRestrictProgram *prog, TraceRestric break; } + case TRVT_WEIGHT: + instruction_string = STR_TRACE_RESTRICT_CONDITIONAL_COMPARE_WEIGHT; + DrawInstructionStringConditionalIntegerCommon(item, properties); + break; + + case TRVT_POWER: + instruction_string = STR_TRACE_RESTRICT_CONDITIONAL_COMPARE_POWER; + DrawInstructionStringConditionalIntegerCommon(item, properties); + break; + + case TRVT_FORCE: + instruction_string = STR_TRACE_RESTRICT_CONDITIONAL_COMPARE_FORCE; + DrawInstructionStringConditionalIntegerCommon(item, properties); + break; + default: NOT_REACHED(); break; @@ -904,7 +969,7 @@ public: case TR_WIDGET_TYPE_COND: case TR_WIDGET_TYPE_NONCOND: { TraceRestrictItem item = this->GetSelected(); - TraceRestrictItemType type = GetTraceRestrictType(item); + TraceRestrictGuiItemType type = GetItemGuiType(item); if (type != TRIT_NULL) { this->ShowDropDownListWithValue(GetTypeDropDownListSet(type), type, false, widget, 0, 0, 0); @@ -1083,11 +1148,8 @@ public: case TR_WIDGET_TYPE_COND: case TR_WIDGET_TYPE_NONCOND: { - SetTraceRestrictTypeAndNormalise(item, static_cast(value)); - if (GetTraceRestrictType(item) == TRIT_COND_LAST_STATION && GetTraceRestrictAuxField(item) != TROCAF_STATION) { - // if changing type from another order type to last visited station, reset value if not currently a station - SetTraceRestrictValueDefault(item, TRVT_ORDER); - } + SetTraceRestrictTypeAndNormalise(item, static_cast(value & 0xFFFF), value >> 16); + TraceRestrictDoCommandP(this->tile, this->track, TRDCT_MODIFY_ITEM, this->selected_instruction - 1, item, STR_TRACE_RESTRICT_ERROR_CAN_T_MODIFY_ITEM); break; } @@ -1649,7 +1711,7 @@ private: this->EnableWidget(type_widget); this->GetWidget(type_widget)->widget_data = - GetTypeString(GetTraceRestrictType(item)); + GetTypeString(item); if (properties.cond_type == TRCOT_BINARY || properties.cond_type == TRCOT_ALL) { middle_sel->SetDisplayedPlane(DPM_COMPARATOR); From 2c6f74a982de043fc85eaa6948656ca593b07617 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Thu, 30 Jun 2016 18:28:42 +0100 Subject: [PATCH 2/6] Move header definition for unit conversion functions to own header. --- source.list | 1 + src/strings.cpp | 1 + src/tracerestrict_gui.cpp | 10 +--------- src/unit_conversion.h | 19 +++++++++++++++++++ 4 files changed, 22 insertions(+), 9 deletions(-) create mode 100644 src/unit_conversion.h diff --git a/source.list b/source.list index db128d271b..45c14de4ce 100644 --- a/source.list +++ b/source.list @@ -393,6 +393,7 @@ widget_type.h os/windows/win32.h music/win32_m.h sound/win32_s.h +unit_conversion.h video/win32_v.h window_func.h window_gui.h diff --git a/src/strings.cpp b/src/strings.cpp index d3b04b9afb..77af0a4ab8 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -34,6 +34,7 @@ #include "smallmap_gui.h" #include "window_func.h" #include "debug.h" +#include "unit_conversion.h" #include "game/game_text.hpp" #include "network/network_content_gui.h" #include diff --git a/src/tracerestrict_gui.cpp b/src/tracerestrict_gui.cpp index 5e5e5e902a..f1dce0f2e2 100644 --- a/src/tracerestrict_gui.cpp +++ b/src/tracerestrict_gui.cpp @@ -36,17 +36,9 @@ #include "cargotype.h" #include "sortlist_type.h" #include "group.h" +#include "unit_conversion.h" #include "table/sprites.h" -extern uint ConvertSpeedToDisplaySpeed(uint speed); -extern uint ConvertDisplaySpeedToSpeed(uint speed); -extern uint ConvertWeightToDisplayWeight(uint weight); -extern uint ConvertDisplayWeightToWeight(uint weight); -extern uint ConvertPowerToDisplayPower(uint power); -extern uint ConvertDisplayPowerToPower(uint power); -extern uint ConvertForceToDisplayForce(uint force); -extern uint ConvertDisplayForceToForce(uint force); - /** Widget IDs */ enum TraceRestrictWindowWidgets { TR_WIDGET_CAPTION, diff --git a/src/unit_conversion.h b/src/unit_conversion.h new file mode 100644 index 0000000000..9dadc35872 --- /dev/null +++ b/src/unit_conversion.h @@ -0,0 +1,19 @@ +/* $Id$ */ + +/* + * This file is part of OpenTTD. + * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. + * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . + */ + +/** @file unit_conversion.h Functions related to unit conversion. */ + +uint ConvertSpeedToDisplaySpeed(uint speed); +uint ConvertDisplaySpeedToSpeed(uint speed); +uint ConvertWeightToDisplayWeight(uint weight); +uint ConvertDisplayWeightToWeight(uint weight); +uint ConvertPowerToDisplayPower(uint power); +uint ConvertDisplayPowerToPower(uint power); +uint ConvertForceToDisplayForce(uint force); +uint ConvertDisplayForceToForce(uint force); From b11d48b43153cd811012f7e0b17f675cb2b63ce1 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Thu, 30 Jun 2016 18:37:39 +0100 Subject: [PATCH 3/6] Update project files --- projects/openttd_vs100.vcxproj | 1 + projects/openttd_vs100.vcxproj.filters | 3 +++ projects/openttd_vs140.vcxproj | 5 +++++ projects/openttd_vs140.vcxproj.filters | 15 +++++++++++++++ projects/openttd_vs80.vcproj | 4 ++++ projects/openttd_vs90.vcproj | 4 ++++ 6 files changed, 32 insertions(+) diff --git a/projects/openttd_vs100.vcxproj b/projects/openttd_vs100.vcxproj index 27c0897a28..ac596c3ef4 100644 --- a/projects/openttd_vs100.vcxproj +++ b/projects/openttd_vs100.vcxproj @@ -654,6 +654,7 @@ + diff --git a/projects/openttd_vs100.vcxproj.filters b/projects/openttd_vs100.vcxproj.filters index c8c74caeda..152cfa84d5 100644 --- a/projects/openttd_vs100.vcxproj.filters +++ b/projects/openttd_vs100.vcxproj.filters @@ -1191,6 +1191,9 @@ Header Files + + Header Files + Header Files diff --git a/projects/openttd_vs140.vcxproj b/projects/openttd_vs140.vcxproj index 88f7b44ddd..fa77e3f40c 100644 --- a/projects/openttd_vs140.vcxproj +++ b/projects/openttd_vs140.vcxproj @@ -671,6 +671,7 @@ + @@ -1288,6 +1289,10 @@ + + + + diff --git a/projects/openttd_vs140.vcxproj.filters b/projects/openttd_vs140.vcxproj.filters index 06800ffdaf..152cfa84d5 100644 --- a/projects/openttd_vs140.vcxproj.filters +++ b/projects/openttd_vs140.vcxproj.filters @@ -1191,6 +1191,9 @@ Header Files + + Header Files + Header Files @@ -3042,6 +3045,18 @@ Threading + + Threading + + + Threading + + + Threading + + + Threading + diff --git a/projects/openttd_vs80.vcproj b/projects/openttd_vs80.vcproj index f02bbcbd28..c1bc56ee9b 100644 --- a/projects/openttd_vs80.vcproj +++ b/projects/openttd_vs80.vcproj @@ -1890,6 +1890,10 @@ RelativePath=".\..\src\sound\win32_s.h" > + + diff --git a/projects/openttd_vs90.vcproj b/projects/openttd_vs90.vcproj index 5048012b3e..2e3d456fa8 100644 --- a/projects/openttd_vs90.vcproj +++ b/projects/openttd_vs90.vcproj @@ -1887,6 +1887,10 @@ RelativePath=".\..\src\sound\win32_s.h" > + + From 91ba8668523aa0946bdd35d0797d73d0fb5e6821 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Thu, 30 Jun 2016 18:55:26 +0100 Subject: [PATCH 4/6] Fix comment typo. --- src/tracerestrict.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tracerestrict.cpp b/src/tracerestrict.cpp index 7e439a7684..cdff1f809f 100644 --- a/src/tracerestrict.cpp +++ b/src/tracerestrict.cpp @@ -791,7 +791,7 @@ void TraceRestrictDoCommandP(TileIndex tile, Track track, TraceRestrictDoCommand } /** - * Check whether a tile/tracl pair contains a usable signal + * Check whether a tile/track pair contains a usable signal */ static CommandCost TraceRestrictCheckTileIsUsable(TileIndex tile, Track track) { From f942de699c4d6bf603fa3e05f1b93c65bba84269 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Thu, 30 Jun 2016 19:31:45 +0100 Subject: [PATCH 5/6] Add power/weight and max TE/weight ratio tracerestrict conditionals. Minor refactorings. --- src/lang/english.txt | 4 ++++ src/tracerestrict.cpp | 31 ++++++++++++++++++++++------- src/tracerestrict.h | 41 +++++++++++++++++++++++++++++++++++++++ src/tracerestrict_gui.cpp | 41 +++++++++++++++++++++++++++++++++++---- 4 files changed, 106 insertions(+), 11 deletions(-) diff --git a/src/lang/english.txt b/src/lang/english.txt index d8e1031e64..147ababafe 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -2399,6 +2399,8 @@ STR_TRACE_RESTRICT_VARIABLE_TRAIN_GROUP :train group STR_TRACE_RESTRICT_VARIABLE_TRAIN_WEIGHT :weight STR_TRACE_RESTRICT_VARIABLE_TRAIN_POWER :power STR_TRACE_RESTRICT_VARIABLE_TRAIN_MAX_TE :max T.E. +STR_TRACE_RESTRICT_VARIABLE_TRAIN_POWER_WEIGHT_RATIO :power / weight ratio +STR_TRACE_RESTRICT_VARIABLE_TRAIN_MAX_TE_WEIGHT_RATIO :max T.E. / weight ratio STR_TRACE_RESTRICT_VARIABLE_UNDEFINED :undefined STR_TRACE_RESTRICT_VARIABLE_UNDEFINED_RED :{RED}undefined STR_TRACE_RESTRICT_CONDITIONAL_COMPARE_INTEGER :{STRING} {STRING} {STRING} {COMMA} then @@ -2406,6 +2408,8 @@ STR_TRACE_RESTRICT_CONDITIONAL_COMPARE_SPEED :{STRING} {STRIN STR_TRACE_RESTRICT_CONDITIONAL_COMPARE_WEIGHT :{STRING} {STRING} {STRING} {WEIGHT_SHORT} then STR_TRACE_RESTRICT_CONDITIONAL_COMPARE_POWER :{STRING} {STRING} {STRING} {POWER} then STR_TRACE_RESTRICT_CONDITIONAL_COMPARE_FORCE :{STRING} {STRING} {STRING} {FORCE} then +STR_TRACE_RESTRICT_CONDITIONAL_COMPARE_POWER_WEIGHT_RATIO :{STRING} {STRING} {STRING} {POWER} / {STRING1} then +STR_TRACE_RESTRICT_CONDITIONAL_COMPARE_FORCE_WEIGHT_RATIO :{STRING} {STRING} {STRING} {FORCE} / {STRING1} then STR_TRACE_RESTRICT_CONDITIONAL_ORDER_STATION :{STRING} {STRING} {STRING} {STATION} then STR_TRACE_RESTRICT_CONDITIONAL_ORDER_WAYPOINT :{STRING} {STRING} {STRING} {WAYPOINT} then STR_TRACE_RESTRICT_CONDITIONAL_ORDER_DEPOT :{STRING} {STRING} {STRING} {DEPOT} then diff --git a/src/tracerestrict.cpp b/src/tracerestrict.cpp index cdff1f809f..8e70ed6d56 100644 --- a/src/tracerestrict.cpp +++ b/src/tracerestrict.cpp @@ -370,6 +370,23 @@ void TraceRestrictProgram::Execute(const Train* v, const TraceRestrictProgramInp break; } + case TRIT_COND_PHYS_RATIO: { + switch (static_cast(GetTraceRestrictAuxField(item))) { + case TRPPRCAF_POWER_WEIGHT: + result = TestCondition(min(UINT16_MAX, (100 * v->gcache.cached_power) / max(1, v->gcache.cached_weight)), condop, condvalue); + break; + + case TRPPRCAF_MAX_TE_WEIGHT: + result = TestCondition(min(UINT16_MAX, (v->gcache.cached_max_te / 10) / max(1, v->gcache.cached_weight)), condop, condvalue); + break; + + default: + NOT_REACHED(); + break; + } + break; + } + default: NOT_REACHED(); } @@ -508,6 +525,7 @@ CommandCost TraceRestrictProgram::Validate(const std::vector case TRIT_COND_PBS_ENTRY_SIGNAL: case TRIT_COND_TRAIN_GROUP: case TRIT_COND_PHYS_PROP: + case TRIT_COND_PHYS_RATIO: break; default: @@ -584,8 +602,12 @@ void SetTraceRestrictValueDefault(TraceRestrictItem &item, TraceRestrictValueTyp case TRVT_WEIGHT: case TRVT_POWER: case TRVT_FORCE: + case TRVT_POWER_WEIGHT_RATIO: + case TRVT_FORCE_WEIGHT_RATIO: SetTraceRestrictValue(item, 0); - SetTraceRestrictAuxField(item, 0); + if (!IsTraceRestrictTypeAuxSubtype(GetTraceRestrictType(item))) { + SetTraceRestrictAuxField(item, 0); + } break; case TRVT_ORDER: @@ -633,10 +655,8 @@ void SetTraceRestrictTypeAndNormalise(TraceRestrictItem &item, TraceRestrictItem TraceRestrictTypePropertySet old_properties = GetTraceRestrictTypeProperties(item); SetTraceRestrictType(item, type); - bool set_aux_field = false; - if (type == TRIT_COND_PHYS_PROP) { + if (IsTraceRestrictTypeAuxSubtype(type)) { SetTraceRestrictAuxField(item, aux_data); - set_aux_field = true; } else { assert(aux_data == 0); } @@ -646,9 +666,6 @@ void SetTraceRestrictTypeAndNormalise(TraceRestrictItem &item, TraceRestrictItem old_properties.value_type != new_properties.value_type) { SetTraceRestrictCondOp(item, TRCO_IS); SetTraceRestrictValueDefault(item, new_properties.value_type); - if (set_aux_field) { - SetTraceRestrictAuxField(item, aux_data); - } } if (GetTraceRestrictType(item) == TRIT_COND_LAST_STATION && GetTraceRestrictAuxField(item) != TROCAF_STATION) { // if changing type from another order type to last visited station, reset value if not currently a station diff --git a/src/tracerestrict.h b/src/tracerestrict.h index f6e92cd87e..03a0b85a31 100644 --- a/src/tracerestrict.h +++ b/src/tracerestrict.h @@ -114,6 +114,7 @@ enum TraceRestrictItemType { TRIT_COND_PBS_ENTRY_SIGNAL = 17, ///< Test tile and PBS-state of previous signal TRIT_COND_TRAIN_GROUP = 18, ///< Test train group membership TRIT_COND_PHYS_PROP = 19, ///< Test train physical property + TRIT_COND_PHYS_RATIO = 20, ///< Test train physical property ratio //TRIT_COND_TRAIN_OWNER = 24, ///< Test train owner: reserved for future use /* space up to 31 */ }; @@ -183,6 +184,15 @@ enum TraceRestrictPhysPropCondAuxField { /* space up to 3 */ }; +/** + * TraceRestrictItem auxiliary type field, for physical property ratio type conditionals + */ +enum TraceRestrictPhysPropRatioCondAuxField { + TRPPRCAF_POWER_WEIGHT = 0, ///< value field is a 100 * power / weight ratio + TRPPRCAF_MAX_TE_WEIGHT = 1, ///< value field is a 100 * tractive effort / weight ratio + /* space up to 3 */ +}; + /** * TraceRestrictItem auxiliary type field, for order type conditionals */ @@ -428,6 +438,8 @@ enum TraceRestrictValueType { TRVT_WEIGHT = 13,///< takes a weight TRVT_POWER = 14,///< takes a power TRVT_FORCE = 15,///< takes a force + TRVT_POWER_WEIGHT_RATIO = 16,///< takes a power / weight ratio, * 100 + TRVT_FORCE_WEIGHT_RATIO = 17,///< takes a force / weight ratio, * 100 }; /** @@ -514,6 +526,22 @@ static inline TraceRestrictTypePropertySet GetTraceRestrictTypeProperties(TraceR } break; + case TRIT_COND_PHYS_RATIO: + switch (static_cast(GetTraceRestrictAuxField(item))) { + case TRPPRCAF_POWER_WEIGHT: + out.value_type = TRVT_POWER_WEIGHT_RATIO; + break; + + case TRPPRCAF_MAX_TE_WEIGHT: + out.value_type = TRVT_FORCE_WEIGHT_RATIO; + break; + + default: + NOT_REACHED(); + break; + } + break; + default: NOT_REACHED(); break; @@ -536,6 +564,19 @@ static inline TraceRestrictTypePropertySet GetTraceRestrictTypeProperties(TraceR return out; } +/** Is the aux field for this TraceRestrictItemType used as a subtype which changes the type of the value field? */ +static inline bool IsTraceRestrictTypeAuxSubtype(TraceRestrictItemType type) +{ + switch (type) { + case TRIT_COND_PHYS_PROP: + case TRIT_COND_PHYS_RATIO: + return true; + + default: + return false; + } +} + /** Get mapping ref ID from tile and track */ static inline TraceRestrictRefId MakeTraceRestrictRefId(TileIndex t, Track track) { diff --git a/src/tracerestrict_gui.cpp b/src/tracerestrict_gui.cpp index f1dce0f2e2..f95604d279 100644 --- a/src/tracerestrict_gui.cpp +++ b/src/tracerestrict_gui.cpp @@ -242,11 +242,12 @@ typedef uint TraceRestrictGuiItemType; static TraceRestrictGuiItemType GetItemGuiType(TraceRestrictItem item) { - TraceRestrictGuiItemType type = GetTraceRestrictType(item); - if (type == TRIT_COND_PHYS_PROP) { - type |= GetTraceRestrictAuxField(item) << 16; + TraceRestrictItemType type = GetTraceRestrictType(item); + if (IsTraceRestrictTypeAuxSubtype(type)) { + return type | (GetTraceRestrictAuxField(item) << 16); + } else { + return type; } - return type; } static TraceRestrictItemType ItemTypeFromGuiType(TraceRestrictGuiItemType type) @@ -289,6 +290,8 @@ static const TraceRestrictDropDownListSet *GetTypeDropDownListSet(TraceRestrictG STR_TRACE_RESTRICT_VARIABLE_TRAIN_WEIGHT, STR_TRACE_RESTRICT_VARIABLE_TRAIN_POWER, STR_TRACE_RESTRICT_VARIABLE_TRAIN_MAX_TE, + STR_TRACE_RESTRICT_VARIABLE_TRAIN_POWER_WEIGHT_RATIO, + STR_TRACE_RESTRICT_VARIABLE_TRAIN_MAX_TE_WEIGHT_RATIO, STR_TRACE_RESTRICT_VARIABLE_UNDEFINED, INVALID_STRING_ID, }; @@ -305,6 +308,8 @@ static const TraceRestrictDropDownListSet *GetTypeDropDownListSet(TraceRestrictG TRIT_COND_PHYS_PROP | (TRPPCAF_WEIGHT << 16), TRIT_COND_PHYS_PROP | (TRPPCAF_POWER << 16), TRIT_COND_PHYS_PROP | (TRPPCAF_MAX_TE << 16), + TRIT_COND_PHYS_RATIO | (TRPPRCAF_POWER_WEIGHT << 16), + TRIT_COND_PHYS_RATIO | (TRPPRCAF_MAX_TE_WEIGHT << 16), TRIT_COND_UNDEFINED, }; static const TraceRestrictDropDownListSet set_cond = { @@ -470,6 +475,8 @@ static bool IsIntegerValueType(TraceRestrictValueType type) case TRVT_WEIGHT: case TRVT_POWER: case TRVT_FORCE: + case TRVT_POWER_WEIGHT_RATIO: + case TRVT_FORCE_WEIGHT_RATIO: return true; default: @@ -509,6 +516,18 @@ static uint ConvertIntegerValue(TraceRestrictValueType type, uint in, bool to_di : ConvertDisplayForceToForce(in); break; + case TRVT_POWER_WEIGHT_RATIO: + return to_display + ? ConvertPowerToDisplayPower(in) * 10 + : ConvertDisplayPowerToPower(in) / 10; + break; + + case TRVT_FORCE_WEIGHT_RATIO: + return to_display + ? ConvertForceToDisplayForce(in) * 10 + : ConvertDisplayForceToForce(in) / 10; + break; + case TRVT_PF_PENALTY: return in; @@ -751,6 +770,20 @@ static void DrawInstructionString(const TraceRestrictProgram *prog, TraceRestric DrawInstructionStringConditionalIntegerCommon(item, properties); break; + case TRVT_POWER_WEIGHT_RATIO: + instruction_string = STR_TRACE_RESTRICT_CONDITIONAL_COMPARE_POWER_WEIGHT_RATIO; + DrawInstructionStringConditionalIntegerCommon(item, properties); + SetDParam(4, STR_UNITS_WEIGHT_LONG_METRIC); + SetDParam(5, 100); + break; + + case TRVT_FORCE_WEIGHT_RATIO: + instruction_string = STR_TRACE_RESTRICT_CONDITIONAL_COMPARE_FORCE_WEIGHT_RATIO; + DrawInstructionStringConditionalIntegerCommon(item, properties); + SetDParam(4, STR_UNITS_WEIGHT_LONG_METRIC); + SetDParam(5, 100); + break; + default: NOT_REACHED(); break; From 71aa4c75cb1e4c889866568b7d43544531d2c69e Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Thu, 30 Jun 2016 20:17:45 +0100 Subject: [PATCH 6/6] Bump tracerestrict version due to weight/power/TE conditionals. --- src/saveload/extended_ver_sl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/saveload/extended_ver_sl.cpp b/src/saveload/extended_ver_sl.cpp index 9ea3ed0bb9..2700bc5e14 100644 --- a/src/saveload/extended_ver_sl.cpp +++ b/src/saveload/extended_ver_sl.cpp @@ -45,7 +45,7 @@ std::vector _sl_xv_discardable_chunk_ids; ///< list of chunks static const uint32 _sl_xv_slxi_chunk_version = 0; ///< current version os SLXI chunk const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = { - { XSLFI_TRACE_RESTRICT, XSCF_NULL, 5, 5, "tracerestrict", NULL, NULL, "TRRM,TRRP" }, + { XSLFI_TRACE_RESTRICT, XSCF_NULL, 6, 6, "tracerestrict", NULL, NULL, "TRRM,TRRP" }, { XSLFI_NULL, XSCF_NULL, 0, 0, NULL, NULL, NULL, NULL },// This is the end marker };