summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2007-02-24 23:36:40 +0000
committerpeter1138 <peter1138@openttd.org>2007-02-24 23:36:40 +0000
commit4c4b035175a6b8c23793bc3250c75bf50c4d72bd (patch)
tree368b3cf550c0fcbbf2c814f0896d36aa12a8e28d
parent29c81427842d282127c0e12789a156a1f833dcae (diff)
downloadopenttd-4c4b035175a6b8c23793bc3250c75bf50c4d72bd.tar.xz
(svn r8891) -Codechange: Remove remains of global cargo scheme. All cargo mapping is now dealt with only in NewGRF code, on load where possible.
-rw-r--r--src/cargotype.cpp22
-rw-r--r--src/cargotype.h2
-rw-r--r--src/newgrf.cpp19
-rw-r--r--src/newgrf_cargo.h39
-rw-r--r--src/newgrf_engine.cpp37
-rw-r--r--src/newgrf_station.cpp20
-rw-r--r--src/newgrf_station.h4
-rw-r--r--src/vehicle.cpp5
-rw-r--r--src/vehicle_gui.cpp8
9 files changed, 42 insertions, 114 deletions
diff --git a/src/cargotype.cpp b/src/cargotype.cpp
index 63253847b..be8403ee5 100644
--- a/src/cargotype.cpp
+++ b/src/cargotype.cpp
@@ -16,10 +16,7 @@ static CargoSpec _cargo[NUM_CARGO];
static const byte INVALID_CARGO = 0xFF;
-/* Quick mapping from cargo type 'bitnums' to real cargo IDs */
-static CargoID _cargo_bitnum_map[32];
-
-/* Bitmask of cargo type 'bitnums' availabe */
+/* Bitmask of cargo types available */
uint32 _cargo_mask;
@@ -31,7 +28,6 @@ void SetupCargoForClimate(LandscapeID l)
memset(_cargo, 0, sizeof(_cargo));
for (CargoID i = 0; i < lengthof(_cargo); i++) _cargo[i].bitnum = INVALID_CARGO;
- memset(_cargo_bitnum_map, CT_INVALID, sizeof(_cargo_bitnum_map));
_cargo_mask = 0;
for (CargoID i = 0; i < lengthof(_default_climate_cargo[l]); i++) {
@@ -43,12 +39,8 @@ void SetupCargoForClimate(LandscapeID l)
if (_default_cargo[j].label == cl) {
_cargo[i] = _default_cargo[j];
- /* Populate the bitnum map and masks */
- byte bitnum = _cargo[i].bitnum;
- if (bitnum < lengthof(_cargo_bitnum_map)) {
- _cargo_bitnum_map[bitnum] = i;
- SETBIT(_cargo_mask, bitnum);
- }
+ /* Populate the available cargo mask */
+ SETBIT(_cargo_mask, i);
break;
}
}
@@ -63,14 +55,6 @@ const CargoSpec *GetCargo(CargoID c)
}
-CargoID GetCargoIDByBitnum(byte bitnum)
-{
- assert(bitnum < lengthof(_cargo_bitnum_map));
- assert(_cargo_bitnum_map[bitnum] != CT_INVALID);
- return _cargo_bitnum_map[bitnum];
-}
-
-
bool CargoSpec::IsValid() const
{
return bitnum != INVALID_CARGO;
diff --git a/src/cargotype.h b/src/cargotype.h
index a584aef98..e006bc993 100644
--- a/src/cargotype.h
+++ b/src/cargotype.h
@@ -45,8 +45,6 @@ extern uint32 _cargo_mask;
void SetupCargoForClimate(LandscapeID l);
/* Retrieve cargo details for the given cargo ID */
const CargoSpec *GetCargo(CargoID c);
-/* Get the cargo ID of a cargo bitnum */
-CargoID GetCargoIDByBitnum(byte bitnum);
/* Get the cargo ID with the cargo label */
CargoID GetCargoIDByLabel(CargoLabel cl);
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index 1263ea151..14755d219 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -1895,8 +1895,8 @@ static void NewSpriteGroup(byte *buf, int len)
static CargoID TranslateCargo(uint8 feature, uint8 ctype)
{
/* Special cargo types for purchase list and stations */
- if (feature == GSF_STATION && ctype == 0xFE) return GC_DEFAULT_NA;
- if (ctype == 0xFF) return GC_PURCHASE;
+ if (feature == GSF_STATION && ctype == 0xFE) return CT_DEFAULT_NA;
+ if (ctype == 0xFF) return CT_PURCHASE;
/* Check if the cargo type is out of bounds of the cargo translation table */
if (ctype >= (_cur_grffile->cargo_max == 0 ? _default_cargo_max : _cur_grffile->cargo_max)) {
@@ -1917,9 +1917,6 @@ static CargoID TranslateCargo(uint8 feature, uint8 ctype)
return CT_INVALID;
}
- /* Remap back to global cargo */
- ctype = GetCargo(ctype)->bitnum;
-
grfmsg(6, "FeatureMapSpriteGroup: Cargo '%c%c%c%c' mapped to cargo type %d.", GB(cl, 24, 8), GB(cl, 16, 8), GB(cl, 8, 8), GB(cl, 0, 8), ctype);
return ctype;
}
@@ -2016,7 +2013,7 @@ static void FeatureMapSpriteGroup(byte *buf, int len)
uint8 stid = buf[3 + i];
StationSpec *statspec = _cur_grffile->stations[stid];
- statspec->spritegroup[GC_DEFAULT] = _cur_grffile->spritegroups[groupid];
+ statspec->spritegroup[CT_DEFAULT] = _cur_grffile->spritegroups[groupid];
statspec->grfid = _cur_grffile->grfid;
statspec->localidx = stid;
SetCustomStationSpec(statspec);
@@ -2106,10 +2103,10 @@ static void FeatureMapSpriteGroup(byte *buf, int len)
SetRotorOverrideSprites(engine, _cur_grffile->spritegroups[groupid]);
} else {
// TODO: No multiple cargo types per vehicle yet. --pasky
- SetWagonOverrideSprites(engine, GC_DEFAULT, _cur_grffile->spritegroups[groupid], last_engines, last_engines_count);
+ SetWagonOverrideSprites(engine, CT_DEFAULT, _cur_grffile->spritegroups[groupid], last_engines, last_engines_count);
}
} else {
- SetCustomEngineSprites(engine, GC_DEFAULT, _cur_grffile->spritegroups[groupid]);
+ SetCustomEngineSprites(engine, CT_DEFAULT, _cur_grffile->spritegroups[groupid]);
SetEngineGRF(engine, _cur_grffile);
last_engines[i] = engine;
}
@@ -3813,8 +3810,8 @@ static void CalculateRefitMasks(void)
// Build up the list of cargo types from the set cargo classes.
for (i = 0; i < NUM_CARGO; i++) {
const CargoSpec *cs = GetCargo(i);
- if (cargo_allowed[engine] & cs->classes) SETBIT(mask, cs->bitnum);
- if (cargo_disallowed[engine] & cs->classes) SETBIT(not_mask, cs->bitnum);
+ if (cargo_allowed[engine] & cs->classes) SETBIT(mask, i);
+ if (cargo_disallowed[engine] & cs->classes) SETBIT(not_mask, i);
}
} else {
// Don't apply default refit mask to wagons or engines with no capacity
@@ -3831,7 +3828,7 @@ static void CalculateRefitMasks(void)
CargoID cargo = GetCargoIDByLabel(cl[i]);
if (cargo == CT_INVALID) continue;
- SETBIT(xor_mask, GetCargo(cargo)->bitnum);
+ SETBIT(xor_mask, cargo);
}
}
}
diff --git a/src/newgrf_cargo.h b/src/newgrf_cargo.h
index 099a35b1a..67acf35bd 100644
--- a/src/newgrf_cargo.h
+++ b/src/newgrf_cargo.h
@@ -15,41 +15,8 @@ enum {
CC_REFRIGERATED = 1 << 7,
};
-enum GlobalCargo {
- GC_PASSENGERS = 0,
- GC_COAL = 1,
- GC_MAIL = 2,
- GC_OIL = 3,
- GC_LIVESTOCK = 4,
- GC_GOODS = 5,
- GC_GRAIN = 6, // GC_WHEAT / GC_MAIZE
- GC_WOOD = 7,
- GC_IRON_ORE = 8,
- GC_STEEL = 9,
- GC_VALUABLES = 10, // GC_GOLD / GC_DIAMONDS
- GC_PAPER = 11,
- GC_FOOD = 12,
- GC_FRUIT = 13,
- GC_COPPER_ORE = 14,
- GC_WATER = 15,
- GC_RUBBER = 16,
- GC_SUGAR = 17,
- GC_TOYS = 18,
- GC_BATTERIES = 19,
- GC_CANDY = 20,
- GC_TOFFEE = 21,
- GC_COLA = 22,
- GC_COTTON_CANDY = 23,
- GC_BUBBLES = 24,
- GC_PLASTIC = 25,
- GC_FIZZY_DRINKS = 26,
- GC_PAPER_TEMP = 27,
- GC_UNDEFINED = 28, // undefined; unused slot in arctic climate
- GC_DEFAULT = 29,
- GC_PURCHASE = 30,
- GC_DEFAULT_NA = 31, // New stations only
- GC_INVALID = 255,
- NUM_GLOBAL_CID = 32
-};
+static const CargoID CT_DEFAULT = NUM_CARGO + 0;
+static const CargoID CT_PURCHASE = NUM_CARGO + 1;
+static const CargoID CT_DEFAULT_NA = NUM_CARGO + 2;
#endif /* NEWGRF_CARGO_H */
diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp
index 27320ce61..b54251e93 100644
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -44,7 +44,7 @@ void SetWagonOverrideSprites(EngineID engine, CargoID cargo, const SpriteGroup *
WagonOverride *wo;
assert(engine < TOTAL_NUM_ENGINES);
- assert(cargo < NUM_GLOBAL_CID);
+ assert(cargo < NUM_CARGO + 1); // Include CT_DEFAULT pseudo cargo. CT_PURCHASE does not apply to overrides.
wos = &_engine_wagon_overrides[engine];
wos->overrides_count++;
@@ -76,7 +76,7 @@ static const SpriteGroup *GetWagonOverrideSpriteSet(EngineID engine, CargoID car
int j;
for (j = 0; j < wo->trains; j++) {
- if (wo->train_id[j] == overriding_engine && (wo->cargo == cargo || wo->cargo == GC_DEFAULT)) return wo->group;
+ if (wo->train_id[j] == overriding_engine && (wo->cargo == cargo || wo->cargo == CT_DEFAULT)) return wo->group;
}
}
return NULL;
@@ -105,17 +105,14 @@ void UnloadWagonOverrides(void)
}
}
-// 0 - 28 are cargos, 29 is default, 30 is the advert (purchase list)
-// (It isn't and shouldn't be like this in the GRF files since new cargo types
-// may appear in future - however it's more convenient to store it like this in
-// memory. --pasky)
-static const SpriteGroup *_engine_custom_sprites[TOTAL_NUM_ENGINES][NUM_GLOBAL_CID];
+/* Space for NUM_CARGO real cargos and 2 pseudo cargos, CT_DEFAULT and CT_PURCHASE */
+static const SpriteGroup *_engine_custom_sprites[TOTAL_NUM_ENGINES][NUM_CARGO + 2];
static const GRFFile *_engine_grf[TOTAL_NUM_ENGINES];
void SetCustomEngineSprites(EngineID engine, byte cargo, const SpriteGroup *group)
{
- assert(engine < TOTAL_NUM_ENGINES);
- assert(cargo < NUM_GLOBAL_CID);
+ assert(engine < lengthof(_engine_custom_sprites));
+ assert(cargo < lengthof(*_engine_custom_sprites));
if (_engine_custom_sprites[engine][cargo] != NULL) {
grfmsg(6, "SetCustomEngineSprites: engine %d cargo %d already has group -- replacing", engine, cargo);
@@ -128,15 +125,8 @@ void SetCustomEngineSprites(EngineID engine, byte cargo, const SpriteGroup *grou
*/
void UnloadCustomEngineSprites(void)
{
- EngineID engine;
- CargoID cargo;
-
- for (engine = 0; engine < TOTAL_NUM_ENGINES; engine++) {
- for (cargo = 0; cargo < NUM_GLOBAL_CID; cargo++) {
- _engine_custom_sprites[engine][cargo] = NULL;
- }
- _engine_grf[engine] = 0;
- }
+ memset(_engine_custom_sprites, 0, sizeof(_engine_custom_sprites));
+ memset(_engine_grf, 0, sizeof(_engine_grf));
}
static const SpriteGroup *heli_rotor_custom_sprites[NUM_AIRCRAFT_ENGINES];
@@ -818,12 +808,9 @@ static const SpriteGroup *GetVehicleSpriteGroup(EngineID engine, const Vehicle *
CargoID cargo;
if (v == NULL) {
- cargo = GC_PURCHASE;
+ cargo = CT_PURCHASE;
} else {
- const CargoSpec *cs = GetCargo(v->cargo_type);
- assert(cs->IsValid());
-
- cargo = cs->bitnum;
+ cargo = v->cargo_type;
if (v->type == VEH_Train) {
group = GetWagonOverrideSpriteSet(engine, cargo, v->u.rail.first_engine);
@@ -836,7 +823,7 @@ static const SpriteGroup *GetVehicleSpriteGroup(EngineID engine, const Vehicle *
if (group != NULL) return group;
/* Fall back to the default set if the selected cargo type is not defined */
- return _engine_custom_sprites[engine][GC_DEFAULT];
+ return _engine_custom_sprites[engine][CT_DEFAULT];
}
@@ -888,7 +875,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, GetCargo(v->cargo_type)->bitnum, v->u.rail.first_engine) != NULL;
+ return GetWagonOverrideSpriteSet(v->engine_type, v->cargo_type, v->u.rail.first_engine) != NULL;
}
/**
diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp
index ce9846d68..741894dcb 100644
--- a/src/newgrf_station.cpp
+++ b/src/newgrf_station.cpp
@@ -447,20 +447,20 @@ static const SpriteGroup *StationResolveReal(const ResolverObject *object, const
}
switch (cargo_type) {
- case GC_INVALID:
- case GC_DEFAULT_NA:
- case GC_PURCHASE:
+ case CT_INVALID:
+ case CT_DEFAULT_NA:
+ case CT_PURCHASE:
cargo = 0;
break;
- case GC_DEFAULT:
+ case CT_DEFAULT:
for (cargo_type = 0; cargo_type < NUM_CARGO; cargo_type++) {
cargo += GB(st->goods[cargo_type].waiting_acceptance, 0, 12);
}
break;
default:
- cargo = GB(st->goods[GetCargoIDByBitnum(cargo_type)].waiting_acceptance, 0, 12);
+ cargo = GB(st->goods[cargo_type].waiting_acceptance, 0, 12);
break;
}
@@ -506,18 +506,18 @@ static void NewStationResolver(ResolverObject *res, const StationSpec *statspec,
static const SpriteGroup *ResolveStation(ResolverObject *object)
{
const SpriteGroup *group;
- CargoID ctype = GC_DEFAULT_NA;
+ CargoID ctype = CT_DEFAULT_NA;
if (object->u.station.st == NULL) {
/* No station, so we are in a purchase list */
- ctype = GC_PURCHASE;
+ ctype = CT_PURCHASE;
} else {
/* Pick the first cargo that we have waiting */
for (CargoID cargo = 0; cargo < NUM_CARGO; cargo++) {
const CargoSpec *cs = GetCargo(cargo);
- if (cs->IsValid() && object->u.station.statspec->spritegroup[cs->bitnum] != NULL &&
+ if (cs->IsValid() && object->u.station.statspec->spritegroup[cargo] != NULL &&
GB(object->u.station.st->goods[cargo].waiting_acceptance, 0, 12) != 0) {
- ctype = cs->bitnum;
+ ctype = cargo;
break;
}
}
@@ -525,7 +525,7 @@ static const SpriteGroup *ResolveStation(ResolverObject *object)
group = object->u.station.statspec->spritegroup[ctype];
if (group == NULL) {
- ctype = GC_DEFAULT;
+ ctype = CT_DEFAULT;
group = object->u.station.statspec->spritegroup[ctype];
}
diff --git a/src/newgrf_station.h b/src/newgrf_station.h
index f504bdd2b..785710762 100644
--- a/src/newgrf_station.h
+++ b/src/newgrf_station.h
@@ -79,11 +79,11 @@ typedef struct StationSpec {
bool copied_layouts;
/**
- * NUM_GLOBAL_CID sprite groups.
+ * NUM_CARGO real cargo plus three pseudo cargo sprite groups.
* Used for obtaining the sprite offset of custom sprites, and for
* evaluating callbacks.
*/
- const struct SpriteGroup *spritegroup[NUM_GLOBAL_CID];
+ const struct SpriteGroup *spritegroup[NUM_CARGO + 3];
} StationSpec;
/**
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 7668c3a3a..c2846ba54 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -762,8 +762,7 @@ bool CanFillVehicle(Vehicle *v)
*/
bool CanRefitTo(EngineID engine_type, CargoID cid_to)
{
- CargoID cid = GetCargo(cid_to)->bitnum;
- return HASBIT(EngInfo(engine_type)->refit_mask, cid);
+ return HASBIT(EngInfo(engine_type)->refit_mask, cid_to);
}
/** Find the first cargo type that an engine can be refitted to.
@@ -776,7 +775,7 @@ CargoID FindFirstRefittableCargo(EngineID engine_type)
if (refit_mask != 0) {
for (CargoID cid = CT_PASSENGERS; cid < NUM_CARGO; cid++) {
- if (HASBIT(refit_mask, GetCargo(cid)->bitnum)) return cid;
+ if (HASBIT(refit_mask, cid)) return cid;
}
}
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index 984d62b7d..1c3d1c55e 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -210,10 +210,8 @@ static RefitList *BuildRefitList(const Vehicle *v)
/* Loop through all cargos in the refit mask */
for (CargoID cid = 0; cid != NUM_CARGO && num_lines < max_lines; cid++) {
- const CargoSpec *cs = GetCargo(cid);
-
/* Skip cargo type if it's not listed */
- if (!HASBIT(cmask, cs->bitnum)) continue;
+ if (!HASBIT(cmask, cid)) continue;
/* Check the vehicle's callback mask for cargo suffixes */
if (HASBIT(callbackmask, CBM_CARGO_SUFFIX)) {
@@ -516,9 +514,7 @@ uint ShowRefitOptionsList(int x, int y, uint w, EngineID engine)
/* Add each cargo type to the list */
for (CargoID cid = 0; cid < NUM_CARGO; cid++) {
- const CargoSpec *cs = GetCargo(cid);
-
- if (!HASBIT(cmask, cs->bitnum)) continue;
+ if (!HASBIT(cmask, cid)) continue;
if (!first) b = strecpy(b, ", ", lastof(_userstring));
first = false;