summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2005-11-13 14:54:09 +0000
committertron <tron@openttd.org>2005-11-13 14:54:09 +0000
commit4a14a586e2f457d38e9fede1a494478105a8acfd (patch)
tree0bcf189f35802c7769cd23e20ed58a18b59d9b2e
parentee15e3de13643b2d09abcc5424bf8e2d916cff75 (diff)
downloadopenttd-4a14a586e2f457d38e9fede1a494478105a8acfd.tar.xz
(svn r3173) Use the trinary operator and switch to improve readability
Also align short cases nicely
-rw-r--r--airport_gui.c23
-rw-r--r--dock_gui.c7
-rw-r--r--gfx.c23
-rw-r--r--intro_gui.c23
-rw-r--r--main_gui.c143
-rw-r--r--misc_gui.c82
-rw-r--r--openttd.c11
-rw-r--r--order_gui.c52
-rw-r--r--player_gui.c23
-rw-r--r--rail_cmd.c27
-rw-r--r--road_gui.c25
-rw-r--r--settings_gui.c44
-rw-r--r--station_cmd.c39
-rw-r--r--vehicle.c14
-rw-r--r--window.c8
15 files changed, 237 insertions, 307 deletions
diff --git a/airport_gui.c b/airport_gui.c
index e219df930..a4c072b97 100644
--- a/airport_gui.c
+++ b/airport_gui.c
@@ -80,8 +80,7 @@ static void BuildAirToolbWndProc(Window *w, WindowEvent *e)
case '1': BuildAirClick_Airport(w); break;
case '2': BuildAirClick_Demolish(w); break;
case 'l': BuildAirClick_Landscaping(w); break;
- default:
- return;
+ default: return;
}
} break;
@@ -167,16 +166,16 @@ static void BuildAirportPickerWndProc(Window *w, WindowEvent *e)
w->click_state = ((1<<3) << sel) | ((1<<8) << _station_show_coverage);
SetTileSelectSize(_airport_size_x[sel],_airport_size_y[sel]);
- if (_patches.modified_catchment) {
- switch (sel) {
- case AT_OILRIG: rad = CA_AIR_OILPAD; break;
- case AT_HELIPORT: rad = CA_AIR_HELIPORT; break;
- case AT_SMALL: rad = CA_AIR_SMALL; break;
- case AT_LARGE: rad = CA_AIR_LARGE; break;
- case AT_METROPOLITAN: rad = CA_AIR_METRO; break;
- case AT_INTERNATIONAL: rad = CA_AIR_INTER; break;
- }
- }
+ if (_patches.modified_catchment) {
+ switch (sel) {
+ case AT_OILRIG: rad = CA_AIR_OILPAD; break;
+ case AT_HELIPORT: rad = CA_AIR_HELIPORT; break;
+ case AT_SMALL: rad = CA_AIR_SMALL; break;
+ case AT_LARGE: rad = CA_AIR_LARGE; break;
+ case AT_METROPOLITAN: rad = CA_AIR_METRO; break;
+ case AT_INTERNATIONAL: rad = CA_AIR_INTER; break;
+ }
+ }
if (_station_show_coverage) SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
diff --git a/dock_gui.c b/dock_gui.c
index 12d07606b..a1e14b726 100644
--- a/dock_gui.c
+++ b/dock_gui.c
@@ -230,11 +230,8 @@ static void BuildDockStationWndProc(Window *w, WindowEvent *e)
return;
w->click_state = (1<<3) << _station_show_coverage;
DrawWindowWidgets(w);
- if (_patches.modified_catchment) {
- rad = CA_DOCK;
- } else {
- rad = 4;
- }
+
+ rad = (_patches.modified_catchment) ? CA_DOCK : 4;
if (_station_show_coverage) SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
else SetTileSelectBigSize(0, 0, 0, 0);
diff --git a/gfx.c b/gfx.c
index c26e4b536..670e62c9f 100644
--- a/gfx.c
+++ b/gfx.c
@@ -434,7 +434,7 @@ void DrawStringMultiCenter(int x, int y, uint16 str, int maxw)
{
char buffer[512];
uint32 tmp;
- int num, w, mt, t;
+ int num, w, mt;
const char *src;
byte c;
@@ -442,12 +442,11 @@ void DrawStringMultiCenter(int x, int y, uint16 str, int maxw)
tmp = FormatStringLinebreaks(buffer, maxw);
num = (uint16)tmp;
- t = tmp >> 16;
- mt = 10;
- if (t != 0) {
- mt = 6;
- if (t != 244) mt = 18;
+ switch (GB(tmp, 16, 16)) {
+ case 0: mt = 10; break;
+ case 244: mt = 6; break;
+ default: mt = 18; break;
}
y -= (mt >> 1) * num;
@@ -481,7 +480,7 @@ void DrawStringMultiLine(int x, int y, uint16 str, int maxw)
{
char buffer[512];
uint32 tmp;
- int num, w, mt, t;
+ int num, w, mt;
const char *src;
byte c;
@@ -489,11 +488,11 @@ void DrawStringMultiLine(int x, int y, uint16 str, int maxw)
tmp = FormatStringLinebreaks(buffer, maxw);
num = (uint16)tmp;
- t = tmp >> 16;
- mt = 10;
- if (t != 0) {
- mt = 6;
- if (t != 244) mt = 18;
+
+ switch (GB(tmp, 16, 16)) {
+ case 0: mt = 10; break;
+ case 244: mt = 6; break;
+ default: mt = 18; break;
}
src = buffer;
diff --git a/intro_gui.c b/intro_gui.c
index 299393f2d..08a7fdbfe 100644
--- a/intro_gui.c
+++ b/intro_gui.c
@@ -107,8 +107,8 @@ static void SelectGameWndProc(Window *w, WindowEvent *e)
case WE_DROPDOWN_SELECT: /* Mapsize selection */
switch (e->dropdown.button) {
- case 11: _patches.map_x = e->dropdown.index + 6; break;
- case 13: _patches.map_y = e->dropdown.index + 6; break;
+ case 11: _patches.map_x = e->dropdown.index + 6; break;
+ case 13: _patches.map_y = e->dropdown.index + 6; break;
}
SetWindowDirty(w);
break;
@@ -177,18 +177,19 @@ static void AskAbandonGameWndProc(Window *w, WindowEvent *e) {
return;
case WE_CLICK:
- switch(e->click.widget) {
- case 3:
- DeleteWindow(w);
- break;
- case 4:
- _exit_game = true;
- break;
+ switch (e->click.widget) {
+ case 3: DeleteWindow(w); break;
+ case 4: _exit_game = true; break;
}
break;
+
case WE_KEYPRESS: /* Exit game on pressing 'Enter' */
- if (e->keypress.keycode == WKC_RETURN || e->keypress.keycode == WKC_NUM_ENTER)
- _exit_game = true;
+ switch (e->keypress.keycode) {
+ case WKC_RETURN:
+ case WKC_NUM_ENTER:
+ _exit_game = true;
+ break;
+ }
break;
}
}
diff --git a/main_gui.c b/main_gui.c
index 2a0b1bd08..2b6a38e64 100644
--- a/main_gui.c
+++ b/main_gui.c
@@ -169,64 +169,49 @@ typedef void MenuClickedProc(int index);
static void MenuClickSettings(int index)
{
- switch(index) {
- case 0: ShowGameOptions(); return;
- case 1: ShowGameDifficulty(); return;
- case 2: ShowPatchesSelection(); return;
- case 3: ShowNewgrf(); return;
-
- case 5: _display_opt ^= DO_SHOW_TOWN_NAMES; MarkWholeScreenDirty(); return;
- case 6: _display_opt ^= DO_SHOW_STATION_NAMES; MarkWholeScreenDirty(); return;
- case 7: _display_opt ^= DO_SHOW_SIGNS; MarkWholeScreenDirty(); return;
- case 8: _display_opt ^= DO_WAYPOINTS; MarkWholeScreenDirty(); return;
- case 9: _display_opt ^= DO_FULL_ANIMATION; MarkWholeScreenDirty(); return;
- case 10: _display_opt ^= DO_FULL_DETAIL; MarkWholeScreenDirty(); return;
- case 11: _display_opt ^= DO_TRANS_BUILDINGS; MarkWholeScreenDirty(); return;
- case 12: _display_opt ^= DO_TRANS_SIGNS; MarkWholeScreenDirty(); return;
+ switch (index) {
+ case 0: ShowGameOptions(); return;
+ case 1: ShowGameDifficulty(); return;
+ case 2: ShowPatchesSelection(); return;
+ case 3: ShowNewgrf(); return;
+
+ case 5: _display_opt ^= DO_SHOW_TOWN_NAMES; break;
+ case 6: _display_opt ^= DO_SHOW_STATION_NAMES; break;
+ case 7: _display_opt ^= DO_SHOW_SIGNS; break;
+ case 8: _display_opt ^= DO_WAYPOINTS; break;
+ case 9: _display_opt ^= DO_FULL_ANIMATION; break;
+ case 10: _display_opt ^= DO_FULL_DETAIL; break;
+ case 11: _display_opt ^= DO_TRANS_BUILDINGS; break;
+ case 12: _display_opt ^= DO_TRANS_SIGNS; break;
}
+ MarkWholeScreenDirty();
}
static void MenuClickSaveLoad(int index)
{
if (_game_mode == GM_EDITOR) {
- switch(index) {
- case 0:
- ShowSaveLoadDialog(SLD_SAVE_SCENARIO);
- break;
- case 1:
- ShowSaveLoadDialog(SLD_LOAD_SCENARIO);
- break;
- case 2:
- AskExitToGameMenu();
- break;
- case 4:
- AskExitGame();
- break;
+ switch (index) {
+ case 0: ShowSaveLoadDialog(SLD_SAVE_SCENARIO); break;
+ case 1: ShowSaveLoadDialog(SLD_LOAD_SCENARIO); break;
+ case 2: AskExitToGameMenu(); break;
+ case 4: AskExitGame(); break;
}
} else {
- switch(index) {
- case 0:
- ShowSaveLoadDialog(SLD_SAVE_GAME);
- break;
- case 1:
- ShowSaveLoadDialog(SLD_LOAD_GAME);
- break;
- case 2:
- AskExitToGameMenu();
- break;
- case 3:
- AskExitGame();
- break;
+ switch (index) {
+ case 0: ShowSaveLoadDialog(SLD_SAVE_GAME); break;
+ case 1: ShowSaveLoadDialog(SLD_LOAD_GAME); break;
+ case 2: AskExitToGameMenu(); break;
+ case 3: AskExitGame(); break;
}
}
}
static void MenuClickMap(int index)
{
- switch(index) {
- case 0: ShowSmallMap(); break;
- case 1: ShowExtraViewPortWindow(); break;
- case 2: ShowSignList(); break;
+ switch (index) {
+ case 0: ShowSmallMap(); break;
+ case 1: ShowExtraViewPortWindow(); break;
+ case 2: ShowSignList(); break;
}
}
@@ -237,11 +222,11 @@ static void MenuClickTown(int index)
static void MenuClickScenMap(int index)
{
- switch(index) {
- case 0: ShowSmallMap(); break;
- case 1: ShowExtraViewPortWindow(); break;
- case 2: ShowSignList(); break;
- case 3: ShowTownDirectory(); break;
+ switch (index) {
+ case 0: ShowSmallMap(); break;
+ case 1: ShowExtraViewPortWindow(); break;
+ case 2: ShowSignList(); break;
+ case 3: ShowTownDirectory(); break;
}
}
@@ -279,29 +264,29 @@ static void MenuClickCompany(int index)
static void MenuClickGraphs(int index)
{
- switch(index) {
- case 0: ShowOperatingProfitGraph(); return;
- case 1: ShowIncomeGraph(); return;
- case 2: ShowDeliveredCargoGraph(); return;
- case 3: ShowPerformanceHistoryGraph(); return;
- case 4: ShowCompanyValueGraph(); return;
- case 5: ShowCargoPaymentRates(); return;
+ switch (index) {
+ case 0: ShowOperatingProfitGraph(); break;
+ case 1: ShowIncomeGraph(); break;
+ case 2: ShowDeliveredCargoGraph(); break;
+ case 3: ShowPerformanceHistoryGraph(); break;
+ case 4: ShowCompanyValueGraph(); break;
+ case 5: ShowCargoPaymentRates(); break;
}
}
static void MenuClickLeague(int index)
{
- switch(index) {
- case 0: ShowCompanyLeagueTable(); return;
- case 1: ShowPerformanceRatingDetail(); return;
+ switch (index) {
+ case 0: ShowCompanyLeagueTable(); break;
+ case 1: ShowPerformanceRatingDetail(); break;
}
}
static void MenuClickIndustry(int index)
{
- switch(index) {
- case 0: ShowIndustryDirectory(); break;
- case 1: ShowBuildIndustryWindow(); break;
+ switch (index) {
+ case 0: ShowIndustryDirectory(); break;
+ case 1: ShowBuildIndustryWindow(); break;
}
}
@@ -414,10 +399,10 @@ static void SelectSignTool(void)
static void MenuClickForest(int index)
{
- switch(index) {
- case 0: ShowTerraformToolbar(); break;
- case 1: ShowBuildTreesToolbar(); break;
- case 2: SelectSignTool(); break;
+ switch (index) {
+ case 0: ShowTerraformToolbar(); break;
+ case 1: ShowBuildTreesToolbar(); break;
+ case 2: SelectSignTool(); break;
}
}
@@ -428,21 +413,21 @@ static void MenuClickMusicWindow(int index)
static void MenuClickNewspaper(int index)
{
- switch(index) {
- case 0: ShowLastNewsMessage(); break;
- case 1: ShowMessageOptions(); break;
- case 2: ShowMessageHistory(); break;
+ switch (index) {
+ case 0: ShowLastNewsMessage(); break;
+ case 1: ShowMessageOptions(); break;
+ case 2: ShowMessageHistory(); break;
}
}
static void MenuClickHelp(int index)
{
switch (index) {
- case 0: PlaceLandBlockInfo(); break;
- case 2: IConsoleSwitch(); break;
- case 3: _make_screenshot = 1; break;
- case 4: _make_screenshot = 2; break;
- case 5: ShowAboutWindow(); break;
+ case 0: PlaceLandBlockInfo(); break;
+ case 2: IConsoleSwitch(); break;
+ case 3: _make_screenshot = 1; break;
+ case 4: _make_screenshot = 2; break;
+ case 5: ShowAboutWindow(); break;
}
}
@@ -863,10 +848,10 @@ bool DoZoomInOutWindow(int how, Window *w)
ViewPort *vp;
int button;
- switch(_game_mode) {
- case GM_EDITOR: button = 9; break;
- case GM_NORMAL: button = 17; break;
- default: return false;
+ switch (_game_mode) {
+ case GM_EDITOR: button = 9; break;
+ case GM_NORMAL: button = 17; break;
+ default: return false;
}
assert(w);
diff --git a/misc_gui.c b/misc_gui.c
index c349dbd46..c40f3bc3f 100644
--- a/misc_gui.c
+++ b/misc_gui.c
@@ -142,10 +142,7 @@ static void Place_LandInfo(TileIndex tile)
lid.tile = tile;
lid.town = ClosestTownFromTile(tile, _patches.dist_local_authority);
- if (_local_player >= MAX_PLAYERS)
- p = GetPlayer(0);
- else
- p = GetPlayer(_local_player);
+ p = GetPlayer(_local_player < MAX_PLAYERS ? _local_player : 0);
old_money = p->money64;
p->money64 = p->player_money = 0x7fffffff;
@@ -1199,22 +1196,21 @@ static void DrawFiosTexts(uint maxw)
static void MakeSortedSaveGameList(void)
{
+ uint sort_start = 0;
+ uint sort_end = 0;
+ uint s_amount;
+ int i;
+
/* Directories are always above the files (FIOS_TYPE_DIR)
* Drives (A:\ (windows only) are always under the files (FIOS_TYPE_DRIVE)
* Only sort savegames/scenarios, not directories
*/
-
- int i, sort_start, sort_end, s_amount;
- i = sort_start = sort_end = 0;
-
- while (i < _fios_num) {
- if (_fios_list[i].type == FIOS_TYPE_DIR || _fios_list[i].type == FIOS_TYPE_PARENT)
- sort_start++;
-
- if (_fios_list[i].type == FIOS_TYPE_DRIVE)
- sort_end++;
-
- i++;
+ for (i = 0; i < _fios_num; i++) {
+ switch (_fios_list[i].type) {
+ case FIOS_TYPE_DIR: sort_start++; break;
+ case FIOS_TYPE_PARENT: sort_start++; break;
+ case FIOS_TYPE_DRIVE: sort_end++; break;
+ }
}
s_amount = _fios_num - sort_start - sort_end;
@@ -1224,13 +1220,9 @@ static void MakeSortedSaveGameList(void)
static void GenerateFileName(void)
{
- const Player *p;
/* Check if we are not a specatator who wants to generate a name..
Let's use the name of player #0 for now. */
- if (_local_player < MAX_PLAYERS)
- p = GetPlayer(_local_player);
- else
- p = GetPlayer(0);
+ const Player* p = GetPlayer(_local_player < MAX_PLAYERS ? _local_player : 0);
SetDParam(0, p->name_1);
SetDParam(1, p->name_2);
@@ -1464,12 +1456,8 @@ void ShowSaveLoadDialog(int mode)
SETBIT(_no_scroll, SCROLL_SAVE);
switch (mode) {
- case SLD_SAVE_GAME:
- GenerateFileName();
- break;
- case SLD_SAVE_SCENARIO:
- strcpy(_edit_str_buf, "UNNAMED");
- break;
+ case SLD_SAVE_GAME: GenerateFileName(); break;
+ case SLD_SAVE_SCENARIO: strcpy(_edit_str_buf, "UNNAMED"); break;
}
w = AllocateWindowDesc(_saveload_dialogs[mode]);
@@ -1716,18 +1704,17 @@ typedef struct CheatEntry {
uint16 step; // step for spinbox
} CheatEntry;
-static int32 ReadCE(const CheatEntry*ce)
+static int32 ReadCE(const CheatEntry* ce)
{
- switch(ce->type) {
- case CE_BOOL: return *(bool*)ce->variable;
- case CE_UINT8: return *(uint8*)ce->variable;
- case CE_INT16: return *(int16*)ce->variable;
- case CE_UINT16: return *(uint16*)ce->variable;
- case CE_INT32: return *(int32*)ce->variable;
- case CE_BYTE: return *(byte*)ce->variable;
- case CE_CLICK: return 0;
- default:
- NOT_REACHED();
+ switch (ce->type) {
+ case CE_BOOL: return *(bool* )ce->variable;
+ case CE_UINT8: return *(uint8* )ce->variable;
+ case CE_INT16: return *(int16* )ce->variable;
+ case CE_UINT16: return *(uint16*)ce->variable;
+ case CE_INT32: return *(int32* )ce->variable;
+ case CE_BYTE: return *(byte* )ce->variable;
+ case CE_CLICK: return 0;
+ default: NOT_REACHED();
}
/* useless, but avoids compiler warning this way */
@@ -1736,16 +1723,15 @@ static int32 ReadCE(const CheatEntry*ce)
static void WriteCE(const CheatEntry *ce, int32 val)
{
- switch(ce->type) {
- case CE_BOOL: *(bool*)ce->variable = (bool)val; break;
- case CE_BYTE: *(byte*)ce->variable = (byte)val; break;
- case CE_UINT8: *(uint8*)ce->variable = (uint8)val; break;
- case CE_INT16: *(int16*)ce->variable = (int16)val; break;
- case CE_UINT16: *(uint16*)ce->variable = (uint16)val; break;
- case CE_INT32: *(int32*)ce->variable = val; break;
- case CE_CLICK: break;
- default:
- NOT_REACHED();
+ switch (ce->type) {
+ case CE_BOOL: *(bool* )ce->variable = (bool )val; break;
+ case CE_BYTE: *(byte* )ce->variable = (byte )val; break;
+ case CE_UINT8: *(uint8* )ce->variable = (uint8 )val; break;
+ case CE_INT16: *(int16* )ce->variable = (int16 )val; break;
+ case CE_UINT16: *(uint16*)ce->variable = (uint16)val; break;
+ case CE_INT32: *(int32* )ce->variable = val; break;
+ case CE_CLICK: break;
+ default: NOT_REACHED();
}
}
diff --git a/openttd.c b/openttd.c
index c591e259e..ede882c11 100644
--- a/openttd.c
+++ b/openttd.c
@@ -707,12 +707,11 @@ bool SafeSaveOrLoad(const char *filename, int mode, int newgm)
_game_mode = newgm;
r = SaveOrLoad(filename, mode);
if (r == SL_REINIT) {
- if (ogm == GM_MENU)
- LoadIntroGame();
- else if (ogm == GM_EDITOR)
- MakeNewEditorWorld();
- else
- MakeNewGame();
+ switch (ogm) {
+ case GM_MENU: LoadIntroGame(); break;
+ case GM_EDITOR: MakeNewEditorWorld(); break;
+ default: MakeNewGame(); break;
+ }
return false;
} else if (r != SL_OK) {
_game_mode = ogm;
diff --git a/order_gui.c b/order_gui.c
index 04c0688ed..e7b1ccba5 100644
--- a/order_gui.c
+++ b/order_gui.c
@@ -127,37 +127,39 @@ static void DrawOrdersWindow(Window *w)
if (i - w->vscroll.pos < w->vscroll.cap) {
SetDParam(1, 6);
- if (order->type == OT_GOTO_STATION) {
- SetDParam(1, StationOrderStrings[order->flags]);
- SetDParam(2, order->station);
- } else if (order->type == OT_GOTO_DEPOT) {
- StringID s = STR_NULL;
-
- if (v->type == VEH_Aircraft) {
- s = STR_GO_TO_AIRPORT_HANGAR;
+ switch (order->type) {
+ case OT_GOTO_STATION:
+ SetDParam(1, StationOrderStrings[order->flags]);
SetDParam(2, order->station);
- } else {
- SetDParam(2, GetDepot(order->station)->town_index);
-
- switch (v->type) {
- case VEH_Train: s = STR_GO_TO_TRAIN_DEPOT; break;
- case VEH_Road: s = STR_9038_GO_TO_ROADVEH_DEPOT; break;
- case VEH_Ship: s = STR_GO_TO_SHIP_DEPOT; break;
- default:
- break;
+ break;
+
+ case OT_GOTO_DEPOT: {
+ StringID s = STR_NULL;
+
+ if (v->type == VEH_Aircraft) {
+ s = STR_GO_TO_AIRPORT_HANGAR;
+ SetDParam(2, order->station);
+ } else {
+ SetDParam(2, GetDepot(order->station)->town_index);
+
+ switch (v->type) {
+ case VEH_Train: s = (order->flags & OF_NON_STOP) ? STR_880F_GO_NON_STOP_TO_TRAIN_DEPOT : STR_GO_TO_TRAIN_DEPOT; break;
+ case VEH_Road: s = STR_9038_GO_TO_ROADVEH_DEPOT; break;
+ case VEH_Ship: s = STR_GO_TO_SHIP_DEPOT; break;
+ default: break;
+ }
}
- if (v->type == VEH_Train && order->flags & OF_NON_STOP) s += 2;
+ if (order->flags & OF_FULL_LOAD) s++; /* service at */
+
SetDParam(1, s);
+ break;
}
- if (order->flags & OF_FULL_LOAD)
- s++; /* service at */
-
- SetDParam(1, s);
- } else if (order->type == OT_GOTO_WAYPOINT) {
- SetDParam(1, (order->flags & OF_NON_STOP) ? STR_GO_NON_STOP_TO_WAYPOINT : STR_GO_TO_WAYPOINT);
- SetDParam(2, order->station);
+ case OT_GOTO_WAYPOINT:
+ SetDParam(1, (order->flags & OF_NON_STOP) ? STR_GO_NON_STOP_TO_WAYPOINT : STR_GO_TO_WAYPOINT);
+ SetDParam(2, order->station);
+ break;
}
color = (i == WP(w,order_d).sel) ? 0xC : 0x10;
diff --git a/player_gui.c b/player_gui.c
index 85cfdf19a..300abd686 100644
--- a/player_gui.c
+++ b/player_gui.c
@@ -422,24 +422,21 @@ static void DrawPlayerVehiclesAmount(PlayerID player)
const int x = 110;
int y = 72;
const Vehicle* v;
- uint train,road,air,ship;
+ uint train = 0;
+ uint road = 0;
+ uint air = 0;
+ uint ship = 0;
DrawString(x, y, STR_7039_VEHICLES, 0);
- train = road = air = ship = 0;
-
FOR_ALL_VEHICLES(v) {
if (v->owner == player) {
- if (v->type == VEH_Train) {
- if (v->subtype == TS_Front_Engine)
- train++;
- } else if (v->type == VEH_Road) {
- road++;
- } else if (v->type == VEH_Aircraft) {
- if (v->subtype <= 2)
- air++;
- } else if (v->type == VEH_Ship) {
- ship++;
+ switch (v->type) {
+ case VEH_Train: if (v->subtype == TS_Front_Engine) train++; break;
+ case VEH_Road: road++; break;
+ case VEH_Aircraft: if (v->subtype <= 2) air++; break;
+ case VEH_Ship: ship++; break;
+ default: break;
}
}
}
diff --git a/rail_cmd.c b/rail_cmd.c
index fe354dc6c..a5c48743d 100644
--- a/rail_cmd.c
+++ b/rail_cmd.c
@@ -2003,21 +2003,20 @@ static void TileLoop_Track(TileIndex tile)
m2 = GB(_m[tile].m2, 0, 4);
- /* special code for alps landscape */
- if (_opt.landscape == LT_HILLY) {
- /* convert into snow? */
- if (GetTileZ(tile) > _opt.snow_line) {
- a2 = RAIL_GROUND_ICE_DESERT;
- goto modify_me;
- }
+ switch (_opt.landscape) {
+ case LT_HILLY:
+ if (GetTileZ(tile) > _opt.snow_line) { /* convert into snow? */
+ a2 = RAIL_GROUND_ICE_DESERT;
+ goto modify_me;
+ }
+ break;
- /* special code for desert landscape */
- } else if (_opt.landscape == LT_DESERT) {
- /* convert into desert? */
- if (GetMapExtraBits(tile) == 1) {
- a2 = RAIL_GROUND_ICE_DESERT;
- goto modify_me;
- }
+ case LT_DESERT:
+ if (GetMapExtraBits(tile) == 1) { /* convert into desert? */
+ a2 = RAIL_GROUND_ICE_DESERT;
+ goto modify_me;
+ }
+ break;
}
// Don't continue tile loop for depots
diff --git a/road_gui.c b/road_gui.c
index 0fc5c383d..facebc49a 100644
--- a/road_gui.c
+++ b/road_gui.c
@@ -202,19 +202,18 @@ static void BuildRoadToolbWndProc(Window *w, WindowEvent *e) {
} break;
case WE_KEYPRESS:
- switch(e->keypress.keycode) {
- case '1': BuildRoadClick_NE(w); break;
- case '2': BuildRoadClick_NW(w); break;
- case '3': BuildRoadClick_Demolish(w); break;
- case '4': BuildRoadClick_Depot(w); break;
- case '5': BuildRoadClick_BusStation(w); break;
- case '6': BuildRoadClick_TruckStation(w); break;
- case 'B': BuildRoadClick_Bridge(w); break;
- case 'T': BuildRoadClick_Tunnel(w); break;
- case 'R': BuildRoadClick_Remove(w); break;
- case 'L': BuildRoadClick_Landscaping(w); break;
- default:
- return;
+ switch (e->keypress.keycode) {
+ case '1': BuildRoadClick_NE(w); break;
+ case '2': BuildRoadClick_NW(w); break;
+ case '3': BuildRoadClick_Demolish(w); break;
+ case '4': BuildRoadClick_Depot(w); break;
+ case '5': BuildRoadClick_BusStation(w); break;
+ case '6': BuildRoadClick_TruckStation(w); break;
+ case 'B': BuildRoadClick_Bridge(w); break;
+ case 'T': BuildRoadClick_Tunnel(w); break;
+ case 'R': BuildRoadClick_Remove(w); break;
+ case 'L': BuildRoadClick_Landscaping(w); break;
+ default: return;
}
MarkTileDirty(_thd.pos.x, _thd.pos.y); // redraw tile selection
e->keypress.cont = false;
diff --git a/settings_gui.c b/settings_gui.c
index c12dd3e0e..4b404992b 100644
--- a/settings_gui.c
+++ b/settings_gui.c
@@ -793,40 +793,28 @@ static int32 ReadPE(const PatchEntry*pe)
return 0;
}
-static void WritePE(const PatchEntry *pe, int32 val)
+static void WritePE(const PatchEntry* p, int32 v)
{
- if ((pe->flags & PF_0ISDIS) && val <= 0) {
- switch (pe->type) {
- case PE_BOOL: case PE_UINT8:
- *(bool*)pe->variable = 0;
- break;
- case PE_INT16: case PE_UINT16:
- *(int16*)pe->variable = 0;
- break;
- case PE_CURRENCY: case PE_INT32:
- *(int32*)pe->variable = 0;
- break;
+ if ((p->flags & PF_0ISDIS) && v <= 0) {
+ switch (p->type) {
+ case PE_BOOL: *(bool* )p->variable = false; break;
+ case PE_UINT8: *(uint8* )p->variable = 0; break;
+ case PE_INT16: *(int16* )p->variable = 0; break;
+ case PE_UINT16: *(uint16*)p->variable = 0; break;
+ case PE_CURRENCY: *(int32* )p->variable = 0; break;
+ case PE_INT32: *(int32* )p->variable = 0; break;
}
return;
}
// "clamp" 'disabled' value to smallest type
- switch (pe->type) {
- case PE_BOOL:
- *(bool*)pe->variable = (bool)val;
- break;
- case PE_UINT8:
- *(uint8*)pe->variable = (uint8)clamp((uint8)val, (uint8)pe->min, (uint8)pe->max);
- break;
- case PE_INT16:
- *(int16*)pe->variable = (int16)clamp((int16)val, (int16)pe->min, (int16)pe->max);
- break;
- case PE_UINT16:
- *(uint16*)pe->variable = (uint16)clamp((uint16)val, (uint16)pe->min, (uint16)pe->max);
- break;
- case PE_CURRENCY: case PE_INT32:
- *(int32*)pe->variable = (int32)clamp((int32)val, (int32)pe->min, (int32)pe->max);
- break;
+ switch (p->type) {
+ case PE_BOOL: *(bool* )p->variable = (v != 0); break;
+ case PE_UINT8: *(uint8* )p->variable = clamp(v, p->min, p->max); break;
+ case PE_INT16: *(int16* )p->variable = clamp(v, p->min, p->max); break;
+ case PE_UINT16: *(uint16*)p->variable = clamp(v, p->min, p->max); break;
+ case PE_CURRENCY: *(int32* )p->variable = clamp(v, p->min, p->max); break;
+ case PE_INT32: *(int32* )p->variable = clamp(v, p->min, p->max); break;
default: NOT_REACHED();
}
}
diff --git a/station_cmd.c b/station_cmd.c
index a2c4acff6..c0a0203df 100644
--- a/station_cmd.c
+++ b/station_cmd.c
@@ -99,10 +99,9 @@ static void InitializeRoadStop(RoadStop *road_stop, RoadStop *previous, TileInde
RoadStop * GetPrimaryRoadStop(const Station *st, RoadStopType type)
{
switch (type) {
- case RS_BUS: return st->bus_stops;
+ case RS_BUS: return st->bus_stops;
case RS_TRUCK: return st->truck_stops;
- default:
- NOT_REACHED();
+ default: NOT_REACHED();
}
return NULL;
@@ -677,11 +676,7 @@ static void UpdateStationAcceptance(Station *st, bool show_msg)
MergePoint(&rect, cur_rs->xy);
}
- if (_patches.modified_catchment) {
- rad = FindCatchmentRadius(st);
- } else {
- rad = 4;
- }
+ rad = (_patches.modified_catchment) ? FindCatchmentRadius(st) : 4;
// And retrieve the acceptance.
if (rect.max_x >= rect.min_x) {
@@ -1242,27 +1237,13 @@ static const RealSpriteGroup *ResolveStationSpriteGroup(const SpriteGroup *spg,
// TTDPatch runs on little-endian arch;
// Variable is 0x70 + offset in the TTD's station structure
switch (dsg->variable - 0x70) {
- case 0x80:
- value = st->facilities;
- break;
- case 0x81:
- value = st->airport_type;
- break;
- case 0x82:
- value = st->truck_stops->status;
- break;
- case 0x83:
- value = st->bus_stops->status;
- break;
- case 0x86:
- value = st->airport_flags & 0xFFFF;
- break;
- case 0x87:
- value = st->airport_flags & 0xFF;
- break;
- case 0x8A:
- value = st->build_date;
- break;
+ case 0x80: value = st->facilities; break;
+ case 0x81: value = st->airport_type; break;
+ case 0x82: value = st->truck_stops->status; break;
+ case 0x83: value = st->bus_stops->status; break;
+ case 0x86: value = st->airport_flags & 0xFFFF; break;
+ case 0x87: value = st->airport_flags & 0xFF; break;
+ case 0x8A: value = st->build_date; break;
}
}
}
diff --git a/vehicle.c b/vehicle.c
index 309a21e08..542d2b99d 100644
--- a/vehicle.c
+++ b/vehicle.c
@@ -109,14 +109,12 @@ bool VehicleNeedsService(const Vehicle *v)
void VehicleInTheWayErrMsg(const Vehicle* v)
{
- StringID id;
-
- (id = STR_8803_TRAIN_IN_THE_WAY,v->type == VEH_Train) ||
- (id = STR_9000_ROAD_VEHICLE_IN_THE_WAY,v->type == VEH_Road) ||
- (id = STR_A015_AIRCRAFT_IN_THE_WAY,v->type == VEH_Aircraft) ||
- (id = STR_980E_SHIP_IN_THE_WAY, true);
-
- _error_message = id;
+ switch (v->type) {
+ case VEH_Train: _error_message = STR_8803_TRAIN_IN_THE_WAY; break;
+ case VEH_Road: _error_message = STR_9000_ROAD_VEHICLE_IN_THE_WAY; break;
+ case VEH_Aircraft: _error_message = STR_A015_AIRCRAFT_IN_THE_WAY; break;
+ default: _error_message = STR_980E_SHIP_IN_THE_WAY; break;
+ }
}
static void *EnsureNoVehicleProc(Vehicle *v, void *data)
diff --git a/window.c b/window.c
index c37e573f8..1830875f3 100644
--- a/window.c
+++ b/window.c
@@ -1462,10 +1462,10 @@ static void MouseLoop(int click, int mousewheel)
if (mousewheel)
DispatchMouseWheelEvent(w, GetWidgetFromPos(w, x - w->left, y - w->top), mousewheel);
- if (click == 1)
- DispatchLeftClickEvent(w, x - w->left, y - w->top);
- else if (click == 2)
- DispatchRightClickEvent(w, x - w->left, y - w->top);
+ switch (click) {
+ case 1: DispatchLeftClickEvent(w, x - w->left, y - w->top); break;
+ case 2: DispatchRightClickEvent(w, x - w->left, y - w->top); break;
+ }
}
}