Mercurial > hg > openttd
changeset 8479:689d2708728a draft
(svn r12054) -Cleanup: Use VehicleType instead of byte for vehicle types...
author | peter1138 <peter1138@openttd.org> |
---|---|
date | Mon, 04 Feb 2008 11:28:12 +0000 |
parents | 963db346bb94 |
children | 82d7ec66e49f |
files | src/autoreplace_gui.cpp src/build_vehicle_gui.cpp src/depot_gui.cpp src/engine.cpp src/engine.h |
diffstat | 5 files changed, 23 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/src/autoreplace_gui.cpp +++ b/src/autoreplace_gui.cpp @@ -80,7 +80,7 @@ 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 @@ { 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];
--- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -81,9 +81,11 @@ }; /* 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 @@ 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 @@ 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 @@ 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 @@ 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;
--- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -519,9 +519,11 @@ * 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;
--- a/src/engine.cpp +++ b/src/engine.cpp @@ -403,22 +403,19 @@ } -/* - * 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;
--- a/src/engine.h +++ b/src/engine.h @@ -168,7 +168,7 @@ 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 @@ 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,