(svn r18123) -Codechange: try our best to keep the vehicles within the build vehicle list/autoreplace lists instead of overflowing.

This commit is contained in:
rubidium 2009-11-16 17:58:46 +00:00
parent fdbe2d827c
commit bae066ecaf
4 changed files with 21 additions and 3 deletions

View File

@ -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);

View File

@ -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)

View File

@ -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)

View File

@ -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);
}
}