(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 */
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;}

7
gfx.c
View File

@ -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);}

View File

@ -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);
}

View File

@ -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;
}
/**

View File

@ -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);
}