summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--aircraft_cmd.c6
-rw-r--r--aircraft_gui.c2
-rw-r--r--command.c4
-rw-r--r--command.h1
-rw-r--r--lang/english.txt7
-rw-r--r--openttd.c16
-rw-r--r--order.h6
-rw-r--r--order_cmd.c58
-rw-r--r--order_gui.c41
-rw-r--r--roadveh_cmd.c5
-rw-r--r--roadveh_gui.c2
-rw-r--r--saveload.c2
-rw-r--r--ship_cmd.c5
-rw-r--r--ship_gui.c2
-rw-r--r--train_cmd.c5
-rw-r--r--train_gui.c2
-rw-r--r--vehicle.c4
-rw-r--r--vehicle_gui.c22
-rw-r--r--vehicle_gui.h2
-rw-r--r--window.h2
20 files changed, 172 insertions, 22 deletions
diff --git a/aircraft_cmd.c b/aircraft_cmd.c
index d7c8a31bd..440347bdc 100644
--- a/aircraft_cmd.c
+++ b/aircraft_cmd.c
@@ -1396,12 +1396,18 @@ static void AircraftEnterHangar(Vehicle *v)
TriggerVehicle(v, VEHICLE_TRIGGER_DEPOT);
if (v->current_order.type == OT_GOTO_DEPOT) {
+ int32 cost;
+
InvalidateWindow(WC_VEHICLE_VIEW, v->index);
old_order = v->current_order;
v->current_order.type = OT_NOTHING;
v->current_order.flags = 0;
+ _current_player = v->owner;
+ cost = DoCommand(v->tile, v->index, old_order.refit_cargo | old_order.refit_subtype << 8, DC_EXEC, CMD_REFIT_AIRCRAFT);
+ if (!CmdFailed(cost) && v->owner == _local_player && cost != 0) ShowCostOrIncomeAnimation(v->x_pos, v->y_pos, v->z_pos, cost);
+
if (HASBIT(old_order.flags, OFB_PART_OF_ORDERS)) {
v->cur_order_index++;
} else if (HASBIT(old_order.flags, OFB_HALT_IN_DEPOT)) { // force depot visit
diff --git a/aircraft_gui.c b/aircraft_gui.c
index 0a16fb793..95e9969cc 100644
--- a/aircraft_gui.c
+++ b/aircraft_gui.c
@@ -522,7 +522,7 @@ static void AircraftViewWndProc(Window *w, WindowEvent *e)
DoCommandP(v->tile, v->index, _ctrl_pressed ? DEPOT_SERVICE : 0, NULL, CMD_SEND_AIRCRAFT_TO_HANGAR | CMD_MSG(STR_A012_CAN_T_SEND_AIRCRAFT_TO));
break;
case 8: /* refit */
- ShowVehicleRefitWindow(v);
+ ShowVehicleRefitWindow(v, INVALID_VEH_ORDER_ID);
break;
case 9: /* show orders */
ShowOrdersWindow(v);
diff --git a/command.c b/command.c
index f08565e01..a1efa8b13 100644
--- a/command.c
+++ b/command.c
@@ -138,6 +138,7 @@ DEF_COMMAND(CmdBuildShip);
DEF_COMMAND(CmdSendShipToDepot);
DEF_COMMAND(CmdRefitShip);
+DEF_COMMAND(CmdOrderRefit);
DEF_COMMAND(CmdCloneOrder);
DEF_COMMAND(CmdClearArea);
@@ -163,7 +164,6 @@ DEF_COMMAND(CmdMassStartStopVehicle);
DEF_COMMAND(CmdDepotSellAllVehicles);
DEF_COMMAND(CmdDepotMassAutoReplace);
-
/* The master command table */
static const Command _command_proc_table[] = {
{CmdBuildRailroadTrack, 0}, /* 0 */
@@ -282,8 +282,8 @@ static const Command _command_proc_table[] = {
{NULL, 0}, /* 95 */
{NULL, 0}, /* 96 */
{NULL, 0}, /* 97 */
- {NULL, 0}, /* 98 */
+ {CmdOrderRefit, 0}, /* 98 */
{CmdCloneOrder, 0}, /* 99 */
{CmdClearArea, 0}, /* 100 */
diff --git a/command.h b/command.h
index ab913352e..497f018cf 100644
--- a/command.h
+++ b/command.h
@@ -114,6 +114,7 @@ enum {
CMD_SEND_SHIP_TO_DEPOT = 89,
CMD_REFIT_SHIP = 91,
+ CMD_ORDER_REFIT = 98,
CMD_CLONE_ORDER = 99,
CMD_CLEAR_AREA = 100,
diff --git a/lang/english.txt b/lang/english.txt
index 34978fa7e..4a9f6bd8c 100644
--- a/lang/english.txt
+++ b/lang/english.txt
@@ -2470,8 +2470,8 @@ STR_8800_TRAIN_DEPOT :{WHITE}{TOWN} T
STR_8801_CITIZENS_CELEBRATE_FIRST :{BLACK}{BIGFONT}Citizens celebrate . . .{}First train arrives at {STATION}!
STR_8802_DETAILS :{WHITE}{STRING1} (Details)
STR_8803_TRAIN_IN_THE_WAY :{WHITE}Train in the way
-STR_8804 :{SETX 10}{COMMA}: {STRING1}
-STR_8805 :{RIGHTARROW}{SETX 10}{COMMA}: {STRING1}
+STR_8804 :{SETX 10}{COMMA}: {STRING1} {STRING1}
+STR_8805 :{RIGHTARROW}{SETX 10}{COMMA}: {STRING1} {STRING1}
STR_8806_GO_TO :Go to {STATION}
STR_8807_GO_TO_TRANSFER :Go to {STATION} (Transfer and take cargo)
STR_8808_GO_TO_UNLOAD :Go to {STATION} (Unload)
@@ -2523,6 +2523,9 @@ STR_8825_NON_STOP :{BLACK}Non-Stop
STR_8826_GO_TO :{BLACK}Go To
STR_8827_FULL_LOAD :{BLACK}Full Load
STR_8828_UNLOAD :{BLACK}Unload
+STR_REFIT :{BLACK}Refit
+STR_REFIT_TIP :{BLACK}Select what cargo type to refit to in this order. Control click to remove refit instruction
+STR_REFIT_ORDER :(Refit to {STRING})
STR_8829_ORDERS :{WHITE}{VEHICLE} (Orders)
STR_882A_END_OF_ORDERS :{SETX 10}- - End of Orders - -
STR_FULLLOAD_OR_SERVICE :{SKIP}{SKIP}{STRING}
diff --git a/openttd.c b/openttd.c
index eb54886cd..ee2b0234b 100644
--- a/openttd.c
+++ b/openttd.c
@@ -1518,5 +1518,21 @@ bool AfterLoadGame(void)
}
}
+ /* Setting no refit flags to all orders in savegames from before refit in orders were added */
+ if (CheckSavegameVersion(36)) {
+ Order *order;
+ Vehicle *v;
+
+ FOR_ALL_ORDERS(order) {
+ order->refit_cargo = CT_NO_REFIT;
+ order->refit_subtype = CT_NO_REFIT;
+ }
+
+ FOR_ALL_VEHICLES(v) {
+ v->current_order.refit_cargo = CT_NO_REFIT;
+ v->current_order.refit_subtype = CT_NO_REFIT;
+ }
+ }
+
return true;
}
diff --git a/order.h b/order.h
index e3c2d1d9d..fd7f96e7e 100644
--- a/order.h
+++ b/order.h
@@ -9,7 +9,8 @@
#include "pool.h"
enum {
- INVALID_ORDER = 0xFFFF,
+ INVALID_VEH_ORDER_ID = 0xFF,
+ INVALID_ORDER = 0xFFFF,
};
/* Order types */
@@ -88,6 +89,9 @@ typedef struct Order {
struct Order *next; ///< Pointer to next order. If NULL, end of list
OrderID index; ///< Index of the order, is not saved or anything, just for reference
+
+ CargoID refit_cargo; // Refit CargoID
+ byte refit_subtype; // Refit subtype
} Order;
#define MAX_BACKUP_ORDER_COUNT 40
diff --git a/order_cmd.c b/order_cmd.c
index 2641c7c93..fad343b1f 100644
--- a/order_cmd.c
+++ b/order_cmd.c
@@ -145,6 +145,9 @@ void AssignOrder(Order *order, Order data)
order->type = data.type;
order->flags = data.flags;
order->dest = data.dest;
+
+ order->refit_cargo = CT_NO_REFIT;
+ order->refit_subtype = CT_NO_REFIT;
}
@@ -751,6 +754,54 @@ int32 CmdCloneOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
return 0;
}
+/** Add/remove refit orders from an order
+ * @param tile Not used
+ * @param p1 VehicleIndex of the vehicle having the order
+ * @param p2 bitmask
+ * - bit 0-7 CargoID
+ * - bit 8-15 Cargo subtype
+ * - bit 16-23 number of order to modify
+ */
+int32 CmdOrderRefit(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
+{
+ const Vehicle *v;
+ Order *order;
+ VehicleID veh = GB(p1, 0, 16);
+ VehicleOrderID order_number = GB(p2, 16, 8);
+ CargoID cargo = GB(p2, 0, 8);
+ byte subtype = GB(p2, 8, 8);
+
+ if (!IsValidVehicleID(veh)) return CMD_ERROR;
+
+ v = GetVehicle(veh);
+
+ if (!CheckOwnership(v->owner)) return CMD_ERROR;
+
+ order = GetVehicleOrder(v, order_number);
+ if (order == NULL) return CMD_ERROR;
+
+ if (flags & DC_EXEC) {
+ Vehicle *u;
+
+ order->refit_cargo = cargo;
+ order->refit_subtype = subtype;
+
+ u = GetFirstVehicleFromSharedList(v);
+ for (; u != NULL; u = u->next_shared) {
+ /* Update any possible open window of the vehicle */
+ InvalidateVehicleOrder(u);
+
+ /* If the vehicle already got the current depot set as current order, then update current order as well */
+ if (u->cur_order_index == order_number && HASBIT(u->current_order.flags, OFB_PART_OF_ORDERS)) {
+ u->current_order.refit_cargo = cargo;
+ u->current_order.refit_subtype = subtype;
+ }
+ }
+ }
+
+ return 0;
+}
+
/**
*
* Backup a vehicle order-list, so you can replace a vehicle
@@ -1116,9 +1167,12 @@ static const SaveLoad _order_desc[] = {
SLE_VAR(Order, flags, SLE_UINT8),
SLE_VAR(Order, dest, SLE_UINT16),
SLE_REF(Order, next, REF_ORDER),
+ SLE_CONDVAR(Order, refit_cargo, SLE_UINT8, 36, SL_MAX_VERSION),
+ SLE_CONDVAR(Order, refit_subtype, SLE_UINT8, 36, SL_MAX_VERSION),
- // reserve extra space in savegame here. (currently 10 bytes)
- SLE_CONDNULL(10, 5, 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 */
+ SLE_CONDNULL(10, 5, 35),
SLE_END()
};
diff --git a/order_gui.c b/order_gui.c
index 403d6ab62..66a30ba7e 100644
--- a/order_gui.c
+++ b/order_gui.c
@@ -96,6 +96,11 @@ static void DrawOrdersWindow(Window *w)
SetWindowWidgetDisabledState(w, 9, not_localplayer || order == NULL); // unload
SetWindowWidgetDisabledState(w, 10, not_localplayer || order == NULL); // transfer
SetWindowWidgetDisabledState(w, 11, !shared_orders || v->orders == NULL); // Disable list of vehicles with the same shared orders if there are no list
+ SetWindowWidgetDisabledState(w, 12, not_localplayer || order == NULL); // Refit
+
+
+ ShowWindowWidget(w, 9); // Unload
+ HideWindowWidget(w, 12); // Refit
if (order != NULL) {
switch (order->type) {
@@ -103,8 +108,11 @@ static void DrawOrdersWindow(Window *w)
break;
case OT_GOTO_DEPOT:
- DisableWindowWidget(w, 9);
DisableWindowWidget(w, 10);
+
+ /* Remove unload and replace it with refit */
+ HideWindowWidget(w, 9);
+ ShowWindowWidget(w, 12);
SetDParam(2,STR_SERVICE);
break;
@@ -131,6 +139,7 @@ static void DrawOrdersWindow(Window *w)
order = GetVehicleOrder(v, i);
while (order != NULL) {
str = (v->cur_order_index == i) ? STR_8805 : STR_8804;
+ SetDParam(3, STR_EMPTY);
if (i - w->vscroll.pos < w->vscroll.cap) {
SetDParam(1, 6);
@@ -161,6 +170,12 @@ static void DrawOrdersWindow(Window *w)
if (order->flags & OF_FULL_LOAD) s++; /* service at */
SetDParam(1, s);
+ if (order->refit_cargo == CT_NO_REFIT) {
+ SetDParam(3, STR_EMPTY);
+ } else {
+ SetDParam(3, STR_REFIT_ORDER);
+ SetDParam(4, _cargoc.names_s[order->refit_cargo]);
+ }
break;
}
@@ -371,6 +386,16 @@ static void OrderClick_Delete(Window *w, const Vehicle *v)
DoCommandP(v->tile, v->index, OrderGetSel(w), NULL, CMD_DELETE_ORDER | CMD_MSG(STR_8834_CAN_T_DELETE_THIS_ORDER));
}
+static void OrderClick_Refit(Window *w, const Vehicle *v)
+{
+ if (_ctrl_pressed) {
+ /* Cancel refitting */
+ DoCommandP(v->tile, v->index, (WP(w,order_d).sel << 16) | (CT_NO_REFIT << 8) | CT_NO_REFIT, NULL, CMD_ORDER_REFIT);
+ } else {
+ ShowVehicleRefitWindow(v, WP(w,order_d).sel);
+ }
+}
+
typedef void OnButtonVehClick(Window *w, const Vehicle *v);
static OnButtonVehClick* const _order_button_proc[] = {
@@ -395,6 +420,15 @@ static const uint16 _order_keycodes[] = {
static void OrdersWndProc(Window *w, WindowEvent *e)
{
switch (e->event) {
+ case WE_CREATE:
+ /* Move Refit to the same location as Unload
+ * This will ensure that they always stay at the same location even if Unload is moved in a later commit */
+ w->widget[12].left = w->widget[9].left;
+ w->widget[12].right = w->widget[9].right;
+ w->widget[12].top = w->widget[9].top;
+ w->widget[12].bottom = w->widget[9].bottom;
+ break;
+
case WE_PAINT:
DrawOrdersWindow(w);
break;
@@ -458,6 +492,9 @@ static void OrdersWndProc(Window *w, WindowEvent *e)
case 11: /* Vehicle with same shared Orders button */
ShowVehWithSharedOrders(v, v->type);
break;
+ case 12:
+ OrderClick_Refit(w, v);
+ break;
}
} break;
@@ -534,6 +571,7 @@ static const Widget _orders_train_widgets[] = {
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 265, 319, 76, 87, STR_8828_UNLOAD, STR_8858_MAKE_THE_HIGHLIGHTED_ORDER},
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 320, 372, 76, 87, STR_886F_TRANSFER, STR_886D_MAKE_THE_HIGHLIGHTED_ORDER},
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 373, 386, 76, 87, STR_TRAIN, STR_VEH_WITH_SHARED_ORDERS_LIST_TIP},
+{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 320, 372, 76, 87, STR_REFIT, STR_REFIT_TIP},
{ WWT_PANEL, RESIZE_RTB, 14, 387, 386, 76, 87, 0x0, STR_NULL},
{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 387, 398, 76, 87, 0x0, STR_RESIZE_BUTTON},
{ WIDGETS_END},
@@ -560,6 +598,7 @@ static const Widget _orders_widgets[] = {
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 257, 319, 76, 87, STR_8828_UNLOAD, STR_8858_MAKE_THE_HIGHLIGHTED_ORDER},
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 320, 383, 76, 87, STR_886F_TRANSFER, STR_886D_MAKE_THE_HIGHLIGHTED_ORDER},
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 384, 397, 76, 87, STR_EMPTY, STR_VEH_WITH_SHARED_ORDERS_LIST_TIP},
+{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 320, 383, 76, 87, STR_REFIT, STR_REFIT_TIP},
{ WWT_PANEL, RESIZE_RTB, 14, 397, 396, 76, 87, 0x0, STR_NULL},
{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 398, 409, 76, 87, 0x0, STR_RESIZE_BUTTON},
{ WIDGETS_END},
diff --git a/roadveh_cmd.c b/roadveh_cmd.c
index e8f0d2884..a38701237 100644
--- a/roadveh_cmd.c
+++ b/roadveh_cmd.c
@@ -1588,6 +1588,7 @@ void RoadVehEnterDepot(Vehicle *v)
if (v->current_order.type == OT_GOTO_DEPOT) {
Order t;
+ int32 cost;
InvalidateWindow(WC_VEHICLE_VIEW, v->index);
@@ -1595,6 +1596,10 @@ void RoadVehEnterDepot(Vehicle *v)
v->current_order.type = OT_DUMMY;
v->current_order.flags = 0;
+ _current_player = v->owner;
+ cost = DoCommand(v->tile, v->index, t.refit_cargo | t.refit_subtype << 8, DC_EXEC, CMD_REFIT_ROAD_VEH);
+ if (!CmdFailed(cost) && v->owner == _local_player && cost != 0) ShowCostOrIncomeAnimation(v->x_pos, v->y_pos, v->z_pos, cost);
+
// Part of the orderlist?
if (HASBIT(t.flags, OFB_PART_OF_ORDERS)) {
v->cur_order_index++;
diff --git a/roadveh_gui.c b/roadveh_gui.c
index fa073b343..84f2ea030 100644
--- a/roadveh_gui.c
+++ b/roadveh_gui.c
@@ -321,7 +321,7 @@ static void RoadVehViewWndProc(Window *w, WindowEvent *e)
DoCommandP(v->tile, v->index, _ctrl_pressed ? 1 : 0, CcCloneRoadVeh, CMD_CLONE_VEHICLE | CMD_MSG(STR_9009_CAN_T_BUILD_ROAD_VEHICLE));
break;
case 12: /* Refit vehicle */
- ShowVehicleRefitWindow(v);
+ ShowVehicleRefitWindow(v, INVALID_VEH_ORDER_ID);
break;
}
} break;
diff --git a/saveload.c b/saveload.c
index bd19679e0..2f837e886 100644
--- a/saveload.c
+++ b/saveload.c
@@ -30,7 +30,7 @@
#include "variables.h"
#include <setjmp.h>
-const uint16 SAVEGAME_VERSION = 35;
+const uint16 SAVEGAME_VERSION = 36;
uint16 _sl_version; /// the major savegame version identifier
byte _sl_minor_version; /// the minor savegame version, DO NOT USE!
diff --git a/ship_cmd.c b/ship_cmd.c
index f39e5d6ac..913fa93ce 100644
--- a/ship_cmd.c
+++ b/ship_cmd.c
@@ -406,6 +406,7 @@ static void ShipEnterDepot(Vehicle *v)
if (v->current_order.type == OT_GOTO_DEPOT) {
Order t;
+ int32 cost;
InvalidateWindow(WC_VEHICLE_VIEW, v->index);
@@ -413,6 +414,10 @@ static void ShipEnterDepot(Vehicle *v)
v->current_order.type = OT_DUMMY;
v->current_order.flags = 0;
+ _current_player = v->owner;
+ cost = DoCommand(v->tile, v->index, t.refit_cargo | t.refit_subtype << 8, DC_EXEC, CMD_REFIT_SHIP);
+ if (!CmdFailed(cost) && v->owner == _local_player && cost != 0) ShowCostOrIncomeAnimation(v->x_pos, v->y_pos, v->z_pos, cost);
+
if (HASBIT(t.flags, OFB_PART_OF_ORDERS)) {
v->cur_order_index++;
} else if (HASBIT(t.flags, OFB_HALT_IN_DEPOT)) {
diff --git a/ship_gui.c b/ship_gui.c
index 9f6064317..7bb8cd284 100644
--- a/ship_gui.c
+++ b/ship_gui.c
@@ -450,7 +450,7 @@ static void ShipViewWndProc(Window *w, WindowEvent *e)
DoCommandP(v->tile, v->index, _ctrl_pressed ? DEPOT_SERVICE : 0, NULL, CMD_SEND_SHIP_TO_DEPOT | CMD_MSG(STR_9819_CAN_T_SEND_SHIP_TO_DEPOT));
break;
case 8: /* refit */
- ShowVehicleRefitWindow(v);
+ ShowVehicleRefitWindow(v, INVALID_VEH_ORDER_ID);
break;
case 9: /* show orders */
ShowOrdersWindow(v);
diff --git a/train_cmd.c b/train_cmd.c
index 5c1ce0eb7..5c1abe6ae 100644
--- a/train_cmd.c
+++ b/train_cmd.c
@@ -3494,6 +3494,7 @@ void TrainEnterDepot(Vehicle *v, TileIndex tile)
if (v->current_order.type == OT_GOTO_DEPOT) {
Order t;
+ int32 cost;
InvalidateWindow(WC_VEHICLE_VIEW, v->index);
@@ -3501,6 +3502,10 @@ void TrainEnterDepot(Vehicle *v, TileIndex tile)
v->current_order.type = OT_DUMMY;
v->current_order.flags = 0;
+ _current_player = v->owner;
+ cost = DoCommand(v->tile, v->index, t.refit_cargo | t.refit_subtype << 8, DC_EXEC, CMD_REFIT_RAIL_VEHICLE);
+ if (!CmdFailed(cost) && v->owner == _local_player && cost != 0) ShowCostOrIncomeAnimation(v->x_pos, v->y_pos, v->z_pos, cost);
+
if (HASBIT(t.flags, OFB_PART_OF_ORDERS)) { // Part of the orderlist?
v->u.rail.days_since_order_progr = 0;
v->cur_order_index++;
diff --git a/train_gui.c b/train_gui.c
index 98376a878..57b824835 100644
--- a/train_gui.c
+++ b/train_gui.c
@@ -543,7 +543,7 @@ static void TrainViewWndProc(Window *w, WindowEvent *e)
ShowTrainDetailsWindow(v);
break;
case 12:
- ShowVehicleRefitWindow(v);
+ ShowVehicleRefitWindow(v, INVALID_VEH_ORDER_ID);
break;
case 13:
DoCommandP(v->tile, v->index, _ctrl_pressed ? 1 : 0, NULL, CMD_CLONE_VEHICLE | CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE));
diff --git a/vehicle.c b/vehicle.c
index 5df0e616e..fc3c78c54 100644
--- a/vehicle.c
+++ b/vehicle.c
@@ -2806,6 +2806,10 @@ const SaveLoad _common_veh_desc[] = {
SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, flags), SLE_UINT8, 5, SL_MAX_VERSION),
SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, dest), SLE_UINT16, 5, SL_MAX_VERSION),
+ /* Refit in current order */
+ SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, refit_cargo), SLE_UINT8, 36, SL_MAX_VERSION),
+ SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, refit_subtype), SLE_UINT8, 36, SL_MAX_VERSION),
+
SLE_REF(Vehicle, orders, REF_ORDER),
SLE_CONDVAR(Vehicle, age, SLE_FILE_U16 | SLE_VAR_I32, 0, 30),
diff --git a/vehicle_gui.c b/vehicle_gui.c
index 9fab39658..0b56eb0cb 100644
--- a/vehicle_gui.c
+++ b/vehicle_gui.c
@@ -373,15 +373,20 @@ static void VehicleRefitWndProc(Window *w, WindowEvent *e)
case 6: // refit button
if (WP(w,refit_d).cargo != NULL) {
const Vehicle *v = GetVehicle(w->window_number);
- int command = 0;
- switch (v->type) {
- case VEH_Train: command = CMD_REFIT_RAIL_VEHICLE | CMD_MSG(STR_RAIL_CAN_T_REFIT_VEHICLE); break;
- case VEH_Road: command = CMD_REFIT_ROAD_VEH | CMD_MSG(STR_REFIT_ROAD_VEHICLE_CAN_T); break;
- case VEH_Ship: command = CMD_REFIT_SHIP | CMD_MSG(STR_9841_CAN_T_REFIT_SHIP); break;
- case VEH_Aircraft: command = CMD_REFIT_AIRCRAFT | CMD_MSG(STR_A042_CAN_T_REFIT_AIRCRAFT); break;
+ if (WP(w, refit_d).order == INVALID_VEH_ORDER_ID) {
+ int command = 0;
+
+ switch (v->type) {
+ case VEH_Train: command = CMD_REFIT_RAIL_VEHICLE | CMD_MSG(STR_RAIL_CAN_T_REFIT_VEHICLE); break;
+ case VEH_Road: command = CMD_REFIT_ROAD_VEH | CMD_MSG(STR_REFIT_ROAD_VEHICLE_CAN_T); break;
+ case VEH_Ship: command = CMD_REFIT_SHIP | CMD_MSG(STR_9841_CAN_T_REFIT_SHIP); break;
+ case VEH_Aircraft: command = CMD_REFIT_AIRCRAFT | CMD_MSG(STR_A042_CAN_T_REFIT_AIRCRAFT); break;
+ }
+ if (DoCommandP(v->tile, v->index, WP(w,refit_d).cargo->cargo | WP(w,refit_d).cargo->subtype << 8, NULL, command)) DeleteWindow(w);
+ } else {
+ if (DoCommandP(v->tile, v->index, WP(w,refit_d).cargo->cargo | WP(w,refit_d).cargo->subtype << 8 | WP(w, refit_d).order << 16, NULL, CMD_ORDER_REFIT)) DeleteWindow(w);
}
- if (DoCommandP(v->tile, v->index, WP(w,refit_d).cargo->cargo | WP(w,refit_d).cargo->subtype << 8, NULL, command)) DeleteWindow(w);
}
break;
}
@@ -423,7 +428,7 @@ static const WindowDesc _vehicle_refit_desc = {
/** Show the refit window for a vehicle
* @param *v The vehicle to show the refit window for
*/
-void ShowVehicleRefitWindow(const Vehicle *v)
+void ShowVehicleRefitWindow(const Vehicle *v, VehicleOrderID order)
{
Window *w;
@@ -432,6 +437,7 @@ void ShowVehicleRefitWindow(const Vehicle *v)
_alloc_wnd_parent_num = v->index;
w = AllocateWindowDesc(&_vehicle_refit_desc);
+ WP(w, refit_d).order = order;
if (w != NULL) {
w->window_number = v->index;
diff --git a/vehicle_gui.h b/vehicle_gui.h
index 1d01177da..564850648 100644
--- a/vehicle_gui.h
+++ b/vehicle_gui.h
@@ -6,7 +6,7 @@
#include "window.h"
void DrawVehicleProfitButton(const Vehicle *v, int x, int y);
-void ShowVehicleRefitWindow(const Vehicle *v);
+void ShowVehicleRefitWindow(const Vehicle *v, VehicleOrderID order);
void InitializeVehiclesGuiList(void);
/* sorter stuff */
diff --git a/window.h b/window.h
index 2197616f7..bd4bb2f08 100644
--- a/window.h
+++ b/window.h
@@ -5,6 +5,7 @@
#include "macros.h"
#include "string.h"
+#include "order.h"
typedef struct WindowEvent WindowEvent;
@@ -433,6 +434,7 @@ typedef struct {
struct RefitOption *cargo;
struct RefitList *list;
uint length;
+ VehicleOrderID order;
} refit_d;
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(refit_d));