From bae066ecaf09327f5e012a43d8f916ad4d443080 Mon Sep 17 00:00:00 2001 From: rubidium Date: Mon, 16 Nov 2009 17:58:46 +0000 Subject: (svn r18123) -Codechange: try our best to keep the vehicles within the build vehicle list/autoreplace lists instead of overflowing. --- src/aircraft_cmd.cpp | 5 ++++- src/roadveh_cmd.cpp | 6 +++++- src/ship_cmd.cpp | 5 ++++- src/train_cmd.cpp | 8 ++++++++ 4 files changed, 21 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp index 767b8531d..22a3872a5 100644 --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -200,7 +200,10 @@ static SpriteID GetAircraftIcon(EngineID engine) void DrawAircraftEngine(int left, int right, int preferred_x, int y, EngineID engine, SpriteID pal) { - DrawSprite(GetAircraftIcon(engine), pal, preferred_x, y); + SpriteID sprite = GetAircraftIcon(engine); + const Sprite *real_sprite = GetSprite(sprite, ST_NORMAL); + preferred_x = Clamp(preferred_x, left - real_sprite->x_offs, right - real_sprite->width - real_sprite->x_offs); + DrawSprite(sprite, pal, preferred_x, y); if (!(AircraftVehInfo(engine)->subtype & AIR_CTOL)) { SpriteID rotor_sprite = GetCustomRotorIcon(engine); diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index b0a535d04..bbe258e84 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -36,6 +36,7 @@ #include "effectvehicle_func.h" #include "roadstop_base.h" #include "cargotype.h" +#include "spritecache.h" #include "table/strings.h" #include "table/sprites.h" @@ -140,7 +141,10 @@ SpriteID RoadVehicle::GetImage(Direction direction) const void DrawRoadVehEngine(int left, int right, int preferred_x, int y, EngineID engine, SpriteID pal) { - DrawSprite(GetRoadVehIcon(engine), pal, preferred_x, y); + SpriteID sprite = GetRoadVehIcon(engine); + const Sprite *real_sprite = GetSprite(sprite, ST_NORMAL); + preferred_x = Clamp(preferred_x, left - real_sprite->x_offs, right - real_sprite->width - real_sprite->x_offs); + DrawSprite(sprite, pal, preferred_x, y); } static uint GetRoadVehLength(const RoadVehicle *v) diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp index d2bf6a7fb..c482539ab 100644 --- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -70,7 +70,10 @@ static SpriteID GetShipIcon(EngineID engine) void DrawShipEngine(int left, int right, int preferred_x, int y, EngineID engine, SpriteID pal) { - DrawSprite(GetShipIcon(engine), pal, preferred_x, y); + SpriteID sprite = GetShipIcon(engine); + const Sprite *real_sprite = GetSprite(sprite, ST_NORMAL); + preferred_x = Clamp(preferred_x, left - real_sprite->x_offs, right - real_sprite->width - real_sprite->x_offs); + DrawSprite(sprite, pal, preferred_x, y); } /** Get the size of the sprite of a ship sprite heading west (used for lists) diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index aa6c53fce..bd5205b6c 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -35,6 +35,7 @@ #include "effectvehicle_func.h" #include "gamelog.h" #include "network/network.h" +#include "spritecache.h" #include "table/strings.h" #include "table/train_cmd.h" @@ -665,10 +666,17 @@ void DrawTrainEngine(int left, int right, int preferred_x, int y, EngineID engin SpriteID spritef = GetRailIcon(engine, false, yf); SpriteID spriter = GetRailIcon(engine, true, yr); + const Sprite *real_spritef = GetSprite(spritef, ST_NORMAL); + const Sprite *real_spriter = GetSprite(spriter, ST_NORMAL); + + preferred_x = Clamp(preferred_x, left - real_spritef->x_offs + 14, right - real_spriter->width - real_spriter->x_offs - 15); + DrawSprite(spritef, pal, preferred_x - 14, yf); DrawSprite(spriter, pal, preferred_x + 15, yr); } else { SpriteID sprite = GetRailIcon(engine, false, y); + const Sprite *real_sprite = GetSprite(sprite, ST_NORMAL); + preferred_x = Clamp(preferred_x, left - real_sprite->x_offs, right - real_sprite->width - real_sprite->x_offs); DrawSprite(sprite, pal, preferred_x, y); } } -- cgit v1.2.3-70-g09d2