From a7c7fa0030d2bf1b1e9617f4432f814c2f993a70 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sun, 4 Jul 2021 00:47:01 +0200 Subject: [PATCH] Fully apply clang-tidy/format to all files --- Source/DiabloUI/dialogs.cpp | 2 +- Source/DiabloUI/dialogs.h | 2 +- Source/controls/keymapper.cpp | 2 +- Source/diablo.cpp | 2 +- Source/diablo.h | 8 +- Source/drlg_l1.cpp | 12 +- Source/dthread.cpp | 16 +- Source/engine/random.hpp | 3 +- Source/engine/surface.hpp | 6 +- Source/init.cpp | 16 +- Source/interfac.cpp | 10 +- Source/itemdat.h | 8 +- Source/items.cpp | 22 +- Source/lighting.cpp | 134 +- Source/loadsave.cpp | 24 +- Source/missiles.cpp | 16 +- Source/missiles.h | 4 +- Source/monster.cpp | 1707 +++++++++++----------- Source/movie.cpp | 8 +- Source/mpqapi.cpp | 70 +- Source/msg.cpp | 6 +- Source/multi.cpp | 38 +- Source/nthread.cpp | 4 +- Source/objects.cpp | 112 +- Source/palette.cpp | 24 +- Source/path.cpp | 98 +- Source/pfile.cpp | 66 +- Source/platform/ctr/asio/sys/socket.c | 2 +- Source/platform/switch/asio/sys/signal.c | 4 +- Source/player.cpp | 8 +- Source/plrmsg.cpp | 8 +- Source/qol/xpbar.cpp | 6 +- Source/scrollrt.cpp | 50 +- Source/sha.cpp | 82 +- Source/sound.cpp | 6 +- Source/storm/storm_svid.cpp | 12 +- Source/towners.h | 2 +- Source/track.cpp | 6 +- Source/utils/log.hpp | 32 +- 39 files changed, 1315 insertions(+), 1323 deletions(-) diff --git a/Source/DiabloUI/dialogs.cpp b/Source/DiabloUI/dialogs.cpp index 03570b2dd..c1ccb0c64 100644 --- a/Source/DiabloUI/dialogs.cpp +++ b/Source/DiabloUI/dialogs.cpp @@ -299,7 +299,7 @@ void UiErrorOkDialog(const char *text, const char *caption, bool error) UiOkDialog(text, caption, error, vecNULL); } -void UiErrorOkDialog(const char *text, const std::vector& renderBehind) +void UiErrorOkDialog(const char *text, const std::vector &renderBehind) { UiErrorOkDialog(text, nullptr, renderBehind); } diff --git a/Source/DiabloUI/dialogs.h b/Source/DiabloUI/dialogs.h index cfb5d68b6..2d0c53127 100644 --- a/Source/DiabloUI/dialogs.h +++ b/Source/DiabloUI/dialogs.h @@ -6,7 +6,7 @@ namespace devilution { -void UiErrorOkDialog(const char *text, const std::vector& renderBehind); +void UiErrorOkDialog(const char *text, const std::vector &renderBehind); void UiErrorOkDialog(const char *text, const char *caption, const std::vector &renderBehind); void UiOkDialog(const char *text, const char *caption, bool error, const std::vector &renderBehind); diff --git a/Source/controls/keymapper.cpp b/Source/controls/keymapper.cpp index c4cf0fec7..e5615386d 100644 --- a/Source/controls/keymapper.cpp +++ b/Source/controls/keymapper.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include diff --git a/Source/diablo.cpp b/Source/diablo.cpp index c4582b989..48190e25e 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -410,7 +410,7 @@ static void RunGameLoop(interface_mode uMsg) } if (gbIsMultiplayer) { - pfile_write_hero(/*write_game_data=*/false, /*clear_tables=*/true); + pfile_write_hero(/*writeGameData=*/false, /*clearTables=*/true); } PaletteFadeOut(8); diff --git a/Source/diablo.h b/Source/diablo.h index e6734a870..2f41a2263 100644 --- a/Source/diablo.h +++ b/Source/diablo.h @@ -101,10 +101,10 @@ extern int debug_mode_key_j; #endif struct QuickMessage { - /** Config variable names for quick message */ - const char *const key; - /** Default quick message */ - const char *const message; + /** Config variable names for quick message */ + const char *const key; + /** Default quick message */ + const char *const message; }; constexpr size_t QUICK_MESSAGE_OPTIONS = 4; diff --git a/Source/drlg_l1.cpp b/Source/drlg_l1.cpp index 7ac8fbd9a..fda3439db 100644 --- a/Source/drlg_l1.cpp +++ b/Source/drlg_l1.cpp @@ -1483,12 +1483,12 @@ static void L5makeDungeon() { for (int j = 0; j < DMAXY; j++) { for (int i = 0; i < DMAXX; i++) { - int i_2 = i * 2; - int j_2 = j * 2; - L5dungeon[i_2][j_2] = dungeon[i][j]; - L5dungeon[i_2][j_2 + 1] = dungeon[i][j]; - L5dungeon[i_2 + 1][j_2] = dungeon[i][j]; - L5dungeon[i_2 + 1][j_2 + 1] = dungeon[i][j]; + int i2 = i * 2; + int j2 = j * 2; + L5dungeon[i2][j2] = dungeon[i][j]; + L5dungeon[i2][j2 + 1] = dungeon[i][j]; + L5dungeon[i2 + 1][j2] = dungeon[i][j]; + L5dungeon[i2 + 1][j2 + 1] = dungeon[i][j]; } } } diff --git a/Source/dthread.cpp b/Source/dthread.cpp index 998ccd3af..6d4393d83 100644 --- a/Source/dthread.cpp +++ b/Source/dthread.cpp @@ -21,14 +21,14 @@ static SDL_Thread *sghThread = nullptr; static unsigned int DthreadHandler(void * /*data*/) { - const char *error_buf; + const char *errorBuf; TMegaPkt *pkt; DWORD dwMilliseconds; while (dthread_running) { if (sgpInfoHead == nullptr && WaitForEvent(sghWorkToDoEvent) == -1) { - error_buf = SDL_GetError(); - app_fatal("dthread4:\n%s", error_buf); + errorBuf = SDL_GetError(); + app_fatal("dthread4:\n%s", errorBuf); } sgMemCrit.Enter(); @@ -97,7 +97,7 @@ void dthread_send_delta(int pnum, _cmd_id cmd, byte *pbSrc, int dwLen) void dthread_start() { - const char *error_buf; + const char *errorBuf; if (!gbIsMultiplayer) { return; @@ -105,16 +105,16 @@ void dthread_start() sghWorkToDoEvent = StartEvent(); if (sghWorkToDoEvent == nullptr) { - error_buf = SDL_GetError(); - app_fatal("dthread:1\n%s", error_buf); + errorBuf = SDL_GetError(); + app_fatal("dthread:1\n%s", errorBuf); } dthread_running = true; sghThread = CreateThread(DthreadHandler, &glpDThreadId); if (sghThread == nullptr) { - error_buf = SDL_GetError(); - app_fatal("dthread2:\n%s", error_buf); + errorBuf = SDL_GetError(); + app_fatal("dthread2:\n%s", errorBuf); } } diff --git a/Source/engine/random.hpp b/Source/engine/random.hpp index 73a219673..95e683448 100644 --- a/Source/engine/random.hpp +++ b/Source/engine/random.hpp @@ -9,8 +9,7 @@ #include -namespace devilution -{ +namespace devilution { /** * @brief Set the state of the RandomNumberEngine used by the base game to the specific seed diff --git a/Source/engine/surface.hpp b/Source/engine/surface.hpp index 40ba4149f..9f1b2ff1f 100644 --- a/Source/engine/surface.hpp +++ b/Source/engine/surface.hpp @@ -44,7 +44,7 @@ struct Surface { } Surface(const Surface &other) = default; - Surface& operator=(const Surface &other) = default; + Surface &operator=(const Surface &other) = default; /** * @brief Allocate a buffer that owns its underlying data. @@ -132,8 +132,8 @@ struct Surface { Surface subregionY(int y, int h) const { SDL_Rect subregion = region; - subregion.y += static_cast(y); - subregion.h = static_cast(h); + subregion.y += static_cast(y); + subregion.h = static_cast(h); return Surface(surface, subregion); } diff --git a/Source/init.cpp b/Source/init.cpp index 9b8a15d11..23f067a4f 100644 --- a/Source/init.cpp +++ b/Source/init.cpp @@ -56,16 +56,16 @@ namespace { HANDLE LoadMPQ(const std::vector &paths, const char *mpqName) { HANDLE archive; - std::string mpq_abspath; + std::string mpqAbsPath; for (const auto &path : paths) { - mpq_abspath = path + mpqName; - if (SFileOpenArchive(mpq_abspath.c_str(), 0, MPQ_OPEN_READ_ONLY, &archive)) { + mpqAbsPath = path + mpqName; + if (SFileOpenArchive(mpqAbsPath.c_str(), 0, MPQ_OPEN_READ_ONLY, &archive)) { LogVerbose(" Found: {} in {}", mpqName, path); SFileSetBasePath(path.c_str()); return archive; } if (SErrGetLastError() != STORM_ERROR_FILE_NOT_FOUND) { - LogError("Open error {}: {}", SErrGetLastError(), mpq_abspath); + LogError("Open error {}: {}", SErrGetLastError(), mpqAbsPath); } } if (SErrGetLastError() == STORM_ERROR_FILE_NOT_FOUND) { @@ -80,7 +80,7 @@ HANDLE LoadMPQ(const std::vector &paths, const char *mpqName) void init_cleanup() { if (gbIsMultiplayer && gbRunGame) { - pfile_write_hero(/*write_game_data=*/false, /*clear_tables=*/true); + pfile_write_hero(/*writeGameData=*/false, /*clearTables=*/true); } if (spawn_mpq != nullptr) { @@ -242,11 +242,11 @@ void MainWndProc(uint32_t msg) WNDPROC SetWindowProc(WNDPROC newProc) { - WNDPROC OldProc; + WNDPROC oldProc; - OldProc = CurrentProc; + oldProc = CurrentProc; CurrentProc = newProc; - return OldProc; + return oldProc; } } // namespace devilution diff --git a/Source/interfac.cpp b/Source/interfac.cpp index 0ddd1de8c..1aa032b22 100644 --- a/Source/interfac.cpp +++ b/Source/interfac.cpp @@ -189,12 +189,12 @@ static void DrawCutscene() void interface_msg_pump() { - tagMSG Msg; + tagMSG msg; - while (FetchMessage(&Msg)) { - if (Msg.message != DVL_WM_QUIT) { - TranslateMessage(&Msg); - PushMessage(&Msg); + while (FetchMessage(&msg)) { + if (msg.message != DVL_WM_QUIT) { + TranslateMessage(&msg); + PushMessage(&msg); } } } diff --git a/Source/itemdat.h b/Source/itemdat.h index 36257f88b..d73d85a4c 100644 --- a/Source/itemdat.h +++ b/Source/itemdat.h @@ -497,10 +497,10 @@ enum item_effect_type : int8_t { IPL_THORNS, IPL_NOMANA, IPL_NOHEALPLR, // unused - IPL_0x30, // Unknown - IPL_0x31, // Unknown - IPL_FIREBALL, /* only used in hellfire */ - IPL_0x33, // Unknown + IPL_0x30, // Unknown + IPL_0x31, // Unknown + IPL_FIREBALL, /* only used in hellfire */ + IPL_0x33, // Unknown IPL_ABSHALFTRAP, IPL_KNOCKBACK, IPL_NOHEALMON, // unused diff --git a/Source/items.cpp b/Source/items.cpp index 83b90cc1a..4a19ade48 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -376,22 +376,22 @@ bool IsUniqueAvailable(int i) static bool IsPrefixValidForItemType(int i, int flgs) { - int PLIType = PL_Prefix[i].PLIType; + int itemTypes = PL_Prefix[i].PLIType; if (!gbIsHellfire) { if (i > 82) return false; if (i >= 12 && i <= 20) - PLIType &= ~PLT_STAFF; + itemTypes &= ~PLT_STAFF; } - return (flgs & PLIType) != 0; + return (flgs & itemTypes) != 0; } static bool IsSuffixValidForItemType(int i, int flgs) { - int PLIType = PL_Suffix[i].PLIType; + int itemTypes = PL_Suffix[i].PLIType; if (!gbIsHellfire) { if (i > 94) @@ -403,17 +403,15 @@ static bool IsSuffixValidForItemType(int i, int flgs) || (i >= 34 && i <= 36) || (i >= 41 && i <= 44) || (i >= 60 && i <= 63)) - PLIType &= ~PLT_STAFF; + itemTypes &= ~PLT_STAFF; } - return (flgs & PLIType) != 0; + return (flgs & itemTypes) != 0; } int items_get_currlevel() { - int lvl; - - lvl = currlevel; + int lvl = currlevel; if (currlevel >= 17 && currlevel <= 20) lvl = currlevel - 8; if (currlevel >= 21 && currlevel <= 24) @@ -2747,7 +2745,7 @@ void hex2bin(const char *src, int bytes, char *target) void CornerstoneLoad(Point position) { - PkItemStruct PkSItem; + PkItemStruct pkSItem; if (CornerStone.activated || position.x == 0 || position.y == 0) { return; @@ -2769,13 +2767,13 @@ void CornerstoneLoad(Point position) if (strlen(sgOptions.Hellfire.szItem) < sizeof(PkItemStruct) * 2) return; - hex2bin(sgOptions.Hellfire.szItem, sizeof(PkItemStruct), (char *)&PkSItem); + hex2bin(sgOptions.Hellfire.szItem, sizeof(PkItemStruct), (char *)&pkSItem); int ii = AllocateItem(); dItem[position.x][position.y] = ii + 1; - UnPackItem(&PkSItem, &items[ii], (PkSItem.dwBuff & CF_HELLFIRE) != 0); + UnPackItem(&pkSItem, &items[ii], (pkSItem.dwBuff & CF_HELLFIRE) != 0); items[ii].position = position; RespawnItem(&items[ii], false); CornerStone.item = items[ii]; diff --git a/Source/lighting.cpp b/Source/lighting.cpp index f8cc8b685..2260a2b83 100644 --- a/Source/lighting.cpp +++ b/Source/lighting.cpp @@ -495,10 +495,10 @@ void DoLighting(Point position, int nRadius, int lnum) { int xoff = 0; int yoff = 0; - int light_x = 0; - int light_y = 0; - int block_x = 0; - int block_y = 0; + int lightX = 0; + int lightY = 0; + int blockX = 0; + int blockY = 0; if (lnum >= 0) { xoff = LightList[lnum].position.offset.x; @@ -513,24 +513,24 @@ void DoLighting(Point position, int nRadius, int lnum) } } - int dist_x = xoff; - int dist_y = yoff; + int distX = xoff; + int distY = yoff; - int min_x = 15; + int minX = 15; if (position.x - 15 < 0) { - min_x = position.x + 1; + minX = position.x + 1; } - int max_x = 15; + int maxX = 15; if (position.x + 15 > MAXDUNX) { - max_x = MAXDUNX - position.x; + maxX = MAXDUNX - position.x; } - int min_y = 15; + int minY = 15; if (position.y - 15 < 0) { - min_y = position.y + 1; + minY = position.y + 1; } - int max_y = 15; + int maxY = 15; if (position.y + 15 > MAXDUNY) { - max_y = MAXDUNY - position.y; + maxY = MAXDUNY - position.y; } if (position.x >= 0 && position.x < MAXDUNX && position.y >= 0 && position.y < MAXDUNY) { @@ -542,61 +542,61 @@ void DoLighting(Point position, int nRadius, int lnum) } int mult = xoff + 8 * yoff; - for (int y = 0; y < min_y; y++) { - for (int x = 1; x < max_x; x++) { - int radius_block = lightblock[mult][y][x]; - if (radius_block < 128) { - int temp_x = position.x + x; - int temp_y = position.y + y; - int v = lightradius[nRadius][radius_block]; - if (temp_x >= 0 && temp_x < MAXDUNX && temp_y >= 0 && temp_y < MAXDUNY) - if (v < GetLight(temp_x, temp_y)) - SetLight(temp_x, temp_y, v); + for (int y = 0; y < minY; y++) { + for (int x = 1; x < maxX; x++) { + int radiusBlock = lightblock[mult][y][x]; + if (radiusBlock < 128) { + int tempX = position.x + x; + int tempY = position.y + y; + int v = lightradius[nRadius][radiusBlock]; + if (tempX >= 0 && tempX < MAXDUNX && tempY >= 0 && tempY < MAXDUNY) + if (v < GetLight(tempX, tempY)) + SetLight(tempX, tempY, v); } } } - RotateRadius(&xoff, &yoff, &dist_x, &dist_y, &light_x, &light_y, &block_x, &block_y); + RotateRadius(&xoff, &yoff, &distX, &distY, &lightX, &lightY, &blockX, &blockY); mult = xoff + 8 * yoff; - for (int y = 0; y < max_y; y++) { - for (int x = 1; x < max_x; x++) { - int radius_block = lightblock[mult][y + block_y][x + block_x]; - if (radius_block < 128) { - int temp_x = position.x + y; - int temp_y = position.y - x; - int v = lightradius[nRadius][radius_block]; - if (temp_x >= 0 && temp_x < MAXDUNX && temp_y >= 0 && temp_y < MAXDUNY) - if (v < GetLight(temp_x, temp_y)) - SetLight(temp_x, temp_y, v); + for (int y = 0; y < maxY; y++) { + for (int x = 1; x < maxX; x++) { + int radiusBlock = lightblock[mult][y + blockY][x + blockX]; + if (radiusBlock < 128) { + int tempX = position.x + y; + int tempY = position.y - x; + int v = lightradius[nRadius][radiusBlock]; + if (tempX >= 0 && tempX < MAXDUNX && tempY >= 0 && tempY < MAXDUNY) + if (v < GetLight(tempX, tempY)) + SetLight(tempX, tempY, v); } } } - RotateRadius(&xoff, &yoff, &dist_x, &dist_y, &light_x, &light_y, &block_x, &block_y); + RotateRadius(&xoff, &yoff, &distX, &distY, &lightX, &lightY, &blockX, &blockY); mult = xoff + 8 * yoff; - for (int y = 0; y < max_y; y++) { - for (int x = 1; x < min_x; x++) { - int radius_block = lightblock[mult][y + block_y][x + block_x]; - if (radius_block < 128) { - int temp_x = position.x - x; - int temp_y = position.y - y; - int v = lightradius[nRadius][radius_block]; - if (temp_x >= 0 && temp_x < MAXDUNX && temp_y >= 0 && temp_y < MAXDUNY) - if (v < GetLight(temp_x, temp_y)) - SetLight(temp_x, temp_y, v); + for (int y = 0; y < maxY; y++) { + for (int x = 1; x < minX; x++) { + int radiusBlock = lightblock[mult][y + blockY][x + blockX]; + if (radiusBlock < 128) { + int tempX = position.x - x; + int tempY = position.y - y; + int v = lightradius[nRadius][radiusBlock]; + if (tempX >= 0 && tempX < MAXDUNX && tempY >= 0 && tempY < MAXDUNY) + if (v < GetLight(tempX, tempY)) + SetLight(tempX, tempY, v); } } } - RotateRadius(&xoff, &yoff, &dist_x, &dist_y, &light_x, &light_y, &block_x, &block_y); + RotateRadius(&xoff, &yoff, &distX, &distY, &lightX, &lightY, &blockX, &blockY); mult = xoff + 8 * yoff; - for (int y = 0; y < min_y; y++) { - for (int x = 1; x < min_x; x++) { - int radius_block = lightblock[mult][y + block_y][x + block_x]; - if (radius_block < 128) { - int temp_x = position.x - y; - int temp_y = position.y + x; - int v = lightradius[nRadius][radius_block]; - if (temp_x >= 0 && temp_x < MAXDUNX && temp_y >= 0 && temp_y < MAXDUNY) - if (v < GetLight(temp_x, temp_y)) - SetLight(temp_x, temp_y, v); + for (int y = 0; y < minY; y++) { + for (int x = 1; x < minX; x++) { + int radiusBlock = lightblock[mult][y + blockY][x + blockX]; + if (radiusBlock < 128) { + int tempX = position.x - y; + int tempY = position.y + x; + int v = lightradius[nRadius][radiusBlock]; + if (tempX >= 0 && tempX < MAXDUNX && tempY >= 0 && tempY < MAXDUNY) + if (v < GetLight(tempX, tempY)) + SetLight(tempX, tempY, v); } } } @@ -606,18 +606,18 @@ void DoUnLight(int nXPos, int nYPos, int nRadius) { nRadius++; - int min_x = nXPos - nRadius; - int max_x = nXPos + nRadius; - int min_y = nYPos - nRadius; - int max_y = nYPos + nRadius; + int minX = nXPos - nRadius; + int maxX = nXPos + nRadius; + int minY = nYPos - nRadius; + int maxY = nYPos + nRadius; - min_x = std::max(min_x, 0); - max_x = std::max(max_x, MAXDUNX); - min_y = std::max(min_y, 0); - max_y = std::max(max_y, MAXDUNY); + minX = std::max(minX, 0); + maxX = std::max(maxX, MAXDUNX); + minY = std::max(minY, 0); + maxY = std::max(maxY, MAXDUNY); - for (int y = min_y; y < max_y; y++) { - for (int x = min_x; x < max_x; x++) { + for (int y = minY; y < maxY; y++) { + for (int x = minX; x < maxX; x++) { if (x >= 0 && x < MAXDUNX && y >= 0 && y < MAXDUNY) dLight[x][y] = dPreLight[x][y]; } diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index 74d5b9edc..2d25f7d52 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -187,10 +187,10 @@ public: ~SaveHelper() { - const auto encoded_len = codec_get_encoded_len(m_cur_); + const auto encodedLen = codec_get_encoded_len(m_cur_); const char *const password = pfile_get_password(); - codec_encode(m_buffer_.get(), m_cur_, encoded_len, password); - mpqapi_write_file(m_szFileName_, m_buffer_.get(), encoded_len); + codec_encode(m_buffer_.get(), m_cur_, encodedLen, password); + mpqapi_write_file(m_szFileName_, m_buffer_.get(), encodedLen); } }; @@ -361,7 +361,7 @@ static void LoadPlayer(LoadHelper *file, int p) file->Skip(2); // Alignment player._pTSpell = static_cast(file->NextLE()); file->Skip(sizeof(int8_t)); // Skip _pTSplType - file->Skip(3); // Alignment + file->Skip(3); // Alignment player._pRSpell = static_cast(file->NextLE()); player._pRSplType = static_cast(file->NextLE()); file->Skip(3); // Alignment @@ -1189,8 +1189,8 @@ void LoadGame(bool firstflag) itemId = file.NextLE(); for (int i = 0; i < numitems; i++) LoadItem(&file, itemactive[i]); - for (bool &UniqueItemFlag : UniqueItemFlags) - UniqueItemFlag = file.NextBool8(); + for (bool &uniqueItemFlag : UniqueItemFlags) + uniqueItemFlag = file.NextBool8(); for (int j = 0; j < MAXDUNY; j++) { for (int i = 0; i < MAXDUNX; i++) // NOLINT(modernize-loop-convert) @@ -1427,7 +1427,7 @@ static void SavePlayer(SaveHelper *file, int p) file->Skip(2); // Alignment file->WriteLE(player._pTSpell); file->Skip(sizeof(int8_t)); // Skip _pTSplType - file->Skip(3); // Alignment + file->Skip(3); // Alignment file->WriteLE(player._pRSpell); file->WriteLE(player._pRSplType); file->Skip(3); // Alignment @@ -1955,8 +1955,8 @@ void SaveGameData() file.WriteLE(itemId); for (int i = 0; i < numitems; i++) SaveItem(&file, &items[itemactive[i]]); - for (bool UniqueItemFlag : UniqueItemFlags) - file.WriteLE(UniqueItemFlag ? 1 : 0); + for (bool uniqueItemFlag : UniqueItemFlags) + file.WriteLE(uniqueItemFlag ? 1 : 0); for (int j = 0; j < MAXDUNY; j++) { for (int i = 0; i < MAXDUNX; i++) // NOLINT(modernize-loop-convert) @@ -2019,12 +2019,12 @@ void SaveGameData() void SaveGame() { gbValidSaveFile = true; - pfile_write_hero(/*write_game_data=*/true); + pfile_write_hero(/*writeGameData=*/true); } void SaveLevel() { - PFileScopedArchiveWriter scoped_writer; + PFileScopedArchiveWriter scopedWriter; DoUnVision(plr[myplr].position.tile, plr[myplr]._pLightRad); // fix for vision staying on the level @@ -2185,7 +2185,7 @@ void LoadLevel() } for (int j = 0; j < MAXDUNY; j++) { for (int i = 0; i < MAXDUNX; i++) // NOLINT(modernize-loop-convert) - dMissile[i][j] = 0; /// BUGFIX: supposed to load saved missiles with "file.NextLE()"? + dMissile[i][j] = 0; /// BUGFIX: supposed to load saved missiles with "file.NextLE()"? } } diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 5c2e2b86c..3194abaa0 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -1683,21 +1683,21 @@ void AddMana(int mi, Point /*src*/, Point /*dst*/, int /*midir*/, int8_t /*miene { auto &player = plr[id]; - int ManaAmount = (GenerateRnd(10) + 1) << 6; + int manaAmount = (GenerateRnd(10) + 1) << 6; for (int i = 0; i < player._pLevel; i++) { - ManaAmount += (GenerateRnd(4) + 1) << 6; + manaAmount += (GenerateRnd(4) + 1) << 6; } for (int i = 0; i < missile[mi]._mispllvl; i++) { - ManaAmount += (GenerateRnd(6) + 1) << 6; + manaAmount += (GenerateRnd(6) + 1) << 6; } if (player._pClass == HeroClass::Sorcerer) - ManaAmount *= 2; + manaAmount *= 2; if (player._pClass == HeroClass::Rogue || player._pClass == HeroClass::Bard) - ManaAmount += ManaAmount / 2; - player._pMana += ManaAmount; + manaAmount += manaAmount / 2; + player._pMana += manaAmount; if (player._pMana > player._pMaxMana) player._pMana = player._pMaxMana; - player._pManaBase += ManaAmount; + player._pManaBase += manaAmount; if (player._pManaBase > player._pMaxManaBase) player._pManaBase = player._pMaxManaBase; UseMana(id, SPL_MANA); @@ -4154,7 +4154,7 @@ void MI_Blood(int i) void MI_Weapexp(int i) { - int ExpLight[10] = { 9, 10, 11, 12, 11, 10, 8, 6, 4, 2 }; + constexpr int ExpLight[10] = { 9, 10, 11, 12, 11, 10, 8, 6, 4, 2 }; missile[i]._mirange--; int id = missile[i]._misource; diff --git a/Source/missiles.h b/Source/missiles.h index dfa2b357b..fb77e9eba 100644 --- a/Source/missiles.h +++ b/Source/missiles.h @@ -35,7 +35,6 @@ struct MissilePosition { Displacement traveled; }; - /* * W sW SW Sw S * ^ @@ -47,8 +46,7 @@ struct MissilePosition { * | * N Ne NE nE E */ -enum Direction16 -{ +enum Direction16 { DIR16_S, DIR16_Sw, DIR16_SW, diff --git a/Source/monster.cpp b/Source/monster.cpp index be954bf20..e35fafa57 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -611,27 +611,24 @@ void InitMonster(int i, Direction rd, int mtype, Point position) void ClrAllMonsters() { - int i; - MonsterStruct *Monst; - - for (i = 0; i < MAXMONSTERS; i++) { - Monst = &monster[i]; + for (int i = 0; i < MAXMONSTERS; i++) { + MonsterStruct *monst = &monster[i]; ClearMVars(i); - Monst->mName = "Invalid Monster"; - Monst->_mgoal = MGOAL_NONE; - Monst->_mmode = MM_STAND; - Monst->_mVar1 = 0; - Monst->_mVar2 = 0; - Monst->position.tile = { 0, 0 }; - Monst->position.future = { 0, 0 }; - Monst->position.old = { 0, 0 }; - Monst->_mdir = static_cast(GenerateRnd(8)); - Monst->position.velocity = { 0, 0 }; - Monst->AnimInfo = {}; - Monst->_mFlags = 0; - Monst->_mDelFlag = false; - Monst->_menemy = GenerateRnd(gbActivePlayers); - Monst->enemyPosition = plr[Monst->_menemy].position.future; + monst->mName = "Invalid Monster"; + monst->_mgoal = MGOAL_NONE; + monst->_mmode = MM_STAND; + monst->_mVar1 = 0; + monst->_mVar2 = 0; + monst->position.tile = { 0, 0 }; + monst->position.future = { 0, 0 }; + monst->position.old = { 0, 0 }; + monst->_mdir = static_cast(GenerateRnd(8)); + monst->position.velocity = { 0, 0 }; + monst->AnimInfo = {}; + monst->_mFlags = 0; + monst->_mDelFlag = false; + monst->_menemy = GenerateRnd(gbActivePlayers); + monst->enemyPosition = plr[monst->_menemy].position.future; } } @@ -696,8 +693,8 @@ void PlaceMonster(int i, int mtype, int x, int y) void PlaceUniqueMonst(int uniqindex, int miniontype, int bosspacksize) { - MonsterStruct *Monst = &monster[nummonsters]; - const UniqMonstStruct *Uniq = &UniqMonst[uniqindex]; + MonsterStruct *monst = &monster[nummonsters]; + const UniqMonstStruct *uniq = &UniqMonst[uniqindex]; if ((uniquetrans + 19) * 256 >= LIGHTSIZE) { return; @@ -804,118 +801,118 @@ void PlaceUniqueMonst(int uniqindex, int miniontype, int bosspacksize) UberDiabloMonsterIndex = nummonsters; } PlaceMonster(nummonsters, uniqtype, xp, yp); - Monst->_uniqtype = uniqindex + 1; + monst->_uniqtype = uniqindex + 1; - if (Uniq->mlevel != 0) { - Monst->mLevel = 2 * Uniq->mlevel; + if (uniq->mlevel != 0) { + monst->mLevel = 2 * uniq->mlevel; } else { - Monst->mLevel += 5; + monst->mLevel += 5; } - Monst->mExp *= 2; - Monst->mName = _(Uniq->mName); - Monst->_mmaxhp = Uniq->mmaxhp << 6; + monst->mExp *= 2; + monst->mName = _(uniq->mName); + monst->_mmaxhp = uniq->mmaxhp << 6; if (!gbIsMultiplayer) { - Monst->_mmaxhp = Monst->_mmaxhp / 2; - if (Monst->_mmaxhp < 64) { - Monst->_mmaxhp = 64; + monst->_mmaxhp = monst->_mmaxhp / 2; + if (monst->_mmaxhp < 64) { + monst->_mmaxhp = 64; } } - Monst->_mhitpoints = Monst->_mmaxhp; - Monst->_mAi = Uniq->mAi; - Monst->_mint = Uniq->mint; - Monst->mMinDamage = Uniq->mMinDamage; - Monst->mMaxDamage = Uniq->mMaxDamage; - Monst->mMinDamage2 = Uniq->mMinDamage; - Monst->mMaxDamage2 = Uniq->mMaxDamage; - Monst->mMagicRes = Uniq->mMagicRes; - Monst->mtalkmsg = Uniq->mtalkmsg; + monst->_mhitpoints = monst->_mmaxhp; + monst->_mAi = uniq->mAi; + monst->_mint = uniq->mint; + monst->mMinDamage = uniq->mMinDamage; + monst->mMaxDamage = uniq->mMaxDamage; + monst->mMinDamage2 = uniq->mMinDamage; + monst->mMaxDamage2 = uniq->mMaxDamage; + monst->mMagicRes = uniq->mMagicRes; + monst->mtalkmsg = uniq->mtalkmsg; if (uniqindex == UMT_HORKDMN) - Monst->mlid = NO_LIGHT; // BUGFIX monsters initial light id should be -1 (fixed) + monst->mlid = NO_LIGHT; // BUGFIX monsters initial light id should be -1 (fixed) else - Monst->mlid = AddLight(Monst->position.tile, 3); + monst->mlid = AddLight(monst->position.tile, 3); if (gbIsMultiplayer) { - if (Monst->_mAi == AI_LAZHELP) - Monst->mtalkmsg = TEXT_NONE; - if (Monst->_mAi == AI_LAZURUS && quests[Q_BETRAYER]._qvar1 > 3) { - Monst->_mgoal = MGOAL_NORMAL; - } else if (Monst->mtalkmsg != TEXT_NONE) { - Monst->_mgoal = MGOAL_INQUIRING; + if (monst->_mAi == AI_LAZHELP) + monst->mtalkmsg = TEXT_NONE; + if (monst->_mAi == AI_LAZURUS && quests[Q_BETRAYER]._qvar1 > 3) { + monst->_mgoal = MGOAL_NORMAL; + } else if (monst->mtalkmsg != TEXT_NONE) { + monst->_mgoal = MGOAL_INQUIRING; } - } else if (Monst->mtalkmsg != TEXT_NONE) { - Monst->_mgoal = MGOAL_INQUIRING; + } else if (monst->mtalkmsg != TEXT_NONE) { + monst->_mgoal = MGOAL_INQUIRING; } if (sgGameInitInfo.nDifficulty == DIFF_NIGHTMARE) { - Monst->_mmaxhp = 3 * Monst->_mmaxhp; + monst->_mmaxhp = 3 * monst->_mmaxhp; if (gbIsHellfire) - Monst->_mmaxhp += (gbIsMultiplayer ? 100 : 50) << 6; + monst->_mmaxhp += (gbIsMultiplayer ? 100 : 50) << 6; else - Monst->_mmaxhp += 64; - Monst->mLevel += 15; - Monst->_mhitpoints = Monst->_mmaxhp; - Monst->mExp = 2 * (Monst->mExp + 1000); - Monst->mMinDamage = 2 * (Monst->mMinDamage + 2); - Monst->mMaxDamage = 2 * (Monst->mMaxDamage + 2); - Monst->mMinDamage2 = 2 * (Monst->mMinDamage2 + 2); - Monst->mMaxDamage2 = 2 * (Monst->mMaxDamage2 + 2); + monst->_mmaxhp += 64; + monst->mLevel += 15; + monst->_mhitpoints = monst->_mmaxhp; + monst->mExp = 2 * (monst->mExp + 1000); + monst->mMinDamage = 2 * (monst->mMinDamage + 2); + monst->mMaxDamage = 2 * (monst->mMaxDamage + 2); + monst->mMinDamage2 = 2 * (monst->mMinDamage2 + 2); + monst->mMaxDamage2 = 2 * (monst->mMaxDamage2 + 2); } else if (sgGameInitInfo.nDifficulty == DIFF_HELL) { - Monst->_mmaxhp = 4 * Monst->_mmaxhp; + monst->_mmaxhp = 4 * monst->_mmaxhp; if (gbIsHellfire) - Monst->_mmaxhp += (gbIsMultiplayer ? 200 : 100) << 6; + monst->_mmaxhp += (gbIsMultiplayer ? 200 : 100) << 6; else - Monst->_mmaxhp += 192; - Monst->mLevel += 30; - Monst->_mhitpoints = Monst->_mmaxhp; - Monst->mExp = 4 * (Monst->mExp + 1000); - Monst->mMinDamage = 4 * Monst->mMinDamage + 6; - Monst->mMaxDamage = 4 * Monst->mMaxDamage + 6; - Monst->mMinDamage2 = 4 * Monst->mMinDamage2 + 6; - Monst->mMaxDamage2 = 4 * Monst->mMaxDamage2 + 6; + monst->_mmaxhp += 192; + monst->mLevel += 30; + monst->_mhitpoints = monst->_mmaxhp; + monst->mExp = 4 * (monst->mExp + 1000); + monst->mMinDamage = 4 * monst->mMinDamage + 6; + monst->mMaxDamage = 4 * monst->mMaxDamage + 6; + monst->mMinDamage2 = 4 * monst->mMinDamage2 + 6; + monst->mMaxDamage2 = 4 * monst->mMaxDamage2 + 6; } char filestr[64]; - sprintf(filestr, "Monsters\\Monsters\\%s.TRN", Uniq->mTrnName); + sprintf(filestr, "Monsters\\Monsters\\%s.TRN", uniq->mTrnName); LoadFileInMem(filestr, &pLightTbl[256 * (uniquetrans + 19)], 256); - Monst->_uniqtrans = uniquetrans++; + monst->_uniqtrans = uniquetrans++; - if ((Uniq->mUnqAttr & 4) != 0) { - Monst->mHit = Uniq->mUnqVar1; - Monst->mHit2 = Uniq->mUnqVar1; + if ((uniq->mUnqAttr & 4) != 0) { + monst->mHit = uniq->mUnqVar1; + monst->mHit2 = uniq->mUnqVar1; if (sgGameInitInfo.nDifficulty == DIFF_NIGHTMARE) { - Monst->mHit += NIGHTMARE_TO_HIT_BONUS; - Monst->mHit2 += NIGHTMARE_TO_HIT_BONUS; + monst->mHit += NIGHTMARE_TO_HIT_BONUS; + monst->mHit2 += NIGHTMARE_TO_HIT_BONUS; } else if (sgGameInitInfo.nDifficulty == DIFF_HELL) { - Monst->mHit += HELL_TO_HIT_BONUS; - Monst->mHit2 += HELL_TO_HIT_BONUS; + monst->mHit += HELL_TO_HIT_BONUS; + monst->mHit2 += HELL_TO_HIT_BONUS; } } - if ((Uniq->mUnqAttr & 8) != 0) { - Monst->mArmorClass = Uniq->mUnqVar1; + if ((uniq->mUnqAttr & 8) != 0) { + monst->mArmorClass = uniq->mUnqVar1; if (sgGameInitInfo.nDifficulty == DIFF_NIGHTMARE) { - Monst->mArmorClass += NIGHTMARE_AC_BONUS; + monst->mArmorClass += NIGHTMARE_AC_BONUS; } else if (sgGameInitInfo.nDifficulty == DIFF_HELL) { - Monst->mArmorClass += HELL_AC_BONUS; + monst->mArmorClass += HELL_AC_BONUS; } } nummonsters++; - if ((Uniq->mUnqAttr & 1) != 0) { - PlaceGroup(miniontype, bosspacksize, Uniq->mUnqAttr, nummonsters - 1); + if ((uniq->mUnqAttr & 1) != 0) { + PlaceGroup(miniontype, bosspacksize, uniq->mUnqAttr, nummonsters - 1); } - if (Monst->_mAi != AI_GARG) { - Monst->AnimInfo.pCelSprite = &*Monst->MType->Anims[MA_STAND].CelSpritesForDirections[Monst->_mdir]; - Monst->AnimInfo.CurrentFrame = GenerateRnd(Monst->AnimInfo.NumberOfFrames - 1) + 1; - Monst->_mFlags &= ~MFLAG_ALLOW_SPECIAL; - Monst->_mmode = MM_STAND; + if (monst->_mAi != AI_GARG) { + monst->AnimInfo.pCelSprite = &*monst->MType->Anims[MA_STAND].CelSpritesForDirections[monst->_mdir]; + monst->AnimInfo.CurrentFrame = GenerateRnd(monst->AnimInfo.NumberOfFrames - 1) + 1; + monst->_mFlags &= ~MFLAG_ALLOW_SPECIAL; + monst->_mmode = MM_STAND; } } @@ -1286,11 +1283,11 @@ void AddDoppelganger(MonsterStruct &monster) void NewMonsterAnim(int i, AnimStruct *anim, Direction md, AnimationDistributionFlags flags = AnimationDistributionFlags::None, int numSkippedFrames = 0, int distributeFramesBeforeFrame = 0) { - MonsterStruct *Monst = &monster[i]; + MonsterStruct *monst = &monster[i]; auto *pCelSprite = &*anim->CelSpritesForDirections[md]; - Monst->AnimInfo.SetNewAnimation(pCelSprite, anim->Frames, anim->Rate, flags, numSkippedFrames, distributeFramesBeforeFrame); - Monst->_mFlags &= ~(MFLAG_LOCK_ANIMATION | MFLAG_ALLOW_SPECIAL); - Monst->_mdir = md; + monst->AnimInfo.SetNewAnimation(pCelSprite, anim->Frames, anim->Rate, flags, numSkippedFrames, distributeFramesBeforeFrame); + monst->_mFlags &= ~(MFLAG_LOCK_ANIMATION | MFLAG_ALLOW_SPECIAL); + monst->_mdir = md; } bool M_Ranged(int i) @@ -1309,24 +1306,24 @@ void M_Enemy(int i) BYTE enemyy; int menemy = -1; - int best_dist = -1; + int bestDist = -1; bool bestsameroom = false; - MonsterStruct *Monst = &monster[i]; - if ((Monst->_mFlags & MFLAG_BERSERK) != 0 || (Monst->_mFlags & MFLAG_GOLEM) == 0) { + MonsterStruct *monst = &monster[i]; + if ((monst->_mFlags & MFLAG_BERSERK) != 0 || (monst->_mFlags & MFLAG_GOLEM) == 0) { for (int pnum = 0; pnum < MAX_PLRS; pnum++) { if (!plr[pnum].plractive || currlevel != plr[pnum].plrlevel || plr[pnum]._pLvlChanging || (((plr[pnum]._pHitPoints >> 6) == 0) && gbIsMultiplayer)) continue; - bool sameroom = (dTransVal[Monst->position.tile.x][Monst->position.tile.y] == dTransVal[plr[pnum].position.tile.x][plr[pnum].position.tile.y]); - int dist = Monst->position.tile.WalkingDistance(plr[pnum].position.tile); + bool sameroom = (dTransVal[monst->position.tile.x][monst->position.tile.y] == dTransVal[plr[pnum].position.tile.x][plr[pnum].position.tile.y]); + int dist = monst->position.tile.WalkingDistance(plr[pnum].position.tile); if ((sameroom && !bestsameroom) - || ((sameroom || !bestsameroom) && dist < best_dist) + || ((sameroom || !bestsameroom) && dist < bestDist) || (menemy == -1)) { - Monst->_mFlags &= ~MFLAG_TARGETS_MONSTER; + monst->_mFlags &= ~MFLAG_TARGETS_MONSTER; menemy = pnum; enemyx = plr[pnum].position.future.x; enemyy = plr[pnum].position.future.y; - best_dist = dist; + bestDist = dist; bestsameroom = sameroom; } } @@ -1341,37 +1338,37 @@ void M_Enemy(int i) continue; if (M_Talker(mi) && monster[mi].mtalkmsg != TEXT_NONE) continue; - if ((Monst->_mFlags & MFLAG_GOLEM) != 0 && (monster[mi]._mFlags & MFLAG_GOLEM) != 0) // prevent golems from fighting each other + if ((monst->_mFlags & MFLAG_GOLEM) != 0 && (monster[mi]._mFlags & MFLAG_GOLEM) != 0) // prevent golems from fighting each other continue; - int dist = monster[mi].position.tile.WalkingDistance(Monst->position.tile); - if (((Monst->_mFlags & MFLAG_GOLEM) == 0 - && (Monst->_mFlags & MFLAG_BERSERK) == 0 + int dist = monster[mi].position.tile.WalkingDistance(monst->position.tile); + if (((monst->_mFlags & MFLAG_GOLEM) == 0 + && (monst->_mFlags & MFLAG_BERSERK) == 0 && dist >= 2 && !M_Ranged(i)) - || ((Monst->_mFlags & MFLAG_GOLEM) == 0 - && (Monst->_mFlags & MFLAG_BERSERK) == 0 + || ((monst->_mFlags & MFLAG_GOLEM) == 0 + && (monst->_mFlags & MFLAG_BERSERK) == 0 && (monster[mi]._mFlags & MFLAG_GOLEM) == 0)) { continue; } - bool sameroom = dTransVal[Monst->position.tile.x][Monst->position.tile.y] == dTransVal[monster[mi].position.tile.x][monster[mi].position.tile.y]; + bool sameroom = dTransVal[monst->position.tile.x][monst->position.tile.y] == dTransVal[monster[mi].position.tile.x][monster[mi].position.tile.y]; if ((sameroom && !bestsameroom) - || ((sameroom || !bestsameroom) && dist < best_dist) + || ((sameroom || !bestsameroom) && dist < bestDist) || (menemy == -1)) { - Monst->_mFlags |= MFLAG_TARGETS_MONSTER; + monst->_mFlags |= MFLAG_TARGETS_MONSTER; menemy = mi; enemyx = monster[mi].position.future.x; enemyy = monster[mi].position.future.y; - best_dist = dist; + bestDist = dist; bestsameroom = sameroom; } } if (menemy != -1) { - Monst->_mFlags &= ~MFLAG_NO_ENEMY; - Monst->_menemy = menemy; - Monst->enemyPosition = { enemyx, enemyy }; + monst->_mFlags &= ~MFLAG_NO_ENEMY; + monst->_menemy = menemy; + monst->enemyPosition = { enemyx, enemyy }; } else { - Monst->_mFlags |= MFLAG_NO_ENEMY; + monst->_mFlags |= MFLAG_NO_ENEMY; } } @@ -1626,7 +1623,7 @@ void M_StartHit(int i, int pnum, int dam) void M_DiabloDeath(int i, bool sendmsg) { - MonsterStruct *Monst = &monster[i]; + MonsterStruct *monst = &monster[i]; PlaySFX(USFX_DIABLOD); quests[Q_DIABLO]._qactive = QUEST_DONE; if (sendmsg) @@ -1635,7 +1632,7 @@ void M_DiabloDeath(int i, bool sendmsg) gbProcessPlayers = false; for (int j = 0; j < nummonsters; j++) { int k = monstactive[j]; - if (k == i || Monst->_msquelch == 0) + if (k == i || monst->_msquelch == 0) continue; NewMonsterAnim(k, &monster[k].MType->Anims[MA_DEATH], monster[k]._mdir); @@ -1647,35 +1644,35 @@ void M_DiabloDeath(int i, bool sendmsg) M_ClearSquares(k); dMonster[monster[k].position.tile.x][monster[k].position.tile.y] = k + 1; } - AddLight(Monst->position.tile, 8); - DoVision(Monst->position.tile, 8, false, true); - int dist = Monst->position.tile.WalkingDistance({ ViewX, ViewY }); + AddLight(monst->position.tile, 8); + DoVision(monst->position.tile, 8, false, true); + int dist = monst->position.tile.WalkingDistance({ ViewX, ViewY }); if (dist > 20) dist = 20; - Monst->_mVar3 = ViewX << 16; - Monst->position.temp.x = ViewY << 16; - Monst->position.temp.y = (int)((Monst->_mVar3 - (Monst->position.tile.x << 16)) / (double)dist); - Monst->position.offset2.deltaX = (int)((Monst->position.temp.x - (Monst->position.tile.y << 16)) / (double)dist); + monst->_mVar3 = ViewX << 16; + monst->position.temp.x = ViewY << 16; + monst->position.temp.y = (int)((monst->_mVar3 - (monst->position.tile.x << 16)) / (double)dist); + monst->position.offset2.deltaX = (int)((monst->position.temp.x - (monst->position.tile.y << 16)) / (double)dist); } void SpawnLoot(int i, bool sendmsg) { - MonsterStruct *Monst = &monster[i]; - if (QuestStatus(Q_GARBUD) && Monst->_uniqtype - 1 == UMT_GARBUD) { - CreateTypeItem(Monst->position.tile + Displacement { 1, 1 }, true, ITYPE_MACE, IMISC_NONE, true, false); - } else if (Monst->_uniqtype - 1 == UMT_DEFILER) { + MonsterStruct *monst = &monster[i]; + if (QuestStatus(Q_GARBUD) && monst->_uniqtype - 1 == UMT_GARBUD) { + CreateTypeItem(monst->position.tile + Displacement { 1, 1 }, true, ITYPE_MACE, IMISC_NONE, true, false); + } else if (monst->_uniqtype - 1 == UMT_DEFILER) { if (effect_is_playing(USFX_DEFILER8)) stream_stop(); quests[Q_DEFILER]._qlog = false; - SpawnMapOfDoom(Monst->position.tile); - } else if (Monst->_uniqtype - 1 == UMT_HORKDMN) { + SpawnMapOfDoom(monst->position.tile); + } else if (monst->_uniqtype - 1 == UMT_HORKDMN) { if (sgGameInitInfo.bTheoQuest != 0) { - SpawnTheodore(Monst->position.tile); + SpawnTheodore(monst->position.tile); } else { - CreateAmulet(Monst->position.tile, 13, false, true); + CreateAmulet(monst->position.tile, 13, false, true); } - } else if (Monst->MType->mtype == MT_HORKSPWN) { - } else if (Monst->MType->mtype == MT_NAKRUL) { + } else if (monst->MType->mtype == MT_HORKSPWN) { + } else if (monst->MType->mtype == MT_NAKRUL) { int nSFX = IsUberRoomOpened ? USFX_NAKRUL4 : USFX_NAKRUL5; if (sgGameInitInfo.bCowQuest != 0) nSFX = USFX_NAKRUL6; @@ -1683,12 +1680,12 @@ void SpawnLoot(int i, bool sendmsg) stream_stop(); quests[Q_NAKRUL]._qlog = false; UberDiabloMonsterIndex = -2; - CreateMagicWeapon(Monst->position.tile, ITYPE_SWORD, ICURS_GREAT_SWORD, false, true); - CreateMagicWeapon(Monst->position.tile, ITYPE_STAFF, ICURS_WAR_STAFF, false, true); - CreateMagicWeapon(Monst->position.tile, ITYPE_BOW, ICURS_LONG_WAR_BOW, false, true); - CreateSpellBook(Monst->position.tile, SPL_APOCA, false, true); + CreateMagicWeapon(monst->position.tile, ITYPE_SWORD, ICURS_GREAT_SWORD, false, true); + CreateMagicWeapon(monst->position.tile, ITYPE_STAFF, ICURS_WAR_STAFF, false, true); + CreateMagicWeapon(monst->position.tile, ITYPE_BOW, ICURS_LONG_WAR_BOW, false, true); + CreateSpellBook(monst->position.tile, SPL_APOCA, false, true); } else if (i > MAX_PLRS - 1) { // Golems should not spawn loot - SpawnItem(i, Monst->position.tile, sendmsg); + SpawnItem(i, monst->position.tile, sendmsg); } } @@ -1736,37 +1733,37 @@ void MonstStartKill(int i, int pnum, bool sendmsg) { assurance((DWORD)i < MAXMONSTERS, i); - MonsterStruct *Monst = &monster[i]; - assurance(Monst->MType != nullptr, i); + MonsterStruct *monst = &monster[i]; + assurance(monst->MType != nullptr, i); if (pnum >= 0) - Monst->mWhoHit |= 1 << pnum; + monst->mWhoHit |= 1 << pnum; if (pnum < MAX_PLRS && i >= MAX_PLRS) /// BUGFIX: i >= MAX_PLRS (fixed) - AddPlrMonstExper(Monst->mLevel, Monst->mExp, Monst->mWhoHit); - monstkills[Monst->MType->mtype]++; - Monst->_mhitpoints = 0; - SetRndSeed(Monst->_mRndSeed); + AddPlrMonstExper(monst->mLevel, monst->mExp, monst->mWhoHit); + monstkills[monst->MType->mtype]++; + monst->_mhitpoints = 0; + SetRndSeed(monst->_mRndSeed); SpawnLoot(i, sendmsg); - if (Monst->MType->mtype == MT_DIABLO) + if (monst->MType->mtype == MT_DIABLO) M_DiabloDeath(i, true); else PlayEffect(i, 2); - Direction md = pnum >= 0 ? M_GetDir(i) : Monst->_mdir; - Monst->_mdir = md; - NewMonsterAnim(i, &Monst->MType->Anims[MA_DEATH], md, gGameLogicStep < GameLogicStep::ProcessMonsters ? AnimationDistributionFlags::ProcessAnimationPending : AnimationDistributionFlags::None); - Monst->_mmode = MM_DEATH; - Monst->_mgoal = MGOAL_NONE; - Monst->position.offset = { 0, 0 }; - Monst->_mVar1 = 0; - Monst->position.tile = Monst->position.old; - Monst->position.future = Monst->position.old; + Direction md = pnum >= 0 ? M_GetDir(i) : monst->_mdir; + monst->_mdir = md; + NewMonsterAnim(i, &monst->MType->Anims[MA_DEATH], md, gGameLogicStep < GameLogicStep::ProcessMonsters ? AnimationDistributionFlags::ProcessAnimationPending : AnimationDistributionFlags::None); + monst->_mmode = MM_DEATH; + monst->_mgoal = MGOAL_NONE; + monst->position.offset = { 0, 0 }; + monst->_mVar1 = 0; + monst->position.tile = monst->position.old; + monst->position.future = monst->position.old; M_ClearSquares(i); - dMonster[Monst->position.tile.x][Monst->position.tile.y] = i + 1; + dMonster[monst->position.tile.x][monst->position.tile.y] = i + 1; CheckQuestKill(i, sendmsg); - M_FallenFear(Monst->position.tile); - if ((Monst->MType->mtype >= MT_NACID && Monst->MType->mtype <= MT_XACID) || Monst->MType->mtype == MT_SPIDLORD) - AddMissile(Monst->position.tile, { 0, 0 }, 0, MIS_ACIDPUD, TARGET_PLAYERS, i, Monst->_mint + 1, 0); + M_FallenFear(monst->position.tile); + if ((monst->MType->mtype >= MT_NACID && monst->MType->mtype <= MT_XACID) || monst->MType->mtype == MT_SPIDLORD) + AddMissile(monst->position.tile, { 0, 0 }, 0, MIS_ACIDPUD, TARGET_PLAYERS, i, monst->_mint + 1, 0); } void M2MStartKill(int i, int mid) @@ -1895,12 +1892,12 @@ void M_StartHeal(int i) assurance((DWORD)i < MAXMONSTERS, i); assurance(monster[i].MType != nullptr, i); - MonsterStruct *Monst = &monster[i]; - Monst->AnimInfo.pCelSprite = &*Monst->MType->Anims[MA_SPECIAL].CelSpritesForDirections[Monst->_mdir]; - Monst->AnimInfo.CurrentFrame = Monst->MType->Anims[MA_SPECIAL].Frames; - Monst->_mFlags |= MFLAG_LOCK_ANIMATION; - Monst->_mmode = MM_HEAL; - Monst->_mVar1 = Monst->_mmaxhp / (16 * (GenerateRnd(5) + 4)); + MonsterStruct *monst = &monster[i]; + monst->AnimInfo.pCelSprite = &*monst->MType->Anims[MA_SPECIAL].CelSpritesForDirections[monst->_mdir]; + monst->AnimInfo.CurrentFrame = monst->MType->Anims[MA_SPECIAL].Frames; + monst->_mFlags |= MFLAG_LOCK_ANIMATION; + monst->_mmode = MM_HEAL; + monst->_mVar1 = monst->_mmaxhp / (16 * (GenerateRnd(5) + 4)); } void M_ChangeLightOffset(int monst) @@ -1919,16 +1916,16 @@ bool M_DoStand(int i) commitment((DWORD)i < MAXMONSTERS, i); commitment(monster[i].MType != nullptr, i); - MonsterStruct *Monst = &monster[i]; - if (Monst->MType->mtype == MT_GOLEM) - Monst->AnimInfo.pCelSprite = &*Monst->MType->Anims[MA_WALK].CelSpritesForDirections[Monst->_mdir]; + MonsterStruct *monst = &monster[i]; + if (monst->MType->mtype == MT_GOLEM) + monst->AnimInfo.pCelSprite = &*monst->MType->Anims[MA_WALK].CelSpritesForDirections[monst->_mdir]; else - Monst->AnimInfo.pCelSprite = &*Monst->MType->Anims[MA_STAND].CelSpritesForDirections[Monst->_mdir]; + monst->AnimInfo.pCelSprite = &*monst->MType->Anims[MA_STAND].CelSpritesForDirections[monst->_mdir]; - if (Monst->AnimInfo.CurrentFrame == Monst->AnimInfo.NumberOfFrames) + if (monst->AnimInfo.CurrentFrame == monst->AnimInfo.NumberOfFrames) M_Enemy(i); - Monst->_mVar2++; + monst->_mVar2++; return false; } @@ -2084,27 +2081,27 @@ void M_TryH2HHit(int i, int pnum, int hit, int minDam, int maxDam) return; } if (monster[i].MType->mtype == MT_YZOMBIE && pnum == myplr) { - int cur_ms_num = -1; + int currentMissileId = -1; for (int j = 0; j < nummissiles; j++) { - int misnum = missileactive[j]; - if (missile[misnum]._mitype != MIS_MANASHIELD) + int mi = missileactive[j]; + if (missile[mi]._mitype != MIS_MANASHIELD) continue; - if (missile[misnum]._misource == pnum) - cur_ms_num = misnum; + if (missile[mi]._misource == pnum) + currentMissileId = mi; } if (plr[pnum]._pMaxHP > 64) { if (plr[pnum]._pMaxHPBase > 64) { plr[pnum]._pMaxHP -= 64; if (plr[pnum]._pHitPoints > plr[pnum]._pMaxHP) { plr[pnum]._pHitPoints = plr[pnum]._pMaxHP; - if (cur_ms_num >= 0) - missile[cur_ms_num]._miVar1 = plr[pnum]._pHitPoints; + if (currentMissileId >= 0) + missile[currentMissileId]._miVar1 = plr[pnum]._pHitPoints; } plr[pnum]._pMaxHPBase -= 64; if (plr[pnum]._pHPBase > plr[pnum]._pMaxHPBase) { plr[pnum]._pHPBase = plr[pnum]._pMaxHPBase; - if (cur_ms_num >= 0) - missile[cur_ms_num]._miVar2 = plr[pnum]._pHPBase; + if (currentMissileId >= 0) + missile[currentMissileId]._miVar2 = plr[pnum]._pHPBase; } } } @@ -2162,9 +2159,9 @@ void M_TryH2HHit(int i, int pnum, int hit, int minDam, int maxDam) bool M_DoAttack(int i) { commitment((DWORD)i < MAXMONSTERS, i); - MonsterStruct *Monst = &monster[i]; - commitment(Monst->MType != nullptr, i); - commitment(Monst->MData != nullptr, i); // BUGFIX: should check MData (fixed) + MonsterStruct *monst = &monster[i]; + commitment(monst->MType != nullptr, i); + commitment(monst->MData != nullptr, i); // BUGFIX: should check MData (fixed) if (monster[i].AnimInfo.CurrentFrame == monster[i].MData->mAFNum) { M_TryH2HHit(i, monster[i]._menemy, monster[i].mHit, monster[i].mMinDamage, monster[i].mMaxDamage); @@ -2325,22 +2322,22 @@ bool M_DoFadeout(int i) bool M_DoHeal(int i) { commitment((DWORD)i < MAXMONSTERS, i); - MonsterStruct *Monst = &monster[i]; + MonsterStruct *monst = &monster[i]; if ((monster[i]._mFlags & MFLAG_NOHEAL) != 0) { - Monst->_mFlags &= ~MFLAG_ALLOW_SPECIAL; - Monst->_mmode = MM_SATTACK; + monst->_mFlags &= ~MFLAG_ALLOW_SPECIAL; + monst->_mmode = MM_SATTACK; return false; } - if (Monst->AnimInfo.CurrentFrame == 1) { - Monst->_mFlags &= ~MFLAG_LOCK_ANIMATION; - Monst->_mFlags |= MFLAG_ALLOW_SPECIAL; - if (Monst->_mVar1 + Monst->_mhitpoints < Monst->_mmaxhp) { - Monst->_mhitpoints = Monst->_mVar1 + Monst->_mhitpoints; + if (monst->AnimInfo.CurrentFrame == 1) { + monst->_mFlags &= ~MFLAG_LOCK_ANIMATION; + monst->_mFlags |= MFLAG_ALLOW_SPECIAL; + if (monst->_mVar1 + monst->_mhitpoints < monst->_mmaxhp) { + monst->_mhitpoints = monst->_mVar1 + monst->_mhitpoints; } else { - Monst->_mhitpoints = Monst->_mmaxhp; - Monst->_mFlags &= ~MFLAG_ALLOW_SPECIAL; - Monst->_mmode = MM_SATTACK; + monst->_mhitpoints = monst->_mmaxhp; + monst->_mFlags &= ~MFLAG_ALLOW_SPECIAL; + monst->_mmode = MM_SATTACK; } } return false; @@ -2350,9 +2347,9 @@ bool M_DoTalk(int i) { commitment((DWORD)i < MAXMONSTERS, i); - MonsterStruct *Monst = &monster[i]; + MonsterStruct *monst = &monster[i]; M_StartStand(i, monster[i]._mdir); - Monst->_mgoal = MGOAL_TALKING; // CODEFIX: apply Monst instead of monster[i] in the rest of the function + monst->_mgoal = MGOAL_TALKING; // CODEFIX: apply Monst instead of monster[i] in the rest of the function if (effect_is_playing(alltext[monster[i].mtalkmsg].sfxnr)) return false; InitQTextMsg(monster[i].mtalkmsg); @@ -2415,12 +2412,12 @@ void M_Teleport(int i) { assurance((DWORD)i < MAXMONSTERS, i); - MonsterStruct *Monst = &monster[i]; - if (Monst->_mmode == MM_STONE) + MonsterStruct *monst = &monster[i]; + if (monst->_mmode == MM_STONE) return; - int mx = Monst->enemyPosition.x; - int my = Monst->enemyPosition.y; + int mx = monst->enemyPosition.x; + int my = monst->enemyPosition.y; int rx = 2 * GenerateRnd(2) - 1; int ry = 2 * GenerateRnd(2) - 1; @@ -2433,7 +2430,7 @@ void M_Teleport(int i) if (j != 0 || k != 0) { x = mx + rx * j; y = my + ry * k; - if (y >= 0 && y < MAXDUNY && x >= 0 && x < MAXDUNX && x != Monst->position.tile.x && y != Monst->position.tile.y) { + if (y >= 0 && y < MAXDUNY && x >= 0 && x < MAXDUNX && x != monst->position.tile.x && y != monst->position.tile.y) { if (PosOkMonst(i, { x, y })) done = true; } @@ -2443,10 +2440,10 @@ void M_Teleport(int i) if (done) { M_ClearSquares(i); - dMonster[Monst->position.tile.x][Monst->position.tile.y] = 0; + dMonster[monst->position.tile.x][monst->position.tile.y] = 0; dMonster[x][y] = i + 1; - Monst->position.old = { x, y }; - Monst->_mdir = M_GetDir(i); + monst->position.old = { x, y }; + monst->_mdir = M_GetDir(i); } } @@ -2739,18 +2736,18 @@ bool M_CallWalk(int i, Direction md) bool M_PathWalk(int i) { int8_t path[MAX_PATH_LENGTH]; - bool (*Check)(int, Point); + bool (*check)(int, Point); /** Maps from walking path step to facing direction. */ const Direction plr2monst[9] = { DIR_S, DIR_NE, DIR_NW, DIR_SE, DIR_SW, DIR_N, DIR_E, DIR_S, DIR_W }; commitment((DWORD)i < MAXMONSTERS, i); - Check = PosOkMonst3; + check = PosOkMonst3; if ((monster[i]._mFlags & MFLAG_CAN_OPEN_DOOR) == 0) - Check = PosOkMonst; + check = PosOkMonst; - if (FindPath(Check, i, monster[i].position.tile.x, monster[i].position.tile.y, monster[i].enemyPosition.x, monster[i].enemyPosition.y, path) == 0) { + if (FindPath(check, i, monster[i].position.tile.x, monster[i].position.tile.y, monster[i].enemyPosition.x, monster[i].enemyPosition.y, path) == 0) { return false; } @@ -2820,23 +2817,23 @@ void MAI_Zombie(int i) { assurance((DWORD)i < MAXMONSTERS, i); - MonsterStruct *Monst = &monster[i]; - if (Monst->_mmode != MM_STAND) { + MonsterStruct *monst = &monster[i]; + if (monst->_mmode != MM_STAND) { return; } - int mx = Monst->position.tile.x; - int my = Monst->position.tile.y; + int mx = monst->position.tile.x; + int my = monst->position.tile.y; if ((dFlags[mx][my] & BFLAG_VISIBLE) == 0) { return; } - if (GenerateRnd(100) < 2 * Monst->_mint + 10) { - int dist = Monst->enemyPosition.WalkingDistance({ mx, my }); + if (GenerateRnd(100) < 2 * monst->_mint + 10) { + int dist = monst->enemyPosition.WalkingDistance({ mx, my }); if (dist >= 2) { - if (dist >= 2 * Monst->_mint + 4) { - Direction md = Monst->_mdir; - if (GenerateRnd(100) < 2 * Monst->_mint + 20) { + if (dist >= 2 * monst->_mint + 4) { + Direction md = monst->_mdir; + if (GenerateRnd(100) < 2 * monst->_mint + 20) { md = static_cast(GenerateRnd(8)); } M_DumbWalk(i, md); @@ -2848,72 +2845,72 @@ void MAI_Zombie(int i) } } - Monst->CheckStandAnimationIsLoaded(Monst->_mdir); + monst->CheckStandAnimationIsLoaded(monst->_mdir); } void MAI_SkelSd(int i) { assurance((DWORD)i < MAXMONSTERS, i); - MonsterStruct *Monst = &monster[i]; - if (Monst->_mmode != MM_STAND || Monst->_msquelch == 0) { + MonsterStruct *monst = &monster[i]; + if (monst->_mmode != MM_STAND || monst->_msquelch == 0) { return; } - int x = Monst->position.tile.x - Monst->enemyPosition.x; - int y = Monst->position.tile.y - Monst->enemyPosition.y; - Direction md = GetDirection(Monst->position.tile, Monst->position.last); - Monst->_mdir = md; + int x = monst->position.tile.x - monst->enemyPosition.x; + int y = monst->position.tile.y - monst->enemyPosition.y; + Direction md = GetDirection(monst->position.tile, monst->position.last); + monst->_mdir = md; if (abs(x) >= 2 || abs(y) >= 2) { - if (Monst->_mVar1 == MM_DELAY || (GenerateRnd(100) >= 35 - 4 * Monst->_mint)) { + if (monst->_mVar1 == MM_DELAY || (GenerateRnd(100) >= 35 - 4 * monst->_mint)) { M_CallWalk(i, md); } else { - M_StartDelay(i, 15 - 2 * Monst->_mint + GenerateRnd(10)); + M_StartDelay(i, 15 - 2 * monst->_mint + GenerateRnd(10)); } } else { - if (Monst->_mVar1 == MM_DELAY || (GenerateRnd(100) < 2 * Monst->_mint + 20)) { + if (monst->_mVar1 == MM_DELAY || (GenerateRnd(100) < 2 * monst->_mint + 20)) { M_StartAttack(i); } else { - M_StartDelay(i, 2 * (5 - Monst->_mint) + GenerateRnd(10)); + M_StartDelay(i, 2 * (5 - monst->_mint) + GenerateRnd(10)); } } - Monst->CheckStandAnimationIsLoaded(md); + monst->CheckStandAnimationIsLoaded(md); } bool MAI_Path(int i) { commitment((DWORD)i < MAXMONSTERS, i); - MonsterStruct *Monst = &monster[i]; - if (Monst->MType->mtype != MT_GOLEM) { - if (Monst->_msquelch == 0) + MonsterStruct *monst = &monster[i]; + if (monst->MType->mtype != MT_GOLEM) { + if (monst->_msquelch == 0) return false; - if (Monst->_mmode != MM_STAND) + if (monst->_mmode != MM_STAND) return false; - if (Monst->_mgoal != MGOAL_NORMAL && Monst->_mgoal != MGOAL_MOVE && Monst->_mgoal != MGOAL_ATTACK2) + if (monst->_mgoal != MGOAL_NORMAL && monst->_mgoal != MGOAL_MOVE && monst->_mgoal != MGOAL_ATTACK2) return false; - if (Monst->position.tile.x == 1 && Monst->position.tile.y == 0) + if (monst->position.tile.x == 1 && monst->position.tile.y == 0) return false; } bool clear = LineClear( PosOkMonst2, i, - Monst->position.tile, - Monst->enemyPosition); - if (!clear || (Monst->_pathcount >= 5 && Monst->_pathcount < 8)) { - if ((Monst->_mFlags & MFLAG_CAN_OPEN_DOOR) != 0) + monst->position.tile, + monst->enemyPosition); + if (!clear || (monst->_pathcount >= 5 && monst->_pathcount < 8)) { + if ((monst->_mFlags & MFLAG_CAN_OPEN_DOOR) != 0) MonstCheckDoors(i); - Monst->_pathcount++; - if (Monst->_pathcount < 5) + monst->_pathcount++; + if (monst->_pathcount < 5) return false; if (M_PathWalk(i)) return true; } - if (Monst->MType->mtype != MT_GOLEM) - Monst->_pathcount = 0; + if (monst->MType->mtype != MT_GOLEM) + monst->_pathcount = 0; return false; } @@ -2922,243 +2919,243 @@ void MAI_Snake(int i) { assurance((DWORD)i < MAXMONSTERS, i); char pattern[6] = { 1, 1, 0, -1, -1, 0 }; - MonsterStruct *Monst = &monster[i]; - int pnum = Monst->_menemy; - if (Monst->_mmode != MM_STAND || Monst->_msquelch == 0) + MonsterStruct *monst = &monster[i]; + int pnum = monst->_menemy; + if (monst->_mmode != MM_STAND || monst->_msquelch == 0) return; - int fx = Monst->enemyPosition.x; - int fy = Monst->enemyPosition.y; - int mx = Monst->position.tile.x - fx; - int my = Monst->position.tile.y - fy; - Direction md = GetDirection(Monst->position.tile, Monst->position.last); - Monst->_mdir = md; + int fx = monst->enemyPosition.x; + int fy = monst->enemyPosition.y; + int mx = monst->position.tile.x - fx; + int my = monst->position.tile.y - fy; + Direction md = GetDirection(monst->position.tile, monst->position.last); + monst->_mdir = md; if (abs(mx) >= 2 || abs(my) >= 2) { - if (abs(mx) < 3 && abs(my) < 3 && LineClear(PosOkMonst, i, Monst->position.tile, { fx, fy }) && Monst->_mVar1 != MM_CHARGE) { - if (AddMissile(Monst->position.tile, { fx, fy }, md, MIS_RHINO, pnum, i, 0, 0) != -1) { + if (abs(mx) < 3 && abs(my) < 3 && LineClear(PosOkMonst, i, monst->position.tile, { fx, fy }) && monst->_mVar1 != MM_CHARGE) { + if (AddMissile(monst->position.tile, { fx, fy }, md, MIS_RHINO, pnum, i, 0, 0) != -1) { PlayEffect(i, 0); - dMonster[Monst->position.tile.x][Monst->position.tile.y] = -(i + 1); - Monst->_mmode = MM_CHARGE; + dMonster[monst->position.tile.x][monst->position.tile.y] = -(i + 1); + monst->_mmode = MM_CHARGE; } - } else if (Monst->_mVar1 == MM_DELAY || GenerateRnd(100) >= 35 - 2 * Monst->_mint) { - if (pattern[Monst->_mgoalvar1] == -1) + } else if (monst->_mVar1 == MM_DELAY || GenerateRnd(100) >= 35 - 2 * monst->_mint) { + if (pattern[monst->_mgoalvar1] == -1) md = left[md]; - else if (pattern[Monst->_mgoalvar1] == 1) + else if (pattern[monst->_mgoalvar1] == 1) md = right[md]; - Monst->_mgoalvar1++; - if (Monst->_mgoalvar1 > 5) - Monst->_mgoalvar1 = 0; + monst->_mgoalvar1++; + if (monst->_mgoalvar1 > 5) + monst->_mgoalvar1 = 0; - if (md != Monst->_mgoalvar2) { - int drift = md - Monst->_mgoalvar2; + if (md != monst->_mgoalvar2) { + int drift = md - monst->_mgoalvar2; if (drift < 0) drift += 8; if (drift < 4) - md = right[Monst->_mgoalvar2]; + md = right[monst->_mgoalvar2]; else if (drift > 4) - md = left[Monst->_mgoalvar2]; - Monst->_mgoalvar2 = md; + md = left[monst->_mgoalvar2]; + monst->_mgoalvar2 = md; } if (!M_DumbWalk(i, md)) - M_CallWalk2(i, Monst->_mdir); + M_CallWalk2(i, monst->_mdir); } else { - M_StartDelay(i, 15 - Monst->_mint + GenerateRnd(10)); + M_StartDelay(i, 15 - monst->_mint + GenerateRnd(10)); } } else { - if (Monst->_mVar1 == MM_DELAY - || Monst->_mVar1 == MM_CHARGE - || (GenerateRnd(100) < Monst->_mint + 20)) { + if (monst->_mVar1 == MM_DELAY + || monst->_mVar1 == MM_CHARGE + || (GenerateRnd(100) < monst->_mint + 20)) { M_StartAttack(i); } else - M_StartDelay(i, 10 - Monst->_mint + GenerateRnd(10)); + M_StartDelay(i, 10 - monst->_mint + GenerateRnd(10)); } - Monst->CheckStandAnimationIsLoaded(Monst->_mdir); + monst->CheckStandAnimationIsLoaded(monst->_mdir); } void MAI_Bat(int i) { assurance((DWORD)i < MAXMONSTERS, i); - MonsterStruct *Monst = &monster[i]; - int pnum = Monst->_menemy; - if (Monst->_mmode != MM_STAND || Monst->_msquelch == 0) { + MonsterStruct *monst = &monster[i]; + int pnum = monst->_menemy; + if (monst->_mmode != MM_STAND || monst->_msquelch == 0) { return; } - int xd = Monst->position.tile.x - Monst->enemyPosition.x; - int yd = Monst->position.tile.y - Monst->enemyPosition.y; - Direction md = GetDirection(Monst->position.tile, Monst->position.last); - Monst->_mdir = md; + int xd = monst->position.tile.x - monst->enemyPosition.x; + int yd = monst->position.tile.y - monst->enemyPosition.y; + Direction md = GetDirection(monst->position.tile, monst->position.last); + monst->_mdir = md; int v = GenerateRnd(100); - if (Monst->_mgoal == MGOAL_RETREAT) { - if (Monst->_mgoalvar1 == 0) { + if (monst->_mgoal == MGOAL_RETREAT) { + if (monst->_mgoalvar1 == 0) { M_CallWalk(i, opposite[md]); - Monst->_mgoalvar1++; + monst->_mgoalvar1++; } else { if (GenerateRnd(2) != 0) M_CallWalk(i, left[md]); else M_CallWalk(i, right[md]); - Monst->_mgoal = MGOAL_NORMAL; + monst->_mgoal = MGOAL_NORMAL; } return; } - int fx = Monst->enemyPosition.x; - int fy = Monst->enemyPosition.y; - if (Monst->MType->mtype == MT_GLOOM + int fx = monst->enemyPosition.x; + int fy = monst->enemyPosition.y; + if (monst->MType->mtype == MT_GLOOM && (abs(xd) >= 5 || abs(yd) >= 5) - && v < 4 * Monst->_mint + 33 - && LineClear(PosOkMonst, i, Monst->position.tile, { fx, fy })) { - if (AddMissile(Monst->position.tile, { fx, fy }, md, MIS_RHINO, pnum, i, 0, 0) != -1) { - dMonster[Monst->position.tile.x][Monst->position.tile.y] = -(i + 1); - Monst->_mmode = MM_CHARGE; + && v < 4 * monst->_mint + 33 + && LineClear(PosOkMonst, i, monst->position.tile, { fx, fy })) { + if (AddMissile(monst->position.tile, { fx, fy }, md, MIS_RHINO, pnum, i, 0, 0) != -1) { + dMonster[monst->position.tile.x][monst->position.tile.y] = -(i + 1); + monst->_mmode = MM_CHARGE; } } else if (abs(xd) >= 2 || abs(yd) >= 2) { - if ((Monst->_mVar2 > 20 && v < Monst->_mint + 13) - || ((Monst->_mVar1 == MM_WALK || Monst->_mVar1 == MM_WALK2 || Monst->_mVar1 == MM_WALK3) - && Monst->_mVar2 == 0 - && v < Monst->_mint + 63)) { + if ((monst->_mVar2 > 20 && v < monst->_mint + 13) + || ((monst->_mVar1 == MM_WALK || monst->_mVar1 == MM_WALK2 || monst->_mVar1 == MM_WALK3) + && monst->_mVar2 == 0 + && v < monst->_mint + 63)) { M_CallWalk(i, md); } - } else if (v < 4 * Monst->_mint + 8) { + } else if (v < 4 * monst->_mint + 8) { M_StartAttack(i); - Monst->_mgoal = MGOAL_RETREAT; - Monst->_mgoalvar1 = 0; - if (Monst->MType->mtype == MT_FAMILIAR) { - AddMissile(Monst->enemyPosition, { Monst->enemyPosition.x + 1, 0 }, -1, MIS_LIGHTNING, TARGET_PLAYERS, i, GenerateRnd(10) + 1, 0); + monst->_mgoal = MGOAL_RETREAT; + monst->_mgoalvar1 = 0; + if (monst->MType->mtype == MT_FAMILIAR) { + AddMissile(monst->enemyPosition, { monst->enemyPosition.x + 1, 0 }, -1, MIS_LIGHTNING, TARGET_PLAYERS, i, GenerateRnd(10) + 1, 0); } } - Monst->CheckStandAnimationIsLoaded(md); + monst->CheckStandAnimationIsLoaded(md); } void MAI_SkelBow(int i) { assurance((DWORD)i < MAXMONSTERS, i); - MonsterStruct *Monst = &monster[i]; - if (Monst->_mmode != MM_STAND || Monst->_msquelch == 0) { + MonsterStruct *monst = &monster[i]; + if (monst->_mmode != MM_STAND || monst->_msquelch == 0) { return; } - int mx = Monst->position.tile.x - Monst->enemyPosition.x; - int my = Monst->position.tile.y - Monst->enemyPosition.y; + int mx = monst->position.tile.x - monst->enemyPosition.x; + int my = monst->position.tile.y - monst->enemyPosition.y; Direction md = M_GetDir(i); - Monst->_mdir = md; + monst->_mdir = md; int v = GenerateRnd(100); bool walking = false; if (abs(mx) < 4 && abs(my) < 4) { - if ((Monst->_mVar2 > 20 && v < 2 * Monst->_mint + 13) - || ((Monst->_mVar1 == MM_WALK || Monst->_mVar1 == MM_WALK2 || Monst->_mVar1 == MM_WALK3) - && Monst->_mVar2 == 0 - && v < 2 * Monst->_mint + 63)) { + if ((monst->_mVar2 > 20 && v < 2 * monst->_mint + 13) + || ((monst->_mVar1 == MM_WALK || monst->_mVar1 == MM_WALK2 || monst->_mVar1 == MM_WALK3) + && monst->_mVar2 == 0 + && v < 2 * monst->_mint + 63)) { walking = M_DumbWalk(i, opposite[md]); } } if (!walking) { - if (GenerateRnd(100) < 2 * Monst->_mint + 3) { - if (LineClearMissile(Monst->position.tile, Monst->enemyPosition)) + if (GenerateRnd(100) < 2 * monst->_mint + 3) { + if (LineClearMissile(monst->position.tile, monst->enemyPosition)) M_StartRAttack(i, MIS_ARROW, 4); } } - Monst->CheckStandAnimationIsLoaded(md); + monst->CheckStandAnimationIsLoaded(md); } void MAI_Fat(int i) { assurance((DWORD)i < MAXMONSTERS, i); - MonsterStruct *Monst = &monster[i]; - if (Monst->_mmode != MM_STAND || Monst->_msquelch == 0) { + MonsterStruct *monst = &monster[i]; + if (monst->_mmode != MM_STAND || monst->_msquelch == 0) { return; } - int mx = Monst->position.tile.x - Monst->enemyPosition.x; - int my = Monst->position.tile.y - Monst->enemyPosition.y; + int mx = monst->position.tile.x - monst->enemyPosition.x; + int my = monst->position.tile.y - monst->enemyPosition.y; Direction md = M_GetDir(i); - Monst->_mdir = md; + monst->_mdir = md; int v = GenerateRnd(100); if (abs(mx) >= 2 || abs(my) >= 2) { - if ((Monst->_mVar2 > 20 && v < 4 * Monst->_mint + 20) - || ((Monst->_mVar1 == MM_WALK || Monst->_mVar1 == MM_WALK2 || Monst->_mVar1 == MM_WALK3) - && Monst->_mVar2 == 0 - && v < 4 * Monst->_mint + 70)) { + if ((monst->_mVar2 > 20 && v < 4 * monst->_mint + 20) + || ((monst->_mVar1 == MM_WALK || monst->_mVar1 == MM_WALK2 || monst->_mVar1 == MM_WALK3) + && monst->_mVar2 == 0 + && v < 4 * monst->_mint + 70)) { M_CallWalk(i, md); } - } else if (v < 4 * Monst->_mint + 15) { + } else if (v < 4 * monst->_mint + 15) { M_StartAttack(i); - } else if (v < 4 * Monst->_mint + 20) { + } else if (v < 4 * monst->_mint + 20) { M_StartSpAttack(i); } - Monst->CheckStandAnimationIsLoaded(md); + monst->CheckStandAnimationIsLoaded(md); } void MAI_Sneak(int i) { assurance((DWORD)i < MAXMONSTERS, i); - MonsterStruct *Monst = &monster[i]; - if (Monst->_mmode != MM_STAND) { + MonsterStruct *monst = &monster[i]; + if (monst->_mmode != MM_STAND) { return; } - int mx = Monst->position.tile.x; - int my = Monst->position.tile.y; + int mx = monst->position.tile.x; + int my = monst->position.tile.y; if (dLight[mx][my] == lightmax) { return; } - mx -= Monst->enemyPosition.x; - my -= Monst->enemyPosition.y; + mx -= monst->enemyPosition.x; + my -= monst->enemyPosition.y; - int dist = 5 - Monst->_mint; - if (Monst->_mVar1 == MM_GOTHIT) { - Monst->_mgoal = MGOAL_RETREAT; - Monst->_mgoalvar1 = 0; - } else if (abs(mx) >= dist + 3 || abs(my) >= dist + 3 || Monst->_mgoalvar1 > 8) { - Monst->_mgoal = MGOAL_NORMAL; - Monst->_mgoalvar1 = 0; + int dist = 5 - monst->_mint; + if (monst->_mVar1 == MM_GOTHIT) { + monst->_mgoal = MGOAL_RETREAT; + monst->_mgoalvar1 = 0; + } else if (abs(mx) >= dist + 3 || abs(my) >= dist + 3 || monst->_mgoalvar1 > 8) { + monst->_mgoal = MGOAL_NORMAL; + monst->_mgoalvar1 = 0; } Direction md = M_GetDir(i); - if (Monst->_mgoal == MGOAL_RETREAT && (Monst->_mFlags & MFLAG_NO_ENEMY) == 0) { - if ((Monst->_mFlags & MFLAG_TARGETS_MONSTER) != 0) - md = GetDirection(Monst->position.tile, monster[Monst->_menemy].position.tile); + if (monst->_mgoal == MGOAL_RETREAT && (monst->_mFlags & MFLAG_NO_ENEMY) == 0) { + if ((monst->_mFlags & MFLAG_TARGETS_MONSTER) != 0) + md = GetDirection(monst->position.tile, monster[monst->_menemy].position.tile); else - md = GetDirection(Monst->position.tile, plr[Monst->_menemy].position.last); + md = GetDirection(monst->position.tile, plr[monst->_menemy].position.last); md = opposite[md]; - if (Monst->MType->mtype == MT_UNSEEN) { + if (monst->MType->mtype == MT_UNSEEN) { if (GenerateRnd(2) != 0) md = left[md]; else md = right[md]; } } - Monst->_mdir = md; + monst->_mdir = md; int v = GenerateRnd(100); - if (abs(mx) < dist && abs(my) < dist && (Monst->_mFlags & MFLAG_HIDDEN) != 0) { + if (abs(mx) < dist && abs(my) < dist && (monst->_mFlags & MFLAG_HIDDEN) != 0) { M_StartFadein(i, md, false); } else { - if ((abs(mx) >= dist + 1 || abs(my) >= dist + 1) && (Monst->_mFlags & MFLAG_HIDDEN) == 0) { + if ((abs(mx) >= dist + 1 || abs(my) >= dist + 1) && (monst->_mFlags & MFLAG_HIDDEN) == 0) { M_StartFadeout(i, md, true); } else { - if (Monst->_mgoal == MGOAL_RETREAT - || ((abs(mx) >= 2 || abs(my) >= 2) && ((Monst->_mVar2 > 20 && v < 4 * Monst->_mint + 14) || ((Monst->_mVar1 == MM_WALK || Monst->_mVar1 == MM_WALK2 || Monst->_mVar1 == MM_WALK3) && Monst->_mVar2 == 0 && v < 4 * Monst->_mint + 64)))) { - Monst->_mgoalvar1++; + if (monst->_mgoal == MGOAL_RETREAT + || ((abs(mx) >= 2 || abs(my) >= 2) && ((monst->_mVar2 > 20 && v < 4 * monst->_mint + 14) || ((monst->_mVar1 == MM_WALK || monst->_mVar1 == MM_WALK2 || monst->_mVar1 == MM_WALK3) && monst->_mVar2 == 0 && v < 4 * monst->_mint + 64)))) { + monst->_mgoalvar1++; M_CallWalk(i, md); } } } - if (Monst->_mmode == MM_STAND) { - if (abs(mx) >= 2 || abs(my) >= 2 || v >= 4 * Monst->_mint + 10) - Monst->AnimInfo.pCelSprite = &*Monst->MType->Anims[MA_STAND].CelSpritesForDirections[md]; + if (monst->_mmode == MM_STAND) { + if (abs(mx) >= 2 || abs(my) >= 2 || v >= 4 * monst->_mint + 10) + monst->AnimInfo.pCelSprite = &*monst->MType->Anims[MA_STAND].CelSpritesForDirections[md]; else M_StartAttack(i); } @@ -3168,8 +3165,8 @@ void MAI_Fireman(int i) { assurance((DWORD)i < MAXMONSTERS, i); - MonsterStruct *Monst = &monster[i]; - if (monster[i]._mmode != MM_STAND || Monst->_msquelch == 0) + MonsterStruct *monst = &monster[i]; + if (monster[i]._mmode != MM_STAND || monst->_msquelch == 0) return; int pnum = monster[i]._menemy; @@ -3179,43 +3176,43 @@ void MAI_Fireman(int i) int yd = monster[i].position.tile.y - fy; Direction md = M_GetDir(i); - if (Monst->_mgoal == MGOAL_NORMAL) { - if (LineClearMissile(Monst->position.tile, { fx, fy }) - && AddMissile(Monst->position.tile, { fx, fy }, md, MIS_FIREMAN, pnum, i, 0, 0) != -1) { - Monst->_mmode = MM_CHARGE; - Monst->_mgoal = MGOAL_ATTACK2; - Monst->_mgoalvar1 = 0; - } - } else if (Monst->_mgoal == MGOAL_ATTACK2) { - if (Monst->_mgoalvar1 == 3) { - Monst->_mgoal = MGOAL_NORMAL; + if (monst->_mgoal == MGOAL_NORMAL) { + if (LineClearMissile(monst->position.tile, { fx, fy }) + && AddMissile(monst->position.tile, { fx, fy }, md, MIS_FIREMAN, pnum, i, 0, 0) != -1) { + monst->_mmode = MM_CHARGE; + monst->_mgoal = MGOAL_ATTACK2; + monst->_mgoalvar1 = 0; + } + } else if (monst->_mgoal == MGOAL_ATTACK2) { + if (monst->_mgoalvar1 == 3) { + monst->_mgoal = MGOAL_NORMAL; M_StartFadeout(i, md, true); - } else if (LineClearMissile(Monst->position.tile, { fx, fy })) { + } else if (LineClearMissile(monst->position.tile, { fx, fy })) { M_StartRAttack(i, MIS_KRULL, 4); - Monst->_mgoalvar1++; + monst->_mgoalvar1++; } else { M_StartDelay(i, GenerateRnd(10) + 5); - Monst->_mgoalvar1++; + monst->_mgoalvar1++; } - } else if (Monst->_mgoal == MGOAL_RETREAT) { + } else if (monst->_mgoal == MGOAL_RETREAT) { M_StartFadein(i, md, false); - Monst->_mgoal = MGOAL_ATTACK2; + monst->_mgoal = MGOAL_ATTACK2; } - Monst->_mdir = md; + monst->_mdir = md; GenerateRnd(100); - if (Monst->_mmode != MM_STAND) + if (monst->_mmode != MM_STAND) return; - if (abs(xd) < 2 && abs(yd) < 2 && Monst->_mgoal == MGOAL_NORMAL) { + if (abs(xd) < 2 && abs(yd) < 2 && monst->_mgoal == MGOAL_NORMAL) { M_TryH2HHit(i, monster[i]._menemy, monster[i].mHit, monster[i].mMinDamage, monster[i].mMaxDamage); - Monst->_mgoal = MGOAL_RETREAT; + monst->_mgoal = MGOAL_RETREAT; if (!M_CallWalk(i, opposite[md])) { M_StartFadein(i, md, false); - Monst->_mgoal = MGOAL_ATTACK2; + monst->_mgoal = MGOAL_ATTACK2; } - } else if (!M_CallWalk(i, md) && (Monst->_mgoal == MGOAL_NORMAL || Monst->_mgoal == MGOAL_RETREAT)) { + } else if (!M_CallWalk(i, md) && (monst->_mgoal == MGOAL_NORMAL || monst->_mgoal == MGOAL_RETREAT)) { M_StartFadein(i, md, false); - Monst->_mgoal = MGOAL_ATTACK2; + monst->_mgoal = MGOAL_ATTACK2; } } @@ -3223,57 +3220,57 @@ void MAI_Fallen(int i) { assurance((DWORD)i < MAXMONSTERS, i); - MonsterStruct *Monst = &monster[i]; - if (Monst->_mgoal == MGOAL_ATTACK2) { - if (Monst->_mgoalvar1 != 0) - Monst->_mgoalvar1--; + MonsterStruct *monst = &monster[i]; + if (monst->_mgoal == MGOAL_ATTACK2) { + if (monst->_mgoalvar1 != 0) + monst->_mgoalvar1--; else - Monst->_mgoal = MGOAL_NORMAL; + monst->_mgoal = MGOAL_NORMAL; } - if (Monst->_mmode != MM_STAND || Monst->_msquelch == 0) { + if (monst->_mmode != MM_STAND || monst->_msquelch == 0) { return; } - if (Monst->_mgoal == MGOAL_RETREAT) { - if (Monst->_mgoalvar1-- == 0) { - Monst->_mgoal = MGOAL_NORMAL; - M_StartStand(i, opposite[Monst->_mdir]); + if (monst->_mgoal == MGOAL_RETREAT) { + if (monst->_mgoalvar1-- == 0) { + monst->_mgoal = MGOAL_NORMAL; + M_StartStand(i, opposite[monst->_mdir]); } } - if (Monst->AnimInfo.CurrentFrame == Monst->AnimInfo.NumberOfFrames) { + if (monst->AnimInfo.CurrentFrame == monst->AnimInfo.NumberOfFrames) { if (GenerateRnd(4) != 0) { return; } if ((monster[i]._mFlags & MFLAG_NOHEAL) == 0) { // CODEFIX: - change to Monst-> in devilutionx - M_StartSpStand(i, Monst->_mdir); - if (Monst->_mmaxhp - (2 * Monst->_mint + 2) >= Monst->_mhitpoints) - Monst->_mhitpoints += 2 * Monst->_mint + 2; + M_StartSpStand(i, monst->_mdir); + if (monst->_mmaxhp - (2 * monst->_mint + 2) >= monst->_mhitpoints) + monst->_mhitpoints += 2 * monst->_mint + 2; else - Monst->_mhitpoints = Monst->_mmaxhp; + monst->_mhitpoints = monst->_mmaxhp; } - int rad = 2 * Monst->_mint + 4; + int rad = 2 * monst->_mint + 4; for (int y = -rad; y <= rad; y++) { for (int x = -rad; x <= rad; x++) { - int xpos = Monst->position.tile.x + x; - int ypos = Monst->position.tile.y + y; + int xpos = monst->position.tile.x + x; + int ypos = monst->position.tile.y + y; if (y >= 0 && y < MAXDUNY && x >= 0 && x < MAXDUNX) { int m = dMonster[xpos][ypos]; if (m > 0) { m--; if (monster[m]._mAi == AI_FALLEN) { monster[m]._mgoal = MGOAL_ATTACK2; - monster[m]._mgoalvar1 = 30 * Monst->_mint + 105; + monster[m]._mgoalvar1 = 30 * monst->_mint + 105; } } } } } - } else if (Monst->_mgoal == MGOAL_RETREAT) { - M_CallWalk(i, Monst->_mdir); - } else if (Monst->_mgoal == MGOAL_ATTACK2) { - int xpos = Monst->position.tile.x - Monst->enemyPosition.x; - int ypos = Monst->position.tile.y - Monst->enemyPosition.y; + } else if (monst->_mgoal == MGOAL_RETREAT) { + M_CallWalk(i, monst->_mdir); + } else if (monst->_mgoal == MGOAL_ATTACK2) { + int xpos = monst->position.tile.x - monst->enemyPosition.x; + int ypos = monst->position.tile.y - monst->enemyPosition.y; if (abs(xpos) < 2 && abs(ypos) < 2) M_StartAttack(i); else @@ -3286,78 +3283,78 @@ void MAI_Cleaver(int i) { assurance((DWORD)i < MAXMONSTERS, i); - MonsterStruct *Monst = &monster[i]; - if (Monst->_mmode != MM_STAND || Monst->_msquelch == 0) { + MonsterStruct *monst = &monster[i]; + if (monst->_mmode != MM_STAND || monst->_msquelch == 0) { return; } - int mx = Monst->position.tile.x; - int my = Monst->position.tile.y; - int x = mx - Monst->enemyPosition.x; - int y = my - Monst->enemyPosition.y; + int mx = monst->position.tile.x; + int my = monst->position.tile.y; + int x = mx - monst->enemyPosition.x; + int y = my - monst->enemyPosition.y; - Direction md = GetDirection({ mx, my }, Monst->position.last); - Monst->_mdir = md; + Direction md = GetDirection({ mx, my }, monst->position.last); + monst->_mdir = md; if (abs(x) >= 2 || abs(y) >= 2) M_CallWalk(i, md); else M_StartAttack(i); - Monst->CheckStandAnimationIsLoaded(md); + monst->CheckStandAnimationIsLoaded(md); } void MAI_Round(int i, bool special) { assurance((DWORD)i < MAXMONSTERS, i); - MonsterStruct *Monst = &monster[i]; - if (Monst->_mmode != MM_STAND || Monst->_msquelch == 0) { + MonsterStruct *monst = &monster[i]; + if (monst->_mmode != MM_STAND || monst->_msquelch == 0) { return; } - int fx = Monst->enemyPosition.x; - int fy = Monst->enemyPosition.y; - int mx = Monst->position.tile.x - fx; - int my = Monst->position.tile.y - fy; - Direction md = GetDirection(Monst->position.tile, Monst->position.last); - if (Monst->_msquelch < UINT8_MAX) + int fx = monst->enemyPosition.x; + int fy = monst->enemyPosition.y; + int mx = monst->position.tile.x - fx; + int my = monst->position.tile.y - fy; + Direction md = GetDirection(monst->position.tile, monst->position.last); + if (monst->_msquelch < UINT8_MAX) MonstCheckDoors(i); int v = GenerateRnd(100); - if ((abs(mx) >= 2 || abs(my) >= 2) && Monst->_msquelch == UINT8_MAX && dTransVal[Monst->position.tile.x][Monst->position.tile.y] == dTransVal[fx][fy]) { - if (Monst->_mgoal == MGOAL_MOVE || ((abs(mx) >= 4 || abs(my) >= 4) && GenerateRnd(4) == 0)) { - if (Monst->_mgoal != MGOAL_MOVE) { - Monst->_mgoalvar1 = 0; - Monst->_mgoalvar2 = GenerateRnd(2); + if ((abs(mx) >= 2 || abs(my) >= 2) && monst->_msquelch == UINT8_MAX && dTransVal[monst->position.tile.x][monst->position.tile.y] == dTransVal[fx][fy]) { + if (monst->_mgoal == MGOAL_MOVE || ((abs(mx) >= 4 || abs(my) >= 4) && GenerateRnd(4) == 0)) { + if (monst->_mgoal != MGOAL_MOVE) { + monst->_mgoalvar1 = 0; + monst->_mgoalvar2 = GenerateRnd(2); } - Monst->_mgoal = MGOAL_MOVE; + monst->_mgoal = MGOAL_MOVE; int dist = std::max(abs(mx), abs(my)); - if ((Monst->_mgoalvar1++ >= 2 * dist && DirOK(i, md)) || dTransVal[Monst->position.tile.x][Monst->position.tile.y] != dTransVal[fx][fy]) { - Monst->_mgoal = MGOAL_NORMAL; - } else if (!M_RoundWalk(i, md, &Monst->_mgoalvar2)) { + if ((monst->_mgoalvar1++ >= 2 * dist && DirOK(i, md)) || dTransVal[monst->position.tile.x][monst->position.tile.y] != dTransVal[fx][fy]) { + monst->_mgoal = MGOAL_NORMAL; + } else if (!M_RoundWalk(i, md, &monst->_mgoalvar2)) { M_StartDelay(i, GenerateRnd(10) + 10); } } } else { - Monst->_mgoal = MGOAL_NORMAL; + monst->_mgoal = MGOAL_NORMAL; } - if (Monst->_mgoal == MGOAL_NORMAL) { + if (monst->_mgoal == MGOAL_NORMAL) { if (abs(mx) >= 2 || abs(my) >= 2) { - if ((Monst->_mVar2 > 20 && v < 2 * Monst->_mint + 28) - || ((Monst->_mVar1 == MM_WALK || Monst->_mVar1 == MM_WALK2 || Monst->_mVar1 == MM_WALK3) - && Monst->_mVar2 == 0 - && v < 2 * Monst->_mint + 78)) { + if ((monst->_mVar2 > 20 && v < 2 * monst->_mint + 28) + || ((monst->_mVar1 == MM_WALK || monst->_mVar1 == MM_WALK2 || monst->_mVar1 == MM_WALK3) + && monst->_mVar2 == 0 + && v < 2 * monst->_mint + 78)) { M_CallWalk(i, md); } - } else if (v < 2 * Monst->_mint + 23) { - Monst->_mdir = md; - if (special && Monst->_mhitpoints < (Monst->_mmaxhp / 2) && GenerateRnd(2) != 0) + } else if (v < 2 * monst->_mint + 23) { + monst->_mdir = md; + if (special && monst->_mhitpoints < (monst->_mmaxhp / 2) && GenerateRnd(2) != 0) M_StartSpAttack(i); else M_StartAttack(i); } } - Monst->CheckStandAnimationIsLoaded(md); + monst->CheckStandAnimationIsLoaded(md); } void MAI_GoatMc(int i) @@ -3373,39 +3370,39 @@ void MAI_Ranged(int i, missile_id missileType, bool special) return; } - MonsterStruct *Monst = &monster[i]; - if (Monst->_msquelch == UINT8_MAX || (Monst->_mFlags & MFLAG_TARGETS_MONSTER) != 0) { - int fx = Monst->enemyPosition.x; - int fy = Monst->enemyPosition.y; - int mx = Monst->position.tile.x - fx; - int my = Monst->position.tile.y - fy; + MonsterStruct *monst = &monster[i]; + if (monst->_msquelch == UINT8_MAX || (monst->_mFlags & MFLAG_TARGETS_MONSTER) != 0) { + int fx = monst->enemyPosition.x; + int fy = monst->enemyPosition.y; + int mx = monst->position.tile.x - fx; + int my = monst->position.tile.y - fy; Direction md = M_GetDir(i); - if (Monst->_msquelch < UINT8_MAX) + if (monst->_msquelch < UINT8_MAX) MonstCheckDoors(i); - Monst->_mdir = md; - if (Monst->_mVar1 == MM_RATTACK) { + monst->_mdir = md; + if (monst->_mVar1 == MM_RATTACK) { M_StartDelay(i, GenerateRnd(20)); } else if (abs(mx) < 4 && abs(my) < 4) { - if (GenerateRnd(100) < 10 * (Monst->_mint + 7)) + if (GenerateRnd(100) < 10 * (monst->_mint + 7)) M_CallWalk(i, opposite[md]); } - if (Monst->_mmode == MM_STAND) { - if (LineClearMissile(Monst->position.tile, { fx, fy })) { + if (monst->_mmode == MM_STAND) { + if (LineClearMissile(monst->position.tile, { fx, fy })) { if (special) M_StartRSpAttack(i, missileType, 4); else M_StartRAttack(i, missileType, 4); } else { - Monst->AnimInfo.pCelSprite = &*Monst->MType->Anims[MA_STAND].CelSpritesForDirections[md]; + monst->AnimInfo.pCelSprite = &*monst->MType->Anims[MA_STAND].CelSpritesForDirections[md]; } } return; } - if (Monst->_msquelch != 0) { - int fx = Monst->position.last.x; - int fy = Monst->position.last.y; - Direction md = GetDirection(Monst->position.tile, { fx, fy }); + if (monst->_msquelch != 0) { + int fx = monst->position.last.x; + int fy = monst->position.last.y; + Direction md = GetDirection(monst->position.tile, { fx, fy }); M_CallWalk(i, md); } } @@ -3459,43 +3456,43 @@ void MAI_Scav(int i) { assurance((DWORD)i < MAXMONSTERS, i); - MonsterStruct *Monst = &monster[i]; + MonsterStruct *monst = &monster[i]; if (monster[i]._mmode != MM_STAND) return; - if (Monst->_mhitpoints < (Monst->_mmaxhp / 2) && Monst->_mgoal != MGOAL_HEALING) { - if (Monst->leaderflag != 0) { - monster[Monst->leader].packsize--; - Monst->leaderflag = 0; + if (monst->_mhitpoints < (monst->_mmaxhp / 2) && monst->_mgoal != MGOAL_HEALING) { + if (monst->leaderflag != 0) { + monster[monst->leader].packsize--; + monst->leaderflag = 0; } - Monst->_mgoal = MGOAL_HEALING; - Monst->_mgoalvar3 = 10; + monst->_mgoal = MGOAL_HEALING; + monst->_mgoalvar3 = 10; } - if (Monst->_mgoal == MGOAL_HEALING && Monst->_mgoalvar3 != 0) { - Monst->_mgoalvar3--; - if (dDead[Monst->position.tile.x][Monst->position.tile.y] != 0) { + if (monst->_mgoal == MGOAL_HEALING && monst->_mgoalvar3 != 0) { + monst->_mgoalvar3--; + if (dDead[monst->position.tile.x][monst->position.tile.y] != 0) { M_StartEat(i); - if ((Monst->_mFlags & MFLAG_NOHEAL) == 0) { + if ((monst->_mFlags & MFLAG_NOHEAL) == 0) { if (gbIsHellfire) { - int mMaxHP = Monst->_mmaxhp; // BUGFIX use _mmaxhp or we loose health when difficulty isn't normal (fixed) - Monst->_mhitpoints += mMaxHP / 8; - if (Monst->_mhitpoints > Monst->_mmaxhp) - Monst->_mhitpoints = Monst->_mmaxhp; - if (Monst->_mgoalvar3 <= 0 || Monst->_mhitpoints == Monst->_mmaxhp) - dDead[Monst->position.tile.x][Monst->position.tile.y] = 0; + int mMaxHP = monst->_mmaxhp; // BUGFIX use _mmaxhp or we loose health when difficulty isn't normal (fixed) + monst->_mhitpoints += mMaxHP / 8; + if (monst->_mhitpoints > monst->_mmaxhp) + monst->_mhitpoints = monst->_mmaxhp; + if (monst->_mgoalvar3 <= 0 || monst->_mhitpoints == monst->_mmaxhp) + dDead[monst->position.tile.x][monst->position.tile.y] = 0; } else { - Monst->_mhitpoints += 64; + monst->_mhitpoints += 64; } } - int targetHealth = Monst->_mmaxhp; + int targetHealth = monst->_mmaxhp; if (!gbIsHellfire) - targetHealth = (Monst->_mmaxhp / 2) + (Monst->_mmaxhp / 4); - if (Monst->_mhitpoints >= targetHealth) { - Monst->_mgoal = MGOAL_NORMAL; - Monst->_mgoalvar1 = 0; - Monst->_mgoalvar2 = 0; + targetHealth = (monst->_mmaxhp / 2) + (monst->_mmaxhp / 4); + if (monst->_mhitpoints >= targetHealth) { + monst->_mgoal = MGOAL_NORMAL; + monst->_mgoalvar1 = 0; + monst->_mgoalvar2 = 0; } } else { - if (Monst->_mgoalvar1 == 0) { + if (monst->_mgoalvar1 == 0) { bool done = false; int x; int y; @@ -3505,10 +3502,10 @@ void MAI_Scav(int i) // BUGFIX: incorrect check of offset against limits of the dungeon if (y < 0 || y >= MAXDUNY || x < 0 || x >= MAXDUNX) continue; - done = dDead[Monst->position.tile.x + x][Monst->position.tile.y + y] != 0 + done = dDead[monst->position.tile.x + x][monst->position.tile.y + y] != 0 && LineClearSolid( - Monst->position.tile, - Monst->position.tile + Displacement { x, y }); + monst->position.tile, + monst->position.tile + Displacement { x, y }); } } x--; @@ -3519,30 +3516,30 @@ void MAI_Scav(int i) // BUGFIX: incorrect check of offset against limits of the dungeon if (y < 0 || y >= MAXDUNY || x < 0 || x >= MAXDUNX) continue; - done = dDead[Monst->position.tile.x + x][Monst->position.tile.y + y] != 0 + done = dDead[monst->position.tile.x + x][monst->position.tile.y + y] != 0 && LineClearSolid( - Monst->position.tile, - Monst->position.tile + Displacement { x, y }); + monst->position.tile, + monst->position.tile + Displacement { x, y }); } } x++; y++; } if (done) { - Monst->_mgoalvar1 = x + Monst->position.tile.x + 1; - Monst->_mgoalvar2 = y + Monst->position.tile.y + 1; + monst->_mgoalvar1 = x + monst->position.tile.x + 1; + monst->_mgoalvar2 = y + monst->position.tile.y + 1; } } - if (Monst->_mgoalvar1 != 0) { - int x = Monst->_mgoalvar1 - 1; - int y = Monst->_mgoalvar2 - 1; - Monst->_mdir = GetDirection(Monst->position.tile, { x, y }); - M_CallWalk(i, Monst->_mdir); + if (monst->_mgoalvar1 != 0) { + int x = monst->_mgoalvar1 - 1; + int y = monst->_mgoalvar2 - 1; + monst->_mdir = GetDirection(monst->position.tile, { x, y }); + M_CallWalk(i, monst->_mdir); } } } - if (Monst->_mmode == MM_STAND) + if (monst->_mmode == MM_STAND) MAI_SkelSd(i); } @@ -3550,33 +3547,33 @@ void MAI_Garg(int i) { assurance((DWORD)i < MAXMONSTERS, i); - MonsterStruct *Monst = &monster[i]; - int dx = Monst->position.tile.x - Monst->position.last.x; - int dy = Monst->position.tile.y - Monst->position.last.y; + MonsterStruct *monst = &monster[i]; + int dx = monst->position.tile.x - monst->position.last.x; + int dy = monst->position.tile.y - monst->position.last.y; Direction md = M_GetDir(i); - if (Monst->_msquelch != 0 && (Monst->_mFlags & MFLAG_ALLOW_SPECIAL) != 0) { + if (monst->_msquelch != 0 && (monst->_mFlags & MFLAG_ALLOW_SPECIAL) != 0) { M_Enemy(i); - int mx = Monst->position.tile.x - Monst->enemyPosition.x; - int my = Monst->position.tile.y - Monst->enemyPosition.y; - if (abs(mx) < Monst->_mint + 2 && abs(my) < Monst->_mint + 2) { - Monst->_mFlags &= ~MFLAG_ALLOW_SPECIAL; + int mx = monst->position.tile.x - monst->enemyPosition.x; + int my = monst->position.tile.y - monst->enemyPosition.y; + if (abs(mx) < monst->_mint + 2 && abs(my) < monst->_mint + 2) { + monst->_mFlags &= ~MFLAG_ALLOW_SPECIAL; } return; } - if (Monst->_mmode != MM_STAND || Monst->_msquelch == 0) { + if (monst->_mmode != MM_STAND || monst->_msquelch == 0) { return; } - if (Monst->_mhitpoints < (Monst->_mmaxhp / 2)) - if ((Monst->_mFlags & MFLAG_NOHEAL) == 0) - Monst->_mgoal = MGOAL_RETREAT; - if (Monst->_mgoal == MGOAL_RETREAT) { - if (abs(dx) >= Monst->_mint + 2 || abs(dy) >= Monst->_mint + 2) { - Monst->_mgoal = MGOAL_NORMAL; + if (monst->_mhitpoints < (monst->_mmaxhp / 2)) + if ((monst->_mFlags & MFLAG_NOHEAL) == 0) + monst->_mgoal = MGOAL_RETREAT; + if (monst->_mgoal == MGOAL_RETREAT) { + if (abs(dx) >= monst->_mint + 2 || abs(dy) >= monst->_mint + 2) { + monst->_mgoal = MGOAL_NORMAL; M_StartHeal(i); } else if (!M_CallWalk(i, opposite[md])) { - Monst->_mgoal = MGOAL_NORMAL; + monst->_mgoal = MGOAL_NORMAL; } } MAI_Round(i, false); @@ -3585,56 +3582,56 @@ void MAI_Garg(int i) void MAI_RoundRanged(int i, missile_id missileType, bool checkdoors, int dam, int lessmissiles) { assurance((DWORD)i < MAXMONSTERS, i); - MonsterStruct *Monst = &monster[i]; - if (Monst->_mmode != MM_STAND || Monst->_msquelch == 0) { + MonsterStruct *monst = &monster[i]; + if (monst->_mmode != MM_STAND || monst->_msquelch == 0) { return; } - int fx = Monst->enemyPosition.x; - int fy = Monst->enemyPosition.y; - int mx = Monst->position.tile.x - fx; - int my = Monst->position.tile.y - fy; - Direction md = GetDirection(Monst->position.tile, Monst->position.last); - if (checkdoors && Monst->_msquelch < UINT8_MAX) + int fx = monst->enemyPosition.x; + int fy = monst->enemyPosition.y; + int mx = monst->position.tile.x - fx; + int my = monst->position.tile.y - fy; + Direction md = GetDirection(monst->position.tile, monst->position.last); + if (checkdoors && monst->_msquelch < UINT8_MAX) MonstCheckDoors(i); int v = GenerateRnd(10000); int dist = std::max(abs(mx), abs(my)); - if (dist >= 2 && Monst->_msquelch == UINT8_MAX && dTransVal[Monst->position.tile.x][Monst->position.tile.y] == dTransVal[fx][fy]) { - if (Monst->_mgoal == MGOAL_MOVE || (dist >= 3 && GenerateRnd(4 << lessmissiles) == 0)) { - if (Monst->_mgoal != MGOAL_MOVE) { - Monst->_mgoalvar1 = 0; - Monst->_mgoalvar2 = GenerateRnd(2); + if (dist >= 2 && monst->_msquelch == UINT8_MAX && dTransVal[monst->position.tile.x][monst->position.tile.y] == dTransVal[fx][fy]) { + if (monst->_mgoal == MGOAL_MOVE || (dist >= 3 && GenerateRnd(4 << lessmissiles) == 0)) { + if (monst->_mgoal != MGOAL_MOVE) { + monst->_mgoalvar1 = 0; + monst->_mgoalvar2 = GenerateRnd(2); } - Monst->_mgoal = MGOAL_MOVE; - if (Monst->_mgoalvar1++ >= 2 * dist && DirOK(i, md)) { - Monst->_mgoal = MGOAL_NORMAL; - } else if (v < (500 * (Monst->_mint + 1) >> lessmissiles) - && (LineClearMissile(Monst->position.tile, { fx, fy }))) { + monst->_mgoal = MGOAL_MOVE; + if (monst->_mgoalvar1++ >= 2 * dist && DirOK(i, md)) { + monst->_mgoal = MGOAL_NORMAL; + } else if (v < (500 * (monst->_mint + 1) >> lessmissiles) + && (LineClearMissile(monst->position.tile, { fx, fy }))) { M_StartRSpAttack(i, missileType, dam); } else { - M_RoundWalk(i, md, &Monst->_mgoalvar2); + M_RoundWalk(i, md, &monst->_mgoalvar2); } } } else { - Monst->_mgoal = MGOAL_NORMAL; + monst->_mgoal = MGOAL_NORMAL; } - if (Monst->_mgoal == MGOAL_NORMAL) { - if (((dist >= 3 && v < ((500 * (Monst->_mint + 2)) >> lessmissiles)) - || v < ((500 * (Monst->_mint + 1)) >> lessmissiles)) - && LineClearMissile(Monst->position.tile, { fx, fy })) { + if (monst->_mgoal == MGOAL_NORMAL) { + if (((dist >= 3 && v < ((500 * (monst->_mint + 2)) >> lessmissiles)) + || v < ((500 * (monst->_mint + 1)) >> lessmissiles)) + && LineClearMissile(monst->position.tile, { fx, fy })) { M_StartRSpAttack(i, missileType, dam); } else if (dist >= 2) { v = GenerateRnd(100); - if (v < 1000 * (Monst->_mint + 5) - || ((Monst->_mVar1 == MM_WALK || Monst->_mVar1 == MM_WALK2 || Monst->_mVar1 == MM_WALK3) && Monst->_mVar2 == 0 && v < 1000 * (Monst->_mint + 8))) { + if (v < 1000 * (monst->_mint + 5) + || ((monst->_mVar1 == MM_WALK || monst->_mVar1 == MM_WALK2 || monst->_mVar1 == MM_WALK3) && monst->_mVar2 == 0 && v < 1000 * (monst->_mint + 8))) { M_CallWalk(i, md); } - } else if (v < 1000 * (Monst->_mint + 6)) { - Monst->_mdir = md; + } else if (v < 1000 * (monst->_mint + 6)) { + monst->_mdir = md; M_StartAttack(i); } } - if (Monst->_mmode == MM_STAND) { + if (monst->_mmode == MM_STAND) { M_StartDelay(i, GenerateRnd(10) + 5); } } @@ -3668,67 +3665,67 @@ void MAI_RR2(int i, missile_id mistype, int dam) { assurance((DWORD)i < MAXMONSTERS, i); - MonsterStruct *Monst = &monster[i]; - int mx = Monst->position.tile.x - Monst->enemyPosition.x; - int my = Monst->position.tile.y - Monst->enemyPosition.y; + MonsterStruct *monst = &monster[i]; + int mx = monst->position.tile.x - monst->enemyPosition.x; + int my = monst->position.tile.y - monst->enemyPosition.y; if (abs(mx) >= 5 || abs(my) >= 5) { MAI_SkelSd(i); return; } - if (Monst->_mmode != MM_STAND || Monst->_msquelch == 0) { + if (monst->_mmode != MM_STAND || monst->_msquelch == 0) { return; } - int fx = Monst->enemyPosition.x; - int fy = Monst->enemyPosition.y; - mx = Monst->position.tile.x - fx; - my = Monst->position.tile.y - fy; - Direction md = GetDirection(Monst->position.tile, Monst->position.last); - if (Monst->_msquelch < UINT8_MAX) + int fx = monst->enemyPosition.x; + int fy = monst->enemyPosition.y; + mx = monst->position.tile.x - fx; + my = monst->position.tile.y - fy; + Direction md = GetDirection(monst->position.tile, monst->position.last); + if (monst->_msquelch < UINT8_MAX) MonstCheckDoors(i); int v = GenerateRnd(100); int dist = std::max(abs(mx), abs(my)); - if (dist >= 2 && Monst->_msquelch == UINT8_MAX && dTransVal[Monst->position.tile.x][Monst->position.tile.y] == dTransVal[fx][fy]) { - if (Monst->_mgoal == MGOAL_MOVE || dist >= 3) { - if (Monst->_mgoal != MGOAL_MOVE) { - Monst->_mgoalvar1 = 0; - Monst->_mgoalvar2 = GenerateRnd(2); + if (dist >= 2 && monst->_msquelch == UINT8_MAX && dTransVal[monst->position.tile.x][monst->position.tile.y] == dTransVal[fx][fy]) { + if (monst->_mgoal == MGOAL_MOVE || dist >= 3) { + if (monst->_mgoal != MGOAL_MOVE) { + monst->_mgoalvar1 = 0; + monst->_mgoalvar2 = GenerateRnd(2); } - Monst->_mgoal = MGOAL_MOVE; - Monst->_mgoalvar3 = 4; - if (Monst->_mgoalvar1++ < 2 * dist || !DirOK(i, md)) { - if (v < 5 * (Monst->_mint + 16)) - M_RoundWalk(i, md, &Monst->_mgoalvar2); + monst->_mgoal = MGOAL_MOVE; + monst->_mgoalvar3 = 4; + if (monst->_mgoalvar1++ < 2 * dist || !DirOK(i, md)) { + if (v < 5 * (monst->_mint + 16)) + M_RoundWalk(i, md, &monst->_mgoalvar2); } else - Monst->_mgoal = MGOAL_NORMAL; + monst->_mgoal = MGOAL_NORMAL; } } else { - Monst->_mgoal = MGOAL_NORMAL; + monst->_mgoal = MGOAL_NORMAL; } - if (Monst->_mgoal == MGOAL_NORMAL) { - if (((dist >= 3 && v < 5 * (Monst->_mint + 2)) || v < 5 * (Monst->_mint + 1) || Monst->_mgoalvar3 == 4) && LineClearMissile(Monst->position.tile, { fx, fy })) { + if (monst->_mgoal == MGOAL_NORMAL) { + if (((dist >= 3 && v < 5 * (monst->_mint + 2)) || v < 5 * (monst->_mint + 1) || monst->_mgoalvar3 == 4) && LineClearMissile(monst->position.tile, { fx, fy })) { M_StartRSpAttack(i, mistype, dam); } else if (dist >= 2) { v = GenerateRnd(100); - if (v < 2 * (5 * Monst->_mint + 25) - || ((Monst->_mVar1 == MM_WALK || Monst->_mVar1 == MM_WALK2 || Monst->_mVar1 == MM_WALK3) - && Monst->_mVar2 == 0 - && v < 2 * (5 * Monst->_mint + 40))) { + if (v < 2 * (5 * monst->_mint + 25) + || ((monst->_mVar1 == MM_WALK || monst->_mVar1 == MM_WALK2 || monst->_mVar1 == MM_WALK3) + && monst->_mVar2 == 0 + && v < 2 * (5 * monst->_mint + 40))) { M_CallWalk(i, md); } } else { - if (GenerateRnd(100) < 10 * (Monst->_mint + 4)) { - Monst->_mdir = md; + if (GenerateRnd(100) < 10 * (monst->_mint + 4)) { + monst->_mdir = md; if (GenerateRnd(2) != 0) M_StartAttack(i); else M_StartRSpAttack(i, mistype, dam); } } - Monst->_mgoalvar3 = 1; + monst->_mgoalvar3 = 1; } - if (Monst->_mmode == MM_STAND) { + if (monst->_mmode == MM_STAND) { M_StartDelay(i, GenerateRnd(10) + 5); } } @@ -3742,23 +3739,23 @@ void MAI_Golum(int i) { assurance((DWORD)i < MAXMONSTERS, i); - MonsterStruct *Monst = &monster[i]; - if (Monst->position.tile.x == 1 && Monst->position.tile.y == 0) { + MonsterStruct *monst = &monster[i]; + if (monst->position.tile.x == 1 && monst->position.tile.y == 0) { return; } - if (Monst->_mmode == MM_DEATH - || Monst->_mmode == MM_SPSTAND - || (Monst->_mmode >= MM_WALK && Monst->_mmode <= MM_WALK3)) { + if (monst->_mmode == MM_DEATH + || monst->_mmode == MM_SPSTAND + || (monst->_mmode >= MM_WALK && monst->_mmode <= MM_WALK3)) { return; } - if ((Monst->_mFlags & MFLAG_TARGETS_MONSTER) == 0) + if ((monst->_mFlags & MFLAG_TARGETS_MONSTER) == 0) M_Enemy(i); - bool have_enemy = (monster[i]._mFlags & MFLAG_NO_ENEMY) == 0; + bool haveEnemy = (monster[i]._mFlags & MFLAG_NO_ENEMY) == 0; - if (Monst->_mmode == MM_ATTACK) { + if (monst->_mmode == MM_ATTACK) { return; } @@ -3768,7 +3765,7 @@ void MAI_Golum(int i) int mey = monster[i].position.tile.y - monster[menemy].position.future.y; Direction md = GetDirection(monster[i].position.tile, monster[menemy].position.tile); monster[i]._mdir = md; - if (abs(mex) < 2 && abs(mey) < 2 && have_enemy) { + if (abs(mex) < 2 && abs(mey) < 2 && haveEnemy) { menemy = monster[i]._menemy; monster[i].enemyPosition = monster[menemy].position.tile; if (monster[menemy]._msquelch == 0) { @@ -3786,7 +3783,7 @@ void MAI_Golum(int i) return; } - if (have_enemy && MAI_Path(i)) + if (haveEnemy && MAI_Path(i)) return; monster[i]._pathcount++; @@ -3809,41 +3806,41 @@ void MAI_Golum(int i) void MAI_SkelKing(int i) { assurance((DWORD)i < MAXMONSTERS, i); - MonsterStruct *Monst = &monster[i]; - if (Monst->_mmode != MM_STAND || Monst->_msquelch == 0) { + MonsterStruct *monst = &monster[i]; + if (monst->_mmode != MM_STAND || monst->_msquelch == 0) { return; } - int fx = Monst->enemyPosition.x; - int fy = Monst->enemyPosition.y; - int mx = Monst->position.tile.x - fx; - int my = Monst->position.tile.y - fy; - Direction md = GetDirection(Monst->position.tile, Monst->position.last); - if (Monst->_msquelch < UINT8_MAX) + int fx = monst->enemyPosition.x; + int fy = monst->enemyPosition.y; + int mx = monst->position.tile.x - fx; + int my = monst->position.tile.y - fy; + Direction md = GetDirection(monst->position.tile, monst->position.last); + if (monst->_msquelch < UINT8_MAX) MonstCheckDoors(i); int v = GenerateRnd(100); int dist = std::max(abs(mx), abs(my)); - if (dist >= 2 && Monst->_msquelch == UINT8_MAX && dTransVal[Monst->position.tile.x][Monst->position.tile.y] == dTransVal[fx][fy]) { - if (Monst->_mgoal == MGOAL_MOVE || ((abs(mx) >= 3 || abs(my) >= 3) && GenerateRnd(4) == 0)) { - if (Monst->_mgoal != MGOAL_MOVE) { - Monst->_mgoalvar1 = 0; - Monst->_mgoalvar2 = GenerateRnd(2); + if (dist >= 2 && monst->_msquelch == UINT8_MAX && dTransVal[monst->position.tile.x][monst->position.tile.y] == dTransVal[fx][fy]) { + if (monst->_mgoal == MGOAL_MOVE || ((abs(mx) >= 3 || abs(my) >= 3) && GenerateRnd(4) == 0)) { + if (monst->_mgoal != MGOAL_MOVE) { + monst->_mgoalvar1 = 0; + monst->_mgoalvar2 = GenerateRnd(2); } - Monst->_mgoal = MGOAL_MOVE; - if ((Monst->_mgoalvar1++ >= 2 * dist && DirOK(i, md)) || dTransVal[Monst->position.tile.x][Monst->position.tile.y] != dTransVal[fx][fy]) { - Monst->_mgoal = MGOAL_NORMAL; - } else if (!M_RoundWalk(i, md, &Monst->_mgoalvar2)) { + monst->_mgoal = MGOAL_MOVE; + if ((monst->_mgoalvar1++ >= 2 * dist && DirOK(i, md)) || dTransVal[monst->position.tile.x][monst->position.tile.y] != dTransVal[fx][fy]) { + monst->_mgoal = MGOAL_NORMAL; + } else if (!M_RoundWalk(i, md, &monst->_mgoalvar2)) { M_StartDelay(i, GenerateRnd(10) + 10); } } } else { - Monst->_mgoal = MGOAL_NORMAL; + monst->_mgoal = MGOAL_NORMAL; } - if (Monst->_mgoal == MGOAL_NORMAL) { + if (monst->_mgoal == MGOAL_NORMAL) { if (!gbIsMultiplayer - && ((dist >= 3 && v < 4 * Monst->_mint + 35) || v < 6) - && LineClearMissile(Monst->position.tile, { fx, fy })) { - Point newPosition = Monst->position.tile + md; + && ((dist >= 3 && v < 4 * monst->_mint + 35) || v < 6) + && LineClearMissile(monst->position.tile, { fx, fy })) { + Point newPosition = monst->position.tile + md; if (PosOkMonst(i, newPosition) && nummonsters < MAXMONSTERS) { M_SpawnSkel(newPosition, md); M_StartSpStand(i, md); @@ -3851,84 +3848,84 @@ void MAI_SkelKing(int i) } else { if (dist >= 2) { v = GenerateRnd(100); - if (v >= Monst->_mint + 25 - && ((Monst->_mVar1 != MM_WALK && Monst->_mVar1 != MM_WALK2 && Monst->_mVar1 != MM_WALK3) || Monst->_mVar2 != 0 || (v >= Monst->_mint + 75))) { + if (v >= monst->_mint + 25 + && ((monst->_mVar1 != MM_WALK && monst->_mVar1 != MM_WALK2 && monst->_mVar1 != MM_WALK3) || monst->_mVar2 != 0 || (v >= monst->_mint + 75))) { M_StartDelay(i, GenerateRnd(10) + 10); } else { M_CallWalk(i, md); } - } else if (v < Monst->_mint + 20) { - Monst->_mdir = md; + } else if (v < monst->_mint + 20) { + monst->_mdir = md; M_StartAttack(i); } } } - Monst->CheckStandAnimationIsLoaded(md); + monst->CheckStandAnimationIsLoaded(md); } void MAI_Rhino(int i) { assurance((DWORD)i < MAXMONSTERS, i); - MonsterStruct *Monst = &monster[i]; - if (Monst->_mmode != MM_STAND || Monst->_msquelch == 0) { + MonsterStruct *monst = &monster[i]; + if (monst->_mmode != MM_STAND || monst->_msquelch == 0) { return; } - int fx = Monst->enemyPosition.x; - int fy = Monst->enemyPosition.y; - int mx = Monst->position.tile.x - fx; - int my = Monst->position.tile.y - fy; - Direction md = GetDirection(Monst->position.tile, Monst->position.last); - if (Monst->_msquelch < UINT8_MAX) + int fx = monst->enemyPosition.x; + int fy = monst->enemyPosition.y; + int mx = monst->position.tile.x - fx; + int my = monst->position.tile.y - fy; + Direction md = GetDirection(monst->position.tile, monst->position.last); + if (monst->_msquelch < UINT8_MAX) MonstCheckDoors(i); int v = GenerateRnd(100); int dist = std::max(abs(mx), abs(my)); if (dist >= 2) { - if (Monst->_mgoal == MGOAL_MOVE || (dist >= 5 && GenerateRnd(4) != 0)) { - if (Monst->_mgoal != MGOAL_MOVE) { - Monst->_mgoalvar1 = 0; - Monst->_mgoalvar2 = GenerateRnd(2); + if (monst->_mgoal == MGOAL_MOVE || (dist >= 5 && GenerateRnd(4) != 0)) { + if (monst->_mgoal != MGOAL_MOVE) { + monst->_mgoalvar1 = 0; + monst->_mgoalvar2 = GenerateRnd(2); } - Monst->_mgoal = MGOAL_MOVE; - if (Monst->_mgoalvar1++ >= 2 * dist || dTransVal[Monst->position.tile.x][Monst->position.tile.y] != dTransVal[fx][fy]) { - Monst->_mgoal = MGOAL_NORMAL; - } else if (!M_RoundWalk(i, md, &Monst->_mgoalvar2)) { + monst->_mgoal = MGOAL_MOVE; + if (monst->_mgoalvar1++ >= 2 * dist || dTransVal[monst->position.tile.x][monst->position.tile.y] != dTransVal[fx][fy]) { + monst->_mgoal = MGOAL_NORMAL; + } else if (!M_RoundWalk(i, md, &monst->_mgoalvar2)) { M_StartDelay(i, GenerateRnd(10) + 10); } } } else { - Monst->_mgoal = MGOAL_NORMAL; + monst->_mgoal = MGOAL_NORMAL; } - if (Monst->_mgoal == MGOAL_NORMAL) { + if (monst->_mgoal == MGOAL_NORMAL) { if (dist >= 5 - && v < 2 * Monst->_mint + 43 - && LineClear(PosOkMonst, i, Monst->position.tile, { fx, fy })) { - if (AddMissile(Monst->position.tile, { fx, fy }, md, MIS_RHINO, Monst->_menemy, i, 0, 0) != -1) { - if (Monst->MData->snd_special) + && v < 2 * monst->_mint + 43 + && LineClear(PosOkMonst, i, monst->position.tile, { fx, fy })) { + if (AddMissile(monst->position.tile, { fx, fy }, md, MIS_RHINO, monst->_menemy, i, 0, 0) != -1) { + if (monst->MData->snd_special) PlayEffect(i, 3); - dMonster[Monst->position.tile.x][Monst->position.tile.y] = -(i + 1); - Monst->_mmode = MM_CHARGE; + dMonster[monst->position.tile.x][monst->position.tile.y] = -(i + 1); + monst->_mmode = MM_CHARGE; } } else { if (dist >= 2) { v = GenerateRnd(100); - if (v >= 2 * Monst->_mint + 33 - && ((Monst->_mVar1 != MM_WALK && Monst->_mVar1 != MM_WALK2 && Monst->_mVar1 != MM_WALK3) - || Monst->_mVar2 != 0 - || v >= 2 * Monst->_mint + 83)) { + if (v >= 2 * monst->_mint + 33 + && ((monst->_mVar1 != MM_WALK && monst->_mVar1 != MM_WALK2 && monst->_mVar1 != MM_WALK3) + || monst->_mVar2 != 0 + || v >= 2 * monst->_mint + 83)) { M_StartDelay(i, GenerateRnd(10) + 10); } else { M_CallWalk(i, md); } - } else if (v < 2 * Monst->_mint + 28) { - Monst->_mdir = md; + } else if (v < 2 * monst->_mint + 28) { + monst->_mdir = md; M_StartAttack(i); } } } - Monst->CheckStandAnimationIsLoaded(Monst->_mdir); + monst->CheckStandAnimationIsLoaded(monst->_mdir); } void MAI_HorkDemon(int i) @@ -3937,54 +3934,54 @@ void MAI_HorkDemon(int i) return; } - MonsterStruct *Monst = &monster[i]; - if (Monst->_mmode != MM_STAND || Monst->_msquelch == 0) { + MonsterStruct *monst = &monster[i]; + if (monst->_mmode != MM_STAND || monst->_msquelch == 0) { return; } - int fx = Monst->enemyPosition.x; - int fy = Monst->enemyPosition.y; - int mx = Monst->position.tile.x - fx; - int my = Monst->position.tile.y - fy; - Direction md = GetDirection(Monst->position.tile, Monst->position.last); + int fx = monst->enemyPosition.x; + int fy = monst->enemyPosition.y; + int mx = monst->position.tile.x - fx; + int my = monst->position.tile.y - fy; + Direction md = GetDirection(monst->position.tile, monst->position.last); - if (Monst->_msquelch < 255) { + if (monst->_msquelch < 255) { MonstCheckDoors(i); } int v = GenerateRnd(100); if (abs(mx) < 2 && abs(my) < 2) { - Monst->_mgoal = MGOAL_NORMAL; - } else if (Monst->_mgoal == 4 || ((abs(mx) >= 5 || abs(my) >= 5) && GenerateRnd(4) != 0)) { - if (Monst->_mgoal != 4) { - Monst->_mgoalvar1 = 0; - Monst->_mgoalvar2 = GenerateRnd(2); + monst->_mgoal = MGOAL_NORMAL; + } else if (monst->_mgoal == 4 || ((abs(mx) >= 5 || abs(my) >= 5) && GenerateRnd(4) != 0)) { + if (monst->_mgoal != 4) { + monst->_mgoalvar1 = 0; + monst->_mgoalvar2 = GenerateRnd(2); } - Monst->_mgoal = MGOAL_MOVE; + monst->_mgoal = MGOAL_MOVE; int dist = std::max(abs(mx), abs(my)); - if (Monst->_mgoalvar1++ >= 2 * dist || dTransVal[Monst->position.tile.x][Monst->position.tile.y] != dTransVal[fx][fy]) { - Monst->_mgoal = MGOAL_NORMAL; - } else if (!M_RoundWalk(i, md, &Monst->_mgoalvar2)) { + if (monst->_mgoalvar1++ >= 2 * dist || dTransVal[monst->position.tile.x][monst->position.tile.y] != dTransVal[fx][fy]) { + monst->_mgoal = MGOAL_NORMAL; + } else if (!M_RoundWalk(i, md, &monst->_mgoalvar2)) { M_StartDelay(i, GenerateRnd(10) + 10); } } - if (Monst->_mgoal == 1) { - if ((abs(mx) >= 3 || abs(my) >= 3) && v < 2 * Monst->_mint + 43) { - Point position = Monst->position.tile + Monst->_mdir; + if (monst->_mgoal == 1) { + if ((abs(mx) >= 3 || abs(my) >= 3) && v < 2 * monst->_mint + 43) { + Point position = monst->position.tile + monst->_mdir; if (PosOkMonst(i, position) && nummonsters < MAXMONSTERS) { M_StartRSpAttack(i, MIS_HORKDMN, 0); } } else if (abs(mx) < 2 && abs(my) < 2) { - if (v < 2 * Monst->_mint + 28) { - Monst->_mdir = md; + if (v < 2 * monst->_mint + 28) { + monst->_mdir = md; M_StartAttack(i); } } else { v = GenerateRnd(100); - if (v < 2 * Monst->_mint + 33 - || ((Monst->_mVar1 == MM_WALK || Monst->_mVar1 == MM_WALK2 || Monst->_mVar1 == MM_WALK3) && Monst->_mVar2 == 0 && v < 2 * Monst->_mint + 83)) { + if (v < 2 * monst->_mint + 33 + || ((monst->_mVar1 == MM_WALK || monst->_mVar1 == MM_WALK2 || monst->_mVar1 == MM_WALK3) && monst->_mVar2 == 0 && v < 2 * monst->_mint + 83)) { M_CallWalk(i, md); } else { M_StartDelay(i, GenerateRnd(10) + 10); @@ -3992,69 +3989,69 @@ void MAI_HorkDemon(int i) } } - Monst->CheckStandAnimationIsLoaded(Monst->_mdir); + monst->CheckStandAnimationIsLoaded(monst->_mdir); } void MAI_Counselor(int i) { assurance((DWORD)i < MAXMONSTERS, i); - MonsterStruct *Monst = &monster[i]; - if (Monst->_mmode != MM_STAND || Monst->_msquelch == 0) { + MonsterStruct *monst = &monster[i]; + if (monst->_mmode != MM_STAND || monst->_msquelch == 0) { return; } - int fx = Monst->enemyPosition.x; - int fy = Monst->enemyPosition.y; - int mx = Monst->position.tile.x - fx; - int my = Monst->position.tile.y - fy; - Direction md = GetDirection(Monst->position.tile, Monst->position.last); - if (Monst->_msquelch < UINT8_MAX) + int fx = monst->enemyPosition.x; + int fy = monst->enemyPosition.y; + int mx = monst->position.tile.x - fx; + int my = monst->position.tile.y - fy; + Direction md = GetDirection(monst->position.tile, monst->position.last); + if (monst->_msquelch < UINT8_MAX) MonstCheckDoors(i); int v = GenerateRnd(100); - if (Monst->_mgoal == MGOAL_RETREAT) { - if (Monst->_mgoalvar1++ <= 3) + if (monst->_mgoal == MGOAL_RETREAT) { + if (monst->_mgoalvar1++ <= 3) M_CallWalk(i, opposite[md]); else { - Monst->_mgoal = MGOAL_NORMAL; + monst->_mgoal = MGOAL_NORMAL; M_StartFadein(i, md, true); } - } else if (Monst->_mgoal == MGOAL_MOVE) { + } else if (monst->_mgoal == MGOAL_MOVE) { int dist = std::max(abs(mx), abs(my)); - if (dist >= 2 && Monst->_msquelch == UINT8_MAX && dTransVal[Monst->position.tile.x][Monst->position.tile.y] == dTransVal[fx][fy]) { - if (Monst->_mgoalvar1++ < 2 * dist || !DirOK(i, md)) { - M_RoundWalk(i, md, &Monst->_mgoalvar2); + if (dist >= 2 && monst->_msquelch == UINT8_MAX && dTransVal[monst->position.tile.x][monst->position.tile.y] == dTransVal[fx][fy]) { + if (monst->_mgoalvar1++ < 2 * dist || !DirOK(i, md)) { + M_RoundWalk(i, md, &monst->_mgoalvar2); } else { - Monst->_mgoal = MGOAL_NORMAL; + monst->_mgoal = MGOAL_NORMAL; M_StartFadein(i, md, true); } } - } else if (Monst->_mgoal == MGOAL_NORMAL) { + } else if (monst->_mgoal == MGOAL_NORMAL) { if (abs(mx) >= 2 || abs(my) >= 2) { - if (v < 5 * (Monst->_mint + 10) && LineClearMissile(Monst->position.tile, { fx, fy })) { + if (v < 5 * (monst->_mint + 10) && LineClearMissile(monst->position.tile, { fx, fy })) { constexpr missile_id MissileTypes[4] = { MIS_FIREBOLT, MIS_CBOLT, MIS_LIGHTCTRL, MIS_FIREBALL }; - M_StartRAttack(i, MissileTypes[Monst->_mint], Monst->mMinDamage + GenerateRnd(Monst->mMaxDamage - Monst->mMinDamage + 1)); + M_StartRAttack(i, MissileTypes[monst->_mint], monst->mMinDamage + GenerateRnd(monst->mMaxDamage - monst->mMinDamage + 1)); } else if (GenerateRnd(100) < 30) { - Monst->_mgoal = MGOAL_MOVE; - Monst->_mgoalvar1 = 0; + monst->_mgoal = MGOAL_MOVE; + monst->_mgoalvar1 = 0; M_StartFadeout(i, md, false); } else - M_StartDelay(i, GenerateRnd(10) + 2 * (5 - Monst->_mint)); + M_StartDelay(i, GenerateRnd(10) + 2 * (5 - monst->_mint)); } else { - Monst->_mdir = md; - if (Monst->_mhitpoints < (Monst->_mmaxhp / 2)) { - Monst->_mgoal = MGOAL_RETREAT; - Monst->_mgoalvar1 = 0; + monst->_mdir = md; + if (monst->_mhitpoints < (monst->_mmaxhp / 2)) { + monst->_mgoal = MGOAL_RETREAT; + monst->_mgoalvar1 = 0; M_StartFadeout(i, md, false); - } else if (Monst->_mVar1 == MM_DELAY - || GenerateRnd(100) < 2 * Monst->_mint + 20) { + } else if (monst->_mVar1 == MM_DELAY + || GenerateRnd(100) < 2 * monst->_mint + 20) { M_StartRAttack(i, MIS_NULL, 0); - AddMissile(Monst->position.tile, { 0, 0 }, Monst->_mdir, MIS_FLASH, TARGET_PLAYERS, i, 4, 0); - AddMissile(Monst->position.tile, { 0, 0 }, Monst->_mdir, MIS_FLASH2, TARGET_PLAYERS, i, 4, 0); + AddMissile(monst->position.tile, { 0, 0 }, monst->_mdir, MIS_FLASH, TARGET_PLAYERS, i, 4, 0); + AddMissile(monst->position.tile, { 0, 0 }, monst->_mdir, MIS_FLASH2, TARGET_PLAYERS, i, 4, 0); } else - M_StartDelay(i, GenerateRnd(10) + 2 * (5 - Monst->_mint)); + M_StartDelay(i, GenerateRnd(10) + 2 * (5 - monst->_mint)); } } - if (Monst->_mmode == MM_STAND) { + if (monst->_mmode == MM_STAND) { M_StartDelay(i, GenerateRnd(10) + 5); } } @@ -4063,29 +4060,29 @@ void MAI_Garbud(int i) { assurance((DWORD)i < MAXMONSTERS, i); - MonsterStruct *Monst = &monster[i]; - if (Monst->_mmode != MM_STAND) { + MonsterStruct *monst = &monster[i]; + if (monst->_mmode != MM_STAND) { return; } - int mx = Monst->position.tile.x; - int my = Monst->position.tile.y; + int mx = monst->position.tile.x; + int my = monst->position.tile.y; Direction md = M_GetDir(i); - if (Monst->mtalkmsg >= TEXT_GARBUD1 - && Monst->mtalkmsg <= TEXT_GARBUD3 + if (monst->mtalkmsg >= TEXT_GARBUD1 + && monst->mtalkmsg <= TEXT_GARBUD3 && (dFlags[mx][my] & BFLAG_VISIBLE) == 0 - && Monst->_mgoal == MGOAL_TALKING) { - Monst->_mgoal = MGOAL_INQUIRING; - switch (Monst->mtalkmsg) { + && monst->_mgoal == MGOAL_TALKING) { + monst->_mgoal = MGOAL_INQUIRING; + switch (monst->mtalkmsg) { case TEXT_GARBUD1: - Monst->mtalkmsg = TEXT_GARBUD2; + monst->mtalkmsg = TEXT_GARBUD2; break; case TEXT_GARBUD2: - Monst->mtalkmsg = TEXT_GARBUD3; + monst->mtalkmsg = TEXT_GARBUD3; break; case TEXT_GARBUD3: - Monst->mtalkmsg = TEXT_GARBUD4; + monst->mtalkmsg = TEXT_GARBUD4; break; default: break; @@ -4093,151 +4090,151 @@ void MAI_Garbud(int i) } if ((dFlags[mx][my] & BFLAG_VISIBLE) != 0) { - if (Monst->mtalkmsg == TEXT_GARBUD4) { - if (!effect_is_playing(USFX_GARBUD4) && Monst->_mgoal == MGOAL_TALKING) { - Monst->_mgoal = MGOAL_NORMAL; - Monst->_msquelch = UINT8_MAX; - Monst->mtalkmsg = TEXT_NONE; + if (monst->mtalkmsg == TEXT_GARBUD4) { + if (!effect_is_playing(USFX_GARBUD4) && monst->_mgoal == MGOAL_TALKING) { + monst->_mgoal = MGOAL_NORMAL; + monst->_msquelch = UINT8_MAX; + monst->mtalkmsg = TEXT_NONE; } } } - if (Monst->_mgoal == MGOAL_NORMAL || Monst->_mgoal == MGOAL_MOVE) + if (monst->_mgoal == MGOAL_NORMAL || monst->_mgoal == MGOAL_MOVE) MAI_Round(i, true); monster[i]._mdir = md; - Monst->CheckStandAnimationIsLoaded(md); + monst->CheckStandAnimationIsLoaded(md); } void MAI_Zhar(int i) { assurance((DWORD)i < MAXMONSTERS, i); - MonsterStruct *Monst = &monster[i]; + MonsterStruct *monst = &monster[i]; if (monster[i]._mmode != MM_STAND) { return; } - int mx = Monst->position.tile.x; - int my = Monst->position.tile.y; + int mx = monst->position.tile.x; + int my = monst->position.tile.y; Direction md = M_GetDir(i); - if (Monst->mtalkmsg == TEXT_ZHAR1 && (dFlags[mx][my] & BFLAG_VISIBLE) == 0 && Monst->_mgoal == MGOAL_TALKING) { - Monst->mtalkmsg = TEXT_ZHAR2; - Monst->_mgoal = MGOAL_INQUIRING; + if (monst->mtalkmsg == TEXT_ZHAR1 && (dFlags[mx][my] & BFLAG_VISIBLE) == 0 && monst->_mgoal == MGOAL_TALKING) { + monst->mtalkmsg = TEXT_ZHAR2; + monst->_mgoal = MGOAL_INQUIRING; } if ((dFlags[mx][my] & BFLAG_VISIBLE) != 0) { - if (Monst->mtalkmsg == TEXT_ZHAR2) { - if (!effect_is_playing(USFX_ZHAR2) && Monst->_mgoal == MGOAL_TALKING) { - Monst->_msquelch = UINT8_MAX; - Monst->mtalkmsg = TEXT_NONE; - Monst->_mgoal = MGOAL_NORMAL; + if (monst->mtalkmsg == TEXT_ZHAR2) { + if (!effect_is_playing(USFX_ZHAR2) && monst->_mgoal == MGOAL_TALKING) { + monst->_msquelch = UINT8_MAX; + monst->mtalkmsg = TEXT_NONE; + monst->_mgoal = MGOAL_NORMAL; } } } - if (Monst->_mgoal == MGOAL_NORMAL || Monst->_mgoal == MGOAL_RETREAT || Monst->_mgoal == MGOAL_MOVE) + if (monst->_mgoal == MGOAL_NORMAL || monst->_mgoal == MGOAL_RETREAT || monst->_mgoal == MGOAL_MOVE) MAI_Counselor(i); - Monst->_mdir = md; + monst->_mdir = md; - Monst->CheckStandAnimationIsLoaded(md); + monst->CheckStandAnimationIsLoaded(md); } void MAI_SnotSpil(int i) { assurance((DWORD)i < MAXMONSTERS, i); - MonsterStruct *Monst = &monster[i]; + MonsterStruct *monst = &monster[i]; if (monster[i]._mmode != MM_STAND) { return; } - int mx = Monst->position.tile.x; - int my = Monst->position.tile.y; + int mx = monst->position.tile.x; + int my = monst->position.tile.y; Direction md = M_GetDir(i); - if (Monst->mtalkmsg == TEXT_BANNER10 && (dFlags[mx][my] & BFLAG_VISIBLE) == 0 && Monst->_mgoal == MGOAL_TALKING) { - Monst->mtalkmsg = TEXT_BANNER11; - Monst->_mgoal = MGOAL_INQUIRING; + if (monst->mtalkmsg == TEXT_BANNER10 && (dFlags[mx][my] & BFLAG_VISIBLE) == 0 && monst->_mgoal == MGOAL_TALKING) { + monst->mtalkmsg = TEXT_BANNER11; + monst->_mgoal = MGOAL_INQUIRING; } - if (Monst->mtalkmsg == TEXT_BANNER11 && quests[Q_LTBANNER]._qvar1 == 3) { - Monst->mtalkmsg = TEXT_NONE; - Monst->_mgoal = MGOAL_NORMAL; + if (monst->mtalkmsg == TEXT_BANNER11 && quests[Q_LTBANNER]._qvar1 == 3) { + monst->mtalkmsg = TEXT_NONE; + monst->_mgoal = MGOAL_NORMAL; } if ((dFlags[mx][my] & BFLAG_VISIBLE) != 0) { - if (Monst->mtalkmsg == TEXT_BANNER12) { - if (!effect_is_playing(USFX_SNOT3) && Monst->_mgoal == MGOAL_TALKING) { + if (monst->mtalkmsg == TEXT_BANNER12) { + if (!effect_is_playing(USFX_SNOT3) && monst->_mgoal == MGOAL_TALKING) { ObjChangeMap(setpc_x, setpc_y, setpc_x + setpc_w + 1, setpc_y + setpc_h + 1); quests[Q_LTBANNER]._qvar1 = 3; RedoPlayerVision(); - Monst->_msquelch = UINT8_MAX; - Monst->mtalkmsg = TEXT_NONE; - Monst->_mgoal = MGOAL_NORMAL; + monst->_msquelch = UINT8_MAX; + monst->mtalkmsg = TEXT_NONE; + monst->_mgoal = MGOAL_NORMAL; } } if (quests[Q_LTBANNER]._qvar1 == 3) { - if (Monst->_mgoal == MGOAL_NORMAL || Monst->_mgoal == MGOAL_ATTACK2) + if (monst->_mgoal == MGOAL_NORMAL || monst->_mgoal == MGOAL_ATTACK2) MAI_Fallen(i); } } - Monst->_mdir = md; + monst->_mdir = md; - Monst->CheckStandAnimationIsLoaded(md); + monst->CheckStandAnimationIsLoaded(md); } void MAI_Lazurus(int i) { assurance((DWORD)i < MAXMONSTERS, i); - MonsterStruct *Monst = &monster[i]; + MonsterStruct *monst = &monster[i]; if (monster[i]._mmode != MM_STAND) { return; } - int mx = Monst->position.tile.x; - int my = Monst->position.tile.y; + int mx = monst->position.tile.x; + int my = monst->position.tile.y; Direction md = M_GetDir(i); if ((dFlags[mx][my] & BFLAG_VISIBLE) != 0) { if (!gbIsMultiplayer) { - if (Monst->mtalkmsg == TEXT_VILE13 && Monst->_mgoal == MGOAL_INQUIRING && plr[myplr].position.tile.x == 35 && plr[myplr].position.tile.y == 46) { + if (monst->mtalkmsg == TEXT_VILE13 && monst->_mgoal == MGOAL_INQUIRING && plr[myplr].position.tile.x == 35 && plr[myplr].position.tile.y == 46) { PlayInGameMovie("gendata\\fprst3.smk"); - Monst->_mmode = MM_TALK; + monst->_mmode = MM_TALK; quests[Q_BETRAYER]._qvar1 = 5; } - if (Monst->mtalkmsg == TEXT_VILE13 && !effect_is_playing(USFX_LAZ1) && Monst->_mgoal == MGOAL_TALKING) { + if (monst->mtalkmsg == TEXT_VILE13 && !effect_is_playing(USFX_LAZ1) && monst->_mgoal == MGOAL_TALKING) { ObjChangeMapResync(1, 18, 20, 24); RedoPlayerVision(); quests[Q_BETRAYER]._qvar1 = 6; - Monst->_mgoal = MGOAL_NORMAL; - Monst->_msquelch = UINT8_MAX; - Monst->mtalkmsg = TEXT_NONE; + monst->_mgoal = MGOAL_NORMAL; + monst->_msquelch = UINT8_MAX; + monst->mtalkmsg = TEXT_NONE; } } - if (gbIsMultiplayer && Monst->mtalkmsg == TEXT_VILE13 && Monst->_mgoal == MGOAL_INQUIRING && quests[Q_BETRAYER]._qvar1 <= 3) { - Monst->_mmode = MM_TALK; + if (gbIsMultiplayer && monst->mtalkmsg == TEXT_VILE13 && monst->_mgoal == MGOAL_INQUIRING && quests[Q_BETRAYER]._qvar1 <= 3) { + monst->_mmode = MM_TALK; } } - if (Monst->_mgoal == MGOAL_NORMAL || Monst->_mgoal == MGOAL_RETREAT || Monst->_mgoal == MGOAL_MOVE) { - if (!gbIsMultiplayer && quests[Q_BETRAYER]._qvar1 == 4 && Monst->mtalkmsg == TEXT_NONE) { // Fix save games affected by teleport bug + if (monst->_mgoal == MGOAL_NORMAL || monst->_mgoal == MGOAL_RETREAT || monst->_mgoal == MGOAL_MOVE) { + if (!gbIsMultiplayer && quests[Q_BETRAYER]._qvar1 == 4 && monst->mtalkmsg == TEXT_NONE) { // Fix save games affected by teleport bug ObjChangeMapResync(1, 18, 20, 24); RedoPlayerVision(); quests[Q_BETRAYER]._qvar1 = 6; } - Monst->mtalkmsg = TEXT_NONE; + monst->mtalkmsg = TEXT_NONE; MAI_Counselor(i); } - Monst->_mdir = md; + monst->_mdir = md; - Monst->CheckStandAnimationIsLoaded(md); + monst->CheckStandAnimationIsLoaded(md); } void MAI_Lazhelp(int i) @@ -4246,90 +4243,90 @@ void MAI_Lazhelp(int i) if (monster[i]._mmode != MM_STAND) return; - MonsterStruct *Monst = &monster[i]; - int mx = Monst->position.tile.x; - int my = Monst->position.tile.y; + MonsterStruct *monst = &monster[i]; + int mx = monst->position.tile.x; + int my = monst->position.tile.y; Direction md = M_GetDir(i); if ((dFlags[mx][my] & BFLAG_VISIBLE) != 0) { if (!gbIsMultiplayer) { if (quests[Q_BETRAYER]._qvar1 <= 5) { - Monst->_mgoal = MGOAL_INQUIRING; + monst->_mgoal = MGOAL_INQUIRING; } else { - Monst->_mgoal = MGOAL_NORMAL; - Monst->mtalkmsg = TEXT_NONE; + monst->_mgoal = MGOAL_NORMAL; + monst->mtalkmsg = TEXT_NONE; } } else - Monst->_mgoal = MGOAL_NORMAL; + monst->_mgoal = MGOAL_NORMAL; } - if (Monst->_mgoal == MGOAL_NORMAL) + if (monst->_mgoal == MGOAL_NORMAL) MAI_Succ(i); - Monst->_mdir = md; + monst->_mdir = md; - Monst->CheckStandAnimationIsLoaded(md); + monst->CheckStandAnimationIsLoaded(md); } void MAI_Lachdanan(int i) { assurance((DWORD)i < MAXMONSTERS, i); - MonsterStruct *Monst = &monster[i]; + MonsterStruct *monst = &monster[i]; if (monster[i]._mmode != MM_STAND) { return; } - int mx = Monst->position.tile.x; - int my = Monst->position.tile.y; + int mx = monst->position.tile.x; + int my = monst->position.tile.y; Direction md = M_GetDir(i); - if (Monst->mtalkmsg == TEXT_VEIL9 && (dFlags[mx][my] & BFLAG_VISIBLE) == 0 && monster[i]._mgoal == MGOAL_TALKING) { - Monst->mtalkmsg = TEXT_VEIL10; + if (monst->mtalkmsg == TEXT_VEIL9 && (dFlags[mx][my] & BFLAG_VISIBLE) == 0 && monster[i]._mgoal == MGOAL_TALKING) { + monst->mtalkmsg = TEXT_VEIL10; monster[i]._mgoal = MGOAL_INQUIRING; } if ((dFlags[mx][my] & BFLAG_VISIBLE) != 0) { - if (Monst->mtalkmsg == TEXT_VEIL11) { - if (!effect_is_playing(USFX_LACH3) && Monst->_mgoal == MGOAL_TALKING) { - Monst->mtalkmsg = TEXT_NONE; + if (monst->mtalkmsg == TEXT_VEIL11) { + if (!effect_is_playing(USFX_LACH3) && monst->_mgoal == MGOAL_TALKING) { + monst->mtalkmsg = TEXT_NONE; quests[Q_VEIL]._qactive = QUEST_DONE; M_StartKill(i, -1); } } } - Monst->_mdir = md; + monst->_mdir = md; - Monst->CheckStandAnimationIsLoaded(md); + monst->CheckStandAnimationIsLoaded(md); } void MAI_Warlord(int i) { assurance((DWORD)i < MAXMONSTERS, i); - MonsterStruct *Monst = &monster[i]; + MonsterStruct *monst = &monster[i]; if (monster[i]._mmode != MM_STAND) { return; } - int mx = Monst->position.tile.x; - int my = Monst->position.tile.y; + int mx = monst->position.tile.x; + int my = monst->position.tile.y; Direction md = M_GetDir(i); if ((dFlags[mx][my] & BFLAG_VISIBLE) != 0) { - if (Monst->mtalkmsg == TEXT_WARLRD9 && Monst->_mgoal == MGOAL_INQUIRING) - Monst->_mmode = MM_TALK; - if (Monst->mtalkmsg == TEXT_WARLRD9 && !effect_is_playing(USFX_WARLRD1) && Monst->_mgoal == MGOAL_TALKING) { - Monst->_msquelch = UINT8_MAX; - Monst->mtalkmsg = TEXT_NONE; - Monst->_mgoal = MGOAL_NORMAL; + if (monst->mtalkmsg == TEXT_WARLRD9 && monst->_mgoal == MGOAL_INQUIRING) + monst->_mmode = MM_TALK; + if (monst->mtalkmsg == TEXT_WARLRD9 && !effect_is_playing(USFX_WARLRD1) && monst->_mgoal == MGOAL_TALKING) { + monst->_msquelch = UINT8_MAX; + monst->mtalkmsg = TEXT_NONE; + monst->_mgoal = MGOAL_NORMAL; } } - if (Monst->_mgoal == MGOAL_NORMAL) + if (monst->_mgoal == MGOAL_NORMAL) MAI_SkelSd(i); - Monst->_mdir = md; + monst->_mdir = md; - Monst->CheckStandAnimationIsLoaded(Monst->_mdir); + monst->CheckStandAnimationIsLoaded(monst->_mdir); } void DeleteMonsterList() @@ -4359,27 +4356,27 @@ void ProcessMonsters() assert((DWORD)nummonsters <= MAXMONSTERS); for (int i = 0; i < nummonsters; i++) { int mi = monstactive[i]; - MonsterStruct *Monst = &monster[mi]; + MonsterStruct *monst = &monster[mi]; bool raflag = false; if (gbIsMultiplayer) { - SetRndSeed(Monst->_mAISeed); - Monst->_mAISeed = AdvanceRndSeed(); + SetRndSeed(monst->_mAISeed); + monst->_mAISeed = AdvanceRndSeed(); } - if ((monster[mi]._mFlags & MFLAG_NOHEAL) == 0 && Monst->_mhitpoints < Monst->_mmaxhp && Monst->_mhitpoints >> 6 > 0) { - if (Monst->mLevel > 1) { - Monst->_mhitpoints += Monst->mLevel / 2; + if ((monster[mi]._mFlags & MFLAG_NOHEAL) == 0 && monst->_mhitpoints < monst->_mmaxhp && monst->_mhitpoints >> 6 > 0) { + if (monst->mLevel > 1) { + monst->_mhitpoints += monst->mLevel / 2; } else { - Monst->_mhitpoints += Monst->mLevel; + monst->_mhitpoints += monst->mLevel; } } - int mx = Monst->position.tile.x; - int my = Monst->position.tile.y; + int mx = monst->position.tile.x; + int my = monst->position.tile.y; - if ((dFlags[mx][my] & BFLAG_VISIBLE) != 0 && Monst->_msquelch == 0) { - if (Monst->MType->mtype == MT_CLEAVER) { + if ((dFlags[mx][my] & BFLAG_VISIBLE) != 0 && monst->_msquelch == 0) { + if (monst->MType->mtype == MT_CLEAVER) { PlaySFX(USFX_CLEAVER); } - if (Monst->MType->mtype == MT_NAKRUL) { + if (monst->MType->mtype == MT_NAKRUL) { if (sgGameInitInfo.bCowQuest != 0) { PlaySFX(USFX_NAKRUL6); } else { @@ -4389,42 +4386,42 @@ void ProcessMonsters() PlaySFX(USFX_NAKRUL5); } } - if (Monst->MType->mtype == MT_DEFILER) + if (monst->MType->mtype == MT_DEFILER) PlaySFX(USFX_DEFILER8); M_Enemy(mi); } int menemy; - if ((Monst->_mFlags & MFLAG_TARGETS_MONSTER) != 0) { - menemy = Monst->_menemy; + if ((monst->_mFlags & MFLAG_TARGETS_MONSTER) != 0) { + menemy = monst->_menemy; assurance((DWORD)menemy < MAXMONSTERS, menemy); - Monst->position.last = monster[Monst->_menemy].position.future; - Monst->enemyPosition = Monst->position.last; + monst->position.last = monster[monst->_menemy].position.future; + monst->enemyPosition = monst->position.last; } else { - menemy = Monst->_menemy; + menemy = monst->_menemy; assurance((DWORD)menemy < MAX_PLRS, menemy); - Monst->enemyPosition = plr[Monst->_menemy].position.future; + monst->enemyPosition = plr[monst->_menemy].position.future; if ((dFlags[mx][my] & BFLAG_VISIBLE) != 0) { - Monst->_msquelch = UINT8_MAX; - Monst->position.last = plr[Monst->_menemy].position.future; - } else if (Monst->_msquelch != 0 && Monst->MType->mtype != MT_DIABLO) { /// BUGFIX: change '_mAi' to 'MType->mtype' - Monst->_msquelch--; + monst->_msquelch = UINT8_MAX; + monst->position.last = plr[monst->_menemy].position.future; + } else if (monst->_msquelch != 0 && monst->MType->mtype != MT_DIABLO) { /// BUGFIX: change '_mAi' to 'MType->mtype' + monst->_msquelch--; } } do { - if ((Monst->_mFlags & MFLAG_SEARCH) == 0) { - AiProc[Monst->_mAi](mi); + if ((monst->_mFlags & MFLAG_SEARCH) == 0) { + AiProc[monst->_mAi](mi); } else if (!MAI_Path(mi)) { - AiProc[Monst->_mAi](mi); + AiProc[monst->_mAi](mi); } - switch (Monst->_mmode) { + switch (monst->_mmode) { case MM_STAND: raflag = M_DoStand(mi); break; case MM_WALK: case MM_WALK2: case MM_WALK3: - raflag = M_DoWalk(mi, Monst->_mmode); + raflag = M_DoWalk(mi, monst->_mmode); break; case MM_ATTACK: raflag = M_DoAttack(mi); @@ -4473,8 +4470,8 @@ void ProcessMonsters() GroupUnity(mi); } } while (raflag); - if (Monst->_mmode != MM_STONE) { - Monst->AnimInfo.ProcessAnimation((Monst->_mFlags & MFLAG_LOCK_ANIMATION) != 0, (Monst->_mFlags & MFLAG_ALLOW_SPECIAL) != 0); + if (monst->_mmode != MM_STONE) { + monst->AnimInfo.ProcessAnimation((monst->_mFlags & MFLAG_LOCK_ANIMATION) != 0, (monst->_mFlags & MFLAG_ALLOW_SPECIAL) != 0); } } @@ -4848,35 +4845,35 @@ void MissToMonst(int i, Point position) { assurance((DWORD)i < MAXMISSILES, i); - MissileStruct *Miss = &missile[i]; - int m = Miss->_misource; + MissileStruct *miss = &missile[i]; + int m = miss->_misource; assurance((DWORD)m < MAXMONSTERS, m); - MonsterStruct *Monst = &monster[m]; - Point oldPosition = Miss->position.tile; + MonsterStruct *monst = &monster[m]; + Point oldPosition = miss->position.tile; dMonster[position.x][position.y] = m + 1; - Monst->_mdir = static_cast(Miss->_mimfnum); - Monst->position.tile = position; - M_StartStand(m, Monst->_mdir); - if (Monst->MType->mtype < MT_INCIN || Monst->MType->mtype > MT_HELLBURN) { - if ((Monst->_mFlags & MFLAG_TARGETS_MONSTER) == 0) + monst->_mdir = static_cast(miss->_mimfnum); + monst->position.tile = position; + M_StartStand(m, monst->_mdir); + if (monst->MType->mtype < MT_INCIN || monst->MType->mtype > MT_HELLBURN) { + if ((monst->_mFlags & MFLAG_TARGETS_MONSTER) == 0) M_StartHit(m, -1, 0); else M2MStartHit(m, -1, 0); } else { - M_StartFadein(m, Monst->_mdir, false); + M_StartFadein(m, monst->_mdir, false); } - if ((Monst->_mFlags & MFLAG_TARGETS_MONSTER) == 0) { + if ((monst->_mFlags & MFLAG_TARGETS_MONSTER) == 0) { int pnum = dPlayer[oldPosition.x][oldPosition.y] - 1; if (dPlayer[oldPosition.x][oldPosition.y] > 0) { - if (Monst->MType->mtype != MT_GLOOM && (Monst->MType->mtype < MT_INCIN || Monst->MType->mtype > MT_HELLBURN)) { - M_TryH2HHit(m, dPlayer[oldPosition.x][oldPosition.y] - 1, 500, Monst->mMinDamage2, Monst->mMaxDamage2); - if (pnum == dPlayer[oldPosition.x][oldPosition.y] - 1 && (Monst->MType->mtype < MT_NSNAKE || Monst->MType->mtype > MT_GSNAKE)) { + if (monst->MType->mtype != MT_GLOOM && (monst->MType->mtype < MT_INCIN || monst->MType->mtype > MT_HELLBURN)) { + M_TryH2HHit(m, dPlayer[oldPosition.x][oldPosition.y] - 1, 500, monst->mMinDamage2, monst->mMaxDamage2); + if (pnum == dPlayer[oldPosition.x][oldPosition.y] - 1 && (monst->MType->mtype < MT_NSNAKE || monst->MType->mtype > MT_GSNAKE)) { if (plr[pnum]._pmode != PM_GOTHIT && plr[pnum]._pmode != PM_DEATH) StartPlrHit(pnum, 0, true); - Point newPosition = oldPosition + Monst->_mdir; + Point newPosition = oldPosition + monst->_mdir; if (PosOkPlayer(pnum, newPosition)) { plr[pnum].position.tile = newPosition; FixPlayerLocation(pnum, plr[pnum]._pdir); @@ -4891,10 +4888,10 @@ void MissToMonst(int i, Point position) } if (dMonster[oldPosition.x][oldPosition.y] > 0) { - if (Monst->MType->mtype != MT_GLOOM && (Monst->MType->mtype < MT_INCIN || Monst->MType->mtype > MT_HELLBURN)) { - M_TryM2MHit(m, dMonster[oldPosition.x][oldPosition.y] - 1, 500, Monst->mMinDamage2, Monst->mMaxDamage2); - if (Monst->MType->mtype < MT_NSNAKE || Monst->MType->mtype > MT_GSNAKE) { - Point newPosition = oldPosition + Monst->_mdir; + if (monst->MType->mtype != MT_GLOOM && (monst->MType->mtype < MT_INCIN || monst->MType->mtype > MT_HELLBURN)) { + M_TryM2MHit(m, dMonster[oldPosition.x][oldPosition.y] - 1, 500, monst->mMinDamage2, monst->mMaxDamage2); + if (monst->MType->mtype < MT_NSNAKE || monst->MType->mtype > MT_GSNAKE) { + Point newPosition = oldPosition + monst->_mdir; if (PosOkMonst(dMonster[oldPosition.x][oldPosition.y] - 1, newPosition)) { m = dMonster[oldPosition.x][oldPosition.y]; dMonster[newPosition.x][newPosition.y] = m; @@ -5102,24 +5099,24 @@ void TalktoMonster(int i) { assurance((DWORD)i < MAXMONSTERS, i); - MonsterStruct *Monst = &monster[i]; - int pnum = Monst->_menemy; - Monst->_mmode = MM_TALK; - if (Monst->_mAi != AI_SNOTSPIL && Monst->_mAi != AI_LACHDAN) { + MonsterStruct *monst = &monster[i]; + int pnum = monst->_menemy; + monst->_mmode = MM_TALK; + if (monst->_mAi != AI_SNOTSPIL && monst->_mAi != AI_LACHDAN) { return; } if (QuestStatus(Q_LTBANNER) && quests[Q_LTBANNER]._qvar1 == 2) { if (plr[pnum].TryRemoveInvItemById(IDI_BANNER)) { quests[Q_LTBANNER]._qactive = QUEST_DONE; - Monst->mtalkmsg = TEXT_BANNER12; - Monst->_mgoal = MGOAL_INQUIRING; + monst->mtalkmsg = TEXT_BANNER12; + monst->_mgoal = MGOAL_INQUIRING; } } - if (QuestStatus(Q_VEIL) && Monst->mtalkmsg >= TEXT_VEIL9) { + if (QuestStatus(Q_VEIL) && monst->mtalkmsg >= TEXT_VEIL9) { if (plr[pnum].TryRemoveInvItemById(IDI_GLDNELIX)) { - Monst->mtalkmsg = TEXT_VEIL11; - Monst->_mgoal = MGOAL_INQUIRING; + monst->mtalkmsg = TEXT_VEIL11; + monst->_mgoal = MGOAL_INQUIRING; } } } diff --git a/Source/movie.cpp b/Source/movie.cpp index 09d69dc58..2811a6a32 100644 --- a/Source/movie.cpp +++ b/Source/movie.cpp @@ -37,14 +37,14 @@ void play_movie(const char *pszMovie, bool userCanClose) #endif if (SVidPlayBegin(pszMovie, loop_movie ? 0x100C0808 : 0x10280808)) { - tagMSG Msg; + tagMSG msg; while (movie_playing) { - while (movie_playing && FetchMessage(&Msg)) { - switch (Msg.message) { + while (movie_playing && FetchMessage(&msg)) { + switch (msg.message) { case DVL_WM_KEYDOWN: case DVL_WM_LBUTTONDOWN: case DVL_WM_RBUTTONDOWN: - if (userCanClose || (Msg.message == DVL_WM_KEYDOWN && Msg.wParam == DVL_VK_ESCAPE)) + if (userCanClose || (msg.message == DVL_WM_KEYDOWN && msg.wParam == DVL_VK_ESCAPE)) movie_playing = false; break; case DVL_WM_QUIT: diff --git a/Source/mpqapi.cpp b/Source/mpqapi.cpp index 09b7c0d5a..3da0552a8 100644 --- a/Source/mpqapi.cpp +++ b/Source/mpqapi.cpp @@ -158,12 +158,12 @@ private: bool CheckError(const char *fmt, PrintFArgs... args) { if (s_->fail()) { - std::string fmt_with_error = fmt; - fmt_with_error.append(": failed with \"{}\""); - const char *error_message = std::strerror(errno); - if (error_message == nullptr) - error_message = ""; - LogError(LogCategory::System, fmt_with_error.c_str(), args..., error_message); + std::string fmtWithError = fmt; + fmtWithError.append(": failed with \"{}\""); + const char *errorMessage = std::strerror(errno); + if (errorMessage == nullptr) + errorMessage = ""; + LogError(LogCategory::System, fmtWithError.c_str(), args..., errorMessage); #ifdef _DEBUG } else { LogVerbose(LogCategory::System, fmt, args...); @@ -338,13 +338,13 @@ bool IsValidMPQHeader(const Archive &archive, _FILEHEADER *hdr) bool ReadMPQHeader(Archive *archive, _FILEHEADER *hdr) { - const bool has_hdr = archive->size >= sizeof(*hdr); - if (has_hdr) { + const bool hasHdr = archive->size >= sizeof(*hdr); + if (hasHdr) { if (!archive->stream.Read(reinterpret_cast(hdr), sizeof(*hdr))) return false; ByteSwapHdr(hdr); } - if (!has_hdr || !IsValidMPQHeader(*archive, hdr)) { + if (!hasHdr || !IsValidMPQHeader(*archive, hdr)) { InitDefaultMpqHeader(archive, hdr); } return true; @@ -509,19 +509,19 @@ bool WriteFileContents(const char *pszName, const byte *pbData, size_t dwLen, _B Hash(pszName, 3); constexpr size_t SectorSize = 4096; - const uint32_t num_sectors = (dwLen + (SectorSize - 1)) / SectorSize; - const uint32_t offset_table_bytesize = sizeof(uint32_t) * (num_sectors + 1); - pBlk->offset = FindFreeBlock(dwLen + offset_table_bytesize, &pBlk->sizealloc); + const uint32_t numSectors = (dwLen + (SectorSize - 1)) / SectorSize; + const uint32_t offsetTableByteSize = sizeof(uint32_t) * (numSectors + 1); + pBlk->offset = FindFreeBlock(dwLen + offsetTableByteSize, &pBlk->sizealloc); pBlk->sizefile = dwLen; pBlk->flags = 0x80000100; // We populate the table of sector offset while we write the data. // We can't pre-populate it because we don't know the compressed sector sizes yet. // First offset is the start of the first sector, last offset is the end of the last sector. - std::unique_ptr sectoroffsettable { new uint32_t[num_sectors + 1] }; + std::unique_ptr sectoroffsettable { new uint32_t[numSectors + 1] }; #ifdef CAN_SEEKP_BEYOND_EOF - if (!cur_archive.stream.Seekp(pBlk->offset + offset_table_bytesize, std::ios::beg)) + if (!cur_archive.stream.Seekp(pBlk->offset + offsetTableByteSize, std::ios::beg)) return false; #else // Ensure we do not Seekp beyond EOF by filling the missing space. @@ -529,31 +529,31 @@ bool WriteFileContents(const char *pszName, const byte *pbData, size_t dwLen, _B if (!cur_archive.stream.Seekp(0, std::ios::end) || !cur_archive.stream.Tellp(&stream_end)) return false; const std::uintmax_t cur_size = stream_end - cur_archive.stream_begin; - if (cur_size < pBlk->offset + offset_table_bytesize) { + if (cur_size < pBlk->offset + offsetTableByteSize) { if (cur_size < pBlk->offset) { std::unique_ptr filler { new char[pBlk->offset - cur_size] }; if (!cur_archive.stream.Write(filler.get(), pBlk->offset - cur_size)) return false; } - if (!cur_archive.stream.Write(reinterpret_cast(sectoroffsettable.get()), offset_table_bytesize)) + if (!cur_archive.stream.Write(reinterpret_cast(sectoroffsettable.get()), offsetTableByteSize)) return false; } else { - if (!cur_archive.stream.Seekp(pBlk->offset + offset_table_bytesize, std::ios::beg)) + if (!cur_archive.stream.Seekp(pBlk->offset + offsetTableByteSize, std::ios::beg)) return false; } #endif - uint32_t destsize = offset_table_bytesize; - byte mpq_buf[SectorSize]; - std::size_t cur_sector = 0; + uint32_t destsize = offsetTableByteSize; + byte mpqBuf[SectorSize]; + std::size_t curSector = 0; while (true) { uint32_t len = std::min(dwLen, SectorSize); - memcpy(mpq_buf, pbData, len); + memcpy(mpqBuf, pbData, len); pbData += len; - len = PkwareCompress(mpq_buf, len); - if (!cur_archive.stream.Write((char *)mpq_buf, len)) + len = PkwareCompress(mpqBuf, len); + if (!cur_archive.stream.Write((char *)mpqBuf, len)) return false; - sectoroffsettable[cur_sector++] = SDL_SwapLE32(destsize); + sectoroffsettable[curSector++] = SDL_SwapLE32(destsize); destsize += len; // compressed length if (dwLen > SectorSize) dwLen -= SectorSize; @@ -561,19 +561,19 @@ bool WriteFileContents(const char *pszName, const byte *pbData, size_t dwLen, _B break; } - sectoroffsettable[num_sectors] = SDL_SwapLE32(destsize); + sectoroffsettable[numSectors] = SDL_SwapLE32(destsize); if (!cur_archive.stream.Seekp(pBlk->offset, std::ios::beg)) return false; - if (!cur_archive.stream.Write(reinterpret_cast(sectoroffsettable.get()), offset_table_bytesize)) + if (!cur_archive.stream.Write(reinterpret_cast(sectoroffsettable.get()), offsetTableByteSize)) return false; - if (!cur_archive.stream.Seekp(destsize - offset_table_bytesize, std::ios::cur)) + if (!cur_archive.stream.Seekp(destsize - offsetTableByteSize, std::ios::cur)) return false; if (destsize < pBlk->sizealloc) { - const uint32_t block_size = pBlk->sizealloc - destsize; - if (block_size >= 1024) { + const uint32_t blockSize = pBlk->sizealloc - destsize; + if (blockSize >= 1024) { pBlk->sizealloc = destsize; - AllocBlock(pBlk->sizealloc + pBlk->offset, block_size); + AllocBlock(pBlk->sizealloc + pBlk->offset, blockSize); } } return true; @@ -591,10 +591,10 @@ void mpqapi_remove_hash_entry(const char *pszName) _HASHENTRY *pHashTbl = &cur_archive.sgpHashTbl[hIdx]; _BLOCKENTRY *blockEntry = &cur_archive.sgpBlockTbl[pHashTbl->block]; pHashTbl->block = -2; - int block_offset = blockEntry->offset; - int block_size = blockEntry->sizealloc; + int blockOffset = blockEntry->offset; + int blockSize = blockEntry->sizealloc; memset(blockEntry, 0, sizeof(*blockEntry)); - AllocBlock(block_offset, block_size); + AllocBlock(blockOffset, blockSize); cur_archive.modified = true; } @@ -690,13 +690,13 @@ bool OpenMPQ(const char *pszArchive) } return true; on_error: - cur_archive.Close(/*clear_tables=*/true); + cur_archive.Close(/*clearTables=*/true); return false; } bool mpqapi_flush_and_close(bool bFree) { - return cur_archive.Close(/*clear_tables=*/bFree); + return cur_archive.Close(/*clearTables=*/bFree); } } // namespace devilution diff --git a/Source/msg.cpp b/Source/msg.cpp index 18f6ceb30..cc2f8751d 100644 --- a/Source/msg.cpp +++ b/Source/msg.cpp @@ -543,15 +543,15 @@ void CheckUpdatePlayer(int pnum) void PlayerMessageFormat(const char *pszFmt, ...) { - static DWORD msg_err_timer; + static DWORD msgErrTimer; DWORD ticks; char msg[256]; va_list va; va_start(va, pszFmt); ticks = SDL_GetTicks(); - if (ticks - msg_err_timer >= 5000) { - msg_err_timer = ticks; + if (ticks - msgErrTimer >= 5000) { + msgErrTimer = ticks; vsprintf(msg, pszFmt, va); ErrorPlrMsg(msg); } diff --git a/Source/multi.cpp b/Source/multi.cpp index e9f191a2b..a5ad9dc0a 100644 --- a/Source/multi.cpp +++ b/Source/multi.cpp @@ -91,21 +91,21 @@ void CopyPacket(TBuffer *buf, byte *packet, uint8_t size) byte *ReceivePacket(TBuffer *pBuf, byte *body, size_t *size) { if (pBuf->dwNextWriteOffset != 0) { - byte *src_ptr = pBuf->bData; + byte *srcPtr = pBuf->bData; while (true) { - auto chunk_size = static_cast(*src_ptr); - if (chunk_size == 0) + auto chunkSize = static_cast(*srcPtr); + if (chunkSize == 0) break; - if (chunk_size > *size) + if (chunkSize > *size) break; - src_ptr++; - memcpy(body, src_ptr, chunk_size); - body += chunk_size; - src_ptr += chunk_size; - *size -= chunk_size; + srcPtr++; + memcpy(body, srcPtr, chunkSize); + body += chunkSize; + srcPtr += chunkSize; + *size -= chunkSize; } - memcpy(pBuf->bData, src_ptr, (pBuf->bData - src_ptr) + pBuf->dwNextWriteOffset + 1); - pBuf->dwNextWriteOffset += (pBuf->bData - src_ptr); + memcpy(pBuf->bData, srcPtr, (pBuf->bData - srcPtr) + pBuf->dwNextWriteOffset + 1); + pBuf->dwNextWriteOffset += (pBuf->bData - srcPtr); return body; } return body; @@ -367,7 +367,7 @@ void SetupLocalPositions() void HandleEvents(_SNETEVENT *pEvt) { - DWORD LeftReason; + DWORD leftReason; switch (pEvt->eventid) { case EVENT_TYPE_PLAYER_CREATE_GAME: { @@ -382,11 +382,11 @@ void HandleEvents(_SNETEVENT *pEvt) sgbPlayerLeftGameTbl[pEvt->playerid] = true; sgbPlayerTurnBitTbl[pEvt->playerid] = false; - LeftReason = 0; + leftReason = 0; if (pEvt->data != nullptr && pEvt->databytes >= sizeof(DWORD)) - LeftReason = *(DWORD *)pEvt->data; - sgdwPlayerLeftReasonTbl[pEvt->playerid] = LeftReason; - if (LeftReason == LEAVE_ENDING) + leftReason = *(DWORD *)pEvt->data; + sgdwPlayerLeftReasonTbl[pEvt->playerid] = leftReason; + if (leftReason == LEAVE_ENDING) gbSomebodyWonGameKludge = true; sgbSendDeltaTbl[pEvt->playerid] = false; @@ -487,9 +487,9 @@ void NetSendHiPri(int playerId, byte *pbMsg, BYTE bLen) TPkt pkt; NetReceivePlayerData(&pkt); size_t size = gdwNormalMsgSize - sizeof(TPktHdr); - byte *hipri_body = ReceivePacket(&sgHiPriBuf, pkt.body, &size); - byte *lowpri_body = ReceivePacket(&sgLoPriBuf, hipri_body, &size); - size = sync_all_monsters(lowpri_body, size); + byte *hipriBody = ReceivePacket(&sgHiPriBuf, pkt.body, &size); + byte *lowpriBody = ReceivePacket(&sgLoPriBuf, hipriBody, &size); + size = sync_all_monsters(lowpriBody, size); size_t len = gdwNormalMsgSize - size; pkt.hdr.wLen = len; if (!SNetSendMessage(-2, &pkt.hdr, len)) diff --git a/Source/nthread.cpp b/Source/nthread.cpp index b59f81d35..0aa5c41b8 100644 --- a/Source/nthread.cpp +++ b/Source/nthread.cpp @@ -58,9 +58,9 @@ uint32_t nthread_send_and_recv_turn(uint32_t curTurn, int turnDelta) } while (curTurnsInTransit++ < gdwTurnsInTransit) { - int turn_tmp = turn_upper_bit | (curTurn & 0x7FFFFFFF); + int turnTmp = turn_upper_bit | (curTurn & 0x7FFFFFFF); turn_upper_bit = 0; - int turn = turn_tmp; + int turn = turnTmp; if (!SNetSendTurn((char *)&turn, sizeof(turn))) { nthread_terminate_game("SNetSendTurn"); diff --git a/Source/objects.cpp b/Source/objects.cpp index 9b9c4e7ec..10d081d8c 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -671,9 +671,9 @@ void AddObjTraps() continue; AddObject(OBJ_TRAPL, xp, j); - int8_t oi_trap = dObject[xp][j] - 1; - object[oi_trap]._oVar1 = i; - object[oi_trap]._oVar2 = j; + int8_t oiTrap = dObject[xp][j] - 1; + object[oiTrap]._oVar1 = i; + object[oiTrap]._oVar2 = j; object[oi]._oTrapFlag = true; } else { int yp = j - 1; @@ -684,9 +684,9 @@ void AddObjTraps() continue; AddObject(OBJ_TRAPR, i, yp); - int8_t oi_trap = dObject[i][yp] - 1; - object[oi_trap]._oVar1 = i; - object[oi_trap]._oVar2 = j; + int8_t oiTrap = dObject[i][yp] - 1; + object[oiTrap]._oVar1 = i; + object[oiTrap]._oVar2 = j; object[oi]._oTrapFlag = true; } } @@ -1040,55 +1040,55 @@ void InitObjects() AddL2Objs(0, 0, MAXDUNX, MAXDUNY); AddL2Torches(); if (QuestStatus(Q_BLIND)) { - _speech_id sp_id; + _speech_id spId; switch (plr[myplr]._pClass) { case HeroClass::Warrior: - sp_id = TEXT_BLINDING; + spId = TEXT_BLINDING; break; case HeroClass::Rogue: - sp_id = TEXT_RBLINDING; + spId = TEXT_RBLINDING; break; case HeroClass::Sorcerer: - sp_id = TEXT_MBLINDING; + spId = TEXT_MBLINDING; break; case HeroClass::Monk: - sp_id = TEXT_HBLINDING; + spId = TEXT_HBLINDING; break; case HeroClass::Bard: - sp_id = TEXT_BBLINDING; + spId = TEXT_BBLINDING; break; case HeroClass::Barbarian: - sp_id = TEXT_BLINDING; + spId = TEXT_BLINDING; break; } - quests[Q_BLIND]._qmsg = sp_id; - AddBookLever(setpc_x, setpc_y, setpc_w + setpc_x + 1, setpc_h + setpc_y + 1, sp_id); + quests[Q_BLIND]._qmsg = spId; + AddBookLever(setpc_x, setpc_y, setpc_w + setpc_x + 1, setpc_h + setpc_y + 1, spId); LoadMapObjs("Levels\\L2Data\\Blind2.DUN", 2 * setpc_x, 2 * setpc_y); } if (QuestStatus(Q_BLOOD)) { - _speech_id sp_id; + _speech_id spId; switch (plr[myplr]._pClass) { case HeroClass::Warrior: - sp_id = TEXT_BLOODY; + spId = TEXT_BLOODY; break; case HeroClass::Rogue: - sp_id = TEXT_RBLOODY; + spId = TEXT_RBLOODY; break; case HeroClass::Sorcerer: - sp_id = TEXT_MBLOODY; + spId = TEXT_MBLOODY; break; case HeroClass::Monk: - sp_id = TEXT_HBLOODY; + spId = TEXT_HBLOODY; break; case HeroClass::Bard: - sp_id = TEXT_BBLOODY; + spId = TEXT_BBLOODY; break; case HeroClass::Barbarian: - sp_id = TEXT_BLOODY; + spId = TEXT_BLOODY; break; } - quests[Q_BLOOD]._qmsg = sp_id; - AddBookLever(setpc_x, setpc_y + 3, setpc_x + 2, setpc_y + 7, sp_id); + quests[Q_BLOOD]._qmsg = spId; + AddBookLever(setpc_x, setpc_y + 3, setpc_x + 2, setpc_y + 7, spId); AddObject(OBJ_PEDISTAL, 2 * setpc_x + 25, 2 * setpc_y + 32); } InitRndBarrels(); @@ -1099,29 +1099,29 @@ void InitObjects() } if (leveltype == DTYPE_HELL) { if (QuestStatus(Q_WARLORD)) { - _speech_id sp_id; + _speech_id spId; switch (plr[myplr]._pClass) { case HeroClass::Warrior: - sp_id = TEXT_BLOODWAR; + spId = TEXT_BLOODWAR; break; case HeroClass::Rogue: - sp_id = TEXT_RBLOODWAR; + spId = TEXT_RBLOODWAR; break; case HeroClass::Sorcerer: - sp_id = TEXT_MBLOODWAR; + spId = TEXT_MBLOODWAR; break; case HeroClass::Monk: - sp_id = TEXT_HBLOODWAR; + spId = TEXT_HBLOODWAR; break; case HeroClass::Bard: - sp_id = TEXT_BBLOODWAR; + spId = TEXT_BBLOODWAR; break; case HeroClass::Barbarian: - sp_id = TEXT_BLOODWAR; + spId = TEXT_BLOODWAR; break; } - quests[Q_WARLORD]._qmsg = sp_id; - AddBookLever(setpc_x, setpc_y, setpc_x + setpc_w, setpc_y + setpc_h, sp_id); + quests[Q_WARLORD]._qmsg = spId; + AddBookLever(setpc_x, setpc_y, setpc_x + setpc_w, setpc_y + setpc_h, spId); LoadMapObjs("Levels\\L4Data\\Warlord.DUN", 2 * setpc_x, 2 * setpc_y); } if (QuestStatus(Q_BETRAYER) && !gbIsMultiplayer) @@ -2054,9 +2054,9 @@ void Obj_BCrossDamage(int i) if (plr[myplr]._pmode == PM_DEATH) return; - int fire_resist = plr[myplr]._pFireResist; - if (fire_resist > 0) - damage[leveltype - 1] -= fire_resist * damage[leveltype - 1] / 100; + int fireResist = plr[myplr]._pFireResist; + if (fireResist > 0) + damage[leveltype - 1] -= fireResist * damage[leveltype - 1] / 100; if (plr[myplr].position.tile.x != object[i].position.x || plr[myplr].position.tile.y != object[i].position.y - 1) return; @@ -2812,8 +2812,8 @@ void OperateBook(int pnum, int i) if (object[i]._oSelFlag == 0) return; if (setlevel && setlvlnum == SL_VILEBETRAYER) { - bool do_add_missile = false; - bool missile_added = false; + bool doAddMissile = false; + bool missileAdded = false; for (int j = 0; j < nobjects; j++) { int oi = objectactive[j]; int otype = object[oi]._otype; @@ -2821,22 +2821,22 @@ void OperateBook(int pnum, int i) dx = 27; dy = 29; object[oi]._oVar6 = 4; - do_add_missile = true; + doAddMissile = true; } if (otype == OBJ_MCIRCLE2 && object[oi]._oVar6 == 2) { dx = 43; dy = 29; object[oi]._oVar6 = 4; - do_add_missile = true; + doAddMissile = true; } - if (do_add_missile) { + if (doAddMissile) { object[dObject[35][36] - 1]._oVar5++; AddMissile(plr[pnum].position.tile, { dx, dy }, plr[pnum]._pdir, MIS_RNDTELEPORT, TARGET_MONSTERS, pnum, 0, 0); - missile_added = true; - do_add_missile = false; + missileAdded = true; + doAddMissile = false; } } - if (!missile_added) + if (!missileAdded) return; } object[i]._oSelFlag = 0; @@ -4809,12 +4809,12 @@ void SyncOpL1Door(int pnum, int cmd, int i) if (pnum == myplr) return; - bool do_sync = false; + bool doSync = false; if (cmd == CMD_OPENDOOR && object[i]._oVar4 == 0) - do_sync = true; + doSync = true; if (cmd == CMD_CLOSEDOOR && object[i]._oVar4 == 1) - do_sync = true; - if (!do_sync) + doSync = true; + if (!doSync) return; if (object[i]._otype == OBJ_L1LDOOR) @@ -4828,12 +4828,12 @@ void SyncOpL2Door(int pnum, int cmd, int i) if (pnum == myplr) return; - bool do_sync = false; + bool doSync = false; if (cmd == CMD_OPENDOOR && object[i]._oVar4 == 0) - do_sync = true; + doSync = true; if (cmd == CMD_CLOSEDOOR && object[i]._oVar4 == 1) - do_sync = true; - if (!do_sync) + doSync = true; + if (!doSync) return; if (object[i]._otype == OBJ_L2LDOOR) @@ -4847,12 +4847,12 @@ void SyncOpL3Door(int pnum, int cmd, int i) if (pnum == myplr) return; - bool do_sync = false; + bool doSync = false; if (cmd == CMD_OPENDOOR && object[i]._oVar4 == 0) - do_sync = true; + doSync = true; if (cmd == CMD_CLOSEDOOR && object[i]._oVar4 == 1) - do_sync = true; - if (!do_sync) + doSync = true; + if (!doSync) return; if (object[i]._otype == OBJ_L3LDOOR) diff --git a/Source/palette.cpp b/Source/palette.cpp index 3496e46ec..7fe886167 100644 --- a/Source/palette.cpp +++ b/Source/palette.cpp @@ -50,14 +50,14 @@ void ApplyGamma(SDL_Color *dst, const SDL_Color *src, int n) static void LoadGamma() { - int gamma_value = sgOptions.Graphics.nGammaCorrection; + int gammaValue = sgOptions.Graphics.nGammaCorrection; - if (gamma_value < 30) { - gamma_value = 30; - } else if (gamma_value > 100) { - gamma_value = 100; + if (gammaValue < 30) { + gammaValue = 30; + } else if (gammaValue > 100) { + gammaValue = 100; } - sgOptions.Graphics.nGammaCorrection = gamma_value - gamma_value % 5; + sgOptions.Graphics.nGammaCorrection = gammaValue - gammaValue % 5; } void palette_init() @@ -136,14 +136,14 @@ void LoadPalette(const char *pszFileName, bool blend /*= true*/) uint8_t b; }; - std::array PalData; + std::array palData; - LoadFileInMem(pszFileName, PalData); + LoadFileInMem(pszFileName, palData); - for (unsigned i = 0; i < PalData.size(); i++) { - orig_palette[i].r = PalData[i].r; - orig_palette[i].g = PalData[i].g; - orig_palette[i].b = PalData[i].b; + for (unsigned i = 0; i < palData.size(); i++) { + orig_palette[i].r = palData[i].r; + orig_palette[i].g = palData[i].g; + orig_palette[i].b = palData[i].b; #ifndef USE_SDL1 orig_palette[i].a = SDL_ALPHA_OPAQUE; #endif diff --git a/Source/path.cpp b/Source/path.cpp index 7da24056b..5ff9a54e6 100644 --- a/Source/path.cpp +++ b/Source/path.cpp @@ -58,36 +58,36 @@ int FindPath(bool (*posOk)(int, Point), int posOkArg, int sx, int sy, int dx, in path_2_nodes = path_new_step(); pnode_ptr = path_new_step(); gdwCurPathStep = 0; - PATHNODE *path_start = path_new_step(); - path_start->g = 0; - path_start->h = path_get_h_cost(sx, sy, dx, dy); - path_start->position.x = sx; - path_start->f = path_start->h + path_start->g; - path_start->position.y = sy; - path_2_nodes->NextNode = path_start; + PATHNODE *pathStart = path_new_step(); + pathStart->g = 0; + pathStart->h = path_get_h_cost(sx, sy, dx, dy); + pathStart->position.x = sx; + pathStart->f = pathStart->h + pathStart->g; + pathStart->position.y = sy; + path_2_nodes->NextNode = pathStart; // A* search until we find (dx,dy) or fail - PATHNODE *next_node; - while ((next_node = GetNextPath()) != nullptr) { + PATHNODE *nextNode; + while ((nextNode = GetNextPath()) != nullptr) { // reached the end, success! - if (next_node->position.x == dx && next_node->position.y == dy) { - PATHNODE *current = next_node; - int path_length = 0; + if (nextNode->position.x == dx && nextNode->position.y == dy) { + PATHNODE *current = nextNode; + int pathLength = 0; while (current->Parent != nullptr) { - if (path_length >= MAX_PATH_LENGTH) + if (pathLength >= MAX_PATH_LENGTH) break; - pnode_vals[path_length++] = path_directions[3 * (current->position.y - current->Parent->position.y) - current->Parent->position.x + 4 + current->position.x]; + pnode_vals[pathLength++] = path_directions[3 * (current->position.y - current->Parent->position.y) - current->Parent->position.x + 4 + current->position.x]; current = current->Parent; } - if (path_length != MAX_PATH_LENGTH) { + if (pathLength != MAX_PATH_LENGTH) { int i; - for (i = 0; i < path_length; i++) - path[i] = pnode_vals[path_length - i - 1]; + for (i = 0; i < pathLength; i++) + path[i] = pnode_vals[pathLength - i - 1]; return i; } return 0; } // ran out of nodes, abort! - if (!path_get_path(posOk, posOkArg, next_node, dx, dy)) + if (!path_get_path(posOk, posOkArg, nextNode, dx, dy)) return 0; } // frontier is empty, no path! @@ -99,11 +99,11 @@ int FindPath(bool (*posOk)(int, Point), int posOkArg, int sx, int sy, int dx, in */ int path_get_h_cost(int sx, int sy, int dx, int dy) { - int delta_x = abs(sx - dx); - int delta_y = abs(sy - dy); + int deltaX = abs(sx - dx); + int deltaY = abs(sy - dy); - int min = delta_x < delta_y ? delta_x : delta_y; - int max = delta_x > delta_y ? delta_x : delta_y; + int min = deltaX < deltaY ? deltaX : deltaY; + int max = deltaX > deltaY ? deltaX : deltaY; // see path_check_equal for why this is times 2 return 2 * (min + max); @@ -199,11 +199,11 @@ bool path_get_path(bool (*posOk)(int, Point), int posOkArg, PATHNODE *pPath, int */ bool path_parent_path(PATHNODE *pPath, int dx, int dy, int sx, int sy) { - int next_g; + int nextG; PATHNODE *dxdy; int i; - next_g = pPath->g + path_check_equal(pPath, dx, dy); + nextG = pPath->g + path_check_equal(pPath, dx, dy); // 3 cases to consider // case 1: (dx,dy) is already on the frontier @@ -214,12 +214,12 @@ bool path_parent_path(PATHNODE *pPath, int dx, int dy, int sx, int sy) break; } pPath->Child[i] = dxdy; - if (next_g < dxdy->g) { + if (nextG < dxdy->g) { if (path_solid_pieces(pPath, dx, dy)) { // we'll explore it later, just update dxdy->Parent = pPath; - dxdy->g = next_g; - dxdy->f = next_g + dxdy->h; + dxdy->g = nextG; + dxdy->f = nextG + dxdy->h; } } } else { @@ -231,11 +231,11 @@ bool path_parent_path(PATHNODE *pPath, int dx, int dy, int sx, int sy) break; } pPath->Child[i] = dxdy; - if (next_g < dxdy->g && path_solid_pieces(pPath, dx, dy)) { + if (nextG < dxdy->g && path_solid_pieces(pPath, dx, dy)) { // update the node dxdy->Parent = pPath; - dxdy->g = next_g; - dxdy->f = next_g + dxdy->h; + dxdy->g = nextG; + dxdy->f = nextG + dxdy->h; // already explored, so re-update others starting from that node path_set_coords(dxdy); } @@ -245,9 +245,9 @@ bool path_parent_path(PATHNODE *pPath, int dx, int dy, int sx, int sy) if (dxdy == nullptr) return false; dxdy->Parent = pPath; - dxdy->g = next_g; + dxdy->g = nextG; dxdy->h = path_get_h_cost(dx, dy, sx, sy); - dxdy->f = next_g + dxdy->h; + dxdy->f = nextG + dxdy->h; dxdy->position = { dx, dy }; // add it to the frontier path_next_node(dxdy); @@ -317,25 +317,25 @@ void path_next_node(PATHNODE *pPath) */ void path_set_coords(PATHNODE *pPath) { - PATHNODE *PathOld; - PATHNODE *PathAct; + PATHNODE *pathOld; + PATHNODE *pathAct; int i; path_push_active_step(pPath); // while there are path nodes to check while (gdwCurPathStep > 0) { - PathOld = path_pop_active_step(); + pathOld = path_pop_active_step(); for (i = 0; i < 8; i++) { - PathAct = PathOld->Child[i]; - if (PathAct == nullptr) + pathAct = pathOld->Child[i]; + if (pathAct == nullptr) break; - if (PathOld->g + path_check_equal(PathOld, PathAct->position.x, PathAct->position.y) < PathAct->g) { - if (path_solid_pieces(PathOld, PathAct->position.x, PathAct->position.y)) { - PathAct->Parent = PathOld; - PathAct->g = PathOld->g + path_check_equal(PathOld, PathAct->position.x, PathAct->position.y); - PathAct->f = PathAct->g + PathAct->h; - path_push_active_step(PathAct); + if (pathOld->g + path_check_equal(pathOld, pathAct->position.x, pathAct->position.y) < pathAct->g) { + if (path_solid_pieces(pathOld, pathAct->position.x, pathAct->position.y)) { + pathAct->Parent = pathOld; + pathAct->g = pathOld->g + path_check_equal(pathOld, pathAct->position.x, pathAct->position.y); + pathAct->f = pathAct->g + pathAct->h; + path_push_active_step(pathAct); } } } @@ -347,9 +347,9 @@ void path_set_coords(PATHNODE *pPath) */ void path_push_active_step(PATHNODE *pPath) { - int stack_index = gdwCurPathStep; + int stackIndex = gdwCurPathStep; gdwCurPathStep++; - pnode_tblptr[stack_index] = pPath; + pnode_tblptr[stackIndex] = pPath; } /** @@ -366,15 +366,15 @@ PATHNODE *path_pop_active_step() */ PATHNODE *path_new_step() { - PATHNODE *new_node; + PATHNODE *newNode; if (gdwCurNodes == MAXPATHNODES) return nullptr; - new_node = &path_nodes[gdwCurNodes]; + newNode = &path_nodes[gdwCurNodes]; gdwCurNodes++; - memset(new_node, 0, sizeof(PATHNODE)); - return new_node; + memset(newNode, 0, sizeof(PATHNODE)); + return newNode; } } // namespace devilution diff --git a/Source/pfile.cpp b/Source/pfile.cpp index 22e2acaff..32ed6f597 100644 --- a/Source/pfile.cpp +++ b/Source/pfile.cpp @@ -55,9 +55,9 @@ std::string GetSavePath(uint32_t saveNum) } } - char save_num_str[21]; - snprintf(save_num_str, sizeof(save_num_str) / sizeof(char), "%i", saveNum); - path.append(save_num_str); + char saveNumStr[21]; + snprintf(saveNumStr, sizeof(saveNumStr) / sizeof(char), "%i", saveNum); + path.append(saveNumStr); path.append(ext); return path; } @@ -280,7 +280,7 @@ PFileScopedArchiveWriter::~PFileScopedArchiveWriter() void pfile_write_hero(bool writeGameData, bool clearTables) { - PFileScopedArchiveWriter scoped_writer(clearTables); + PFileScopedArchiveWriter scopedWriter(clearTables); if (writeGameData) { SaveGameData(); RenameTempToPerm(); @@ -338,20 +338,20 @@ bool pfile_ui_save_create(_uiheroinfo *heroinfo) { PkPlayerStruct pkplr; - uint32_t save_num = GetSaveNumberFromName(heroinfo->name); - if (save_num >= MAX_CHARACTERS) { - for (save_num = 0; save_num < MAX_CHARACTERS; save_num++) { - if (hero_names[save_num][0] == '\0') + uint32_t saveNum = GetSaveNumberFromName(heroinfo->name); + if (saveNum >= MAX_CHARACTERS) { + for (saveNum = 0; saveNum < MAX_CHARACTERS; saveNum++) { + if (hero_names[saveNum][0] == '\0') break; } - if (save_num >= MAX_CHARACTERS) + if (saveNum >= MAX_CHARACTERS) return false; } - if (!OpenArchive(save_num)) + if (!OpenArchive(saveNum)) return false; mpqapi_remove_hash_entries(GetFileName); - strncpy(hero_names[save_num], heroinfo->name, PLR_NAME_LEN); - hero_names[save_num][PLR_NAME_LEN - 1] = '\0'; + strncpy(hero_names[saveNum], heroinfo->name, PLR_NAME_LEN); + hero_names[saveNum][PLR_NAME_LEN - 1] = '\0'; auto &player = plr[0]; CreatePlayer(0, heroinfo->heroclass); @@ -371,10 +371,10 @@ bool pfile_ui_save_create(_uiheroinfo *heroinfo) bool pfile_delete_save(_uiheroinfo *heroInfo) { - uint32_t save_num = GetSaveNumberFromName(heroInfo->name); - if (save_num < MAX_CHARACTERS) { - hero_names[save_num][0] = '\0'; - RemoveFile(GetSavePath(save_num).c_str()); + uint32_t saveNum = GetSaveNumberFromName(heroInfo->name); + if (saveNum < MAX_CHARACTERS) { + hero_names[saveNum][0] = '\0'; + RemoveFile(GetSavePath(saveNum).c_str()); } return true; } @@ -384,8 +384,8 @@ void pfile_read_player_from_save(char name[16], int playerId) HANDLE archive; PkPlayerStruct pkplr; - uint32_t save_num = GetSaveNumberFromName(name); - archive = OpenSaveArchive(save_num); + uint32_t saveNum = GetSaveNumberFromName(name); + archive = OpenSaveArchive(saveNum); if (archive == nullptr) app_fatal("%s", _("Unable to open archive")); if (!ReadHero(archive, &pkplr)) @@ -410,13 +410,13 @@ bool LevelFileExists() GetPermLevelNames(szName); - uint32_t save_num = GetSaveNumberFromName(plr[myplr]._pName); - if (!OpenArchive(save_num)) + uint32_t saveNum = GetSaveNumberFromName(plr[myplr]._pName); + if (!OpenArchive(saveNum)) app_fatal("%s", _("Unable to read to save file archive")); - bool has_file = mpqapi_has_file(szName); + bool hasFile = mpqapi_has_file(szName); mpqapi_flush_and_close(true); - return has_file; + return hasFile; } void GetTempLevelNames(char *szTemp) @@ -429,14 +429,14 @@ void GetTempLevelNames(char *szTemp) void GetPermLevelNames(char *szPerm) { - uint32_t save_num = GetSaveNumberFromName(plr[myplr]._pName); + uint32_t saveNum = GetSaveNumberFromName(plr[myplr]._pName); GetTempLevelNames(szPerm); - if (!OpenArchive(save_num)) + if (!OpenArchive(saveNum)) app_fatal("%s", _("Unable to read to save file archive")); - bool has_file = mpqapi_has_file(szPerm); + bool hasFile = mpqapi_has_file(szPerm); mpqapi_flush_and_close(true); - if (!has_file) { + if (!hasFile) { if (setlevel) sprintf(szPerm, "perms%02d", setlvlnum); else @@ -449,8 +449,8 @@ void pfile_remove_temp_files() if (gbIsMultiplayer) return; - uint32_t save_num = GetSaveNumberFromName(plr[myplr]._pName); - if (!OpenArchive(save_num)) + uint32_t saveNum = GetSaveNumberFromName(plr[myplr]._pName); + if (!OpenArchive(saveNum)) app_fatal("%s", _("Unable to write to save file archive")); mpqapi_remove_hash_entries(GetTempSaveNames); mpqapi_flush_and_close(true); @@ -460,8 +460,8 @@ std::unique_ptr pfile_read(const char *pszName, size_t *pdwLen) { HANDLE archive; - uint32_t save_num = GetSaveNumberFromName(plr[myplr]._pName); - archive = OpenSaveArchive(save_num); + uint32_t saveNum = GetSaveNumberFromName(plr[myplr]._pName); + archive = OpenSaveArchive(saveNum); if (archive == nullptr) return nullptr; @@ -475,16 +475,16 @@ std::unique_ptr pfile_read(const char *pszName, size_t *pdwLen) void pfile_update(bool forceSave) { - static Uint32 save_prev_tc; + static Uint32 prevTick; if (!gbIsMultiplayer) return; Uint32 tick = SDL_GetTicks(); - if (!forceSave && tick - save_prev_tc <= 60000) + if (!forceSave && tick - prevTick <= 60000) return; - save_prev_tc = tick; + prevTick = tick; pfile_write_hero(); } diff --git a/Source/platform/ctr/asio/sys/socket.c b/Source/platform/ctr/asio/sys/socket.c index 7bb578b2b..30710ec66 100644 --- a/Source/platform/ctr/asio/sys/socket.c +++ b/Source/platform/ctr/asio/sys/socket.c @@ -83,7 +83,7 @@ ssize_t stream_sendmsg(int socket, const struct msghdr *message, int flags) ssize_t dgram_sendmsg(int socket, const struct msghdr *message, int flags) { - return ENOTSUP; + return ENOTSUP; } ssize_t sendmsg(int socket, const struct msghdr *message, int flags) diff --git a/Source/platform/switch/asio/sys/signal.c b/Source/platform/switch/asio/sys/signal.c index f7b4c077a..4b9c394d4 100644 --- a/Source/platform/switch/asio/sys/signal.c +++ b/Source/platform/switch/asio/sys/signal.c @@ -1,7 +1,7 @@ #include #include -int pthread_sigmask (int, const sigset_t *, sigset_t *) +int pthread_sigmask(int, const sigset_t *, sigset_t *) { - return ENOTSUP; + return ENOTSUP; } diff --git a/Source/player.cpp b/Source/player.cpp index 358ecc11c..29d02d48c 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -720,11 +720,11 @@ void NewPlrAnim(PlayerStruct &player, player_graphic graphic, Direction dir, int if (player.AnimationData[static_cast(graphic)].RawData == nullptr) LoadPlrGFX(player, graphic); - auto &CelSprites = player.AnimationData[static_cast(graphic)].CelSpritesForDirections; + auto &celSprites = player.AnimationData[static_cast(graphic)].CelSpritesForDirections; CelSprite *pCelSprite = nullptr; - if (CelSprites[dir]) - pCelSprite = &*CelSprites[dir]; + if (celSprites[dir]) + pCelSprite = &*celSprites[dir]; player.AnimInfo.SetNewAnimation(pCelSprite, numberOfFrames, delayLen, flags, numSkippedFrames, distributeFramesBeforeFrame); } @@ -1622,7 +1622,7 @@ void StartPlrHit(int pnum, int dam, bool forcehit) Direction pd = player._pdir; int skippedAnimationFrames = 0; - const int ZenFlags = ISPL_FASTRECOVER | ISPL_FASTERRECOVER | ISPL_FASTESTRECOVER; + constexpr int ZenFlags = ISPL_FASTRECOVER | ISPL_FASTERRECOVER | ISPL_FASTESTRECOVER; if ((player._pIFlags & ZenFlags) == ZenFlags) { // if multiple hitrecovery modes are present the skipping of frames can go so far, that they skip frames that would skip. so the additional skipping thats skipped. that means we can't add the different modes together. skippedAnimationFrames = 4; } else if ((player._pIFlags & ISPL_FASTESTRECOVER) != 0) { diff --git a/Source/plrmsg.cpp b/Source/plrmsg.cpp index 15e89ed69..7854b8945 100644 --- a/Source/plrmsg.cpp +++ b/Source/plrmsg.cpp @@ -26,17 +26,17 @@ void plrmsg_delay(bool delay) { int i; _plrmsg *pMsg; - static DWORD plrmsg_ticks; + static DWORD plrmsgTicks; if (delay) { - plrmsg_ticks = -SDL_GetTicks(); + plrmsgTicks = -SDL_GetTicks(); return; } - plrmsg_ticks += SDL_GetTicks(); + plrmsgTicks += SDL_GetTicks(); pMsg = plr_msgs; for (i = 0; i < PMSG_COUNT; i++, pMsg++) - pMsg->time += plrmsg_ticks; + pMsg->time += plrmsgTicks; } void ErrorPlrMsg(const char *pszMsg) diff --git a/Source/qol/xpbar.cpp b/Source/qol/xpbar.cpp index eeccc78f5..4f24e9e35 100644 --- a/Source/qol/xpbar.cpp +++ b/Source/qol/xpbar.cpp @@ -93,15 +93,15 @@ void DrawXPBar(const Surface &out) if (player._pExperience < prevXp) return; - uint64_t prevXpDelta_1 = player._pExperience - prevXp; + uint64_t prevXpDelta1 = player._pExperience - prevXp; uint64_t prevXpDelta = ExpLvlsTbl[charLevel] - prevXp; - uint64_t fullBar = BarWidth * prevXpDelta_1 / prevXpDelta; + uint64_t fullBar = BarWidth * prevXpDelta1 / prevXpDelta; // Figure out how much to fill the last pixel of the XP bar, to make it gradually appear with gained XP uint64_t onePx = prevXpDelta / BarWidth + 1; uint64_t lastFullPx = fullBar * prevXpDelta / BarWidth; - const uint64_t fade = (prevXpDelta_1 - lastFullPx) * (SilverGradient.size() - 1) / onePx; + const uint64_t fade = (prevXpDelta1 - lastFullPx) * (SilverGradient.size() - 1) / onePx; // Draw beginning of bar full brightness DrawBar(out, xPos, yPos, fullBar, SilverGradient); diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index 196ec03f8..f0b0a019c 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -957,53 +957,53 @@ static void DrawTileContent(const Surface &out, int x, int y, int sx, int sy, in */ static void Zoom(const Surface &out) { - int viewport_width = out.w(); - int viewport_offset_x = 0; + int viewportWidth = out.w(); + int viewportOffsetX = 0; if (CanPanelsCoverView()) { if (chrflag || questlog) { - viewport_width -= SPANEL_WIDTH; - viewport_offset_x = SPANEL_WIDTH; + viewportWidth -= SPANEL_WIDTH; + viewportOffsetX = SPANEL_WIDTH; } else if (invflag || sbookflag) { - viewport_width -= SPANEL_WIDTH; + viewportWidth -= SPANEL_WIDTH; } } // We round to even for the source width and height. // If the width / height was odd, we copy just one extra pixel / row later on. - const int src_width = (viewport_width + 1) / 2; - const int doubleable_width = viewport_width / 2; - const int src_height = (out.h() + 1) / 2; - const int doubleable_height = out.h() / 2; + const int srcWidth = (viewportWidth + 1) / 2; + const int doubleableWidth = viewportWidth / 2; + const int srcHeight = (out.h() + 1) / 2; + const int doubleableHeight = out.h() / 2; - BYTE *src = out.at(src_width - 1, src_height - 1); - BYTE *dst = out.at(viewport_offset_x + viewport_width - 1, out.h() - 1); - const bool odd_viewport_width = (viewport_width % 2) == 1; + BYTE *src = out.at(srcWidth - 1, srcHeight - 1); + BYTE *dst = out.at(viewportOffsetX + viewportWidth - 1, out.h() - 1); + const bool oddViewportWidth = (viewportWidth % 2) == 1; - for (int hgt = 0; hgt < doubleable_height; hgt++) { + for (int hgt = 0; hgt < doubleableHeight; hgt++) { // Double the pixels in the line. - for (int i = 0; i < doubleable_width; i++) { + for (int i = 0; i < doubleableWidth; i++) { *dst-- = *src; *dst-- = *src; --src; } // Copy a single extra pixel if the output width is odd. - if (odd_viewport_width) { + if (oddViewportWidth) { *dst-- = *src; --src; } // Skip the rest of the source line. - src -= (out.pitch() - src_width); + src -= (out.pitch() - srcWidth); // Double the line. - memcpy(dst - out.pitch() + 1, dst + 1, viewport_width); + memcpy(dst - out.pitch() + 1, dst + 1, viewportWidth); // Skip the rest of the destination line. - dst -= 2 * out.pitch() - viewport_width; + dst -= 2 * out.pitch() - viewportWidth; } if ((out.h() % 2) == 1) { - memcpy(dst - out.pitch() + 1, dst + 1, viewport_width); + memcpy(dst - out.pitch() + 1, dst + 1, viewportWidth); } } @@ -1431,7 +1431,7 @@ void EnableFrameCount() */ static void DrawFPS(const Surface &out) { - char String[12]; + char string[12]; if (!frameflag || !gbActive) { return; @@ -1445,8 +1445,8 @@ static void DrawFPS(const Surface &out) framerate = 1000 * frameend / frames; frameend = 0; } - snprintf(String, 12, "%i FPS", framerate); - DrawString(out, String, Point { 8, 65 }, UIS_RED); + snprintf(string, 12, "%i FPS", framerate); + DrawString(out, string, Point { 8, 65 }, UIS_RED); } /** @@ -1460,14 +1460,14 @@ static void DoBlitScreen(Sint16 dwX, Sint16 dwY, Uint16 dwWdt, Uint16 dwHgt) { // In SDL1 SDL_Rect x and y are Sint16. Cast explicitly to avoid a compiler warning. using CoordType = decltype(SDL_Rect {}.x); - SDL_Rect src_rect { + SDL_Rect srcRect { static_cast(dwX), static_cast(dwY), dwWdt, dwHgt }; - SDL_Rect dst_rect { dwX, dwY, dwWdt, dwHgt }; + SDL_Rect dstRect { dwX, dwY, dwWdt, dwHgt }; - BltFast(&src_rect, &dst_rect); + BltFast(&srcRect, &dstRect); } /** diff --git a/Source/sha.cpp b/Source/sha.cpp index f5f0107b1..6b98d8dc0 100644 --- a/Source/sha.cpp +++ b/Source/sha.cpp @@ -50,63 +50,63 @@ static void SHA1Init(SHA1Context *context) static void SHA1ProcessMessageBlock(SHA1Context *context) { - std::uint32_t W[80]; + std::uint32_t w[80]; auto *buf = (std::uint32_t *)context->buffer; for (int i = 0; i < 16; i++) - W[i] = SDL_SwapLE32(buf[i]); + w[i] = SDL_SwapLE32(buf[i]); for (int i = 16; i < 80; i++) { - W[i] = W[i - 16] ^ W[i - 14] ^ W[i - 8] ^ W[i - 3]; + w[i] = w[i - 16] ^ w[i - 14] ^ w[i - 8] ^ w[i - 3]; } - std::uint32_t A = context->state[0]; - std::uint32_t B = context->state[1]; - std::uint32_t C = context->state[2]; - std::uint32_t D = context->state[3]; - std::uint32_t E = context->state[4]; + std::uint32_t a = context->state[0]; + std::uint32_t b = context->state[1]; + std::uint32_t c = context->state[2]; + std::uint32_t d = context->state[3]; + std::uint32_t e = context->state[4]; for (int i = 0; i < 20; i++) { - std::uint32_t temp = SHA1CircularShift(5, A) + ((B & C) | ((~B) & D)) + E + W[i] + 0x5A827999; - E = D; - D = C; - C = SHA1CircularShift(30, B); - B = A; - A = temp; + std::uint32_t temp = SHA1CircularShift(5, a) + ((b & c) | ((~b) & d)) + e + w[i] + 0x5A827999; + e = d; + d = c; + c = SHA1CircularShift(30, b); + b = a; + a = temp; } for (int i = 20; i < 40; i++) { - std::uint32_t temp = SHA1CircularShift(5, A) + (B ^ C ^ D) + E + W[i] + 0x6ED9EBA1; - E = D; - D = C; - C = SHA1CircularShift(30, B); - B = A; - A = temp; + std::uint32_t temp = SHA1CircularShift(5, a) + (b ^ c ^ d) + e + w[i] + 0x6ED9EBA1; + e = d; + d = c; + c = SHA1CircularShift(30, b); + b = a; + a = temp; } for (int i = 40; i < 60; i++) { - std::uint32_t temp = SHA1CircularShift(5, A) + ((B & C) | (B & D) | (C & D)) + E + W[i] + 0x8F1BBCDC; - E = D; - D = C; - C = SHA1CircularShift(30, B); - B = A; - A = temp; + std::uint32_t temp = SHA1CircularShift(5, a) + ((b & c) | (b & d) | (c & d)) + e + w[i] + 0x8F1BBCDC; + e = d; + d = c; + c = SHA1CircularShift(30, b); + b = a; + a = temp; } for (int i = 60; i < 80; i++) { - std::uint32_t temp = SHA1CircularShift(5, A) + (B ^ C ^ D) + E + W[i] + 0xCA62C1D6; - E = D; - D = C; - C = SHA1CircularShift(30, B); - B = A; - A = temp; + std::uint32_t temp = SHA1CircularShift(5, a) + (b ^ c ^ d) + e + w[i] + 0xCA62C1D6; + e = d; + d = c; + c = SHA1CircularShift(30, b); + b = a; + a = temp; } - context->state[0] += A; - context->state[1] += B; - context->state[2] += C; - context->state[3] += D; - context->state[4] += E; + context->state[0] += a; + context->state[1] += b; + context->state[2] += c; + context->state[3] += d; + context->state[4] += e; } static void SHA1Input(SHA1Context *context, const char *messageArray, std::uint32_t len) @@ -132,14 +132,14 @@ void SHA1Clear() void SHA1Result(int n, char messageDigest[SHA1HashSize]) { - std::uint32_t *Message_Digest_Block; + std::uint32_t *messageDigestBlock; int i; - Message_Digest_Block = (std::uint32_t *)messageDigest; + messageDigestBlock = (std::uint32_t *)messageDigest; if (messageDigest != nullptr) { for (i = 0; i < 5; i++) { - *Message_Digest_Block = SDL_SwapLE32(sgSHA1[n].state[i]); - Message_Digest_Block++; + *messageDigestBlock = SDL_SwapLE32(sgSHA1[n].state[i]); + messageDigestBlock++; } } } diff --git a/Source/sound.cpp b/Source/sound.cpp index 765b3c884..1f203bcc6 100644 --- a/Source/sound.cpp +++ b/Source/sound.cpp @@ -180,9 +180,9 @@ std::unique_ptr sound_file_load(const char *path, bool stream) ErrDlg("SFileOpenFile failed", path, __FILE__, __LINE__); } DWORD dwBytes = SFileGetFileSize(file); - auto wave_file = MakeArraySharedPtr(dwBytes); - SFileReadFileThreadSafe(file, wave_file.get(), dwBytes); - error = snd->DSB.SetChunk(wave_file, dwBytes); + auto waveFile = MakeArraySharedPtr(dwBytes); + SFileReadFileThreadSafe(file, waveFile.get(), dwBytes); + error = snd->DSB.SetChunk(waveFile, dwBytes); SFileCloseFileThreadSafe(file); } #endif diff --git a/Source/storm/storm_svid.cpp b/Source/storm/storm_svid.cpp index 76b4015f3..c6f2bcb28 100644 --- a/Source/storm/storm_svid.cpp +++ b/Source/storm/storm_svid.cpp @@ -150,16 +150,16 @@ bool SVidPlayBegin(const char *filename, int flags) //0x800000 // Edge detection //0x200800 // Clear FB - HANDLE video_stream; - SFileOpenFile(filename, &video_stream); + HANDLE videoStream; + SFileOpenFile(filename, &videoStream); #ifdef DEVILUTIONX_STORM_FILE_WRAPPER_AVAILABLE - FILE *file = FILE_FromStormHandle(video_stream); + FILE *file = FILE_FromStormHandle(videoStream); SVidSMK = smk_open_filepointer(file, SMK_MODE_DISK); #else - int bytestoread = SFileGetFileSize(video_stream); + int bytestoread = SFileGetFileSize(videoStream); SVidBuffer = std::unique_ptr { new uint8_t[bytestoread] }; - SFileReadFileThreadSafe(video_stream, SVidBuffer.get(), bytestoread); - SFileCloseFileThreadSafe(video_stream); + SFileReadFileThreadSafe(videoStream, SVidBuffer.get(), bytestoread); + SFileCloseFileThreadSafe(videoStream); SVidSMK = smk_open_memory(SVidBuffer.get(), bytestoread); #endif if (SVidSMK == nullptr) { diff --git a/Source/towners.h b/Source/towners.h index d4fa0cf78..6c24b2c0e 100644 --- a/Source/towners.h +++ b/Source/towners.h @@ -45,7 +45,7 @@ struct TownerStruct { byte *_tNAnim[8]; std::unique_ptr _tNData; byte *_tAnimData; - /** Used to get a voice line and text related to active quests when the player speaks to a town npc */ + /** Used to get a voice line and text related to active quests when the player speaks to a town npc */ int16_t _tSeed; /** Tile position of NPC */ Point position; diff --git a/Source/track.cpp b/Source/track.cpp index 38c983c77..5325911f7 100644 --- a/Source/track.cpp +++ b/Source/track.cpp @@ -37,10 +37,10 @@ void track_process() const Point target = player.GetTargetPosition(); if (cursmx != target.x || cursmy != target.y) { Uint32 tick = SDL_GetTicks(); - int TickMultiplier = 6; + int tickMultiplier = 6; if (currlevel == 0 && sgGameInitInfo.bRunInTown != 0) - TickMultiplier = 3; - if ((int)(tick - sgdwLastWalk) >= gnTickDelay * TickMultiplier) { + tickMultiplier = 3; + if ((int)(tick - sgdwLastWalk) >= gnTickDelay * tickMultiplier) { sgdwLastWalk = tick; NetSendCmdLoc(myplr, true, CMD_WALKXY, { cursmx, cursmy }); if (!sgbIsScrolling) diff --git a/Source/utils/log.hpp b/Source/utils/log.hpp index b3d3f5ed9..f904bad4d 100644 --- a/Source/utils/log.hpp +++ b/Source/utils/log.hpp @@ -39,7 +39,7 @@ enum class LogPriority { namespace detail { template -std::string format(const char *fmt, Args &&... args) +std::string format(const char *fmt, Args &&...args) { FMT_TRY { @@ -56,99 +56,99 @@ std::string format(const char *fmt, Args &&... args) } // namespace detail template -void Log(const char *fmt, Args &&... args) +void Log(const char *fmt, Args &&...args) { auto str = detail::format(fmt, std::forward(args)...); SDL_Log("%s", str.c_str()); } template -void LogVerbose(LogCategory category, const char *fmt, Args &&... args) +void LogVerbose(LogCategory category, const char *fmt, Args &&...args) { auto str = detail::format(fmt, std::forward(args)...); SDL_LogVerbose(static_cast(category), "%s", str.c_str()); } template -void LogVerbose(const char *fmt, Args &&... args) +void LogVerbose(const char *fmt, Args &&...args) { LogVerbose(defaultCategory, fmt, std::forward(args)...); } template -void LogDebug(LogCategory category, const char *fmt, Args &&... args) +void LogDebug(LogCategory category, const char *fmt, Args &&...args) { auto str = detail::format(fmt, std::forward(args)...); SDL_LogDebug(static_cast(category), "%s", str.c_str()); } template -void LogDebug(const char *fmt, Args &&... args) +void LogDebug(const char *fmt, Args &&...args) { LogDebug(defaultCategory, fmt, std::forward(args)...); } template -void LogInfo(LogCategory category, const char *fmt, Args &&... args) +void LogInfo(LogCategory category, const char *fmt, Args &&...args) { auto str = detail::format(fmt, std::forward(args)...); SDL_LogInfo(static_cast(category), "%s", str.c_str()); } template -void LogInfo(const char *fmt, Args &&... args) +void LogInfo(const char *fmt, Args &&...args) { LogInfo(defaultCategory, fmt, std::forward(args)...); } template -void LogWarn(LogCategory category, const char *fmt, Args &&... args) +void LogWarn(LogCategory category, const char *fmt, Args &&...args) { auto str = detail::format(fmt, std::forward(args)...); SDL_LogWarn(static_cast(category), "%s", str.c_str()); } template -void LogWarn(const char *fmt, Args &&... args) +void LogWarn(const char *fmt, Args &&...args) { LogWarn(defaultCategory, fmt, std::forward(args)...); } template -void LogError(LogCategory category, const char *fmt, Args &&... args) +void LogError(LogCategory category, const char *fmt, Args &&...args) { auto str = detail::format(fmt, std::forward(args)...); SDL_LogError(static_cast(category), "%s", str.c_str()); } template -void LogError(const char *fmt, Args &&... args) +void LogError(const char *fmt, Args &&...args) { LogError(defaultCategory, fmt, std::forward(args)...); } template -void LogCritical(LogCategory category, const char *fmt, Args &&... args) +void LogCritical(LogCategory category, const char *fmt, Args &&...args) { auto str = detail::format(fmt, std::forward(args)...); SDL_LogCritical(static_cast(category), "%s", str.c_str()); } template -void LogCritical(const char *fmt, Args &&... args) +void LogCritical(const char *fmt, Args &&...args) { LogCritical(defaultCategory, fmt, std::forward(args)...); } template -void LogMessageV(LogCategory category, LogPriority priority, const char *fmt, Args &&... args) +void LogMessageV(LogCategory category, LogPriority priority, const char *fmt, Args &&...args) { auto str = detail::format(fmt, std::forward(args)...); SDL_LogMessageV(static_cast(category), static_cast(priority), "%s", str.c_str()); } template -void LogMessageV(const char *fmt, Args &&... args) +void LogMessageV(const char *fmt, Args &&...args) { LogMessageV(defaultCategory, fmt, std::forward(args)...); }