summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2005-11-15 09:47:25 +0000
committertron <tron@openttd.org>2005-11-15 09:47:25 +0000
commit24f857ed5edab0bf79b1f0f2c18b9a6280103ffb (patch)
treed754a4bbb7a3e5f12b31a28e64345ca8be3cdd20
parent9f8c5d8fd268cc6007047025650951a546133ce1 (diff)
downloadopenttd-24f857ed5edab0bf79b1f0f2c18b9a6280103ffb.tar.xz
(svn r3187) Simplify overly complicated ifs, especially if (foo) return false; else return true; is confusing
-rw-r--r--command.c9
-rw-r--r--gfx.c7
-rw-r--r--newgrf.c20
-rw-r--r--order_cmd.c8
-rw-r--r--rail_cmd.c28
5 files changed, 17 insertions, 55 deletions
diff --git a/command.c b/command.c
index 3a929c941..02569d01d 100644
--- a/command.c
+++ b/command.c
@@ -309,12 +309,11 @@ static const Command _command_proc_table[] = {
/* This function range-checks a cmd, and checks if the cmd is not NULL */
bool IsValidCommand(uint cmd)
{
- cmd = cmd & 0xFF;
+ cmd &= 0xFF;
- if (cmd >= lengthof(_command_proc_table) || _command_proc_table[cmd].proc == NULL)
- return false;
-
- return true;
+ return
+ cmd < lengthof(_command_proc_table) &&
+ _command_proc_table[cmd].proc != NULL;
}
byte GetCommandFlags(uint cmd) {return _command_proc_table[cmd & 0xFF].flags;}
diff --git a/gfx.c b/gfx.c
index c8c6d6845..32ecca3ae 100644
--- a/gfx.c
+++ b/gfx.c
@@ -1970,10 +1970,9 @@ void SetAnimatedMouseCursor(const CursorID *table)
bool ChangeResInGame(int w, int h)
{
- if ((_screen.width != w || _screen.height != h) && !_video_driver->change_resolution(w, h))
- return false;
-
- return true;
+ return
+ (_screen.width == w && _screen.height == h) ||
+ _video_driver->change_resolution(w, h);
}
void ToggleFullScreen(bool fs) {_video_driver->toggle_fullscreen(fs);}
diff --git a/newgrf.c b/newgrf.c
index aa4ddfc07..5396ef323 100644
--- a/newgrf.c
+++ b/newgrf.c
@@ -2572,24 +2572,14 @@ static void DecodeSpecialSprite(const char* filename, uint num, uint stage)
if (action >= lengthof(handlers)) {
DEBUG(grf, 7) ("Skipping unknown action 0x%02X", action);
- free(buf);
- return;
- }
-
- if (!HASBIT(action_mask, action)) {
+ } else if (!HASBIT(action_mask, action)) {
DEBUG(grf, 7) ("Skipping action 0x%02X in stage %d", action, stage);
- free(buf);
- return;
- }
-
- if (handlers[action] == NULL) {
+ } else if (handlers[action] == NULL) {
DEBUG(grf, 7) ("Skipping unsupported Action 0x%02X", action);
- free(buf);
- return;
+ } else {
+ DEBUG(grf, 7) ("Handling action 0x%02X in stage %d", action, stage);
+ handlers[action](buf, num);
}
-
- DEBUG(grf, 7) ("Handling action 0x%02X in stage %d", action, stage);
- handlers[action](buf, num);
free(buf);
}
diff --git a/order_cmd.c b/order_cmd.c
index 38515d80b..6e8f176ca 100644
--- a/order_cmd.c
+++ b/order_cmd.c
@@ -1077,13 +1077,7 @@ void DeleteVehicleOrders(Vehicle *v)
*/
bool IsOrderListShared(const Vehicle *v)
{
- if (v->next_shared != NULL)
- return true;
-
- if (v->prev_shared != NULL)
- return true;
-
- return false;
+ return v->next_shared != NULL || v->prev_shared != NULL;
}
/**
diff --git a/rail_cmd.c b/rail_cmd.c
index 45021856a..6cc2e1dfd 100644
--- a/rail_cmd.c
+++ b/rail_cmd.c
@@ -1225,12 +1225,7 @@ static uint32 _drawtile_track_palette;
static void DrawTrackFence_NW(const TileInfo *ti)
{
uint32 image = 0x515;
- if (ti->tileh != 0) {
- image = 0x519;
- if (!(ti->tileh & 2)) {
- image = 0x51B;
- }
- }
+ if (ti->tileh != 0) image = (ti->tileh & 2) ? 0x519 : 0x51B;
AddSortableSpriteToDraw(image | _drawtile_track_palette,
ti->x, ti->y+1, 16, 1, 4, ti->z);
}
@@ -1238,12 +1233,7 @@ static void DrawTrackFence_NW(const TileInfo *ti)
static void DrawTrackFence_SE(const TileInfo *ti)
{
uint32 image = 0x515;
- if (ti->tileh != 0) {
- image = 0x519;
- if (!(ti->tileh & 2)) {
- image = 0x51B;
- }
- }
+ if (ti->tileh != 0) image = (ti->tileh & 2) ? 0x519 : 0x51B;
AddSortableSpriteToDraw(image | _drawtile_track_palette,
ti->x, ti->y+15, 16, 1, 4, ti->z);
}
@@ -1257,12 +1247,7 @@ static void DrawTrackFence_NW_SE(const TileInfo *ti)
static void DrawTrackFence_NE(const TileInfo *ti)
{
uint32 image = 0x516;
- if (ti->tileh != 0) {
- image = 0x51A;
- if (!(ti->tileh & 2)) {
- image = 0x51C;
- }
- }
+ if (ti->tileh != 0) image = (ti->tileh & 2) ? 0x51A : 0x51C;
AddSortableSpriteToDraw(image | _drawtile_track_palette,
ti->x+1, ti->y, 1, 16, 4, ti->z);
}
@@ -1270,12 +1255,7 @@ static void DrawTrackFence_NE(const TileInfo *ti)
static void DrawTrackFence_SW(const TileInfo *ti)
{
uint32 image = 0x516;
- if (ti->tileh != 0) {
- image = 0x51A;
- if (!(ti->tileh & 2)) {
- image = 0x51C;
- }
- }
+ if (ti->tileh != 0) image = (ti->tileh & 2) ? 0x51A : 0x51C;
AddSortableSpriteToDraw(image | _drawtile_track_palette,
ti->x+15, ti->y, 1, 16, 4, ti->z);
}