summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2006-03-31 12:59:43 +0000
committerpeter1138 <peter1138@openttd.org>2006-03-31 12:59:43 +0000
commitcd0a67dc657c8c967745cb3fb91ea9d04a79a826 (patch)
tree3f9c7926897f63e5f92550c9c7802e07ec3a2f67
parent859fc1d7f0173102d16e3a31b3ceb5066870ccb5 (diff)
downloadopenttd-cd0a67dc657c8c967745cb3fb91ea9d04a79a826.tar.xz
(svn r4201) - Codechange: Do for _engine_info[] what we do for _*_vehicle_info[]; create and use a function to retrieve data, and ensure constness.
-rw-r--r--engine.h6
-rw-r--r--players.c2
-rw-r--r--train_gui.c4
-rw-r--r--vehicle.c4
-rw-r--r--vehicle_gui.c6
5 files changed, 14 insertions, 8 deletions
diff --git a/engine.h b/engine.h
index f35f9570c..b0293efe1 100644
--- a/engine.h
+++ b/engine.h
@@ -219,6 +219,12 @@ extern ShipVehicleInfo _ship_vehicle_info[NUM_SHIP_ENGINES];
extern AircraftVehicleInfo _aircraft_vehicle_info[NUM_AIRCRAFT_ENGINES];
extern RoadVehicleInfo _road_vehicle_info[NUM_ROAD_ENGINES];
+static inline const EngineInfo *EngInfo(EngineID e)
+{
+ assert(e < lengthof(_engine_info));
+ return &_engine_info[e];
+}
+
static inline const RailVehicleInfo* RailVehInfo(EngineID e)
{
assert(e < lengthof(_rail_vehicle_info));
diff --git a/players.c b/players.c
index 2cdffd984..bdf8df98a 100644
--- a/players.c
+++ b/players.c
@@ -625,7 +625,7 @@ byte GetPlayerRailtypes(PlayerID p)
for (i = 0; i != TOTAL_NUM_ENGINES; i++) {
const Engine* e = GetEngine(i);
- const EngineInfo *ei = &_engine_info[i];
+ const EngineInfo *ei = EngInfo(i);
if (e->type == VEH_Train && HASBIT(ei->climates, _opt.landscape) &&
(HASBIT(e->player_avail, p) || _date >= (e->intro_date + 365)) &&
diff --git a/train_gui.c b/train_gui.c
index 23ce740f9..c4a83a3bd 100644
--- a/train_gui.c
+++ b/train_gui.c
@@ -92,7 +92,7 @@ void DrawTrainEnginePurchaseInfo(int x, int y, EngineID engine_number)
void DrawTrainWagonPurchaseInfo(int x, int y, EngineID engine_number)
{
const RailVehicleInfo *rvi = RailVehInfo(engine_number);
- bool refittable = (_engine_info[engine_number].refit_mask != 0);
+ bool refittable = (EngInfo(engine_number)->refit_mask != 0);
/* Purchase cost */
SetDParam(0, (rvi->base_cost * _price.build_railwagon) >> 8);
@@ -910,7 +910,7 @@ static void TrainViewWndProc(Window *w, WindowEvent *e)
/* See if any vehicle can be refitted */
for (u = v; u != NULL; u = u->next) {
- if (_engine_info[u->engine_type].refit_mask != 0 ||
+ if (EngInfo(u->engine_type)->refit_mask != 0 ||
(!(RailVehInfo(v->engine_type)->flags & RVI_WAGON) && v->cargo_cap != 0)) {
CLRBIT(w->disabled_state, 12);
/* We have a refittable carriage, bail out */
diff --git a/vehicle.c b/vehicle.c
index 90cf7e3fa..0d938f5f7 100644
--- a/vehicle.c
+++ b/vehicle.c
@@ -694,7 +694,7 @@ bool CanFillVehicle(Vehicle *v)
bool CanRefitTo(EngineID engine_type, CargoID cid_to)
{
CargoID cid = _global_cargo_id[_opt_ptr->landscape][cid_to];
- return HASBIT(_engine_info[engine_type].refit_mask, cid);
+ return HASBIT(EngInfo(engine_type)->refit_mask, cid);
}
static void DoDrawVehicle(const Vehicle *v)
@@ -2061,7 +2061,7 @@ static PalSpriteID GetEngineColourMap(EngineID engine_type, PlayerID player)
byte colour = _player_colors[player];
/* XXX Magic 0x307 is the first company colour remap sprite */
- map = HASBIT(_engine_info[engine_type].misc_flags, EF_USES_2CC) ?
+ map = HASBIT(EngInfo(engine_type)->misc_flags, EF_USES_2CC) ?
(SPR_2CCMAP_BASE + colour + colour * 16) : (PALETTE_RECOLOR_START + colour);
return SPRITE_PALETTE(map << PALETTE_SPRITE_START);
diff --git a/vehicle_gui.c b/vehicle_gui.c
index 31b8e9bf0..7e92c5147 100644
--- a/vehicle_gui.c
+++ b/vehicle_gui.c
@@ -233,7 +233,7 @@ CargoID DrawVehicleRefitWindow(const Vehicle *v, int sel)
* it with the bitmask of available cargo on the current landscape, and
* where the bits are set: those are available */
do {
- cmask |= _engine_info[u->engine_type].refit_mask;
+ cmask |= EngInfo(u->engine_type)->refit_mask;
u = u->next;
} while (v->type == VEH_Train && u != NULL);
@@ -461,7 +461,7 @@ static void train_engine_drawing_loop(int *x, int *y, int *pos, int *sel, Engine
EngineID i = GetRailVehAtPosition(j);
const Engine *e = GetEngine(i);
const RailVehicleInfo *rvi = RailVehInfo(i);
- const EngineInfo *info = &_engine_info[i];
+ const EngineInfo *info = EngInfo(i);
if (!EngineHasReplacementForPlayer(p, i) && _player_num_engines[i] == 0 && show_outdated) continue;
@@ -523,7 +523,7 @@ static void SetupScrollStuffForReplaceWindow(Window *w)
for (i = 0; i < NUM_TRAIN_ENGINES; i++) {
EngineID eid = GetRailVehAtPosition(i);
const Engine* e = GetEngine(eid);
- const EngineInfo* info = &_engine_info[eid];
+ const EngineInfo* info = EngInfo(eid);
// left window contains compatible engines while right window only contains engines of the selected type
if (ENGINE_AVAILABLE && (