summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2008-01-05 15:39:22 +0000
committerpeter1138 <peter1138@openttd.org>2008-01-05 15:39:22 +0000
commit0c4e3b83e40c334201d1f1873af79f132852fd0a (patch)
tree658c76c4837adf5c3277e65025e9fc14fa20eb73 /src
parentf02cf9281bbbfd0118269dd8431263e2f95005a1 (diff)
downloadopenttd-0c4e3b83e40c334201d1f1873af79f132852fd0a.tar.xz
(svn r11761) -Codechange: Use appropriate variable types for NewGRF engine overrides, and adjust scope while there.
Diffstat (limited to 'src')
-rw-r--r--src/newgrf.cpp4
-rw-r--r--src/newgrf_engine.cpp32
-rw-r--r--src/newgrf_engine.h4
3 files changed, 17 insertions, 23 deletions
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index 1032a9747..fa531f5ed 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -2772,8 +2772,8 @@ static CargoID TranslateCargo(uint8 feature, uint8 ctype)
static void VehicleMapSpriteGroup(byte *buf, byte feature, uint8 idcount, uint8 cidcount, bool wagover)
{
- static byte *last_engines;
- static int last_engines_count;
+ static EngineID *last_engines;
+ static uint last_engines_count;
if (!wagover) {
if (last_engines_count != idcount) {
diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp
index a12d04ce4..b0ab246e9 100644
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -26,20 +26,20 @@ int _traininfo_vehicle_pitch = 0;
int _traininfo_vehicle_width = 29;
struct WagonOverride {
- byte *train_id;
- int trains;
+ EngineID *train_id;
+ uint trains;
CargoID cargo;
const SpriteGroup *group;
};
struct WagonOverrides {
- int overrides_count;
+ uint overrides_count;
WagonOverride *overrides;
};
static WagonOverrides _engine_wagon_overrides[TOTAL_NUM_ENGINES];
-void SetWagonOverrideSprites(EngineID engine, CargoID cargo, const SpriteGroup *group, byte *train_id, int trains)
+void SetWagonOverrideSprites(EngineID engine, CargoID cargo, const SpriteGroup *group, EngineID *train_id, uint trains)
{
WagonOverrides *wos;
WagonOverride *wo;
@@ -58,11 +58,11 @@ void SetWagonOverrideSprites(EngineID engine, CargoID cargo, const SpriteGroup *
wo->group = group;
wo->cargo = cargo;
wo->trains = trains;
- wo->train_id = MallocT<byte>(trains);
- memcpy(wo->train_id, train_id, trains);
+ wo->train_id = MallocT<EngineID>(trains);
+ memcpy(wo->train_id, train_id, trains * sizeof *train_id);
}
-const SpriteGroup *GetWagonOverrideSpriteSet(EngineID engine, CargoID cargo, byte overriding_engine)
+const SpriteGroup *GetWagonOverrideSpriteSet(EngineID engine, CargoID cargo, EngineID overriding_engine)
{
const WagonOverrides *wos = &_engine_wagon_overrides[engine];
@@ -71,12 +71,12 @@ const SpriteGroup *GetWagonOverrideSpriteSet(EngineID engine, CargoID cargo, byt
* for O(1). Or O(logMlogN) and searching binary tree or smt. like
* that. --pasky */
- for (int i = 0; i < wos->overrides_count; i++) {
+ for (uint i = 0; i < wos->overrides_count; i++) {
const WagonOverride *wo = &wos->overrides[i];
if (wo->cargo != cargo && wo->cargo != CT_DEFAULT) continue;
- for (int j = 0; j < wo->trains; j++) {
+ for (uint j = 0; j < wo->trains; j++) {
if (wo->train_id[j] == overriding_engine) return wo->group;
}
}
@@ -88,16 +88,10 @@ const SpriteGroup *GetWagonOverrideSpriteSet(EngineID engine, CargoID cargo, byt
*/
void UnloadWagonOverrides()
{
- WagonOverrides *wos;
- WagonOverride *wo;
- EngineID engine;
- int i;
-
- for (engine = 0; engine < TOTAL_NUM_ENGINES; engine++) {
- wos = &_engine_wagon_overrides[engine];
- for (i = 0; i < wos->overrides_count; i++) {
- wo = &wos->overrides[i];
- wo->group = NULL;
+ for (EngineID engine = 0; engine < TOTAL_NUM_ENGINES; engine++) {
+ WagonOverrides *wos = &_engine_wagon_overrides[engine];
+ for (uint i = 0; i < wos->overrides_count; i++) {
+ WagonOverride *wo = &wos->overrides[i];
free(wo->train_id);
}
free(wos->overrides);
diff --git a/src/newgrf_engine.h b/src/newgrf_engine.h
index c94bff9b6..2aa7b0716 100644
--- a/src/newgrf_engine.h
+++ b/src/newgrf_engine.h
@@ -13,8 +13,8 @@ extern int _traininfo_vehicle_pitch;
extern int _traininfo_vehicle_width;
-void SetWagonOverrideSprites(EngineID engine, CargoID cargo, const struct SpriteGroup *group, byte *train_id, int trains);
-const SpriteGroup *GetWagonOverrideSpriteSet(EngineID engine, CargoID cargo, byte overriding_engine);
+void SetWagonOverrideSprites(EngineID engine, CargoID cargo, const struct SpriteGroup *group, EngineID *train_id, uint trains);
+const SpriteGroup *GetWagonOverrideSpriteSet(EngineID engine, CargoID cargo, EngineID overriding_engine);
void SetCustomEngineSprites(EngineID engine, byte cargo, const struct SpriteGroup *group);
void SetRotorOverrideSprites(EngineID engine, const struct SpriteGroup *group);
SpriteID GetCustomEngineSprite(EngineID engine, const Vehicle* v, Direction direction);