mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-10-31 15:20:10 +00:00
Codechange: remove loaded_at_xy from CargoPacket as it was unused (#11276)
This commit is contained in:
parent
f3b4f9d640
commit
b0e73277d6
@ -120,7 +120,6 @@ bool CargoLoad::operator()(CargoPacket *cp)
|
||||
{
|
||||
CargoPacket *cp_new = this->Preprocess(cp);
|
||||
if (cp_new == nullptr) return false;
|
||||
cp_new->SetLoadPlace(this->load_place);
|
||||
this->source->RemoveFromCache(cp_new, cp_new->Count());
|
||||
this->destination->Append(cp_new, VehicleCargoList::MTA_KEEP);
|
||||
return cp_new == cp;
|
||||
@ -135,7 +134,6 @@ bool CargoReservation::operator()(CargoPacket *cp)
|
||||
{
|
||||
CargoPacket *cp_new = this->Preprocess(cp);
|
||||
if (cp_new == nullptr) return false;
|
||||
cp_new->SetLoadPlace(this->load_place);
|
||||
this->source->reserved_count += cp_new->Count();
|
||||
this->source->RemoveFromCache(cp_new, cp_new->Count());
|
||||
this->destination->Append(cp_new, VehicleCargoList::MTA_LOAD);
|
||||
|
@ -77,19 +77,17 @@ public:
|
||||
|
||||
/** Action of loading cargo from a station onto a vehicle. */
|
||||
class CargoLoad : public CargoMovement<StationCargoList, VehicleCargoList> {
|
||||
protected:
|
||||
TileIndex load_place; ///< TileIndex to be saved in the packets' loaded_at_xy.
|
||||
public:
|
||||
CargoLoad(StationCargoList *source, VehicleCargoList *destination, uint max_move, TileIndex load_place) :
|
||||
CargoMovement<StationCargoList, VehicleCargoList>(source, destination, max_move), load_place(load_place) {}
|
||||
CargoLoad(StationCargoList *source, VehicleCargoList *destination, uint max_move) :
|
||||
CargoMovement<StationCargoList, VehicleCargoList>(source, destination, max_move) {}
|
||||
bool operator()(CargoPacket *cp);
|
||||
};
|
||||
|
||||
/** Action of reserving cargo from a station to be loaded onto a vehicle. */
|
||||
class CargoReservation : public CargoLoad {
|
||||
public:
|
||||
CargoReservation(StationCargoList *source, VehicleCargoList *destination, uint max_move, TileIndex load_place) :
|
||||
CargoLoad(source, destination, max_move, load_place) {}
|
||||
CargoReservation(StationCargoList *source, VehicleCargoList *destination, uint max_move) :
|
||||
CargoLoad(source, destination, max_move) {}
|
||||
bool operator()(CargoPacket *cp);
|
||||
};
|
||||
|
||||
|
@ -46,7 +46,6 @@ CargoPacket::CargoPacket(StationID source, TileIndex source_xy, uint16_t count,
|
||||
periods_in_transit(0),
|
||||
feeder_share(0),
|
||||
source_xy(source_xy),
|
||||
loaded_at_xy(0),
|
||||
source_id(source_id),
|
||||
source(source),
|
||||
source_type(source_type)
|
||||
@ -61,19 +60,17 @@ CargoPacket::CargoPacket(StationID source, TileIndex source_xy, uint16_t count,
|
||||
* @param periods_in_transit Number of cargo aging periods the cargo has been in transit.
|
||||
* @param source Station the cargo was initially loaded.
|
||||
* @param source_xy Station location the cargo was initially loaded.
|
||||
* @param loaded_at_xy Location the cargo was loaded last.
|
||||
* @param feeder_share Feeder share the packet has already accumulated.
|
||||
* @param source_type 'Type' of source the packet comes from (for subsidies).
|
||||
* @param source_id Actual source of the packet (for subsidies).
|
||||
* @note We have to zero memory ourselves here because we are using a 'new'
|
||||
* that, in contrary to all other pools, does not memset to 0.
|
||||
*/
|
||||
CargoPacket::CargoPacket(uint16_t count, uint16_t periods_in_transit, StationID source, TileIndex source_xy, TileIndex loaded_at_xy, Money feeder_share, SourceType source_type, SourceID source_id) :
|
||||
CargoPacket::CargoPacket(uint16_t count, uint16_t periods_in_transit, StationID source, TileIndex source_xy, Money feeder_share, SourceType source_type, SourceID source_id) :
|
||||
count(count),
|
||||
periods_in_transit(periods_in_transit),
|
||||
feeder_share(feeder_share),
|
||||
source_xy(source_xy),
|
||||
loaded_at_xy(loaded_at_xy),
|
||||
source_id(source_id),
|
||||
source(source),
|
||||
source_type(source_type)
|
||||
@ -91,7 +88,7 @@ CargoPacket *CargoPacket::Split(uint new_size)
|
||||
if (!CargoPacket::CanAllocateItem()) return nullptr;
|
||||
|
||||
Money fs = this->FeederShare(new_size);
|
||||
CargoPacket *cp_new = new CargoPacket(new_size, this->periods_in_transit, this->source, this->source_xy, this->loaded_at_xy, fs, this->source_type, this->source_id);
|
||||
CargoPacket *cp_new = new CargoPacket(new_size, this->periods_in_transit, this->source, this->source_xy, fs, this->source_type, this->source_id);
|
||||
this->feeder_share -= fs;
|
||||
this->count -= new_size;
|
||||
return cp_new;
|
||||
@ -389,23 +386,6 @@ void VehicleCargoList::AgeCargo()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets loaded_at_xy to the current station for all cargo to be transferred.
|
||||
* This is done when stopping or skipping while the vehicle is unloading. In
|
||||
* that case the vehicle will get part of its transfer credits early and it may
|
||||
* get more transfer credits than it's entitled to.
|
||||
* @param xy New loaded_at_xy for the cargo.
|
||||
*/
|
||||
void VehicleCargoList::SetTransferLoadPlace(TileIndex xy)
|
||||
{
|
||||
uint sum = 0;
|
||||
for (Iterator it = this->packets.begin(); sum < this->action_counts[MTA_TRANSFER]; ++it) {
|
||||
CargoPacket *cp = *it;
|
||||
cp->loaded_at_xy = xy;
|
||||
sum += cp->count;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Choose action to be performed with the given cargo packet.
|
||||
* @param cp The packet.
|
||||
@ -815,13 +795,12 @@ uint StationCargoList::Truncate(uint max_move, StationCargoAmountMap *cargo_per_
|
||||
* Reserves cargo for loading onto the vehicle.
|
||||
* @param max_move Maximum amount of cargo to reserve.
|
||||
* @param dest VehicleCargoList to reserve for.
|
||||
* @param load_place Tile index of the current station.
|
||||
* @param next_station Next station(s) the loading vehicle will visit.
|
||||
* @return Amount of cargo actually reserved.
|
||||
*/
|
||||
uint StationCargoList::Reserve(uint max_move, VehicleCargoList *dest, TileIndex load_place, StationIDStack next_station)
|
||||
uint StationCargoList::Reserve(uint max_move, VehicleCargoList *dest, StationIDStack next_station)
|
||||
{
|
||||
return this->ShiftCargo(CargoReservation(this, dest, max_move, load_place), next_station, true);
|
||||
return this->ShiftCargo(CargoReservation(this, dest, max_move), next_station, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -829,14 +808,13 @@ uint StationCargoList::Reserve(uint max_move, VehicleCargoList *dest, TileIndex
|
||||
* Otherwise load cargo from the station.
|
||||
* @param max_move Amount of cargo to load.
|
||||
* @param dest Vehicle cargo list where the cargo resides.
|
||||
* @param load_place The new loaded_at_xy to be assigned to packets being moved.
|
||||
* @param next_station Next station(s) the loading vehicle will visit.
|
||||
* @return Amount of cargo actually loaded.
|
||||
* @note Vehicles may or may not reserve, depending on their orders. The two
|
||||
* modes of loading are exclusive, though. If cargo is reserved we don't
|
||||
* need to load unreserved cargo.
|
||||
*/
|
||||
uint StationCargoList::Load(uint max_move, VehicleCargoList *dest, TileIndex load_place, StationIDStack next_station)
|
||||
uint StationCargoList::Load(uint max_move, VehicleCargoList *dest, StationIDStack next_station)
|
||||
{
|
||||
uint move = std::min(dest->ActionCount(VehicleCargoList::MTA_LOAD), max_move);
|
||||
if (move > 0) {
|
||||
@ -844,7 +822,7 @@ uint StationCargoList::Load(uint max_move, VehicleCargoList *dest, TileIndex loa
|
||||
dest->Reassign<VehicleCargoList::MTA_LOAD, VehicleCargoList::MTA_KEEP>(move);
|
||||
return move;
|
||||
} else {
|
||||
return this->ShiftCargo(CargoLoad(this, dest, max_move, load_place), next_station, true);
|
||||
return this->ShiftCargo(CargoLoad(this, dest, max_move), next_station, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,13 +34,6 @@ template <class Tinst, class Tcont> class CargoList;
|
||||
class StationCargoList; // forward-declare, so we can use it in VehicleCargoList.
|
||||
extern SaveLoadTable GetCargoPacketDesc();
|
||||
|
||||
/**
|
||||
* To make alignment in the union in CargoPacket a bit easier, create a new type
|
||||
* that is a StationID, but stored as 32bit.
|
||||
*/
|
||||
typedef uint32_t StationID_32bit;
|
||||
static_assert(sizeof(TileIndex) == sizeof(StationID_32bit));
|
||||
|
||||
/**
|
||||
* Container for cargo from the same location and time.
|
||||
*/
|
||||
@ -50,10 +43,7 @@ private:
|
||||
uint16_t periods_in_transit; ///< Amount of cargo aging periods this packet has been in transit.
|
||||
Money feeder_share; ///< Value of feeder pickup to be paid for on delivery of cargo.
|
||||
TileIndex source_xy; ///< The origin of the cargo (first station in feeder chain).
|
||||
union {
|
||||
TileIndex loaded_at_xy; ///< Location where this cargo has been loaded into the vehicle.
|
||||
StationID_32bit next_station; ///< Station where the cargo wants to go next.
|
||||
};
|
||||
StationID next_station; ///< Station where the cargo wants to go next.
|
||||
SourceID source_id; ///< Index of source, INVALID_SOURCE if unknown/invalid.
|
||||
StationID source; ///< The station where the cargo came from first.
|
||||
SourceType source_type; ///< Type of \c source_id.
|
||||
@ -70,7 +60,7 @@ public:
|
||||
|
||||
CargoPacket();
|
||||
CargoPacket(StationID source, TileIndex source_xy, uint16_t count, SourceType source_type, SourceID source_id);
|
||||
CargoPacket(uint16_t count, uint16_t periods_in_transit, StationID source, TileIndex source_xy, TileIndex loaded_at_xy, Money feeder_share = 0, SourceType source_type = SourceType::Industry, SourceID source_id = INVALID_SOURCE);
|
||||
CargoPacket(uint16_t count, uint16_t periods_in_transit, StationID source, TileIndex source_xy, Money feeder_share = 0, SourceType source_type = SourceType::Industry, SourceID source_id = INVALID_SOURCE);
|
||||
|
||||
/** Destroy the packet. */
|
||||
~CargoPacket() { }
|
||||
@ -79,12 +69,6 @@ public:
|
||||
void Merge(CargoPacket *cp);
|
||||
void Reduce(uint count);
|
||||
|
||||
/**
|
||||
* Sets the tile where the packet was loaded last.
|
||||
* @param load_place Tile where the packet was loaded last.
|
||||
*/
|
||||
void SetLoadPlace(TileIndex load_place) { this->loaded_at_xy = load_place; }
|
||||
|
||||
/**
|
||||
* Sets the station where the packet is supposed to go next.
|
||||
* @param next_station Next station the packet should go to.
|
||||
@ -175,15 +159,6 @@ public:
|
||||
return this->source_xy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the coordinates of the cargo's last loading station.
|
||||
* @return Last loading station's coordinates.
|
||||
*/
|
||||
inline TileIndex LoadedAtXY() const
|
||||
{
|
||||
return this->loaded_at_xy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ID of station the cargo wants to go next.
|
||||
* @return Next station for this packets.
|
||||
@ -401,8 +376,6 @@ public:
|
||||
|
||||
void InvalidateCache();
|
||||
|
||||
void SetTransferLoadPlace(TileIndex xy);
|
||||
|
||||
bool Stage(bool accepted, StationID current_station, StationIDStack next_station, uint8_t order_flags, const GoodsEntry *ge, CargoPayment *payment);
|
||||
|
||||
/**
|
||||
@ -440,8 +413,7 @@ public:
|
||||
return cp1->source_xy == cp2->source_xy &&
|
||||
cp1->periods_in_transit == cp2->periods_in_transit &&
|
||||
cp1->source_type == cp2->source_type &&
|
||||
cp1->source_id == cp2->source_id &&
|
||||
cp1->loaded_at_xy == cp2->loaded_at_xy;
|
||||
cp1->source_id == cp2->source_id;
|
||||
}
|
||||
};
|
||||
|
||||
@ -538,8 +510,8 @@ public:
|
||||
* amount of cargo to be moved. Second parameter is destination (if
|
||||
* applicable), return value is amount of cargo actually moved. */
|
||||
|
||||
uint Reserve(uint max_move, VehicleCargoList *dest, TileIndex load_place, StationIDStack next);
|
||||
uint Load(uint max_move, VehicleCargoList *dest, TileIndex load_place, StationIDStack next);
|
||||
uint Reserve(uint max_move, VehicleCargoList *dest, StationIDStack next);
|
||||
uint Load(uint max_move, VehicleCargoList *dest, StationIDStack next);
|
||||
uint Truncate(uint max_move = UINT_MAX, StationCargoAmountMap *cargo_per_source = nullptr);
|
||||
uint Reroute(uint max_move, StationCargoList *dest, StationID avoid, StationID avoid2, const GoodsEntry *ge);
|
||||
|
||||
|
@ -1469,7 +1469,7 @@ struct FinalizeRefitAction
|
||||
{
|
||||
if (this->do_reserve) {
|
||||
this->st->goods[v->cargo_type].cargo.Reserve(v->cargo_cap - v->cargo.RemainingCount(),
|
||||
&v->cargo, st->xy, this->next_station);
|
||||
&v->cargo, this->next_station);
|
||||
}
|
||||
this->consist_capleft[v->cargo_type] += v->cargo_cap - v->cargo.RemainingCount();
|
||||
return true;
|
||||
@ -1560,7 +1560,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, st->xy, *next_station);
|
||||
&v->cargo, *next_station);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -1791,7 +1791,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, st->xy, next_station);
|
||||
uint loaded = ge->cargo.Load(cap_left, &v->cargo, next_station);
|
||||
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. */
|
||||
|
@ -34,7 +34,6 @@
|
||||
for (VehicleCargoList::ConstIterator it(packets->begin()); it != packets->end(); it++) {
|
||||
CargoPacket *cp = *it;
|
||||
cp->source_xy = Station::IsValidID(cp->source) ? Station::Get(cp->source)->xy : v->tile;
|
||||
cp->loaded_at_xy = cp->source_xy;
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,7 +50,6 @@
|
||||
for (StationCargoList::ConstIterator it(packets->begin()); it != packets->end(); it++) {
|
||||
CargoPacket *cp = *it;
|
||||
cp->source_xy = Station::IsValidID(cp->source) ? Station::Get(cp->source)->xy : st->xy;
|
||||
cp->loaded_at_xy = cp->source_xy;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -90,7 +88,6 @@ SaveLoadTable GetCargoPacketDesc()
|
||||
static const SaveLoad _cargopacket_desc[] = {
|
||||
SLE_VAR(CargoPacket, source, SLE_UINT16),
|
||||
SLE_VAR(CargoPacket, source_xy, SLE_UINT32),
|
||||
SLE_VAR(CargoPacket, loaded_at_xy, SLE_UINT32),
|
||||
SLE_VAR(CargoPacket, count, SLE_UINT16),
|
||||
SLE_CONDVARNAME(CargoPacket, periods_in_transit, "days_in_transit", SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_MORE_CARGO_AGE),
|
||||
SLE_CONDVARNAME(CargoPacket, periods_in_transit, "days_in_transit", SLE_UINT16, SLV_MORE_CARGO_AGE, SLV_PERIODS_IN_TRANSIT_RENAME),
|
||||
|
@ -16,7 +16,7 @@
|
||||
const SaveLoadCompat _cargopacket_sl_compat[] = {
|
||||
SLC_VAR("source"),
|
||||
SLC_VAR("source_xy"),
|
||||
SLC_VAR("loaded_at_xy"),
|
||||
SLC_NULL(4, SL_MIN_VERSION, SLV_REMOVE_LOADED_AT_XY),
|
||||
SLC_VAR("count"),
|
||||
SLC_VAR("days_in_transit"),
|
||||
SLC_VAR("feeder_share"),
|
||||
|
@ -82,7 +82,7 @@ const SaveLoadCompat _vehicle_common_sl_compat[] = {
|
||||
SLC_VAR("profit_this_year"),
|
||||
SLC_VAR("profit_last_year"),
|
||||
SLC_VAR("cargo_feeder_share"),
|
||||
SLC_VAR("cargo_loaded_at_xy"),
|
||||
SLC_NULL(4, SLV_51, SLV_68),
|
||||
SLC_VAR("value"),
|
||||
SLC_VAR("random_bits"),
|
||||
SLC_VAR("waiting_triggers"),
|
||||
|
@ -1353,7 +1353,7 @@ bool LoadOldVehicle(LoadgameState *ls, int num)
|
||||
if (_cargo_count != 0 && CargoPacket::CanAllocateItem()) {
|
||||
StationID source = (_cargo_source == 0xFF) ? INVALID_STATION : _cargo_source;
|
||||
TileIndex source_xy = (source != INVALID_STATION) ? Station::Get(source)->xy : (TileIndex)0;
|
||||
v->cargo.Append(new CargoPacket(_cargo_count, _cargo_periods, source, source_xy, source_xy));
|
||||
v->cargo.Append(new CargoPacket(_cargo_count, _cargo_periods, source, source_xy));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -359,6 +359,7 @@ enum SaveLoadVersion : uint16_t {
|
||||
SLV_INDUSTRY_CARGO_REORGANISE, ///< 315 PR#10853 Industry accepts/produced data reorganised.
|
||||
SLV_PERIODS_IN_TRANSIT_RENAME, ///< 316 PR#11112 Rename days in transit to (cargo) periods in transit.
|
||||
SLV_NEWGRF_LAST_SERVICE, ///< 317 PR#11124 Added stable date_of_last_service to avoid NewGRF trouble.
|
||||
SLV_REMOVE_LOADED_AT_XY, ///< 318 PR#11276 Remove loaded_at_xy variable from CargoPacket.
|
||||
|
||||
SL_MAX_VERSION, ///< Highest possible saveload version
|
||||
};
|
||||
|
@ -449,7 +449,7 @@ public:
|
||||
assert(CargoPacket::CanAllocateItem());
|
||||
|
||||
/* Don't construct the packet with station here, because that'll fail with old savegames */
|
||||
CargoPacket *cp = new CargoPacket(GB(_waiting_acceptance, 0, 12), _cargo_periods, source, _cargo_source_xy, _cargo_source_xy, _cargo_feeder_share);
|
||||
CargoPacket *cp = new CargoPacket(GB(_waiting_acceptance, 0, 12), _cargo_periods, source, _cargo_source_xy, _cargo_feeder_share);
|
||||
ge->cargo.Append(cp, INVALID_STATION);
|
||||
SB(ge->status, GoodsEntry::GES_RATING, 1, 1);
|
||||
}
|
||||
|
@ -577,7 +577,6 @@ static uint32_t _cargo_source_xy;
|
||||
static uint16_t _cargo_count;
|
||||
static uint16_t _cargo_paid_for;
|
||||
static Money _cargo_feeder_share;
|
||||
static uint32_t _cargo_loaded_at_xy;
|
||||
|
||||
class SlVehicleCommon : public DefaultSaveLoadHandler<SlVehicleCommon, Vehicle> {
|
||||
public:
|
||||
@ -699,7 +698,6 @@ public:
|
||||
SLE_CONDVAR(Vehicle, profit_last_year, SLE_INT64, SLV_65, SL_MAX_VERSION),
|
||||
SLEG_CONDVAR("cargo_feeder_share", _cargo_feeder_share, SLE_FILE_I32 | SLE_VAR_I64, SLV_51, SLV_65),
|
||||
SLEG_CONDVAR("cargo_feeder_share", _cargo_feeder_share, SLE_INT64, SLV_65, SLV_68),
|
||||
SLEG_CONDVAR("cargo_loaded_at_xy", _cargo_loaded_at_xy, SLE_UINT32, SLV_51, SLV_68),
|
||||
SLE_CONDVAR(Vehicle, value, SLE_FILE_I32 | SLE_VAR_I64, SL_MIN_VERSION, SLV_65),
|
||||
SLE_CONDVAR(Vehicle, value, SLE_INT64, SLV_65, SL_MAX_VERSION),
|
||||
|
||||
@ -1043,7 +1041,7 @@ struct VEHSChunkHandler : ChunkHandler {
|
||||
|
||||
if (_cargo_count != 0 && IsCompanyBuildableVehicleType(v) && CargoPacket::CanAllocateItem()) {
|
||||
/* Don't construct the packet with station here, because that'll fail with old savegames */
|
||||
CargoPacket *cp = new CargoPacket(_cargo_count, _cargo_periods, _cargo_source, _cargo_source_xy, _cargo_loaded_at_xy, _cargo_feeder_share);
|
||||
CargoPacket *cp = new CargoPacket(_cargo_count, _cargo_periods, _cargo_source, _cargo_source_xy, _cargo_feeder_share);
|
||||
v->cargo.Append(cp);
|
||||
}
|
||||
|
||||
|
@ -2242,7 +2242,6 @@ void Vehicle::CancelReservation(StationID next, Station *st)
|
||||
if (cargo.ActionCount(VehicleCargoList::MTA_LOAD) > 0) {
|
||||
Debug(misc, 1, "cancelling cargo reservation");
|
||||
cargo.Return(UINT_MAX, &st->goods[v->cargo_type].cargo, next);
|
||||
cargo.SetTransferLoadPlace(st->xy);
|
||||
}
|
||||
cargo.KeepAll();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user