Skip to content

Commit

Permalink
Fix OpenTTD#12415, 9c49a61, df400ef: Aircraft::tile is valid only for…
Browse files Browse the repository at this point in the history
… front vehicle (OpenTTD#12416)
  • Loading branch information
glx22 authored Apr 3, 2024
1 parent 931aa39 commit 243c6be
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/aircraft.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ struct Aircraft final : public SpecializedVehicle<Aircraft, VEH_AIRCRAFT> {
void OnNewEconomyDay() override;
uint Crash(bool flooded = false) override;
TileIndex GetOrderStationLocation(StationID station) override;
TileIndex GetCargoTile() const override { return this->First()->tile; }
ClosestDepot FindClosestDepot() override;

/**
Expand Down
14 changes: 7 additions & 7 deletions src/economy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@ void PrepareUnload(Vehicle *front_v)
front_v->last_station_visited, next_station,
front_v->current_order.GetUnloadType(), ge,
front_v->cargo_payment,
v->tile);
v->GetCargoTile());
if (v->cargo.UnloadCount() > 0) SetBit(v->vehicle_flags, VF_CARGO_UNLOADING);
}
}
Expand Down Expand Up @@ -1441,7 +1441,7 @@ struct ReturnCargoAction
*/
bool operator()(Vehicle *v)
{
v->cargo.Return(UINT_MAX, &this->st->goods[v->cargo_type].cargo, this->next_hop, v->tile);
v->cargo.Return(UINT_MAX, &this->st->goods[v->cargo_type].cargo, this->next_hop, v->GetCargoTile());
return true;
}
};
Expand Down Expand Up @@ -1476,7 +1476,7 @@ struct FinalizeRefitAction
{
if (this->do_reserve) {
this->st->goods[v->cargo_type].cargo.Reserve(v->cargo_cap - v->cargo.RemainingCount(),
&v->cargo, this->next_station, v->tile);
&v->cargo, this->next_station, v->GetCargoTile());
}
this->consist_capleft[v->cargo_type] += v->cargo_cap - v->cargo.RemainingCount();
return true;
Expand Down Expand Up @@ -1567,7 +1567,7 @@ struct ReserveCargoAction {
{
if (v->cargo_cap > v->cargo.RemainingCount() && MayLoadUnderExclusiveRights(st, v)) {
st->goods[v->cargo_type].cargo.Reserve(v->cargo_cap - v->cargo.RemainingCount(),
&v->cargo, *next_station, v->tile);
&v->cargo, *next_station, v->GetCargoTile());
}

return true;
Expand Down Expand Up @@ -1701,7 +1701,7 @@ static void LoadUnloadVehicle(Vehicle *front)
uint new_remaining = v->cargo.RemainingCount() + v->cargo.ActionCount(VehicleCargoList::MTA_DELIVER);
if (v->cargo_cap < new_remaining) {
/* Return some of the reserved cargo to not overload the vehicle. */
v->cargo.Return(new_remaining - v->cargo_cap, &ge->cargo, INVALID_STATION, v->tile);
v->cargo.Return(new_remaining - v->cargo_cap, &ge->cargo, INVALID_STATION, v->GetCargoTile());
}

/* Keep instead of delivering. This may lead to no cargo being unloaded, so ...*/
Expand All @@ -1728,7 +1728,7 @@ static void LoadUnloadVehicle(Vehicle *front)
}
}

amount_unloaded = v->cargo.Unload(amount_unloaded, &ge->cargo, payment, v->tile);
amount_unloaded = v->cargo.Unload(amount_unloaded, &ge->cargo, payment, v->GetCargoTile());
remaining = v->cargo.UnloadCount() > 0;
if (amount_unloaded > 0) {
dirty_vehicle = true;
Expand Down Expand Up @@ -1798,7 +1798,7 @@ static void LoadUnloadVehicle(Vehicle *front)
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));

uint loaded = ge->cargo.Load(cap_left, &v->cargo, next_station, v->tile);
uint loaded = ge->cargo.Load(cap_left, &v->cargo, next_station, v->GetCargoTile());
if (v->cargo.ActionCount(VehicleCargoList::MTA_LOAD) > 0) {
/* Remember if there are reservations left so that we don't stop
* loading before they're loaded. */
Expand Down
2 changes: 2 additions & 0 deletions src/vehicle_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,8 @@ struct Vehicle : VehiclePool::PoolItem<&_vehicle_pool>, BaseVehicle, BaseConsist
*/
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,
* DestinationID and whether we should reverse.
Expand Down

0 comments on commit 243c6be

Please sign in to comment.