changeset 6638:5479975c4e36 draft

(svn r9869) -Codechange: replace some bytes with VehicleType, i.e. more type strictness.
author rubidium <rubidium@openttd.org>
date Fri, 18 May 2007 17:31:41 +0000
parents 7d0d7bde3390
children 0333109c382d
files src/autoreplace_gui.cpp src/build_vehicle_gui.cpp src/depot.cpp src/depot.h src/depot_gui.cpp src/engine.h src/newgrf.cpp src/order_cmd.cpp src/vehicle.cpp src/vehicle_gui.cpp src/vehicle_gui.h src/window.h src/yapf/yapf.hpp
diffstat 13 files changed, 39 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/src/autoreplace_gui.cpp
+++ b/src/autoreplace_gui.cpp
@@ -62,7 +62,7 @@
 /** When an engine is made buildable or is removed from being buildable, add/remove it from the build/autoreplace lists
  * @param type The type of engine
  */
-void AddRemoveEngineFromAutoreplaceAndBuildWindows(byte type)
+void AddRemoveEngineFromAutoreplaceAndBuildWindows(VehicleType type)
 {
 	_rebuild_left_list = false; // left list is only for the vehicles the player owns and is not related to being buildable
 	_rebuild_right_list = true;
@@ -202,7 +202,7 @@
 }
 
 
