summaryrefslogtreecommitdiff
path: root/src/newgrf_engine.cpp
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2007-02-22 22:09:51 +0000
committerpeter1138 <peter1138@openttd.org>2007-02-22 22:09:51 +0000
commit60620049606d5ce556d26ddaf401fcf5f28f1954 (patch)
tree432cebbeb0022164d562965a95d0ae34877f212e /src/newgrf_engine.cpp
parent4f41a8a5e29795e52f999089cd11b3b5a149443d (diff)
downloadopenttd-60620049606d5ce556d26ddaf401fcf5f28f1954.tar.xz
(svn r8849) -Codechange: Replace hardcoded global/climate cargo mapping tables with dynamically generated data. Change associated code to use new functions.
Diffstat (limited to 'src/newgrf_engine.cpp')
-rw-r--r--src/newgrf_engine.cpp23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp
index 2c3e0ac6a..7e21cc8ec 100644
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -539,10 +539,9 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
const Vehicle *u;
byte cargo_classes = 0;
uint common_cargo_best = 0;
- uint common_cargos[NUM_GLOBAL_CID];
+ uint common_cargos[NUM_CARGO];
byte user_def_data = 0;
- CargoID cargo;
- CargoID common_cargo_type = GC_PASSENGERS;
+ CargoID common_cargo_type = CT_PASSENGERS;
/* Reset our arrays */
memset(common_cargos, 0, sizeof(common_cargos));
@@ -550,18 +549,17 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
for (u = v; u != NULL; u = u->next) {
/* Skip empty engines */
if (u->cargo_cap == 0) continue;
- /* Map from climate to global cargo ID */
- cargo = _global_cargo_id[_opt.landscape][u->cargo_type];
- cargo_classes |= GetCargo(cargo)->classes;
- common_cargos[cargo]++;
+
+ cargo_classes |= GetCargo(u->cargo_type)->classes;
+ common_cargos[u->cargo_type]++;
user_def_data |= RailVehInfo(u->engine_type)->user_def_data;
}
/* Pick the most common cargo type */
- for (cargo = 0; cargo < NUM_GLOBAL_CID; cargo++) {
+ for (CargoID cargo = 0; cargo < NUM_CARGO; cargo++) {
if (common_cargos[cargo] > common_cargo_best) {
common_cargo_best = common_cargos[cargo];
- common_cargo_type = cargo;
+ common_cargo_type = GetCargo(cargo)->bitnum;
}
}
@@ -608,10 +606,9 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
* ww - cargo unit weight in 1/16 tons, same as cargo prop. 0F.
* cccc - the cargo class value of the cargo transported by the vehicle.
*/
- CargoID cid = _global_cargo_id[_opt.landscape][v->cargo_type];
const CargoSpec *cs = GetCargo(v->cargo_type);
- return (cs->classes << 16) | (cs->weight << 8) | cid;
+ return (cs->classes << 16) | (cs->weight << 8) | cs->bitnum;
}
case 0x48: return GetVehicleTypeInfo(v->engine_type); /* Vehicle Type Info */
@@ -823,7 +820,7 @@ static const SpriteGroup *GetVehicleSpriteGroup(EngineID engine, const Vehicle *
if (v == NULL) {
cargo = GC_PURCHASE;
} else {
- cargo = _global_cargo_id[_opt.landscape][v->cargo_type];
+ cargo = GetCargo(v->cargo_type)->bitnum;
assert(cargo != GC_INVALID);
if (v->type == VEH_Train) {
@@ -889,7 +886,7 @@ SpriteID GetRotorOverrideSprite(EngineID engine, const Vehicle *v, bool info_vie
bool UsesWagonOverride(const Vehicle* v)
{
assert(v->type == VEH_Train);
- return GetWagonOverrideSpriteSet(v->engine_type, _global_cargo_id[_opt.landscape][v->cargo_type], v->u.rail.first_engine) != NULL;
+ return GetWagonOverrideSpriteSet(v->engine_type, GetCargo(v->cargo_type)->bitnum, v->u.rail.first_engine) != NULL;
}
/**