diff --git a/src/lang/english.txt b/src/lang/english.txt index d4302e4ac2..db48890f2f 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -3494,6 +3494,18 @@ STR_ORDER_CONDITIONAL_AGE :Age (years) STR_ORDER_CONDITIONAL_REQUIRES_SERVICE :Requires service STR_ORDER_CONDITIONAL_UNCONDITIONALLY :Always STR_ORDER_CONDITIONAL_REMAINING_LIFETIME :Remaining lifetime (years) +STR_ORDER_CONDITIONAL_CARGO_WAITING :Waiting cargo +STR_ORDER_CONDITIONAL_ACCEPTANCE_DROPDOWN :Accepted cargo +STR_ORDER_CONDITIONAL_FREE_PLATFORMS :Free platforms +STR_ORDER_CONDITIONAL_PERCENT :Percent of times + +STR_ORDER_CONDITIONAL_REQUIRES_SERVICE_ORDER :Requires service {STRING} +STR_ORDER_CONDITIONAL_CARGO_WAITING_ORDER :Next station {STRING} {STRING} waiting +STR_ORDER_CONDITIONAL_ACCEPTANCE :Next station {STRING} {STRING} +STR_CONDITIONAL_FREE_PLATFORMS :Jump to order {COMMA} when Next station {STRING} {COMMA} free platform{P "" s} +STR_CONDITIONAL_PERCENT :Jump to order {COMMA} {COMMA} percent of times + +STR_ORDER_CONDITIONAL_NEXT_STATION :Next station STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP :{BLACK}How to compare the vehicle data to the given value STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS :is equal to @@ -3506,8 +3518,18 @@ STR_ORDER_CONDITIONAL_COMPARATOR_IS_TRUE :is true STR_ORDER_CONDITIONAL_COMPARATOR_IS_FALSE :is false STR_ORDER_CONDITIONAL_VALUE_TOOLTIP :{BLACK}The value to compare the vehicle data against +STR_ORDER_CONDITIONAL_CARGO_TOOLTIP :{BLACK}The cargo to compare the station data against STR_ORDER_CONDITIONAL_VALUE_CAPT :{WHITE}Enter value to compare against +STR_ORDER_CONDITIONAL_COMPARATOR_ACCEPTS :accepts +STR_ORDER_CONDITIONAL_COMPARATOR_DOES_NOT_ACCEPT :does not accept +STR_ORDER_CONDITIONAL_COMPARATOR_HAS :has +STR_ORDER_CONDITIONAL_COMPARATOR_HAS_NO :does not have +STR_ORDER_CONDITIONAL_COMPARATOR_HAS_LESS_THAN :has less than +STR_ORDER_CONDITIONAL_COMPARATOR_HAS_LESS_EQUALS :has less than or exactly +STR_ORDER_CONDITIONAL_COMPARATOR_HAS_MORE_THAN :has more than +STR_ORDER_CONDITIONAL_COMPARATOR_HAS_MORE_EQUALS :has more than or exactly + STR_ORDERS_SKIP_BUTTON :{BLACK}Skip STR_ORDERS_SKIP_TOOLTIP :{BLACK}Skip the current order, and start the next. Ctrl+Click skips to the selected order @@ -3588,6 +3610,7 @@ STR_ORDER_OUT_OF_RANGE :{RED} (Next des STR_ORDER_CONDITIONAL_UNCONDITIONAL :Jump to order {COMMA} STR_ORDER_CONDITIONAL_NUM :Jump to order {COMMA} when {STRING} {STRING} {COMMA} +STR_ORDER_CONDITIONAL_CARGO :Jump to order {COMMA} when {STRING} {STRING} {STRING} STR_ORDER_CONDITIONAL_TRUE_FALSE :Jump to order {COMMA} when {STRING} {STRING} STR_INVALID_ORDER :{RED} (Invalid Order) diff --git a/src/lang/russian.txt b/src/lang/russian.txt index 1937458390..4717353183 100644 --- a/src/lang/russian.txt +++ b/src/lang/russian.txt @@ -3685,10 +3685,19 @@ STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE :Процент STR_ORDER_CONDITIONAL_RELIABILITY :Надёжность STR_ORDER_CONDITIONAL_MAX_SPEED :Макс. скорость STR_ORDER_CONDITIONAL_AGE :Возраст (лет) -STR_ORDER_CONDITIONAL_REQUIRES_SERVICE :Требуется обслуживание +STR_ORDER_CONDITIONAL_REQUIRES_SERVICE :Требуется обслуживание {STRING} STR_ORDER_CONDITIONAL_UNCONDITIONALLY :Всегда STR_ORDER_CONDITIONAL_REMAINING_LIFETIME :Оставшийся срок службы (лет) +STR_ORDER_CONDITIONAL_CARGO_WAITING :Следующая станция {STRING} {STRING} для погрузки +STR_ORDER_CONDITIONAL_ACCEPTANCE :Следующая станция {STRING} {STRING} +STR_ORDER_CONDITIONAL_PERCENT :Процентов времени +STR_ORDER_CONDITIONAL_FREE_PLATFORMS :Свободные платформы +STR_ORDER_CONDITIONAL_REQUIRES_SERVICE_DROPDOWN :Требует обслуживания +STR_ORDER_CONDITIONAL_CARGO_WAITING_DROPDOWN :Ожидает +STR_ORDER_CONDITIONAL_ACCEPTANCE_DROPDOWN :Принимает +STR_ORDER_CONDITIONAL_NEXT_STATION :следующая станция + STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP :{BLACK}Условие перехода STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS :равно STR_ORDER_CONDITIONAL_COMPARATOR_NOT_EQUALS :не равно @@ -3783,6 +3792,16 @@ STR_ORDER_OUT_OF_RANGE :{RED} (Расс STR_ORDER_CONDITIONAL_UNCONDITIONAL :Перейти к заданию {COMMA} STR_ORDER_CONDITIONAL_NUM :Перейти к заданию {COMMA}, если {STRING} {STRING} {COMMA} STR_ORDER_CONDITIONAL_TRUE_FALSE :Перейти к заданию {COMMA}, если {STRING} - {STRING} +STR_CONDITIONAL_FREE_PLATFORMS :Перейти к заданию {COMMA} когда след. станция {STRING} {COMMA} свободн{P ая ые ых} платформ{P а ы ""} +STR_CONDITIONAL_PERCENT :Перейти к заданию {COMMA} {COMMA} процентов времени +STR_ORDER_CONDITIONAL_COMPARATOR_ACCEPTS :принимает +STR_ORDER_CONDITIONAL_COMPARATOR_DOES_NOT_ACCEPT :не принимает +STR_ORDER_CONDITIONAL_COMPARATOR_HAS :имеет +STR_ORDER_CONDITIONAL_COMPARATOR_HAS_NO :не имеет +STR_ORDER_CONDITIONAL_COMPARATOR_HAS_LESS_THAN :имеет меньше чем +STR_ORDER_CONDITIONAL_COMPARATOR_HAS_LESS_EQUALS :имеет меньше или равно +STR_ORDER_CONDITIONAL_COMPARATOR_HAS_MORE_THAN :имеет больше чем +STR_ORDER_CONDITIONAL_COMPARATOR_HAS_MORE_EQUALS :имеет больше или равно STR_INVALID_ORDER :{RED} (Неверное место назначения) diff --git a/src/order_base.h b/src/order_base.h index 82e1371eec..3c2c813d22 100644 --- a/src/order_base.h +++ b/src/order_base.h @@ -44,6 +44,8 @@ private: CargoID refit_cargo; ///< Refit CargoID byte refit_subtype; ///< Refit subtype + int8 jump_counter; ///< Counter for the 'jump xx% of times' option + public: Order *next; ///< Pointer to next order. If NULL, end of list @@ -133,6 +135,14 @@ public: void SetRefit(CargoID cargo, byte subtype = 0); + /** + * Update the jump_counter of this order. + * @param the jump chance in %. + * @return whether to jump or not. + * @pre IsType(OT_CONDITIONAL) && this->GetConditionVariable() == OCV_PERCENT. + */ + bool UpdateJumpCounter(uint8 percent); + /** How must the consist be loaded? */ inline OrderLoadFlags GetLoadType() const { return (OrderLoadFlags)GB(this->flags, 4, 4); } /** How must the consist be unloaded? */ diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index d79f1e8042..f03182db37 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -17,6 +17,11 @@ #include "news_func.h" #include "strings_func.h" #include "timetable.h" +#include "station_base.h" +#include "station_map.h" +#include "station_func.h" +#include "map_func.h" +#include "cargotype.h" #include "vehicle_func.h" #include "depot_base.h" #include "core/pool_func.hpp" @@ -119,6 +124,17 @@ void Order::MakeLoading(bool ordered) /** * Makes this order a Leave Station order. */ + +bool Order::UpdateJumpCounter(byte percent) +{ + if(this->jump_counter >= 0) { + this->jump_counter += (percent - 100); + return true; + } + this->jump_counter += percent; + return false; +} + void Order::MakeLeaveStation() { this->type = OT_LEAVESTATION; @@ -241,6 +257,7 @@ Order::Order(uint32 packed) this->refit_subtype = 0; this->wait_time = 0; this->travel_time = 0; + this->jump_counter = 0; this->max_speed = UINT16_MAX; } @@ -281,6 +298,8 @@ void Order::AssignOrder(const Order &other) this->refit_subtype = other.refit_subtype; this->wait_time = other.wait_time; + + this->jump_counter = other.jump_counter; this->travel_time = other.travel_time; this->max_speed = other.max_speed; } @@ -763,6 +782,10 @@ CommandCost CmdInsertOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 OrderConditionComparator occ = new_order.GetConditionComparator(); if (occ >= OCC_END) return CMD_ERROR; switch (new_order.GetConditionVariable()) { + case OCV_CARGO_WAITING: + case OCV_CARGO_ACCEPTANCE: + if (!CargoSpec::Get(new_order.GetConditionValue())->IsValid()) return CMD_ERROR; + /* FALL THROUGH */ case OCV_REQUIRES_SERVICE: if (occ != OCC_IS_TRUE && occ != OCC_IS_FALSE) return CMD_ERROR; break; @@ -772,6 +795,14 @@ CommandCost CmdInsertOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 if (new_order.GetConditionValue() != 0) return CMD_ERROR; break; + case OCV_FREE_PLATFORMS: + if (v->type != VEH_TRAIN) return CMD_ERROR; + if (occ == OCC_IS_TRUE || occ == OCC_IS_FALSE) return CMD_ERROR; + break; + + case OCV_PERCENT: + if (occ != OCC_EQUALS) return CMD_ERROR; + /* FALL THROUGH */ case OCV_LOAD_PERCENTAGE: case OCV_RELIABILITY: if (new_order.GetConditionValue() > 100) return CMD_ERROR; @@ -921,6 +952,20 @@ static CommandCost DecloneOrder(Vehicle *dst, DoCommandFlag flags) return CommandCost(); } +/** + * Get the first cargoID that points to a valid cargo (usually 0) + */ +static CargoID GetFirstValidCargo() +{ + for (CargoID i = 0; i < NUM_CARGO; i++) { + if (CargoSpec::Get(i)->IsValid()) return i; + } + /* No cargos defined -> 'Houston, we have a problem!' */ + assert(0); + /* Return something to avoid compiler warning */ + return 0; +} + /** * Delete an order from the orderlist of a vehicle. * @param tile unused @@ -1252,15 +1297,20 @@ CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 break; case MOF_COND_VARIABLE: + if (data == OCV_FREE_PLATFORMS && v->type != VEH_TRAIN) return CMD_ERROR; if (data >= OCV_END) return CMD_ERROR; break; case MOF_COND_COMPARATOR: if (data >= OCC_END) return CMD_ERROR; switch (order->GetConditionVariable()) { - case OCV_UNCONDITIONALLY: return CMD_ERROR; + case OCV_UNCONDITIONALLY: + case OCV_PERCENT: + return CMD_ERROR; case OCV_REQUIRES_SERVICE: + case OCV_CARGO_ACCEPTANCE: + case OCV_CARGO_WAITING: if (data != OCC_IS_TRUE && data != OCC_IS_FALSE) return CMD_ERROR; break; @@ -1276,9 +1326,15 @@ CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 case OCV_LOAD_PERCENTAGE: case OCV_RELIABILITY: + case OCV_PERCENT: if (data > 100) return CMD_ERROR; break; + case OCV_CARGO_ACCEPTANCE: + case OCV_CARGO_WAITING: + if (!(data < NUM_CARGO && CargoSpec::Get(data)->IsValid())) return CMD_ERROR; + break; + default: if (data > 2047) return CMD_ERROR; break; @@ -1336,6 +1392,8 @@ CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 } case MOF_COND_VARIABLE: { + /* Check whether old conditional variable had a cargo as value */ + bool old_var_was_cargo = (order->GetConditionVariable() == OCV_CARGO_ACCEPTANCE || order->GetConditionVariable() == OCV_CARGO_WAITING); order->SetConditionVariable((OrderConditionVariable)data); OrderConditionComparator occ = order->GetConditionComparator(); @@ -1345,15 +1403,25 @@ CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 order->SetConditionValue(0); break; + case OCV_CARGO_ACCEPTANCE: + case OCV_CARGO_WAITING: + if (!old_var_was_cargo) order->SetConditionValue((uint16) GetFirstValidCargo()); + if (occ != OCC_IS_TRUE && occ != OCC_IS_FALSE) order->SetConditionComparator(OCC_IS_TRUE); + break; case OCV_REQUIRES_SERVICE: + if (old_var_was_cargo) order->SetConditionValue(0); if (occ != OCC_IS_TRUE && occ != OCC_IS_FALSE) order->SetConditionComparator(OCC_IS_TRUE); break; + case OCV_PERCENT: + order->SetConditionComparator(OCC_EQUALS); + /* FALL THROUGH */ case OCV_LOAD_PERCENTAGE: case OCV_RELIABILITY: if (order->GetConditionValue() > 100) order->SetConditionValue(100); /* FALL THROUGH */ default: + if (old_var_was_cargo) order->SetConditionValue(0); if (occ == OCC_IS_TRUE || occ == OCC_IS_FALSE) order->SetConditionComparator(OCC_EQUALS); break; } @@ -1862,6 +1930,52 @@ static bool OrderConditionCompare(OrderConditionComparator occ, int variable, in } } +/* Get the number of free (train) platforms in a station. + * @param st_id The StationID of the station. + * @return The number of free train platforms. + */ +static uint16 GetFreeStationPlatforms(StationID st_id) +{ + assert(Station::IsValidID(st_id)); + const Station *st = Station::Get(st_id); + if (!(st->facilities & FACIL_TRAIN)) return 0; + bool is_free; + TileIndex t2; + uint16 counter = 0; + TILE_AREA_LOOP(t1, st->train_station) { + if (st->TileBelongsToRailStation(t1)) { + /* We only proceed if this tile is a track tile and the north(-east/-west) end of the platform */ + if (IsCompatibleTrainStationTile(t1 + TileOffsByDiagDir(GetRailStationAxis(t1) == AXIS_X ? DIAGDIR_NE : DIAGDIR_NW), t1) || IsStationTileBlocked(t1)) continue; + is_free = true; + t2 = t1; + do { + if (GetStationReservationTrackBits(t2)) { + is_free = false; + break; + } + t2 += TileOffsByDiagDir(GetRailStationAxis(t1) == AXIS_X ? DIAGDIR_SW : DIAGDIR_SE); + } while (IsCompatibleTrainStationTile(t2, t1)); + if (is_free) counter++; + } + } + return counter; +} + +/** Gets the next 'real' station in the order list + * @param v the vehicle in question + * @param order the current (conditional) order + * @return the StationID of the next valid station in the order list, or INVALID_STATION if there is none. + */ +static StationID GetNextRealStation(const Vehicle *v, const Order *order, int conditional_depth = 0) +{ + if (order->IsType(OT_GOTO_STATION)) { + if (Station::IsValidID(order->GetDestination())) return order->GetDestination(); + } + //nothing conditional about this + if (conditional_depth > v->GetNumOrders()) return INVALID_STATION; + return GetNextRealStation(v, (order->next != NULL) ? order->next : v->GetFirstOrder(), ++conditional_depth); +} + /** * Process a conditional order and determine the next order. * @param order the order the vehicle currently has @@ -1883,6 +1997,27 @@ VehicleOrderID ProcessConditionalOrder(const Order *order, const Vehicle *v) case OCV_AGE: skip_order = OrderConditionCompare(occ, v->age / DAYS_IN_LEAP_YEAR, value); break; case OCV_REQUIRES_SERVICE: skip_order = OrderConditionCompare(occ, v->NeedsServicing(), value); break; case OCV_UNCONDITIONALLY: skip_order = true; break; + case OCV_CARGO_WAITING: { + StationID next_station = GetNextRealStation(v, order); + if (Station::IsValidID(next_station)) skip_order = OrderConditionCompare(occ, !Station::Get(next_station)->goods[value].cargo.Empty(), value); + break; + } + case OCV_CARGO_ACCEPTANCE: { + StationID next_station = GetNextRealStation(v, order); + if (Station::IsValidID(next_station)) skip_order = OrderConditionCompare(occ, HasBit(Station::Get(next_station)->goods[value].acceptance_pickup, GoodsEntry::GES_ACCEPTANCE), value); + break; + } + case OCV_FREE_PLATFORMS: { + StationID next_station = GetNextRealStation(v, order); + if (Station::IsValidID(next_station)) skip_order = OrderConditionCompare(occ, GetFreeStationPlatforms(next_station), value); + break; + } + case OCV_PERCENT: { + /* get a non-const reference to the current order */ + Order *ord = (Order *)order; + skip_order = ord->UpdateJumpCounter((byte)value); + break; + } case OCV_REMAINING_LIFETIME: skip_order = OrderConditionCompare(occ, max(v->max_age - v->age + DAYS_IN_LEAP_YEAR - 1, 0) / DAYS_IN_LEAP_YEAR, value); break; default: NOT_REACHED(); } diff --git a/src/order_gui.cpp b/src/order_gui.cpp index 0e7579546c..90ca91d0fd 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -153,6 +153,10 @@ static const OrderConditionVariable _order_conditional_variable[] = { OCV_AGE, OCV_REMAINING_LIFETIME, OCV_REQUIRES_SERVICE, + OCV_CARGO_WAITING, + OCV_CARGO_ACCEPTANCE, + OCV_FREE_PLATFORMS, + OCV_PERCENT, OCV_UNCONDITIONALLY, }; @@ -168,6 +172,30 @@ static const StringID _order_conditional_condition[] = { INVALID_STRING_ID, }; +static const StringID _order_conditional_condition_has[] = { + STR_ORDER_CONDITIONAL_COMPARATOR_HAS, + STR_ORDER_CONDITIONAL_COMPARATOR_HAS_NO, + STR_ORDER_CONDITIONAL_COMPARATOR_HAS_LESS_THAN, + STR_ORDER_CONDITIONAL_COMPARATOR_HAS_LESS_EQUALS, + STR_ORDER_CONDITIONAL_COMPARATOR_HAS_MORE_THAN, + STR_ORDER_CONDITIONAL_COMPARATOR_HAS_MORE_EQUALS, + STR_ORDER_CONDITIONAL_COMPARATOR_HAS, + STR_ORDER_CONDITIONAL_COMPARATOR_HAS_NO, + INVALID_STRING_ID, +}; + +static const StringID _order_conditional_condition_accepts[] = { + STR_NULL, + STR_NULL, + STR_NULL, + STR_NULL, + STR_NULL, + STR_NULL, + STR_ORDER_CONDITIONAL_COMPARATOR_ACCEPTS, + STR_ORDER_CONDITIONAL_COMPARATOR_DOES_NOT_ACCEPT, + INVALID_STRING_ID, +}; + extern uint ConvertSpeedToDisplaySpeed(uint speed); extern uint ConvertDisplaySpeedToSpeed(uint speed); @@ -316,20 +344,46 @@ void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int SetDParam(1, order->GetDestination()); break; - case OT_CONDITIONAL: + case OT_CONDITIONAL: { SetDParam(1, order->GetConditionSkipToOrder() + 1); - if (order->GetConditionVariable() == OCV_UNCONDITIONALLY) { + const OrderConditionVariable ocv = order->GetConditionVariable( ); + /* handle some non-ordinary cases seperately */ + if ( ocv == OCV_UNCONDITIONALLY ) { SetDParam(0, STR_ORDER_CONDITIONAL_UNCONDITIONAL); + } else if ( ocv == OCV_PERCENT ) { + SetDParam( 0, STR_CONDITIONAL_PERCENT ); + SetDParam( 2, order->GetConditionValue( ) ); + } else if ( ocv == OCV_FREE_PLATFORMS ) { + SetDParam( 0, STR_CONDITIONAL_FREE_PLATFORMS ); + SetDParam( 2, STR_ORDER_CONDITIONAL_COMPARATOR_HAS + order->GetConditionComparator() ); + SetDParam( 3, order->GetConditionValue( ) ); } else { OrderConditionComparator occ = order->GetConditionComparator(); - SetDParam(0, (occ == OCC_IS_TRUE || occ == OCC_IS_FALSE) ? STR_ORDER_CONDITIONAL_TRUE_FALSE : STR_ORDER_CONDITIONAL_NUM); - SetDParam(2, STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + order->GetConditionVariable()); - SetDParam(3, STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS + occ); + bool is_cargo = ocv == OCV_CARGO_ACCEPTANCE || ocv == OCV_CARGO_WAITING; + SetDParam( 0, is_cargo ? STR_ORDER_CONDITIONAL_CARGO : (occ == OCC_IS_TRUE || occ == OCC_IS_FALSE) ? STR_ORDER_CONDITIONAL_TRUE_FALSE : STR_ORDER_CONDITIONAL_NUM ); + SetDParam( 2, (ocv == OCV_CARGO_ACCEPTANCE || ocv == OCV_CARGO_WAITING || ocv == OCV_FREE_PLATFORMS) ? STR_ORDER_CONDITIONAL_NEXT_STATION : STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + ocv ); uint value = order->GetConditionValue(); - if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value); + switch ( ocv ) { + case OCV_CARGO_ACCEPTANCE: + SetDParam( 3, STR_ORDER_CONDITIONAL_COMPARATOR_ACCEPTS + occ - OCC_IS_TRUE ); + SetDParam( 4, CargoSpec::Get( value )->name ); + break; + case OCV_CARGO_WAITING: + SetDParam( 3, STR_ORDER_CONDITIONAL_COMPARATOR_HAS + occ - OCC_IS_TRUE ); + SetDParam( 4, CargoSpec::Get( value )->name ); + break; + case OCV_REQUIRES_SERVICE: + SetDParam( 3, STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS + occ ); + break; + case OCV_MAX_SPEED: + value = ConvertSpeedToDisplaySpeed( value ); + /* FALL THROUGH */ + default: + SetDParam( 3, STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS + occ ); SetDParam(4, value); } + } if (timetable && order->wait_time > 0) { SetDParam(5, STR_TIMETABLE_AND_TRAVEL_FOR); @@ -337,6 +391,7 @@ void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int } else { SetDParam(5, STR_EMPTY); } + } break; default: NOT_REACHED(); @@ -506,6 +561,11 @@ private: /* WID_O_SEL_TOP_ROW */ DP_ROW_LOAD = 0, ///< Display 'load' / 'unload' / 'refit' buttons in the top row of the ship/airplane order window. DP_ROW_DEPOT = 1, ///< Display 'refit' / 'service' buttons in the top row of the ship/airplane order window. + + /* WID_O_SEL_COND_VALUE */ + DP_COND_VALUE_NUMBER = 0, ///< Display number widget + DP_COND_VALUE_CARGO = 1, ///< Display dropdown widget cargo types + DP_ROW_CONDITIONAL = 2, ///< Display the conditional order buttons in the top row of the ship/airplane order window. /* WID_O_SEL_BOTTOM_MIDDLE */ @@ -519,6 +579,8 @@ private: const Vehicle *vehicle; ///< Vehicle owning the orders being displayed and manipulated. Scrollbar *vscroll; bool can_do_autorefit; ///< Vehicle chain can be auto-refitted. + StringID cargo_names_list[NUM_CARGO + 1]; + uint32 cargo_bitmask; /** * Return the memorised selected order. @@ -551,6 +613,23 @@ private: return (sel <= vehicle->GetNumOrders() && sel >= 0) ? sel : INVALID_VEH_ORDER_ID; } + /** + * Determine which strings should be displayed in the conditional comparator dropdown + * + * @param order the order to evaluate + * @return the StringIDs to display + */ + static const StringID *GetComparatorStrings(const Order *order) + { + if (order == NULL) return _order_conditional_condition; + switch (order->GetConditionVariable()) { + case OCV_FREE_PLATFORMS: //fall through + case OCV_CARGO_WAITING: return _order_conditional_condition_has; break; + case OCV_CARGO_ACCEPTANCE: return _order_conditional_condition_accepts; break; + default: return _order_conditional_condition; break; + } + } + /** * Handle the click on the goto button. * @param i Dummy parameter. @@ -853,6 +932,18 @@ public: break; } } + + + /* Create cargo bitmask */ + assert_compile(NUM_CARGO <= 32); + for (CargoID c = 0; c < NUM_CARGO; c++) { + if (CargoSpec::Get(c)->IsValid()) { + this->cargo_names_list[c] = CargoSpec::Get(c)->name; + SetBit(this->cargo_bitmask, c); + } + } + this->cargo_bitmask = ~this->cargo_bitmask; + this->cargo_names_list[NUM_CARGO] = INVALID_STRING_ID; } /** @@ -1054,11 +1145,20 @@ public: } else { train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_CONDITIONAL); } - OrderConditionVariable ocv = order->GetConditionVariable(); + OrderConditionVariable ocv = (order == NULL) ? OCV_LOAD_PERCENTAGE : order->GetConditionVariable(); + bool is_cargo = ocv == OCV_CARGO_ACCEPTANCE || ocv == OCV_CARGO_WAITING; + + if ( is_cargo ) { + this->GetWidget(WID_O_COND_CARGO)->widget_data = cargo_names_list[order == NULL ? 0 : order->GetConditionValue()]; + this->GetWidget(WID_O_SEL_COND_VALUE)->SetDisplayedPlane(DP_COND_VALUE_CARGO); + } else { + this->GetWidget(WID_O_SEL_COND_VALUE)->SetDisplayedPlane(DP_COND_VALUE_NUMBER); + } + /* Set the strings for the dropdown boxes. */ this->GetWidget(WID_O_COND_VARIABLE)->widget_data = STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + (order == NULL ? 0 : ocv); - this->GetWidget(WID_O_COND_COMPARATOR)->widget_data = _order_conditional_condition[order == NULL ? 0 : order->GetConditionComparator()]; - this->SetWidgetDisabledState(WID_O_COND_COMPARATOR, ocv == OCV_UNCONDITIONALLY); + this->GetWidget(WID_O_COND_COMPARATOR)->widget_data = GetComparatorStrings(order)[order == NULL ? 0 : order->GetConditionComparator()]; + this->SetWidgetDisabledState(WID_O_COND_COMPARATOR, ocv == OCV_UNCONDITIONALLY || ocv == OCV_PERCENT); this->SetWidgetDisabledState(WID_O_COND_VALUE, ocv == OCV_REQUIRES_SERVICE || ocv == OCV_UNCONDITIONALLY); break; } @@ -1291,6 +1391,12 @@ public: } break; + case WID_O_COND_CARGO: { + uint value = this->vehicle->GetOrder(this->OrderGetSel())->GetConditionValue(); + ShowDropDownMenu(this, cargo_names_list, value, WID_O_COND_CARGO, 0, cargo_bitmask); + break; + } + case WID_O_TIMETABLE_VIEW: ShowTimetableWindow(this->vehicle); break; @@ -1306,7 +1412,11 @@ public: case WID_O_COND_COMPARATOR: { const Order *o = this->vehicle->GetOrder(this->OrderGetSel()); - ShowDropDownMenu(this, _order_conditional_condition, o->GetConditionComparator(), WID_O_COND_COMPARATOR, 0, (o->GetConditionVariable() == OCV_REQUIRES_SERVICE) ? 0x3F : 0xC0); + OrderConditionVariable cond_var = o->GetConditionVariable(); + ShowDropDownMenu(this, GetComparatorStrings( o ), o->GetConditionComparator(), WID_O_COND_COMPARATOR, 0, + (cond_var == OCV_REQUIRES_SERVICE || + cond_var == OCV_CARGO_ACCEPTANCE || + cond_var == OCV_CARGO_WAITING) ? 0x3F : 0xC0); break; } @@ -1336,6 +1446,7 @@ public: value = ConvertDisplaySpeedToSpeed(value); break; + case OCV_PERCENT: case OCV_RELIABILITY: case OCV_LOAD_PERCENTAGE: value = Clamp(value, 0, 100); @@ -1388,6 +1499,10 @@ public: case WID_O_COND_COMPARATOR: DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), MOF_COND_COMPARATOR | index << 4, CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER)); break; + + case WID_O_COND_CARGO: + DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), MOF_COND_VALUE | index << 4, CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER)); + break; } } @@ -1579,10 +1694,14 @@ static const NWidgetPart _nested_orders_train_widgets[] = { SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP), SetResize(1, 0), NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_COMPARATOR), SetMinimalSize(124, 12), SetFill(1, 0), SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP), SetResize(1, 0), + NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_COND_VALUE), NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_COND_VALUE), SetMinimalSize(124, 12), SetFill(1, 0), SetDataTip(STR_BLACK_COMMA, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP), SetResize(1, 0), + NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_CARGO), SetMinimalSize(124, 12), SetFill(1, 0), + SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_CARGO_TOOLTIP), SetResize(1, 0), EndContainer(), EndContainer(), + EndContainer(), NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_O_SHARED_ORDER_LIST), SetMinimalSize(12, 12), SetDataTip(SPR_SHARED_ORDERS_ICON, STR_ORDERS_VEH_WITH_SHARED_ORDERS_LIST_TOOLTIP), EndContainer(), diff --git a/src/order_type.h b/src/order_type.h index 44f93218ba..1cb49e342f 100644 --- a/src/order_type.h +++ b/src/order_type.h @@ -117,6 +117,10 @@ enum OrderConditionVariable { OCV_REQUIRES_SERVICE, ///< Skip when the vehicle requires service OCV_UNCONDITIONALLY, ///< Always skip OCV_REMAINING_LIFETIME, ///< Skip based on the remaining lifetime + OCV_CARGO_WAITING, ///< Skip if specified cargo is waiting at next station + OCV_CARGO_ACCEPTANCE, ///< Skip if specified cargo is accepted at next station + OCV_FREE_PLATFORMS, ///< Skip based on free platforms at next station + OCV_PERCENT, ///< Skip xx percent of times OCV_END }; diff --git a/src/saveload/order_sl.cpp b/src/saveload/order_sl.cpp index 0437a2d7ac..9e7e65fa8a 100644 --- a/src/saveload/order_sl.cpp +++ b/src/saveload/order_sl.cpp @@ -111,6 +111,7 @@ const SaveLoad *GetOrderDescription() SLE_CONDVAR(Order, wait_time, SLE_UINT16, 67, SL_MAX_VERSION), SLE_CONDVAR(Order, travel_time, SLE_UINT16, 67, SL_MAX_VERSION), SLE_CONDVAR(Order, max_speed, SLE_UINT16, 172, SL_MAX_VERSION), + SLE_CONDVAR(Order, jump_counter, SLE_INT8, SL_CONDORDERS, SL_MAX_VERSION), /* Leftover from the minor savegame version stuff * We will never use those free bytes, but we have to keep this line to allow loading of old savegames */ diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index f9e569680f..d792f47455 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -240,7 +240,7 @@ * 174 23973 1.2.x * 175 24136 */ -extern const uint16 SAVEGAME_VERSION = 175; ///< Current savegame version of OpenTTD. +extern const uint16 SAVEGAME_VERSION = SL_CONDORDERS; ///< Current savegame version of OpenTTD. SavegameType _savegame_type; ///< type of savegame we are loading diff --git a/src/saveload/saveload.h b/src/saveload/saveload.h index c5ffbeff8f..3a0e082a45 100644 --- a/src/saveload/saveload.h +++ b/src/saveload/saveload.h @@ -87,7 +87,7 @@ enum SLRefType { /** Highest possible savegame version. */ #define SL_MAX_VERSION 255 - +#define SL_CONDORDERS 200 /** Flags of a chunk. */ enum ChunkType { CH_RIFF = 0, diff --git a/src/widgets/order_widget.h b/src/widgets/order_widget.h index 825f791ea8..8fedc032fe 100644 --- a/src/widgets/order_widget.h +++ b/src/widgets/order_widget.h @@ -32,6 +32,8 @@ enum OrderWidgets { WID_O_COND_VARIABLE, ///< Choose condition variable. WID_O_COND_COMPARATOR, ///< Choose condition type. WID_O_COND_VALUE, ///< Choose condition value. + WID_O_COND_CARGO, + WID_O_SEL_COND_VALUE, ///< widget for conditional value or conditional cargo type. WID_O_SEL_TOP_LEFT, ///< #NWID_SELECTION widget for left part of the top row of the 'your train' order window. WID_O_SEL_TOP_MIDDLE, ///< #NWID_SELECTION widget for middle part of the top row of the 'your train' order window. WID_O_SEL_TOP_RIGHT, ///< #NWID_SELECTION widget for right part of the top row of the 'your train' order window.