-void DrawEngineList(byte type, int x, int y, const EngineList eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count);
+void DrawEngineList(VehicleType type, int x, int y, const EngineList eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count);
 
 static void ReplaceVehicleWndProc(Window *w, WindowEvent *e)
 {
@@ -296,7 +296,7 @@
 				EngineID end    = min((i == 0 ? w->vscroll.cap : w->vscroll2.cap) + start, EngList_Count(&list));
 
 				/* Do the actual drawing */
-				DrawEngineList(w->window_number, x, 15, list, start, end, WP(w, replaceveh_d).sel_engine[i], i == 0);
+				DrawEngineList((VehicleType)w->window_number, x, 15, list, start, end, WP(w, replaceveh_d).sel_engine[i], i == 0);
 
 				/* Also draw the details if an engine is selected */
 				if (WP(w, replaceveh_d).sel_engine[i] != INVALID_ENGINE) {
@@ -480,7 +480,7 @@
 };
 
 
-void ShowReplaceVehicleWindow(byte vehicletype)
+void ShowReplaceVehicleWindow(VehicleType vehicletype)
 {
 	Window *w;
 
--- a/src/build_vehicle_gui.cpp
+++ b/src/build_vehicle_gui.cpp
@@ -543,6 +543,7 @@
 	bool refitable = false;
 
 	switch (e->type) {
+		default: NOT_REACHED();
 		case VEH_TRAIN: {
 			const RailVehicleInfo *rvi = RailVehInfo(engine_number);
 			uint capacity = GetEngineProperty(engine_number, 0x14, rvi->capacity);
@@ -720,6 +721,7 @@
 	buildvehicle_d *bv = &WP(w, buildvehicle_d);
 
 	switch (bv->vehicle_type) {
+		default: NOT_REACHED();
 		case VEH_TRAIN:
 			GenerateBuildTrainList(w);
 			return; // trains should not reach the last sorting
@@ -757,7 +759,7 @@
  * @param selected_id what engine to highlight as selected, if any
  * @param show_count Display the number of vehicles (used by autoreplace)
  */
-void DrawEngineList(byte type, int x, int y, const EngineList eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count)
+void DrawEngineList(VehicleType type, int x, int y, const EngineList eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count)
 {
 	byte step_size = GetVehicleListHeight(type);
 	byte x_offset = 0;
@@ -872,6 +874,7 @@
 			EngineID sel_eng = bv->sel_engine;
 			if (sel_eng != INVALID_ENGINE) {
 				switch (bv->vehicle_type) {
+					default: NOT_REACHED();
 					case VEH_TRAIN:
 						DoCommandP(w->window_number, sel_eng, 0, (RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON) ? CcBuildWagon : CcBuildLoco,
 								   CMD_BUILD_RAIL_VEHICLE | CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE));
@@ -897,6 +900,7 @@
 
 				bv->rename_engine = sel_eng;
 				switch (bv->vehicle_type) {
+					default: NOT_REACHED();
 					case VEH_TRAIN:    str = STR_886A_RENAME_TRAIN_VEHICLE_TYPE; break;
 					case VEH_ROAD:     str = STR_9036_RENAME_ROAD_VEHICLE_TYPE;  break;
 					case VEH_SHIP:     str = STR_9838_RENAME_SHIP_TYPE;          break;
@@ -940,6 +944,7 @@
 				StringID str = STR_NULL;
 				_cmd_text = e->we.edittext.str;
 				switch (bv->vehicle_type) {
+					default: NOT_REACHED();
 					case VEH_TRAIN:    str = STR_886B_CAN_T_RENAME_TRAIN_VEHICLE; break;
 					case VEH_ROAD:     str = STR_9037_CAN_T_RENAME_ROAD_VEHICLE;  break;
 					case VEH_SHIP:     str = STR_9839_CAN_T_RENAME_SHIP_TYPE;     break;
@@ -977,7 +982,7 @@
 	NewVehicleWndProc
 };
 
-void ShowBuildVehicleWindow(TileIndex tile, byte type)
+void ShowBuildVehicleWindow(TileIndex tile, VehicleType type)
 {
 	buildvehicle_d *bv;
 	Window *w;
@@ -1006,6 +1011,7 @@
 	bv->descending_sort_order = _last_sort_order[type];
 
 	switch (type) {
+		default: NOT_REACHED();
 		case VEH_TRAIN:
 			WP(w, buildvehicle_d).filter.railtype = (tile == 0) ? RAILTYPE_END : GetRailType(tile);
 			ResizeWindow(w, 0, 16);
--- a/src/depot.cpp
+++ b/src/depot.cpp
@@ -4,6 +4,7 @@
 
 #include "stdafx.h"
 #include "openttd.h"
+#include "vehicle.h"
 #include "depot.h"
 #include "functions.h"
 #include "landscape.h"
--- a/src/depot.h
+++ b/src/depot.h
@@ -42,7 +42,7 @@
 	depot->xy = 0;
 }
 
-void ShowDepotWindow(TileIndex tile, byte type);
+void ShowDepotWindow(TileIndex tile, VehicleType type);
 
 #define FOR_ALL_DEPOTS_FROM(d, start) for (d = GetDepot(start); d != NULL; d = (d->index + 1U < GetDepotPoolSize()) ? GetDepot(d->index + 1U) : NULL) if (IsValidDepot(d))
 #define FOR_ALL_DEPOTS(d) FOR_ALL_DEPOTS_FROM(d, 0)
--- a/src/depot_gui.cpp
+++ b/src/depot_gui.cpp
@@ -657,7 +657,7 @@
 	_block_sizes[VEH_ROAD][1] = GetVehicleListHeight(VEH_ROAD);
 }
 
-static void ResizeDefaultWindowSize(byte type)
+static void ResizeDefaultWindowSize(VehicleType type)
 {
 	EngineID engine;
 	uint max_width  = 0;
@@ -697,7 +697,7 @@
 	ResizeDefaultWindowSize(VEH_AIRCRAFT);
 }
 
-static void CreateDepotListWindow(Window *w, byte type)
+static void CreateDepotListWindow(Window *w, VehicleType type)
 {
 	WP(w, depot_d).type = type;
 	_backup_orders_tile = 0;
@@ -975,7 +975,7 @@
  * @param tile The tile where the depot/hangar is located
  * @param type The type of vehicles in the depot
  */
-void ShowDepotWindow(TileIndex tile, byte type)
+void ShowDepotWindow(TileIndex tile, VehicleType type)
 {
 	Window *w;
 
--- a/src/engine.h
+++ b/src/engine.h
@@ -120,7 +120,7 @@
 	PlayerByte preview_player;
 	byte preview_wait;
 	byte player_avail;
-	byte type; ///< type, ie VEH_ROAD, VEH_TRAIN, etc. Same as in vehicle.h
+	VehicleType type; ///< type, ie VEH_ROAD, VEH_TRAIN, etc. Same as in vehicle.h
 };
 
 /**
@@ -341,7 +341,7 @@
 /** When an engine is made buildable or is removed from being buildable, add/remove it from the build/autoreplace lists
  * @param type The type of engine
  */
-void AddRemoveEngineFromAutoreplaceAndBuildWindows(byte type);
+void AddRemoveEngineFromAutoreplaceAndBuildWindows(VehicleType type);
 
 /* Engine list manipulators - current implementation is only C wrapper of CBlobT<EngineID> class (helpers.cpp) */
 void EngList_Create(EngineList *el);            ///< Creates engine list
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -4550,6 +4550,8 @@
 		/* Check if this engine's cargo type is valid. If not, set to the first refittable
 		 * cargo type. Apparently cargo_type isn't a common property... */
 		switch (GetEngine(engine)->type) {
+			default: NOT_REACHED();
+			case VEH_AIRCRAFT: break;
 			case VEH_TRAIN: {
 				RailVehicleInfo *rvi = &_rail_vehicle_info[engine];
 				if (rvi->cargo_type == CT_INVALID) rvi->cargo_type = FindFirstRefittableCargo(engine);
--- a/src/order_cmd.cpp
+++ b/src/order_cmd.cpp
@@ -6,10 +6,10 @@
 #include "openttd.h"
 #include "order.h"
 #include "airport.h"
+#include "vehicle.h"
 #include "depot.h"
 #include "functions.h"
 #include "table/strings.h"
-#include "vehicle.h"
 #include "waypoint.h"
 #include "command.h"
 #include "station.h"
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -2443,6 +2443,7 @@
 	if (p->livery[LS_DEFAULT].in_use && (_patches.liveries == 2 || (_patches.liveries == 1 && player == _local_player))) {
 		/* Determine the livery scheme to use */
 		switch (GetEngine(engine_type)->type) {
+			default: NOT_REACHED();
 			case VEH_TRAIN: {
 				const RailVehicleInfo *rvi = RailVehInfo(engine_type);
 
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -45,7 +45,7 @@
 	const Vehicle** sort_list;  // List of vehicles (sorted)
 	Listing *_sorting;          // pointer to the appropiate subcategory of _sorting
 	uint16 length_of_sort_list; // Keeps track of how many vehicle pointers sort list got space for
-	byte vehicle_type;          // The vehicle type that is sorted
+	VehicleType vehicle_type;   // The vehicle type that is sorted
 	list_d l;                   // General list struct
 };
 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(vehiclelist_d));
@@ -809,7 +809,7 @@
 	uint16 window_type = w->window_number & VLW_MASK;
 	PlayerID player = (PlayerID)GB(w->window_number, 0, 8);
 
-	vl->vehicle_type = GB(w->window_number, 11, 5);
+	vl->vehicle_type = (VehicleType)GB(w->window_number, 11, 5);
 	vl->length_of_sort_list = 0;
 	vl->sort_list = NULL;
 	w->caption_color = player;
@@ -1236,7 +1236,7 @@
 	PlayerVehWndProc
 };
 
-static void ShowVehicleListWindowLocal(PlayerID player, uint16 VLW_flag, byte vehicle_type, uint16 unique_number)
+static void ShowVehicleListWindowLocal(PlayerID player, uint16 VLW_flag, VehicleType vehicle_type, uint16 unique_number)
 {
 	Window *w;
 	WindowNumber num;
@@ -1273,7 +1273,7 @@
 	}
 }
 
-void ShowVehicleListWindow(PlayerID player, byte vehicle_type)
+void ShowVehicleListWindow(PlayerID player, VehicleType vehicle_type)
 {
 	ShowVehicleListWindowLocal(player, VLW_STANDARD, vehicle_type, 0);
 }
@@ -1284,12 +1284,12 @@
 	ShowVehicleListWindowLocal(v->owner, VLW_SHARED_ORDERS, v->type, v->orders->index);
 }
 
-void ShowVehicleListWindow(PlayerID player, byte vehicle_type, StationID station)
+void ShowVehicleListWindow(PlayerID player, VehicleType vehicle_type, StationID station)
 {
 	ShowVehicleListWindowLocal(player, VLW_STATION_LIST, vehicle_type, station);
 }
 
-void ShowVehicleListWindow(PlayerID player, byte vehicle_type, TileIndex depot_tile)
+void ShowVehicleListWindow(PlayerID player, VehicleType vehicle_type, TileIndex depot_tile)
 {
 	uint16 depot_airport_index;
 
--- a/src/vehicle_gui.h
+++ b/src/vehicle_gui.h
@@ -41,7 +41,7 @@
 void DrawShipImage(const Vehicle *v, int x, int y, VehicleID selection);
 void DrawAircraftImage(const Vehicle *v, int x, int y, VehicleID selection);
 
-void ShowBuildVehicleWindow(TileIndex tile, byte type);
+void ShowBuildVehicleWindow(TileIndex tile, VehicleType type);
 
 void ChangeVehicleViewWindow(const Vehicle *from_v, const Vehicle *to_v);
 
@@ -49,11 +49,11 @@
 uint ShowRefitOptionsList(int x, int y, uint w, EngineID engine);
 
 void ShowVehicleListWindow(const Vehicle *v);
-void ShowVehicleListWindow(PlayerID player, byte vehicle_type);
-void ShowVehicleListWindow(PlayerID player, byte vehicle_type, StationID station);
-void ShowVehicleListWindow(PlayerID player, byte vehicle_type, TileIndex depot_tile);
+void ShowVehicleListWindow(PlayerID player, VehicleType vehicle_type);
+void ShowVehicleListWindow(PlayerID player, VehicleType vehicle_type, StationID station);
+void ShowVehicleListWindow(PlayerID player, VehicleType vehicle_type, TileIndex depot_tile);
 
-void ShowReplaceVehicleWindow(byte vehicletype);
+void ShowReplaceVehicleWindow(VehicleType vehicletype);
 
 static inline void DrawVehicleImage(const Vehicle *v, int x, int y, int count, int skip, VehicleID selection)
 {
@@ -66,7 +66,7 @@
 	}
 }
 
-static inline uint GetVehicleListHeight(byte type)
+static inline uint GetVehicleListHeight(VehicleType type)
 {
 	return (type == VEH_TRAIN || type == VEH_ROAD) ? 14 : 24;
 }
--- a/src/window.h
+++ b/src/window.h
@@ -10,6 +10,7 @@
 #include "order.h"
 #include "rail.h"
 #include "airport.h"
+#include "vehicle.h"
 
 struct WindowEvent;
 
@@ -323,7 +324,7 @@
 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(tooltips_d));
 
 struct buildvehicle_d {
-	byte vehicle_type;
+	VehicleType vehicle_type;
 	union {
 		RailTypeByte railtype;
 		AirportFTAClass::Flags flags;
@@ -352,7 +353,7 @@
 
 struct depot_d {
 	VehicleID sel;
-	byte type;
+	VehicleType type;
 	bool generate_list;
 	uint16 engine_list_length;
 	uint16 wagon_list_length;
--- a/src/yapf/yapf.hpp
+++ b/src/yapf/yapf.hpp
@@ -7,6 +7,7 @@
 
 #include "track_dir.hpp"
 
+#include "../vehicle.h"
 #include "../depot.h"
 #include "../road_map.h"
 #include "../tunnel_map.h"
@@ -14,7 +15,6 @@
 #include "../bridge.h"
 #include "../station.h"
 #include "../station_map.h"
-#include "../vehicle.h"
 #include "../date.h"
 #include "../functions.h"
 #include "../landscape.h"