From 71b0d5f09156841b8d6728ab926000f0d6305f82 Mon Sep 17 00:00:00 2001 From: peter1138 Date: Mon, 4 Feb 2008 11:28:12 +0000 Subject: (svn r12054) -Cleanup: Use VehicleType instead of byte for vehicle types... --- src/autoreplace_gui.cpp | 4 ++-- src/build_vehicle_gui.cpp | 9 +++++++-- src/depot_gui.cpp | 4 +++- src/engine.cpp | 19 ++++++++----------- src/engine.h | 6 +++--- 5 files changed, 23 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/autoreplace_gui.cpp b/src/autoreplace_gui.cpp index a478f1456..3ea1cbdb4 100644 --- a/src/autoreplace_gui.cpp +++ b/src/autoreplace_gui.cpp @@ -80,7 +80,7 @@ void InitializeVehiclesGuiList() void InvalidateAutoreplaceWindow(EngineID e, GroupID id_g) { Player *p = GetPlayer(_local_player); - byte type = GetEngine(e)->type; + VehicleType type = GetEngine(e)->type; uint num_engines = GetGroupNumEngines(_local_player, id_g, e); if (num_engines == 0 || p->num_engines[e] == 0) { @@ -175,7 +175,7 @@ static void GenerateReplaceVehList(Window *w, bool draw_left) { EngineID e; EngineID selected_engine = INVALID_ENGINE; - byte type = w->window_number; + VehicleType type = (VehicleType)w->window_number; byte i = draw_left ? 0 : 1; EngineList *list = &WP(w, replaceveh_d).list[i]; diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index d524b0770..2922f301b 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -81,9 +81,11 @@ static const Widget _build_vehicle_widgets[] = { }; /* Setup widget strings to fit the different types of vehicles */ -static void SetupWindowStrings(Window *w, byte type) +static void SetupWindowStrings(Window *w, VehicleType type) { switch (type) { + default: NOT_REACHED(); + case VEH_TRAIN: w->widget[BUILD_VEHICLE_WIDGET_CAPTION].data = STR_JUST_STRING; w->widget[BUILD_VEHICLE_WIDGET_LIST].tooltips = STR_8843_TRAIN_VEHICLE_SELECTION; @@ -92,6 +94,7 @@ static void SetupWindowStrings(Window *w, byte type) w->widget[BUILD_VEHICLE_WIDGET_RENAME].data = STR_8820_RENAME; w->widget[BUILD_VEHICLE_WIDGET_RENAME].tooltips = STR_8845_RENAME_TRAIN_VEHICLE_TYPE; break; + case VEH_ROAD: w->widget[BUILD_VEHICLE_WIDGET_CAPTION].data = STR_9006_NEW_ROAD_VEHICLES; w->widget[BUILD_VEHICLE_WIDGET_LIST].tooltips = STR_9026_ROAD_VEHICLE_SELECTION; @@ -100,6 +103,7 @@ static void SetupWindowStrings(Window *w, byte type) w->widget[BUILD_VEHICLE_WIDGET_RENAME].data = STR_9034_RENAME; w->widget[BUILD_VEHICLE_WIDGET_RENAME].tooltips = STR_9035_RENAME_ROAD_VEHICLE_TYPE; break; + case VEH_SHIP: w->widget[BUILD_VEHICLE_WIDGET_CAPTION].data = STR_9808_NEW_SHIPS; w->widget[BUILD_VEHICLE_WIDGET_LIST].tooltips = STR_9825_SHIP_SELECTION_LIST_CLICK; @@ -108,6 +112,7 @@ static void SetupWindowStrings(Window *w, byte type) w->widget[BUILD_VEHICLE_WIDGET_RENAME].data = STR_9836_RENAME; w->widget[BUILD_VEHICLE_WIDGET_RENAME].tooltips = STR_9837_RENAME_SHIP_TYPE; break; + case VEH_AIRCRAFT: w->widget[BUILD_VEHICLE_WIDGET_CAPTION].data = STR_A005_NEW_AIRCRAFT; w->widget[BUILD_VEHICLE_WIDGET_LIST].tooltips = STR_A025_AIRCRAFT_SELECTION_LIST; @@ -890,7 +895,7 @@ static void GenerateBuildList(Window *w) EngList_Sort(&bv->eng_list, _sorter[bv->vehicle_type][bv->sort_criteria]); } -static void DrawVehicleEngine(byte type, int x, int y, EngineID engine, SpriteID pal) +static void DrawVehicleEngine(VehicleType type, int x, int y, EngineID engine, SpriteID pal) { switch (type) { case VEH_TRAIN: DrawTrainEngine( x, y, engine, pal); break; diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index 97ca253d7..98097817c 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -519,9 +519,11 @@ static void ResizeDepotButtons(Window *w) * Only use this if it's the same widget, that's used for more than one vehicle type and it needs different text/sprites * Vehicle specific text/sprites, that's in a widget, that's only shown for one vehicle type (like sell whole train) is set in the widget array */ -static void SetupStringsForDepotWindow(Window *w, byte type) +static void SetupStringsForDepotWindow(Window *w, VehicleType type) { switch (type) { + default: NOT_REACHED(); + case VEH_TRAIN: w->widget[DEPOT_WIDGET_CAPTION].data = STR_8800_TRAIN_DEPOT; w->widget[DEPOT_WIDGET_STOP_ALL].tooltips = STR_MASS_STOP_DEPOT_TRAIN_TIP; diff --git a/src/engine.cpp b/src/engine.cpp index 9ef09432d..c6b776667 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -403,22 +403,19 @@ CommandCost CmdRenameEngine(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) } -/* - * returns true if an engine is valid, of the specified type, and buildable by - * the given player, false otherwise - * - * engine = index of the engine to check - * type = the type the engine should be of (VEH_xxx) - * player = index of the player +/** Check if an engine is buildable. + * @param engine index of the engine to check. + * @param type the type the engine should be. + * @param player index of the player. + * @return True if an engine is valid, of the specified type, and buildable by + * the given player. */ -bool IsEngineBuildable(EngineID engine, byte type, PlayerID player) +bool IsEngineBuildable(EngineID engine, VehicleType type, PlayerID player) { - const Engine *e; - /* check if it's an engine that is in the engine array */ if (!IsEngineIndex(engine)) return false; - e = GetEngine(engine); + const Engine *e = GetEngine(engine); /* check if it's an engine of specified type */ if (e->type != type) return false; diff --git a/src/engine.h b/src/engine.h index 38f824522..66eb97b17 100644 --- a/src/engine.h +++ b/src/engine.h @@ -168,7 +168,7 @@ void DrawAircraftEngine(int x, int y, EngineID engine, SpriteID pal); void LoadCustomEngineNames(); void DeleteCustomEngineNames(); -bool IsEngineBuildable(EngineID engine, byte type, PlayerID player); +bool IsEngineBuildable(EngineID engine, VehicleType type, PlayerID player); CargoID GetEngineCargoType(EngineID engine); enum { @@ -185,14 +185,14 @@ enum { ROAD_ENGINES_INDEX = NUM_TRAIN_ENGINES, }; -static inline EngineID GetFirstEngineOfType(byte type) +static inline EngineID GetFirstEngineOfType(VehicleType type) { const EngineID start[] = {0, ROAD_ENGINES_INDEX, SHIP_ENGINES_INDEX, AIRCRAFT_ENGINES_INDEX}; return start[type]; } -static inline EngineID GetLastEngineOfType(byte type) +static inline EngineID GetLastEngineOfType(VehicleType type) { const EngineID end[] = { NUM_TRAIN_ENGINES, -- cgit v1.2.3-70-g09d2