diff --git a/aircraft.h b/aircraft.h new file mode 100644 index 0000000000..55fc35c899 --- /dev/null +++ b/aircraft.h @@ -0,0 +1,16 @@ +/* $Id$ */ + +#include "station_map.h" +#include "vehicle.h" + + +static inline bool IsAircraftInHangar(const Vehicle* v) +{ + assert(v->type == VEH_Aircraft); + return v->vehstatus & VS_HIDDEN && IsHangarTile(v->tile); +} + +static inline bool IsAircraftInHangarStopped(const Vehicle* v) +{ + return IsAircraftInHangar(v) && v->vehstatus & VS_STOPPED; +} diff --git a/aircraft_cmd.c b/aircraft_cmd.c index c451722d1c..a41cada341 100644 --- a/aircraft_cmd.c +++ b/aircraft_cmd.c @@ -2,6 +2,7 @@ #include "stdafx.h" #include "openttd.h" +#include "aircraft.h" #include "debug.h" #include "functions.h" #include "table/strings.h" @@ -312,16 +313,6 @@ bool IsAircraftHangarTile(TileIndex tile) (_m[tile].m5 == 32 || _m[tile].m5 == 65 || _m[tile].m5 == 86); } -bool CheckStoppedInHangar(const Vehicle* v) -{ - if (!(v->vehstatus & VS_STOPPED) || !IsAircraftHangarTile(v->tile)) { - _error_message = STR_A01B_AIRCRAFT_MUST_BE_STOPPED; - return false; - } - - return true; -} - static void DoDeleteAircraft(Vehicle *v) { @@ -345,8 +336,8 @@ int32 CmdSellAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2) v = GetVehicle(p1); - if (v->type != VEH_Aircraft || !CheckOwnership(v->owner) || !CheckStoppedInHangar(v)) - return CMD_ERROR; + if (v->type != VEH_Aircraft || !CheckOwnership(v->owner)) return CMD_ERROR; + if (!IsAircraftInHangarStopped(v)) return_cmd_error(STR_A01B_AIRCRAFT_MUST_BE_STOPPED); SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); @@ -472,7 +463,7 @@ int32 CmdRefitAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2) v = GetVehicle(p1); if (v->type != VEH_Aircraft || !CheckOwnership(v->owner)) return CMD_ERROR; - if (!CheckStoppedInHangar(v)) return_cmd_error(STR_A01B_AIRCRAFT_MUST_BE_STOPPED); + if (!IsAircraftInHangarStopped(v)) return_cmd_error(STR_A01B_AIRCRAFT_MUST_BE_STOPPED); avi = AircraftVehInfo(v->engine_type); diff --git a/aircraft_gui.c b/aircraft_gui.c index 4bb83c1c46..ed13d5e01d 100644 --- a/aircraft_gui.c +++ b/aircraft_gui.c @@ -2,6 +2,7 @@ #include "stdafx.h" #include "openttd.h" +#include "aircraft.h" #include "debug.h" #include "functions.h" #include "table/sprites.h" @@ -492,7 +493,6 @@ static const Widget _aircraft_view_widgets[] = { { WIDGETS_END } }; -bool CheckStoppedInHangar(const Vehicle* v); /* XXX extern function declaration in .c */ static void AircraftViewWndProc(Window *w, WindowEvent *e) { @@ -502,9 +502,7 @@ static void AircraftViewWndProc(Window *w, WindowEvent *e) uint32 disabled = 1 << 8; StringID str; - if (v->vehstatus & VS_STOPPED && IsAircraftHangarTile(v->tile)) { - disabled = 0; - } + if (IsAircraftInHangarStopped(v)) disabled = 0; if (v->owner != _local_player) disabled |= 1 << 8 | 1 << 7; w->disabled_state = disabled; @@ -597,7 +595,7 @@ static void AircraftViewWndProc(Window *w, WindowEvent *e) case WE_MOUSELOOP: { const Vehicle* v = GetVehicle(w->window_number); - uint32 h = CheckStoppedInHangar(v) ? (1 << 7) : (1 << 11); + uint32 h = IsAircraftInHangarStopped(v) ? 1 << 7 : 1 << 11; if (h != w->hidden_state) { w->hidden_state = h; @@ -1033,7 +1031,7 @@ static void PlayerAircraftWndProc(Window *w, WindowEvent *e) DrawVehicleProfitButton(v, x, y + 13); SetDParam(0, v->unitnumber); - if (IsAircraftHangarTile(v->tile) && (v->vehstatus & VS_HIDDEN)) { + if (IsAircraftInHangar(v)) { str = STR_021F; } else { str = v->age > v->max_age - 366 ? STR_00E3 : STR_00E2; diff --git a/station_map.h b/station_map.h new file mode 100644 index 0000000000..cba5be3369 --- /dev/null +++ b/station_map.h @@ -0,0 +1,40 @@ +/* $Id$ */ + +#include "tile.h" + +#ifndef STATION_MAP_H +#define STATION_MAP_H + +typedef byte StationGfx; + + +typedef enum HangarTiles { + HANGAR_TILE_0 = 32, + HANGAR_TILE_1 = 65, + HANGAR_TILE_2 = 86 +} HangarTiles; + + +static inline StationGfx GetStationGfx(TileIndex t) +{ + assert(IsTileType(t, MP_STATION)); + return _m[t].m5; +} + + +static inline bool IsHangar(TileIndex t) +{ + StationGfx gfx = GetStationGfx(t); + return + gfx == HANGAR_TILE_0 || + gfx == HANGAR_TILE_1 || + gfx == HANGAR_TILE_2; +} + + +static inline bool IsHangarTile(TileIndex t) +{ + return IsTileType(t, MP_STATION) && IsHangar(t); +} + +#endif