summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2005-01-28 17:31:42 +0000
committerbjarni <bjarni@openttd.org>2005-01-28 17:31:42 +0000
commit6d52ee4962db5e1cbadf279a614d4eb02e18189a (patch)
tree18486d264af3219fdac58f0ba6d0b556c9884830
parent400f07fdb834dc99aa8a2a4695e20b36e5d23dc4 (diff)
downloadopenttd-6d52ee4962db5e1cbadf279a614d4eb02e18189a.tar.xz
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
-rw-r--r--roadveh_cmd.c35
1 files changed, 30 insertions, 5 deletions
diff --git a/roadveh_cmd.c b/roadveh_cmd.c
index 69cb01188..9fa910cab 100644
--- a/roadveh_cmd.c
+++ b/roadveh_cmd.c
@@ -291,6 +291,9 @@ static int FindClosestRoadDepot(Vehicle *v)
return GetDepotByTile(rfdd.tile);
}
+/* Send a road vehicle to the nearest depot
+ p1 = index of the road vehicle
+ p2 = bit 0 = do not stop in depot, bit 1 = have depot in orders */
int32 CmdSendRoadVehToDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
Vehicle *v = GetVehicle(p1);
@@ -299,6 +302,10 @@ int32 CmdSendRoadVehToDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (v->type != VEH_Road || !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)
@@ -316,7 +323,7 @@ int32 CmdSendRoadVehToDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (flags & DC_EXEC) {
v->current_order.type = OT_GOTO_DEPOT;
- v->current_order.flags = OF_NON_STOP | OF_FULL_LOAD;
+ v->current_order.flags = p2 == 0 ? OF_NON_STOP | OF_FULL_LOAD : 0;
v->current_order.station = (byte)depot;
v->dest_tile = _depots[depot].xy;
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
@@ -568,7 +575,7 @@ static void ProcessRoadVehOrder(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++;
}
@@ -638,6 +645,21 @@ static void HandleRoadVehLoading(Vehicle *v)
v->cur_order_index++;
InvalidateVehicleOrder(v);
+
+ 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_ROADVEH_TO_DEPOT | CMD_SHOW_NO_ERROR);
+ _current_player = OWNER_NONE;
+ }
+ }
+ }
}
static void StartRoadVehSound(Vehicle *v)
@@ -1431,10 +1453,10 @@ static void CheckIfRoadVehNeedsService(Vehicle *v)
{
int i;
- if (_patches.servint_roadveh == 0)
+ if (_patches.servint_roadveh == 0 && !v->set_for_replacement)
return;
- if (!VehicleNeedsService(v))
+ if (!VehicleNeedsService(v) && !v->set_for_replacement)
return;
if (v->vehstatus & VS_STOPPED)
@@ -1452,7 +1474,10 @@ static void CheckIfRoadVehNeedsService(Vehicle *v)
i = FindClosestRoadDepot(v);
if (i < 0 || GetTileDist(v->tile, (&_depots[i])->xy) > 12) {
- if (v->current_order.type == OT_GOTO_DEPOT) {
+ if (v->current_order.type == OT_GOTO_DEPOT && !(
+ GetTileDist(v->tile, v->dest_tile) > 25 && v->set_for_replacement)) {
+ /* a vehicle needs a greater distance to a depot to loose it than to find it since
+ they can circle forever othervise if they are in a loop with an unlucky distance */
v->current_order.type = OT_DUMMY;
v->current_order.flags = 0;
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);