Merge branch 'more_cond_orders-sx' into jgrpp

Conflicts:
	src/order_base.h
	src/order_gui.cpp
	src/saveload/extended_ver_sl.cpp
	src/saveload/extended_ver_sl.h
pull/3/head
Jonathan G Rennison 9 years ago
commit 8357b911e5

@ -4218,6 +4218,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
@ -4230,8 +4242,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
@ -4317,6 +4339,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)

@ -4078,6 +4078,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} (Неверное место назначения)

@ -44,6 +44,7 @@ private:
CargoID refit_cargo; ///< Refit CargoID
uint8 occupancy; ///< Estimate of vehicle occupancy on departure, for the current order, 0 indicates invalid, 1 - 101 indicate 0 - 100%
int8 jump_counter; ///< Counter for the 'jump xx% of times' option
uint16 wait_time; ///< How long in ticks to wait at the destination.
uint16 travel_time; ///< How long in ticks the journey to this destination should take.
@ -128,6 +129,14 @@ public:
void SetRefit(CargoID cargo);
/**
* 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, 3); }
/** How must the consist be unloaded? */

@ -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"
@ -120,6 +125,25 @@ void Order::MakeLoading(bool ordered)
if (!ordered) this->flags = 0;
}
/**
* Update the jump counter, for percent probability
* conditional orders
*
* Not that jump_counter is signed and may become
* negative when a jump has been taken
*
* @return true if the jump should be taken
*/
bool Order::UpdateJumpCounter(byte percent)
{
if (this->jump_counter >= 0) {
this->jump_counter += (percent - 100);
return true;
}
this->jump_counter += percent;
return false;
}
/**
* Makes this order a Leave Station order.
*/
@ -248,6 +272,7 @@ Order::Order(uint32 packed)
this->occupancy = 0;
this->wait_time = 0;
this->travel_time = 0;
this->jump_counter = 0;
this->max_speed = UINT16_MAX;
}
@ -287,6 +312,8 @@ void Order::AssignOrder(const Order &other)
this->refit_cargo = other.refit_cargo;
this->wait_time = other.wait_time;
this->jump_counter = other.jump_counter;
this->travel_time = other.travel_time;
this->max_speed = other.max_speed;
}
@ -875,6 +902,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;
@ -884,6 +915,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;
@ -1033,6 +1072,18 @@ 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!' */
NOT_REACHED();
}
/**
* Delete an order from the orderlist of a vehicle.
* @param tile unused
@ -1370,15 +1421,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;
@ -1396,9 +1452,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;
@ -1460,6 +1522,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();
@ -1469,16 +1533,26 @@ 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);
order->SetConditionValue(0);
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;
}
@ -2019,6 +2093,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
@ -2040,6 +2160,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.AvailableCount() > 0, 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].status, 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 = const_cast<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();
}

@ -157,6 +157,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,
};
@ -172,6 +176,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);
@ -327,19 +355,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);
SetDParam(4, 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->GetWaitTime() > 0) {
@ -348,7 +403,9 @@ void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int
} else {
SetDParam(5, STR_EMPTY);
}
break;
}
default: NOT_REACHED();
}
@ -509,6 +566,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 */
@ -523,6 +585,8 @@ private:
Scrollbar *vscroll;
bool can_do_refit; ///< Vehicle chain can be refitted in depot.
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.
@ -555,6 +619,28 @@ 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:
case OCV_CARGO_WAITING:
return _order_conditional_condition_has;
case OCV_CARGO_ACCEPTANCE:
return _order_conditional_condition_accepts;
default:
return _order_conditional_condition;
}
}
/**
* Handle the click on the goto button.
*/
@ -851,6 +937,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;
}
/**
@ -1061,11 +1159,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<NWidgetCore>(WID_O_COND_CARGO)->widget_data = cargo_names_list[(order == NULL) ? 0 : order->GetConditionValue()];
this->GetWidget<NWidgetStacked>(WID_O_SEL_COND_VALUE)->SetDisplayedPlane(DP_COND_VALUE_CARGO);
} else {
this->GetWidget<NWidgetStacked>(WID_O_SEL_COND_VALUE)->SetDisplayedPlane(DP_COND_VALUE_NUMBER);
}
/* Set the strings for the dropdown boxes. */
this->GetWidget<NWidgetCore>(WID_O_COND_VARIABLE)->widget_data = STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + ocv;
this->GetWidget<NWidgetCore>(WID_O_COND_COMPARATOR)->widget_data = _order_conditional_condition[order->GetConditionComparator()];
this->SetWidgetDisabledState(WID_O_COND_COMPARATOR, ocv == OCV_UNCONDITIONALLY);
this->GetWidget<NWidgetCore>(WID_O_COND_COMPARATOR)->widget_data = GetComparatorStrings(order)[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;
}
@ -1352,6 +1459,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;
@ -1367,7 +1480,9 @@ 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, 0, DDSF_LOST_FOCUS);
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, 0, DDSF_LOST_FOCUS);
break;
}
@ -1403,6 +1518,7 @@ public:
value = ConvertDisplaySpeedToSpeed(value);
break;
case OCV_PERCENT:
case OCV_RELIABILITY:
case OCV_LOAD_PERCENTAGE:
value = Clamp(value, 0, 100);
@ -1455,6 +1571,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;
}
}
@ -1672,8 +1792,12 @@ 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(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_COND_VALUE), SetMinimalSize(124, 12), SetFill(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_TEXTBTN, COLOUR_GREY, WID_O_OCCUPANCY_TOGGLE), SetMinimalSize(12, 12), SetDataTip(STR_ORDERS_OCCUPANCY_BUTTON, STR_ORDERS_OCCUPANCY_BUTTON_TOOLTIP),

@ -125,6 +125,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
};

@ -61,6 +61,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
{ XSLFI_INFRA_SHARING, XSCF_NULL, 1, 1, "infra_sharing", NULL, NULL, NULL },
{ XSLFI_VARIABLE_DAY_LENGTH, XSCF_NULL, 1, 1, "variable_day_length", NULL, NULL, NULL },
{ XSLFI_ORDER_OCCUPANCY, XSCF_NULL, 1, 1, "order_occupancy", NULL, NULL, NULL },
{ XSLFI_MORE_COND_ORDERS, XSCF_NULL, 1, 1, "more_cond_orders", NULL, NULL, NULL },
{ XSLFI_NULL, XSCF_NULL, 0, 0, NULL, NULL, NULL, NULL },// This is the end marker
};

@ -36,6 +36,7 @@ enum SlXvFeatureIndex {
XSLFI_INFRA_SHARING, ///< Infrastructure sharing patch
XSLFI_VARIABLE_DAY_LENGTH, ///< Variable day length patch
XSLFI_ORDER_OCCUPANCY, ///< Running average of order occupancy
XSLFI_MORE_COND_ORDERS, ///< More conditional orders patch
XSLFI_SIZE, ///< Total count of features, including null feature
};

@ -114,6 +114,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_X(Order, jump_counter, SLE_INT8, 0, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_MORE_COND_ORDERS)),
/* 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 */

@ -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.

Loading…
Cancel
Save