summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-05-18 17:31:41 +0000
committerrubidium <rubidium@openttd.org>2007-05-18 17:31:41 +0000
commitba24c34f8558369cc0802c92963b40ff5c7b0bc2 (patch)
tree3eac526253ee6111911b7ea868ca46065b6d5889
parent2196abd71d687564597a0d4f6f9defc8679ba87b (diff)
downloadopenttd-ba24c34f8558369cc0802c92963b40ff5c7b0bc2.tar.xz
(svn r9869) -Codechange: replace some bytes with VehicleType, i.e. more type strictness.
-rw-r--r--src/autoreplace_gui.cpp8
-rw-r--r--src/build_vehicle_gui.cpp10
-rw-r--r--src/depot.cpp1
-rw-r--r--src/depot.h2
-rw-r--r--src/depot_gui.cpp6
-rw-r--r--src/engine.h4
-rw-r--r--src/newgrf.cpp2
-rw-r--r--src/order_cmd.cpp2
-rw-r--r--src/vehicle.cpp1
-rw-r--r--src/vehicle_gui.cpp12
-rw-r--r--src/vehicle_gui.h12
-rw-r--r--src/window.h5
-rw-r--r--src/yapf/yapf.hpp2
13 files changed, 39 insertions, 28 deletions
diff --git a/src/autoreplace_gui.cpp b/src/autoreplace_gui.cpp
index 2915f8476..03c1610e8 100644
--- a/src/autoreplace_gui.cpp
+++ b/src/autoreplace_gui.cpp
@@ -62,7 +62,7 @@ void InvalidateAutoreplaceWindow(EngineID e)
/** 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 @@ static void GenerateLists(Window *w)
}
-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 @@ static void ReplaceVehicleWndProc(Window *w, WindowEvent *e)
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 @@ static const WindowDesc _replace_ship_aircraft_vehicle_desc = {
};
-void ShowReplaceVehicleWindow(byte vehicletype)
+void ShowReplaceVehicleWindow(VehicleType vehicletype)
{
Window *w;
diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp
index c7fb5f30e..33a08f40c 100644
--- a/src/build_vehicle_gui.cpp
+++ b/src/build_vehicle_gui.cpp
@@ -543,6 +543,7 @@ int DrawVehiclePurchaseInfo(int x, int y, uint w, EngineID engine_number)
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 @@ static void GenerateBuildList(Window *w)
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 @@ static void DrawVehicleEngine(byte type, int x, int y, EngineID engine, SpriteID
* @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 @@ static void BuildVehicleClickEvent(Window *w, WindowEvent *e)
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 @@ static void BuildVehicleClickEvent(Window *w, WindowEvent *e)
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 @@ static void NewVehicleWndProc(Window *w, WindowEvent *e)
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 @@ static const WindowDesc _build_vehicle_desc = {
NewVehicleWndProc
};
-void ShowBuildVehicleWindow(TileIndex tile, byte type)
+void ShowBuildVehicleWindow(TileIndex tile, VehicleType type)
{
buildvehicle_d *bv;
Window *w;
@@ -1006,6 +1011,7 @@ void ShowBuildVehicleWindow(TileIndex tile, byte type)
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);
diff --git a/src/depot.cpp b/src/depot.cpp
index 2267e362e..3789c0edd 100644
--- 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"
diff --git a/src/depot.h b/src/depot.h
index 49ed1465e..300423ad7 100644
--- a/src/depot.h
+++ b/src/depot.h
@@ -42,7 +42,7 @@ static inline void DeleteDepot(Depot *depot)
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)
diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp
index d0fa558b0..8aea0298c 100644
--- a/src/depot_gui.cpp
+++ b/src/depot_gui.cpp
@@ -657,7 +657,7 @@ static void ResizeDefaultWindowSizeForRoadVehicles()
_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 @@ void InitDepotWindowBlockSizes()
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 @@ static void DepotWndProc(Window *w, WindowEvent *e)
* @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;
diff --git a/src/engine.h b/src/engine.h
index 641299697..c54e3bb10 100644
--- a/src/engine.h
+++ b/src/engine.h
@@ -120,7 +120,7 @@ struct Engine {
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 @@ int32 RemoveEngineReplacement(EngineRenewList* erl, EngineID engine, uint32 flag
/** 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
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index 3dc46fcbf..10326ef7a 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -4550,6 +4550,8 @@ static void CalculateRefitMasks()
/* 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);
diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp
index 912e5b2a8..c7d4f7ab7 100644
--- 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"
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 1b5b720b9..8b626a4d3 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -2443,6 +2443,7 @@ const Livery *GetEngineLivery(EngineID engine_type, PlayerID player, EngineID pa
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);
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index 02f90e70f..f9859e917 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -45,7 +45,7 @@ struct vehiclelist_d {
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 @@ static void CreateVehicleListWindow(Window *w)
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 @@ static const WindowDesc _player_vehicle_list_aircraft_desc = {
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 @@ static void ShowVehicleListWindowLocal(PlayerID player, uint16 VLW_flag, byte ve
}
}
-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 @@ void ShowVehicleListWindow(const Vehicle *v)
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;
diff --git a/src/vehicle_gui.h b/src/vehicle_gui.h
index 602d765c0..2e54de24c 100644
--- a/src/vehicle_gui.h
+++ b/src/vehicle_gui.h
@@ -41,7 +41,7 @@ void DrawRoadVehImage(const Vehicle *v, int x, int y, VehicleID selection);
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 ShowAdditionalText(int x, int y, uint w, EngineID engine);
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 void DrawVehicleImage(const Vehicle *v, int x, int y, int count, i
}
}
-static inline uint GetVehicleListHeight(byte type)
+static inline uint GetVehicleListHeight(VehicleType type)
{
return (type == VEH_TRAIN || type == VEH_ROAD) ? 14 : 24;
}
diff --git a/src/window.h b/src/window.h
index 1f74df9b0..85bb74dac 100644
--- 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 @@ struct tooltips_d {
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 @@ assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(replaceveh_d));
struct depot_d {
VehicleID sel;
- byte type;
+ VehicleType type;
bool generate_list;
uint16 engine_list_length;
uint16 wagon_list_length;
diff --git a/src/yapf/yapf.hpp b/src/yapf/yapf.hpp
index 2756326c8..4faff60b5 100644
--- 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"