♻️Clean up implicit bool conversions

This commit is contained in:
Anders Jenbo 2021-06-26 03:49:46 +02:00
commit 22b632f04a
42 changed files with 683 additions and 649 deletions

View file

@ -355,6 +355,7 @@ set(libdevilutionx_SRCS
Source/nthread.cpp
Source/objdat.cpp
Source/objects.cpp
Source/options.cpp
Source/pack.cpp
Source/palette.cpp
Source/path.cpp

View file

@ -447,9 +447,9 @@ void selgame_Password_Select(int value)
m_game_data->nDifficulty = nDifficulty;
m_game_data->nTickRate = nTickRate;
m_game_data->bRunInTown = sgOptions.Gameplay.bRunInTown;
m_game_data->bTheoQuest = sgOptions.Gameplay.bTheoQuest;
m_game_data->bCowQuest = sgOptions.Gameplay.bCowQuest;
m_game_data->bRunInTown = sgOptions.Gameplay.bRunInTown ? 1 : 0;
m_game_data->bTheoQuest = sgOptions.Gameplay.bTheoQuest ? 1 : 0;
m_game_data->bCowQuest = sgOptions.Gameplay.bCowQuest ? 1 : 0;
if (SNetCreateGame(nullptr, selgame_Password, (char *)m_game_data, sizeof(*m_game_data), gdwPlayerId)) {
UiInitList_clear();

View file

@ -334,11 +334,11 @@ void CheckCursMove()
ShiftGrid(&mx, &my, -columns / 2, -lrow / 2);
// Align grid
if ((columns & 1) == 0 && (lrow & 1) == 0) {
if ((columns % 2) == 0 && (lrow % 2) == 0) {
sy += TILE_HEIGHT / 2;
} else if (columns & 1 && lrow & 1) {
} else if ((columns % 2) != 0 && (lrow % 2) != 0) {
sx -= TILE_WIDTH / 2;
} else if (columns & 1 && (lrow & 1) == 0) {
} else if ((columns % 2) != 0 && (lrow % 2) == 0) {
my++;
}
@ -420,136 +420,136 @@ void CheckCursMove()
if (leveltype != DTYPE_TOWN) {
if (pcurstemp != -1) {
if (!flipflag && mx + 2 < MAXDUNX && my + 1 < MAXDUNY && dMonster[mx + 2][my + 1] != 0 && dFlags[mx + 2][my + 1] & BFLAG_LIT) {
if (!flipflag && mx + 2 < MAXDUNX && my + 1 < MAXDUNY && dMonster[mx + 2][my + 1] != 0 && (dFlags[mx + 2][my + 1] & BFLAG_LIT) != 0) {
mi = dMonster[mx + 2][my + 1] > 0 ? dMonster[mx + 2][my + 1] - 1 : -(dMonster[mx + 2][my + 1] + 1);
if (mi == pcurstemp && monster[mi]._mhitpoints >> 6 > 0 && monster[mi].MData->mSelFlag & 4) {
if (mi == pcurstemp && monster[mi]._mhitpoints >> 6 > 0 && (monster[mi].MData->mSelFlag & 4) != 0) {
cursmx = mx + 2; /// BUGFIX: 'mx + 2' (fixed)
cursmy = my + 1; /// BUGFIX: 'my + 1' (fixed)
pcursmonst = mi;
}
}
if (flipflag && mx + 1 < MAXDUNX && my + 2 < MAXDUNY && dMonster[mx + 1][my + 2] != 0 && dFlags[mx + 1][my + 2] & BFLAG_LIT) {
if (flipflag && mx + 1 < MAXDUNX && my + 2 < MAXDUNY && dMonster[mx + 1][my + 2] != 0 && (dFlags[mx + 1][my + 2] & BFLAG_LIT) != 0) {
mi = dMonster[mx + 1][my + 2] > 0 ? dMonster[mx + 1][my + 2] - 1 : -(dMonster[mx + 1][my + 2] + 1);
if (mi == pcurstemp && monster[mi]._mhitpoints >> 6 > 0 && monster[mi].MData->mSelFlag & 4) {
if (mi == pcurstemp && monster[mi]._mhitpoints >> 6 > 0 && (monster[mi].MData->mSelFlag & 4) != 0) {
cursmx = mx + 1;
cursmy = my + 2;
pcursmonst = mi;
}
}
if (mx + 2 < MAXDUNX && my + 2 < MAXDUNY && dMonster[mx + 2][my + 2] != 0 && dFlags[mx + 2][my + 2] & BFLAG_LIT) {
if (mx + 2 < MAXDUNX && my + 2 < MAXDUNY && dMonster[mx + 2][my + 2] != 0 && (dFlags[mx + 2][my + 2] & BFLAG_LIT) != 0) {
mi = dMonster[mx + 2][my + 2] > 0 ? dMonster[mx + 2][my + 2] - 1 : -(dMonster[mx + 2][my + 2] + 1);
if (mi == pcurstemp && monster[mi]._mhitpoints >> 6 > 0 && monster[mi].MData->mSelFlag & 4) {
if (mi == pcurstemp && monster[mi]._mhitpoints >> 6 > 0 && (monster[mi].MData->mSelFlag & 4) != 0) {
cursmx = mx + 2;
cursmy = my + 2;
pcursmonst = mi;
}
}
if (mx + 1 < MAXDUNX && !flipflag && dMonster[mx + 1][my] != 0 && dFlags[mx + 1][my] & BFLAG_LIT) {
if (mx + 1 < MAXDUNX && !flipflag && dMonster[mx + 1][my] != 0 && (dFlags[mx + 1][my] & BFLAG_LIT) != 0) {
mi = dMonster[mx + 1][my] > 0 ? dMonster[mx + 1][my] - 1 : -(dMonster[mx + 1][my] + 1);
if (mi == pcurstemp && monster[mi]._mhitpoints >> 6 > 0 && monster[mi].MData->mSelFlag & 2) {
if (mi == pcurstemp && monster[mi]._mhitpoints >> 6 > 0 && (monster[mi].MData->mSelFlag & 2) != 0) {
cursmx = mx + 1;
cursmy = my;
pcursmonst = mi;
}
}
if (my + 1 < MAXDUNY && flipflag && dMonster[mx][my + 1] != 0 && dFlags[mx][my + 1] & BFLAG_LIT) {
if (my + 1 < MAXDUNY && flipflag && dMonster[mx][my + 1] != 0 && (dFlags[mx][my + 1] & BFLAG_LIT) != 0) {
mi = dMonster[mx][my + 1] > 0 ? dMonster[mx][my + 1] - 1 : -(dMonster[mx][my + 1] + 1);
if (mi == pcurstemp && monster[mi]._mhitpoints >> 6 > 0 && monster[mi].MData->mSelFlag & 2) {
if (mi == pcurstemp && monster[mi]._mhitpoints >> 6 > 0 && (monster[mi].MData->mSelFlag & 2) != 0) {
cursmx = mx;
cursmy = my + 1;
pcursmonst = mi;
}
}
if (dMonster[mx][my] != 0 && dFlags[mx][my] & BFLAG_LIT) {
if (dMonster[mx][my] != 0 && (dFlags[mx][my] & BFLAG_LIT) != 0) {
mi = dMonster[mx][my] > 0 ? dMonster[mx][my] - 1 : -(dMonster[mx][my] + 1);
if (mi == pcurstemp && monster[mi]._mhitpoints >> 6 > 0 && monster[mi].MData->mSelFlag & 1) {
if (mi == pcurstemp && monster[mi]._mhitpoints >> 6 > 0 && (monster[mi].MData->mSelFlag & 1) != 0) {
cursmx = mx;
cursmy = my;
pcursmonst = mi;
}
}
if (mx + 1 < MAXDUNX && my + 1 < MAXDUNY && dMonster[mx + 1][my + 1] != 0 && dFlags[mx + 1][my + 1] & BFLAG_LIT) {
if (mx + 1 < MAXDUNX && my + 1 < MAXDUNY && dMonster[mx + 1][my + 1] != 0 && (dFlags[mx + 1][my + 1] & BFLAG_LIT) != 0) {
mi = dMonster[mx + 1][my + 1] > 0 ? dMonster[mx + 1][my + 1] - 1 : -(dMonster[mx + 1][my + 1] + 1);
if (mi == pcurstemp && monster[mi]._mhitpoints >> 6 > 0 && monster[mi].MData->mSelFlag & 2) {
if (mi == pcurstemp && monster[mi]._mhitpoints >> 6 > 0 && (monster[mi].MData->mSelFlag & 2) != 0) {
cursmx = mx + 1;
cursmy = my + 1;
pcursmonst = mi;
}
}
if (pcursmonst != -1 && monster[pcursmonst]._mFlags & MFLAG_HIDDEN) {
if (pcursmonst != -1 && (monster[pcursmonst]._mFlags & MFLAG_HIDDEN) != 0) {
pcursmonst = -1;
cursmx = mx;
cursmy = my;
}
if (pcursmonst != -1 && monster[pcursmonst]._mFlags & MFLAG_GOLEM && !(monster[pcursmonst]._mFlags & MFLAG_BERSERK)) {
if (pcursmonst != -1 && (monster[pcursmonst]._mFlags & MFLAG_GOLEM) != 0 && (monster[pcursmonst]._mFlags & MFLAG_BERSERK) == 0) {
pcursmonst = -1;
}
if (pcursmonst != -1) {
return;
}
}
if (!flipflag && mx + 2 < MAXDUNX && my + 1 < MAXDUNY && dMonster[mx + 2][my + 1] != 0 && dFlags[mx + 2][my + 1] & BFLAG_LIT) {
if (!flipflag && mx + 2 < MAXDUNX && my + 1 < MAXDUNY && dMonster[mx + 2][my + 1] != 0 && (dFlags[mx + 2][my + 1] & BFLAG_LIT) != 0) {
mi = dMonster[mx + 2][my + 1] > 0 ? dMonster[mx + 2][my + 1] - 1 : -(dMonster[mx + 2][my + 1] + 1);
if (monster[mi]._mhitpoints >> 6 > 0 && monster[mi].MData->mSelFlag & 4) {
if (monster[mi]._mhitpoints >> 6 > 0 && (monster[mi].MData->mSelFlag & 4) != 0) {
cursmx = mx + 2;
cursmy = my + 1;
pcursmonst = mi;
}
}
if (flipflag && mx + 1 < MAXDUNX && my + 2 < MAXDUNY && dMonster[mx + 1][my + 2] != 0 && dFlags[mx + 1][my + 2] & BFLAG_LIT) {
if (flipflag && mx + 1 < MAXDUNX && my + 2 < MAXDUNY && dMonster[mx + 1][my + 2] != 0 && (dFlags[mx + 1][my + 2] & BFLAG_LIT) != 0) {
mi = dMonster[mx + 1][my + 2] > 0 ? dMonster[mx + 1][my + 2] - 1 : -(dMonster[mx + 1][my + 2] + 1);
if (monster[mi]._mhitpoints >> 6 > 0 && monster[mi].MData->mSelFlag & 4) {
if (monster[mi]._mhitpoints >> 6 > 0 && (monster[mi].MData->mSelFlag & 4) != 0) {
cursmx = mx + 1;
cursmy = my + 2;
pcursmonst = mi;
}
}
if (mx + 2 < MAXDUNX && my + 2 < MAXDUNY && dMonster[mx + 2][my + 2] != 0 && dFlags[mx + 2][my + 2] & BFLAG_LIT) {
if (mx + 2 < MAXDUNX && my + 2 < MAXDUNY && dMonster[mx + 2][my + 2] != 0 && (dFlags[mx + 2][my + 2] & BFLAG_LIT) != 0) {
mi = dMonster[mx + 2][my + 2] > 0 ? dMonster[mx + 2][my + 2] - 1 : -(dMonster[mx + 2][my + 2] + 1);
if (monster[mi]._mhitpoints >> 6 > 0 && monster[mi].MData->mSelFlag & 4) {
if (monster[mi]._mhitpoints >> 6 > 0 && (monster[mi].MData->mSelFlag & 4) != 0) {
cursmx = mx + 2;
cursmy = my + 2;
pcursmonst = mi;
}
}
if (!flipflag && mx + 1 < MAXDUNX && dMonster[mx + 1][my] != 0 && dFlags[mx + 1][my] & BFLAG_LIT) {
if (!flipflag && mx + 1 < MAXDUNX && dMonster[mx + 1][my] != 0 && (dFlags[mx + 1][my] & BFLAG_LIT) != 0) {
mi = dMonster[mx + 1][my] > 0 ? dMonster[mx + 1][my] - 1 : -(dMonster[mx + 1][my] + 1);
if (monster[mi]._mhitpoints >> 6 > 0 && monster[mi].MData->mSelFlag & 2) {
if (monster[mi]._mhitpoints >> 6 > 0 && (monster[mi].MData->mSelFlag & 2) != 0) {
cursmx = mx + 1;
cursmy = my;
pcursmonst = mi;
}
}
if (flipflag && my + 1 < MAXDUNY && dMonster[mx][my + 1] != 0 && dFlags[mx][my + 1] & BFLAG_LIT) {
if (flipflag && my + 1 < MAXDUNY && dMonster[mx][my + 1] != 0 && (dFlags[mx][my + 1] & BFLAG_LIT) != 0) {
mi = dMonster[mx][my + 1] > 0 ? dMonster[mx][my + 1] - 1 : -(dMonster[mx][my + 1] + 1);
if (monster[mi]._mhitpoints >> 6 > 0 && monster[mi].MData->mSelFlag & 2) {
if (monster[mi]._mhitpoints >> 6 > 0 && (monster[mi].MData->mSelFlag & 2) != 0) {
cursmx = mx;
cursmy = my + 1;
pcursmonst = mi;
}
}
if (dMonster[mx][my] != 0 && dFlags[mx][my] & BFLAG_LIT) {
if (dMonster[mx][my] != 0 && (dFlags[mx][my] & BFLAG_LIT) != 0) {
mi = dMonster[mx][my] > 0 ? dMonster[mx][my] - 1 : -(dMonster[mx][my] + 1);
if (monster[mi]._mhitpoints >> 6 > 0 && monster[mi].MData->mSelFlag & 1) {
if (monster[mi]._mhitpoints >> 6 > 0 && (monster[mi].MData->mSelFlag & 1) != 0) {
cursmx = mx;
cursmy = my;
pcursmonst = mi;
}
}
if (mx + 1 < MAXDUNX && my + 1 < MAXDUNY && dMonster[mx + 1][my + 1] != 0 && dFlags[mx + 1][my + 1] & BFLAG_LIT) {
if (mx + 1 < MAXDUNX && my + 1 < MAXDUNY && dMonster[mx + 1][my + 1] != 0 && (dFlags[mx + 1][my + 1] & BFLAG_LIT) != 0) {
mi = dMonster[mx + 1][my + 1] > 0 ? dMonster[mx + 1][my + 1] - 1 : -(dMonster[mx + 1][my + 1] + 1);
if (monster[mi]._mhitpoints >> 6 > 0 && monster[mi].MData->mSelFlag & 2) {
if (monster[mi]._mhitpoints >> 6 > 0 && (monster[mi].MData->mSelFlag & 2) != 0) {
cursmx = mx + 1;
cursmy = my + 1;
pcursmonst = mi;
}
}
if (pcursmonst != -1 && monster[pcursmonst]._mFlags & MFLAG_HIDDEN) {
if (pcursmonst != -1 && (monster[pcursmonst]._mFlags & MFLAG_HIDDEN) != 0) {
pcursmonst = -1;
cursmx = mx;
cursmy = my;
}
if (pcursmonst != -1 && monster[pcursmonst]._mFlags & MFLAG_GOLEM && !(monster[pcursmonst]._mFlags & MFLAG_BERSERK)) {
if (pcursmonst != -1 && (monster[pcursmonst]._mFlags & MFLAG_GOLEM) != 0 && (monster[pcursmonst]._mFlags & MFLAG_BERSERK) == 0) {
pcursmonst = -1;
}
} else {
@ -612,7 +612,7 @@ void CheckCursMove()
if (pcurs == CURSOR_RESURRECT) {
for (xx = -1; xx < 2; xx++) {
for (yy = -1; yy < 2; yy++) {
if (mx + xx < MAXDUNX && my + yy < MAXDUNY && dFlags[mx + xx][my + yy] & BFLAG_DEAD_PLAYER) {
if (mx + xx < MAXDUNX && my + yy < MAXDUNY && (dFlags[mx + xx][my + yy] & BFLAG_DEAD_PLAYER) != 0) {
for (i = 0; i < MAX_PLRS; i++) {
if (plr[i].position.tile.x == mx + xx && plr[i].position.tile.y == my + yy && i != myplr) {
cursmx = mx + xx;
@ -716,7 +716,7 @@ void CheckCursMove()
cursmx = mx;
cursmy = my;
}
if (pcursmonst != -1 && monster[pcursmonst]._mFlags & MFLAG_GOLEM && !(monster[pcursmonst]._mFlags & MFLAG_BERSERK)) {
if (pcursmonst != -1 && (monster[pcursmonst]._mFlags & MFLAG_GOLEM) != 0 && (monster[pcursmonst]._mFlags & MFLAG_BERSERK) == 0) {
pcursmonst = -1;
}
}

View file

@ -71,25 +71,6 @@
namespace devilution {
#ifndef DEFAULT_WIDTH
#define DEFAULT_WIDTH 640
#endif
#ifndef DEFAULT_HEIGHT
#define DEFAULT_HEIGHT 480
#endif
#ifndef DEFAULT_AUDIO_SAMPLE_RATE
#define DEFAULT_AUDIO_SAMPLE_RATE 22050
#endif
#ifndef DEFAULT_AUDIO_CHANNELS
#define DEFAULT_AUDIO_CHANNELS 2
#endif
#ifndef DEFAULT_AUDIO_BUFFER_SIZE
#define DEFAULT_AUDIO_BUFFER_SIZE 2048
#endif
#ifndef DEFAULT_AUDIO_RESAMPLING_QUALITY
#define DEFAULT_AUDIO_RESAMPLING_QUALITY 5
#endif
SDL_Window *ghMainWnd;
DWORD glSeedTbl[NUMLEVELS];
dungeon_type gnLevelTypeTbl[NUMLEVELS];
@ -120,8 +101,6 @@ int sgnTimeoutCurs;
clicktype sgbMouseDown;
int color_cycle_timer;
uint16_t gnTickDelay = 50;
/** Game options */
Options sgOptions;
Keymapper keymapper {
// Workaround: remove once the INI library has been replaced.
[](const std::string &key, const std::string &value) {
@ -157,15 +136,13 @@ int arrowdebug = 0;
#endif
/** Specifies whether players are in non-PvP mode. */
bool gbFriendlyMode = true;
/** Default quick messages */
const char *const spszMsgTbl[] = {
const char *const spszMsgTbl[4] = {
N_("I need help! Come Here!"),
N_("Follow me."),
N_("Here's something for you."),
N_("Now you DIE!")
};
/** INI files variable names for quick messages */
const char *const spszMsgNameTbl[] = { "QuickMessage1", "QuickMessage2", "QuickMessage3", "QuickMessage4" };
const char *const spszMsgNameTbl[4] = { "QuickMessage1", "QuickMessage2", "QuickMessage3", "QuickMessage4" };
/** To know if these things have been done when we get to the diablo_deinit() function */
bool was_archives_init = false;
@ -173,7 +150,6 @@ bool was_archives_init = false;
bool was_window_init = false;
bool was_ui_init = false;
bool was_snd_init = false;
bool sbWasOptionsLoaded = false;
// Controller support:
extern void plrctrls_every_frame();
@ -492,177 +468,6 @@ bool StartGame(bool bNewGame, bool bSinglePlayer)
return gbRunGameResult;
}
/**
* @brief Save game configurations to ini file
*/
static void SaveOptions()
{
setIniInt("Diablo", "Intro", sgOptions.Diablo.bIntro);
setIniInt("Hellfire", "Intro", sgOptions.Hellfire.bIntro);
setIniValue("Hellfire", "SItem", sgOptions.Hellfire.szItem);
setIniInt("Audio", "Sound Volume", sgOptions.Audio.nSoundVolume);
setIniInt("Audio", "Music Volume", sgOptions.Audio.nMusicVolume);
setIniInt("Audio", "Walking Sound", sgOptions.Audio.bWalkingSound);
setIniInt("Audio", "Auto Equip Sound", sgOptions.Audio.bAutoEquipSound);
setIniInt("Audio", "Sample Rate", sgOptions.Audio.nSampleRate);
setIniInt("Audio", "Channels", sgOptions.Audio.nChannels);
setIniInt("Audio", "Buffer Size", sgOptions.Audio.nBufferSize);
setIniInt("Audio", "Resampling Quality", sgOptions.Audio.nResamplingQuality);
setIniInt("Graphics", "Width", sgOptions.Graphics.nWidth);
setIniInt("Graphics", "Height", sgOptions.Graphics.nHeight);
#ifndef __vita__
setIniInt("Graphics", "Fullscreen", sgOptions.Graphics.bFullscreen);
#endif
#if !defined(USE_SDL1)
setIniInt("Graphics", "Upscale", sgOptions.Graphics.bUpscale);
#endif
setIniInt("Graphics", "Fit to Screen", sgOptions.Graphics.bFitToScreen);
setIniValue("Graphics", "Scaling Quality", sgOptions.Graphics.szScaleQuality);
setIniInt("Graphics", "Integer Scaling", sgOptions.Graphics.bIntegerScaling);
setIniInt("Graphics", "Vertical Sync", sgOptions.Graphics.bVSync);
setIniInt("Graphics", "Blended Transparency", sgOptions.Graphics.bBlendedTransparancy);
setIniInt("Graphics", "Gamma Correction", sgOptions.Graphics.nGammaCorrection);
setIniInt("Graphics", "Color Cycling", sgOptions.Graphics.bColorCycling);
#ifndef USE_SDL1
setIniInt("Graphics", "Hardware Cursor", sgOptions.Graphics.bHardwareCursor);
#endif
setIniInt("Graphics", "FPS Limiter", sgOptions.Graphics.bFPSLimit);
setIniInt("Graphics", "Show FPS", sgOptions.Graphics.bShowFPS);
setIniInt("Game", "Speed", sgOptions.Gameplay.nTickRate);
setIniInt("Game", "Run in Town", sgOptions.Gameplay.bRunInTown);
setIniInt("Game", "Grab Input", sgOptions.Gameplay.bGrabInput);
setIniInt("Game", "Theo Quest", sgOptions.Gameplay.bTheoQuest);
setIniInt("Game", "Cow Quest", sgOptions.Gameplay.bCowQuest);
setIniInt("Game", "Friendly Fire", sgOptions.Gameplay.bFriendlyFire);
setIniInt("Game", "Test Bard", sgOptions.Gameplay.bTestBard);
setIniInt("Game", "Test Barbarian", sgOptions.Gameplay.bTestBarbarian);
setIniInt("Game", "Experience Bar", sgOptions.Gameplay.bExperienceBar);
setIniInt("Game", "Enemy Health Bar", sgOptions.Gameplay.bEnemyHealthBar);
setIniInt("Game", "Auto Gold Pickup", sgOptions.Gameplay.bAutoGoldPickup);
setIniInt("Game", "Adria Refills Mana", sgOptions.Gameplay.bAdriaRefillsMana);
setIniInt("Game", "Auto Equip Weapons", sgOptions.Gameplay.bAutoEquipWeapons);
setIniInt("Game", "Auto Equip Armor", sgOptions.Gameplay.bAutoEquipArmor);
setIniInt("Game", "Auto Equip Helms", sgOptions.Gameplay.bAutoEquipHelms);
setIniInt("Game", "Auto Equip Shields", sgOptions.Gameplay.bAutoEquipShields);
setIniInt("Game", "Auto Equip Jewelry", sgOptions.Gameplay.bAutoEquipJewelry);
setIniInt("Game", "Randomize Quests", sgOptions.Gameplay.bRandomizeQuests);
setIniInt("Game", "Show Monster Type", sgOptions.Gameplay.bShowMonsterType);
setIniInt("Game", "Disable Crippling Shrines", sgOptions.Gameplay.bDisableCripplingShrines);
setIniValue("Network", "Bind Address", sgOptions.Network.szBindAddress);
setIniInt("Network", "Port", sgOptions.Network.nPort);
setIniValue("Network", "Previous Host", sgOptions.Network.szPreviousHost);
for (size_t i = 0; i < sizeof(spszMsgTbl) / sizeof(spszMsgTbl[0]); i++)
setIniValue("NetMsg", spszMsgNameTbl[i], sgOptions.Chat.szHotKeyMsgs[i]);
setIniValue("Controller", "Mapping", sgOptions.Controller.szMapping);
setIniInt("Controller", "Swap Shoulder Button Mode", sgOptions.Controller.bSwapShoulderButtonMode);
setIniInt("Controller", "Dpad Hotkeys", sgOptions.Controller.bDpadHotkeys);
setIniFloat("Controller", "deadzone", sgOptions.Controller.fDeadzone);
#ifdef __vita__
setIniInt("Controller", "Enable Rear Touchpad", sgOptions.Controller.bRearTouch);
#endif
setIniValue("Language", "Code", sgOptions.Language.szCode);
keymapper.save();
SaveIni();
}
/**
* @brief Load game configurations from ini file
*/
static void LoadOptions()
{
sgOptions.Diablo.bIntro = getIniBool("Diablo", "Intro", true);
sgOptions.Hellfire.bIntro = getIniBool("Hellfire", "Intro", true);
getIniValue("Hellfire", "SItem", sgOptions.Hellfire.szItem, sizeof(sgOptions.Hellfire.szItem), "");
sgOptions.Audio.nSoundVolume = getIniInt("Audio", "Sound Volume", VOLUME_MAX);
sgOptions.Audio.nMusicVolume = getIniInt("Audio", "Music Volume", VOLUME_MAX);
sgOptions.Audio.bWalkingSound = getIniBool("Audio", "Walking Sound", true);
sgOptions.Audio.bAutoEquipSound = getIniBool("Audio", "Auto Equip Sound", false);
sgOptions.Audio.nSampleRate = getIniInt("Audio", "Sample Rate", DEFAULT_AUDIO_SAMPLE_RATE);
sgOptions.Audio.nChannels = getIniInt("Audio", "Channels", DEFAULT_AUDIO_CHANNELS);
sgOptions.Audio.nBufferSize = getIniInt("Audio", "Buffer Size", DEFAULT_AUDIO_BUFFER_SIZE);
sgOptions.Audio.nResamplingQuality = getIniInt("Audio", "Resampling Quality", DEFAULT_AUDIO_RESAMPLING_QUALITY);
sgOptions.Graphics.nWidth = getIniInt("Graphics", "Width", DEFAULT_WIDTH);
sgOptions.Graphics.nHeight = getIniInt("Graphics", "Height", DEFAULT_HEIGHT);
#ifndef __vita__
sgOptions.Graphics.bFullscreen = getIniBool("Graphics", "Fullscreen", true);
#else
sgOptions.Graphics.bFullscreen = true;
#endif
#if !defined(USE_SDL1)
sgOptions.Graphics.bUpscale = getIniBool("Graphics", "Upscale", true);
#else
sgOptions.Graphics.bUpscale = false;
#endif
sgOptions.Graphics.bFitToScreen = getIniBool("Graphics", "Fit to Screen", true);
getIniValue("Graphics", "Scaling Quality", sgOptions.Graphics.szScaleQuality, sizeof(sgOptions.Graphics.szScaleQuality), "2");
sgOptions.Graphics.bIntegerScaling = getIniBool("Graphics", "Integer Scaling", false);
sgOptions.Graphics.bVSync = getIniBool("Graphics", "Vertical Sync", true);
sgOptions.Graphics.bBlendedTransparancy = getIniBool("Graphics", "Blended Transparency", true);
sgOptions.Graphics.nGammaCorrection = getIniInt("Graphics", "Gamma Correction", 100);
sgOptions.Graphics.bColorCycling = getIniBool("Graphics", "Color Cycling", true);
#ifndef USE_SDL1
sgOptions.Graphics.bHardwareCursor = getIniBool("Graphics", "Hardware Cursor", false);
#else
sgOptions.Graphics.bHardwareCursor = false;
#endif
sgOptions.Graphics.bFPSLimit = getIniBool("Graphics", "FPS Limiter", true);
sgOptions.Graphics.bShowFPS = getIniInt("Graphics", "Show FPS", false);
sgOptions.Gameplay.nTickRate = getIniInt("Game", "Speed", 20);
sgOptions.Gameplay.bRunInTown = getIniBool("Game", "Run in Town", false);
sgOptions.Gameplay.bGrabInput = getIniBool("Game", "Grab Input", false);
sgOptions.Gameplay.bTheoQuest = getIniBool("Game", "Theo Quest", false);
sgOptions.Gameplay.bCowQuest = getIniBool("Game", "Cow Quest", false);
sgOptions.Gameplay.bFriendlyFire = getIniBool("Game", "Friendly Fire", true);
sgOptions.Gameplay.bTestBard = getIniBool("Game", "Test Bard", false);
sgOptions.Gameplay.bTestBarbarian = getIniBool("Game", "Test Barbarian", false);
sgOptions.Gameplay.bExperienceBar = getIniBool("Game", "Experience Bar", false);
sgOptions.Gameplay.bEnemyHealthBar = getIniBool("Game", "Enemy Health Bar", false);
sgOptions.Gameplay.bAutoGoldPickup = getIniBool("Game", "Auto Gold Pickup", false);
sgOptions.Gameplay.bAdriaRefillsMana = getIniBool("Game", "Adria Refills Mana", false);
sgOptions.Gameplay.bAutoEquipWeapons = getIniBool("Game", "Auto Equip Weapons", true);
sgOptions.Gameplay.bAutoEquipArmor = getIniBool("Game", "Auto Equip Armor", false);
sgOptions.Gameplay.bAutoEquipHelms = getIniBool("Game", "Auto Equip Helms", false);
sgOptions.Gameplay.bAutoEquipShields = getIniBool("Game", "Auto Equip Shields", false);
sgOptions.Gameplay.bAutoEquipJewelry = getIniBool("Game", "Auto Equip Jewelry", false);
sgOptions.Gameplay.bRandomizeQuests = getIniBool("Game", "Randomize Quests", true);
sgOptions.Gameplay.bShowMonsterType = getIniBool("Game", "Show Monster Type", false);
sgOptions.Gameplay.bDisableCripplingShrines = getIniBool("Game", "Disable Crippling Shrines", false);
getIniValue("Network", "Bind Address", sgOptions.Network.szBindAddress, sizeof(sgOptions.Network.szBindAddress), "0.0.0.0");
sgOptions.Network.nPort = getIniInt("Network", "Port", 6112);
getIniValue("Network", "Previous Host", sgOptions.Network.szPreviousHost, sizeof(sgOptions.Network.szPreviousHost), "");
for (size_t i = 0; i < sizeof(spszMsgTbl) / sizeof(spszMsgTbl[0]); i++)
getIniValue("NetMsg", spszMsgNameTbl[i], sgOptions.Chat.szHotKeyMsgs[i], MAX_SEND_STR_LEN, "");
getIniValue("Controller", "Mapping", sgOptions.Controller.szMapping, sizeof(sgOptions.Controller.szMapping), "");
sgOptions.Controller.bSwapShoulderButtonMode = getIniBool("Controller", "Swap Shoulder Button Mode", false);
sgOptions.Controller.bDpadHotkeys = getIniBool("Controller", "Dpad Hotkeys", false);
sgOptions.Controller.fDeadzone = getIniFloat("Controller", "deadzone", 0.07);
#ifdef __vita__
sgOptions.Controller.bRearTouch = getIniBool("Controller", "Enable Rear Touchpad", true);
#endif
getIniValue("Language", "Code", sgOptions.Language.szCode, sizeof(sgOptions.Language.szCode), "en");
keymapper.load();
sbWasOptionsLoaded = true;
}
static void diablo_init_screen()
{
MouseX = gnScreenWidth / 2;
@ -1965,11 +1770,9 @@ static void timeout_cursor(bool bTimeout)
*/
void game_loop(bool bStartup)
{
int i;
uint16_t wait = bStartup ? sgGameInitInfo.nTickRate * 3 : 3;
i = bStartup ? sgGameInitInfo.nTickRate * 3 : 3;
while (i--) {
for (unsigned i = 0; i < wait; i++) {
if (!multi_handle_delta()) {
timeout_cursor(true);
break;

View file

@ -9,6 +9,7 @@
#include "utils/endian.hpp"
#include "controls/keymapper.hpp"
#ifdef _DEBUG
#include "monstdat.h"
#endif
@ -69,6 +70,7 @@ void diablo_color_cyc_logic();
/* rdata */
extern Keymapper keymapper;
extern bool gbForceWindowed;
extern bool leveldebug;
#ifdef _DEBUG
@ -83,6 +85,10 @@ extern bool debug_mode_dollar_sign;
extern bool debug_mode_key_i;
extern int debug_mode_key_j;
#endif
/** Default quick messages */
extern const char *const spszMsgTbl[4];
/** INI files variable names for quick messages */
extern const char *const spszMsgNameTbl[4];
extern bool gbFriendlyMode;
} // namespace devilution

View file

@ -30,11 +30,11 @@ BYTE L5dflags[DMAXX][DMAXY];
/** Specifies whether a single player quest DUN has been loaded. */
bool L5setloadflag;
/** Specifies whether to generate a horizontal room at position 1 in the Cathedral. */
int HR1;
bool HR1;
/** Specifies whether to generate a horizontal room at position 2 in the Cathedral. */
int HR2;
bool HR2;
/** Specifies whether to generate a horizontal room at position 3 in the Cathedral. */
int HR3;
bool HR3;
/** Specifies whether to generate a vertical room at position 1 in the Cathedral. */
bool VR1;
@ -869,18 +869,18 @@ static void DRLG_L1Shadows()
for (i = 0; i < 37; i++) {
if (SPATS[i].strig == sd[0][0]) {
patflag = true;
if (SPATS[i].s1 && SPATS[i].s1 != sd[1][1])
if (SPATS[i].s1 != 0 && SPATS[i].s1 != sd[1][1])
patflag = false;
if (SPATS[i].s2 && SPATS[i].s2 != sd[0][1])
if (SPATS[i].s2 != 0 && SPATS[i].s2 != sd[0][1])
patflag = false;
if (SPATS[i].s3 && SPATS[i].s3 != sd[1][0])
if (SPATS[i].s3 != 0 && SPATS[i].s3 != sd[1][0])
patflag = false;
if (patflag) {
if (SPATS[i].nv1 && !L5dflags[x - 1][y - 1])
if (SPATS[i].nv1 != 0 && L5dflags[x - 1][y - 1] == 0)
dungeon[x - 1][y - 1] = SPATS[i].nv1;
if (SPATS[i].nv2 && !L5dflags[x][y - 1])
if (SPATS[i].nv2 != 0 && L5dflags[x][y - 1] == 0)
dungeon[x][y - 1] = SPATS[i].nv2;
if (SPATS[i].nv3 && !L5dflags[x - 1][y])
if (SPATS[i].nv3 != 0 && L5dflags[x - 1][y] == 0)
dungeon[x - 1][y] = SPATS[i].nv3;
}
}
@ -890,7 +890,7 @@ static void DRLG_L1Shadows()
for (y = 1; y < DMAXY; y++) {
for (x = 1; x < DMAXX; x++) {
if (dungeon[x - 1][y] == 139 && !L5dflags[x - 1][y]) {
if (dungeon[x - 1][y] == 139 && L5dflags[x - 1][y] == 0) {
tnv3 = 139;
if (dungeon[x][y] == 29)
tnv3 = 141;
@ -906,7 +906,7 @@ static void DRLG_L1Shadows()
tnv3 = 141;
dungeon[x - 1][y] = tnv3;
}
if (dungeon[x - 1][y] == 149 && !L5dflags[x - 1][y]) {
if (dungeon[x - 1][y] == 149 && L5dflags[x - 1][y] == 0) {
tnv3 = 149;
if (dungeon[x][y] == 29)
tnv3 = 153;
@ -922,7 +922,7 @@ static void DRLG_L1Shadows()
tnv3 = 153;
dungeon[x - 1][y] = tnv3;
}
if (dungeon[x - 1][y] == 148 && !L5dflags[x - 1][y]) {
if (dungeon[x - 1][y] == 148 && L5dflags[x - 1][y] == 0) {
tnv3 = 148;
if (dungeon[x][y] == 29)
tnv3 = 154;
@ -995,9 +995,9 @@ static int DRLG_PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, in
for (yy = 0; yy < sh && abort; yy++) {
for (xx = 0; xx < sw && abort; xx++) {
if (miniset[ii] && dungeon[xx + sx][sy + yy] != miniset[ii])
if (miniset[ii] != 0 && dungeon[xx + sx][sy + yy] != miniset[ii])
abort = false;
if (L5dflags[xx + sx][sy + yy])
if (L5dflags[xx + sx][sy + yy] != 0)
abort = false;
ii++;
}
@ -1439,19 +1439,19 @@ static void L5firstRoom()
if (VR3)
L5roomGen(15, 29, 10, 10, 0);
HR3 = 0;
HR2 = 0;
HR1 = 0;
HR3 = false;
HR2 = false;
HR1 = false;
} else {
xs = 1;
xe = DMAXX - 1;
HR1 = GenerateRnd(2);
HR2 = GenerateRnd(2);
HR3 = GenerateRnd(2);
HR1 = GenerateRnd(2) != 0;
HR2 = GenerateRnd(2) != 0;
HR3 = GenerateRnd(2) != 0;
if (HR1 + HR3 <= 1)
HR2 = 1;
if (HR1 && HR3)
HR2 = true;
if (HR1)
L5drawRoom(1, 15, 10, 10);
else
@ -1548,7 +1548,7 @@ static int L5HWallOk(int i, int j)
bool wallok;
for (x = 1; dungeon[i + x][j] == 13; x++) {
if (dungeon[i + x][j - 1] != 13 || dungeon[i + x][j + 1] != 13 || L5dflags[i + x][j])
if (dungeon[i + x][j - 1] != 13 || dungeon[i + x][j + 1] != 13 || L5dflags[i + x][j] != 0)
break;
}
@ -1574,7 +1574,7 @@ static int L5VWallOk(int i, int j)
bool wallok;
for (y = 1; dungeon[i][j + y] == 13; y++) {
if (dungeon[i - 1][j + y] != 13 || dungeon[i + 1][j + y] != 13 || L5dflags[i][j + y])
if (dungeon[i - 1][j + y] != 13 || dungeon[i + 1][j + y] != 13 || L5dflags[i][j + y] != 0)
break;
}
@ -1698,7 +1698,7 @@ static void L5AddWall()
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
if (!L5dflags[i][j]) {
if (L5dflags[i][j] == 0) {
if (dungeon[i][j] == 3 && GenerateRnd(100) < WALL_CHANCE) {
x = L5HWallOk(i, j);
if (x != -1)
@ -1993,7 +1993,7 @@ static void DRLG_L5Subs()
if (GenerateRnd(4) == 0) {
BYTE c = L5BTYPES[dungeon[x][y]];
if (c && !L5dflags[x][y]) {
if (c != 0 && L5dflags[x][y] == 0) {
rv = GenerateRnd(16);
i = -1;
@ -2006,14 +2006,14 @@ static void DRLG_L5Subs()
// BUGFIX: Add `&& y > 0` to the if statement. (fixed)
if (i == 89 && y > 0) {
if (L5BTYPES[dungeon[x][y - 1]] != 79 || L5dflags[x][y - 1])
if (L5BTYPES[dungeon[x][y - 1]] != 79 || L5dflags[x][y - 1] != 0)
i = 79;
else
dungeon[x][y - 1] = 90;
}
// BUGFIX: Add `&& x + 1 < DMAXX` to the if statement. (fixed)
if (i == 91 && x + 1 < DMAXX) {
if (L5BTYPES[dungeon[x + 1][y]] != 80 || L5dflags[x + 1][y])
if (L5BTYPES[dungeon[x + 1][y]] != 80 || L5dflags[x + 1][y] != 0)
i = 80;
else
dungeon[x + 1][y] = 92;
@ -2181,13 +2181,13 @@ static void L5FillChambers()
}
} else {
int c = 1;
if (!HR1 && HR2 && HR3 && GenerateRnd(2))
if (!HR1 && HR2 && HR3 && GenerateRnd(2) != 0)
c = 2;
if (HR1 && HR2 && !HR3 && GenerateRnd(2))
if (HR1 && HR2 && !HR3 && GenerateRnd(2) != 0)
c = 0;
if (HR1 && !HR2 && HR3) {
if (GenerateRnd(2))
if (GenerateRnd(2) != 0)
c = 0;
else
c = 2;
@ -2288,7 +2288,7 @@ void drlg_l1_set_crypt_room(int rx1, int ry1)
for (int j = 0; j < rh; j++) {
for (int i = 0; i < rw; i++) {
if (UberRoomPattern[sp]) {
if (UberRoomPattern[sp] != 0) {
dungeon[rx1 + i][ry1 + j] = UberRoomPattern[sp];
L5dflags[rx1 + i][ry1 + j] |= DLRG_PROTECTED;
} else {
@ -2313,7 +2313,7 @@ void drlg_l1_set_corner_room(int rx1, int ry1)
for (int j = 0; j < rh; j++) {
for (int i = 0; i < rw; i++) {
if (CornerstoneRoomPattern[sp]) {
if (CornerstoneRoomPattern[sp] != 0) {
dungeon[rx1 + i][ry1 + j] = CornerstoneRoomPattern[sp];
L5dflags[rx1 + i][ry1 + j] |= DLRG_PROTECTED;
} else {
@ -2326,7 +2326,7 @@ void drlg_l1_set_corner_room(int rx1, int ry1)
static void DRLG_L5FTVR(int i, int j, int x, int y, int d)
{
if (dTransVal[x][y] || dungeon[i][j] != 13) {
if (dTransVal[x][y] != 0 || dungeon[i][j] != 13) {
if (d == 1) {
dTransVal[x][y] = TransVal;
dTransVal[x][y + 1] = TransVal;
@ -2376,7 +2376,7 @@ static void DRLG_L5FloodTVal()
int xx = 16;
for (int i = 0; i < DMAXX; i++) {
if (dungeon[i][j] == 13 && !dTransVal[xx][yy]) {
if (dungeon[i][j] == 13 && dTransVal[xx][yy] == 0) {
DRLG_L5FTVR(i, j, xx, yy, 0);
TransVal++;
}
@ -2465,7 +2465,7 @@ static void DRLG_L5CornerFix()
{
for (int j = 1; j < DMAXY - 1; j++) {
for (int i = 1; i < DMAXX - 1; i++) {
if (!(L5dflags[i][j] & DLRG_PROTECTED) && dungeon[i][j] == 17 && dungeon[i - 1][j] == 13 && dungeon[i][j - 1] == 1) {
if ((L5dflags[i][j] & DLRG_PROTECTED) == 0 && dungeon[i][j] == 17 && dungeon[i - 1][j] == 13 && dungeon[i][j - 1] == 1) {
dungeon[i][j] = 16;
L5dflags[i][j - 1] &= DLRG_PROTECTED;
}
@ -2632,7 +2632,7 @@ static void DRLG_L5(lvl_entry entry)
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
if (L5dflags[i][j] & ~DLRG_PROTECTED)
if ((L5dflags[i][j] & ~DLRG_PROTECTED) != 0)
DRLG_PlaceDoor(i, j);
}
}

View file

@ -20,7 +20,7 @@ void base::setup_password(std::string pw)
void base::run_event_handler(_SNETEVENT &ev)
{
auto f = registered_handlers[static_cast<event_type>(ev.eventid)];
if (f) {
if (f != nullptr) {
f(&ev);
}
}

View file

@ -44,12 +44,12 @@ void frame_queue::write(buffer_t buf)
bool frame_queue::packet_ready()
{
if (!nextsize) {
if (nextsize == 0) {
if (size() < sizeof(framesize_t))
return false;
auto szbuf = read(sizeof(framesize_t));
std::memcpy(&nextsize, &szbuf[0], sizeof(framesize_t));
if (!nextsize)
if (nextsize == 0)
throw frame_queue_exception();
}
if (size() >= nextsize)
@ -60,7 +60,7 @@ bool frame_queue::packet_ready()
buffer_t frame_queue::read_packet()
{
if (!nextsize || (size() < nextsize))
if (nextsize == 0 || size() < nextsize)
throw frame_queue_exception();
auto ret = read(nextsize);
nextsize = 0;

View file

@ -164,13 +164,13 @@ void packet_in::decrypt()
- crypto_secretbox_NONCEBYTES
- crypto_secretbox_MACBYTES);
decrypted_buffer.resize(pktlen);
if (crypto_secretbox_open_easy(decrypted_buffer.data(),
encrypted_buffer.data()
+ crypto_secretbox_NONCEBYTES,
encrypted_buffer.size()
- crypto_secretbox_NONCEBYTES,
encrypted_buffer.data(),
key.data()))
int status = crypto_secretbox_open_easy(
decrypted_buffer.data(),
encrypted_buffer.data() + crypto_secretbox_NONCEBYTES,
encrypted_buffer.size() - crypto_secretbox_NONCEBYTES,
encrypted_buffer.data(),
key.data());
if (status != 0)
throw packet_exception();
} else
#endif
@ -202,13 +202,13 @@ void packet_out::encrypt()
encrypted_buffer.insert(encrypted_buffer.end(),
crypto_secretbox_MACBYTES, 0);
randombytes_buf(encrypted_buffer.data(), crypto_secretbox_NONCEBYTES);
if (crypto_secretbox_easy(encrypted_buffer.data()
+ crypto_secretbox_NONCEBYTES,
encrypted_buffer.data()
+ crypto_secretbox_NONCEBYTES,
lenCleartext,
encrypted_buffer.data(),
key.data()))
int status = crypto_secretbox_easy(
encrypted_buffer.data() + crypto_secretbox_NONCEBYTES,
encrypted_buffer.data() + crypto_secretbox_NONCEBYTES,
lenCleartext,
encrypted_buffer.data(),
key.data());
if (status != 0)
ABORT();
}
#endif
@ -224,12 +224,16 @@ packet_factory::packet_factory(std::string pw)
pw.resize(std::max<std::size_t>(pw.size(), crypto_pwhash_argon2id_PASSWD_MIN), 0);
std::string salt("W9bE9dQgVaeybwr2");
salt.resize(crypto_pwhash_argon2id_SALTBYTES, 0);
if (crypto_pwhash(key.data(), crypto_secretbox_KEYBYTES,
pw.data(), pw.size(),
reinterpret_cast<const unsigned char *>(salt.data()),
3 * crypto_pwhash_argon2id_OPSLIMIT_MIN,
2 * crypto_pwhash_argon2id_MEMLIMIT_MIN,
crypto_pwhash_ALG_ARGON2ID13))
int status = crypto_pwhash(
key.data(),
crypto_secretbox_KEYBYTES,
pw.data(),
pw.size(),
reinterpret_cast<const unsigned char *>(salt.data()),
3 * crypto_pwhash_argon2id_OPSLIMIT_MIN,
2 * crypto_pwhash_argon2id_MEMLIMIT_MIN,
crypto_pwhash_ALG_ARGON2ID13);
if (status != 0)
ABORT();
#endif
}

View file

@ -256,7 +256,7 @@ bool protocol_zt::get_disconnected(endpoint &peer)
void protocol_zt::disconnect(const endpoint &peer)
{
if (peer_list.count(peer)) {
if (peer_list.count(peer) != 0) {
if (peer_list[peer].fd != -1) {
if (lwip_close(peer_list[peer].fd) < 0) {
Log("lwip_close: {}", strerror(errno));
@ -291,7 +291,7 @@ protocol_zt::~protocol_zt()
void protocol_zt::endpoint::from_string(const std::string &str)
{
ip_addr_t a;
if (!ipaddr_aton(str.c_str(), &a))
if (ipaddr_aton(str.c_str(), &a) == 0)
return;
if (!IP_IS_V6_VAL(a))
return;

View file

@ -194,9 +194,8 @@ void tcp_server::handle_timeout(const scc &con, const asio::error_code &ec)
}
if (con->timeout > 0)
con->timeout -= 1;
if (con->timeout < 0)
if (con->timeout <= 0) {
con->timeout = 0;
if (!con->timeout) {
drop_connection(con);
return;
}

View file

@ -1170,10 +1170,10 @@ static void PlaySFX_priv(TSFX *pSFX, bool loc, int x, int y)
{
int lPan, lVolume;
if (plr[myplr].pLvlLoad && gbIsMultiplayer) {
if (plr[myplr].pLvlLoad != 0 && gbIsMultiplayer) {
return;
}
if (!gbSndInited || !gbSoundOn || gbBufferMsgs) {
if (!gbSndInited || !gbSoundOn || gbBufferMsgs != 0) {
return;
}
@ -1203,12 +1203,12 @@ void PlayEffect(int i, int mode)
{
int sndIdx, mi, lVolume, lPan;
if (plr[myplr].pLvlLoad) {
if (plr[myplr].pLvlLoad != 0) {
return;
}
sndIdx = GenerateRnd(2);
if (!gbSndInited || !gbSoundOn || gbBufferMsgs) {
if (!gbSndInited || !gbSoundOn || gbBufferMsgs != 0) {
return;
}

View file

@ -46,7 +46,7 @@ uint32_t Hash(const char *s, int type)
{
uint32_t seed1 = 0x7FED7FED;
uint32_t seed2 = 0xEEEEEEEE;
while (s != nullptr && *s) {
while (s != nullptr && (*s != '\0')) {
int8_t ch = *s++;
ch = toupper(ch);
seed1 = hashtable[type][ch] ^ (seed1 + seed2);

View file

@ -615,7 +615,7 @@ void CalcPlrItemVals(int playerId, bool Loadgfx)
if (itm->_iMagical == ITEM_QUALITY_NORMAL || itm->_iIdentified) {
bdam += itm->_iPLDam;
btohit += itm->_iPLToHit;
if (itm->_iPLAC) {
if (itm->_iPLAC != 0) {
int tmpac = itm->_iAC;
tmpac *= itm->_iPLAC;
tmpac /= 100;
@ -2232,7 +2232,7 @@ void GetItemBonus(int i, int minlvl, int maxlvl, bool onlygood, bool allowspells
void SetupItem(int i)
{
items[i].SetNewAnimation(!plr[myplr].pLvlLoad);
items[i].SetNewAnimation(plr[myplr].pLvlLoad == 0);
items[i]._iIdentified = false;
}
@ -2780,7 +2780,7 @@ void items_427ABA(Point position)
CornerStone.item._itype = ITYPE_NONE;
CornerStone.activated = true;
if (dItem[position.x][position.y]) {
if (dItem[position.x][position.y] != 0) {
int ii = dItem[position.x][position.y] - 1;
for (int i = 0; i < numitems; i++) {
if (itemactive[i] == ii) {
@ -2808,7 +2808,7 @@ void items_427ABA(Point position)
void SpawnQuestItem(int itemid, Point position, int randarea, int selflag)
{
if (randarea) {
if (randarea > 0) {
int tries = 0;
while (true) {
tries++;
@ -2844,7 +2844,7 @@ void SpawnQuestItem(int itemid, Point position, int randarea, int selflag)
SetupItem(ii);
items[ii]._iSeed = AdvanceRndSeed();
items[ii]._iPostDraw = true;
if (selflag) {
if (selflag != 0) {
items[ii]._iSelFlag = selflag;
items[ii].AnimInfo.CurrentFrame = items[ii].AnimInfo.NumberOfFrames;
items[ii]._iAnimFlag = false;
@ -3038,7 +3038,7 @@ static void RepairItem(ItemStruct *i, int lvl)
do {
rep += lvl + GenerateRnd(lvl);
i->_iMaxDur -= std::max(i->_iMaxDur / (lvl + 9), 1);
if (!i->_iMaxDur) {
if (i->_iMaxDur == 0) {
i->_itype = ITYPE_NONE;
return;
}
@ -3782,11 +3782,11 @@ static void PrintItemInfo(ItemStruct *x)
uint8_t mag = x->_iMinMag;
if (str != 0 || mag != 0 || dex != 0) {
strcpy(tempstr, _("Required:"));
if (str)
if (str != 0)
strcpy(tempstr + strlen(tempstr), fmt::format(_(" {:d} Str"), str).c_str());
if (mag)
if (mag != 0)
strcpy(tempstr + strlen(tempstr), fmt::format(_(" {:d} Mag"), mag).c_str());
if (dex)
if (dex != 0)
strcpy(tempstr + strlen(tempstr), fmt::format(_(" {:d} Dex"), dex).c_str());
AddPanelString(tempstr);
}

View file

@ -218,7 +218,7 @@ struct ItemStruct {
int16_t _iPLGetHit;
int16_t _iPLLight;
int8_t _iSplLvlAdd;
int8_t _iRequest;
bool _iRequest;
int _iUid;
int16_t _iFMinDam;
int16_t _iFMaxDam;

View file

@ -1125,7 +1125,7 @@ int AddVision(Point position, int r, bool mine)
VisionList[numvision]._lid = vid;
VisionList[numvision]._ldel = false;
VisionList[numvision]._lunflag = false;
VisionList[numvision]._lflags = mine != 0;
VisionList[numvision]._lflags = mine;
numvision++;
dovision = true;
}

View file

@ -263,7 +263,7 @@ static void LoadItemData(LoadHelper *file, ItemStruct *pItem)
pItem->_iPLGetHit = file->nextLE<int32_t>();
pItem->_iPLLight = file->nextLE<int32_t>();
pItem->_iSplLvlAdd = file->nextLE<int8_t>();
pItem->_iRequest = file->nextLE<int8_t>();
pItem->_iRequest = file->nextBool8();
file->skip(2); // Alignment
pItem->_iUid = file->nextLE<int32_t>();
pItem->_iFMinDam = file->nextLE<int32_t>();
@ -687,7 +687,7 @@ static void LoadMissile(LoadHelper *file, int i)
pMissile->_miVar5 = file->nextLE<int32_t>();
pMissile->_miVar6 = file->nextLE<int32_t>();
pMissile->_miVar7 = file->nextLE<int32_t>();
pMissile->_miVar8 = file->nextBool32();
pMissile->limitReached = file->nextBool32();
}
static void LoadObject(LoadHelper *file, int i)
@ -1284,7 +1284,7 @@ static void SaveItem(SaveHelper *file, ItemStruct *pItem)
file->writeLE<int32_t>(iType);
file->writeLE<int32_t>(pItem->position.x);
file->writeLE<int32_t>(pItem->position.y);
file->writeLE<uint32_t>(pItem->_iAnimFlag);
file->writeLE<uint32_t>(pItem->_iAnimFlag ? 1 : 0);
file->skip(4); // Skip pointer _iAnimData
file->writeLE<int32_t>(pItem->AnimInfo.NumberOfFrames);
file->writeLE<int32_t>(pItem->AnimInfo.CurrentFrame);
@ -1295,8 +1295,8 @@ static void SaveItem(SaveHelper *file, ItemStruct *pItem)
file->skip(4); // Unused since 1.02
file->writeLE<uint8_t>(pItem->_iSelFlag);
file->skip(3); // Alignment
file->writeLE<uint32_t>(pItem->_iPostDraw);
file->writeLE<uint32_t>(pItem->_iIdentified);
file->writeLE<uint32_t>(pItem->_iPostDraw ? 1 : 0);
file->writeLE<uint32_t>(pItem->_iIdentified ? 1 : 0);
file->writeLE<int8_t>(pItem->_iMagical);
file->writeBytes(pItem->_iName, 64);
file->writeBytes(pItem->_iIName, 64);
@ -1332,7 +1332,7 @@ static void SaveItem(SaveHelper *file, ItemStruct *pItem)
file->writeLE<int32_t>(pItem->_iPLGetHit);
file->writeLE<int32_t>(pItem->_iPLLight);
file->writeLE<int8_t>(pItem->_iSplLvlAdd);
file->writeLE<int8_t>(pItem->_iRequest);
file->writeLE<int8_t>(pItem->_iRequest ? 1 : 0);
file->skip(2); // Alignment
file->writeLE<int32_t>(pItem->_iUid);
file->writeLE<int32_t>(pItem->_iFMinDam);
@ -1351,7 +1351,7 @@ static void SaveItem(SaveHelper *file, ItemStruct *pItem)
file->writeLE<uint8_t>(pItem->_iMinMag);
file->writeLE<int8_t>(pItem->_iMinDex);
file->skip(1); // Alignment
file->writeLE<uint32_t>(pItem->_iStatFlag);
file->writeLE<uint32_t>(pItem->_iStatFlag ? 1 : 0);
file->writeLE<int32_t>(idx);
file->writeLE<uint32_t>(pItem->dwBuff);
if (gbIsHellfire)
@ -1372,7 +1372,7 @@ static void SavePlayer(SaveHelper *file, int p)
file->writeLE<int32_t>(player._pmode);
for (int8_t step : player.walkpath)
file->writeLE<int8_t>(step);
file->writeLE<uint8_t>(player.plractive);
file->writeLE<uint8_t>(player.plractive ? 1 : 0);
file->skip(2); // Alignment
file->writeLE<int32_t>(player.destAction);
file->writeLE<int32_t>(player.destParam1);
@ -1441,10 +1441,10 @@ static void SavePlayer(SaveHelper *file, int p)
file->writeLE<int8_t>(spellType);
file->writeLE<int32_t>(player._pwtype);
file->writeLE<uint8_t>(player._pBlockFlag);
file->writeLE<uint8_t>(player._pInvincible);
file->writeLE<uint8_t>(player._pBlockFlag ? 1 : 0);
file->writeLE<uint8_t>(player._pInvincible ? 1 : 0);
file->writeLE<int8_t>(player._pLightRad);
file->writeLE<uint8_t>(player._pLvlChanging);
file->writeLE<uint8_t>(player._pLvlChanging ? 1 : 0);
file->writeBytes(player._pName, PLR_NAME_LEN);
file->writeLE<int8_t>(static_cast<int8_t>(player._pClass));
@ -1483,7 +1483,7 @@ static void SavePlayer(SaveHelper *file, int p)
file->writeLE<int8_t>(player._pLghtResist);
file->writeLE<int32_t>(player._pGold);
file->writeLE<uint32_t>(player._pInfraFlag);
file->writeLE<uint32_t>(player._pInfraFlag ? 1 : 0);
file->writeLE<int32_t>(player.position.temp.x);
file->writeLE<int32_t>(player.position.temp.y);
file->writeLE<int32_t>(player.tempDirection);
@ -1494,9 +1494,9 @@ static void SavePlayer(SaveHelper *file, int p)
// Write actionFrame for vanilla compatibility
file->writeLE<int32_t>(0);
for (uint8_t i = 0; i < giNumberOfLevels; i++)
file->writeLE<uint8_t>(player._pLvlVisited[i]);
file->writeLE<uint8_t>(player._pLvlVisited[i] ? 1 : 0);
for (uint8_t i = 0; i < giNumberOfLevels; i++)
file->writeLE<uint8_t>(player._pSLvlVisited[i]); // only 10 used
file->writeLE<uint8_t>(player._pSLvlVisited[i] ? 1 : 0); // only 10 used
file->skip(2); // Alignment
@ -1565,9 +1565,9 @@ static void SavePlayer(SaveHelper *file, int p)
if (gbIsHellfire)
file->writeLE<uint8_t>(player.pDungMsgs2);
else
file->writeLE<uint8_t>(player.pBattleNet);
file->writeLE<uint8_t>(player.pManaShield);
file->writeLE<uint8_t>(player.pOriginalCathedral);
file->writeLE<uint8_t>(player.pBattleNet ? 1 : 0);
file->writeLE<uint8_t>(player.pManaShield ? 1 : 0);
file->writeLE<uint8_t>(player.pOriginalCathedral ? 1 : 0);
file->skip(2); // Available bytes
file->writeLE<uint16_t>(player.wReflections);
file->skip(14); // Available bytes
@ -1625,7 +1625,7 @@ static void SaveMonster(SaveHelper *file, int i)
file->writeLE<int32_t>(pMonster->AnimInfo.NumberOfFrames);
file->writeLE<int32_t>(pMonster->AnimInfo.CurrentFrame);
file->skip(4); // Skip _meflag
file->writeLE<uint32_t>(pMonster->_mDelFlag);
file->writeLE<uint32_t>(pMonster->_mDelFlag ? 1 : 0);
file->writeLE<int32_t>(pMonster->_mVar1);
file->writeLE<int32_t>(pMonster->_mVar2);
file->writeLE<int32_t>(pMonster->_mVar3);
@ -1699,7 +1699,7 @@ static void SaveMissile(SaveHelper *file, int i)
file->writeLE<int32_t>(pMissile->position.traveled.y);
file->writeLE<int32_t>(pMissile->_mimfnum);
file->writeLE<int32_t>(pMissile->_mispllvl);
file->writeLE<uint32_t>(pMissile->_miDelFlag);
file->writeLE<uint32_t>(pMissile->_miDelFlag ? 1 : 0);
file->writeLE<uint8_t>(pMissile->_miAnimType);
file->skip(3); // Alignment
file->writeLE<int32_t>(pMissile->_miAnimFlags);
@ -1711,15 +1711,15 @@ static void SaveMissile(SaveHelper *file, int i)
file->writeLE<int32_t>(pMissile->_miAnimCnt);
file->writeLE<int32_t>(pMissile->_miAnimAdd);
file->writeLE<int32_t>(pMissile->_miAnimFrame);
file->writeLE<uint32_t>(pMissile->_miDrawFlag);
file->writeLE<uint32_t>(pMissile->_miLightFlag);
file->writeLE<uint32_t>(pMissile->_miPreFlag);
file->writeLE<uint32_t>(pMissile->_miDrawFlag ? 1 : 0);
file->writeLE<uint32_t>(pMissile->_miLightFlag ? 1 : 0);
file->writeLE<uint32_t>(pMissile->_miPreFlag ? 1 : 0);
file->writeLE<uint32_t>(pMissile->_miUniqTrans);
file->writeLE<int32_t>(pMissile->_mirange);
file->writeLE<int32_t>(pMissile->_misource);
file->writeLE<int32_t>(pMissile->_micaster);
file->writeLE<int32_t>(pMissile->_midam);
file->writeLE<uint32_t>(pMissile->_miHitFlag);
file->writeLE<uint32_t>(pMissile->_miHitFlag ? 1 : 0);
file->writeLE<int32_t>(pMissile->_midist);
file->writeLE<int32_t>(pMissile->_mlid);
file->writeLE<int32_t>(pMissile->_mirnd);
@ -1730,7 +1730,7 @@ static void SaveMissile(SaveHelper *file, int i)
file->writeLE<int32_t>(pMissile->_miVar5);
file->writeLE<int32_t>(pMissile->_miVar6);
file->writeLE<int32_t>(pMissile->_miVar7);
file->writeLE<int32_t>(pMissile->_miVar8);
file->writeLE<uint32_t>(pMissile->limitReached ? 1 : 0);
}
static void SaveObject(SaveHelper *file, int i)
@ -1740,7 +1740,7 @@ static void SaveObject(SaveHelper *file, int i)
file->writeLE<int32_t>(pObject->_otype);
file->writeLE<int32_t>(pObject->position.x);
file->writeLE<int32_t>(pObject->position.y);
file->writeLE<uint32_t>(pObject->_oLight);
file->writeLE<uint32_t>(pObject->_oLight ? 1 : 0);
file->writeLE<uint32_t>(pObject->_oAnimFlag);
file->skip(4); // Skip pointer _oAnimData
file->writeLE<int32_t>(pObject->_oAnimDelay);
@ -1750,17 +1750,17 @@ static void SaveObject(SaveHelper *file, int i)
file->writeLE<int32_t>(pObject->_oAnimWidth);
file->writeLE<int32_t>(CalculateWidth2(pObject->_oAnimWidth));
// Write _oAnimWidth2 for vanilla compatibility
file->writeLE<uint32_t>(pObject->_oDelFlag);
file->writeLE<uint32_t>(pObject->_oDelFlag ? 1 : 0);
file->writeLE<int8_t>(pObject->_oBreak);
file->skip(3); // Alignment
file->writeLE<uint32_t>(pObject->_oSolidFlag);
file->writeLE<uint32_t>(pObject->_oMissFlag);
file->writeLE<uint32_t>(pObject->_oSolidFlag ? 1 : 0);
file->writeLE<uint32_t>(pObject->_oMissFlag ? 1 : 0);
file->writeLE<int8_t>(pObject->_oSelFlag);
file->skip(3); // Alignment
file->writeLE<uint32_t>(pObject->_oPreFlag);
file->writeLE<uint32_t>(pObject->_oTrapFlag);
file->writeLE<uint32_t>(pObject->_oDoorFlag);
file->writeLE<uint32_t>(pObject->_oPreFlag ? 1 : 0);
file->writeLE<uint32_t>(pObject->_oTrapFlag ? 1 : 0);
file->writeLE<uint32_t>(pObject->_oDoorFlag ? 1 : 0);
file->writeLE<int32_t>(pObject->_olid);
file->writeLE<int32_t>(pObject->_oRndSeed);
file->writeLE<int32_t>(pObject->_oVar1);
@ -1801,7 +1801,7 @@ static void SaveQuest(SaveHelper *file, int i)
file->skip(2); // Alignment
if (!gbIsHellfire)
file->skip(1); // Alignment
file->writeLE<uint32_t>(pQuest->_qlog);
file->writeLE<uint32_t>(pQuest->_qlog ? 1 : 0);
file->writeBE<int32_t>(ReturnLvlX);
file->writeBE<int32_t>(ReturnLvlY);
@ -1816,27 +1816,27 @@ static void SaveLighting(SaveHelper *file, LightListStruct *pLight)
file->writeLE<int32_t>(pLight->position.tile.y);
file->writeLE<int32_t>(pLight->_lradius);
file->writeLE<int32_t>(pLight->_lid);
file->writeLE<uint32_t>(pLight->_ldel);
file->writeLE<uint32_t>(pLight->_lunflag);
file->writeLE<uint32_t>(pLight->_ldel ? 1 : 0);
file->writeLE<uint32_t>(pLight->_lunflag ? 1 : 0);
file->skip(4); // Unused
file->writeLE<int32_t>(pLight->position.old.x);
file->writeLE<int32_t>(pLight->position.old.y);
file->writeLE<int32_t>(pLight->oldRadious);
file->writeLE<int32_t>(pLight->position.offset.x);
file->writeLE<int32_t>(pLight->position.offset.y);
file->writeLE<uint32_t>(pLight->_lflags);
file->writeLE<uint32_t>(pLight->_lflags ? 1 : 0);
}
static void SavePortal(SaveHelper *file, int i)
{
PortalStruct *pPortal = &portal[i];
file->writeLE<uint32_t>(pPortal->open);
file->writeLE<uint32_t>(pPortal->open ? 1 : 0);
file->writeLE<int32_t>(pPortal->position.x);
file->writeLE<int32_t>(pPortal->position.y);
file->writeLE<int32_t>(pPortal->level);
file->writeLE<int32_t>(pPortal->ltype);
file->writeLE<uint32_t>(pPortal->setlvl);
file->writeLE<uint32_t>(pPortal->setlvl ? 1 : 0);
}
const int DiabloItemSaveSize = 368;
@ -1847,7 +1847,7 @@ void SaveHeroItems(PlayerStruct &player)
size_t items = NUM_INVLOC + NUM_INV_GRID_ELEM + MAXBELTITEMS;
SaveHelper file("heroitems", items * (gbIsHellfire ? HellfireItemSaveSize : DiabloItemSaveSize) + sizeof(uint8_t));
file.writeLE<uint8_t>(gbIsHellfire);
file.writeLE<uint8_t>(gbIsHellfire ? 1 : 0);
SaveItems(&file, player.InvBody, NUM_INVLOC);
SaveItems(&file, player.InvList, NUM_INV_GRID_ELEM);
@ -1883,14 +1883,14 @@ void SaveGameData()
giNumberOfSmithPremiumItems = 6;
}
file.writeLE<uint8_t>(setlevel);
file.writeLE<uint8_t>(setlevel ? 1 : 0);
file.writeBE<uint32_t>(setlvlnum);
file.writeBE<uint32_t>(currlevel);
file.writeBE<uint32_t>(leveltype);
file.writeBE<int32_t>(ViewX);
file.writeBE<int32_t>(ViewY);
file.writeLE<uint8_t>(invflag);
file.writeLE<uint8_t>(chrflag);
file.writeLE<uint8_t>(invflag ? 1 : 0);
file.writeLE<uint8_t>(chrflag ? 1 : 0);
file.writeBE<int32_t>(nummonsters);
file.writeBE<int32_t>(numitems);
file.writeBE<int32_t>(nummissiles);
@ -1950,7 +1950,7 @@ void SaveGameData()
for (int i = 0; i < numitems; i++)
SaveItem(&file, &items[itemactive[i]]);
for (bool UniqueItemFlag : UniqueItemFlags)
file.writeLE<int8_t>(UniqueItemFlag);
file.writeLE<uint8_t>(UniqueItemFlag ? 1 : 0);
for (int j = 0; j < MAXDUNY; j++) {
for (int i = 0; i < MAXDUNX; i++)
@ -1992,7 +1992,7 @@ void SaveGameData()
}
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++)
file.writeLE<uint8_t>(AutomapView[i][j]);
file.writeLE<uint8_t>(AutomapView[i][j] ? 1 : 0);
}
for (int j = 0; j < MAXDUNY; j++) {
for (int i = 0; i < MAXDUNX; i++)
@ -2006,7 +2006,7 @@ void SaveGameData()
for (int i = 0; i < giNumberOfSmithPremiumItems; i++)
SavePremium(&file, i);
file.writeLE<uint8_t>(AutomapActive);
file.writeLE<uint8_t>(AutomapActive ? 1 : 0);
file.writeBE<int32_t>(AutoMapScale);
}
@ -2089,7 +2089,7 @@ void SaveLevel()
}
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++)
file.writeLE<uint8_t>(AutomapView[i][j]);
file.writeLE<uint8_t>(AutomapView[i][j] ? 1 : 0);
}
for (int j = 0; j < MAXDUNY; j++) {
for (int i = 0; i < MAXDUNX; i++)

View file

@ -312,7 +312,7 @@ bool FetchMessage(tagMSG *lpMsg)
}
SDL_Event e;
if (!SDL_PollEvent(&e)) {
if (SDL_PollEvent(&e) == 0) {
return false;
}

View file

@ -434,15 +434,15 @@ bool MonsterTrapHit(int m, int mindam, int maxdam, int dist, int t, bool shift)
missile_resistance mir = missiledata[t].mResist;
mor = monster[m].mMagicRes;
if ((mor & IMMUNE_MAGIC && mir == MISR_MAGIC)
|| (mor & IMMUNE_FIRE && mir == MISR_FIRE)
|| (mor & IMMUNE_LIGHTNING && mir == MISR_LIGHTNING)) {
if (((mor & IMMUNE_MAGIC) != 0 && mir == MISR_MAGIC)
|| ((mor & IMMUNE_FIRE) != 0 && mir == MISR_FIRE)
|| ((mor & IMMUNE_LIGHTNING) != 0 && mir == MISR_LIGHTNING)) {
return false;
}
if ((mor & RESIST_MAGIC && mir == MISR_MAGIC)
|| (mor & RESIST_FIRE && mir == MISR_FIRE)
|| (mor & RESIST_LIGHTNING && mir == MISR_LIGHTNING)) {
if (((mor & RESIST_MAGIC) != 0 && mir == MISR_MAGIC)
|| ((mor & RESIST_FIRE) != 0 && mir == MISR_FIRE)
|| ((mor & RESIST_LIGHTNING) != 0 && mir == MISR_LIGHTNING)) {
resist = true;
}
@ -491,9 +491,8 @@ bool MonsterTrapHit(int m, int mindam, int maxdam, int dist, int t, bool shift)
}
}
return true;
} else {
return false;
}
return false;
}
bool MonsterMHit(int pnum, int m, int mindam, int maxdam, int dist, int t, bool shift)
@ -514,15 +513,15 @@ bool MonsterMHit(int pnum, int m, int mindam, int maxdam, int dist, int t, bool
uint8_t mor = monster[m].mMagicRes;
missile_resistance mir = missiledata[t].mResist;
if ((mor & IMMUNE_MAGIC && mir == MISR_MAGIC)
|| (mor & IMMUNE_FIRE && mir == MISR_FIRE)
|| (mor & IMMUNE_LIGHTNING && mir == MISR_LIGHTNING)
|| (mor & IMMUNE_ACID && mir == MISR_ACID))
if (((mor & IMMUNE_MAGIC) != 0 && mir == MISR_MAGIC)
|| ((mor & IMMUNE_FIRE) != 0 && mir == MISR_FIRE)
|| ((mor & IMMUNE_LIGHTNING) != 0 && mir == MISR_LIGHTNING)
|| ((mor & IMMUNE_ACID) != 0 && mir == MISR_ACID))
return false;
if ((mor & RESIST_MAGIC && mir == MISR_MAGIC)
|| (mor & RESIST_FIRE && mir == MISR_FIRE)
|| (mor & RESIST_LIGHTNING && mir == MISR_LIGHTNING))
if (((mor & RESIST_MAGIC) != 0 && mir == MISR_MAGIC)
|| ((mor & RESIST_FIRE) != 0 && mir == MISR_FIRE)
|| ((mor & RESIST_LIGHTNING) != 0 && mir == MISR_LIGHTNING))
resist = true;
if (gbIsHellfire && t == MIS_HBOLT && (monster[m].MType->mtype == MT_DIABLO || monster[m].MType->mtype == MT_BONEDEMN))
@ -595,7 +594,7 @@ bool MonsterMHit(int pnum, int m, int mindam, int maxdam, int dist, int t, bool
if (pnum == myplr)
monster[m]._mhitpoints -= dam;
if ((gbIsHellfire && plr[pnum]._pIFlags & ISPL_NOHEALMON) || (!gbIsHellfire && plr[pnum]._pIFlags & ISPL_FIRE_ARROWS))
if ((gbIsHellfire && (plr[pnum]._pIFlags & ISPL_NOHEALMON) != 0) || (!gbIsHellfire && (plr[pnum]._pIFlags & ISPL_FIRE_ARROWS) != 0))
monster[m]._mFlags |= MFLAG_NOHEAL;
if (monster[m]._mhitpoints >> 6 <= 0) {
@ -613,7 +612,7 @@ bool MonsterMHit(int pnum, int m, int mindam, int maxdam, int dist, int t, bool
M_StartHit(m, pnum, dam);
monster[m].Petrify();
} else {
if (missiledata[t].mType == 0 && plr[pnum]._pIFlags & ISPL_KNOCKBACK) {
if (missiledata[t].mType == 0 && (plr[pnum]._pIFlags & ISPL_KNOCKBACK) != 0) {
M_GetKnockback(m);
}
if (m > MAX_PLRS - 1)
@ -644,7 +643,7 @@ bool PlayerMHit(int pnum, int m, int dist, int mind, int maxd, int mtype, bool s
return false;
}
if ((player._pSpellFlags & 1) && missiledata[mtype].mType == 0) {
if ((player._pSpellFlags & 1) != 0 && missiledata[mtype].mType == 0) {
return false;
}
@ -778,7 +777,7 @@ bool Plr2PlrMHit(int pnum, int p, int mindam, int maxdam, int dist, int mtype, b
{
int dam, hit, resper;
if (!sgGameInitInfo.bFriendlyFire && gbFriendlyMode)
if (sgGameInitInfo.bFriendlyFire == 0 && gbFriendlyMode)
return false;
*blocked = false;
@ -794,7 +793,7 @@ bool Plr2PlrMHit(int pnum, int p, int mindam, int maxdam, int dist, int mtype, b
return false;
}
if ((target._pSpellFlags & 1) && missiledata[mtype].mType == 0) {
if ((target._pSpellFlags & 1) != 0 && missiledata[mtype].mType == 0) {
return false;
}
@ -956,9 +955,9 @@ void CheckMissileCol(int i, int mindam, int maxdam, bool shift, Point position,
missile[i]._miHitFlag = true;
}
} else {
if (monster[missile[i]._misource]._mFlags & MFLAG_TARGETS_MONSTER
if ((monster[missile[i]._misource]._mFlags & MFLAG_TARGETS_MONSTER) != 0
&& dMonster[mx][my] > 0
&& monster[dMonster[mx][my] - 1]._mFlags & MFLAG_GOLEM
&& (monster[dMonster[mx][my] - 1]._mFlags & MFLAG_GOLEM) != 0
&& MonsterTrapHit(dMonster[mx][my] - 1, mindam, maxdam, missile[i]._midist, missile[i]._mitype, shift)) {
if (!nodel)
missile[i]._mirange = 0;
@ -1020,7 +1019,7 @@ void CheckMissileCol(int i, int mindam, int maxdam, bool shift, Point position,
maxdam,
missile[i]._mitype,
shift,
missile[i]._miAnimType == MFILE_FIREWAL || missile[i]._miAnimType == MFILE_LGHNING,
(missile[i]._miAnimType == MFILE_FIREWAL || missile[i]._miAnimType == MFILE_LGHNING) ? 1 : 0,
&blocked)) {
if (gbIsHellfire && blocked) {
dir = missile[i]._mimfnum + (GenerateRnd(2) != 0 ? 1 : -1);
@ -1109,7 +1108,7 @@ void InitMissileGFX()
{
int mi;
for (mi = 0; misfiledata[mi].mAnimFAmt; mi++) {
for (mi = 0; misfiledata[mi].mAnimFAmt != 0; mi++) {
if (!gbIsHellfire && mi > MFILE_SCBSEXPD)
break;
if ((misfiledata[mi].mFlags & MFLAG_HIDDEN) == 0)
@ -1122,8 +1121,8 @@ void FreeMissileGFX(int mi)
int i;
DWORD *p;
if (misfiledata[mi].mFlags & MFLAG_ALLOW_SPECIAL) {
if (misfiledata[mi].mAnimData[0]) {
if ((misfiledata[mi].mFlags & MFLAG_ALLOW_SPECIAL) != 0) {
if (misfiledata[mi].mAnimData[0] != nullptr) {
p = (DWORD *)misfiledata[mi].mAnimData[0];
p -= misfiledata[mi].mAnimFAmt;
delete[] p;
@ -1144,8 +1143,8 @@ void FreeMissiles()
{
int mi;
for (mi = 0; misfiledata[mi].mAnimFAmt; mi++) {
if (!(misfiledata[mi].mFlags & MFLAG_HIDDEN))
for (mi = 0; misfiledata[mi].mAnimFAmt != 0; mi++) {
if ((misfiledata[mi].mFlags & MFLAG_HIDDEN) == 0)
FreeMissileGFX(mi);
}
}
@ -1154,8 +1153,8 @@ void FreeMissiles2()
{
int mi;
for (mi = 0; misfiledata[mi].mAnimFAmt; mi++) {
if (misfiledata[mi].mFlags & MFLAG_HIDDEN)
for (mi = 0; misfiledata[mi].mAnimFAmt != 0; mi++) {
if ((misfiledata[mi].mFlags & MFLAG_HIDDEN) != 0)
FreeMissileGFX(mi);
}
}
@ -1334,7 +1333,7 @@ void AddReflection(int mi, Point src, Point dst, int midir, int8_t mienemy, int
{
if (id >= 0) {
int lvl = 2;
if (missile[mi]._mispllvl)
if (missile[mi]._mispllvl != 0)
lvl = missile[mi]._mispllvl;
plr[id].wReflections += lvl * plr[id]._pLevel;
@ -1374,7 +1373,7 @@ void AddBerserk(int mi, Point src, Point dst, int midir, int8_t mienemy, int id,
continue;
if ((monster[dm].mMagicRes & IMMUNE_MAGIC) != 0)
continue;
if ((monster[dm].mMagicRes & RESIST_MAGIC) != 0 && ((monster[dm].mMagicRes & RESIST_MAGIC) != 1 || GenerateRnd(2)))
if ((monster[dm].mMagicRes & RESIST_MAGIC) != 0 && ((monster[dm].mMagicRes & RESIST_MAGIC) != 1 || GenerateRnd(2) != 0))
continue;
if (monster[dm]._mmode == MM_CHARGE)
continue;
@ -1754,7 +1753,7 @@ void AddRing(int mi, Point src, Point dst, int midir, int8_t mienemy, int id, in
missile[mi]._miVar5 = 0;
missile[mi]._miVar6 = 0;
missile[mi]._miVar7 = 0;
missile[mi]._miVar8 = 0;
missile[mi].limitReached = false;
missile[mi]._mirange = 7;
}
@ -1771,7 +1770,7 @@ void AddSearch(int mi, Point src, Point dst, int midir, int8_t mienemy, int id,
missile[mi]._miVar5 = 0;
missile[mi]._miVar6 = 0;
missile[mi]._miVar7 = 0;
missile[mi]._miVar8 = 0;
missile[mi].limitReached = false;
AutoMapShowItems = true;
int lvl = 2;
if (id > -1)
@ -1981,7 +1980,7 @@ void AddMagmaball(int mi, Point src, Point dst, int midir, int8_t mienemy, int i
missile[mi].position.traveled.x += 3 * missile[mi].position.velocity.x;
missile[mi].position.traveled.y += 3 * missile[mi].position.velocity.y;
GetMissilePos(mi);
if (!gbIsHellfire || missile[mi].position.velocity.x & 0xFFFF0000 || missile[mi].position.velocity.y & 0xFFFF0000)
if (!gbIsHellfire || (missile[mi].position.velocity.x & 0xFFFF0000) != 0 || (missile[mi].position.velocity.y & 0xFFFF0000) != 0)
missile[mi]._mirange = 256;
else
missile[mi]._mirange = 1;
@ -2011,7 +2010,7 @@ void AddTeleport(int mi, Point src, Point dst, int midir, int8_t mienemy, int id
tx = dst.x + CrawlTable[pn - 1];
ty = dst.y + CrawlTable[pn];
if (0 < tx && tx < MAXDUNX && 0 < ty && ty < MAXDUNY) {
if ((nSolidTable[dPiece[tx][ty]] | dMonster[tx][ty] | dObject[tx][ty] | dPlayer[tx][ty]) == 0) {
if (!nSolidTable[dPiece[tx][ty]] && dMonster[tx][ty] == 0 && dObject[tx][ty] == 0 && dPlayer[tx][ty] == 0) {
missile[mi].position.tile = { tx, ty };
missile[mi].position.start = { tx, ty };
missile[mi]._miDelFlag = false;
@ -2090,7 +2089,7 @@ void AddFireball(int mi, Point src, Point dst, int midir, int8_t mienemy, int id
void AddLightctrl(int mi, Point src, Point dst, int midir, int8_t mienemy, int id, int dam)
{
if (!dam && mienemy == TARGET_MONSTERS)
if (dam == 0 && mienemy == TARGET_MONSTERS)
UseMana(id, SPL_LIGHTNING);
missile[mi]._miVar1 = src.x;
missile[mi]._miVar2 = src.y;
@ -2121,7 +2120,7 @@ void AddLightning(int mi, Point src, Point dst, int midir, int8_t mienemy, int i
void AddMisexp(int mi, Point src, Point dst, int midir, int8_t mienemy, int id, int dam)
{
if (mienemy && id > 0) {
if (mienemy != 0 && id > 0) {
switch (monster[id].MType->mtype) {
case MT_SUCCUBUS:
SetMissAnim(mi, MFILE_FLAREEXP);
@ -2186,7 +2185,7 @@ void AddTown(int mi, Point src, Point dst, int midir, int8_t mienemy, int id, in
ty = dst.y + CrawlTable[k];
if (InDungeonBounds({ tx, ty })) {
dp = dPiece[tx][ty];
if ((dMissile[tx][ty] | nSolidTable[dp] | nMissileTable[dp] | dObject[tx][ty] | dPlayer[tx][ty]) == 0) {
if (dMissile[tx][ty] == 0 && !nSolidTable[dp] && !nMissileTable[dp] && dObject[tx][ty] == 0 && dPlayer[tx][ty] == 0) {
if (!CheckIfTrig({ tx, ty })) {
missile[mi].position.tile = { tx, ty };
missile[mi].position.start = { tx, ty };
@ -2295,7 +2294,7 @@ void AddGuardian(int mi, Point src, Point dst, int midir, int8_t mienemy, int id
pn = dPiece[tx][ty];
if (InDungeonBounds({ tx, ty })) {
if (LineClearMissile(src, { tx, ty })) {
if ((dMonster[tx][ty] | nSolidTable[pn] | nMissileTable[pn] | dObject[tx][ty] | dMissile[tx][ty]) == 0) {
if (dMonster[tx][ty] == 0 && !nSolidTable[pn] && !nMissileTable[pn] && dObject[tx][ty] == 0 && dMissile[tx][ty] == 0) {
missile[mi].position.tile = { tx, ty };
missile[mi].position.start = { tx, ty };
missile[mi]._miDelFlag = false;
@ -2450,7 +2449,7 @@ void AddAcid(int mi, Point src, Point dst, int midir, int8_t mienemy, int id, in
{
GetMissileVel(mi, src, dst, 16);
SetMissDir(mi, GetDirection16(src, dst));
if ((!gbIsHellfire && missile[mi].position.velocity.x & 0xFFFF0000) || missile[mi].position.velocity.y & 0xFFFF0000)
if ((!gbIsHellfire && (missile[mi].position.velocity.x & 0xFFFF0000) != 0) || (missile[mi].position.velocity.y & 0xFFFF0000) != 0)
missile[mi]._mirange = 5 * (monster[id]._mint + 4);
else
missile[mi]._mirange = 1;
@ -2682,7 +2681,7 @@ void AddFirewallC(int mi, Point src, Point dst, int midir, int8_t mienemy, int i
if (0 < tx && tx < MAXDUNX && 0 < ty && ty < MAXDUNY) {
k = dPiece[tx][ty];
if (LineClearMissile(src, { tx, ty })) {
if (src != Point { tx, ty } && (nSolidTable[k] | dObject[tx][ty]) == 0) {
if (src != Point { tx, ty } && !nSolidTable[k] && dObject[tx][ty] == 0) {
missile[mi]._miVar1 = tx;
missile[mi]._miVar2 = ty;
missile[mi]._miVar5 = tx;
@ -2699,7 +2698,7 @@ void AddFirewallC(int mi, Point src, Point dst, int midir, int8_t mienemy, int i
if (!missile[mi]._miDelFlag) {
missile[mi]._miVar7 = 0;
missile[mi]._miVar8 = 0;
missile[mi].limitReached = false;
missile[mi]._miVar3 = left[left[midir]];
missile[mi]._miVar4 = right[right[midir]];
missile[mi]._mirange = 7;
@ -2749,7 +2748,7 @@ void AddBlodboil(int mi, Point src, Point dst, int midir, int8_t mienemy, int id
{
auto &player = plr[id];
if (player._pSpellFlags & 6 || player._pHitPoints <= player._pLevel << 6) {
if ((player._pSpellFlags & 6) != 0 || player._pHitPoints <= player._pLevel << 6) {
missile[mi]._miDelFlag = true;
return;
}
@ -3088,7 +3087,7 @@ void MI_Golem(int i)
if (0 < tx && tx < MAXDUNX && 0 < ty && ty < MAXDUNY) {
dp = dPiece[tx][ty];
if (LineClearMissile({ missile[i]._miVar1, missile[i]._miVar2 }, { tx, ty })) {
if ((dMonster[tx][ty] | nSolidTable[dp] | dObject[tx][ty]) == 0) {
if (dMonster[tx][ty] == 0 && !nSolidTable[dp] && dObject[tx][ty] == 0) {
l = 6;
SpawnGolum(src, { tx, ty }, i);
break;
@ -3319,7 +3318,7 @@ void MI_Lightball(int i)
if (missile[i]._miHitFlag)
missile[i]._mirange = j;
obj = dObject[tx][ty];
if (obj && tx == missile[i].position.tile.x && ty == missile[i].position.tile.y) {
if (obj != 0 && tx == missile[i].position.tile.x && ty == missile[i].position.tile.y) {
if (obj > 0) {
oi = obj - 1;
} else {
@ -3707,8 +3706,8 @@ static void MI_Ring(int i, int type)
continue;
if (!LineClearMissile(missile[i].position.tile, { tx, ty }))
continue;
if (nMissileTable[dp] || missile[i]._miVar8) {
missile[i]._miVar8 = 1;
if (nMissileTable[dp] || missile[i].limitReached) {
missile[i].limitReached = true;
continue;
}
@ -3766,11 +3765,11 @@ void MI_LightningWallC(int i)
Point position = { missile[i]._miVar1, missile[i]._miVar2 };
Point target = position + static_cast<Direction>(missile[i]._miVar3);
if (missile[i]._miVar8 == 0 && GrowWall(id, position, target, MIS_LIGHTWALL, missile[i]._mispllvl, dmg)) {
if (!missile[i].limitReached && GrowWall(id, position, target, MIS_LIGHTWALL, missile[i]._mispllvl, dmg)) {
missile[i]._miVar1 = target.x;
missile[i]._miVar2 = target.y;
} else {
missile[i]._miVar8 = 1;
missile[i].limitReached = true;
}
}
@ -3952,7 +3951,7 @@ void MI_Lightning(int i)
void MI_Town(int i)
{
int ExpLight[17] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 15, 15 };
int expLight[17] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 15, 15 };
if (missile[i]._mirange > 1)
missile[i]._mirange--;
@ -3961,7 +3960,7 @@ void MI_Town(int i)
if (currlevel != 0 && missile[i]._mimfnum != 1 && missile[i]._mirange != 0) {
if (missile[i]._miVar2 == 0)
missile[i]._mlid = AddLight(missile[i].position.tile, 1);
ChangeLight(missile[i]._mlid, missile[i].position.tile, ExpLight[missile[i]._miVar2]);
ChangeLight(missile[i]._mlid, missile[i].position.tile, expLight[missile[i]._miVar2]);
missile[i]._miVar2++;
}
@ -4424,7 +4423,7 @@ void MI_Fireman(int i)
Point b = missile[i].position.tile;
int enemy = monster[src]._menemy;
Point c = (monster[src]._mFlags & MFLAG_TARGETS_MONSTER) == 0 ? plr[enemy].position.tile : monster[enemy].position.tile;
if (b != a && ((missile[i]._miVar1 & 1 && a.WalkingDistance(c) >= 4) || missile[i]._miVar2 > 1) && PosOkMonst(missile[i]._misource, a)) {
if (b != a && (((missile[i]._miVar1 & 1) != 0 && a.WalkingDistance(c) >= 4) || missile[i]._miVar2 > 1) && PosOkMonst(missile[i]._misource, a)) {
MissToMonst(i, a);
missile[i]._miDelFlag = true;
} else if ((monster[src]._mFlags & MFLAG_TARGETS_MONSTER) == 0) {
@ -4432,7 +4431,7 @@ void MI_Fireman(int i)
} else {
j = dMonster[b.x][b.y];
}
if (!PosOkMissile(0, b) || (j > 0 && !(missile[i]._miVar1 & 1))) {
if (!PosOkMissile(0, b) || (j > 0 && (missile[i]._miVar1 & 1) == 0)) {
missile[i].position.velocity *= -1;
missile[i]._mimfnum = opposite[missile[i]._mimfnum];
missile[i]._miAnimData = monster[src].MType->Anims[MA_WALK].CelSpritesForDirections[missile[i]._mimfnum]->Data();
@ -4458,11 +4457,11 @@ void MI_FirewallC(int i)
Point position = { missile[i]._miVar1, missile[i]._miVar2 };
Point target = position + static_cast<Direction>(missile[i]._miVar3);
if (missile[i]._miVar8 == 0 && GrowWall(id, position, target, MIS_FIREWALL, missile[i]._mispllvl, 0)) {
if (!missile[i].limitReached && GrowWall(id, position, target, MIS_FIREWALL, missile[i]._mispllvl, 0)) {
missile[i]._miVar1 = target.x;
missile[i]._miVar2 = target.y;
} else {
missile[i]._miVar8 = 1;
missile[i].limitReached = true;
}
}
@ -4871,7 +4870,7 @@ void MI_ResurrectBeam(int i)
void MI_Rportal(int i)
{
int ExpLight[17] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 15, 15 };
int expLight[17] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 15, 15 };
if (missile[i]._mirange > 1)
missile[i]._mirange--;
@ -4881,7 +4880,7 @@ void MI_Rportal(int i)
if (currlevel != 0 && missile[i]._mimfnum != 1 && missile[i]._mirange != 0) {
if (missile[i]._miVar2 == 0)
missile[i]._mlid = AddLight(missile[i].position.tile, 1);
ChangeLight(missile[i]._mlid, missile[i].position.tile, ExpLight[missile[i]._miVar2]);
ChangeLight(missile[i]._mlid, missile[i].position.tile, expLight[missile[i]._miVar2]);
missile[i]._miVar2++;
}
if (missile[i]._mirange == 0) {

View file

@ -103,7 +103,7 @@ struct MissileStruct {
int _miVar5;
int _miVar6;
int _miVar7;
int _miVar8;
bool limitReached;
};
extern int missileactive[MAXMISSILES];

View file

@ -279,7 +279,7 @@ void GetLevelMTypes()
maxl = 15 * monsterdata[i].mMaxDLvl / 30 + 1;
if (currlevel >= minl && currlevel <= maxl) {
if (MonstAvailTbl[i] & mamask) {
if ((MonstAvailTbl[i] & mamask) != 0) {
skeltypes[nt++] = (_monster_id)i;
}
}
@ -294,7 +294,7 @@ void GetLevelMTypes()
maxl = 15 * monsterdata[i].mMaxDLvl / 30 + 1;
if (currlevel >= minl && currlevel <= maxl) {
if (MonstAvailTbl[i] & mamask) {
if ((MonstAvailTbl[i] & mamask) != 0) {
typelist[nt++] = (_monster_id)i;
}
}
@ -387,72 +387,72 @@ void InitMonsterGFX(int monst)
InitMonsterTRN(Monsters[monst]);
}
if (mtype >= MT_NMAGMA && mtype <= MT_WMAGMA && !(MissileFileFlag & 1)) {
if (mtype >= MT_NMAGMA && mtype <= MT_WMAGMA && (MissileFileFlag & 1) == 0) {
MissileFileFlag |= 1;
LoadMissileGFX(MFILE_MAGBALL);
}
if (mtype >= MT_STORM && mtype <= MT_MAEL && !(MissileFileFlag & 2)) {
if (mtype >= MT_STORM && mtype <= MT_MAEL && (MissileFileFlag & 2) == 0) {
MissileFileFlag |= 2;
LoadMissileGFX(MFILE_THINLGHT);
}
if (mtype == MT_SUCCUBUS && !(MissileFileFlag & 4)) {
if (mtype == MT_SUCCUBUS && (MissileFileFlag & 4) == 0) {
MissileFileFlag |= 4;
LoadMissileGFX(MFILE_FLARE);
LoadMissileGFX(MFILE_FLAREEXP);
}
if (mtype >= MT_INCIN && mtype <= MT_HELLBURN && !(MissileFileFlag & 8)) {
if (mtype >= MT_INCIN && mtype <= MT_HELLBURN && (MissileFileFlag & 8) == 0) {
MissileFileFlag |= 8;
LoadMissileGFX(MFILE_KRULL);
}
if (mtype == MT_SNOWWICH && !(MissileFileFlag & 0x20)) {
if (mtype == MT_SNOWWICH && (MissileFileFlag & 0x20) == 0) {
MissileFileFlag |= 0x20;
LoadMissileGFX(MFILE_SCUBMISB);
LoadMissileGFX(MFILE_SCBSEXPB);
}
if (mtype == MT_HLSPWN && !(MissileFileFlag & 0x40)) {
if (mtype == MT_HLSPWN && (MissileFileFlag & 0x40) == 0) {
MissileFileFlag |= 0x40;
LoadMissileGFX(MFILE_SCUBMISD);
LoadMissileGFX(MFILE_SCBSEXPD);
}
if (mtype == MT_SOLBRNR && !(MissileFileFlag & 0x80)) {
if (mtype == MT_SOLBRNR && (MissileFileFlag & 0x80) == 0) {
MissileFileFlag |= 0x80;
LoadMissileGFX(MFILE_SCUBMISC);
LoadMissileGFX(MFILE_SCBSEXPC);
}
if (mtype >= MT_INCIN && mtype <= MT_HELLBURN && !(MissileFileFlag & 8)) {
if (mtype >= MT_INCIN && mtype <= MT_HELLBURN && (MissileFileFlag & 8) == 0) {
MissileFileFlag |= 8;
LoadMissileGFX(MFILE_KRULL);
}
if (((mtype >= MT_NACID && mtype <= MT_XACID) || mtype == MT_SPIDLORD) && !(MissileFileFlag & 0x10)) {
if (((mtype >= MT_NACID && mtype <= MT_XACID) || mtype == MT_SPIDLORD) && (MissileFileFlag & 0x10) == 0) {
MissileFileFlag |= 0x10;
LoadMissileGFX(MFILE_ACIDBF);
LoadMissileGFX(MFILE_ACIDSPLA);
LoadMissileGFX(MFILE_ACIDPUD);
}
if (mtype == MT_LICH && !(MissileFileFlag & 0x100)) {
if (mtype == MT_LICH && (MissileFileFlag & 0x100) == 0) {
MissileFileFlag |= 0x100u;
LoadMissileGFX(MFILE_LICH);
LoadMissileGFX(MFILE_EXORA1);
}
if (mtype == MT_ARCHLICH && !(MissileFileFlag & 0x200)) {
if (mtype == MT_ARCHLICH && (MissileFileFlag & 0x200) == 0) {
MissileFileFlag |= 0x200u;
LoadMissileGFX(MFILE_ARCHLICH);
LoadMissileGFX(MFILE_EXYEL2);
}
if ((mtype == MT_PSYCHORB || mtype == MT_BONEDEMN) && !(MissileFileFlag & 0x400)) {
if ((mtype == MT_PSYCHORB || mtype == MT_BONEDEMN) && (MissileFileFlag & 0x400) == 0) {
MissileFileFlag |= 0x400u;
LoadMissileGFX(MFILE_BONEDEMON);
}
if (mtype == MT_NECRMORB && !(MissileFileFlag & 0x800)) {
if (mtype == MT_NECRMORB && (MissileFileFlag & 0x800) == 0) {
MissileFileFlag |= 0x800u;
LoadMissileGFX(MFILE_NECROMORB);
LoadMissileGFX(MFILE_EXRED3);
}
if (mtype == MT_PSYCHORB && !(MissileFileFlag & 0x1000)) {
if (mtype == MT_PSYCHORB && (MissileFileFlag & 0x1000) == 0) {
MissileFileFlag |= 0x1000u;
LoadMissileGFX(MFILE_EXBL2);
}
if (mtype == MT_BONEDEMN && !(MissileFileFlag & 0x2000)) {
if (mtype == MT_BONEDEMN && (MissileFileFlag & 0x2000) == 0) {
MissileFileFlag |= 0x2000u;
LoadMissileGFX(MFILE_EXBL3);
}
@ -615,11 +615,11 @@ bool MonstPlace(int xp, int yp)
f = dFlags[xp][yp];
if (f & BFLAG_VISIBLE) {
if ((f & BFLAG_VISIBLE) != 0) {
return false;
}
if (f & BFLAG_POPULATED) {
if ((f & BFLAG_POPULATED) != 0) {
return false;
}
@ -780,7 +780,7 @@ void PlaceUniqueMonst(int uniqindex, int miniontype, int bosspacksize)
PlaceMonster(nummonsters, uniqtype, xp, yp);
Monst->_uniqtype = uniqindex + 1;
if (Uniq->mlevel) {
if (Uniq->mlevel != 0) {
Monst->mLevel = 2 * Uniq->mlevel;
} else {
Monst->mLevel += 5;
@ -856,7 +856,7 @@ void PlaceUniqueMonst(int uniqindex, int miniontype, int bosspacksize)
Monst->_uniqtrans = uniquetrans++;
if (Uniq->mUnqAttr & 4) {
if ((Uniq->mUnqAttr & 4) != 0) {
Monst->mHit = Uniq->mUnqVar1;
Monst->mHit2 = Uniq->mUnqVar1;
@ -868,7 +868,7 @@ void PlaceUniqueMonst(int uniqindex, int miniontype, int bosspacksize)
Monst->mHit2 += HELL_TO_HIT_BONUS;
}
}
if (Uniq->mUnqAttr & 8) {
if ((Uniq->mUnqAttr & 8) != 0) {
Monst->mArmorClass = Uniq->mUnqVar1;
if (sgGameInitInfo.nDifficulty == DIFF_NIGHTMARE) {
@ -880,7 +880,7 @@ void PlaceUniqueMonst(int uniqindex, int miniontype, int bosspacksize)
nummonsters++;
if (Uniq->mUnqAttr & 1) {
if ((Uniq->mUnqAttr & 1) != 0) {
PlaceGroup(miniontype, bosspacksize, Uniq->mUnqAttr, nummonsters - 1);
}
@ -1007,19 +1007,19 @@ void PlaceQuestMonsters()
void PlaceGroup(int mtype, int num, int leaderf, int leader)
{
int placed, try1, try2, j;
int try1, try2, j;
int xp, yp, x1, y1;
placed = 0;
int placed = 0;
for (try1 = 0; try1 < 10; try1++) {
while (placed) {
while (placed != 0) {
nummonsters--;
placed--;
dMonster[monster[nummonsters].position.tile.x][monster[nummonsters].position.tile.y] = 0;
}
if (leaderf & 1) {
if ((leaderf & 1) != 0) {
int offset = GenerateRnd(8);
auto position = monster[leader].position.tile + static_cast<Direction>(offset);
x1 = xp = position.x;
@ -1045,12 +1045,12 @@ void PlaceGroup(int mtype, int num, int leaderf, int leader)
}
PlaceMonster(nummonsters, mtype, xp, yp);
if (leaderf & 1) {
if ((leaderf & 1) != 0) {
monster[nummonsters]._mmaxhp *= 2;
monster[nummonsters]._mhitpoints = monster[nummonsters]._mmaxhp;
monster[nummonsters]._mint = monster[leader]._mint;
if (leaderf & 2) {
if ((leaderf & 2) != 0) {
monster[nummonsters].leader = leader;
monster[nummonsters].leaderflag = 1;
monster[nummonsters]._mAi = monster[leader]._mAi;
@ -1073,7 +1073,7 @@ void PlaceGroup(int mtype, int num, int leaderf, int leader)
}
}
if (leaderf & 2) {
if ((leaderf & 2) != 0) {
monster[leader].packsize = placed;
}
}
@ -1150,7 +1150,7 @@ void InitMonsters()
numplacemonsters = MAXMONSTERS - 10 - nummonsters;
totalmonsters = nummonsters + numplacemonsters;
for (i = 0; i < nummtypes; i++) {
if (Monsters[i].mPlaceFlags & PLACE_SCATTER) {
if ((Monsters[i].mPlaceFlags & PLACE_SCATTER) != 0) {
scattertypes[numscattypes] = i;
numscattypes++;
}
@ -1240,7 +1240,7 @@ void monster_43C785(int i)
int d, j, oi;
Point position = {};
if (monster[i].MType) {
if (monster[i].MType != nullptr) {
for (d = 0; d < 8; d++) {
position = monster[i].position.tile + monster[i]._mdir;
if (!SolidLoc(position)) {
@ -3063,7 +3063,7 @@ void MAI_Bat(int i)
Monst->_mdir = md;
v = GenerateRnd(100);
if (Monst->_mgoal == MGOAL_RETREAT) {
if (!Monst->_mgoalvar1) {
if (Monst->_mgoalvar1 == 0) {
M_CallWalk(i, opposite[md]);
Monst->_mgoalvar1++;
} else {
@ -4195,7 +4195,7 @@ void MAI_Garbud(int i)
if (Monst->mtalkmsg >= TEXT_GARBUD1
&& Monst->mtalkmsg <= TEXT_GARBUD3
&& !(dFlags[_mx][_my] & BFLAG_VISIBLE)
&& (dFlags[_mx][_my] & BFLAG_VISIBLE) == 0
&& Monst->_mgoal == MGOAL_TALKING) {
Monst->_mgoal = MGOAL_INQUIRING;
switch (Monst->mtalkmsg) {
@ -4213,7 +4213,7 @@ void MAI_Garbud(int i)
}
}
if (dFlags[_mx][_my] & BFLAG_VISIBLE) {
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;
@ -4246,12 +4246,12 @@ void MAI_Zhar(int i)
mx = Monst->position.tile.x;
my = Monst->position.tile.y;
Direction md = M_GetDir(i);
if (Monst->mtalkmsg == TEXT_ZHAR1 && !(dFlags[mx][my] & BFLAG_VISIBLE) && Monst->_mgoal == MGOAL_TALKING) {
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) {
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;
@ -4285,7 +4285,7 @@ void MAI_SnotSpil(int i)
my = Monst->position.tile.y;
Direction md = M_GetDir(i);
if (Monst->mtalkmsg == TEXT_BANNER10 && !(dFlags[mx][my] & BFLAG_VISIBLE) && Monst->_mgoal == MGOAL_TALKING) {
if (Monst->mtalkmsg == TEXT_BANNER10 && (dFlags[mx][my] & BFLAG_VISIBLE) == 0 && Monst->_mgoal == MGOAL_TALKING) {
Monst->mtalkmsg = TEXT_BANNER11;
Monst->_mgoal = MGOAL_INQUIRING;
}
@ -4295,7 +4295,7 @@ void MAI_SnotSpil(int i)
Monst->_mgoal = MGOAL_NORMAL;
}
if (dFlags[mx][my] & BFLAG_VISIBLE) {
if ((dFlags[mx][my] & BFLAG_VISIBLE) != 0) {
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);
@ -4332,7 +4332,7 @@ void MAI_Lazurus(int i)
mx = Monst->position.tile.x;
my = Monst->position.tile.y;
Direction md = M_GetDir(i);
if (dFlags[mx][my] & BFLAG_VISIBLE) {
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) {
PlayInGameMovie("gendata\\fprst3.smk");
@ -4384,7 +4384,7 @@ void MAI_Lazhelp(int i)
_my = Monst->position.tile.y;
Direction md = M_GetDir(i);
if (dFlags[_mx][_my] & BFLAG_VISIBLE) {
if ((dFlags[_mx][_my] & BFLAG_VISIBLE) != 0) {
if (!gbIsMultiplayer) {
if (quests[Q_BETRAYER]._qvar1 <= 5) {
Monst->_mgoal = MGOAL_INQUIRING;
@ -4418,12 +4418,12 @@ void MAI_Lachdanan(int i)
_my = Monst->position.tile.y;
Direction md = M_GetDir(i);
if (Monst->mtalkmsg == TEXT_VEIL9 && !(dFlags[_mx][_my] & BFLAG_VISIBLE) && monster[i]._mgoal == MGOAL_TALKING) {
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) {
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;
@ -4453,7 +4453,7 @@ void MAI_Warlord(int i)
mx = Monst->position.tile.x;
my = Monst->position.tile.y;
Direction md = M_GetDir(i);
if (dFlags[mx][my] & BFLAG_VISIBLE) {
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) {
@ -4511,7 +4511,7 @@ void ProcessMonsters()
SetRndSeed(Monst->_mAISeed);
Monst->_mAISeed = AdvanceRndSeed();
}
if (!(monster[mi]._mFlags & MFLAG_NOHEAL) && Monst->_mhitpoints < Monst->_mmaxhp && Monst->_mhitpoints >> 6 > 0) {
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 {
@ -4526,7 +4526,7 @@ void ProcessMonsters()
PlaySFX(USFX_CLEAVER);
}
if (Monst->MType->mtype == MT_NAKRUL) {
if (sgGameInitInfo.bCowQuest) {
if (sgGameInitInfo.bCowQuest != 0) {
PlaySFX(USFX_NAKRUL6);
} else {
if (IsUberRoomOpened)
@ -4549,7 +4549,7 @@ void ProcessMonsters()
_menemy = Monst->_menemy;
assurance((DWORD)_menemy < MAX_PLRS, _menemy);
Monst->enemyPosition = plr[Monst->_menemy].position.future;
if (dFlags[mx][my] & BFLAG_VISIBLE) {
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'
@ -4557,7 +4557,7 @@ void ProcessMonsters()
}
}
do {
if (!(Monst->_mFlags & MFLAG_SEARCH)) {
if ((Monst->_mFlags & MFLAG_SEARCH) == 0) {
AiProc[Monst->_mAi](mi);
} else if (!MAI_Path(mi)) {
AiProc[Monst->_mAi](mi);
@ -4651,10 +4651,10 @@ bool DirOK(int i, Direction mdir)
if (futurePosition.y < 0 || futurePosition.y >= MAXDUNY || futurePosition.x < 0 || futurePosition.x >= MAXDUNX || !PosOkMonst(i, futurePosition))
return false;
if (mdir == DIR_E) {
if (SolidLoc(position + DIR_SE) || dFlags[position.x + 1][position.y] & BFLAG_MONSTLR)
if (SolidLoc(position + DIR_SE) || (dFlags[position.x + 1][position.y] & BFLAG_MONSTLR) != 0)
return false;
} else if (mdir == DIR_W) {
if (SolidLoc(position + DIR_SW) || dFlags[position.x][position.y + 1] & BFLAG_MONSTLR)
if (SolidLoc(position + DIR_SW) || (dFlags[position.x][position.y + 1] & BFLAG_MONSTLR) != 0)
return false;
} else if (mdir == DIR_N) {
if (SolidLoc(position + DIR_NE) || SolidLoc(position + DIR_NW))
@ -4667,7 +4667,7 @@ bool DirOK(int i, Direction mdir)
return false;
return true;
}
if (monster[i]._uniqtype == 0 || !(UniqMonst[monster[i]._uniqtype - 1].mUnqAttr & 2))
if (monster[i]._uniqtype == 0 || (UniqMonst[monster[i]._uniqtype - 1].mUnqAttr & 2) == 0)
return true;
int mcount = 0;
for (int x = futurePosition.x - 3; x <= futurePosition.x + 3; x++) {
@ -4692,7 +4692,7 @@ bool DirOK(int i, Direction mdir)
bool PosOkMissile(int entity, Point position)
{
return !nMissileTable[dPiece[position.x][position.y]] && !(dFlags[position.x][position.y] & BFLAG_MONSTLR);
return !nMissileTable[dPiece[position.x][position.y]] && (dFlags[position.x][position.y] & BFLAG_MONSTLR) == 0;
}
bool CheckNoSolid(int entity, Point position)
@ -4938,29 +4938,28 @@ void PrintMonstHistory(int mt)
res = monsterdata[mt].mMagicRes;
else
res = monsterdata[mt].mMagicRes2;
res = res & (RESIST_MAGIC | RESIST_FIRE | RESIST_LIGHTNING | IMMUNE_MAGIC | IMMUNE_FIRE | IMMUNE_LIGHTNING);
if (!res) {
if ((res & (RESIST_MAGIC | RESIST_FIRE | RESIST_LIGHTNING | IMMUNE_MAGIC | IMMUNE_FIRE | IMMUNE_LIGHTNING)) == 0) {
strcpy(tempstr, _("No magic resistance"));
AddPanelString(tempstr);
} else {
if (res & (RESIST_MAGIC | RESIST_FIRE | RESIST_LIGHTNING)) {
if ((res & (RESIST_MAGIC | RESIST_FIRE | RESIST_LIGHTNING)) != 0) {
strcpy(tempstr, _("Resists: "));
if (res & RESIST_MAGIC)
if ((res & RESIST_MAGIC) != 0)
strcat(tempstr, _("Magic "));
if (res & RESIST_FIRE)
if ((res & RESIST_FIRE) != 0)
strcat(tempstr, _("Fire "));
if (res & RESIST_LIGHTNING)
if ((res & RESIST_LIGHTNING) != 0)
strcat(tempstr, _("Lightning "));
tempstr[strlen(tempstr) - 1] = '\0';
AddPanelString(tempstr);
}
if (res & (IMMUNE_MAGIC | IMMUNE_FIRE | IMMUNE_LIGHTNING)) {
if ((res & (IMMUNE_MAGIC | IMMUNE_FIRE | IMMUNE_LIGHTNING)) != 0) {
strcpy(tempstr, _("Immune: "));
if (res & IMMUNE_MAGIC)
if ((res & IMMUNE_MAGIC) != 0)
strcat(tempstr, _("Magic "));
if (res & IMMUNE_FIRE)
if ((res & IMMUNE_FIRE) != 0)
strcat(tempstr, _("Fire "));
if (res & IMMUNE_LIGHTNING)
if ((res & IMMUNE_LIGHTNING) != 0)
strcat(tempstr, _("Lightning "));
tempstr[strlen(tempstr) - 1] = '\0';
AddPanelString(tempstr);
@ -4980,17 +4979,17 @@ void PrintUniqueHistory()
}
res = monster[pcursmonst].mMagicRes & (RESIST_MAGIC | RESIST_FIRE | RESIST_LIGHTNING | IMMUNE_MAGIC | IMMUNE_FIRE | IMMUNE_LIGHTNING);
if (!res) {
if (res == 0) {
strcpy(tempstr, _("No resistances"));
AddPanelString(tempstr);
strcpy(tempstr, _("No Immunities"));
} else {
if (res & (RESIST_MAGIC | RESIST_FIRE | RESIST_LIGHTNING))
if ((res & (RESIST_MAGIC | RESIST_FIRE | RESIST_LIGHTNING)) != 0)
strcpy(tempstr, _("Some Magic Resistances"));
else
strcpy(tempstr, _("No resistances"));
AddPanelString(tempstr);
if (res & (IMMUNE_MAGIC | IMMUNE_FIRE | IMMUNE_LIGHTNING)) {
if ((res & (IMMUNE_MAGIC | IMMUNE_FIRE | IMMUNE_LIGHTNING)) != 0) {
strcpy(tempstr, _("Some Magic Immunities"));
} else {
strcpy(tempstr, _("No Immunities"));
@ -5020,7 +5019,7 @@ void MissToMonst(int i, Point position)
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))
if ((Monst->_mFlags & MFLAG_TARGETS_MONSTER) == 0)
M_StartHit(m, -1, 0);
else
M2MStartHit(m, -1, 0);
@ -5029,7 +5028,7 @@ void MissToMonst(int i, Point position)
}
Point newPosition = {};
if (!(Monst->_mFlags & MFLAG_TARGETS_MONSTER)) {
if ((Monst->_mFlags & MFLAG_TARGETS_MONSTER) == 0) {
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)) {
@ -5116,9 +5115,9 @@ bool monster_posok(int i, Point position)
}
}
}
if (fire && (!(monster[i].mMagicRes & IMMUNE_FIRE) || monster[i].MType->mtype == MT_DIABLO))
if (fire && ((monster[i].mMagicRes & IMMUNE_FIRE) == 0 || monster[i].MType->mtype == MT_DIABLO))
ret = false;
if (lightning && (!(monster[i].mMagicRes & IMMUNE_LIGHTNING) || monster[i].MType->mtype == MT_DIABLO))
if (lightning && ((monster[i].mMagicRes & IMMUNE_LIGHTNING) == 0 || monster[i].MType->mtype == MT_DIABLO))
ret = false;
}
@ -5192,7 +5191,7 @@ int M_SpawnSkel(Point position, Direction dir)
j++;
}
if (j) {
if (j != 0) {
skeltypes = GenerateRnd(j);
j = 0;
for (i = 0; i < nummtypes && j <= skeltypes; i++) {
@ -5221,8 +5220,7 @@ void ActivateSpawn(int i, int x, int y, Direction dir)
bool SpawnSkeleton(int ii, Point position)
{
int dx, dy, xx, yy, j, k, rs;
bool savail;
int monstok[3][3];
bool monstok[3][3];
if (ii == -1)
return false;
@ -5233,13 +5231,13 @@ bool SpawnSkeleton(int ii, Point position)
return true;
}
savail = false;
bool savail = false;
yy = 0;
for (j = position.y - 1; j <= position.y + 1; j++) {
xx = 0;
for (k = position.x - 1; k <= position.x + 1; k++) {
monstok[xx][yy] = PosOkMonst(-1, { k, j });
savail |= monstok[xx][yy];
savail = savail || monstok[xx][yy];
xx++;
}
yy++;
@ -5284,7 +5282,7 @@ int PreSpawnSkeleton()
j++;
}
if (j) {
if (j != 0) {
skeltypes = GenerateRnd(j);
j = 0;
for (i = 0; i < nummtypes && j <= skeltypes; i++) {
@ -5369,7 +5367,7 @@ bool CheckMonsterHit(int m, bool *ret)
{
commitment((DWORD)m < MAXMONSTERS, m);
if (monster[m]._mAi == AI_GARG && monster[m]._mFlags & MFLAG_ALLOW_SPECIAL) {
if (monster[m]._mAi == AI_GARG && (monster[m]._mFlags & MFLAG_ALLOW_SPECIAL) != 0) {
monster[m]._mFlags &= ~MFLAG_ALLOW_SPECIAL;
monster[m]._mmode = MM_SATTACK;
*ret = true;
@ -5388,7 +5386,7 @@ bool CheckMonsterHit(int m, bool *ret)
int encode_enemy(int m)
{
if (monster[m]._mFlags & MFLAG_TARGETS_MONSTER)
if ((monster[m]._mFlags & MFLAG_TARGETS_MONSTER) != 0)
return monster[m]._menemy + MAX_PLRS;
return monster[m]._menemy;

View file

@ -1270,7 +1270,7 @@ static DWORD On_STRING2(int pnum, TCmd *pCmd)
auto *p = (TCmdString *)pCmd;
int len = strlen(p->str);
if (!gbBufferMsgs)
if (gbBufferMsgs == 0)
SendPlrMsg(pnum, p->str);
return len + 2; // length of string + nul terminator + sizeof(p->bCmd)

View file

@ -80,7 +80,7 @@ bool nthread_recv_turns(bool *pfSendAsync)
{
*pfSendAsync = false;
sgbPacketCountdown--;
if (sgbPacketCountdown) {
if (sgbPacketCountdown > 0) {
last_tick += gnTickDelay;
return true;
}

View file

@ -4277,7 +4277,7 @@ bool OperateShrineMurphys(int pnum)
for (auto &item : plr[myplr].InvBody) {
if (!item.isEmpty() && GenerateRnd(3) == 0) {
if (item._iDurability != DUR_INDESTRUCTIBLE) {
if (item._iDurability) {
if (item._iDurability > 0) {
item._iDurability /= 2;
broke = true;
break;

307
Source/options.cpp Normal file
View file

@ -0,0 +1,307 @@
/**
* @file options.cpp
*
* Load and save options from the diablo.ini file.
*/
#include <fstream>
#include <cstdint>
#define SI_SUPPORT_IOSTREAMS
#include <SimpleIni.h>
#include "options.h"
#include "diablo.h"
#include "utils/file_util.h"
#include "utils/paths.h"
namespace devilution {
#ifndef DEFAULT_WIDTH
#define DEFAULT_WIDTH 640
#endif
#ifndef DEFAULT_HEIGHT
#define DEFAULT_HEIGHT 480
#endif
#ifndef DEFAULT_AUDIO_SAMPLE_RATE
#define DEFAULT_AUDIO_SAMPLE_RATE 22050
#endif
#ifndef DEFAULT_AUDIO_CHANNELS
#define DEFAULT_AUDIO_CHANNELS 2
#endif
#ifndef DEFAULT_AUDIO_BUFFER_SIZE
#define DEFAULT_AUDIO_BUFFER_SIZE 2048
#endif
#ifndef DEFAULT_AUDIO_RESAMPLING_QUALITY
#define DEFAULT_AUDIO_RESAMPLING_QUALITY 5
#endif
namespace {
std::string getIniPath()
{
auto path = paths::ConfigPath() + std::string("diablo.ini");
return path;
}
CSimpleIni &getIni()
{
static CSimpleIni ini;
static bool isIniLoaded = false;
if (!isIniLoaded) {
auto path = getIniPath();
auto stream = CreateFileStream(path.c_str(), std::fstream::in | std::fstream::binary);
ini.SetSpaces(false);
if (stream != nullptr)
ini.LoadData(*stream);
isIniLoaded = true;
}
return ini;
}
int getIniInt(const char *keyname, const char *valuename, int defaultValue)
{
long value = getIni().GetLongValue(keyname, valuename, defaultValue);
return value;
}
bool getIniBool(const char *sectionName, const char *keyName, bool defaultValue)
{
bool value = getIni().GetBoolValue(sectionName, keyName, defaultValue);
return value;
}
float getIniFloat(const char *sectionName, const char *keyName, float defaultValue)
{
const double value = getIni().GetDoubleValue(sectionName, keyName, defaultValue);
return (float)value;
}
void setIniValue(const char *keyname, const char *valuename, int value)
{
getIni().SetLongValue(keyname, valuename, value);
}
void setIniValue(const char *keyname, const char *valuename, std::uint8_t value)
{
getIni().SetLongValue(keyname, valuename, value);
}
void setIniValue(const char *keyname, const char *valuename, std::uint32_t value)
{
getIni().SetLongValue(keyname, valuename, value);
}
void setIniValue(const char *keyname, const char *valuename, bool value)
{
getIni().SetLongValue(keyname, valuename, value ? 1 : 0);
}
void setIniValue(const char *keyname, const char *valuename, float value)
{
getIni().SetDoubleValue(keyname, valuename, value);
}
void SaveIni()
{
auto iniPath = getIniPath();
auto stream = CreateFileStream(iniPath.c_str(), std::fstream::out | std::fstream::trunc | std::fstream::binary);
getIni().Save(*stream, true);
}
}
void setIniValue(const char *sectionName, const char *keyName, const char *value, int len)
{
auto &ini = getIni();
std::string stringValue(value, len != 0 ? len : strlen(value));
ini.SetValue(sectionName, keyName, stringValue.c_str());
}
bool getIniValue(const char *sectionName, const char *keyName, char *string, int stringSize, const char *defaultString)
{
const char *value = getIni().GetValue(sectionName, keyName);
if (value == nullptr) {
strncpy(string, defaultString, stringSize);
return false;
}
strncpy(string, value, stringSize);
return true;
}
/** Game options */
Options sgOptions;
bool sbWasOptionsLoaded = false;
/**
* @brief Load game configurations from ini file
*/
void LoadOptions()
{
sgOptions.Diablo.bIntro = getIniBool("Diablo", "Intro", true);
sgOptions.Hellfire.bIntro = getIniBool("Hellfire", "Intro", true);
getIniValue("Hellfire", "SItem", sgOptions.Hellfire.szItem, sizeof(sgOptions.Hellfire.szItem), "");
sgOptions.Audio.nSoundVolume = getIniInt("Audio", "Sound Volume", VOLUME_MAX);
sgOptions.Audio.nMusicVolume = getIniInt("Audio", "Music Volume", VOLUME_MAX);
sgOptions.Audio.bWalkingSound = getIniBool("Audio", "Walking Sound", true);
sgOptions.Audio.bAutoEquipSound = getIniBool("Audio", "Auto Equip Sound", false);
sgOptions.Audio.nSampleRate = getIniInt("Audio", "Sample Rate", DEFAULT_AUDIO_SAMPLE_RATE);
sgOptions.Audio.nChannels = getIniInt("Audio", "Channels", DEFAULT_AUDIO_CHANNELS);
sgOptions.Audio.nBufferSize = getIniInt("Audio", "Buffer Size", DEFAULT_AUDIO_BUFFER_SIZE);
sgOptions.Audio.nResamplingQuality = getIniInt("Audio", "Resampling Quality", DEFAULT_AUDIO_RESAMPLING_QUALITY);
sgOptions.Graphics.nWidth = getIniInt("Graphics", "Width", DEFAULT_WIDTH);
sgOptions.Graphics.nHeight = getIniInt("Graphics", "Height", DEFAULT_HEIGHT);
#ifndef __vita__
sgOptions.Graphics.bFullscreen = getIniBool("Graphics", "Fullscreen", true);
#else
sgOptions.Graphics.bFullscreen = true;
#endif
#if !defined(USE_SDL1)
sgOptions.Graphics.bUpscale = getIniBool("Graphics", "Upscale", true);
#else
sgOptions.Graphics.bUpscale = false;
#endif
sgOptions.Graphics.bFitToScreen = getIniBool("Graphics", "Fit to Screen", true);
getIniValue("Graphics", "Scaling Quality", sgOptions.Graphics.szScaleQuality, sizeof(sgOptions.Graphics.szScaleQuality), "2");
sgOptions.Graphics.bIntegerScaling = getIniBool("Graphics", "Integer Scaling", false);
sgOptions.Graphics.bVSync = getIniBool("Graphics", "Vertical Sync", true);
sgOptions.Graphics.bBlendedTransparancy = getIniBool("Graphics", "Blended Transparency", true);
sgOptions.Graphics.nGammaCorrection = getIniInt("Graphics", "Gamma Correction", 100);
sgOptions.Graphics.bColorCycling = getIniBool("Graphics", "Color Cycling", true);
#ifndef USE_SDL1
sgOptions.Graphics.bHardwareCursor = getIniBool("Graphics", "Hardware Cursor", false);
#else
sgOptions.Graphics.bHardwareCursor = false;
#endif
sgOptions.Graphics.bFPSLimit = getIniBool("Graphics", "FPS Limiter", true);
sgOptions.Graphics.bShowFPS = (getIniInt("Graphics", "Show FPS", 0) != 0);
sgOptions.Gameplay.nTickRate = getIniInt("Game", "Speed", 20);
sgOptions.Gameplay.bRunInTown = getIniBool("Game", "Run in Town", false);
sgOptions.Gameplay.bGrabInput = getIniBool("Game", "Grab Input", false);
sgOptions.Gameplay.bTheoQuest = getIniBool("Game", "Theo Quest", false);
sgOptions.Gameplay.bCowQuest = getIniBool("Game", "Cow Quest", false);
sgOptions.Gameplay.bFriendlyFire = getIniBool("Game", "Friendly Fire", true);
sgOptions.Gameplay.bTestBard = getIniBool("Game", "Test Bard", false);
sgOptions.Gameplay.bTestBarbarian = getIniBool("Game", "Test Barbarian", false);
sgOptions.Gameplay.bExperienceBar = getIniBool("Game", "Experience Bar", false);
sgOptions.Gameplay.bEnemyHealthBar = getIniBool("Game", "Enemy Health Bar", false);
sgOptions.Gameplay.bAutoGoldPickup = getIniBool("Game", "Auto Gold Pickup", false);
sgOptions.Gameplay.bAdriaRefillsMana = getIniBool("Game", "Adria Refills Mana", false);
sgOptions.Gameplay.bAutoEquipWeapons = getIniBool("Game", "Auto Equip Weapons", true);
sgOptions.Gameplay.bAutoEquipArmor = getIniBool("Game", "Auto Equip Armor", false);
sgOptions.Gameplay.bAutoEquipHelms = getIniBool("Game", "Auto Equip Helms", false);
sgOptions.Gameplay.bAutoEquipShields = getIniBool("Game", "Auto Equip Shields", false);
sgOptions.Gameplay.bAutoEquipJewelry = getIniBool("Game", "Auto Equip Jewelry", false);
sgOptions.Gameplay.bRandomizeQuests = getIniBool("Game", "Randomize Quests", true);
sgOptions.Gameplay.bShowMonsterType = getIniBool("Game", "Show Monster Type", false);
sgOptions.Gameplay.bDisableCripplingShrines = getIniBool("Game", "Disable Crippling Shrines", false);
getIniValue("Network", "Bind Address", sgOptions.Network.szBindAddress, sizeof(sgOptions.Network.szBindAddress), "0.0.0.0");
sgOptions.Network.nPort = getIniInt("Network", "Port", 6112);
getIniValue("Network", "Previous Host", sgOptions.Network.szPreviousHost, sizeof(sgOptions.Network.szPreviousHost), "");
for (size_t i = 0; i < sizeof(spszMsgTbl) / sizeof(spszMsgTbl[0]); i++)
getIniValue("NetMsg", spszMsgNameTbl[i], sgOptions.Chat.szHotKeyMsgs[i], MAX_SEND_STR_LEN, "");
getIniValue("Controller", "Mapping", sgOptions.Controller.szMapping, sizeof(sgOptions.Controller.szMapping), "");
sgOptions.Controller.bSwapShoulderButtonMode = getIniBool("Controller", "Swap Shoulder Button Mode", false);
sgOptions.Controller.bDpadHotkeys = getIniBool("Controller", "Dpad Hotkeys", false);
sgOptions.Controller.fDeadzone = getIniFloat("Controller", "deadzone", 0.07);
#ifdef __vita__
sgOptions.Controller.bRearTouch = getIniBool("Controller", "Enable Rear Touchpad", true);
#endif
getIniValue("Language", "Code", sgOptions.Language.szCode, sizeof(sgOptions.Language.szCode), "en");
keymapper.load();
sbWasOptionsLoaded = true;
}
/**
* @brief Save game configurations to ini file
*/
void SaveOptions()
{
setIniValue("Diablo", "Intro", sgOptions.Diablo.bIntro);
setIniValue("Hellfire", "Intro", sgOptions.Hellfire.bIntro);
setIniValue("Hellfire", "SItem", sgOptions.Hellfire.szItem);
setIniValue("Audio", "Sound Volume", sgOptions.Audio.nSoundVolume);
setIniValue("Audio", "Music Volume", sgOptions.Audio.nMusicVolume);
setIniValue("Audio", "Walking Sound", sgOptions.Audio.bWalkingSound);
setIniValue("Audio", "Auto Equip Sound", sgOptions.Audio.bAutoEquipSound);
setIniValue("Audio", "Sample Rate", sgOptions.Audio.nSampleRate);
setIniValue("Audio", "Channels", sgOptions.Audio.nChannels);
setIniValue("Audio", "Buffer Size", sgOptions.Audio.nBufferSize);
setIniValue("Audio", "Resampling Quality", sgOptions.Audio.nResamplingQuality);
setIniValue("Graphics", "Width", sgOptions.Graphics.nWidth);
setIniValue("Graphics", "Height", sgOptions.Graphics.nHeight);
#ifndef __vita__
setIniValue("Graphics", "Fullscreen", sgOptions.Graphics.bFullscreen);
#endif
#if !defined(USE_SDL1)
setIniValue("Graphics", "Upscale", sgOptions.Graphics.bUpscale);
#endif
setIniValue("Graphics", "Fit to Screen", sgOptions.Graphics.bFitToScreen);
setIniValue("Graphics", "Scaling Quality", sgOptions.Graphics.szScaleQuality);
setIniValue("Graphics", "Integer Scaling", sgOptions.Graphics.bIntegerScaling);
setIniValue("Graphics", "Vertical Sync", sgOptions.Graphics.bVSync);
setIniValue("Graphics", "Blended Transparency", sgOptions.Graphics.bBlendedTransparancy);
setIniValue("Graphics", "Gamma Correction", sgOptions.Graphics.nGammaCorrection);
setIniValue("Graphics", "Color Cycling", sgOptions.Graphics.bColorCycling);
#ifndef USE_SDL1
setIniValue("Graphics", "Hardware Cursor", sgOptions.Graphics.bHardwareCursor);
#endif
setIniValue("Graphics", "FPS Limiter", sgOptions.Graphics.bFPSLimit);
setIniValue("Graphics", "Show FPS", sgOptions.Graphics.bShowFPS);
setIniValue("Game", "Speed", sgOptions.Gameplay.nTickRate);
setIniValue("Game", "Run in Town", sgOptions.Gameplay.bRunInTown);
setIniValue("Game", "Grab Input", sgOptions.Gameplay.bGrabInput);
setIniValue("Game", "Theo Quest", sgOptions.Gameplay.bTheoQuest);
setIniValue("Game", "Cow Quest", sgOptions.Gameplay.bCowQuest);
setIniValue("Game", "Friendly Fire", sgOptions.Gameplay.bFriendlyFire);
setIniValue("Game", "Test Bard", sgOptions.Gameplay.bTestBard);
setIniValue("Game", "Test Barbarian", sgOptions.Gameplay.bTestBarbarian);
setIniValue("Game", "Experience Bar", sgOptions.Gameplay.bExperienceBar);
setIniValue("Game", "Enemy Health Bar", sgOptions.Gameplay.bEnemyHealthBar);
setIniValue("Game", "Auto Gold Pickup", sgOptions.Gameplay.bAutoGoldPickup);
setIniValue("Game", "Adria Refills Mana", sgOptions.Gameplay.bAdriaRefillsMana);
setIniValue("Game", "Auto Equip Weapons", sgOptions.Gameplay.bAutoEquipWeapons);
setIniValue("Game", "Auto Equip Armor", sgOptions.Gameplay.bAutoEquipArmor);
setIniValue("Game", "Auto Equip Helms", sgOptions.Gameplay.bAutoEquipHelms);
setIniValue("Game", "Auto Equip Shields", sgOptions.Gameplay.bAutoEquipShields);
setIniValue("Game", "Auto Equip Jewelry", sgOptions.Gameplay.bAutoEquipJewelry);
setIniValue("Game", "Randomize Quests", sgOptions.Gameplay.bRandomizeQuests);
setIniValue("Game", "Show Monster Type", sgOptions.Gameplay.bShowMonsterType);
setIniValue("Game", "Disable Crippling Shrines", sgOptions.Gameplay.bDisableCripplingShrines);
setIniValue("Network", "Bind Address", sgOptions.Network.szBindAddress);
setIniValue("Network", "Port", sgOptions.Network.nPort);
setIniValue("Network", "Previous Host", sgOptions.Network.szPreviousHost);
for (size_t i = 0; i < sizeof(spszMsgTbl) / sizeof(spszMsgTbl[0]); i++)
setIniValue("NetMsg", spszMsgNameTbl[i], sgOptions.Chat.szHotKeyMsgs[i]);
setIniValue("Controller", "Mapping", sgOptions.Controller.szMapping);
setIniValue("Controller", "Swap Shoulder Button Mode", sgOptions.Controller.bSwapShoulderButtonMode);
setIniValue("Controller", "Dpad Hotkeys", sgOptions.Controller.bDpadHotkeys);
setIniValue("Controller", "deadzone", sgOptions.Controller.fDeadzone);
#ifdef __vita__
setIniValue("Controller", "Enable Rear Touchpad", sgOptions.Controller.bRearTouch);
#endif
setIniValue("Language", "Code", sgOptions.Language.szCode);
keymapper.save();
SaveIni();
}
} // namespace devilution

View file

@ -158,6 +158,13 @@ struct Options {
LanguageOptions Language;
};
bool getIniValue(const char *sectionName, const char *keyName, char *string, int stringSize, const char *defaultString = "");
void setIniValue(const char *sectionName, const char *keyName, const char *value, int len = 0);
extern Options sgOptions;
extern bool sbWasOptionsLoaded;
void SaveOptions();
void LoadOptions();
} // namespace devilution

View file

@ -39,7 +39,7 @@ void PackItem(PkItemStruct *id, const ItemStruct *is)
} else {
id->iSeed = SDL_SwapLE32(is->_iSeed);
id->iCreateInfo = SDL_SwapLE16(is->_iCreateInfo);
id->bId = is->_iIdentified + 2 * is->_iMagical;
id->bId = (is->_iMagical << 1) | (is->_iIdentified ? 1 : 0);
id->bDur = is->_iDurability;
id->bMDur = is->_iMaxDur;
id->bCh = is->_iCharges;
@ -106,12 +106,12 @@ void PackPlayer(PkPlayerStruct *pPack, const PlayerStruct &player, bool manashie
pPack->pDifficulty = SDL_SwapLE32(player.pDifficulty);
pPack->pDamAcFlags = SDL_SwapLE32(player.pDamAcFlags);
pPack->pDiabloKillLevel = SDL_SwapLE32(player.pDiabloKillLevel);
pPack->bIsHellfire = gbIsHellfire;
pPack->bIsHellfire = gbIsHellfire ? 1 : 0;
if (!gbIsMultiplayer || manashield)
pPack->pManaShield = SDL_SwapLE32(player.pManaShield);
else
pPack->pManaShield = false;
pPack->pManaShield = 0;
}
/**
@ -234,13 +234,13 @@ void UnPackPlayer(const PkPlayerStruct *pPack, int pnum, bool netSync)
for (int i = 0; i < NUM_INVLOC; i++) {
auto packedItem = pPack->InvBody[i];
bool isHellfire = netSync ? ((packedItem.dwBuff & CF_HELLFIRE) != 0) : pPack->bIsHellfire;
bool isHellfire = netSync ? ((packedItem.dwBuff & CF_HELLFIRE) != 0) : (pPack->bIsHellfire != 0);
UnPackItem(&packedItem, &player.InvBody[i], isHellfire);
}
for (int i = 0; i < NUM_INV_GRID_ELEM; i++) {
auto packedItem = pPack->InvList[i];
bool isHellfire = netSync ? ((packedItem.dwBuff & CF_HELLFIRE) != 0) : pPack->bIsHellfire;
bool isHellfire = netSync ? ((packedItem.dwBuff & CF_HELLFIRE) != 0) : (pPack->bIsHellfire != 0);
UnPackItem(&packedItem, &player.InvList[i], isHellfire);
}
@ -252,7 +252,7 @@ void UnPackPlayer(const PkPlayerStruct *pPack, int pnum, bool netSync)
for (int i = 0; i < MAXBELTITEMS; i++) {
auto packedItem = pPack->SpdList[i];
bool isHellfire = netSync ? ((packedItem.dwBuff & CF_HELLFIRE) != 0) : pPack->bIsHellfire;
bool isHellfire = netSync ? ((packedItem.dwBuff & CF_HELLFIRE) != 0) : (pPack->bIsHellfire != 0);
UnPackItem(&packedItem, &player.SpdList[i], isHellfire);
}
@ -268,7 +268,7 @@ void UnPackPlayer(const PkPlayerStruct *pPack, int pnum, bool netSync)
player.pDungMsgs2 = 0;
player.pLvlLoad = 0;
player.pDiabloKillLevel = SDL_SwapLE32(pPack->pDiabloKillLevel);
player.pBattleNet = pPack->pBattleNet;
player.pBattleNet = pPack->pBattleNet != 0;
player.pManaShield = SDL_SwapLE32(pPack->pManaShield);
player.pDifficulty = (_difficulty)SDL_SwapLE32(pPack->pDifficulty);
player.pDamAcFlags = SDL_SwapLE32(pPack->pDamAcFlags);

View file

@ -65,6 +65,7 @@ struct PkPlayerStruct {
uint8_t pBattleNet;
uint8_t pManaShield;
uint8_t pDungMsgs2;
/** The format the charater is in, 0: Diablo, 1: Hellfire */
int8_t bIsHellfire;
int8_t bReserved; // For future use
uint16_t wReflections;

View file

@ -212,7 +212,7 @@ void DecreaseGamma()
int UpdateGamma(int gamma)
{
if (gamma) {
if (gamma > 0) {
sgOptions.Graphics.nGammaCorrection = 130 - gamma;
ApplyGamma(system_palette, logical_palette, 256);
palette_update();

View file

@ -69,7 +69,7 @@ int FindPath(bool (*PosOk)(int, Point), int PosOkArg, int sx, int sy, int dx, in
path_start->position.y = sy;
path_2_nodes->NextNode = path_start;
// A* search until we find (dx,dy) or fail
while ((next_node = GetNextPath())) {
while ((next_node = GetNextPath()) != nullptr) {
// reached the end, success!
if (next_node->position.x == dx && next_node->position.y == dy) {
current = next_node;
@ -300,23 +300,21 @@ PATHNODE *path_get_node2(int dx, int dy)
*/
void path_next_node(PATHNODE *pPath)
{
PATHNODE *next, *current;
int f;
next = path_2_nodes;
PATHNODE *next = path_2_nodes;
if (path_2_nodes->NextNode == nullptr) {
path_2_nodes->NextNode = pPath;
} else {
current = path_2_nodes;
next = path_2_nodes->NextNode;
f = pPath->f;
while (next && next->f < f) {
current = next;
next = next->NextNode;
}
pPath->NextNode = next;
current->NextNode = pPath;
return;
}
PATHNODE *current = path_2_nodes;
next = path_2_nodes->NextNode;
int f = pPath->f;
while (next != nullptr && next->f < f) {
current = next;
next = next->NextNode;
}
pPath->NextNode = next;
current->NextNode = pPath;
}
/**
@ -329,7 +327,8 @@ void path_set_coords(PATHNODE *pPath)
int i;
path_push_active_step(pPath);
while (gdwCurPathStep) {
// while there are path nodes to check
while (gdwCurPathStep > 0) {
PathOld = path_pop_active_step();
for (i = 0; i < 8; i++) {
PathAct = PathOld->Child[i];

View file

@ -351,7 +351,7 @@ bool pfile_get_file_name(uint8_t lvl, char *dst)
const char *fmt;
if (gbIsMultiplayer) {
if (lvl)
if (lvl != 0)
return false;
fmt = "hero";
} else {

View file

@ -1170,7 +1170,7 @@ void AddPlrMonstExper(int lvl, int exp, char pmask)
}
}
if (totplrs) {
if (totplrs != 0) {
e = exp / totplrs;
if ((pmask & (1 << myplr)) != 0)
AddPlrExperience(myplr, lvl, e);

View file

@ -80,7 +80,7 @@ void DrawMonsterHealthBar(const CelOutputBuffer &out)
DrawArt(out, xPos, yPos, &healthBox);
DrawHalfTransparentRectTo(out, xPos + border, yPos + border, width - (border * 2), height - (border * 2));
int barProgress = (width * mon._mhitpoints) / maxLife;
if (barProgress) {
if (barProgress != 0) {
DrawArt(out, xPos + border + 1, yPos + border + 1, &health, 0, barProgress, height - (border * 2) - 2);
}
@ -110,10 +110,10 @@ void DrawMonsterHealthBar(const CelOutputBuffer &out)
int resOffset = 5;
for (int i = 0; i < 3; i++) {
if (mon.mMagicRes & immunes[i]) {
if ((mon.mMagicRes & immunes[i]) != 0) {
DrawArt(out, xPos + resOffset, yPos + height - 6, &resistance, i * 2 + 1);
resOffset += resistance.w() + 2;
} else if (mon.mMagicRes & resists[i]) {
} else if ((mon.mMagicRes & resists[i]) != 0) {
DrawArt(out, xPos + resOffset, yPos + height - 6, &resistance, i * 2);
resOffset += resistance.w() + 2;
}

View file

@ -764,7 +764,7 @@ void StartQuestlog()
void QuestlogUp()
{
if (numqlines) {
if (numqlines != 0) {
if (qline == qtopline) {
qline = 22;
} else if (qline == 22) {
@ -778,7 +778,7 @@ void QuestlogUp()
void QuestlogDown()
{
if (numqlines) {
if (numqlines != 0) {
if (qline == 22) {
qline = qtopline;
} else if (qline == qtopline + 2 * numqlines - 2) {
@ -800,15 +800,11 @@ void QuestlogEnter()
void QuestlogESC()
{
int y, i;
y = (MouseY - 32) / 12;
if (numqlines) {
for (i = 0; i < numqlines; i++) {
if (y == qtopline + 2 * i) {
qline = y;
QuestlogEnter();
}
int y = (MouseY - 32) / 12;
for (int i = 0; i < numqlines; i++) {
if (y == qtopline + 2 * i) {
qline = y;
QuestlogEnter();
}
}
if (y == 22) {

View file

@ -25,7 +25,7 @@ uint32_t SHA1CircularShift(uint32_t bits, uint32_t word)
assert(bits < 32);
assert(bits > 0);
if (word >> 31) {
if ((word >> 31) != 0) {
//moving this part to a separate volatile variable fixes saves in x64-release build in visual studio 2017
volatile uint32_t tmp = ((~word) >> (32 - bits));
return (word << bits) | (~tmp);

View file

@ -5,9 +5,6 @@
#include <mutex>
#include <string>
#define SI_SUPPORT_IOSTREAMS
#include <SimpleIni.h>
#include "storm/storm.h"
#include "DiabloUI/diabloui.h"
#include "options.h"
@ -37,27 +34,6 @@ std::string *SBasePath = nullptr;
SdlMutex Mutex;
std::string getIniPath()
{
auto path = paths::ConfigPath() + std::string("diablo.ini");
return path;
}
CSimpleIni &getIni()
{
static CSimpleIni ini;
static bool isIniLoaded = false;
if (!isIniLoaded) {
auto path = getIniPath();
auto stream = CreateFileStream(path.c_str(), std::fstream::in | std::fstream::binary);
ini.SetSpaces(false);
if (stream != nullptr)
ini.LoadData(*stream);
isIniLoaded = true;
}
return ini;
}
} // namespace
bool SFileReadFileThreadSafe(HANDLE hFile, void *buffer, DWORD nNumberOfBytesToRead, DWORD *read, int *lpDistanceToMoveHigh)
@ -162,59 +138,6 @@ bool SFileOpenFile(const char *filename, HANDLE *phFile)
return result;
}
bool getIniBool(const char *sectionName, const char *keyName, bool defaultValue)
{
bool value = getIni().GetBoolValue(sectionName, keyName, defaultValue);
return value;
}
float getIniFloat(const char *sectionName, const char *keyName, float defaultValue)
{
const double value = getIni().GetDoubleValue(sectionName, keyName, defaultValue);
return (float)value;
}
bool getIniValue(const char *sectionName, const char *keyName, char *string, int stringSize, const char *defaultString)
{
const char *value = getIni().GetValue(sectionName, keyName);
if (value == nullptr) {
strncpy(string, defaultString, stringSize);
return false;
}
strncpy(string, value, stringSize);
return true;
}
void setIniValue(const char *sectionName, const char *keyName, const char *value, int len)
{
auto &ini = getIni();
std::string stringValue(value, len ? len : strlen(value));
ini.SetValue(sectionName, keyName, stringValue.c_str());
}
void SaveIni()
{
auto iniPath = getIniPath();
auto stream = CreateFileStream(iniPath.c_str(), std::fstream::out | std::fstream::trunc | std::fstream::binary);
getIni().Save(*stream, true);
}
int getIniInt(const char *keyname, const char *valuename, int defaultValue)
{
long value = getIni().GetLongValue(keyname, valuename, defaultValue);
return value;
}
void setIniInt(const char *keyname, const char *valuename, int value)
{
getIni().SetLongValue(keyname, valuename, value);
}
void setIniFloat(const char *keyname, const char *valuename, float value)
{
getIni().SetDoubleValue(keyname, valuename, value);
}
DWORD SErrGetLastError()
{
return ::GetLastError();

View file

@ -256,15 +256,6 @@ DWORD WINAPI SFileGetFileSize(HANDLE hFile, uint32_t *lpFileSizeHigh = nullptr);
DWORD WINAPI SFileSetFilePointer(HANDLE, int, int *, int);
bool WINAPI SFileCloseFile(HANDLE hFile);
bool getIniBool(const char *sectionName, const char *keyName, bool defaultValue = false);
float getIniFloat(const char *sectionName, const char *keyName, float defaultValue);
bool getIniValue(const char *sectionName, const char *keyName, char *string, int stringSize, const char *defaultString = "");
void setIniValue(const char *sectionName, const char *keyName, const char *value, int len = 0);
void SaveIni();
int getIniInt(const char *keyname, const char *valuename, int defaultValue);
void setIniInt(const char *keyname, const char *valuename, int value);
void setIniFloat(const char *keyname, const char *valuename, float value);
// These error codes are used and returned by StormLib.
// See StormLib/src/StormPort.h
#if defined(_WIN32)

View file

@ -36,7 +36,7 @@ std::uint8_t SVidAudioDepth;
unsigned long SVidWidth, SVidHeight;
double SVidFrameEnd;
double SVidFrameLength;
BYTE SVidLoop;
bool SVidLoop;
smk SVidSMK;
SDL_Color SVidPreviousPalette[256];
SDL_Palette *SVidPalette;
@ -136,7 +136,7 @@ bool SVidLoadNextFrame()
bool SVidPlayBegin(const char *filename, int flags, HANDLE *video)
{
if (flags & 0x10000 || flags & 0x20000000) {
if ((flags & 0x10000) != 0 || (flags & 0x20000000) != 0) {
return false;
}
@ -179,7 +179,7 @@ bool SVidPlayBegin(const char *filename, int flags, HANDLE *video)
if (enableAudio && depth[0] != 0) {
sound_stop(); // Stop in-progress music and sound effects
smk_enable_audio(SVidSMK, 0, enableAudio);
smk_enable_audio(SVidSMK, 0, enableAudio ? 1 : 0);
SVidAudioDepth = depth[0];
auto decoder = std::make_unique<PushAulibDecoder>(channels[0], rate[0]);
SVidAudioDecoder = decoder.get();
@ -204,7 +204,7 @@ bool SVidPlayBegin(const char *filename, int flags, HANDLE *video)
smk_info_all(SVidSMK, nullptr, &nFrames, &SVidFrameLength);
smk_info_video(SVidSMK, &SVidWidth, &SVidHeight, nullptr);
smk_enable_video(SVidSMK, enableVideo);
smk_enable_video(SVidSMK, enableVideo ? 1 : 0);
smk_first(SVidSMK); // Decode first frame
smk_info_video(SVidSMK, &SVidWidth, &SVidHeight, nullptr);
@ -251,7 +251,7 @@ bool SVidPlayBegin(const char *filename, int flags, HANDLE *video)
bool SVidPlayContinue()
{
if (smk_palette_updated(SVidSMK)) {
if (smk_palette_updated(SVidSMK) != 0) {
SDL_Color colors[256];
const unsigned char *paletteData = smk_get_palette(SVidSMK);
@ -387,7 +387,7 @@ void SVidPlayEnd(HANDLE video)
if (texture == nullptr) {
ErrSdl();
}
if (renderer && SDL_RenderSetLogicalSize(renderer, gnScreenWidth, gnScreenHeight) <= -1) {
if (renderer != nullptr && SDL_RenderSetLogicalSize(renderer, gnScreenWidth, gnScreenHeight) <= -1) {
ErrSdl();
}
}

View file

@ -123,7 +123,7 @@ static void SyncPlrInv(TSyncHeader *pHdr)
} else {
pHdr->wItemCI = items[ii]._iCreateInfo;
pHdr->dwItemSeed = items[ii]._iSeed;
pHdr->bItemId = items[ii]._iIdentified;
pHdr->bItemId = items[ii]._iIdentified ? 1 : 0;
pHdr->bItemDur = items[ii]._iDurability;
pHdr->bItemMDur = items[ii]._iMaxDur;
pHdr->bItemCh = items[ii]._iCharges;
@ -143,7 +143,7 @@ static void SyncPlrInv(TSyncHeader *pHdr)
pHdr->wPInvIndx = pItem->IDidx;
pHdr->wPInvCI = pItem->_iCreateInfo;
pHdr->dwPInvSeed = pItem->_iSeed;
pHdr->bPInvId = pItem->_iIdentified;
pHdr->bPInvId = pItem->_iIdentified ? 1 : 0;
} else {
pHdr->bPInvLoc = -1;
}

View file

@ -823,15 +823,15 @@ void InitTowners()
continue;
break;
case TOWN_FARMER:
if (!gbIsHellfire || sgGameInitInfo.bCowQuest)
if (!gbIsHellfire || sgGameInitInfo.bCowQuest != 0)
continue;
break;
case TOWN_COWFARM:
if (!gbIsHellfire || !sgGameInitInfo.bCowQuest || quests[Q_FARMER]._qactive == 10)
if (!gbIsHellfire || sgGameInitInfo.bCowQuest == 0 || quests[Q_FARMER]._qactive == 10)
continue;
break;
case TOWN_GIRL:
if (!gbIsHellfire || !sgGameInitInfo.bTheoQuest || !plr->_pLvlVisited[17])
if (!gbIsHellfire || sgGameInitInfo.bTheoQuest == 0 || !plr->_pLvlVisited[17])
continue;
break;
default:

View file

@ -38,7 +38,7 @@ void track_process()
if (cursmx != target.x || cursmy != target.y) {
Uint32 tick = SDL_GetTicks();
int TickMultiplier = 6;
if (currlevel == 0 && sgGameInitInfo.bRunInTown)
if (currlevel == 0 && sgGameInitInfo.bRunInTown != 0)
TickMultiplier = 3;
if ((int)(tick - sgdwLastWalk) >= gnTickDelay * TickMultiplier) {
sgdwLastWalk = tick;

View file

@ -78,7 +78,7 @@ void InitTownTriggers()
if (!gbIsSpawn) {
auto &myPlayer = plr[myplr];
if (gbIsMultiplayer || myPlayer.pTownWarps & 1 || (gbIsHellfire && myPlayer._pLevel >= 10)) {
if (gbIsMultiplayer || (myPlayer.pTownWarps & 1) != 0 || (gbIsHellfire && myPlayer._pLevel >= 10)) {
townwarps[0] = true;
trigs[numtrigs].position = { 49, 21 };
trigs[numtrigs]._tmsg = WM_DIABTOWNWARP;
@ -89,14 +89,14 @@ void InitTownTriggers()
#endif
numtrigs++;
}
if (gbIsMultiplayer || myPlayer.pTownWarps & 2 || (gbIsHellfire && myPlayer._pLevel >= 15)) {
if (gbIsMultiplayer || (myPlayer.pTownWarps & 2) != 0 || (gbIsHellfire && myPlayer._pLevel >= 15)) {
townwarps[1] = true;
trigs[numtrigs].position = { 17, 69 };
trigs[numtrigs]._tmsg = WM_DIABTOWNWARP;
trigs[numtrigs]._tlvl = 9;
numtrigs++;
}
if (gbIsMultiplayer || myPlayer.pTownWarps & 4 || (gbIsHellfire && myPlayer._pLevel >= 20)) {
if (gbIsMultiplayer || (myPlayer.pTownWarps & 4) != 0 || (gbIsHellfire && myPlayer._pLevel >= 20)) {
townwarps[2] = true;
trigs[numtrigs].position = { 41, 80 };
trigs[numtrigs]._tmsg = WM_DIABTOWNWARP;