(svn r27666) -Codechange: Pass vehicle sprites around using a struct VehicleSpriteSeq.
This commit is contained in:
@@ -152,64 +152,67 @@ static StationID FindNearestHangar(const Aircraft *v)
|
||||
return index;
|
||||
}
|
||||
|
||||
SpriteID Aircraft::GetImage(Direction direction, EngineImageType image_type) const
|
||||
void Aircraft::GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const
|
||||
{
|
||||
uint8 spritenum = this->spritenum;
|
||||
|
||||
if (is_custom_sprite(spritenum)) {
|
||||
SpriteID sprite = GetCustomVehicleSprite(this, direction, image_type);
|
||||
if (sprite != 0) return sprite;
|
||||
GetCustomVehicleSprite(this, direction, image_type, result);
|
||||
if (result->IsValid()) return;
|
||||
|
||||
spritenum = this->GetEngine()->original_image_index;
|
||||
}
|
||||
|
||||
assert(IsValidImageIndex<VEH_AIRCRAFT>(spritenum));
|
||||
return direction + _aircraft_sprite[spritenum];
|
||||
result->Set(direction + _aircraft_sprite[spritenum]);
|
||||
}
|
||||
|
||||
SpriteID GetRotorImage(const Aircraft *v, EngineImageType image_type)
|
||||
void GetRotorImage(const Aircraft *v, EngineImageType image_type, VehicleSpriteSeq *result)
|
||||
{
|
||||
assert(v->subtype == AIR_HELICOPTER);
|
||||
|
||||
const Aircraft *w = v->Next()->Next();
|
||||
if (is_custom_sprite(v->spritenum)) {
|
||||
SpriteID sprite = GetCustomRotorSprite(v, false, image_type);
|
||||
if (sprite != 0) return sprite;
|
||||
GetCustomRotorSprite(v, false, image_type, result);
|
||||
if (result->IsValid()) return;
|
||||
}
|
||||
|
||||
/* Return standard rotor sprites if there are no custom sprites for this helicopter */
|
||||
return SPR_ROTOR_STOPPED + w->state;
|
||||
result->Set(SPR_ROTOR_STOPPED + w->state);
|
||||
}
|
||||
|
||||
static SpriteID GetAircraftIcon(EngineID engine, EngineImageType image_type)
|
||||
static void GetAircraftIcon(EngineID engine, EngineImageType image_type, VehicleSpriteSeq *result)
|
||||
{
|
||||
const Engine *e = Engine::Get(engine);
|
||||
uint8 spritenum = e->u.air.image_index;
|
||||
|
||||
if (is_custom_sprite(spritenum)) {
|
||||
SpriteID sprite = GetCustomVehicleIcon(engine, DIR_W, image_type);
|
||||
if (sprite != 0) return sprite;
|
||||
GetCustomVehicleIcon(engine, DIR_W, image_type, result);
|
||||
if (result->IsValid()) return;
|
||||
|
||||
spritenum = e->original_image_index;
|
||||
}
|
||||
|
||||
assert(IsValidImageIndex<VEH_AIRCRAFT>(spritenum));
|
||||
return DIR_W + _aircraft_sprite[spritenum];
|
||||
result->Set(DIR_W + _aircraft_sprite[spritenum]);
|
||||
}
|
||||
|
||||
void DrawAircraftEngine(int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type)
|
||||
{
|
||||
SpriteID sprite = GetAircraftIcon(engine, image_type);
|
||||
const Sprite *real_sprite = GetSprite(sprite, ST_NORMAL);
|
||||
VehicleSpriteSeq seq;
|
||||
GetAircraftIcon(engine, image_type, &seq);
|
||||
|
||||
const Sprite *real_sprite = GetSprite(seq.sprite, ST_NORMAL);
|
||||
preferred_x = Clamp(preferred_x,
|
||||
left - UnScaleGUI(real_sprite->x_offs),
|
||||
right - UnScaleGUI(real_sprite->width) - UnScaleGUI(real_sprite->x_offs));
|
||||
DrawSprite(sprite, pal, preferred_x, y);
|
||||
DrawSprite(seq.sprite, pal, preferred_x, y);
|
||||
|
||||
if (!(AircraftVehInfo(engine)->subtype & AIR_CTOL)) {
|
||||
SpriteID rotor_sprite = GetCustomRotorIcon(engine, image_type);
|
||||
if (rotor_sprite == 0) rotor_sprite = SPR_ROTOR_STOPPED;
|
||||
DrawSprite(rotor_sprite, PAL_NONE, preferred_x, y - ScaleGUITrad(5));
|
||||
VehicleSpriteSeq rotor_seq;
|
||||
GetCustomRotorIcon(engine, image_type, &rotor_seq);
|
||||
if (!rotor_seq.IsValid()) rotor_seq.Set(SPR_ROTOR_STOPPED);
|
||||
DrawSprite(rotor_seq.sprite, PAL_NONE, preferred_x, y - ScaleGUITrad(5));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,7 +227,10 @@ void DrawAircraftEngine(int left, int right, int preferred_x, int y, EngineID en
|
||||
*/
|
||||
void GetAircraftSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type)
|
||||
{
|
||||
const Sprite *spr = GetSprite(GetAircraftIcon(engine, image_type), ST_NORMAL);
|
||||
VehicleSpriteSeq seq;
|
||||
GetAircraftIcon(engine, image_type, &seq);
|
||||
|
||||
const Sprite *spr = GetSprite(seq.sprite, ST_NORMAL);
|
||||
|
||||
width = UnScaleGUI(spr->width);
|
||||
height = UnScaleGUI(spr->height);
|
||||
@@ -317,7 +323,8 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, const Engine *
|
||||
v->date_of_last_service = _date;
|
||||
v->build_year = u->build_year = _cur_year;
|
||||
|
||||
v->cur_image = u->cur_image = SPR_IMG_QUERY;
|
||||
v->sprite_seq.Set(SPR_IMG_QUERY);
|
||||
u->sprite_seq.Set(SPR_IMG_QUERY);
|
||||
|
||||
v->random_bits = VehicleRandomBits();
|
||||
u->random_bits = VehicleRandomBits();
|
||||
@@ -349,7 +356,7 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, const Engine *
|
||||
w->vehstatus = VS_HIDDEN | VS_UNCLICKABLE;
|
||||
w->spritenum = 0xFF;
|
||||
w->subtype = AIR_ROTOR;
|
||||
w->cur_image = SPR_ROTOR_STOPPED;
|
||||
w->sprite_seq.Set(SPR_ROTOR_STOPPED);
|
||||
w->random_bits = VehicleRandomBits();
|
||||
/* Use rotor's air.state to store the rotor animation frame */
|
||||
w->state = HRS_ROTOR_STOPPED;
|
||||
@@ -468,21 +475,21 @@ static void HelicopterTickHandler(Aircraft *v)
|
||||
int tick = ++u->tick_counter;
|
||||
int spd = u->cur_speed >> 4;
|
||||
|
||||
SpriteID img;
|
||||
VehicleSpriteSeq seq;
|
||||
if (spd == 0) {
|
||||
u->state = HRS_ROTOR_STOPPED;
|
||||
img = GetRotorImage(v, EIT_ON_MAP);
|
||||
if (u->cur_image == img) return;
|
||||
GetRotorImage(v, EIT_ON_MAP, &seq);
|
||||
if (u->sprite_seq == seq) return;
|
||||
} else if (tick >= spd) {
|
||||
u->tick_counter = 0;
|
||||
u->state++;
|
||||
if (u->state > HRS_ROTOR_MOVING_3) u->state = HRS_ROTOR_MOVING_1;
|
||||
img = GetRotorImage(v, EIT_ON_MAP);
|
||||
GetRotorImage(v, EIT_ON_MAP, &seq);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
u->cur_image = img;
|
||||
u->sprite_seq = seq;
|
||||
|
||||
u->UpdatePositionAndViewport();
|
||||
}
|
||||
@@ -502,7 +509,9 @@ void SetAircraftPosition(Aircraft *v, int x, int y, int z)
|
||||
|
||||
v->UpdatePosition();
|
||||
v->UpdateViewport(true, false);
|
||||
if (v->subtype == AIR_HELICOPTER) v->Next()->Next()->cur_image = GetRotorImage(v, EIT_ON_MAP);
|
||||
if (v->subtype == AIR_HELICOPTER) {
|
||||
GetRotorImage(v, EIT_ON_MAP, &v->Next()->Next()->sprite_seq);
|
||||
}
|
||||
|
||||
Aircraft *u = v->Next();
|
||||
|
||||
@@ -513,7 +522,7 @@ void SetAircraftPosition(Aircraft *v, int x, int y, int z)
|
||||
|
||||
safe_y = Clamp(u->y_pos, 0, MapMaxY() * TILE_SIZE);
|
||||
u->z_pos = GetSlopePixelZ(safe_x, safe_y);
|
||||
u->cur_image = v->cur_image;
|
||||
u->sprite_seq.sprite = v->sprite_seq.sprite;
|
||||
|
||||
u->UpdatePositionAndViewport();
|
||||
|
||||
@@ -1237,7 +1246,9 @@ void Aircraft::MarkDirty()
|
||||
{
|
||||
this->colourmap = PAL_NONE;
|
||||
this->UpdateViewport(true, false);
|
||||
if (this->subtype == AIR_HELICOPTER) this->Next()->Next()->cur_image = GetRotorImage(this, EIT_ON_MAP);
|
||||
if (this->subtype == AIR_HELICOPTER) {
|
||||
GetRotorImage(this, EIT_ON_MAP, &this->Next()->Next()->sprite_seq);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user