(svn r17435) -Codechange: Move _cargo_payment_rates[] to CargoSpec::current_payment.

This commit is contained in:
frosch 2009-09-06 20:36:17 +00:00
parent 00ed9c83ee
commit eb1306110a
3 changed files with 12 additions and 7 deletions

View File

@ -12,6 +12,7 @@
#ifndef CARGOTYPE_H
#define CARGOTYPE_H
#include "economy_type.h"
#include "cargo_type.h"
#include "gfx_type.h"
#include "strings_type.h"
@ -57,6 +58,8 @@ struct CargoSpec {
const struct GRFFile *grffile; ///< NewGRF where 'group' belongs to
const struct SpriteGroup *group;
Money current_payment;
/**
* Determines index of this cargospec
* @return index (in the CargoSpec::array array)

View File

@ -107,7 +107,6 @@ const ScoreInfo _score_info[] = {
int _score_part[MAX_COMPANIES][SCORE_END];
Economy _economy;
Prices _price;
static Money _cargo_payment_rates[NUM_CARGO];
Money _additional_cash_required;
static byte _price_base_multiplier[NUM_PRICES];
@ -665,10 +664,9 @@ void RecomputePrices()
}
/* Setup cargo payment */
memset(_cargo_payment_rates, 0, sizeof(_cargo_payment_rates));
const CargoSpec *cs;
CargoSpec *cs;
FOR_ALL_CARGOSPECS(cs) {
_cargo_payment_rates[cs->Index()] = ((int64)cs->initial_payment * _economy.inflation_payment) >> 16;
cs->current_payment = ((int64)cs->initial_payment * _economy.inflation_payment) >> 16;
}
InvalidateWindowClasses(WC_BUILD_VEHICLE);
@ -803,6 +801,10 @@ Money GetPriceByIndex(uint8 index)
Money GetTransportedGoodsIncome(uint num_pieces, uint dist, byte transit_days, CargoID cargo_type)
{
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 */
if (HasBit(cs->callback_mask, CBM_CARGO_PROFIT_CALC)) {
@ -817,7 +819,7 @@ Money GetTransportedGoodsIncome(uint num_pieces, uint dist, byte transit_days, C
/* "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 * _cargo_payment_rates[cargo_type] / 8192;
return result * num_pieces * cs->current_payment / 8192;
}
}
@ -845,7 +847,7 @@ Money GetTransportedGoodsIncome(uint num_pieces, uint dist, byte transit_days, C
*/
const int time_factor = max(MAX_TIME_FACTOR - days_over_days1 - days_over_days2, MIN_TIME_FACTOR);
return BigMulS(dist * time_factor * num_pieces, _cargo_payment_rates[cargo_type], 21);
return BigMulS(dist * time_factor * num_pieces, cs->current_payment, 21);
}
/** The industries we've currently brought cargo to. */

View File

@ -10,7 +10,7 @@
/** @file cargo_const.h Table of all default cargo types */
#define MK(bt, label, c, e, f, g, h, fr, te, ks1, ks2, ks3, ks4, ks5, l, m) \
{bt, label, c, c, e, f, {g, h}, fr, te, 0, 0, ks1, ks2, ks3, ks4, ks5, l, m, NULL, NULL}
{bt, label, c, c, e, f, {g, h}, fr, te, 0, 0, ks1, ks2, ks3, ks4, ks5, l, m, NULL, NULL, 0}
static const CargoSpec _default_cargo[] = {
MK( 0, 'PASS', 152, 1, 3185, 0, 24, false, TE_PASSENGERS,
STR_CARGO_PLURAL_PASSENGERS, STR_CARGO_SINGULAR_PASSENGER, STR_PASSENGERS, STR_QUANTITY_PASSENGERS, STR_ABBREV_PASSENGERS,