diff options
author | bjarni <bjarni@openttd.org> | 2005-01-28 20:43:46 +0000 |
---|---|---|
committer | bjarni <bjarni@openttd.org> | 2005-01-28 20:43:46 +0000 |
commit | 27cd24c3169eb5bc254e32ee294dd560b3b9079a (patch) | |
tree | 480d6c6171b342086abb399d6072b02b8dc31d37 /ship_cmd.c | |
parent | 41ca1be4ffcd91a3e4d1d27c4a1cd461611bee2a (diff) | |
download | openttd-27cd24c3169eb5bc254e32ee294dd560b3b9079a.tar.xz |
(svn r1709) - Feature: [autoreplace] ships now automatically goes to a depot if they need to be replaced
Diffstat (limited to 'ship_cmd.c')
-rw-r--r-- | ship_cmd.c | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/ship_cmd.c b/ship_cmd.c index a0efa79aa..0a12aa290 100644 --- a/ship_cmd.c +++ b/ship_cmd.c @@ -87,10 +87,10 @@ static void CheckIfShipNeedsService(Vehicle *v) { int i; - if (_patches.servint_ships == 0) + if (_patches.servint_ships == 0 && !v->set_for_replacement) return; - if (!VehicleNeedsService(v)) + if (!VehicleNeedsService(v) && !v->set_for_replacement) return; if (v->vehstatus & VS_STOPPED) @@ -215,7 +215,7 @@ static void ProcessShipOrder(Vehicle *v) if (v->current_order.type == OT_GOTO_DEPOT && (v->current_order.flags & (OF_UNLOAD | OF_FULL_LOAD)) == (OF_UNLOAD | OF_FULL_LOAD) && - !VehicleNeedsService(v)) { + !VehicleNeedsService(v) && !v->set_for_replacement) { v->cur_order_index++; } @@ -286,6 +286,21 @@ static void HandleShipLoading(Vehicle *v) Order b = v->current_order; v->current_order.type = OT_LEAVESTATION; v->current_order.flags = 0; + + if (v->current_order.type != OT_GOTO_DEPOT && v->owner == _local_player) { + // only the vehicle owner needs to calculate the rest (locally) + if ((_autoreplace_array[v->engine_type] != v->engine_type) || + (_patches.autorenew && v->age - v->max_age > (_patches.autorenew_months * 30))) { + byte flags = 1; + // the flags means, bit 0 = needs to go to depot, bit 1 = have depot in orders + if (VehicleHasDepotOrders(v)) SETBIT(flags, 1); + if (!(HASBIT(flags, 1) && v->set_for_replacement)) { + _current_player = _local_player; + DoCommandP(v->tile, v->index, flags, NULL, CMD_SEND_SHIP_TO_DEPOT | CMD_SHOW_NO_ERROR); + _current_player = OWNER_NONE; + } + } + } if (!(b.flags & OF_NON_STOP)) return; } @@ -932,6 +947,9 @@ int32 CmdStartStopShip(int x, int y, uint32 flags, uint32 p1, uint32 p2) return 0; } +/* Send a ship to the nearest depot + p1 = index of the ship + p2 = bit 0 = do not stop in depot, bit 1 = have depot in orders */ int32 CmdSendShipToDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2) { Vehicle *v; @@ -942,6 +960,10 @@ int32 CmdSendShipToDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2) if (!CheckOwnership(v->owner)) return CMD_ERROR; + if (HASBIT(p2, 0)) v->set_for_replacement = true; + + if (HASBIT(p2, 1)) return CMD_ERROR; // vehicle has a depot in schedule. It just needed to set set_for_replacement + if (v->current_order.type == OT_GOTO_DEPOT) { if (flags & DC_EXEC) { if (v->current_order.flags & OF_UNLOAD) v->cur_order_index++; @@ -957,7 +979,7 @@ int32 CmdSendShipToDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2) if (flags & DC_EXEC) { v->dest_tile = _depots[depot].xy; v->current_order.type = OT_GOTO_DEPOT; - v->current_order.flags = OF_NON_STOP | OF_FULL_LOAD; + v->current_order.flags = HASBIT(p2, 0) ? 0 : OF_NON_STOP | OF_FULL_LOAD; v->current_order.station = depot; InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); } |