mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 18:40:29 +00:00
Codechange: simplify splitting of CargoPacket (#11286)
This commit is contained in:
parent
a16aa3ef7d
commit
d1a0ca67be
@ -32,48 +32,59 @@ CargoPacket::CargoPacket()
|
||||
|
||||
/**
|
||||
* Creates a new cargo packet.
|
||||
*
|
||||
* @param first_station Source station of the packet.
|
||||
* @param source_xy Source location of the packet.
|
||||
* @param count Number of cargo entities to put in this packet.
|
||||
* @param source_type 'Type' of source the packet comes from (for subsidies).
|
||||
* @param source_id Actual source of the packet (for subsidies).
|
||||
* @pre count != 0
|
||||
* @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(StationID first_station, TileIndex source_xy, uint16_t count, SourceType source_type, SourceID source_id) :
|
||||
count(count),
|
||||
source_xy(source_xy),
|
||||
source_id(source_id),
|
||||
source_type(source_type),
|
||||
first_station(first_station)
|
||||
count(count),
|
||||
source_xy(source_xy),
|
||||
source_id(source_id),
|
||||
source_type(source_type),
|
||||
first_station(first_station)
|
||||
{
|
||||
assert(count != 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new cargo packet. Initializes the fields that cannot be changed later.
|
||||
* Used when loading or splitting packets.
|
||||
* Create a new cargo packet. Used for older savegames to load in their partial data.
|
||||
*
|
||||
* @param count Number of cargo entities to put in this packet.
|
||||
* @param periods_in_transit Number of cargo aging periods the cargo has been in transit.
|
||||
* @param first_station Station the cargo was initially loaded.
|
||||
* @param next_hop Next station the cargo wants to go.
|
||||
* @param source_xy Station location the cargo was initially loaded.
|
||||
* @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 first_station, StationID next_hop, TileIndex source_xy, Money feeder_share, SourceType source_type, SourceID source_id) :
|
||||
CargoPacket::CargoPacket(uint16_t count, uint16_t periods_in_transit, StationID first_station, TileIndex source_xy, Money feeder_share) :
|
||||
count(count),
|
||||
periods_in_transit(periods_in_transit),
|
||||
feeder_share(feeder_share),
|
||||
source_xy(source_xy),
|
||||
source_id(source_id),
|
||||
source_type(source_type),
|
||||
first_station(first_station),
|
||||
next_hop(next_hop)
|
||||
first_station(first_station)
|
||||
{
|
||||
assert(count != 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new cargo packet. Used when loading or splitting packets.
|
||||
*
|
||||
* @param count Number of cargo entities to put in this packet.
|
||||
* @param feeder_share Feeder share the packet has already accumulated.
|
||||
* @param original The original packet we are splitting.
|
||||
*/
|
||||
CargoPacket::CargoPacket(uint16_t count, Money feeder_share, CargoPacket &original) :
|
||||
count(count),
|
||||
periods_in_transit(original.periods_in_transit),
|
||||
feeder_share(feeder_share),
|
||||
source_xy(original.source_xy),
|
||||
source_id(original.source_id),
|
||||
source_type(original.source_type),
|
||||
first_station(original.first_station),
|
||||
next_hop(original.next_hop)
|
||||
{
|
||||
assert(count != 0);
|
||||
}
|
||||
@ -88,7 +99,7 @@ CargoPacket *CargoPacket::Split(uint new_size)
|
||||
if (!CargoPacket::CanAllocateItem()) return nullptr;
|
||||
|
||||
Money fs = this->GetFeederShare(new_size);
|
||||
CargoPacket *cp_new = new CargoPacket(new_size, this->periods_in_transit, this->first_station, this->next_hop, this->source_xy, fs, this->source_type, this->source_id);
|
||||
CargoPacket *cp_new = new CargoPacket(new_size, fs, *this);
|
||||
this->feeder_share -= fs;
|
||||
this->count -= new_size;
|
||||
return cp_new;
|
||||
|
@ -63,7 +63,8 @@ public:
|
||||
|
||||
CargoPacket();
|
||||
CargoPacket(StationID first_station, TileIndex source_xy, uint16_t count, SourceType source_type, SourceID source_id);
|
||||
CargoPacket(uint16_t count, uint16_t periods_in_transit, StationID first_station, StationID next_station, TileIndex source_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 first_station, TileIndex source_xy, Money feeder_share);
|
||||
CargoPacket(uint16_t count, Money feeder_share, CargoPacket &original);
|
||||
|
||||
/** Destroy the packet. */
|
||||
~CargoPacket() { }
|
||||
|
@ -710,7 +710,7 @@ static bool LoadOldGood(LoadgameState *ls, int num)
|
||||
SB(ge->status, GoodsEntry::GES_ACCEPTANCE, 1, HasBit(_waiting_acceptance, 15));
|
||||
SB(ge->status, GoodsEntry::GES_RATING, 1, _cargo_source != 0xFF);
|
||||
if (GB(_waiting_acceptance, 0, 12) != 0 && CargoPacket::CanAllocateItem()) {
|
||||
ge->cargo.Append(new CargoPacket(GB(_waiting_acceptance, 0, 12), _cargo_periods, (_cargo_source == 0xFF) ? INVALID_STATION : _cargo_source, INVALID_STATION, 0),
|
||||
ge->cargo.Append(new CargoPacket(GB(_waiting_acceptance, 0, 12), _cargo_periods, (_cargo_source == 0xFF) ? INVALID_STATION : _cargo_source, INVALID_TILE, 0),
|
||||
INVALID_STATION);
|
||||
}
|
||||
|
||||
@ -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, INVALID_STATION, source_xy));
|
||||
v->cargo.Append(new CargoPacket(_cargo_count, _cargo_periods, source, source_xy, 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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, INVALID_STATION, _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);
|
||||
}
|
||||
|
@ -1041,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, INVALID_STATION, _cargo_source_xy, _cargo_feeder_share);
|
||||
CargoPacket *cp = new CargoPacket(_cargo_count, _cargo_periods, _cargo_source, _cargo_source_xy, _cargo_feeder_share);
|
||||
v->cargo.Append(cp);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user