summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2009-09-06 20:36:17 +0000
committerfrosch <frosch@openttd.org>2009-09-06 20:36:17 +0000
commiteb1306110a84eb1cb4f1d755bb9e24b745171749 (patch)
treef58ce88620c1ad6c1640c0f9ed19659ca8d35ded
parent00ed9c83eed27ca566b526cd06922e108c511e1d (diff)
downloadopenttd-eb1306110a84eb1cb4f1d755bb9e24b745171749.tar.xz
(svn r17435) -Codechange: Move _cargo_payment_rates[] to CargoSpec::current_payment.
-rw-r--r--src/cargotype.h3
-rw-r--r--src/economy.cpp14
-rw-r--r--src/table/cargo_const.h2
3 files changed, 12 insertions, 7 deletions
diff --git a/src/cargotype.h b/src/cargotype.h
index 385c73baf..a960b5764 100644
--- a/src/cargotype.h
+++ b/src/cargotype.h
@@ -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)
diff --git a/src/economy.cpp b/src/economy.cpp
index bfbd0028c..1eaaf1160 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -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. */
diff --git a/src/table/cargo_const.h b/src/table/cargo_const.h
index 2ace23258..410713f11 100644
--- a/src/table/cargo_const.h
+++ b/src/table/cargo_const.h
@@ -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,