Fix #12415, 9c49a61, df400ef: Aircraft::tile is valid only for front vehicle (#12416)

(cherry picked from commit 243c6bead3)

# Conflicts:
#	src/economy.cpp
pull/684/head
Loïc Guilloux 2 months ago committed by Jonathan G Rennison
parent 0008e7d769
commit 3cf43de059

@ -114,6 +114,7 @@ struct Aircraft final : public SpecializedVehicle<Aircraft, VEH_AIRCRAFT> {
void OnPeriodic() override; void OnPeriodic() override;
uint Crash(bool flooded = false) override; uint Crash(bool flooded = false) override;
TileIndex GetOrderStationLocation(StationID station) override; TileIndex GetOrderStationLocation(StationID station) override;
TileIndex GetCargoTile() const override { return this->First()->tile; }
ClosestDepot FindClosestDepot() override; ClosestDepot FindClosestDepot() override;
/** /**

@ -1569,7 +1569,7 @@ void PrepareUnload(Vehicle *front_v)
front_v->last_station_visited, next_station.Get(v->cargo_type), front_v->last_station_visited, next_station.Get(v->cargo_type),
GetUnloadType(v), ge, GetUnloadType(v), ge,
front_v->cargo_payment, front_v->cargo_payment,
v->tile); v->GetCargoTile());
if (v->cargo.UnloadCount() > 0) SetBit(v->vehicle_flags, VF_CARGO_UNLOADING); if (v->cargo.UnloadCount() > 0) SetBit(v->vehicle_flags, VF_CARGO_UNLOADING);
} }
} }
@ -1727,7 +1727,7 @@ struct ReturnCargoAction
*/ */
bool operator()(Vehicle *v) bool operator()(Vehicle *v)
{ {
v->cargo.Return(UINT_MAX, &this->st->goods[v->cargo_type].CreateData().cargo, this->next_hop, v->tile); v->cargo.Return(UINT_MAX, &this->st->goods[v->cargo_type].CreateData().cargo, this->next_hop, v->GetCargoTile());
return true; return true;
} }
}; };
@ -1764,7 +1764,7 @@ struct FinalizeRefitAction
{ {
if (this->do_reserve || (cargo_type_loading == nullptr || (cargo_type_loading->current_order.GetCargoLoadTypeRaw(v->cargo_type) & OLFB_FULL_LOAD))) { if (this->do_reserve || (cargo_type_loading == nullptr || (cargo_type_loading->current_order.GetCargoLoadTypeRaw(v->cargo_type) & OLFB_FULL_LOAD))) {
this->st->goods[v->cargo_type].CreateData().cargo.Reserve(v->cargo_cap - v->cargo.RemainingCount(), this->st->goods[v->cargo_type].CreateData().cargo.Reserve(v->cargo_cap - v->cargo.RemainingCount(),
&v->cargo, this->next_station.Get(v->cargo_type), v->tile); &v->cargo, this->next_station.Get(v->cargo_type), v->GetCargoTile());
} }
this->consist_capleft[v->cargo_type] += v->cargo_cap - v->cargo.RemainingCount(); this->consist_capleft[v->cargo_type] += v->cargo_cap - v->cargo.RemainingCount();
return true; return true;
@ -1869,7 +1869,7 @@ struct ReserveCargoAction {
} }
if (v->cargo_cap > v->cargo.RemainingCount() && MayLoadUnderExclusiveRights(st, v)) { if (v->cargo_cap > v->cargo.RemainingCount() && MayLoadUnderExclusiveRights(st, v)) {
st->goods[v->cargo_type].CreateData().cargo.Reserve(v->cargo_cap - v->cargo.RemainingCount(), st->goods[v->cargo_type].CreateData().cargo.Reserve(v->cargo_cap - v->cargo.RemainingCount(),
&v->cargo, next_station.Get(v->cargo_type), v->tile); &v->cargo, next_station.Get(v->cargo_type), v->GetCargoTile());
} }
return true; return true;
@ -2107,7 +2107,7 @@ static void LoadUnloadVehicle(Vehicle *front)
uint new_remaining = v->cargo.RemainingCount() + v->cargo.ActionCount(VehicleCargoList::MTA_DELIVER); uint new_remaining = v->cargo.RemainingCount() + v->cargo.ActionCount(VehicleCargoList::MTA_DELIVER);
if (v->cargo_cap < new_remaining) { if (v->cargo_cap < new_remaining) {
/* Return some of the reserved cargo to not overload the vehicle. */ /* Return some of the reserved cargo to not overload the vehicle. */
v->cargo.Return(new_remaining - v->cargo_cap, &ged->cargo, INVALID_STATION, v->tile); v->cargo.Return(new_remaining - v->cargo_cap, &ged->cargo, INVALID_STATION, v->GetCargoTile());
} }
/* Keep instead of delivering. This may lead to no cargo being unloaded, so ...*/ /* Keep instead of delivering. This may lead to no cargo being unloaded, so ...*/
@ -2134,7 +2134,7 @@ static void LoadUnloadVehicle(Vehicle *front)
} }
} }
amount_unloaded = v->cargo.Unload(amount_unloaded, &ged->cargo, payment, v->tile); amount_unloaded = v->cargo.Unload(amount_unloaded, &ged->cargo, payment, v->GetCargoTile());
remaining = v->cargo.UnloadCount() > 0; remaining = v->cargo.UnloadCount() > 0;
if (amount_unloaded > 0) { if (amount_unloaded > 0) {
dirty_vehicle = true; dirty_vehicle = true;
@ -2210,7 +2210,7 @@ static void LoadUnloadVehicle(Vehicle *front)
if (v->cargo.StoredCount() == 0) TriggerVehicle(v, VEHICLE_TRIGGER_NEW_CARGO); if (v->cargo.StoredCount() == 0) TriggerVehicle(v, VEHICLE_TRIGGER_NEW_CARGO);
if (_settings_game.order.gradual_loading) cap_left = std::min(cap_left, GetLoadAmount(v)); if (_settings_game.order.gradual_loading) cap_left = std::min(cap_left, GetLoadAmount(v));
uint loaded = ged->cargo.Load(cap_left, &v->cargo, next_station.Get(v->cargo_type), v->tile); uint loaded = ged->cargo.Load(cap_left, &v->cargo, next_station.Get(v->cargo_type), v->GetCargoTile());
if (v->cargo.ActionCount(VehicleCargoList::MTA_LOAD) > 0) { if (v->cargo.ActionCount(VehicleCargoList::MTA_LOAD) > 0) {
/* Remember if there are reservations left so that we don't stop /* Remember if there are reservations left so that we don't stop
* loading before they're loaded. */ * loading before they're loaded. */

@ -957,6 +957,8 @@ public:
*/ */
virtual TileIndex GetOrderStationLocation([[maybe_unused]] StationID station) { return INVALID_TILE; } virtual TileIndex GetOrderStationLocation([[maybe_unused]] StationID station) { return INVALID_TILE; }
virtual TileIndex GetCargoTile() const { return this->tile; }
/** /**
* Find the closest depot for this vehicle and tell us the location, * Find the closest depot for this vehicle and tell us the location,
* DestinationID and whether we should reverse. * DestinationID and whether we should reverse.

Loading…
Cancel
Save