Simplify boolean expresions

This commit is contained in:
Filip Gawin authored and Michael Steenbeek committed 2019-05-10 22:00:38 +02:00
1 parent 9af568d97c
commit 6833da77e3
25 files changed
+52 -100

No files matched your search

@@ -1460,10 +1460,7 @@ static bool filter_chunks(const ObjectRepositoryItem* item)
break;
}
}
if (_filter_flags & (1 << (gRideCategories[rideType] + _numSourceGameItems)))
return true;
return false;
return (_filter_flags & (1 << (gRideCategories[rideType] + _numSourceGameItems))) != 0;
}
return true;
}
+2 -2
View File
@@ -2449,14 +2449,14 @@ static void sub_6CBCE2(
// Set the temporary track element
_tempTrackTileElement.SetType(TILE_ELEMENT_TYPE_TRACK);
_tempTrackTileElement.SetDirection(trackDirection);
_tempTrackTileElement.AsTrack()->SetHasChain((edx & 0x10000) ? true : false);
_tempTrackTileElement.AsTrack()->SetHasChain((edx & 0x10000) != 0);
_tempTrackTileElement.flags = quarterTile.GetBaseQuarterOccupied() | TILE_ELEMENT_FLAG_LAST_TILE;
_tempTrackTileElement.base_height = baseZ;
_tempTrackTileElement.clearance_height = clearanceZ;
_tempTrackTileElement.AsTrack()->SetTrackType(trackType);
_tempTrackTileElement.AsTrack()->SetSequenceIndex(trackBlock->index);
_tempTrackTileElement.AsTrack()->SetHasCableLift(false);
_tempTrackTileElement.AsTrack()->SetInverted((edx & 0x20000) ? true : false);
_tempTrackTileElement.AsTrack()->SetInverted((edx & 0x20000) != 0);
_tempTrackTileElement.AsTrack()->SetColourScheme(RIDE_COLOUR_SCHEME_MAIN);
// Skipping seat rotation, should not be necessary for a temporary piece.
_tempTrackTileElement.AsTrack()->SetRideIndex(rideIndex);
+1 -1
View File
@@ -639,7 +639,7 @@ static void join_server(std::string address)
static void fetch_servers()
{
std::string masterServerUrl = OPENRCT2_MASTER_SERVER_URL;
if (gConfigNetwork.master_server_url.empty() == false)
if (!gConfigNetwork.master_server_url.empty())
{
masterServerUrl = gConfigNetwork.master_server_url;
}
+3 -3
View File
@@ -1211,7 +1211,7 @@ void window_staff_overview_tool_down(rct_window* w, rct_widgetindex widgetIndex,
return;
rct_sprite* sprite = try_get_sprite(w->number);
if (sprite == nullptr || sprite->IsPeep() == false)
if (sprite == nullptr || !sprite->IsPeep())
return;
Peep& peep = sprite->peep;
@@ -1252,7 +1252,7 @@ void window_staff_overview_tool_drag(rct_window* w, rct_widgetindex widgetIndex,
return;
rct_sprite* sprite = try_get_sprite(w->number);
if (sprite == nullptr || sprite->IsPeep() == false)
if (sprite == nullptr || !sprite->IsPeep())
return;
Peep& peep = sprite->peep;
@@ -1262,7 +1262,7 @@ void window_staff_overview_tool_drag(rct_window* w, rct_widgetindex widgetIndex,
bool patrolAreaValue = staff_is_patrol_area_set(peep.staff_id, dest_x, dest_y);
if (_staffPatrolAreaPaintValue == PatrolAreaValue::SET && patrolAreaValue)
return; // Since area is already the value we want, skip...
if (_staffPatrolAreaPaintValue == PatrolAreaValue::UNSET && patrolAreaValue == false)
if (_staffPatrolAreaPaintValue == PatrolAreaValue::UNSET && !patrolAreaValue)
return; // Since area is already the value we want, skip...
auto staffSetPatrolAreaAction = StaffSetPatrolAreaAction(w->number, { dest_x, dest_y });
+4 -7
View File
@@ -443,12 +443,12 @@ namespace OpenRCT2
{
_mode = ReplayMode::NORMALISATION;
if (StartPlayback(file) == false)
if (!StartPlayback(file))
{
return false;
}
if (StartRecording(outFile, k_MaxReplayTicks) == false)
if (!StartRecording(outFile, k_MaxReplayTicks))
{
StopPlayback();
return false;
@@ -621,7 +621,7 @@ namespace OpenRCT2
return false;
char buffer[128];
while (feof(fp) == false)
while (feof(fp) == 0)
{
size_t numBytesRead = fread(buffer, 1, 128, fp);
if (numBytesRead == 0)
@@ -785,10 +785,7 @@ namespace OpenRCT2
bool Compatible(ReplayRecordData& data)
{
if (data.version == 1 && ReplayVersion == 2)
return true;
return false;
return data.version == 1 && ReplayVersion == 2;
}
bool Serialise(DataSerialiser& serialiser, ReplayRecordData& data)
+2 -2
View File
@@ -154,7 +154,7 @@ namespace GameActions
if (result->Error == GA_ERROR::OK)
{
if (finance_check_affordability(result->Cost, action->GetFlags()) == false)
if (!finance_check_affordability(result->Cost, action->GetFlags()))
{
result->Error = GA_ERROR::INSUFFICIENT_FUNDS;
result->ErrorMessage = STR_NOT_ENOUGH_CASH_REQUIRES;
@@ -290,7 +290,7 @@ namespace GameActions
LogActionFinish(logContext, action, result);
// If not top level just give away the result.
if (topLevel == false)
if (!topLevel)
return result;
gCommandPosition.x = result->Position.x;
+1 -8
View File
@@ -252,14 +252,7 @@ bool place_peep_spawn(CoordsXYZD location)
{
auto gameAction = PlacePeepSpawnAction(location);
auto result = GameActions::Execute(&gameAction);
if (result->Error == GA_ERROR::OK)
{
return true;
}
else
{
return false;
}
return result->Error == GA_ERROR::OK;
}
#pragma endregion
@@ -1436,7 +1436,7 @@ static int32_t cc_replay_stoprecord(InteractiveConsole& console, const arguments
}
auto* replayManager = OpenRCT2::GetContext()->GetReplayManager();
if (replayManager->IsRecording() == false && replayManager->IsNormalising() == false)
if (!replayManager->IsRecording() && !replayManager->IsNormalising())
{
console.WriteFormatLine("Replay currently not recording");
return 0;
+1 -3
View File
@@ -276,7 +276,5 @@ bool utf8_is_format_code(int32_t codepoint)
bool utf8_is_colour_code(int32_t codepoint)
{
if (codepoint >= FORMAT_COLOUR_CODE_START && codepoint <= FORMAT_COLOUR_CODE_END)
return true;
return false;
return codepoint >= FORMAT_COLOUR_CODE_START && codepoint <= FORMAT_COLOUR_CODE_END;
}
+1 -7
View File
@@ -89,13 +89,7 @@ bool finance_check_money_required(uint32_t flags)
*/
bool finance_check_affordability(money32 cost, uint32_t flags)
{
if (cost <= 0)
return true;
if (finance_check_money_required(flags) == false)
return true;
if (cost > gCash)
return false;
return true;
return cost <= 0 || !finance_check_money_required(flags) || cost <= gCash;
}
/**
+3 -3
View File
@@ -986,7 +986,7 @@ void Network::SendPacketToClients(NetworkPacket& packet, bool front, bool gameCm
bool Network::CheckSRAND(uint32_t tick, uint32_t srand0)
{
// We have to wait for the map to be loaded first, ticks may match current loaded map.
if (_clientMapLoaded == false)
if (!_clientMapLoaded)
return true;
auto itTickData = _serverTickData.find(tick);
@@ -999,7 +999,7 @@ bool Network::CheckSRAND(uint32_t tick, uint32_t srand0)
if (storedTick.srand0 != srand0)
return false;
if (storedTick.spriteHash.empty() == false)
if (!storedTick.spriteHash.empty())
{
rct_sprite_checksum checksum = sprite_checksum();
std::string clientSpriteHash = checksum.ToString();
@@ -2198,7 +2198,7 @@ NetworkPlayer* Network::AddPlayer(const std::string& name, const std::string& ke
if (networkUser == nullptr)
{
player->Group = GetDefaultGroup();
if (name.empty() == false)
if (!name.empty())
{
player->SetName(MakePlayerNameUnique(String::Trim(name)));
}
@@ -254,7 +254,7 @@ private:
static std::string GetMasterServerUrl()
{
std::string result = OPENRCT2_MASTER_SERVER_URL;
if (gConfigNetwork.master_server_url.empty() == false)
if (!gConfigNetwork.master_server_url.empty())
{
result = gConfigNetwork.master_server_url;
}
+1 -1
View File
@@ -1320,7 +1320,7 @@ bool path_b_supports_paint_setup(
baseHeight += z;
}
if (keepGoing == false)
if (!keepGoing)
{
break;
}
@@ -781,7 +781,7 @@ static void viewport_surface_draw_tile_side_top(
return;
}
if (isWater == false)
if (!isWater)
dl = height;
// save ecx
+1 -6
View File
@@ -5884,12 +5884,7 @@ bool Guest::ShouldFindBench()
return false;
}
if (!GetNextIsSurface() && !GetNextIsSloped())
{
return true;
}
return false;
return !GetNextIsSurface() && !GetNextIsSloped();
}
/**
+1 -1
View File
@@ -1797,7 +1797,7 @@ static void get_ride_queue_end(TileCoordsXYZ& loc)
}
} while (!(tileElement++)->IsLastForTile());
if (found == false)
if (!found)
break;
if (!tileElement->AsPath()->IsQueue())
+1 -1
View File
@@ -710,7 +710,7 @@ static uint8_t staff_direction_surface(Peep* peep, uint8_t initialDirection)
LocationXY16 chosenTile = { static_cast<int16_t>(peep->next_x + CoordsDirectionDelta[direction].x),
static_cast<int16_t>(peep->next_y + CoordsDirectionDelta[direction].y) };
if (map_surface_is_blocked(chosenTile.x, chosenTile.y) == false)
if (!map_surface_is_blocked(chosenTile.x, chosenTile.y))
{
return direction;
}
+1 -5
View File
@@ -130,11 +130,7 @@ bool platform_directory_exists(const utf8* path)
struct stat dirinfo;
int32_t result = stat(buffer, &dirinfo);
log_verbose("checking dir %s, result = %d, is_dir = %d", buffer, result, S_ISDIR(dirinfo.st_mode));
if ((result != 0) || !S_ISDIR(dirinfo.st_mode))
{
return false;
}
return true;
return result == 0 && S_ISDIR(dirinfo.st_mode);
}
bool platform_original_game_data_exists(const utf8* path)
+5 -14
View File
@@ -2570,12 +2570,7 @@ bool Ride::CanBreakDown() const
}
rct_ride_entry* entry = GetRideEntry();
if (entry == nullptr || entry->flags & RIDE_ENTRY_FLAG_CANNOT_BREAK_DOWN)
{
return false;
}
return true;
return entry != nullptr && !(entry->flags & RIDE_ENTRY_FLAG_CANNOT_BREAK_DOWN);
}
static void choose_random_train_to_breakdown_safe(Ride* ride)
@@ -7197,7 +7192,7 @@ void sub_6CB945(Ride* ride)
break;
} while (!(tileElement++)->IsLastForTile());
if (trackFound == false)
if (!trackFound)
{
break;
}
@@ -7212,7 +7207,7 @@ void sub_6CB945(Ride* ride)
}
}
if (specialTrack == false)
if (!specialTrack)
{
continue;
}
@@ -7782,13 +7777,9 @@ uint8_t ride_entry_get_first_non_null_ride_type(const rct_ride_entry* rideEntry)
bool ride_type_supports_boosters(uint8_t rideType)
{
if (rideType == RIDE_TYPE_LOOPING_ROLLER_COASTER || rideType == RIDE_TYPE_CORKSCREW_ROLLER_COASTER
return rideType == RIDE_TYPE_LOOPING_ROLLER_COASTER || rideType == RIDE_TYPE_CORKSCREW_ROLLER_COASTER
|| rideType == RIDE_TYPE_TWISTER_ROLLER_COASTER || rideType == RIDE_TYPE_VERTICAL_DROP_ROLLER_COASTER
|| rideType == RIDE_TYPE_GIGA_COASTER || rideType == RIDE_TYPE_JUNIOR_ROLLER_COASTER)
{
return true;
}
return false;
|| rideType == RIDE_TYPE_GIGA_COASTER || rideType == RIDE_TYPE_JUNIOR_ROLLER_COASTER;
}
int32_t get_booster_speed(uint8_t rideType, int32_t rawSpeed)
+5 -8
View File
@@ -1862,7 +1862,7 @@ static void vehicle_update_measurements(rct_vehicle* vehicle)
// Iterate through each tile_element.
} while (!(tile_element++)->IsLastForTile());
if (cover_found == false)
if (!cover_found)
{
ride->testing_flags &= ~RIDE_TESTING_SHELTERED;
return;
@@ -2544,7 +2544,7 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle)
}
}
if (skipCheck == false)
if (!skipCheck)
{
if (!(ride->stations[vehicle->current_station].Depart & STATION_DEPART_FLAG))
return;
@@ -3414,7 +3414,7 @@ static void vehicle_update_departing(rct_vehicle* vehicle)
}
}
if (vehicle_current_tower_element_is_top(vehicle) == false)
if (!vehicle_current_tower_element_is_top(vehicle))
{
if (ride->mode == RIDE_MODE_FREEFALL_DROP)
vehicle_invalidate(vehicle);
@@ -7669,10 +7669,7 @@ static bool vehicle_update_motion_collision_detection(
return false;
uint8_t direction = (vehicle->sprite_direction - collideVehicle->sprite_direction + 7) & 0x1F;
if (direction >= 0xF)
return false;
return true;
return direction < 0xF;
}
LocationXY8 location = { static_cast<uint8_t>(x / 32), static_cast<uint8_t>(y / 32) };
@@ -7760,7 +7757,7 @@ static bool vehicle_update_motion_collision_detection(
}
}
if (mayCollide == false)
if (!mayCollide)
{
vehicle->var_C4 = 0;
return false;
@@ -927,7 +927,7 @@ static void paint_miniature_railway_track_right_quarter_turn_5_tiles(
session, right_quarter_turn_5_supports_type[direction][trackSequence], 0, height,
session->TrackColours[SCHEME_SUPPORTS], nullptr);
if (isSupported == false || (trackSequence == 3 && direction == 2))
if (!isSupported || (trackSequence == 3 && direction == 2))
{
track_paint_util_right_quarter_turn_5_tiles_paint(
session, 2, height, direction, trackSequence, session->TrackColours[SCHEME_TRACK],
@@ -1063,7 +1063,7 @@ static void paint_miniature_railway_track_s_bend_left(
LocationXY16 offset = offsetList[trackSequence];
LocationXY16 bounds = boundsList[trackSequence];
if (isSupported == false)
if (!isSupported)
{
sub_98197C_rotated(
session, direction, imageId, (int8_t)offset.x, (int8_t)offset.y, bounds.x, bounds.y, 2, height, offset.x, offset.y,
@@ -1163,7 +1163,7 @@ static void paint_miniature_railway_track_s_bend_right(
| session->TrackColours[SCHEME_TRACK];
LocationXY16 offset = offsetList[trackSequence];
LocationXY16 bounds = boundsList[trackSequence];
if (isSupported == false)
if (!isSupported)
{
sub_98197C_rotated(
session, direction, imageId, (int8_t)offset.x, (int8_t)offset.y, bounds.x, bounds.y, 2, height, offset.x, offset.y,
@@ -1274,7 +1274,7 @@ static void paint_miniature_railway_track_right_quarter_turn_3_tiles(
isSupported = wooden_a_supports_paint_setup(
session, supportType[direction], 0, height, session->TrackColours[SCHEME_SUPPORTS], nullptr);
}
if (isSupported == false)
if (!isSupported)
{
track_paint_util_right_quarter_turn_3_tiles_paint(
session, 3, height, direction, trackSequence, session->TrackColours[SCHEME_TRACK],
@@ -1429,7 +1429,7 @@ static void paint_miniature_railway_track_left_eighth_to_diag(
session, supportType[direction][trackSequence], 0, height, session->TrackColours[SCHEME_SUPPORTS], nullptr);
}
uint32_t imageId;
if (isSupported == false)
if (!isSupported)
{
int8_t index = paint_miniature_railway_eighth_to_diag_index[trackSequence];
if (index >= 0)
@@ -1566,7 +1566,7 @@ static void paint_miniature_railway_track_right_eighth_to_diag(
}
uint32_t imageId;
if (isSupported == false)
if (!isSupported)
{
int8_t index = paint_miniature_railway_eighth_to_diag_index[trackSequence];
if (index >= 0)
+1 -1
View File
@@ -44,7 +44,7 @@ size_t sawyercoding_write_chunk_buffer(uint8_t* dst_file, const uint8_t* buffer,
{
uint8_t *encode_buffer, *encode_buffer2;
if (gUseRLE == false)
if (!gUseRLE)
{
if (chunkHeader.encoding == CHUNK_ENCODING_RLE || chunkHeader.encoding == CHUNK_ENCODING_RLECOMPRESSED)
{
+1 -1
View File
@@ -214,7 +214,7 @@ void fix_duplicated_banners()
log_error("Failed to create new banner.");
continue;
}
Guard::Assert(activeBanners[newBannerIndex] == false);
Guard::Assert(!activeBanners[newBannerIndex]);
// Copy over the original banner, but update the location
rct_banner& newBanner = gBanners[newBannerIndex];
+6 -9
View File
@@ -733,12 +733,9 @@ int32_t map_height_from_slope(const CoordsXY coords, int32_t slope, bool isSlope
bool map_is_location_valid(const CoordsXY coords)
{
if (coords.x < (MAXIMUM_MAP_SIZE_TECHNICAL * 32) && coords.x >= 0 && coords.y < (MAXIMUM_MAP_SIZE_TECHNICAL * 32)
&& coords.y >= 0)
{
return true;
}
return false;
const bool is_x_valid = coords.x < (MAXIMUM_MAP_SIZE_TECHNICAL * 32) && coords.x >= 0;
const bool is_y_valid = coords.y < (MAXIMUM_MAP_SIZE_TECHNICAL * 32) && coords.y >= 0;
return is_x_valid && is_y_valid;
}
bool map_is_edge(const CoordsXY coords)
@@ -1904,7 +1901,7 @@ EntranceElement* map_get_park_entrance_element_at(int32_t x, int32_t y, int32_t
if (tileElement->AsEntrance()->GetEntranceType() != ENTRANCE_TYPE_PARK_ENTRANCE)
continue;
if ((ghost == false) && (tileElement->IsGhost()))
if (!ghost && tileElement->IsGhost())
continue;
return tileElement->AsEntrance();
@@ -1929,7 +1926,7 @@ EntranceElement* map_get_ride_entrance_element_at(int32_t x, int32_t y, int32_t
if (tileElement->AsEntrance()->GetEntranceType() != ENTRANCE_TYPE_RIDE_ENTRANCE)
continue;
if ((ghost == false) && (tileElement->IsGhost()))
if (!ghost && tileElement->IsGhost())
continue;
return tileElement->AsEntrance();
@@ -1954,7 +1951,7 @@ EntranceElement* map_get_ride_exit_element_at(int32_t x, int32_t y, int32_t z, b
if (tileElement->AsEntrance()->GetEntranceType() != ENTRANCE_TYPE_RIDE_EXIT)
continue;
if ((ghost == false) && (tileElement->IsGhost()))
if (!ghost && tileElement->IsGhost())
continue;
return tileElement->AsEntrance();
+1 -4
View File
@@ -715,10 +715,7 @@ static bool litter_can_be_at(int32_t x, int32_t y, int32_t z)
if (pathZ < z || pathZ >= z + 32)
continue;
if (tile_element_is_underground(tileElement))
return false;
return true;
return !tile_element_is_underground(tileElement);
} while (!(tileElement++)->IsLastForTile());
return false;
}