(svn r16427) -Codechange: replace a few magic numbers with an existing constant and unduplicate a few lines.

This commit is contained in:
rubidium 2009-05-26 08:53:16 +00:00
parent 37b391901a
commit 82cdacb20c
4 changed files with 10 additions and 5 deletions

View File

@ -187,7 +187,7 @@ static SpriteID GetAircraftIcon(EngineID engine)
spritenum = Engine::Get(engine)->image_index; spritenum = Engine::Get(engine)->image_index;
} }
return 6 + _aircraft_sprite[spritenum]; return DIR_W + _aircraft_sprite[spritenum];
} }
void DrawAircraftEngine(int x, int y, EngineID engine, SpriteID pal) void DrawAircraftEngine(int x, int y, EngineID engine, SpriteID pal)

View File

@ -93,7 +93,7 @@ static SpriteID GetRoadVehIcon(EngineID engine)
spritenum = Engine::Get(engine)->image_index; spritenum = Engine::Get(engine)->image_index;
} }
return 6 + _roadveh_images[spritenum]; return DIR_W + _roadveh_images[spritenum];
} }
SpriteID RoadVehicle::GetImage(Direction direction) const SpriteID RoadVehicle::GetImage(Direction direction) const

View File

@ -59,7 +59,7 @@ static SpriteID GetShipIcon(EngineID engine)
spritenum = Engine::Get(engine)->image_index; spritenum = Engine::Get(engine)->image_index;
} }
return 6 + _ship_sprites[spritenum]; return DIR_W + _ship_sprites[spritenum];
} }
void DrawShipEngine(int x, int y, EngineID engine, SpriteID pal) void DrawShipEngine(int x, int y, EngineID engine, SpriteID pal)

View File

@ -568,6 +568,11 @@ void UpdateTrainAcceleration(Train *v)
v->acceleration = Clamp(power / weight * 4, 1, 255); v->acceleration = Clamp(power / weight * 4, 1, 255);
} }
static SpriteID GetDefaultTrainSprite(uint8 spritenum, Direction direction)
{
return ((direction + _engine_sprite_add[spritenum]) & _engine_sprite_and[spritenum]) + _engine_sprite_base[spritenum];
}
SpriteID Train::GetImage(Direction direction) const SpriteID Train::GetImage(Direction direction) const
{ {
uint8 spritenum = this->spritenum; uint8 spritenum = this->spritenum;
@ -582,7 +587,7 @@ SpriteID Train::GetImage(Direction direction) const
spritenum = Engine::Get(this->engine_type)->image_index; spritenum = Engine::Get(this->engine_type)->image_index;
} }
sprite = _engine_sprite_base[spritenum] + ((direction + _engine_sprite_add[spritenum]) & _engine_sprite_and[spritenum]); sprite = GetDefaultTrainSprite(spritenum, direction);
if (this->cargo.Count() >= this->cargo_cap / 2U) sprite += _wagon_full_adder[spritenum]; if (this->cargo.Count() >= this->cargo_cap / 2U) sprite += _wagon_full_adder[spritenum];
@ -606,7 +611,7 @@ static SpriteID GetRailIcon(EngineID engine, bool rear_head, int &y)
if (rear_head) spritenum++; if (rear_head) spritenum++;
return ((6 + _engine_sprite_add[spritenum]) & _engine_sprite_and[spritenum]) + _engine_sprite_base[spritenum]; return GetDefaultTrainSprite(spritenum, DIR_W);
} }
void DrawTrainEngine(int x, int y, EngineID engine, SpriteID pal) void DrawTrainEngine(int x, int y, EngineID engine, SpriteID pal)