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

This commit is contained in:
Patric Stout
2023-09-13 16:41:09 +02:00
committed by GitHub
parent ba67f39db6
commit 9c49a61249
7 changed files with 79 additions and 45 deletions

View File

@@ -44,7 +44,7 @@ private:
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.
@@ -62,7 +62,7 @@ public:
static const uint16_t 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, CargoPacket &original);
@@ -82,6 +82,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.
@@ -161,12 +180,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);
}
/**
@@ -386,7 +408,7 @@ public:
void InvalidateCache();
bool Stage(bool accepted, StationID current_station, StationIDStack next_station, uint8_t 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
@@ -406,7 +428,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);
@@ -423,6 +445,7 @@ public:
return cp1->source_xy == cp2->source_xy &&
cp1->periods_in_transit == cp2->periods_in_transit &&
cp1->source_type == cp2->source_type &&
cp1->first_station == cp2->first_station &&
cp1->source_id == cp2->source_id;
}
};
@@ -520,8 +543,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);
@@ -537,6 +560,7 @@ public:
return cp1->source_xy == cp2->source_xy &&
cp1->periods_in_transit == cp2->periods_in_transit &&
cp1->source_type == cp2->source_type &&
cp1->first_station == cp2->first_station &&
cp1->source_id == cp2->source_id;
}
};