mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
This commit is contained in:
parent
65fedf0cfb
commit
5eb5889954
|
@ -126,6 +126,7 @@ struct Aircraft : public Vehicle {
|
||||||
bool IsInDepot() const { return (this->vehstatus & VS_HIDDEN) != 0 && IsHangarTile(this->tile); }
|
bool IsInDepot() const { return (this->vehstatus & VS_HIDDEN) != 0 && IsHangarTile(this->tile); }
|
||||||
void Tick();
|
void Tick();
|
||||||
void OnNewDay();
|
void OnNewDay();
|
||||||
|
TileIndex GetOrderStationLocation(StationID station);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* AIRCRAFT_H */
|
#endif /* AIRCRAFT_H */
|
||||||
|
|
|
@ -1361,74 +1361,48 @@ static void HandleAircraftSmoke(Vehicle *v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ProcessAircraftOrder(Vehicle *v)
|
void HandleMissingAircraftOrders(Vehicle *v)
|
||||||
{
|
{
|
||||||
switch (v->current_order.type) {
|
/*
|
||||||
case OT_GOTO_DEPOT:
|
* We do not have an order. This can be divided into two cases:
|
||||||
if (!(v->current_order.flags & OFB_PART_OF_ORDERS)) return;
|
* 1) we are heading to an invalid station. In this case we must
|
||||||
if (v->current_order.flags & OFB_SERVICE_IF_NEEDED &&
|
* find another airport to go to. If there is nowhere to go,
|
||||||
!VehicleNeedsService(v)) {
|
* we will destroy the aircraft as it otherwise will enter
|
||||||
UpdateVehicleTimetable(v, true);
|
* the holding pattern for the first airport, which can cause
|
||||||
v->cur_order_index++;
|
* the plane to go into an undefined state when building an
|
||||||
}
|
* airport with the same StationID.
|
||||||
break;
|
* 2) we are (still) heading to a (still) valid airport, then we
|
||||||
|
* can continue going there. This can happen when you are
|
||||||
|
* changing the aircraft's orders while in-flight or in for
|
||||||
|
* example a depot. However, when we have a current order to
|
||||||
|
* go to a depot, we have to keep that order so the aircraft
|
||||||
|
* actually stops.
|
||||||
|
*/
|
||||||
|
const Station *st = GetStation(v->u.air.targetairport);
|
||||||
|
if (!st->IsValid() || st->airport_tile == 0) {
|
||||||
|
CommandCost ret;
|
||||||
|
PlayerID old_player = _current_player;
|
||||||
|
|
||||||
case OT_LOADING: return;
|
_current_player = v->owner;
|
||||||
|
ret = DoCommand(v->tile, v->index, 0, DC_EXEC, CMD_SEND_AIRCRAFT_TO_HANGAR);
|
||||||
|
_current_player = old_player;
|
||||||
|
|
||||||
default: break;
|
if (CmdFailed(ret)) CrashAirplane(v);
|
||||||
|
} else if (v->current_order.type != OT_GOTO_DEPOT) {
|
||||||
|
v->current_order.Free();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TileIndex Aircraft::GetOrderStationLocation(StationID station)
|
||||||
|
{
|
||||||
|
/* Orders are changed in flight, ensure going to the right station. */
|
||||||
|
if (this->u.air.state == FLYING) {
|
||||||
|
AircraftNextAirportPos_and_Order(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (v->cur_order_index >= v->num_orders) v->cur_order_index = 0;
|
/* Aircraft do not use dest-tile */
|
||||||
|
return 0;
|
||||||
const Order *order = GetVehicleOrder(v, v->cur_order_index);
|
|
||||||
|
|
||||||
if (order == NULL|| (order->type == OT_DUMMY && !CheckForValidOrders(v))) {
|
|
||||||
/*
|
|
||||||
* We do not have an order. This can be divided into two cases:
|
|
||||||
* 1) we are heading to an invalid station. In this case we must
|
|
||||||
* find another airport to go to. If there is nowhere to go,
|
|
||||||
* we will destroy the aircraft as it otherwise will enter
|
|
||||||
* the holding pattern for the first airport, which can cause
|
|
||||||
* the plane to go into an undefined state when building an
|
|
||||||
* airport with the same StationID.
|
|
||||||
* 2) we are (still) heading to a (still) valid airport, then we
|
|
||||||
* can continue going there. This can happen when you are
|
|
||||||
* changing the aircraft's orders while in-flight or in for
|
|
||||||
* example a depot. However, when we have a current order to
|
|
||||||
* go to a depot, we have to keep that order so the aircraft
|
|
||||||
* actually stops.
|
|
||||||
*/
|
|
||||||
const Station *st = GetStation(v->u.air.targetairport);
|
|
||||||
if (!st->IsValid() || st->airport_tile == 0) {
|
|
||||||
CommandCost ret;
|
|
||||||
PlayerID old_player = _current_player;
|
|
||||||
|
|
||||||
_current_player = v->owner;
|
|
||||||
ret = DoCommand(v->tile, v->index, 0, DC_EXEC, CMD_SEND_AIRCRAFT_TO_HANGAR);
|
|
||||||
_current_player = old_player;
|
|
||||||
|
|
||||||
if (CmdFailed(ret)) CrashAirplane(v);
|
|
||||||
} else if (v->current_order.type != OT_GOTO_DEPOT) {
|
|
||||||
v->current_order.Free();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (order->type == v->current_order.type &&
|
|
||||||
order->flags == v->current_order.flags &&
|
|
||||||
order->dest == v->current_order.dest)
|
|
||||||
return;
|
|
||||||
|
|
||||||
v->current_order = *order;
|
|
||||||
|
|
||||||
/* orders are changed in flight, ensure going to the right station */
|
|
||||||
if (order->type == OT_GOTO_STATION && v->u.air.state == FLYING) {
|
|
||||||
AircraftNextAirportPos_and_Order(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
InvalidateVehicleOrder(v);
|
|
||||||
|
|
||||||
InvalidateWindowClasses(WC_AIRCRAFT_LIST);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Aircraft::MarkDirty()
|
void Aircraft::MarkDirty()
|
||||||
|
@ -2149,7 +2123,7 @@ static void AircraftEventHandler(Vehicle *v, int loop)
|
||||||
}
|
}
|
||||||
|
|
||||||
HandleAircraftSmoke(v);
|
HandleAircraftSmoke(v);
|
||||||
ProcessAircraftOrder(v);
|
ProcessOrders(v);
|
||||||
v->HandleLoading(loop != 0);
|
v->HandleLoading(loop != 0);
|
||||||
|
|
||||||
if (v->current_order.type >= OT_LOADING) return;
|
if (v->current_order.type >= OT_LOADING) return;
|
||||||
|
|
|
@ -1277,6 +1277,22 @@ Date GetServiceIntervalClamped(uint index)
|
||||||
return (_patches.servint_ispercent) ? Clamp(index, MIN_SERVINT_PERCENT, MAX_SERVINT_PERCENT) : Clamp(index, MIN_SERVINT_DAYS, MAX_SERVINT_DAYS);
|
return (_patches.servint_ispercent) ? Clamp(index, MIN_SERVINT_PERCENT, MAX_SERVINT_PERCENT) : Clamp(index, MIN_SERVINT_DAYS, MAX_SERVINT_DAYS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Check if a vehicle has any valid orders
|
||||||
|
*
|
||||||
|
* @return false if there are no valid orders
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static bool CheckForValidOrders(const Vehicle *v)
|
||||||
|
{
|
||||||
|
const Order *order;
|
||||||
|
|
||||||
|
FOR_VEHICLE_ORDERS(v, order) if (order->type != OT_DUMMY) return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle the orders of a vehicle and determine the next place
|
* Handle the orders of a vehicle and determine the next place
|
||||||
* to go to if needed.
|
* to go to if needed.
|
||||||
|
@ -1298,9 +1314,12 @@ bool ProcessOrders(Vehicle *v)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OT_LOADING:
|
case OT_LOADING:
|
||||||
case OT_LEAVESTATION:
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
case OT_LEAVESTATION:
|
||||||
|
if (v->type != VEH_AIRCRAFT) return false;
|
||||||
|
break;
|
||||||
|
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1334,7 +1353,14 @@ bool ProcessOrders(Vehicle *v)
|
||||||
const Order *order = GetVehicleOrder(v, v->cur_order_index);
|
const Order *order = GetVehicleOrder(v, v->cur_order_index);
|
||||||
|
|
||||||
/* If no order, do nothing. */
|
/* If no order, do nothing. */
|
||||||
if (order == NULL) {
|
if (order == NULL || (v->type == VEH_AIRCRAFT && order->type == OT_DUMMY && !CheckForValidOrders(v))) {
|
||||||
|
if (v->type == VEH_AIRCRAFT) {
|
||||||
|
/* Aircraft do something vastly different here, so handle separately */
|
||||||
|
extern void HandleMissingAircraftOrders(Vehicle *v);
|
||||||
|
HandleMissingAircraftOrders(v);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
v->current_order.Free();
|
v->current_order.Free();
|
||||||
v->dest_tile = 0;
|
v->dest_tile = 0;
|
||||||
if (v->type == VEH_ROAD) ClearSlot(v);
|
if (v->type == VEH_ROAD) ClearSlot(v);
|
||||||
|
@ -1361,6 +1387,7 @@ bool ProcessOrders(Vehicle *v)
|
||||||
case VEH_TRAIN:
|
case VEH_TRAIN:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case VEH_AIRCRAFT:
|
||||||
case VEH_SHIP:
|
case VEH_SHIP:
|
||||||
InvalidateWindowClasses(v->GetVehicleListWindowClass());
|
InvalidateWindowClasses(v->GetVehicleListWindowClass());
|
||||||
break;
|
break;
|
||||||
|
@ -1368,14 +1395,11 @@ bool ProcessOrders(Vehicle *v)
|
||||||
|
|
||||||
switch (order->type) {
|
switch (order->type) {
|
||||||
case OT_GOTO_STATION:
|
case OT_GOTO_STATION:
|
||||||
if (order->dest == v->last_station_visited) {
|
|
||||||
v->last_station_visited = INVALID_STATION;
|
|
||||||
}
|
|
||||||
v->dest_tile = v->GetOrderStationLocation(order->dest);
|
v->dest_tile = v->GetOrderStationLocation(order->dest);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OT_GOTO_DEPOT:
|
case OT_GOTO_DEPOT:
|
||||||
v->dest_tile = GetDepot(order->dest)->xy;
|
if (v->type != VEH_AIRCRAFT) v->dest_tile = GetDepot(order->dest)->xy;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OT_GOTO_WAYPOINT:
|
case OT_GOTO_WAYPOINT:
|
||||||
|
@ -1390,22 +1414,6 @@ bool ProcessOrders(Vehicle *v)
|
||||||
return may_reverse;
|
return may_reverse;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Check if a vehicle has any valid orders
|
|
||||||
*
|
|
||||||
* @return false if there are no valid orders
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
bool CheckForValidOrders(const Vehicle* v)
|
|
||||||
{
|
|
||||||
const Order *order;
|
|
||||||
|
|
||||||
FOR_VEHICLE_ORDERS(v, order) if (order->type != OT_DUMMY) return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void InitializeOrders()
|
void InitializeOrders()
|
||||||
{
|
{
|
||||||
_Order_pool.CleanPool();
|
_Order_pool.CleanPool();
|
||||||
|
|
|
@ -35,7 +35,6 @@ void InvalidateVehicleOrder(const Vehicle *v);
|
||||||
bool VehicleHasDepotOrders(const Vehicle *v);
|
bool VehicleHasDepotOrders(const Vehicle *v);
|
||||||
void CheckOrders(const Vehicle*);
|
void CheckOrders(const Vehicle*);
|
||||||
void DeleteVehicleOrders(Vehicle *v);
|
void DeleteVehicleOrders(Vehicle *v);
|
||||||
bool CheckForValidOrders(const Vehicle* v);
|
|
||||||
bool ProcessOrders(Vehicle *v);
|
bool ProcessOrders(Vehicle *v);
|
||||||
|
|
||||||
#define MIN_SERVINT_PERCENT 5
|
#define MIN_SERVINT_PERCENT 5
|
||||||
|
|
|
@ -756,8 +756,9 @@ static void HandleBrokenRoadVeh(Vehicle *v)
|
||||||
|
|
||||||
TileIndex RoadVehicle::GetOrderStationLocation(StationID station)
|
TileIndex RoadVehicle::GetOrderStationLocation(StationID station)
|
||||||
{
|
{
|
||||||
TileIndex dest = INVALID_TILE;
|
if (station == this->last_station_visited) this->last_station_visited = INVALID_STATION;
|
||||||
|
|
||||||
|
TileIndex dest = INVALID_TILE;
|
||||||
const RoadStop *rs = GetStation(station)->GetPrimaryRoadStop(this);
|
const RoadStop *rs = GetStation(station)->GetPrimaryRoadStop(this);
|
||||||
if (rs != NULL) {
|
if (rs != NULL) {
|
||||||
uint mindist = MAX_UVALUE(uint);
|
uint mindist = MAX_UVALUE(uint);
|
||||||
|
|
|
@ -244,6 +244,8 @@ void Ship::PlayLeaveStationSound() const
|
||||||
|
|
||||||
TileIndex Ship::GetOrderStationLocation(StationID station)
|
TileIndex Ship::GetOrderStationLocation(StationID station)
|
||||||
{
|
{
|
||||||
|
if (station == this->last_station_visited) this->last_station_visited = INVALID_STATION;
|
||||||
|
|
||||||
Station *st = GetStation(station);
|
Station *st = GetStation(station);
|
||||||
if (st->dock_tile != 0) {
|
if (st->dock_tile != 0) {
|
||||||
return TILE_ADD(st->dock_tile, ToTileIndexDiff(GetDockOffset(st->dock_tile)));
|
return TILE_ADD(st->dock_tile, ToTileIndexDiff(GetDockOffset(st->dock_tile)));
|
||||||
|
|
|
@ -2617,6 +2617,8 @@ bad:;
|
||||||
|
|
||||||
TileIndex Train::GetOrderStationLocation(StationID station)
|
TileIndex Train::GetOrderStationLocation(StationID station)
|
||||||
{
|
{
|
||||||
|
if (station == this->last_station_visited) this->last_station_visited = INVALID_STATION;
|
||||||
|
|
||||||
return GetStation(station)->xy;
|
return GetStation(station)->xy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue