summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-07-01 19:11:47 +0000
committerrubidium <rubidium@openttd.org>2007-07-01 19:11:47 +0000
commit83a880c882992efb1b949b26ac881abc3825964f (patch)
tree2e6180dd4e262fcc66cf94a5d26c4c6fb7df642f
parentc49fd0957d9e0fbecd365b2c86e82a1a37625921 (diff)
downloadopenttd-83a880c882992efb1b949b26ac881abc3825964f.tar.xz
(svn r10408) -Codechange: make GetImage a class method of Vehicle instead of Get(Aircraft|RoadVeh|Ship|Train)Image.
-rw-r--r--src/aircraft.h1
-rw-r--r--src/aircraft_cmd.cpp12
-rw-r--r--src/aircraft_gui.cpp2
-rw-r--r--src/depot_gui.cpp12
-rw-r--r--src/group_gui.cpp12
-rw-r--r--src/roadveh.h1
-rw-r--r--src/roadveh_cmd.cpp26
-rw-r--r--src/roadveh_gui.cpp2
-rw-r--r--src/ship.h1
-rw-r--r--src/ship_cmd.cpp14
-rw-r--r--src/ship_gui.cpp2
-rw-r--r--src/train.h1
-rw-r--r--src/train_cmd.cpp22
-rw-r--r--src/train_gui.cpp4
-rw-r--r--src/vehicle.cpp9
-rw-r--r--src/vehicle.h12
16 files changed, 61 insertions, 72 deletions
diff --git a/src/aircraft.h b/src/aircraft.h
index f7cd1b457..22a3e1a2b 100644
--- a/src/aircraft.h
+++ b/src/aircraft.h
@@ -136,6 +136,7 @@ struct Aircraft : public Vehicle {
ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_AIRCRAFT_INC : EXPENSES_AIRCRAFT_RUN; }
WindowClass GetVehicleListWindowClass() const { return WC_AIRCRAFT_LIST; }
bool IsPrimaryVehicle() const { return IsNormalAircraft(this); }
+ int GetImage(Direction direction) const;
};
#endif /* AIRCRAFT_H */
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index fa16ab26b..99a3b7e2d 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -153,15 +153,15 @@ static bool HaveHangarInOrderList(Vehicle *v)
}
#endif
-int GetAircraftImage(const Vehicle* v, Direction direction)
+int Aircraft::GetImage(Direction direction) const
{
- int spritenum = v->spritenum;
+ int spritenum = this->spritenum;
if (is_custom_sprite(spritenum)) {
- int sprite = GetCustomVehicleSprite(v, direction);
+ int sprite = GetCustomVehicleSprite(this, direction);
if (sprite != 0) return sprite;
- spritenum = orig_aircraft_vehicle_info[v->engine_type - AIRCRAFT_ENGINES_INDEX].image_index;
+ spritenum = orig_aircraft_vehicle_info[this->engine_type - AIRCRAFT_ENGINES_INDEX].image_index;
}
return direction + _aircraft_sprite[spritenum];
}
@@ -827,7 +827,7 @@ static void SetAircraftPosition(Vehicle *v, int x, int y, int z)
v->y_pos = y;
v->z_pos = z;
- v->cur_image = GetAircraftImage(v, v->direction);
+ v->cur_image = v->GetImage(v->direction);
if (v->subtype == AIR_HELICOPTER) v->next->next->cur_image = GetRotorImage(v);
BeginVehicleMove(v);
@@ -1409,7 +1409,7 @@ static void ProcessAircraftOrder(Vehicle *v)
void Aircraft::MarkDirty()
{
- this->cur_image = GetAircraftImage(this, this->direction);
+ this->cur_image = this->GetImage(this->direction);
if (this->subtype == AIR_HELICOPTER) this->next->next->cur_image = GetRotorImage(this);
MarkAllViewportsDirty(this->left_coord, this->top_coord, this->right_coord + 1, this->bottom_coord + 1);
}
diff --git a/src/aircraft_gui.cpp b/src/aircraft_gui.cpp
index cea5097f0..c02a21346 100644
--- a/src/aircraft_gui.cpp
+++ b/src/aircraft_gui.cpp
@@ -25,7 +25,7 @@
void DrawAircraftImage(const Vehicle *v, int x, int y, VehicleID selection)
{
SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
- DrawSprite(GetAircraftImage(v, DIR_W), pal, x + 25, y + 10);
+ DrawSprite(v->GetImage(DIR_W), pal, x + 25, y + 10);
if (v->subtype == AIR_HELICOPTER) {
SpriteID rotor_sprite = GetCustomRotorSprite(v, true);
if (rotor_sprite == 0) rotor_sprite = SPR_ROTOR_STOPPED;
diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp
index 59f97f4c8..2f63a0945 100644
--- a/src/depot_gui.cpp
+++ b/src/depot_gui.cpp
@@ -187,7 +187,7 @@ static void DrawVehicleInDepot(Window *w, const Vehicle *v, int x, int y)
case VEH_ROAD: DrawRoadVehImage( v, x + 24, sprite_y, 1, WP(w, depot_d).sel); break;
case VEH_SHIP: DrawShipImage( v, x + 19, sprite_y - 1, WP(w, depot_d).sel); break;
case VEH_AIRCRAFT: {
- const Sprite *spr = GetSprite(GetAircraftImage(v, DIR_W));
+ const Sprite *spr = GetSprite(v->GetImage(DIR_W));
DrawAircraftImage(v, x + 12,
y + max(spr->height + spr->y_offs - 14, 0), // tall sprites needs an y offset
WP(w, depot_d).sel);
@@ -438,15 +438,7 @@ static void DepotClick(Window *w, int x, int y)
WP(w,depot_d).sel = INVALID_VEHICLE;
TrainDepotMoveVehicle(v, sel, gdvp.head);
} else if (v != NULL) {
- int image;
-
- switch (WP(w, depot_d).type) {
- case VEH_TRAIN: image = GetTrainImage(v, DIR_W); break;
- case VEH_ROAD: image = GetRoadVehImage(v, DIR_W); break;
- case VEH_SHIP: image = GetShipImage(v, DIR_W); break;
- case VEH_AIRCRAFT: image = GetAircraftImage(v, DIR_W); break;
- default: NOT_REACHED(); image = 0;
- }
+ int image = v->GetImage(DIR_W);
WP(w, depot_d).sel = v->index;
SetWindowDirty(w);
diff --git a/src/group_gui.cpp b/src/group_gui.cpp
index 356407247..d4af0ba78 100644
--- a/src/group_gui.cpp
+++ b/src/group_gui.cpp
@@ -531,17 +531,7 @@ static void GroupWndProc(Window *w, WindowEvent *e)
gv->vehicle_sel = v->index;
if (IsValidVehicle(v)) {
- CursorID image;
-
- switch (gv->vehicle_type) {
- case VEH_TRAIN: image = GetTrainImage(v, DIR_W); break;
- case VEH_ROAD: image = GetRoadVehImage(v, DIR_W); break;
- case VEH_SHIP: image = GetShipImage(v, DIR_W); break;
- case VEH_AIRCRAFT: image = GetAircraftImage(v, DIR_W); break;
- default: NOT_REACHED(); break;
- }
-
- SetObjectToPlaceWnd(image, GetVehiclePalette(v), 4, w);
+ SetObjectToPlaceWnd(v->GetImage(DIR_W), GetVehiclePalette(v), 4, w);
}
SetWindowDirty(w);
diff --git a/src/roadveh.h b/src/roadveh.h
index 6547d7442..f623317a8 100644
--- a/src/roadveh.h
+++ b/src/roadveh.h
@@ -81,6 +81,7 @@ struct RoadVehicle : public Vehicle {
WindowClass GetVehicleListWindowClass() const { return WC_ROADVEH_LIST; }
bool IsPrimaryVehicle() const { return IsRoadVehFront(this); }
bool HasFront() const { return true; }
+ int GetImage(Direction direction) const;
};
byte GetRoadVehLength(const Vehicle *v);
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index 9fa95b8e0..5217e3b8a 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -85,19 +85,19 @@ static const Trackdir _roadveh_depot_exit_trackdir[DIAGDIR_END] = {
TRACKDIR_X_NE, TRACKDIR_Y_SE, TRACKDIR_X_SW, TRACKDIR_Y_NW
};
-int GetRoadVehImage(const Vehicle* v, Direction direction)
+int RoadVehicle::GetImage(Direction direction) const
{
- int img = v->spritenum;
+ int img = this->spritenum;
int image;
if (is_custom_sprite(img)) {
- image = GetCustomVehicleSprite(v, (Direction)(direction + 4 * IS_CUSTOM_SECONDHEAD_SPRITE(img)));
+ image = GetCustomVehicleSprite(this, (Direction)(direction + 4 * IS_CUSTOM_SECONDHEAD_SPRITE(img)));
if (image != 0) return image;
- img = orig_road_vehicle_info[v->engine_type - ROAD_ENGINES_INDEX].image_index;
+ img = orig_road_vehicle_info[this->engine_type - ROAD_ENGINES_INDEX].image_index;
}
image = direction + _roadveh_images[img];
- if (v->cargo.Count() >= v->cargo_cap / 2U) image += _roadveh_full_adder[img];
+ if (this->cargo.Count() >= this->cargo_cap / 2U) image += _roadveh_full_adder[img];
return image;
}
@@ -555,7 +555,7 @@ CommandCost CmdTurnRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
void RoadVehicle::MarkDirty()
{
- this->cur_image = GetRoadVehImage(this, this->direction);
+ this->cur_image = this->GetImage(this->direction);
MarkAllViewportsDirty(this->left_coord, this->top_coord, this->right_coord + 1, this->bottom_coord + 1);
}
@@ -641,7 +641,7 @@ static void RoadVehSetRandomDirection(Vehicle *v)
v->direction = ChangeDir(v->direction, delta[r & 3]);
BeginVehicleMove(v);
v->UpdateDeltaXY(v->direction);
- v->cur_image = GetRoadVehImage(v, v->direction);
+ v->cur_image = v->GetImage(v->direction);
SetRoadVehPosition(v, v->x_pos, v->y_pos);
} while ((v = v->next) != NULL);
}
@@ -1366,7 +1366,7 @@ static bool RoadVehLeaveDepot(Vehicle *v, bool first)
v->u.road.state = tdir;
v->u.road.frame = RVC_DEPOT_START_FRAME;
- v->cur_image = GetRoadVehImage(v, v->direction);
+ v->cur_image = v->GetImage(v->direction);
v->UpdateDeltaXY(v->direction);
SetRoadVehPosition(v,x,y);
@@ -1459,7 +1459,7 @@ static bool IndividualRoadVehicleController(Vehicle *v, const Vehicle *prev)
if ((IsTunnelTile(gp.new_tile) || IsBridgeTile(gp.new_tile)) && HASBIT(VehicleEnterTile(v, gp.new_tile, gp.x, gp.y), VETS_ENTERED_WORMHOLE)) {
/* Vehicle has just entered a bridge or tunnel */
- v->cur_image = GetRoadVehImage(v, v->direction);
+ v->cur_image = v->GetImage(v->direction);
v->UpdateDeltaXY(v->direction);
SetRoadVehPosition(v,gp.x,gp.y);
return true;
@@ -1574,7 +1574,7 @@ again:
v->cur_speed -= v->cur_speed >> 2;
}
- v->cur_image = GetRoadVehImage(v, newdir);
+ v->cur_image = v->GetImage(newdir);
v->UpdateDeltaXY(v->direction);
RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y));
return true;
@@ -1614,7 +1614,7 @@ again:
v->cur_speed -= v->cur_speed >> 2;
}
- v->cur_image = GetRoadVehImage(v, newdir);
+ v->cur_image = v->GetImage(newdir);
v->UpdateDeltaXY(v->direction);
RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y));
return true;
@@ -1656,7 +1656,7 @@ again:
v->cur_speed -= (v->cur_speed >> 2);
if (old_dir != v->u.road.state) {
/* The vehicle is in a road stop */
- v->cur_image = GetRoadVehImage(v, new_dir);
+ v->cur_image = v->GetImage(new_dir);
v->UpdateDeltaXY(v->direction);
SetRoadVehPosition(v, v->x_pos, v->y_pos);
/* Note, return here means that the frame counter is not incremented
@@ -1776,7 +1776,7 @@ again:
* in a depot or entered a tunnel/bridge */
if (!HASBIT(r, VETS_ENTERED_WORMHOLE)) v->u.road.frame++;
- v->cur_image = GetRoadVehImage(v, v->direction);
+ v->cur_image = v->GetImage(v->direction);
v->UpdateDeltaXY(v->direction);
RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y));
return true;
diff --git a/src/roadveh_gui.cpp b/src/roadveh_gui.cpp
index a746cb413..79eb3fa14 100644
--- a/src/roadveh_gui.cpp
+++ b/src/roadveh_gui.cpp
@@ -38,7 +38,7 @@ void DrawRoadVehImage(const Vehicle *v, int x, int y, int count, VehicleID selec
if (dx + length > 0 && dx <= max_length) {
SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
- DrawSprite(GetRoadVehImage(v, DIR_W), pal, x + 14 + RoadVehLengthToPixels(dx), y + 6);
+ DrawSprite(v->GetImage(DIR_W), pal, x + 14 + RoadVehLengthToPixels(dx), y + 6);
if (v->index == selection) {
DrawFrameRect(x - 1, y - 1, x + 28, y + 12, 15, FR_BORDERONLY);
diff --git a/src/ship.h b/src/ship.h
index b045beb05..200c1016c 100644
--- a/src/ship.h
+++ b/src/ship.h
@@ -46,6 +46,7 @@ struct Ship: public Vehicle {
WindowClass GetVehicleListWindowClass() const { return WC_SHIPS_LIST; }
void PlayLeaveStationSound() const;
bool IsPrimaryVehicle() const { return true; }
+ int GetImage(Direction direction) const;
};
#endif /* SHIP_H */
diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp
index f98fde144..555af11b5 100644
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -90,15 +90,15 @@ void GetShipSpriteSize(EngineID engine, uint &width, uint &height)
height = spr->height;
}
-int GetShipImage(const Vehicle* v, Direction direction)
+int Ship::GetImage(Direction direction) const
{
- int spritenum = v->spritenum;
+ int spritenum = this->spritenum;
if (is_custom_sprite(spritenum)) {
- int sprite = GetCustomVehicleSprite(v, direction);
+ int sprite = GetCustomVehicleSprite(this, direction);
if (sprite != 0) return sprite;
- spritenum = orig_ship_vehicle_info[v->engine_type - SHIP_ENGINES_INDEX].image_index;
+ spritenum = orig_ship_vehicle_info[this->engine_type - SHIP_ENGINES_INDEX].image_index;
}
return _ship_sprites[spritenum] + direction;
}
@@ -233,7 +233,7 @@ static void HandleBrokenShip(Vehicle *v)
void Ship::MarkDirty()
{
- this->cur_image = GetShipImage(this, this->direction);
+ this->cur_image = this->GetImage(this->direction);
MarkAllViewportsDirty(this->left_coord, this->top_coord, this->right_coord + 1, this->bottom_coord + 1);
}
@@ -337,7 +337,7 @@ void Ship::UpdateDeltaXY(Direction direction)
void RecalcShipStuff(Vehicle *v)
{
v->UpdateDeltaXY(v->direction);
- v->cur_image = GetShipImage(v, v->direction);
+ v->cur_image = v->GetImage(v->direction);
v->MarkDirty();
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
}
@@ -770,7 +770,7 @@ static void ShipController(Vehicle *v)
getout:
v->UpdateDeltaXY(dir);
- v->cur_image = GetShipImage(v, dir);
+ v->cur_image = v->GetImage(dir);
VehiclePositionChanged(v);
EndVehicleMove(v);
return;
diff --git a/src/ship_gui.cpp b/src/ship_gui.cpp
index ceb13defb..bf931167b 100644
--- a/src/ship_gui.cpp
+++ b/src/ship_gui.cpp
@@ -19,7 +19,7 @@
void DrawShipImage(const Vehicle *v, int x, int y, VehicleID selection)
{
- DrawSprite(GetShipImage(v, DIR_W), GetVehiclePalette(v), x + 32, y + 10);
+ DrawSprite(v->GetImage(DIR_W), GetVehiclePalette(v), x + 32, y + 10);
if (v->index == selection) {
DrawFrameRect(x - 5, y - 1, x + 67, y + 21, 15, FR_BORDERONLY);
diff --git a/src/train.h b/src/train.h
index 3d09d4cea..33d500a26 100644
--- a/src/train.h
+++ b/src/train.h
@@ -272,6 +272,7 @@ struct Train : public Vehicle {
void PlayLeaveStationSound() const;
bool IsPrimaryVehicle() const { return IsFrontEngine(this); }
bool HasFront() const { return true; }
+ int GetImage(Direction direction) const;
};
#endif /* TRAIN_H */
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 4cb427b81..3102d2e55 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -448,22 +448,22 @@ static void UpdateTrainAcceleration(Vehicle* v)
v->acceleration = clamp(power / weight * 4, 1, 255);
}
-int GetTrainImage(const Vehicle* v, Direction direction)
+int Train::GetImage(Direction direction) const
{
- int img = v->spritenum;
+ int img = this->spritenum;
int base;
- if (HASBIT(v->u.rail.flags, VRF_REVERSE_DIRECTION)) direction = ReverseDir(direction);
+ if (HASBIT(this->u.rail.flags, VRF_REVERSE_DIRECTION)) direction = ReverseDir(direction);
if (is_custom_sprite(img)) {
- base = GetCustomVehicleSprite(v, (Direction)(direction + 4 * IS_CUSTOM_SECONDHEAD_SPRITE(img)));
+ base = GetCustomVehicleSprite(this, (Direction)(direction + 4 * IS_CUSTOM_SECONDHEAD_SPRITE(img)));
if (base != 0) return base;
- img = orig_rail_vehicle_info[v->engine_type].image_index;
+ img = orig_rail_vehicle_info[this->engine_type].image_index;
}
base = _engine_sprite_base[img] + ((direction + _engine_sprite_add[img]) & _engine_sprite_and[img]);
- if (v->cargo.Count() >= v->cargo_cap / 2U) base += _wagon_full_adder[img];
+ if (this->cargo.Count() >= this->cargo_cap / 2U) base += _wagon_full_adder[img];
return base;
}
@@ -1424,7 +1424,7 @@ void Train::UpdateDeltaXY(Direction direction)
static void UpdateVarsAfterSwap(Vehicle *v)
{
v->UpdateDeltaXY(v->direction);
- v->cur_image = GetTrainImage(v, v->direction);
+ v->cur_image = v->GetImage(v->direction);
BeginVehicleMove(v);
VehiclePositionChanged(v);
EndVehicleMove(v);
@@ -2081,7 +2081,7 @@ static bool CheckTrainStayInDepot(Vehicle *v)
v->cur_speed = 0;
v->UpdateDeltaXY(v->direction);
- v->cur_image = GetTrainImage(v, v->direction);
+ v->cur_image = v->GetImage(v->direction);
VehiclePositionChanged(v);
UpdateSignalsOnSegment(v->tile, DirToDiagDir(v->direction));
UpdateTrainAcceleration(v);
@@ -2467,7 +2467,7 @@ void Train::MarkDirty()
{
Vehicle *v = this;
do {
- v->cur_image = GetTrainImage(v, v->direction);
+ v->cur_image = v->GetImage(v->direction);
MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1);
} while ((v = v->next) != NULL);
@@ -2969,7 +2969,7 @@ static void TrainController(Vehicle *v, bool update_image)
/* update image of train, as well as delta XY */
Direction newdir = GetNewVehicleDirection(v, gp.x, gp.y);
v->UpdateDeltaXY(newdir);
- if (update_image) v->cur_image = GetTrainImage(v, newdir);
+ if (update_image) v->cur_image = v->GetImage(newdir);
v->x_pos = gp.x;
v->y_pos = gp.y;
@@ -3076,7 +3076,7 @@ static void ChangeTrainDirRandomly(Vehicle *v)
v->direction = ChangeDir(v->direction, delta[GB(Random(), 0, 2)]);
BeginVehicleMove(v);
v->UpdateDeltaXY(v->direction);
- v->cur_image = GetTrainImage(v, v->direction);
+ v->cur_image = v->GetImage(v->direction);
/* Refrain from updating the z position of the vehicle when on
a bridge, because AfterSetTrainPos will put the vehicle under
the bridge in that case */
diff --git a/src/train_gui.cpp b/src/train_gui.cpp
index 161a997b7..699feb4b1 100644
--- a/src/train_gui.cpp
+++ b/src/train_gui.cpp
@@ -93,7 +93,7 @@ void DrawTrainImage(const Vehicle *v, int x, int y, int count, int skip, Vehicle
if (dx + width > 0) {
if (dx <= count) {
SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
- DrawSprite(GetTrainImage(v, DIR_W), pal, 16 + WagonLengthToPixels(dx), 7 + (is_custom_sprite(RailVehInfo(v->engine_type)->image_index) ? _traininfo_vehicle_pitch : 0));
+ DrawSprite(v->GetImage(DIR_W), pal, 16 + WagonLengthToPixels(dx), 7 + (is_custom_sprite(RailVehInfo(v->engine_type)->image_index) ? _traininfo_vehicle_pitch : 0));
if (v->index == selection) {
/* Set the highlight position */
highlight_l = WagonLengthToPixels(dx) + 1;
@@ -459,7 +459,7 @@ static void DrawTrainDetailsWindow(Window *w)
u = v;
do {
SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
- DrawSprite(GetTrainImage(u, DIR_W), pal, x + WagonLengthToPixels(4 + dx), y + 6 + (is_custom_sprite(RailVehInfo(u->engine_type)->image_index) ? _traininfo_vehicle_pitch : 0));
+ DrawSprite(u->GetImage(DIR_W), pal, x + WagonLengthToPixels(4 + dx), y + 6 + (is_custom_sprite(RailVehInfo(u->engine_type)->image_index) ? _traininfo_vehicle_pitch : 0));
dx += u->u.rail.cached_veh_length;
u = u->next;
} while (u != NULL && IsArticulatedPart(u) && u->cargo_cap == 0);
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 775113536..8b17afdb9 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -249,16 +249,17 @@ void AfterLoadVehicles()
FOR_ALL_VEHICLES(v) {
switch (v->type) {
case VEH_ROAD:
- v->cur_image = GetRoadVehImage(v, v->direction);
v->u.road.roadtype = HASBIT(EngInfo(v->engine_type)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD;
v->u.road.compatible_roadtypes = RoadTypeToRoadTypes(v->u.road.roadtype);
+ /* FALL THROUGH */
+ case VEH_TRAIN:
+ case VEH_SHIP:
+ v->cur_image = v->GetImage(v->direction);
break;
- case VEH_TRAIN: v->cur_image = GetTrainImage(v, v->direction); break;
- case VEH_SHIP: v->cur_image = GetShipImage(v, v->direction); break;
case VEH_AIRCRAFT:
if (IsNormalAircraft(v)) {
- v->cur_image = GetAircraftImage(v, v->direction);
+ v->cur_image = v->GetImage(v->direction);
/* The plane's shadow will have the same image as the plane */
Vehicle *shadow = v->next;
diff --git a/src/vehicle.h b/src/vehicle.h
index df587b84b..8d2ac0e08 100644
--- a/src/vehicle.h
+++ b/src/vehicle.h
@@ -420,6 +420,13 @@ struct Vehicle {
* basically, if GetFirstVehicleInChain() can be called for it.
*/
virtual bool HasFront() const { return false; }
+
+ /**
+ * Gets the sprite to show for the given direction
+ * @param direction the direction the vehicle is facing
+ * @return the sprite for the given vehicle in the given direction
+ */
+ virtual int GetImage(Direction direction) const { return 0; }
};
/**
@@ -520,11 +527,6 @@ CommandCost GetRefitCost(EngineID engine_type);
void ViewportAddVehicles(DrawPixelInfo *dpi);
-/* train_cmd.h */
-int GetTrainImage(const Vehicle* v, Direction direction);
-int GetAircraftImage(const Vehicle* v, Direction direction);
-int GetRoadVehImage(const Vehicle* v, Direction direction);
-int GetShipImage(const Vehicle* v, Direction direction);
SpriteID GetRotorImage(const Vehicle *v);
Vehicle *CreateEffectVehicle(int x, int y, int z, EffectVehicle type);