summaryrefslogtreecommitdiff
path: root/order_cmd.c
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2006-10-03 14:52:39 +0000
committerbjarni <bjarni@openttd.org>2006-10-03 14:52:39 +0000
commitea63050d5f6e33e32917ff0df670638197a5ec05 (patch)
tree2957d8696ffee8fa709210c52f0ada2ce013e1bd /order_cmd.c
parent7b1053c35044e32ef959f3d8ef7a2e3ba06c9568 (diff)
downloadopenttd-ea63050d5f6e33e32917ff0df670638197a5ec05.tar.xz
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
Example: make a train transport iron ore from A to B, then it visits a depot and refits to steel It then transport steel back to A or near A if there is a factory and then it visits another depot to refit to iron ore again This is controlled in the orders. If a goto depot order is lightlighted, then "Unload" changes to "Refit" Control click "Refit" removes the refit part of the order (as the tooltip says) The player will still pay the normal refit costs Known issues: If a vehicle is not in a depot, then the refit window will fail to tell refitted cargo capacity Refit costs in the refit window can sometimes print 0 when it should not because the refit calculation is unaware that the vehicle will be refitted in between Warning: autoreplace got a protection against replacing something so you get a new cargo type, but it can fail here. In the iron ore/steel example, it can see that the vehicle carries iron ore and the new one can be refitted to iron ore, then it will replace. It will not check to see that it's valid for steel as well. This is something to look into in the future
Diffstat (limited to 'order_cmd.c')
-rw-r--r--order_cmd.c58
1 files changed, 56 insertions, 2 deletions
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()
};