summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2005-07-30 18:04:49 +0000
committertron <tron@openttd.org>2005-07-30 18:04:49 +0000
commita2c42e06ed5aaca7d23d47bc0ee7f9279ae1a38c (patch)
tree52eb08731454c2d01bd47aeef1de7f8886d6ad26
parent4761d92399fbbad03000f2da4d9e37f1305a820c (diff)
downloadopenttd-a2c42e06ed5aaca7d23d47bc0ee7f9279ae1a38c.tar.xz
(svn r2762) Simplify a loop, remove an unused variable and add many consts
-rw-r--r--engine.c90
-rw-r--r--sprite.c6
-rw-r--r--sprite.h6
3 files changed, 45 insertions, 57 deletions
diff --git a/engine.c b/engine.c
index e35085b42..4b2d0748c 100644
--- a/engine.c
+++ b/engine.c
@@ -163,36 +163,24 @@ static void CalcEngineReliability(Engine *e)
void AddTypeToEngines(void)
{
- Engine *e;
- uint32 counter = 0;
-
- for(e=_engines; e != endof(_engines); e++, counter++) {
-
- e->type = VEH_Train;
- if (counter >= ROAD_ENGINES_INDEX) {
- e->type = VEH_Road;
- if (counter >= SHIP_ENGINES_INDEX) {
- e->type = VEH_Ship;
- if (counter >= AIRCRAFT_ENGINES_INDEX) {
- e->type = VEH_Aircraft;
- if (counter >= TOTAL_NUM_ENGINES) {
- e->type = VEH_Special;
- }
- }
- }
- }
- }
+ Engine* e = _engines;
+
+ do e->type = VEH_Train; while (++e < &_engines[ROAD_ENGINES_INDEX]);
+ do e->type = VEH_Road; while (++e < &_engines[SHIP_ENGINES_INDEX]);
+ do e->type = VEH_Ship; while (++e < &_engines[AIRCRAFT_ENGINES_INDEX]);
+ do e->type = VEH_Aircraft; while (++e < &_engines[TOTAL_NUM_ENGINES]);
+ do e->type = VEH_Special; while (++e < endof(_engines));
}
void StartupEngines(void)
{
Engine *e;
const EngineInfo *ei;
- uint32 r, counter = 0;
SetupEngineNames();
- for(e=_engines, ei=_engine_info; e != endof(_engines); e++, ei++, counter++) {
+ for (e = _engines, ei = _engine_info; e != endof(_engines); e++, ei++) {
+ uint32 r;
e->age = 0;
e->railtype = ei->railtype_climates >> 4;
@@ -283,9 +271,9 @@ void SetWagonOverrideSprites(byte engine, SpriteGroup *group, byte *train_id,
memcpy(wo->train_id, train_id, trains);
}
-static SpriteGroup *GetWagonOverrideSpriteSet(byte engine, byte overriding_engine)
+static const SpriteGroup *GetWagonOverrideSpriteSet(byte engine, byte overriding_engine)
{
- WagonOverrides *wos = &_engine_wagon_overrides[engine];
+ const WagonOverrides *wos = &_engine_wagon_overrides[engine];
int i;
// XXX: This could turn out to be a timesink on profiles. We could
@@ -294,7 +282,7 @@ static SpriteGroup *GetWagonOverrideSpriteSet(byte engine, byte overriding_engin
// that. --pasky
for (i = 0; i < wos->overrides_count; i++) {
- WagonOverride *wo = &wos->overrides[i];
+ const WagonOverride *wo = &wos->overrides[i];
int j;
for (j = 0; j < wo->trains; j++) {
@@ -306,7 +294,6 @@ static SpriteGroup *GetWagonOverrideSpriteSet(byte engine, byte overriding_engin
}
-byte _engine_original_sprites[TOTAL_NUM_ENGINES];
// 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
@@ -321,10 +308,10 @@ void SetCustomEngineSprites(byte engine, byte cargo, SpriteGroup *group)
_engine_custom_sprites[engine][cargo] = *group;
}
-typedef SpriteGroup *(*resolve_callback)(SpriteGroup *spritegroup,
+typedef SpriteGroup *(*resolve_callback)(const SpriteGroup *spritegroup,
const Vehicle *veh, uint16 callback_info, void *resolve_func); /* XXX data pointer used as function pointer */
-static SpriteGroup* ResolveVehicleSpriteGroup(SpriteGroup *spritegroup,
+static const SpriteGroup* ResolveVehicleSpriteGroup(const SpriteGroup *spritegroup,
const Vehicle *veh, uint16 callback_info, resolve_callback resolve_func)
{
//debug("spgt %d", spritegroup->type);
@@ -334,8 +321,8 @@ static SpriteGroup* ResolveVehicleSpriteGroup(SpriteGroup *spritegroup,
return spritegroup;
case SGT_DETERMINISTIC: {
- DeterministicSpriteGroup *dsg = &spritegroup->g.determ;
- SpriteGroup *target;
+ const DeterministicSpriteGroup *dsg = &spritegroup->g.determ;
+ const SpriteGroup *target;
int value = -1;
//debug("[%p] Having fun resolving variable %x", veh, dsg->variable);
@@ -369,7 +356,7 @@ static SpriteGroup* ResolveVehicleSpriteGroup(SpriteGroup *spritegroup,
if (dsg->variable == 0x40 || dsg->variable == 0x41) {
if (veh->type == VEH_Train) {
- Vehicle *u = GetFirstVehicleInChain(veh);
+ const Vehicle *u = GetFirstVehicleInChain(veh);
byte chain_before = 0, chain_after = 0;
while (u != veh) {
@@ -483,7 +470,7 @@ static SpriteGroup* ResolveVehicleSpriteGroup(SpriteGroup *spritegroup,
}
case SGT_RANDOMIZED: {
- RandomizedSpriteGroup *rsg = &spritegroup->g.random;
+ const RandomizedSpriteGroup *rsg = &spritegroup->g.random;
if (veh == NULL) {
/* Purchase list of something. Show the first one. */
@@ -507,9 +494,9 @@ static SpriteGroup* ResolveVehicleSpriteGroup(SpriteGroup *spritegroup,
}
}
-static SpriteGroup *GetVehicleSpriteGroup(byte engine, const Vehicle *v)
+static const SpriteGroup *GetVehicleSpriteGroup(byte engine, const Vehicle *v)
{
- SpriteGroup *group;
+ const SpriteGroup *group;
byte cargo = GC_PURCHASE;
if (v != NULL) {
@@ -520,7 +507,7 @@ static SpriteGroup *GetVehicleSpriteGroup(byte engine, const Vehicle *v)
group = &_engine_custom_sprites[engine][cargo];
if (v != NULL && v->type == VEH_Train) {
- SpriteGroup *overset = GetWagonOverrideSpriteSet(engine, v->u.rail.first_engine);
+ const SpriteGroup *overset = GetWagonOverrideSpriteSet(engine, v->u.rail.first_engine);
if (overset != NULL) group = overset;
}
@@ -530,8 +517,8 @@ static SpriteGroup *GetVehicleSpriteGroup(byte engine, const Vehicle *v)
int GetCustomEngineSprite(byte engine, const Vehicle *v, byte direction)
{
- SpriteGroup *group;
- RealSpriteGroup *rsg;
+ const SpriteGroup *group;
+ const RealSpriteGroup *rsg;
byte cargo = GC_PURCHASE;
byte loaded = 0;
bool in_motion = 0;
@@ -598,7 +585,7 @@ int GetCustomEngineSprite(byte engine, const Vehicle *v, byte direction)
*/
bool UsesWagonOverride(const Vehicle *v) {
assert(v->type == VEH_Train);
- return (GetWagonOverrideSpriteSet(v->engine_type, v->u.rail.first_engine) != NULL);
+ return GetWagonOverrideSpriteSet(v->engine_type, v->u.rail.first_engine) != NULL;
}
/**
@@ -612,7 +599,7 @@ bool UsesWagonOverride(const Vehicle *v) {
*/
uint16 GetCallBackResult(uint16 callback_info, byte engine, const Vehicle *v)
{
- SpriteGroup *group;
+ const SpriteGroup *group;
byte cargo = GC_DEFAULT;
if (v != NULL)
@@ -621,7 +608,7 @@ uint16 GetCallBackResult(uint16 callback_info, byte engine, const Vehicle *v)
group = &_engine_custom_sprites[engine][cargo];
if (v != NULL && v->type == VEH_Train) {
- SpriteGroup *overset = GetWagonOverrideSpriteSet(engine, v->u.rail.first_engine);
+ const SpriteGroup *overset = GetWagonOverrideSpriteSet(engine, v->u.rail.first_engine);
if (overset != NULL) group = overset;
}
@@ -647,7 +634,7 @@ uint16 GetCallBackResult(uint16 callback_info, byte engine, const Vehicle *v)
static byte _vsg_random_triggers;
static byte _vsg_bits_to_reseed;
-static SpriteGroup *TriggerVehicleSpriteGroup(SpriteGroup *spritegroup,
+static const SpriteGroup *TriggerVehicleSpriteGroup(const SpriteGroup *spritegroup,
Vehicle *veh, uint16 callback_info, resolve_callback resolve_func)
{
if (spritegroup->type == SGT_RANDOMIZED) {
@@ -663,8 +650,8 @@ static SpriteGroup *TriggerVehicleSpriteGroup(SpriteGroup *spritegroup,
static void DoTriggerVehicle(Vehicle *veh, VehicleTrigger trigger, byte base_random_bits, bool first)
{
- SpriteGroup *group;
- RealSpriteGroup *rsg;
+ const SpriteGroup *group;
+ const RealSpriteGroup *rsg;
byte new_random_bits;
_vsg_random_triggers = trigger;
@@ -793,12 +780,13 @@ static PlayerID GetBestPlayer(PlayerID pp)
void EnginesDailyLoop(void)
{
- Engine *e;
- int i;
+ uint i;
if (_cur_year >= 130) return;
- for (e = _engines, i = 0; i != TOTAL_NUM_ENGINES; e++, i++) {
+ for (i = 0; i != lengthof(_engines); i++) {
+ Engine* e = &_engines[i];
+
if (e->flags & ENGINE_INTRODUCING) {
if (e->flags & ENGINE_PREVIEWING) {
if (e->preview_player != 0xFF && !--e->preview_wait) {
@@ -920,9 +908,9 @@ void EnginesMonthlyLoop(void)
Engine *e;
if (_cur_year < 130) {
- for(e=_engines; e != endof(_engines); e++) {
+ for (e = _engines; e != endof(_engines); e++) {
// Age the vehicle
- if (e->flags&ENGINE_AVAILABLE && e->age != 0xFFFF) {
+ if (e->flags & ENGINE_AVAILABLE && e->age != 0xFFFF) {
e->age++;
CalcEngineReliability(e);
}
@@ -998,11 +986,11 @@ static const SaveLoad _engine_desc[] = {
static void Save_ENGN(void)
{
- Engine *e;
- int i;
- for(i=0,e=_engines; i != lengthof(_engines); i++,e++) {
+ uint i;
+
+ for (i = 0; i != lengthof(_engines); i++) {
SlSetArrayIndex(i);
- SlObject(e, _engine_desc);
+ SlObject(&_engines[i], _engine_desc);
}
}
diff --git a/sprite.c b/sprite.c
index 1b36fac49..1322a4649 100644
--- a/sprite.c
+++ b/sprite.c
@@ -9,7 +9,7 @@
#include "variables.h"
-SpriteGroup *EvalDeterministicSpriteGroup(DeterministicSpriteGroup *dsg, int value)
+SpriteGroup *EvalDeterministicSpriteGroup(const DeterministicSpriteGroup *dsg, int value)
{
int i;
@@ -64,7 +64,7 @@ int GetDeterministicSpriteValue(byte var)
}
}
-SpriteGroup *EvalRandomizedSpriteGroup(RandomizedSpriteGroup *rsg, byte random_bits)
+SpriteGroup *EvalRandomizedSpriteGroup(const RandomizedSpriteGroup *rsg, byte random_bits)
{
byte mask;
byte index;
@@ -78,7 +78,7 @@ SpriteGroup *EvalRandomizedSpriteGroup(RandomizedSpriteGroup *rsg, byte random_b
return &rsg->groups[index];
}
-byte RandomizedSpriteGroupTriggeredBits(RandomizedSpriteGroup *rsg,
+byte RandomizedSpriteGroupTriggeredBits(const RandomizedSpriteGroup *rsg,
byte triggers, byte *waiting_triggers)
{
byte match = rsg->triggers & (*waiting_triggers | triggers);
diff --git a/sprite.h b/sprite.h
index b199509c3..5d21dcee5 100644
--- a/sprite.h
+++ b/sprite.h
@@ -140,17 +140,17 @@ struct DeterministicSpriteGroupRange {
/* This takes value (probably of the variable specified in the group) and
* chooses corresponding SpriteGroup accordingly to the given
* DeterministicSpriteGroup. */
-struct SpriteGroup *EvalDeterministicSpriteGroup(struct DeterministicSpriteGroup *dsg, int value);
+SpriteGroup *EvalDeterministicSpriteGroup(const DeterministicSpriteGroup *dsg, int value);
/* Get value of a common deterministic SpriteGroup variable. */
int GetDeterministicSpriteValue(byte var);
/* This takes randomized bitmask (probably associated with
* vehicle/station/whatever) and chooses corresponding SpriteGroup
* accordingly to the given RandomizedSpriteGroup. */
-SpriteGroup *EvalRandomizedSpriteGroup(RandomizedSpriteGroup *rsg, byte random_bits);
+SpriteGroup *EvalRandomizedSpriteGroup(const RandomizedSpriteGroup *rsg, byte random_bits);
/* Triggers given RandomizedSpriteGroup with given bitmask and returns and-mask
* of random bits to be reseeded, or zero if there were no triggers matched
* (then they are |ed to @waiting_triggers instead). */
-byte RandomizedSpriteGroupTriggeredBits(RandomizedSpriteGroup *rsg, byte triggers, byte *waiting_triggers);
+byte RandomizedSpriteGroupTriggeredBits(const RandomizedSpriteGroup *rsg, byte triggers, byte *waiting_triggers);
#endif