mirror of https://github.com/OpenTTD/OpenTTD
Change: base cargo payment on load tile, not station sign location
parent
0a2bbb0f6c
commit
22066a653a
|
@ -120,6 +120,7 @@ bool CargoLoad::operator()(CargoPacket *cp)
|
|||
{
|
||||
CargoPacket *cp_new = this->Preprocess(cp);
|
||||
if (cp_new == nullptr) return false;
|
||||
cp_new->SetSourceXY(this->current_tile);
|
||||
this->source->RemoveFromCache(cp_new, cp_new->Count());
|
||||
this->destination->Append(cp_new, VehicleCargoList::MTA_KEEP);
|
||||
return cp_new == cp;
|
||||
|
@ -134,6 +135,7 @@ bool CargoReservation::operator()(CargoPacket *cp)
|
|||
{
|
||||
CargoPacket *cp_new = this->Preprocess(cp);
|
||||
if (cp_new == nullptr) return false;
|
||||
cp_new->SetSourceXY(this->current_tile);
|
||||
this->source->reserved_count += cp_new->Count();
|
||||
this->source->RemoveFromCache(cp_new, cp_new->Count());
|
||||
this->destination->Append(cp_new, VehicleCargoList::MTA_LOAD);
|
||||
|
|
|
@ -78,17 +78,19 @@ public:
|
|||
|
||||
/** Action of loading cargo from a station onto a vehicle. */
|
||||
class CargoLoad : public CargoMovement<StationCargoList, VehicleCargoList> {
|
||||
protected:
|
||||
TileIndex current_tile; ///< Current tile cargo loading is happening.
|
||||
public:
|
||||
CargoLoad(StationCargoList *source, VehicleCargoList *destination, uint max_move) :
|
||||
CargoMovement<StationCargoList, VehicleCargoList>(source, destination, max_move) {}
|
||||
CargoLoad(StationCargoList *source, VehicleCargoList *destination, uint max_move, TileIndex current_tile) :
|
||||
CargoMovement<StationCargoList, VehicleCargoList>(source, destination, max_move), current_tile(current_tile) {}
|
||||
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) :
|
||||
CargoLoad(source, destination, max_move) {}
|
||||
CargoReservation(StationCargoList *source, VehicleCargoList *destination, uint max_move, TileIndex current_tile) :
|
||||
CargoLoad(source, destination, max_move, current_tile) {}
|
||||
bool operator()(CargoPacket *cp);
|
||||
};
|
||||
|
||||
|
|
|
@ -34,15 +34,13 @@ 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
|
||||
*/
|
||||
CargoPacket::CargoPacket(StationID first_station, TileIndex source_xy, uint16_t count, SourceType source_type, SourceID source_id) :
|
||||
CargoPacket::CargoPacket(StationID first_station,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)
|
||||
|
@ -808,11 +806,12 @@ uint StationCargoList::Truncate(uint max_move, StationCargoAmountMap *cargo_per_
|
|||
* @param max_move Maximum amount of cargo to reserve.
|
||||
* @param dest VehicleCargoList to reserve for.
|
||||
* @param next_station Next station(s) the loading vehicle will visit.
|
||||
* @param current_tile Current tile the cargo handling is happening on.
|
||||
* @return Amount of cargo actually reserved.
|
||||
*/
|
||||
uint StationCargoList::Reserve(uint max_move, VehicleCargoList *dest, StationIDStack next_station)
|
||||
uint StationCargoList::Reserve(uint max_move, VehicleCargoList *dest, StationIDStack next_station, TileIndex current_tile)
|
||||
{
|
||||
return this->ShiftCargo(CargoReservation(this, dest, max_move), next_station, true);
|
||||
return this->ShiftCargo(CargoReservation(this, dest, max_move, current_tile), next_station, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -821,12 +820,13 @@ uint StationCargoList::Reserve(uint max_move, VehicleCargoList *dest, StationIDS
|
|||
* @param max_move Amount of cargo to load.
|
||||
* @param dest Vehicle cargo list where the cargo resides.
|
||||
* @param next_station Next station(s) the loading vehicle will visit.
|
||||
* @param current_tile Current tile the cargo handling is happening on.
|
||||
* @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, StationIDStack next_station)
|
||||
uint StationCargoList::Load(uint max_move, VehicleCargoList *dest, StationIDStack next_station, TileIndex current_tile)
|
||||
{
|
||||
uint move = std::min(dest->ActionCount(VehicleCargoList::MTA_LOAD), max_move);
|
||||
if (move > 0) {
|
||||
|
@ -834,7 +834,7 @@ uint StationCargoList::Load(uint max_move, VehicleCargoList *dest, StationIDStac
|
|||
dest->Reassign<VehicleCargoList::MTA_LOAD, VehicleCargoList::MTA_KEEP>(move);
|
||||
return move;
|
||||
} else {
|
||||
return this->ShiftCargo(CargoLoad(this, dest, max_move), next_station, true);
|
||||
return this->ShiftCargo(CargoLoad(this, dest, max_move, current_tile), next_station, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
@ -168,6 +187,7 @@ public:
|
|||
*/
|
||||
inline uint GetDistance(TileIndex current_tile) const
|
||||
{
|
||||
assert(this->source_xy != INVALID_TILE);
|
||||
return DistanceManhattan(this->source_xy, current_tile);
|
||||
}
|
||||
|
||||
|
@ -425,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;
|
||||
}
|
||||
};
|
||||
|
@ -522,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);
|
||||
|
||||
|
@ -539,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;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1472,7 +1472,7 @@ struct FinalizeRefitAction
|
|||
{
|
||||
if (this->do_reserve) {
|
||||
this->st->goods[v->cargo_type].cargo.Reserve(v->cargo_cap - v->cargo.RemainingCount(),
|
||||
&v->cargo, this->next_station);
|
||||
&v->cargo, this->next_station, v->tile);
|
||||
}
|
||||
this->consist_capleft[v->cargo_type] += v->cargo_cap - v->cargo.RemainingCount();
|
||||
return true;
|
||||
|
@ -1563,7 +1563,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, *next_station);
|
||||
&v->cargo, *next_station, v->tile);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -1794,7 +1794,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, next_station);
|
||||
uint loaded = ge->cargo.Load(cap_left, &v->cargo, next_station, v->tile);
|
||||
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. */
|
||||
|
|
|
@ -4039,7 +4039,7 @@ static uint UpdateStationWaiting(Station *st, CargoID type, uint amount, SourceT
|
|||
if (amount == 0) return 0;
|
||||
|
||||
StationID next = ge.GetVia(st->index);
|
||||
ge.cargo.Append(new CargoPacket(st->index, st->xy, amount, source_type, source_id), next);
|
||||
ge.cargo.Append(new CargoPacket(st->index, amount, source_type, source_id), next);
|
||||
LinkGraph *lg = nullptr;
|
||||
if (ge.link_graph == INVALID_LINK_GRAPH) {
|
||||
if (LinkGraph::CanAllocateItem()) {
|
||||
|
|
Loading…
Reference in New Issue