diff --git a/MakefileVC b/MakefileVC index 384d4bd41..5f26fc300 100644 --- a/MakefileVC +++ b/MakefileVC @@ -105,6 +105,6 @@ diablo.res: Diablo.rc $(RC) /i $(VC_INC_DIR) /l 0x409 /fo $@ $< clean: - @$(RM) -v $(OBJS) + @$(RM) -v $(OBJS) vc60.idb vc60.pdb Diablo.pdb Diablo.pch .PHONY: clean all diff --git a/Source/automap.cpp b/Source/automap.cpp index f2446d3c5..432b8cc5f 100644 --- a/Source/automap.cpp +++ b/Source/automap.cpp @@ -577,7 +577,7 @@ void SetAutomapView(int x, int y) return; } - automapview[xx][yy] = 1; + automapview[xx][yy] = TRUE; maptype = GetAutomapType(xx, yy, FALSE); solid = maptype & 0x4000; diff --git a/Source/control.cpp b/Source/control.cpp index 57d38af4f..aa435f170 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -2640,7 +2640,7 @@ void control_press_enter() } if (i >= 8) { strcpy(sgszTalkSave[sgbNextTalkSave], sgszTalkMsg); - sgbNextTalkSave = sgbNextTalkSave + 1; + sgbNextTalkSave++; sgbNextTalkSave &= 7; } else { talk_save = sgbNextTalkSave - 1; diff --git a/Source/drlg_l1.cpp b/Source/drlg_l1.cpp index 756b2221d..f9e28fe57 100644 --- a/Source/drlg_l1.cpp +++ b/Source/drlg_l1.cpp @@ -240,15 +240,12 @@ void DRLG_Init_Globals() memset(dItem, 0, sizeof(dItem)); memset(dMissile, 0, sizeof(dMissile)); memset(dArch, 0, sizeof(dArch)); - if (!lightflag) - { + if (!lightflag) { if (light4flag) c = 3; else c = 15; - } - else - { + } else { c = 0; } memset(dLight, c, sizeof(dLight)); @@ -1258,10 +1255,8 @@ void DRLG_L1Shadows() dungeon[x - 1][y - 1] = SPATS[i].nv1; if (SPATS[i].nv2 && !L5dflags[x][y - 1]) dungeon[x][y - 1] = SPATS[i].nv2; - if (SPATS[i].nv3) { - if (!L5dflags[x - 1][y]) - dungeon[x - 1][y] = SPATS[i].nv3; - } + if (SPATS[i].nv3 && !L5dflags[x - 1][y]) + dungeon[x - 1][y] = SPATS[i].nv3; } } } diff --git a/Source/drlg_l3.cpp b/Source/drlg_l3.cpp index 74ca32ebc..3395e7392 100644 --- a/Source/drlg_l3.cpp +++ b/Source/drlg_l3.cpp @@ -993,8 +993,8 @@ void DRLG_L3MakeMegas() { int i, j, v, rv; - for (j = 0; j < DMAXY-1; j++) { - for (i = 0; i < DMAXX-1; i++) { + for (j = 0; j < DMAXY - 1; j++) { + for (i = 0; i < DMAXX - 1; i++) { v = dungeon[i + 1][j + 1] + 2 * dungeon[i][j + 1] + 4 * dungeon[i + 1][j] + 8 * dungeon[i][j]; if (v == 6) { rv = random(0, 2); @@ -1014,10 +1014,10 @@ void DRLG_L3MakeMegas() } dungeon[i][j] = L3ConvTbl[v]; } - dungeon[DMAXX-1][j] = 8; + dungeon[DMAXX - 1][j] = 8; } for (i = 0; i < DMAXX; i++) { - dungeon[i][DMAXY-1] = 8; + dungeon[i][DMAXY - 1] = 8; } } @@ -1430,7 +1430,7 @@ void DRLG_L3PoolFix() { int dunx, duny; - for (duny = 0; duny < DMAXY; duny++) { // BUGFIX: Change '0' to '1' and 'DMAXY' to 'DMAXY - 1' + for (duny = 0; duny < DMAXY; duny++) { // BUGFIX: Change '0' to '1' and 'DMAXY' to 'DMAXY - 1' for (dunx = 0; dunx < DMAXX; dunx++) { // BUGFIX: Change '0' to '1' and 'DMAXX' to 'DMAXX - 1' if (dungeon[dunx][duny] == 8) { if (dungeon[dunx - 1][duny - 1] >= 25 && dungeon[dunx - 1][duny - 1] <= 41 @@ -1649,7 +1649,7 @@ void DRLG_L3Wood() int i, j, x, y, xx, yy, rt, rp, x1, y1, x2, y2; BOOL skip; - for (j = 0; j < DMAXY - 1; j++) { // BUGFIX: Change '0' to '1' + for (j = 0; j < DMAXY - 1; j++) { // BUGFIX: Change '0' to '1' for (i = 0; i < DMAXX - 1; i++) { // BUGFIX: Change '0' to '1' if (dungeon[i][j] == 10 && random(0, 2) != 0) { x = i; @@ -1719,7 +1719,7 @@ void DRLG_L3Wood() } } - for (j = 0; j < DMAXY; j++) { // BUGFIX: Change '0' to '1' + for (j = 0; j < DMAXY; j++) { // BUGFIX: Change '0' to '1' for (i = 0; i < DMAXX; i++) { // BUGFIX: Change '0' to '1' if (dungeon[i][j] == 7 && random(0, 1) == 0 && SkipThemeRoom(i, j)) { rt = random(0, 2); diff --git a/Source/drlg_l4.cpp b/Source/drlg_l4.cpp index 91b1ebef2..aadfa212e 100644 --- a/Source/drlg_l4.cpp +++ b/Source/drlg_l4.cpp @@ -492,7 +492,7 @@ void CreateL4Dungeon(DWORD rseed, int entry) void DRLG_L4(int entry) { - int i, j, spi, spj; + int i, j, spi, spj, ar; BOOL doneflag; do { @@ -501,8 +501,11 @@ void DRLG_L4(int entry) InitL4Dungeon(); L4firstRoom(); L4FixRim(); - } while (GetArea() < 173); - uShape(); + ar = GetArea(); + if (ar >= 173) { + uShape(); + } + } while (ar < 173); L4makeDungeon(); L4makeDmt(); L4tileFix(); diff --git a/Source/engine.cpp b/Source/engine.cpp index 9a4c4de8a..a7173b2f3 100644 --- a/Source/engine.cpp +++ b/Source/engine.cpp @@ -2337,9 +2337,9 @@ int random(BYTE idx, int v) { if (v <= 0) return 0; - if (v >= 0xFFFF) - return GetRndSeed() % v; - return (GetRndSeed() >> 16) % v; + if (v < 0xFFFF) + return (GetRndSeed() >> 16) % v; + return GetRndSeed() % v; } void engine_debug_trap(BOOL show_cursor) diff --git a/Source/gmenu.cpp b/Source/gmenu.cpp index 0b7a5165e..9b3e7f3ab 100644 --- a/Source/gmenu.cpp +++ b/Source/gmenu.cpp @@ -311,7 +311,6 @@ BOOLEAN gmenu_valid_mouse_pos(int *plOffset) BOOL gmenu_left_mouse(BOOL isDown) { - BOOL result; TMenuItem *pItem; DWORD i, w; int dummy; @@ -319,53 +318,45 @@ BOOL gmenu_left_mouse(BOOL isDown) if (!isDown) { if (mouseNavigation) { mouseNavigation = FALSE; - result = TRUE; + return TRUE; } else { - result = FALSE; + return FALSE; } + } + if (!sgpCurrentMenu) { + return FALSE; + } + if (MouseY >= PANEL_TOP) { + return FALSE; + } + if (MouseY - 117 < 0) { + return TRUE; + } + i = (MouseY - 117) / 45; + if (i >= sgCurrentMenuIdx) { + return TRUE; + } + pItem = &sgpCurrentMenu[i]; + if (!(sgpCurrentMenu[i].dwFlags & GMENU_ENABLED)) { + return TRUE; + } + w = gmenu_get_lfont(pItem); + if (MouseX < SCREEN_WIDTH / 2 - w / 2) { + return TRUE; + } + if (MouseX > SCREEN_WIDTH / 2 + w / 2) { + return TRUE; + } + sgpCurrItem = pItem; + PlaySFX(IS_TITLEMOV); + if (pItem->dwFlags & GMENU_SLIDER) { + mouseNavigation = gmenu_valid_mouse_pos(&dummy); + gmenu_on_mouse_move(); } else { - - if (!sgpCurrentMenu) { - return FALSE; - } - if (MouseY >= PANEL_TOP) { - return FALSE; - } - if (MouseY - 117 >= 0) { - i = (MouseY - 117) / 45; - if (i < sgCurrentMenuIdx) { - pItem = &sgpCurrentMenu[i]; - if ((sgpCurrentMenu[i].dwFlags & GMENU_ENABLED) != 0) { - w = gmenu_get_lfont(pItem); - if (MouseX >= SCREEN_WIDTH / 2 - w / 2) { - if (MouseX <= SCREEN_WIDTH / 2 + w / 2) { - sgpCurrItem = pItem; - PlaySFX(IS_TITLEMOV); - if (pItem->dwFlags & GMENU_SLIDER) { - mouseNavigation = gmenu_valid_mouse_pos(&dummy); - gmenu_on_mouse_move(); - } else { - sgpCurrItem->fnMenu(TRUE); - } - result = TRUE; - } else { - result = TRUE; - } - } else { - result = TRUE; - } - } else { - result = TRUE; - } - } else { - result = TRUE; - } - } else { - result = TRUE; - } + sgpCurrItem->fnMenu(TRUE); } - return result; + return TRUE; } void gmenu_enable(TMenuItem *pMenuItem, BOOL enable) diff --git a/Source/init.cpp b/Source/init.cpp index 0f6965c50..ff9d824e6 100644 --- a/Source/init.cpp +++ b/Source/init.cpp @@ -159,24 +159,30 @@ void init_disable_screensaver(BOOLEAN disable) char Data[16]; DWORD Type, cbData; HKEY phkResult; + LRESULT success; // BUGFIX: this is probably the worst possible way to do this. Alternatives: ExtEscape() with SETPOWERMANAGEMENT, // SystemParametersInfo() with SPI_SETSCREENSAVEACTIVE/SPI_SETPOWEROFFACTIVE/SPI_SETLOWPOWERACTIVE - if (!RegOpenKeyEx(HKEY_CURRENT_USER, "Control Panel\\Desktop", 0, KEY_READ | KEY_WRITE, (PHKEY)&phkResult)) { - if (disable) { - cbData = 16; - if (!RegQueryValueEx(phkResult, "ScreenSaveActive", 0, &Type, (LPBYTE)Data, &cbData)) - screensaver_enabled_prev = Data[0] != '0'; - enabled = FALSE; - } else { - enabled = screensaver_enabled_prev; - } - Data[1] = 0; - Data[0] = enabled ? '1' : '0'; - RegSetValueEx(phkResult, "ScreenSaveActive", 0, REG_SZ, (const BYTE *)Data, 2); - RegCloseKey(phkResult); + success = RegOpenKeyEx(HKEY_CURRENT_USER, "Control Panel\\Desktop", 0, KEY_READ | KEY_WRITE, (PHKEY)&phkResult); + if (success != ERROR_SUCCESS) { + return; + } + + if (disable) { + cbData = 16; + success = RegQueryValueEx(phkResult, "ScreenSaveActive", 0, &Type, (LPBYTE)Data, &cbData); + if (success == ERROR_SUCCESS) + screensaver_enabled_prev = Data[0] != '0'; + enabled = FALSE; + } else { + enabled = screensaver_enabled_prev; } + + Data[1] = 0; + Data[0] = enabled ? '1' : '0'; + RegSetValueEx(phkResult, "ScreenSaveActive", 0, REG_SZ, (const BYTE *)Data, 2); + RegCloseKey(phkResult); } void init_create_window(int nCmdShow) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index c2e02ccc6..bbc38a7fd 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -1002,9 +1002,9 @@ void CheckMissileCol(int i, int mindam, int maxdam, BOOL shift, int mx, int my, missile[i]._miHitFlag = 1; } } else { - if (monster[missile[i]._misource]._mFlags & 0x10 + if (monster[missile[i]._misource]._mFlags & MFLAG_TARGETS_MONSTER && dMonster[mx][my] > 0 - && monster[dMonster[mx][my] - 1]._mFlags & 0x20 + && monster[dMonster[mx][my] - 1]._mFlags & MFLAG_GOLEM && MonsterTrapHit(dMonster[mx][my] - 1, mindam, maxdam, missile[i]._midist, missile[i]._mitype, shift)) { if (!nodel) missile[i]._mirange = 0; @@ -2392,9 +2392,9 @@ void AddBoneSpirit(int mi, int sx, int sy, int dx, int dy, int midir, char miene missile[mi]._mlid = AddLight(sx, sy, 8); if (!mienemy) { UseMana(id, SPL_BONESPIRIT); - drawhpflag = TRUE; plr[id]._pHitPoints -= 384; plr[id]._pHPBase -= 384; + drawhpflag = TRUE; if (plr[id]._pHitPoints <= 0) SyncPlrKill(id, 0); } diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index 253c23f3e..2baf2cdf3 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -787,7 +787,7 @@ void scrollrt_draw_clipped_dungeon(BYTE *pBuff, int sx, int sy, int dx, int dy, draw_monster_num = -(negMon + 1); if ((DWORD)draw_monster_num < MAXMONSTERS) { pMonster = &monster[draw_monster_num]; - if (!(pMonster->_mFlags & 1)) { + if (!(pMonster->_mFlags & MFLAG_HIDDEN)) { if (pMonster->MType != NULL) { px = dx + pMonster->_mxoff - pMonster->MType->width2; py = dy + pMonster->_myoff; @@ -830,7 +830,7 @@ void scrollrt_draw_clipped_dungeon(BYTE *pBuff, int sx, int sy, int dx, int dy, draw_monster_num = nMon - 1; if ((DWORD)draw_monster_num < MAXMONSTERS) { pMonster = &monster[draw_monster_num]; - if (!(pMonster->_mFlags & 1)) { + if (!(pMonster->_mFlags & MFLAG_HIDDEN)) { if (pMonster->MType != NULL) { px = dx + pMonster->_mxoff - pMonster->MType->width2; py = dy + pMonster->_myoff; @@ -1253,7 +1253,7 @@ void scrollrt_draw_clipped_dungeon_2(BYTE *pBuff, int sx, int sy, int skipChunks draw_monster_num = -(negMon + 1); if ((DWORD)draw_monster_num < MAXMONSTERS) { pMonster = &monster[draw_monster_num]; - if (!(pMonster->_mFlags & 1)) { + if (!(pMonster->_mFlags & MFLAG_HIDDEN)) { if (pMonster->MType != NULL) { px = dx + pMonster->_mxoff - pMonster->MType->width2; py = dy + pMonster->_myoff; @@ -1296,7 +1296,7 @@ void scrollrt_draw_clipped_dungeon_2(BYTE *pBuff, int sx, int sy, int skipChunks draw_monster_num = nMon - 1; if ((DWORD)draw_monster_num < MAXMONSTERS) { pMonster = &monster[draw_monster_num]; - if (!(pMonster->_mFlags & 1)) { + if (!(pMonster->_mFlags & MFLAG_HIDDEN)) { if (pMonster->MType != NULL) { px = dx + pMonster->_mxoff - pMonster->MType->width2; py = dy + pMonster->_myoff; @@ -1680,7 +1680,7 @@ void scrollrt_draw_dungeon(BYTE *pBuff, int sx, int sy, int capChunks, int CelCa draw_monster_num = -(negMon + 1); if ((DWORD)draw_monster_num < MAXMONSTERS) { pMonster = &monster[draw_monster_num]; - if (!(pMonster->_mFlags & 1)) { + if (!(pMonster->_mFlags & MFLAG_HIDDEN)) { if (pMonster->MType != NULL) { px = dx + pMonster->_mxoff - pMonster->MType->width2; py = dy + pMonster->_myoff; @@ -1723,7 +1723,7 @@ void scrollrt_draw_dungeon(BYTE *pBuff, int sx, int sy, int capChunks, int CelCa draw_monster_num = nMon - 1; if ((DWORD)draw_monster_num < MAXMONSTERS) { pMonster = &monster[draw_monster_num]; - if (!(pMonster->_mFlags & 1)) { + if (!(pMonster->_mFlags & MFLAG_HIDDEN)) { if (pMonster->MType != NULL) { px = dx + pMonster->_mxoff - pMonster->MType->width2; py = dy + pMonster->_myoff;