(svn r9872) -Codechange: more type strictness for vehicle types
authorrubidium
Fri, 18 May 2007 23:38:29 +0000
changeset 7137 94dd139831be
parent 7136 5f788c5c8aad
child 7138 feca3eff4054
(svn r9872) -Codechange: more type strictness for vehicle types
src/vehicle.cpp
src/vehicle.h
--- a/src/vehicle.cpp	Fri May 18 21:50:32 2007 +0000
+++ b/src/vehicle.cpp	Fri May 18 23:38:29 2007 +0000
@@ -1566,7 +1566,7 @@
 	int32 return_value = CMD_ERROR;
 	uint i;
 	uint stop_command;
-	byte vehicle_type = GB(p2, 0, 5);
+	VehicleType vehicle_type = (VehicleType)GB(p2, 0, 5);
 	bool start_stop = HASBIT(p2, 5);
 	bool vehicle_list_window = HASBIT(p2, 6);
 
@@ -1633,7 +1633,7 @@
 
 	int32 cost = 0;
 	uint i, sell_command, total_number_vehicles;
-	byte vehicle_type = GB(p1, 0, 8);
+	VehicleType vehicle_type = (VehicleType)GB(p1, 0, 8);
 
 	switch (vehicle_type) {
 		case VEH_TRAIN:    sell_command = CMD_SELL_RAIL_WAGON; break;
@@ -1682,8 +1682,7 @@
 	uint16 engine_count = 0;
 	uint i, x = 0, y = 0, z = 0;
 	int32 cost = 0;
-	byte vehicle_type = GB(p1, 0, 8);
-
+	VehicleType vehicle_type = (VehicleType)GB(p1, 0, 8);
 
 	if (!IsTileOwner(tile, _current_player)) return CMD_ERROR;
 
@@ -1895,7 +1894,7 @@
  * @param *wagon_list_length Allocated size of wagon_list. Needs to be set to 0 when wagon_list points to a NULL array
  * @param *wagon_count The number of engines stored in the list
  */
-void BuildDepotVehicleList(byte type, TileIndex tile, Vehicle ***engine_list, uint16 *engine_list_length, uint16 *engine_count, Vehicle ***wagon_list, uint16 *wagon_list_length, uint16 *wagon_count)
+void BuildDepotVehicleList(VehicleType type, TileIndex tile, Vehicle ***engine_list, uint16 *engine_list_length, uint16 *engine_count, Vehicle ***wagon_list, uint16 *wagon_list_length, uint16 *wagon_count)
 {
 	Vehicle *v;
 
@@ -1978,7 +1977,7 @@
 * @param window_type tells what kind of window the list is for. Use the VLW flags in vehicle_gui.h
 * @return the number of vehicles added to the list
 */
-uint GenerateVehicleSortList(const Vehicle ***sort_list, uint16 *length_of_array, byte type, PlayerID owner, uint32 index, uint16 window_type)
+uint GenerateVehicleSortList(const Vehicle ***sort_list, uint16 *length_of_array, VehicleType type, PlayerID owner, uint32 index, uint16 window_type)
 {
 	const byte subtype = (type != VEH_AIRCRAFT) ? (byte)Train_Front : (byte)AIR_AIRCRAFT;
 	uint n = 0;
@@ -2075,7 +2074,7 @@
  * @param vlw_flag tells what kind of list requested the goto depot
  * @return 0 for success and CMD_ERROR if no vehicle is able to go to depot
  */
-int32 SendAllVehiclesToDepot(byte type, uint32 flags, bool service, PlayerID owner, uint16 vlw_flag, uint32 id)
+int32 SendAllVehiclesToDepot(VehicleType type, uint32 flags, bool service, PlayerID owner, uint16 vlw_flag, uint32 id)
 {
 	const Vehicle **sort_list = NULL;
 	uint n, i;
@@ -2385,7 +2384,7 @@
 	return _tile_type_procs[GetTileType(tile)]->vehicle_enter_tile_proc(v, tile, x, y);
 }
 
-UnitID GetFreeUnitNumber(byte type)
+UnitID GetFreeUnitNumber(VehicleType type)
 {
 	UnitID unit, max = 0;
 	const Vehicle *u;
--- a/src/vehicle.h	Fri May 18 21:50:32 2007 +0000
+++ b/src/vehicle.h	Fri May 18 23:38:29 2007 +0000
@@ -522,7 +522,7 @@
 
 void ShowAircraftViewWindow(const Vehicle* v);
 
-UnitID GetFreeUnitNumber(byte type);
+UnitID GetFreeUnitNumber(VehicleType type);
 
 void TrainConsistChanged(Vehicle *v);
 void TrainPowerChanged(Vehicle *v);
@@ -532,9 +532,9 @@
 
 bool VehicleNeedsService(const Vehicle *v);
 
-uint GenerateVehicleSortList(const Vehicle*** sort_list, uint16 *length_of_array, byte type, PlayerID owner, uint32 index, uint16 window_type);
-void BuildDepotVehicleList(byte type, TileIndex tile, Vehicle ***engine_list, uint16 *engine_list_length, uint16 *engine_count, Vehicle ***wagon_list, uint16 *wagon_list_length, uint16 *wagon_count);
-int32 SendAllVehiclesToDepot(byte type, uint32 flags, bool service, PlayerID owner, uint16 vlw_flag, uint32 id);
+uint GenerateVehicleSortList(const Vehicle*** sort_list, uint16 *length_of_array, VehicleType type, PlayerID owner, uint32 index, uint16 window_type);
+void BuildDepotVehicleList(VehicleType type, TileIndex tile, Vehicle ***engine_list, uint16 *engine_list_length, uint16 *engine_count, Vehicle ***wagon_list, uint16 *wagon_list_length, uint16 *wagon_count);
+int32 SendAllVehiclesToDepot(VehicleType type, uint32 flags, bool service, PlayerID owner, uint16 vlw_flag, uint32 id);
 bool IsVehicleInDepot(const Vehicle *v);
 void VehicleEnterDepot(Vehicle *v);
 
@@ -610,7 +610,7 @@
 	v = new (v) InvalidVehicle();
 }
 
-static inline bool IsPlayerBuildableVehicleType(byte type)
+static inline bool IsPlayerBuildableVehicleType(VehicleType type)
 {
 	switch (type) {
 		case VEH_TRAIN:
@@ -618,8 +618,9 @@
 		case VEH_SHIP:
 		case VEH_AIRCRAFT:
 			return true;
+
+		default: return false;
 	}
-	return false;
 }
 
 static inline bool IsPlayerBuildableVehicleType(const Vehicle *v)
@@ -715,7 +716,7 @@
 extern const uint32 _send_to_depot_proc_table[];
 
 /* Functions to find the right command for certain vehicle type */
-static inline uint32 GetCmdBuildVeh(byte type)
+static inline uint32 GetCmdBuildVeh(VehicleType type)
 {
 	return _veh_build_proc_table[type];
 }
@@ -725,7 +726,7 @@
 	return GetCmdBuildVeh(v->type);
 }
 
-static inline uint32 GetCmdSellVeh(byte type)
+static inline uint32 GetCmdSellVeh(VehicleType type)
 {
 	return _veh_sell_proc_table[type];
 }
@@ -735,7 +736,7 @@
 	return GetCmdSellVeh(v->type);
 }
 
-static inline uint32 GetCmdRefitVeh(byte type)
+static inline uint32 GetCmdRefitVeh(VehicleType type)
 {
 	return _veh_refit_proc_table[type];
 }
@@ -745,7 +746,7 @@
 	return GetCmdRefitVeh(v->type);
 }
 
-static inline uint32 GetCmdSendToDepot(byte type)
+static inline uint32 GetCmdSendToDepot(VehicleType type)
 {
 	return _send_to_depot_proc_table[type];
 }