(svn r3187) Simplify overly complicated ifs, especially if (foo) return false; else return true; is confusing

This commit is contained in:
tron 2005-11-15 09:47:25 +00:00
parent 9f8c5d8fd2
commit 24f857ed5e
5 changed files with 17 additions and 55 deletions

View File

@ -309,12 +309,11 @@ static const Command _command_proc_table[] = {
/* This function range-checks a cmd, and checks if the cmd is not NULL */ /* This function range-checks a cmd, and checks if the cmd is not NULL */
bool IsValidCommand(uint cmd) bool IsValidCommand(uint cmd)
{ {
cmd = cmd & 0xFF; cmd &= 0xFF;
if (cmd >= lengthof(_command_proc_table) || _command_proc_table[cmd].proc == NULL) return
return false; cmd < lengthof(_command_proc_table) &&
_command_proc_table[cmd].proc != NULL;
return true;
} }
byte GetCommandFlags(uint cmd) {return _command_proc_table[cmd & 0xFF].flags;} byte GetCommandFlags(uint cmd) {return _command_proc_table[cmd & 0xFF].flags;}

7
gfx.c
View File

@ -1970,10 +1970,9 @@ void SetAnimatedMouseCursor(const CursorID *table)
bool ChangeResInGame(int w, int h) bool ChangeResInGame(int w, int h)
{ {
if ((_screen.width != w || _screen.height != h) && !_video_driver->change_resolution(w, h)) return
return false; (_screen.width == w && _screen.height == h) ||
_video_driver->change_resolution(w, h);
return true;
} }
void ToggleFullScreen(bool fs) {_video_driver->toggle_fullscreen(fs);} void ToggleFullScreen(bool fs) {_video_driver->toggle_fullscreen(fs);}

View File

@ -2572,24 +2572,14 @@ static void DecodeSpecialSprite(const char* filename, uint num, uint stage)
if (action >= lengthof(handlers)) { if (action >= lengthof(handlers)) {
DEBUG(grf, 7) ("Skipping unknown action 0x%02X", action); DEBUG(grf, 7) ("Skipping unknown action 0x%02X", action);
free(buf); } else if (!HASBIT(action_mask, action)) {
return;
}
if (!HASBIT(action_mask, action)) {
DEBUG(grf, 7) ("Skipping action 0x%02X in stage %d", action, stage); DEBUG(grf, 7) ("Skipping action 0x%02X in stage %d", action, stage);
free(buf); } else if (handlers[action] == NULL) {
return;
}
if (handlers[action] == NULL) {
DEBUG(grf, 7) ("Skipping unsupported Action 0x%02X", action); DEBUG(grf, 7) ("Skipping unsupported Action 0x%02X", action);
free(buf); } else {
return; 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); free(buf);
} }

View File

@ -1077,13 +1077,7 @@ void DeleteVehicleOrders(Vehicle *v)
*/ */
bool IsOrderListShared(const Vehicle *v) bool IsOrderListShared(const Vehicle *v)
{ {
if (v->next_shared != NULL) return v->next_shared != NULL || v->prev_shared != NULL;
return true;
if (v->prev_shared != NULL)
return true;
return false;
} }
/** /**

View File

@ -1225,12 +1225,7 @@ static uint32 _drawtile_track_palette;
static void DrawTrackFence_NW(const TileInfo *ti) static void DrawTrackFence_NW(const TileInfo *ti)
{ {
uint32 image = 0x515; uint32 image = 0x515;
if (ti->tileh != 0) { if (ti->tileh != 0) image = (ti->tileh & 2) ? 0x519 : 0x51B;
image = 0x519;
if (!(ti->tileh & 2)) {
image = 0x51B;
}
}
AddSortableSpriteToDraw(image | _drawtile_track_palette, AddSortableSpriteToDraw(image | _drawtile_track_palette,
ti->x, ti->y+1, 16, 1, 4, ti->z); 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) static void DrawTrackFence_SE(const TileInfo *ti)
{ {
uint32 image = 0x515; uint32 image = 0x515;
if (ti->tileh != 0) { if (ti->tileh != 0) image = (ti->tileh & 2) ? 0x519 : 0x51B;
image = 0x519;
if (!(ti->tileh & 2)) {
image = 0x51B;
}
}
AddSortableSpriteToDraw(image | _drawtile_track_palette, AddSortableSpriteToDraw(image | _drawtile_track_palette,
ti->x, ti->y+15, 16, 1, 4, ti->z); 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) static void DrawTrackFence_NE(const TileInfo *ti)
{ {
uint32 image = 0x516; uint32 image = 0x516;
if (ti->tileh != 0) { if (ti->tileh != 0) image = (ti->tileh & 2) ? 0x51A : 0x51C;
image = 0x51A;
if (!(ti->tileh & 2)) {
image = 0x51C;
}
}
AddSortableSpriteToDraw(image | _drawtile_track_palette, AddSortableSpriteToDraw(image | _drawtile_track_palette,
ti->x+1, ti->y, 1, 16, 4, ti->z); 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) static void DrawTrackFence_SW(const TileInfo *ti)
{ {
uint32 image = 0x516; uint32 image = 0x516;
if (ti->tileh != 0) { if (ti->tileh != 0) image = (ti->tileh & 2) ? 0x51A : 0x51C;
image = 0x51A;
if (!(ti->tileh & 2)) {
image = 0x51C;
}
}
AddSortableSpriteToDraw(image | _drawtile_track_palette, AddSortableSpriteToDraw(image | _drawtile_track_palette,
ti->x+15, ti->y, 1, 16, 4, ti->z); ti->x+15, ti->y, 1, 16, 4, ti->z);
} }