diff --git a/Source/dthread.cpp b/Source/dthread.cpp index feb0b2c1a..d348be728 100644 --- a/Source/dthread.cpp +++ b/Source/dthread.cpp @@ -19,7 +19,7 @@ event_emul *sghWorkToDoEvent; /* rdata */ static SDL_Thread *sghThread = nullptr; -static unsigned int DthreadHandler(void * /*data*/) +static void DthreadHandler() { const char *errorBuf; TMegaPkt *pkt; @@ -53,8 +53,6 @@ static unsigned int DthreadHandler(void * /*data*/) SDL_Delay(dwMilliseconds); } } - - return 0; } void dthread_remove_player(uint8_t pnum) diff --git a/Source/effects.cpp b/Source/effects.cpp index 33b944b36..fac289417 100644 --- a/Source/effects.cpp +++ b/Source/effects.cpp @@ -1121,10 +1121,10 @@ void InitMonsterSND(int monst) const int mtype = Monsters[monst].mtype; for (int i = 0; i < 4; i++) { - if (MonstSndChar[i] != 's' || monsterdata[mtype].snd_special) { + if (MonstSndChar[i] != 's' || MonsterData[mtype].snd_special) { for (int j = 0; j < 2; j++) { char path[MAX_PATH]; - sprintf(path, monsterdata[mtype].sndfile, MonstSndChar[i], j + 1); + sprintf(path, MonsterData[mtype].sndfile, MonstSndChar[i], j + 1); Monsters[monst].Snds[i][j] = sound_file_load(path); } } diff --git a/Source/monstdat.cpp b/Source/monstdat.cpp index fc7758899..22669301c 100644 --- a/Source/monstdat.cpp +++ b/Source/monstdat.cpp @@ -12,7 +12,7 @@ namespace devilution { /** Contains the data related to each monster ID. */ -const MonsterData monsterdata[] = { +const MonsterDataStruct MonsterData[] = { // clang-format off // mName, GraphicType, sndfile, TransFile, width, mImage, has_special, snd_special, has_trans, Frames[6], Rate[6], mMinDLvl, mMaxDLvl, mLevel, mMinHP, mMaxHP, mAi, mFlags , mInt, mHit, mAFNum, mMinDamage, mMaxDamage, mHit2, mAFNum2, mMinDamage2, mMaxDamage2, mArmorClass, mMonstClass, mMagicRes , mMagicRes2 , mSelFlag, mTreasure, mExp // TRANSLATORS: Monster Block start diff --git a/Source/monstdat.h b/Source/monstdat.h index fe1185980..0e445292e 100644 --- a/Source/monstdat.h +++ b/Source/monstdat.h @@ -74,7 +74,7 @@ enum monster_resistance : uint8_t { // clang-format on }; -struct MonsterData { +struct MonsterDataStruct { const char *mName; const char *GraphicType; const char *sndfile; @@ -281,7 +281,7 @@ struct UniqMonstStruct { _speech_id mtalkmsg; }; -extern const MonsterData monsterdata[]; +extern const MonsterDataStruct MonsterData[]; extern const _monster_id MonstConvTbl[]; extern const char MonstAvailTbl[]; extern const UniqMonstStruct UniqMonst[]; diff --git a/Source/monster.cpp b/Source/monster.cpp index 374dd3cce..712164e5f 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -240,7 +240,7 @@ int AddMonsterType(_monster_id type, placeflag placeflag) i = nummtypes; nummtypes++; Monsters[i].mtype = type; - monstimgtot += monsterdata[type].mImage; + monstimgtot += MonsterData[type].mImage; InitMonsterGFX(i); InitMonsterSND(i); } @@ -311,8 +311,8 @@ void GetLevelMTypes() nt = 0; for (i = MT_WSKELAX; i <= MT_WSKELAX + numskeltypes; i++) { if (IsSkel(i)) { - minl = 15 * monsterdata[i].mMinDLvl / 30 + 1; - maxl = 15 * monsterdata[i].mMaxDLvl / 30 + 1; + minl = 15 * MonsterData[i].mMinDLvl / 30 + 1; + maxl = 15 * MonsterData[i].mMaxDLvl / 30 + 1; if (currlevel >= minl && currlevel <= maxl) { if ((MonstAvailTbl[i] & mamask) != 0) { @@ -326,8 +326,8 @@ void GetLevelMTypes() nt = 0; for (i = MT_NZOMBIE; i < NUM_MTYPES; i++) { - minl = 15 * monsterdata[i].mMinDLvl / 30 + 1; - maxl = 15 * monsterdata[i].mMaxDLvl / 30 + 1; + minl = 15 * MonsterData[i].mMinDLvl / 30 + 1; + maxl = 15 * MonsterData[i].mMaxDLvl / 30 + 1; if (currlevel >= minl && currlevel <= maxl) { if ((MonstAvailTbl[i] & mamask) != 0) { @@ -346,7 +346,7 @@ void GetLevelMTypes() while (nt > 0 && nummtypes < MAX_LVLMTYPES && monstimgtot < 4000) { for (i = 0; i < nt;) { - if (monsterdata[typelist[i]].mImage > 4000 - monstimgtot) { + if (MonsterData[typelist[i]].mImage > 4000 - monstimgtot) { typelist[i] = typelist[--nt]; continue; } @@ -372,16 +372,16 @@ void GetLevelMTypes() void InitMonsterGFX(int monst) { int mtype = Monsters[monst].mtype; - int width = monsterdata[mtype].width; + int width = MonsterData[mtype].width; for (int anim = 0; anim < 6; anim++) { - int frames = monsterdata[mtype].Frames[anim]; + int frames = MonsterData[mtype].Frames[anim]; if (gbIsHellfire && mtype == MT_DIABLO && anim == 3) frames = 2; - if ((animletter[anim] != 's' || monsterdata[mtype].has_special) && frames > 0) { + if ((animletter[anim] != 's' || MonsterData[mtype].has_special) && frames > 0) { char strBuff[256]; - sprintf(strBuff, monsterdata[mtype].GraphicType, animletter[anim]); + sprintf(strBuff, MonsterData[mtype].GraphicType, animletter[anim]); byte *celBuf; { @@ -403,20 +403,19 @@ void InitMonsterGFX(int monst) } Monsters[monst].Anims[anim].Frames = frames; - Monsters[monst].Anims[anim].Rate = monsterdata[mtype].Rate[anim]; + Monsters[monst].Anims[anim].Rate = MonsterData[mtype].Rate[anim]; } - Monsters[monst].mMinHP = monsterdata[mtype].mMinHP; - Monsters[monst].mMaxHP = monsterdata[mtype].mMaxHP; + Monsters[monst].mMinHP = MonsterData[mtype].mMinHP; + Monsters[monst].mMaxHP = MonsterData[mtype].mMaxHP; if (!gbIsHellfire && mtype == MT_DIABLO) { Monsters[monst].mMinHP -= 2000; Monsters[monst].mMaxHP -= 2000; } - Monsters[monst].has_special = monsterdata[mtype].has_special; - Monsters[monst].mAFNum = monsterdata[mtype].mAFNum; - Monsters[monst].MData = &monsterdata[mtype]; + Monsters[monst].mAFNum = MonsterData[mtype].mAFNum; + Monsters[monst].MData = &MonsterData[mtype]; - if (monsterdata[mtype].has_trans) { + if (MonsterData[mtype].has_trans) { InitMonsterTRN(Monsters[monst]); } @@ -1332,7 +1331,7 @@ void M_Enemy(int i) int mi = monstactive[j]; if (mi == i) continue; - if (!((monster[mi]._mhitpoints >> 6) > 0)) + if ((monster[mi]._mhitpoints >> 6) <= 0) continue; if (monster[mi].position.tile.x == 1 && monster[mi].position.tile.y == 0) continue; @@ -2374,7 +2373,7 @@ bool M_DoTalk(int i) if (monster[i]._uniqtype - 1 == UMT_SNOTSPIL) { if (monster[i].mtalkmsg == TEXT_BANNER10 && (monster[i]._mFlags & MFLAG_QUEST_COMPLETE) == 0) { ObjChangeMap(setpc_x, setpc_y, (setpc_w / 2) + setpc_x + 2, (setpc_h / 2) + setpc_y - 2); - int tren = TransVal; + int8_t tren = TransVal; TransVal = 9; DRLG_MRectTrans(setpc_x, setpc_y, (setpc_w / 2) + setpc_x + 4, setpc_y + (setpc_h / 2)); TransVal = tren; @@ -2491,14 +2490,18 @@ void DoEnding() if (gbIsSpawn) return; - if (plr[myplr]._pClass == HeroClass::Warrior || plr[myplr]._pClass == HeroClass::Barbarian) { - play_movie("gendata\\DiabVic2.smk", false); - } else if (plr[myplr]._pClass == HeroClass::Sorcerer) { - play_movie("gendata\\DiabVic1.smk", false); - } else if (plr[myplr]._pClass == HeroClass::Monk) { + switch (plr[myplr]._pClass) { + case HeroClass::Sorcerer: + case HeroClass::Monk: play_movie("gendata\\DiabVic1.smk", false); - } else { + break; + case HeroClass::Warrior: + case HeroClass::Barbarian: + play_movie("gendata\\DiabVic2.smk", false); + break; + default: play_movie("gendata\\DiabVic3.smk", false); + break; } play_movie("gendata\\Diabend.smk", false); @@ -4409,9 +4412,7 @@ void ProcessMonsters() } } do { - if ((monst->_mFlags & MFLAG_SEARCH) == 0) { - AiProc[monst->_mAi](mi); - } else if (!MAI_Path(mi)) { + if ((monst->_mFlags & MFLAG_SEARCH) == 0 || !MAI_Path(mi)) { AiProc[monst->_mAi](mi); } switch (monst->_mmode) { @@ -4483,7 +4484,7 @@ void FreeMonsters() for (int i = 0; i < nummtypes; i++) { int mtype = Monsters[i].mtype; for (int j = 0; j < 6; j++) { - if (animletter[j] != 's' || monsterdata[mtype].has_special) { + if (animletter[j] != 's' || MonsterData[mtype].has_special) { Monsters[i].Anims[j].CMem = nullptr; } } @@ -4725,7 +4726,7 @@ void M_FallenFear(Point position) } } -const char *GetMonsterTypeText(const MonsterData &monsterData) +const char *GetMonsterTypeText(const MonsterDataStruct &monsterData) { switch (monsterData.mMonstClass) { case MC_ANIMAL: @@ -4742,15 +4743,15 @@ const char *GetMonsterTypeText(const MonsterData &monsterData) void PrintMonstHistory(int mt) { if (sgOptions.Gameplay.bShowMonsterType) { - strcpy(tempstr, fmt::format(_("Type: {:s} Kills: {:d}"), GetMonsterTypeText(monsterdata[mt]), monstkills[mt]).c_str()); + strcpy(tempstr, fmt::format(_("Type: {:s} Kills: {:d}"), GetMonsterTypeText(MonsterData[mt]), monstkills[mt]).c_str()); } else { strcpy(tempstr, fmt::format(_("Total kills: {:d}"), monstkills[mt]).c_str()); } AddPanelString(tempstr); if (monstkills[mt] >= 30) { - int minHP = monsterdata[mt].mMinHP; - int maxHP = monsterdata[mt].mMaxHP; + int minHP = MonsterData[mt].mMinHP; + int maxHP = MonsterData[mt].mMaxHP; if (!gbIsHellfire && mt == MT_DIABLO) { minHP -= 2000; maxHP -= 2000; @@ -4781,7 +4782,7 @@ void PrintMonstHistory(int mt) AddPanelString(tempstr); } if (monstkills[mt] >= 15) { - int res = (sgGameInitInfo.nDifficulty != DIFF_HELL) ? monsterdata[mt].mMagicRes : monsterdata[mt].mMagicRes2; + int res = (sgGameInitInfo.nDifficulty != DIFF_HELL) ? MonsterData[mt].mMagicRes : MonsterData[mt].mMagicRes2; if ((res & (RESIST_MAGIC | RESIST_FIRE | RESIST_LIGHTNING | IMMUNE_MAGIC | IMMUNE_FIRE | IMMUNE_LIGHTNING)) == 0) { strcpy(tempstr, _("No magic resistance")); AddPanelString(tempstr); @@ -4915,7 +4916,7 @@ bool PosOkMonst(int i, Point position) bool monster_posok(int i, Point position) { - int mi = dMissile[position.x][position.y]; + int8_t mi = dMissile[position.x][position.y]; if (mi == 0 || i < 0) { return true; } diff --git a/Source/monster.h b/Source/monster.h index 4ae4d5762..66ff9ea68 100644 --- a/Source/monster.h +++ b/Source/monster.h @@ -132,10 +132,9 @@ struct CMonster { #endif uint16_t mMinHP; uint16_t mMaxHP; - bool has_special; uint8_t mAFNum; int8_t mdeadval; - const MonsterData *MData; + const MonsterDataStruct *MData; }; struct MonsterStruct { // note: missing field _mAFNum @@ -192,7 +191,7 @@ struct MonsterStruct { // note: missing field _mAFNum int8_t mlid; // BUGFIX -1 is used when not emitting light this should be signed (fixed) const char *mName; CMonster *MType; - const MonsterData *MData; + const MonsterDataStruct *MData; /** * @brief Check thats the correct stand Animation is loaded. This is needed if direction is changed (monster stands and looks to player). @@ -293,7 +292,6 @@ bool DirOK(int i, Direction mdir); bool PosOkMissile(int entity, Point position); bool LineClearSolid(Point startPoint, Point endPoint); bool LineClearMissile(Point startPoint, Point endPoint); -bool LineClear(Point startPoint, Point endPoint); bool LineClear(bool (*Clear)(int, Point), int entity, Point startPoint, Point endPoint); void SyncMonsterAnim(int i); void M_FallenFear(Point position); diff --git a/Source/movie.cpp b/Source/movie.cpp index 2811a6a32..721e79095 100644 --- a/Source/movie.cpp +++ b/Source/movie.cpp @@ -50,7 +50,6 @@ void play_movie(const char *pszMovie, bool userCanClose) case DVL_WM_QUIT: SVidPlayEnd(); diablo_quit(0); - break; } } if (!SVidPlayContinue()) diff --git a/Source/mpqapi.cpp b/Source/mpqapi.cpp index 3da0552a8..7a7b12e60 100644 --- a/Source/mpqapi.cpp +++ b/Source/mpqapi.cpp @@ -105,18 +105,6 @@ public: return s_ != nullptr; } - bool Seekg(std::streampos pos) - { - s_->seekg(pos); - return CheckError("seekg(%" PRIuMAX ")", static_cast(pos)); - } - - bool Seekg(std::streamoff pos, std::ios::seekdir dir) - { - s_->seekg(pos, dir); - return CheckError("seekg(%" PRIdMAX ", %s)", static_cast(pos), DirToString(dir)); - } - bool Seekp(std::streampos pos) { s_->seekp(pos); @@ -129,12 +117,6 @@ public: return CheckError("seekp(%" PRIdMAX ", %s)", static_cast(pos), DirToString(dir)); } - bool Tellg(std::streampos *result) - { - *result = s_->tellg(); - return CheckError("tellg() = %" PRIuMAX, static_cast(*result)); - } - bool Tellp(std::streampos *result) { *result = s_->tellp(); @@ -194,32 +176,32 @@ struct Archive { _HASHENTRY *sgpHashTbl; _BLOCKENTRY *sgpBlockTbl; - bool Open(const char *name) + bool Open(const char *path) { Close(); #ifdef _DEBUG - Log("Opening {}", name); + Log("Opening {}", path); #endif - exists = FileExists(name); + exists = FileExists(path); std::ios::openmode mode = std::ios::in | std::ios::out | std::ios::binary; if (exists) { - if (!GetFileSize(name, &size)) { - Log(R"(GetFileSize("{}") failed with "{}")", name, std::strerror(errno)); + if (!GetFileSize(path, &size)) { + Log(R"(GetFileSize("{}") failed with "{}")", path, std::strerror(errno)); return false; } #ifdef _DEBUG - Log("GetFileSize(\"{}\") = {}", name, size); + Log("GetFileSize(\"{}\") = {}", path, size); #endif } else { mode |= std::ios::trunc; } - if (!stream.Open(name, mode)) { + if (!stream.Open(path, mode)) { stream.Close(); return false; } modified = !exists; - this->name = name; + name = path; return true; } @@ -475,7 +457,7 @@ _BLOCKENTRY *AddFile(const char *pszName, _BLOCKENTRY *pBlk, int blockIndex) uint32_t h3 = Hash(pszName, 2); if (GetHashIndex(h1, h2, h3) != -1) app_fatal("Hash collision between \"%s\" and existing file\n", pszName); - int hIdx = h1 & 0x7FF; + unsigned int hIdx = h1 & 0x7FF; bool hasSpace = false; for (int i = 0; i < INDEX_ENTRIES; i++) { diff --git a/Source/msg.cpp b/Source/msg.cpp index cc2f8751d..4a4a2a276 100644 --- a/Source/msg.cpp +++ b/Source/msg.cpp @@ -130,7 +130,6 @@ void SendPacket(int pnum, const void *packet, DWORD dwSize) int WaitForTurns() { - bool received; DWORD turns; if (sgbDeltaChunks == 0) { @@ -143,8 +142,9 @@ int WaitForTurns() } multi_process_network_packets(); nthread_send_and_recv_turn(0, 0); - if (nthread_has_500ms_passed()) - nthread_recv_turns(&received); + if (nthread_has_500ms_passed()) { + nthread_recv_turns(); + } if (gbGameDestroyed) return 100; @@ -326,10 +326,7 @@ DWORD OnLevelData(int pnum, TCmd *pCmd) auto *p = (TCmdPlrInfoHdr *)pCmd; if (gbDeltaSender != pnum) { - if (p->bCmd == CMD_DLEVEL_END) { - gbDeltaSender = pnum; - sgbRecvCmd = CMD_DLEVEL_END; - } else if (p->bCmd == CMD_DLEVEL_0 && p->wOffset == 0) { + if (p->bCmd == CMD_DLEVEL_END || (p->bCmd == CMD_DLEVEL_0 && p->wOffset == 0)) { gbDeltaSender = pnum; sgbRecvCmd = CMD_DLEVEL_END; } else { diff --git a/Source/msg.h b/Source/msg.h index c002416cf..879a235ea 100644 --- a/Source/msg.h +++ b/Source/msg.h @@ -308,8 +308,6 @@ struct TSyncHeader { _cmd_id bCmd; uint8_t bLevel; uint16_t wLen; - uint8_t bObjId; - uint8_t bObjCmd; uint8_t bItemI; uint8_t bItemX; uint8_t bItemY; @@ -328,12 +326,6 @@ struct TSyncHeader { uint16_t wPInvCI; uint32_t dwPInvSeed; uint8_t bPInvId; - uint16_t wToHit; - uint16_t wMaxDam; - uint8_t bMinStr; - uint8_t bMinMag; - uint8_t bMinDex; - uint8_t bAC; }; struct TSyncMonster { diff --git a/Source/multi.cpp b/Source/multi.cpp index 000ed18ac..f173e137d 100644 --- a/Source/multi.cpp +++ b/Source/multi.cpp @@ -240,7 +240,7 @@ void BeginTimeout() } #endif - int nTicks = SDL_GetTicks() - sglTimeoutStart; + uint32_t nTicks = SDL_GetTicks() - sglTimeoutStart; if (nTicks > 20000) { gbRunGame = false; return; @@ -287,7 +287,7 @@ void BeginTimeout() } } -void HandleAllPackets(int pnum, byte *pData, int nSize) +void HandleAllPackets(int pnum, byte *pData, size_t nSize) { while (nSize != 0) { int nLen = ParseCmd(pnum, (TCmd *)pData); @@ -301,7 +301,7 @@ void HandleAllPackets(int pnum, byte *pData, int nSize) void ProcessTmsgs() { - int cnt; + size_t cnt; TPkt pkt; while ((cnt = tmsg_get((byte *)&pkt)) != 0) { diff --git a/Source/nthread.cpp b/Source/nthread.cpp index 0aa5c41b8..f4b1b0b9c 100644 --- a/Source/nthread.cpp +++ b/Source/nthread.cpp @@ -6,6 +6,7 @@ #include "diablo.h" #include "gmenu.h" +#include "nthread.h" #include "storm/storm.h" #include "utils/thread.h" @@ -20,7 +21,7 @@ DWORD gdwTurnsInTransit; uintptr_t glpMsgTbl[MAX_PLRS]; SDL_threadID glpNThreadId; char sgbSyncCountdown; -int turn_upper_bit; +uint32_t turn_upper_bit; bool sgbTicsOutOfSync; char sgbPacketCountdown; bool sgbThreadIsRunning; @@ -34,19 +35,15 @@ static SDL_Thread *sghThread = nullptr; void nthread_terminate_game(const char *pszFcn) { - DWORD sErr; - - sErr = SErrGetLastError(); + uint32_t sErr = SErrGetLastError(); if (sErr == STORM_ERROR_INVALID_PLAYER) { return; } - if (sErr == STORM_ERROR_GAME_TERMINATED) { - gbGameDestroyed = true; - } else if (sErr == STORM_ERROR_NOT_IN_GAME) { - gbGameDestroyed = true; - } else { + if (sErr != STORM_ERROR_GAME_TERMINATED && sErr != STORM_ERROR_NOT_IN_GAME) { app_fatal("%s:\n%s", pszFcn, SDL_GetError()); } + + gbGameDestroyed = true; } uint32_t nthread_send_and_recv_turn(uint32_t curTurn, int turnDelta) @@ -58,9 +55,9 @@ uint32_t nthread_send_and_recv_turn(uint32_t curTurn, int turnDelta) } while (curTurnsInTransit++ < gdwTurnsInTransit) { - int turnTmp = turn_upper_bit | (curTurn & 0x7FFFFFFF); + uint32_t turnTmp = turn_upper_bit | (curTurn & 0x7FFFFFFF); turn_upper_bit = 0; - int turn = turnTmp; + uint32_t turn = turnTmp; if (!SNetSendTurn((char *)&turn, sizeof(turn))) { nthread_terminate_game("SNetSendTurn"); @@ -76,7 +73,8 @@ uint32_t nthread_send_and_recv_turn(uint32_t curTurn, int turnDelta) bool nthread_recv_turns(bool *pfSendAsync) { - *pfSendAsync = false; + if (pfSendAsync != nullptr) + *pfSendAsync = false; sgbPacketCountdown--; if (sgbPacketCountdown > 0) { last_tick += gnTickDelay; @@ -85,8 +83,8 @@ bool nthread_recv_turns(bool *pfSendAsync) sgbSyncCountdown--; sgbPacketCountdown = sgbNetUpdateRate; if (sgbSyncCountdown != 0) { - - *pfSendAsync = true; + if (pfSendAsync != nullptr) + *pfSendAsync = true; last_tick += gnTickDelay; return true; } @@ -104,35 +102,34 @@ bool nthread_recv_turns(bool *pfSendAsync) } sgbSyncCountdown = 4; multi_msg_countdown(); - *pfSendAsync = true; + if (pfSendAsync != nullptr) + *pfSendAsync = true; last_tick += gnTickDelay; return true; } -static unsigned int NthreadHandler(void * /*data*/) +static void NthreadHandler() { - int delta; - bool received; + if (!nthread_should_run) { + return; + } - if (nthread_should_run) { - while (true) { - sgMemCrit.Enter(); - if (!nthread_should_run) - break; - nthread_send_and_recv_turn(0, 0); - if (nthread_recv_turns(&received)) - delta = last_tick - SDL_GetTicks(); - else - delta = gnTickDelay; + while (true) { + sgMemCrit.Enter(); + if (!nthread_should_run) { sgMemCrit.Leave(); - if (delta > 0) - SDL_Delay(delta); - if (!nthread_should_run) - return 0; + break; } + nthread_send_and_recv_turn(0, 0); + int delta = gnTickDelay; + if (nthread_recv_turns()) + delta = last_tick - SDL_GetTicks(); sgMemCrit.Leave(); + if (delta > 0) + SDL_Delay(delta); + if (!nthread_should_run) + return; } - return 0; } void nthread_set_turn_upper_bit() @@ -223,11 +220,8 @@ void nthread_ignore_mutex(bool bStart) */ bool nthread_has_500ms_passed() { - DWORD currentTickCount; - int ticksElapsed; - - currentTickCount = SDL_GetTicks(); - ticksElapsed = currentTickCount - last_tick; + int currentTickCount = SDL_GetTicks(); + int ticksElapsed = currentTickCount - last_tick; if (!gbIsMultiplayer && ticksElapsed > gnTickDelay * 10) { last_tick = currentTickCount; ticksElapsed = 0; diff --git a/Source/nthread.h b/Source/nthread.h index f4740a975..49376a53f 100644 --- a/Source/nthread.h +++ b/Source/nthread.h @@ -21,7 +21,7 @@ extern float gfProgressToNextGameTick; // the progress as a fraction (0.0f to 1. void nthread_terminate_game(const char *pszFcn); DWORD nthread_send_and_recv_turn(DWORD cur_turn, int turn_delta); -bool nthread_recv_turns(bool *pfSendAsync); +bool nthread_recv_turns(bool *pfSendAsync = nullptr); void nthread_set_turn_upper_bit(); void nthread_start(bool set_turn_upper_bit); void nthread_cleanup(); diff --git a/Source/objects.cpp b/Source/objects.cpp index da38db53e..0f7cea19c 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -1625,48 +1625,63 @@ void AddCryptObject(int i, int a2) if (a2 > 5) { switch (a2) { case 6: - if (plr[myplr]._pClass == HeroClass::Warrior) { + switch (plr[myplr]._pClass) { + case HeroClass::Warrior: + case HeroClass::Barbarian: object[i]._oVar2 = TEXT_BOOKA; - } else if (plr[myplr]._pClass == HeroClass::Rogue) { + break; + case HeroClass::Rogue: object[i]._oVar2 = TEXT_RBOOKA; - } else if (plr[myplr]._pClass == HeroClass::Sorcerer) { + break; + case HeroClass::Sorcerer: object[i]._oVar2 = TEXT_MBOOKA; - } else if (plr[myplr]._pClass == HeroClass::Monk) { + break; + case HeroClass::Monk: object[i]._oVar2 = TEXT_OBOOKA; - } else if (plr[myplr]._pClass == HeroClass::Bard) { + break; + case HeroClass::Bard: object[i]._oVar2 = TEXT_BBOOKA; - } else if (plr[myplr]._pClass == HeroClass::Barbarian) { - object[i]._oVar2 = TEXT_BOOKA; + break; } break; case 7: - if (plr[myplr]._pClass == HeroClass::Warrior) { + switch (plr[myplr]._pClass) { + case HeroClass::Warrior: + case HeroClass::Barbarian: object[i]._oVar2 = TEXT_BOOKB; - } else if (plr[myplr]._pClass == HeroClass::Rogue) { + break; + case HeroClass::Rogue: object[i]._oVar2 = TEXT_RBOOKB; - } else if (plr[myplr]._pClass == HeroClass::Sorcerer) { + break; + case HeroClass::Sorcerer: object[i]._oVar2 = TEXT_MBOOKB; - } else if (plr[myplr]._pClass == HeroClass::Monk) { + break; + case HeroClass::Monk: object[i]._oVar2 = TEXT_OBOOKB; - } else if (plr[myplr]._pClass == HeroClass::Bard) { + break; + case HeroClass::Bard: object[i]._oVar2 = TEXT_BBOOKB; - } else if (plr[myplr]._pClass == HeroClass::Barbarian) { - object[i]._oVar2 = TEXT_BOOKB; + break; } break; case 8: - if (plr[myplr]._pClass == HeroClass::Warrior) { + switch (plr[myplr]._pClass) { + case HeroClass::Warrior: + case HeroClass::Barbarian: object[i]._oVar2 = TEXT_BOOKC; - } else if (plr[myplr]._pClass == HeroClass::Rogue) { + break; + case HeroClass::Rogue: object[i]._oVar2 = TEXT_RBOOKC; - } else if (plr[myplr]._pClass == HeroClass::Sorcerer) { + break; + case HeroClass::Sorcerer: object[i]._oVar2 = TEXT_MBOOKC; - } else if (plr[myplr]._pClass == HeroClass::Monk) { + break; + case HeroClass::Monk: object[i]._oVar2 = TEXT_OBOOKC; - } else if (plr[myplr]._pClass == HeroClass::Bard) { + break; + case HeroClass::Bard: object[i]._oVar2 = TEXT_BBOOKC; - } else if (plr[myplr]._pClass == HeroClass::Barbarian) { - object[i]._oVar2 = TEXT_BOOKC; + break; } break; } @@ -1694,8 +1709,6 @@ void AddObject(_object_id ot, int ox, int oy) SetupObject(oi, ox, oy, ot); switch (ot) { case OBJ_L1LIGHT: - AddObjLight(oi, 5); - break; case OBJ_SKFIRE: case OBJ_CANDLE1: case OBJ_CANDLE2: @@ -2054,7 +2067,7 @@ void Obj_BCrossDamage(int i) if (plr[myplr]._pmode == PM_DEATH) return; - int fireResist = plr[myplr]._pFireResist; + int8_t fireResist = plr[myplr]._pFireResist; if (fireResist > 0) damage[leveltype - 1] -= fireResist * damage[leveltype - 1] / 100; @@ -2903,7 +2916,7 @@ void OperateBookLever(int pnum, int i) ObjChangeMap(object[i]._oVar1, object[i]._oVar2, object[i]._oVar3, object[i]._oVar4); if (object[i]._otype == OBJ_BLINDBOOK) { SpawnUnique(UITEM_OPTAMULET, Point { x, y } + Displacement { 5, 5 }); - int tren = TransVal; + int8_t tren = TransVal; TransVal = 9; DRLG_MRectTrans(object[i]._oVar1, object[i]._oVar2, object[i]._oVar3, object[i]._oVar4); TransVal = tren; @@ -5154,7 +5167,7 @@ void SyncQSTLever(int i) if (object[i]._oAnimFrame == object[i]._oVar6) { ObjChangeMapResync(object[i]._oVar1, object[i]._oVar2, object[i]._oVar3, object[i]._oVar4); if (object[i]._otype == OBJ_BLINDBOOK) { - int tren = TransVal; + int8_t tren = TransVal; TransVal = 9; DRLG_MRectTrans(object[i]._oVar1, object[i]._oVar2, object[i]._oVar3, object[i]._oVar4); TransVal = tren; diff --git a/Source/options.cpp b/Source/options.cpp index 5ebff0474..4364de5a8 100644 --- a/Source/options.cpp +++ b/Source/options.cpp @@ -61,20 +61,17 @@ CSimpleIni &GetIni() int GetIniInt(const char *keyname, const char *valuename, int defaultValue) { - long value = GetIni().GetLongValue(keyname, valuename, defaultValue); - return value; + return GetIni().GetLongValue(keyname, valuename, defaultValue); } bool GetIniBool(const char *sectionName, const char *keyName, bool defaultValue) { - bool value = GetIni().GetBoolValue(sectionName, keyName, defaultValue); - return value; + return GetIni().GetBoolValue(sectionName, keyName, defaultValue); } float GetIniFloat(const char *sectionName, const char *keyName, float defaultValue) { - const double value = GetIni().GetDoubleValue(sectionName, keyName, defaultValue); - return (float)value; + return (float)GetIni().GetDoubleValue(sectionName, keyName, defaultValue); } void SetIniValue(const char *keyname, const char *valuename, int value) diff --git a/Source/sync.cpp b/Source/sync.cpp index dccd9f8f9..99e3f7f0f 100644 --- a/Source/sync.cpp +++ b/Source/sync.cpp @@ -152,20 +152,16 @@ void SyncPlrInv(TSyncHeader *pHdr) uint32_t sync_all_monsters(const byte *pbBuf, uint32_t dwMaxLen) { - TSyncHeader *pHdr; - int i; - bool sync; - if (nummonsters < 1) { return dwMaxLen; } - if (dwMaxLen < sizeof(*pHdr) + sizeof(TSyncMonster)) { + if (dwMaxLen < sizeof(TSyncHeader) + sizeof(TSyncMonster)) { return dwMaxLen; } - pHdr = (TSyncHeader *)pbBuf; - pbBuf += sizeof(*pHdr); - dwMaxLen -= sizeof(*pHdr); + auto *pHdr = (TSyncHeader *)pbBuf; + pbBuf += sizeof(TSyncHeader); + dwMaxLen -= sizeof(TSyncHeader); pHdr->bCmd = CMD_SYNCDATA; pHdr->bLevel = currlevel; @@ -174,8 +170,8 @@ uint32_t sync_all_monsters(const byte *pbBuf, uint32_t dwMaxLen) assert(dwMaxLen <= 0xffff); SyncOneMonster(); - for (i = 0; i < nummonsters && dwMaxLen >= sizeof(TSyncMonster); i++) { - sync = false; + for (int i = 0; i < nummonsters && dwMaxLen >= sizeof(TSyncMonster); i++) { + bool sync = false; if (i < 2) { sync = SyncMonsterActive2((TSyncMonster *)pbBuf); } diff --git a/Source/tmsg.cpp b/Source/tmsg.cpp index 23a3af245..c7046f0dd 100644 --- a/Source/tmsg.cpp +++ b/Source/tmsg.cpp @@ -15,9 +15,8 @@ TMsg *sgpTimedMsgHead; } // namespace -int tmsg_get(byte *pbMsg) +size_t tmsg_get(byte *pbMsg) { - int len; TMsg *head; if (sgpTimedMsgHead == nullptr) @@ -27,7 +26,7 @@ int tmsg_get(byte *pbMsg) return 0; head = sgpTimedMsgHead; sgpTimedMsgHead = head->hdr.pNext; - len = head->hdr.bLen; + size_t len = head->hdr.bLen; // BUGFIX: ignores dwMaxLen memcpy(pbMsg, head->body, len); std::free(head); diff --git a/Source/tmsg.h b/Source/tmsg.h index b854787d5..1c7937220 100644 --- a/Source/tmsg.h +++ b/Source/tmsg.h @@ -26,7 +26,7 @@ struct TMsg { }; #pragma pack(pop) -int tmsg_get(byte *pbMsg); +size_t tmsg_get(byte *pbMsg); void tmsg_add(byte *pbMsg, uint8_t bLen); void tmsg_start(); void tmsg_cleanup(); diff --git a/Source/utils/thread.cpp b/Source/utils/thread.cpp index 7d186c0af..f7666701a 100644 --- a/Source/utils/thread.cpp +++ b/Source/utils/thread.cpp @@ -11,12 +11,14 @@ namespace devilution { static int SDLCALL ThreadTranslate(void *ptr) { - auto handler = (unsigned int (*)(void *))ptr; + auto handler = (void (*)())ptr; - return handler(nullptr); + handler(); + + return 0; } -SDL_Thread *CreateThread(unsigned int (*handler)(void *), SDL_threadID *threadId) +SDL_Thread *CreateThread(void (*handler)(), SDL_threadID *threadId) { #ifdef USE_SDL1 SDL_Thread *ret = SDL_CreateThread(ThreadTranslate, (void *)handler); diff --git a/Source/utils/thread.h b/Source/utils/thread.h index c36785668..d418fd6c6 100644 --- a/Source/utils/thread.h +++ b/Source/utils/thread.h @@ -18,6 +18,6 @@ void EndEvent(event_emul *event); void SetEvent(event_emul *e); void ResetEvent(event_emul *e); int WaitForEvent(event_emul *e); -SDL_Thread *CreateThread(unsigned int (*handler)(void *), SDL_threadID *ThreadID); +SDL_Thread *CreateThread(void (*handler)(), SDL_threadID *ThreadID); } // namespace devilution