mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-04 06:00:15 +00:00
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
This commit is contained in:
parent
400f07fdb8
commit
6d52ee4962
@ -291,6 +291,9 @@ static int FindClosestRoadDepot(Vehicle *v)
|
|||||||
return GetDepotByTile(rfdd.tile);
|
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)
|
int32 CmdSendRoadVehToDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
{
|
{
|
||||||
Vehicle *v = GetVehicle(p1);
|
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))
|
if (v->type != VEH_Road || !CheckOwnership(v->owner))
|
||||||
return CMD_ERROR;
|
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 (v->current_order.type == OT_GOTO_DEPOT) {
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
if (v->current_order.flags & OF_UNLOAD)
|
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) {
|
if (flags & DC_EXEC) {
|
||||||
v->current_order.type = OT_GOTO_DEPOT;
|
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->current_order.station = (byte)depot;
|
||||||
v->dest_tile = _depots[depot].xy;
|
v->dest_tile = _depots[depot].xy;
|
||||||
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
|
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 &&
|
if (v->current_order.type == OT_GOTO_DEPOT &&
|
||||||
(v->current_order.flags & (OF_UNLOAD | OF_FULL_LOAD)) == (OF_UNLOAD | OF_FULL_LOAD) &&
|
(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++;
|
v->cur_order_index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -638,6 +645,21 @@ static void HandleRoadVehLoading(Vehicle *v)
|
|||||||
|
|
||||||
v->cur_order_index++;
|
v->cur_order_index++;
|
||||||
InvalidateVehicleOrder(v);
|
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)
|
static void StartRoadVehSound(Vehicle *v)
|
||||||
@ -1431,10 +1453,10 @@ static void CheckIfRoadVehNeedsService(Vehicle *v)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (_patches.servint_roadveh == 0)
|
if (_patches.servint_roadveh == 0 && !v->set_for_replacement)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!VehicleNeedsService(v))
|
if (!VehicleNeedsService(v) && !v->set_for_replacement)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (v->vehstatus & VS_STOPPED)
|
if (v->vehstatus & VS_STOPPED)
|
||||||
@ -1452,7 +1474,10 @@ static void CheckIfRoadVehNeedsService(Vehicle *v)
|
|||||||
i = FindClosestRoadDepot(v);
|
i = FindClosestRoadDepot(v);
|
||||||
|
|
||||||
if (i < 0 || GetTileDist(v->tile, (&_depots[i])->xy) > 12) {
|
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.type = OT_DUMMY;
|
||||||
v->current_order.flags = 0;
|
v->current_order.flags = 0;
|
||||||
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
|
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
|
||||||
|
Loading…
Reference in New Issue
Block a user