Fix: base cargo payment on load/unload tile, instead of station sign location (#11281)

(cherry picked from commit 9c49a61249)
This commit is contained in:
Patric Stout
2023-09-13 16:41:09 +02:00
committed by Jonathan G Rennison
parent a15847cf4f
commit 05c35c8e31
7 changed files with 80 additions and 46 deletions

View File

@@ -54,7 +54,7 @@ private:
uint16 count = 0; ///< The amount of cargo in this packet.
uint16 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.
TileIndex source_xy = INVALID_TILE; ///< 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.
uint8 flags = 0; ///< NOSAVE: temporary flags
@@ -79,7 +79,7 @@ public:
static const uint16 MAX_COUNT = UINT16_MAX;
CargoPacket();
CargoPacket(StationID first_station, TileIndex source_xy, uint16_t count, SourceType source_type, SourceID source_id);
CargoPacket(StationID first_station, uint16_t count, SourceType source_type, SourceID source_id);
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, const CargoPacket &original);
~CargoPacket();
@@ -97,6 +97,25 @@ public:
this->next_hop = next_hop;
}
/**
* Set the origin of the packet.
*
* Can only be set once.
*
* When a packet is created, it is moved to a station. But at that moment
* in time it is not known yet at which tile the cargo will be picked up.
* As this tile is used for payment information, we delay setting the
* source_xy till first pickup.
*
* @param tile Tile the cargo is being picked up from.
*/
void SetSourceXY(TileIndex tile)
{
if (this->source_xy == INVALID_TILE) {
this->source_xy = tile;
}
}
/**
* Adds some feeder share to the packet.
* @param new_share Feeder share to be added.
@@ -178,12 +197,15 @@ public:
}
/**
* Gets the coordinates of the cargo's source.
* @return Source coordinates of cargo.
* Get the current distance the cargo has traveled.
*
* @param current_tile Current tile of the cargo.
* @return uint The distance (in tiles) traveled.
*/
inline TileIndex GetSourceXY() const
inline uint GetDistance(TileIndex current_tile) const
{
return this->source_xy;
assert(this->source_xy != INVALID_TILE);
return DistanceManhattan(this->source_xy, current_tile);
}
/**
@@ -434,7 +456,7 @@ public:
void InvalidateCache();
bool Stage(bool accepted, StationID current_station, StationIDStack next_station, uint8 order_flags, const GoodsEntry *ge, CargoPayment *payment);
bool Stage(bool accepted, StationID current_station, StationIDStack next_station, uint8_t order_flags, const GoodsEntry *ge, CargoPayment *payment, TileIndex current_tile);
/**
* Marks all cargo in the vehicle as to be kept. This is mostly useful for
@@ -454,7 +476,7 @@ public:
template<MoveToAction Tfrom, MoveToAction Tto>
uint Reassign(uint max_move);
uint Return(uint max_move, StationCargoList *dest, StationID next_station);
uint Unload(uint max_move, StationCargoList *dest, CargoPayment *payment);
uint Unload(uint max_move, StationCargoList *dest, CargoPayment *payment, TileIndex current_tile);
uint Shift(uint max_move, VehicleCargoList *dest);
uint Truncate(uint max_move = UINT_MAX);
uint Reroute(uint max_move, VehicleCargoList *dest, StationID avoid, StationID avoid2, const GoodsEntry *ge);
@@ -471,6 +493,7 @@ public:
{
return cp1->source_xy == cp2->source_xy &&
cp1->periods_in_transit == cp2->periods_in_transit &&
cp1->first_station == cp2->first_station &&
cp1->source_type == cp2->source_type &&
cp1->source_id == cp2->source_id;
}
@@ -578,8 +601,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, StationIDStack next);
uint Load(uint max_move, VehicleCargoList *dest, StationIDStack next);
uint Reserve(uint max_move, VehicleCargoList *dest, StationIDStack next, TileIndex current_tile);
uint Load(uint max_move, VehicleCargoList *dest, StationIDStack next, TileIndex current_tile);
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);
uint RerouteFromSource(uint max_move, StationCargoList *dest, StationID source, StationID avoid, StationID avoid2, const GoodsEntry *ge);
@@ -605,6 +628,7 @@ public:
{
return cp1->source_xy == cp2->source_xy &&
cp1->periods_in_transit == cp2->periods_in_transit &&
cp1->first_station == cp2->first_station &&
cp1->source_type == cp2->source_type &&
cp1->source_id == cp2->source_id;
}