Eddi wrote:
no, that's not how that works. if the cargo was loaded 16 days ago, then "days_in_transit" in all the relevant formulas will be 6
But it only applies to new grfs then? I'm sure I got numbers for vanilla game right and this wasn't the case there.
Plus, I investigated the cargo payment graphs ingame and it seems you're right - the graphs are shifted. By default, the graph should be a downward trending line with turning points in "day1" and "day2" value where slope becomes steeper. With FIRS active, it looks like the turning points are in values for "day1", "day2" x2.5 than in documentation (eg for wood day1=about 60 when it should be 24)
As for the calculation, I run through code and found a formula that makes even less sense for me:
Code:
Money GetTransportedGoodsIncome(uint num_pieces, uint dist, byte transit_days, CargoID cargo_type)
{
/* non-important */
const CargoSpec *cs = CargoSpec::Get(cargo_type);
if (!cs->IsValid()) {
/* User changed newgrfs and some vehicle still carries some cargo which is no longer available. */
return 0;
}
/* Use callback to calculate cargo profit, if available */
/* starts here */
if (HasBit(cs->callback_mask, CBM_CARGO_PROFIT_CALC)) {
/* bitwise sum of distance, amount moved, transit days */
uint32 var18 = min(dist, 0xFFFF) | (min(num_pieces, 0xFF) << 16) | (transit_days << 24);
/* CBID_CARGO_PROFIT_CALC = 0x39 = 57 */
uint16 callback = GetCargoCallback(CBID_CARGO_PROFIT_CALC, 0, var18, cs);
/* apply GB function to "callback" */
/* GB can be found https://github.com/OpenTTD/OpenTTD/blob/18ca3e8660f90737d672b6780301ff4b998df56f/src/core/bitmath_func.hpp */
/* GB (x, s, n) = (x << s) & ( 1U << n) - 1) where 1U << 1 = 1 = 00000001, 1U << 2 = 2 = 00000010 etc * /
if (callback != CALLBACK_FAILED) {
int result = GB(callback, 0, 14);
/* Simulate a 15 bit signed value */
/* if "callback" is max value for 14bits, lower it by 1, result = 16384-1 = 16383; this is max "result" */
if (HasBit(callback, 14)) result -= 0x4000;
/* "The result should be a signed multiplier that gets multiplied
* by the amount of cargo moved and the price factor, then gets
* divided by 8192." */
return result * num_pieces * cs->current_payment / 8192;
}
}
I'm not really skilled in C++ so I may be making some mistakes here, I can elaborate if someone's willing to check me up with this