mirror of https://github.com/OpenTTD/OpenTTD
Compare commits
7 Commits
7bd019df90
...
30172fc037
Author | SHA1 | Date |
---|---|---|
|
30172fc037 | |
|
b0e73277d6 | |
|
f3b4f9d640 | |
|
f6939d6c4d | |
|
3c61c642a9 | |
|
78b841d14e | |
|
7519f7ad79 |
|
@ -56,10 +56,10 @@ void DrawAircraftDetails(const Aircraft *v, const Rect &r)
|
|||
/* Cargo names (fix pluralness) */
|
||||
SetDParam(0, u->cargo_type);
|
||||
SetDParam(1, cargo_count);
|
||||
SetDParam(2, u->cargo.Source());
|
||||
SetDParam(2, u->cargo.GetFirstStation());
|
||||
DrawString(r.left, r.right, y, STR_VEHICLE_DETAILS_CARGO_FROM);
|
||||
y += FONT_HEIGHT_NORMAL;
|
||||
feeder_share += u->cargo.FeederShare();
|
||||
feeder_share += u->cargo.GetFeederShare();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
@ -169,7 +167,7 @@ bool CargoTransfer::operator()(CargoPacket *cp)
|
|||
if (cp_new == nullptr) return false;
|
||||
this->source->RemoveFromMeta(cp_new, VehicleCargoList::MTA_TRANSFER, cp_new->Count());
|
||||
/* No transfer credits here as they were already granted during Stage(). */
|
||||
this->destination->Append(cp_new, cp_new->NextStation());
|
||||
this->destination->Append(cp_new, cp_new->GetNextStation());
|
||||
return cp_new == cp;
|
||||
}
|
||||
|
||||
|
@ -196,7 +194,7 @@ bool StationCargoReroute::operator()(CargoPacket *cp)
|
|||
{
|
||||
CargoPacket *cp_new = this->Preprocess(cp);
|
||||
if (cp_new == nullptr) cp_new = cp;
|
||||
StationID next = this->ge->GetVia(cp_new->SourceStation(), this->avoid, this->avoid2);
|
||||
StationID next = this->ge->GetVia(cp_new->GetFirstStation(), this->avoid, this->avoid2);
|
||||
assert(next != this->avoid && next != this->avoid2);
|
||||
if (this->source != this->destination) {
|
||||
this->source->RemoveFromCache(cp_new, cp_new->Count());
|
||||
|
@ -219,8 +217,8 @@ bool VehicleCargoReroute::operator()(CargoPacket *cp)
|
|||
{
|
||||
CargoPacket *cp_new = this->Preprocess(cp);
|
||||
if (cp_new == nullptr) cp_new = cp;
|
||||
if (cp_new->NextStation() == this->avoid || cp_new->NextStation() == this->avoid2) {
|
||||
cp->SetNextStation(this->ge->GetVia(cp_new->SourceStation(), this->avoid, this->avoid2));
|
||||
if (cp_new->GetNextStation() == this->avoid || cp_new->GetNextStation() == this->avoid2) {
|
||||
cp->SetNextStation(this->ge->GetVia(cp_new->GetFirstStation(), this->avoid, this->avoid2));
|
||||
}
|
||||
if (this->source != this->destination) {
|
||||
this->source->RemoveFromMeta(cp_new, VehicleCargoList::MTA_TRANSFER, cp_new->Count());
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
||||
|
|
|
@ -32,24 +32,21 @@ CargoPacket::CargoPacket()
|
|||
|
||||
/**
|
||||
* Creates a new cargo packet.
|
||||
* @param source 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).
|
||||
* @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 source, TileIndex source_xy, uint16_t count, SourceType source_type, SourceID source_id) :
|
||||
CargoPacket::CargoPacket(StationID first_station, TileIndex source_xy, uint16_t count, SourceType source_type, SourceID source_id) :
|
||||
count(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)
|
||||
source_type(source_type),
|
||||
first_station(first_station)
|
||||
{
|
||||
assert(count != 0);
|
||||
}
|
||||
|
@ -57,26 +54,24 @@ CargoPacket::CargoPacket(StationID source, TileIndex source_xy, uint16_t count,
|
|||
/**
|
||||
* Creates a new cargo packet. Initializes the fields that cannot be changed later.
|
||||
* Used when loading or splitting packets.
|
||||
* @param count Number of cargo entities to put in this packet.
|
||||
* @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 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).
|
||||
* @param first_station Station the cargo was initially loaded.
|
||||
* @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 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 first_station, 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)
|
||||
source_type(source_type),
|
||||
first_station(first_station)
|
||||
{
|
||||
assert(count != 0);
|
||||
}
|
||||
|
@ -90,8 +85,8 @@ 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);
|
||||
Money fs = this->GetFeederShare(new_size);
|
||||
CargoPacket *cp_new = new CargoPacket(new_size, this->periods_in_transit, this->first_station, this->source_xy, fs, this->source_type, this->source_id);
|
||||
this->feeder_share -= fs;
|
||||
this->count -= new_size;
|
||||
return cp_new;
|
||||
|
@ -115,7 +110,7 @@ void CargoPacket::Merge(CargoPacket *cp)
|
|||
void CargoPacket::Reduce(uint count)
|
||||
{
|
||||
assert(count < this->count);
|
||||
this->feeder_share -= this->FeederShare(count);
|
||||
this->feeder_share -= this->GetFeederShare(count);
|
||||
this->count -= count;
|
||||
}
|
||||
|
||||
|
@ -138,7 +133,7 @@ void CargoPacket::Reduce(uint count)
|
|||
/* static */ void CargoPacket::InvalidateAllFrom(StationID sid)
|
||||
{
|
||||
for (CargoPacket *cp : CargoPacket::Iterate()) {
|
||||
if (cp->source == sid) cp->source = INVALID_STATION;
|
||||
if (cp->first_station == sid) cp->first_station = INVALID_STATION;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -179,7 +174,7 @@ template <class Tinst, class Tcont>
|
|||
void CargoList<Tinst, Tcont>::RemoveFromCache(const CargoPacket *cp, uint count)
|
||||
{
|
||||
assert(count <= cp->count);
|
||||
this->count -= count;
|
||||
this->count -= count;
|
||||
this->cargo_periods_in_transit -= static_cast<uint64_t>(cp->periods_in_transit) * count;
|
||||
}
|
||||
|
||||
|
@ -191,7 +186,7 @@ void CargoList<Tinst, Tcont>::RemoveFromCache(const CargoPacket *cp, uint count)
|
|||
template <class Tinst, class Tcont>
|
||||
void CargoList<Tinst, Tcont>::AddToCache(const CargoPacket *cp)
|
||||
{
|
||||
this->count += cp->count;
|
||||
this->count += cp->count;
|
||||
this->cargo_periods_in_transit += static_cast<uint64_t>(cp->periods_in_transit) * cp->count;
|
||||
}
|
||||
|
||||
|
@ -332,7 +327,7 @@ void VehicleCargoList::PopCargo(Taction action)
|
|||
*/
|
||||
void VehicleCargoList::RemoveFromCache(const CargoPacket *cp, uint count)
|
||||
{
|
||||
this->feeder_share -= cp->FeederShare(count);
|
||||
this->feeder_share -= cp->GetFeederShare(count);
|
||||
this->Parent::RemoveFromCache(cp, count);
|
||||
}
|
||||
|
||||
|
@ -389,23 +384,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.
|
||||
|
@ -419,7 +397,7 @@ void VehicleCargoList::SetTransferLoadPlace(TileIndex xy)
|
|||
StationID current_station, bool accepted, StationIDStack next_station)
|
||||
{
|
||||
if (cargo_next == INVALID_STATION) {
|
||||
return (accepted && cp->source != current_station) ? MTA_DELIVER : MTA_KEEP;
|
||||
return (accepted && cp->first_station != current_station) ? MTA_DELIVER : MTA_KEEP;
|
||||
} else if (cargo_next == current_station) {
|
||||
return MTA_DELIVER;
|
||||
} else if (next_station.Contains(cargo_next)) {
|
||||
|
@ -463,13 +441,13 @@ bool VehicleCargoList::Stage(bool accepted, StationID current_station, StationID
|
|||
MoveToAction action = MTA_LOAD;
|
||||
if (force_keep) {
|
||||
action = MTA_KEEP;
|
||||
} else if (force_unload && accepted && cp->source != current_station) {
|
||||
} else if (force_unload && accepted && cp->first_station != current_station) {
|
||||
action = MTA_DELIVER;
|
||||
} else if (force_transfer) {
|
||||
action = MTA_TRANSFER;
|
||||
/* We cannot send the cargo to any of the possible next hops and
|
||||
* also not to the current station. */
|
||||
FlowStatMap::const_iterator flow_it(ge->flows.find(cp->source));
|
||||
FlowStatMap::const_iterator flow_it(ge->flows.find(cp->first_station));
|
||||
if (flow_it == ge->flows.end()) {
|
||||
cargo_next = INVALID_STATION;
|
||||
} else {
|
||||
|
@ -488,11 +466,11 @@ bool VehicleCargoList::Stage(bool accepted, StationID current_station, StationID
|
|||
} else {
|
||||
/* Rewrite an invalid source station to some random other one to
|
||||
* avoid keeping the cargo in the vehicle forever. */
|
||||
if (cp->source == INVALID_STATION && !ge->flows.empty()) {
|
||||
cp->source = ge->flows.begin()->first;
|
||||
if (cp->first_station == INVALID_STATION && !ge->flows.empty()) {
|
||||
cp->first_station = ge->flows.begin()->first;
|
||||
}
|
||||
bool restricted = false;
|
||||
FlowStatMap::const_iterator flow_it(ge->flows.find(cp->source));
|
||||
FlowStatMap::const_iterator flow_it(ge->flows.find(cp->first_station));
|
||||
if (flow_it == ge->flows.end()) {
|
||||
cargo_next = INVALID_STATION;
|
||||
} else {
|
||||
|
@ -777,7 +755,7 @@ uint StationCargoList::Truncate(uint max_move, StationCargoAmountMap *cargo_per_
|
|||
CargoPacket *cp = *it;
|
||||
if (prev_count > max_move && RandomRange(prev_count) < prev_count - max_move) {
|
||||
if (do_count && loop == 0) {
|
||||
(*cargo_per_source)[cp->source] += cp->count;
|
||||
(*cargo_per_source)[cp->first_station] += cp->count;
|
||||
}
|
||||
++it;
|
||||
continue;
|
||||
|
@ -790,16 +768,16 @@ uint StationCargoList::Truncate(uint max_move, StationCargoAmountMap *cargo_per_
|
|||
moved += diff;
|
||||
}
|
||||
if (loop > 0) {
|
||||
if (do_count) (*cargo_per_source)[cp->source] -= diff;
|
||||
if (do_count) (*cargo_per_source)[cp->first_station] -= diff;
|
||||
return moved;
|
||||
} else {
|
||||
if (do_count) (*cargo_per_source)[cp->source] += cp->count;
|
||||
if (do_count) (*cargo_per_source)[cp->first_station] += cp->count;
|
||||
++it;
|
||||
}
|
||||
} else {
|
||||
it = this->packets.erase(it);
|
||||
if (do_count && loop > 0) {
|
||||
(*cargo_per_source)[cp->source] -= cp->count;
|
||||
(*cargo_per_source)[cp->first_station] -= cp->count;
|
||||
}
|
||||
moved += cp->count;
|
||||
this->RemoveFromCache(cp, cp->count);
|
||||
|
@ -815,13 +793,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 +806,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 +820,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,29 +34,22 @@ 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.
|
||||
*/
|
||||
struct CargoPacket : CargoPacketPool::PoolItem<&_cargopacket_pool> {
|
||||
private:
|
||||
uint16_t count; ///< The amount of cargo in this packet.
|
||||
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.
|
||||
};
|
||||
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.
|
||||
uint16_t count{0}; ///< The amount of cargo in this packet.
|
||||
uint16_t periods_in_transit{0}; ///< Amount of cargo aging periods this packet has been in transit.
|
||||
|
||||
Money feeder_share{0}; ///< Value of feeder pickup to be paid for on delivery of cargo.
|
||||
|
||||
TileIndex source_xy{0}; ///< The origin of the cargo.
|
||||
SourceID source_id{INVALID_SOURCE}; ///< Index of industry/town/HQ, INVALID_SOURCE if unknown/invalid.
|
||||
SourceType source_type{SourceType::Industry}; ///< Type of \c source_id.
|
||||
|
||||
StationID first_station{INVALID_STATION}; ///< The station where the cargo came from first.
|
||||
StationID next_station{INVALID_STATION}; ///< Station where the cargo wants to go next.
|
||||
|
||||
/** The CargoList caches, thus needs to know about it. */
|
||||
template <class Tinst, class Tcont> friend class CargoList;
|
||||
|
@ -69,8 +62,8 @@ public:
|
|||
static const uint16_t MAX_COUNT = UINT16_MAX;
|
||||
|
||||
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(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 source, TileIndex source_xy, Money feeder_share = 0, SourceType source_type = SourceType::Industry, SourceID source_id = INVALID_SOURCE);
|
||||
|
||||
/** Destroy the packet. */
|
||||
~CargoPacket() { }
|
||||
|
@ -79,23 +72,23 @@ 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.
|
||||
*/
|
||||
void SetNextStation(StationID next_station) { this->next_station = next_station; }
|
||||
void SetNextStation(StationID next_station)
|
||||
{
|
||||
this->next_station = next_station;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds some feeder share to the packet.
|
||||
* @param new_share Feeder share to be added.
|
||||
*/
|
||||
void AddFeederShare(Money new_share) { this->feeder_share += new_share; }
|
||||
void AddFeederShare(Money new_share)
|
||||
{
|
||||
this->feeder_share += new_share;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of 'items' in this packet.
|
||||
|
@ -111,7 +104,7 @@ public:
|
|||
* the feeder chain.
|
||||
* @return Feeder share.
|
||||
*/
|
||||
inline Money FeederShare() const
|
||||
inline Money GetFeederShare() const
|
||||
{
|
||||
return this->feeder_share;
|
||||
}
|
||||
|
@ -122,7 +115,7 @@ public:
|
|||
* @param part Amount of cargo to get the share for.
|
||||
* @return Feeder share for the given amount of cargo.
|
||||
*/
|
||||
inline Money FeederShare(uint part) const
|
||||
inline Money GetFeederShare(uint part) const
|
||||
{
|
||||
return this->feeder_share * part / static_cast<uint>(this->count);
|
||||
}
|
||||
|
@ -134,7 +127,7 @@ public:
|
|||
* value is capped at UINT16_MAX.
|
||||
* @return Length this cargo has been in transit.
|
||||
*/
|
||||
inline uint16_t PeriodsInTransit() const
|
||||
inline uint16_t GetPeriodsInTransit() const
|
||||
{
|
||||
return this->periods_in_transit;
|
||||
}
|
||||
|
@ -143,7 +136,7 @@ public:
|
|||
* Gets the type of the cargo's source. industry, town or head quarter.
|
||||
* @return Source type.
|
||||
*/
|
||||
inline SourceType SourceSubsidyType() const
|
||||
inline SourceType GetSourceType() const
|
||||
{
|
||||
return this->source_type;
|
||||
}
|
||||
|
@ -152,7 +145,7 @@ public:
|
|||
* Gets the ID of the cargo's source. An IndustryID, TownID or CompanyID.
|
||||
* @return Source ID.
|
||||
*/
|
||||
inline SourceID SourceSubsidyID() const
|
||||
inline SourceID GetSourceID() const
|
||||
{
|
||||
return this->source_id;
|
||||
}
|
||||
|
@ -161,34 +154,25 @@ public:
|
|||
* Gets the ID of the station where the cargo was loaded for the first time.
|
||||
* @return StationID.
|
||||
*/
|
||||
inline StationID SourceStation() const
|
||||
inline StationID GetFirstStation() const
|
||||
{
|
||||
return this->source;
|
||||
return this->first_station;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the coordinates of the cargo's source station.
|
||||
* @return Source station's coordinates.
|
||||
* Gets the coordinates of the cargo's source.
|
||||
* @return Source coordinates of cargo.
|
||||
*/
|
||||
inline TileIndex SourceStationXY() const
|
||||
inline TileIndex GetSourceXY() const
|
||||
{
|
||||
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.
|
||||
*/
|
||||
inline StationID NextStation() const
|
||||
inline StationID GetNextStation() const
|
||||
{
|
||||
return this->next_station;
|
||||
}
|
||||
|
@ -322,19 +306,19 @@ public:
|
|||
friend class VehicleCargoReroute;
|
||||
|
||||
/**
|
||||
* Returns source of the first cargo packet in this list.
|
||||
* @return The before mentioned source.
|
||||
* Returns the first station of the first cargo packet in this list.
|
||||
* @return The before mentioned station.
|
||||
*/
|
||||
inline StationID Source() const
|
||||
inline StationID GetFirstStation() const
|
||||
{
|
||||
return this->count == 0 ? INVALID_STATION : this->packets.front()->source;
|
||||
return this->count == 0 ? INVALID_STATION : this->packets.front()->first_station;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns total sum of the feeder share for all packets.
|
||||
* @return The before mentioned number.
|
||||
*/
|
||||
inline Money FeederShare() const
|
||||
inline Money GetFeederShare() const
|
||||
{
|
||||
return this->feeder_share;
|
||||
}
|
||||
|
@ -401,8 +385,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 +422,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;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -497,12 +478,12 @@ public:
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns source of the first cargo packet in this list.
|
||||
* @return The before mentioned source.
|
||||
* Returns first station of the first cargo packet in this list.
|
||||
* @return The before mentioned station.
|
||||
*/
|
||||
inline StationID Source() const
|
||||
inline StationID GetFirstStation() const
|
||||
{
|
||||
return this->count == 0 ? INVALID_STATION : this->packets.begin()->second.front()->source;
|
||||
return this->count == 0 ? INVALID_STATION : this->packets.begin()->second.front()->first_station;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -538,8 +519,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);
|
||||
|
||||
|
|
|
@ -1233,11 +1233,11 @@ void CargoPayment::PayFinalDelivery(const CargoPacket *cp, uint count)
|
|||
}
|
||||
|
||||
/* Handle end of route payment */
|
||||
Money profit = DeliverGoods(count, this->ct, this->current_station, cp->SourceStationXY(), cp->PeriodsInTransit(), this->owner, cp->SourceSubsidyType(), cp->SourceSubsidyID());
|
||||
Money profit = DeliverGoods(count, this->ct, this->current_station, cp->GetSourceXY(), cp->GetPeriodsInTransit(), this->owner, cp->GetSourceType(), cp->GetSourceID());
|
||||
this->route_profit += profit;
|
||||
|
||||
/* The vehicle's profit is whatever route profit there is minus feeder shares. */
|
||||
this->visual_profit += profit - cp->FeederShare(count);
|
||||
this->visual_profit += profit - cp->GetFeederShare(count);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1248,12 +1248,12 @@ void CargoPayment::PayFinalDelivery(const CargoPacket *cp, uint count)
|
|||
*/
|
||||
Money CargoPayment::PayTransfer(const CargoPacket *cp, uint count)
|
||||
{
|
||||
Money profit = -cp->FeederShare(count) + GetTransportedGoodsIncome(
|
||||
Money profit = -cp->GetFeederShare(count) + GetTransportedGoodsIncome(
|
||||
count,
|
||||
/* pay transfer vehicle the difference between the payment for the journey from
|
||||
* the source to the current point, and the sum of the previous transfer payments */
|
||||
DistanceManhattan(cp->SourceStationXY(), Station::Get(this->current_station)->xy),
|
||||
cp->PeriodsInTransit(),
|
||||
DistanceManhattan(cp->GetSourceXY(), Station::Get(this->current_station)->xy),
|
||||
cp->GetPeriodsInTransit(),
|
||||
this->ct);
|
||||
|
||||
profit = profit * _settings_game.economy.feeder_payment_share / 100;
|
||||
|
@ -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. */
|
||||
|
|
|
@ -823,7 +823,7 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
|
|||
case 0x3B: return GB(v->cargo_cap, 8, 8);
|
||||
case 0x3C: return ClampTo<uint16_t>(v->cargo.StoredCount());
|
||||
case 0x3D: return GB(ClampTo<uint16_t>(v->cargo.StoredCount()), 8, 8);
|
||||
case 0x3E: return v->cargo.Source();
|
||||
case 0x3E: return v->cargo.GetFirstStation();
|
||||
case 0x3F: return ClampTo<uint8_t>(v->cargo.PeriodsInTransit());
|
||||
case 0x40: return ClampTo<uint16_t>(v->age);
|
||||
case 0x41: return GB(ClampTo<uint16_t>(v->age), 8, 8);
|
||||
|
|
|
@ -445,7 +445,7 @@ uint32_t Station::GetNewGRFVariable(const ResolverObject &object, byte variable,
|
|||
case 1: return GB(std::min(g->cargo.TotalCount(), 4095u), 0, 4) | (GB(g->status, GoodsEntry::GES_ACCEPTANCE, 1) << 7);
|
||||
case 2: return g->time_since_pickup;
|
||||
case 3: return g->rating;
|
||||
case 4: return g->cargo.Source();
|
||||
case 4: return g->cargo.GetFirstStation();
|
||||
case 5: return g->cargo.PeriodsInTransit();
|
||||
case 6: return g->last_speed;
|
||||
case 7: return g->last_age;
|
||||
|
|
|
@ -81,9 +81,9 @@ void DrawRoadVehDetails(const Vehicle *v, const Rect &r)
|
|||
if (u->cargo.StoredCount() > 0) {
|
||||
SetDParam(0, u->cargo_type);
|
||||
SetDParam(1, u->cargo.StoredCount());
|
||||
SetDParam(2, u->cargo.Source());
|
||||
SetDParam(2, u->cargo.GetFirstStation());
|
||||
str = STR_VEHICLE_DETAILS_CARGO_FROM;
|
||||
feeder_share += u->cargo.FeederShare();
|
||||
feeder_share += u->cargo.GetFeederShare();
|
||||
}
|
||||
DrawString(r.left, r.right, y, str);
|
||||
y += FONT_HEIGHT_NORMAL;
|
||||
|
@ -100,9 +100,9 @@ void DrawRoadVehDetails(const Vehicle *v, const Rect &r)
|
|||
if (v->cargo.StoredCount() > 0) {
|
||||
SetDParam(0, v->cargo_type);
|
||||
SetDParam(1, v->cargo.StoredCount());
|
||||
SetDParam(2, v->cargo.Source());
|
||||
SetDParam(2, v->cargo.GetFirstStation());
|
||||
str = STR_VEHICLE_DETAILS_CARGO_FROM;
|
||||
feeder_share += v->cargo.FeederShare();
|
||||
feeder_share += v->cargo.GetFeederShare();
|
||||
}
|
||||
DrawString(r.left, r.right, y, str);
|
||||
y += FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.vsep_normal;
|
||||
|
|
|
@ -33,8 +33,7 @@
|
|||
const CargoPacketList *packets = v->cargo.Packets();
|
||||
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;
|
||||
cp->source_xy = Station::IsValidID(cp->first_station) ? Station::Get(cp->first_station)->xy : v->tile;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,8 +49,7 @@
|
|||
const StationCargoPacketMap *packets = ge->cargo.Packets();
|
||||
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;
|
||||
cp->source_xy = Station::IsValidID(cp->first_station) ? Station::Get(cp->first_station)->xy : st->xy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +58,7 @@
|
|||
if (IsSavegameVersionBefore(SLV_120)) {
|
||||
/* CargoPacket's source should be either INVALID_STATION or a valid station */
|
||||
for (CargoPacket *cp : CargoPacket::Iterate()) {
|
||||
if (!Station::IsValidID(cp->source)) cp->source = INVALID_STATION;
|
||||
if (!Station::IsValidID(cp->first_station)) cp->first_station = INVALID_STATION;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,9 +86,8 @@
|
|||
SaveLoadTable GetCargoPacketDesc()
|
||||
{
|
||||
static const SaveLoad _cargopacket_desc[] = {
|
||||
SLE_VAR(CargoPacket, source, SLE_UINT16),
|
||||
SLE_VARNAME(CargoPacket, first_station, "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);
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ template<bool Tfrom, bool Tvia>
|
|||
StationCargoList::ConstIterator(cargo_list.Packets()->end()));
|
||||
for (StationCargoList::ConstIterator it = range.first; it != range.second; it++) {
|
||||
const CargoPacket *cp = *it;
|
||||
if (!Tfrom || cp->SourceStation() == from_station_id) cargo_count += cp->Count();
|
||||
if (!Tfrom || cp->GetFirstStation() == from_station_id) cargo_count += cp->Count();
|
||||
}
|
||||
|
||||
return cargo_count;
|
||||
|
|
|
@ -179,7 +179,7 @@ void ScriptStationList_CargoWaiting::Add(StationID station_id, CargoID cargo, St
|
|||
StationCargoList::ConstIterator iter = collector.GE()->cargo.Packets()->begin();
|
||||
StationCargoList::ConstIterator end = collector.GE()->cargo.Packets()->end();
|
||||
for (; iter != end; ++iter) {
|
||||
collector.Update<Tselector>((*iter)->SourceStation(), iter.GetKey(), (*iter)->Count());
|
||||
collector.Update<Tselector>((*iter)->GetFirstStation(), iter.GetKey(), (*iter)->Count());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -218,7 +218,7 @@ ScriptStationList_CargoWaitingViaByFrom::ScriptStationList_CargoWaitingViaByFrom
|
|||
std::pair<StationCargoList::ConstIterator, StationCargoList::ConstIterator> range =
|
||||
collector.GE()->cargo.Packets()->equal_range(via);
|
||||
for (StationCargoList::ConstIterator iter = range.first; iter != range.second; ++iter) {
|
||||
collector.Update<CS_VIA_BY_FROM>((*iter)->SourceStation(), iter.GetKey(), (*iter)->Count());
|
||||
collector.Update<CS_VIA_BY_FROM>((*iter)->GetFirstStation(), iter.GetKey(), (*iter)->Count());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -79,13 +79,13 @@ void DrawShipDetails(const Vehicle *v, const Rect &r)
|
|||
if (v->cargo.StoredCount() > 0) {
|
||||
SetDParam(0, v->cargo_type);
|
||||
SetDParam(1, v->cargo.StoredCount());
|
||||
SetDParam(2, v->cargo.Source());
|
||||
SetDParam(2, v->cargo.GetFirstStation());
|
||||
str = STR_VEHICLE_DETAILS_CARGO_FROM;
|
||||
}
|
||||
DrawString(r.left, r.right, y, str);
|
||||
y += FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.vsep_normal;
|
||||
|
||||
/* Draw Transfer credits text */
|
||||
SetDParam(0, v->cargo.FeederShare());
|
||||
SetDParam(0, v->cargo.GetFeederShare());
|
||||
DrawString(r.left, r.right, y, STR_VEHICLE_INFO_FEEDER_CARGO_VALUE);
|
||||
}
|
||||
|
|
|
@ -1591,15 +1591,15 @@ struct StationViewWindow : public Window {
|
|||
const CargoPacket *cp = *it;
|
||||
StationID next = it.GetKey();
|
||||
|
||||
const CargoDataEntry *source_entry = source_dest->Retrieve(cp->SourceStation());
|
||||
const CargoDataEntry *source_entry = source_dest->Retrieve(cp->GetFirstStation());
|
||||
if (source_entry == nullptr) {
|
||||
this->ShowCargo(cargo, i, cp->SourceStation(), next, INVALID_STATION, cp->Count());
|
||||
this->ShowCargo(cargo, i, cp->GetFirstStation(), next, INVALID_STATION, cp->Count());
|
||||
continue;
|
||||
}
|
||||
|
||||
const CargoDataEntry *via_entry = source_entry->Retrieve(next);
|
||||
if (via_entry == nullptr) {
|
||||
this->ShowCargo(cargo, i, cp->SourceStation(), next, INVALID_STATION, cp->Count());
|
||||
this->ShowCargo(cargo, i, cp->GetFirstStation(), next, INVALID_STATION, cp->Count());
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -1620,7 +1620,7 @@ struct StationViewWindow : public Window {
|
|||
val = std::min<uint>(remaining, DivideApprox(cp->Count() * dest_entry->GetCount(), via_entry->GetCount()));
|
||||
remaining -= val;
|
||||
}
|
||||
this->ShowCargo(cargo, i, cp->SourceStation(), next, dest_entry->GetStation(), val);
|
||||
this->ShowCargo(cargo, i, cp->GetFirstStation(), next, dest_entry->GetStation(), val);
|
||||
}
|
||||
}
|
||||
this->ShowCargo(cargo, i, NEW_STATION, NEW_STATION, NEW_STATION, packets.ReservedCount());
|
||||
|
|
|
@ -42,13 +42,14 @@ TextEffectID AddTextEffect(StringID msg, int center, int y, uint8_t duration, Te
|
|||
{
|
||||
if (_game_mode == GM_MENU) return INVALID_TE_ID;
|
||||
|
||||
TextEffectID i;
|
||||
for (i = 0; i < _text_effects.size(); i++) {
|
||||
if (_text_effects[i].string_id == INVALID_STRING_ID) break;
|
||||
auto it = std::find_if(std::begin(_text_effects), std::end(_text_effects), [](const TextEffect &te) { return te.string_id == INVALID_STRING_ID; });
|
||||
if (it == std::end(_text_effects)) {
|
||||
/* _text_effects.size() is the maximum ID + 1 that has been allocated. We should not allocate INVALID_TE_ID or beyond. */
|
||||
if (_text_effects.size() >= INVALID_TE_ID) return INVALID_TE_ID;
|
||||
it = _text_effects.emplace(std::end(_text_effects));
|
||||
}
|
||||
if (i == _text_effects.size()) _text_effects.emplace_back();
|
||||
|
||||
TextEffect &te = _text_effects[i];
|
||||
TextEffect &te = *it;
|
||||
|
||||
/* Start defining this object */
|
||||
te.string_id = msg;
|
||||
|
@ -60,18 +61,18 @@ TextEffectID AddTextEffect(StringID msg, int center, int y, uint8_t duration, Te
|
|||
te.width_normal = 0;
|
||||
te.UpdatePosition(center, y, msg);
|
||||
|
||||
return i;
|
||||
return static_cast<TextEffectID>(it - std::begin(_text_effects));
|
||||
}
|
||||
|
||||
void UpdateTextEffect(TextEffectID te_id, StringID msg)
|
||||
{
|
||||
/* Update details */
|
||||
TextEffect *te = _text_effects.data() + te_id;
|
||||
if (msg == te->string_id && !HaveDParamChanged(te->params)) return;
|
||||
te->string_id = msg;
|
||||
CopyOutDParam(te->params, 2);
|
||||
TextEffect &te = _text_effects[te_id];
|
||||
if (msg == te.string_id && !HaveDParamChanged(te.params)) return;
|
||||
te.string_id = msg;
|
||||
CopyOutDParam(te.params, 2);
|
||||
|
||||
te->UpdatePosition(te->center, te->top, te->string_id, te->string_id - 1);
|
||||
te.UpdatePosition(te.center, te.top, te.string_id, te.string_id - 1);
|
||||
}
|
||||
|
||||
void UpdateAllTextEffectVirtCoords()
|
||||
|
|
|
@ -17,14 +17,14 @@
|
|||
/**
|
||||
* Text effect modes.
|
||||
*/
|
||||
enum TextEffectMode {
|
||||
enum TextEffectMode : uint8_t {
|
||||
TE_RISING, ///< Make the text effect slowly go upwards
|
||||
TE_STATIC, ///< Keep the text effect static
|
||||
|
||||
INVALID_TE_ID = 0xFFFF,
|
||||
};
|
||||
|
||||
typedef size_t TextEffectID;
|
||||
using TextEffectID = uint16_t;
|
||||
|
||||
static const TextEffectID INVALID_TE_ID = UINT16_MAX;
|
||||
|
||||
TextEffectID AddTextEffect(StringID msg, int x, int y, uint8_t duration, TextEffectMode mode);
|
||||
void InitTextEffects();
|
||||
|
|
|
@ -291,7 +291,7 @@ static void GetCargoSummaryOfArticulatedVehicle(const Train *v, CargoSummary *su
|
|||
|
||||
item->capacity += v->cargo_cap;
|
||||
item->amount += v->cargo.StoredCount();
|
||||
if (item->source == INVALID_STATION) item->source = v->cargo.Source();
|
||||
if (item->source == INVALID_STATION) item->source = v->cargo.GetFirstStation();
|
||||
} while ((v = v->Next()) != nullptr && v->IsArticulatedPart());
|
||||
}
|
||||
|
||||
|
@ -440,7 +440,7 @@ void DrawTrainDetails(const Train *v, const Rect &r, int vscroll_pos, uint16_t v
|
|||
for (const Vehicle *u = v; u != nullptr; u = u->Next()) {
|
||||
act_cargo[u->cargo_type] += u->cargo.StoredCount();
|
||||
max_cargo[u->cargo_type] += u->cargo_cap;
|
||||
feeder_share += u->cargo.FeederShare();
|
||||
feeder_share += u->cargo.GetFeederShare();
|
||||
}
|
||||
|
||||
/* draw total cargo tab */
|
||||
|
|
|
@ -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