(svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
* cheating by starting to unload and after getting paid rushing to the depot to get sold (or unloading, loading and getting paid again for the remainder) * cargo being dropped onto a station at the moment a stockpiling industry doesn't accept it anymore * industries getting cargo that has not been unloaded yet and subsequently dumping it back on the station in one go Note: you will now get paid after the unloading has finished, so you'll have to wait a bit longer for 'your' money.
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include "stdafx.h"
|
||||
#include "station_base.h"
|
||||
#include "core/pool_func.hpp"
|
||||
#include "economy_base.h"
|
||||
|
||||
/* Initialize the cargopacket-pool */
|
||||
CargoPacketPool _cargopacket_pool("CargoPacket");
|
||||
@@ -26,7 +27,6 @@ CargoPacket::CargoPacket(StationID source, uint16 count)
|
||||
this->count = count;
|
||||
this->days_in_transit = 0;
|
||||
this->feeder_share = 0;
|
||||
this->paid_for = false;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -99,9 +99,10 @@ void CargoList::Truncate(uint count)
|
||||
InvalidateCache();
|
||||
}
|
||||
|
||||
bool CargoList::MoveTo(CargoList *dest, uint count, CargoList::MoveToAction mta, uint data)
|
||||
bool CargoList::MoveTo(CargoList *dest, uint count, CargoList::MoveToAction mta, CargoPayment *payment, uint data)
|
||||
{
|
||||
assert(mta == MTA_FINAL_DELIVERY || dest != NULL);
|
||||
assert(mta == MTA_UNLOAD || mta == MTA_CARGO_LOAD || payment != NULL);
|
||||
CargoList tmp;
|
||||
|
||||
while (!packets.empty() && count > 0) {
|
||||
@@ -114,20 +115,25 @@ bool CargoList::MoveTo(CargoList *dest, uint count, CargoList::MoveToAction mta,
|
||||
if (cp->source == data) {
|
||||
tmp.Append(cp);
|
||||
} else {
|
||||
payment->PayFinalDelivery(cp, cp->count);
|
||||
count -= cp->count;
|
||||
delete cp;
|
||||
}
|
||||
break;
|
||||
continue; // of the loop
|
||||
|
||||
case MTA_CARGO_LOAD:
|
||||
cp->loaded_at_xy = data;
|
||||
/* When cargo is moved into another vehicle you have *always* paid for it */
|
||||
cp->paid_for = false;
|
||||
/* FALL THROUGH */
|
||||
case MTA_OTHER:
|
||||
count -= cp->count;
|
||||
dest->packets.push_back(cp);
|
||||
break;
|
||||
|
||||
case MTA_TRANSFER:
|
||||
payment->PayTransfer(cp, cp->count);
|
||||
break;
|
||||
|
||||
case MTA_UNLOAD:
|
||||
break;
|
||||
}
|
||||
count -= cp->count;
|
||||
dest->packets.push_back(cp);
|
||||
} else {
|
||||
/* Can move only part of the packet, so split it into two pieces */
|
||||
if (mta != MTA_FINAL_DELIVERY) {
|
||||
@@ -142,11 +148,13 @@ bool CargoList::MoveTo(CargoList *dest, uint count, CargoList::MoveToAction mta,
|
||||
|
||||
cp_new->days_in_transit = cp->days_in_transit;
|
||||
cp_new->feeder_share = fs;
|
||||
/* When cargo is moved into another vehicle you have *always* paid for it */
|
||||
cp_new->paid_for = (mta == MTA_CARGO_LOAD) ? false : cp->paid_for;
|
||||
|
||||
cp_new->count = count;
|
||||
dest->packets.push_back(cp_new);
|
||||
|
||||
if (mta == MTA_TRANSFER) payment->PayTransfer(cp_new, count);
|
||||
} else {
|
||||
payment->PayFinalDelivery(cp, count);
|
||||
}
|
||||
cp->count -= count;
|
||||
|
||||
@@ -158,7 +166,7 @@ bool CargoList::MoveTo(CargoList *dest, uint count, CargoList::MoveToAction mta,
|
||||
|
||||
if (mta == MTA_FINAL_DELIVERY && !tmp.Empty()) {
|
||||
/* There are some packets that could not be delivered at the station, put them back */
|
||||
tmp.MoveTo(this, UINT_MAX);
|
||||
tmp.MoveTo(this, UINT_MAX, MTA_UNLOAD, NULL);
|
||||
tmp.packets.clear();
|
||||
}
|
||||
|
||||
@@ -172,7 +180,6 @@ void CargoList::InvalidateCache()
|
||||
{
|
||||
empty = packets.empty();
|
||||
count = 0;
|
||||
unpaid_cargo = false;
|
||||
feeder_share = 0;
|
||||
source = INVALID_STATION;
|
||||
days_in_transit = 0;
|
||||
@@ -182,7 +189,6 @@ void CargoList::InvalidateCache()
|
||||
uint dit = 0;
|
||||
for (List::const_iterator it = packets.begin(); it != packets.end(); it++) {
|
||||
count += (*it)->count;
|
||||
unpaid_cargo |= !(*it)->paid_for;
|
||||
dit += (*it)->days_in_transit * (*it)->count;
|
||||
feeder_share += (*it)->feeder_share;
|
||||
}
|
||||
|
Reference in New Issue
Block a user