From ade8aba8223c011ad900e924a3edb3abb6d0feb2 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Sun, 3 Apr 2022 14:52:19 +0100 Subject: [PATCH] Fix some more warnings --- Source/DiabloUI/settingsmenu.cpp | 7 ++--- Source/control.h | 5 ++-- Source/controls/plrctrls.cpp | 2 +- Source/controls/plrctrls.h | 3 ++- Source/drlg_l1.cpp | 6 ++--- Source/drlg_l2.cpp | 4 +-- Source/drlg_l3.cpp | 4 +-- Source/drlg_l4.cpp | 2 +- Source/engine/render/text_render.cpp | 9 ++++--- Source/monster.cpp | 2 +- Source/msg.cpp | 38 ++++++++++++++-------------- Source/msg.h | 14 +++++----- Source/multi.cpp | 26 +++++++++---------- Source/objects.cpp | 8 +++--- Source/options.cpp | 18 +++++-------- Source/options.h | 10 +++++--- Source/panels/spell_list.cpp | 4 +-- Source/panels/spell_list.hpp | 5 ++-- Source/quests.cpp | 10 ++++---- Source/stores.cpp | 24 +++++++++++------- 20 files changed, 106 insertions(+), 95 deletions(-) diff --git a/Source/DiabloUI/settingsmenu.cpp b/Source/DiabloUI/settingsmenu.cpp index 27ff88408..2c88d18e8 100644 --- a/Source/DiabloUI/settingsmenu.cpp +++ b/Source/DiabloUI/settingsmenu.cpp @@ -142,7 +142,8 @@ bool ChangeOptionValue(OptionEntryBase *pOption, size_t listIndex) void ItemSelected(int value) { - auto &vecItem = vecDialogItems[value]; + const auto index = static_cast(value); + auto &vecItem = vecDialogItems[index]; int vecItemValue = vecItem->m_value; if (vecItemValue < 0) { auto specialMenuEntry = static_cast(vecItemValue); @@ -187,7 +188,7 @@ void ItemSelected(int value) } if (updateValueDescription) { auto args = CreateDrawStringFormatArgForEntry(pOption); - bool optionUsesTwoLines = ((value + 1) < vecDialogItems.size() && vecDialogItems[value]->m_value == vecDialogItems[value + 1]->m_value); + bool optionUsesTwoLines = ((index + 1) < vecDialogItems.size() && vecDialogItems[index]->m_value == vecDialogItems[index + 1]->m_value); if (NeedsTwoLinesToDisplayOption(args) != optionUsesTwoLines) { selectedOption = pOption; endMenu = true; @@ -196,7 +197,7 @@ void ItemSelected(int value) for (auto &arg : args) vecItem->args.push_back(arg); if (optionUsesTwoLines) { - vecDialogItems[value + 1]->m_text = pOption->GetValueDescription().data(); + vecDialogItems[index + 1]->m_text = pOption->GetValueDescription().data(); } } } diff --git a/Source/control.h b/Source/control.h index 721c5d5a3..65e325fe9 100644 --- a/Source/control.h +++ b/Source/control.h @@ -5,6 +5,7 @@ */ #pragma once +#include #include #include "DiabloUI/ui_flags.hpp" @@ -70,8 +71,8 @@ inline bool CanPanelsCoverView() } void DrawSpellList(const Surface &out); void SetSpell(); -void SetSpeedSpell(int slot); -void ToggleSpell(int slot); +void SetSpeedSpell(size_t slot); +void ToggleSpell(size_t slot); void AddPanelString(string_view str); void ClearPanel(); diff --git a/Source/controls/plrctrls.cpp b/Source/controls/plrctrls.cpp index c047ea470..7488f82db 100644 --- a/Source/controls/plrctrls.cpp +++ b/Source/controls/plrctrls.cpp @@ -2028,7 +2028,7 @@ void PerformSecondaryAction() } } -void QuickCast(int slot) +void QuickCast(size_t slot) { auto &myPlayer = Players[MyPlayerId]; spell_id spell = myPlayer._pSplHotKey[slot]; diff --git a/Source/controls/plrctrls.h b/Source/controls/plrctrls.h index f3f382f09..1db24b43c 100644 --- a/Source/controls/plrctrls.h +++ b/Source/controls/plrctrls.h @@ -1,6 +1,7 @@ #pragma once // Controller actions implementation +#include #include #include @@ -77,7 +78,7 @@ bool TryDropItem(); void InvalidateInventorySlot(); void FocusOnInventory(); void PerformSpellAction(); -void QuickCast(int slot); +void QuickCast(size_t slot); extern int speedspellcount; diff --git a/Source/drlg_l1.cpp b/Source/drlg_l1.cpp index 62a54038b..d5f938ebc 100644 --- a/Source/drlg_l1.cpp +++ b/Source/drlg_l1.cpp @@ -1691,7 +1691,7 @@ void SetRoom(int rx1, int ry1) for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { - uint8_t tileId = SDL_SwapLE16(tileLayer[j * width + i]); + auto tileId = static_cast(SDL_SwapLE16(tileLayer[j * width + i])); if (tileId != 0) { dungeon[rx1 + i][ry1 + j] = tileId; L5dflags[rx1 + i][ry1 + j] |= DLRG_PROTECTED; @@ -2422,7 +2422,7 @@ void LoadL1Dungeon(const char *path, int vx, int vy) for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { - uint8_t tileId = SDL_SwapLE16(*tileLayer); + auto tileId = static_cast(SDL_SwapLE16(*tileLayer)); tileLayer++; if (tileId != 0) { dungeon[i][j] = tileId; @@ -2468,7 +2468,7 @@ void LoadPreL1Dungeon(const char *path) for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { - uint8_t tileId = SDL_SwapLE16(*tileLayer); + auto tileId = static_cast(SDL_SwapLE16(*tileLayer)); tileLayer++; if (tileId != 0) { dungeon[i][j] = tileId; diff --git a/Source/drlg_l2.cpp b/Source/drlg_l2.cpp index 8f0e5ed8f..3c828ac6d 100644 --- a/Source/drlg_l2.cpp +++ b/Source/drlg_l2.cpp @@ -2312,7 +2312,7 @@ void SetRoom(int rx1, int ry1) for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { - uint8_t tileId = SDL_SwapLE16(tileLayer[j * width + i]); + auto tileId = static_cast(SDL_SwapLE16(tileLayer[j * width + i])); if (tileId != 0) { dungeon[rx1 + i][ry1 + j] = tileId; dflags[rx1 + i][ry1 + j] |= DLRG_PROTECTED; @@ -3055,7 +3055,7 @@ void LoadDungeonData(const uint16_t *dunData) for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { - uint8_t tileId = SDL_SwapLE16(*tileLayer); + auto tileId = static_cast(SDL_SwapLE16(*tileLayer)); tileLayer++; if (tileId != 0) { dungeon[i][j] = tileId; diff --git a/Source/drlg_l3.cpp b/Source/drlg_l3.cpp index 347026adc..cd072a107 100644 --- a/Source/drlg_l3.cpp +++ b/Source/drlg_l3.cpp @@ -2531,7 +2531,7 @@ void LoadL3Dungeon(const char *path, int vx, int vy) for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { - uint8_t tileId = SDL_SwapLE16(tileLayer[j * width + i]); + auto tileId = static_cast(SDL_SwapLE16(tileLayer[j * width + i])); dungeon[i][j] = (tileId != 0) ? tileId : 7; } } @@ -2579,7 +2579,7 @@ void LoadPreL3Dungeon(const char *path) for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { - uint8_t tileId = SDL_SwapLE16(tileLayer[j * width + i]); + auto tileId = static_cast(SDL_SwapLE16(tileLayer[j * width + i])); dungeon[i][j] = (tileId != 0) ? tileId : 7; } } diff --git a/Source/drlg_l4.cpp b/Source/drlg_l4.cpp index c106c28a8..596b17835 100644 --- a/Source/drlg_l4.cpp +++ b/Source/drlg_l4.cpp @@ -273,7 +273,7 @@ void SetRoom(const uint16_t *dunData, int rx1, int ry1) for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { - uint8_t tileId = SDL_SwapLE16(tileLayer[j * width + i]); + auto tileId = static_cast(SDL_SwapLE16(tileLayer[j * width + i])); if (tileId != 0) { dungeon[i + rx1][j + ry1] = tileId; dflags[i + rx1][j + ry1] |= DLRG_PROTECTED; diff --git a/Source/engine/render/text_render.cpp b/Source/engine/render/text_render.cpp index 85e91de0c..a69c02ee9 100644 --- a/Source/engine/render/text_render.cpp +++ b/Source/engine/render/text_render.cpp @@ -6,6 +6,7 @@ #include "text_render.hpp" #include +#include #include #include @@ -511,7 +512,7 @@ std::string WordWrapString(string_view text, unsigned width, GameFontTables size output.reserve(text.size()); const char *begin = text.data(); const char *processedEnd = text.data(); - std::size_t lastBreakablePos = -1; + string_view::size_type lastBreakablePos = string_view::npos; std::size_t lastBreakableLen; bool lastBreakableKeep = false; uint32_t currentUnicodeRow = 0; @@ -532,7 +533,7 @@ std::string WordWrapString(string_view text, unsigned width, GameFontTables size nextCodepoint = !remaining.empty() ? DecodeFirstUtf8CodePoint(remaining, &nextCodepointLen) : U'\0'; if (codepoint == U'\n') { // Existing line break, scan next line - lastBreakablePos = -1; + lastBreakablePos = string_view::npos; lineWidth = 0; output.append(processedEnd, remaining.data()); processedEnd = remaining.data(); @@ -561,7 +562,7 @@ std::string WordWrapString(string_view text, unsigned width, GameFontTables size continue; // String is still within the limit, continue to the next symbol } - if (lastBreakablePos == -1) { // Single word longer than width + if (lastBreakablePos == string_view::npos) { // Single word longer than width continue; } @@ -576,7 +577,7 @@ std::string WordWrapString(string_view text, unsigned width, GameFontTables size // Restart from the beginning of the new line. remaining = text.substr(lastBreakablePos + lastBreakableLen); processedEnd = remaining.data(); - lastBreakablePos = -1; + lastBreakablePos = string_view::npos; lineWidth = 0; nextCodepoint = !remaining.empty() ? DecodeFirstUtf8CodePoint(remaining, &nextCodepointLen) : U'\0'; } while (!remaining.empty() && remaining[0] != '\0'); diff --git a/Source/monster.cpp b/Source/monster.cpp index b4ccbfbeb..8ec8d638e 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -3917,7 +3917,7 @@ void SetMapMonsters(const uint16_t *dunData, Point startPosition) for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { - uint8_t monsterId = SDL_SwapLE16(monsterLayer[j * width + i]); + auto monsterId = static_cast(SDL_SwapLE16(monsterLayer[j * width + i])); if (monsterId != 0) { int mtype = AddMonsterType(MonstConvTbl[monsterId - 1], PLACE_SPECIAL); PlaceMonster(ActiveMonsterCount++, mtype, i + startPosition.x + 16, j + startPosition.y + 16); diff --git a/Source/msg.cpp b/Source/msg.cpp index 7f9564088..e783c6468 100644 --- a/Source/msg.cpp +++ b/Source/msg.cpp @@ -38,7 +38,7 @@ namespace devilution { bool deltaload; -BYTE gbBufferMsgs; +uint8_t gbBufferMsgs; int dwRecCount; namespace { @@ -59,13 +59,13 @@ uint32_t sgdwOwnerWait; uint32_t sgdwRecvOffset; int sgnCurrMegaPlayer; DLevel sgLevels[NUMLEVELS]; -BYTE sbLastCmd; +uint8_t sbLastCmd; byte sgRecvBuf[sizeof(DLevel) + 1]; _cmd_id sgbRecvCmd; LocalLevel sgLocals[NUMLEVELS]; DJunk sgJunk; bool sgbDeltaChanged; -BYTE sgbDeltaChunks; +uint8_t sgbDeltaChunks; std::list MegaPktList; Item ItemLimbo; @@ -290,10 +290,10 @@ void DeltaImportJunk(const byte *src) } } -DWORD CompressData(byte *buffer, byte *end) +uint32_t CompressData(byte *buffer, byte *end) { - DWORD size = end - buffer - 1; - DWORD pkSize = PkwareCompress(buffer + 1, size); + const auto size = static_cast(end - buffer - 1); + const uint32_t pkSize = PkwareCompress(buffer + 1, size); *buffer = size != pkSize ? byte { 1 } : byte { 0 }; @@ -377,7 +377,7 @@ void DeltaSyncGolem(const TCmdGolem &message, int pnum, uint8_t level) monster._mhitpoints = message._mhitpoints; } -void DeltaLeaveSync(BYTE bLevel) +void DeltaLeaveSync(uint8_t bLevel) { if (!gbIsMultiplayer) return; @@ -404,7 +404,7 @@ void DeltaLeaveSync(BYTE bLevel) memcpy(&sgLocals[bLevel].automapsv, AutomapView, sizeof(AutomapView)); } -void DeltaSyncObject(int oi, _cmd_id bCmd, BYTE bLevel) +void DeltaSyncObject(int oi, _cmd_id bCmd, uint8_t bLevel) { if (!gbIsMultiplayer) return; @@ -413,7 +413,7 @@ void DeltaSyncObject(int oi, _cmd_id bCmd, BYTE bLevel) sgLevels[bLevel].object[oi].bCmd = bCmd; } -bool DeltaGetItem(const TCmdGItem &message, BYTE bLevel) +bool DeltaGetItem(const TCmdGItem &message, uint8_t bLevel) { if (!gbIsMultiplayer) return true; @@ -470,7 +470,7 @@ bool DeltaGetItem(const TCmdGItem &message, BYTE bLevel) return true; } -void DeltaPutItem(const TCmdPItem &message, Point position, BYTE bLevel) +void DeltaPutItem(const TCmdPItem &message, Point position, uint8_t bLevel) { if (!gbIsMultiplayer) return; @@ -1610,7 +1610,7 @@ DWORD OnPlayerLevel(const TCmd *pCmd, int pnum) if (gbBufferMsgs == 1) SendPacket(pnum, &message, sizeof(message)); else if (message.wParam1 <= MAXCHARLEVEL && pnum != MyPlayerId) - Players[pnum]._pLevel = message.wParam1; + Players[pnum]._pLevel = static_cast(message.wParam1); return sizeof(message); } @@ -2025,14 +2025,14 @@ void DeltaExportData(int pnum) dstEnd = DeltaExportItem(dstEnd, sgLevels[i].item); dstEnd = DeltaExportObject(dstEnd, sgLevels[i].object); dstEnd = DeltaExportMonster(dstEnd, sgLevels[i].monster); - int size = CompressData(dst.get(), dstEnd); + uint32_t size = CompressData(dst.get(), dstEnd); dthread_send_delta(pnum, static_cast<_cmd_id>(i + CMD_DLEVEL_0), std::move(dst), size); } std::unique_ptr dst { new byte[sizeof(DJunk) + 1] }; byte *dstEnd = &dst.get()[1]; dstEnd = DeltaExportJunk(dstEnd); - int size = CompressData(dst.get(), dstEnd); + uint32_t size = CompressData(dst.get(), dstEnd); dthread_send_delta(pnum, CMD_DLEVEL_JUNK, std::move(dst), size); } @@ -2049,7 +2049,7 @@ void delta_init() deltaload = false; } -void delta_kill_monster(int mi, Point position, BYTE bLevel) +void delta_kill_monster(int mi, Point position, uint8_t bLevel) { if (!gbIsMultiplayer) return; @@ -2062,7 +2062,7 @@ void delta_kill_monster(int mi, Point position, BYTE bLevel) pD->_mhitpoints = 0; } -void delta_monster_hp(int mi, int hp, BYTE bLevel) +void delta_monster_hp(int mi, int hp, uint8_t bLevel) { if (!gbIsMultiplayer) return; @@ -2351,7 +2351,7 @@ void NetSendCmd(bool bHiPri, _cmd_id bCmd) NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); } -void NetSendCmdGolem(BYTE mx, BYTE my, Direction dir, BYTE menemy, int hp, BYTE cl) +void NetSendCmdGolem(uint8_t mx, uint8_t my, Direction dir, uint8_t menemy, int hp, uint8_t cl) { TCmdGolem cmd; @@ -2524,7 +2524,7 @@ void NetSendCmdQuest(bool bHiPri, const Quest &quest) NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); } -void NetSendCmdGItem(bool bHiPri, _cmd_id bCmd, BYTE mast, BYTE pnum, BYTE ii) +void NetSendCmdGItem(bool bHiPri, _cmd_id bCmd, uint8_t mast, uint8_t pnum, uint8_t ii) { TCmdGItem cmd; @@ -2617,7 +2617,7 @@ void NetSendCmdPItem(bool bHiPri, _cmd_id bCmd, Point position, const Item &item NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); } -void NetSendCmdChItem(bool bHiPri, BYTE bLoc) +void NetSendCmdChItem(bool bHiPri, uint8_t bLoc) { TCmdChItem cmd; @@ -2638,7 +2638,7 @@ void NetSendCmdChItem(bool bHiPri, BYTE bLoc) NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); } -void NetSendCmdDelItem(bool bHiPri, BYTE bLoc) +void NetSendCmdDelItem(bool bHiPri, uint8_t bLoc) { TCmdDelItem cmd; diff --git a/Source/msg.h b/Source/msg.h index 4f5d0251b..3ba39949d 100644 --- a/Source/msg.h +++ b/Source/msg.h @@ -775,7 +775,7 @@ struct TBuffer { }; extern bool deltaload; -extern BYTE gbBufferMsgs; +extern uint8_t gbBufferMsgs; extern int dwRecCount; void msg_send_drop_pkt(int pnum, int reason); @@ -784,14 +784,14 @@ void run_delta_info(); void DeltaExportData(int pnum); void DeltaSyncJunk(); void delta_init(); -void delta_kill_monster(int mi, Point position, BYTE bLevel); -void delta_monster_hp(int mi, int hp, BYTE bLevel); +void delta_kill_monster(int mi, Point position, uint8_t bLevel); +void delta_monster_hp(int mi, int hp, uint8_t bLevel); void delta_sync_monster(const TSyncMonster &monsterSync, uint8_t level); void DeltaAddItem(int ii); void DeltaSaveLevel(); void DeltaLoadLevel(); void NetSendCmd(bool bHiPri, _cmd_id bCmd); -void NetSendCmdGolem(BYTE mx, BYTE my, Direction dir, BYTE menemy, int hp, BYTE cl); +void NetSendCmdGolem(uint8_t mx, uint8_t my, Direction dir, uint8_t menemy, int hp, uint8_t cl); void NetSendCmdLoc(int playerId, bool bHiPri, _cmd_id bCmd, Point position); void NetSendCmdLocParam1(bool bHiPri, _cmd_id bCmd, Point position, uint16_t wParam1); void NetSendCmdLocParam2(bool bHiPri, _cmd_id bCmd, Point position, uint16_t wParam1, uint16_t wParam2); @@ -802,10 +802,10 @@ void NetSendCmdParam2(bool bHiPri, _cmd_id bCmd, uint16_t wParam1, uint16_t wPar void NetSendCmdParam3(bool bHiPri, _cmd_id bCmd, uint16_t wParam1, uint16_t wParam2, uint16_t wParam3); void NetSendCmdParam4(bool bHiPri, _cmd_id bCmd, uint16_t wParam1, uint16_t wParam2, uint16_t wParam3, uint16_t wParam4); void NetSendCmdQuest(bool bHiPri, const Quest &quest); -void NetSendCmdGItem(bool bHiPri, _cmd_id bCmd, BYTE mast, BYTE pnum, BYTE ii); +void NetSendCmdGItem(bool bHiPri, _cmd_id bCmd, uint8_t mast, uint8_t pnum, uint8_t ii); void NetSendCmdPItem(bool bHiPri, _cmd_id bCmd, Point position, const Item &item); -void NetSendCmdChItem(bool bHiPri, BYTE bLoc); -void NetSendCmdDelItem(bool bHiPri, BYTE bLoc); +void NetSendCmdChItem(bool bHiPri, uint8_t bLoc); +void NetSendCmdDelItem(bool bHiPri, uint8_t bLoc); void NetSendCmdDamage(bool bHiPri, uint8_t bPlr, uint32_t dwDam); void NetSendCmdMonDmg(bool bHiPri, uint16_t wMon, uint32_t dwDam); void NetSendCmdString(uint32_t pmask, const char *pszStr); diff --git a/Source/multi.cpp b/Source/multi.cpp index 0b5ce38f1..f5c5aa3b6 100644 --- a/Source/multi.cpp +++ b/Source/multi.cpp @@ -77,7 +77,7 @@ void BufferInit(TBuffer *pBuf) pBuf->bData[0] = byte { 0 }; } -void CopyPacket(TBuffer *buf, const byte *packet, uint8_t size) +void CopyPacket(TBuffer *buf, const byte *packet, size_t size) { if (buf->dwNextWriteOffset + size + 2 > 0x1000) { return; @@ -108,7 +108,7 @@ byte *ReceivePacket(TBuffer *pBuf, byte *body, size_t *size) *size -= chunkSize; } memcpy(pBuf->bData, srcPtr, (pBuf->bData - srcPtr) + pBuf->dwNextWriteOffset + 1); - pBuf->dwNextWriteOffset += (pBuf->bData - srcPtr); + pBuf->dwNextWriteOffset += static_cast(pBuf->bData - srcPtr); return body; } return body; @@ -138,7 +138,7 @@ void SendPacket(int playerId, const byte *packet, size_t size) TPkt pkt; NetReceivePlayerData(&pkt); - pkt.hdr.wLen = size + sizeof(pkt.hdr); + pkt.hdr.wLen = static_cast(size + sizeof(pkt.hdr)); memcpy(pkt.body, packet, size); if (!SNetSendMessage(playerId, &pkt.hdr, pkt.hdr.wLen)) nthread_terminate_game("SNetSendMessage0"); @@ -147,9 +147,9 @@ void SendPacket(int playerId, const byte *packet, size_t size) void MonsterSeeds() { sgdwGameLoops++; - uint32_t l = (sgdwGameLoops >> 8) | (sgdwGameLoops << 24); // _rotr(sgdwGameLoops, 8) + const uint32_t seed = (sgdwGameLoops >> 8) | (sgdwGameLoops << 24); // _rotr(sgdwGameLoops, 8) for (int i = 0; i < MAXMONSTERS; i++) - Monsters[i]._mAISeed = l + i; + Monsters[i]._mAISeed = seed + i; } void HandleTurnUpperBit(int pnum) @@ -435,7 +435,7 @@ bool InitMulti(GameData *gameData) void InitGameInfo() { sgGameInitInfo.size = sizeof(sgGameInitInfo); - sgGameInitInfo.dwSeed = time(nullptr); + sgGameInitInfo.dwSeed = static_cast(time(nullptr)); sgGameInitInfo.programid = GAME_ID; sgGameInitInfo.versionMajor = PROJECT_VERSION_MAJOR; sgGameInitInfo.versionMinor = PROJECT_VERSION_MINOR; @@ -470,8 +470,8 @@ void NetSendHiPri(int playerId, const byte *data, size_t size) byte *lowpriBody = ReceivePacket(&sgLoPriBuf, hipriBody, &msgSize); msgSize = sync_all_monsters(lowpriBody, msgSize); size_t len = gdwNormalMsgSize - msgSize; - pkt.hdr.wLen = len; - if (!SNetSendMessage(SNPLAYER_OTHERS, &pkt.hdr, len)) + pkt.hdr.wLen = static_cast(len); + if (!SNetSendMessage(SNPLAYER_OTHERS, &pkt.hdr, static_cast(len))) nthread_terminate_game("SNetSendMessage"); } } @@ -480,13 +480,13 @@ void multi_send_msg_packet(uint32_t pmask, const byte *data, size_t size) { TPkt pkt; NetReceivePlayerData(&pkt); - size_t t = size + sizeof(pkt.hdr); - pkt.hdr.wLen = t; + size_t len = size + sizeof(pkt.hdr); + pkt.hdr.wLen = static_cast(len); memcpy(pkt.body, data, size); - size_t p = 0; - for (size_t v = 1; p < MAX_PLRS; p++, v <<= 1) { + size_t playerID = 0; + for (size_t v = 1; playerID < MAX_PLRS; playerID++, v <<= 1) { if ((v & pmask) != 0) { - if (!SNetSendMessage(p, &pkt.hdr, t) && SErrGetLastError() != STORM_ERROR_INVALID_PLAYER) { + if (!SNetSendMessage(playerID, &pkt.hdr, len) && SErrGetLastError() != STORM_ERROR_INVALID_PLAYER) { nthread_terminate_game("SNetSendMessage"); return; } diff --git a/Source/objects.cpp b/Source/objects.cpp index 170ef5028..52fc3e85d 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -685,7 +685,7 @@ void LoadMapObjects(const char *path, Point start, Rectangle mapRange, int lever start += Displacement { 16, 16 }; for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { - uint8_t objectId = SDL_SwapLE16(objectLayer[j * width + i]); + auto objectId = static_cast(SDL_SwapLE16(objectLayer[j * width + i])); if (objectId != 0) { Point mapPos = start + Displacement { i, j }; AddObject(ObjTypeConv[objectId], mapPos); @@ -719,7 +719,7 @@ void LoadMapObjs(const char *path, Point start) start += Displacement { 16, 16 }; for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { - uint8_t objectId = SDL_SwapLE16(objectLayer[j * width + i]); + auto objectId = static_cast(SDL_SwapLE16(objectLayer[j * width + i])); if (objectId != 0) { AddObject(ObjTypeConv[objectId], start + Displacement { i, j }); } @@ -4655,7 +4655,7 @@ void SetMapObjects(const uint16_t *dunData, int startx, int starty) for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { - uint8_t objectId = SDL_SwapLE16(objectLayer[j * width + i]); + auto objectId = static_cast(SDL_SwapLE16(objectLayer[j * width + i])); if (objectId != 0) { filesLoaded[AllObjects[ObjTypeConv[objectId]].ofindex] = true; } @@ -4674,7 +4674,7 @@ void SetMapObjects(const uint16_t *dunData, int startx, int starty) for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { - uint8_t objectId = SDL_SwapLE16(objectLayer[j * width + i]); + auto objectId = static_cast(SDL_SwapLE16(objectLayer[j * width + i])); if (objectId != 0) { AddObject(ObjTypeConv[objectId], { startx + 16 + i, starty + 16 + j }); } diff --git a/Source/options.cpp b/Source/options.cpp index 9e03df042..77e3d1bee 100644 --- a/Source/options.cpp +++ b/Source/options.cpp @@ -7,6 +7,8 @@ #include #include +#include + #define SI_SUPPORT_IOSTREAMS #include @@ -171,12 +173,6 @@ void SetIniValue(const char *keyname, const char *valuename, int value) GetIni().SetLongValue(keyname, valuename, value, nullptr, false, true); } -void SetIniValue(const char *keyname, const char *valuename, std::uint32_t value) -{ - IniChangedChecker changedChecker(keyname, valuename); - GetIni().SetLongValue(keyname, valuename, value, nullptr, false, true); -} - void SetIniValue(const char *keyname, const char *valuename, bool value) { IniChangedChecker changedChecker(keyname, valuename); @@ -1082,7 +1078,7 @@ std::vector KeymapperOptions::GetEntries() return entries; } -KeymapperOptions::Action::Action(string_view key, string_view name, string_view description, int defaultKey, std::function actionPressed, std::function actionReleased, std::function enable, int index) +KeymapperOptions::Action::Action(string_view key, string_view name, string_view description, int defaultKey, std::function actionPressed, std::function actionReleased, std::function enable, unsigned index) : OptionEntryBase(key, OptionEntryFlags::None, name, description) , defaultKey(defaultKey) , actionPressed(std::move(actionPressed)) @@ -1090,15 +1086,15 @@ KeymapperOptions::Action::Action(string_view key, string_view name, string_view , enable(std::move(enable)) , dynamicIndex(index) { - if (index >= 0) { - dynamicKey = fmt::format(key, index); + if (index != 0) { + dynamicKey = fmt::format(fmt::string_view(key.data(), key.size()), index); this->key = dynamicKey; } } string_view KeymapperOptions::Action::GetName() const { - if (dynamicIndex < 0) + if (dynamicIndex == 0) return _(name.data()); dynamicName = fmt::format(_(name.data()), dynamicIndex); return dynamicName; @@ -1184,7 +1180,7 @@ bool KeymapperOptions::Action::SetValue(int value) return true; } -void KeymapperOptions::AddAction(string_view key, string_view name, string_view description, int defaultKey, std::function actionPressed, std::function actionReleased, std::function enable, int index) +void KeymapperOptions::AddAction(string_view key, string_view name, string_view description, int defaultKey, std::function actionPressed, std::function actionReleased, std::function enable, unsigned index) { actions.push_back(std::unique_ptr(new Action(key, name, description, defaultKey, std::move(actionPressed), std::move(actionReleased), std::move(enable), index))); } diff --git a/Source/options.h b/Source/options.h index 1aff4be83..3fe36d211 100644 --- a/Source/options.h +++ b/Source/options.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -555,13 +556,13 @@ struct KeymapperOptions : OptionCategoryBase { bool SetValue(int value); private: - Action(string_view key, string_view name, string_view description, int defaultKey, std::function actionPressed, std::function actionReleased, std::function enable, int index); + Action(string_view key, string_view name, string_view description, int defaultKey, std::function actionPressed, std::function actionReleased, std::function enable, unsigned index); int defaultKey; std::function actionPressed; std::function actionReleased; std::function enable; int boundKey = DVL_VK_INVALID; - int dynamicIndex; + unsigned dynamicIndex; std::string dynamicKey; mutable std::string dynamicName; @@ -573,7 +574,10 @@ struct KeymapperOptions : OptionCategoryBase { void AddAction( string_view key, string_view name, string_view description, int defaultKey, - std::function actionPressed, std::function actionReleased = nullptr, std::function enable = nullptr, int index = -1); + std::function actionPressed, + std::function actionReleased = nullptr, + std::function enable = nullptr, + unsigned index = 0); void KeyPressed(int key) const; void KeyReleased(int key) const; string_view KeyNameForAction(string_view actionName) const; diff --git a/Source/panels/spell_list.cpp b/Source/panels/spell_list.cpp index ae329461e..f5074d618 100644 --- a/Source/panels/spell_list.cpp +++ b/Source/panels/spell_list.cpp @@ -277,7 +277,7 @@ void SetSpell() force_redraw = 255; } -void SetSpeedSpell(int slot) +void SetSpeedSpell(size_t slot) { spell_id pSpell; spell_type pSplType; @@ -294,7 +294,7 @@ void SetSpeedSpell(int slot) myPlayer._pSplTHotKey[slot] = pSplType; } -void ToggleSpell(int slot) +void ToggleSpell(size_t slot) { uint64_t spells; diff --git a/Source/panels/spell_list.hpp b/Source/panels/spell_list.hpp index f88420174..9ca9da551 100644 --- a/Source/panels/spell_list.hpp +++ b/Source/panels/spell_list.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include "engine/point.hpp" @@ -19,8 +20,8 @@ void DrawSpell(const Surface &out); void DrawSpellList(const Surface &out); std::vector GetSpellListItems(); void SetSpell(); -void SetSpeedSpell(int slot); -void ToggleSpell(int slot); +void SetSpeedSpell(size_t slot); +void ToggleSpell(size_t slot); /** * Draws the "Speed Book": the rows of known spells for quick-setting a spell that diff --git a/Source/quests.cpp b/Source/quests.cpp index 8097ef593..dc30c3481 100644 --- a/Source/quests.cpp +++ b/Source/quests.cpp @@ -149,7 +149,7 @@ void DrawWarLord(int x, int y) for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { - uint8_t tileId = SDL_SwapLE16(tileLayer[j * width + i]); + auto tileId = static_cast(SDL_SwapLE16(tileLayer[j * width + i])); dungeon[x + i][y + j] = (tileId != 0) ? tileId : 6; } } @@ -171,7 +171,7 @@ void DrawSChamber(quest_id q, int x, int y) for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { - uint8_t tileId = SDL_SwapLE16(tileLayer[j * width + i]); + auto tileId = static_cast(SDL_SwapLE16(tileLayer[j * width + i])); dungeon[x + i][y + j] = (tileId != 0) ? tileId : 3; } } @@ -195,7 +195,7 @@ void DrawLTBanner(int x, int y) for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { - uint8_t tileId = SDL_SwapLE16(tileLayer[j * width + i]); + auto tileId = static_cast(SDL_SwapLE16(tileLayer[j * width + i])); if (tileId != 0) { pdungeon[x + i][y + j] = tileId; } @@ -219,7 +219,7 @@ void DrawBlind(int x, int y) for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { - uint8_t tileId = SDL_SwapLE16(tileLayer[j * width + i]); + auto tileId = static_cast(SDL_SwapLE16(tileLayer[j * width + i])); if (tileId != 0) { pdungeon[x + i][y + j] = tileId; } @@ -243,7 +243,7 @@ void DrawBlood(int x, int y) for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { - uint8_t tileId = SDL_SwapLE16(tileLayer[j * width + i]); + auto tileId = static_cast(SDL_SwapLE16(tileLayer[j * width + i])); if (tileId != 0) { dungeon[x + i][y + j] = tileId; } diff --git a/Source/stores.cpp b/Source/stores.cpp index b3254e0aa..c9adf4ebc 100644 --- a/Source/stores.cpp +++ b/Source/stores.cpp @@ -353,6 +353,12 @@ uint32_t TotalPlayerGold() return MyPlayer->_pGold + Stash.gold; } +// TODO: Change `_iIvalue` to be unsigned instead of passing `int` here. +bool PlayerCanAfford(int price) +{ + return TotalPlayerGold() >= static_cast(price); +} + void StartSmithBuy() { stextsize = true; @@ -1399,7 +1405,7 @@ void SmithBuyEnter() auto &myPlayer = Players[MyPlayerId]; int idx = stextsval + ((stextsel - stextup) / 4); - if (TotalPlayerGold() < smithitem[idx]._iIvalue) { + if (!PlayerCanAfford(smithitem[idx]._iIvalue)) { StartStore(STORE_NOMONEY); return; } @@ -1465,7 +1471,7 @@ void SmithPremiumBuyEnter() auto &myPlayer = Players[MyPlayerId]; - if (TotalPlayerGold() < premiumitems[idx]._iIvalue) { + if (!PlayerCanAfford(premiumitems[idx]._iIvalue)) { StartStore(STORE_NOMONEY); return; } @@ -1588,7 +1594,7 @@ void SmithRepairEnter() auto &myPlayer = Players[MyPlayerId]; myPlayer.HoldItem = storehold[idx]; - if (TotalPlayerGold() < storehold[idx]._iIvalue) + if (!PlayerCanAfford(storehold[idx]._iIvalue)) StartStore(STORE_NOMONEY); else StartStore(STORE_CONFIRM); @@ -1665,7 +1671,7 @@ void WitchBuyEnter() int idx = stextsval + ((stextsel - stextup) / 4); - if (TotalPlayerGold() < witchitem[idx]._iIvalue) { + if (!PlayerCanAfford(witchitem[idx]._iIvalue)) { StartStore(STORE_NOMONEY); return; } @@ -1737,7 +1743,7 @@ void WitchRechargeEnter() int idx = stextsval + ((stextsel - stextup) / 4); myPlayer.HoldItem = storehold[idx]; - if (TotalPlayerGold() < storehold[idx]._iIvalue) + if (!PlayerCanAfford(storehold[idx]._iIvalue)) StartStore(STORE_NOMONEY); else StartStore(STORE_CONFIRM); @@ -1746,7 +1752,7 @@ void WitchRechargeEnter() void BoyEnter() { if (!boyitem.isEmpty() && stextsel == 18) { - if (TotalPlayerGold() < 50) { + if (!PlayerCanAfford(50)) { stextshold = STORE_BOY; stextlhold = 18; stextvhold = stextsval; @@ -1841,7 +1847,7 @@ void BoyBuyEnter() auto &myPlayer = Players[MyPlayerId]; - if (TotalPlayerGold() < price) { + if (!PlayerCanAfford(price)) { StartStore(STORE_NOMONEY); return; } @@ -1976,7 +1982,7 @@ void HealerBuyEnter() auto &myPlayer = Players[MyPlayerId]; - if (TotalPlayerGold() < healitem[idx]._iIvalue) { + if (!PlayerCanAfford(healitem[idx]._iIvalue)) { StartStore(STORE_NOMONEY); return; } @@ -2027,7 +2033,7 @@ void StorytellerIdentifyEnter() int idx = stextsval + ((stextsel - stextup) / 4); myPlayer.HoldItem = storehold[idx]; - if (TotalPlayerGold() < storehold[idx]._iIvalue) + if (!PlayerCanAfford(storehold[idx]._iIvalue)) StartStore(STORE_NOMONEY); else StartStore(STORE_CONFIRM);