From 373f28736ff979abd8f4c8bb5df62ee8142f5d76 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Mon, 19 Apr 2021 20:08:03 +0200 Subject: [PATCH] :art: Acceptable parts of modernize-* --- Source/DiabloUI/diabloui.cpp | 25 ++- Source/DiabloUI/dialogs.cpp | 3 +- Source/DiabloUI/mainmenu.cpp | 9 +- Source/DiabloUI/selconn.cpp | 9 +- Source/DiabloUI/selgame.cpp | 6 +- Source/DiabloUI/selhero.cpp | 13 +- Source/DiabloUI/selok.cpp | 9 +- Source/DiabloUI/selyesno.cpp | 9 +- Source/DiabloUI/title.cpp | 3 +- Source/automap.cpp | 4 +- Source/codec.cpp | 8 +- Source/control.cpp | 96 +++++----- Source/controls/devices/game_controller.cpp | 7 +- Source/controls/devices/joystick.cpp | 7 +- Source/controls/plrctrls.cpp | 6 +- Source/controls/touch.cpp | 30 +-- Source/diablo.cpp | 2 +- Source/drlg_l1.cpp | 32 ++-- Source/drlg_l2.cpp | 20 +- Source/dvlnet/abstract_net.cpp | 6 +- Source/dvlnet/base.cpp | 9 +- Source/dvlnet/base_protocol.cpp | 6 - Source/dvlnet/frame_queue.cpp | 6 +- Source/dvlnet/loopback.cpp | 8 +- Source/dvlnet/packet.cpp | 6 +- Source/dvlnet/protocol_zt.cpp | 14 +- Source/dvlnet/tcp_client.cpp | 9 +- Source/dvlnet/tcp_server.cpp | 9 +- Source/dvlnet/zerotier_lwip.cpp | 8 +- Source/dvlnet/zerotier_native.cpp | 6 +- Source/error.cpp | 4 +- Source/inv.cpp | 14 +- Source/items.cpp | 64 +++---- Source/items.h | 2 +- Source/lighting.cpp | 2 +- Source/lighting.h | 2 +- Source/loadsave.cpp | 199 ++++++++++---------- Source/miniwin/misc_msg.cpp | 8 +- Source/missiles.cpp | 88 ++++----- Source/monster.cpp | 28 +-- Source/mpqapi.cpp | 10 +- Source/msg.cpp | 156 +++++++-------- Source/multi.cpp | 6 +- Source/nthread.cpp | 2 +- Source/objects.cpp | 119 ++++++------ Source/palette.cpp | 16 +- Source/player.cpp | 18 +- Source/player.h | 7 +- Source/plrmsg.cpp | 2 +- Source/qol.cpp | 6 +- Source/render.cpp | 2 +- Source/scrollrt.cpp | 12 +- Source/sha.cpp | 2 +- Source/stores.cpp | 30 +-- Source/stores.h | 2 +- Source/storm/storm.cpp | 3 +- Source/storm/storm_svid.cpp | 42 ++--- Source/sync.cpp | 2 +- Source/themes.cpp | 4 - Source/towners.cpp | 28 +-- Source/trigs.cpp | 4 +- Source/utils/paths.cpp | 2 +- Source/utils/thread.cpp | 2 +- 63 files changed, 608 insertions(+), 665 deletions(-) diff --git a/Source/DiabloUI/diabloui.cpp b/Source/DiabloUI/diabloui.cpp index f291f8352..936195fca 100644 --- a/Source/DiabloUI/diabloui.cpp +++ b/Source/DiabloUI/diabloui.cpp @@ -93,10 +93,10 @@ void UiInitList(int count, void (*fnFocus)(int value), void (*fnSelect)(int valu SDL_StopTextInput(); // input is enabled by default #endif textInputActive = false; - for (std::size_t i = 0; i < items.size(); i++) { - if (items[i]->m_type == UI_EDIT) { - UiEdit *pItemUIEdit = dynamic_cast(items[i]); - SDL_SetTextInputRect(&items[i]->m_rect); + for (auto &item : items) { + if (item->m_type == UI_EDIT) { + auto *pItemUIEdit = dynamic_cast(item); + SDL_SetTextInputRect(&item->m_rect); textInputActive = true; #ifdef __SWITCH__ switch_start_text_input("", pItemUIEdit->m_value, pItemUIEdit->m_max_length, /*multiline=*/0); @@ -576,7 +576,7 @@ bool UiValidPlayerName(const char *name) if (*letter < 0x20 || (*letter > 0x7E && *letter < 0xC0)) return false; - const char *const reserved[] = { + const char *const bannedNames[] = { "gvdl", "dvou", "tiju", @@ -592,8 +592,8 @@ bool UiValidPlayerName(const char *name) for (size_t i = 0, n = strlen(tmpname); i < n; i++) tmpname[i]++; - for (uint32_t i = 0; i < sizeof(reserved) / sizeof(*reserved); i++) { - if (strstr(tmpname, reserved[i])) + for (auto bannedName : bannedNames) { + if (strstr(tmpname, bannedName)) return false; } @@ -918,8 +918,8 @@ void LoadPalInMem(const SDL_Color *pPal) void UiRenderItems(std::vector items) { - for (std::size_t i = 0; i < items.size(); i++) - RenderItem(items[i]); + for (auto &item : items) + RenderItem(item); } bool UiItemMouseEvents(SDL_Event *event, std::vector items) @@ -934,8 +934,8 @@ bool UiItemMouseEvents(SDL_Event *event, std::vector items) #endif bool handled = false; - for (std::size_t i = 0; i < items.size(); i++) { - if (HandleMouseEvent(*event, items[i])) { + for (auto &item : items) { + if (HandleMouseEvent(*event, item)) { handled = true; break; } @@ -943,8 +943,7 @@ bool UiItemMouseEvents(SDL_Event *event, std::vector items) if (event->type == SDL_MOUSEBUTTONUP && event->button.button == SDL_BUTTON_LEFT) { scrollBarState.downArrowPressed = scrollBarState.upArrowPressed = false; - for (std::size_t i = 0; i < items.size(); ++i) { - UiItemBase *&item = items[i]; + for (auto &item : items) { if (item->m_type == UI_BUTTON) HandleGlobalMouseUpButton(dynamic_cast(item)); } diff --git a/Source/DiabloUI/dialogs.cpp b/Source/DiabloUI/dialogs.cpp index b34bc8660..aaff61a36 100644 --- a/Source/DiabloUI/dialogs.cpp +++ b/Source/DiabloUI/dialogs.cpp @@ -210,8 +210,7 @@ void Deinit() if (!fontWasLoaded) UnloadTtfFont(); - for (std::size_t i = 0; i < vecOkDialog.size(); i++) { - UiItemBase *pUIItem = vecOkDialog[i]; + for (auto pUIItem : vecOkDialog) { delete pUIItem; } vecOkDialog.clear(); diff --git a/Source/DiabloUI/mainmenu.cpp b/Source/DiabloUI/mainmenu.cpp index e1c9d1c33..9d8740af2 100644 --- a/Source/DiabloUI/mainmenu.cpp +++ b/Source/DiabloUI/mainmenu.cpp @@ -68,16 +68,13 @@ void mainmenu_Free() ArtBackgroundWidescreen.Unload(); ArtBackground.Unload(); - for (std::size_t i = 0; i < vecMainMenuDialog.size(); i++) { - UiItemBase *pUIItem = vecMainMenuDialog[i]; + for (auto pUIItem : vecMainMenuDialog) { delete pUIItem; } vecMainMenuDialog.clear(); - for (std::size_t i = 0; i < vecMenuItems.size(); i++) { - UiListItem *pUIMenuItem = vecMenuItems[i]; - if (pUIMenuItem) - delete pUIMenuItem; + for (auto pUIMenuItem : vecMenuItems) { + delete pUIMenuItem; } vecMenuItems.clear(); } diff --git a/Source/DiabloUI/selconn.cpp b/Source/DiabloUI/selconn.cpp index 78b3c5c0b..253a3c700 100644 --- a/Source/DiabloUI/selconn.cpp +++ b/Source/DiabloUI/selconn.cpp @@ -76,16 +76,13 @@ void selconn_Free() { ArtBackground.Unload(); - for (std::size_t i = 0; i < vecConnItems.size(); i++) { - UiListItem *pUIItem = vecConnItems[i]; + for (auto pUIItem : vecConnItems) { delete pUIItem; } vecConnItems.clear(); - for (std::size_t i = 0; i < vecSelConnDlg.size(); i++) { - UiItemBase *pUIMenuItem = vecSelConnDlg[i]; - if (pUIMenuItem) - delete pUIMenuItem; + for (auto pUIMenuItem : vecSelConnDlg) { + delete pUIMenuItem; } vecSelConnDlg.clear(); } diff --git a/Source/DiabloUI/selgame.cpp b/Source/DiabloUI/selgame.cpp index 8d4721f0b..c1e8011a9 100644 --- a/Source/DiabloUI/selgame.cpp +++ b/Source/DiabloUI/selgame.cpp @@ -41,14 +41,12 @@ std::vector vecSelGameDialog; void selgame_FreeVectors() { - for (std::size_t i = 0; i < vecSelGameDlgItems.size(); i++) { - UiListItem *pUIItem = vecSelGameDlgItems[i]; + for (auto pUIItem : vecSelGameDlgItems) { delete pUIItem; } vecSelGameDlgItems.clear(); - for (std::size_t i = 0; i < vecSelGameDialog.size(); i++) { - UiItemBase *pUIItem = vecSelGameDialog[i]; + for (auto pUIItem : vecSelGameDialog) { delete pUIItem; } vecSelGameDialog.clear(); diff --git a/Source/DiabloUI/selhero.cpp b/Source/DiabloUI/selhero.cpp index e07b3cc06..420c8d485 100644 --- a/Source/DiabloUI/selhero.cpp +++ b/Source/DiabloUI/selhero.cpp @@ -67,8 +67,7 @@ void selhero_UiFocusNavigationYesNo() void selhero_FreeListItems() { - for (std::size_t i = 0; i < vecSelHeroDlgItems.size(); i++) { - UiListItem *pUIItem = vecSelHeroDlgItems[i]; + for (auto pUIItem : vecSelHeroDlgItems) { delete pUIItem; } vecSelHeroDlgItems.clear(); @@ -76,8 +75,7 @@ void selhero_FreeListItems() void selhero_FreeDlgItems() { - for (std::size_t i = 0; i < vecSelDlgItems.size(); i++) { - UiItemBase *pUIItem = vecSelDlgItems[i]; + for (auto pUIItem : vecSelDlgItems) { delete pUIItem; } vecSelDlgItems.clear(); @@ -87,8 +85,7 @@ void selhero_Free() { ArtBackground.Unload(); - for (std::size_t i = 0; i < vecSelHeroDialog.size(); i++) { - UiItemBase *pUIItem = vecSelHeroDialog[i]; + for (auto pUIItem : vecSelHeroDialog) { delete pUIItem; } vecSelHeroDialog.clear(); @@ -150,7 +147,7 @@ bool SelHero_GetHeroInfo(_uiheroinfo *pInfo) void selhero_List_Focus(int value) { - const std::size_t index = static_cast(value); + const auto index = static_cast(value); selhero_ScrollIntoView(index); int baseFlags = UIS_CENTER | UIS_BIG; if (selhero_SaveCount && index < selhero_SaveCount) { @@ -557,7 +554,7 @@ void selhero_List_Init() vecSelDlgItems.push_back(new UiList(vecSelHeroDlgItems, PANEL_LEFT + 265, (UI_OFFSET_Y + 256), 320, 26, UIS_CENTER | UIS_MED | UIS_GOLD)); SDL_Rect rect2 = { (Sint16)(PANEL_LEFT + 585), (Sint16)(UI_OFFSET_Y + 244), 25, 178 }; - UiScrollBar *scrollBar = new UiScrollBar(&ArtScrollBarBackground, &ArtScrollBarThumb, &ArtScrollBarArrow, rect2); + auto *scrollBar = new UiScrollBar(&ArtScrollBarBackground, &ArtScrollBarThumb, &ArtScrollBarArrow, rect2); vecSelDlgItems.push_back(scrollBar); SDL_Rect rect3 = { (Sint16)(PANEL_LEFT + 239), (Sint16)(UI_OFFSET_Y + 429), 120, 35 }; diff --git a/Source/DiabloUI/selok.cpp b/Source/DiabloUI/selok.cpp index 51a6f8701..48c6638cd 100644 --- a/Source/DiabloUI/selok.cpp +++ b/Source/DiabloUI/selok.cpp @@ -23,15 +23,12 @@ void selok_Free() { ArtBackground.Unload(); - for (std::size_t i = 0; i < vecSelOkDialogItems.size(); i++) { - UiListItem *pUIListItem = vecSelOkDialogItems[i]; - if (pUIListItem) - delete pUIListItem; + for (auto pUIListItem : vecSelOkDialogItems) { + delete pUIListItem; } vecSelOkDialogItems.clear(); - for (std::size_t i = 0; i < vecSelOkDialog.size(); i++) { - UiItemBase *pUIItem = vecSelOkDialog[i]; + for (auto pUIItem : vecSelOkDialog) { delete pUIItem; } vecSelOkDialog.clear(); diff --git a/Source/DiabloUI/selyesno.cpp b/Source/DiabloUI/selyesno.cpp index a646634ef..1974e5c6c 100644 --- a/Source/DiabloUI/selyesno.cpp +++ b/Source/DiabloUI/selyesno.cpp @@ -20,15 +20,12 @@ void selyesno_Free() { ArtBackground.Unload(); - for (std::size_t i = 0; i < vecSelYesNoDialogItems.size(); i++) { - UiListItem *pUIListItem = vecSelYesNoDialogItems[i]; - if (pUIListItem) - delete pUIListItem; + for (auto pUIListItem : vecSelYesNoDialogItems) { + delete pUIListItem; } vecSelYesNoDialogItems.clear(); - for (std::size_t i = 0; i < vecSelYesNoDialog.size(); i++) { - UiItemBase *pUIItem = vecSelYesNoDialog[i]; + for (auto pUIItem : vecSelYesNoDialog) { delete pUIItem; } vecSelYesNoDialog.clear(); diff --git a/Source/DiabloUI/title.cpp b/Source/DiabloUI/title.cpp index de5b8e6b1..787ad16bd 100644 --- a/Source/DiabloUI/title.cpp +++ b/Source/DiabloUI/title.cpp @@ -24,8 +24,7 @@ void title_Free() ArtBackgroundWidescreen.Unload(); ArtLogos[LOGO_BIG].Unload(); - for (std::size_t i = 0; i < vecTitleScreen.size(); i++) { - UiItemBase *pUIItem = vecTitleScreen[i]; + for (auto pUIItem : vecTitleScreen) { delete pUIItem; } vecTitleScreen.clear(); diff --git a/Source/automap.cpp b/Source/automap.cpp index e2557c7c7..ced501473 100644 --- a/Source/automap.cpp +++ b/Source/automap.cpp @@ -523,8 +523,8 @@ void InitAutomap() memset(automapview, 0, sizeof(automapview)); for (int y = 0; y < MAXDUNY; y++) { - for (int x = 0; x < MAXDUNX; x++) - dFlags[x][y] &= ~BFLAG_EXPLORED; + for (auto &dFlag : dFlags) + dFlag[y] &= ~BFLAG_EXPLORED; } } diff --git a/Source/codec.cpp b/Source/codec.cpp index a19954617..67bff9af5 100644 --- a/Source/codec.cpp +++ b/Source/codec.cpp @@ -13,12 +13,12 @@ namespace devilution { -typedef struct CodecSignature { +struct CodecSignature { DWORD checksum; BYTE error; BYTE last_chunk_size; WORD unused; -} CodecSignature; +}; #define BLOCKSIZE 64 @@ -26,9 +26,9 @@ static void codec_init_key(const char *pszPassword) { char key[136]; // last 64 bytes are the SHA1 uint32_t rand_state = 0x7058; - for (std::size_t i = 0; i < sizeof(key); ++i) { + for (char ¬ch : key) { rand_state = rand_state * 214013 + 2531011; - key[i] = rand_state >> 16; // Downcasting to char keeps the 2 least-significant bytes + notch = rand_state >> 16; // Downcasting to char keeps the 2 least-significant bytes } char pw[64]; diff --git a/Source/control.cpp b/Source/control.cpp index cdb7858a6..c6924de44 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -38,7 +38,7 @@ BYTE *pDurIcons; BYTE *pChrButtons; bool drawhpflag; bool dropGoldFlag; -bool panbtn[8]; +bool panbtns[8]; bool chrbtn[4]; BYTE *pMultiBtns; BYTE *pPanelButtons; @@ -54,14 +54,14 @@ BYTE *pTalkBtns; bool pstrjust[4]; int pnumlines; bool pinfoflag; -bool talkbtndown[3]; +bool talkButtonsDown[3]; spell_id pSpell; text_color infoclr; int sgbPlrTalkTbl; BYTE *pGBoxBuff; BYTE *pSBkBtnCel; char tempstr[256]; -bool whisper[MAX_PLRS]; +bool whisperList[MAX_PLRS]; int sbooktab; spell_type pSplType; int initialDropGoldIndex; @@ -814,24 +814,24 @@ void InitControlPan() pTalkBtns = LoadFileInMem("CtrlPan\\TalkButt.CEL", nullptr); sgbPlrTalkTbl = 0; sgszTalkMsg[0] = '\0'; - for (unsigned i = 0; i < MAX_PLRS; i++) - whisper[i] = true; - for (unsigned i = 0; i < sizeof(talkbtndown) / sizeof(talkbtndown[0]); i++) - talkbtndown[i] = false; + for (bool &whisper : whisperList) + whisper = true; + for (bool &talkButtonDown : talkButtonsDown) + talkButtonDown = false; } panelflag = false; lvlbtndown = false; pPanelButtons = LoadFileInMem("CtrlPan\\Panel8bu.CEL", nullptr); - for (unsigned i = 0; i < sizeof(panbtn) / sizeof(panbtn[0]); i++) - panbtn[i] = false; + for (bool &panbtn : panbtns) + panbtn = false; panbtndown = false; if (!gbIsMultiplayer) numpanbtns = 6; else numpanbtns = 8; pChrButtons = LoadFileInMem("Data\\CharBut.CEL", nullptr); - for (unsigned i = 0; i < sizeof(chrbtn) / sizeof(chrbtn[0]); i++) - chrbtn[i] = false; + for (bool &buttonEnabled : chrbtn) + buttonEnabled = false; chrbtnactive = false; pDurIcons = LoadFileInMem("Items\\DurIcons.CEL", nullptr); strcpy(infostr, ""); @@ -877,17 +877,17 @@ void DrawCtrlBtns(CelOutputBuffer out) int i; for (i = 0; i < 6; i++) { - if (!panbtn[i]) + if (!panbtns[i]) DrawPanelBox(out, PanBtnPos[i][0], PanBtnPos[i][1] + 16, 71, 20, PanBtnPos[i][0] + PANEL_X, PanBtnPos[i][1] + PANEL_Y); else CelDrawTo(out, PanBtnPos[i][0] + PANEL_X, PanBtnPos[i][1] + PANEL_Y + 18, pPanelButtons, i + 1, 71); } if (numpanbtns == 8) { - CelDrawTo(out, 87 + PANEL_X, 122 + PANEL_Y, pMultiBtns, panbtn[6] + 1, 33); + CelDrawTo(out, 87 + PANEL_X, 122 + PANEL_Y, pMultiBtns, panbtns[6] + 1, 33); if (gbFriendlyMode) - CelDrawTo(out, 527 + PANEL_X, 122 + PANEL_Y, pMultiBtns, panbtn[7] + 3, 33); + CelDrawTo(out, 527 + PANEL_X, 122 + PANEL_Y, pMultiBtns, panbtns[7] + 3, 33); else - CelDrawTo(out, 527 + PANEL_X, 122 + PANEL_Y, pMultiBtns, panbtn[7] + 5, 33); + CelDrawTo(out, 527 + PANEL_X, 122 + PANEL_Y, pMultiBtns, panbtns[7] + 5, 33); } } @@ -961,7 +961,7 @@ void DoPanBtn() int y = PanBtnPos[i][1] + PANEL_TOP + PanBtnPos[i][3]; if (MouseX >= PanBtnPos[i][0] + PANEL_LEFT && MouseX <= x) { if (MouseY >= PanBtnPos[i][1] + PANEL_TOP && MouseY <= y) { - panbtn[i] = true; + panbtns[i] = true; drawbtnflag = true; panbtndown = true; } @@ -981,7 +981,7 @@ void DoPanBtn() void control_set_button_down(int btn_id) { - panbtn[btn_id] = true; + panbtns[btn_id] = true; drawbtnflag = true; panbtndown = true; } @@ -1138,11 +1138,11 @@ void CheckBtnUp() panbtndown = false; for (i = 0; i < 8; i++) { - if (!panbtn[i]) { + if (!panbtns[i]) { continue; } - panbtn[i] = false; + panbtns[i] = false; if (MouseX < PanBtnPos[i][0] + PANEL_LEFT || MouseX > PanBtnPos[i][0] + PANEL_LEFT + PanBtnPos[i][2] @@ -1648,9 +1648,9 @@ void CheckChrBtns() int x, y; if (!chrbtnactive && plr[myplr]._pStatPts) { - for (auto i : enum_values()) { - int max = plr[myplr].GetMaximumAttributeValue(i); - switch (i) { + for (auto attribute : enum_values()) { + int max = plr[myplr].GetMaximumAttributeValue(attribute); + switch (attribute) { case CharacterAttribute::Strength: if (plr[myplr]._pBaseStr >= max) continue; @@ -1670,13 +1670,14 @@ void CheckChrBtns() default: continue; } - x = ChrBtnsRect[static_cast(i)].x + ChrBtnsRect[static_cast(i)].w; - y = ChrBtnsRect[static_cast(i)].y + ChrBtnsRect[static_cast(i)].h; - if (MouseX >= ChrBtnsRect[static_cast(i)].x + auto buttonId = static_cast(attribute); + x = ChrBtnsRect[buttonId].x + ChrBtnsRect[buttonId].w; + y = ChrBtnsRect[buttonId].y + ChrBtnsRect[buttonId].h; + if (MouseX >= ChrBtnsRect[buttonId].x && MouseX <= x - && MouseY >= ChrBtnsRect[static_cast(i)].y + && MouseY >= ChrBtnsRect[buttonId].y && MouseY <= y) { - chrbtn[static_cast(i)] = true; + chrbtn[buttonId] = true; chrbtnactive = true; } } @@ -1693,20 +1694,21 @@ int CapStatPointsToAdd(int remainingStatPoints, const PlayerStruct &player, Char void ReleaseChrBtns(bool addAllStatPoints) { chrbtnactive = false; - for (auto i : enum_values()) { - if (!chrbtn[static_cast(i)]) + for (auto attribute : enum_values()) { + auto buttonId = static_cast(attribute); + if (!chrbtn[buttonId]) continue; - chrbtn[static_cast(i)] = false; - if (MouseX >= ChrBtnsRect[static_cast(i)].x - && MouseX <= ChrBtnsRect[static_cast(i)].x + ChrBtnsRect[static_cast(i)].w - && MouseY >= ChrBtnsRect[static_cast(i)].y - && MouseY <= ChrBtnsRect[static_cast(i)].y + ChrBtnsRect[static_cast(i)].h) { + chrbtn[buttonId] = false; + if (MouseX >= ChrBtnsRect[buttonId].x + && MouseX <= ChrBtnsRect[buttonId].x + ChrBtnsRect[buttonId].w + && MouseY >= ChrBtnsRect[buttonId].y + && MouseY <= ChrBtnsRect[buttonId].y + ChrBtnsRect[buttonId].h) { PlayerStruct &player = plr[myplr]; int statPointsToAdd = 1; if (addAllStatPoints) - statPointsToAdd = CapStatPointsToAdd(player._pStatPts, player, i); - switch (i) { + statPointsToAdd = CapStatPointsToAdd(player._pStatPts, player, attribute); + switch (attribute) { case CharacterAttribute::Strength: NetSendCmdParam1(true, CMD_ADDSTR, statPointsToAdd); player._pStatPts -= statPointsToAdd; @@ -2128,9 +2130,9 @@ void DrawTalkPan(CelOutputBuffer out) if (i == myplr) continue; text_color color = COL_RED; - if (whisper[i]) { + if (whisperList[i]) { color = COL_GOLD; - if (talkbtndown[talk_btn]) { + if (talkButtonsDown[talk_btn]) { if (talk_btn != 0) nCel = 4; else @@ -2142,7 +2144,7 @@ void DrawTalkPan(CelOutputBuffer out) nCel = 2; else nCel = 1; - if (talkbtndown[talk_btn]) + if (talkButtonsDown[talk_btn]) nCel += 4; CelDrawTo(out, 172 + PANEL_X, 84 + 18 * talk_btn + PANEL_Y, pTalkBtns, nCel, 61); } @@ -2169,11 +2171,11 @@ bool control_check_talk_btn() if (MouseY > 123 + PANEL_TOP) return false; - for (unsigned i = 0; i < sizeof(talkbtndown) / sizeof(talkbtndown[0]); i++) { - talkbtndown[i] = false; + for (bool &talkButtonDown : talkButtonsDown) { + talkButtonDown = false; } - talkbtndown[(MouseY - (69 + PANEL_TOP)) / 18] = true; + talkButtonsDown[(MouseY - (69 + PANEL_TOP)) / 18] = true; return true; } @@ -2181,8 +2183,8 @@ bool control_check_talk_btn() void control_release_talk_btn() { if (talkflag) { - for (unsigned i = 0; i < sizeof(talkbtndown) / sizeof(talkbtndown[0]); i++) - talkbtndown[i] = false; + for (bool &talkButtonDown : talkButtonsDown) + talkButtonDown = false; if (MouseX >= 172 + PANEL_LEFT && MouseY >= 69 + PANEL_TOP && MouseX <= 233 + PANEL_LEFT && MouseY <= 123 + PANEL_TOP) { int off = (MouseY - (69 + PANEL_TOP)) / 18; @@ -2192,7 +2194,7 @@ void control_release_talk_btn() off--; } if (p <= MAX_PLRS) - whisper[p - 1] = !whisper[p - 1]; + whisperList[p - 1] = !whisperList[p - 1]; } } } @@ -2203,7 +2205,7 @@ void control_reset_talk_msg(char *msg) pmask = 0; for (i = 0; i < MAX_PLRS; i++) { - if (whisper[i]) + if (whisperList[i]) pmask |= 1 << i; } NetSendCmdString(pmask, sgszTalkMsg); @@ -2220,7 +2222,7 @@ void control_type_message() talkflag = true; sgszTalkMsg[0] = '\0'; for (i = 0; i < 3; i++) { - talkbtndown[i] = false; + talkButtonsDown[i] = false; } sgbPlrTalkTbl = PANEL_HEIGHT + 16; force_redraw = 255; diff --git a/Source/controls/devices/game_controller.cpp b/Source/controls/devices/game_controller.cpp index 9aa717c79..0cbdf34ef 100644 --- a/Source/controls/devices/game_controller.cpp +++ b/Source/controls/devices/game_controller.cpp @@ -187,8 +187,7 @@ void GameController::Remove(SDL_JoystickID instance_id) GameController *GameController::Get(SDL_JoystickID instance_id) { - for (std::size_t i = 0; i < controllers_->size(); ++i) { - GameController &controller = (*controllers_)[i]; + for (auto &controller : *controllers_) { if (controller.instance_id_ == instance_id) return &controller; } @@ -215,8 +214,8 @@ const std::vector &GameController::All() bool GameController::IsPressedOnAnyController(ControllerButton button) { - for (std::size_t i = 0; i < controllers_->size(); ++i) - if ((*controllers_)[i].IsPressed(button)) + for (auto &controller : *controllers_) + if (controller.IsPressed(button)) return true; return false; } diff --git a/Source/controls/devices/joystick.cpp b/Source/controls/devices/joystick.cpp index 90202c13f..e46918c59 100644 --- a/Source/controls/devices/joystick.cpp +++ b/Source/controls/devices/joystick.cpp @@ -289,8 +289,7 @@ const std::vector &Joystick::All() Joystick *Joystick::Get(SDL_JoystickID instance_id) { - for (std::size_t i = 0; i < joysticks_->size(); ++i) { - Joystick &joystick = (*joysticks_)[i]; + for (auto &joystick : *joysticks_) { if (joystick.instance_id_ == instance_id) return &joystick; } @@ -328,8 +327,8 @@ Joystick *Joystick::Get(const SDL_Event &event) bool Joystick::IsPressedOnAnyJoystick(ControllerButton button) { - for (std::size_t i = 0; i < joysticks_->size(); ++i) - if ((*joysticks_)[i].IsPressed(button)) + for (auto &joystick : *joysticks_) + if (joystick.IsPressed(button)) return true; return false; } diff --git a/Source/controls/plrctrls.cpp b/Source/controls/plrctrls.cpp index 217090928..405cf15de 100644 --- a/Source/controls/plrctrls.cpp +++ b/Source/controls/plrctrls.cpp @@ -238,7 +238,7 @@ void FindRangedTarget() void FindMeleeTarget() { - bool visited[MAXDUNX][MAXDUNY] = { { 0 } }; + bool visited[MAXDUNX][MAXDUNY] = { {} }; int maxSteps = 25; // Max steps for FindPath is 25 int rotations = 0; bool canTalk = false; @@ -853,7 +853,7 @@ void StoreMove(AxisDirection move_dir) STextDown(); } -typedef void (*HandleLeftStickOrDPadFn)(devilution::AxisDirection); +using HandleLeftStickOrDPadFn = void (*)(devilution::AxisDirection); HandleLeftStickOrDPadFn GetLeftStickOrDPadGameUIHandler() { @@ -1110,7 +1110,7 @@ void PerformPrimaryAction() && MouseX <= ChrBtnsRect[i].x + ChrBtnsRect[i].w && MouseY >= ChrBtnsRect[i].y && MouseY <= ChrBtnsRect[i].h + ChrBtnsRect[i].y) { - chrbtn[i] = 1; + chrbtn[i] = true; chrbtnactive = true; ReleaseChrBtns(false); } diff --git a/Source/controls/touch.cpp b/Source/controls/touch.cpp index ab0c216c8..f53f9788f 100644 --- a/Source/controls/touch.cpp +++ b/Source/controls/touch.cpp @@ -1,5 +1,5 @@ #ifndef USE_SDL1 -#include +#include #include "options.h" #include "touch.h" @@ -25,7 +25,7 @@ inline T clip(T v, T amin, T amax) #define TOUCH_PORT_MAX_NUM 1 #define NO_TOUCH (-1) // finger id setting if finger is not touching the screen -static void init_touch(void); +static void init_touch(); static void preprocess_events(SDL_Event *event); static void preprocess_finger_down(SDL_Event *event); static void preprocess_finger_up(SDL_Event *event); @@ -52,26 +52,26 @@ enum { // clang-format on }; -typedef struct { +struct Touch { int id; // -1: not touching uint32_t time_last_down; int last_x; // last known screen coordinates int last_y; // last known screen coordinates float last_down_x; // SDL touch coordinates when last pressed down float last_down_y; // SDL touch coordinates when last pressed down -} Touch; +}; static Touch finger[TOUCH_PORT_MAX_NUM][MAX_NUM_FINGERS]; // keep track of finger status -typedef enum { +enum DraggingType { DRAG_NONE, DRAG_TWO_FINGER, DRAG_THREE_FINGER, -} DraggingType; +}; static DraggingType multi_finger_dragging[TOUCH_PORT_MAX_NUM]; // keep track whether we are currently drag-and-dropping -static void init_touch(void) +static void init_touch() { for (int port = 0; port < TOUCH_PORT_MAX_NUM; port++) { for (int i = 0; i < MAX_NUM_FINGERS; i++) { @@ -80,9 +80,9 @@ static void init_touch(void) multi_finger_dragging[port] = DRAG_NONE; } - for (int port = 0; port < TOUCH_PORT_MAX_NUM; port++) { - for (int i = 0; i < 2; i++) { - simulated_click_start_time[port][i] = 0; + for (auto &port : simulated_click_start_time) { + for (unsigned int &time : port) { + time = 0; } } @@ -250,7 +250,7 @@ static void preprocess_finger_up(SDL_Event *event) // but only if the finger hasn't moved since it was pressed down by more than MAX_TAP_MOTION_DISTANCE pixels float xrel = ((event->tfinger.x * devilution::GetOutputSurface()->w) - (finger[port][i].last_down_x * devilution::GetOutputSurface()->w)); float yrel = ((event->tfinger.y * devilution::GetOutputSurface()->h) - (finger[port][i].last_down_y * devilution::GetOutputSurface()->h)); - float max_r_squared = (float)(MAX_TAP_MOTION_DISTANCE * MAX_TAP_MOTION_DISTANCE); + auto max_r_squared = static_cast(MAX_TAP_MOTION_DISTANCE * MAX_TAP_MOTION_DISTANCE); if ((xrel * xrel + yrel * yrel) >= max_r_squared) { continue; } @@ -440,14 +440,14 @@ void finish_simulated_mouse_clicks(int current_mouse_x, int current_mouse_y) mouse_x = current_mouse_x; mouse_y = current_mouse_y; - for (int port = 0; port < TOUCH_PORT_MAX_NUM; port++) { + for (auto &port : simulated_click_start_time) { for (int i = 0; i < 2; i++) { - if (simulated_click_start_time[port][i] == 0) { + if (port[i] == 0) { continue; } Uint32 current_time = SDL_GetTicks(); - if (current_time - simulated_click_start_time[port][i] < SIMULATED_CLICK_DURATION) { + if (current_time - port[i] < SIMULATED_CLICK_DURATION) { continue; } @@ -461,7 +461,7 @@ void finish_simulated_mouse_clicks(int current_mouse_x, int current_mouse_y) set_mouse_button_event(&ev, SDL_MOUSEBUTTONUP, simulated_button, mouse_x, mouse_y); SDL_PushEvent(&ev); - simulated_click_start_time[port][i] = 0; + port[i] = 0; } } } diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 384cf10e5..2af231886 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -1492,7 +1492,7 @@ static void PressChar(WPARAM vkey) return; case 'a': if (debug_mode_key_inverted_v) { - spelldata[SPL_TELEPORT].sTownSpell = 1; + spelldata[SPL_TELEPORT].sTownSpell = true; plr[myplr]._pSplLvl[plr[myplr]._pSpell]++; } return; diff --git a/Source/drlg_l1.cpp b/Source/drlg_l1.cpp index 1365c76d3..e7f25b8e1 100644 --- a/Source/drlg_l1.cpp +++ b/Source/drlg_l1.cpp @@ -1421,7 +1421,7 @@ static void L5firstRoom() VR3 = random_(0, 2); if (VR1 + VR3 <= 1) - VR2 = 1; + VR2 = true; if (VR1) L5drawRoom(15, 1, 10, 10); else @@ -1491,9 +1491,9 @@ static void L5firstRoom() if (HR3) L5roomGen(29, 15, 10, 10, 1); - VR3 = 0; - VR2 = 0; - VR1 = 0; + VR3 = false; + VR2 = false; + VR1 = false; } } @@ -2071,21 +2071,21 @@ static void L5FillChambers() int c; if (HR1) - DRLG_L5GChamber(0, 14, 0, 0, 0, 1); + DRLG_L5GChamber(0, 14, false, false, false, true); if (HR2) { if (HR1 && !HR3) - DRLG_L5GChamber(14, 14, 0, 0, 1, 0); + DRLG_L5GChamber(14, 14, false, false, true, false); if (!HR1 && HR3) - DRLG_L5GChamber(14, 14, 0, 0, 0, 1); + DRLG_L5GChamber(14, 14, false, false, false, true); if (HR1 && HR3) - DRLG_L5GChamber(14, 14, 0, 0, 1, 1); + DRLG_L5GChamber(14, 14, false, false, true, true); if (!HR1 && !HR3) - DRLG_L5GChamber(14, 14, 0, 0, 0, 0); + DRLG_L5GChamber(14, 14, false, false, false, false); } if (HR3) - DRLG_L5GChamber(28, 14, 0, 0, 1, 0); + DRLG_L5GChamber(28, 14, false, false, true, false); if (HR1 && HR2) DRLG_L5GHall(12, 18, 14, 18); if (HR2 && HR3) @@ -2093,21 +2093,21 @@ static void L5FillChambers() if (HR1 && !HR2 && HR3) DRLG_L5GHall(12, 18, 28, 18); if (VR1) - DRLG_L5GChamber(14, 0, 0, 1, 0, 0); + DRLG_L5GChamber(14, 0, false, true, false, false); if (VR2) { if (VR1 && !VR3) - DRLG_L5GChamber(14, 14, 1, 0, 0, 0); + DRLG_L5GChamber(14, 14, true, false, false, false); if (!VR1 && VR3) - DRLG_L5GChamber(14, 14, 0, 1, 0, 0); + DRLG_L5GChamber(14, 14, false, true, false, false); if (VR1 && VR3) - DRLG_L5GChamber(14, 14, 1, 1, 0, 0); + DRLG_L5GChamber(14, 14, true, true, false, false); if (!VR1 && !VR3) - DRLG_L5GChamber(14, 14, 0, 0, 0, 0); + DRLG_L5GChamber(14, 14, false, false, false, false); } if (VR3) - DRLG_L5GChamber(14, 28, 1, 0, 0, 0); + DRLG_L5GChamber(14, 28, true, false, false, false); if (VR1 && VR2) DRLG_L5GHall(18, 12, 18, 14); if (VR2 && VR3) diff --git a/Source/drlg_l2.cpp b/Source/drlg_l2.cpp index bd450ad69..817a3baef 100644 --- a/Source/drlg_l2.cpp +++ b/Source/drlg_l2.cpp @@ -2116,15 +2116,15 @@ static void CreateRoom(int nX1, int nY1, int nX2, int nY2, int nRDest, int nHDir } if (nRh > nRw) { - CreateRoom(nX1 + 2, nY1 + 2, nRx1 - 2, nRy2 - 2, nRid, 2, 0, 0, 0); - CreateRoom(nRx2 + 2, nRy1 + 2, nX2 - 2, nY2 - 2, nRid, 4, 0, 0, 0); - CreateRoom(nX1 + 2, nRy2 + 2, nRx2 - 2, nY2 - 2, nRid, 1, 0, 0, 0); - CreateRoom(nRx1 + 2, nY1 + 2, nX2 - 2, nRy1 - 2, nRid, 3, 0, 0, 0); + CreateRoom(nX1 + 2, nY1 + 2, nRx1 - 2, nRy2 - 2, nRid, 2, false, 0, 0); + CreateRoom(nRx2 + 2, nRy1 + 2, nX2 - 2, nY2 - 2, nRid, 4, false, 0, 0); + CreateRoom(nX1 + 2, nRy2 + 2, nRx2 - 2, nY2 - 2, nRid, 1, false, 0, 0); + CreateRoom(nRx1 + 2, nY1 + 2, nX2 - 2, nRy1 - 2, nRid, 3, false, 0, 0); } else { - CreateRoom(nX1 + 2, nY1 + 2, nRx2 - 2, nRy1 - 2, nRid, 3, 0, 0, 0); - CreateRoom(nRx1 + 2, nRy2 + 2, nX2 - 2, nY2 - 2, nRid, 1, 0, 0, 0); - CreateRoom(nX1 + 2, nRy1 + 2, nRx1 - 2, nY2 - 2, nRid, 2, 0, 0, 0); - CreateRoom(nRx2 + 2, nY1 + 2, nX2 - 2, nRy2 - 2, nRid, 4, 0, 0, 0); + CreateRoom(nX1 + 2, nY1 + 2, nRx2 - 2, nRy1 - 2, nRid, 3, false, 0, 0); + CreateRoom(nRx1 + 2, nRy2 + 2, nX2 - 2, nY2 - 2, nRid, 1, false, 0, 0); + CreateRoom(nX1 + 2, nRy1 + 2, nRx1 - 2, nY2 - 2, nRid, 2, false, 0, 0); + CreateRoom(nRx2 + 2, nY1 + 2, nX2 - 2, nRy2 - 2, nRid, 4, false, 0, 0); } } @@ -3035,7 +3035,7 @@ void L2LockoutFix() } if ((dungeon[i][j] == 2 || dungeon[i][j] == 5) && dungeon[i][j - 1] == 3 && dungeon[i][j + 1] == 3) { doorok = false; - while (1) { + while (true) { if (dungeon[i][j] != 2 && dungeon[i][j] != 5) { break; } @@ -3060,7 +3060,7 @@ void L2LockoutFix() } if ((dungeon[j][i] == 1 || dungeon[j][i] == 4) && dungeon[j - 1][i] == 3 && dungeon[j + 1][i] == 3) { doorok = false; - while (1) { + while (true) { if (dungeon[j][i] != 1 && dungeon[j][i] != 4) { break; } diff --git a/Source/dvlnet/abstract_net.cpp b/Source/dvlnet/abstract_net.cpp index f3827fe49..72be2b237 100644 --- a/Source/dvlnet/abstract_net.cpp +++ b/Source/dvlnet/abstract_net.cpp @@ -10,8 +10,7 @@ #include "dvlnet/loopback.h" #include "storm/storm.h" -namespace devilution { -namespace net { +namespace devilution::net { std::unique_ptr abstract_net::make_net(provider_t provider) { @@ -31,5 +30,4 @@ std::unique_ptr abstract_net::make_net(provider_t provider) #endif } -} // namespace net -} // namespace devilution +} // namespace devilution::net diff --git a/Source/dvlnet/base.cpp b/Source/dvlnet/base.cpp index e05f31531..3b4ffc88a 100644 --- a/Source/dvlnet/base.cpp +++ b/Source/dvlnet/base.cpp @@ -2,9 +2,9 @@ #include #include +#include -namespace devilution { -namespace net { +namespace devilution::net { void base::setup_gameinfo(buffer_t info) { @@ -13,7 +13,7 @@ void base::setup_gameinfo(buffer_t info) void base::setup_password(std::string pw) { - pktfty.reset(new packet_factory(pw)); + pktfty = std::make_unique(pw); } void base::run_event_handler(_SNETEVENT &ev) @@ -263,5 +263,4 @@ bool base::SNetGetTurnsInTransit(DWORD *turns) return true; } -} // namespace net -} // namespace devilution +} // namespace devilution::net diff --git a/Source/dvlnet/base_protocol.cpp b/Source/dvlnet/base_protocol.cpp index 5c8394802..4d69930e6 100644 --- a/Source/dvlnet/base_protocol.cpp +++ b/Source/dvlnet/base_protocol.cpp @@ -6,9 +6,3 @@ #ifdef USE_SDL1 #include "utils/sdl2_to_1_2_backports.h" #endif - -namespace devilution { -namespace net { - -} // namespace net -} // namespace devilution diff --git a/Source/dvlnet/frame_queue.cpp b/Source/dvlnet/frame_queue.cpp index f27088343..81fd54f69 100644 --- a/Source/dvlnet/frame_queue.cpp +++ b/Source/dvlnet/frame_queue.cpp @@ -4,8 +4,7 @@ #include "dvlnet/packet.h" -namespace devilution { -namespace net { +namespace devilution::net { framesize_t frame_queue::size() { @@ -78,5 +77,4 @@ buffer_t frame_queue::make_frame(buffer_t packetbuf) return ret; } -} // namespace net -} // namespace devilution +} // namespace devilution::net diff --git a/Source/dvlnet/loopback.cpp b/Source/dvlnet/loopback.cpp index ea053fb8f..7c4619b4e 100644 --- a/Source/dvlnet/loopback.cpp +++ b/Source/dvlnet/loopback.cpp @@ -1,8 +1,7 @@ #include "dvlnet/loopback.h" #include "utils/stubs.h" -namespace devilution { -namespace net { +namespace devilution::net { int loopback::create(std::string addrstr, std::string passwd) { @@ -29,7 +28,7 @@ bool loopback::SNetReceiveMessage(int *sender, char **data, int *size) bool loopback::SNetSendMessage(int dest, void *data, unsigned int size) { if (dest == plr_single || dest == SNPLAYER_ALL) { - unsigned char *raw_message = reinterpret_cast(data); + auto *raw_message = reinterpret_cast(data); buffer_t message(raw_message, raw_message + size); message_queue.push(message); } @@ -112,5 +111,4 @@ std::string loopback::make_default_gamename() return std::string("loopback"); } -} // namespace net -} // namespace devilution +} // namespace devilution::net diff --git a/Source/dvlnet/packet.cpp b/Source/dvlnet/packet.cpp index 933bdd468..223c20feb 100644 --- a/Source/dvlnet/packet.cpp +++ b/Source/dvlnet/packet.cpp @@ -1,7 +1,6 @@ #include "dvlnet/packet.h" -namespace devilution { -namespace net { +namespace devilution::net { #ifndef NONET static constexpr bool disable_encryption = false; @@ -234,5 +233,4 @@ packet_factory::packet_factory(std::string pw) #endif } -} // namespace net -} // namespace devilution +} // namespace devilution::net diff --git a/Source/dvlnet/protocol_zt.cpp b/Source/dvlnet/protocol_zt.cpp index 1406792a0..1732e6c43 100644 --- a/Source/dvlnet/protocol_zt.cpp +++ b/Source/dvlnet/protocol_zt.cpp @@ -17,8 +17,7 @@ #include "dvlnet/zerotier_native.h" -namespace devilution { -namespace net { +namespace devilution::net { protocol_zt::protocol_zt() { @@ -265,9 +264,9 @@ void protocol_zt::close_all() lwip_close(fd_udp); fd_udp = -1; } - for (auto &i : peer_list) { - if (i.second.fd != -1) - lwip_close(i.second.fd); + for (auto &peer : peer_list) { + if (peer.second.fd != -1) + lwip_close(peer.second.fd); } peer_list.clear(); } @@ -284,7 +283,7 @@ void protocol_zt::endpoint::from_string(const std::string &str) return; if (!IP_IS_V6_VAL(a)) return; - const unsigned char *r = reinterpret_cast(a.u_addr.ip6.addr); + const auto *r = reinterpret_cast(a.u_addr.ip6.addr); std::copy(r, r + 16, addr.begin()); } @@ -305,5 +304,4 @@ std::string protocol_zt::make_default_gamename() return ret; } -} // namespace net -} // namespace devilution +} // namespace devilution::net diff --git a/Source/dvlnet/tcp_client.cpp b/Source/dvlnet/tcp_client.cpp index a8459378f..c9c0473c4 100644 --- a/Source/dvlnet/tcp_client.cpp +++ b/Source/dvlnet/tcp_client.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -11,14 +12,13 @@ #include -namespace devilution { -namespace net { +namespace devilution::net { int tcp_client::create(std::string addrstr, std::string passwd) { try { auto port = sgOptions.Network.nPort; - local_server.reset(new tcp_server(ioc, addrstr, port, passwd)); + local_server = std::make_unique(ioc, addrstr, port, passwd); return join(local_server->localhost_self(), passwd); } catch (std::system_error &e) { SDL_SetError("%s", e.what()); @@ -136,5 +136,4 @@ tcp_client::~tcp_client() { } -} // namespace net -} // namespace devilution +} // namespace devilution::net diff --git a/Source/dvlnet/tcp_server.cpp b/Source/dvlnet/tcp_server.cpp index 914859b72..b81246e2c 100644 --- a/Source/dvlnet/tcp_server.cpp +++ b/Source/dvlnet/tcp_server.cpp @@ -2,11 +2,11 @@ #include #include +#include #include "dvlnet/base.h" -namespace devilution { -namespace net { +namespace devilution::net { tcp_server::tcp_server(asio::io_context &ioc, std::string bindaddr, unsigned short port, std::string pw) @@ -15,7 +15,7 @@ tcp_server::tcp_server(asio::io_context &ioc, std::string bindaddr, { auto addr = asio::ip::address::from_string(bindaddr); auto ep = asio::ip::tcp::endpoint(addr, port); - acceptor.reset(new asio::ip::tcp::acceptor(ioc, ep, true)); + acceptor = std::make_unique(ioc, ep, true); start_accept(); } @@ -222,5 +222,4 @@ tcp_server::~tcp_server() { } -} // namespace net -} // namespace devilution +} // namespace devilution::net diff --git a/Source/dvlnet/zerotier_lwip.cpp b/Source/dvlnet/zerotier_lwip.cpp index 25d4636a8..a4a5633a7 100644 --- a/Source/dvlnet/zerotier_lwip.cpp +++ b/Source/dvlnet/zerotier_lwip.cpp @@ -15,13 +15,12 @@ #include "dvlnet/zerotier_native.h" -namespace devilution { -namespace net { +namespace devilution::net { void print_ip6_addr(void *x) { char ipstr[INET6_ADDRSTRLEN]; - struct sockaddr_in6 *in = (struct sockaddr_in6 *)x; + auto *in = static_cast(x); lwip_inet_ntop(AF_INET6, &(in->sin6_addr), ipstr, INET6_ADDRSTRLEN); SDL_Log("ZeroTier: ZTS_EVENT_ADDR_NEW_IP6, addr=%s\n", ipstr); } @@ -36,5 +35,4 @@ void zt_ip6setup() UNLOCK_TCPIP_CORE(); } -} // namespace net -} // namespace devilution +} // namespace devilution::net diff --git a/Source/dvlnet/zerotier_native.cpp b/Source/dvlnet/zerotier_native.cpp index 8aaab60d4..588b1f60d 100644 --- a/Source/dvlnet/zerotier_native.cpp +++ b/Source/dvlnet/zerotier_native.cpp @@ -16,8 +16,7 @@ #include "dvlnet/zerotier_lwip.h" -namespace devilution { -namespace net { +namespace devilution::net { //static constexpr uint64_t zt_earth = 0x8056c2e21c000001; static constexpr uint64_t zt_network = 0xaf78bf943649eb12; @@ -67,5 +66,4 @@ void zerotier_network_start() std::atexit(zerotier_network_stop); } -} // namespace net -} // namespace devilution +} // namespace devilution::net diff --git a/Source/error.cpp b/Source/error.cpp index 19be18533..028858b8c 100644 --- a/Source/error.cpp +++ b/Source/error.cpp @@ -95,8 +95,8 @@ void InitDiabloMsg(diablo_message e) void ClrDiabloMsg() { - for (unsigned i = 0; i < sizeof(msgtable); i++) - msgtable[i] = EMSG_NONE; + for (auto &msg : msgtable) + msg = EMSG_NONE; msgflag = EMSG_NONE; msgcnt = 0; diff --git a/Source/inv.cpp b/Source/inv.cpp index 4d1eb8369..149f960df 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -428,10 +428,10 @@ bool AutoPlaceItemInBelt(int playerNumber, const ItemStruct &item, bool persistI return false; } - for (int i = 0; i < MAXBELTITEMS; i++) { - if (plr[playerNumber].SpdList[i].isEmpty()) { + for (auto &beltItem : plr[playerNumber].SpdList) { + if (beltItem.isEmpty()) { if (persistItem) { - plr[playerNumber].SpdList[i] = item; + beltItem = item; CalcPlrScrolls(playerNumber); drawsbarflag = true; } @@ -1935,7 +1935,7 @@ int FindGetItem(int idx, WORD ci, int iseed) int ii; int i = 0; - while (1) { + while (true) { ii = itemactive[i]; if (items[ii].IDidx == idx && items[ii]._iSeed == iseed && items[ii]._iCreateInfo == ci) break; @@ -2097,7 +2097,7 @@ int InvPutItem(int pnum, int x, int y) yp = cursmy; xp = cursmx; if (plr[pnum].HoldItem._iCurs == ICURS_RUNE_BOMB && xp >= 79 && xp <= 82 && yp >= 61 && yp <= 64) { - NetSendCmdLocParam2(0, CMD_OPENHIVE, plr[pnum]._px, plr[pnum]._py, xx, yy); + NetSendCmdLocParam2(false, CMD_OPENHIVE, plr[pnum]._px, plr[pnum]._py, xx, yy); quests[Q_FARMER]._qactive = QUEST_DONE; if (gbIsMultiplayer) { NetSendCmdQuest(true, Q_FARMER); @@ -2128,7 +2128,7 @@ int InvPutItem(int pnum, int x, int y) if (currlevel == 21 && x == CornerStone.x && y == CornerStone.y) { CornerStone.item = items[ii]; InitQTextMsg(TEXT_CORNSTN); - quests[Q_CORNSTN]._qlog = 0; + quests[Q_CORNSTN]._qlog = false; quests[Q_CORNSTN]._qactive = QUEST_DONE; } @@ -2215,7 +2215,7 @@ int SyncPutItem(int pnum, int x, int y, int idx, WORD icreateinfo, int iseed, in if (currlevel == 21 && x == CornerStone.x && y == CornerStone.y) { CornerStone.item = items[ii]; InitQTextMsg(TEXT_CORNSTN); - quests[Q_CORNSTN]._qlog = 0; + quests[Q_CORNSTN]._qlog = false; quests[Q_CORNSTN]._qactive = QUEST_DONE; } return ii; diff --git a/Source/items.cpp b/Source/items.cpp index 702669340..3b486609a 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -4,8 +4,8 @@ * Implementation of item functionality. */ #include -#include -#include +#include +#include #include "cursor.h" #include "doom.h" @@ -38,7 +38,7 @@ ItemStruct items[MAXITEMS + 1]; bool itemhold[3][3]; CornerStoneStruct CornerStone; BYTE *itemanims[ITEMTYPES]; -bool UniqueItemFlag[128]; +bool UniqueItemFlags[128]; int numitems; int gnNumGetRecords; @@ -409,7 +409,7 @@ void InitItemGFX() sprintf(arglist, "Items\\%s.CEL", ItemDropNames[i]); itemanims[i] = LoadFileInMem(arglist, nullptr); } - memset(UniqueItemFlag, 0, sizeof(UniqueItemFlag)); + memset(UniqueItemFlags, 0, sizeof(UniqueItemFlags)); } bool ItemPlace(int xp, int yp) @@ -2483,7 +2483,7 @@ _unique_items CheckUnique(int i, int lvl, int uper, bool recreate) break; if (UniqueItemList[j].UIItemId == AllItemsList[items[i].IDidx].iItemId && lvl >= UniqueItemList[j].UIMinLvl - && (recreate || !UniqueItemFlag[j] || gbIsMultiplayer)) { + && (recreate || !UniqueItemFlags[j] || gbIsMultiplayer)) { uok[j] = true; numu++; } @@ -2509,7 +2509,7 @@ _unique_items CheckUnique(int i, int lvl, int uper, bool recreate) void GetUniqueItem(int i, _unique_items uid) { - UniqueItemFlag[uid] = true; + UniqueItemFlags[uid] = true; SaveItemPower(i, UniqueItemList[uid].UIPower1, UniqueItemList[uid].UIParam1, UniqueItemList[uid].UIParam2, 0, 0, 1); if (UniqueItemList[uid].UINumPL > 1) @@ -2912,7 +2912,7 @@ void SpawnQuestItem(int itemid, int x, int y, int randarea, int selflag) { if (randarea) { int tries = 0; - while (1) { + while (true) { tries++; if (tries > 1000 && randarea > 1) randarea--; @@ -3106,8 +3106,8 @@ void ProcessItems() void FreeItemGFX() { - for (int i = 0; i < ITEMTYPES; i++) { - MemFreeDbg(itemanims[i]); + for (auto &itemanim : itemanims) { + MemFreeDbg(itemanim); } } @@ -4540,10 +4540,10 @@ static void SpawnOnePremium(int i, int plvl, int myplr) || items[0]._iMinDex > dexterity || items[0]._iIvalue < ivalue) && count < 150)); - premiumitem[i] = items[0]; - premiumitem[i]._iCreateInfo = plvl | CF_SMITHPREMIUM; - premiumitem[i]._iIdentified = true; - premiumitem[i]._iStatFlag = StoreStatOk(&premiumitem[i]); + premiumitems[i] = items[0]; + premiumitems[i]._iCreateInfo = plvl | CF_SMITHPREMIUM; + premiumitems[i]._iIdentified = true; + premiumitems[i]._iStatFlag = StoreStatOk(&premiumitems[i]); items[0] = holditem; } @@ -4555,7 +4555,7 @@ void SpawnPremium(int pnum) int maxItems = gbIsHellfire ? SMITH_PREMIUM_ITEMS : 6; if (numpremium < maxItems) { for (i = 0; i < maxItems; i++) { - if (premiumitem[i].isEmpty()) { + if (premiumitems[i].isEmpty()) { int plvl = premiumlevel + (gbIsHellfire ? premiumLvlAddHellfire[i] : premiumlvladd[i]); SpawnOnePremium(i, plvl, pnum); } @@ -4565,27 +4565,27 @@ void SpawnPremium(int pnum) while (premiumlevel < lvl) { premiumlevel++; if (gbIsHellfire) { - premiumitem[0] = premiumitem[3]; - premiumitem[1] = premiumitem[4]; - premiumitem[2] = premiumitem[5]; - premiumitem[3] = premiumitem[6]; - premiumitem[4] = premiumitem[7]; - premiumitem[5] = premiumitem[8]; - premiumitem[6] = premiumitem[9]; - premiumitem[7] = premiumitem[10]; - premiumitem[8] = premiumitem[11]; - premiumitem[9] = premiumitem[12]; + premiumitems[0] = premiumitems[3]; + premiumitems[1] = premiumitems[4]; + premiumitems[2] = premiumitems[5]; + premiumitems[3] = premiumitems[6]; + premiumitems[4] = premiumitems[7]; + premiumitems[5] = premiumitems[8]; + premiumitems[6] = premiumitems[9]; + premiumitems[7] = premiumitems[10]; + premiumitems[8] = premiumitems[11]; + premiumitems[9] = premiumitems[12]; SpawnOnePremium(10, premiumlevel + premiumLvlAddHellfire[10], pnum); - premiumitem[11] = premiumitem[13]; + premiumitems[11] = premiumitems[13]; SpawnOnePremium(12, premiumlevel + premiumLvlAddHellfire[12], pnum); - premiumitem[13] = premiumitem[14]; + premiumitems[13] = premiumitems[14]; SpawnOnePremium(14, premiumlevel + premiumLvlAddHellfire[14], pnum); } else { - premiumitem[0] = premiumitem[2]; - premiumitem[1] = premiumitem[3]; - premiumitem[2] = premiumitem[4]; + premiumitems[0] = premiumitems[2]; + premiumitems[1] = premiumitems[3]; + premiumitems[2] = premiumitems[4]; SpawnOnePremium(3, premiumlevel + premiumlvladd[3], pnum); - premiumitem[4] = premiumitem[5]; + premiumitems[4] = premiumitems[5]; SpawnOnePremium(5, premiumlevel + premiumlvladd[5], pnum); } } @@ -5125,8 +5125,8 @@ void RecalcStoreStats() } } for (i = 0; i < SMITH_PREMIUM_ITEMS; i++) { - if (!premiumitem[i].isEmpty()) { - premiumitem[i]._iStatFlag = StoreStatOk(&premiumitem[i]); + if (!premiumitems[i].isEmpty()) { + premiumitems[i]._iStatFlag = StoreStatOk(&premiumitems[i]); } } for (i = 0; i < 20; i++) { diff --git a/Source/items.h b/Source/items.h index 11d309992..90b5d1d86 100644 --- a/Source/items.h +++ b/Source/items.h @@ -368,7 +368,7 @@ extern bool uitemflag; extern int itemavail[MAXITEMS]; extern ItemStruct items[MAXITEMS + 1]; extern CornerStoneStruct CornerStone; -extern bool UniqueItemFlag[128]; +extern bool UniqueItemFlags[128]; extern int numitems; BYTE GetOutlineColor(ItemStruct &item, bool checkReq); diff --git a/Source/lighting.cpp b/Source/lighting.cpp index 9610da6ec..c505655d4 100644 --- a/Source/lighting.cpp +++ b/Source/lighting.cpp @@ -12,7 +12,7 @@ namespace devilution { LightListStruct VisionList[MAXVISION]; -BYTE lightactive[MAXLIGHTS]; +uint8_t lightactive[MAXLIGHTS]; LightListStruct LightList[MAXLIGHTS]; int numlights; BYTE lightradius[16][128]; diff --git a/Source/lighting.h b/Source/lighting.h index adf2ea9b9..493335b1b 100644 --- a/Source/lighting.h +++ b/Source/lighting.h @@ -30,7 +30,7 @@ struct LightListStruct { }; extern LightListStruct VisionList[MAXVISION]; -extern BYTE lightactive[MAXLIGHTS]; +extern uint8_t lightactive[MAXLIGHTS]; extern LightListStruct LightList[MAXLIGHTS]; extern int numlights; extern int numvision; diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index 58ff33d48..a6fbee43b 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -5,7 +5,7 @@ */ #include "loadsave.h" -#include +#include #include "automap.h" #include "codec.h" @@ -312,8 +312,8 @@ static void LoadPlayer(LoadHelper *file, int p) pPlayer->_pmode = static_cast(file->nextLE()); - for (int i = 0; i < MAX_PATH_LENGTH; i++) { - pPlayer->walkpath[i] = file->nextLE(); + for (int8_t &step : pPlayer->walkpath) { + step = file->nextLE(); } pPlayer->plractive = file->nextBool8(); file->skip(2); // Alignment @@ -363,18 +363,18 @@ static void LoadPlayer(LoadHelper *file, int p) file->skip(3); // Alignment pPlayer->_pSBkSpell = static_cast(file->nextLE()); pPlayer->_pSBkSplType = static_cast(file->nextLE()); - for (int i = 0; i < 64; i++) - pPlayer->_pSplLvl[i] = file->nextLE(); + for (int8_t &spellLevel : pPlayer->_pSplLvl) + spellLevel = file->nextLE(); file->skip(7); // Alignment pPlayer->_pMemSpells = file->nextLE(); pPlayer->_pAblSpells = file->nextLE(); pPlayer->_pScrlSpells = file->nextLE(); pPlayer->_pSpellFlags = file->nextLE(); file->skip(3); // Alignment - for (int i = 0; i < 4; i++) - pPlayer->_pSplHotKey[i] = static_cast(file->nextLE()); - for (int i = 0; i < 4; i++) - pPlayer->_pSplTHotKey[i] = static_cast(file->nextLE()); + for (auto &spell : pPlayer->_pSplHotKey) + spell = static_cast(file->nextLE()); + for (auto &spellType : pPlayer->_pSplTHotKey) + spellType = static_cast(file->nextLE()); pPlayer->_pwtype = static_cast(file->nextLE()); pPlayer->_pBlockFlag = file->nextBool8(); @@ -466,8 +466,8 @@ static void LoadPlayer(LoadHelper *file, int p) LoadItems(file, NUM_INVLOC, pPlayer->InvBody); LoadItems(file, NUM_INV_GRID_ELEM, pPlayer->InvList); pPlayer->_pNumInv = file->nextLE(); - for (int i = 0; i < NUM_INV_GRID_ELEM; i++) - pPlayer->InvGrid[i] = file->nextLE(); + for (int8_t &cell : pPlayer->InvGrid) + cell = file->nextLE(); LoadItems(file, MAXBELTITEMS, pPlayer->SpdList); LoadItemData(file, &pPlayer->HoldItem); @@ -735,7 +735,7 @@ static void LoadItem(LoadHelper *file, int i) static void LoadPremium(LoadHelper *file, int i) { - LoadItemData(file, &premiumitem[i]); + LoadItemData(file, &premiumitems[i]); } static void LoadQuest(LoadHelper *file, int i) @@ -876,17 +876,17 @@ static void ConvertLevels() } setlevel = true; // Convert quest levels - for (int i = 0; i < MAXQUESTS; i++) { - if (quests[i]._qactive == QUEST_NOTAVAIL) { + for (auto &quest : quests) { + if (quest._qactive == QUEST_NOTAVAIL) { continue; } - leveltype = quests[i]._qlvltype; + leveltype = quest._qlvltype; if (leveltype == DTYPE_NONE) { continue; } - setlvlnum = quests[i]._qslvl; + setlvlnum = quest._qslvl; if (!LevelFileExists()) continue; @@ -909,14 +909,11 @@ void LoadHotkeys() if (!file.isValid()) return; - const size_t nHotkeyTypes = sizeof(plr[myplr]._pSplHotKey) / sizeof(plr[myplr]._pSplHotKey[0]); - const size_t nHotkeySpells = sizeof(plr[myplr]._pSplTHotKey) / sizeof(plr[myplr]._pSplTHotKey[0]); - - for (size_t i = 0; i < nHotkeyTypes; i++) { - plr[myplr]._pSplHotKey[i] = static_cast(file.nextLE()); + for (auto &spellId : plr[myplr]._pSplHotKey) { + spellId = static_cast(file.nextLE()); } - for (size_t i = 0; i < nHotkeySpells; i++) { - plr[myplr]._pSplTHotKey[i] = static_cast(file.nextLE()); + for (auto &spellType : plr[myplr]._pSplTHotKey) { + spellType = static_cast(file.nextLE()); } plr[myplr]._pRSpell = static_cast(file.nextLE()); plr[myplr]._pRSplType = static_cast(file.nextLE()); @@ -929,11 +926,11 @@ void SaveHotkeys() SaveHelper file("hotkeys", (nHotkeyTypes * 4) + nHotkeySpells + 4 + 1); - for (size_t i = 0; i < nHotkeyTypes; i++) { - file.writeLE(plr[myplr]._pSplHotKey[i]); + for (auto &spellId : plr[myplr]._pSplHotKey) { + file.writeLE(spellId); } - for (size_t i = 0; i < nHotkeySpells; i++) { - file.writeLE(plr[myplr]._pSplTHotKey[i]); + for (auto &spellType : plr[myplr]._pSplTHotKey) { + file.writeLE(spellType); } file.writeLE(plr[myplr]._pRSpell); file.writeLE(plr[myplr]._pRSplType); @@ -1066,24 +1063,24 @@ void LoadGame(bool firstflag) nummissiles = _nummissiles; nobjects = _nobjects; - for (int i = 0; i < MAXMONSTERS; i++) - monstkills[i] = file.nextBE(); + for (int &monstkill : monstkills) + monstkill = file.nextBE(); if (leveltype != DTYPE_TOWN) { - for (int i = 0; i < MAXMONSTERS; i++) - monstactive[i] = file.nextBE(); + for (int &monsterId : monstactive) + monsterId = file.nextBE(); for (int i = 0; i < nummonsters; i++) LoadMonster(&file, monstactive[i]); - for (int i = 0; i < MAXMISSILES; i++) - missileactive[i] = file.nextLE(); - for (int i = 0; i < MAXMISSILES; i++) - missileavail[i] = file.nextLE(); + for (int &missileId : missileactive) + missileId = file.nextLE(); + for (int &missileId : missileavail) + missileId = file.nextLE(); for (int i = 0; i < nummissiles; i++) LoadMissile(&file, missileactive[i]); - for (int i = 0; i < MAXOBJECTS; i++) - objectactive[i] = file.nextLE(); - for (int i = 0; i < MAXOBJECTS; i++) - objectavail[i] = file.nextLE(); + for (int &objectId : objectactive) + objectId = file.nextLE(); + for (int &objectId : objectavail) + objectId = file.nextLE(); for (int i = 0; i < nobjects; i++) LoadObject(&file, objectactive[i]); for (int i = 0; i < nobjects; i++) @@ -1091,8 +1088,8 @@ void LoadGame(bool firstflag) numlights = file.nextBE(); - for (int i = 0; i < MAXLIGHTS; i++) - lightactive[i] = file.nextLE(); + for (uint8_t &lightId : lightactive) + lightId = file.nextLE(); for (int i = 0; i < numlights; i++) LoadLighting(&file, &LightList[lightactive[i]]); @@ -1103,14 +1100,14 @@ void LoadGame(bool firstflag) LoadLighting(&file, &VisionList[i]); } - for (int i = 0; i < MAXITEMS; i++) - itemactive[i] = file.nextLE(); - for (int i = 0; i < MAXITEMS; i++) - itemavail[i] = file.nextLE(); + for (int &itemId : itemactive) + itemId = file.nextLE(); + for (int &itemId : itemavail) + itemId = file.nextLE(); for (int i = 0; i < numitems; i++) LoadItem(&file, itemactive[i]); - for (int i = 0; i < 128; i++) - UniqueItemFlag[i] = file.nextBool8(); + for (bool &UniqueItemFlag : UniqueItemFlags) + UniqueItemFlag = file.nextBool8(); for (int j = 0; j < MAXDUNY; j++) { for (int i = 0; i < MAXDUNX; i++) @@ -1292,8 +1289,8 @@ static void SavePlayer(SaveHelper *file, int p) PlayerStruct *pPlayer = &plr[p]; file->writeLE(pPlayer->_pmode); - for (int i = 0; i < MAX_PATH_LENGTH; i++) - file->writeLE(pPlayer->walkpath[i]); + for (int8_t step : pPlayer->walkpath) + file->writeLE(step); file->writeLE(pPlayer->plractive); file->skip(2); // Alignment file->writeLE(pPlayer->destAction); @@ -1342,18 +1339,18 @@ static void SavePlayer(SaveHelper *file, int p) file->skip(3); // Alignment file->writeLE(pPlayer->_pSBkSpell); file->writeLE(pPlayer->_pSBkSplType); - for (int i = 0; i < 64; i++) - file->writeLE(pPlayer->_pSplLvl[i]); + for (int8_t spellLevel : pPlayer->_pSplLvl) + file->writeLE(spellLevel); file->skip(7); // Alignment file->writeLE(pPlayer->_pMemSpells); file->writeLE(pPlayer->_pAblSpells); file->writeLE(pPlayer->_pScrlSpells); file->writeLE(pPlayer->_pSpellFlags); file->skip(3); // Alignment - for (int i = 0; i < 4; i++) - file->writeLE(pPlayer->_pSplHotKey[i]); - for (int i = 0; i < 4; i++) - file->writeLE(pPlayer->_pSplTHotKey[i]); + for (auto &spellId : pPlayer->_pSplHotKey) + file->writeLE(spellId); + for (auto &spellType : pPlayer->_pSplTHotKey) + file->writeLE(spellType); file->writeLE(pPlayer->_pwtype); file->writeLE(pPlayer->_pBlockFlag); @@ -1444,8 +1441,8 @@ static void SavePlayer(SaveHelper *file, int p) SaveItems(file, pPlayer->InvBody, NUM_INVLOC); SaveItems(file, pPlayer->InvList, NUM_INV_GRID_ELEM); file->writeLE(pPlayer->_pNumInv); - for (int i = 0; i < NUM_INV_GRID_ELEM; i++) - file->writeLE(pPlayer->InvGrid[i]); + for (int8_t cell : pPlayer->InvGrid) + file->writeLE(cell); SaveItems(file, pPlayer->SpdList, MAXBELTITEMS); SaveItem(file, &pPlayer->HoldItem); @@ -1686,7 +1683,7 @@ static void SaveObject(SaveHelper *file, int i) static void SavePremium(SaveHelper *file, int i) { - SaveItem(file, &premiumitem[i]); + SaveItem(file, &premiumitems[i]); } static void SaveQuest(SaveHelper *file, int i) @@ -1819,31 +1816,31 @@ void SaveGameData() SaveQuest(&file, i); for (int i = 0; i < MAXPORTAL; i++) SavePortal(&file, i); - for (int i = 0; i < MAXMONSTERS; i++) - file.writeBE(monstkills[i]); + for (int monstkill : monstkills) + file.writeBE(monstkill); if (leveltype != DTYPE_TOWN) { - for (int i = 0; i < MAXMONSTERS; i++) - file.writeBE(monstactive[i]); + for (int monsterId : monstactive) + file.writeBE(monsterId); for (int i = 0; i < nummonsters; i++) SaveMonster(&file, monstactive[i]); - for (int i = 0; i < MAXMISSILES; i++) - file.writeLE(missileactive[i]); - for (int i = 0; i < MAXMISSILES; i++) - file.writeLE(missileavail[i]); + for (int missileId : missileactive) + file.writeLE(missileId); + for (int missileId : missileavail) + file.writeLE(missileId); for (int i = 0; i < nummissiles; i++) SaveMissile(&file, missileactive[i]); - for (int i = 0; i < MAXOBJECTS; i++) - file.writeLE(objectactive[i]); - for (int i = 0; i < MAXOBJECTS; i++) - file.writeLE(objectavail[i]); + for (int objectId : objectactive) + file.writeLE(objectId); + for (int objectId : objectavail) + file.writeLE(objectId); for (int i = 0; i < nobjects; i++) SaveObject(&file, objectactive[i]); file.writeBE(numlights); - for (int i = 0; i < MAXLIGHTS; i++) - file.writeLE(lightactive[i]); + for (uint8_t lightId : lightactive) + file.writeLE(lightId); for (int i = 0; i < numlights; i++) SaveLighting(&file, &LightList[lightactive[i]]); @@ -1854,14 +1851,14 @@ void SaveGameData() SaveLighting(&file, &VisionList[i]); } - for (int i = 0; i < MAXITEMS; i++) - file.writeLE(itemactive[i]); - for (int i = 0; i < MAXITEMS; i++) - file.writeLE(itemavail[i]); + for (int itemId : itemactive) + file.writeLE(itemId); + for (int itemId : itemavail) + file.writeLE(itemId); for (int i = 0; i < numitems; i++) SaveItem(&file, &items[itemactive[i]]); - for (int i = 0; i < 128; i++) - file.writeLE(UniqueItemFlag[i]); + for (bool UniqueItemFlag : UniqueItemFlags) + file.writeLE(UniqueItemFlag); for (int j = 0; j < MAXDUNY; j++) { for (int i = 0; i < MAXDUNX; i++) @@ -1952,22 +1949,22 @@ void SaveLevel() file.writeBE(nobjects); if (leveltype != DTYPE_TOWN) { - for (int i = 0; i < MAXMONSTERS; i++) - file.writeBE(monstactive[i]); + for (int monsterId : monstactive) + file.writeBE(monsterId); for (int i = 0; i < nummonsters; i++) SaveMonster(&file, monstactive[i]); - for (int i = 0; i < MAXOBJECTS; i++) - file.writeLE(objectactive[i]); - for (int i = 0; i < MAXOBJECTS; i++) - file.writeLE(objectavail[i]); + for (int objectId : objectactive) + file.writeLE(objectId); + for (int objectId : objectavail) + file.writeLE(objectId); for (int i = 0; i < nobjects; i++) SaveObject(&file, objectactive[i]); } - for (int i = 0; i < MAXITEMS; i++) - file.writeLE(itemactive[i]); - for (int i = 0; i < MAXITEMS; i++) - file.writeLE(itemavail[i]); + for (int itemId : itemactive) + file.writeLE(itemId); + for (int itemId : itemavail) + file.writeLE(itemId); for (int i = 0; i < numitems; i++) SaveItem(&file, &items[itemactive[i]]); @@ -2035,14 +2032,14 @@ void LoadLevel() nobjects = file.nextBE(); if (leveltype != DTYPE_TOWN) { - for (int i = 0; i < MAXMONSTERS; i++) - monstactive[i] = file.nextBE(); + for (int &monsterId : monstactive) + monsterId = file.nextBE(); for (int i = 0; i < nummonsters; i++) LoadMonster(&file, monstactive[i]); - for (int i = 0; i < MAXOBJECTS; i++) - objectactive[i] = file.nextLE(); - for (int i = 0; i < MAXOBJECTS; i++) - objectavail[i] = file.nextLE(); + for (int &objectId : objectactive) + objectId = file.nextLE(); + for (int &objectId : objectavail) + objectId = file.nextLE(); for (int i = 0; i < nobjects; i++) LoadObject(&file, objectactive[i]); if (!gbSkipSync) { @@ -2051,10 +2048,10 @@ void LoadLevel() } } - for (int i = 0; i < MAXITEMS; i++) - itemactive[i] = file.nextLE(); - for (int i = 0; i < MAXITEMS; i++) - itemavail[i] = file.nextLE(); + for (int &itemId : itemactive) + itemId = file.nextLE(); + for (int &itemId : itemavail) + itemId = file.nextLE(); for (int i = 0; i < numitems; i++) LoadItem(&file, itemactive[i]); @@ -2105,9 +2102,9 @@ void LoadLevel() dolighting = true; } - for (int i = 0; i < MAX_PLRS; i++) { - if (plr[i].plractive && currlevel == plr[i].plrlevel) - LightList[plr[i]._plid]._lunflag = true; + for (auto &player : plr) { + if (player.plractive && currlevel == player.plrlevel) + LightList[player._plid]._lunflag = true; } } diff --git a/Source/miniwin/misc_msg.cpp b/Source/miniwin/misc_msg.cpp index f1a0c881d..baeebbe58 100644 --- a/Source/miniwin/misc_msg.cpp +++ b/Source/miniwin/misc_msg.cpp @@ -51,9 +51,9 @@ void FocusOnCharInfo() // Find the first incrementable stat. int stat = -1; - for (auto i : enum_values()) { - int max = plr[myplr].GetMaximumAttributeValue(i); - switch (i) { + for (auto attribute : enum_values()) { + int max = plr[myplr].GetMaximumAttributeValue(attribute); + switch (attribute) { case CharacterAttribute::Strength: if (plr[myplr]._pBaseStr >= max) continue; @@ -71,7 +71,7 @@ void FocusOnCharInfo() continue; break; } - stat = static_cast(i); + stat = static_cast(attribute); } if (stat == -1) return; diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 6992d8dc8..75983d85b 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -5,7 +5,7 @@ */ #include "missiles.h" -#include +#include #include "control.h" #include "cursor.h" @@ -1485,7 +1485,7 @@ void AddReflection(Sint32 mi, Sint32 sx, Sint32 sy, Sint32 dx, Sint32 dy, Sint32 UseMana(id, SPL_REFLECT); } missile[mi]._mirange = 0; - missile[mi]._miDelFlag = 0; + missile[mi]._miDelFlag = false; } void AddBerserk(Sint32 mi, Sint32 sx, Sint32 sy, Sint32 dx, Sint32 dy, Sint32 midir, Sint8 mienemy, Sint32 id, Sint32 dam) @@ -1508,7 +1508,7 @@ void AddBerserk(Sint32 mi, Sint32 sx, Sint32 sy, Sint32 dx, Sint32 dy, Sint32 mi if (!(monster[dm].mMagicRes & IMMUNE_MAGIC)) { if ((!(monster[dm].mMagicRes & RESIST_MAGIC) || ((monster[dm].mMagicRes & RESIST_MAGIC) == 1 && !random_(99, 2))) && monster[dm]._mmode != MM_CHARGE) { j = 6; - double slvl = (double)GetSpellLevel(id, SPL_BERSERK); + auto slvl = static_cast(GetSpellLevel(id, SPL_BERSERK)); monster[dm]._mFlags |= MFLAG_BERSERK | MFLAG_GOLEM; monster[dm].mMinDamage = ((double)(random_(145, 10) + 20) / 100 - -1) * (double)monster[dm].mMinDamage + slvl; monster[dm].mMaxDamage = ((double)(random_(145, 10) + 20) / 100 - -1) * (double)monster[dm].mMaxDamage + slvl; @@ -1787,19 +1787,19 @@ void AddRuneExplosion(Sint32 mi, Sint32 sx, Sint32 sy, Sint32 dx, Sint32 dy, Sin } dmg = missile[mi]._midam; - CheckMissileCol(mi, dmg, dmg, 0, missile[mi]._mix - 1, missile[mi]._miy - 1, 1); - CheckMissileCol(mi, dmg, dmg, 0, missile[mi]._mix, missile[mi]._miy - 1, 1); - CheckMissileCol(mi, dmg, dmg, 0, missile[mi]._mix + 1, missile[mi]._miy - 1, 1); - CheckMissileCol(mi, dmg, dmg, 0, missile[mi]._mix - 1, missile[mi]._miy, 1); - CheckMissileCol(mi, dmg, dmg, 0, missile[mi]._mix, missile[mi]._miy, 1); - CheckMissileCol(mi, dmg, dmg, 0, missile[mi]._mix + 1, missile[mi]._miy, 1); - CheckMissileCol(mi, dmg, dmg, 0, missile[mi]._mix - 1, missile[mi]._miy + 1, 1); - CheckMissileCol(mi, dmg, dmg, 0, missile[mi]._mix, missile[mi]._miy + 1, 1); - CheckMissileCol(mi, dmg, dmg, 0, missile[mi]._mix + 1, missile[mi]._miy + 1, 1); + CheckMissileCol(mi, dmg, dmg, false, missile[mi]._mix - 1, missile[mi]._miy - 1, true); + CheckMissileCol(mi, dmg, dmg, false, missile[mi]._mix, missile[mi]._miy - 1, true); + CheckMissileCol(mi, dmg, dmg, false, missile[mi]._mix + 1, missile[mi]._miy - 1, true); + CheckMissileCol(mi, dmg, dmg, false, missile[mi]._mix - 1, missile[mi]._miy, true); + CheckMissileCol(mi, dmg, dmg, false, missile[mi]._mix, missile[mi]._miy, true); + CheckMissileCol(mi, dmg, dmg, false, missile[mi]._mix + 1, missile[mi]._miy, true); + CheckMissileCol(mi, dmg, dmg, false, missile[mi]._mix - 1, missile[mi]._miy + 1, true); + CheckMissileCol(mi, dmg, dmg, false, missile[mi]._mix, missile[mi]._miy + 1, true); + CheckMissileCol(mi, dmg, dmg, false, missile[mi]._mix + 1, missile[mi]._miy + 1, true); } missile[mi]._mlid = AddLight(sx, sy, 8); SetMissDir(mi, 0); - missile[mi]._miDelFlag = 0; + missile[mi]._miDelFlag = false; missile[mi]._mirange = missile[mi]._miAnimLen - 1; } @@ -3785,29 +3785,29 @@ void MI_Fireball(Sint32 i) missile[i]._mityoff += missile[i]._miyvel; GetMissilePos(i); if (missile[i]._mix != missile[i]._misx || missile[i]._miy != missile[i]._misy) - CheckMissileCol(i, dam, dam, 0, missile[i]._mix, missile[i]._miy, 0); + CheckMissileCol(i, dam, dam, false, missile[i]._mix, missile[i]._miy, false); if (missile[i]._mirange == 0) { mx = missile[i]._mix; my = missile[i]._miy; ChangeLight(missile[i]._mlid, missile[i]._mix, my, missile[i]._miAnimFrame); if (!CheckBlock(px, py, mx, my)) - CheckMissileCol(i, dam, dam, 0, mx, my, 1); + CheckMissileCol(i, dam, dam, false, mx, my, true); if (!CheckBlock(px, py, mx, my + 1)) - CheckMissileCol(i, dam, dam, 0, mx, my + 1, 1); + CheckMissileCol(i, dam, dam, false, mx, my + 1, true); if (!CheckBlock(px, py, mx, my - 1)) - CheckMissileCol(i, dam, dam, 0, mx, my - 1, 1); + CheckMissileCol(i, dam, dam, false, mx, my - 1, true); if (!CheckBlock(px, py, mx + 1, my)) - CheckMissileCol(i, dam, dam, 0, mx + 1, my, 1); + CheckMissileCol(i, dam, dam, false, mx + 1, my, true); if (!CheckBlock(px, py, mx + 1, my - 1)) - CheckMissileCol(i, dam, dam, 0, mx + 1, my - 1, 1); + CheckMissileCol(i, dam, dam, false, mx + 1, my - 1, true); if (!CheckBlock(px, py, mx + 1, my + 1)) - CheckMissileCol(i, dam, dam, 0, mx + 1, my + 1, 1); + CheckMissileCol(i, dam, dam, false, mx + 1, my + 1, true); if (!CheckBlock(px, py, mx - 1, my)) - CheckMissileCol(i, dam, dam, 0, mx - 1, my, 1); + CheckMissileCol(i, dam, dam, false, mx - 1, my, true); if (!CheckBlock(px, py, mx - 1, my + 1)) - CheckMissileCol(i, dam, dam, 0, mx - 1, my + 1, 1); + CheckMissileCol(i, dam, dam, false, mx - 1, my + 1, true); if (!CheckBlock(px, py, mx - 1, my - 1)) - CheckMissileCol(i, dam, dam, 0, mx - 1, my - 1, 1); + CheckMissileCol(i, dam, dam, false, mx - 1, my - 1, true); if (!TransList[dTransVal[mx][my]] || (missile[i]._mixvel < 0 && ((TransList[dTransVal[mx][my + 1]] && nSolidTable[dPiece[mx][my + 1]]) || (TransList[dTransVal[mx][my - 1]] && nSolidTable[dPiece[mx][my - 1]])))) { missile[i]._mix++; @@ -3842,7 +3842,7 @@ void MI_HorkSpawn(Sint32 i) int t, j, k, tx, ty, dp; missile[i]._mirange--; - CheckMissileCol(i, 0, 0, 0, missile[i]._mix, missile[i]._miy, 0); + CheckMissileCol(i, 0, 0, false, missile[i]._mix, missile[i]._miy, false); if (missile[i]._mirange <= 0) { missile[i]._miDelFlag = true; for (j = 0; j < 2; j++) { @@ -3854,7 +3854,7 @@ void MI_HorkSpawn(Sint32 i) dp = dPiece[tx][ty]; if (!nSolidTable[dp] && dMonster[tx][ty] == 0 && dPlayer[tx][ty] == 0 && dObject[tx][ty] == 0) { j = 6; - direction md = static_cast(missile[i]._miVar1); + auto md = static_cast(missile[i]._miVar1); int mon = AddMonster(tx, ty, md, 1, true); M_StartStand(mon, md); break; @@ -3907,7 +3907,7 @@ void MI_LightningWall(Sint32 i) missile[i]._mirange--; range = missile[i]._mirange; - CheckMissileCol(i, missile[i]._midam, missile[i]._midam, 1, missile[i]._mix, missile[i]._miy, 0); + CheckMissileCol(i, missile[i]._midam, missile[i]._midam, true, missile[i]._mix, missile[i]._miy, false); if (missile[i]._miHitFlag) missile[i]._mirange = range; if (missile[i]._mirange == 0) @@ -4198,7 +4198,7 @@ void MI_FireRing(Sint32 i) BYTE lvl; b = CrawlNum[3]; - missile[i]._miDelFlag = 1; + missile[i]._miDelFlag = true; src = missile[i]._micaster; k = CrawlNum[3] + 1; if (src > 0) @@ -4229,7 +4229,7 @@ void MI_LightningRing(Sint32 i) BYTE lvl; b = CrawlNum[3]; - missile[i]._miDelFlag = 1; + missile[i]._miDelFlag = true; src = missile[i]._micaster; k = CrawlNum[3] + 1; if (src > 0) @@ -4314,14 +4314,14 @@ void MI_FireNova(Sint32 i) dir = plr[id]._pdir; en = TARGET_MONSTERS; } - for (int k = 0; k < 23; k++) { - if (sx1 != vCrawlTable[k][6] || sy1 != vCrawlTable[k][7]) { - AddMissile(sx, sy, sx + vCrawlTable[k][6], sy + vCrawlTable[k][7], dir, MIS_FIRENOVA, en, id, dam, missile[i]._mispllvl); - AddMissile(sx, sy, sx - vCrawlTable[k][6], sy - vCrawlTable[k][7], dir, MIS_FIRENOVA, en, id, dam, missile[i]._mispllvl); - AddMissile(sx, sy, sx - vCrawlTable[k][6], sy + vCrawlTable[k][7], dir, MIS_FIRENOVA, en, id, dam, missile[i]._mispllvl); - AddMissile(sx, sy, sx + vCrawlTable[k][6], sy - vCrawlTable[k][7], dir, MIS_FIRENOVA, en, id, dam, missile[i]._mispllvl); - sx1 = vCrawlTable[k][6]; - sy1 = vCrawlTable[k][7]; + for (const auto &k : vCrawlTable) { + if (sx1 != k[6] || sy1 != k[7]) { + AddMissile(sx, sy, sx + k[6], sy + k[7], dir, MIS_FIRENOVA, en, id, dam, missile[i]._mispllvl); + AddMissile(sx, sy, sx - k[6], sy - k[7], dir, MIS_FIRENOVA, en, id, dam, missile[i]._mispllvl); + AddMissile(sx, sy, sx - k[6], sy + k[7], dir, MIS_FIRENOVA, en, id, dam, missile[i]._mispllvl); + AddMissile(sx, sy, sx + k[6], sy - k[7], dir, MIS_FIRENOVA, en, id, dam, missile[i]._mispllvl); + sx1 = k[6]; + sy1 = k[7]; } } missile[i]._mirange--; @@ -5147,14 +5147,14 @@ void MI_Nova(Sint32 i) dir = plr[id]._pdir; en = TARGET_MONSTERS; } - for (int k = 0; k < 23; k++) { - if (sx1 != vCrawlTable[k][6] || sy1 != vCrawlTable[k][7]) { - AddMissile(sx, sy, sx + vCrawlTable[k][6], sy + vCrawlTable[k][7], dir, MIS_LIGHTBALL, en, id, dam, missile[i]._mispllvl); - AddMissile(sx, sy, sx - vCrawlTable[k][6], sy - vCrawlTable[k][7], dir, MIS_LIGHTBALL, en, id, dam, missile[i]._mispllvl); - AddMissile(sx, sy, sx - vCrawlTable[k][6], sy + vCrawlTable[k][7], dir, MIS_LIGHTBALL, en, id, dam, missile[i]._mispllvl); - AddMissile(sx, sy, sx + vCrawlTable[k][6], sy - vCrawlTable[k][7], dir, MIS_LIGHTBALL, en, id, dam, missile[i]._mispllvl); - sx1 = vCrawlTable[k][6]; - sy1 = vCrawlTable[k][7]; + for (const auto &k : vCrawlTable) { + if (sx1 != k[6] || sy1 != k[7]) { + AddMissile(sx, sy, sx + k[6], sy + k[7], dir, MIS_LIGHTBALL, en, id, dam, missile[i]._mispllvl); + AddMissile(sx, sy, sx - k[6], sy - k[7], dir, MIS_LIGHTBALL, en, id, dam, missile[i]._mispllvl); + AddMissile(sx, sy, sx - k[6], sy + k[7], dir, MIS_LIGHTBALL, en, id, dam, missile[i]._mispllvl); + AddMissile(sx, sy, sx + k[6], sy - k[7], dir, MIS_LIGHTBALL, en, id, dam, missile[i]._mispllvl); + sx1 = k[6]; + sy1 = k[7]; } } missile[i]._mirange--; diff --git a/Source/monster.cpp b/Source/monster.cpp index 2fde946a8..68d149fd6 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -6,7 +6,7 @@ #include "monster.h" #include -#include +#include #include "control.h" #include "cursor.h" @@ -647,7 +647,7 @@ void monster_some_crypt() if (currlevel == 24 && UberDiabloMonsterIndex >= 0 && UberDiabloMonsterIndex < nummonsters) { mon = &monster[UberDiabloMonsterIndex]; PlayEffect(UberDiabloMonsterIndex, 2); - quests[Q_NAKRUL]._qlog = 0; + quests[Q_NAKRUL]._qlog = false; mon->mArmorClass -= 50; hp = mon->_mmaxhp / 2; mon->mMagicRes = 0; @@ -670,7 +670,7 @@ void PlaceMonster(int i, int mtype, int x, int y) } dMonster[x][y] = i + 1; - direction rd = static_cast(random_(90, 8)); + auto rd = static_cast(random_(90, 8)); InitMonster(i, rd, mtype, x, y); } @@ -699,7 +699,7 @@ void PlaceUniqueMonst(int uniqindex, int miniontype, int bosspacksize) } } - while (1) { + while (true) { xp = random_(91, 80) + 16; yp = random_(91, 80) + 16; count2 = 0; @@ -1325,7 +1325,7 @@ void M_Enemy(int i) _menemy = -1; best_dist = -1; - bestsameroom = 0; + bestsameroom = false; Monst = &monster[i]; if (Monst->_mFlags & MFLAG_BERSERK || !(Monst->_mFlags & MFLAG_GOLEM)) { for (pnum = 0; pnum < MAX_PLRS; pnum++) { @@ -1739,7 +1739,7 @@ void SpawnLoot(int i, bool sendmsg) } else if (Monst->_uniqtype - 1 == UMT_DEFILER) { if (effect_is_playing(USFX_DEFILER8)) stream_stop(); - quests[Q_DEFILER]._qlog = 0; + quests[Q_DEFILER]._qlog = false; SpawnMapOfDoom(Monst->_mx, Monst->_my); } else if (Monst->_uniqtype - 1 == UMT_HORKDMN) { if (sgGameInitInfo.bTheoQuest) { @@ -1754,7 +1754,7 @@ void SpawnLoot(int i, bool sendmsg) nSFX = USFX_NAKRUL6; if (effect_is_playing(nSFX)) stream_stop(); - quests[Q_NAKRUL]._qlog = 0; + quests[Q_NAKRUL]._qlog = false; UberDiabloMonsterIndex = -2; CreateMagicWeapon(Monst->_mx, Monst->_my, ITYPE_SWORD, ICURS_GREAT_SWORD, false, true); CreateMagicWeapon(Monst->_mx, Monst->_my, ITYPE_STAFF, ICURS_WAR_STAFF, false, true); @@ -2679,14 +2679,14 @@ void PrepDoEnding() newKillLevel = *killLevel; plr[myplr].pDiabloKillLevel = newKillLevel; - for (int i = 0; i < MAX_PLRS; i++) { - plr[i]._pmode = PM_QUIT; - plr[i]._pInvincible = true; + for (auto &player : plr) { + player._pmode = PM_QUIT; + player._pInvincible = true; if (gbIsMultiplayer) { - if (plr[i]._pHitPoints >> 6 == 0) - plr[i]._pHitPoints = 64; - if (plr[i]._pMana >> 6 == 0) - plr[i]._pMana = 64; + if (player._pHitPoints >> 6 == 0) + player._pHitPoints = 64; + if (player._pMana >> 6 == 0) + player._pMana = 64; } } } diff --git a/Source/mpqapi.cpp b/Source/mpqapi.cpp index 1ac37fe13..f50887586 100644 --- a/Source/mpqapi.cpp +++ b/Source/mpqapi.cpp @@ -34,11 +34,11 @@ namespace { // Done with templates so that error messages include actual size. template struct assert_eq : std::true_type { - static_assert(A == B, ""); + static_assert(A == B); }; template struct assert_lte : std::true_type { - static_assert(A <= B, ""); + static_assert(A <= B); }; template struct check_size : assert_eq, assert_lte { @@ -47,8 +47,8 @@ struct check_size : assert_eq, assert_lte { // Check sizes and alignments of the structs that we decrypt and encrypt. // The decryption algorithm treats them as a stream of 32-bit uints, so the // sizes must be exact as there cannot be any padding. -static_assert(check_size<_HASHENTRY, 4 * 4>::value, ""); -static_assert(check_size<_BLOCKENTRY, 4 * 4>::value, ""); +static_assert(check_size<_HASHENTRY, 4 * 4>::value); +static_assert(check_size<_BLOCKENTRY, 4 * 4>::value); const char *DirToString(std::ios::seekdir dir) { @@ -88,7 +88,7 @@ struct FStreamWrapper { public: bool Open(const char *path, std::ios::openmode mode) { - s_.reset(new std::fstream(path, mode)); + s_ = std::make_unique(path, mode); return CheckError("new std::fstream(\"%s\", %s)", path, OpenModeToString(mode).c_str()); } diff --git a/Source/msg.cpp b/Source/msg.cpp index ac2c4c2e2..3102fe728 100644 --- a/Source/msg.cpp +++ b/Source/msg.cpp @@ -3,7 +3,7 @@ * * Implementation of function for sending and reciving network messages. */ -#include +#include #include "DiabloUI/diabloui.h" #include "automap.h" @@ -79,12 +79,12 @@ static void msg_pre_packet() size_t spaceLeft = sizeof(pkt->data); while (spaceLeft != pkt->dwSpaceLeft) { if (*data == FAKE_CMD_SETID) { - TFakeCmdPlr *cmd = (TFakeCmdPlr *)data; + auto *cmd = (TFakeCmdPlr *)data; data += sizeof(*cmd); spaceLeft -= sizeof(*cmd); i = cmd->bPlr; } else if (*data == FAKE_CMD_DROPID) { - TFakeDropPlr *cmd = (TFakeDropPlr *)data; + auto *cmd = (TFakeDropPlr *)data; data += sizeof(*cmd); spaceLeft -= sizeof(*cmd); multi_player_left(cmd->bPlr, cmd->dwReason); @@ -387,7 +387,7 @@ static void DeltaImportData(BYTE cmd, DWORD recv_offset) static DWORD On_DLEVEL(int pnum, TCmd *pCmd) { - TCmdPlrInfoHdr *p = (TCmdPlrInfoHdr *)pCmd; + auto *p = (TCmdPlrInfoHdr *)pCmd; if (gbDeltaSender != pnum) { if (p->bCmd == CMD_DLEVEL_END) { @@ -1263,7 +1263,7 @@ void NetSendCmdString(int pmask, const char *pszStr) static DWORD On_STRING2(int pnum, TCmd *pCmd) { - TCmdString *p = (TCmdString *)pCmd; + auto *p = (TCmdString *)pCmd; int len = strlen(p->str); if (!gbBufferMsgs) @@ -1318,7 +1318,7 @@ static DWORD On_SYNCDATA(TCmd *pCmd, int pnum) static DWORD On_WALKXY(TCmd *pCmd, int pnum) { - TCmdLoc *p = (TCmdLoc *)pCmd; + auto *p = (TCmdLoc *)pCmd; if (gbBufferMsgs != 1 && currlevel == plr[pnum].plrlevel) { ClrPlrPath(pnum); @@ -1331,7 +1331,7 @@ static DWORD On_WALKXY(TCmd *pCmd, int pnum) static DWORD On_ADDSTR(TCmd *pCmd, int pnum) { - TCmdParam1 *p = (TCmdParam1 *)pCmd; + auto *p = (TCmdParam1 *)pCmd; if (gbBufferMsgs == 1) msg_send_packet(pnum, p, sizeof(*p)); @@ -1343,7 +1343,7 @@ static DWORD On_ADDSTR(TCmd *pCmd, int pnum) static DWORD On_ADDMAG(TCmd *pCmd, int pnum) { - TCmdParam1 *p = (TCmdParam1 *)pCmd; + auto *p = (TCmdParam1 *)pCmd; if (gbBufferMsgs == 1) msg_send_packet(pnum, p, sizeof(*p)); @@ -1355,7 +1355,7 @@ static DWORD On_ADDMAG(TCmd *pCmd, int pnum) static DWORD On_ADDDEX(TCmd *pCmd, int pnum) { - TCmdParam1 *p = (TCmdParam1 *)pCmd; + auto *p = (TCmdParam1 *)pCmd; if (gbBufferMsgs == 1) msg_send_packet(pnum, p, sizeof(*p)); @@ -1367,7 +1367,7 @@ static DWORD On_ADDDEX(TCmd *pCmd, int pnum) static DWORD On_ADDVIT(TCmd *pCmd, int pnum) { - TCmdParam1 *p = (TCmdParam1 *)pCmd; + auto *p = (TCmdParam1 *)pCmd; if (gbBufferMsgs == 1) msg_send_packet(pnum, p, sizeof(*p)); @@ -1379,10 +1379,10 @@ static DWORD On_ADDVIT(TCmd *pCmd, int pnum) static DWORD On_SBSPELL(TCmd *pCmd, int pnum) { - TCmdParam1 *p = (TCmdParam1 *)pCmd; + auto *p = (TCmdParam1 *)pCmd; if (gbBufferMsgs != 1) { - spell_id spell = (spell_id)p->wParam1; + auto spell = static_cast(p->wParam1); if (currlevel != 0 || spelldata[spell].sTownSpell) { plr[pnum]._pSpell = spell; plr[pnum]._pSplType = plr[pnum]._pSBkSplType; @@ -1397,7 +1397,7 @@ static DWORD On_SBSPELL(TCmd *pCmd, int pnum) static DWORD On_GOTOGETITEM(TCmd *pCmd, int pnum) { - TCmdLocParam1 *p = (TCmdLocParam1 *)pCmd; + auto *p = (TCmdLocParam1 *)pCmd; if (gbBufferMsgs != 1 && currlevel == plr[pnum].plrlevel) { MakePlrPath(pnum, p->x, p->y, false); @@ -1410,7 +1410,7 @@ static DWORD On_GOTOGETITEM(TCmd *pCmd, int pnum) static DWORD On_REQUESTGITEM(TCmd *pCmd, int pnum) { - TCmdGItem *p = (TCmdGItem *)pCmd; + auto *p = (TCmdGItem *)pCmd; if (gbBufferMsgs != 1 && i_own_level(plr[pnum].plrlevel)) { if (GetItemRecord(p->dwSeed, p->wCI, p->wIndx)) { @@ -1432,7 +1432,7 @@ static DWORD On_REQUESTGITEM(TCmd *pCmd, int pnum) static DWORD On_GETITEM(TCmd *pCmd, int pnum) { - TCmdGItem *p = (TCmdGItem *)pCmd; + auto *p = (TCmdGItem *)pCmd; if (gbBufferMsgs == 1) msg_send_packet(pnum, p, sizeof(*p)); @@ -1459,7 +1459,7 @@ static DWORD On_GETITEM(TCmd *pCmd, int pnum) static DWORD On_GOTOAGETITEM(TCmd *pCmd, int pnum) { - TCmdLocParam1 *p = (TCmdLocParam1 *)pCmd; + auto *p = (TCmdLocParam1 *)pCmd; if (gbBufferMsgs != 1 && currlevel == plr[pnum].plrlevel) { MakePlrPath(pnum, p->x, p->y, false); @@ -1472,7 +1472,7 @@ static DWORD On_GOTOAGETITEM(TCmd *pCmd, int pnum) static DWORD On_REQUESTAGITEM(TCmd *pCmd, int pnum) { - TCmdGItem *p = (TCmdGItem *)pCmd; + auto *p = (TCmdGItem *)pCmd; if (gbBufferMsgs != 1 && i_own_level(plr[pnum].plrlevel)) { if (GetItemRecord(p->dwSeed, p->wCI, p->wIndx)) { @@ -1494,7 +1494,7 @@ static DWORD On_REQUESTAGITEM(TCmd *pCmd, int pnum) static DWORD On_AGETITEM(TCmd *pCmd, int pnum) { - TCmdGItem *p = (TCmdGItem *)pCmd; + auto *p = (TCmdGItem *)pCmd; if (gbBufferMsgs == 1) msg_send_packet(pnum, p, sizeof(*p)); @@ -1521,7 +1521,7 @@ static DWORD On_AGETITEM(TCmd *pCmd, int pnum) static DWORD On_ITEMEXTRA(TCmd *pCmd, int pnum) { - TCmdGItem *p = (TCmdGItem *)pCmd; + auto *p = (TCmdGItem *)pCmd; if (gbBufferMsgs == 1) msg_send_packet(pnum, p, sizeof(*p)); @@ -1536,7 +1536,7 @@ static DWORD On_ITEMEXTRA(TCmd *pCmd, int pnum) static DWORD On_PUTITEM(TCmd *pCmd, int pnum) { - TCmdPItem *p = (TCmdPItem *)pCmd; + auto *p = (TCmdPItem *)pCmd; if (gbBufferMsgs == 1) msg_send_packet(pnum, p, sizeof(*p)); @@ -1563,7 +1563,7 @@ static DWORD On_PUTITEM(TCmd *pCmd, int pnum) static DWORD On_SYNCPUTITEM(TCmd *pCmd, int pnum) { - TCmdPItem *p = (TCmdPItem *)pCmd; + auto *p = (TCmdPItem *)pCmd; if (gbBufferMsgs == 1) msg_send_packet(pnum, p, sizeof(*p)); @@ -1586,7 +1586,7 @@ static DWORD On_SYNCPUTITEM(TCmd *pCmd, int pnum) static DWORD On_RESPAWNITEM(TCmd *pCmd, int pnum) { - TCmdPItem *p = (TCmdPItem *)pCmd; + auto *p = (TCmdPItem *)pCmd; if (gbBufferMsgs == 1) msg_send_packet(pnum, p, sizeof(*p)); @@ -1603,7 +1603,7 @@ static DWORD On_RESPAWNITEM(TCmd *pCmd, int pnum) static DWORD On_ATTACKXY(TCmd *pCmd, int pnum) { - TCmdLoc *p = (TCmdLoc *)pCmd; + auto *p = (TCmdLoc *)pCmd; if (gbBufferMsgs != 1 && currlevel == plr[pnum].plrlevel) { MakePlrPath(pnum, p->x, p->y, false); @@ -1617,7 +1617,7 @@ static DWORD On_ATTACKXY(TCmd *pCmd, int pnum) static DWORD On_SATTACKXY(TCmd *pCmd, int pnum) { - TCmdLoc *p = (TCmdLoc *)pCmd; + auto *p = (TCmdLoc *)pCmd; if (gbBufferMsgs != 1 && currlevel == plr[pnum].plrlevel) { ClrPlrPath(pnum); @@ -1631,7 +1631,7 @@ static DWORD On_SATTACKXY(TCmd *pCmd, int pnum) static DWORD On_RATTACKXY(TCmd *pCmd, int pnum) { - TCmdLoc *p = (TCmdLoc *)pCmd; + auto *p = (TCmdLoc *)pCmd; if (gbBufferMsgs != 1 && currlevel == plr[pnum].plrlevel) { ClrPlrPath(pnum); @@ -1645,10 +1645,10 @@ static DWORD On_RATTACKXY(TCmd *pCmd, int pnum) static DWORD On_SPELLXYD(TCmd *pCmd, int pnum) { - TCmdLocParam3 *p = (TCmdLocParam3 *)pCmd; + auto *p = (TCmdLocParam3 *)pCmd; if (gbBufferMsgs != 1 && currlevel == plr[pnum].plrlevel) { - spell_id spell = (spell_id)p->wParam1; + auto spell = static_cast(p->wParam1); if (currlevel != 0 || spelldata[spell].sTownSpell) { ClrPlrPath(pnum); plr[pnum].destAction = ACTION_SPELLWALL; @@ -1668,10 +1668,10 @@ static DWORD On_SPELLXYD(TCmd *pCmd, int pnum) static DWORD On_SPELLXY(TCmd *pCmd, int pnum) { - TCmdLocParam2 *p = (TCmdLocParam2 *)pCmd; + auto *p = (TCmdLocParam2 *)pCmd; if (gbBufferMsgs != 1 && currlevel == plr[pnum].plrlevel) { - spell_id spell = (spell_id)p->wParam1; + auto spell = static_cast(p->wParam1); if (currlevel != 0 || spelldata[spell].sTownSpell) { ClrPlrPath(pnum); plr[pnum].destAction = ACTION_SPELL; @@ -1690,10 +1690,10 @@ static DWORD On_SPELLXY(TCmd *pCmd, int pnum) static DWORD On_TSPELLXY(TCmd *pCmd, int pnum) { - TCmdLocParam2 *p = (TCmdLocParam2 *)pCmd; + auto *p = (TCmdLocParam2 *)pCmd; if (gbBufferMsgs != 1 && currlevel == plr[pnum].plrlevel) { - spell_id spell = (spell_id)p->wParam1; + auto spell = static_cast(p->wParam1); if (currlevel != 0 || spelldata[spell].sTownSpell) { ClrPlrPath(pnum); plr[pnum].destAction = ACTION_SPELL; @@ -1712,7 +1712,7 @@ static DWORD On_TSPELLXY(TCmd *pCmd, int pnum) static DWORD On_OPOBJXY(TCmd *pCmd, int pnum) { - TCmdLocParam1 *p = (TCmdLocParam1 *)pCmd; + auto *p = (TCmdLocParam1 *)pCmd; if (gbBufferMsgs != 1 && currlevel == plr[pnum].plrlevel) { if (object[p->wParam1]._oSolidFlag || object[p->wParam1]._oDoorFlag) @@ -1728,7 +1728,7 @@ static DWORD On_OPOBJXY(TCmd *pCmd, int pnum) static DWORD On_DISARMXY(TCmd *pCmd, int pnum) { - TCmdLocParam1 *p = (TCmdLocParam1 *)pCmd; + auto *p = (TCmdLocParam1 *)pCmd; if (gbBufferMsgs != 1 && currlevel == plr[pnum].plrlevel) { if (object[p->wParam1]._oSolidFlag || object[p->wParam1]._oDoorFlag) @@ -1744,7 +1744,7 @@ static DWORD On_DISARMXY(TCmd *pCmd, int pnum) static DWORD On_OPOBJT(TCmd *pCmd, int pnum) { - TCmdParam1 *p = (TCmdParam1 *)pCmd; + auto *p = (TCmdParam1 *)pCmd; if (gbBufferMsgs != 1 && currlevel == plr[pnum].plrlevel) { plr[pnum].destAction = ACTION_OPERATETK; @@ -1756,7 +1756,7 @@ static DWORD On_OPOBJT(TCmd *pCmd, int pnum) static DWORD On_ATTACKID(TCmd *pCmd, int pnum) { - TCmdParam1 *p = (TCmdParam1 *)pCmd; + auto *p = (TCmdParam1 *)pCmd; if (gbBufferMsgs != 1 && currlevel == plr[pnum].plrlevel) { int distx = abs(plr[pnum]._px - monster[p->wParam1]._mfutx); @@ -1772,7 +1772,7 @@ static DWORD On_ATTACKID(TCmd *pCmd, int pnum) static DWORD On_ATTACKPID(TCmd *pCmd, int pnum) { - TCmdParam1 *p = (TCmdParam1 *)pCmd; + auto *p = (TCmdParam1 *)pCmd; if (gbBufferMsgs != 1 && currlevel == plr[pnum].plrlevel) { MakePlrPath(pnum, plr[p->wParam1]._pfutx, plr[p->wParam1]._pfuty, false); @@ -1785,7 +1785,7 @@ static DWORD On_ATTACKPID(TCmd *pCmd, int pnum) static DWORD On_RATTACKID(TCmd *pCmd, int pnum) { - TCmdParam1 *p = (TCmdParam1 *)pCmd; + auto *p = (TCmdParam1 *)pCmd; if (gbBufferMsgs != 1 && currlevel == plr[pnum].plrlevel) { ClrPlrPath(pnum); @@ -1798,7 +1798,7 @@ static DWORD On_RATTACKID(TCmd *pCmd, int pnum) static DWORD On_RATTACKPID(TCmd *pCmd, int pnum) { - TCmdParam1 *p = (TCmdParam1 *)pCmd; + auto *p = (TCmdParam1 *)pCmd; if (gbBufferMsgs != 1 && currlevel == plr[pnum].plrlevel) { ClrPlrPath(pnum); @@ -1811,10 +1811,10 @@ static DWORD On_RATTACKPID(TCmd *pCmd, int pnum) static DWORD On_SPELLID(TCmd *pCmd, int pnum) { - TCmdParam3 *p = (TCmdParam3 *)pCmd; + auto *p = (TCmdParam3 *)pCmd; if (gbBufferMsgs != 1 && currlevel == plr[pnum].plrlevel) { - spell_id spell = (spell_id)p->wParam2; + auto spell = static_cast(p->wParam2); if (currlevel != 0 || spelldata[spell].sTownSpell) { ClrPlrPath(pnum); plr[pnum].destAction = ACTION_SPELLMON; @@ -1832,10 +1832,10 @@ static DWORD On_SPELLID(TCmd *pCmd, int pnum) static DWORD On_SPELLPID(TCmd *pCmd, int pnum) { - TCmdParam3 *p = (TCmdParam3 *)pCmd; + auto *p = (TCmdParam3 *)pCmd; if (gbBufferMsgs != 1 && currlevel == plr[pnum].plrlevel) { - spell_id spell = (spell_id)p->wParam2; + auto spell = static_cast(p->wParam2); if (currlevel != 0 || spelldata[spell].sTownSpell) { ClrPlrPath(pnum); plr[pnum].destAction = ACTION_SPELLPLR; @@ -1853,10 +1853,10 @@ static DWORD On_SPELLPID(TCmd *pCmd, int pnum) static DWORD On_TSPELLID(TCmd *pCmd, int pnum) { - TCmdParam3 *p = (TCmdParam3 *)pCmd; + auto *p = (TCmdParam3 *)pCmd; if (gbBufferMsgs != 1 && currlevel == plr[pnum].plrlevel) { - spell_id spell = (spell_id)p->wParam2; + auto spell = static_cast(p->wParam2); if (currlevel != 0 || spelldata[spell].sTownSpell) { ClrPlrPath(pnum); plr[pnum].destAction = ACTION_SPELLMON; @@ -1874,10 +1874,10 @@ static DWORD On_TSPELLID(TCmd *pCmd, int pnum) static DWORD On_TSPELLPID(TCmd *pCmd, int pnum) { - TCmdParam3 *p = (TCmdParam3 *)pCmd; + auto *p = (TCmdParam3 *)pCmd; if (gbBufferMsgs != 1 && currlevel == plr[pnum].plrlevel) { - spell_id spell = (spell_id)p->wParam2; + auto spell = static_cast(p->wParam2); if (currlevel != 0 || spelldata[spell].sTownSpell) { ClrPlrPath(pnum); plr[pnum].destAction = ACTION_SPELLPLR; @@ -1895,7 +1895,7 @@ static DWORD On_TSPELLPID(TCmd *pCmd, int pnum) static DWORD On_KNOCKBACK(TCmd *pCmd, int pnum) { - TCmdParam1 *p = (TCmdParam1 *)pCmd; + auto *p = (TCmdParam1 *)pCmd; if (gbBufferMsgs != 1 && currlevel == plr[pnum].plrlevel) { M_GetKnockback(p->wParam1); @@ -1907,7 +1907,7 @@ static DWORD On_KNOCKBACK(TCmd *pCmd, int pnum) static DWORD On_RESURRECT(TCmd *pCmd, int pnum) { - TCmdParam1 *p = (TCmdParam1 *)pCmd; + auto *p = (TCmdParam1 *)pCmd; if (gbBufferMsgs == 1) msg_send_packet(pnum, p, sizeof(*p)); @@ -1921,7 +1921,7 @@ static DWORD On_RESURRECT(TCmd *pCmd, int pnum) static DWORD On_HEALOTHER(TCmd *pCmd, int pnum) { - TCmdParam1 *p = (TCmdParam1 *)pCmd; + auto *p = (TCmdParam1 *)pCmd; if (gbBufferMsgs != 1 && currlevel == plr[pnum].plrlevel) DoHealOther(pnum, p->wParam1); @@ -1931,7 +1931,7 @@ static DWORD On_HEALOTHER(TCmd *pCmd, int pnum) static DWORD On_TALKXY(TCmd *pCmd, int pnum) { - TCmdLocParam1 *p = (TCmdLocParam1 *)pCmd; + auto *p = (TCmdLocParam1 *)pCmd; if (gbBufferMsgs != 1 && currlevel == plr[pnum].plrlevel) { MakePlrPath(pnum, p->x, p->y, false); @@ -1944,7 +1944,7 @@ static DWORD On_TALKXY(TCmd *pCmd, int pnum) static DWORD On_NEWLVL(TCmd *pCmd, int pnum) { - TCmdParam2 *p = (TCmdParam2 *)pCmd; + auto *p = (TCmdParam2 *)pCmd; if (gbBufferMsgs == 1) msg_send_packet(pnum, p, sizeof(*p)); @@ -1956,7 +1956,7 @@ static DWORD On_NEWLVL(TCmd *pCmd, int pnum) static DWORD On_WARP(TCmd *pCmd, int pnum) { - TCmdParam1 *p = (TCmdParam1 *)pCmd; + auto *p = (TCmdParam1 *)pCmd; if (gbBufferMsgs == 1) msg_send_packet(pnum, p, sizeof(*p)); @@ -1969,7 +1969,7 @@ static DWORD On_WARP(TCmd *pCmd, int pnum) static DWORD On_MONSTDEATH(TCmd *pCmd, int pnum) { - TCmdLocParam1 *p = (TCmdLocParam1 *)pCmd; + auto *p = (TCmdLocParam1 *)pCmd; if (gbBufferMsgs == 1) msg_send_packet(pnum, p, sizeof(*p)); @@ -1984,7 +1984,7 @@ static DWORD On_MONSTDEATH(TCmd *pCmd, int pnum) static DWORD On_KILLGOLEM(TCmd *pCmd, int pnum) { - TCmdLocParam1 *p = (TCmdLocParam1 *)pCmd; + auto *p = (TCmdLocParam1 *)pCmd; if (gbBufferMsgs == 1) msg_send_packet(pnum, p, sizeof(*p)); @@ -1999,7 +1999,7 @@ static DWORD On_KILLGOLEM(TCmd *pCmd, int pnum) static DWORD On_AWAKEGOLEM(TCmd *pCmd, int pnum) { - TCmdGolem *p = (TCmdGolem *)pCmd; + auto *p = (TCmdGolem *)pCmd; if (gbBufferMsgs == 1) msg_send_packet(pnum, p, sizeof(*p)); @@ -2025,7 +2025,7 @@ static DWORD On_AWAKEGOLEM(TCmd *pCmd, int pnum) static DWORD On_MONSTDAMAGE(TCmd *pCmd, int pnum) { - TCmdMonDamage *p = (TCmdMonDamage *)pCmd; + auto *p = (TCmdMonDamage *)pCmd; if (gbBufferMsgs == 1) msg_send_packet(pnum, p, sizeof(*p)); // BUGFIX: change to sizeof(*p) or it still uses TCmdParam2 size for hellfire (fixed) @@ -2046,7 +2046,7 @@ static DWORD On_MONSTDAMAGE(TCmd *pCmd, int pnum) static DWORD On_PLRDEAD(TCmd *pCmd, int pnum) { - TCmdParam1 *p = (TCmdParam1 *)pCmd; + auto *p = (TCmdParam1 *)pCmd; if (gbBufferMsgs == 1) msg_send_packet(pnum, p, sizeof(*p)); @@ -2060,7 +2060,7 @@ static DWORD On_PLRDEAD(TCmd *pCmd, int pnum) static DWORD On_PLRDAMAGE(TCmd *pCmd, int pnum) { - TCmdDamage *p = (TCmdDamage *)pCmd; + auto *p = (TCmdDamage *)pCmd; if (p->bPlr == myplr && currlevel != 0 && gbBufferMsgs != 1) { if (currlevel == plr[pnum].plrlevel && p->dwDam <= 192000 && plr[myplr]._pHitPoints >> 6 > 0) { @@ -2073,7 +2073,7 @@ static DWORD On_PLRDAMAGE(TCmd *pCmd, int pnum) static DWORD On_OPENDOOR(TCmd *pCmd, int pnum) { - TCmdParam1 *p = (TCmdParam1 *)pCmd; + auto *p = (TCmdParam1 *)pCmd; if (gbBufferMsgs == 1) msg_send_packet(pnum, p, sizeof(*p)); @@ -2088,7 +2088,7 @@ static DWORD On_OPENDOOR(TCmd *pCmd, int pnum) static DWORD On_CLOSEDOOR(TCmd *pCmd, int pnum) { - TCmdParam1 *p = (TCmdParam1 *)pCmd; + auto *p = (TCmdParam1 *)pCmd; if (gbBufferMsgs == 1) msg_send_packet(pnum, p, sizeof(*p)); @@ -2103,7 +2103,7 @@ static DWORD On_CLOSEDOOR(TCmd *pCmd, int pnum) static DWORD On_OPERATEOBJ(TCmd *pCmd, int pnum) { - TCmdParam1 *p = (TCmdParam1 *)pCmd; + auto *p = (TCmdParam1 *)pCmd; if (gbBufferMsgs == 1) msg_send_packet(pnum, p, sizeof(*p)); @@ -2118,7 +2118,7 @@ static DWORD On_OPERATEOBJ(TCmd *pCmd, int pnum) static DWORD On_PLROPOBJ(TCmd *pCmd, int pnum) { - TCmdParam2 *p = (TCmdParam2 *)pCmd; + auto *p = (TCmdParam2 *)pCmd; if (gbBufferMsgs == 1) msg_send_packet(pnum, p, sizeof(*p)); @@ -2133,7 +2133,7 @@ static DWORD On_PLROPOBJ(TCmd *pCmd, int pnum) static DWORD On_BREAKOBJ(TCmd *pCmd, int pnum) { - TCmdParam2 *p = (TCmdParam2 *)pCmd; + auto *p = (TCmdParam2 *)pCmd; if (gbBufferMsgs == 1) msg_send_packet(pnum, p, sizeof(*p)); @@ -2148,7 +2148,7 @@ static DWORD On_BREAKOBJ(TCmd *pCmd, int pnum) static DWORD On_CHANGEPLRITEMS(TCmd *pCmd, int pnum) { - TCmdChItem *p = (TCmdChItem *)pCmd; + auto *p = (TCmdChItem *)pCmd; if (gbBufferMsgs == 1) msg_send_packet(pnum, p, sizeof(*p)); @@ -2160,7 +2160,7 @@ static DWORD On_CHANGEPLRITEMS(TCmd *pCmd, int pnum) static DWORD On_DELPLRITEMS(TCmd *pCmd, int pnum) { - TCmdDelItem *p = (TCmdDelItem *)pCmd; + auto *p = (TCmdDelItem *)pCmd; if (gbBufferMsgs == 1) msg_send_packet(pnum, p, sizeof(*p)); @@ -2172,7 +2172,7 @@ static DWORD On_DELPLRITEMS(TCmd *pCmd, int pnum) static DWORD On_PLRLEVEL(TCmd *pCmd, int pnum) { - TCmdParam1 *p = (TCmdParam1 *)pCmd; + auto *p = (TCmdParam1 *)pCmd; if (gbBufferMsgs == 1) msg_send_packet(pnum, p, sizeof(*p)); @@ -2184,7 +2184,7 @@ static DWORD On_PLRLEVEL(TCmd *pCmd, int pnum) static DWORD On_DROPITEM(TCmd *pCmd, int pnum) { - TCmdPItem *p = (TCmdPItem *)pCmd; + auto *p = (TCmdPItem *)pCmd; if (gbBufferMsgs == 1) msg_send_packet(pnum, p, sizeof(*p)); @@ -2196,7 +2196,7 @@ static DWORD On_DROPITEM(TCmd *pCmd, int pnum) static DWORD On_SEND_PLRINFO(TCmd *pCmd, int pnum) { - TCmdPlrInfoHdr *p = (TCmdPlrInfoHdr *)pCmd; + auto *p = (TCmdPlrInfoHdr *)pCmd; if (gbBufferMsgs == 1) msg_send_packet(pnum, p, p->wBytes + sizeof(*p)); @@ -2213,7 +2213,7 @@ static DWORD On_ACK_PLRINFO(TCmd *pCmd, int pnum) static DWORD On_PLAYER_JOINLEVEL(TCmd *pCmd, int pnum) { - TCmdLocParam1 *p = (TCmdLocParam1 *)pCmd; + auto *p = (TCmdLocParam1 *)pCmd; if (gbBufferMsgs == 1) msg_send_packet(pnum, p, sizeof(*p)); @@ -2257,7 +2257,7 @@ static DWORD On_PLAYER_JOINLEVEL(TCmd *pCmd, int pnum) static DWORD On_ACTIVATEPORTAL(TCmd *pCmd, int pnum) { - TCmdLocParam3 *p = (TCmdLocParam3 *)pCmd; + auto *p = (TCmdLocParam3 *)pCmd; if (gbBufferMsgs == 1) msg_send_packet(pnum, p, sizeof(*p)); @@ -2317,7 +2317,7 @@ static DWORD On_RETOWN(TCmd *pCmd, int pnum) static DWORD On_SETSTR(TCmd *pCmd, int pnum) { - TCmdParam1 *p = (TCmdParam1 *)pCmd; + auto *p = (TCmdParam1 *)pCmd; if (gbBufferMsgs == 1) msg_send_packet(pnum, p, sizeof(*p)); @@ -2329,7 +2329,7 @@ static DWORD On_SETSTR(TCmd *pCmd, int pnum) static DWORD On_SETDEX(TCmd *pCmd, int pnum) { - TCmdParam1 *p = (TCmdParam1 *)pCmd; + auto *p = (TCmdParam1 *)pCmd; if (gbBufferMsgs == 1) msg_send_packet(pnum, p, sizeof(*p)); @@ -2341,7 +2341,7 @@ static DWORD On_SETDEX(TCmd *pCmd, int pnum) static DWORD On_SETMAG(TCmd *pCmd, int pnum) { - TCmdParam1 *p = (TCmdParam1 *)pCmd; + auto *p = (TCmdParam1 *)pCmd; if (gbBufferMsgs == 1) msg_send_packet(pnum, p, sizeof(*p)); @@ -2353,7 +2353,7 @@ static DWORD On_SETMAG(TCmd *pCmd, int pnum) static DWORD On_SETVIT(TCmd *pCmd, int pnum) { - TCmdParam1 *p = (TCmdParam1 *)pCmd; + auto *p = (TCmdParam1 *)pCmd; if (gbBufferMsgs == 1) msg_send_packet(pnum, p, sizeof(*p)); @@ -2370,7 +2370,7 @@ static DWORD On_STRING(TCmd *pCmd, int pnum) static DWORD On_SYNCQUEST(TCmd *pCmd, int pnum) { - TCmdQuest *p = (TCmdQuest *)pCmd; + auto *p = (TCmdQuest *)pCmd; if (gbBufferMsgs == 1) msg_send_packet(pnum, p, sizeof(*p)); @@ -2432,7 +2432,7 @@ static DWORD On_DEBUG(TCmd *pCmd) static DWORD On_NOVA(TCmd *pCmd, int pnum) { - TCmdLoc *p = (TCmdLoc *)pCmd; + auto *p = (TCmdLoc *)pCmd; if (gbBufferMsgs != 1 && currlevel == plr[pnum].plrlevel && pnum != myplr) { ClrPlrPath(pnum); @@ -2482,7 +2482,7 @@ static DWORD On_NAKRUL(TCmd *pCmd) { if (gbBufferMsgs != 1) { operate_lv24_lever(); - IsUberRoomOpened = 1; + IsUberRoomOpened = true; quests[Q_NAKRUL]._qactive = QUEST_DONE; monster_some_crypt(); } @@ -2491,7 +2491,7 @@ static DWORD On_NAKRUL(TCmd *pCmd) static DWORD On_OPENHIVE(TCmd *pCmd, int pnum) { - TCmdLocParam2 *p = (TCmdLocParam2 *)pCmd; + auto *p = (TCmdLocParam2 *)pCmd; if (gbBufferMsgs != 1) { AddMissile(p->x, p->y, p->wParam1, p->wParam2, 0, MIS_HIVEEXP2, TARGET_MONSTERS, pnum, 0, 0); TownOpenHive(); diff --git a/Source/multi.cpp b/Source/multi.cpp index be88d80a0..da1efdcc9 100644 --- a/Source/multi.cpp +++ b/Source/multi.cpp @@ -657,7 +657,7 @@ static bool multi_upgrade(bool *pfExitProgram) DrawDlg("Network upgrade failed"); } } else { - *pfExitProgram = 1; + *pfExitProgram = true; } result = false; @@ -672,7 +672,7 @@ static void multi_handle_events(_SNETEVENT *pEvt) switch (pEvt->eventid) { case EVENT_TYPE_PLAYER_CREATE_GAME: { - GameData *gameData = (GameData *)pEvt->data; + auto *gameData = (GameData *)pEvt->data; if (gameData->size != sizeof(GameData)) app_fatal("Invalid size of game data: %d", gameData->size); sgGameInitInfo = *gameData; @@ -737,7 +737,7 @@ void NetClose() bool NetInit(bool bSinglePlayer, bool *pfExitProgram) { - while (1) { + while (true) { *pfExitProgram = false; SetRndSeed(0); sgGameInitInfo.size = sizeof(sgGameInitInfo); diff --git a/Source/nthread.cpp b/Source/nthread.cpp index 576c43559..31b86e116 100644 --- a/Source/nthread.cpp +++ b/Source/nthread.cpp @@ -123,7 +123,7 @@ static unsigned int nthread_handler(void *data) bool received; if (nthread_should_run) { - while (1) { + while (true) { sgMemCrit.Enter(); if (!nthread_should_run) break; diff --git a/Source/objects.cpp b/Source/objects.cpp index 228c4d205..30d525d6d 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -3,8 +3,8 @@ * * Implementation of object functionality, interaction, spawning, loading, etc. */ -#include -#include +#include +#include #include "automap.h" #include "control.h" @@ -362,7 +362,7 @@ void InitRndLocObj(int min, int max, _object_id objtype) numobjs = random_(139, max - min) + min; for (i = 0; i < numobjs; i++) { - while (1) { + while (true) { xp = random_(139, 80) + 16; yp = random_(139, 80) + 16; if (RndLocOk(xp - 1, yp - 1) @@ -387,7 +387,7 @@ void InitRndLocBigObj(int min, int max, _object_id objtype) numobjs = random_(140, max - min) + min; for (i = 0; i < numobjs; i++) { - while (1) { + while (true) { xp = random_(140, 80) + 16; yp = random_(140, 80) + 16; if (RndLocOk(xp - 1, yp - 2) @@ -1630,7 +1630,7 @@ void GetRndObjLoc(int randarea, int *xx, int *yy) return; tries = 0; - while (1) { + while (true) { tries++; if (tries > 1000 && randarea > 1) randarea--; @@ -2948,7 +2948,7 @@ void OperateLever(int pnum, int i) } if (currlevel == 24) { operate_lv24_lever(); - IsUberLeverActivated = 1; + IsUberLeverActivated = true; mapflag = false; quests[Q_NAKRUL]._qactive = QUEST_DONE; } @@ -3484,27 +3484,27 @@ bool OperateShrineHidden(int pnum) return false; int cnt = 0; - for (int j = 0; j < NUM_INVLOC; j++) { - if (!plr[pnum].InvBody[j].isEmpty()) + for (const auto &item : plr[pnum].InvBody) { + if (!item.isEmpty()) cnt++; } if (cnt > 0) { - for (int j = 0; j < NUM_INVLOC; j++) { - if (!plr[pnum].InvBody[j].isEmpty() - && plr[pnum].InvBody[j]._iMaxDur != DUR_INDESTRUCTIBLE - && plr[pnum].InvBody[j]._iMaxDur != 0) { - plr[pnum].InvBody[j]._iDurability += 10; - plr[pnum].InvBody[j]._iMaxDur += 10; - if (plr[pnum].InvBody[j]._iDurability > plr[pnum].InvBody[j]._iMaxDur) - plr[pnum].InvBody[j]._iDurability = plr[pnum].InvBody[j]._iMaxDur; + for (auto &item : plr[pnum].InvBody) { + if (!item.isEmpty() + && item._iMaxDur != DUR_INDESTRUCTIBLE + && item._iMaxDur != 0) { + item._iDurability += 10; + item._iMaxDur += 10; + if (item._iDurability > item._iMaxDur) + item._iDurability = item._iMaxDur; } } while (true) { cnt = 0; - for (int j = 0; j < NUM_INVLOC; j++) { - if (!plr[pnum].InvBody[j].isEmpty()) - if (plr[pnum].InvBody[j]._iMaxDur != DUR_INDESTRUCTIBLE - && plr[pnum].InvBody[j]._iMaxDur != 0) + for (auto &item : plr[pnum].InvBody) { + if (!item.isEmpty()) + if (item._iMaxDur != DUR_INDESTRUCTIBLE + && item._iMaxDur != 0) cnt++; } if (cnt == 0) @@ -3649,17 +3649,17 @@ bool OperateShrineStone(int pnum) if (pnum != myplr) return true; - for (int j = 0; j < NUM_INVLOC; j++) { - if (plr[pnum].InvBody[j]._itype == ITYPE_STAFF) - plr[pnum].InvBody[j]._iCharges = plr[pnum].InvBody[j]._iMaxCharges; + for (auto &item : plr[pnum].InvBody) { + if (item._itype == ITYPE_STAFF) + item._iCharges = item._iMaxCharges; } for (int j = 0; j < plr[pnum]._pNumInv; j++) { if (plr[pnum].InvList[j]._itype == ITYPE_STAFF) plr[pnum].InvList[j]._iCharges = plr[pnum].InvList[j]._iMaxCharges; } - for (int j = 0; j < MAXBELTITEMS; j++) { - if (plr[pnum].SpdList[j]._itype == ITYPE_STAFF) - plr[pnum].SpdList[j]._iCharges = plr[pnum].SpdList[j]._iMaxCharges; // belt items don't have charges? + for (auto &item : plr[pnum].SpdList) { + if (item._itype == ITYPE_STAFF) + item._iCharges = item._iMaxCharges; // belt items don't have charges? } InitDiabloMsg(EMSG_SHRINE_STONE); @@ -3674,12 +3674,12 @@ bool OperateShrineReligious(int pnum) if (pnum != myplr) return true; - for (int j = 0; j < NUM_INVLOC; j++) - plr[pnum].InvBody[j]._iDurability = plr[pnum].InvBody[j]._iMaxDur; + for (auto &item : plr[pnum].InvBody) + item._iDurability = item._iMaxDur; for (int j = 0; j < plr[pnum]._pNumInv; j++) plr[pnum].InvList[j]._iDurability = plr[pnum].InvList[j]._iMaxDur; - for (int j = 0; j < MAXBELTITEMS; j++) - plr[pnum].SpdList[j]._iDurability = plr[pnum].SpdList[j]._iMaxDur; // belt items don't have durability? + for (auto &item : plr[pnum].SpdList) + item._iDurability = item._iMaxDur; // belt items don't have durability? InitDiabloMsg(EMSG_SHRINE_RELIGIOUS); @@ -3841,21 +3841,21 @@ bool OperateShrineEldritch(int pnum) } } } - for (int j = 0; j < MAXBELTITEMS; j++) { - if (plr[pnum].SpdList[j]._itype == ITYPE_MISC) { - if (plr[pnum].SpdList[j]._iMiscId == IMISC_HEAL - || plr[pnum].SpdList[j]._iMiscId == IMISC_MANA) { + for (auto &item : plr[pnum].SpdList) { + if (item._itype == ITYPE_MISC) { + if (item._iMiscId == IMISC_HEAL + || item._iMiscId == IMISC_MANA) { SetPlrHandItem(&plr[pnum].HoldItem, ItemMiscIdIdx(IMISC_REJUV)); GetPlrHandSeed(&plr[pnum].HoldItem); plr[pnum].HoldItem._iStatFlag = true; - plr[pnum].SpdList[j] = plr[pnum].HoldItem; + item = plr[pnum].HoldItem; } - if (plr[pnum].SpdList[j]._iMiscId == IMISC_FULLHEAL - || plr[pnum].SpdList[j]._iMiscId == IMISC_FULLMANA) { + if (item._iMiscId == IMISC_FULLHEAL + || item._iMiscId == IMISC_FULLMANA) { SetPlrHandItem(&plr[pnum].HoldItem, ItemMiscIdIdx(IMISC_FULLREJUV)); GetPlrHandSeed(&plr[pnum].HoldItem); plr[pnum].HoldItem._iStatFlag = true; - plr[pnum].SpdList[j] = plr[pnum].HoldItem; + item = plr[pnum].HoldItem; } } } @@ -3972,14 +3972,14 @@ bool OperateShrineSpiritual(int pnum) if (pnum != myplr) return false; - for (int j = 0; j < NUM_INV_GRID_ELEM; j++) { - if (plr[pnum].InvGrid[j] == 0) { + for (int8_t &gridItem : plr[pnum].InvGrid) { + if (gridItem == 0) { int r = 5 * leveltype + random_(160, 10 * leveltype); DWORD t = plr[pnum]._pNumInv; // check plr[pnum].InvList[t] = golditem; plr[pnum].InvList[t]._iSeed = AdvanceRndSeed(); plr[pnum]._pNumInv++; - plr[pnum].InvGrid[j] = plr[pnum]._pNumInv; + gridItem = plr[pnum]._pNumInv; plr[pnum].InvList[t]._ivalue = r; plr[pnum]._pGold += r; SetGoldCurs(pnum, t); @@ -4073,8 +4073,8 @@ bool OperateShrineSecluded(int pnum) return true; for (int yy = 0; yy < DMAXY; yy++) { - for (int xx = 0; xx < DMAXX; xx++) { - automapview[xx][yy] = true; + for (auto &xx : automapview) { + xx[yy] = true; } } @@ -4124,17 +4124,17 @@ bool OperateShrineGlimmering(int pnum) if (pnum != myplr) return false; - for (int j = 0; j < NUM_INVLOC; j++) { - if (plr[pnum].InvBody[j]._iMagical && !plr[pnum].InvBody[j]._iIdentified) - plr[pnum].InvBody[j]._iIdentified = true; + for (auto &item : plr[pnum].InvBody) { + if (item._iMagical && !item._iIdentified) + item._iIdentified = true; } for (int j = 0; j < plr[pnum]._pNumInv; j++) { if (plr[pnum].InvList[j]._iMagical && !plr[pnum].InvList[j]._iIdentified) plr[pnum].InvList[j]._iIdentified = true; } - for (int j = 0; j < MAXBELTITEMS; j++) { - if (plr[pnum].SpdList[j]._iMagical && !plr[pnum].SpdList[j]._iIdentified) - plr[pnum].SpdList[j]._iIdentified = true; // belt items can't be magical? + for (auto &item : plr[pnum].SpdList) { + if (item._iMagical && !item._iIdentified) + item._iIdentified = true; // belt items can't be magical? } InitDiabloMsg(EMSG_SHRINE_GLIMMERING); @@ -4369,12 +4369,11 @@ bool OperateShrineMurphys(int pnum) return false; bool broke = false; - for (int j = 0; j < NUM_INVLOC; j++) { - ItemStruct *item = &plr[myplr].InvBody[j]; - if (!item->isEmpty() && random_(0, 3) == 0) { - if (item->_iDurability != DUR_INDESTRUCTIBLE) { - if (item->_iDurability) { - item->_iDurability /= 2; + for (auto &item : plr[myplr].InvBody) { + if (!item.isEmpty() && random_(0, 3) == 0) { + if (item._iDurability != DUR_INDESTRUCTIBLE) { + if (item._iDurability) { + item._iDurability /= 2; broke = true; break; } @@ -4860,7 +4859,7 @@ void OperateStoryBook(int pnum, int i) } } else if (currlevel >= 21) { quests[Q_NAKRUL]._qactive = QUEST_ACTIVE; - quests[Q_NAKRUL]._qlog = 1; + quests[Q_NAKRUL]._qlog = true; quests[Q_NAKRUL]._qmsg = static_cast<_speech_id>(object[i]._oVar2); } InitQTextMsg(object[i]._oVar2); @@ -4892,9 +4891,9 @@ bool objectIsDisabled(int i) return true; if ((object[i]._otype != OBJ_SHRINEL) && (object[i]._otype != OBJ_SHRINER)) return false; - if ((object[i]._oVar1 == SHRINE_FASCINATING) || - (object[i]._oVar1 == SHRINE_ORNATE) || - (object[i]._oVar1 == SHRINE_SACRED)) + if ((object[i]._oVar1 == SHRINE_FASCINATING) + || (object[i]._oVar1 == SHRINE_ORNATE) + || (object[i]._oVar1 == SHRINE_SACRED)) return true; return false; } @@ -5695,7 +5694,7 @@ void objects_rnd_454BEA() { int xp, yp; - while (1) { + while (true) { xp = random_(141, 80) + 16; yp = random_(141, 80) + 16; if (RndLocOk(xp - 1, yp - 1) diff --git a/Source/palette.cpp b/Source/palette.cpp index fc05f8b00..208137613 100644 --- a/Source/palette.cpp +++ b/Source/palette.cpp @@ -276,12 +276,12 @@ static void CycleColors(int from, int to) if (!sgOptions.Graphics.bBlendedTransparancy) return; - for (int i = 0; i < 256; i++) { - Uint8 col = paletteTransparencyLookup[i][from]; + for (auto &palette : paletteTransparencyLookup) { + Uint8 col = palette[from]; for (int j = from; j < to; j++) { - paletteTransparencyLookup[i][j] = paletteTransparencyLookup[i][j + 1]; + palette[j] = palette[j + 1]; } - paletteTransparencyLookup[i][to] = col; + palette[to] = col; } Uint8 colRow[256]; @@ -308,12 +308,12 @@ static void CycleColorsReverse(int from, int to) if (!sgOptions.Graphics.bBlendedTransparancy) return; - for (int i = 0; i < 256; i++) { - Uint8 col = paletteTransparencyLookup[i][to]; + for (auto &palette : paletteTransparencyLookup) { + Uint8 col = palette[to]; for (int j = to; j > from; j--) { - paletteTransparencyLookup[i][j] = paletteTransparencyLookup[i][j - 1]; + palette[j] = palette[j - 1]; } - paletteTransparencyLookup[i][from] = col; + palette[from] = col; } Uint8 colRow[256]; diff --git a/Source/player.cpp b/Source/player.cpp index 2e94abd1f..d2073e606 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -538,7 +538,7 @@ void SetPlrAnims(int pnum) } plr[pnum]._pSFNum = PlrGFXAnimLens[static_cast(pc)][10]; - anim_weapon_id gn = static_cast(plr[pnum]._pgfxnum & 0xF); + auto gn = static_cast(plr[pnum]._pgfxnum & 0xF); if (pc == HeroClass::Warrior) { if (gn == ANIM_ID_BOW) { if (leveltype != DTYPE_TOWN) { @@ -760,8 +760,8 @@ void CreatePlayer(int pnum, HeroClass c) plr[pnum]._pMemSpells = 0; } - for (size_t i = 0; i < sizeof(plr[pnum]._pSplLvl) / sizeof(plr[pnum]._pSplLvl[0]); i++) { - plr[pnum]._pSplLvl[i] = 0; + for (int8_t &spellLevel : plr[pnum]._pSplLvl) { + spellLevel = 0; } plr[pnum]._pSpellFlags = 0; @@ -790,8 +790,8 @@ void CreatePlayer(int pnum, HeroClass c) plr[pnum]._pgfxnum = ANIM_ID_SWORD_SHIELD; } - for (int i = 0; i < NUMLEVELS; i++) { - plr[pnum]._pLvlVisited[i] = false; + for (bool &levelVisited : plr[pnum]._pLvlVisited) { + levelVisited = false; } for (int i = 0; i < 10; i++) { @@ -4093,9 +4093,9 @@ void CheckStats(int p) app_fatal("CheckStats: illegal player %d", p); } - for (auto i : enum_values()) { - int maxStatPoint = plr[p].GetMaximumAttributeValue(i); - switch (i) { + for (auto attribute : enum_values()) { + int maxStatPoint = plr[p].GetMaximumAttributeValue(attribute); + switch (attribute) { case CharacterAttribute::Strength: if (plr[p]._pBaseStr > maxStatPoint) { plr[p]._pBaseStr = maxStatPoint; @@ -4445,7 +4445,7 @@ void PlayDungMsgs() sfxdelay = 10; sfxdnum = USFX_DEFILER1; quests[Q_DEFILER]._qactive = QUEST_ACTIVE; - quests[Q_DEFILER]._qlog = 1; + quests[Q_DEFILER]._qlog = true; quests[Q_DEFILER]._qmsg = TEXT_DEFILER1; plr[myplr].pDungMsgs2 |= 1; } else if (currlevel == 19 && !plr[myplr]._pLvlVisited[19] && !gbIsMultiplayer && !(plr[myplr].pDungMsgs2 & 4)) { diff --git a/Source/player.h b/Source/player.h index fe2f98186..f6066a64a 100644 --- a/Source/player.h +++ b/Source/player.h @@ -148,7 +148,7 @@ enum player_weapon_type : uint8_t { struct PlayerStruct { PLR_MODE _pmode; - Sint8 walkpath[MAX_PATH_LENGTH]; + int8_t walkpath[MAX_PATH_LENGTH]; bool plractive; action_id destAction; Sint32 destParam1; @@ -190,11 +190,10 @@ struct PlayerStruct { spell_id _pTSpell; spell_type _pTSplType; spell_id _pRSpell; - // enum spell_type spell_type _pRSplType; spell_id _pSBkSpell; spell_type _pSBkSplType; - Sint8 _pSplLvl[64]; + int8_t _pSplLvl[64]; Uint64 _pMemSpells; // Bitmask of learned spells Uint64 _pAblSpells; // Bitmask of abilities Uint64 _pScrlSpells; // Bitmask of spells available via scrolls @@ -280,7 +279,7 @@ struct PlayerStruct { ItemStruct InvBody[NUM_INVLOC]; ItemStruct InvList[NUM_INV_GRID_ELEM]; Sint32 _pNumInv; - Sint8 InvGrid[NUM_INV_GRID_ELEM]; + int8_t InvGrid[NUM_INV_GRID_ELEM]; ItemStruct SpdList[MAXBELTITEMS]; ItemStruct HoldItem; Sint32 _pIMinDam; diff --git a/Source/plrmsg.cpp b/Source/plrmsg.cpp index 83f52009e..ab1b5ce0e 100644 --- a/Source/plrmsg.cpp +++ b/Source/plrmsg.cpp @@ -100,7 +100,7 @@ static void PrintPlrMsg(CelOutputBuffer out, DWORD x, DWORD y, DWORD width, cons const char *sstr = str; const char *endstr = sstr; - while (1) { + while (true) { if (*sstr) { c = gbFontTransTbl[(BYTE)*sstr++]; c = fontframe[c]; diff --git a/Source/qol.cpp b/Source/qol.cpp index 0b89435a5..126e665a4 100644 --- a/Source/qol.cpp +++ b/Source/qol.cpp @@ -146,13 +146,9 @@ void DrawMonsterHealthBar(CelOutputBuffer out) } } - - bool HasRoomForGold() { - for (int i = 0; i < NUM_INV_GRID_ELEM; i++) { - int idx = plr[myplr].InvGrid[i]; - + for (int idx : plr[myplr].InvGrid) { // Secondary item cell. No need to check those as we'll go through the main item cells anyway. if (idx < 0) continue; diff --git a/Source/render.cpp b/Source/render.cpp index 416f339d4..dc1da80e1 100644 --- a/Source/render.cpp +++ b/Source/render.cpp @@ -5,7 +5,7 @@ */ #include "render.h" -#include +#include #include "lighting.h" #include "options.h" diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index c1e6c96a4..0b9b00a1f 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -764,7 +764,7 @@ static void scrollrt_draw_dungeon(CelOutputBuffer out, int sx, int sy, int dx, i if (light_table_index < lightmax && bDead != 0) { do { DeadStruct *pDeadGuy = &dead[(bDead & 0x1F) - 1]; - direction dd = static_cast((bDead >> 5) & 7); + auto dd = static_cast((bDead >> 5) & 7); int px = dx - pDeadGuy->_deadWidth2; BYTE *pCelBuff = pDeadGuy->_deadData[dd]; assert(pCelBuff != nullptr); @@ -781,10 +781,10 @@ static void scrollrt_draw_dungeon(CelOutputBuffer out, int sx, int sy, int dx, i } else { Cl2DrawLight(out, px, dy, pCelBuff, nCel, pDeadGuy->_deadWidth); } - } while (0); + } while (false); } - DrawObject(out, sx, sy, dx, dy, 1); - DrawItem(out, sx, sy, dx, dy, 1); + DrawObject(out, sx, sy, dx, dy, true); + DrawItem(out, sx, sy, dx, dy, true); if (bFlag & BFLAG_PLAYERLR) { assert((DWORD)(sy - 1) < MAXDUNY); DrawPlayerHelper(out, sx, sy - 1, dx, dy); @@ -802,8 +802,8 @@ static void scrollrt_draw_dungeon(CelOutputBuffer out, int sx, int sy, int dx, i DrawMonsterHelper(out, sx, sy, 0, dx, dy); } DrawMissile(out, sx, sy, dx, dy, false); - DrawObject(out, sx, sy, dx, dy, 0); - DrawItem(out, sx, sy, dx, dy, 0); + DrawObject(out, sx, sy, dx, dy, false); + DrawItem(out, sx, sy, dx, dy, false); if (leveltype != DTYPE_TOWN) { char bArch = dSpecial[sx][sy]; diff --git a/Source/sha.cpp b/Source/sha.cpp index 912b55d53..dd34469bb 100644 --- a/Source/sha.cpp +++ b/Source/sha.cpp @@ -55,7 +55,7 @@ static void SHA1ProcessMessageBlock(SHA1Context *context) DWORD W[80]; DWORD A, B, C, D, E; - DWORD *buf = (DWORD *)context->buffer; + auto *buf = (DWORD *)context->buffer; for (i = 0; i < 16; i++) W[i] = SDL_SwapLE32(buf[i]); diff --git a/Source/stores.cpp b/Source/stores.cpp index f0916cb8a..ee55953f1 100644 --- a/Source/stores.cpp +++ b/Source/stores.cpp @@ -296,16 +296,16 @@ void S_ScrollSPBuy(int idx) stextup = 5; for (idx = 0; boughtitems; idx++) { - if (!premiumitem[idx].isEmpty()) + if (!premiumitems[idx].isEmpty()) boughtitems--; } for (l = 5; l < 20 && idx < SMITH_PREMIUM_ITEMS; l += 4) { - if (!premiumitem[idx].isEmpty()) { - text_color iclr = GetItemTextColor(premiumitem[idx]); - AddSText(20, l, false, premiumitem[idx]._iIName, iclr, true); - AddSTextVal(l, premiumitem[idx]._iIvalue); - PrintStoreItem(&premiumitem[idx], l + 1, iclr); + if (!premiumitems[idx].isEmpty()) { + text_color iclr = GetItemTextColor(premiumitems[idx]); + AddSText(20, l, false, premiumitems[idx]._iIName, iclr, true); + AddSTextVal(l, premiumitems[idx]._iIvalue); + PrintStoreItem(&premiumitems[idx], l + 1, iclr); stextdown = l; } else { l -= 4; @@ -322,7 +322,7 @@ bool S_StartSPBuy() storenumh = 0; for (i = 0; i < SMITH_PREMIUM_ITEMS; i++) { - if (!premiumitem[i].isEmpty()) + if (!premiumitems[i].isEmpty()) storenumh++; } if (!storenumh) { @@ -1300,13 +1300,13 @@ void SmithBuyPItem() idx = stextvhold + ((stextlhold - stextup) >> 2); xx = 0; for (i = 0; idx >= 0; i++) { - if (!premiumitem[i].isEmpty()) { + if (!premiumitems[i].isEmpty()) { idx--; xx = i; } } - premiumitem[xx]._itype = ITYPE_NONE; + premiumitems[xx]._itype = ITYPE_NONE; numpremium--; SpawnPremium(myplr); } @@ -1326,15 +1326,15 @@ void S_SPBuyEnter() xx = stextsval + ((stextsel - stextup) >> 2); idx = 0; for (i = 0; xx >= 0; i++) { - if (!premiumitem[i].isEmpty()) { + if (!premiumitems[i].isEmpty()) { xx--; idx = i; } } - if (plr[myplr]._pGold < premiumitem[idx]._iIvalue) { + if (plr[myplr]._pGold < premiumitems[idx]._iIvalue) { StartStore(STORE_NOMONEY); } else { - plr[myplr].HoldItem = premiumitem[idx]; + plr[myplr].HoldItem = premiumitems[idx]; NewCursor(plr[myplr].HoldItem._iCurs + CURSOR_FIRSTITEM); done = false; if (AutoEquipEnabled(plr[myplr], plr[myplr].HoldItem) && AutoEquip(myplr, plr[myplr].HoldItem, false)) { @@ -2070,7 +2070,7 @@ ItemStruct storehold[48]; ItemStruct smithitem[SMITH_ITEMS]; int numpremium; int premiumlevel; -ItemStruct premiumitem[SMITH_PREMIUM_ITEMS]; +ItemStruct premiumitems[SMITH_PREMIUM_ITEMS]; ItemStruct healitem[20]; @@ -2114,8 +2114,8 @@ void InitStores() numpremium = 0; premiumlevel = 1; - for (int i = 0; i < SMITH_PREMIUM_ITEMS; i++) - premiumitem[i]._itype = ITYPE_NONE; + for (auto &premiumitem : premiumitems) + premiumitem._itype = ITYPE_NONE; boyitem._itype = ITYPE_NONE; boylevel = 0; diff --git a/Source/stores.h b/Source/stores.h index 43e1a9bdc..90ca6e210 100644 --- a/Source/stores.h +++ b/Source/stores.h @@ -80,7 +80,7 @@ extern int numpremium; /** Base level of current premium items sold by Griswold */ extern int premiumlevel; /** Premium items sold by Griswold */ -extern ItemStruct premiumitem[SMITH_PREMIUM_ITEMS]; +extern ItemStruct premiumitems[SMITH_PREMIUM_ITEMS]; /** Items sold by Pepin */ extern ItemStruct healitem[20]; diff --git a/Source/storm/storm.cpp b/Source/storm/storm.cpp index f5200a358..37ad725b1 100644 --- a/Source/storm/storm.cpp +++ b/Source/storm/storm.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include "Radon.hpp" @@ -78,7 +77,7 @@ bool SFileOpenFile(const char *filename, HANDLE *phFile) std::string path = *SBasePath + filename; for (std::size_t i = SBasePath->size(); i < path.size(); ++i) path[i] = AsciiToLowerTable_Path[static_cast(path[i])]; - result = SFileOpenFileEx((HANDLE)nullptr, path.c_str(), SFILE_OPEN_LOCAL_FILE, phFile); + result = SFileOpenFileEx((HANDLE) nullptr, path.c_str(), SFILE_OPEN_LOCAL_FILE, phFile); } if (!result && devilutionx_mpq != nullptr) { diff --git a/Source/storm/storm_svid.cpp b/Source/storm/storm_svid.cpp index dc075ea0e..c5bf612cb 100644 --- a/Source/storm/storm_svid.cpp +++ b/Source/storm/storm_svid.cpp @@ -210,7 +210,7 @@ void SVidRestartMixer() unsigned char *SVidApplyVolume(const unsigned char *raw, unsigned long rawLen) { - unsigned char *scaled = (unsigned char *)malloc(rawLen); + auto *scaled = (unsigned char *)malloc(rawLen); if (SVidAudioDepth == 16) { for (unsigned long i = 0; i < rawLen / 2; i++) @@ -259,18 +259,18 @@ void SVidPlayBegin(const char *filename, int flags, HANDLE *video) SFileOpenFile(filename, video); - int bytestoread = SFileGetFileSize(*video, 0); + int bytestoread = SFileGetFileSize(*video, nullptr); SVidBuffer = DiabloAllocPtr(bytestoread); - SFileReadFile(*video, SVidBuffer, bytestoread, NULL, 0); + SFileReadFile(*video, SVidBuffer, bytestoread, nullptr, nullptr); SVidSMK = smk_open_memory(SVidBuffer, bytestoread); - if (SVidSMK == NULL) { + if (SVidSMK == nullptr) { return; } unsigned char channels[7], depth[7]; unsigned long rate[7]; - smk_info_audio(SVidSMK, NULL, channels, depth, rate); + smk_info_audio(SVidSMK, nullptr, channels, depth, rate); if (enableAudio && depth[0] != 0) { smk_enable_audio(SVidSMK, 0, enableAudio); SDL_AudioSpec audioFormat; @@ -286,7 +286,7 @@ void SVidPlayBegin(const char *filename, int flags, HANDLE *video) Mix_CloseAudio(); #if SDL_VERSION_ATLEAST(2, 0, 4) - deviceId = SDL_OpenAudioDevice(NULL, 0, &audioFormat, NULL, 0); + deviceId = SDL_OpenAudioDevice(nullptr, 0, &audioFormat, nullptr, 0); if (deviceId == 0) { ErrSdl(); } @@ -302,18 +302,18 @@ void SVidPlayBegin(const char *filename, int flags, HANDLE *video) } unsigned long nFrames; - smk_info_all(SVidSMK, NULL, &nFrames, &SVidFrameLength); - smk_info_video(SVidSMK, &SVidWidth, &SVidHeight, NULL); + smk_info_all(SVidSMK, nullptr, &nFrames, &SVidFrameLength); + smk_info_video(SVidSMK, &SVidWidth, &SVidHeight, nullptr); smk_enable_video(SVidSMK, enableVideo); smk_first(SVidSMK); // Decode first frame - smk_info_video(SVidSMK, &SVidWidth, &SVidHeight, NULL); + smk_info_video(SVidSMK, &SVidWidth, &SVidHeight, nullptr); #ifndef USE_SDL1 if (renderer) { SDL_DestroyTexture(texture); texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STREAMING, SVidWidth, SVidHeight); - if (texture == NULL) { + if (texture == nullptr) { ErrSdl(); } if (SDL_RenderSetLogicalSize(renderer, SVidWidth, SVidHeight) <= -1) { @@ -333,12 +333,12 @@ void SVidPlayBegin(const char *filename, int flags, HANDLE *video) 8, SVidWidth, SDL_PIXELFORMAT_INDEX8); - if (SVidSurface == NULL) { + if (SVidSurface == nullptr) { ErrSdl(); } SVidPalette = SDL_AllocPalette(256); - if (SVidPalette == NULL) { + if (SVidPalette == nullptr) { ErrSdl(); } if (SDLC_SetSurfaceColors(SVidSurface, SVidPalette) <= -1) { @@ -346,7 +346,7 @@ void SVidPlayBegin(const char *filename, int flags, HANDLE *video) } SVidFrameEnd = SDL_GetTicks() * 1000 + SVidFrameLength; - SDL_FillRect(GetOutputSurface(), NULL, 0x000000); + SDL_FillRect(GetOutputSurface(), nullptr, 0x000000); } bool SVidPlayContinue() @@ -399,7 +399,7 @@ bool SVidPlayContinue() #ifndef USE_SDL1 if (renderer) { - if (SDL_BlitSurface(SVidSurface, NULL, GetOutputSurface(), NULL) <= -1) { + if (SDL_BlitSurface(SVidSurface, nullptr, GetOutputSurface(), nullptr) <= -1) { SDL_Log("%s", SDL_GetError()); return false; } @@ -431,7 +431,7 @@ bool SVidPlayContinue() if (is_indexed_output_format || output_surface->w == static_cast(SVidWidth) || output_surface->h == static_cast(SVidHeight)) { - if (SDL_BlitSurface(SVidSurface, NULL, output_surface, &output_rect) <= -1) { + if (SDL_BlitSurface(SVidSurface, nullptr, output_surface, &output_rect) <= -1) { ErrSdl(); } } else { @@ -442,7 +442,7 @@ bool SVidPlayContinue() #else SDLSurfaceUniquePtr converted { SDL_ConvertSurfaceFormat(SVidSurface, wnd_format, 0) }; #endif - if (SDL_BlitScaled(converted.get(), NULL, output_surface, &output_rect) <= -1) { + if (SDL_BlitScaled(converted.get(), nullptr, output_surface, &output_rect) <= -1) { SDL_Log("%s", SDL_GetError()); return false; } @@ -478,24 +478,24 @@ void SVidPlayEnd(HANDLE video) if (SVidBuffer) { mem_free_dbg(SVidBuffer); - SVidBuffer = NULL; + SVidBuffer = nullptr; } SDL_FreePalette(SVidPalette); - SVidPalette = NULL; + SVidPalette = nullptr; SDL_FreeSurface(SVidSurface); - SVidSurface = NULL; + SVidSurface = nullptr; SFileCloseFile(video); - video = NULL; + video = nullptr; memcpy(orig_palette, SVidPreviousPalette, sizeof(orig_palette)); #ifndef USE_SDL1 if (renderer) { SDL_DestroyTexture(texture); texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STREAMING, gnScreenWidth, gnScreenHeight); - if (texture == NULL) { + if (texture == nullptr) { ErrSdl(); } if (renderer && SDL_RenderSetLogicalSize(renderer, gnScreenWidth, gnScreenHeight) <= -1) { diff --git a/Source/sync.cpp b/Source/sync.cpp index 5f7ff4125..8ab5288fb 100644 --- a/Source/sync.cpp +++ b/Source/sync.cpp @@ -3,7 +3,7 @@ * * Implementation of functionality for syncing game state with other players. */ -#include +#include #include "gendung.h" #include "monster.h" diff --git a/Source/themes.cpp b/Source/themes.cpp index 45c17b9a2..f873a5a9a 100644 --- a/Source/themes.cpp +++ b/Source/themes.cpp @@ -15,7 +15,6 @@ namespace devilution { int numthemes; bool armorFlag; -bool ThemeGoodIn[4]; bool weaponFlag; bool treasureFlag; bool mFountainFlag; @@ -423,9 +422,6 @@ void InitThemes() return; if (leveltype == DTYPE_CATHEDRAL) { - for (size_t i = 0; i < sizeof(ThemeGoodIn) / sizeof(ThemeGoodIn[0]); i++) - ThemeGoodIn[i] = false; - for (size_t i = 0; i < 256 && numthemes < MAXTHEMES; i++) { if (CheckThemeRoom(i)) { themes[numthemes].ttval = i; diff --git a/Source/towners.cpp b/Source/towners.cpp index e87efc8c6..30dcc2de7 100644 --- a/Source/towners.cpp +++ b/Source/towners.cpp @@ -247,8 +247,8 @@ void InitBarOwner() InitTownerInfo(numtowners, 96, true, TOWN_TAVERN, 55, 62, 3); InitQstSnds(numtowners, TOWN_TAVERN); towner[numtowners]._tNData = LoadFileInMem("Towners\\TwnF\\TwnFN.CEL", nullptr); - for (int i = 0; i < 8; i++) { - towner[numtowners]._tNAnim[i] = towner[numtowners]._tNData; + for (auto &i : towner[numtowners]._tNAnim) { + i = towner[numtowners]._tNData; } towner[numtowners]._tNFrames = 16; NewTownerAnim(numtowners, towner[numtowners]._tNAnim[DIR_SW], towner[numtowners]._tNFrames, 3); @@ -967,7 +967,7 @@ void TalkToTowner(int p, int t) } else if (t == GetActiveTowner(TOWN_BMAID)) { if (!plr[p]._pLvlVisited[21] && PlrHasItem(p, IDI_MAPOFDOOM, &i)) { quests[Q_GRAVE]._qactive = QUEST_ACTIVE; - quests[Q_GRAVE]._qlog = 1; + quests[Q_GRAVE]._qlog = true; quests[Q_GRAVE]._qmsg = TEXT_GRAVE8; InitQTextMsg(TEXT_GRAVE8); towner[t]._tMsgSaid = true; @@ -1087,7 +1087,7 @@ void TalkToTowner(int p, int t) qt = TEXT_FARMER2; quests[Q_FARMER]._qactive = QUEST_ACTIVE; quests[Q_FARMER]._qvar1 = 1; - quests[Q_FARMER]._qlog = 1; + quests[Q_FARMER]._qlog = true; quests[Q_FARMER]._qmsg = TEXT_FARMER1; break; } else if (!plr[p]._pLvlVisited[9] && plr[p]._pLevel < 15) { @@ -1102,7 +1102,7 @@ void TalkToTowner(int p, int t) qt = TEXT_FARMER1; quests[Q_FARMER]._qactive = QUEST_ACTIVE; quests[Q_FARMER]._qvar1 = 1; - quests[Q_FARMER]._qlog = 1; + quests[Q_FARMER]._qlog = true; quests[Q_FARMER]._qmsg = TEXT_FARMER1; SpawnRuneBomb(towner[t]._tx + 1, towner[t]._ty); t2 = 1; @@ -1120,7 +1120,7 @@ void TalkToTowner(int p, int t) quests[Q_FARMER]._qactive = QUEST_ACTIVE; quests[Q_FARMER]._qvar1 = 1; quests[Q_FARMER]._qmsg = TEXT_FARMER1; - quests[Q_FARMER]._qlog = 1; + quests[Q_FARMER]._qlog = true; } else if (!plr[p]._pLvlVisited[9] && plr[p]._pLevel < 15) { qt = TEXT_FARMER8; if (plr[p]._pLvlVisited[2]) { @@ -1136,7 +1136,7 @@ void TalkToTowner(int p, int t) qt = TEXT_FARMER1; quests[Q_FARMER]._qactive = QUEST_ACTIVE; quests[Q_FARMER]._qvar1 = 1; - quests[Q_FARMER]._qlog = 1; + quests[Q_FARMER]._qlog = true; quests[Q_FARMER]._qmsg = TEXT_FARMER1; SpawnRuneBomb(towner[t]._tx + 1, towner[t]._ty); t2 = 1; @@ -1146,7 +1146,7 @@ void TalkToTowner(int p, int t) qt = TEXT_FARMER4; SpawnRewardItem(IDI_AURIC, towner[t]._tx + 1, towner[t]._ty); quests[Q_FARMER]._qactive = QUEST_HIVE_DONE; - quests[Q_FARMER]._qlog = 0; + quests[Q_FARMER]._qlog = false; t2 = 1; break; case QUEST_HIVE_DONE: @@ -1184,7 +1184,7 @@ void TalkToTowner(int p, int t) quests[Q_JERSEY]._qactive = QUEST_ACTIVE; quests[Q_JERSEY]._qvar1 = 1; quests[Q_JERSEY]._qmsg = TEXT_JERSEY4; - quests[Q_JERSEY]._qlog = 1; + quests[Q_JERSEY]._qlog = true; } else { switch (quests[Q_JERSEY]._qactive) { case QUEST_NOTAVAIL: @@ -1227,7 +1227,7 @@ void TalkToTowner(int p, int t) quests[Q_JERSEY]._qactive = QUEST_ACTIVE; quests[Q_JERSEY]._qvar1 = 1; quests[Q_JERSEY]._qmsg = TEXT_JERSEY4; - quests[Q_JERSEY]._qlog = 1; + quests[Q_JERSEY]._qlog = true; SpawnRuneBomb(towner[t]._tx + 1, towner[t]._ty); t2 = 1; } @@ -1258,14 +1258,14 @@ void TalkToTowner(int p, int t) qt = TEXT_GIRL2; quests[Q_GIRL]._qactive = QUEST_ACTIVE; quests[Q_GIRL]._qvar1 = 1; - quests[Q_GIRL]._qlog = 1; + quests[Q_GIRL]._qlog = true; quests[Q_GIRL]._qmsg = TEXT_GIRL2; t2 = 1; break; case 1: qt = TEXT_GIRL2; quests[Q_GIRL]._qvar1 = 1; - quests[Q_GIRL]._qlog = 1; + quests[Q_GIRL]._qlog = true; quests[Q_GIRL]._qmsg = TEXT_GIRL2; quests[Q_GIRL]._qactive = QUEST_ACTIVE; t2 = 1; @@ -1285,8 +1285,8 @@ void TalkToTowner(int p, int t) } else { qt = TEXT_GIRL4; RemoveInvItem(p, i); - CreateAmulet(towner[t]._tx, towner[t]._ty, 13, 0, 1); - quests[Q_GIRL]._qlog = 0; + CreateAmulet(towner[t]._tx, towner[t]._ty, 13, false, true); + quests[Q_GIRL]._qlog = false; quests[Q_GIRL]._qactive = QUEST_DONE; t2 = 1; } diff --git a/Source/trigs.cpp b/Source/trigs.cpp index 6d07b9d30..7f41eb828 100644 --- a/Source/trigs.cpp +++ b/Source/trigs.cpp @@ -70,8 +70,8 @@ void InitTownTriggers() trigs[numtrigs]._tmsg = WM_DIABNEXTLVL; numtrigs++; - for (size_t i = 0; i < sizeof(townwarps) / sizeof(townwarps[0]); i++) { - townwarps[i] = gbIsMultiplayer && !gbIsSpawn; + for (bool &townwarp : townwarps) { + townwarp = gbIsMultiplayer && !gbIsSpawn; } if (!gbIsSpawn) { if (gbIsMultiplayer || plr[myplr].pTownWarps & 1 || (gbIsHellfire && plr[myplr]._pLevel >= 10)) { diff --git a/Source/utils/paths.cpp b/Source/utils/paths.cpp index 433c783c7..0aff05bc3 100644 --- a/Source/utils/paths.cpp +++ b/Source/utils/paths.cpp @@ -37,7 +37,7 @@ void AddTrailingSlash(std::string *path) std::string *FromSDL(char *s) { - std::string *result = new std::string(s != nullptr ? s : ""); + auto *result = new std::string(s != nullptr ? s : ""); if (s != nullptr) { SDL_free(s); } else { diff --git a/Source/utils/thread.cpp b/Source/utils/thread.cpp index 2b13bbf3a..e7c9ac540 100644 --- a/Source/utils/thread.cpp +++ b/Source/utils/thread.cpp @@ -10,7 +10,7 @@ namespace devilution { static int SDLCALL thread_translate(void *ptr) { - unsigned int (*handler)(void *) = (unsigned int (*)(void *))ptr; + auto handler = (unsigned int (*)(void *))ptr; return handler(nullptr); }