mirror of https://github.com/OpenTTD/OpenTTD
Change: base cargo payment on unload tile, not station sign location
parent
d1a0ca67be
commit
0a2bbb0f6c
|
@ -107,7 +107,7 @@ bool CargoDelivery::operator()(CargoPacket *cp)
|
||||||
{
|
{
|
||||||
uint remove = this->Preprocess(cp);
|
uint remove = this->Preprocess(cp);
|
||||||
this->source->RemoveFromMeta(cp, VehicleCargoList::MTA_DELIVER, remove);
|
this->source->RemoveFromMeta(cp, VehicleCargoList::MTA_DELIVER, remove);
|
||||||
this->payment->PayFinalDelivery(cp, remove);
|
this->payment->PayFinalDelivery(cp, remove, this->current_tile);
|
||||||
return this->Postprocess(cp, remove);
|
return this->Postprocess(cp, remove);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,10 +38,11 @@ public:
|
||||||
/** Action of final delivery of cargo. */
|
/** Action of final delivery of cargo. */
|
||||||
class CargoDelivery : public CargoRemoval<VehicleCargoList> {
|
class CargoDelivery : public CargoRemoval<VehicleCargoList> {
|
||||||
protected:
|
protected:
|
||||||
|
TileIndex current_tile; ///< Current tile cargo delivery is happening.
|
||||||
CargoPayment *payment; ///< Payment object where payments will be registered.
|
CargoPayment *payment; ///< Payment object where payments will be registered.
|
||||||
public:
|
public:
|
||||||
CargoDelivery(VehicleCargoList *source, uint max_move, CargoPayment *payment) :
|
CargoDelivery(VehicleCargoList *source, uint max_move, CargoPayment *payment, TileIndex current_tile) :
|
||||||
CargoRemoval<VehicleCargoList>(source, max_move), payment(payment) {}
|
CargoRemoval<VehicleCargoList>(source, max_move), current_tile(current_tile), payment(payment) {}
|
||||||
bool operator()(CargoPacket *cp);
|
bool operator()(CargoPacket *cp);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -431,9 +431,10 @@ void VehicleCargoList::AgeCargo()
|
||||||
* @param order_flags OrderUnloadFlags that will apply to the unload operation.
|
* @param order_flags OrderUnloadFlags that will apply to the unload operation.
|
||||||
* @param ge GoodsEntry for getting the flows.
|
* @param ge GoodsEntry for getting the flows.
|
||||||
* @param payment Payment object for registering transfers.
|
* @param payment Payment object for registering transfers.
|
||||||
|
* @param current_tile Current tile the cargo handling is happening on.
|
||||||
* return If any cargo will be unloaded.
|
* return If any cargo will be unloaded.
|
||||||
*/
|
*/
|
||||||
bool VehicleCargoList::Stage(bool accepted, StationID current_station, StationIDStack next_station, uint8_t order_flags, const GoodsEntry *ge, CargoPayment *payment)
|
bool VehicleCargoList::Stage(bool accepted, StationID current_station, StationIDStack next_station, uint8_t order_flags, const GoodsEntry *ge, CargoPayment *payment, TileIndex current_tile)
|
||||||
{
|
{
|
||||||
this->AssertCountConsistency();
|
this->AssertCountConsistency();
|
||||||
assert(this->action_counts[MTA_LOAD] == 0);
|
assert(this->action_counts[MTA_LOAD] == 0);
|
||||||
|
@ -509,7 +510,7 @@ bool VehicleCargoList::Stage(bool accepted, StationID current_station, StationID
|
||||||
case MTA_TRANSFER:
|
case MTA_TRANSFER:
|
||||||
this->packets.push_front(cp);
|
this->packets.push_front(cp);
|
||||||
/* Add feeder share here to allow reusing field for next station. */
|
/* Add feeder share here to allow reusing field for next station. */
|
||||||
share = payment->PayTransfer(cp, cp->count);
|
share = payment->PayTransfer(cp, cp->count, current_tile);
|
||||||
cp->AddFeederShare(share);
|
cp->AddFeederShare(share);
|
||||||
this->feeder_share += share;
|
this->feeder_share += share;
|
||||||
cp->next_hop = cargo_next;
|
cp->next_hop = cargo_next;
|
||||||
|
@ -616,9 +617,10 @@ uint VehicleCargoList::Shift(uint max_move, VehicleCargoList *dest)
|
||||||
* @param dest StationCargoList to add transferred cargo to.
|
* @param dest StationCargoList to add transferred cargo to.
|
||||||
* @param max_move Maximum amount of cargo to move.
|
* @param max_move Maximum amount of cargo to move.
|
||||||
* @param payment Payment object to register payments in.
|
* @param payment Payment object to register payments in.
|
||||||
|
* @param current_tile Current tile the cargo handling is happening on.
|
||||||
* @return Amount of cargo actually unloaded.
|
* @return Amount of cargo actually unloaded.
|
||||||
*/
|
*/
|
||||||
uint VehicleCargoList::Unload(uint max_move, StationCargoList *dest, CargoPayment *payment)
|
uint VehicleCargoList::Unload(uint max_move, StationCargoList *dest, CargoPayment *payment, TileIndex current_tile)
|
||||||
{
|
{
|
||||||
uint moved = 0;
|
uint moved = 0;
|
||||||
if (this->action_counts[MTA_TRANSFER] > 0) {
|
if (this->action_counts[MTA_TRANSFER] > 0) {
|
||||||
|
@ -628,7 +630,7 @@ uint VehicleCargoList::Unload(uint max_move, StationCargoList *dest, CargoPaymen
|
||||||
}
|
}
|
||||||
if (this->action_counts[MTA_TRANSFER] == 0 && this->action_counts[MTA_DELIVER] > 0 && moved < max_move) {
|
if (this->action_counts[MTA_TRANSFER] == 0 && this->action_counts[MTA_DELIVER] > 0 && moved < max_move) {
|
||||||
uint move = std::min(this->action_counts[MTA_DELIVER], max_move - moved);
|
uint move = std::min(this->action_counts[MTA_DELIVER], max_move - moved);
|
||||||
this->ShiftCargo(CargoDelivery(this, move, payment));
|
this->ShiftCargo(CargoDelivery(this, move, payment, current_tile));
|
||||||
moved += move;
|
moved += move;
|
||||||
}
|
}
|
||||||
return moved;
|
return moved;
|
||||||
|
|
|
@ -161,12 +161,14 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the coordinates of the cargo's source.
|
* Get the current distance the cargo has traveled.
|
||||||
* @return Source coordinates of cargo.
|
*
|
||||||
|
* @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;
|
return DistanceManhattan(this->source_xy, current_tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -386,7 +388,7 @@ public:
|
||||||
|
|
||||||
void InvalidateCache();
|
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
|
* Marks all cargo in the vehicle as to be kept. This is mostly useful for
|
||||||
|
@ -406,7 +408,7 @@ public:
|
||||||
template<MoveToAction Tfrom, MoveToAction Tto>
|
template<MoveToAction Tfrom, MoveToAction Tto>
|
||||||
uint Reassign(uint max_move);
|
uint Reassign(uint max_move);
|
||||||
uint Return(uint max_move, StationCargoList *dest, StationID next_station);
|
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 Shift(uint max_move, VehicleCargoList *dest);
|
||||||
uint Truncate(uint max_move = UINT_MAX);
|
uint Truncate(uint max_move = UINT_MAX);
|
||||||
uint Reroute(uint max_move, VehicleCargoList *dest, StationID avoid, StationID avoid2, const GoodsEntry *ge);
|
uint Reroute(uint max_move, VehicleCargoList *dest, StationID avoid, StationID avoid2, const GoodsEntry *ge);
|
||||||
|
|
|
@ -1096,7 +1096,7 @@ static uint DeliverGoodsToIndustry(const Station *st, CargoID cargo_type, uint n
|
||||||
* @param num_pieces amount of cargo delivered
|
* @param num_pieces amount of cargo delivered
|
||||||
* @param cargo_type the type of cargo that is delivered
|
* @param cargo_type the type of cargo that is delivered
|
||||||
* @param dest Station the cargo has been unloaded
|
* @param dest Station the cargo has been unloaded
|
||||||
* @param source_tile The origin of the cargo for distance calculation
|
* @param distance The distance the cargo has traveled.
|
||||||
* @param periods_in_transit Travel time in cargo aging periods
|
* @param periods_in_transit Travel time in cargo aging periods
|
||||||
* @param company The company delivering the cargo
|
* @param company The company delivering the cargo
|
||||||
* @param src_type Type of source of cargo (industry, town, headquarters)
|
* @param src_type Type of source of cargo (industry, town, headquarters)
|
||||||
|
@ -1104,7 +1104,7 @@ static uint DeliverGoodsToIndustry(const Station *st, CargoID cargo_type, uint n
|
||||||
* @return Revenue for delivering cargo
|
* @return Revenue for delivering cargo
|
||||||
* @note The cargo is just added to the stockpile of the industry. It is due to the caller to trigger the industry's production machinery
|
* @note The cargo is just added to the stockpile of the industry. It is due to the caller to trigger the industry's production machinery
|
||||||
*/
|
*/
|
||||||
static Money DeliverGoods(int num_pieces, CargoID cargo_type, StationID dest, TileIndex source_tile, uint16_t periods_in_transit, Company *company, SourceType src_type, SourceID src)
|
static Money DeliverGoods(int num_pieces, CargoID cargo_type, StationID dest, uint distance, uint16_t periods_in_transit, Company *company, SourceType src_type, SourceID src)
|
||||||
{
|
{
|
||||||
assert(num_pieces > 0);
|
assert(num_pieces > 0);
|
||||||
|
|
||||||
|
@ -1131,7 +1131,7 @@ static Money DeliverGoods(int num_pieces, CargoID cargo_type, StationID dest, Ti
|
||||||
st->town->received[cs->town_effect].new_act += accepted_total;
|
st->town->received[cs->town_effect].new_act += accepted_total;
|
||||||
|
|
||||||
/* Determine profit */
|
/* Determine profit */
|
||||||
Money profit = GetTransportedGoodsIncome(accepted_total, DistanceManhattan(source_tile, st->xy), periods_in_transit, cargo_type);
|
Money profit = GetTransportedGoodsIncome(accepted_total, distance, periods_in_transit, cargo_type);
|
||||||
|
|
||||||
/* Update the cargo monitor. */
|
/* Update the cargo monitor. */
|
||||||
AddCargoDelivery(cargo_type, company->index, accepted_total - accepted_ind, src_type, src, st);
|
AddCargoDelivery(cargo_type, company->index, accepted_total - accepted_ind, src_type, src, st);
|
||||||
|
@ -1225,15 +1225,16 @@ CargoPayment::~CargoPayment()
|
||||||
* Handle payment for final delivery of the given cargo packet.
|
* Handle payment for final delivery of the given cargo packet.
|
||||||
* @param cp The cargo packet to pay for.
|
* @param cp The cargo packet to pay for.
|
||||||
* @param count The number of packets to pay for.
|
* @param count The number of packets to pay for.
|
||||||
|
* @param current_tile Current tile the payment is happening on.
|
||||||
*/
|
*/
|
||||||
void CargoPayment::PayFinalDelivery(const CargoPacket *cp, uint count)
|
void CargoPayment::PayFinalDelivery(const CargoPacket *cp, uint count, TileIndex current_tile)
|
||||||
{
|
{
|
||||||
if (this->owner == nullptr) {
|
if (this->owner == nullptr) {
|
||||||
this->owner = Company::Get(this->front->owner);
|
this->owner = Company::Get(this->front->owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Handle end of route payment */
|
/* Handle end of route payment */
|
||||||
Money profit = DeliverGoods(count, this->ct, this->current_station, cp->GetSourceXY(), cp->GetPeriodsInTransit(), this->owner, cp->GetSourceType(), cp->GetSourceID());
|
Money profit = DeliverGoods(count, this->ct, this->current_station, cp->GetDistance(current_tile), cp->GetPeriodsInTransit(), this->owner, cp->GetSourceType(), cp->GetSourceID());
|
||||||
this->route_profit += profit;
|
this->route_profit += profit;
|
||||||
|
|
||||||
/* The vehicle's profit is whatever route profit there is minus feeder shares. */
|
/* The vehicle's profit is whatever route profit there is minus feeder shares. */
|
||||||
|
@ -1244,15 +1245,16 @@ void CargoPayment::PayFinalDelivery(const CargoPacket *cp, uint count)
|
||||||
* Handle payment for transfer of the given cargo packet.
|
* Handle payment for transfer of the given cargo packet.
|
||||||
* @param cp The cargo packet to pay for; actual payment won't be made!.
|
* @param cp The cargo packet to pay for; actual payment won't be made!.
|
||||||
* @param count The number of packets to pay for.
|
* @param count The number of packets to pay for.
|
||||||
|
* @param current_tile Current tile the payment is happening on.
|
||||||
* @return The amount of money paid for the transfer.
|
* @return The amount of money paid for the transfer.
|
||||||
*/
|
*/
|
||||||
Money CargoPayment::PayTransfer(const CargoPacket *cp, uint count)
|
Money CargoPayment::PayTransfer(const CargoPacket *cp, uint count, TileIndex current_tile)
|
||||||
{
|
{
|
||||||
|
/* 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 */
|
||||||
Money profit = -cp->GetFeederShare(count) + GetTransportedGoodsIncome(
|
Money profit = -cp->GetFeederShare(count) + GetTransportedGoodsIncome(
|
||||||
count,
|
count,
|
||||||
/* pay transfer vehicle the difference between the payment for the journey from
|
cp->GetDistance(current_tile),
|
||||||
* the source to the current point, and the sum of the previous transfer payments */
|
|
||||||
DistanceManhattan(cp->GetSourceXY(), Station::Get(this->current_station)->xy),
|
|
||||||
cp->GetPeriodsInTransit(),
|
cp->GetPeriodsInTransit(),
|
||||||
this->ct);
|
this->ct);
|
||||||
|
|
||||||
|
@ -1294,7 +1296,8 @@ void PrepareUnload(Vehicle *front_v)
|
||||||
HasBit(ge->status, GoodsEntry::GES_ACCEPTANCE),
|
HasBit(ge->status, GoodsEntry::GES_ACCEPTANCE),
|
||||||
front_v->last_station_visited, next_station,
|
front_v->last_station_visited, next_station,
|
||||||
front_v->current_order.GetUnloadType(), ge,
|
front_v->current_order.GetUnloadType(), ge,
|
||||||
front_v->cargo_payment);
|
front_v->cargo_payment,
|
||||||
|
v->tile);
|
||||||
if (v->cargo.UnloadCount() > 0) SetBit(v->vehicle_flags, VF_CARGO_UNLOADING);
|
if (v->cargo.UnloadCount() > 0) SetBit(v->vehicle_flags, VF_CARGO_UNLOADING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1721,7 +1724,7 @@ static void LoadUnloadVehicle(Vehicle *front)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
amount_unloaded = v->cargo.Unload(amount_unloaded, &ge->cargo, payment);
|
amount_unloaded = v->cargo.Unload(amount_unloaded, &ge->cargo, payment, v->tile);
|
||||||
remaining = v->cargo.UnloadCount() > 0;
|
remaining = v->cargo.UnloadCount() > 0;
|
||||||
if (amount_unloaded > 0) {
|
if (amount_unloaded > 0) {
|
||||||
dirty_vehicle = true;
|
dirty_vehicle = true;
|
||||||
|
|
|
@ -37,8 +37,8 @@ struct CargoPayment : CargoPaymentPool::PoolItem<&_cargo_payment_pool> {
|
||||||
CargoPayment(Vehicle *front);
|
CargoPayment(Vehicle *front);
|
||||||
~CargoPayment();
|
~CargoPayment();
|
||||||
|
|
||||||
Money PayTransfer(const CargoPacket *cp, uint count);
|
Money PayTransfer(const CargoPacket *cp, uint count, TileIndex current_tile);
|
||||||
void PayFinalDelivery(const CargoPacket *cp, uint count);
|
void PayFinalDelivery(const CargoPacket *cp, uint count, TileIndex current_tile);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the currently handled cargo type.
|
* Sets the currently handled cargo type.
|
||||||
|
|
Loading…
Reference in New Issue