From 1e3ed903be447dcbb77e4fd9a4a3d7bfe7582760 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Thu, 22 Apr 2021 00:39:34 +0200 Subject: [PATCH] :art: strip redundant else --- Source/DiabloUI/diabloui.cpp | 6 ++++-- Source/DiabloUI/selhero.cpp | 3 +-- Source/DiabloUI/text.cpp | 3 ++- Source/DiabloUI/ttf_render_wrapped.cpp | 5 ++--- Source/controls/plrctrls.cpp | 3 ++- Source/controls/touch.cpp | 2 +- Source/diablo.cpp | 6 +++--- Source/drlg_l1.cpp | 12 ++++++------ Source/drlg_l4.cpp | 6 ++---- Source/dvlnet/base.cpp | 13 ++++++------- Source/dvlnet/frame_queue.cpp | 4 ++-- Source/dvlnet/protocol_zt.cpp | 6 +++--- Source/dvlnet/tcp_server.cpp | 3 ++- Source/engine.cpp | 9 +++------ Source/gmenu.cpp | 3 +-- Source/inv.cpp | 18 +++++++++--------- Source/lighting.cpp | 4 ++-- Source/loadsave.cpp | 3 ++- Source/miniwin/misc_msg.cpp | 3 ++- Source/missiles.cpp | 19 +++++++++---------- Source/monster.cpp | 4 ++-- Source/mpqapi.cpp | 5 ++--- Source/msg.cpp | 8 ++++---- Source/multi.cpp | 11 +++++------ Source/nthread.cpp | 23 ++++++++++++----------- Source/objects.cpp | 4 ++-- Source/player.cpp | 16 +++++++--------- Source/portal.cpp | 4 ++-- Source/scrollrt.cpp | 6 ++++-- Source/sha.cpp | 3 +-- 30 files changed, 105 insertions(+), 110 deletions(-) diff --git a/Source/DiabloUI/diabloui.cpp b/Source/DiabloUI/diabloui.cpp index 3387f8d1c..abe59d9a7 100644 --- a/Source/DiabloUI/diabloui.cpp +++ b/Source/DiabloUI/diabloui.cpp @@ -864,7 +864,8 @@ bool HandleMouseEventScrollBar(const SDL_Event &event, const UiScrollBar *ui_sb) if (scrollBarState.upArrowPressed && IsInsideRect(event, UpArrowRect(ui_sb))) { UiFocusUp(); return true; - } else if (scrollBarState.downArrowPressed && IsInsideRect(event, DownArrowRect(ui_sb))) { + } + if (scrollBarState.downArrowPressed && IsInsideRect(event, DownArrowRect(ui_sb))) { UiFocusDown(); return true; } @@ -878,7 +879,8 @@ bool HandleMouseEventScrollBar(const SDL_Event &event, const UiScrollBar *ui_sb) UiFocusPageDown(); } return true; - } else if (IsInsideRect(event, UpArrowRect(ui_sb))) { + } + if (IsInsideRect(event, UpArrowRect(ui_sb))) { scrollBarState.upArrowPressed = true; return true; } else if (IsInsideRect(event, DownArrowRect(ui_sb))) { diff --git a/Source/DiabloUI/selhero.cpp b/Source/DiabloUI/selhero.cpp index 420c8d485..b02dc56ba 100644 --- a/Source/DiabloUI/selhero.cpp +++ b/Source/DiabloUI/selhero.cpp @@ -352,9 +352,8 @@ void selhero_Name_Select(int value) if (gfnHeroCreate(&selhero_heroInfo)) { selhero_Load_Select(1); return; - } else { - UiErrorOkDialog("Unable to create character.", vecSelDlgItems); } + UiErrorOkDialog("Unable to create character.", vecSelDlgItems); } } diff --git a/Source/DiabloUI/text.cpp b/Source/DiabloUI/text.cpp index 935e33fc4..5bf39fdfa 100644 --- a/Source/DiabloUI/text.cpp +++ b/Source/DiabloUI/text.cpp @@ -25,7 +25,8 @@ void WordWrapArtStr(char *text, std::size_t width) if (text[i] == '\n') { lineStart = i + 1; continue; - } else if (text[i] != ' ' && i != len) { + } + if (text[i] != ' ' && i != len) { continue; } diff --git a/Source/DiabloUI/ttf_render_wrapped.cpp b/Source/DiabloUI/ttf_render_wrapped.cpp index bb7324161..6b1df90d0 100644 --- a/Source/DiabloUI/ttf_render_wrapped.cpp +++ b/Source/DiabloUI/ttf_render_wrapped.cpp @@ -102,10 +102,9 @@ SDL_Surface *RenderUTF8_Solid_Wrapped(TTF_Font *font, const char *text, SDL_Colo TTF_SizeUTF8(font, tok, &w, &h); if ((Uint32)w <= wrapLength) { break; - } else { - /* Back up and try again... */ - *spot = delim; } + /* Back up and try again... */ + *spot = delim; while (spot > tok && !CharacterIsDelimiter(spot[-1], wrapDelims)) { --spot; diff --git a/Source/controls/plrctrls.cpp b/Source/controls/plrctrls.cpp index 916e08a6e..b924c2398 100644 --- a/Source/controls/plrctrls.cpp +++ b/Source/controls/plrctrls.cpp @@ -859,7 +859,8 @@ HandleLeftStickOrDPadFn GetLeftStickOrDPadGameUIHandler() { if (invflag) { return &InvMove; - } else if (chrflag && plr[myplr]._pStatPts > 0) { + } + if (chrflag && plr[myplr]._pStatPts > 0) { return &AttrIncBtnSnap; } else if (spselflag) { return &HotSpellMove; diff --git a/Source/controls/touch.cpp b/Source/controls/touch.cpp index f53f9788f..a51a45c3a 100644 --- a/Source/controls/touch.cpp +++ b/Source/controls/touch.cpp @@ -16,7 +16,7 @@ inline T clip(T v, T amin, T amax) { if (v < amin) return amin; - else if (v > amax) + if (v > amax) return amax; else return v; diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 3873d0c7a..6649ee50f 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -2116,10 +2116,10 @@ void game_loop(bool bStartup) if (!multi_handle_delta()) { timeout_cursor(true); break; - } else { - timeout_cursor(false); - game_logic(); } + timeout_cursor(false); + game_logic(); + if (!gbRunGame || !gbIsMultiplayer || !nthread_has_500ms_passed()) break; } diff --git a/Source/drlg_l1.cpp b/Source/drlg_l1.cpp index 2d28f6c49..4cb5e6f98 100644 --- a/Source/drlg_l1.cpp +++ b/Source/drlg_l1.cpp @@ -1048,8 +1048,8 @@ static int DRLG_PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, in return 1; if (sx < cx && sy > cy) return 2; - else - return 3; + + return 3; } static void DRLG_L1Floor() @@ -1575,8 +1575,8 @@ static int L5HWallOk(int i, int j) if (wallok) return x; - else - return -1; + + return -1; } static int L5VWallOk(int i, int j) @@ -1601,8 +1601,8 @@ static int L5VWallOk(int i, int j) if (wallok) return y; - else - return -1; + + return -1; } static void L5HorizWall(int i, int j, char p, int dx) diff --git a/Source/drlg_l4.cpp b/Source/drlg_l4.cpp index daceb9f4d..3ba0a4289 100644 --- a/Source/drlg_l4.cpp +++ b/Source/drlg_l4.cpp @@ -306,9 +306,8 @@ static int L4HWallOk(int i, int j) if (wallok) { return x; - } else { - return -1; } + return -1; } static int L4VWallOk(int i, int j) @@ -360,9 +359,8 @@ static int L4VWallOk(int i, int j) if (wallok) { return y; - } else { - return -1; } + return -1; } static void L4HorizWall(int i, int j, int dx) diff --git a/Source/dvlnet/base.cpp b/Source/dvlnet/base.cpp index e35733499..e2324d06d 100644 --- a/Source/dvlnet/base.cpp +++ b/Source/dvlnet/base.cpp @@ -163,16 +163,15 @@ bool base::SNetReceiveTurns(char **data, unsigned int *size, DWORD *status) } } return true; - } else { - for (auto i = 0; i < MAX_PLRS; ++i) { - if (connected_table[i]) { - if (!turn_queue[i].empty()) { - status[i] |= PS_ACTIVE; - } + } + for (auto i = 0; i < MAX_PLRS; ++i) { + if (connected_table[i]) { + if (!turn_queue[i].empty()) { + status[i] |= PS_ACTIVE; } } - return false; } + return false; } bool base::SNetSendTurn(char *data, unsigned int size) diff --git a/Source/dvlnet/frame_queue.cpp b/Source/dvlnet/frame_queue.cpp index 81fd54f69..25b64a63f 100644 --- a/Source/dvlnet/frame_queue.cpp +++ b/Source/dvlnet/frame_queue.cpp @@ -53,8 +53,8 @@ bool frame_queue::packet_ready() } if (size() >= nextsize) return true; - else - return false; + + return false; } buffer_t frame_queue::read_packet() diff --git a/Source/dvlnet/protocol_zt.cpp b/Source/dvlnet/protocol_zt.cpp index 9f1418916..8e848198c 100644 --- a/Source/dvlnet/protocol_zt.cpp +++ b/Source/dvlnet/protocol_zt.cpp @@ -127,7 +127,8 @@ bool protocol_zt::send_queued_peer(const endpoint &peer) if (r < 0) { // handle error return false; - } else if (decltype(len)(r) < len) { + } + if (decltype(len)(r) < len) { // partial send auto it = peer_list[peer].send_queue.front().begin(); peer_list[peer].send_queue.front().erase(it, it + r); @@ -151,9 +152,8 @@ bool protocol_zt::recv_peer(const endpoint &peer) } else { if (errno == EAGAIN || errno == EWOULDBLOCK) { return true; - } else { - return false; } + return false; } } } diff --git a/Source/dvlnet/tcp_server.cpp b/Source/dvlnet/tcp_server.cpp index 9b46fb6cf..2de7a9286 100644 --- a/Source/dvlnet/tcp_server.cpp +++ b/Source/dvlnet/tcp_server.cpp @@ -26,7 +26,8 @@ std::string tcp_server::localhost_self() if (addr.is_unspecified()) { if (addr.is_v4()) { return asio::ip::address_v4::loopback().to_string(); - } else if (addr.is_v6()) { + } + if (addr.is_v6()) { return asio::ip::address_v6::loopback().to_string(); } ABORT(); diff --git a/Source/engine.cpp b/Source/engine.cpp index c0987f503..3d0bf5784 100644 --- a/Source/engine.cpp +++ b/Source/engine.cpp @@ -816,9 +816,8 @@ static void Cl2BlitSafe(CelOutputBuffer out, int sx, int sy, BYTE *pRLEBytes, in dst -= out.pitch() + w; } continue; - } else { - src += width; } + src += width; } } while (width) { @@ -903,9 +902,8 @@ static void Cl2BlitOutlineSafe(CelOutputBuffer out, int sx, int sy, BYTE *pRLEBy dst -= out.pitch() + w; } continue; - } else { - src += width; } + src += width; } } while (width) { @@ -985,9 +983,8 @@ static void Cl2BlitLightSafe(CelOutputBuffer out, int sx, int sy, BYTE *pRLEByte dst -= out.pitch() + w; } continue; - } else { - src += width; } + src += width; } } while (width) { diff --git a/Source/gmenu.cpp b/Source/gmenu.cpp index ce8a440db..f578c9622 100644 --- a/Source/gmenu.cpp +++ b/Source/gmenu.cpp @@ -353,9 +353,8 @@ bool gmenu_left_mouse(bool isDown) if (mouseNavigation) { mouseNavigation = false; return true; - } else { - return false; } + return false; } if (!sgpCurrentMenu) { diff --git a/Source/inv.cpp b/Source/inv.cpp index 97a75a16c..e750c75ba 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -2348,16 +2348,16 @@ bool UseInvItem(int pnum, int cii) } RemoveSpdBarItem(pnum, c); return true; - } else { - if (plr[pnum].InvList[c]._iMiscId == IMISC_MAPOFDOOM) - return true; - if (plr[pnum].InvList[c]._iMiscId == IMISC_NOTE) { - InitQTextMsg(TEXT_BOOK9); - invflag = false; - return true; - } - RemoveInvItem(pnum, c); } + if (plr[pnum].InvList[c]._iMiscId == IMISC_MAPOFDOOM) + return true; + if (plr[pnum].InvList[c]._iMiscId == IMISC_NOTE) { + InitQTextMsg(TEXT_BOOK9); + invflag = false; + return true; + } + RemoveInvItem(pnum, c); + return true; } diff --git a/Source/lighting.cpp b/Source/lighting.cpp index c505655d4..5ecc980a0 100644 --- a/Source/lighting.cpp +++ b/Source/lighting.cpp @@ -488,8 +488,8 @@ char GetLight(int x, int y) { if (LoadMapObjsFlag) return dPreLight[x][y]; - else - return dLight[x][y]; + + return dLight[x][y]; } void DoLighting(int nXPos, int nYPos, int nRadius, int Lnum) diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index bdd638a1e..3f96da17c 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -840,7 +840,8 @@ bool IsHeaderValid(Uint32 magicNumber) gbIsHellfireSaveGame = false; if (magicNumber == LOAD_LE32("SHAR")) { return true; - } else if (magicNumber == LOAD_LE32("SHLF")) { + } + if (magicNumber == LOAD_LE32("SHLF")) { gbIsHellfireSaveGame = true; return true; } else if (!gbIsSpawn && magicNumber == LOAD_LE32("RETL")) { diff --git a/Source/miniwin/misc_msg.cpp b/Source/miniwin/misc_msg.cpp index a16d89da6..5543d1b9c 100644 --- a/Source/miniwin/misc_msg.cpp +++ b/Source/miniwin/misc_msg.cpp @@ -443,7 +443,8 @@ bool FetchMessage(LPMSG lpMsg) } return true; #ifndef USE_SDL1 - } else if (e.type < SDL_JOYAXISMOTION || (e.type >= SDL_FINGERDOWN && e.type < SDL_DOLLARGESTURE)) { + } + if (e.type < SDL_JOYAXISMOTION || (e.type >= SDL_FINGERDOWN && e.type < SDL_DOLLARGESTURE)) { #else } else if (e.type < SDL_JOYAXISMOTION) { #endif diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 4bd85451f..479f8f047 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -579,7 +579,7 @@ bool MonsterTrapHit(int m, int mindam, int maxdam, int dist, int t, bool shift) return ret; } #ifdef _DEBUG - else if (hit < hper || debug_mode_dollar_sign || debug_mode_key_inverted_v || monster[m]._mmode == MM_STONE) { + if (hit < hper || debug_mode_dollar_sign || debug_mode_key_inverted_v || monster[m]._mmode == MM_STONE) { #else else if (hit < hper || monster[m]._mmode == MM_STONE) { #endif @@ -983,17 +983,16 @@ bool Plr2PlrMHit(int pnum, int p, int mindam, int maxdam, int dist, int mtype, b NetSendCmdDamage(true, p, dam); plr[pnum].PlaySpeach(69); return true; + } + if (blkper < blk) { + StartPlrBlock(p, GetDirection(plr[p]._px, plr[p]._py, plr[pnum]._px, plr[pnum]._py)); + *blocked = true; } else { - if (blkper < blk) { - StartPlrBlock(p, GetDirection(plr[p]._px, plr[p]._py, plr[pnum]._px, plr[pnum]._py)); - *blocked = true; - } else { - if (pnum == myplr) - NetSendCmdDamage(true, p, dam); - StartPlrHit(p, dam, false); - } - return true; + if (pnum == myplr) + NetSendCmdDamage(true, p, dam); + StartPlrHit(p, dam, false); } + return true; } return false; } diff --git a/Source/monster.cpp b/Source/monster.cpp index 1e10e72a7..ed6a038f5 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -5661,8 +5661,8 @@ int encode_enemy(int m) { if (monster[m]._mFlags & MFLAG_TARGETS_MONSTER) return monster[m]._menemy + MAX_PLRS; - else - return monster[m]._menemy; + + return monster[m]._menemy; } void decode_enemy(int m, int enemy) diff --git a/Source/mpqapi.cpp b/Source/mpqapi.cpp index d4e1d3089..64bd4f569 100644 --- a/Source/mpqapi.cpp +++ b/Source/mpqapi.cpp @@ -203,11 +203,10 @@ struct Archive { if (GetFileSize(name, &size) == 0) { SDL_Log("GetFileSize(\"%s\") failed with \"%s\"", name, std::strerror(errno)); return false; + } #ifdef _DEBUG - } else { - SDL_Log("GetFileSize(\"%s\") = %" PRIuMAX, name, size); + SDL_Log("GetFileSize(\"%s\") = %" PRIuMAX, name, size); #endif - } } else { mode |= std::ios::trunc; } diff --git a/Source/msg.cpp b/Source/msg.cpp index 723f15cf9..7c0a767e3 100644 --- a/Source/msg.cpp +++ b/Source/msg.cpp @@ -404,7 +404,8 @@ static DWORD On_DLEVEL(int pnum, TCmd *pCmd) if (p->bCmd == CMD_DLEVEL_END) { sgbDeltaChunks = MAX_CHUNKS - 1; return p->wBytes + sizeof(*p); - } else if (p->bCmd == CMD_DLEVEL_0 && p->wOffset == 0) { + } + if (p->bCmd == CMD_DLEVEL_0 && p->wOffset == 0) { sgdwRecvOffset = 0; sgbRecvCmd = p->bCmd; } else { @@ -416,10 +417,9 @@ static DWORD On_DLEVEL(int pnum, TCmd *pCmd) sgbDeltaChunks = MAX_CHUNKS - 1; sgbRecvCmd = CMD_DLEVEL_END; return p->wBytes + sizeof(*p); - } else { - sgdwRecvOffset = 0; - sgbRecvCmd = p->bCmd; } + sgdwRecvOffset = 0; + sgbRecvCmd = p->bCmd; } assert(p->wOffset == sgdwRecvOffset); diff --git a/Source/multi.cpp b/Source/multi.cpp index 11d7ad97c..ac531c48e 100644 --- a/Source/multi.cpp +++ b/Source/multi.cpp @@ -823,14 +823,13 @@ bool multi_init_multi(GameData *gameData) if ((DWORD)playerId >= MAX_PLRS) { return false; - } else { - myplr = playerId; - gbIsMultiplayer = true; + } + myplr = playerId; + gbIsMultiplayer = true; - pfile_read_player_from_save(); + pfile_read_player_from_save(); - return true; - } + return true; } void recv_plrinfo(int pnum, TCmdPlrInfoHdr *p, bool recv) diff --git a/Source/nthread.cpp b/Source/nthread.cpp index a3d543e59..b17ec8e90 100644 --- a/Source/nthread.cpp +++ b/Source/nthread.cpp @@ -39,7 +39,8 @@ void nthread_terminate_game(const char *pszFcn) sErr = SErrGetLastError(); if (sErr == STORM_ERROR_INVALID_PLAYER) { return; - } else if (sErr == STORM_ERROR_GAME_TERMINATED) { + } + if (sErr == STORM_ERROR_GAME_TERMINATED) { gbGameDestroyed = true; } else if (sErr == STORM_ERROR_NOT_IN_GAME) { gbGameDestroyed = true; @@ -103,17 +104,17 @@ bool nthread_recv_turns(bool *pfSendAsync) sgbSyncCountdown = 1; sgbPacketCountdown = 1; return false; - } else { - if (!sgbTicsOutOfSync) { - sgbTicsOutOfSync = true; - last_tick = SDL_GetTicks(); - } - sgbSyncCountdown = 4; - multi_msg_countdown(); - *pfSendAsync = true; - last_tick += gnTickDelay; - return true; } + if (!sgbTicsOutOfSync) { + sgbTicsOutOfSync = true; + last_tick = SDL_GetTicks(); + } + sgbSyncCountdown = 4; + multi_msg_countdown(); + *pfSendAsync = true; + last_tick += gnTickDelay; + return true; + #endif } diff --git a/Source/objects.cpp b/Source/objects.cpp index b3ca83838..f5538af36 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -352,8 +352,8 @@ static bool WallTrapLocOkK(int xp, int yp) if (nTrapTable[dPiece[xp][yp]]) return true; - else - return false; + + return false; } void InitRndLocObj(int min, int max, _object_id objtype) diff --git a/Source/player.cpp b/Source/player.cpp index 6c441da56..7d742e093 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -2324,10 +2324,9 @@ bool PM_DoWalk(int pnum, int variant) AutoGoldPickup(pnum); return true; - } else { //We didn't reach new tile so update player's "sub-tile" position - PM_ChangeOffset(pnum); - return false; - } + } //We didn't reach new tile so update player's "sub-tile" position + PM_ChangeOffset(pnum); + return false; } static bool WeaponDurDecay(int pnum, int ii) @@ -2880,9 +2879,8 @@ bool PM_DoAttack(int pnum) StartStand(pnum, plr[pnum]._pdir); ClearPlrPVars(pnum); return true; - } else { - return false; } + return false; } bool PM_DoRangeAttack(int pnum) @@ -2964,9 +2962,8 @@ bool PM_DoRangeAttack(int pnum) StartStand(pnum, plr[pnum]._pdir); ClearPlrPVars(pnum); return true; - } else { - return false; } + return false; } void ShieldDur(int pnum) @@ -3512,7 +3509,8 @@ bool PlrDeathModeOK(int p) if (plr[p]._pmode == PM_DEATH) { return true; - } else if (plr[p]._pmode == PM_QUIT) { + } + if (plr[p]._pmode == PM_QUIT) { return true; } else if (plr[p]._pmode == PM_NEWLVL) { return true; diff --git a/Source/portal.cpp b/Source/portal.cpp index 4e38926f2..250ac11d5 100644 --- a/Source/portal.cpp +++ b/Source/portal.cpp @@ -107,8 +107,8 @@ bool PortalOnLevel(int i) { if (portal[i].level == currlevel) return true; - else - return currlevel == 0; + + return currlevel == 0; } void RemovePortalMissile(int id) diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index c22f99c45..ea47d819c 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -175,13 +175,15 @@ static void scrollrt_draw_cursor_item(CelOutputBuffer out) mx = MouseX - 1; if (mx < 0 - cursW - 1) { return; - } else if (mx > gnScreenWidth - 1) { + } + if (mx > gnScreenWidth - 1) { return; } my = MouseY - 1; if (my < 0 - cursH - 1) { return; - } else if (my > gnScreenHeight - 1) { + } + if (my > gnScreenHeight - 1) { return; } diff --git a/Source/sha.cpp b/Source/sha.cpp index dd34469bb..ddb9418cf 100644 --- a/Source/sha.cpp +++ b/Source/sha.cpp @@ -29,9 +29,8 @@ uint32_t SHA1CircularShift(uint32_t bits, uint32_t word) //moving this part to a separate volatile variable fixes saves in x64-release build in visual studio 2017 volatile uint32_t tmp = ((~word) >> (32 - bits)); return (word << bits) | (~tmp); - } else { - return (word << bits) | (word >> (32 - bits)); } + return (word << bits) | (word >> (32 - bits)); } } // namespace