diff --git a/projects/openttd_vs100.vcxproj b/projects/openttd_vs100.vcxproj index 8d1c9058fe..c6e4ab084f 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 37c6b1559c..0aedfe549f 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 b82aba741c..04f1cc3760 100644 --- a/projects/openttd_vs140.vcxproj +++ b/projects/openttd_vs140.vcxproj @@ -671,6 +671,7 @@ + @@ -1290,6 +1291,10 @@ + + + + diff --git a/projects/openttd_vs140.vcxproj.filters b/projects/openttd_vs140.vcxproj.filters index 0b6dc573b4..0aedfe549f 100644 --- a/projects/openttd_vs140.vcxproj.filters +++ b/projects/openttd_vs140.vcxproj.filters @@ -1191,6 +1191,9 @@ Header Files + + Header Files + Header Files @@ -3048,6 +3051,18 @@ Threading + + Threading + + + Threading + + + Threading + + + Threading + diff --git a/projects/openttd_vs80.vcproj b/projects/openttd_vs80.vcproj index 5c874a0801..c1c353b595 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 7554ff3a58..80d9ad8594 100644 --- a/projects/openttd_vs90.vcproj +++ b/projects/openttd_vs90.vcproj @@ -1887,6 +1887,10 @@ RelativePath=".\..\src\sound\win32_s.h" > + + diff --git a/source.list b/source.list index 8386d82d1e..006d3c385e 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/lang/english.txt b/src/lang/english.txt index 3507e7af5a..cba3a33954 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -2396,10 +2396,20 @@ 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_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 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_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/strings.cpp b/src/strings.cpp index d2ce762b70..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 @@ -759,6 +760,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..8e70ed6d56 100644 --- a/src/tracerestrict.cpp +++ b/src/tracerestrict.cpp @@ -349,6 +349,44 @@ 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; + } + + 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(); } @@ -486,6 +524,8 @@ 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: + case TRIT_COND_PHYS_RATIO: break; default: @@ -559,8 +599,15 @@ 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: + 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: @@ -598,7 +645,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,6 +655,11 @@ void SetTraceRestrictTypeAndNormalise(TraceRestrictItem &item, TraceRestrictItem TraceRestrictTypePropertySet old_properties = GetTraceRestrictTypeProperties(item); SetTraceRestrictType(item, type); + if (IsTraceRestrictTypeAuxSubtype(type)) { + SetTraceRestrictAuxField(item, aux_data); + } else { + assert(aux_data == 0); + } TraceRestrictTypePropertySet new_properties = GetTraceRestrictTypeProperties(item); if (old_properties.cond_type != new_properties.cond_type || @@ -615,6 +667,10 @@ void SetTraceRestrictTypeAndNormalise(TraceRestrictItem &item, TraceRestrictItem SetTraceRestrictCondOp(item, TRCO_IS); SetTraceRestrictValueDefault(item, new_properties.value_type); } + 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); + } } /** @@ -752,7 +808,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) { diff --git a/src/tracerestrict.h b/src/tracerestrict.h index d838681e00..03a0b85a31 100644 --- a/src/tracerestrict.h +++ b/src/tracerestrict.h @@ -113,6 +113,8 @@ 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_PHYS_RATIO = 20, ///< Test train physical property ratio //TRIT_COND_TRAIN_OWNER = 24, ///< Test train owner: reserved for future use /* space up to 31 */ }; @@ -172,6 +174,25 @@ 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 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 */ @@ -414,6 +435,11 @@ 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 + TRVT_POWER_WEIGHT_RATIO = 16,///< takes a power / weight ratio, * 100 + TRVT_FORCE_WEIGHT_RATIO = 17,///< takes a force / weight ratio, * 100 }; /** @@ -425,7 +451,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 +506,42 @@ 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; + + 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; @@ -502,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 d1b2abd2bc..c95f7ac1e7 100644 --- a/src/tracerestrict_gui.cpp +++ b/src/tracerestrict_gui.cpp @@ -36,11 +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); - /** Widget IDs */ enum TraceRestrictWindowWidgets { TR_WIDGET_CAPTION, @@ -240,10 +238,27 @@ static StringID GetDropDownStringByValue(const TraceRestrictDropDownListSet *lis return list_set->string_array[GetDropDownListIndexByValue(list_set, value, false)]; } +typedef uint TraceRestrictGuiItemType; + +static TraceRestrictGuiItemType GetItemGuiType(TraceRestrictItem item) +{ + TraceRestrictItemType type = GetTraceRestrictType(item); + if (IsTraceRestrictTypeAuxSubtype(type)) { + return type | (GetTraceRestrictAuxField(item) << 16); + } else { + 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 +287,11 @@ 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_TRAIN_POWER_WEIGHT_RATIO, + STR_TRACE_RESTRICT_VARIABLE_TRAIN_MAX_TE_WEIGHT_RATIO, STR_TRACE_RESTRICT_VARIABLE_UNDEFINED, INVALID_STRING_ID, }; @@ -285,13 +305,18 @@ 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_PHYS_RATIO | (TRPPRCAF_POWER_WEIGHT << 16), + TRIT_COND_PHYS_RATIO | (TRPPRCAF_MAX_TE_WEIGHT << 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 +403,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 +472,11 @@ static bool IsIntegerValueType(TraceRestrictValueType type) switch (type) { case TRVT_INT: case TRVT_SPEED: + case TRVT_WEIGHT: + case TRVT_POWER: + case TRVT_FORCE: + case TRVT_POWER_WEIGHT_RATIO: + case TRVT_FORCE_WEIGHT_RATIO: return true; default: @@ -467,6 +498,36 @@ 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_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; @@ -549,7 +610,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 +755,35 @@ 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; + + 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; @@ -904,7 +994,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 +1173,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 +1736,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); 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);