1132 int32 GetTransportedGoodsIncome(uint num_pieces, uint dist, byte transit_days, CargoID cargo_type) |
1132 int32 GetTransportedGoodsIncome(uint num_pieces, uint dist, byte transit_days, CargoID cargo_type) |
1133 { |
1133 { |
1134 const CargoSpec *cs = GetCargo(cargo_type); |
1134 const CargoSpec *cs = GetCargo(cargo_type); |
1135 byte f; |
1135 byte f; |
1136 |
1136 |
|
1137 /* Use callback to calculate cargo profit, if available */ |
|
1138 if (HASBIT(cs->callback_mask, CBM_CARGO_PROFIT_CALC)) { |
|
1139 uint32 var18 = min(dist, 0xFFFF) | (min(num_pieces, 0xFF) << 16) | (transit_days << 24); |
|
1140 uint16 callback = GetCargoCallback(CBID_CARGO_PROFIT_CALC, 0, var18, cs); |
|
1141 if (callback != CALLBACK_FAILED) { |
|
1142 int result = GB(callback, 0, 14); |
|
1143 |
|
1144 /* Simulate a 15 bit signed value */ |
|
1145 if (HASBIT(callback, 14)) result = 0x4000 - result; |
|
1146 |
|
1147 /* "The result should be a signed multiplier that gets multiplied |
|
1148 * by the amount of cargo moved and the price factor, then gets |
|
1149 * divided by 8192." */ |
|
1150 return result * num_pieces * _cargo_payment_rates[cargo_type] / 8192; |
|
1151 } |
|
1152 } |
|
1153 |
1137 /* zero the distance if it's the bank and very short transport. */ |
1154 /* zero the distance if it's the bank and very short transport. */ |
1138 if (_opt.landscape == LT_TEMPERATE && cs->label == 'VALU' && dist < 10) |
1155 if (_opt.landscape == LT_TEMPERATE && cs->label == 'VALU' && dist < 10) |
1139 dist = 0; |
1156 dist = 0; |
1140 |
1157 |
1141 f = 255; |
1158 f = 255; |