From d1914efa4109ebd6f3016c5c6fd494c53c000fd9 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Wed, 16 Oct 2019 13:52:28 +0200 Subject: [PATCH 01/13] Make sens of lineoffset (#1810) --- Source/control.cpp | 89 ++++++++++++++++++++++++++-------------------- Source/control.h | 2 +- 2 files changed, 52 insertions(+), 39 deletions(-) diff --git a/Source/control.cpp b/Source/control.cpp index 42ae61cf0..b163d31db 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -75,32 +75,45 @@ const BYTE fontkern[68] = { 3, 2, 7, 6, 3, 10, 10, 6, 6, 7, 4, 4, 9, 6, 6, 12, 3, 7 }; -const int lineoffset[25] = { - BUFFER_WIDTH * 594 + 241, - BUFFER_WIDTH * 32, - BUFFER_WIDTH * 32, - BUFFER_WIDTH * 32, - BUFFER_WIDTH * 32 + 180, - BUFFER_WIDTH * 582 + 241, - BUFFER_WIDTH * 606 + 241, - BUFFER_WIDTH * 32, - BUFFER_WIDTH * 32, - BUFFER_WIDTH * 32, - BUFFER_WIDTH * 576 + 241, - BUFFER_WIDTH * 594 + 241, - BUFFER_WIDTH * 612 + 241, - BUFFER_WIDTH * 32, - BUFFER_WIDTH * 32, - BUFFER_WIDTH * 572 + 241, - BUFFER_WIDTH * 587 + 241, - BUFFER_WIDTH * 601 + 241, - BUFFER_WIDTH * 616 + 241, - BUFFER_WIDTH * 32, - BUFFER_WIDTH * 570 + 241, - BUFFER_WIDTH * 582 + 241, - BUFFER_WIDTH * 594 + 241, - BUFFER_WIDTH * 606 + 241, - BUFFER_WIDTH * 617 + 241 +/** + * Line height for info box when displaying 1, 2, 3, 4 and 5 lines respectivly + */ +const int lineOffsets[5][5] = { + { + BUFFER_WIDTH * (434 + SCREEN_Y) + 177 + SCREEN_X, + BUFFER_WIDTH * 32, + BUFFER_WIDTH * 32, + BUFFER_WIDTH * 32, + BUFFER_WIDTH * 32 + 180, + }, + { + BUFFER_WIDTH * (422 + SCREEN_Y) + 177 + SCREEN_X, + BUFFER_WIDTH * (446 + SCREEN_Y) + 177 + SCREEN_X, + BUFFER_WIDTH * 32, + BUFFER_WIDTH * 32, + BUFFER_WIDTH * 32, + }, + { + BUFFER_WIDTH * (416 + SCREEN_Y) + 177 + SCREEN_X, + BUFFER_WIDTH * (434 + SCREEN_Y) + 177 + SCREEN_X, + BUFFER_WIDTH * (452 + SCREEN_Y) + 177 + SCREEN_X, + BUFFER_WIDTH * 32, + BUFFER_WIDTH * 32, + }, + { + BUFFER_WIDTH * (412 + SCREEN_Y) + 177 + SCREEN_X, + BUFFER_WIDTH * (427 + SCREEN_Y) + 177 + SCREEN_X, + BUFFER_WIDTH * (441 + SCREEN_Y) + 177 + SCREEN_X, + BUFFER_WIDTH * (456 + SCREEN_Y) + 177 + SCREEN_X, + BUFFER_WIDTH * 32, + }, + { + BUFFER_WIDTH * (410 + SCREEN_Y) + 177 + SCREEN_X, + BUFFER_WIDTH * (422 + SCREEN_Y) + 177 + SCREEN_X, + BUFFER_WIDTH * (434 + SCREEN_Y) + 177 + SCREEN_X, + BUFFER_WIDTH * (446 + SCREEN_Y) + 177 + SCREEN_X, + BUFFER_WIDTH * (457 + SCREEN_Y) + 177 + SCREEN_X, + } }; const BYTE gbFontTransTbl[256] = { // clang-format off @@ -1612,31 +1625,31 @@ void control_print_info_str(int y, char *str, BOOL center, int lines) { BYTE c; char *tmp; - int screen_x, line, nOffset; + int strWidth, lineOffset, lineStart; - line = 0; - nOffset = lineoffset[y + 4 * lines + lines] + (SCREEN_WIDTH - PANEL_WIDTH) / 2; + lineOffset = 0; + lineStart = lineOffsets[lines][y] + (SCREEN_WIDTH - PANEL_WIDTH) / 2; if (center == 1) { - screen_x = 0; + strWidth = 0; tmp = str; while (*tmp) { c = gbFontTransTbl[(BYTE)*tmp++]; - screen_x += fontkern[fontframe[c]] + 1; + strWidth += fontkern[fontframe[c]] + 1; } - if (screen_x < 288) - line = (288 - screen_x) >> 1; - nOffset += line; + if (strWidth < 288) + lineOffset = (288 - strWidth) >> 1; + lineStart += lineOffset; } while (*str) { c = gbFontTransTbl[(BYTE)*str++]; c = fontframe[c]; - line += fontkern[c] + 2; + lineOffset += fontkern[c] + 2; if (c) { - if (line < 288) { - CPrintString(nOffset, c, infoclr); + if (lineOffset < 288) { + CPrintString(lineStart, c, infoclr); } } - nOffset += fontkern[c] + 2; + lineStart += fontkern[c] + 2; } } diff --git a/Source/control.h b/Source/control.h index c2e08e0a5..181be4c5d 100644 --- a/Source/control.h +++ b/Source/control.h @@ -123,7 +123,7 @@ void control_up_down(int v); /* rdata */ extern const BYTE fontframe[128]; extern const BYTE fontkern[68]; -extern const int lineoffset[25]; +extern const int lineOffsets[5][5]; extern const BYTE gbFontTransTbl[256]; /* data */ From f72b3fbd489935e986989a3bdaa396ec33bd0a29 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Fri, 18 Oct 2019 00:31:35 +0100 Subject: [PATCH 02/13] credits.cpp: Enum for CreateFontA iPitchAndFamily (#1811) * credits.cpp: Enum for CreateFontA iPitchAndFamily From https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createfonta: > The two low-order bits specify the pitch of the font > The four high-order bits specify the font family [[MS-WMF]: 2.1.1.8 FamilyFont Enumeration](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-wmf/9a632766-1f1c-4e2b-b1a4-f5b1a45f99ad) [[MS-WMF]: 2.1.1.24 PitchFont Enumeration](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-wmf/22dbe377-aec4-4669-88e6-b8fdd9351d76) * credits.cpp: Use enum for font weight https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createfonta --- DiabloUI/credits.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DiabloUI/credits.cpp b/DiabloUI/credits.cpp index b6e6b3d6c..110cfde91 100644 --- a/DiabloUI/credits.cpp +++ b/DiabloUI/credits.cpp @@ -135,7 +135,7 @@ void __fastcall credits_LoadImgCreditTxt(HWND hWnd, LPARAM lParam) SDlgSetBitmapI(v13, 0, 0, -1, 1, credit_back_img, (int)&Rect, v7, v8, -1); credit_vertical_pos2 = v8 - 30; credits_CalcPosROP3(hWnd); - v9 = CreateFontA(-17, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 0x12u, "Times New Roman"); + v9 = CreateFontA(-17, 0, 0, 0, FW_BOLD, 0, 0, 0, 0, 0, 0, 0, VARIABLE_PITCH | (FF_SCRIPT << 2), "Times New Roman"); if (!v9 || (v11 = SGdiImportFont(v9, (int)&creditsobj), DeleteObject(v9), !v11)) Title_KillAndFadeDlg(hWnd); } From 85afd0768a78731ac4cf041179e0731d1fa77bad Mon Sep 17 00:00:00 2001 From: galaxyhaxz Date: Fri, 18 Oct 2019 06:33:10 -0500 Subject: [PATCH 03/13] Add bugfix for dupe bug --- Source/inv.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/inv.cpp b/Source/inv.cpp index 036f203e9..9ffbb043d 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -1521,7 +1521,7 @@ void AutoGetItem(int pnum, int ii) } item[ii]._iCreateInfo &= 0x7FFF; - plr[pnum].HoldItem = item[ii]; + plr[pnum].HoldItem = item[ii]; /// BUGFIX: overwrites cursor item, allowing for belt dupe bug CheckQuestItem(pnum); CheckBookLevel(pnum); CheckItemStats(pnum); From 57f1fcce4c6727b6437b2ad0691bdf2bb95e86d8 Mon Sep 17 00:00:00 2001 From: qndel Date: Sun, 20 Oct 2019 20:40:35 +0200 Subject: [PATCH 04/13] some enums (#1816) --- Source/diablo.cpp | 16 ++++++++-------- Source/inv.cpp | 18 +++++++++--------- Source/multi.cpp | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 7e53f72cb..25e5a6b28 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -1335,43 +1335,43 @@ void PressChar(int vkey) case '!': case '1': if (plr[myplr].SpdList[0]._itype != -1 && plr[myplr].SpdList[0]._itype != 11) { - UseInvItem(myplr, 47); + UseInvItem(myplr, INVITEM_BELT_FIRST); } return; case '@': case '2': if (plr[myplr].SpdList[1]._itype != -1 && plr[myplr].SpdList[1]._itype != 11) { - UseInvItem(myplr, 48); + UseInvItem(myplr, INVITEM_BELT_FIRST + 1); } return; case '#': case '3': if (plr[myplr].SpdList[2]._itype != -1 && plr[myplr].SpdList[2]._itype != 11) { - UseInvItem(myplr, 49); + UseInvItem(myplr, INVITEM_BELT_FIRST + 2); } return; case '$': case '4': if (plr[myplr].SpdList[3]._itype != -1 && plr[myplr].SpdList[3]._itype != 11) { - UseInvItem(myplr, 50); + UseInvItem(myplr, INVITEM_BELT_FIRST + 3); } return; case '%': case '5': if (plr[myplr].SpdList[4]._itype != -1 && plr[myplr].SpdList[4]._itype != 11) { - UseInvItem(myplr, 51); + UseInvItem(myplr, INVITEM_BELT_FIRST + 4); } return; case '^': case '6': if (plr[myplr].SpdList[5]._itype != -1 && plr[myplr].SpdList[5]._itype != 11) { - UseInvItem(myplr, 52); + UseInvItem(myplr, INVITEM_BELT_FIRST + 5); } return; case '&': case '7': if (plr[myplr].SpdList[6]._itype != -1 && plr[myplr].SpdList[6]._itype != 11) { - UseInvItem(myplr, 53); + UseInvItem(myplr, INVITEM_BELT_FIRST + 6); } return; case '*': @@ -1383,7 +1383,7 @@ void PressChar(int vkey) } #endif if (plr[myplr].SpdList[7]._itype != -1 && plr[myplr].SpdList[7]._itype != 11) { - UseInvItem(myplr, 54); + UseInvItem(myplr, INVITEM_BELT_FIRST + 7); } return; #ifdef _DEBUG diff --git a/Source/inv.cpp b/Source/inv.cpp index 9ffbb043d..e1e245307 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -426,30 +426,30 @@ void DrawInvBelt() continue; } - InvDrawSlotBack(InvRect[i + 65].X + 64, InvRect[i + 65].Y + 159, 28, 28); + InvDrawSlotBack(InvRect[i + SLOTXY_BELT_FIRST].X + 64, InvRect[i + SLOTXY_BELT_FIRST].Y + 159, 28, 28); frame = plr[myplr].SpdList[i]._iCurs + CURSOR_FIRSTITEM; frame_width = InvItemWidth[frame]; - if (pcursinvitem == i + 47) { + if (pcursinvitem == i + INVITEM_BELT_FIRST) { colour = ICOL_WHITE; if (plr[myplr].SpdList[i]._iMagical) colour = ICOL_BLUE; if (!plr[myplr].SpdList[i]._iStatFlag) colour = ICOL_RED; - CelBlitOutline(colour, InvRect[i + 65].X + 64, InvRect[i + 65].Y + 159, pCursCels, frame, frame_width, 0, 8); + CelBlitOutline(colour, InvRect[i + SLOTXY_BELT_FIRST].X + 64, InvRect[i + SLOTXY_BELT_FIRST].Y + 159, pCursCels, frame, frame_width, 0, 8); } if (plr[myplr].SpdList[i]._iStatFlag) - CelClippedDraw(InvRect[i + 65].X + 64, InvRect[i + 65].Y + 159, pCursCels, frame, frame_width, 0, 8); + CelClippedDraw(InvRect[i + SLOTXY_BELT_FIRST].X + 64, InvRect[i + SLOTXY_BELT_FIRST].Y + 159, pCursCels, frame, frame_width, 0, 8); else - CelDrawLightRed(InvRect[i + 65].X + 64, InvRect[i + 65].Y + 159, pCursCels, frame, frame_width, 0, 8, 1); + CelDrawLightRed(InvRect[i + SLOTXY_BELT_FIRST].X + 64, InvRect[i + SLOTXY_BELT_FIRST].Y + 159, pCursCels, frame, frame_width, 0, 8, 1); if (AllItemsList[plr[myplr].SpdList[i].IDidx].iUsable && plr[myplr].SpdList[i]._iStatFlag && plr[myplr].SpdList[i]._itype != ITYPE_GOLD) { fi = i + 49; ff = fontframe[gbFontTransTbl[fi]]; - CPrintString(InvRect[i + 65].X + 64 + PitchTbl[InvRect[i + 65].Y + 159] - fontkern[ff] + 28, ff, 0); + CPrintString(InvRect[i + SLOTXY_BELT_FIRST].X + 64 + PitchTbl[InvRect[i + SLOTXY_BELT_FIRST].Y + 159] - fontkern[ff] + 28, ff, 0); } } } @@ -2078,10 +2078,10 @@ BOOL UseStaff() void StartGoldDrop() { initialDropGoldIndex = pcursinvitem; - if (pcursinvitem <= 46) - initialDropGoldValue = plr[myplr].InvList[pcursinvitem - 7]._ivalue; + if (pcursinvitem <= INVITEM_INV_LAST) + initialDropGoldValue = plr[myplr].InvList[pcursinvitem - INVITEM_INV_FIRST]._ivalue; else - initialDropGoldValue = plr[myplr].SpdList[pcursinvitem - 47]._ivalue; + initialDropGoldValue = plr[myplr].SpdList[pcursinvitem - INVITEM_BELT_FIRST]._ivalue; dropGoldFlag = TRUE; dropGoldValue = 0; if (talkflag) diff --git a/Source/multi.cpp b/Source/multi.cpp index dcf954101..97b024ff3 100644 --- a/Source/multi.cpp +++ b/Source/multi.cpp @@ -351,7 +351,7 @@ void multi_mon_seeds() sgdwGameLoops++; l = _rotr(sgdwGameLoops, 8); - for (i = 0; i < 200; i++) + for (i = 0; i < MAXMONSTERS; i++) monster[i]._mAISeed = l + i; } From 80840b4d69cbacbdb8cca51b7b46e740cfdfe8f5 Mon Sep 17 00:00:00 2001 From: galaxyhaxz Date: Sun, 20 Oct 2019 10:59:29 -0500 Subject: [PATCH 05/13] PlrHasItem: change pointer to reference --- Source/monster.cpp | 4 ++-- Source/objects.cpp | 2 +- Source/towners.cpp | 28 +++++++++++++--------------- Source/towners.h | 2 +- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/Source/monster.cpp b/Source/monster.cpp index a604c4141..0eeb17221 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -5432,14 +5432,14 @@ void TalktoMonster(int i) pnum = Monst->_menemy; Monst->_mmode = MM_TALK; if (Monst->_mAi == AI_SNOTSPIL || Monst->_mAi == AI_LACHDAN) { - if (QuestStatus(QTYPE_BOL) && quests[QTYPE_BOL]._qvar1 == 2 && PlrHasItem(pnum, IDI_BANNER, &itm)) { + if (QuestStatus(QTYPE_BOL) && quests[QTYPE_BOL]._qvar1 == 2 && PlrHasItem(pnum, IDI_BANNER, itm)) { RemoveInvItem(pnum, itm); quests[QTYPE_BOL]._qactive = 3; Monst->mtalkmsg = QUEST_BANNER12; Monst->_mgoal = MGOAL_INQUIRING; } if (QuestStatus(QTYPE_VEIL) && Monst->mtalkmsg >= QUEST_VEIL9) { - if (PlrHasItem(pnum, IDI_GLDNELIX, &itm)) { + if (PlrHasItem(pnum, IDI_GLDNELIX, itm)) { RemoveInvItem(pnum, itm); Monst->mtalkmsg = QUEST_VEIL11; Monst->_mgoal = MGOAL_INQUIRING; diff --git a/Source/objects.cpp b/Source/objects.cpp index 37a44e1d9..577496c49 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -2787,7 +2787,7 @@ void OperatePedistal(int pnum, int i) int iv; if (object[i]._oVar6 != 3) { - if (PlrHasItem(pnum, IDI_BLDSTONE, &iv)) { + if (PlrHasItem(pnum, IDI_BLDSTONE, iv)) { RemoveInvItem(pnum, iv); object[i]._oAnimFrame++; object[i]._oVar6++; diff --git a/Source/towners.cpp b/Source/towners.cpp index 968541e18..3ff09d6c9 100644 --- a/Source/towners.cpp +++ b/Source/towners.cpp @@ -571,13 +571,11 @@ void ProcessTowners() } } -ItemStruct *PlrHasItem(int pnum, int item, int *inv_item_num) +ItemStruct *PlrHasItem(int pnum, int item, int &i) { - int i; - - for (i = 0, *inv_item_num = i; i < plr[pnum]._pNumInv; i = *inv_item_num + 1, *inv_item_num = i) { - if (plr[pnum].InvList[*inv_item_num].IDidx == item) - return &plr[pnum].InvList[*inv_item_num]; + for (i = 0; i < plr[pnum]._pNumInv; i++) { + if (plr[pnum].InvList[i].IDidx == item) + return &plr[pnum].InvList[i]; } return NULL; @@ -666,7 +664,7 @@ void TalkToTowner(int p, int t) InitQTextMsg(QUEST_BANNER2); towner[t]._tMsgSaid = TRUE; } - if (quests[QTYPE_BOL]._qvar2 == 1 && PlrHasItem(p, IDI_BANNER, &i) != NULL && !towner[t]._tMsgSaid) { + if (quests[QTYPE_BOL]._qvar2 == 1 && PlrHasItem(p, IDI_BANNER, i) != NULL && !towner[t]._tMsgSaid) { quests[QTYPE_BOL]._qactive = 3; quests[QTYPE_BOL]._qvar1 = 3; RemoveInvItem(p, i); @@ -730,7 +728,7 @@ void TalkToTowner(int p, int t) InitQTextMsg(QUEST_INFRA5); towner[t]._tMsgSaid = TRUE; } - if (quests[QTYPE_INFRA]._qvar2 == 1 && PlrHasItem(p, IDI_ROCK, &i) != NULL && !towner[t]._tMsgSaid) { + if (quests[QTYPE_INFRA]._qvar2 == 1 && PlrHasItem(p, IDI_ROCK, i) != NULL && !towner[t]._tMsgSaid) { quests[QTYPE_INFRA]._qactive = 3; quests[QTYPE_INFRA]._qvar2 = 2; quests[QTYPE_INFRA]._qvar1 = 2; @@ -757,7 +755,7 @@ void TalkToTowner(int p, int t) towner[t]._tMsgSaid = TRUE; } } - if (quests[QTYPE_ANVIL]._qvar2 == 1 && PlrHasItem(p, IDI_ANVIL, &i) != NULL) { + if (quests[QTYPE_ANVIL]._qvar2 == 1 && PlrHasItem(p, IDI_ANVIL, i) != NULL) { if (!towner[t]._tMsgSaid) { quests[QTYPE_ANVIL]._qactive = 3; quests[QTYPE_ANVIL]._qvar2 = 2; @@ -779,7 +777,7 @@ void TalkToTowner(int p, int t) } } } else if (t == GetActiveTowner(TOWN_WITCH)) { - if (quests[QTYPE_BLKM]._qactive == 1 && PlrHasItem(p, IDI_FUNGALTM, &i) != NULL) { + if (quests[QTYPE_BLKM]._qactive == 1 && PlrHasItem(p, IDI_FUNGALTM, i) != NULL) { RemoveInvItem(p, i); quests[QTYPE_BLKM]._qactive = 2; quests[QTYPE_BLKM]._qlog = TRUE; @@ -790,7 +788,7 @@ void TalkToTowner(int p, int t) towner[t]._tMsgSaid = TRUE; } else if (quests[QTYPE_BLKM]._qactive == 2) { if (quests[QTYPE_BLKM]._qvar1 >= 2 && quests[QTYPE_BLKM]._qvar1 <= 4) { - if (PlrHasItem(p, IDI_MUSHROOM, &i) != NULL) { + if (PlrHasItem(p, IDI_MUSHROOM, i) != NULL) { RemoveInvItem(p, i); quests[QTYPE_BLKM]._qvar1 = 5; Qtalklist[TOWN_HEALER]._qblkm = QUEST_MUSH3; @@ -808,7 +806,7 @@ void TalkToTowner(int p, int t) towner[t]._tMsgSaid = TRUE; } } else { - Item = PlrHasItem(p, IDI_SPECELIX, &i); + Item = PlrHasItem(p, IDI_SPECELIX, i); if (Item != NULL) { towner[t]._tbtcnt = 150; towner[t]._tVar1 = p; @@ -816,7 +814,7 @@ void TalkToTowner(int p, int t) quests[QTYPE_BLKM]._qactive = 3; towner[t]._tMsgSaid = TRUE; AllItemsList[Item->IDidx].iUsable = TRUE; - } else if (PlrHasItem(p, IDI_BRAIN, &i) != NULL && quests[QTYPE_BLKM]._qvar2 != QUEST_MUSH11) { + } else if (PlrHasItem(p, IDI_BRAIN, i) != NULL && quests[QTYPE_BLKM]._qvar2 != QUEST_MUSH11) { towner[t]._tbtcnt = 150; towner[t]._tVar1 = p; quests[QTYPE_BLKM]._qvar2 = QUEST_MUSH11; @@ -866,7 +864,7 @@ void TalkToTowner(int p, int t) towner[t]._tMsgSaid = TRUE; } } - if (quests[QTYPE_BLKM]._qactive == 2 && quests[QTYPE_BLKM]._qmsg == QUEST_MUSH10 && PlrHasItem(p, IDI_BRAIN, &i) != NULL) { + if (quests[QTYPE_BLKM]._qactive == 2 && quests[QTYPE_BLKM]._qmsg == QUEST_MUSH10 && PlrHasItem(p, IDI_BRAIN, i) != NULL) { RemoveInvItem(p, i); SpawnQuestItem(IDI_SPECELIX, towner[t]._tx, towner[t]._ty + 1, 0, 0); InitQTextMsg(QUEST_MUSH4); @@ -889,7 +887,7 @@ void TalkToTowner(int p, int t) } } else if (t == GetActiveTowner(TOWN_STORY)) { if (gbMaxPlayers == 1) { - if (quests[QTYPE_VB]._qactive == 1 && PlrHasItem(p, IDI_LAZSTAFF, &i) != NULL) { + if (quests[QTYPE_VB]._qactive == 1 && PlrHasItem(p, IDI_LAZSTAFF, i) != NULL) { RemoveInvItem(p, i); quests[QTYPE_VB]._qvar1 = 2; towner[t]._tbtcnt = 150; diff --git a/Source/towners.h b/Source/towners.h index 310d84e3c..fccb6eb18 100644 --- a/Source/towners.h +++ b/Source/towners.h @@ -33,7 +33,7 @@ void TownWitch(); void TownBarMaid(); void TownCow(); void ProcessTowners(); -ItemStruct *PlrHasItem(int pnum, int item, int *i); +ItemStruct *PlrHasItem(int pnum, int item, int &i); void TownerTalk(int first, int t); void TalkToTowner(int p, int t); void CowSFX(int pnum); From e155a9423e2d7b54845b5b634928811844e9ff92 Mon Sep 17 00:00:00 2001 From: Robin Eklind Date: Fri, 18 Oct 2019 20:30:17 +0200 Subject: [PATCH 06/13] rename random to random_ to avoid collision with random in stdlib.h Fixes #1813. --- Source/drlg_l1.cpp | 76 +++++++++--------- Source/drlg_l2.cpp | 60 +++++++------- Source/drlg_l3.cpp | 122 ++++++++++++++-------------- Source/drlg_l4.cpp | 80 +++++++++--------- Source/effects.cpp | 4 +- Source/engine.cpp | 2 +- Source/engine.h | 2 +- Source/gendung.cpp | 12 +-- Source/inv.cpp | 6 +- Source/items.cpp | 110 ++++++++++++------------- Source/missiles.cpp | 112 +++++++++++++------------- Source/monster.cpp | 192 ++++++++++++++++++++++---------------------- Source/objects.cpp | 132 +++++++++++++++--------------- Source/palette.cpp | 2 +- Source/player.cpp | 30 +++---- Source/quests.cpp | 10 +-- Source/spells.cpp | 6 +- Source/stores.cpp | 2 +- Source/themes.cpp | 52 ++++++------ Source/town.cpp | 2 +- Source/towners.cpp | 8 +- 21 files changed, 511 insertions(+), 511 deletions(-) diff --git a/Source/drlg_l1.cpp b/Source/drlg_l1.cpp index 07c8655a7..ad87c7f06 100644 --- a/Source/drlg_l1.cpp +++ b/Source/drlg_l1.cpp @@ -270,11 +270,11 @@ static int DRLG_PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, in if (tmax - tmin == 0) numt = 1; else - numt = random(0, tmax - tmin) + tmin; + numt = random_(0, tmax - tmin) + tmin; for (i = 0; i < numt; i++) { - sx = random(0, DMAXX - sw); - sy = random(0, DMAXY - sh); + sx = random_(0, DMAXX - sw); + sy = random_(0, DMAXY - sh); abort = FALSE; found = 0; @@ -380,7 +380,7 @@ static void DRLG_L1Floor() for (j = 0; j < DMAXY; j++) { for (i = 0; i < DMAXX; i++) { if (L5dflags[i][j] == 0 && dungeon[i][j] == 13) { - rv = random(0, 3); + rv = random_(0, 3); if (rv == 1) dungeon[i][j] = 162; @@ -720,14 +720,14 @@ static void L5roomGen(int x, int y, int w, int h, int dir) int width, height, rx, ry, ry2; int cw, ch, cx1, cy1, cx2; - dirProb = random(0, 4); + dirProb = random_(0, 4); switch (dir == 1 ? dirProb != 0 : dirProb == 0) { case FALSE: num = 0; do { - cw = (random(0, 5) + 2) & 0xFFFFFFFE; - ch = (random(0, 5) + 2) & 0xFFFFFFFE; + cw = (random_(0, 5) + 2) & 0xFFFFFFFE; + ch = (random_(0, 5) + 2) & 0xFFFFFFFE; cy1 = h / 2 + y - ch / 2; cx1 = x - cw; ran = L5checkRoom(cx1 - 1, cy1 - 1, ch + 2, cw + 1); /// BUGFIX: swap args 3 and 4 ("ch+2" and "cw+1") @@ -748,8 +748,8 @@ static void L5roomGen(int x, int y, int w, int h, int dir) case TRUE: num = 0; do { - width = (random(0, 5) + 2) & 0xFFFFFFFE; - height = (random(0, 5) + 2) & 0xFFFFFFFE; + width = (random_(0, 5) + 2) & 0xFFFFFFFE; + height = (random_(0, 5) + 2) & 0xFFFFFFFE; rx = w / 2 + x - width / 2; ry = y - height; ran = L5checkRoom(rx - 1, ry - 1, width + 2, height + 1); @@ -775,13 +775,13 @@ static void L5firstRoom() int ys, ye, y; int xs, xe, x; - if (random(0, 2) == 0) { + if (random_(0, 2) == 0) { ys = 1; ye = DMAXY - 1; - VR1 = random(0, 2); - VR2 = random(0, 2); - VR3 = random(0, 2); + VR1 = random_(0, 2); + VR2 = random_(0, 2); + VR3 = random_(0, 2); if (VR1 + VR3 <= 1) VR2 = 1; @@ -820,9 +820,9 @@ static void L5firstRoom() xs = 1; xe = DMAXX - 1; - HR1 = random(0, 2); - HR2 = random(0, 2); - HR3 = random(0, 2); + HR1 = random_(0, 2); + HR2 = random_(0, 2); + HR3 = random_(0, 2); if (HR1 + HR3 <= 1) HR2 = 1; @@ -972,7 +972,7 @@ static void L5HorizWall(int i, int j, char p, int dx) int xx; char wt, dt; - switch (random(0, 4)) { + switch (random_(0, 4)) { case 0: case 1: dt = 2; @@ -993,7 +993,7 @@ static void L5HorizWall(int i, int j, char p, int dx) break; } - if (random(0, 6) == 5) + if (random_(0, 6) == 5) wt = 12; else wt = 26; @@ -1006,7 +1006,7 @@ static void L5HorizWall(int i, int j, char p, int dx) dungeon[i + xx][j] = dt; } - xx = random(0, dx - 1) + 1; + xx = random_(0, dx - 1) + 1; if (wt == 12) { dungeon[i + xx][j] = wt; @@ -1021,7 +1021,7 @@ static void L5VertWall(int i, int j, char p, int dy) int yy; char wt, dt; - switch (random(0, 4)) { + switch (random_(0, 4)) { case 0: case 1: dt = 1; @@ -1042,7 +1042,7 @@ static void L5VertWall(int i, int j, char p, int dy) break; } - if (random(0, 6) == 5) + if (random_(0, 6) == 5) wt = 11; else wt = 25; @@ -1055,7 +1055,7 @@ static void L5VertWall(int i, int j, char p, int dy) dungeon[i][j + yy] = dt; } - yy = random(0, dy - 1) + 1; + yy = random_(0, dy - 1) + 1; if (wt == 11) { dungeon[i][j + yy] = wt; @@ -1072,32 +1072,32 @@ static void L5AddWall() for (j = 0; j < DMAXY; j++) { for (i = 0; i < DMAXX; i++) { if (!L5dflags[i][j]) { - if (dungeon[i][j] == 3 && random(0, 100) < 100) { + if (dungeon[i][j] == 3 && random_(0, 100) < 100) { x = L5HWallOk(i, j); if (x != -1) L5HorizWall(i, j, 2, x); } - if (dungeon[i][j] == 3 && random(0, 100) < 100) { + if (dungeon[i][j] == 3 && random_(0, 100) < 100) { y = L5VWallOk(i, j); if (y != -1) L5VertWall(i, j, 1, y); } - if (dungeon[i][j] == 6 && random(0, 100) < 100) { + if (dungeon[i][j] == 6 && random_(0, 100) < 100) { x = L5HWallOk(i, j); if (x != -1) L5HorizWall(i, j, 4, x); } - if (dungeon[i][j] == 7 && random(0, 100) < 100) { + if (dungeon[i][j] == 7 && random_(0, 100) < 100) { y = L5VWallOk(i, j); if (y != -1) L5VertWall(i, j, 4, y); } - if (dungeon[i][j] == 2 && random(0, 100) < 100) { + if (dungeon[i][j] == 2 && random_(0, 100) < 100) { x = L5HWallOk(i, j); if (x != -1) L5HorizWall(i, j, 2, x); } - if (dungeon[i][j] == 1 && random(0, 100) < 100) { + if (dungeon[i][j] == 1 && random_(0, 100) < 100) { y = L5VWallOk(i, j); if (y != -1) L5VertWall(i, j, 1, y); @@ -1296,11 +1296,11 @@ static void DRLG_L5Subs() for (y = 0; y < DMAXY; y++) { for (x = 0; x < DMAXX; x++) { - if (!random(0, 4)) { + if (!random_(0, 4)) { BYTE c = L5BTYPES[dungeon[x][y]]; if (c && !L5dflags[x][y]) { - rv = random(0, 16); + rv = random_(0, 16); i = -1; while (rv >= 0) { @@ -1409,20 +1409,20 @@ static void L5FillChambers() if (setloadflag) { if (VR1 || VR2 || VR3) { c = 1; - if (!VR1 && VR2 && VR3 && random(0, 2)) + if (!VR1 && VR2 && VR3 && random_(0, 2)) c = 2; - if (VR1 && VR2 && !VR3 && random(0, 2)) + if (VR1 && VR2 && !VR3 && random_(0, 2)) c = 0; if (VR1 && !VR2 && VR3) { - if (random(0, 2)) + if (random_(0, 2)) c = 0; else c = 2; } if (VR1 && VR2 && VR3) - c = random(0, 3); + c = random_(0, 3); switch (c) { case 0: @@ -1437,20 +1437,20 @@ static void L5FillChambers() } } else { c = 1; - if (!HR1 && HR2 && HR3 && random(0, 2)) + if (!HR1 && HR2 && HR3 && random_(0, 2)) c = 2; - if (HR1 && HR2 && !HR3 && random(0, 2)) + if (HR1 && HR2 && !HR3 && random_(0, 2)) c = 0; if (HR1 && !HR2 && HR3) { - if (random(0, 2)) + if (random_(0, 2)) c = 0; else c = 2; } if (HR1 && HR2 && HR3) - c = random(0, 3); + c = random_(0, 3); switch (c) { case 0: diff --git a/Source/drlg_l2.cpp b/Source/drlg_l2.cpp index 20f2accd9..4dc79a77d 100644 --- a/Source/drlg_l2.cpp +++ b/Source/drlg_l2.cpp @@ -797,12 +797,12 @@ BOOL DRLG_L2PlaceMiniSet(BYTE *miniset, int tmin, int tmax, int cx, int cy, BOOL if (tmax - tmin == 0) { numt = 1; } else { - numt = random(0, tmax - tmin) + tmin; + numt = random_(0, tmax - tmin) + tmin; } for (i = 0; i < numt; i++) { - sx = random(0, DMAXX - sw); - sy = random(0, DMAXY - sh); + sx = random_(0, DMAXX - sw); + sy = random_(0, DMAXY - sh); found = FALSE; for (bailcnt = 0; !found && bailcnt < 200; bailcnt++) { found = TRUE; @@ -810,13 +810,13 @@ BOOL DRLG_L2PlaceMiniSet(BYTE *miniset, int tmin, int tmax, int cx, int cy, BOOL found = FALSE; } if (cx != -1 && sx >= cx - sw && sx <= cx + 12) { - sx = random(0, DMAXX - sw); - sy = random(0, DMAXY - sh); + sx = random_(0, DMAXX - sw); + sy = random_(0, DMAXY - sh); found = FALSE; } if (cy != -1 && sy >= cy - sh && sy <= cy + 12) { - sx = random(0, DMAXX - sw); - sy = random(0, DMAXY - sh); + sx = random_(0, DMAXX - sw); + sy = random_(0, DMAXY - sh); found = FALSE; } ii = 2; @@ -909,7 +909,7 @@ void DRLG_L2PlaceRndSet(BYTE *miniset, int rndper) } } } - if (found == TRUE && random(0, 100) < rndper) { + if (found == TRUE && random_(0, 100) < rndper) { for (yy = 0; yy < sh; yy++) { for (xx = 0; xx < sw; xx++) { if (miniset[kk] != 0) { @@ -930,10 +930,10 @@ void DRLG_L2Subs() for (y = 0; y < DMAXY; y++) { for (x = 0; x < DMAXX; x++) { - if ((x < nSx1 || x > nSx2) && (y < nSy1 || y > nSy2) && random(0, 4) == 0) { + if ((x < nSx1 || x > nSx2) && (y < nSy1 || y > nSy2) && random_(0, 4) == 0) { c = BTYPESL2[dungeon[x][y]]; if (c != 0) { - rv = random(0, 16); + rv = random_(0, 16); k = -1; while (rv >= 0) { k++; @@ -1181,16 +1181,16 @@ void CreateRoom(int nX1, int nY1, int nX2, int nY2, int nRDest, int nHDir, BOOL } if (nAw > Room_Max) { - nRw = random(0, Room_Max - Room_Min) + Room_Min; + nRw = random_(0, Room_Max - Room_Min) + Room_Min; } else if (nAw > Room_Min) { - nRw = random(0, nAw - Room_Min) + Room_Min; + nRw = random_(0, nAw - Room_Min) + Room_Min; } else { nRw = nAw; } if (nAh > Room_Max) { - nRh = random(0, Room_Max - Room_Min) + Room_Min; + nRh = random_(0, Room_Max - Room_Min) + Room_Min; } else if (nAh > Room_Min) { - nRh = random(0, nAh - Room_Min) + Room_Min; + nRh = random_(0, nAh - Room_Min) + Room_Min; } else { nRh = nAh; } @@ -1200,8 +1200,8 @@ void CreateRoom(int nX1, int nY1, int nX2, int nY2, int nRDest, int nHDir, BOOL nRh = nH; } - nRx1 = random(0, nX2 - nX1) + nX1; - nRy1 = random(0, nY2 - nY1) + nY1; + nRx1 = random_(0, nX2 - nX1) + nX1; + nRy1 = random_(0, nY2 - nY1) + nY1; nRx2 = nRw + nRx1; nRy2 = nRh + nRy1; if (nRx2 > nX2) { @@ -1251,32 +1251,32 @@ void CreateRoom(int nX1, int nY1, int nX2, int nY2, int nRDest, int nHDir, BOOL if (nRDest != 0) { if (nHDir == 1) { - nHx1 = random(0, nRx2 - nRx1 - 2) + nRx1 + 1; + nHx1 = random_(0, nRx2 - nRx1 - 2) + nRx1 + 1; nHy1 = nRy1; nHw = RoomList[nRDest].nRoomx2 - RoomList[nRDest].nRoomx1 - 2; - nHx2 = random(0, nHw) + RoomList[nRDest].nRoomx1 + 1; + nHx2 = random_(0, nHw) + RoomList[nRDest].nRoomx1 + 1; nHy2 = RoomList[nRDest].nRoomy2; } if (nHDir == 3) { - nHx1 = random(0, nRx2 - nRx1 - 2) + nRx1 + 1; + nHx1 = random_(0, nRx2 - nRx1 - 2) + nRx1 + 1; nHy1 = nRy2; nHw = RoomList[nRDest].nRoomx2 - RoomList[nRDest].nRoomx1 - 2; - nHx2 = random(0, nHw) + RoomList[nRDest].nRoomx1 + 1; + nHx2 = random_(0, nHw) + RoomList[nRDest].nRoomx1 + 1; nHy2 = RoomList[nRDest].nRoomy1; } if (nHDir == 2) { nHx1 = nRx2; - nHy1 = random(0, nRy2 - nRy1 - 2) + nRy1 + 1; + nHy1 = random_(0, nRy2 - nRy1 - 2) + nRy1 + 1; nHx2 = RoomList[nRDest].nRoomx1; nHh = RoomList[nRDest].nRoomy2 - RoomList[nRDest].nRoomy1 - 2; - nHy2 = random(0, nHh) + RoomList[nRDest].nRoomy1 + 1; + nHy2 = random_(0, nHh) + RoomList[nRDest].nRoomy1 + 1; } if (nHDir == 4) { nHx1 = nRx1; - nHy1 = random(0, nRy2 - nRy1 - 2) + nRy1 + 1; + nHy1 = random_(0, nRy2 - nRy1 - 2) + nRy1 + 1; nHx2 = RoomList[nRDest].nRoomx2; nHh = RoomList[nRDest].nRoomy2 - RoomList[nRDest].nRoomy1 - 2; - nHy2 = random(0, nHh) + RoomList[nRDest].nRoomy1 + 1; + nHy2 = random_(0, nHh) + RoomList[nRDest].nRoomy1 + 1; } AddHall(nHx1, nHy1, nHx2, nHy2, nHDir); } @@ -1380,8 +1380,8 @@ void ConnectHall(int nX1, int nY1, int nX2, int nY2, int nHd) BOOL fDoneflag, fInroom; fDoneflag = FALSE; - fMinusFlag = random(0, 100); - fPlusFlag = random(0, 100); + fMinusFlag = random_(0, 100); + fPlusFlag = random_(0, 100); nOrigX1 = nX1; nOrigY1 = nY1; CreateDoorType(nX1, nY1); @@ -1457,7 +1457,7 @@ void ConnectHall(int nX1, int nY1, int nX2, int nY2, int nHd) if (nRp > 30) { nRp = 30; } - if (random(0, 100) < nRp) { + if (random_(0, 100) < nRp) { if (nX2 <= nX1 || nX1 >= DMAXX) { nCurrd = 4; } else { @@ -1469,7 +1469,7 @@ void ConnectHall(int nX1, int nY1, int nX2, int nY2, int nHd) if (nRp > 80) { nRp = 80; } - if (random(0, 100) < nRp) { + if (random_(0, 100) < nRp) { if (nY2 <= nY1 || nY1 >= DMAXY) { nCurrd = 1; } else { @@ -1638,8 +1638,8 @@ BOOL DL2_FillVoids() to = 0; while (DL2_NumNoChar() > 700 && to < 100) { - xx = random(0, 38) + 1; - yy = random(0, 38) + 1; + xx = random_(0, 38) + 1; + yy = random_(0, 38) + 1; if (predungeon[xx][yy] != 35) { continue; } diff --git a/Source/drlg_l3.cpp b/Source/drlg_l3.cpp index 76656dbbc..ab7e8647c 100644 --- a/Source/drlg_l3.cpp +++ b/Source/drlg_l3.cpp @@ -109,18 +109,18 @@ static BOOL DRLG_L3FillRoom(int x1, int y1, int x2, int y2) } } for (j = y1; j <= y2; j++) { - if (random(0, 2) != 0) { + if (random_(0, 2) != 0) { dungeon[x1][j] = 1; } - if (random(0, 2) != 0) { + if (random_(0, 2) != 0) { dungeon[x2][j] = 1; } } for (i = x1; i <= x2; i++) { - if (random(0, 2) != 0) { + if (random_(0, 2) != 0) { dungeon[i][y1] = 1; } - if (random(0, 2) != 0) { + if (random_(0, 2) != 0) { dungeon[i][y2] = 1; } } @@ -133,20 +133,20 @@ static void DRLG_L3CreateBlock(int x, int y, int obs, int dir) int blksizex, blksizey, x1, y1, x2, y2; BOOL contflag; - blksizex = random(0, 2) + 3; - blksizey = random(0, 2) + 3; + blksizex = random_(0, 2) + 3; + blksizey = random_(0, 2) + 3; if (dir == 0) { y2 = y - 1; y1 = y2 - blksizey; if (blksizex < obs) { - x1 = random(0, blksizex) + x; + x1 = random_(0, blksizex) + x; } if (blksizex == obs) { x1 = x; } if (blksizex > obs) { - x1 = x - random(0, blksizex); + x1 = x - random_(0, blksizex); } x2 = blksizex + x1; } @@ -154,13 +154,13 @@ static void DRLG_L3CreateBlock(int x, int y, int obs, int dir) x2 = x - 1; x1 = x2 - blksizex; if (blksizey < obs) { - y1 = random(0, blksizey) + y; + y1 = random_(0, blksizey) + y; } if (blksizey == obs) { y1 = y; } if (blksizey > obs) { - y1 = y - random(0, blksizey); + y1 = y - random_(0, blksizey); } y2 = y1 + blksizey; } @@ -168,13 +168,13 @@ static void DRLG_L3CreateBlock(int x, int y, int obs, int dir) y1 = y + 1; y2 = y1 + blksizey; if (blksizex < obs) { - x1 = random(0, blksizex) + x; + x1 = random_(0, blksizex) + x; } if (blksizex == obs) { x1 = x; } if (blksizex > obs) { - x1 = x - random(0, blksizex); + x1 = x - random_(0, blksizex); } x2 = blksizex + x1; } @@ -182,19 +182,19 @@ static void DRLG_L3CreateBlock(int x, int y, int obs, int dir) x1 = x + 1; x2 = x1 + blksizex; if (blksizey < obs) { - y1 = random(0, blksizey) + y; + y1 = random_(0, blksizey) + y; } if (blksizey == obs) { y1 = y; } if (blksizey > obs) { - y1 = y - random(0, blksizey); + y1 = y - random_(0, blksizey); } y2 = y1 + blksizey; } if (DRLG_L3FillRoom(x1, y1, x2, y2) == TRUE) { - contflag = random(0, 4); + contflag = random_(0, 4); if (contflag && dir != 2) { DRLG_L3CreateBlock(x1, y1, blksizey, 0); } @@ -229,14 +229,14 @@ static void DRLG_L3FillDiags() 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) { - if (random(0, 2) == 0) { + if (random_(0, 2) == 0) { dungeon[i][j] = 1; } else { dungeon[i + 1][j + 1] = 1; } } if (v == 9) { - if (random(0, 2) == 0) { + if (random_(0, 2) == 0) { dungeon[i + 1][j] = 1; } else { dungeon[i][j + 1] = 1; @@ -275,9 +275,9 @@ static void DRLG_L3FillStraights() } xs++; } else { - if (xs > 3 && random(0, 2) != 0) { + if (xs > 3 && random_(0, 2) != 0) { for (k = xc; k < i; k++) { - rv = random(0, 2); + rv = random_(0, 2); dungeon[k][j] = rv; } } @@ -294,9 +294,9 @@ static void DRLG_L3FillStraights() } xs++; } else { - if (xs > 3 && random(0, 2) != 0) { + if (xs > 3 && random_(0, 2) != 0) { for (k = xc; k < i; k++) { - rv = random(0, 2); + rv = random_(0, 2); dungeon[k][j + 1] = rv; } } @@ -313,9 +313,9 @@ static void DRLG_L3FillStraights() } ys++; } else { - if (ys > 3 && random(0, 2) != 0) { + if (ys > 3 && random_(0, 2) != 0) { for (k = yc; k < j; k++) { - rv = random(0, 2); + rv = random_(0, 2); dungeon[i][k] = rv; } } @@ -332,9 +332,9 @@ static void DRLG_L3FillStraights() } ys++; } else { - if (ys > 3 && random(0, 2) != 0) { + if (ys > 3 && random_(0, 2) != 0) { for (k = yc; k < j; k++) { - rv = random(0, 2); + rv = random_(0, 2); dungeon[i + 1][k] = rv; } } @@ -379,7 +379,7 @@ static void DRLG_L3MakeMegas() 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); + rv = random_(0, 2); if (rv == 0) { v = 12; } else { @@ -387,7 +387,7 @@ static void DRLG_L3MakeMegas() } } if (v == 9) { - rv = random(0, 2); + rv = random_(0, 2); if (rv == 0) { v = 13; } else { @@ -424,8 +424,8 @@ static void DRLG_L3River() ry = 0; i = 0; while ((dungeon[rx][ry] < 25 || dungeon[rx][ry] > 28) && i < 100) { - rx = random(0, DMAXX); - ry = random(0, DMAXY); + rx = random_(0, DMAXX); + ry = random_(0, DMAXY); i++; while ((dungeon[rx][ry] < 25 || dungeon[rx][ry] > 28) && ry < DMAXY) { rx++; @@ -469,7 +469,7 @@ static void DRLG_L3River() px = rx; py = ry; if (dircheck == 0) { - dir = random(0, 4); + dir = random_(0, 4); } else { dir = (dir + 1) & 3; } @@ -493,10 +493,10 @@ static void DRLG_L3River() if (dungeon[rx][ry] == 7) { dircheck = 0; if (dir < 2) { - river[2][riveramt] = (BYTE)random(0, 2) + 17; + river[2][riveramt] = (BYTE)random_(0, 2) + 17; } if (dir > 1) { - river[2][riveramt] = (BYTE)random(0, 2) + 15; + river[2][riveramt] = (BYTE)random_(0, 2) + 15; } river[0][riveramt] = rx; river[1][riveramt] = ry; @@ -604,7 +604,7 @@ static void DRLG_L3River() lpcnt = 0; while (found == 0 && lpcnt < 30) { lpcnt++; - bridge = random(0, riveramt); + bridge = random_(0, riveramt); if ((river[2][bridge] == 15 || river[2][bridge] == 16) && dungeon[river[0][bridge]][river[1][bridge] - 1] == 7 && dungeon[river[0][bridge]][river[1][bridge] + 1] == 7) { @@ -789,7 +789,7 @@ static void DRLG_L3Pool() } else { found = TRUE; } - poolchance = random(0, 100); + poolchance = random_(0, 100); for (j = duny - totarea; j < duny + totarea; j++) { for (i = dunx - totarea; i < dunx + totarea; i++) { // BUGFIX: In the following swap the order to first do the @@ -843,25 +843,25 @@ static BOOL DRLG_L3PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, if (tmax - tmin == 0) { numt = 1; } else { - numt = random(0, tmax - tmin) + tmin; + numt = random_(0, tmax - tmin) + tmin; } for (i = 0; i < numt; i++) { - sx = random(0, DMAXX - sw); - sy = random(0, DMAXY - sh); + sx = random_(0, DMAXX - sw); + sy = random_(0, DMAXY - sh); found = FALSE; trys = 0; while (!found && trys < 200) { trys++; found = TRUE; if (cx != -1 && sx >= cx - sw && sx <= cx + 12) { - sx = random(0, DMAXX - sw); - sy = random(0, DMAXY - sh); + sx = random_(0, DMAXX - sw); + sy = random_(0, DMAXY - sh); found = FALSE; } if (cy != -1 && sy >= cy - sh && sy <= cy + 12) { - sx = random(0, DMAXX - sw); - sy = random(0, DMAXY - sh); + sx = random_(0, DMAXX - sw); + sy = random_(0, DMAXY - sh); found = FALSE; } ii = 2; @@ -953,7 +953,7 @@ static void DRLG_L3PlaceRndSet(const BYTE *miniset, int rndper) found = FALSE; } } - if (found == TRUE && random(0, 100) < rndper) { + if (found == TRUE && random_(0, 100) < rndper) { for (yy = 0; yy < sh; yy++) { for (xx = 0; xx < sw; xx++) { if (miniset[kk] != 0) { @@ -1142,7 +1142,7 @@ static void DRLG_L3Wood() 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) { + if (dungeon[i][j] == 10 && random_(0, 2) != 0) { x = i; while (dungeon[x][j] == 10) { x++; @@ -1151,7 +1151,7 @@ static void DRLG_L3Wood() if (x - i > 0) { dungeon[i][j] = 127; for (xx = i + 1; xx < x; xx++) { - if (random(0, 2) != 0) { + if (random_(0, 2) != 0) { dungeon[xx][j] = 126; } else { dungeon[xx][j] = 129; @@ -1160,7 +1160,7 @@ static void DRLG_L3Wood() dungeon[x][j] = 128; } } - if (dungeon[i][j] == 9 && random(0, 2) != 0) { + if (dungeon[i][j] == 9 && random_(0, 2) != 0) { y = j; while (dungeon[i][y] == 9) { y++; @@ -1169,7 +1169,7 @@ static void DRLG_L3Wood() if (y - j > 0) { dungeon[i][j] = 123; for (yy = j + 1; yy < y; yy++) { - if (random(0, 2) != 0) { + if (random_(0, 2) != 0) { dungeon[i][yy] = 121; } else { dungeon[i][yy] = 124; @@ -1178,7 +1178,7 @@ static void DRLG_L3Wood() dungeon[i][y] = 122; } } - if (dungeon[i][j] == 11 && dungeon[i + 1][j] == 10 && dungeon[i][j + 1] == 9 && random(0, 2) != 0) { + if (dungeon[i][j] == 11 && dungeon[i + 1][j] == 10 && dungeon[i][j + 1] == 9 && random_(0, 2) != 0) { dungeon[i][j] = 125; x = i + 1; while (dungeon[x][j] == 10) { @@ -1186,7 +1186,7 @@ static void DRLG_L3Wood() } x--; for (xx = i + 1; xx < x; xx++) { - if (random(0, 2) != 0) { + if (random_(0, 2) != 0) { dungeon[xx][j] = 126; } else { dungeon[xx][j] = 129; @@ -1199,7 +1199,7 @@ static void DRLG_L3Wood() } y--; for (yy = j + 1; yy < y; yy++) { - if (random(0, 2) != 0) { + if (random_(0, 2) != 0) { dungeon[i][yy] = 121; } else { dungeon[i][yy] = 124; @@ -1212,8 +1212,8 @@ static void DRLG_L3Wood() 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); + if (dungeon[i][j] == 7 && random_(0, 1) == 0 && SkipThemeRoom(i, j)) { + rt = random_(0, 2); if (rt == 0) { y1 = j; while (WoodVertU(i, y1)) { @@ -1233,13 +1233,13 @@ static void DRLG_L3Wood() skip = FALSE; } if (y2 - y1 > 1 && skip) { - rp = random(0, y2 - y1 - 1) + y1 + 1; + rp = random_(0, y2 - y1 - 1) + y1 + 1; for (y = y1; y <= y2; y++) { if (y == rp) { continue; } if (dungeon[i][y] == 7) { - if (random(0, 2) != 0) { + if (random_(0, 2) != 0) { dungeon[i][y] = 135; } else { dungeon[i][y] = 137; @@ -1285,13 +1285,13 @@ static void DRLG_L3Wood() skip = FALSE; } if (x2 - x1 > 1 && skip) { - rp = random(0, x2 - x1 - 1) + x1 + 1; + rp = random_(0, x2 - x1 - 1) + x1 + 1; for (x = x1; x <= x2; x++) { if (x == rp) { continue; } if (dungeon[x][j] == 7) { - if (random(0, 2) != 0) { + if (random_(0, 2) != 0) { dungeon[x][j] = 134; } else { dungeon[x][j] = 136; @@ -1333,8 +1333,8 @@ BOOL DRLG_L3Anvil() sw = L3ANVIL[0]; sh = L3ANVIL[1]; - sx = random(0, DMAXX - sw); - sy = random(0, DMAXY - sh); + sx = random_(0, DMAXX - sw); + sy = random_(0, DMAXY - sh); found = FALSE; trys = 0; @@ -1483,8 +1483,8 @@ static void DRLG_L3(int entry) do { do { InitL3Dungeon(); - x1 = random(0, 20) + 10; - y1 = random(0, 20) + 10; + x1 = random_(0, 20) + 10; + y1 = random_(0, 20) + 10; x2 = x1 + 2; y2 = y1 + 2; DRLG_L3FillRoom(x1, y1, x2, y2); @@ -1493,8 +1493,8 @@ static void DRLG_L3(int entry) DRLG_L3CreateBlock(x1, y2, 2, 2); DRLG_L3CreateBlock(x1, y1, 2, 3); if (QuestStatus(QTYPE_ANVIL)) { - x1 = random(0, 10) + 10; - y1 = random(0, 10) + 10; + x1 = random_(0, 10) + 10; + y1 = random_(0, 10) + 10; x2 = x1 + 12; y2 = y1 + 12; DRLG_L3FloorArea(x1, y1, x2, y2); diff --git a/Source/drlg_l4.cpp b/Source/drlg_l4.cpp index e78bb7efa..68a91dcfc 100644 --- a/Source/drlg_l4.cpp +++ b/Source/drlg_l4.cpp @@ -533,7 +533,7 @@ static void L4HorizWall(int i, int j, int dx) dungeon[i + dx][j] = 29; } - xx = random(0, dx - 3) + 1; + xx = random_(0, dx - 3) + 1; dungeon[i + xx][j] = 57; dungeon[i + xx + 2][j] = 56; dungeon[i + xx + 1][j] = 60; @@ -580,7 +580,7 @@ static void L4VertWall(int i, int j, int dy) dungeon[i][j + dy] = 29; } - yy = random(0, dy - 3) + 1; + yy = random_(0, dy - 3) + 1; dungeon[i][j + yy] = 53; dungeon[i][j + yy + 2] = 52; dungeon[i][j + yy + 1] = 6; @@ -602,91 +602,91 @@ static void L4AddWall() if (dflags[i][j] != 0) { continue; } - if (dungeon[i][j] == 10 && random(0, 100) < 100) { + if (dungeon[i][j] == 10 && random_(0, 100) < 100) { x = L4HWallOk(i, j); if (x != -1) { L4HorizWall(i, j, x); } } - if (dungeon[i][j] == 12 && random(0, 100) < 100) { + if (dungeon[i][j] == 12 && random_(0, 100) < 100) { x = L4HWallOk(i, j); if (x != -1) { L4HorizWall(i, j, x); } } - if (dungeon[i][j] == 13 && random(0, 100) < 100) { + if (dungeon[i][j] == 13 && random_(0, 100) < 100) { x = L4HWallOk(i, j); if (x != -1) { L4HorizWall(i, j, x); } } - if (dungeon[i][j] == 15 && random(0, 100) < 100) { + if (dungeon[i][j] == 15 && random_(0, 100) < 100) { x = L4HWallOk(i, j); if (x != -1) { L4HorizWall(i, j, x); } } - if (dungeon[i][j] == 16 && random(0, 100) < 100) { + if (dungeon[i][j] == 16 && random_(0, 100) < 100) { x = L4HWallOk(i, j); if (x != -1) { L4HorizWall(i, j, x); } } - if (dungeon[i][j] == 21 && random(0, 100) < 100) { + if (dungeon[i][j] == 21 && random_(0, 100) < 100) { x = L4HWallOk(i, j); if (x != -1) { L4HorizWall(i, j, x); } } - if (dungeon[i][j] == 22 && random(0, 100) < 100) { + if (dungeon[i][j] == 22 && random_(0, 100) < 100) { x = L4HWallOk(i, j); if (x != -1) { L4HorizWall(i, j, x); } } - if (dungeon[i][j] == 8 && random(0, 100) < 100) { + if (dungeon[i][j] == 8 && random_(0, 100) < 100) { y = L4VWallOk(i, j); if (y != -1) { L4VertWall(i, j, y); } } - if (dungeon[i][j] == 9 && random(0, 100) < 100) { + if (dungeon[i][j] == 9 && random_(0, 100) < 100) { y = L4VWallOk(i, j); if (y != -1) { L4VertWall(i, j, y); } } - if (dungeon[i][j] == 11 && random(0, 100) < 100) { + if (dungeon[i][j] == 11 && random_(0, 100) < 100) { y = L4VWallOk(i, j); if (y != -1) { L4VertWall(i, j, y); } } - if (dungeon[i][j] == 14 && random(0, 100) < 100) { + if (dungeon[i][j] == 14 && random_(0, 100) < 100) { y = L4VWallOk(i, j); if (y != -1) { L4VertWall(i, j, y); } } - if (dungeon[i][j] == 15 && random(0, 100) < 100) { + if (dungeon[i][j] == 15 && random_(0, 100) < 100) { y = L4VWallOk(i, j); if (y != -1) { L4VertWall(i, j, y); } } - if (dungeon[i][j] == 16 && random(0, 100) < 100) { + if (dungeon[i][j] == 16 && random_(0, 100) < 100) { y = L4VWallOk(i, j); if (y != -1) { L4VertWall(i, j, y); } } - if (dungeon[i][j] == 21 && random(0, 100) < 100) { + if (dungeon[i][j] == 21 && random_(0, 100) < 100) { y = L4VWallOk(i, j); if (y != -1) { L4VertWall(i, j, y); } } - if (dungeon[i][j] == 23 && random(0, 100) < 100) { + if (dungeon[i][j] == 23 && random_(0, 100) < 100) { y = L4VWallOk(i, j); if (y != -1) { L4VertWall(i, j, y); @@ -1049,10 +1049,10 @@ static void DRLG_L4Subs() for (y = 0; y < DMAXY; y++) { for (x = 0; x < DMAXX; x++) { - if (random(0, 3) == 0) { + if (random_(0, 3) == 0) { c = L4BTYPES[dungeon[x][y]]; if (c != 0 && dflags[x][y] == 0) { - rv = random(0, 16); + rv = random_(0, 16); i = -1; while (rv >= 0) { i++; @@ -1070,9 +1070,9 @@ static void DRLG_L4Subs() } for (y = 0; y < DMAXY; y++) { for (x = 0; x < DMAXX; x++) { - if (random(0, 10) == 0) { + if (random_(0, 10) == 0) { if (L4BTYPES[dungeon[x][y]] == 6 && dflags[x][y] == 0) { - dungeon[x][y] = random(0, 3) + 95; + dungeon[x][y] = random_(0, 3) + 95; } } } @@ -1146,7 +1146,7 @@ static void uShape() } } - rv = random(0, 19) + 1; + rv = random_(0, 19) + 1; do { if (hallok[rv]) { for (i = 19; i >= 0; i--) { @@ -1183,7 +1183,7 @@ static void uShape() } } - rv = random(0, 19) + 1; + rv = random_(0, 19) + 1; do { if (hallok[rv]) { for (j = 19; j >= 0; j--) { @@ -1262,14 +1262,14 @@ static void L4roomGen(int x, int y, int w, int h, int dir) int width, height, rx, ry, ry2; int cw, ch, cx1, cy1, cx2; - int dirProb = random(0, 4); + int dirProb = random_(0, 4); switch (dir == 1 ? dirProb != 0 : dirProb == 0) { case FALSE: num = 0; do { - cw = (random(0, 5) + 2) & ~1; - ch = (random(0, 5) + 2) & ~1; + cw = (random_(0, 5) + 2) & ~1; + ch = (random_(0, 5) + 2) & ~1; cy1 = h / 2 + y - ch / 2; cx1 = x - cw; ran = L4checkRoom(cx1 - 1, cy1 - 1, ch + 2, cw + 1); /// BUGFIX: swap args 3 and 4 ("ch+2" and "cw+1") @@ -1290,8 +1290,8 @@ static void L4roomGen(int x, int y, int w, int h, int dir) case TRUE: num = 0; do { - width = (random(0, 5) + 2) & ~1; - height = (random(0, 5) + 2) & ~1; + width = (random_(0, 5) + 2) & ~1; + height = (random_(0, 5) + 2) & ~1; rx = w / 2 + x - width / 2; ry = y - height; ran = L4checkRoom(rx - 1, ry - 1, width + 2, height + 1); @@ -1325,8 +1325,8 @@ static void L4firstRoom() w = 11; h = 11; } else { - w = random(0, 5) + 2; - h = random(0, 5) + 2; + w = random_(0, 5) + 2; + h = random_(0, 5) + 2; } } else { w = 14; @@ -1335,7 +1335,7 @@ static void L4firstRoom() xmin = (20 - w) >> 1; xmax = 19 - w; - rndx = random(0, xmax - xmin + 1) + xmin; + rndx = random_(0, xmax - xmin + 1) + xmin; if (rndx + w > 19) { x = 19 - w + 1; } else { @@ -1343,7 +1343,7 @@ static void L4firstRoom() } ymin = (20 - h) >> 1; ymax = 19 - h; - rndy = random(0, ymax - ymin + 1) + ymin; + rndy = random_(0, ymax - ymin + 1) + ymin; if (rndy + h > 19) { y = 19 - h + 1; } else { @@ -1367,7 +1367,7 @@ static void L4firstRoom() } L4drawRoom(x, y, w, h); - L4roomGen(x, y, w, h, random(0, 2)); + L4roomGen(x, y, w, h, random_(0, 2)); } void L4SaveQuads() @@ -1462,12 +1462,12 @@ static BOOL DRLG_L4PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, if (tmax - tmin == 0) { numt = 1; } else { - numt = random(0, tmax - tmin) + tmin; + numt = random_(0, tmax - tmin) + tmin; } for (i = 0; i < numt; i++) { - sx = random(0, DMAXX - sw); - sy = random(0, DMAXY - sh); + sx = random_(0, DMAXX - sw); + sy = random_(0, DMAXY - sh); found = FALSE; for (bailcnt = 0; !found && bailcnt < 200; bailcnt++) { found = TRUE; @@ -1475,13 +1475,13 @@ static BOOL DRLG_L4PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, found = FALSE; } if (cx != -1 && sx >= cx - sw && sx <= cx + 12) { - sx = random(0, DMAXX - sw); - sy = random(0, DMAXY - sh); + sx = random_(0, DMAXX - sw); + sy = random_(0, DMAXY - sh); found = FALSE; } if (cy != -1 && sy >= cy - sh && sy <= cy + 12) { - sx = random(0, DMAXX - sw); - sy = random(0, DMAXY - sh); + sx = random_(0, DMAXX - sw); + sy = random_(0, DMAXY - sh); found = FALSE; } ii = 2; diff --git a/Source/effects.cpp b/Source/effects.cpp index 0c2ce43bf..c9f6f1e3f 100644 --- a/Source/effects.cpp +++ b/Source/effects.cpp @@ -981,7 +981,7 @@ void PlayEffect(int i, int mode) return; } - sndIdx = random(164, 2); + sndIdx = random_(164, 2); if (!gbSndInited || !gbSoundOn || gbBufferMsgs) { return; } @@ -1125,7 +1125,7 @@ int RndSFX(int psfx) #endif else return psfx; - return psfx + random(165, nRand); + return psfx + random_(165, nRand); } void PlaySfxLoc(int psfx, int x, int y) diff --git a/Source/engine.cpp b/Source/engine.cpp index f7699c2d6..bca987670 100644 --- a/Source/engine.cpp +++ b/Source/engine.cpp @@ -2356,7 +2356,7 @@ int GetRndSeed() return abs(sglGameSeed); } -int random(BYTE idx, int v) +int random_(BYTE idx, int v) { if (v <= 0) return 0; diff --git a/Source/engine.h b/Source/engine.h index c7bd94e85..fb62860c5 100644 --- a/Source/engine.h +++ b/Source/engine.h @@ -41,7 +41,7 @@ void DrawLine(int x0, int y0, int x1, int y1, BYTE col); int GetDirection(int x1, int y1, int x2, int y2); void SetRndSeed(int s); int GetRndSeed(); -int random(BYTE idx, int v); +int random_(BYTE idx, int v); void engine_debug_trap(BOOL show_cursor); BYTE *DiabloAllocPtr(DWORD dwBytes); void mem_free_dbg(void *p); diff --git a/Source/gendung.cpp b/Source/gendung.cpp index 04d1bb1ea..3ca59f03f 100644 --- a/Source/gendung.cpp +++ b/Source/gendung.cpp @@ -838,7 +838,7 @@ void DRLG_CreateThemeRoom(int themeIndex) } if (leveltype == DTYPE_CATACOMBS) { - switch (random(0, 2)) { + switch (random_(0, 2)) { case 0: dungeon[themeLoc[themeIndex].x + themeLoc[themeIndex].width - 1][themeLoc[themeIndex].y + themeLoc[themeIndex].height / 2] = 4; break; @@ -848,7 +848,7 @@ void DRLG_CreateThemeRoom(int themeIndex) } } if (leveltype == DTYPE_CAVES) { - switch (random(0, 2)) { + switch (random_(0, 2)) { case 0: dungeon[themeLoc[themeIndex].x + themeLoc[themeIndex].width - 1][themeLoc[themeIndex].y + themeLoc[themeIndex].height / 2] = 147; break; @@ -858,7 +858,7 @@ void DRLG_CreateThemeRoom(int themeIndex) } } if (leveltype == DTYPE_HELL) { - switch (random(0, 2)) { + switch (random_(0, 2)) { case 0: dungeon[themeLoc[themeIndex].x + themeLoc[themeIndex].width - 1][themeLoc[themeIndex].y + themeLoc[themeIndex].height / 2 - 1] = 53; dungeon[themeLoc[themeIndex].x + themeLoc[themeIndex].width - 1][themeLoc[themeIndex].y + themeLoc[themeIndex].height / 2] = 6; @@ -886,16 +886,16 @@ void DRLG_PlaceThemeRooms(int minSize, int maxSize, int floor, int freq, int rnd memset(themeLoc, 0, sizeof(*themeLoc)); for (j = 0; j < DMAXY; j++) { for (i = 0; i < DMAXX; i++) { - if (dungeon[i][j] == floor && !random(0, freq) && DRLG_WillThemeRoomFit(floor, i, j, minSize, maxSize, &themeW, &themeH)) { + if (dungeon[i][j] == floor && !random_(0, freq) && DRLG_WillThemeRoomFit(floor, i, j, minSize, maxSize, &themeW, &themeH)) { if (rndSize) { min = minSize - 2; max = maxSize - 2; - rv2 = min + random(0, random(0, themeW - min + 1)); + rv2 = min + random_(0, random_(0, themeW - min + 1)); if (rv2 >= min && rv2 <= max) themeW = rv2; else themeW = min; - rv2 = min + random(0, random(0, themeH - min + 1)); + rv2 = min + random_(0, random_(0, themeH - min + 1)); if (rv2 >= min && rv2 <= max) themeH = rv2; else diff --git a/Source/inv.cpp b/Source/inv.cpp index e1e245307..f44644669 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -1621,12 +1621,12 @@ void AutoGetItem(int pnum, int ii) } else { if (pnum == myplr) { if (plr[pnum]._pClass == PC_WARRIOR) { - PlaySFX(random(0, 3) + PS_WARR14); + PlaySFX(random_(0, 3) + PS_WARR14); #ifndef SPAWN } else if (plr[pnum]._pClass == PC_ROGUE) { - PlaySFX(random(0, 3) + PS_ROGUE14); + PlaySFX(random_(0, 3) + PS_ROGUE14); } else if (plr[pnum]._pClass == PC_SORCERER) { - PlaySFX(random(0, 3) + PS_MAGE14); + PlaySFX(random_(0, 3) + PS_MAGE14); #endif } } diff --git a/Source/items.cpp b/Source/items.cpp index 9c9cd3b51..e52b97d37 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -218,23 +218,23 @@ void AddInitItems() { int x, y, i, j, rnd; - rnd = random(11, 3) + 3; + rnd = random_(11, 3) + 3; for (j = 0; j < rnd; j++) { i = itemavail[0]; itemavail[0] = itemavail[MAXITEMS - numitems - 1]; itemactive[numitems] = i; - x = random(12, 80) + 16; - y = random(12, 80) + 16; + x = random_(12, 80) + 16; + y = random_(12, 80) + 16; while (!ItemPlace(x, y)) { - x = random(12, 80) + 16; - y = random(12, 80) + 16; + x = random_(12, 80) + 16; + y = random_(12, 80) + 16; } item[i]._ix = x; item[i]._iy = y; dItem[x][y] = i + 1; item[i]._iSeed = GetRndSeed(); SetRndSeed(item[i]._iSeed); - if (random(12, 2)) + if (random_(12, 2)) GetItemAttrs(i, IDI_HEAL, currlevel); else GetItemAttrs(i, IDI_MANA, currlevel); @@ -1017,7 +1017,7 @@ BOOL GetItemSpace(int x, int y, char inum) } } - rs = random(13, 15) + 1; + rs = random_(13, 15) + 1; if (!savail) return FALSE; @@ -1111,7 +1111,7 @@ void GetBookSpell(int i, int lvl) if (lvl == 0) lvl = 1; - rv = random(14, MAX_SPELLS) + 1; + rv = random_(14, MAX_SPELLS) + 1; #ifdef SPAWN if (lvl > 5) lvl = 5; @@ -1154,7 +1154,7 @@ void GetStaffPower(int i, int lvl, int bs, BOOL onlygood) BOOL addok; int tmp; - tmp = random(15, 10); + tmp = random_(15, 10); preidx = -1; if (tmp == 0 || onlygood) { nl = 0; @@ -1174,7 +1174,7 @@ void GetStaffPower(int i, int lvl, int bs, BOOL onlygood) } } if (nl != 0) { - preidx = l[random(16, nl)]; + preidx = l[random_(16, nl)]; sprintf(istr, "%s %s", PL_Prefix[preidx].PLName, item[i]._iIName); strcpy(item[i]._iIName, istr); item[i]._iMagical = ITEM_QUALITY_MAGIC; @@ -1208,13 +1208,13 @@ void GetStaffSpell(int i, int lvl, BOOL onlygood) int l, rv, s, minc, maxc, v, bs; char istr[64]; - if (!random(17, 4)) { + if (!random_(17, 4)) { GetItemPower(i, lvl >> 1, lvl, 256, onlygood); } else { l = lvl >> 1; if (l == 0) l = 1; - rv = random(18, MAX_SPELLS) + 1; + rv = random_(18, MAX_SPELLS) + 1; #ifdef SPAWN if (lvl > 10) lvl = 10; @@ -1242,7 +1242,7 @@ void GetStaffSpell(int i, int lvl, BOOL onlygood) minc = spelldata[bs].sStaffMin; maxc = spelldata[bs].sStaffMax - minc + 1; item[i]._iSpell = bs; - item[i]._iCharges = minc + random(19, maxc); + item[i]._iCharges = minc + random_(19, maxc); item[i]._iMaxCharges = item[i]._iCharges; item[i]._iMinMag = spelldata[bs].sMinInt; @@ -1265,7 +1265,7 @@ void GetItemAttrs(int i, int idata, int lvl) item[i]._iClass = AllItemsList[idata].iClass; item[i]._iMinDam = AllItemsList[idata].iMinDam; item[i]._iMaxDam = AllItemsList[idata].iMaxDam; - item[i]._iAC = AllItemsList[idata].iMinAC + random(20, AllItemsList[idata].iMaxAC - AllItemsList[idata].iMinAC + 1); + item[i]._iAC = AllItemsList[idata].iMinAC + random_(20, AllItemsList[idata].iMaxAC - AllItemsList[idata].iMinAC + 1); item[i]._iFlags = AllItemsList[idata].iFlags; item[i]._iMiscId = AllItemsList[idata].iMiscId; item[i]._iSpell = AllItemsList[idata].iSpell; @@ -1314,11 +1314,11 @@ void GetItemAttrs(int i, int idata, int lvl) if (item[i]._itype == ITYPE_GOLD) { if (gnDifficulty == DIFF_NORMAL) - rndv = 5 * currlevel + random(21, 10 * currlevel); + rndv = 5 * currlevel + random_(21, 10 * currlevel); if (gnDifficulty == DIFF_NIGHTMARE) - rndv = 5 * (currlevel + 16) + random(21, 10 * (currlevel + 16)); + rndv = 5 * (currlevel + 16) + random_(21, 10 * (currlevel + 16)); if (gnDifficulty == DIFF_HELL) - rndv = 5 * (currlevel + 32) + random(21, 10 * (currlevel + 32)); + rndv = 5 * (currlevel + 32) + random_(21, 10 * (currlevel + 32)); if (leveltype == DTYPE_HELL) rndv += rndv >> 3; @@ -1336,7 +1336,7 @@ void GetItemAttrs(int i, int idata, int lvl) int RndPL(int param1, int param2) { - return param1 + random(22, param2 - param1 + 1); + return param1 + random_(22, param2 - param1 + 1); } int PLVal(int pv, int p1, int p2, int minv, int maxv) @@ -1664,10 +1664,10 @@ void GetItemPower(int i, int minlvl, int maxlvl, int flgs, BOOL onlygood) char istr[128]; BYTE goe; - pre = random(23, 4); - post = random(23, 3); + pre = random_(23, 4); + post = random_(23, 3); if (pre != 0 && post == 0) { - if (random(23, 2)) + if (random_(23, 2)) post = 1; else pre = 0; @@ -1675,7 +1675,7 @@ void GetItemPower(int i, int minlvl, int maxlvl, int flgs, BOOL onlygood) preidx = -1; sufidx = -1; goe = 0; - if (!onlygood && random(0, 3)) + if (!onlygood && random_(0, 3)) onlygood = TRUE; if (!pre) { nt = 0; @@ -1692,7 +1692,7 @@ void GetItemPower(int i, int minlvl, int maxlvl, int flgs, BOOL onlygood) } } if (nt) { - preidx = l[random(23, nt)]; + preidx = l[random_(23, nt)]; sprintf(istr, "%s %s", PL_Prefix[preidx].PLName, item[i]._iIName); strcpy(item[i]._iIName, istr); item[i]._iMagical = ITEM_QUALITY_MAGIC; @@ -1720,7 +1720,7 @@ void GetItemPower(int i, int minlvl, int maxlvl, int flgs, BOOL onlygood) } } if (nl) { - sufidx = l[random(23, nl)]; + sufidx = l[random_(23, nl)]; sprintf(istr, "%s of %s", item[i]._iIName, PL_Suffix[sufidx].PLName); strcpy(item[i]._iIName, istr); item[i]._iMagical = ITEM_QUALITY_MAGIC; @@ -1819,10 +1819,10 @@ int RndItem(int m) if (monster[m].MData->mTreasure & 0x4000) return 0; - if (random(24, 100) > 40) + if (random_(24, 100) > 40) return 0; - if (random(24, 100) > 25) + if (random_(24, 100) > 25) return 1; ri = 0; @@ -1841,7 +1841,7 @@ int RndItem(int m) ri--; } - return ril[random(24, ri)] + 1; + return ril[random_(24, ri)] + 1; } int RndUItem(int m) @@ -1883,7 +1883,7 @@ int RndUItem(int m) } } - return ril[random(25, ri)]; + return ril[random_(25, ri)]; } int RndAllItems() @@ -1891,7 +1891,7 @@ int RndAllItems() int i, ri; int ril[512]; - if (random(26, 100) > 25) + if (random_(26, 100) > 25) return 0; ri = 0; @@ -1906,7 +1906,7 @@ int RndAllItems() ri--; } - return ril[random(26, ri)]; + return ril[random_(26, ri)]; } int RndTypeItems(int itype, int imid) @@ -1932,7 +1932,7 @@ int RndTypeItems(int itype, int imid) } } - return ril[random(27, ri)]; + return ril[random_(27, ri)]; } int CheckUnique(int i, int lvl, int uper, BOOL recreate) @@ -1940,7 +1940,7 @@ int CheckUnique(int i, int lvl, int uper, BOOL recreate) int j, idata, numu; BOOLEAN uok[128]; - if (random(28, 100) > uper) + if (random_(28, 100) > uper) return -1; numu = 0; @@ -1957,7 +1957,7 @@ int CheckUnique(int i, int lvl, int uper, BOOL recreate) if (!numu) return -1; - random(29, 10); + random_(29, 10); idata = 0; while (numu > 0) { if (uok[idata]) @@ -2025,7 +2025,7 @@ void SpawnUnique(int uid, int x, int y) void ItemRndDur(int ii) { if (item[ii]._iDurability && item[ii]._iDurability != DUR_INDESTRUCTIBLE) - item[ii]._iDurability = random(0, item[ii]._iMaxDur >> 1) + (item[ii]._iMaxDur >> 2) + 1; + item[ii]._iDurability = random_(0, item[ii]._iMaxDur >> 1) + (item[ii]._iMaxDur >> 2) + 1; } void SetupAllItems(int ii, int idx, int iseed, int lvl, int uper, int onlygood, BOOL recreate, BOOL pregen) @@ -2049,7 +2049,7 @@ void SetupAllItems(int ii, int idx, int iseed, int lvl, int uper, int onlygood, if (item[ii]._iMiscId != IMISC_UNIQUE) { iblvl = -1; - if (random(32, 100) > 10 && random(33, 100) > lvl || (iblvl = lvl, lvl == -1)) { + if (random_(32, 100) > 10 && random_(33, 100) > lvl || (iblvl = lvl, lvl == -1)) { if (item[ii]._iMiscId != IMISC_STAFF || (iblvl = lvl, lvl == -1)) { if (item[ii]._iMiscId != IMISC_RING || (iblvl = lvl, lvl == -1)) { @@ -2176,12 +2176,12 @@ void SetupAllUseful(int ii, int iseed, int lvl) item[ii]._iSeed = iseed; SetRndSeed(iseed); - if (random(34, 2)) + if (random_(34, 2)) idx = IDI_HEAL; else idx = IDI_MANA; - if (lvl > 1 && !random(34, 3)) + if (lvl > 1 && !random_(34, 3)) idx = IDI_PORTAL; GetItemAttrs(ii, idx, lvl); @@ -2315,8 +2315,8 @@ void SpawnQuestItem(int itemid, int x, int y, int randarea, int selflag) tries++; if (tries > 1000 && randarea > 1) randarea--; - x = random(0, MAXDUNX); - y = random(0, MAXDUNY); + x = random_(0, MAXDUNX); + y = random_(0, MAXDUNY); failed = FALSE; for (i = 0; i < randarea && !failed; i++) { for (j = 0; j < randarea && !failed; j++) { @@ -2548,7 +2548,7 @@ void RepairItem(ItemStruct *i, int lvl) rep = 0; do { - rep += lvl + random(37, lvl); + rep += lvl + random_(37, lvl); d = i->_iMaxDur / (lvl + 9); if (d < 1) d = 1; @@ -2578,7 +2578,7 @@ void DoRecharge(int pnum, int cii) } if (pi->_itype == ITYPE_STAFF && pi->_iSpell) { r = spelldata[pi->_iSpell].sBookLvl; - r = random(38, p->_pLevel / r) + 1; + r = random_(38, p->_pLevel / r) + 1; RechargeItem(pi, r); CalcPlrInv(pnum, TRUE); } @@ -3147,7 +3147,7 @@ void UseItem(int p, int Mid, int spl) case IMISC_HEAL: case IMISC_HEAL_1C: j = plr[p]._pMaxHP >> 8; - l = ((j >> 1) + random(39, j)) << 6; + l = ((j >> 1) + random_(39, j)) << 6; if (plr[p]._pClass == PC_WARRIOR) l *= 2; if (plr[p]._pClass == PC_ROGUE) @@ -3167,7 +3167,7 @@ void UseItem(int p, int Mid, int spl) break; case IMISC_MANA: j = plr[p]._pMaxMana >> 8; - l = ((j >> 1) + random(40, j)) << 6; + l = ((j >> 1) + random_(40, j)) << 6; if (plr[p]._pClass == PC_SORCERER) l *= 2; if (plr[p]._pClass == PC_ROGUE) @@ -3203,7 +3203,7 @@ void UseItem(int p, int Mid, int spl) break; case IMISC_REJUV: j = plr[p]._pMaxHP >> 8; - l = ((j >> 1) + random(39, j)) << 6; + l = ((j >> 1) + random_(39, j)) << 6; if (plr[p]._pClass == PC_WARRIOR) l *= 2; if (plr[p]._pClass == PC_ROGUE) @@ -3216,7 +3216,7 @@ void UseItem(int p, int Mid, int spl) plr[p]._pHPBase = plr[p]._pMaxHPBase; drawhpflag = TRUE; j = plr[p]._pMaxMana >> 8; - l = ((j >> 1) + random(40, j)) << 6; + l = ((j >> 1) + random_(40, j)) << 6; if (plr[p]._pClass == PC_SORCERER) l *= 2; if (plr[p]._pClass == PC_ROGUE) @@ -3354,7 +3354,7 @@ int RndSmithItem(int lvl) } } - return ril[random(50, ri)] + 1; + return ril[random_(50, ri)] + 1; } void BubbleSwapItem(ItemStruct *a, ItemStruct *b) @@ -3393,7 +3393,7 @@ void SpawnSmith(int lvl) { int i, iCnt, idata; - iCnt = random(50, 10) + 10; + iCnt = random_(50, 10) + 10; for (i = 0; i < iCnt; i++) { do { item[0]._iSeed = GetRndSeed(); @@ -3453,7 +3453,7 @@ int RndPremiumItem(int minlvl, int maxlvl) } } - return ril[random(50, ri)] + 1; + return ril[random_(50, ri)] + 1; } void SpawnOnePremium(int i, int plvl) @@ -3542,7 +3542,7 @@ int RndWitchItem(int lvl) } } - return ril[random(51, ri)] + 1; + return ril[random_(51, ri)] + 1; } void SortWitch() @@ -3603,7 +3603,7 @@ void SpawnWitch(int lvl) witchitem[2] = item[0]; witchitem[2]._iCreateInfo = lvl; witchitem[2]._iStatFlag = 1; - iCnt = random(51, 8) + 10; + iCnt = random_(51, 8) + 10; for (i = 3; i < iCnt; i++) { do { @@ -3612,7 +3612,7 @@ void SpawnWitch(int lvl) idata = RndWitchItem(lvl) - 1; GetItemAttrs(0, idata, lvl); maxlvl = -1; - if (random(51, 100) <= 5) + if (random_(51, 100) <= 5) maxlvl = 2 * lvl; if (maxlvl == -1 && item[0]._iMiscId == IMISC_STAFF) maxlvl = 2 * lvl; @@ -3645,7 +3645,7 @@ int RndBoyItem(int lvl) } } - return ril[random(49, ri)] + 1; + return ril[random_(49, ri)] + 1; } void SpawnBoy(int lvl) @@ -3726,7 +3726,7 @@ int RndHealerItem(int lvl) } } - return ril[random(50, ri)] + 1; + return ril[random_(50, ri)] + 1; } void SortHealer() @@ -3776,7 +3776,7 @@ void SpawnHealer(int lvl) } else { srnd = 2; } - nsi = random(50, 8) + 10; + nsi = random_(50, 8) + 10; for (i = srnd; i < nsi; i++) { item[0]._iSeed = GetRndSeed(); SetRndSeed(item[0]._iSeed); @@ -3852,7 +3852,7 @@ void RecreateWitchItem(int ii, int idx, int lvl, int iseed) iblvl = -1; itype = RndWitchItem(lvl) - 1; GetItemAttrs(ii, itype, lvl); - if (random(51, 100) <= 5) + if (random_(51, 100) <= 5) iblvl = 2 * lvl; if (iblvl == -1 && item[ii]._iMiscId == IMISC_STAFF) iblvl = 2 * lvl; diff --git a/Source/missiles.cpp b/Source/missiles.cpp index af579986b..a3c0bb7d2 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -502,7 +502,7 @@ BOOL MonsterTrapHit(int m, int mindam, int maxdam, int dist, int t, BOOLEAN shif resist = TRUE; } - hit = random(68, 100); + hit = random_(68, 100); hper = 90 - (BYTE)monster[m].mArmorClass - dist; if (hper < 5) hper = 5; @@ -516,7 +516,7 @@ BOOL MonsterTrapHit(int m, int mindam, int maxdam, int dist, int t, BOOLEAN shif #else else if (hit < hper || monster[m]._mmode == MM_STONE) { #endif - dam = mindam + random(68, maxdam - mindam + 1); + dam = mindam + random_(68, maxdam - mindam + 1); if (!shift) dam <<= 6; if (resist) @@ -582,7 +582,7 @@ BOOL MonsterMHit(int pnum, int m, int mindam, int maxdam, int dist, int t, BOOLE || mor & RESIST_LIGHTNING && mir == MISR_LIGHTNING) resist = TRUE; - hit = random(69, 100); + hit = random_(69, 100); if (!missiledata[t].mType) { hper = plr[pnum]._pDexterity + plr[pnum]._pIBonusToHit @@ -618,7 +618,7 @@ BOOL MonsterMHit(int pnum, int m, int mindam, int maxdam, int dist, int t, BOOLE if (t == MIS_BONESPIRIT) { dam = monster[m]._mhitpoints / 3 >> 6; } else { - dam = mindam + random(70, maxdam - mindam + 1); + dam = mindam + random_(70, maxdam - mindam + 1); } if (!missiledata[t].mType) { dam = plr[pnum]._pIBonusDamMod + dam * plr[pnum]._pIBonusDam / 100 + dam; @@ -683,7 +683,7 @@ BOOL PlayerMHit(int pnum, int m, int dist, int mind, int maxd, int mtype, BOOLEA return FALSE; } - hit = random(72, 100); + hit = random_(72, 100); #ifdef _DEBUG if (debug_mode_dollar_sign || debug_mode_key_inverted_v) hit = 1000; @@ -719,7 +719,7 @@ BOOL PlayerMHit(int pnum, int m, int dist, int mind, int maxd, int mtype, BOOLEA } if ((plr[pnum]._pmode == PM_STAND || plr[pnum]._pmode == PM_ATTACK) && plr[pnum]._pBlockFlag) { - blk = random(73, 100); + blk = random_(73, 100); } else { blk = 100; } @@ -759,12 +759,12 @@ BOOL PlayerMHit(int pnum, int m, int dist, int mind, int maxd, int mtype, BOOLEA } else { if (shift == FALSE) { - dam = (mind << 6) + random(75, (maxd - mind + 1) << 6); + dam = (mind << 6) + random_(75, (maxd - mind + 1) << 6); if (m == -1 && plr[pnum]._pIFlags & ISPL_ABSHALFTRAP) dam >>= 1; dam += (plr[pnum]._pIGetHit << 6); } else { - dam = mind + random(75, maxd - mind + 1); + dam = mind + random_(75, maxd - mind + 1); if (m == -1 && plr[pnum]._pIFlags & ISPL_ABSHALFTRAP) dam >>= 1; dam += plr[pnum]._pIGetHit; @@ -859,7 +859,7 @@ BOOL Plr2PlrMHit(int pnum, int p, int mindam, int maxdam, int dist, int mtype, B resper = 0; break; } - hper = random(69, 100); + hper = random_(69, 100); if (!missiledata[mtype].mType) { hit = plr[pnum]._pIBonusToHit + plr[pnum]._pLevel @@ -886,7 +886,7 @@ BOOL Plr2PlrMHit(int pnum, int p, int mindam, int maxdam, int dist, int mtype, B hit = 95; if (hper < hit) { if ((plr[p]._pmode == PM_STAND || plr[p]._pmode == PM_ATTACK) && plr[p]._pBlockFlag) { - blkper = random(73, 100); + blkper = random_(73, 100); } else { blkper = 100; } @@ -904,7 +904,7 @@ BOOL Plr2PlrMHit(int pnum, int p, int mindam, int maxdam, int dist, int mtype, B if (mtype == MIS_BONESPIRIT) { dam = plr[p]._pHitPoints / 3; } else { - dam = mindam + random(70, maxdam - mindam + 1); + dam = mindam + random_(70, maxdam - mindam + 1); if (!missiledata[mtype].mType) dam += plr[pnum]._pIBonusDamMod + plr[pnum]._pDamageMod + dam * plr[pnum]._pIBonusDam / 100; if (!shift) @@ -1230,7 +1230,7 @@ void AddArrow(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy, i if (!mienemy) { av = 32; if (plr[id]._pIFlags & ISPL_RNDARROWVEL) { - av = random(64, 32) + 16; + av = random_(64, 32) + 16; } if (plr[id]._pClass == PC_ROGUE) av += (plr[id]._pLevel - 1) >> 2; @@ -1277,11 +1277,11 @@ void AddRndTeleport(int mi, int sx, int sy, int dx, int dy, int midir, char mien r2 = 0; break; } - r1 = random(58, 3) + 4; - r2 = random(58, 3) + 4; - if (random(58, 2) == 1) + r1 = random_(58, 3) + 4; + r2 = random_(58, 3) + 4; + if (random_(58, 2) == 1) r1 = -r1; - if (random(58, 2) == 1) + if (random_(58, 2) == 1) r2 = -r2; } while (nSolidTable[dPiece[r1 + sx][sy + r2]] || dObject[r1 + sx][sy + r2] || dMonster[r1 + sx][sy + r2]); @@ -1396,7 +1396,7 @@ void AddLightball(int mi, int sx, int sy, int dx, int dy, int midir, char mienem { GetMissileVel(mi, sx, sy, dx, dy, 16); missile[mi]._midam = dam; - missile[mi]._miAnimFrame = random(63, 8) + 1; + missile[mi]._miAnimFrame = random_(63, 8) + 1; missile[mi]._mirange = 255; if (id < 0) { missile[mi]._miVar1 = sx; @@ -1411,7 +1411,7 @@ void AddFirewall(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy { int i; - missile[mi]._midam = 16 * (random(53, 10) + random(53, 10) + plr[id]._pLevel + 2) >> 1; + missile[mi]._midam = 16 * (random_(53, 10) + random_(53, 10) + plr[id]._pLevel + 2) >> 1; GetMissileVel(mi, sx, sy, dx, dy, 16); missile[mi]._mirange = 10; i = missile[mi]._mispllvl; @@ -1431,7 +1431,7 @@ void AddFireball(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy dy += YDirAdd[midir]; } if (!mienemy) { - missile[mi]._midam = 2 * (plr[id]._pLevel + random(60, 10) + random(60, 10)) + 4; + missile[mi]._midam = 2 * (plr[id]._pLevel + random_(60, 10) + random_(60, 10)) + 4; for (i = missile[mi]._mispllvl; i > 0; i--) { missile[mi]._midam += missile[mi]._midam >> 3; } @@ -1460,7 +1460,7 @@ void AddLightctrl(int mi, int sx, int sy, int dx, int dy, int midir, char mienem missile[mi]._miVar1 = sx; missile[mi]._miVar2 = sy; GetMissileVel(mi, sx, sy, dx, dy, 32); - missile[mi]._miAnimFrame = random(52, 8) + 1; + missile[mi]._miAnimFrame = random_(52, 8) + 1; missile[mi]._mirange = 256; } @@ -1474,7 +1474,7 @@ void AddLightning(int mi, int sx, int sy, int dx, int dy, int midir, char mienem missile[mi]._mitxoff = missile[midir]._mitxoff; missile[mi]._mityoff = missile[midir]._mityoff; } - missile[mi]._miAnimFrame = random(52, 8) + 1; + missile[mi]._miAnimFrame = random_(52, 8) + 1; if (midir < 0 || mienemy == 1 || id == -1) { if (midir < 0 || id == -1) @@ -1610,7 +1610,7 @@ void AddFlash(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy, i if (id != -1) { missile[mi]._midam = 0; for (i = 0; i <= plr[id]._pLevel; i++) { - missile[mi]._midam += random(55, 20) + 1; + missile[mi]._midam += random_(55, 20) + 1; } for (i = missile[mi]._mispllvl; i > 0; i--) { missile[mi]._midam += missile[mi]._midam >> 3; @@ -1634,7 +1634,7 @@ void AddFlash2(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy, if (id != -1) { missile[mi]._midam = 0; for (i = 0; i <= plr[id]._pLevel; i++) { - missile[mi]._midam += random(56, 2) + 1; + missile[mi]._midam += random_(56, 2) + 1; } for (i = missile[mi]._mispllvl; i > 0; i--) { missile[mi]._midam += missile[mi]._midam >> 3; @@ -1663,7 +1663,7 @@ void AddManashield(int mi, int sx, int sy, int dx, int dy, int midir, char miene void AddFiremove(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy, int id, int dam) { - missile[mi]._midam = random(59, 10) + plr[id]._pLevel + 1; + missile[mi]._midam = random_(59, 10) + plr[id]._pLevel + 1; GetMissileVel(mi, sx, sy, dx, dy, 16); missile[mi]._mirange = 255; missile[mi]._miVar1 = 0; @@ -1678,7 +1678,7 @@ void AddGuardian(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy int i, pn, k, j, tx, ty; int CrawlNum[6] = { 0, 3, 12, 45, 94, 159 }; - missile[mi]._midam = random(62, 10) + (plr[id]._pLevel >> 1) + 1; + missile[mi]._midam = random_(62, 10) + (plr[id]._pLevel >> 1) + 1; for (i = missile[mi]._mispllvl; i > 0; i--) { missile[mi]._midam += missile[mi]._midam >> 3; } @@ -1887,7 +1887,7 @@ void AddAcidpud(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy, missile[mi]._miyoff = 0; missile[mi]._miLightFlag = TRUE; monst = missile[mi]._misource; - missile[mi]._mirange = random(50, 15) + 40 * (monster[monst]._mint + 1); + missile[mi]._mirange = random_(50, 15) + 40 * (monster[monst]._mint + 1); missile[mi]._miPreFlag = TRUE; } @@ -2016,12 +2016,12 @@ void AddHeal(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy, in int i; int HealAmount; - HealAmount = (random(57, 10) + 1) << 6; + HealAmount = (random_(57, 10) + 1) << 6; for (i = 0; i < plr[id]._pLevel; i++) { - HealAmount += (random(57, 4) + 1) << 6; + HealAmount += (random_(57, 4) + 1) << 6; } for (i = 0; i < missile[mi]._mispllvl; i++) { - HealAmount += (random(57, 6) + 1) << 6; + HealAmount += (random_(57, 6) + 1) << 6; } if (plr[id]._pClass == PC_WARRIOR) @@ -2059,7 +2059,7 @@ void AddElement(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy, dx += XDirAdd[midir]; dy += YDirAdd[midir]; } - missile[mi]._midam = 2 * (plr[id]._pLevel + random(60, 10) + random(60, 10)) + 4; + missile[mi]._midam = 2 * (plr[id]._pLevel + random_(60, 10) + random_(60, 10)) + 4; for (i = missile[mi]._mispllvl; i > 0; i--) { missile[mi]._midam += missile[mi]._midam >> 3; } @@ -2160,7 +2160,7 @@ void AddNova(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy, in missile[mi]._miVar1 = dx; missile[mi]._miVar2 = dy; if (id != -1) { - missile[mi]._midam = (random(66, 6) + random(66, 6) + random(66, 6) + random(66, 6) + random(66, 6)); + missile[mi]._midam = (random_(66, 6) + random_(66, 6) + random_(66, 6) + random_(66, 6) + random_(66, 6)); missile[mi]._midam += plr[id]._pLevel + 5; missile[mi]._midam >>= 1; for (k = missile[mi]._mispllvl; k > 0; k--) { @@ -2169,7 +2169,7 @@ void AddNova(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy, in if (!mienemy) UseMana(id, SPL_NOVA); } else { - missile[mi]._midam = ((DWORD)currlevel >> 1) + random(66, 3) + random(66, 3) + random(66, 3); + missile[mi]._midam = ((DWORD)currlevel >> 1) + random_(66, 3) + random_(66, 3) + random_(66, 3); } missile[mi]._mirange = 1; } @@ -2227,7 +2227,7 @@ void AddApoca(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy, i if (missile[mi]._miVar5 >= MAXDUNX) missile[mi]._miVar5 = MAXDUNX - 1; for (i = 0; i < plr[id]._pLevel; i++) { - missile[mi]._midam += random(67, 6) + 1; + missile[mi]._midam += random_(67, 6) + 1; } missile[mi]._mirange = 255; missile[mi]._miDelFlag = FALSE; @@ -2251,10 +2251,10 @@ void AddFlame(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy, i missile[mi]._mirange = missile[mi]._miVar2 + 20; missile[mi]._mlid = AddLight(sx, sy, 1); if (!mienemy) { - i = random(79, plr[id]._pLevel) + random(79, 2); + i = random_(79, plr[id]._pLevel) + random_(79, 2); missile[mi]._midam = 8 * i + 16 + ((8 * i + 16) >> 1); } else { - missile[mi]._midam = monster[id].mMinDamage + random(77, monster[id].mMaxDamage - monster[id].mMinDamage + 1); + missile[mi]._midam = monster[id].mMinDamage + random_(77, monster[id].mMaxDamage - monster[id].mMinDamage + 1); } } @@ -2279,14 +2279,14 @@ void AddCbolt(int mi, int sx, int sy, int dx, int dy, int midir, char micaster, if (micaster == 0) { if (id == myplr) { - missile[mi]._mirnd = random(63, 15) + 1; - missile[mi]._midam = random(68, plr[id]._pMagic >> 2) + 1; + missile[mi]._mirnd = random_(63, 15) + 1; + missile[mi]._midam = random_(68, plr[id]._pMagic >> 2) + 1; } else { - missile[mi]._mirnd = random(63, 15) + 1; - missile[mi]._midam = random(68, plr[id]._pMagic >> 2) + 1; + missile[mi]._mirnd = random_(63, 15) + 1; + missile[mi]._midam = random_(68, plr[id]._pMagic >> 2) + 1; } } else { - missile[mi]._mirnd = random(63, 15) + 1; + missile[mi]._mirnd = random_(63, 15) + 1; missile[mi]._midam = 15; } @@ -2295,7 +2295,7 @@ void AddCbolt(int mi, int sx, int sy, int dx, int dy, int midir, char micaster, dy += YDirAdd[midir]; } - missile[mi]._miAnimFrame = random(63, 8) + 1; + missile[mi]._miAnimFrame = random_(63, 8) + 1; missile[mi]._mlid = AddLight(sx, sy, 5); GetMissileVel(mi, sx, sy, dx, dy, 8); @@ -2327,7 +2327,7 @@ void AddHbolt(int mi, int sx, int sy, int dx, int dy, int midir, char micaster, missile[mi]._miVar1 = sx; missile[mi]._miVar2 = sy; missile[mi]._mlid = AddLight(sx, sy, 8); - missile[mi]._midam = random(69, 10) + plr[id]._pLevel + 9; + missile[mi]._midam = random_(69, 10) + plr[id]._pLevel + 9; UseMana(id, SPL_HBOLT); } @@ -2552,8 +2552,8 @@ void MI_LArrow(int i) mind = plr[p]._pILMinDam; maxd = plr[p]._pILMaxDam; } else { - mind = random(68, 10) + 1 + currlevel; - maxd = random(68, 10) + 1 + currlevel * 2; + mind = random_(68, 10) + 1 + currlevel; + maxd = random_(68, 10) + 1 + currlevel * 2; } missiledata[MIS_LARROW].mResist = MISR_LIGHTNING; CheckMissileCol(i, mind, maxd, 0, missile[i]._mix, missile[i]._miy, 1); @@ -2563,8 +2563,8 @@ void MI_LArrow(int i) mind = plr[p]._pIFMinDam; maxd = plr[p]._pIFMaxDam; } else { - mind = random(68, 10) + 1 + currlevel; - maxd = random(68, 10) + 1 + currlevel * 2; + mind = random_(68, 10) + 1 + currlevel; + maxd = random_(68, 10) + 1 + currlevel * 2; } missiledata[MIS_FARROW].mResist = MISR_FIRE; CheckMissileCol(i, mind, maxd, 0, missile[i]._mix, missile[i]._miy, 1); @@ -2585,8 +2585,8 @@ void MI_LArrow(int i) maxd = monster[p].mMaxDamage; } } else { - mind = random(68, 10) + 1 + currlevel; - maxd = random(68, 10) + 1 + currlevel * 2; + mind = random_(68, 10) + 1 + currlevel; + maxd = random_(68, 10) + 1 + currlevel * 2; } if (missile[i]._mix != missile[i]._misx || missile[i]._miy != missile[i]._misy) { @@ -2666,7 +2666,7 @@ void MI_Firebolt(int i) if (!missile[i]._micaster) { switch (missile[i]._mitype) { case MIS_FIREBOLT: - d = random(75, 10) + (plr[p]._pMagic >> 3) + missile[i]._mispllvl + 1; + d = random_(75, 10) + (plr[p]._pMagic >> 3) + missile[i]._mispllvl + 1; break; case MIS_FLARE: d = 3 * missile[i]._mispllvl - (plr[p]._pMagic >> 3) + (plr[p]._pMagic >> 1); @@ -2676,10 +2676,10 @@ void MI_Firebolt(int i) break; } } else { - d = monster[p].mMinDamage + random(77, monster[p].mMaxDamage - monster[p].mMinDamage + 1); + d = monster[p].mMinDamage + random_(77, monster[p].mMaxDamage - monster[p].mMinDamage + 1); } } else { - d = currlevel + random(78, 2 * currlevel); + d = currlevel + random_(78, 2 * currlevel); } if (missile[i]._mix != missile[i]._misx || missile[i]._miy != missile[i]._misy) { CheckMissileCol(i, d, d, 0, missile[i]._mix, missile[i]._miy, 0); @@ -2797,7 +2797,7 @@ void MI_Firewall(int i) missile[i]._mirange--; if (missile[i]._mirange == missile[i]._miVar1) { SetMissDir(i, 1); - missile[i]._miAnimFrame = random(83, 11) + 1; + missile[i]._miAnimFrame = random_(83, 11) + 1; } if (missile[i]._mirange == missile[i]._miAnimLen - 1) { SetMissDir(i, 0); @@ -2906,12 +2906,12 @@ void MI_Lightctrl(int i) p = missile[i]._misource; if (p != -1) { if (missile[i]._micaster == 0) { - dam = (random(79, 2) + random(79, plr[p]._pLevel) + 2) << 6; + dam = (random_(79, 2) + random_(79, plr[p]._pLevel) + 2) << 6; } else { - dam = 2 * (monster[p].mMinDamage + random(80, monster[p].mMaxDamage - monster[p].mMinDamage + 1)); + dam = 2 * (monster[p].mMinDamage + random_(80, monster[p].mMaxDamage - monster[p].mMinDamage + 1)); } } else { - dam = random(81, currlevel) + 2 * currlevel; + dam = random_(81, currlevel) + 2 * currlevel; } missile[i]._mitxoff += missile[i]._mixvel; @@ -3195,7 +3195,7 @@ void MI_Firemove(int i) missile[i]._miVar1++; if (missile[i]._miVar1 == missile[i]._miAnimLen) { SetMissDir(i, 1); - missile[i]._miAnimFrame = random(82, 11) + 1; + missile[i]._miAnimFrame = random_(82, 11) + 1; } missile[i]._mitxoff += missile[i]._mixvel; missile[i]._mityoff += missile[i]._miyvel; diff --git a/Source/monster.cpp b/Source/monster.cpp index 0eeb17221..6686eb2c2 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -229,7 +229,7 @@ void GetLevelMTypes() } } } - AddMonsterType(skeltypes[random(88, nt)], 1); + AddMonsterType(skeltypes[random_(88, nt)], 1); } nt = 0; @@ -260,7 +260,7 @@ void GetLevelMTypes() } if (nt != 0) { - i = random(88, nt); + i = random_(88, nt); AddMonsterType(typelist[i], 1); typelist[i] = typelist[--nt]; } @@ -393,14 +393,14 @@ void InitMonster(int i, int rd, int mtype, int x, int y) monster[i].MData = monst->MData; monster[i]._mAnimData = monst->Anims[MA_STAND].Data[rd]; monster[i]._mAnimDelay = monst->Anims[MA_STAND].Rate; - monster[i]._mAnimCnt = random(88, monster[i]._mAnimDelay - 1); + monster[i]._mAnimCnt = random_(88, monster[i]._mAnimDelay - 1); monster[i]._mAnimLen = monst->Anims[MA_STAND].Frames; - monster[i]._mAnimFrame = random(88, monster[i]._mAnimLen - 1) + 1; + monster[i]._mAnimFrame = random_(88, monster[i]._mAnimLen - 1) + 1; if (monst->mtype == MT_DIABLO) { - monster[i]._mmaxhp = (random(88, 1) + 1666) << 6; + monster[i]._mmaxhp = (random_(88, 1) + 1666) << 6; } else { - monster[i]._mmaxhp = (monst->mMinHP + random(88, monst->mMaxHP - monst->mMinHP + 1)) << 6; + monster[i]._mmaxhp = (monst->mMinHP + random_(88, monst->mMaxHP - monst->mMinHP + 1)) << 6; } if (gbMaxPlayers == 1) { @@ -496,7 +496,7 @@ void ClrAllMonsters() Monst->_mfuty = 0; Monst->_moldx = 0; Monst->_moldy = 0; - Monst->_mdir = random(89, 8); + Monst->_mdir = random_(89, 8); Monst->_mxvel = 0; Monst->_myvel = 0; Monst->_mAnimData = NULL; @@ -506,7 +506,7 @@ void ClrAllMonsters() Monst->_mAnimFrame = 0; Monst->_mFlags = 0; Monst->_mDelFlag = FALSE; - Monst->_menemy = random(89, gbActivePlayers); + Monst->_menemy = random_(89, gbActivePlayers); Monst->_menemyx = plr[Monst->_menemy]._px; Monst->_menemyy = plr[Monst->_menemy]._py; } @@ -542,7 +542,7 @@ void PlaceMonster(int i, int mtype, int x, int y) dMonster[x][y] = i + 1; - rd = random(90, 8); + rd = random_(90, 8); InitMonster(i, rd, mtype, x, y); } @@ -573,8 +573,8 @@ void PlaceUniqueMonst(int uniqindex, int miniontype, int unpackfilesize) } while (1) { - xp = random(91, 80) + 16; - yp = random(91, 80) + 16; + xp = random_(91, 80) + 16; + yp = random_(91, 80) + 16; count2 = 0; for (x = xp - 3; x < xp + 3; x++) { for (y = yp - 3; y < yp + 3; y++) { @@ -746,7 +746,7 @@ void PlaceUniqueMonst(int uniqindex, int miniontype, int unpackfilesize) if (Monst->_mAi != AI_GARG) { Monst->_mAnimData = Monst->MType->Anims[MA_STAND].Data[Monst->_mdir]; - Monst->_mAnimFrame = random(88, Monst->_mAnimLen - 1) + 1; + Monst->_mAnimFrame = random_(88, Monst->_mAnimLen - 1) + 1; Monst->_mFlags &= ~MFLAG_ALLOW_SPECIAL; Monst->_mmode = MM_STAND; } @@ -838,13 +838,13 @@ void PlaceGroup(int mtype, int num, int leaderf, int leader) } if (leaderf & 1) { - int offset = random(92, 8); + int offset = random_(92, 8); x1 = xp = monster[leader]._mx + offset_x[offset]; y1 = yp = monster[leader]._my + offset_y[offset]; } else { do { - x1 = xp = random(93, 80) + 16; - y1 = yp = random(93, 80) + 16; + x1 = xp = random_(93, 80) + 16; + y1 = yp = random_(93, 80) + 16; } while (!MonstPlace(xp, yp)); } @@ -853,7 +853,7 @@ void PlaceGroup(int mtype, int num, int leaderf, int leader) } j = 0; - for (try2 = 0; j < num && try2 < 100; xp += offset_x[random(94, 8)], yp += offset_x[random(94, 8)]) { + for (try2 = 0; j < num && try2 < 100; xp += offset_x[random_(94, 8)], yp += offset_x[random_(94, 8)]) { if (!MonstPlace(xp, yp) || (dTransVal[xp][yp] != dTransVal[x1][y1]) || (leaderf & 2) && ((abs(xp - x1) >= 4) || (abs(yp - y1) >= 4))) { @@ -875,7 +875,7 @@ void PlaceGroup(int mtype, int num, int leaderf, int leader) if (monster[nummonsters]._mAi != AI_GARG) { monster[nummonsters]._mAnimData = monster[nummonsters].MType->Anims[MA_STAND].Data[monster[nummonsters]._mdir]; - monster[nummonsters]._mAnimFrame = random(88, monster[nummonsters]._mAnimLen - 1) + 1; + monster[nummonsters]._mAnimFrame = random_(88, monster[nummonsters]._mAnimLen - 1) + 1; monster[nummonsters]._mFlags &= ~MFLAG_ALLOW_SPECIAL; monster[nummonsters]._mmode = MM_STAND; } @@ -971,13 +971,13 @@ void InitMonsters() } } while (nummonsters < totalmonsters) { - mtype = scattertypes[random(95, numscattypes)]; - if (currlevel == 1 || random(95, 2) == 0) + mtype = scattertypes[random_(95, numscattypes)]; + if (currlevel == 1 || random_(95, 2) == 0) na = 1; else if (currlevel == 2) - na = random(95, 2) + 2; + na = random_(95, 2) + 2; else - na = random(95, 3) + 3; + na = random_(95, 3) + 3; PlaceGroup(mtype, na, 0, 0); } } @@ -1835,7 +1835,7 @@ void M_StartHeal(int i) Monst->_mAnimFrame = Monst->MType->Anims[MA_SPECIAL].Frames; Monst->_mFlags |= MFLAG_LOCK_ANIMATION; Monst->_mmode = MM_HEAL; - Monst->_mVar1 = Monst->_mmaxhp / (16 * (random(97, 5) + 4)); + Monst->_mVar1 = Monst->_mmaxhp / (16 * (random_(97, 5) + 4)); } void M_ChangeLightOffset(int monst) @@ -1998,11 +1998,11 @@ void M_TryM2MHit(int i, int mid, int hper, int mind, int maxd) if (monster[mid].MType == NULL) app_fatal("M_TryM2MHit: Monster %d \"%s\" MType NULL", mid, monster[mid].mName); if (monster[mid]._mhitpoints >> 6 > 0 && (monster[mid].MType->mtype != MT_ILLWEAV || monster[mid]._mgoal != MGOAL_RETREAT)) { - int hit = random(4, 100); + int hit = random_(4, 100); if (monster[mid]._mmode == MM_STONE) hit = 0; if (!CheckMonsterHit(mid, &ret) && hit < hper) { - int dam = (mind + random(5, maxd - mind + 1)) << 6; + int dam = (mind + random_(5, maxd - mind + 1)) << 6; monster[mid]._mhitpoints -= dam; if (monster[mid]._mhitpoints >> 6 <= 0) { if (monster[mid]._mmode == MM_STONE) { @@ -2047,7 +2047,7 @@ void M_TryH2HHit(int i, int pnum, int Hit, int MinDam, int MaxDam) if (dx >= 2 || dy >= 2) return; - hper = random(98, 100); + hper = random_(98, 100); #ifdef _DEBUG if (debug_mode_dollar_sign || debug_mode_key_inverted_v) hper = 1000; @@ -2067,7 +2067,7 @@ void M_TryH2HHit(int i, int pnum, int Hit, int MinDam, int MaxDam) if (currlevel == 16 && hit < 30) hit = 30; if ((plr[pnum]._pmode == PM_STAND || plr[pnum]._pmode == PM_ATTACK) && plr[pnum]._pBlockFlag) { - blkper = random(98, 100); + blkper = random_(98, 100); } else { blkper = 100; } @@ -2116,7 +2116,7 @@ void M_TryH2HHit(int i, int pnum, int Hit, int MinDam, int MaxDam) } } } - dam = (MinDam << 6) + random(99, (MaxDam - MinDam + 1) << 6); + dam = (MinDam << 6) + random_(99, (MaxDam - MinDam + 1) << 6); dam += (plr[pnum]._pIGetHit << 6); if (dam < 64) dam = 64; @@ -2125,7 +2125,7 @@ void M_TryH2HHit(int i, int pnum, int Hit, int MinDam, int MaxDam) plr[pnum]._pHPBase -= dam; } if (plr[pnum]._pIFlags & ISPL_THORNS) { - mdam = (random(99, 3) + 1) << 6; + mdam = (random_(99, 3) + 1) << 6; monster[i]._mhitpoints -= mdam; if (monster[i]._mhitpoints >> 6 <= 0) M_StartKill(i, pnum); @@ -2451,8 +2451,8 @@ void M_Teleport(int i) if (Monst->_mmode != MM_STONE) { _mx = Monst->_menemyx; _my = Monst->_menemyy; - rx = 2 * random(100, 2) - 1; - ry = 2 * random(100, 2) - 1; + rx = 2 * random_(100, 2) - 1; + ry = 2 * random_(100, 2) - 1; for (j = -1; j <= 1 && !tren; j++) { for (k = -1; k < 1 && !tren; k++) { @@ -2791,11 +2791,11 @@ BOOL M_CallWalk(int i, int md) mdtemp = md; ok = DirOK(i, md); - if (random(101, 2)) + if (random_(101, 2)) ok = ok || (md = left[mdtemp], DirOK(i, md)) || (md = right[mdtemp], DirOK(i, md)); else ok = ok || (md = right[mdtemp], DirOK(i, md)) || (md = left[mdtemp], DirOK(i, md)); - if (random(102, 2)) + if (random_(102, 2)) ok = ok || (md = right[right[mdtemp]], DirOK(i, md)) || (md = left[left[mdtemp]], DirOK(i, md)); @@ -2836,7 +2836,7 @@ BOOL M_CallWalk2(int i, int md) mdtemp = md; ok = DirOK(i, md); // Can we continue in the same direction - if (random(101, 2)) { // Randomly go left or right + if (random_(101, 2)) { // Randomly go left or right ok = ok || (mdtemp = left[md], DirOK(i, left[md])) || (mdtemp = right[md], DirOK(i, right[md])); } else { ok = ok || (mdtemp = right[md], DirOK(i, right[md])) || (mdtemp = left[md], DirOK(i, left[md])); @@ -2911,12 +2911,12 @@ void MAI_Zombie(int i) mx = mx - Monst->_menemyx; my = my - Monst->_menemyy; md = Monst->_mdir; - v = random(103, 100); + v = random_(103, 100); if (abs(mx) >= 2 || abs(my) >= 2) { if (v < 2 * Monst->_mint + 10) { if (abs(mx) >= 2 * Monst->_mint + 4 || abs(my) >= 2 * Monst->_mint + 4) { - if (random(104, 100) < 2 * Monst->_mint + 20) { - md = random(104, 8); + if (random_(104, 100) < 2 * Monst->_mint + 20) { + md = random_(104, 8); } M_DumbWalk(i, md); } else { @@ -2952,16 +2952,16 @@ void MAI_SkelSd(int i) md = GetDirection(mx, my, Monst->_lastx, Monst->_lasty); Monst->_mdir = md; if (abs(x) >= 2 || abs(y) >= 2) { - if (Monst->_mVar1 == MM_DELAY || (random(106, 100) >= 35 - 4 * Monst->_mint)) { + if (Monst->_mVar1 == MM_DELAY || (random_(106, 100) >= 35 - 4 * Monst->_mint)) { M_CallWalk(i, md); } else { - M_StartDelay(i, 15 - 2 * Monst->_mint + random(106, 10)); + M_StartDelay(i, 15 - 2 * Monst->_mint + random_(106, 10)); } } else { - if (Monst->_mVar1 == MM_DELAY || (random(105, 100) < 2 * Monst->_mint + 20)) { + if (Monst->_mVar1 == MM_DELAY || (random_(105, 100) < 2 * Monst->_mint + 20)) { M_StartAttack(i); } else { - M_StartDelay(i, 2 * (5 - Monst->_mint) + random(105, 10)); + M_StartDelay(i, 2 * (5 - Monst->_mint) + random_(105, 10)); } } @@ -3039,7 +3039,7 @@ void MAI_Snake(int i) Monst->_mmode = MM_CHARGE; dMonster[Monst->_mx][Monst->_my] = -1 - i; } - } else if (Monst->_mVar1 == MM_DELAY || random(106, 100) >= 35 - 2 * Monst->_mint) { + } else if (Monst->_mVar1 == MM_DELAY || random_(106, 100) >= 35 - 2 * Monst->_mint) { if (md + pattern[Monst->_mgoalvar1] < 0) { tmp = md + pattern[Monst->_mgoalvar1] + 8; } else { @@ -3080,15 +3080,15 @@ void MAI_Snake(int i) if (!M_DumbWalk(i, Monst->_mgoalvar2)) M_CallWalk2(i, Monst->_mdir); } else { - M_StartDelay(i, 15 - Monst->_mint + random(106, 10)); + M_StartDelay(i, 15 - Monst->_mint + random_(106, 10)); } } else { if (Monst->_mVar1 == MM_DELAY || Monst->_mVar1 == MM_CHARGE - || (random(105, 100) < Monst->_mint + 20)) { + || (random_(105, 100) < Monst->_mint + 20)) { M_StartAttack(i); } else - M_StartDelay(i, 10 - Monst->_mint + random(105, 10)); + M_StartDelay(i, 10 - Monst->_mint + random_(105, 10)); } if (Monst->_mmode == MM_STAND) Monst->_mAnimData = Monst->MType->Anims[MA_STAND].Data[Monst->_mdir]; @@ -3113,13 +3113,13 @@ void MAI_Bat(int i) yd = Monst->_my - Monst->_menemyy; md = GetDirection(Monst->_mx, Monst->_my, Monst->_lastx, Monst->_lasty); Monst->_mdir = md; - v = random(107, 100); + v = random_(107, 100); if (Monst->_mgoal == MGOAL_RETREAT) { if (!Monst->_mgoalvar1) { M_CallWalk(i, opposite[md]); Monst->_mgoalvar1++; } else { - if (random(108, 2)) + if (random_(108, 2)) M_CallWalk(i, left[md]); else M_CallWalk(i, right[md]); @@ -3150,7 +3150,7 @@ void MAI_Bat(int i) Monst->_mgoal = MGOAL_RETREAT; Monst->_mgoalvar1 = 0; if (Monst->MType->mtype == MT_FAMILIAR) { - AddMissile(Monst->_menemyx, Monst->_menemyy, Monst->_menemyx + 1, 0, -1, MIS_LIGHTNING, 1, i, random(109, 10) + 1, 0); + AddMissile(Monst->_menemyx, Monst->_menemyy, Monst->_menemyx + 1, 0, -1, MIS_LIGHTNING, 1, i, random_(109, 10) + 1, 0); } } @@ -3178,7 +3178,7 @@ void MAI_SkelBow(int i) md = M_GetDir(i); Monst->_mdir = md; - v = random(110, 100); + v = random_(110, 100); if (abs(mx) < 4 && abs(my) < 4) { if (Monst->_mVar2 > 20 && v < 2 * Monst->_mint + 13 @@ -3192,7 +3192,7 @@ void MAI_SkelBow(int i) mx = Monst->_menemyx; my = Monst->_menemyy; if (!walking) { - if (random(110, 100) < 2 * Monst->_mint + 3) { + if (random_(110, 100) < 2 * Monst->_mint + 3) { if (LineClear(Monst->_mx, Monst->_my, mx, my)) M_StartRAttack(i, MIS_ARROW, 4); } @@ -3219,7 +3219,7 @@ void MAI_Fat(int i) my = Monst->_my - Monst->_menemyy; md = M_GetDir(i); Monst->_mdir = md; - v = random(111, 100); + v = random_(111, 100); if (abs(mx) >= 2 || abs(my) >= 2) { if (Monst->_mVar2 > 20 && v < 4 * Monst->_mint + 20 || (Monst->_mVar1 == MM_WALK || Monst->_mVar1 == MM_WALK2 || Monst->_mVar1 == MM_WALK3) @@ -3271,14 +3271,14 @@ void MAI_Sneak(int i) md = GetDirection(Monst->_mx, Monst->_my, plr[Monst->_menemy]._pownerx, plr[Monst->_menemy]._pownery); md = opposite[md]; if (Monst->MType->mtype == MT_UNSEEN) { - if (random(112, 2)) + if (random_(112, 2)) md = left[md]; else md = right[md]; } } Monst->_mdir = md; - v = random(112, 100); + v = random_(112, 100); if (abs(mx) < dist && abs(my) < dist && Monst->_mFlags & MFLAG_HIDDEN) { M_StartFadein(i, md, FALSE); } else { @@ -3338,7 +3338,7 @@ void MAI_Fireman(int i) M_StartRAttack(i, MIS_KRULL, 4); Monst->_mgoalvar1++; } else { - M_StartDelay(i, random(112, 10) + 5); + M_StartDelay(i, random_(112, 10) + 5); Monst->_mgoalvar1++; } } else if (Monst->_mgoal == MGOAL_RETREAT) { @@ -3346,7 +3346,7 @@ void MAI_Fireman(int i) Monst->_mgoal = MGOAL_SHOOT; } Monst->_mdir = md; - random(112, 100); + random_(112, 100); if (Monst->_mmode != MM_STAND) return; @@ -3392,7 +3392,7 @@ void MAI_Fallen(int i) } if (Monst->_mAnimFrame == Monst->_mAnimLen) { - if (random(113, 4)) { + if (random_(113, 4)) { return; } if (!(Monst->_mFlags & MFLAG_NOHEAL)) { @@ -3483,12 +3483,12 @@ void MAI_Round(int i, BOOL special) md = GetDirection(Monst->_mx, Monst->_my, Monst->_lastx, Monst->_lasty); if (Monst->_msquelch < UCHAR_MAX) MonstCheckDoors(i); - v = random(114, 100); + v = random_(114, 100); if ((abs(mx) >= 2 || abs(my) >= 2) && Monst->_msquelch == UCHAR_MAX && dTransVal[Monst->_mx][Monst->_my] == dTransVal[fx][fy]) { - if (Monst->_mgoal == MGOAL_MOVE || (abs(mx) >= 4 || abs(my) >= 4) && random(115, 4) == 0) { + if (Monst->_mgoal == MGOAL_MOVE || (abs(mx) >= 4 || abs(my) >= 4) && random_(115, 4) == 0) { if (Monst->_mgoal != MGOAL_MOVE) { Monst->_mgoalvar1 = 0; - Monst->_mgoalvar2 = random(116, 2); + Monst->_mgoalvar2 = random_(116, 2); } Monst->_mgoal = MGOAL_MOVE; if (abs(mx) > abs(my)) @@ -3498,7 +3498,7 @@ void MAI_Round(int i, BOOL special) if (Monst->_mgoalvar1++ >= 2 * dist && DirOK(i, md) || dTransVal[Monst->_mx][Monst->_my] != dTransVal[fx][fy]) { Monst->_mgoal = MGOAL_NORMAL; } else if (!M_RoundWalk(i, md, &Monst->_mgoalvar2)) { - M_StartDelay(i, random(125, 10) + 10); + M_StartDelay(i, random_(125, 10) + 10); } } } else @@ -3513,7 +3513,7 @@ void MAI_Round(int i, BOOL special) } } else if (v < 2 * Monst->_mint + 23) { Monst->_mdir = md; - if (special && Monst->_mhitpoints < (Monst->_mmaxhp >> 1) && random(117, 2) != 0) + if (special && Monst->_mhitpoints < (Monst->_mmaxhp >> 1) && random_(117, 2) != 0) M_StartSpAttack(i); else M_StartAttack(i); @@ -3553,9 +3553,9 @@ void MAI_Ranged(int i, int missile_type, BOOL special) MonstCheckDoors(i); Monst->_mdir = md; if (Monst->_mVar1 == MM_RATTACK) { - M_StartDelay(i, random(118, 20)); + M_StartDelay(i, random_(118, 20)); } else if (abs(mx) < 4 && abs(my) < 4) { - if (random(119, 100) < 10 * (Monst->_mint + 7)) + if (random_(119, 100) < 10 * (Monst->_mint + 7)) M_CallWalk(i, opposite[md]); } if (Monst->_mmode == MM_STAND) { @@ -3627,7 +3627,7 @@ void MAI_Scav(int i) } } else { if (Monst->_mgoalvar1 == 0) { - if (random(120, 2) != 0) { + if (random_(120, 2) != 0) { for (y = -4; y <= 4 && !done; y++) { for (x = -4; x <= 4 && !done; x++) { // BUGFIX: incorrect check of offset against limits of the dungeon @@ -3736,12 +3736,12 @@ void MAI_RoundRanged(int i, int missile_type, BOOL checkdoors, int dam, int less md = GetDirection(Monst->_mx, Monst->_my, Monst->_lastx, Monst->_lasty); if (checkdoors && Monst->_msquelch < UCHAR_MAX) MonstCheckDoors(i); - v = random(121, 10000); + v = random_(121, 10000); if ((abs(mx) >= 2 || abs(my) >= 2) && Monst->_msquelch == UCHAR_MAX && dTransVal[Monst->_mx][Monst->_my] == dTransVal[fx][fy]) { - if (Monst->_mgoal == MGOAL_MOVE || ((abs(mx) >= 3 || abs(my) >= 3) && random(122, 4 << lessmissiles) == 0)) { + if (Monst->_mgoal == MGOAL_MOVE || ((abs(mx) >= 3 || abs(my) >= 3) && random_(122, 4 << lessmissiles) == 0)) { if (Monst->_mgoal != MGOAL_MOVE) { Monst->_mgoalvar1 = 0; - Monst->_mgoalvar2 = random(123, 2); + Monst->_mgoalvar2 = random_(123, 2); } Monst->_mgoal = MGOAL_MOVE; if (abs(mx) > abs(my)) { @@ -3767,7 +3767,7 @@ void MAI_RoundRanged(int i, int missile_type, BOOL checkdoors, int dam, int less && LineClear(Monst->_mx, Monst->_my, fx, fy)) { M_StartRSpAttack(i, missile_type, dam); } else if (abs(mx) >= 2 || abs(my) >= 2) { - v = random(124, 100); + v = random_(124, 100); if (v < 1000 * (Monst->_mint + 5) || (Monst->_mVar1 == MM_WALK || Monst->_mVar1 == MM_WALK2 || Monst->_mVar1 == MM_WALK3) && Monst->_mVar2 == 0 && v < 1000 * (Monst->_mint + 8)) { M_CallWalk(i, md); @@ -3778,7 +3778,7 @@ void MAI_RoundRanged(int i, int missile_type, BOOL checkdoors, int dam, int less } } if (Monst->_mmode == MM_STAND) { - M_StartDelay(i, random(125, 10) + 5); + M_StartDelay(i, random_(125, 10) + 5); } } } @@ -3828,12 +3828,12 @@ void MAI_RR2(int i, int mistype, int dam) md = GetDirection(Monst->_mx, Monst->_my, Monst->_lastx, Monst->_lasty); if (Monst->_msquelch < UCHAR_MAX) MonstCheckDoors(i); - v = random(121, 100); + v = random_(121, 100); if ((abs(mx) >= 2 || abs(my) >= 2) && Monst->_msquelch == UCHAR_MAX && dTransVal[Monst->_mx][Monst->_my] == dTransVal[fx][fy]) { if (Monst->_mgoal == MGOAL_MOVE || (abs(mx) >= 3 || abs(my) >= 3)) { if (Monst->_mgoal != MGOAL_MOVE) { Monst->_mgoalvar1 = 0; - Monst->_mgoalvar2 = random(123, 2); + Monst->_mgoalvar2 = random_(123, 2); } Monst->_mgoal = MGOAL_MOVE; Monst->_mgoalvar3 = 4; @@ -3854,7 +3854,7 @@ void MAI_RR2(int i, int mistype, int dam) if (((abs(mx) >= 3 || abs(my) >= 3) && v < 5 * (Monst->_mint + 2) || v < 5 * (Monst->_mint + 1) || Monst->_mgoalvar3 == 4) && LineClear(Monst->_mx, Monst->_my, fx, fy)) { M_StartRSpAttack(i, mistype, dam); } else if (abs(mx) >= 2 || abs(my) >= 2) { - v = random(124, 100); + v = random_(124, 100); if (v < 2 * (5 * Monst->_mint + 25) || (Monst->_mVar1 == MM_WALK || Monst->_mVar1 == MM_WALK2 || Monst->_mVar1 == MM_WALK3) && Monst->_mVar2 == 0 @@ -3862,9 +3862,9 @@ void MAI_RR2(int i, int mistype, int dam) M_CallWalk(i, md); } } else { - if (random(124, 100) < 10 * (Monst->_mint + 4)) { + if (random_(124, 100) < 10 * (Monst->_mint + 4)) { Monst->_mdir = md; - if (random(124, 2) != 0) + if (random_(124, 2) != 0) M_StartAttack(i); else M_StartRSpAttack(i, mistype, dam); @@ -3873,7 +3873,7 @@ void MAI_RR2(int i, int mistype, int dam) Monst->_mgoalvar3 = 1; } if (Monst->_mmode == MM_STAND) { - M_StartDelay(i, random(125, 10) + 5); + M_StartDelay(i, random_(125, 10) + 5); } } } @@ -3979,12 +3979,12 @@ void MAI_SkelKing(int i) md = GetDirection(Monst->_mx, Monst->_my, Monst->_lastx, Monst->_lasty); if (Monst->_msquelch < UCHAR_MAX) MonstCheckDoors(i); - v = random(126, 100); + v = random_(126, 100); if ((abs(mx) >= 2 || abs(my) >= 2) && Monst->_msquelch == UCHAR_MAX && dTransVal[Monst->_mx][Monst->_my] == dTransVal[fx][fy]) { - if (Monst->_mgoal == MGOAL_MOVE || (abs(mx) >= 3 || abs(my) >= 3) && random(127, 4) == 0) { + if (Monst->_mgoal == MGOAL_MOVE || (abs(mx) >= 3 || abs(my) >= 3) && random_(127, 4) == 0) { if (Monst->_mgoal != MGOAL_MOVE) { Monst->_mgoalvar1 = 0; - Monst->_mgoalvar2 = random(128, 2); + Monst->_mgoalvar2 = random_(128, 2); } Monst->_mgoal = MGOAL_MOVE; if (abs(mx) > abs(my)) { @@ -3995,7 +3995,7 @@ void MAI_SkelKing(int i) if (Monst->_mgoalvar1++ >= 2 * dist && DirOK(i, md) || dTransVal[Monst->_mx][Monst->_my] != dTransVal[fx][fy]) { Monst->_mgoal = MGOAL_NORMAL; } else if (!M_RoundWalk(i, md, &Monst->_mgoalvar2)) { - M_StartDelay(i, random(125, 10) + 10); + M_StartDelay(i, random_(125, 10) + 10); } } } else @@ -4012,10 +4012,10 @@ void MAI_SkelKing(int i) } } else { if (abs(mx) >= 2 || abs(my) >= 2) { - v = random(129, 100); + v = random_(129, 100); if (v >= Monst->_mint + 25 && (Monst->_mVar1 != MM_WALK && Monst->_mVar1 != MM_WALK2 && Monst->_mVar1 != MM_WALK3 || Monst->_mVar2 != 0 || (v >= Monst->_mint + 75))) { - M_StartDelay(i, random(130, 10) + 10); + M_StartDelay(i, random_(130, 10) + 10); } else { M_CallWalk(i, md); } @@ -4047,12 +4047,12 @@ void MAI_Rhino(int i) md = GetDirection(Monst->_mx, Monst->_my, Monst->_lastx, Monst->_lasty); if (Monst->_msquelch < UCHAR_MAX) MonstCheckDoors(i); - v = random(131, 100); + v = random_(131, 100); if (abs(mx) >= 2 || abs(my) >= 2) { - if (Monst->_mgoal == MGOAL_MOVE || (abs(mx) >= 5 || abs(my) >= 5) && random(132, 4) != 0) { + if (Monst->_mgoal == MGOAL_MOVE || (abs(mx) >= 5 || abs(my) >= 5) && random_(132, 4) != 0) { if (Monst->_mgoal != MGOAL_MOVE) { Monst->_mgoalvar1 = 0; - Monst->_mgoalvar2 = random(133, 2); + Monst->_mgoalvar2 = random_(133, 2); } Monst->_mgoal = 4; if (abs(mx) > abs(my)) { @@ -4063,7 +4063,7 @@ void MAI_Rhino(int i) if (Monst->_mgoalvar1++ >= 2 * dist || dTransVal[Monst->_mx][Monst->_my] != dTransVal[fx][fy]) { Monst->_mgoal = MGOAL_NORMAL; } else if (!M_RoundWalk(i, md, &Monst->_mgoalvar2)) { - M_StartDelay(i, random(125, 10) + 10); + M_StartDelay(i, random_(125, 10) + 10); } } } else @@ -4080,12 +4080,12 @@ void MAI_Rhino(int i) } } else { if (abs(mx) >= 2 || abs(my) >= 2) { - v = random(134, 100); + v = random_(134, 100); if (v >= 2 * Monst->_mint + 33 && (Monst->_mVar1 != MM_WALK && Monst->_mVar1 != MM_WALK2 && Monst->_mVar1 != MM_WALK3 || Monst->_mVar2 || v >= 2 * Monst->_mint + 83)) { - M_StartDelay(i, random(135, 10) + 10); + M_StartDelay(i, random_(135, 10) + 10); } else { M_CallWalk(i, md); } @@ -4117,7 +4117,7 @@ void MAI_Counselor(int i) md = GetDirection(Monst->_mx, Monst->_my, Monst->_lastx, Monst->_lasty); if (Monst->_msquelch < UCHAR_MAX) MonstCheckDoors(i); - v = random(121, 100); + v = random_(121, 100); if (Monst->_mgoal == MGOAL_RETREAT) { if (Monst->_mgoalvar1++ <= 3) M_CallWalk(i, opposite[md]); @@ -4144,13 +4144,13 @@ void MAI_Counselor(int i) } else if (Monst->_mgoal == MGOAL_NORMAL) { if (abs(mx) >= 2 || abs(my) >= 2) { if (v < 5 * (Monst->_mint + 10) && LineClear(Monst->_mx, Monst->_my, fx, fy)) { - M_StartRAttack(i, counsmiss[Monst->_mint], Monst->mMinDamage + random(77, Monst->mMaxDamage - Monst->mMinDamage + 1)); - } else if (random(124, 100) < 30) { + M_StartRAttack(i, counsmiss[Monst->_mint], Monst->mMinDamage + random_(77, Monst->mMaxDamage - Monst->mMinDamage + 1)); + } else if (random_(124, 100) < 30) { Monst->_mgoal = MGOAL_MOVE; Monst->_mgoalvar1 = 0; M_StartFadeout(i, md, FALSE); } else - M_StartDelay(i, random(105, 10) + 2 * (5 - Monst->_mint)); + M_StartDelay(i, random_(105, 10) + 2 * (5 - Monst->_mint)); } else { Monst->_mdir = md; if (Monst->_mhitpoints < (Monst->_mmaxhp >> 1)) { @@ -4158,16 +4158,16 @@ void MAI_Counselor(int i) Monst->_mgoalvar1 = 0; M_StartFadeout(i, md, FALSE); } else if (Monst->_mVar1 == MM_DELAY - || random(105, 100) < 2 * Monst->_mint + 20) { + || random_(105, 100) < 2 * Monst->_mint + 20) { M_StartRAttack(i, -1, 0); AddMissile(Monst->_mx, Monst->_my, 0, 0, Monst->_mdir, MIS_FLASH, 1, i, 4, 0); AddMissile(Monst->_mx, Monst->_my, 0, 0, Monst->_mdir, MIS_FLASH2, 1, i, 4, 0); } else - M_StartDelay(i, random(105, 10) + 2 * (5 - Monst->_mint)); + M_StartDelay(i, random_(105, 10) + 2 * (5 - Monst->_mint)); } } if (Monst->_mmode == MM_STAND) { - M_StartDelay(i, random(125, 10) + 5); + M_StartDelay(i, random_(125, 10) + 5); } } } @@ -5309,7 +5309,7 @@ int M_SpawnSkel(int x, int y, int dir) } if (j) { - skeltypes = random(136, j); + skeltypes = random_(136, j); j = 0; for (i = 0; i < nummtypes && j <= skeltypes; i++) { if (IsSkel(Monsters[i].mtype)) @@ -5367,7 +5367,7 @@ BOOL SpawnSkeleton(int ii, int x, int y) return FALSE; } - rs = random(137, 15) + 1; + rs = random_(137, 15) + 1; xx = 0; yy = 0; while (rs > 0) { @@ -5404,7 +5404,7 @@ int PreSpawnSkeleton() } if (j) { - skeltypes = random(136, j); + skeltypes = random_(136, j); j = 0; for (i = 0; i < nummtypes && j <= skeltypes; i++) { if (IsSkel(Monsters[i].mtype)) diff --git a/Source/objects.cpp b/Source/objects.cpp index 577496c49..4aff4a846 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -143,12 +143,12 @@ void InitRndLocObj(int min, int max, int objtype) { int i, xp, yp, numobjs; - numobjs = random(139, max - min) + min; + numobjs = random_(139, max - min) + min; for (i = 0; i < numobjs; i++) { while (1) { - xp = random(139, 80) + 16; - yp = random(139, 80) + 16; + xp = random_(139, 80) + 16; + yp = random_(139, 80) + 16; if (RndLocOk(xp - 1, yp - 1) && RndLocOk(xp, yp - 1) && RndLocOk(xp + 1, yp - 1) @@ -169,11 +169,11 @@ void InitRndLocBigObj(int min, int max, int objtype) { int i, xp, yp, numobjs; - numobjs = random(140, max - min) + min; + numobjs = random_(140, max - min) + min; for (i = 0; i < numobjs; i++) { while (1) { - xp = random(140, 80) + 16; - yp = random(140, 80) + 16; + xp = random_(140, 80) + 16; + yp = random_(140, 80) + 16; if (RndLocOk(xp - 1, yp - 2) && RndLocOk(xp, yp - 2) && RndLocOk(xp + 1, yp - 2) @@ -198,13 +198,13 @@ void InitRndLocObj5x5(int min, int max, int objtype) BOOL exit; int xp, yp, numobjs, i, k, m, n; - numobjs = min + random(139, max - min); + numobjs = min + random_(139, max - min); for (i = 0; i < numobjs; i++) { k = 0; for (;;) { exit = TRUE; - xp = random(139, 80) + 16; - yp = random(139, 80) + 16; + xp = random_(139, 80) + 16; + yp = random_(139, 80) + 16; for (n = -2; n <= 2; n++) { for (m = -2; m <= 2; m++) { if (!RndLocOk(xp + m, yp + n)) @@ -292,8 +292,8 @@ void AddBookLever(int lx1, int ly1, int lx2, int ly2, int x1, int y1, int x2, in k = 0; for (;;) { exit = TRUE; - xp = random(139, 80) + 16; - yp = random(139, 80) + 16; + xp = random_(139, 80) + 16; + yp = random_(139, 80) + 16; for (n = -2; n <= 2; n++) { for (m = -2; m <= 2; m++) { if (!RndLocOk(xp + m, yp + n)) @@ -335,24 +335,24 @@ void InitRndBarrels() int c; // number of barrels in current group int i; - numobjs = random(143, 5) + 3; + numobjs = random_(143, 5) + 3; for (i = 0; i < numobjs; i++) { do { - xp = random(143, 80) + 16; - yp = random(143, 80) + 16; + xp = random_(143, 80) + 16; + yp = random_(143, 80) + 16; } while (!RndLocOk(xp, yp)); - o = (random(143, 4) != 0) ? OBJ_BARREL : OBJ_BARRELEX; + o = (random_(143, 4) != 0) ? OBJ_BARREL : OBJ_BARRELEX; AddObject(o, xp, yp); found = TRUE; p = 0; c = 1; - while (random(143, p) == 0 && found) { + while (random_(143, p) == 0 && found) { t = 0; found = FALSE; while (TRUE) { if (t >= 3) break; - dir = random(143, 8); + dir = random_(143, 8); xp += bxadd[dir]; yp += byadd[dir]; found = RndLocOk(xp, yp); @@ -361,7 +361,7 @@ void InitRndBarrels() break; } if (found) { - o = (random(143, 5) != 0) ? OBJ_BARREL : OBJ_BARRELEX; + o = (random_(143, 5) != 0) ? OBJ_BARREL : OBJ_BARRELEX; AddObject(o, xp, yp); c++; } @@ -434,16 +434,16 @@ void AddL2Torches() continue; pn = dPiece[i][j]; - if (pn == 1 && random(145, 3) == 0) + if (pn == 1 && random_(145, 3) == 0) AddObject(OBJ_TORCHL2, i, j); - if (pn == 5 && random(145, 3) == 0) + if (pn == 5 && random_(145, 3) == 0) AddObject(OBJ_TORCHR2, i, j); - if (pn == 37 && random(145, 10) == 0 && dObject[i - 1][j] == 0) + if (pn == 37 && random_(145, 10) == 0 && dObject[i - 1][j] == 0) AddObject(OBJ_TORCHL, i - 1, j); - if (pn == 41 && random(145, 10) == 0 && dObject[i][j - 1] == 0) + if (pn == 41 && random_(145, 10) == 0 && dObject[i][j - 1] == 0) AddObject(OBJ_TORCHR, i, j - 1); } } @@ -474,14 +474,14 @@ void AddObjTraps() rndv = 25; for (j = 0; j < MAXDUNY; j++) { for (i = 0; i < MAXDUNX; i++) { - if (dObject[i][j] <= 0 || random(144, 100) >= rndv) + if (dObject[i][j] <= 0 || random_(144, 100) >= rndv) continue; oi = dObject[i][j] - 1; if (!AllObjects[object[oi]._otype].oTrapFlag) continue; - if (random(144, 2) == 0) { + if (random_(144, 2) == 0) { xp = i - 1; while (!nSolidTable[dPiece[xp][j]]) xp--; @@ -521,13 +521,13 @@ void AddChestTraps() for (i = 0; i < MAXDUNX; i++) { if (dObject[i][j] > 0) { oi = dObject[i][j] - 1; - if (object[oi]._otype >= OBJ_CHEST1 && object[oi]._otype <= OBJ_CHEST3 && !object[oi]._oTrapFlag && random(0, 100) < 10) { + if (object[oi]._otype >= OBJ_CHEST1 && object[oi]._otype <= OBJ_CHEST3 && !object[oi]._oTrapFlag && random_(0, 100) < 10) { object[oi]._otype += OBJ_BOOKCASER; object[oi]._oTrapFlag = TRUE; if (leveltype == DTYPE_CATACOMBS) { - object[oi]._oVar4 = random(0, 2); + object[oi]._oVar4 = random_(0, 2); } else { - object[oi]._oVar4 = random(0, 3); + object[oi]._oVar4 = random_(0, 3); } } } @@ -618,8 +618,8 @@ void AddStoryBooks() cnt = 0; while (TRUE) { done = TRUE; - xp = random(139, 80) + 16; - yp = random(139, 80) + 16; + xp = random_(139, 80) + 16; + yp = random_(139, 80) + 16; for (yy = -2; yy <= 2; yy++) { for (xx = -3; xx <= 3; xx++) { if (!RndLocOk(xx + xp, yy + yp)) @@ -651,12 +651,12 @@ void AddHookedBodies(int freq) ii = 16 + i * 2; if (dungeon[i][j] != 1 && dungeon[i][j] != 2) continue; - if (random(0, freq) != 0) + if (random_(0, freq) != 0) continue; if (!SkipThemeRoom(i, j)) continue; if (dungeon[i][j] == 1 && dungeon[i + 1][j] == 6) { - switch (random(0, 3)) { + switch (random_(0, 3)) { case 0: AddObject(OBJ_TORTURE1, ii + 1, jj); break; @@ -670,7 +670,7 @@ void AddHookedBodies(int freq) continue; } if (dungeon[i][j] == 2 && dungeon[i][j + 1] == 6) { - switch (random(0, 2)) { + switch (random_(0, 2)) { case 0: AddObject(OBJ_TORTURE3, ii, jj); break; @@ -706,8 +706,8 @@ void AddLazStand() cnt = 0; while (TRUE) { found = 1; - xp = random(139, 80) + 16; - yp = random(139, 80) + 16; + xp = random_(139, 80) + 16; + yp = random_(139, 80) + 16; for (yy = -3; yy <= 3; yy++) { for (xx = -2; xx <= 3; xx++) { if (!RndLocOk(xp + xx, yp + yy)) @@ -929,9 +929,9 @@ void SetupObject(int i, int x, int y, int ot) object[i]._oAnimFlag = AllObjects[ot].oAnimFlag; if (AllObjects[ot].oAnimFlag) { object[i]._oAnimDelay = AllObjects[ot].oAnimDelay; - object[i]._oAnimCnt = random(146, AllObjects[ot].oAnimDelay); + object[i]._oAnimCnt = random_(146, AllObjects[ot].oAnimDelay); object[i]._oAnimLen = AllObjects[ot].oAnimLen; - object[i]._oAnimFrame = random(146, AllObjects[ot].oAnimLen - 1) + 1; + object[i]._oAnimFrame = random_(146, AllObjects[ot].oAnimLen - 1) + 1; } else { object[i]._oAnimDelay = 1000; object[i]._oAnimLen = AllObjects[ot].oAnimLen; @@ -992,7 +992,7 @@ void AddSCambBook(int i) void AddChest(int i, int t) { - if (!random(147, 2)) + if (!random_(147, 2)) object[i]._oAnimFrame += 3; object[i]._oRndSeed = GetRndSeed(); switch (t) { @@ -1002,7 +1002,7 @@ void AddChest(int i, int t) object[i]._oVar1 = 1; break; } - object[i]._oVar1 = random(147, 2); + object[i]._oVar1 = random_(147, 2); break; case OBJ_TCHEST2: case OBJ_CHEST2: @@ -1010,7 +1010,7 @@ void AddChest(int i, int t) object[i]._oVar1 = 2; break; } - object[i]._oVar1 = random(147, 3); + object[i]._oVar1 = random_(147, 3); break; case OBJ_TCHEST3: case OBJ_CHEST3: @@ -1018,10 +1018,10 @@ void AddChest(int i, int t) object[i]._oVar1 = 3; break; } - object[i]._oVar1 = random(147, 4); + object[i]._oVar1 = random_(147, 4); break; } - object[i]._oVar2 = random(147, 8); + object[i]._oVar2 = random_(147, 8); } void AddL2Door(int i, int x, int y, int ot) @@ -1047,7 +1047,7 @@ void AddL3Door(int i, int x, int y, int ot) void AddSarc(int i) { dObject[object[i]._ox][object[i]._oy - 1] = -(i + 1); - object[i]._oVar1 = random(153, 10); + object[i]._oVar1 = random_(153, 10); object[i]._oRndSeed = GetRndSeed(); if (object[i]._oVar1 >= 8) object[i]._oVar2 = PreSpawnSkeleton(); @@ -1072,7 +1072,7 @@ void AddTrap(int i, int ot) int mt; mt = currlevel / 3 + 1; - mt = random(148, mt); + mt = random_(148, mt); if (mt == 0) object[i]._oVar3 = 0; // arrow if (mt == 1) @@ -1096,8 +1096,8 @@ void AddBarrel(int i, int t) { object[i]._oVar1 = 0; object[i]._oRndSeed = GetRndSeed(); - object[i]._oVar2 = random(149, 10); - object[i]._oVar3 = random(149, 3); + object[i]._oVar2 = random_(149, 10); + object[i]._oVar3 = random_(149, 3); if (object[i]._oVar2 >= 8) object[i]._oVar4 = PreSpawnSkeleton(); @@ -1125,14 +1125,14 @@ void AddShrine(int i) } } while (1) { - val = random(150, NUM_SHRINETYPE); + val = random_(150, NUM_SHRINETYPE); if (slist[val]) { break; } } object[i]._oVar1 = val; - if (random(150, 2)) { + if (random_(150, 2)) { object[i]._oAnimFrame = 12; object[i]._oAnimLen = 22; } @@ -1206,7 +1206,7 @@ void AddTearFountain(int i) void AddDecap(int i) { object[i]._oRndSeed = GetRndSeed(); - object[i]._oAnimFrame = random(151, 8) + 1; + object[i]._oAnimFrame = random_(151, 8) + 1; object[i]._oPreFlag = TRUE; } @@ -1243,7 +1243,7 @@ void AddStoryBook(int i) int bookframe; SetRndSeed(glSeedTbl[16]); - bookframe = random(0, 3); + bookframe = random_(0, 3); object[i]._oVar1 = bookframe; if (currlevel == 4) @@ -1269,7 +1269,7 @@ void AddWeaponRack(int i) void AddTorturedBody(int i) { object[i]._oRndSeed = GetRndSeed(); - object[i]._oAnimFrame = random(0, 4) + 1; + object[i]._oAnimFrame = random_(0, 4) + 1; object[i]._oPreFlag = TRUE; } @@ -1286,8 +1286,8 @@ void GetRndObjLoc(int randarea, int *xx, int *yy) tries++; if (tries > 1000 && randarea > 1) randarea--; - *xx = random(0, MAXDUNX); - *yy = random(0, MAXDUNY); + *xx = random_(0, MAXDUNX); + *yy = random_(0, MAXDUNY); failed = FALSE; for (i = 0; i < randarea && !failed; i++) { for (j = 0; j < randarea && !failed; j++) { @@ -2824,7 +2824,7 @@ void TryDisarm(int pnum, int i) SetCursor_(CURSOR_HAND); if (object[i]._oTrapFlag) { trapdisper = 2 * plr[pnum]._pDexterity - 5 * currlevel; - if (random(154, 100) <= trapdisper) { + if (random_(154, 100) <= trapdisper) { for (j = 0; j < nobjects; j++) { checkflag = FALSE; oi = objectactive[j]; @@ -2897,7 +2897,7 @@ void OperateShrine(int pnum, int i, int sType) ModifyPlrMag(pnum, -1); ModifyPlrDex(pnum, -1); ModifyPlrVit(pnum, -1); - switch (random(0, 4)) { + switch (random_(0, 4)) { case 0: ModifyPlrStr(pnum, 6); break; @@ -2945,7 +2945,7 @@ void OperateShrine(int pnum, int i, int sType) } if (cnt == 0) break; - r = random(0, 7); + r = random_(0, 7); if (plr[pnum].InvBody[r]._itype == -1 || plr[pnum].InvBody[r]._iMaxDur == DUR_INDESTRUCTIBLE || plr[pnum].InvBody[r]._iMaxDur == 0) continue; @@ -3109,7 +3109,7 @@ void OperateShrine(int pnum, int i, int sType) spell <<= 1; } do { - r = random(0, 37); + r = random_(0, 37); } while (!(plr[pnum]._pMemSpells & ((__int64)1 << r))); if (plr[pnum]._pSplLvl[r] >= 2) plr[pnum]._pSplLvl[r] -= 2; @@ -3259,8 +3259,8 @@ void OperateShrine(int pnum, int i, int sType) return; j = 0; do { - xx = random(159, MAXDUNX); - yy = random(159, MAXDUNY); + xx = random_(159, MAXDUNX); + yy = random_(159, MAXDUNY); j++; if (j > MAXDUNX * 112) break; @@ -3303,7 +3303,7 @@ void OperateShrine(int pnum, int i, int sType) return; for (j = 0; j < NUM_INV_GRID_ELEM; j++) { if (!plr[pnum].InvGrid[j]) { - r = 5 * leveltype + random(160, 10 * leveltype); + r = 5 * leveltype + random_(160, 10 * leveltype); t = plr[pnum]._pNumInv; // check plr[pnum].InvList[t] = golditem; plr[pnum].InvList[t]._iSeed = GetRndSeed(); @@ -3425,7 +3425,7 @@ void OperateShrine(int pnum, int i, int sType) InitDiabloMsg(EMSG_SHRINE_TAINTED1); } else { InitDiabloMsg(EMSG_SHRINE_TAINTED2); - r = random(155, 4); + r = random_(155, 4); if (r != 0) v1 = -1; @@ -3470,7 +3470,7 @@ void OperateSkelBook(int pnum, int i, BOOL sendmsg) object[i]._oSelFlag = 0; if (!deltaload) { SetRndSeed(object[i]._oRndSeed); - if (random(161, 5)) + if (random_(161, 5)) CreateTypeItem(object[i]._ox, object[i]._oy, 0, ITYPE_MISC, 21, sendmsg, 0); else CreateTypeItem(object[i]._ox, object[i]._oy, 0, ITYPE_MISC, 24, sendmsg, 0); @@ -3527,7 +3527,7 @@ void OperateArmorStand(int pnum, int i, BOOL sendmsg) object[i]._oSelFlag = 0; if (!deltaload) { SetRndSeed(object[i]._oRndSeed); - uniqueRnd = random(0, 2); + uniqueRnd = random_(0, 2); if (currlevel <= 5) { CreateTypeItem(object[i]._ox, object[i]._oy, 1, ITYPE_LARMOR, 0, sendmsg, 0); } else if (currlevel >= 6 && currlevel <= 9) { @@ -3552,7 +3552,7 @@ int FindValidShrine(int i) while (1) { done = FALSE; while (!done) { - rv = random(0, 26); + rv = random_(0, 26); if (currlevel >= shrinemin[rv] && currlevel <= shrinemax[rv] && rv != 8) done = TRUE; } @@ -3674,7 +3674,7 @@ BOOL OperateFountains(int pnum, int i) if (pnum != myplr) return FALSE; while (!done) { - rnd = random(0, 4); + rnd = random_(0, 4); if (rnd != prev) { switch (rnd) { case 0: @@ -3717,7 +3717,7 @@ void OperateWeaponRack(int pnum, int i, BOOL sendmsg) return; SetRndSeed(object[i]._oRndSeed); - switch (random(0, 4) + 1) { + switch (random_(0, 4) + 1) { case ITYPE_SWORD: weaponType = ITYPE_SWORD; break; @@ -4152,7 +4152,7 @@ void BreakObject(int pnum, int oi) if (pnum != -1) { mind = plr[pnum]._pIMinDam; - maxd = random(163, plr[pnum]._pIMaxDam - mind + 1); + maxd = random_(163, plr[pnum]._pIMaxDam - mind + 1); objdam = maxd + mind; objdam += plr[pnum]._pDamageMod + plr[pnum]._pIBonusDamMod + objdam * plr[pnum]._pIBonusDam / 100; } else { diff --git a/Source/palette.cpp b/Source/palette.cpp index f4b21fd75..ed294c412 100644 --- a/Source/palette.cpp +++ b/Source/palette.cpp @@ -118,7 +118,7 @@ void LoadRndLvlPal(int l) if (l == DTYPE_TOWN) { LoadPalette("Levels\\TownData\\Town.pal"); } else { - rv = random(0, 4) + 1; + rv = random_(0, 4) + 1; sprintf(szFileName, "Levels\\L%iData\\L%i_%i.PAL", l, l, rv); LoadPalette(szFileName); } diff --git a/Source/player.cpp b/Source/player.cpp index d45867159..4ce8d5f3e 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -862,8 +862,8 @@ void InitPlayer(int pnum, BOOL FirstTime) if (plr[pnum]._pHitPoints >> 6 > 0) { plr[pnum]._pmode = PM_STAND; NewPlrAnim(pnum, plr[pnum]._pNAnim[DIR_S], plr[pnum]._pNFrames, 3, plr[pnum]._pNWidth); - plr[pnum]._pAnimFrame = random(2, plr[pnum]._pNFrames - 1) + 1; - plr[pnum]._pAnimCnt = random(2, 3); + plr[pnum]._pAnimFrame = random_(2, plr[pnum]._pNFrames - 1) + 1; + plr[pnum]._pAnimCnt = random_(2, 3); } else { plr[pnum]._pmode = PM_DEATH; NewPlrAnim(pnum, plr[pnum]._pDAnim[DIR_S], plr[pnum]._pDFrames, 1, plr[pnum]._pDWidth); @@ -2261,7 +2261,7 @@ BOOL WeaponDur(int pnum, int durrnd) return FALSE; } - if (random(3, durrnd) != 0) { + if (random_(3, durrnd) != 0) { return FALSE; } @@ -2355,7 +2355,7 @@ BOOL PlrHitMonst(int pnum, int m) rv = FALSE; - hit = random(4, 100); + hit = random_(4, 100); if (monster[m]._mmode == MM_STONE) { hit = 0; } @@ -2383,12 +2383,12 @@ BOOL PlrHitMonst(int pnum, int m) #endif mind = plr[pnum]._pIMinDam; maxd = plr[pnum]._pIMaxDam; - dam = random(5, maxd - mind + 1) + mind; + dam = random_(5, maxd - mind + 1) + mind; dam += dam * plr[pnum]._pIBonusDam / 100; dam += plr[pnum]._pDamageMod + plr[pnum]._pIBonusDamMod; if (plr[pnum]._pClass == PC_WARRIOR) { ddp = plr[pnum]._pLevel; - if (random(6, 100) < ddp) { + if (random_(6, 100) < ddp) { dam *= 2; } } @@ -2430,7 +2430,7 @@ BOOL PlrHitMonst(int pnum, int m) } if (plr[pnum]._pIFlags & ISPL_RNDSTEALLIFE) { - skdam = random(7, dam >> 3); + skdam = random_(7, dam >> 3); plr[pnum]._pHitPoints += skdam; if (plr[pnum]._pHitPoints > plr[pnum]._pMaxHP) { plr[pnum]._pHitPoints = plr[pnum]._pMaxHP; @@ -2530,7 +2530,7 @@ BOOL PlrHitPlr(int pnum, char p) app_fatal("PlrHitPlr: illegal attacking player %d", pnum); } - hit = random(4, 100); + hit = random_(4, 100); hper = (plr[pnum]._pDexterity >> 1) + plr[pnum]._pLevel + 50 - (plr[p]._pIBonusAC + plr[p]._pIAC + plr[p]._pDexterity / 5); @@ -2546,7 +2546,7 @@ BOOL PlrHitPlr(int pnum, char p) } if ((plr[p]._pmode == PM_STAND || plr[p]._pmode == PM_ATTACK) && plr[p]._pBlockFlag) { - blk = random(5, 100); + blk = random_(5, 100); } else { blk = 100; } @@ -2565,19 +2565,19 @@ BOOL PlrHitPlr(int pnum, char p) StartPlrBlock(p, dir); } else { mind = plr[pnum]._pIMinDam; - maxd = random(5, plr[pnum]._pIMaxDam - mind + 1); + maxd = random_(5, plr[pnum]._pIMaxDam - mind + 1); dam = maxd + mind; dam += plr[pnum]._pDamageMod + plr[pnum]._pIBonusDamMod + dam * plr[pnum]._pIBonusDam / 100; if (plr[pnum]._pClass == PC_WARRIOR) { lvl = plr[pnum]._pLevel; - if (random(6, 100) < lvl) { + if (random_(6, 100) < lvl) { dam *= 2; } } skdam = dam << 6; if (plr[pnum]._pIFlags & ISPL_RNDSTEALLIFE) { - tac = random(7, skdam >> 3); + tac = random_(7, skdam >> 3); plr[pnum]._pHitPoints += tac; if (plr[pnum]._pHitPoints > plr[pnum]._pMaxHP) { plr[pnum]._pHitPoints = plr[pnum]._pMaxHP; @@ -2808,7 +2808,7 @@ BOOL PM_DoBlock(int pnum) StartStand(pnum, plr[pnum]._pdir); ClearPlrPVars(pnum); - if (!random(3, 10)) { + if (!random_(3, 10)) { ShieldDur(pnum); } return TRUE; @@ -2894,7 +2894,7 @@ BOOL PM_DoGotHit(int pnum) if (plr[pnum]._pAnimFrame >= plr[pnum]._pHFrames) { StartStand(pnum, plr[pnum]._pdir); ClearPlrPVars(pnum); - if (random(3, 4)) { + if (random_(3, 4)) { ArmorDur(pnum); } @@ -2923,7 +2923,7 @@ void ArmorDur(int pnum) return; } - a = random(8, 3); + a = random_(8, 3); if (p->InvBody[INVLOC_CHEST]._itype != ITYPE_NONE && p->InvBody[INVLOC_HEAD]._itype == ITYPE_NONE) { a = 1; } diff --git a/Source/quests.cpp b/Source/quests.cpp index e0a60344d..ca0ec2249 100644 --- a/Source/quests.cpp +++ b/Source/quests.cpp @@ -101,15 +101,15 @@ void InitQuests() if (gbMaxPlayers == 1) { SetRndSeed(glSeedTbl[15]); - if (random(0, 2)) + if (random_(0, 2)) quests[QTYPE_PW]._qactive = 0; else quests[QTYPE_KING]._qactive = 0; - quests[QuestGroup1[random(0, sizeof(QuestGroup1) / sizeof(int))]]._qactive = 0; - quests[QuestGroup2[random(0, sizeof(QuestGroup2) / sizeof(int))]]._qactive = 0; - quests[QuestGroup3[random(0, sizeof(QuestGroup3) / sizeof(int))]]._qactive = 0; - quests[QuestGroup4[random(0, sizeof(QuestGroup4) / sizeof(int))]]._qactive = 0; + quests[QuestGroup1[random_(0, sizeof(QuestGroup1) / sizeof(int))]]._qactive = 0; + quests[QuestGroup2[random_(0, sizeof(QuestGroup2) / sizeof(int))]]._qactive = 0; + quests[QuestGroup3[random_(0, sizeof(QuestGroup3) / sizeof(int))]]._qactive = 0; + quests[QuestGroup4[random_(0, sizeof(QuestGroup4) / sizeof(int))]]._qactive = 0; } #ifdef _DEBUG if (questdebug != -1) diff --git a/Source/spells.cpp b/Source/spells.cpp index bedadaaf8..3cf248f58 100644 --- a/Source/spells.cpp +++ b/Source/spells.cpp @@ -247,14 +247,14 @@ void DoHealOther(int pnum, int rid) } if ((char)rid != -1 && (plr[rid]._pHitPoints >> 6) > 0) { - hp = (random(57, 10) + 1) << 6; + hp = (random_(57, 10) + 1) << 6; for (i = 0; i < plr[pnum]._pLevel; i++) { - hp += (random(57, 4) + 1) << 6; + hp += (random_(57, 4) + 1) << 6; } for (j = 0; j < GetSpellLevel(pnum, SPL_HEALOTHER); ++j) { - hp += (random(57, 6) + 1) << 6; + hp += (random_(57, 6) + 1) << 6; } if (plr[pnum]._pClass == PC_WARRIOR) { diff --git a/Source/stores.cpp b/Source/stores.cpp index 2e25fe735..3e7a9b6f3 100644 --- a/Source/stores.cpp +++ b/Source/stores.cpp @@ -2607,7 +2607,7 @@ void S_TalkEnter() if (stextsel == sn - 2) { SetRndSeed(towner[talker]._tSeed); - tq = gossipstart + random(0, gossipend - gossipstart + 1); + tq = gossipstart + random_(0, gossipend - gossipstart + 1); InitQTextMsg(tq); return; } diff --git a/Source/themes.cpp b/Source/themes.cpp index cbc333d6b..173c998c6 100644 --- a/Source/themes.cpp +++ b/Source/themes.cpp @@ -100,7 +100,7 @@ BOOL TFit_Obj5(int t) xp = 0; yp = 0; - r = random(0, 5) + 1; + r = random_(0, 5) + 1; rs = r; while (r > 0) { found = FALSE; @@ -185,7 +185,7 @@ BOOL CheckThemeObj3(int xp, int yp, int t, int f) return FALSE; if (dObject[xp + trm3x[i]][yp + trm3y[i]]) return FALSE; - if (f != -1 && !random(0, f)) + if (f != -1 && !random_(0, f)) return FALSE; } @@ -413,7 +413,7 @@ void InitThemes() for (i = 0; i < 256 && numthemes < MAXTHEMES; i++) { if (CheckThemeRoom(i)) { themes[numthemes].ttval = i; - for (j = ThemeGood[random(0, 4)];; j = random(0, 17)) { + for (j = ThemeGood[random_(0, 4)];; j = random_(0, 17)) { if (SpecialThemeFit(numthemes, j)) { break; } @@ -439,7 +439,7 @@ void InitThemes() for (i = 0; i < themeCount; i++) { if (themes[i].ttype == THEME_NONE) { themes[i].ttval = themeLoc[i].ttval; - for (j = ThemeGood[random(0, 4)];; j = random(0, 17)) { + for (j = ThemeGood[random_(0, 4)];; j = random_(0, 17)) { if (SpecialThemeFit(i, j)) { break; } @@ -493,12 +493,12 @@ void PlaceThemeMonsts(int t, int f) numscattypes++; } } - mtype = scattertypes[random(0, numscattypes)]; + mtype = scattertypes[random_(0, numscattypes)]; for (yp = 0; yp < MAXDUNY; yp++) { for (xp = 0; xp < MAXDUNX; xp++) { if (dTransVal[xp][yp] == themes[t].ttval && !nSolidTable[dPiece[xp][yp]] && dItem[xp][yp] == 0 && dObject[xp][yp] == 0) { - if (random(0, f) == 0) { - AddMonster(xp, yp, random(0, 8), mtype, 1); + if (random_(0, f) == 0) { + AddMonster(xp, yp, random_(0, 8), mtype, 1); } } } @@ -518,8 +518,8 @@ void Theme_Barrel(int t) for (yp = 0; yp < MAXDUNY; yp++) { for (xp = 0; xp < MAXDUNX; xp++) { if (dTransVal[xp][yp] == themes[t].ttval && !nSolidTable[dPiece[xp][yp]]) { - if (random(0, barrnd[leveltype - 1]) == 0) { - if (random(0, barrnd[leveltype - 1]) == 0) { + if (random_(0, barrnd[leveltype - 1]) == 0) { + if (random_(0, barrnd[leveltype - 1]) == 0) { r = OBJ_BARREL; } else { r = OBJ_BARRELEX; @@ -563,7 +563,7 @@ void Theme_MonstPit(int t) int ixp, iyp; char monstrnd[4] = { 6, 7, 3, 9 }; - r = random(0, 100) + 1; + r = random_(0, 100) + 1; ixp = 0; iyp = 0; if (r > 0) { @@ -605,7 +605,7 @@ void Theme_SkelRoom(int t) AddObject(OBJ_SKFIRE, xp, yp); - if (random(0, monstrnd[leveltype - 1]) != 0) { + if (random_(0, monstrnd[leveltype - 1]) != 0) { i = PreSpawnSkeleton(); SpawnSkeleton(i, xp - 1, yp - 1); } else { @@ -615,25 +615,25 @@ void Theme_SkelRoom(int t) i = PreSpawnSkeleton(); SpawnSkeleton(i, xp, yp - 1); - if (random(0, monstrnd[leveltype - 1]) != 0) { + if (random_(0, monstrnd[leveltype - 1]) != 0) { i = PreSpawnSkeleton(); SpawnSkeleton(i, xp + 1, yp - 1); } else { AddObject(OBJ_BANNERR, xp + 1, yp - 1); } - if (random(0, monstrnd[leveltype - 1]) != 0) { + if (random_(0, monstrnd[leveltype - 1]) != 0) { i = PreSpawnSkeleton(); SpawnSkeleton(i, xp - 1, yp); } else { AddObject(OBJ_BANNERM, xp - 1, yp); } - if (random(0, monstrnd[leveltype - 1]) != 0) { + if (random_(0, monstrnd[leveltype - 1]) != 0) { i = PreSpawnSkeleton(); SpawnSkeleton(i, xp + 1, yp); } else { AddObject(OBJ_BANNERM, xp + 1, yp); } - if (random(0, monstrnd[leveltype - 1]) != 0) { + if (random_(0, monstrnd[leveltype - 1]) != 0) { i = PreSpawnSkeleton(); SpawnSkeleton(i, xp - 1, yp + 1); } else { @@ -643,7 +643,7 @@ void Theme_SkelRoom(int t) i = PreSpawnSkeleton(); SpawnSkeleton(i, xp, yp + 1); - if (random(0, monstrnd[leveltype - 1]) != 0) { + if (random_(0, monstrnd[leveltype - 1]) != 0) { i = PreSpawnSkeleton(); SpawnSkeleton(i, xp + 1, yp + 1); } else { @@ -673,9 +673,9 @@ void Theme_Treasure(int t) for (yp = 0; yp < MAXDUNY; yp++) { for (xp = 0; xp < MAXDUNX; xp++) { if (dTransVal[xp][yp] == themes[t].ttval && !nSolidTable[dPiece[xp][yp]]) { - int rv = random(0, treasrnd[leveltype - 1]); - // BUGFIX: the `2*` in `2*random(0, treasrnd...) == 0` has no effect, should probably be `random(0, 2*treasrnd...) == 0` - if ((2 * random(0, treasrnd[leveltype - 1])) == 0) { + int rv = random_(0, treasrnd[leveltype - 1]); + // BUGFIX: the `2*` in `2*random_(0, treasrnd...) == 0` has no effect, should probably be `random_(0, 2*treasrnd...) == 0` + if ((2 * random_(0, treasrnd[leveltype - 1])) == 0) { CreateTypeItem(xp, yp, FALSE, ITYPE_GOLD, IMISC_NONE, FALSE, TRUE); ItemNoFlippy(); } @@ -719,9 +719,9 @@ void Theme_Library(int t) for (yp = 1; yp < MAXDUNY - 1; yp++) { for (xp = 1; xp < MAXDUNX - 1; xp++) { - if (CheckThemeObj3(xp, yp, t, -1) && dMonster[xp][yp] == 0 && random(0, librnd[leveltype - 1]) == 0) { + if (CheckThemeObj3(xp, yp, t, -1) && dMonster[xp][yp] == 0 && random_(0, librnd[leveltype - 1]) == 0) { AddObject(OBJ_BOOKSTAND, xp, yp); - if (random(0, 2 * librnd[leveltype - 1]) != 0) { + if (random_(0, 2 * librnd[leveltype - 1]) != 0) { oi = dObject[xp][yp] - 1; object[oi]._oSelFlag = 0; object[oi]._oAnimFrame += 2; @@ -754,7 +754,7 @@ void Theme_Torture(int t) for (xp = 1; xp < MAXDUNX - 1; xp++) { if (dTransVal[xp][yp] == themes[t].ttval && !nSolidTable[dPiece[xp][yp]]) { if (CheckThemeObj3(xp, yp, t, -1)) { - if (random(0, tortrnd[leveltype - 1]) == 0) { + if (random_(0, tortrnd[leveltype - 1]) == 0) { AddObject(OBJ_TNUDEM2, xp, yp); } } @@ -791,7 +791,7 @@ void Theme_Decap(int t) for (xp = 1; xp < MAXDUNX - 1; xp++) { if (dTransVal[xp][yp] == themes[t].ttval && !nSolidTable[dPiece[xp][yp]]) { if (CheckThemeObj3(xp, yp, t, -1)) { - if (random(0, decaprnd[leveltype - 1]) == 0) { + if (random_(0, decaprnd[leveltype - 1]) == 0) { AddObject(OBJ_DECAP, xp, yp); } } @@ -832,7 +832,7 @@ void Theme_ArmorStand(int t) for (xp = 0; xp < MAXDUNX; xp++) { if (dTransVal[xp][yp] == themes[t].ttval && !nSolidTable[dPiece[xp][yp]]) { if (CheckThemeObj3(xp, yp, t, -1)) { - if (random(0, armorrnd[leveltype - 1]) == 0) { + if (random_(0, armorrnd[leveltype - 1]) == 0) { AddObject(OBJ_ARMORSTANDN, xp, yp); } } @@ -915,7 +915,7 @@ void Theme_BrnCross(int t) for (xp = 0; xp < MAXDUNX; xp++) { if (dTransVal[xp][yp] == themes[t].ttval && !nSolidTable[dPiece[xp][yp]]) { if (CheckThemeObj3(xp, yp, t, -1)) { - if (random(0, bcrossrnd[leveltype - 1]) == 0) { + if (random_(0, bcrossrnd[leveltype - 1]) == 0) { AddObject(OBJ_TBCROSS, xp, yp); } } @@ -944,7 +944,7 @@ void Theme_WeaponRack(int t) for (xp = 0; xp < MAXDUNX; xp++) { if (dTransVal[xp][yp] == themes[t].ttval && !nSolidTable[dPiece[xp][yp]]) { if (CheckThemeObj3(xp, yp, t, -1)) { - if (random(0, weaponrnd[leveltype - 1]) == 0) { + if (random_(0, weaponrnd[leveltype - 1]) == 0) { AddObject(OBJ_WEAPONRACKN, xp, yp); } } diff --git a/Source/town.cpp b/Source/town.cpp index eb5cb9693..5c6d9b5c9 100644 --- a/Source/town.cpp +++ b/Source/town.cpp @@ -1464,7 +1464,7 @@ void T_Pass3() if (!(plr[myplr].pTownWarps & 4)) { #endif for (x = 36; x < 46; x++) { - T_FillTile(P3Tiles, x, 78, random(0, 4) + 1); + T_FillTile(P3Tiles, x, 78, random_(0, 4) + 1); } #ifndef SPAWN } diff --git a/Source/towners.cpp b/Source/towners.cpp index 3ff09d6c9..97b375366 100644 --- a/Source/towners.cpp +++ b/Source/towners.cpp @@ -355,7 +355,7 @@ void InitCows() SetTownerGPtrs(towner[numtowners]._tNData, towner[numtowners]._tNAnim); towner[numtowners]._tNFrames = 12; NewTownerAnim(numtowners, towner[numtowners]._tNAnim[dir], towner[numtowners]._tNFrames, 3); - towner[numtowners]._tAnimFrame = random(0, 11) + 1; + towner[numtowners]._tAnimFrame = random_(0, 11) + 1; towner[numtowners]._tSelFlag = 1; strcpy(towner[numtowners]._tName, "Cow"); @@ -594,9 +594,9 @@ void TalkToTowner(int p, int t) int i, dx, dy, rv1, rv2, rv3; ItemStruct *Item; - rv1 = random(6, 3); /* unused */ - rv2 = random(6, 4); /* unused */ - rv3 = random(6, 5); /* unused */ + rv1 = random_(6, 3); /* unused */ + rv2 = random_(6, 4); /* unused */ + rv3 = random_(6, 5); /* unused */ dx = abs(plr[p].WorldX - towner[t]._tx); dy = abs(plr[p].WorldY - towner[t]._ty); From 2348c3a8fdff09f407323189d5e5d45dfc657cc1 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Mon, 21 Oct 2019 00:51:47 +0200 Subject: [PATCH 07/13] Documentations, enums and clean ups --- Source/control.cpp | 10 +- Source/cursor.cpp | 2 +- Source/diablo.cpp | 3 + Source/drlg_l1.cpp | 4 +- Source/drlg_l2.cpp | 4 +- Source/drlg_l3.cpp | 4 +- Source/drlg_l4.cpp | 4 +- Source/gmenu.cpp | 2 +- Source/inv.cpp | 13 +- Source/minitext.cpp | 5 +- Source/quests.cpp | 2 +- Source/render.cpp | 4 + Source/scrollrt.cpp | 335 +++++++++++++++++++++++++++++++++++++------- Source/scrollrt.h | 6 +- Source/stores.cpp | 2 +- Source/town.cpp | 217 +++++++++++++++++++++++----- Source/town.h | 12 +- 17 files changed, 521 insertions(+), 108 deletions(-) diff --git a/Source/control.cpp b/Source/control.cpp index b163d31db..6ccc3929a 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -18,7 +18,7 @@ BOOL drawmanaflag; BOOL chrbtnactive; char sgszTalkMsg[MAX_SEND_STR_LEN]; BYTE *pPanelText; -int nGoldFrame; +int nGoldFrame; /** current frame # for the pentagram caret in gold input */ BYTE *pLifeBuff; BYTE *pBtmBuff; BYTE *pTalkBtns; @@ -36,7 +36,7 @@ char tempstr[256]; BOOLEAN whisper[MAX_PLRS]; int sbooktab; int pSplType; -int frame; +int frame; /** current frame # for the pentagram caret in chat input */ int initialDropGoldIndex; BOOL talkflag; BYTE *pSBkIconCels; @@ -947,6 +947,9 @@ void DrawPanelBox(int x, int y, int w, int h, int sx, int sy) #endif } +/** + * Draws parts of the flasks that are on the panel + */ void SetFlaskHeight(BYTE *pCelBuff, int min, int max, int c, int r) { int nSrcOff, nDstOff, w; @@ -982,6 +985,9 @@ void SetFlaskHeight(BYTE *pCelBuff, int min, int max, int c, int r) #endif } +/** + * Draws parts of the flasks that are above the panel + */ void DrawFlask(BYTE *pCelBuff, int w, int nSrcOff, BYTE *pBuff, int nDstOff, int h) { #ifdef USE_ASM diff --git a/Source/cursor.cpp b/Source/cursor.cpp index d04284aac..adc9075e7 100644 --- a/Source/cursor.cpp +++ b/Source/cursor.cpp @@ -226,7 +226,7 @@ void CheckCursMove() mx = ViewX + tx + ty - (zoomflag ? 10 : 5); my = ViewY + ty - tx; - flipy = py> 1; + flipy = py < (px >> 1); if (flipy) { my--; } diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 25e5a6b28..010a976e7 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -1538,6 +1538,9 @@ void LoadAllGFX() IncProgress(); } +/** + * @param lvldir method of entry + */ void CreateLevel(int lvldir) { switch (leveltype) { diff --git a/Source/drlg_l1.cpp b/Source/drlg_l1.cpp index ad87c7f06..d8150f5d6 100644 --- a/Source/drlg_l1.cpp +++ b/Source/drlg_l1.cpp @@ -419,7 +419,7 @@ static void DRLG_L1Pass3() mov v4, eax } #else - v1 = *((WORD *)&pMegaTiles[lv * 8]) + 1; + v1 = *((WORD *)&pMegaTiles[lv * 8] + 0) + 1; v2 = *((WORD *)&pMegaTiles[lv * 8] + 1) + 1; v3 = *((WORD *)&pMegaTiles[lv * 8] + 2) + 1; v4 = *((WORD *)&pMegaTiles[lv * 8] + 3) + 1; @@ -462,7 +462,7 @@ static void DRLG_L1Pass3() mov v4, eax } #else - v1 = *((WORD *)&pMegaTiles[lv * 8]) + 1; + v1 = *((WORD *)&pMegaTiles[lv * 8] + 0) + 1; v2 = *((WORD *)&pMegaTiles[lv * 8] + 1) + 1; v3 = *((WORD *)&pMegaTiles[lv * 8] + 2) + 1; v4 = *((WORD *)&pMegaTiles[lv * 8] + 3) + 1; diff --git a/Source/drlg_l2.cpp b/Source/drlg_l2.cpp index 4dc79a77d..137132e6c 100644 --- a/Source/drlg_l2.cpp +++ b/Source/drlg_l2.cpp @@ -446,7 +446,7 @@ void DRLG_L2Pass3() mov v4, eax } #else - v1 = *((WORD *)&pMegaTiles[lv * 8]) + 1; + v1 = *((WORD *)&pMegaTiles[lv * 8] + 0) + 1; v2 = *((WORD *)&pMegaTiles[lv * 8] + 1) + 1; v3 = *((WORD *)&pMegaTiles[lv * 8] + 2) + 1; v4 = *((WORD *)&pMegaTiles[lv * 8] + 3) + 1; @@ -488,7 +488,7 @@ void DRLG_L2Pass3() mov v4, eax } #else - v1 = *((WORD *)&pMegaTiles[lv * 8]) + 1; + v1 = *((WORD *)&pMegaTiles[lv * 8] + 0) + 1; v2 = *((WORD *)&pMegaTiles[lv * 8] + 1) + 1; v3 = *((WORD *)&pMegaTiles[lv * 8] + 2) + 1; v4 = *((WORD *)&pMegaTiles[lv * 8] + 3) + 1; diff --git a/Source/drlg_l3.cpp b/Source/drlg_l3.cpp index ab7e8647c..b88161c24 100644 --- a/Source/drlg_l3.cpp +++ b/Source/drlg_l3.cpp @@ -1633,7 +1633,7 @@ static void DRLG_L3Pass3() mov v4, eax } #else - v1 = *((WORD *)&pMegaTiles[lv * 8]) + 1; + v1 = *((WORD *)&pMegaTiles[lv * 8] + 0) + 1; v2 = *((WORD *)&pMegaTiles[lv * 8] + 1) + 1; v3 = *((WORD *)&pMegaTiles[lv * 8] + 2) + 1; v4 = *((WORD *)&pMegaTiles[lv * 8] + 3) + 1; @@ -1683,7 +1683,7 @@ static void DRLG_L3Pass3() } #else if (lv >= 0) { - v1 = *((WORD *)&pMegaTiles[lv * 8]) + 1; + v1 = *((WORD *)&pMegaTiles[lv * 8] + 0) + 1; v2 = *((WORD *)&pMegaTiles[lv * 8] + 1) + 1; v3 = *((WORD *)&pMegaTiles[lv * 8] + 2) + 1; v4 = *((WORD *)&pMegaTiles[lv * 8] + 3) + 1; diff --git a/Source/drlg_l4.cpp b/Source/drlg_l4.cpp index 68a91dcfc..d41eeaf4f 100644 --- a/Source/drlg_l4.cpp +++ b/Source/drlg_l4.cpp @@ -1902,7 +1902,7 @@ static void DRLG_L4Pass3() mov v4, eax } #else - v1 = *((WORD *)&pMegaTiles[lv * 8]) + 1; + v1 = *((WORD *)&pMegaTiles[lv * 8] + 0) + 1; v2 = *((WORD *)&pMegaTiles[lv * 8] + 1) + 1; v3 = *((WORD *)&pMegaTiles[lv * 8] + 2) + 1; v4 = *((WORD *)&pMegaTiles[lv * 8] + 3) + 1; @@ -1952,7 +1952,7 @@ static void DRLG_L4Pass3() } #else if (lv >= 0) { - v1 = *((WORD *)&pMegaTiles[lv * 8]) + 1; + v1 = *((WORD *)&pMegaTiles[lv * 8] + 0) + 1; v2 = *((WORD *)&pMegaTiles[lv * 8] + 1) + 1; v3 = *((WORD *)&pMegaTiles[lv * 8] + 2) + 1; v4 = *((WORD *)&pMegaTiles[lv * 8] + 3) + 1; diff --git a/Source/gmenu.cpp b/Source/gmenu.cpp index 39e28b331..b3f92f09b 100644 --- a/Source/gmenu.cpp +++ b/Source/gmenu.cpp @@ -163,7 +163,7 @@ void gmenu_draw() } ticks = GetTickCount(); - if ((int)(ticks - PentSpin_tick) > 25) { + if ((int)(ticks - PentSpin_tick) > 25) { // BUGFIX: thould be 50ms PentSpin_frame++; if (PentSpin_frame == 9) PentSpin_frame = 1; diff --git a/Source/inv.cpp b/Source/inv.cpp index f44644669..4928b7b82 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -426,7 +426,7 @@ void DrawInvBelt() continue; } - InvDrawSlotBack(InvRect[i + SLOTXY_BELT_FIRST].X + 64, InvRect[i + SLOTXY_BELT_FIRST].Y + 159, 28, 28); + InvDrawSlotBack(InvRect[i + SLOTXY_BELT_FIRST].X + SCREEN_X, InvRect[i + SLOTXY_BELT_FIRST].Y + SCREEN_Y - 1, 28, 28); frame = plr[myplr].SpdList[i]._iCurs + CURSOR_FIRSTITEM; frame_width = InvItemWidth[frame]; @@ -436,20 +436,20 @@ void DrawInvBelt() colour = ICOL_BLUE; if (!plr[myplr].SpdList[i]._iStatFlag) colour = ICOL_RED; - CelBlitOutline(colour, InvRect[i + SLOTXY_BELT_FIRST].X + 64, InvRect[i + SLOTXY_BELT_FIRST].Y + 159, pCursCels, frame, frame_width, 0, 8); + CelBlitOutline(colour, InvRect[i + SLOTXY_BELT_FIRST].X + SCREEN_X, InvRect[i + SLOTXY_BELT_FIRST].Y + SCREEN_Y - 1, pCursCels, frame, frame_width, 0, 8); } if (plr[myplr].SpdList[i]._iStatFlag) - CelClippedDraw(InvRect[i + SLOTXY_BELT_FIRST].X + 64, InvRect[i + SLOTXY_BELT_FIRST].Y + 159, pCursCels, frame, frame_width, 0, 8); + CelClippedDraw(InvRect[i + SLOTXY_BELT_FIRST].X + SCREEN_X, InvRect[i + SLOTXY_BELT_FIRST].Y + SCREEN_Y - 1, pCursCels, frame, frame_width, 0, 8); else - CelDrawLightRed(InvRect[i + SLOTXY_BELT_FIRST].X + 64, InvRect[i + SLOTXY_BELT_FIRST].Y + 159, pCursCels, frame, frame_width, 0, 8, 1); + CelDrawLightRed(InvRect[i + SLOTXY_BELT_FIRST].X + SCREEN_X, InvRect[i + SLOTXY_BELT_FIRST].Y + SCREEN_Y - 1, pCursCels, frame, frame_width, 0, 8, 1); if (AllItemsList[plr[myplr].SpdList[i].IDidx].iUsable && plr[myplr].SpdList[i]._iStatFlag && plr[myplr].SpdList[i]._itype != ITYPE_GOLD) { fi = i + 49; ff = fontframe[gbFontTransTbl[fi]]; - CPrintString(InvRect[i + SLOTXY_BELT_FIRST].X + 64 + PitchTbl[InvRect[i + SLOTXY_BELT_FIRST].Y + 159] - fontkern[ff] + 28, ff, 0); + CPrintString(InvRect[i + SLOTXY_BELT_FIRST].X + SCREEN_X + PitchTbl[InvRect[i + SLOTXY_BELT_FIRST].Y + SCREEN_Y - 1] - fontkern[ff] + 28, ff, 0); } } } @@ -1354,6 +1354,9 @@ void CheckInvItem() } } +/** + * Check for interactions with belt + */ void CheckInvScrn() { if (MouseX > 190 && MouseX < 437 diff --git a/Source/minitext.cpp b/Source/minitext.cpp index 194db7ec1..e7adc0f5e 100644 --- a/Source/minitext.cpp +++ b/Source/minitext.cpp @@ -35,6 +35,9 @@ const BYTE mfontkern[56] = { /* data */ +/** + * Positive numbers will delay scrolling 1 out of n frames, negative numbers will scroll 1+(-n) pixels. + */ int qscroll_spd_tbl[9] = { 2, 4, 6, 8, 0, -1, -2, -3, -4 }; void FreeQuestText() @@ -57,7 +60,7 @@ void InitQTextMsg(int m) qtextptr = alltext[m].txtstr; qtextflag = TRUE; qtexty = 500; - sgLastScroll = qscroll_spd_tbl[alltext[m].txtspd - 1]; /* double check offset */ + sgLastScroll = qscroll_spd_tbl[alltext[m].txtspd - 1]; scrolltexty = sgLastScroll; qtextSpd = GetTickCount(); } diff --git a/Source/quests.cpp b/Source/quests.cpp index ca0ec2249..bc83ade9b 100644 --- a/Source/quests.cpp +++ b/Source/quests.cpp @@ -11,7 +11,7 @@ int WaterDone; int ReturnLvlY; int ReturnLvlX; int ReturnLvlT; -int ALLQUESTS; +int ALLQUESTS; /** current frame # for the pentagram selector */ int ReturnLvl; QuestData questlist[MAXQUESTS] = { diff --git a/Source/render.cpp b/Source/render.cpp index fae2d3138..bf740a637 100644 --- a/Source/render.cpp +++ b/Source/render.cpp @@ -5191,6 +5191,10 @@ void drawLowerScreen(BYTE *pBuff) } } +/** + * @brief Render a black tile + * @param pBuff pointer where to render the tile + */ void world_draw_black_tile(BYTE *pBuff) { BYTE *dst; diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index 1b331dfe5..63078c524 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -66,6 +66,9 @@ void ClearCursor() // CODE_FIX: this was supposed to be in cursor.cpp sgdwCursWdtOld = 0; } +/** + * @brief Remove the cursor from the backbuffer + */ static void scrollrt_draw_cursor_back_buffer() { int i; @@ -90,6 +93,9 @@ static void scrollrt_draw_cursor_back_buffer() sgdwCursWdt = 0; } +/** + * @brief Draw the cursor on the backbuffer + */ static void scrollrt_draw_cursor_item() { int i, mx, my, col; @@ -164,6 +170,16 @@ static void scrollrt_draw_cursor_item() } } +/** + * @brief Render a missile sprite + * @param x dPice coordinate + * @param y dPice coordinate + * @param sx Backbuffer coordinate + * @param sy Backbuffer coordinate + * @param CelSkip Skip part of sprite, see Cl2Draw + * @param CelCap Skip part of sprite, see Cl2Draw + * @param pre Is the sprite in the background + */ void DrawMissile(int x, int y, int sx, int sy, int CelSkip, int CelCap, BOOL pre) { int i, mx, my, nCel; @@ -225,6 +241,16 @@ void DrawMissile(int x, int y, int sx, int sy, int CelSkip, int CelCap, BOOL pre } } +/** + * @brief Render a missile sprite, check for overdraw on lower screen + * @param x dPice coordinate + * @param y dPice coordinate + * @param sx Backbuffer coordinate + * @param sy Backbuffer coordinate + * @param CelSkip Skip part of sprite, see Cl2Draw + * @param CelCap Skip part of sprite, see Cl2Draw + * @param pre Is the sprite in the background + */ void DrawClippedMissile(int x, int y, int sx, int sy, int CelSkip, int CelCap, BOOL pre) { int i, mx, my, nCel; @@ -286,6 +312,15 @@ void DrawClippedMissile(int x, int y, int sx, int sy, int CelSkip, int CelCap, B } } +/** + * @brief Render a monster sprite + * @param x dPice coordinate + * @param y dPice coordinate + * @param mx Backbuffer coordinate + * @param my Backbuffer coordinate + * @param CelSkip Skip part of sprite, see Cl2Draw + * @param CelCap Skip part of sprite, see Cl2Draw + */ static void DrawMonster(int x, int y, int mx, int my, int m, int CelSkip, int CelCap) { int nCel; @@ -339,6 +374,15 @@ static void DrawMonster(int x, int y, int mx, int my, int m, int CelSkip, int Ce } } +/** + * @brief Render a monster sprite, check for overdraw on lower screen + * @param x dPice coordinate + * @param y dPice coordinate + * @param mx Backbuffer coordinate + * @param my Backbuffer coordinate + * @param CelSkip Skip part of sprite, see Cl2Draw + * @param CelCap Skip part of sprite, see Cl2Draw + */ static void DrawClippedMonster(int x, int y, int mx, int my, int m, int CelSkip, int CelCap) { int nCel; @@ -392,6 +436,19 @@ static void DrawClippedMonster(int x, int y, int mx, int my, int m, int CelSkip, } } +/** + * @brief Render a monster sprite + * @param pnum Player id + * @param x dPice coordinate + * @param y dPice coordinate + * @param px Backbuffer coordinate + * @param py Backbuffer coordinate + * @param pCelBuff sprite buffer + * @param nCel frame + * @param nWidth width + * @param CelSkip Skip part of sprite, see Cl2Draw + * @param CelCap Skip part of sprite, see Cl2Draw + */ static void DrawPlayer(int pnum, int x, int y, int px, int py, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) { int l; @@ -465,6 +522,19 @@ static void DrawPlayer(int pnum, int x, int y, int px, int py, BYTE *pCelBuff, i } } +/** + * @brief Render a monster sprite, check for overdraw on lower screen + * @param pnum Player id + * @param x dPice coordinate + * @param y dPice coordinate + * @param px Backbuffer coordinate + * @param py Backbuffer coordinate + * @param pCelBuff sprite buffer + * @param nCel frame + * @param nWidth width + * @param CelSkip Skip part of sprite, see Cl2Draw + * @param CelCap Skip part of sprite, see Cl2Draw + */ static void DrawClippedPlayer(int pnum, int x, int y, int px, int py, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) { int l; @@ -538,6 +608,16 @@ static void DrawClippedPlayer(int pnum, int x, int y, int px, int py, BYTE *pCel } } +/** + * @brief Render a monster sprite + * @param x dPice coordinate + * @param y dPice coordinate + * @param sx Backbuffer coordinate + * @param sy Backbuffer coordinate + * @param CelSkip Skip part of sprite, see Cl2Draw + * @param CelCap Skip part of sprite, see Cl2Draw + * @param clipped check for overdraw on lower screen + */ void DrawDeadPlayer(int x, int y, int sx, int sy, int CelSkip, int CelCap, BOOL clipped) { int i, px, py, nCel; @@ -574,6 +654,16 @@ void DrawDeadPlayer(int x, int y, int sx, int sy, int CelSkip, int CelCap, BOOL } } +/** + * @brief Render an object sprite + * @param x dPice coordinate + * @param y dPice coordinate + * @param ox Backbuffer coordinate + * @param oy Backbuffer coordinate + * @param pre Is the sprite in the background + * @param CelSkip Skip part of sprite, see Cl2Draw + * @param CelCap Skip part of sprite, see Cl2Draw + */ static void DrawObject(int x, int y, int ox, int oy, BOOL pre, int CelSkip, int CelCap) { int sx, sy, xx, yy, nCel; @@ -627,6 +717,16 @@ static void DrawObject(int x, int y, int ox, int oy, BOOL pre, int CelSkip, int } } +/** + * @brief Render an object sprite, check for overdraw on lower screen + * @param x dPice coordinate + * @param y dPice coordinate + * @param ox Backbuffer coordinate + * @param oy Backbuffer coordinate + * @param pre Is the sprite in the background + * @param CelSkip Skip part of sprite, see Cl2Draw + * @param CelCap Skip part of sprite, see Cl2Draw + */ static void DrawClippedObject(int x, int y, int ox, int oy, BOOL pre, int CelSkip, int CelCap) { int sx, sy, xx, yy, nCel; @@ -679,6 +779,16 @@ static void DrawClippedObject(int x, int y, int ox, int oy, BOOL pre, int CelSki static void scrollrt_draw_clipped_dungeon(BYTE *pBuff, int sx, int sy, int dx, int dy, int eflag); +/** + * This variant checks for of screen element on the lower screen + * This function it self causes rendering issues since it will render on top of objects on the other side of walls + * @brief Re render tile to workaround sorting issues with players walking east/west + * @param pBuff Pointer to output buffer at location sx,sy + * @param y dPiece coordinate + * @param x dPiece coordinate + * @param sx Backbuffer coordinate + * @param sy Backbuffer coordinate + */ static void scrollrt_draw_clipped_e_flag(BYTE *pBuff, int x, int y, int sx, int sy) { int i, lti_old, cta_old, lpi_old; @@ -727,6 +837,15 @@ static void scrollrt_draw_clipped_e_flag(BYTE *pBuff, int x, int y, int sx, int level_piece_id = lpi_old; } +/** + * @brief Render object sprites + * @param pBuff where to render to with sx,sy already applied + * @param sx dPice coordinate + * @param sy dPice coordinate + * @param dx Backbuffer coordinate + * @param dy Backbuffer coordinate + * @param eflag Should the sorting workaround be applied + */ static void scrollrt_draw_clipped_dungeon(BYTE *pBuff, int sx, int sy, int dx, int dy, int eflag) { int px, py, nCel, nMon, negMon, p; @@ -941,6 +1060,15 @@ static void scrollrt_draw_clipped_dungeon(BYTE *pBuff, int sx, int sy, int dx, i } } +/** + * @brief Render a row of tile + * @param x dPice coordinate + * @param y dPice coordinate + * @param sx Backbuffer coordinate + * @param sy Backbuffer coordinate + * @param chunks tile width of row + * @param eflag is it an even (0) or odd (1) row + */ static void scrollrt_draw_lower(int x, int y, int sx, int sy, int chunks, int eflag) { int i, j; @@ -1089,9 +1217,21 @@ static void scrollrt_draw_lower(int x, int y, int sx, int sy, int chunks, int ef } } -static void scrollrt_draw_clipped_dungeon_2(BYTE *pBuff, int sx, int sy, int skipChunks, int CelSkip, int dx, int dy, int eflag); - -static void scrollrt_draw_clipped_e_flag_2(BYTE *pBuff, int x, int y, int skipChunks, int CelSkip, int sx, int sy) +static void scrollrt_draw_clipped_dungeon_2(BYTE *pBuff, int sx, int sy, int row, int CelSkip, int dx, int dy, int eflag); + +/** + * This variant checks for of screen element on the lower screen + * This function it self causes rendering issues since it will render on top of objects on the other side of walls + * @brief Re render tile to workaround sorting issues with players walking east/west + * @param pBuff Pointer to output buffer at location sx,sy + * @param y dPiece coordinate + * @param x dPiece coordinate + * @param row The current row being rendered + * @param CelSkip chunks of cell to skip + * @param sx Backbuffer coordinate + * @param sy Backbuffer coordinate + */ +static void scrollrt_draw_clipped_e_flag_2(BYTE *pBuff, int x, int y, int row, int CelSkip, int sx, int sy) { int lti_old, cta_old, lpi_old; BYTE *dst; @@ -1103,11 +1243,11 @@ static void scrollrt_draw_clipped_e_flag_2(BYTE *pBuff, int x, int y, int skipCh level_piece_id = dPiece[x][y]; light_table_index = dLight[x][y]; - dst = &pBuff[BUFFER_WIDTH * 32 * skipChunks]; + dst = &pBuff[BUFFER_WIDTH * 32 * row]; cel_transparency_active = (BYTE)(nTransTable[level_piece_id] & TransList[dTransVal[x][y]]); pMap = &dpiece_defs_map_1[IsometricCoord(x, y)]; - switch (skipChunks) { + switch (row) { case 0: level_cel_block = pMap->mt[2]; if (level_cel_block != 0) { @@ -1151,7 +1291,7 @@ static void scrollrt_draw_clipped_e_flag_2(BYTE *pBuff, int x, int y, int skipCh } if (CelSkip < 8) { - scrollrt_draw_clipped_dungeon_2(pBuff, x, y, skipChunks, CelSkip, sx, sy, 0); + scrollrt_draw_clipped_dungeon_2(pBuff, x, y, row, CelSkip, sx, sy, 0); } light_table_index = lti_old; @@ -1159,7 +1299,19 @@ static void scrollrt_draw_clipped_e_flag_2(BYTE *pBuff, int x, int y, int skipCh level_piece_id = lpi_old; } -static void scrollrt_draw_clipped_dungeon_2(BYTE *pBuff, int sx, int sy, int skipChunks, int CelSkip, int dx, int dy, int eflag) +/** + * This variant checks for of screen element on the lower screen + * @brief Render object sprites, skip offscreen parts for lower screen + * @param pBuff where to render to with sx,sy already applied + * @param sx dPice coordinate + * @param sy dPice coordinate + * @param row The current row being rendered + * @param CelSkip chunks of cell to skip + * @param dx Backbuffer coordinate + * @param dy Backbuffer coordinate + * @param eflag Should the sorting workaround be applied + */ +static void scrollrt_draw_clipped_dungeon_2(BYTE *pBuff, int sx, int sy, int row, int CelSkip, int dx, int dy, int eflag) { int px, py, nCel, nMon, negMon, p; char bFlag, bDead, bObj, bItem, bPlr, bArch, bMap, negPlr, dd; @@ -1256,9 +1408,9 @@ static void scrollrt_draw_clipped_dungeon_2(BYTE *pBuff, int sx, int sy, int ski DrawClippedPlayer(p, sx, sy - 1, px, py, pPlayer->_pAnimData, pPlayer->_pAnimFrame, pPlayer->_pAnimWidth, CelSkip, 8); if (eflag && pPlayer->_peflag != 0) { if (pPlayer->_peflag == 2) { - scrollrt_draw_clipped_e_flag_2(pBuff - (BUFFER_WIDTH * 16 + 96), sx - 2, sy + 1, skipChunks, CelSkip, dx - 96, dy - 16); + scrollrt_draw_clipped_e_flag_2(pBuff - (BUFFER_WIDTH * 16 + 96), sx - 2, sy + 1, row, CelSkip, dx - 96, dy - 16); } - scrollrt_draw_clipped_e_flag_2(pBuff - 64, sx - 1, sy + 1, skipChunks, CelSkip, dx - 64, dy); + scrollrt_draw_clipped_e_flag_2(pBuff - 64, sx - 1, sy + 1, row, CelSkip, dx - 64, dy); } } else { // app_fatal("draw player clipped: tried to draw illegal player %d", p); @@ -1277,7 +1429,7 @@ static void scrollrt_draw_clipped_dungeon_2(BYTE *pBuff, int sx, int sy, int ski } DrawClippedMonster(sx, sy, px, py, draw_monster_num, CelSkip, 8); if (eflag && !pMonster->_meflag) { - scrollrt_draw_clipped_e_flag_2(pBuff - 64, sx - 1, sy + 1, skipChunks, CelSkip, dx - 64, dy); + scrollrt_draw_clipped_e_flag_2(pBuff - 64, sx - 1, sy + 1, row, CelSkip, dx - 64, dy); } } else { // app_fatal("Draw Monster \"%s\" Clipped: uninitialized monster", pMonster->mName); @@ -1299,9 +1451,9 @@ static void scrollrt_draw_clipped_dungeon_2(BYTE *pBuff, int sx, int sy, int ski DrawClippedPlayer(p, sx, sy, px, py, pPlayer->_pAnimData, pPlayer->_pAnimFrame, pPlayer->_pAnimWidth, CelSkip, 8); if (eflag && pPlayer->_peflag != 0) { if (pPlayer->_peflag == 2) { - scrollrt_draw_clipped_e_flag_2(pBuff - (BUFFER_WIDTH * 16 + 96), sx - 2, sy + 1, skipChunks, CelSkip, dx - 96, dy - 16); + scrollrt_draw_clipped_e_flag_2(pBuff - (BUFFER_WIDTH * 16 + 96), sx - 2, sy + 1, row, CelSkip, dx - 96, dy - 16); } - scrollrt_draw_clipped_e_flag_2(pBuff - 64, sx - 1, sy + 1, skipChunks, CelSkip, dx - 64, dy); + scrollrt_draw_clipped_e_flag_2(pBuff - 64, sx - 1, sy + 1, row, CelSkip, dx - 64, dy); } } else { // app_fatal("draw player clipped: tried to draw illegal player %d", p); @@ -1320,7 +1472,7 @@ static void scrollrt_draw_clipped_dungeon_2(BYTE *pBuff, int sx, int sy, int ski } DrawClippedMonster(sx, sy, px, py, draw_monster_num, CelSkip, 8); if (eflag && !pMonster->_meflag) { - scrollrt_draw_clipped_e_flag_2(pBuff - 64, sx - 1, sy + 1, skipChunks, CelSkip, dx - 64, dy); + scrollrt_draw_clipped_e_flag_2(pBuff - 64, sx - 1, sy + 1, row, CelSkip, dx - 64, dy); } } else { // app_fatal("Draw Monster \"%s\" Clipped: uninitialized monster", pMonster->mName); @@ -1373,7 +1525,17 @@ static void scrollrt_draw_clipped_dungeon_2(BYTE *pBuff, int sx, int sy, int ski } } -static void scrollrt_draw_lower_2(int x, int y, int sx, int sy, int chunks, int skipChunks, int eflag) +/** + * @brief Render a row of tile, checking for overdrawing on lower part of screen + * @param x dPice coordinate + * @param y dPice coordinate + * @param sx Backbuffer coordinate + * @param sy Backbuffer coordinate + * @param chunks tile width of row + * @param row current row being rendered + * @param eflag is it an even (0) or odd (1) row + */ +static void scrollrt_draw_lower_2(int x, int y, int sx, int sy, int chunks, int row, int eflag) { int i, j, CelSkip; BYTE *dst; @@ -1382,7 +1544,7 @@ static void scrollrt_draw_lower_2(int x, int y, int sx, int sy, int chunks, int /// ASSERT: assert(gpBuffer); pMap = &dpiece_defs_map_1[IsometricCoord(x, y)]; - CelSkip = 2 * skipChunks + 2; + CelSkip = 2 * row + 2; if (eflag) { if (y >= 0 && y < MAXDUNY && x >= 0 && x < MAXDUNX) { @@ -1392,7 +1554,7 @@ static void scrollrt_draw_lower_2(int x, int y, int sx, int sy, int chunks, int dst = &gpBuffer[sx - (BUFFER_WIDTH * 32 - 32) + PitchTbl[sy]]; cel_transparency_active = (BYTE)(nTransTable[level_piece_id] & TransList[dTransVal[x][y]]); for (i = 0; i < (MicroTileLen >> 1) - 1; i++) { - if (skipChunks <= i) { + if (row <= i) { level_cel_block = pMap->mt[2 * i + 3]; if (level_cel_block != 0) { drawLowerScreen(dst); @@ -1401,7 +1563,7 @@ static void scrollrt_draw_lower_2(int x, int y, int sx, int sy, int chunks, int dst -= BUFFER_WIDTH * 32; } if (CelSkip < 8) { - scrollrt_draw_clipped_dungeon_2(&gpBuffer[sx + PitchTbl[sy] - BUFFER_WIDTH * 16 * CelSkip], x, y, skipChunks, CelSkip, sx, sy, 0); + scrollrt_draw_clipped_dungeon_2(&gpBuffer[sx + PitchTbl[sy] - BUFFER_WIDTH * 16 * CelSkip], x, y, row, CelSkip, sx, sy, 0); } } } @@ -1425,7 +1587,7 @@ static void scrollrt_draw_lower_2(int x, int y, int sx, int sy, int chunks, int cel_transparency_active = (BYTE)(nTransTable[level_piece_id] & TransList[dTransVal[x][y]]); i = 0; while (i < (MicroTileLen >> 1) - 1) { - if (skipChunks <= i) { + if (row <= i) { level_cel_block = pMap->mt[2 * i + 2]; if (level_cel_block != 0) { drawLowerScreen(dst); @@ -1439,7 +1601,7 @@ static void scrollrt_draw_lower_2(int x, int y, int sx, int sy, int chunks, int dst -= BUFFER_WIDTH * 32; } if (CelSkip < 8) { - scrollrt_draw_clipped_dungeon_2(&gpBuffer[sx + PitchTbl[sy] - BUFFER_WIDTH * 32 * (skipChunks + 1)], x, y, skipChunks, CelSkip, sx, sy, 1); + scrollrt_draw_clipped_dungeon_2(&gpBuffer[sx + PitchTbl[sy] - BUFFER_WIDTH * 32 * (row + 1)], x, y, row, CelSkip, sx, sy, 1); } } } @@ -1457,7 +1619,7 @@ static void scrollrt_draw_lower_2(int x, int y, int sx, int sy, int chunks, int dst = &gpBuffer[sx - BUFFER_WIDTH * 32 + PitchTbl[sy]]; cel_transparency_active = (BYTE)(nTransTable[level_piece_id] & TransList[dTransVal[x][y]]); for (i = 0; i < (MicroTileLen >> 1) - 1; i++) { - if (skipChunks <= i) { + if (row <= i) { level_cel_block = pMap->mt[2 * i + 2]; if (level_cel_block != 0) { drawLowerScreen(dst); @@ -1466,16 +1628,28 @@ static void scrollrt_draw_lower_2(int x, int y, int sx, int sy, int chunks, int dst -= BUFFER_WIDTH * 32; } if (CelSkip < 8) { - scrollrt_draw_clipped_dungeon_2(&gpBuffer[sx + PitchTbl[sy] - BUFFER_WIDTH * 16 * CelSkip], x, y, skipChunks, CelSkip, sx, sy, 0); + scrollrt_draw_clipped_dungeon_2(&gpBuffer[sx + PitchTbl[sy] - BUFFER_WIDTH * 16 * CelSkip], x, y, row, CelSkip, sx, sy, 0); } } } } } -static void scrollrt_draw_dungeon(BYTE *pBuff, int sx, int sy, int capChunks, int CelCap, int dx, int dy, int eflag); - -static void scrollrt_draw_e_flag(BYTE *pBuff, int x, int y, int capChunks, int CelCap, int sx, int sy) +static void scrollrt_draw_dungeon(BYTE *pBuff, int sx, int sy, int row, int CelCap, int dx, int dy, int eflag); + +/** + * This variant checks for of screen element on the upper screen + * This function it self causes rendering issues since it will render on top of objects on the other side of walls + * @brief Re render tile to workaround sorting issues with players walking east/west + * @param pBuff Pointer to output buffer at location sx,sy + * @param y dPiece coordinate + * @param x dPiece coordinate + * @param row The current row being rendered + * @param CelCap chunks of cell to skip + * @param sx Backbuffer coordinate + * @param sy Backbuffer coordinate + */ +static void scrollrt_draw_e_flag(BYTE *pBuff, int x, int y, int row, int CelCap, int sx, int sy) { int i, lti_old, cta_old, lpi_old; BYTE *dst; @@ -1505,7 +1679,7 @@ static void scrollrt_draw_e_flag(BYTE *pBuff, int x, int y, int capChunks, int C arch_draw_type = 0; for (i = 1; i < (MicroTileLen >> 1) - 1; i++) { dst -= BUFFER_WIDTH * 32; - if (capChunks >= i) { + if (row >= i) { level_cel_block = pMap->mt[2 * i]; if (level_cel_block != 0) { drawUpperScreen(dst); @@ -1517,14 +1691,25 @@ static void scrollrt_draw_e_flag(BYTE *pBuff, int x, int y, int capChunks, int C } } - scrollrt_draw_dungeon(pBuff, x, y, capChunks, CelCap, sx, sy, 0); + scrollrt_draw_dungeon(pBuff, x, y, row, CelCap, sx, sy, 0); light_table_index = lti_old; cel_transparency_active = cta_old; level_piece_id = lpi_old; } -static void scrollrt_draw_dungeon(BYTE *pBuff, int sx, int sy, int capChunks, int CelCap, int dx, int dy, int eflag) +/** + * @brief Render object sprites, skip offscreen parts for upper screen + * @param pBuff where to render to with sx,sx already applied + * @param sx dPice coordinate + * @param sy dPice coordinate + * @param row The current row being rendered + * @param CelCap chunks of cell to skip + * @param dx Backbuffer coordinate + * @param dy Backbuffer coordinate + * @param eflag Should the sorting workaround be applied + */ +static void scrollrt_draw_dungeon(BYTE *pBuff, int sx, int sy, int row, int CelCap, int dx, int dy, int eflag) { int px, py, nCel, nMon, negMon, p, tx, ty; char bFlag, bDead, bObj, bItem, bPlr, bArch, bMap, negPlr, dd; @@ -1618,9 +1803,9 @@ static void scrollrt_draw_dungeon(BYTE *pBuff, int sx, int sy, int capChunks, in DrawPlayer(p, sx, sy - 1, px, py, pPlayer->_pAnimData, pPlayer->_pAnimFrame, pPlayer->_pAnimWidth, 0, CelCap); if (eflag && pPlayer->_peflag != 0) { if (pPlayer->_peflag == 2) { - scrollrt_draw_e_flag(pBuff - (BUFFER_WIDTH * 16 + 96), sx - 2, sy + 1, capChunks, CelCap, tx, ty); + scrollrt_draw_e_flag(pBuff - (BUFFER_WIDTH * 16 + 96), sx - 2, sy + 1, row, CelCap, tx, ty); } - scrollrt_draw_e_flag(pBuff - 64, sx - 1, sy + 1, capChunks, CelCap, dx - 64, dy); + scrollrt_draw_e_flag(pBuff - 64, sx - 1, sy + 1, row, CelCap, dx - 64, dy); } } else { // app_fatal("draw player: tried to draw illegal player %d", p); @@ -1639,7 +1824,7 @@ static void scrollrt_draw_dungeon(BYTE *pBuff, int sx, int sy, int capChunks, in } DrawMonster(sx, sy, px, py, draw_monster_num, 0, CelCap); if (eflag && !pMonster->_meflag) { - scrollrt_draw_e_flag(pBuff - 64, sx - 1, sy + 1, capChunks, CelCap, dx - 64, dy); + scrollrt_draw_e_flag(pBuff - 64, sx - 1, sy + 1, row, CelCap, dx - 64, dy); } } else { // app_fatal("Draw Monster \"%s\": uninitialized monster", pMonster->mName); @@ -1661,9 +1846,9 @@ static void scrollrt_draw_dungeon(BYTE *pBuff, int sx, int sy, int capChunks, in DrawPlayer(p, sx, sy, px, py, pPlayer->_pAnimData, pPlayer->_pAnimFrame, pPlayer->_pAnimWidth, 0, CelCap); if (eflag && pPlayer->_peflag != 0) { if (pPlayer->_peflag == 2) { - scrollrt_draw_e_flag(pBuff - (BUFFER_WIDTH * 16 + 96), sx - 2, sy + 1, capChunks, CelCap, dx - 96, dy - 16); + scrollrt_draw_e_flag(pBuff - (BUFFER_WIDTH * 16 + 96), sx - 2, sy + 1, row, CelCap, dx - 96, dy - 16); } - scrollrt_draw_e_flag(pBuff - 64, sx - 1, sy + 1, capChunks, CelCap, dx - 64, dy); + scrollrt_draw_e_flag(pBuff - 64, sx - 1, sy + 1, row, CelCap, dx - 64, dy); } } else { // app_fatal("draw player: tried to draw illegal player %d", p); @@ -1682,7 +1867,7 @@ static void scrollrt_draw_dungeon(BYTE *pBuff, int sx, int sy, int capChunks, in } DrawMonster(sx, sy, px, py, draw_monster_num, 0, CelCap); if (eflag && !pMonster->_meflag) { - scrollrt_draw_e_flag(pBuff - 64, sx - 1, sy + 1, capChunks, CelCap, dx - 64, dy); + scrollrt_draw_e_flag(pBuff - 64, sx - 1, sy + 1, row, CelCap, dx - 64, dy); } } else { // app_fatal("Draw Monster \"%s\": uninitialized monster", pMonster->mName); @@ -1728,7 +1913,17 @@ static void scrollrt_draw_dungeon(BYTE *pBuff, int sx, int sy, int capChunks, in } } -static void scrollrt_draw_upper(int x, int y, int sx, int sy, int chunks, int capChunks, int eflag) +/** + * @brief Render a row of tile, checking for overdrawing on upper part of screen + * @param x dPice coordinate + * @param y dPice coordinate + * @param sx Backbuffer coordinate + * @param sy Backbuffer coordinate + * @param chunks tile width of row + * @param row current row being rendered + * @param eflag is it an even (0) or odd (1) row + */ +static void scrollrt_draw_upper(int x, int y, int sx, int sy, int chunks, int row, int eflag) { int i, j, CelCap; BYTE *dst; @@ -1737,7 +1932,7 @@ static void scrollrt_draw_upper(int x, int y, int sx, int sy, int chunks, int ca /// ASSERT: assert(gpBuffer); pMap = &dpiece_defs_map_1[IsometricCoord(x, y)]; - CelCap = 2 * capChunks + 2; + CelCap = 2 * row + 2; if (CelCap > 8) { CelCap = 8; } @@ -1749,7 +1944,7 @@ static void scrollrt_draw_upper(int x, int y, int sx, int sy, int chunks, int ca if (level_piece_id != 0) { dst = &gpBuffer[sx + 32 + PitchTbl[sy]]; cel_transparency_active = (BYTE)(nTransTable[level_piece_id] & TransList[dTransVal[x][y]]); - if (capChunks >= 0) { + if (row >= 0) { level_cel_block = pMap->mt[1]; if (level_cel_block != 0) { arch_draw_type = 2; @@ -1758,27 +1953,27 @@ static void scrollrt_draw_upper(int x, int y, int sx, int sy, int chunks, int ca } } dst -= BUFFER_WIDTH * 32; - if (capChunks >= 1) { + if (row >= 1) { level_cel_block = pMap->mt[3]; if (level_cel_block != 0) { drawUpperScreen(dst); } } dst -= BUFFER_WIDTH * 32; - if (capChunks >= 2) { + if (row >= 2) { level_cel_block = pMap->mt[5]; if (level_cel_block != 0) { drawUpperScreen(dst); } } dst -= BUFFER_WIDTH * 32; - if (capChunks >= 3) { + if (row >= 3) { level_cel_block = pMap->mt[7]; if (level_cel_block != 0) { drawUpperScreen(dst); } } - scrollrt_draw_dungeon(&gpBuffer[sx + PitchTbl[sy]], x, y, capChunks, CelCap, sx, sy, 0); + scrollrt_draw_dungeon(&gpBuffer[sx + PitchTbl[sy]], x, y, row, CelCap, sx, sy, 0); } else { world_draw_black_tile(&gpBuffer[sx + PitchTbl[sy]]); } @@ -1810,7 +2005,7 @@ static void scrollrt_draw_upper(int x, int y, int sx, int sy, int chunks, int ca arch_draw_type = 0; for (i = 1; i < (MicroTileLen >> 1) - 1; i++) { dst -= BUFFER_WIDTH * 32; - if (capChunks >= i) { + if (row >= i) { level_cel_block = pMap->mt[2 * i]; if (level_cel_block != 0) { drawUpperScreen(dst); @@ -1821,7 +2016,7 @@ static void scrollrt_draw_upper(int x, int y, int sx, int sy, int chunks, int ca } } } - scrollrt_draw_dungeon(&gpBuffer[sx + PitchTbl[sy]], x, y, capChunks, CelCap, sx, sy, 1); + scrollrt_draw_dungeon(&gpBuffer[sx + PitchTbl[sy]], x, y, row, CelCap, sx, sy, 1); } else { world_draw_black_tile(&gpBuffer[sx + PitchTbl[sy]]); } @@ -1840,7 +2035,7 @@ static void scrollrt_draw_upper(int x, int y, int sx, int sy, int chunks, int ca dst = &gpBuffer[sx + PitchTbl[sy]]; cel_transparency_active = (BYTE)(nTransTable[level_piece_id] & TransList[dTransVal[x][y]]); arch_draw_type = 1; - if (capChunks >= 0) { + if (row >= 0) { level_cel_block = pMap->mt[0]; if (level_cel_block != 0) { drawUpperScreen(dst); @@ -1848,27 +2043,27 @@ static void scrollrt_draw_upper(int x, int y, int sx, int sy, int chunks, int ca } arch_draw_type = 0; dst -= BUFFER_WIDTH * 32; - if (capChunks >= 1) { + if (row >= 1) { level_cel_block = pMap->mt[2]; if (level_cel_block != 0) { drawUpperScreen(dst); } } dst -= BUFFER_WIDTH * 32; - if (capChunks >= 2) { + if (row >= 2) { level_cel_block = pMap->mt[4]; if (level_cel_block != 0) { drawUpperScreen(dst); } } dst -= BUFFER_WIDTH * 32; - if (capChunks >= 3) { + if (row >= 3) { level_cel_block = pMap->mt[6]; if (level_cel_block != 0) { drawUpperScreen(dst); } } - scrollrt_draw_dungeon(&gpBuffer[sx + PitchTbl[sy]], x, y, capChunks, CelCap, sx, sy, 0); + scrollrt_draw_dungeon(&gpBuffer[sx + PitchTbl[sy]], x, y, row, CelCap, sx, sy, 0); } else { world_draw_black_tile(&gpBuffer[sx + PitchTbl[sy]]); } @@ -1876,6 +2071,11 @@ static void scrollrt_draw_upper(int x, int y, int sx, int sy, int chunks, int ca } } +/** + * @brief Configure render and process screen rows + * @param x Center of view in dPice coordinate + * @param y Center of view in dPice coordinate + */ static void DrawGame(int x, int y) { int i, sx, sy, chunks, blocks; @@ -1978,6 +2178,11 @@ static void DrawGame(int x, int y) } } +/** + * @brief Configure render for zoomed view and process screen rows + * @param x Center of view in dPice coordinate + * @param y Center of view in dPice coordinate + */ static void DrawZoom(int x, int y) { int i, sx, sy, chunks, blocks; @@ -2135,6 +2340,11 @@ static void DrawZoom(int x, int y) #endif } +/** + * @brief Start rendering of screen, town variation + * @param StartX Center of view in dPice coordinate + * @param StartY Center of view in dPice coordinate + */ void DrawView(int StartX, int StartY) { if (zoomflag) { @@ -2192,6 +2402,9 @@ void DrawView(int StartX, int StartY) DrawManaFlask(); } +/** + * @brief Render the whole screen black + */ void ClearScreenBuffer() { lock_buf(3); @@ -2226,6 +2439,9 @@ void ClearScreenBuffer() } #ifdef _DEBUG +/** + * @brief Scroll the screen when mouse is close to the edge + */ void ScrollView() { BOOL scroll; @@ -2304,12 +2520,18 @@ void ScrollView() ScrollInfo._sdir = SDIR_NONE; } +/** + * @brief Initialize the FPS meter + */ void EnableFrameCount() { frameflag = frameflag == 0; framestart = GetTickCount(); } +/** + * @brief Display the current average FPS over 1 sec + */ static void DrawFPS() { DWORD tc, frames; @@ -2343,6 +2565,13 @@ static void DrawFPS() } #endif +/** + * @brief Update part of the screen from the backbuffer + * @param dwX Backbuffer coordinate + * @param dwY Backbuffer coordinate + * @param dwWdt Backbuffer coordinate + * @param dwHgt Backbuffer coordinate + */ static void DoBlitScreen(DWORD dwX, DWORD dwY, DWORD dwWdt, DWORD dwHgt) { int nSrcOff, nDstOff, nSrcWdt, nDstWdt; @@ -2440,6 +2669,15 @@ static void DoBlitScreen(DWORD dwX, DWORD dwY, DWORD dwWdt, DWORD dwHgt) } } +/** + * @brief Check render pipline and blit indivudal screen parts + * @param dwHgt Section of screen to update from top to bottom + * @param draw_desc Render info box + * @param draw_hp Render halth bar + * @param draw_mana Render mana bar + * @param draw_sbar Render belt + * @param draw_btn Render panel buttons + */ static void DrawMain(int dwHgt, BOOL draw_desc, BOOL draw_hp, BOOL draw_mana, BOOL draw_sbar, BOOL draw_btn) { int ysize; @@ -2585,6 +2823,9 @@ void scrollrt_draw_game_screen(BOOL draw_cursor) } } +/** + * @brief Render the game + */ void DrawAndBlit() { int hgt; diff --git a/Source/scrollrt.h b/Source/scrollrt.h index 4b334c622..56d69dfa2 100644 --- a/Source/scrollrt.h +++ b/Source/scrollrt.h @@ -14,9 +14,9 @@ extern void (*DrawPlrProc)(int, int, int, int, int, BYTE *, int, int, int, int); extern int draw_monster_num; void ClearCursor(); -void DrawMissile(int x, int y, int sx, int sy, int CelSkip, int capChunks, BOOL pre); -void DrawClippedMissile(int x, int y, int sx, int sy, int CelSkip, int capChunks, BOOL pre); -void DrawDeadPlayer(int x, int y, int sx, int sy, int CelSkip, int capChunks, BOOL clipped); +void DrawMissile(int x, int y, int sx, int sy, int CelSkip, int CelCap, BOOL pre); +void DrawClippedMissile(int x, int y, int sx, int sy, int CelSkip, int CelCap, BOOL pre); +void DrawDeadPlayer(int x, int y, int sx, int sy, int CelSkip, int CelCap, BOOL clipped); void DrawView(int StartX, int StartY); void ClearScreenBuffer(); #ifdef _DEBUG diff --git a/Source/stores.cpp b/Source/stores.cpp index 3e7a9b6f3..686b4ce0e 100644 --- a/Source/stores.cpp +++ b/Source/stores.cpp @@ -12,7 +12,7 @@ int talker; STextStruct stext[24]; char stextsize; int stextsmax; -int InStoreFlag; +int InStoreFlag; /** current frame # for the pentagram selector */ ItemStruct storehold[48]; int gossipstart; ItemStruct witchitem[20]; diff --git a/Source/town.cpp b/Source/town.cpp index 5c6d9b5c9..8fc5cb538 100644 --- a/Source/town.cpp +++ b/Source/town.cpp @@ -1,5 +1,10 @@ #include "diablo.h" +/** + * Used under building to avoid HOM and outside of level + * @brief world_draw_black_tile but limited to upper half of screen + * @param pBuff location in back buffer to render the tile, must be on upper half of screen + */ void town_clear_upper_buf(BYTE *pBuff) { /// ASSERT: assert(gpBuffer); @@ -62,6 +67,11 @@ void town_clear_upper_buf(BYTE *pBuff) #endif } +/** + * Used under building to avoid HOM and outside of level + * @brief world_draw_black_tile but limited to lower half of screen + * @param pBuff location in back buffer to render the tile, must be on lower half of screen + */ void town_clear_low_buf(BYTE *pBuff) { /// ASSERT: assert(gpBuffer); @@ -138,6 +148,11 @@ void town_clear_low_buf(BYTE *pBuff) #endif } +/** + * @brief Render trees on top of player, buggy disabled in 1.09 + * @param pBuff backbuffer pointing where to render on lower part of screen + * @param nCel Frame number for pSpecialCels tile to draw + */ void town_special_lower(BYTE *pBuff, int nCel) { #if 0 @@ -252,6 +267,11 @@ void town_special_lower(BYTE *pBuff, int nCel) #endif } +/** + * @brief Render trees on top of player, buggy disabled in 1.09 + * @param pBuff backbuffer pointing where to render on upper part of screen + * @param nCel Frame number for pSpecialCels tile to draw + */ void town_special_upper(BYTE *pBuff, int nCel) { #if 0 @@ -362,6 +382,16 @@ void town_special_upper(BYTE *pBuff, int nCel) #endif } +/** + * This variant checks for of screen element on the lower screen + * This function it self causes rendering issues since it will render on top of objects on the other side of walls + * @brief Re render tile to workaround sorting issues with players walking east/west + * @param pBuff Pointer to output buffer at location sx,sy + * @param y dPiece coordinate + * @param x dPiece coordinate + * @param sx Backbuffer coordinate + * @param sy Backbuffer coordinate + */ void town_draw_clipped_e_flag(BYTE *pBuff, int x, int y, int sx, int sy) { int i; @@ -386,6 +416,15 @@ void town_draw_clipped_e_flag(BYTE *pBuff, int x, int y, int sx, int sy) town_draw_clipped_town(pBuff, x, y, sx, sy, 0); } +/** + * @brief Render object sprites + * @param pBuff where to render to with sx,sy already applied + * @param sx dPice coordinate + * @param sy dPice coordinate + * @param dx Backbuffer coordinate + * @param dy Backbuffer coordinate + * @param eflag Should the sorting workaround be applied + */ void town_draw_clipped_town(BYTE *pBuff, int sx, int sy, int dx, int dy, int eflag) { int mi, px, py; @@ -454,6 +493,15 @@ void town_draw_clipped_town(BYTE *pBuff, int sx, int sy, int dx, int dy, int efl } } +/** + * @brief Render a row of tile + * @param x dPice coordinate + * @param y dPice coordinate + * @param sx Backbuffer coordinate + * @param sy Backbuffer coordinate + * @param chunks tile width of row + * @param eflag is it an even (0) or odd (1) row + */ void town_draw_lower(int x, int y, int sx, int sy, int chunks, int eflag) { int i, j; @@ -539,22 +587,34 @@ void town_draw_lower(int x, int y, int sx, int sy, int chunks, int eflag) } } -void town_draw_clipped_e_flag_2(BYTE *pBuff, int x, int y, int skipChunks, int CelSkip, int sx, int sy) +/** + * This variant checks for of screen element on the lower screen + * This function it self causes rendering issues since it will render on top of objects on the other side of walls + * @brief Re render tile to workaround sorting issues with players walking east/west + * @param pBuff Pointer to output buffer at location sx,sy + * @param y dPiece coordinate + * @param x dPiece coordinate + * @param row The current row being rendered + * @param CelSkip chunks of cell to skip + * @param sx Backbuffer coordinate + * @param sy Backbuffer coordinate + */ +void town_draw_clipped_e_flag_2(BYTE *pBuff, int x, int y, int row, int CelSkip, int sx, int sy) { int i; BYTE *dst; MICROS *pMap; - if (skipChunks == 0) { + if (row == 0) { dst = pBuff; } else { - dst = &pBuff[BUFFER_WIDTH * 32 * skipChunks]; + dst = &pBuff[BUFFER_WIDTH * 32 * row]; } pMap = &dpiece_defs_map_1[IsometricCoord(x, y)]; for (i = 0; i < 6; i++) { - if (skipChunks <= i) { + if (row <= i) { level_cel_block = pMap->mt[2 * i + 2]; if (level_cel_block != 0) { drawLowerScreen(dst); @@ -568,11 +628,22 @@ void town_draw_clipped_e_flag_2(BYTE *pBuff, int x, int y, int skipChunks, int C } if (CelSkip < 8) { - town_draw_clipped_town_2(pBuff, x, y, skipChunks, CelSkip, sx, sy, 0); + town_draw_clipped_town_2(pBuff, x, y, row, CelSkip, sx, sy, 0); } } -void town_draw_clipped_town_2(BYTE *pBuff, int sx, int sy, int skipChunks, int CelSkip, int dx, int dy, int eflag) +/** + * @brief Render object sprites, skip offscreen parts for lower screen + * @param pBuff where to render to with sx,sy already applied + * @param sx dPice coordinate + * @param sy dPice coordinate + * @param row The current row being rendered + * @param CelSkip chunks of cell to skip + * @param dx Backbuffer coordinate + * @param dy Backbuffer coordinate + * @param eflag Should the sorting workaround be applied + */ +void town_draw_clipped_town_2(BYTE *pBuff, int sx, int sy, int row, int CelSkip, int dx, int dy, int eflag) { int mi, px, py; char bv; @@ -610,7 +681,7 @@ void town_draw_clipped_town_2(BYTE *pBuff, int sx, int sy, int skipChunks, int C } Cl2DrawSafe(px, py, plr[bv]._pAnimData, plr[bv]._pAnimFrame, plr[bv]._pAnimWidth, CelSkip, 8); if (eflag && plr[bv]._peflag) { - town_draw_clipped_e_flag_2(pBuff - 64, sx - 1, sy + 1, skipChunks, CelSkip, dx - 64, dy); + town_draw_clipped_e_flag_2(pBuff - 64, sx - 1, sy + 1, row, CelSkip, dx - 64, dy); } } if (dFlags[sx][sy] & BFLAG_DEAD_PLAYER) { @@ -625,7 +696,7 @@ void town_draw_clipped_town_2(BYTE *pBuff, int sx, int sy, int skipChunks, int C } Cl2DrawSafe(px, py, plr[bv]._pAnimData, plr[bv]._pAnimFrame, plr[bv]._pAnimWidth, CelSkip, 8); if (eflag && plr[bv]._peflag) { - town_draw_clipped_e_flag_2(pBuff - 64, sx - 1, sy + 1, skipChunks, CelSkip, dx - 64, dy); + town_draw_clipped_e_flag_2(pBuff - 64, sx - 1, sy + 1, row, CelSkip, dx - 64, dy); } } if (dFlags[sx][sy] & BFLAG_MISSILE) { @@ -636,7 +707,17 @@ void town_draw_clipped_town_2(BYTE *pBuff, int sx, int sy, int skipChunks, int C } } -void town_draw_lower_2(int x, int y, int sx, int sy, int chunks, int skipChunks, int eflag) +/** + * @brief Render a row of tile, checking for overdrawing on lower part of screen + * @param x dPice coordinate + * @param y dPice coordinate + * @param sx Backbuffer coordinate + * @param sy Backbuffer coordinate + * @param chunks tile width of row + * @param row current row being rendered + * @param eflag is it an even (0) or odd (1) row + */ +void town_draw_lower_2(int x, int y, int sx, int sy, int chunks, int row, int eflag) { int i, j, CelSkip; BYTE *dst; @@ -644,7 +725,7 @@ void town_draw_lower_2(int x, int y, int sx, int sy, int chunks, int skipChunks, /// ASSERT: assert(gpBuffer); - CelSkip = 2 * skipChunks + 2; + CelSkip = 2 * row + 2; if (eflag) { if (y >= 0 && y < MAXDUNY && x >= 0 && x < MAXDUNX) { @@ -653,7 +734,7 @@ void town_draw_lower_2(int x, int y, int sx, int sy, int chunks, int skipChunks, dst = &gpBuffer[sx - (BUFFER_WIDTH * 32 - 32) + PitchTbl[sy]]; pMap = &dpiece_defs_map_1[IsometricCoord(x, y)]; for (i = 0; i < 7; i++) { - if (skipChunks <= i) { + if (row <= i) { level_cel_block = pMap->mt[2 * i + 3]; if (level_cel_block != 0) { drawLowerScreen(dst); @@ -662,7 +743,7 @@ void town_draw_lower_2(int x, int y, int sx, int sy, int chunks, int skipChunks, dst -= BUFFER_WIDTH * 32; } if (CelSkip < 8) { - town_draw_clipped_town_2(&gpBuffer[sx + PitchTbl[sy]], x, y, skipChunks, CelSkip, sx, sy, 0); + town_draw_clipped_town_2(&gpBuffer[sx + PitchTbl[sy]], x, y, row, CelSkip, sx, sy, 0); } } else { town_clear_low_buf(&gpBuffer[sx + PitchTbl[sy]]); @@ -682,7 +763,7 @@ void town_draw_lower_2(int x, int y, int sx, int sy, int chunks, int skipChunks, dst = &gpBuffer[sx - BUFFER_WIDTH * 32 + PitchTbl[sy]]; pMap = &dpiece_defs_map_1[IsometricCoord(x, y)]; for (i = 0; i < 7; i++) { - if (skipChunks <= i) { + if (row <= i) { level_cel_block = pMap->mt[2 * i + 2]; if (level_cel_block != 0) { drawLowerScreen(dst); @@ -695,7 +776,7 @@ void town_draw_lower_2(int x, int y, int sx, int sy, int chunks, int skipChunks, dst -= BUFFER_WIDTH * 32; } if (CelSkip < 8) { - town_draw_clipped_town_2(&gpBuffer[sx + PitchTbl[sy] - BUFFER_WIDTH * 16 * CelSkip], x, y, skipChunks, CelSkip, sx, sy, 1); + town_draw_clipped_town_2(&gpBuffer[sx + PitchTbl[sy] - BUFFER_WIDTH * 16 * CelSkip], x, y, row, CelSkip, sx, sy, 1); } } else { town_clear_low_buf(&gpBuffer[sx + PitchTbl[sy]]); @@ -715,7 +796,7 @@ void town_draw_lower_2(int x, int y, int sx, int sy, int chunks, int skipChunks, dst = &gpBuffer[sx - BUFFER_WIDTH * 32 + PitchTbl[sy]]; pMap = &dpiece_defs_map_1[IsometricCoord(x, y)]; for (i = 0; i < 7; i++) { - if (skipChunks <= i) { + if (row <= i) { level_cel_block = pMap->mt[2 * i + 2]; if (level_cel_block != 0) { drawLowerScreen(dst); @@ -724,7 +805,7 @@ void town_draw_lower_2(int x, int y, int sx, int sy, int chunks, int skipChunks, dst -= BUFFER_WIDTH * 32; } if (CelSkip < 8) { - town_draw_clipped_town_2(&gpBuffer[sx + PitchTbl[sy]], x, y, skipChunks, CelSkip, sx, sy, 0); + town_draw_clipped_town_2(&gpBuffer[sx + PitchTbl[sy]], x, y, row, CelSkip, sx, sy, 0); } } else { town_clear_low_buf(&gpBuffer[sx + PitchTbl[sy]]); @@ -735,7 +816,19 @@ void town_draw_lower_2(int x, int y, int sx, int sy, int chunks, int skipChunks, } } -void town_draw_e_flag(BYTE *pBuff, int x, int y, int capChunks, int CelCap, int sx, int sy) +/** + * This variant checks for of screen element on the upper screen + * This function it self causes rendering issues since it will render on top of objects on the other side of walls + * @brief Re render tile to workaround sorting issues with players walking east/west + * @param pBuff Pointer to output buffer at location sx,sy + * @param y dPiece coordinate + * @param x dPiece coordinate + * @param row The current row being rendered + * @param CelCap chunks of cell to skip + * @param sx Backbuffer coordinate + * @param sy Backbuffer coordinate + */ +void town_draw_e_flag(BYTE *pBuff, int x, int y, int row, int CelCap, int sx, int sy) { int i; BYTE *dst; @@ -745,7 +838,7 @@ void town_draw_e_flag(BYTE *pBuff, int x, int y, int capChunks, int CelCap, int pMap = &dpiece_defs_map_1[IsometricCoord(x, y)]; for (i = 0; i < 7; i++) { - if (capChunks >= i) { + if (row >= i) { level_cel_block = pMap->mt[2 * i]; if (level_cel_block != 0) { drawUpperScreen(dst); @@ -758,10 +851,21 @@ void town_draw_e_flag(BYTE *pBuff, int x, int y, int capChunks, int CelCap, int dst -= BUFFER_WIDTH * 32; } - town_draw_town_all(pBuff, x, y, capChunks, CelCap, sx, sy, 0); + town_draw_town_all(pBuff, x, y, row, CelCap, sx, sy, 0); } -void town_draw_town_all(BYTE *pBuff, int x, int y, int capChunks, int CelCap, int sx, int sy, int eflag) +/** + * @brief Render object sprites, skip offscreen parts for upper screen + * @param pBuff where to render to with sx,sx already applied + * @param x dPice coordinate + * @param y dPice coordinate + * @param row The current row being rendered + * @param CelCap chunks of cell to skip + * @param sx Backbuffer coordinate + * @param sy Backbuffer coordinate + * @param eflag Should the sorting workaround be applied + */ +void town_draw_town_all(BYTE *pBuff, int x, int y, int row, int CelCap, int sx, int sy, int eflag) { int mi, px, py; char bv; @@ -803,7 +907,7 @@ void town_draw_town_all(BYTE *pBuff, int x, int y, int capChunks, int CelCap, in /// ASSERT: assert(plr[bv]._pAnimData); Cl2Draw(px, py, plr[bv]._pAnimData, plr[bv]._pAnimFrame, plr[bv]._pAnimWidth, 0, CelCap); if (eflag && plr[bv]._peflag) { - town_draw_e_flag(pBuff - 64, x - 1, y + 1, capChunks, CelCap, sx - 64, sy); + town_draw_e_flag(pBuff - 64, x - 1, y + 1, row, CelCap, sx - 64, sy); } } if (dFlags[x][y] & BFLAG_DEAD_PLAYER) { @@ -819,7 +923,7 @@ void town_draw_town_all(BYTE *pBuff, int x, int y, int capChunks, int CelCap, in /// ASSERT: assert(plr[bv]._pAnimData); Cl2Draw(px, py, plr[bv]._pAnimData, plr[bv]._pAnimFrame, plr[bv]._pAnimWidth, 0, CelCap); if (eflag && plr[bv]._peflag) { - town_draw_e_flag(pBuff - 64, x - 1, y + 1, capChunks, CelCap, sx - 64, sy); + town_draw_e_flag(pBuff - 64, x - 1, y + 1, row, CelCap, sx - 64, sy); } } if (dFlags[x][y] & BFLAG_MISSILE) { @@ -830,7 +934,17 @@ void town_draw_town_all(BYTE *pBuff, int x, int y, int capChunks, int CelCap, in } } -void town_draw_upper(int x, int y, int sx, int sy, int chunks, int capChunks, int eflag) +/** + * @brief Render a row of tile, checking for overdrawing on upper part of screen + * @param x dPice coordinate + * @param y dPice coordinate + * @param sx Backbuffer coordinate + * @param sy Backbuffer coordinate + * @param chunks tile width of row + * @param row current row being rendered + * @param eflag is it an even (0) or odd (1) row + */ +void town_draw_upper(int x, int y, int sx, int sy, int chunks, int row, int eflag) { int i, j, CelCap; BYTE *dst; @@ -838,7 +952,7 @@ void town_draw_upper(int x, int y, int sx, int sy, int chunks, int capChunks, in /// ASSERT: assert(gpBuffer); - CelCap = 2 * capChunks + 2; + CelCap = 2 * row + 2; if (CelCap > 8) { CelCap = 8; } @@ -850,7 +964,7 @@ void town_draw_upper(int x, int y, int sx, int sy, int chunks, int capChunks, in dst = &gpBuffer[sx + 32 + PitchTbl[sy]]; pMap = &dpiece_defs_map_1[IsometricCoord(x, y)]; for (i = 0; i < 7; i++) { - if (capChunks >= i) { + if (row >= i) { level_cel_block = pMap->mt[2 * i + 1]; if (level_cel_block != 0) { drawUpperScreen(dst); @@ -858,7 +972,7 @@ void town_draw_upper(int x, int y, int sx, int sy, int chunks, int capChunks, in } dst -= BUFFER_WIDTH * 32; } - town_draw_town_all(&gpBuffer[sx + PitchTbl[sy]], x, y, capChunks, CelCap, sx, sy, 0); + town_draw_town_all(&gpBuffer[sx + PitchTbl[sy]], x, y, row, CelCap, sx, sy, 0); } else { town_clear_upper_buf(&gpBuffer[sx + PitchTbl[sy]]); } @@ -877,7 +991,7 @@ void town_draw_upper(int x, int y, int sx, int sy, int chunks, int capChunks, in dst = &gpBuffer[sx + PitchTbl[sy]]; pMap = &dpiece_defs_map_1[IsometricCoord(x, y)]; for (i = 0; i < 7; i++) { - if (capChunks >= i) { + if (row >= i) { level_cel_block = pMap->mt[2 * i]; if (level_cel_block != 0) { drawUpperScreen(dst); @@ -889,7 +1003,7 @@ void town_draw_upper(int x, int y, int sx, int sy, int chunks, int capChunks, in } dst -= BUFFER_WIDTH * 32; } - town_draw_town_all(&gpBuffer[sx + PitchTbl[sy]], x, y, capChunks, CelCap, sx, sy, 1); + town_draw_town_all(&gpBuffer[sx + PitchTbl[sy]], x, y, row, CelCap, sx, sy, 1); } else { town_clear_upper_buf(&gpBuffer[sx + PitchTbl[sy]]); } @@ -908,7 +1022,7 @@ void town_draw_upper(int x, int y, int sx, int sy, int chunks, int capChunks, in dst = &gpBuffer[sx + PitchTbl[sy]]; pMap = &dpiece_defs_map_1[IsometricCoord(x, y)]; for (i = 0; i < 7; i++) { - if (capChunks >= i) { + if (row >= i) { level_cel_block = pMap->mt[2 * i]; if (level_cel_block != 0) { drawUpperScreen(dst); @@ -916,7 +1030,7 @@ void town_draw_upper(int x, int y, int sx, int sy, int chunks, int capChunks, in } dst -= BUFFER_WIDTH * 32; } - town_draw_town_all(&gpBuffer[sx + PitchTbl[sy]], x, y, capChunks, CelCap, sx, sy, 0); + town_draw_town_all(&gpBuffer[sx + PitchTbl[sy]], x, y, row, CelCap, sx, sy, 0); } else { town_clear_upper_buf(&gpBuffer[sx + PitchTbl[sy]]); } @@ -926,6 +1040,11 @@ void town_draw_upper(int x, int y, int sx, int sy, int chunks, int capChunks, in } } +/** + * @brief Configure render and process screen rows + * @param x Center of view in dPice coordinate + * @param y Center of view in dPice coordinate + */ void T_DrawGame(int x, int y) { int i, sx, sy, chunks, blocks; @@ -1039,6 +1158,11 @@ void T_DrawGame(int x, int y) } } +/** + * @brief Configure render for zoomed view and process screen rows + * @param x Center of view in dPice coordinate + * @param y Center of view in dPice coordinate + */ void T_DrawZoom(int x, int y) { int i, sx, sy, chunks, blocks; @@ -1207,6 +1331,12 @@ void T_DrawZoom(int x, int y) #endif } +/** + * Mostly like DrawView but enables stores and lacks death screen + * @brief Start rendering of screen, town variation + * @param StartX Center of view in dPice coordinate + * @param StartY Center of view in dPice coordinate + */ void T_DrawView(int StartX, int StartY) { light_table_index = 0; @@ -1303,6 +1433,15 @@ void SetTownMicros() } } +/** + * @brief Load level data into dPiece + * @param P3Tiles Tile set + * @param pSector Sector data + * @param xi upper left destination + * @param yi upper left destination + * @param w width of sector + * @param h height of sector + */ void T_FillSector(BYTE *P3Tiles, BYTE *pSector, int xi, int yi, int w, int h) { int i, j, xx, yy; @@ -1353,7 +1492,7 @@ void T_FillSector(BYTE *P3Tiles, BYTE *pSector, int xi, int yi, int w, int h) Map = (WORD *)&pSector[ii]; if (*Map) { - v1 = *((WORD *)&P3Tiles[(*Map - 1) * 8]) + 1; + v1 = *((WORD *)&P3Tiles[(*Map - 1) * 8] + 0) + 1; v2 = *((WORD *)&P3Tiles[(*Map - 1) * 8] + 1) + 1; v3 = *((WORD *)&P3Tiles[(*Map - 1) * 8] + 2) + 1; v4 = *((WORD *)&P3Tiles[(*Map - 1) * 8] + 3) + 1; @@ -1375,6 +1514,13 @@ void T_FillSector(BYTE *P3Tiles, BYTE *pSector, int xi, int yi, int w, int h) } } +/** + * @brief Load a tile in to dPiece + * @param P3Tiles Tile set + * @param xx upper left destination + * @param yy upper left destination + * @param t tile id + */ void T_FillTile(BYTE *P3Tiles, int xx, int yy, int t) { long v1, v2, v3, v4; @@ -1408,7 +1554,7 @@ void T_FillTile(BYTE *P3Tiles, int xx, int yy, int t) nop } #else - v1 = *((WORD *)&P3Tiles[(t - 1) * 8]) + 1; + v1 = *((WORD *)&P3Tiles[(t - 1) * 8] + 0) + 1; v2 = *((WORD *)&P3Tiles[(t - 1) * 8] + 1) + 1; v3 = *((WORD *)&P3Tiles[(t - 1) * 8] + 2) + 1; v4 = *((WORD *)&P3Tiles[(t - 1) * 8] + 3) + 1; @@ -1420,6 +1566,9 @@ void T_FillTile(BYTE *P3Tiles, int xx, int yy, int t) dPiece[xx + 1][yy + 1] = v4; } +/** + * @brief Initialize all of the levels data + */ void T_Pass3() { int xx, yy, x; @@ -1480,6 +1629,10 @@ void T_Pass3() mem_free_dbg(P3Tiles); } +/** + * @brief Initialize town level + * @param entry Methode of entry + */ void CreateTown(int entry) { int x, y; diff --git a/Source/town.h b/Source/town.h index 842a43c7c..5327894d1 100644 --- a/Source/town.h +++ b/Source/town.h @@ -9,12 +9,12 @@ void town_special_upper(BYTE *pBuff, int nCel); void town_draw_clipped_e_flag(BYTE *pBuff, int x, int y, int sx, int sy); void town_draw_clipped_town(BYTE *pBuff, int sx, int sy, int dx, int dy, int eflag); void town_draw_lower(int x, int y, int sx, int sy, int chunks, int eflag); -void town_draw_clipped_e_flag_2(BYTE *pBuff, int x, int y, int skipChunks, int CelSkip, int sx, int sy); -void town_draw_clipped_town_2(BYTE *pBuff, int sx, int sy, int skipChunks, int CelSkip, int dx, int dy, int eflag); -void town_draw_lower_2(int x, int y, int sx, int sy, int chunks, int skipChunks, int eflag); -void town_draw_e_flag(BYTE *pBuff, int x, int y, int capChunks, int CelCap, int sx, int sy); -void town_draw_town_all(BYTE *pBuff, int x, int y, int capChunks, int CelCap, int sx, int sy, int eflag); -void town_draw_upper(int x, int y, int sx, int sy, int chunks, int capChunks, int eflag); +void town_draw_clipped_e_flag_2(BYTE *pBuff, int x, int y, int row, int CelSkip, int sx, int sy); +void town_draw_clipped_town_2(BYTE *pBuff, int sx, int sy, int row, int CelSkip, int dx, int dy, int eflag); +void town_draw_lower_2(int x, int y, int sx, int sy, int chunks, int row, int eflag); +void town_draw_e_flag(BYTE *pBuff, int x, int y, int row, int CelCap, int sx, int sy); +void town_draw_town_all(BYTE *pBuff, int x, int y, int row, int CelCap, int sx, int sy, int eflag); +void town_draw_upper(int x, int y, int sx, int sy, int chunks, int row, int eflag); void T_DrawGame(int x, int y); void T_DrawZoom(int x, int y); void T_DrawView(int StartX, int StartY); From 02b40e27c59570c5eafcfd4bdcc6cfaed983c49b Mon Sep 17 00:00:00 2001 From: galaxyhaxz Date: Sun, 13 Oct 2019 08:44:24 -0500 Subject: [PATCH 08/13] Fix function order [drlg_l2.cpp] --- Source/drlg_l2.cpp | 2572 ++++++++++++++++++++++---------------------- Source/drlg_l2.h | 29 - 2 files changed, 1286 insertions(+), 1315 deletions(-) diff --git a/Source/drlg_l2.cpp b/Source/drlg_l2.cpp index 137132e6c..5b518f62c 100644 --- a/Source/drlg_l2.cpp +++ b/Source/drlg_l2.cpp @@ -233,1173 +233,563 @@ int Patterns[100][10] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }; -void InitDungeon() +static BOOL DRLG_L2PlaceMiniSet(BYTE *miniset, int tmin, int tmax, int cx, int cy, BOOL setview, int ldir) { - int i, j; + int sx, sy, sw, sh, xx, yy, i, ii, numt, bailcnt; + BOOL found; - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) { - predungeon[i][j] = 32; - dflags[i][j] = 0; - } - } -} + sw = miniset[0]; + sh = miniset[1]; -void L2LockoutFix() -{ - int i, j; - BOOL doorok; + if (tmax - tmin == 0) { + numt = 1; + } else { + numt = random_(0, tmax - tmin) + tmin; + } - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) { - if (dungeon[i][j] == 4 && dungeon[i - 1][j] != 3) { - dungeon[i][j] = 1; + for (i = 0; i < numt; i++) { + sx = random_(0, DMAXX - sw); + sy = random_(0, DMAXY - sh); + found = FALSE; + for (bailcnt = 0; !found && bailcnt < 200; bailcnt++) { + found = TRUE; + if (sx >= nSx1 && sx <= nSx2 && sy >= nSy1 && sy <= nSy2) { + found = FALSE; } - if (dungeon[i][j] == 5 && dungeon[i][j - 1] != 3) { - dungeon[i][j] = 2; + if (cx != -1 && sx >= cx - sw && sx <= cx + 12) { + sx = random_(0, DMAXX - sw); + sy = random_(0, DMAXY - sh); + found = FALSE; } - } - } - for (j = 1; j < DMAXY - 1; j++) { - for (i = 1; i < DMAXX - 1; i++) { - if (dflags[i][j] & DLRG_PROTECTED) { - continue; + if (cy != -1 && sy >= cy - sh && sy <= cy + 12) { + sx = random_(0, DMAXX - sw); + sy = random_(0, DMAXY - sh); + found = FALSE; } - if ((dungeon[i][j] == 2 || dungeon[i][j] == 5) && dungeon[i][j - 1] == 3 && dungeon[i][j + 1] == 3) { - doorok = FALSE; - while (1) { - if (dungeon[i][j] != 2 && dungeon[i][j] != 5) { - break; + ii = 2; + for (yy = 0; yy < sh && found == TRUE; yy++) { + for (xx = 0; xx < sw && found == TRUE; xx++) { + if (miniset[ii] != 0 && dungeon[xx + sx][yy + sy] != miniset[ii]) { + found = FALSE; } - if (dungeon[i][j - 1] != 3 || dungeon[i][j + 1] != 3) { - break; + if (dflags[xx + sx][yy + sy] != 0) { + found = FALSE; } - if (dungeon[i][j] == 5) { - doorok = TRUE; + ii++; + } + } + if (!found) { + sx++; + if (sx == DMAXX - sw) { + sx = 0; + sy++; + if (sy == DMAXY - sh) { + sy = 0; } - i++; } - if (!doorok && !(dflags[i - 1][j] & DLRG_PROTECTED)) { - dungeon[i - 1][j] = 5; + } + } + if (bailcnt >= 200) { + return FALSE; + } + ii = sw * sh + 2; + for (yy = 0; yy < sh; yy++) { + for (xx = 0; xx < sw; xx++) { + if (miniset[ii] != 0) { + dungeon[xx + sx][yy + sy] = miniset[ii]; } + ii++; } } } - for (j = 1; j < DMAXX - 1; j++) { /* check: might be flipped */ - for (i = 1; i < DMAXY - 1; i++) { - if (dflags[j][i] & DLRG_PROTECTED) { - continue; + + if (setview == TRUE) { + ViewX = 2 * sx + 21; + ViewY = 2 * sy + 22; + } + if (ldir == 0) { + LvlViewX = 2 * sx + 21; + LvlViewY = 2 * sy + 22; + } + if (ldir == 6) { + LvlViewX = 2 * sx + 21; + LvlViewY = 2 * sy + 22; + } + + return TRUE; +} + +static void DRLG_L2PlaceRndSet(BYTE *miniset, int rndper) +{ + int sx, sy, sw, sh, xx, yy, ii, kk; + BOOL found; + + sw = miniset[0]; + sh = miniset[1]; + + for (sy = 0; sy < DMAXY - sh; sy++) { + for (sx = 0; sx < DMAXX - sw; sx++) { + found = TRUE; + ii = 2; + if (sx >= nSx1 && sx <= nSx2 && sy >= nSy1 && sy <= nSy2) { + found = FALSE; } - if ((dungeon[j][i] == 1 || dungeon[j][i] == 4) && dungeon[j - 1][i] == 3 && dungeon[j + 1][i] == 3) { - doorok = FALSE; - while (1) { - if (dungeon[j][i] != 1 && dungeon[j][i] != 4) { - break; + for (yy = 0; yy < sh && found == TRUE; yy++) { + for (xx = 0; xx < sw && found == TRUE; xx++) { + if (miniset[ii] != 0 && dungeon[xx + sx][yy + sy] != miniset[ii]) { + found = FALSE; } - if (dungeon[j - 1][i] != 3 || dungeon[j + 1][i] != 3) { - break; + if (dflags[xx + sx][yy + sy] != 0) { + found = FALSE; } - if (dungeon[j][i] == 4) { - doorok = TRUE; + ii++; + } + } + kk = sw * sh + 2; + if (found == TRUE) { + for (yy = sy - sh; yy < sy + 2 * sh && found == TRUE; yy++) { + for (xx = sx - sw; xx < sx + 2 * sw; xx++) { + // BUGFIX: yy and xx can go out of bounds + if (dungeon[xx][yy] == miniset[kk]) { + found = FALSE; + } } - i++; } - if (!doorok && !(dflags[j][i - 1] & DLRG_PROTECTED)) { - dungeon[j][i - 1] = 4; + } + if (found == TRUE && random_(0, 100) < rndper) { + for (yy = 0; yy < sh; yy++) { + for (xx = 0; xx < sw; xx++) { + if (miniset[kk] != 0) { + dungeon[xx + sx][yy + sy] = miniset[kk]; + } + kk++; + } } } } } } -void L2DoorFix() +static void DRLG_L2Subs() { - int i, j; + int x, y, i, j, k, rv; + BYTE c; - for (j = 1; j < DMAXY; j++) { - for (i = 1; i < DMAXX; i++) { - if (dungeon[i][j] == 4 && dungeon[i][j - 1] == 3) { - dungeon[i][j] = 7; - } - if (dungeon[i][j] == 5 && dungeon[i - 1][j] == 3) { - dungeon[i][j] = 9; + for (y = 0; y < DMAXY; y++) { + for (x = 0; x < DMAXX; x++) { + if ((x < nSx1 || x > nSx2) && (y < nSy1 || y > nSy2) && random_(0, 4) == 0) { + c = BTYPESL2[dungeon[x][y]]; + if (c != 0) { + rv = random_(0, 16); + k = -1; + while (rv >= 0) { + k++; + if (k == sizeof(BTYPESL2)) { + k = 0; + } + if (c == BTYPESL2[k]) { + rv--; + } + } + for (j = y - 2; j < y + 2; j++) { + for (i = x - 2; i < x + 2; i++) { + if (dungeon[i][j] == k) { + j = y + 3; + i = x + 2; + } + } + } + if (j < y + 3) { + dungeon[x][y] = k; + } + } } } } } -void LoadL2Dungeon(char *sFileName, int vx, int vy) +static void DRLG_L2Shadows() { - int i, j, rw, rh, pc; - BYTE *pLevelMap, *lm; + int x, y, i; + BOOL patflag; + BYTE sd[2][2]; - InitDungeon(); - DRLG_InitTrans(); - pLevelMap = LoadFileInMem(sFileName, NULL); + for (y = 1; y < DMAXY; y++) { + for (x = 1; x < DMAXX; x++) { + sd[0][0] = BSTYPESL2[dungeon[x][y]]; + sd[1][0] = BSTYPESL2[dungeon[x - 1][y]]; + sd[0][1] = BSTYPESL2[dungeon[x][y - 1]]; + sd[1][1] = BSTYPESL2[dungeon[x - 1][y - 1]]; + for (i = 0; i < 2; i++) { + if (SPATSL2[i].strig == sd[0][0]) { + patflag = TRUE; + if (SPATSL2[i].s1 != 0 && SPATSL2[i].s1 != sd[1][1]) { + patflag = FALSE; + } + if (SPATSL2[i].s2 != 0 && SPATSL2[i].s2 != sd[0][1]) { + patflag = FALSE; + } + if (SPATSL2[i].s3 != 0 && SPATSL2[i].s3 != sd[1][0]) { + patflag = FALSE; + } + if (patflag == TRUE) { + if (SPATSL2[i].nv1 != 0) { + dungeon[x - 1][y - 1] = SPATSL2[i].nv1; + } + if (SPATSL2[i].nv2 != 0) { + dungeon[x][y - 1] = SPATSL2[i].nv2; + } + if (SPATSL2[i].nv3 != 0) { + dungeon[x - 1][y] = SPATSL2[i].nv3; + } + } + } + } + } + } +} + +void InitDungeon() +{ + int i, j; for (j = 0; j < DMAXY; j++) { for (i = 0; i < DMAXX; i++) { - dungeon[i][j] = 12; + predungeon[i][j] = 32; dflags[i][j] = 0; } } +} - lm = pLevelMap; - rw = *lm; - lm += 2; - rh = *lm; - lm += 2; +static void DRLG_LoadL2SP() +{ + setloadflag_2 = 0; + + if (QuestStatus(QTYPE_BLIND)) { + pSetPiece_2 = (char *)LoadFileInMem("Levels\\L2Data\\Blind2.DUN", NULL); + setloadflag_2 = 1; + } else if (QuestStatus(QTYPE_BLOOD)) { + pSetPiece_2 = (char *)LoadFileInMem("Levels\\L2Data\\Blood1.DUN", NULL); + setloadflag_2 = 1; + } else if (QuestStatus(QTYPE_BONE)) { + pSetPiece_2 = (char *)LoadFileInMem("Levels\\L2Data\\Bonestr2.DUN", NULL); + setloadflag_2 = 1; + } +} + +static void DRLG_FreeL2SP() +{ + MemFreeDbg(pSetPiece_2); +} + +static void DRLG_L2SetRoom(int rx1, int ry1) +{ + int rw, rh, i, j; + BYTE *sp; + + rw = (BYTE)pSetPiece_2[0]; + rh = (BYTE)pSetPiece_2[2]; + + setpc_x = rx1; + setpc_y = ry1; + setpc_w = rw; + setpc_h = rh; + + sp = (BYTE *)&pSetPiece_2[4]; for (j = 0; j < rh; j++) { for (i = 0; i < rw; i++) { - if (*lm != 0) { - dungeon[i][j] = *lm; - dflags[i][j] |= DLRG_PROTECTED; + if (*sp != 0) { + dungeon[i + rx1][j + ry1] = *sp; + dflags[i + rx1][j + ry1] |= DLRG_PROTECTED; } else { - dungeon[i][j] = 3; - } - lm += 2; - } - } - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) { - if (dungeon[i][j] == 0) { - dungeon[i][j] = 12; + dungeon[i + rx1][j + ry1] = 3; } + sp += 2; } } +} - DRLG_L2Pass3(); - DRLG_Init_Globals(); +static void DefineRoom(int nX1, int nY1, int nX2, int nY2, BOOL ForceHW) +{ + int i, j; - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) { - pc = 0; - if (dPiece[i][j] == 541) { - pc = 5; - } - if (dPiece[i][j] == 178) { - pc = 5; - } - if (dPiece[i][j] == 551) { - pc = 5; - } - if (dPiece[i][j] == 542) { - pc = 6; - } - if (dPiece[i][j] == 553) { - pc = 6; - } - if (dPiece[i][j] == 13) { - pc = 5; - } - if (dPiece[i][j] == 17) { - pc = 6; + predungeon[nX1][nY1] = 67; + predungeon[nX1][nY2] = 69; + predungeon[nX2][nY1] = 66; + predungeon[nX2][nY2] = 65; + + nRoomCnt++; + RoomList[nRoomCnt].nRoomx1 = nX1; + RoomList[nRoomCnt].nRoomx2 = nX2; + RoomList[nRoomCnt].nRoomy1 = nY1; + RoomList[nRoomCnt].nRoomy2 = nY2; + + if (ForceHW == TRUE) { + for (i = nX1; i < nX2; i++) { + /// BUGFIX: Should loop j between nY1 and nY2 instead of always using nY1. + while (i < nY2) { + dflags[i][nY1] |= DLRG_PROTECTED; + i++; } - dArch[i][j] = pc; } } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) { - if (dPiece[i][j] == 132) { - dArch[i][j + 1] = 2; - dArch[i][j + 2] = 1; - } else if (dPiece[i][j] == 135 || dPiece[i][j] == 139) { - dArch[i + 1][j] = 3; - dArch[i + 2][j] = 4; - } + for (i = nX1 + 1; i <= nX2 - 1; i++) { + predungeon[i][nY1] = 35; + predungeon[i][nY2] = 35; + } + nY2--; + for (j = nY1 + 1; j <= nY2; j++) { + predungeon[nX1][j] = 35; + predungeon[nX2][j] = 35; + for (i = nX1 + 1; i < nX2; i++) { + predungeon[i][j] = 46; } } - - ViewX = vx; - ViewY = vy; - SetMapMonsters(pLevelMap, 0, 0); - SetMapObjects(pLevelMap, 0, 0); - mem_free_dbg(pLevelMap); } -void DRLG_L2Pass3() +static void CreateDoorType(int nX, int nY) { - int i, j, xx, yy; - long v1, v2, v3, v4, lv; + BOOL fDoneflag; - lv = 12 - 1; + fDoneflag = FALSE; -#ifdef USE_ASM - __asm { - mov esi, pMegaTiles - mov eax, lv - shl eax, 3 - add esi, eax - xor eax, eax - lodsw - inc eax - mov v1, eax - lodsw - inc eax - mov v2, eax - lodsw - inc eax - mov v3, eax - lodsw - inc eax - mov v4, eax + if (predungeon[nX - 1][nY] == 68) { + fDoneflag = TRUE; } -#else - v1 = *((WORD *)&pMegaTiles[lv * 8] + 0) + 1; - v2 = *((WORD *)&pMegaTiles[lv * 8] + 1) + 1; - v3 = *((WORD *)&pMegaTiles[lv * 8] + 2) + 1; - v4 = *((WORD *)&pMegaTiles[lv * 8] + 3) + 1; -#endif - - for (j = 0; j < MAXDUNY; j += 2) - { - for (i = 0; i < MAXDUNX; i += 2) { - dPiece[i][j] = v1; - dPiece[i + 1][j] = v2; - dPiece[i][j + 1] = v3; - dPiece[i + 1][j + 1] = v4; - } + if (predungeon[nX + 1][nY] == 68) { + fDoneflag = TRUE; + } + if (predungeon[nX][nY - 1] == 68) { + fDoneflag = TRUE; + } + if (predungeon[nX][nY + 1] == 68) { + fDoneflag = TRUE; + } + if (predungeon[nX][nY] == 66 || predungeon[nX][nY] == 67 || predungeon[nX][nY] == 65 || predungeon[nX][nY] == 69) { + fDoneflag = TRUE; } - yy = 16; - for (j = 0; j < DMAXY; j++) { - xx = 16; - for (i = 0; i < DMAXX; i++) { - lv = dungeon[i][j] - 1; -#ifdef USE_ASM - __asm { - mov esi, pMegaTiles - mov eax, lv - shl eax, 3 - add esi, eax - xor eax, eax - lodsw - inc eax - mov v1, eax - lodsw - inc eax - mov v2, eax - lodsw - inc eax - mov v3, eax - lodsw - inc eax - mov v4, eax - } -#else - v1 = *((WORD *)&pMegaTiles[lv * 8] + 0) + 1; - v2 = *((WORD *)&pMegaTiles[lv * 8] + 1) + 1; - v3 = *((WORD *)&pMegaTiles[lv * 8] + 2) + 1; - v4 = *((WORD *)&pMegaTiles[lv * 8] + 3) + 1; -#endif - dPiece[xx][yy] = v1; - dPiece[xx + 1][yy] = v2; - dPiece[xx][yy + 1] = v3; - dPiece[xx + 1][yy + 1] = v4; - xx += 2; - } - yy += 2; + if (!fDoneflag) { + predungeon[nX][nY] = 68; } } -void LoadPreL2Dungeon(char *sFileName, int vx, int vy) +static void PlaceHallExt(int nX, int nY) { - int i, j, rw, rh; - BYTE *pLevelMap, *lm; + if (predungeon[nX][nY] == 32) { + predungeon[nX][nY] = 44; + } +} - InitDungeon(); - DRLG_InitTrans(); - pLevelMap = LoadFileInMem(sFileName, NULL); +static void AddHall(int nX1, int nY1, int nX2, int nY2, int nHd) +{ + HALLNODE *p1, *p2; - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) { - dungeon[i][j] = 12; - dflags[i][j] = 0; + if (pHallList == NULL) { + pHallList = (HALLNODE *)DiabloAllocPtr(sizeof(*pHallList)); + pHallList->nHallx1 = nX1; + pHallList->nHally1 = nY1; + pHallList->nHallx2 = nX2; + pHallList->nHally2 = nY2; + pHallList->nHalldir = nHd; + pHallList->pNext = NULL; + } else { + p1 = (HALLNODE *)DiabloAllocPtr(sizeof(*pHallList)); + p1->nHallx1 = nX1; + p1->nHally1 = nY1; + p1->nHallx2 = nX2; + p1->nHally2 = nY2; + p1->nHalldir = nHd; + p1->pNext = NULL; + p2 = pHallList; + while (p2->pNext != NULL) { + p2 = p2->pNext; } + p2->pNext = p1; } +} - lm = pLevelMap; - rw = *lm; - lm += 2; - rh = *lm; - lm += 2; - - for (j = 0; j < rh; j++) { - for (i = 0; i < rw; i++) { - if (*lm != 0) { - dungeon[i][j] = *lm; - dflags[i][j] |= DLRG_PROTECTED; - } else { - dungeon[i][j] = 3; - } - lm += 2; - } +/** + * Draws a random room rectangle, and then subdivides the rest of the passed in rectangle into 4 and recurses. + * @param nX1 Lower X boundary of the area to draw into. + * @param nY1 Lower Y boundary of the area to draw into. + * @param nX2 Upper X boundary of the area to draw into. + * @param nY2 Upper Y boundary of the area to draw into. + * @param nRDest The room number of the parent room this call was invoked for. Zero for empty + * @param nHDir The direction of the hall from nRDest to this room. + * @param ForceHW If set, nH and nW are used for room size instead of random values. + * @param nH Height of the room, if ForceHW is set. + * @param nW Width of the room, if ForceHW is set. + */ +static void CreateRoom(int nX1, int nY1, int nX2, int nY2, int nRDest, int nHDir, BOOL ForceHW, int nH, int nW) +{ + int nAw, nAh, nRw, nRh, nRx1, nRy1, nRx2, nRy2, nHw, nHh, nHx1, nHy1, nHx2, nHy2, nRid; + + if (nRoomCnt >= 80) { + return; } - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) { - if (dungeon[i][j] == 0) { - dungeon[i][j] = 12; - } - } + + nAw = nX2 - nX1; + nAh = nY2 - nY1; + if (nAw < Area_Min || nAh < Area_Min) { + return; } - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) { - pdungeon[i][j] = dungeon[i][j]; - } + + if (nAw > Room_Max) { + nRw = random_(0, Room_Max - Room_Min) + Room_Min; + } else if (nAw > Room_Min) { + nRw = random_(0, nAw - Room_Min) + Room_Min; + } else { + nRw = nAw; + } + if (nAh > Room_Max) { + nRh = random_(0, Room_Max - Room_Min) + Room_Min; + } else if (nAh > Room_Min) { + nRh = random_(0, nAh - Room_Min) + Room_Min; + } else { + nRh = nAh; } - mem_free_dbg(pLevelMap); -} + if (ForceHW == TRUE) { + nRw = nW; + nRh = nH; + } -void CreateL2Dungeon(DWORD rseed, int entry) -{ - if (gbMaxPlayers == 1) { - if (currlevel == 7 && !quests[QTYPE_BLIND]._qactive) { - currlevel = 6; - CreateL2Dungeon(glSeedTbl[6], 4); - currlevel = 7; - } - if (currlevel == 8) { - if (!quests[QTYPE_BLIND]._qactive) { - currlevel = 6; - CreateL2Dungeon(glSeedTbl[6], 4); - currlevel = 8; - } else { - currlevel = 7; - CreateL2Dungeon(glSeedTbl[7], 4); - currlevel = 8; - } - } + nRx1 = random_(0, nX2 - nX1) + nX1; + nRy1 = random_(0, nY2 - nY1) + nY1; + nRx2 = nRw + nRx1; + nRy2 = nRh + nRy1; + if (nRx2 > nX2) { + nRx2 = nX2; + nRx1 = nX2 - nRw; + } + if (nRy2 > nY2) { + nRy2 = nY2; + nRy1 = nY2 - nRh; } - SetRndSeed(rseed); + if (nRx1 >= 38) { + nRx1 = 38; + } + if (nRy1 >= 38) { + nRy1 = 38; + } + if (nRx1 <= 1) { + nRx1 = 1; + } + if (nRy1 <= 1) { + nRy1 = 1; + } + if (nRx2 >= 38) { + nRx2 = 38; + } + if (nRy2 >= 38) { + nRy2 = 38; + } + if (nRx2 <= 1) { + nRx2 = 1; + } + if (nRy2 <= 1) { + nRy2 = 1; + } + DefineRoom(nRx1, nRy1, nRx2, nRy2, ForceHW); - dminx = 16; - dminy = 16; - dmaxx = 96; - dmaxy = 96; + if (ForceHW == TRUE) { + nSx1 = nRx1 + 2; + nSy1 = nRy1 + 2; + nSx2 = nRx2; + nSy2 = nRy2; + } - DRLG_InitTrans(); - DRLG_InitSetPC(); - DRLG_LoadL2SP(); - DRLG_L2(entry); - DRLG_L2Pass3(); - DRLG_FreeL2SP(); - DRLG_InitL2Vals(); - DRLG_SetPC(); -} + nRid = nRoomCnt; + RoomList[nRid].nRoomDest = nRDest; -void DRLG_LoadL2SP() -{ - setloadflag_2 = 0; + if (nRDest != 0) { + if (nHDir == 1) { + nHx1 = random_(0, nRx2 - nRx1 - 2) + nRx1 + 1; + nHy1 = nRy1; + nHw = RoomList[nRDest].nRoomx2 - RoomList[nRDest].nRoomx1 - 2; + nHx2 = random_(0, nHw) + RoomList[nRDest].nRoomx1 + 1; + nHy2 = RoomList[nRDest].nRoomy2; + } + if (nHDir == 3) { + nHx1 = random_(0, nRx2 - nRx1 - 2) + nRx1 + 1; + nHy1 = nRy2; + nHw = RoomList[nRDest].nRoomx2 - RoomList[nRDest].nRoomx1 - 2; + nHx2 = random_(0, nHw) + RoomList[nRDest].nRoomx1 + 1; + nHy2 = RoomList[nRDest].nRoomy1; + } + if (nHDir == 2) { + nHx1 = nRx2; + nHy1 = random_(0, nRy2 - nRy1 - 2) + nRy1 + 1; + nHx2 = RoomList[nRDest].nRoomx1; + nHh = RoomList[nRDest].nRoomy2 - RoomList[nRDest].nRoomy1 - 2; + nHy2 = random_(0, nHh) + RoomList[nRDest].nRoomy1 + 1; + } + if (nHDir == 4) { + nHx1 = nRx1; + nHy1 = random_(0, nRy2 - nRy1 - 2) + nRy1 + 1; + nHx2 = RoomList[nRDest].nRoomx2; + nHh = RoomList[nRDest].nRoomy2 - RoomList[nRDest].nRoomy1 - 2; + nHy2 = random_(0, nHh) + RoomList[nRDest].nRoomy1 + 1; + } + AddHall(nHx1, nHy1, nHx2, nHy2, nHDir); + } - if (QuestStatus(QTYPE_BLIND)) { - pSetPiece_2 = (char *)LoadFileInMem("Levels\\L2Data\\Blind2.DUN", NULL); - setloadflag_2 = 1; - } else if (QuestStatus(QTYPE_BLOOD)) { - pSetPiece_2 = (char *)LoadFileInMem("Levels\\L2Data\\Blood1.DUN", NULL); - setloadflag_2 = 1; - } else if (QuestStatus(QTYPE_BONE)) { - pSetPiece_2 = (char *)LoadFileInMem("Levels\\L2Data\\Bonestr2.DUN", NULL); - setloadflag_2 = 1; + if (nRh > nRw) { + CreateRoom(nX1 + 2, nY1 + 2, nRx1 - 2, nRy2 - 2, nRid, 2, 0, 0, 0); + CreateRoom(nRx2 + 2, nRy1 + 2, nX2 - 2, nY2 - 2, nRid, 4, 0, 0, 0); + CreateRoom(nX1 + 2, nRy2 + 2, nRx2 - 2, nY2 - 2, nRid, 1, 0, 0, 0); + CreateRoom(nRx1 + 2, nY1 + 2, nX2 - 2, nRy1 - 2, nRid, 3, 0, 0, 0); + } else { + CreateRoom(nX1 + 2, nY1 + 2, nRx2 - 2, nRy1 - 2, nRid, 3, 0, 0, 0); + CreateRoom(nRx1 + 2, nRy2 + 2, nX2 - 2, nY2 - 2, nRid, 1, 0, 0, 0); + CreateRoom(nX1 + 2, nRy1 + 2, nRx1 - 2, nY2 - 2, nRid, 2, 0, 0, 0); + CreateRoom(nRx2 + 2, nY1 + 2, nX2 - 2, nRy2 - 2, nRid, 4, 0, 0, 0); } } -void DRLG_FreeL2SP() +static void GetHall(int *nX1, int *nY1, int *nX2, int *nY2, int *nHd) { - MemFreeDbg(pSetPiece_2); + HALLNODE *p1; + + p1 = pHallList->pNext; + *nX1 = pHallList->nHallx1; + *nY1 = pHallList->nHally1; + *nX2 = pHallList->nHallx2; + *nY2 = pHallList->nHally2; + *nHd = pHallList->nHalldir; + MemFreeDbg(pHallList); + pHallList = p1; } -void DRLG_L2(int entry) +static void ConnectHall(int nX1, int nY1, int nX2, int nY2, int nHd) { - int i, j; - BOOL doneflag; + int nCurrd, nDx, nDy, nRp, nOrigX1, nOrigY1, fMinusFlag, fPlusFlag; + BOOL fDoneflag, fInroom; - doneflag = FALSE; - while (!doneflag) { - nRoomCnt = 0; - InitDungeon(); - DRLG_InitTrans(); - if (!CreateDungeon()) { - continue; + fDoneflag = FALSE; + fMinusFlag = random_(0, 100); + fPlusFlag = random_(0, 100); + nOrigX1 = nX1; + nOrigY1 = nY1; + CreateDoorType(nX1, nY1); + CreateDoorType(nX2, nY2); + nDx = abs(nX2 - nX1); /* unused */ + nDy = abs(nY2 - nY1); /* unused */ + nCurrd = nHd; + nX2 -= Dir_Xadd[nCurrd]; + nY2 -= Dir_Yadd[nCurrd]; + predungeon[nX2][nY2] = 44; + fInroom = FALSE; + + while (!fDoneflag) { + if (nX1 >= 38 && nCurrd == 2) { + nCurrd = 4; } - L2TileFix(); - if (setloadflag_2) { - DRLG_L2SetRoom(nSx1, nSy1); - } - DRLG_L2FloodTVal(); - DRLG_L2TransFix(); - if (entry == 0) { - doneflag = DRLG_L2PlaceMiniSet(USTAIRS, 1, 1, -1, -1, 1, 0); - if (doneflag) { - doneflag = DRLG_L2PlaceMiniSet(DSTAIRS, 1, 1, -1, -1, 0, 1); - if (doneflag && currlevel == 5) { - doneflag = DRLG_L2PlaceMiniSet(WARPSTAIRS, 1, 1, -1, -1, 0, 6); - } - } - ViewY -= 2; - } else if (entry == 1) { - doneflag = DRLG_L2PlaceMiniSet(USTAIRS, 1, 1, -1, -1, 0, 0); - if (doneflag) { - doneflag = DRLG_L2PlaceMiniSet(DSTAIRS, 1, 1, -1, -1, 1, 1); - if (doneflag && currlevel == 5) { - doneflag = DRLG_L2PlaceMiniSet(WARPSTAIRS, 1, 1, -1, -1, 0, 6); - } - } - ViewX--; - } else { - doneflag = DRLG_L2PlaceMiniSet(USTAIRS, 1, 1, -1, -1, 0, 0); - if (doneflag) { - doneflag = DRLG_L2PlaceMiniSet(DSTAIRS, 1, 1, -1, -1, 0, 1); - if (doneflag && currlevel == 5) { - doneflag = DRLG_L2PlaceMiniSet(WARPSTAIRS, 1, 1, -1, -1, 1, 6); - } - } - ViewY -= 2; - } - } - - L2LockoutFix(); - L2DoorFix(); - L2DirtFix(); - - DRLG_PlaceThemeRooms(6, 10, 3, 0, 0); - DRLG_L2PlaceRndSet(CTRDOOR1, 100); - DRLG_L2PlaceRndSet(CTRDOOR2, 100); - DRLG_L2PlaceRndSet(CTRDOOR3, 100); - DRLG_L2PlaceRndSet(CTRDOOR4, 100); - DRLG_L2PlaceRndSet(CTRDOOR5, 100); - DRLG_L2PlaceRndSet(CTRDOOR6, 100); - DRLG_L2PlaceRndSet(CTRDOOR7, 100); - DRLG_L2PlaceRndSet(CTRDOOR8, 100); - DRLG_L2PlaceRndSet(VARCH33, 100); - DRLG_L2PlaceRndSet(VARCH34, 100); - DRLG_L2PlaceRndSet(VARCH35, 100); - DRLG_L2PlaceRndSet(VARCH36, 100); - DRLG_L2PlaceRndSet(VARCH37, 100); - DRLG_L2PlaceRndSet(VARCH38, 100); - DRLG_L2PlaceRndSet(VARCH39, 100); - DRLG_L2PlaceRndSet(VARCH40, 100); - DRLG_L2PlaceRndSet(VARCH1, 100); - DRLG_L2PlaceRndSet(VARCH2, 100); - DRLG_L2PlaceRndSet(VARCH3, 100); - DRLG_L2PlaceRndSet(VARCH4, 100); - DRLG_L2PlaceRndSet(VARCH5, 100); - DRLG_L2PlaceRndSet(VARCH6, 100); - DRLG_L2PlaceRndSet(VARCH7, 100); - DRLG_L2PlaceRndSet(VARCH8, 100); - DRLG_L2PlaceRndSet(VARCH9, 100); - DRLG_L2PlaceRndSet(VARCH10, 100); - DRLG_L2PlaceRndSet(VARCH11, 100); - DRLG_L2PlaceRndSet(VARCH12, 100); - DRLG_L2PlaceRndSet(VARCH13, 100); - DRLG_L2PlaceRndSet(VARCH14, 100); - DRLG_L2PlaceRndSet(VARCH15, 100); - DRLG_L2PlaceRndSet(VARCH16, 100); - DRLG_L2PlaceRndSet(VARCH17, 100); - DRLG_L2PlaceRndSet(VARCH18, 100); - DRLG_L2PlaceRndSet(VARCH19, 100); - DRLG_L2PlaceRndSet(VARCH20, 100); - DRLG_L2PlaceRndSet(VARCH21, 100); - DRLG_L2PlaceRndSet(VARCH22, 100); - DRLG_L2PlaceRndSet(VARCH23, 100); - DRLG_L2PlaceRndSet(VARCH24, 100); - DRLG_L2PlaceRndSet(VARCH25, 100); - DRLG_L2PlaceRndSet(VARCH26, 100); - DRLG_L2PlaceRndSet(VARCH27, 100); - DRLG_L2PlaceRndSet(VARCH28, 100); - DRLG_L2PlaceRndSet(VARCH29, 100); - DRLG_L2PlaceRndSet(VARCH30, 100); - DRLG_L2PlaceRndSet(VARCH31, 100); - DRLG_L2PlaceRndSet(VARCH32, 100); - DRLG_L2PlaceRndSet(HARCH1, 100); - DRLG_L2PlaceRndSet(HARCH2, 100); - DRLG_L2PlaceRndSet(HARCH3, 100); - DRLG_L2PlaceRndSet(HARCH4, 100); - DRLG_L2PlaceRndSet(HARCH5, 100); - DRLG_L2PlaceRndSet(HARCH6, 100); - DRLG_L2PlaceRndSet(HARCH7, 100); - DRLG_L2PlaceRndSet(HARCH8, 100); - DRLG_L2PlaceRndSet(HARCH9, 100); - DRLG_L2PlaceRndSet(HARCH10, 100); - DRLG_L2PlaceRndSet(HARCH11, 100); - DRLG_L2PlaceRndSet(HARCH12, 100); - DRLG_L2PlaceRndSet(HARCH13, 100); - DRLG_L2PlaceRndSet(HARCH14, 100); - DRLG_L2PlaceRndSet(HARCH15, 100); - DRLG_L2PlaceRndSet(HARCH16, 100); - DRLG_L2PlaceRndSet(HARCH17, 100); - DRLG_L2PlaceRndSet(HARCH18, 100); - DRLG_L2PlaceRndSet(HARCH19, 100); - DRLG_L2PlaceRndSet(HARCH20, 100); - DRLG_L2PlaceRndSet(HARCH21, 100); - DRLG_L2PlaceRndSet(HARCH22, 100); - DRLG_L2PlaceRndSet(HARCH23, 100); - DRLG_L2PlaceRndSet(HARCH24, 100); - DRLG_L2PlaceRndSet(HARCH25, 100); - DRLG_L2PlaceRndSet(HARCH26, 100); - DRLG_L2PlaceRndSet(HARCH27, 100); - DRLG_L2PlaceRndSet(HARCH28, 100); - DRLG_L2PlaceRndSet(HARCH29, 100); - DRLG_L2PlaceRndSet(HARCH30, 100); - DRLG_L2PlaceRndSet(HARCH31, 100); - DRLG_L2PlaceRndSet(HARCH32, 100); - DRLG_L2PlaceRndSet(HARCH33, 100); - DRLG_L2PlaceRndSet(HARCH34, 100); - DRLG_L2PlaceRndSet(HARCH35, 100); - DRLG_L2PlaceRndSet(HARCH36, 100); - DRLG_L2PlaceRndSet(HARCH37, 100); - DRLG_L2PlaceRndSet(HARCH38, 100); - DRLG_L2PlaceRndSet(HARCH39, 100); - DRLG_L2PlaceRndSet(HARCH40, 100); - DRLG_L2PlaceRndSet(CRUSHCOL, 99); - DRLG_L2PlaceRndSet(RUINS1, 10); - DRLG_L2PlaceRndSet(RUINS2, 10); - DRLG_L2PlaceRndSet(RUINS3, 10); - DRLG_L2PlaceRndSet(RUINS4, 10); - DRLG_L2PlaceRndSet(RUINS5, 10); - DRLG_L2PlaceRndSet(RUINS6, 10); - DRLG_L2PlaceRndSet(RUINS7, 50); - DRLG_L2PlaceRndSet(PANCREAS1, 1); - DRLG_L2PlaceRndSet(PANCREAS2, 1); - DRLG_L2PlaceRndSet(BIG1, 3); - DRLG_L2PlaceRndSet(BIG2, 3); - DRLG_L2PlaceRndSet(BIG3, 3); - DRLG_L2PlaceRndSet(BIG4, 3); - DRLG_L2PlaceRndSet(BIG5, 3); - DRLG_L2PlaceRndSet(BIG6, 20); - DRLG_L2PlaceRndSet(BIG7, 20); - DRLG_L2PlaceRndSet(BIG8, 3); - DRLG_L2PlaceRndSet(BIG9, 20); - DRLG_L2PlaceRndSet(BIG10, 20); - DRLG_L2Subs(); - DRLG_L2Shadows(); - - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) { - pdungeon[i][j] = dungeon[i][j]; - } - } - - DRLG_Init_Globals(); - DRLG_CheckQuests(nSx1, nSy1); -} - -BOOL DRLG_L2PlaceMiniSet(BYTE *miniset, int tmin, int tmax, int cx, int cy, BOOL setview, int ldir) -{ - int sx, sy, sw, sh, xx, yy, i, ii, numt, bailcnt; - BOOL found; - - sw = miniset[0]; - sh = miniset[1]; - - if (tmax - tmin == 0) { - numt = 1; - } else { - numt = random_(0, tmax - tmin) + tmin; - } - - for (i = 0; i < numt; i++) { - sx = random_(0, DMAXX - sw); - sy = random_(0, DMAXY - sh); - found = FALSE; - for (bailcnt = 0; !found && bailcnt < 200; bailcnt++) { - found = TRUE; - if (sx >= nSx1 && sx <= nSx2 && sy >= nSy1 && sy <= nSy2) { - found = FALSE; - } - if (cx != -1 && sx >= cx - sw && sx <= cx + 12) { - sx = random_(0, DMAXX - sw); - sy = random_(0, DMAXY - sh); - found = FALSE; - } - if (cy != -1 && sy >= cy - sh && sy <= cy + 12) { - sx = random_(0, DMAXX - sw); - sy = random_(0, DMAXY - sh); - found = FALSE; - } - ii = 2; - for (yy = 0; yy < sh && found == TRUE; yy++) { - for (xx = 0; xx < sw && found == TRUE; xx++) { - if (miniset[ii] != 0 && dungeon[xx + sx][yy + sy] != miniset[ii]) { - found = FALSE; - } - if (dflags[xx + sx][yy + sy] != 0) { - found = FALSE; - } - ii++; - } - } - if (!found) { - sx++; - if (sx == DMAXX - sw) { - sx = 0; - sy++; - if (sy == DMAXY - sh) { - sy = 0; - } - } - } - } - if (bailcnt >= 200) { - return FALSE; - } - ii = sw * sh + 2; - for (yy = 0; yy < sh; yy++) { - for (xx = 0; xx < sw; xx++) { - if (miniset[ii] != 0) { - dungeon[xx + sx][yy + sy] = miniset[ii]; - } - ii++; - } - } - } - - if (setview == TRUE) { - ViewX = 2 * sx + 21; - ViewY = 2 * sy + 22; - } - if (ldir == 0) { - LvlViewX = 2 * sx + 21; - LvlViewY = 2 * sy + 22; - } - if (ldir == 6) { - LvlViewX = 2 * sx + 21; - LvlViewY = 2 * sy + 22; - } - - return TRUE; -} - -void DRLG_L2PlaceRndSet(BYTE *miniset, int rndper) -{ - int sx, sy, sw, sh, xx, yy, ii, kk; - BOOL found; - - sw = miniset[0]; - sh = miniset[1]; - - for (sy = 0; sy < DMAXY - sh; sy++) { - for (sx = 0; sx < DMAXX - sw; sx++) { - found = TRUE; - ii = 2; - if (sx >= nSx1 && sx <= nSx2 && sy >= nSy1 && sy <= nSy2) { - found = FALSE; - } - for (yy = 0; yy < sh && found == TRUE; yy++) { - for (xx = 0; xx < sw && found == TRUE; xx++) { - if (miniset[ii] != 0 && dungeon[xx + sx][yy + sy] != miniset[ii]) { - found = FALSE; - } - if (dflags[xx + sx][yy + sy] != 0) { - found = FALSE; - } - ii++; - } - } - kk = sw * sh + 2; - if (found == TRUE) { - for (yy = sy - sh; yy < sy + 2 * sh && found == TRUE; yy++) { - for (xx = sx - sw; xx < sx + 2 * sw; xx++) { - // BUGFIX: yy and xx can go out of bounds - if (dungeon[xx][yy] == miniset[kk]) { - found = FALSE; - } - } - } - } - if (found == TRUE && random_(0, 100) < rndper) { - for (yy = 0; yy < sh; yy++) { - for (xx = 0; xx < sw; xx++) { - if (miniset[kk] != 0) { - dungeon[xx + sx][yy + sy] = miniset[kk]; - } - kk++; - } - } - } - } - } -} - -void DRLG_L2Subs() -{ - int x, y, i, j, k, rv; - BYTE c; - - for (y = 0; y < DMAXY; y++) { - for (x = 0; x < DMAXX; x++) { - if ((x < nSx1 || x > nSx2) && (y < nSy1 || y > nSy2) && random_(0, 4) == 0) { - c = BTYPESL2[dungeon[x][y]]; - if (c != 0) { - rv = random_(0, 16); - k = -1; - while (rv >= 0) { - k++; - if (k == sizeof(BTYPESL2)) { - k = 0; - } - if (c == BTYPESL2[k]) { - rv--; - } - } - for (j = y - 2; j < y + 2; j++) { - for (i = x - 2; i < x + 2; i++) { - if (dungeon[i][j] == k) { - j = y + 3; - i = x + 2; - } - } - } - if (j < y + 3) { - dungeon[x][y] = k; - } - } - } - } - } -} - -void DRLG_L2Shadows() -{ - int x, y, i; - BOOL patflag; - BYTE sd[2][2]; - - for (y = 1; y < DMAXY; y++) { - for (x = 1; x < DMAXX; x++) { - sd[0][0] = BSTYPESL2[dungeon[x][y]]; - sd[1][0] = BSTYPESL2[dungeon[x - 1][y]]; - sd[0][1] = BSTYPESL2[dungeon[x][y - 1]]; - sd[1][1] = BSTYPESL2[dungeon[x - 1][y - 1]]; - for (i = 0; i < 2; i++) { - if (SPATSL2[i].strig == sd[0][0]) { - patflag = TRUE; - if (SPATSL2[i].s1 != 0 && SPATSL2[i].s1 != sd[1][1]) { - patflag = FALSE; - } - if (SPATSL2[i].s2 != 0 && SPATSL2[i].s2 != sd[0][1]) { - patflag = FALSE; - } - if (SPATSL2[i].s3 != 0 && SPATSL2[i].s3 != sd[1][0]) { - patflag = FALSE; - } - if (patflag == TRUE) { - if (SPATSL2[i].nv1 != 0) { - dungeon[x - 1][y - 1] = SPATSL2[i].nv1; - } - if (SPATSL2[i].nv2 != 0) { - dungeon[x][y - 1] = SPATSL2[i].nv2; - } - if (SPATSL2[i].nv3 != 0) { - dungeon[x - 1][y] = SPATSL2[i].nv3; - } - } - } - } - } - } -} - -void DRLG_L2SetRoom(int rx1, int ry1) -{ - int rw, rh, i, j; - BYTE *sp; - - rw = (BYTE)pSetPiece_2[0]; - rh = (BYTE)pSetPiece_2[2]; - - setpc_x = rx1; - setpc_y = ry1; - setpc_w = rw; - setpc_h = rh; - - sp = (BYTE *)&pSetPiece_2[4]; - - for (j = 0; j < rh; j++) { - for (i = 0; i < rw; i++) { - if (*sp != 0) { - dungeon[i + rx1][j + ry1] = *sp; - dflags[i + rx1][j + ry1] |= DLRG_PROTECTED; - } else { - dungeon[i + rx1][j + ry1] = 3; - } - sp += 2; - } - } -} - -void L2TileFix() -{ - int i, j; - - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) { - if (dungeon[i][j] == 1 && dungeon[i][j + 1] == 3) { - dungeon[i][j + 1] = 1; - } - if (dungeon[i][j] == 3 && dungeon[i][j + 1] == 1) { - dungeon[i][j + 1] = 3; - } - if (dungeon[i][j] == 3 && dungeon[i + 1][j] == 7) { - dungeon[i + 1][j] = 3; - } - if (dungeon[i][j] == 2 && dungeon[i + 1][j] == 3) { - dungeon[i + 1][j] = 2; - } - if (dungeon[i][j] == 11 && dungeon[i + 1][j] == 14) { - dungeon[i + 1][j] = 16; - } - } - } -} - -BOOL CreateDungeon() -{ - int i, j, nHx1, nHy1, nHx2, nHy2, nHd, ForceH, ForceW; - BOOL ForceHW; - - ForceW = 0; - ForceH = 0; - ForceHW = FALSE; - - switch (currlevel) { - case 5: - if (quests[QTYPE_BLOOD]._qactive) { - ForceHW = TRUE; - ForceH = 20; - ForceW = 14; - } - break; - case 6: - if (quests[QTYPE_BONE]._qactive) { - ForceHW = TRUE; - ForceW = 10; - ForceH = 10; - } - break; - case 7: - if (quests[QTYPE_BLIND]._qactive) { - ForceHW = TRUE; - ForceW = 15; - ForceH = 15; - } - break; - case 8: - break; - } - - CreateRoom(2, 2, DMAXX - 1, DMAXY - 1, 0, 0, ForceHW, ForceH, ForceW); - - while (pHallList != NULL) { - GetHall(&nHx1, &nHy1, &nHx2, &nHy2, &nHd); - ConnectHall(nHx1, nHy1, nHx2, nHy2, nHd); - } - - for (j = 0; j <= DMAXY; j++) { /// BUGFIX: change '<=' to '<' - for (i = 0; i <= DMAXX; i++) { /// BUGFIX: change '<=' to '<' - if (predungeon[i][j] == 67) { - predungeon[i][j] = 35; - } - if (predungeon[i][j] == 66) { - predungeon[i][j] = 35; - } - if (predungeon[i][j] == 69) { - predungeon[i][j] = 35; - } - if (predungeon[i][j] == 65) { - predungeon[i][j] = 35; - } - if (predungeon[i][j] == 44) { - predungeon[i][j] = 46; - if (predungeon[i - 1][j - 1] == 32) { - predungeon[i - 1][j - 1] = 35; - } - if (predungeon[i - 1][j] == 32) { - predungeon[i - 1][j] = 35; - } - if (predungeon[i - 1][1 + j] == 32) { - predungeon[i - 1][1 + j] = 35; - } - if (predungeon[i + 1][j - 1] == 32) { - predungeon[i + 1][j - 1] = 35; - } - if (predungeon[i + 1][j] == 32) { - predungeon[i + 1][j] = 35; - } - if (predungeon[i + 1][1 + j] == 32) { - predungeon[i + 1][1 + j] = 35; - } - if (predungeon[i][j - 1] == 32) { - predungeon[i][j - 1] = 35; - } - if (predungeon[i][j + 1] == 32) { - predungeon[i][j + 1] = 35; - } - } - } - } - - if (!DL2_FillVoids()) { - return FALSE; - } - - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) { - DoPatternCheck(i, j); - } - } - - return TRUE; -} - -/** - * Draws a random room rectangle, and then subdivides the rest of the passed in rectangle into 4 and recurses. - * @param nX1 Lower X boundary of the area to draw into. - * @param nY1 Lower Y boundary of the area to draw into. - * @param nX2 Upper X boundary of the area to draw into. - * @param nY2 Upper Y boundary of the area to draw into. - * @param nRDest The room number of the parent room this call was invoked for. Zero for empty - * @param nHDir The direction of the hall from nRDest to this room. - * @param ForceHW If set, nH and nW are used for room size instead of random values. - * @param nH Height of the room, if ForceHW is set. - * @param nW Width of the room, if ForceHW is set. - */ -void CreateRoom(int nX1, int nY1, int nX2, int nY2, int nRDest, int nHDir, BOOL ForceHW, int nH, int nW) -{ - int nAw, nAh, nRw, nRh, nRx1, nRy1, nRx2, nRy2, nHw, nHh, nHx1, nHy1, nHx2, nHy2, nRid; - - if (nRoomCnt >= 80) { - return; - } - - nAw = nX2 - nX1; - nAh = nY2 - nY1; - if (nAw < Area_Min || nAh < Area_Min) { - return; - } - - if (nAw > Room_Max) { - nRw = random_(0, Room_Max - Room_Min) + Room_Min; - } else if (nAw > Room_Min) { - nRw = random_(0, nAw - Room_Min) + Room_Min; - } else { - nRw = nAw; - } - if (nAh > Room_Max) { - nRh = random_(0, Room_Max - Room_Min) + Room_Min; - } else if (nAh > Room_Min) { - nRh = random_(0, nAh - Room_Min) + Room_Min; - } else { - nRh = nAh; - } - - if (ForceHW == TRUE) { - nRw = nW; - nRh = nH; - } - - nRx1 = random_(0, nX2 - nX1) + nX1; - nRy1 = random_(0, nY2 - nY1) + nY1; - nRx2 = nRw + nRx1; - nRy2 = nRh + nRy1; - if (nRx2 > nX2) { - nRx2 = nX2; - nRx1 = nX2 - nRw; - } - if (nRy2 > nY2) { - nRy2 = nY2; - nRy1 = nY2 - nRh; - } - - if (nRx1 >= 38) { - nRx1 = 38; - } - if (nRy1 >= 38) { - nRy1 = 38; - } - if (nRx1 <= 1) { - nRx1 = 1; - } - if (nRy1 <= 1) { - nRy1 = 1; - } - if (nRx2 >= 38) { - nRx2 = 38; - } - if (nRy2 >= 38) { - nRy2 = 38; - } - if (nRx2 <= 1) { - nRx2 = 1; - } - if (nRy2 <= 1) { - nRy2 = 1; - } - DefineRoom(nRx1, nRy1, nRx2, nRy2, ForceHW); - - if (ForceHW == TRUE) { - nSx1 = nRx1 + 2; - nSy1 = nRy1 + 2; - nSx2 = nRx2; - nSy2 = nRy2; - } - - nRid = nRoomCnt; - RoomList[nRid].nRoomDest = nRDest; - - if (nRDest != 0) { - if (nHDir == 1) { - nHx1 = random_(0, nRx2 - nRx1 - 2) + nRx1 + 1; - nHy1 = nRy1; - nHw = RoomList[nRDest].nRoomx2 - RoomList[nRDest].nRoomx1 - 2; - nHx2 = random_(0, nHw) + RoomList[nRDest].nRoomx1 + 1; - nHy2 = RoomList[nRDest].nRoomy2; - } - if (nHDir == 3) { - nHx1 = random_(0, nRx2 - nRx1 - 2) + nRx1 + 1; - nHy1 = nRy2; - nHw = RoomList[nRDest].nRoomx2 - RoomList[nRDest].nRoomx1 - 2; - nHx2 = random_(0, nHw) + RoomList[nRDest].nRoomx1 + 1; - nHy2 = RoomList[nRDest].nRoomy1; - } - if (nHDir == 2) { - nHx1 = nRx2; - nHy1 = random_(0, nRy2 - nRy1 - 2) + nRy1 + 1; - nHx2 = RoomList[nRDest].nRoomx1; - nHh = RoomList[nRDest].nRoomy2 - RoomList[nRDest].nRoomy1 - 2; - nHy2 = random_(0, nHh) + RoomList[nRDest].nRoomy1 + 1; - } - if (nHDir == 4) { - nHx1 = nRx1; - nHy1 = random_(0, nRy2 - nRy1 - 2) + nRy1 + 1; - nHx2 = RoomList[nRDest].nRoomx2; - nHh = RoomList[nRDest].nRoomy2 - RoomList[nRDest].nRoomy1 - 2; - nHy2 = random_(0, nHh) + RoomList[nRDest].nRoomy1 + 1; - } - AddHall(nHx1, nHy1, nHx2, nHy2, nHDir); - } - - if (nRh > nRw) { - CreateRoom(nX1 + 2, nY1 + 2, nRx1 - 2, nRy2 - 2, nRid, 2, 0, 0, 0); - CreateRoom(nRx2 + 2, nRy1 + 2, nX2 - 2, nY2 - 2, nRid, 4, 0, 0, 0); - CreateRoom(nX1 + 2, nRy2 + 2, nRx2 - 2, nY2 - 2, nRid, 1, 0, 0, 0); - CreateRoom(nRx1 + 2, nY1 + 2, nX2 - 2, nRy1 - 2, nRid, 3, 0, 0, 0); - } else { - CreateRoom(nX1 + 2, nY1 + 2, nRx2 - 2, nRy1 - 2, nRid, 3, 0, 0, 0); - CreateRoom(nRx1 + 2, nRy2 + 2, nX2 - 2, nY2 - 2, nRid, 1, 0, 0, 0); - CreateRoom(nX1 + 2, nRy1 + 2, nRx1 - 2, nY2 - 2, nRid, 2, 0, 0, 0); - CreateRoom(nRx2 + 2, nY1 + 2, nX2 - 2, nRy2 - 2, nRid, 4, 0, 0, 0); - } -} - -void DefineRoom(int nX1, int nY1, int nX2, int nY2, BOOL ForceHW) -{ - int i, j; - - predungeon[nX1][nY1] = 67; - predungeon[nX1][nY2] = 69; - predungeon[nX2][nY1] = 66; - predungeon[nX2][nY2] = 65; - - nRoomCnt++; - RoomList[nRoomCnt].nRoomx1 = nX1; - RoomList[nRoomCnt].nRoomx2 = nX2; - RoomList[nRoomCnt].nRoomy1 = nY1; - RoomList[nRoomCnt].nRoomy2 = nY2; - - if (ForceHW == TRUE) { - for (i = nX1; i < nX2; i++) { - /// BUGFIX: Should loop j between nY1 and nY2 instead of always using nY1. - while (i < nY2) { - dflags[i][nY1] |= DLRG_PROTECTED; - i++; - } - } - } - for (i = nX1 + 1; i <= nX2 - 1; i++) { - predungeon[i][nY1] = 35; - predungeon[i][nY2] = 35; - } - nY2--; - for (j = nY1 + 1; j <= nY2; j++) { - predungeon[nX1][j] = 35; - predungeon[nX2][j] = 35; - for (i = nX1 + 1; i < nX2; i++) { - predungeon[i][j] = 46; - } - } -} - -void AddHall(int nX1, int nY1, int nX2, int nY2, int nHd) -{ - HALLNODE *p1, *p2; - - if (pHallList == NULL) { - pHallList = (HALLNODE *)DiabloAllocPtr(sizeof(*pHallList)); - pHallList->nHallx1 = nX1; - pHallList->nHally1 = nY1; - pHallList->nHallx2 = nX2; - pHallList->nHally2 = nY2; - pHallList->nHalldir = nHd; - pHallList->pNext = NULL; - } else { - p1 = (HALLNODE *)DiabloAllocPtr(sizeof(*pHallList)); - p1->nHallx1 = nX1; - p1->nHally1 = nY1; - p1->nHallx2 = nX2; - p1->nHally2 = nY2; - p1->nHalldir = nHd; - p1->pNext = NULL; - p2 = pHallList; - while (p2->pNext != NULL) { - p2 = p2->pNext; - } - p2->pNext = p1; - } -} - -void GetHall(int *nX1, int *nY1, int *nX2, int *nY2, int *nHd) -{ - HALLNODE *p1; - - p1 = pHallList->pNext; - *nX1 = pHallList->nHallx1; - *nY1 = pHallList->nHally1; - *nX2 = pHallList->nHallx2; - *nY2 = pHallList->nHally2; - *nHd = pHallList->nHalldir; - MemFreeDbg(pHallList); - pHallList = p1; -} - -void ConnectHall(int nX1, int nY1, int nX2, int nY2, int nHd) -{ - int nCurrd, nDx, nDy, nRp, nOrigX1, nOrigY1, fMinusFlag, fPlusFlag; - BOOL fDoneflag, fInroom; - - fDoneflag = FALSE; - fMinusFlag = random_(0, 100); - fPlusFlag = random_(0, 100); - nOrigX1 = nX1; - nOrigY1 = nY1; - CreateDoorType(nX1, nY1); - CreateDoorType(nX2, nY2); - nDx = abs(nX2 - nX1); /* unused */ - nDy = abs(nY2 - nY1); /* unused */ - nCurrd = nHd; - nX2 -= Dir_Xadd[nCurrd]; - nY2 -= Dir_Yadd[nCurrd]; - predungeon[nX2][nY2] = 44; - fInroom = FALSE; - - while (!fDoneflag) { - if (nX1 >= 38 && nCurrd == 2) { - nCurrd = 4; - } - if (nY1 >= 38 && nCurrd == 3) { - nCurrd = 1; + if (nY1 >= 38 && nCurrd == 3) { + nCurrd = 1; } if (nX1 <= 1 && nCurrd == 4) { nCurrd = 2; @@ -1525,41 +915,7 @@ void ConnectHall(int nX1, int nY1, int nX2, int nY2, int nHd) } } -void CreateDoorType(int nX, int nY) -{ - BOOL fDoneflag; - - fDoneflag = FALSE; - - if (predungeon[nX - 1][nY] == 68) { - fDoneflag = TRUE; - } - if (predungeon[nX + 1][nY] == 68) { - fDoneflag = TRUE; - } - if (predungeon[nX][nY - 1] == 68) { - fDoneflag = TRUE; - } - if (predungeon[nX][nY + 1] == 68) { - fDoneflag = TRUE; - } - if (predungeon[nX][nY] == 66 || predungeon[nX][nY] == 67 || predungeon[nX][nY] == 65 || predungeon[nX][nY] == 69) { - fDoneflag = TRUE; - } - - if (!fDoneflag) { - predungeon[nX][nY] = 68; - } -} - -void PlaceHallExt(int nX, int nY) -{ - if (predungeon[nX][nY] == 32) { - predungeon[nX][nY] = 44; - } -} - -void DoPatternCheck(int i, int j) +static void DoPatternCheck(int i, int j) { int k, l, x, y, nOk; @@ -1630,7 +986,116 @@ void DoPatternCheck(int i, int j) } } -BOOL DL2_FillVoids() +static void L2TileFix() +{ + int i, j; + + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) { + if (dungeon[i][j] == 1 && dungeon[i][j + 1] == 3) { + dungeon[i][j + 1] = 1; + } + if (dungeon[i][j] == 3 && dungeon[i][j + 1] == 1) { + dungeon[i][j + 1] = 3; + } + if (dungeon[i][j] == 3 && dungeon[i + 1][j] == 7) { + dungeon[i + 1][j] = 3; + } + if (dungeon[i][j] == 2 && dungeon[i + 1][j] == 3) { + dungeon[i + 1][j] = 2; + } + if (dungeon[i][j] == 11 && dungeon[i + 1][j] == 14) { + dungeon[i + 1][j] = 16; + } + } + } +} + +static BOOL DL2_Cont(BOOL x1f, BOOL y1f, BOOL x2f, BOOL y2f) +{ + if (x1f && x2f && y1f && y2f) { + return FALSE; + } + if (x1f && x2f && (y1f || y2f)) { + return TRUE; + } + if (y1f && y2f && (x1f || x2f)) { + return TRUE; + } + + return FALSE; +} + +static int DL2_NumNoChar() +{ + int t, ii, jj; + + t = 0; + for (jj = 0; jj < DMAXY; jj++) { + for (ii = 0; ii < DMAXX; ii++) { + if (predungeon[ii][jj] == 32) { + t++; + } + } + } + + return t; +} + +static void DL2_DrawRoom(int x1, int y1, int x2, int y2) +{ + int ii, jj; + + for (jj = y1; jj <= y2; jj++) { + for (ii = x1; ii <= x2; ii++) { + predungeon[ii][jj] = 46; + } + } + for (jj = y1; jj <= y2; jj++) { + predungeon[x1][jj] = 35; + predungeon[x2][jj] = 35; + } + for (ii = x1; ii <= x2; ii++) { + predungeon[ii][y1] = 35; + predungeon[ii][y2] = 35; + } +} + +static void DL2_KnockWalls(int x1, int y1, int x2, int y2) +{ + int ii, jj; + + for (ii = x1 + 1; ii < x2; ii++) { + if (predungeon[ii][y1 - 1] == 46 && predungeon[ii][y1 + 1] == 46) { + predungeon[ii][y1] = 46; + } + if (predungeon[ii][y2 - 1] == 46 && predungeon[ii][y2 + 1] == 46) { + predungeon[ii][y2] = 46; + } + if (predungeon[ii][y1 - 1] == 68) { + predungeon[ii][y1 - 1] = 46; + } + if (predungeon[ii][y2 + 1] == 68) { + predungeon[ii][y2 + 1] = 46; + } + } + for (jj = y1 + 1; jj < y2; jj++) { + if (predungeon[x1 - 1][jj] == 46 && predungeon[x1 + 1][jj] == 46) { + predungeon[x1][jj] = 46; + } + if (predungeon[x2 - 1][jj] == 46 && predungeon[x2 + 1][jj] == 46) { + predungeon[x2][jj] = 46; + } + if (predungeon[x1 - 1][jj] == 68) { + predungeon[x1 - 1][jj] = 46; + } + if (predungeon[x2 + 1][jj] == 68) { + predungeon[x2 + 1][jj] = 46; + } + } +} + +static BOOL DL2_FillVoids() { int ii, jj, xx, yy, x1, x2, y1, y2; BOOL xf1, xf2, yf1, yf2; @@ -1896,246 +1361,688 @@ BOOL DL2_FillVoids() } } } - to++; + to++; + } + + return DL2_NumNoChar() <= 700; +} + +static BOOL CreateDungeon() +{ + int i, j, nHx1, nHy1, nHx2, nHy2, nHd, ForceH, ForceW; + BOOL ForceHW; + + ForceW = 0; + ForceH = 0; + ForceHW = FALSE; + + switch (currlevel) { + case 5: + if (quests[QTYPE_BLOOD]._qactive) { + ForceHW = TRUE; + ForceH = 20; + ForceW = 14; + } + break; + case 6: + if (quests[QTYPE_BONE]._qactive) { + ForceHW = TRUE; + ForceW = 10; + ForceH = 10; + } + break; + case 7: + if (quests[QTYPE_BLIND]._qactive) { + ForceHW = TRUE; + ForceW = 15; + ForceH = 15; + } + break; + case 8: + break; + } + + CreateRoom(2, 2, DMAXX - 1, DMAXY - 1, 0, 0, ForceHW, ForceH, ForceW); + + while (pHallList != NULL) { + GetHall(&nHx1, &nHy1, &nHx2, &nHy2, &nHd); + ConnectHall(nHx1, nHy1, nHx2, nHy2, nHd); + } + + for (j = 0; j <= DMAXY; j++) { /// BUGFIX: change '<=' to '<' + for (i = 0; i <= DMAXX; i++) { /// BUGFIX: change '<=' to '<' + if (predungeon[i][j] == 67) { + predungeon[i][j] = 35; + } + if (predungeon[i][j] == 66) { + predungeon[i][j] = 35; + } + if (predungeon[i][j] == 69) { + predungeon[i][j] = 35; + } + if (predungeon[i][j] == 65) { + predungeon[i][j] = 35; + } + if (predungeon[i][j] == 44) { + predungeon[i][j] = 46; + if (predungeon[i - 1][j - 1] == 32) { + predungeon[i - 1][j - 1] = 35; + } + if (predungeon[i - 1][j] == 32) { + predungeon[i - 1][j] = 35; + } + if (predungeon[i - 1][1 + j] == 32) { + predungeon[i - 1][1 + j] = 35; + } + if (predungeon[i + 1][j - 1] == 32) { + predungeon[i + 1][j - 1] = 35; + } + if (predungeon[i + 1][j] == 32) { + predungeon[i + 1][j] = 35; + } + if (predungeon[i + 1][1 + j] == 32) { + predungeon[i + 1][1 + j] = 35; + } + if (predungeon[i][j - 1] == 32) { + predungeon[i][j - 1] = 35; + } + if (predungeon[i][j + 1] == 32) { + predungeon[i][j + 1] = 35; + } + } + } + } + + if (!DL2_FillVoids()) { + return FALSE; + } + + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) { + DoPatternCheck(i, j); + } + } + + return TRUE; +} + +static void DRLG_L2Pass3() +{ + int i, j, xx, yy; + long v1, v2, v3, v4, lv; + + lv = 12 - 1; + +#ifdef USE_ASM + __asm { + mov esi, pMegaTiles + mov eax, lv + shl eax, 3 + add esi, eax + xor eax, eax + lodsw + inc eax + mov v1, eax + lodsw + inc eax + mov v2, eax + lodsw + inc eax + mov v3, eax + lodsw + inc eax + mov v4, eax + } +#else + v1 = *((WORD *)&pMegaTiles[lv * 8] + 0) + 1; + v2 = *((WORD *)&pMegaTiles[lv * 8] + 1) + 1; + v3 = *((WORD *)&pMegaTiles[lv * 8] + 2) + 1; + v4 = *((WORD *)&pMegaTiles[lv * 8] + 3) + 1; +#endif + + for (j = 0; j < MAXDUNY; j += 2) + { + for (i = 0; i < MAXDUNX; i += 2) { + dPiece[i][j] = v1; + dPiece[i + 1][j] = v2; + dPiece[i][j + 1] = v3; + dPiece[i + 1][j + 1] = v4; + } } - return DL2_NumNoChar() <= 700; + yy = 16; + for (j = 0; j < DMAXY; j++) { + xx = 16; + for (i = 0; i < DMAXX; i++) { + lv = dungeon[i][j] - 1; +#ifdef USE_ASM + __asm { + mov esi, pMegaTiles + mov eax, lv + shl eax, 3 + add esi, eax + xor eax, eax + lodsw + inc eax + mov v1, eax + lodsw + inc eax + mov v2, eax + lodsw + inc eax + mov v3, eax + lodsw + inc eax + mov v4, eax + } +#else + v1 = *((WORD *)&pMegaTiles[lv * 8] + 0) + 1; + v2 = *((WORD *)&pMegaTiles[lv * 8] + 1) + 1; + v3 = *((WORD *)&pMegaTiles[lv * 8] + 2) + 1; + v4 = *((WORD *)&pMegaTiles[lv * 8] + 3) + 1; +#endif + dPiece[xx][yy] = v1; + dPiece[xx + 1][yy] = v2; + dPiece[xx][yy + 1] = v3; + dPiece[xx + 1][yy + 1] = v4; + xx += 2; + } + yy += 2; + } } -BOOL DL2_Cont(BOOL x1f, BOOL y1f, BOOL x2f, BOOL y2f) +static void DRLG_L2FTVR(int i, int j, int x, int y, int d) { - if (x1f && x2f && y1f && y2f) { - return FALSE; + if (dTransVal[x][y] != 0 || dungeon[i][j] != 3) { + if (d == 1) { + dTransVal[x][y] = TransVal; + dTransVal[x][y + 1] = TransVal; + } + if (d == 2) { + dTransVal[x + 1][y] = TransVal; + dTransVal[x + 1][y + 1] = TransVal; + } + if (d == 3) { + dTransVal[x][y] = TransVal; + dTransVal[x + 1][y] = TransVal; + } + if (d == 4) { + dTransVal[x][y + 1] = TransVal; + dTransVal[x + 1][y + 1] = TransVal; + } + if (d == 5) { + dTransVal[x + 1][y + 1] = TransVal; + } + if (d == 6) { + dTransVal[x][y + 1] = TransVal; + } + if (d == 7) { + dTransVal[x + 1][y] = TransVal; + } + if (d == 8) { + dTransVal[x][y] = TransVal; + } + } else { + dTransVal[x][y] = TransVal; + dTransVal[x + 1][y] = TransVal; + dTransVal[x][y + 1] = TransVal; + dTransVal[x + 1][y + 1] = TransVal; + DRLG_L2FTVR(i + 1, j, x + 2, y, 1); + DRLG_L2FTVR(i - 1, j, x - 2, y, 2); + DRLG_L2FTVR(i, j + 1, x, y + 2, 3); + DRLG_L2FTVR(i, j - 1, x, y - 2, 4); + DRLG_L2FTVR(i - 1, j - 1, x - 2, y - 2, 5); + DRLG_L2FTVR(i + 1, j - 1, x + 2, y - 2, 6); + DRLG_L2FTVR(i - 1, j + 1, x - 2, y + 2, 7); + DRLG_L2FTVR(i + 1, j + 1, x + 2, y + 2, 8); } - if (x1f && x2f && (y1f || y2f)) { - return TRUE; +} + +static void DRLG_L2FloodTVal() +{ + int i, j, xx, yy; + + yy = 16; + for (j = 0; j < DMAXY; j++) { + xx = 16; + for (i = 0; i < DMAXX; i++) { + if (dungeon[i][j] == 3 && dTransVal[xx][yy] == 0) { + DRLG_L2FTVR(i, j, xx, yy, 0); + TransVal++; + } + xx += 2; + } + yy += 2; } - if (y1f && y2f && (x1f || x2f)) { - return TRUE; +} + +static void DRLG_L2TransFix() +{ + int i, j, xx, yy; + + yy = 16; + for (j = 0; j < DMAXY; j++) { + xx = 16; + for (i = 0; i < DMAXX; i++) { + if (dungeon[i][j] == 14 && dungeon[i][j - 1] == 10) { + dTransVal[xx + 1][yy] = dTransVal[xx][yy]; + dTransVal[xx + 1][yy + 1] = dTransVal[xx][yy]; + } + if (dungeon[i][j] == 15 && dungeon[i + 1][j] == 11) { + dTransVal[xx][yy + 1] = dTransVal[xx][yy]; + dTransVal[xx + 1][yy + 1] = dTransVal[xx][yy]; + } + if (dungeon[i][j] == 10) { + dTransVal[xx + 1][yy] = dTransVal[xx][yy]; + dTransVal[xx + 1][yy + 1] = dTransVal[xx][yy]; + } + if (dungeon[i][j] == 11) { + dTransVal[xx][yy + 1] = dTransVal[xx][yy]; + dTransVal[xx + 1][yy + 1] = dTransVal[xx][yy]; + } + if (dungeon[i][j] == 16) { + dTransVal[xx + 1][yy] = dTransVal[xx][yy]; + dTransVal[xx][yy + 1] = dTransVal[xx][yy]; + dTransVal[xx + 1][yy + 1] = dTransVal[xx][yy]; + } + xx += 2; + } + yy += 2; } +} - return FALSE; +static void L2DirtFix() +{ + int i, j; + + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) { + if (dungeon[i][j] == 13 && dungeon[i + 1][j] != 11) { + dungeon[i][j] = 146; + } + if (dungeon[i][j] == 11 && dungeon[i + 1][j] != 11) { + dungeon[i][j] = 144; + } + if (dungeon[i][j] == 15 && dungeon[i + 1][j] != 11) { + dungeon[i][j] = 148; + } + if (dungeon[i][j] == 10 && dungeon[i][j + 1] != 10) { + dungeon[i][j] = 143; + } + if (dungeon[i][j] == 13 && dungeon[i][j + 1] != 10) { + dungeon[i][j] = 146; + } + if (dungeon[i][j] == 14 && dungeon[i][j + 1] != 15) { + dungeon[i][j] = 147; + } + } + } } -int DL2_NumNoChar() +void L2LockoutFix() { - int t, ii, jj; + int i, j; + BOOL doorok; - t = 0; - for (jj = 0; jj < DMAXY; jj++) { - for (ii = 0; ii < DMAXX; ii++) { - if (predungeon[ii][jj] == 32) { - t++; + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) { + if (dungeon[i][j] == 4 && dungeon[i - 1][j] != 3) { + dungeon[i][j] = 1; + } + if (dungeon[i][j] == 5 && dungeon[i][j - 1] != 3) { + dungeon[i][j] = 2; + } + } + } + for (j = 1; j < DMAXY - 1; j++) { + for (i = 1; i < DMAXX - 1; i++) { + if (dflags[i][j] & DLRG_PROTECTED) { + continue; + } + if ((dungeon[i][j] == 2 || dungeon[i][j] == 5) && dungeon[i][j - 1] == 3 && dungeon[i][j + 1] == 3) { + doorok = FALSE; + while (1) { + if (dungeon[i][j] != 2 && dungeon[i][j] != 5) { + break; + } + if (dungeon[i][j - 1] != 3 || dungeon[i][j + 1] != 3) { + break; + } + if (dungeon[i][j] == 5) { + doorok = TRUE; + } + i++; + } + if (!doorok && !(dflags[i - 1][j] & DLRG_PROTECTED)) { + dungeon[i - 1][j] = 5; + } + } + } + } + for (j = 1; j < DMAXX - 1; j++) { /* check: might be flipped */ + for (i = 1; i < DMAXY - 1; i++) { + if (dflags[j][i] & DLRG_PROTECTED) { + continue; + } + if ((dungeon[j][i] == 1 || dungeon[j][i] == 4) && dungeon[j - 1][i] == 3 && dungeon[j + 1][i] == 3) { + doorok = FALSE; + while (1) { + if (dungeon[j][i] != 1 && dungeon[j][i] != 4) { + break; + } + if (dungeon[j - 1][i] != 3 || dungeon[j + 1][i] != 3) { + break; + } + if (dungeon[j][i] == 4) { + doorok = TRUE; + } + i++; + } + if (!doorok && !(dflags[j][i - 1] & DLRG_PROTECTED)) { + dungeon[j][i - 1] = 4; + } } } } - - return t; } -void DL2_DrawRoom(int x1, int y1, int x2, int y2) +void L2DoorFix() { - int ii, jj; + int i, j; - for (jj = y1; jj <= y2; jj++) { - for (ii = x1; ii <= x2; ii++) { - predungeon[ii][jj] = 46; + for (j = 1; j < DMAXY; j++) { + for (i = 1; i < DMAXX; i++) { + if (dungeon[i][j] == 4 && dungeon[i][j - 1] == 3) { + dungeon[i][j] = 7; + } + if (dungeon[i][j] == 5 && dungeon[i - 1][j] == 3) { + dungeon[i][j] = 9; + } } } - for (jj = y1; jj <= y2; jj++) { - predungeon[x1][jj] = 35; - predungeon[x2][jj] = 35; - } - for (ii = x1; ii <= x2; ii++) { - predungeon[ii][y1] = 35; - predungeon[ii][y2] = 35; - } } -void DL2_KnockWalls(int x1, int y1, int x2, int y2) +static void DRLG_L2(int entry) { - int ii, jj; + int i, j; + BOOL doneflag; - for (ii = x1 + 1; ii < x2; ii++) { - if (predungeon[ii][y1 - 1] == 46 && predungeon[ii][y1 + 1] == 46) { - predungeon[ii][y1] = 46; - } - if (predungeon[ii][y2 - 1] == 46 && predungeon[ii][y2 + 1] == 46) { - predungeon[ii][y2] = 46; - } - if (predungeon[ii][y1 - 1] == 68) { - predungeon[ii][y1 - 1] = 46; - } - if (predungeon[ii][y2 + 1] == 68) { - predungeon[ii][y2 + 1] = 46; - } - } - for (jj = y1 + 1; jj < y2; jj++) { - if (predungeon[x1 - 1][jj] == 46 && predungeon[x1 + 1][jj] == 46) { - predungeon[x1][jj] = 46; - } - if (predungeon[x2 - 1][jj] == 46 && predungeon[x2 + 1][jj] == 46) { - predungeon[x2][jj] = 46; - } - if (predungeon[x1 - 1][jj] == 68) { - predungeon[x1 - 1][jj] = 46; + doneflag = FALSE; + while (!doneflag) { + nRoomCnt = 0; + InitDungeon(); + DRLG_InitTrans(); + if (!CreateDungeon()) { + continue; } - if (predungeon[x2 + 1][jj] == 68) { - predungeon[x2 + 1][jj] = 46; + L2TileFix(); + if (setloadflag_2) { + DRLG_L2SetRoom(nSx1, nSy1); } - } -} - -void DRLG_L2FloodTVal() -{ - int i, j, xx, yy; - - yy = 16; - for (j = 0; j < DMAXY; j++) { - xx = 16; - for (i = 0; i < DMAXX; i++) { - if (dungeon[i][j] == 3 && dTransVal[xx][yy] == 0) { - DRLG_L2FTVR(i, j, xx, yy, 0); - TransVal++; + DRLG_L2FloodTVal(); + DRLG_L2TransFix(); + if (entry == 0) { + doneflag = DRLG_L2PlaceMiniSet(USTAIRS, 1, 1, -1, -1, 1, 0); + if (doneflag) { + doneflag = DRLG_L2PlaceMiniSet(DSTAIRS, 1, 1, -1, -1, 0, 1); + if (doneflag && currlevel == 5) { + doneflag = DRLG_L2PlaceMiniSet(WARPSTAIRS, 1, 1, -1, -1, 0, 6); + } } - xx += 2; + ViewY -= 2; + } else if (entry == 1) { + doneflag = DRLG_L2PlaceMiniSet(USTAIRS, 1, 1, -1, -1, 0, 0); + if (doneflag) { + doneflag = DRLG_L2PlaceMiniSet(DSTAIRS, 1, 1, -1, -1, 1, 1); + if (doneflag && currlevel == 5) { + doneflag = DRLG_L2PlaceMiniSet(WARPSTAIRS, 1, 1, -1, -1, 0, 6); + } + } + ViewX--; + } else { + doneflag = DRLG_L2PlaceMiniSet(USTAIRS, 1, 1, -1, -1, 0, 0); + if (doneflag) { + doneflag = DRLG_L2PlaceMiniSet(DSTAIRS, 1, 1, -1, -1, 0, 1); + if (doneflag && currlevel == 5) { + doneflag = DRLG_L2PlaceMiniSet(WARPSTAIRS, 1, 1, -1, -1, 1, 6); + } + } + ViewY -= 2; } - yy += 2; } -} -void DRLG_L2FTVR(int i, int j, int x, int y, int d) -{ - if (dTransVal[x][y] != 0 || dungeon[i][j] != 3) { - if (d == 1) { - dTransVal[x][y] = TransVal; - dTransVal[x][y + 1] = TransVal; - } - if (d == 2) { - dTransVal[x + 1][y] = TransVal; - dTransVal[x + 1][y + 1] = TransVal; - } - if (d == 3) { - dTransVal[x][y] = TransVal; - dTransVal[x + 1][y] = TransVal; - } - if (d == 4) { - dTransVal[x][y + 1] = TransVal; - dTransVal[x + 1][y + 1] = TransVal; - } - if (d == 5) { - dTransVal[x + 1][y + 1] = TransVal; - } - if (d == 6) { - dTransVal[x][y + 1] = TransVal; - } - if (d == 7) { - dTransVal[x + 1][y] = TransVal; - } - if (d == 8) { - dTransVal[x][y] = TransVal; + L2LockoutFix(); + L2DoorFix(); + L2DirtFix(); + + DRLG_PlaceThemeRooms(6, 10, 3, 0, 0); + DRLG_L2PlaceRndSet(CTRDOOR1, 100); + DRLG_L2PlaceRndSet(CTRDOOR2, 100); + DRLG_L2PlaceRndSet(CTRDOOR3, 100); + DRLG_L2PlaceRndSet(CTRDOOR4, 100); + DRLG_L2PlaceRndSet(CTRDOOR5, 100); + DRLG_L2PlaceRndSet(CTRDOOR6, 100); + DRLG_L2PlaceRndSet(CTRDOOR7, 100); + DRLG_L2PlaceRndSet(CTRDOOR8, 100); + DRLG_L2PlaceRndSet(VARCH33, 100); + DRLG_L2PlaceRndSet(VARCH34, 100); + DRLG_L2PlaceRndSet(VARCH35, 100); + DRLG_L2PlaceRndSet(VARCH36, 100); + DRLG_L2PlaceRndSet(VARCH37, 100); + DRLG_L2PlaceRndSet(VARCH38, 100); + DRLG_L2PlaceRndSet(VARCH39, 100); + DRLG_L2PlaceRndSet(VARCH40, 100); + DRLG_L2PlaceRndSet(VARCH1, 100); + DRLG_L2PlaceRndSet(VARCH2, 100); + DRLG_L2PlaceRndSet(VARCH3, 100); + DRLG_L2PlaceRndSet(VARCH4, 100); + DRLG_L2PlaceRndSet(VARCH5, 100); + DRLG_L2PlaceRndSet(VARCH6, 100); + DRLG_L2PlaceRndSet(VARCH7, 100); + DRLG_L2PlaceRndSet(VARCH8, 100); + DRLG_L2PlaceRndSet(VARCH9, 100); + DRLG_L2PlaceRndSet(VARCH10, 100); + DRLG_L2PlaceRndSet(VARCH11, 100); + DRLG_L2PlaceRndSet(VARCH12, 100); + DRLG_L2PlaceRndSet(VARCH13, 100); + DRLG_L2PlaceRndSet(VARCH14, 100); + DRLG_L2PlaceRndSet(VARCH15, 100); + DRLG_L2PlaceRndSet(VARCH16, 100); + DRLG_L2PlaceRndSet(VARCH17, 100); + DRLG_L2PlaceRndSet(VARCH18, 100); + DRLG_L2PlaceRndSet(VARCH19, 100); + DRLG_L2PlaceRndSet(VARCH20, 100); + DRLG_L2PlaceRndSet(VARCH21, 100); + DRLG_L2PlaceRndSet(VARCH22, 100); + DRLG_L2PlaceRndSet(VARCH23, 100); + DRLG_L2PlaceRndSet(VARCH24, 100); + DRLG_L2PlaceRndSet(VARCH25, 100); + DRLG_L2PlaceRndSet(VARCH26, 100); + DRLG_L2PlaceRndSet(VARCH27, 100); + DRLG_L2PlaceRndSet(VARCH28, 100); + DRLG_L2PlaceRndSet(VARCH29, 100); + DRLG_L2PlaceRndSet(VARCH30, 100); + DRLG_L2PlaceRndSet(VARCH31, 100); + DRLG_L2PlaceRndSet(VARCH32, 100); + DRLG_L2PlaceRndSet(HARCH1, 100); + DRLG_L2PlaceRndSet(HARCH2, 100); + DRLG_L2PlaceRndSet(HARCH3, 100); + DRLG_L2PlaceRndSet(HARCH4, 100); + DRLG_L2PlaceRndSet(HARCH5, 100); + DRLG_L2PlaceRndSet(HARCH6, 100); + DRLG_L2PlaceRndSet(HARCH7, 100); + DRLG_L2PlaceRndSet(HARCH8, 100); + DRLG_L2PlaceRndSet(HARCH9, 100); + DRLG_L2PlaceRndSet(HARCH10, 100); + DRLG_L2PlaceRndSet(HARCH11, 100); + DRLG_L2PlaceRndSet(HARCH12, 100); + DRLG_L2PlaceRndSet(HARCH13, 100); + DRLG_L2PlaceRndSet(HARCH14, 100); + DRLG_L2PlaceRndSet(HARCH15, 100); + DRLG_L2PlaceRndSet(HARCH16, 100); + DRLG_L2PlaceRndSet(HARCH17, 100); + DRLG_L2PlaceRndSet(HARCH18, 100); + DRLG_L2PlaceRndSet(HARCH19, 100); + DRLG_L2PlaceRndSet(HARCH20, 100); + DRLG_L2PlaceRndSet(HARCH21, 100); + DRLG_L2PlaceRndSet(HARCH22, 100); + DRLG_L2PlaceRndSet(HARCH23, 100); + DRLG_L2PlaceRndSet(HARCH24, 100); + DRLG_L2PlaceRndSet(HARCH25, 100); + DRLG_L2PlaceRndSet(HARCH26, 100); + DRLG_L2PlaceRndSet(HARCH27, 100); + DRLG_L2PlaceRndSet(HARCH28, 100); + DRLG_L2PlaceRndSet(HARCH29, 100); + DRLG_L2PlaceRndSet(HARCH30, 100); + DRLG_L2PlaceRndSet(HARCH31, 100); + DRLG_L2PlaceRndSet(HARCH32, 100); + DRLG_L2PlaceRndSet(HARCH33, 100); + DRLG_L2PlaceRndSet(HARCH34, 100); + DRLG_L2PlaceRndSet(HARCH35, 100); + DRLG_L2PlaceRndSet(HARCH36, 100); + DRLG_L2PlaceRndSet(HARCH37, 100); + DRLG_L2PlaceRndSet(HARCH38, 100); + DRLG_L2PlaceRndSet(HARCH39, 100); + DRLG_L2PlaceRndSet(HARCH40, 100); + DRLG_L2PlaceRndSet(CRUSHCOL, 99); + DRLG_L2PlaceRndSet(RUINS1, 10); + DRLG_L2PlaceRndSet(RUINS2, 10); + DRLG_L2PlaceRndSet(RUINS3, 10); + DRLG_L2PlaceRndSet(RUINS4, 10); + DRLG_L2PlaceRndSet(RUINS5, 10); + DRLG_L2PlaceRndSet(RUINS6, 10); + DRLG_L2PlaceRndSet(RUINS7, 50); + DRLG_L2PlaceRndSet(PANCREAS1, 1); + DRLG_L2PlaceRndSet(PANCREAS2, 1); + DRLG_L2PlaceRndSet(BIG1, 3); + DRLG_L2PlaceRndSet(BIG2, 3); + DRLG_L2PlaceRndSet(BIG3, 3); + DRLG_L2PlaceRndSet(BIG4, 3); + DRLG_L2PlaceRndSet(BIG5, 3); + DRLG_L2PlaceRndSet(BIG6, 20); + DRLG_L2PlaceRndSet(BIG7, 20); + DRLG_L2PlaceRndSet(BIG8, 3); + DRLG_L2PlaceRndSet(BIG9, 20); + DRLG_L2PlaceRndSet(BIG10, 20); + DRLG_L2Subs(); + DRLG_L2Shadows(); + + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) { + pdungeon[i][j] = dungeon[i][j]; } - } else { - dTransVal[x][y] = TransVal; - dTransVal[x + 1][y] = TransVal; - dTransVal[x][y + 1] = TransVal; - dTransVal[x + 1][y + 1] = TransVal; - DRLG_L2FTVR(i + 1, j, x + 2, y, 1); - DRLG_L2FTVR(i - 1, j, x - 2, y, 2); - DRLG_L2FTVR(i, j + 1, x, y + 2, 3); - DRLG_L2FTVR(i, j - 1, x, y - 2, 4); - DRLG_L2FTVR(i - 1, j - 1, x - 2, y - 2, 5); - DRLG_L2FTVR(i + 1, j - 1, x + 2, y - 2, 6); - DRLG_L2FTVR(i - 1, j + 1, x - 2, y + 2, 7); - DRLG_L2FTVR(i + 1, j + 1, x + 2, y + 2, 8); } + + DRLG_Init_Globals(); + DRLG_CheckQuests(nSx1, nSy1); } -void DRLG_L2TransFix() +static void DRLG_InitL2Vals() { - int i, j, xx, yy; + int i, j, pc; - yy = 16; - for (j = 0; j < DMAXY; j++) { - xx = 16; - for (i = 0; i < DMAXX; i++) { - if (dungeon[i][j] == 14 && dungeon[i][j - 1] == 10) { - dTransVal[xx + 1][yy] = dTransVal[xx][yy]; - dTransVal[xx + 1][yy + 1] = dTransVal[xx][yy]; - } - if (dungeon[i][j] == 15 && dungeon[i + 1][j] == 11) { - dTransVal[xx][yy + 1] = dTransVal[xx][yy]; - dTransVal[xx + 1][yy + 1] = dTransVal[xx][yy]; - } - if (dungeon[i][j] == 10) { - dTransVal[xx + 1][yy] = dTransVal[xx][yy]; - dTransVal[xx + 1][yy + 1] = dTransVal[xx][yy]; - } - if (dungeon[i][j] == 11) { - dTransVal[xx][yy + 1] = dTransVal[xx][yy]; - dTransVal[xx + 1][yy + 1] = dTransVal[xx][yy]; + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) { + if (dPiece[i][j] == 541) { + pc = 5; + } else if (dPiece[i][j] == 178) { + pc = 5; + } else if (dPiece[i][j] == 551) { + pc = 5; + } else if (dPiece[i][j] == 542) { + pc = 6; + } else if (dPiece[i][j] == 553) { + pc = 6; + } else if (dPiece[i][j] == 13) { + pc = 5; + } else if (dPiece[i][j] == 17) { + pc = 6; + } else { + continue; } - if (dungeon[i][j] == 16) { - dTransVal[xx + 1][yy] = dTransVal[xx][yy]; - dTransVal[xx][yy + 1] = dTransVal[xx][yy]; - dTransVal[xx + 1][yy + 1] = dTransVal[xx][yy]; + dArch[i][j] = pc; + } + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) { + if (dPiece[i][j] == 132) { + dArch[i][j + 1] = 2; + dArch[i][j + 2] = 1; + } else if (dPiece[i][j] == 135 || dPiece[i][j] == 139) { + dArch[i + 1][j] = 3; + dArch[i + 2][j] = 4; } - xx += 2; } - yy += 2; } } -void L2DirtFix() +void LoadL2Dungeon(char *sFileName, int vx, int vy) { - int i, j; + int i, j, rw, rh, pc; + BYTE *pLevelMap, *lm; + + InitDungeon(); + DRLG_InitTrans(); + pLevelMap = LoadFileInMem(sFileName, NULL); for (j = 0; j < DMAXY; j++) { for (i = 0; i < DMAXX; i++) { - if (dungeon[i][j] == 13 && dungeon[i + 1][j] != 11) { - dungeon[i][j] = 146; - } - if (dungeon[i][j] == 11 && dungeon[i + 1][j] != 11) { - dungeon[i][j] = 144; - } - if (dungeon[i][j] == 15 && dungeon[i + 1][j] != 11) { - dungeon[i][j] = 148; - } - if (dungeon[i][j] == 10 && dungeon[i][j + 1] != 10) { - dungeon[i][j] = 143; - } - if (dungeon[i][j] == 13 && dungeon[i][j + 1] != 10) { - dungeon[i][j] = 146; + dungeon[i][j] = 12; + dflags[i][j] = 0; + } + } + + lm = pLevelMap; + rw = *lm; + lm += 2; + rh = *lm; + lm += 2; + + for (j = 0; j < rh; j++) { + for (i = 0; i < rw; i++) { + if (*lm != 0) { + dungeon[i][j] = *lm; + dflags[i][j] |= DLRG_PROTECTED; + } else { + dungeon[i][j] = 3; } - if (dungeon[i][j] == 14 && dungeon[i][j + 1] != 15) { - dungeon[i][j] = 147; + lm += 2; + } + } + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) { + if (dungeon[i][j] == 0) { + dungeon[i][j] = 12; } } } -} -void DRLG_InitL2Vals() -{ - int i, j, pc; + DRLG_L2Pass3(); + DRLG_Init_Globals(); for (j = 0; j < MAXDUNY; j++) { for (i = 0; i < MAXDUNX; i++) { + pc = 0; if (dPiece[i][j] == 541) { pc = 5; - } else if (dPiece[i][j] == 178) { + } + if (dPiece[i][j] == 178) { pc = 5; - } else if (dPiece[i][j] == 551) { + } + if (dPiece[i][j] == 551) { pc = 5; - } else if (dPiece[i][j] == 542) { + } + if (dPiece[i][j] == 542) { pc = 6; - } else if (dPiece[i][j] == 553) { + } + if (dPiece[i][j] == 553) { pc = 6; - } else if (dPiece[i][j] == 13) { + } + if (dPiece[i][j] == 13) { pc = 5; - } else if (dPiece[i][j] == 17) { + } + if (dPiece[i][j] == 17) { pc = 6; - } else { - continue; } dArch[i][j] = pc; } @@ -2151,5 +2058,98 @@ void DRLG_InitL2Vals() } } } + + ViewX = vx; + ViewY = vy; + SetMapMonsters(pLevelMap, 0, 0); + SetMapObjects(pLevelMap, 0, 0); + mem_free_dbg(pLevelMap); +} + +void LoadPreL2Dungeon(char *sFileName, int vx, int vy) +{ + int i, j, rw, rh; + BYTE *pLevelMap, *lm; + + InitDungeon(); + DRLG_InitTrans(); + pLevelMap = LoadFileInMem(sFileName, NULL); + + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) { + dungeon[i][j] = 12; + dflags[i][j] = 0; + } + } + + lm = pLevelMap; + rw = *lm; + lm += 2; + rh = *lm; + lm += 2; + + for (j = 0; j < rh; j++) { + for (i = 0; i < rw; i++) { + if (*lm != 0) { + dungeon[i][j] = *lm; + dflags[i][j] |= DLRG_PROTECTED; + } else { + dungeon[i][j] = 3; + } + lm += 2; + } + } + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) { + if (dungeon[i][j] == 0) { + dungeon[i][j] = 12; + } + } + } + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) { + pdungeon[i][j] = dungeon[i][j]; + } + } + + mem_free_dbg(pLevelMap); +} + +void CreateL2Dungeon(DWORD rseed, int entry) +{ + if (gbMaxPlayers == 1) { + if (currlevel == 7 && !quests[QTYPE_BLIND]._qactive) { + currlevel = 6; + CreateL2Dungeon(glSeedTbl[6], 4); + currlevel = 7; + } + if (currlevel == 8) { + if (!quests[QTYPE_BLIND]._qactive) { + currlevel = 6; + CreateL2Dungeon(glSeedTbl[6], 4); + currlevel = 8; + } else { + currlevel = 7; + CreateL2Dungeon(glSeedTbl[7], 4); + currlevel = 8; + } + } + } + + SetRndSeed(rseed); + + dminx = 16; + dminy = 16; + dmaxx = 96; + dmaxy = 96; + + DRLG_InitTrans(); + DRLG_InitSetPC(); + DRLG_LoadL2SP(); + DRLG_L2(entry); + DRLG_L2Pass3(); + DRLG_FreeL2SP(); + DRLG_InitL2Vals(); + DRLG_SetPC(); } #endif diff --git a/Source/drlg_l2.h b/Source/drlg_l2.h index 82d34acdf..35beda6bc 100644 --- a/Source/drlg_l2.h +++ b/Source/drlg_l2.h @@ -15,37 +15,8 @@ void InitDungeon(); void L2LockoutFix(); void L2DoorFix(); void LoadL2Dungeon(char *sFileName, int vx, int vy); -void DRLG_L2Pass3(); void LoadPreL2Dungeon(char *sFileName, int vx, int vy); void CreateL2Dungeon(DWORD rseed, int entry); -void DRLG_LoadL2SP(); -void DRLG_FreeL2SP(); -void DRLG_L2(int entry); -BOOL DRLG_L2PlaceMiniSet(BYTE *miniset, int tmin, int tmax, int cx, int cy, BOOL setview, int ldir); -void DRLG_L2PlaceRndSet(BYTE *miniset, int rndper); -void DRLG_L2Subs(); -void DRLG_L2Shadows(); -void DRLG_L2SetRoom(int rx1, int ry1); -void L2TileFix(); -BOOL CreateDungeon(); -void CreateRoom(int nX1, int nY1, int nX2, int nY2, int nRDest, int nHDir, BOOL ForceHW, int nH, int nW); -void DefineRoom(int nX1, int nY1, int nX2, int nY2, BOOL ForceHW); -void AddHall(int nX1, int nY1, int nX2, int nY2, int nHd); -void GetHall(int *nX1, int *nY1, int *nX2, int *nY2, int *nHd); -void ConnectHall(int nX1, int nY1, int nX2, int nY2, int nHd); -void CreateDoorType(int nX, int nY); -void PlaceHallExt(int nX, int nY); -void DoPatternCheck(int i, int j); -BOOL DL2_FillVoids(); -BOOL DL2_Cont(BOOL x1f, BOOL y1f, BOOL x2f, BOOL y2f); -int DL2_NumNoChar(); -void DL2_DrawRoom(int x1, int y1, int x2, int y2); -void DL2_KnockWalls(int x1, int y1, int x2, int y2); -void DRLG_L2FloodTVal(); -void DRLG_L2FTVR(int i, int j, int x, int y, int d); -void DRLG_L2TransFix(); -void L2DirtFix(); -void DRLG_InitL2Vals(); /* rdata */ extern int Area_Min; From 86bf1fe0d521f10d30c0a9980f0bb330c17f8576 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Mon, 21 Oct 2019 19:54:32 +0200 Subject: [PATCH 09/13] Correct spelling --- Source/scrollrt.cpp | 72 ++++++++++++++++++++++----------------------- Source/town.cpp | 36 +++++++++++------------ 2 files changed, 54 insertions(+), 54 deletions(-) diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index 63078c524..2e0a1ad6a 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -172,8 +172,8 @@ static void scrollrt_draw_cursor_item() /** * @brief Render a missile sprite - * @param x dPice coordinate - * @param y dPice coordinate + * @param x dPiece coordinate + * @param y dPiece coordinate * @param sx Backbuffer coordinate * @param sy Backbuffer coordinate * @param CelSkip Skip part of sprite, see Cl2Draw @@ -243,8 +243,8 @@ void DrawMissile(int x, int y, int sx, int sy, int CelSkip, int CelCap, BOOL pre /** * @brief Render a missile sprite, check for overdraw on lower screen - * @param x dPice coordinate - * @param y dPice coordinate + * @param x dPiece coordinate + * @param y dPiece coordinate * @param sx Backbuffer coordinate * @param sy Backbuffer coordinate * @param CelSkip Skip part of sprite, see Cl2Draw @@ -314,8 +314,8 @@ void DrawClippedMissile(int x, int y, int sx, int sy, int CelSkip, int CelCap, B /** * @brief Render a monster sprite - * @param x dPice coordinate - * @param y dPice coordinate + * @param x dPiece coordinate + * @param y dPiece coordinate * @param mx Backbuffer coordinate * @param my Backbuffer coordinate * @param CelSkip Skip part of sprite, see Cl2Draw @@ -376,8 +376,8 @@ static void DrawMonster(int x, int y, int mx, int my, int m, int CelSkip, int Ce /** * @brief Render a monster sprite, check for overdraw on lower screen - * @param x dPice coordinate - * @param y dPice coordinate + * @param x dPiece coordinate + * @param y dPiece coordinate * @param mx Backbuffer coordinate * @param my Backbuffer coordinate * @param CelSkip Skip part of sprite, see Cl2Draw @@ -439,8 +439,8 @@ static void DrawClippedMonster(int x, int y, int mx, int my, int m, int CelSkip, /** * @brief Render a monster sprite * @param pnum Player id - * @param x dPice coordinate - * @param y dPice coordinate + * @param x dPiece coordinate + * @param y dPiece coordinate * @param px Backbuffer coordinate * @param py Backbuffer coordinate * @param pCelBuff sprite buffer @@ -525,8 +525,8 @@ static void DrawPlayer(int pnum, int x, int y, int px, int py, BYTE *pCelBuff, i /** * @brief Render a monster sprite, check for overdraw on lower screen * @param pnum Player id - * @param x dPice coordinate - * @param y dPice coordinate + * @param x dPiece coordinate + * @param y dPiece coordinate * @param px Backbuffer coordinate * @param py Backbuffer coordinate * @param pCelBuff sprite buffer @@ -610,8 +610,8 @@ static void DrawClippedPlayer(int pnum, int x, int y, int px, int py, BYTE *pCel /** * @brief Render a monster sprite - * @param x dPice coordinate - * @param y dPice coordinate + * @param x dPiece coordinate + * @param y dPiece coordinate * @param sx Backbuffer coordinate * @param sy Backbuffer coordinate * @param CelSkip Skip part of sprite, see Cl2Draw @@ -656,8 +656,8 @@ void DrawDeadPlayer(int x, int y, int sx, int sy, int CelSkip, int CelCap, BOOL /** * @brief Render an object sprite - * @param x dPice coordinate - * @param y dPice coordinate + * @param x dPiece coordinate + * @param y dPiece coordinate * @param ox Backbuffer coordinate * @param oy Backbuffer coordinate * @param pre Is the sprite in the background @@ -719,8 +719,8 @@ static void DrawObject(int x, int y, int ox, int oy, BOOL pre, int CelSkip, int /** * @brief Render an object sprite, check for overdraw on lower screen - * @param x dPice coordinate - * @param y dPice coordinate + * @param x dPiece coordinate + * @param y dPiece coordinate * @param ox Backbuffer coordinate * @param oy Backbuffer coordinate * @param pre Is the sprite in the background @@ -840,8 +840,8 @@ static void scrollrt_draw_clipped_e_flag(BYTE *pBuff, int x, int y, int sx, int /** * @brief Render object sprites * @param pBuff where to render to with sx,sy already applied - * @param sx dPice coordinate - * @param sy dPice coordinate + * @param sx dPiece coordinate + * @param sy dPiece coordinate * @param dx Backbuffer coordinate * @param dy Backbuffer coordinate * @param eflag Should the sorting workaround be applied @@ -1062,8 +1062,8 @@ static void scrollrt_draw_clipped_dungeon(BYTE *pBuff, int sx, int sy, int dx, i /** * @brief Render a row of tile - * @param x dPice coordinate - * @param y dPice coordinate + * @param x dPiece coordinate + * @param y dPiece coordinate * @param sx Backbuffer coordinate * @param sy Backbuffer coordinate * @param chunks tile width of row @@ -1303,8 +1303,8 @@ static void scrollrt_draw_clipped_e_flag_2(BYTE *pBuff, int x, int y, int row, i * This variant checks for of screen element on the lower screen * @brief Render object sprites, skip offscreen parts for lower screen * @param pBuff where to render to with sx,sy already applied - * @param sx dPice coordinate - * @param sy dPice coordinate + * @param sx dPiece coordinate + * @param sy dPiece coordinate * @param row The current row being rendered * @param CelSkip chunks of cell to skip * @param dx Backbuffer coordinate @@ -1527,8 +1527,8 @@ static void scrollrt_draw_clipped_dungeon_2(BYTE *pBuff, int sx, int sy, int row /** * @brief Render a row of tile, checking for overdrawing on lower part of screen - * @param x dPice coordinate - * @param y dPice coordinate + * @param x dPiece coordinate + * @param y dPiece coordinate * @param sx Backbuffer coordinate * @param sy Backbuffer coordinate * @param chunks tile width of row @@ -1701,8 +1701,8 @@ static void scrollrt_draw_e_flag(BYTE *pBuff, int x, int y, int row, int CelCap, /** * @brief Render object sprites, skip offscreen parts for upper screen * @param pBuff where to render to with sx,sx already applied - * @param sx dPice coordinate - * @param sy dPice coordinate + * @param sx dPiece coordinate + * @param sy dPiece coordinate * @param row The current row being rendered * @param CelCap chunks of cell to skip * @param dx Backbuffer coordinate @@ -1915,8 +1915,8 @@ static void scrollrt_draw_dungeon(BYTE *pBuff, int sx, int sy, int row, int CelC /** * @brief Render a row of tile, checking for overdrawing on upper part of screen - * @param x dPice coordinate - * @param y dPice coordinate + * @param x dPiece coordinate + * @param y dPiece coordinate * @param sx Backbuffer coordinate * @param sy Backbuffer coordinate * @param chunks tile width of row @@ -2073,8 +2073,8 @@ static void scrollrt_draw_upper(int x, int y, int sx, int sy, int chunks, int ro /** * @brief Configure render and process screen rows - * @param x Center of view in dPice coordinate - * @param y Center of view in dPice coordinate + * @param x Center of view in dPiece coordinate + * @param y Center of view in dPiece coordinate */ static void DrawGame(int x, int y) { @@ -2180,8 +2180,8 @@ static void DrawGame(int x, int y) /** * @brief Configure render for zoomed view and process screen rows - * @param x Center of view in dPice coordinate - * @param y Center of view in dPice coordinate + * @param x Center of view in dPiece coordinate + * @param y Center of view in dPiece coordinate */ static void DrawZoom(int x, int y) { @@ -2342,8 +2342,8 @@ static void DrawZoom(int x, int y) /** * @brief Start rendering of screen, town variation - * @param StartX Center of view in dPice coordinate - * @param StartY Center of view in dPice coordinate + * @param StartX Center of view in dPiece coordinate + * @param StartY Center of view in dPiece coordinate */ void DrawView(int StartX, int StartY) { diff --git a/Source/town.cpp b/Source/town.cpp index 8fc5cb538..4fed3ed10 100644 --- a/Source/town.cpp +++ b/Source/town.cpp @@ -419,8 +419,8 @@ void town_draw_clipped_e_flag(BYTE *pBuff, int x, int y, int sx, int sy) /** * @brief Render object sprites * @param pBuff where to render to with sx,sy already applied - * @param sx dPice coordinate - * @param sy dPice coordinate + * @param sx dPiece coordinate + * @param sy dPiece coordinate * @param dx Backbuffer coordinate * @param dy Backbuffer coordinate * @param eflag Should the sorting workaround be applied @@ -495,8 +495,8 @@ void town_draw_clipped_town(BYTE *pBuff, int sx, int sy, int dx, int dy, int efl /** * @brief Render a row of tile - * @param x dPice coordinate - * @param y dPice coordinate + * @param x dPiece coordinate + * @param y dPiece coordinate * @param sx Backbuffer coordinate * @param sy Backbuffer coordinate * @param chunks tile width of row @@ -635,8 +635,8 @@ void town_draw_clipped_e_flag_2(BYTE *pBuff, int x, int y, int row, int CelSkip, /** * @brief Render object sprites, skip offscreen parts for lower screen * @param pBuff where to render to with sx,sy already applied - * @param sx dPice coordinate - * @param sy dPice coordinate + * @param sx dPiece coordinate + * @param sy dPiece coordinate * @param row The current row being rendered * @param CelSkip chunks of cell to skip * @param dx Backbuffer coordinate @@ -709,8 +709,8 @@ void town_draw_clipped_town_2(BYTE *pBuff, int sx, int sy, int row, int CelSkip, /** * @brief Render a row of tile, checking for overdrawing on lower part of screen - * @param x dPice coordinate - * @param y dPice coordinate + * @param x dPiece coordinate + * @param y dPiece coordinate * @param sx Backbuffer coordinate * @param sy Backbuffer coordinate * @param chunks tile width of row @@ -857,8 +857,8 @@ void town_draw_e_flag(BYTE *pBuff, int x, int y, int row, int CelCap, int sx, in /** * @brief Render object sprites, skip offscreen parts for upper screen * @param pBuff where to render to with sx,sx already applied - * @param x dPice coordinate - * @param y dPice coordinate + * @param x dPiece coordinate + * @param y dPiece coordinate * @param row The current row being rendered * @param CelCap chunks of cell to skip * @param sx Backbuffer coordinate @@ -936,8 +936,8 @@ void town_draw_town_all(BYTE *pBuff, int x, int y, int row, int CelCap, int sx, /** * @brief Render a row of tile, checking for overdrawing on upper part of screen - * @param x dPice coordinate - * @param y dPice coordinate + * @param x dPiece coordinate + * @param y dPiece coordinate * @param sx Backbuffer coordinate * @param sy Backbuffer coordinate * @param chunks tile width of row @@ -1042,8 +1042,8 @@ void town_draw_upper(int x, int y, int sx, int sy, int chunks, int row, int efla /** * @brief Configure render and process screen rows - * @param x Center of view in dPice coordinate - * @param y Center of view in dPice coordinate + * @param x Center of view in dPiece coordinate + * @param y Center of view in dPiece coordinate */ void T_DrawGame(int x, int y) { @@ -1160,8 +1160,8 @@ void T_DrawGame(int x, int y) /** * @brief Configure render for zoomed view and process screen rows - * @param x Center of view in dPice coordinate - * @param y Center of view in dPice coordinate + * @param x Center of view in dPiece coordinate + * @param y Center of view in dPiece coordinate */ void T_DrawZoom(int x, int y) { @@ -1334,8 +1334,8 @@ void T_DrawZoom(int x, int y) /** * Mostly like DrawView but enables stores and lacks death screen * @brief Start rendering of screen, town variation - * @param StartX Center of view in dPice coordinate - * @param StartY Center of view in dPice coordinate + * @param StartX Center of view in dPiece coordinate + * @param StartY Center of view in dPiece coordinate */ void T_DrawView(int StartX, int StartY) { From 3e7d352fde9afb87dbe9bbd555a3350bfa11469f Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Mon, 21 Oct 2019 20:04:14 +0200 Subject: [PATCH 10/13] Format files --- Source/automap.cpp | 2 +- Source/control.cpp | 52 ++++++++++++++++++++++----------------------- Source/engine.h | 2 +- Source/init.cpp | 4 ++-- Source/lighting.cpp | 43 ++++++++++++++++++------------------- Source/missiles.cpp | 8 +++---- Source/monster.cpp | 2 +- Source/msg.cpp | 2 +- Source/multi.cpp | 6 +++--- 9 files changed, 60 insertions(+), 61 deletions(-) diff --git a/Source/automap.cpp b/Source/automap.cpp index 044f8f93b..22b791995 100644 --- a/Source/automap.cpp +++ b/Source/automap.cpp @@ -170,7 +170,7 @@ void DrawAutomap() return; } - gpBufEnd = &gpBuffer[(PANEL_Y) * BUFFER_WIDTH]; + gpBufEnd = &gpBuffer[(PANEL_Y)*BUFFER_WIDTH]; MapX = (ViewX - 16) >> 1; while (MapX + AutoMapXOfs < 0) diff --git a/Source/control.cpp b/Source/control.cpp index 6ccc3929a..5e267dc64 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -80,39 +80,39 @@ const BYTE fontkern[68] = { */ const int lineOffsets[5][5] = { { - BUFFER_WIDTH * (434 + SCREEN_Y) + 177 + SCREEN_X, - BUFFER_WIDTH * 32, - BUFFER_WIDTH * 32, - BUFFER_WIDTH * 32, - BUFFER_WIDTH * 32 + 180, + BUFFER_WIDTH * (434 + SCREEN_Y) + 177 + SCREEN_X, + BUFFER_WIDTH * 32, + BUFFER_WIDTH * 32, + BUFFER_WIDTH * 32, + BUFFER_WIDTH * 32 + 180, }, { - BUFFER_WIDTH * (422 + SCREEN_Y) + 177 + SCREEN_X, - BUFFER_WIDTH * (446 + SCREEN_Y) + 177 + SCREEN_X, - BUFFER_WIDTH * 32, - BUFFER_WIDTH * 32, - BUFFER_WIDTH * 32, + BUFFER_WIDTH * (422 + SCREEN_Y) + 177 + SCREEN_X, + BUFFER_WIDTH *(446 + SCREEN_Y) + 177 + SCREEN_X, + BUFFER_WIDTH * 32, + BUFFER_WIDTH * 32, + BUFFER_WIDTH * 32, }, { - BUFFER_WIDTH * (416 + SCREEN_Y) + 177 + SCREEN_X, - BUFFER_WIDTH * (434 + SCREEN_Y) + 177 + SCREEN_X, - BUFFER_WIDTH * (452 + SCREEN_Y) + 177 + SCREEN_X, - BUFFER_WIDTH * 32, - BUFFER_WIDTH * 32, + BUFFER_WIDTH * (416 + SCREEN_Y) + 177 + SCREEN_X, + BUFFER_WIDTH *(434 + SCREEN_Y) + 177 + SCREEN_X, + BUFFER_WIDTH *(452 + SCREEN_Y) + 177 + SCREEN_X, + BUFFER_WIDTH * 32, + BUFFER_WIDTH * 32, }, { - BUFFER_WIDTH * (412 + SCREEN_Y) + 177 + SCREEN_X, - BUFFER_WIDTH * (427 + SCREEN_Y) + 177 + SCREEN_X, - BUFFER_WIDTH * (441 + SCREEN_Y) + 177 + SCREEN_X, - BUFFER_WIDTH * (456 + SCREEN_Y) + 177 + SCREEN_X, - BUFFER_WIDTH * 32, + BUFFER_WIDTH * (412 + SCREEN_Y) + 177 + SCREEN_X, + BUFFER_WIDTH *(427 + SCREEN_Y) + 177 + SCREEN_X, + BUFFER_WIDTH *(441 + SCREEN_Y) + 177 + SCREEN_X, + BUFFER_WIDTH *(456 + SCREEN_Y) + 177 + SCREEN_X, + BUFFER_WIDTH * 32, }, { - BUFFER_WIDTH * (410 + SCREEN_Y) + 177 + SCREEN_X, - BUFFER_WIDTH * (422 + SCREEN_Y) + 177 + SCREEN_X, - BUFFER_WIDTH * (434 + SCREEN_Y) + 177 + SCREEN_X, - BUFFER_WIDTH * (446 + SCREEN_Y) + 177 + SCREEN_X, - BUFFER_WIDTH * (457 + SCREEN_Y) + 177 + SCREEN_X, + BUFFER_WIDTH * (410 + SCREEN_Y) + 177 + SCREEN_X, + BUFFER_WIDTH *(422 + SCREEN_Y) + 177 + SCREEN_X, + BUFFER_WIDTH *(434 + SCREEN_Y) + 177 + SCREEN_X, + BUFFER_WIDTH *(446 + SCREEN_Y) + 177 + SCREEN_X, + BUFFER_WIDTH *(457 + SCREEN_Y) + 177 + SCREEN_X, } }; const BYTE gbFontTransTbl[256] = { @@ -2257,7 +2257,7 @@ void PrintSBookStr(int x, int y, BOOL cjustflag, char *pszStr, char col) char *tmp; int screen_x, line, width; - width = PitchTbl[y] + x + SCREEN_WIDTH - 320 + 120;; + width = PitchTbl[y] + x + SCREEN_WIDTH - 320 + 120; line = 0; if (cjustflag) { screen_x = 0; diff --git a/Source/engine.h b/Source/engine.h index fb62860c5..faa424e33 100644 --- a/Source/engine.h +++ b/Source/engine.h @@ -5,7 +5,7 @@ //offset 0 //pCelBuff->pFrameTable[0] -extern char gbPixelCol; // automap pixel color 8-bit (palette entry) +extern char gbPixelCol; // automap pixel color 8-bit (palette entry) extern BOOL gbRotateMap; // flip - if y < x extern int orgseed; extern int SeedCount; diff --git a/Source/init.cpp b/Source/init.cpp index 6261ebac5..15d047230 100644 --- a/Source/init.cpp +++ b/Source/init.cpp @@ -241,9 +241,9 @@ void init_archives() diabdat_mpq = init_test_access(diabdat_mpq_path, "\\spawn.mpq", "DiabloSpawn", 1000, FS_PC); #else #ifdef COPYPROT - diabdat_mpq = init_test_access(diabdat_mpq_path, "\\diabdat.mpq", "DiabloCD", 1000, FS_CD); + diabdat_mpq = init_test_access(diabdat_mpq_path, "\\diabdat.mpq", "DiabloCD", 1000, FS_CD); #else - diabdat_mpq = init_test_access(diabdat_mpq_path, "\\diabdat.mpq", "DiabloCD", 1000, FS_PC); + diabdat_mpq = init_test_access(diabdat_mpq_path, "\\diabdat.mpq", "DiabloCD", 1000, FS_PC); #endif #endif #ifdef COPYPROT diff --git a/Source/lighting.cpp b/Source/lighting.cpp index 17eaefc67..ef1035d77 100644 --- a/Source/lighting.cpp +++ b/Source/lighting.cpp @@ -402,28 +402,27 @@ char CrawlTable[2749] = { // pCrawlTable maps from circle radius to the X- and Y-coordinate deltas from // the center of a circle. -char *pCrawlTable[19] = - { - CrawlTable, - CrawlTable + 3, - CrawlTable + 12, - CrawlTable + 45, - CrawlTable + 94, - CrawlTable + 159, - CrawlTable + 240, - CrawlTable + 337, - CrawlTable + 450, - CrawlTable + 579, - CrawlTable + 724, - CrawlTable + 885, - CrawlTable + 1062, - CrawlTable + 1255, - CrawlTable + 1464, - CrawlTable + 1689, - CrawlTable + 1930, - CrawlTable + 2187, - CrawlTable + 2460 - }; +char *pCrawlTable[19] = { + CrawlTable, + CrawlTable + 3, + CrawlTable + 12, + CrawlTable + 45, + CrawlTable + 94, + CrawlTable + 159, + CrawlTable + 240, + CrawlTable + 337, + CrawlTable + 450, + CrawlTable + 579, + CrawlTable + 724, + CrawlTable + 885, + CrawlTable + 1062, + CrawlTable + 1255, + CrawlTable + 1464, + CrawlTable + 1689, + CrawlTable + 1930, + CrawlTable + 2187, + CrawlTable + 2460 +}; BYTE vCrawlTable[23][30] = { { 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0 }, { 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 1, 9, 1, 10, 1, 11, 1, 12, 1, 13, 1, 14, 1, 15, 1 }, diff --git a/Source/missiles.cpp b/Source/missiles.cpp index a3c0bb7d2..401c0efe7 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -491,14 +491,14 @@ BOOL MonsterTrapHit(int m, int mindam, int maxdam, int dist, int t, BOOLEAN shif mir = missiledata[t].mResist; mor = monster[m].mMagicRes; if (mor & IMUNE_MAGIC && mir == MISR_MAGIC - || mor & IMUNE_FIRE && mir == MISR_FIRE - || mor & IMUNE_LIGHTNING && mir == MISR_LIGHTNING) { + || mor & IMUNE_FIRE && mir == MISR_FIRE + || mor & IMUNE_LIGHTNING && mir == MISR_LIGHTNING) { return FALSE; } if ((mor & RESIST_MAGIC && mir == MISR_MAGIC) - || (mor & RESIST_FIRE && mir == MISR_FIRE) - || (mor & RESIST_LIGHTNING && mir == MISR_LIGHTNING)) { + || (mor & RESIST_FIRE && mir == MISR_FIRE) + || (mor & RESIST_LIGHTNING && mir == MISR_LIGHTNING)) { resist = TRUE; } diff --git a/Source/monster.cpp b/Source/monster.cpp index 6686eb2c2..7b60aed1d 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -2835,7 +2835,7 @@ BOOL M_CallWalk2(int i, int md) int mdtemp; mdtemp = md; - ok = DirOK(i, md); // Can we continue in the same direction + ok = DirOK(i, md); // Can we continue in the same direction if (random_(101, 2)) { // Randomly go left or right ok = ok || (mdtemp = left[md], DirOK(i, left[md])) || (mdtemp = right[md], DirOK(i, right[md])); } else { diff --git a/Source/msg.cpp b/Source/msg.cpp index 0f4387873..d381816bb 100644 --- a/Source/msg.cpp +++ b/Source/msg.cpp @@ -1848,7 +1848,7 @@ DWORD On_OPOBJT(TCmd *pCmd, int pnum) if (gbBufferMsgs != 1 && currlevel == plr[pnum].plrlevel) { plr[pnum].destAction = ACTION_OPERATETK; - plr[pnum].destParam1 =p->wParam1; + plr[pnum].destParam1 = p->wParam1; } return sizeof(*p); diff --git a/Source/multi.cpp b/Source/multi.cpp index 97b024ff3..acaadc35f 100644 --- a/Source/multi.cpp +++ b/Source/multi.cpp @@ -544,7 +544,7 @@ void multi_send_zero_packet(int pnum, BYTE bCmd, BYTE *pbSrc, DWORD dwLen) dwOffset = 0; - while(dwLen != 0) { + while (dwLen != 0) { pkt.hdr.wCheck = 'ip'; pkt.hdr.px = 0; pkt.hdr.py = 0; @@ -559,7 +559,7 @@ void multi_send_zero_packet(int pnum, BYTE bCmd, BYTE *pbSrc, DWORD dwLen) p->bCmd = bCmd; p->wOffset = dwOffset; dwBody = gdwLargestMsgSize - sizeof(pkt.hdr) - sizeof(*p); - if(dwLen < dwBody) { + if (dwLen < dwBody) { dwBody = dwLen; } /// ASSERT: assert(dwBody <= 0x0ffff); @@ -569,7 +569,7 @@ void multi_send_zero_packet(int pnum, BYTE bCmd, BYTE *pbSrc, DWORD dwLen) dwMsg += sizeof(*p); dwMsg += p->wBytes; pkt.hdr.wLen = dwMsg; - if(!SNetSendMessage(pnum, &pkt, dwMsg)) { + if (!SNetSendMessage(pnum, &pkt, dwMsg)) { nthread_terminate_game("SNetSendMessage2"); return; } From 8570d3bdfe999ac0ddbadd3d39ef42e8351821e9 Mon Sep 17 00:00:00 2001 From: galaxyhaxz Date: Sun, 20 Oct 2019 23:45:19 -0500 Subject: [PATCH 11/13] Fix function order [dx.cpp] --- Source/dx.cpp | 202 +++++++++++++++++++++++--------------------- Source/dx.h | 5 -- Source/scrollrt.cpp | 2 +- 3 files changed, 105 insertions(+), 104 deletions(-) diff --git a/Source/dx.cpp b/Source/dx.cpp index 75c6220ed..a92b39612 100644 --- a/Source/dx.cpp +++ b/Source/dx.cpp @@ -18,91 +18,7 @@ char gbBackBuf; char gbEmulate; HMODULE ghDiabMod; -void dx_init(HWND hWnd) -{ - HRESULT hDDVal; - int winw, winh; - BOOL bSuccess; - GUID *lpGUID; - - /// ASSERT: assert(! gpBuffer); - /// ASSERT: assert(! sgdwLockCount); - /// ASSERT: assert(! sgpBackBuf); - - SetFocus(hWnd); - ShowWindow(hWnd, SW_SHOWNORMAL); - - lpGUID = NULL; - if (gbEmulate) { - lpGUID = (GUID *)DDCREATE_EMULATIONONLY; - } - hDDVal = dx_DirectDrawCreate(lpGUID, &lpDDInterface, NULL); - if (hDDVal != DD_OK) { - ErrDlg(IDD_DIALOG1, hDDVal, "C:\\Src\\Diablo\\Source\\dx.cpp", 149); - } - -#ifdef COLORFIX -#ifdef __DDRAWI_INCLUDED__ - ((LPDDRAWI_DIRECTDRAW_INT)lpDDInterface)->lpLcl->dwAppHackFlags |= 0x800; -#else - ((DWORD **)lpDDInterface)[1][18] |= 0x800; -#endif -#endif - -#ifndef _DEBUG - fullscreen = TRUE; -#endif - if (!fullscreen) { -#ifdef __cplusplus - hDDVal = lpDDInterface->SetCooperativeLevel(hWnd, DDSCL_NORMAL | DDSCL_ALLOWREBOOT); -#else - hDDVal = lpDDInterface->lpVtbl->SetCooperativeLevel(lpDDInterface, hWnd, DDSCL_NORMAL | DDSCL_ALLOWREBOOT); -#endif - if (hDDVal == DDERR_EXCLUSIVEMODEALREADYSET) { - TriggerBreak(); - } else if (hDDVal != DD_OK) { - ErrDlg(IDD_DIALOG1, hDDVal, "C:\\Diablo\\Direct\\dx.cpp", 155); - } - SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE); - } else { -#ifdef __cplusplus - hDDVal = lpDDInterface->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT | DDSCL_FULLSCREEN); -#else - hDDVal = lpDDInterface->lpVtbl->SetCooperativeLevel(lpDDInterface, hWnd, DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT | DDSCL_FULLSCREEN); -#endif - if (hDDVal == DDERR_EXCLUSIVEMODEALREADYSET) { - TriggerBreak(); - } else if (hDDVal != DD_OK) { - ErrDlg(IDD_DIALOG1, hDDVal, "C:\\Src\\Diablo\\Source\\dx.cpp", 170); - } -#ifdef __cplusplus - hDDVal = lpDDInterface->SetDisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP); -#else - hDDVal = lpDDInterface->lpVtbl->SetDisplayMode(lpDDInterface, SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP); -#endif - if (hDDVal != DD_OK) { - winw = GetSystemMetrics(SM_CXSCREEN); - winh = GetSystemMetrics(SM_CYSCREEN); -#ifdef __cplusplus - hDDVal = lpDDInterface->SetDisplayMode(winw, winh, SCREEN_BPP); -#else - hDDVal = lpDDInterface->lpVtbl->SetDisplayMode(lpDDInterface, winw, winh, SCREEN_BPP); -#endif - } - if (hDDVal != DD_OK) { - ErrDlg(IDD_DIALOG1, hDDVal, "C:\\Src\\Diablo\\Source\\dx.cpp", 183); - } - } - - dx_create_primary_surface(); - palette_init(); - GdiSetBatchLimit(1); - dx_create_back_buffer(); - bSuccess = SDrawManualInitialize(hWnd, lpDDInterface, lpDDSPrimary, NULL, NULL, lpDDSBackBuf, lpDDPalette, NULL); - /// ASSERT: assert(bSuccess); -} - -void dx_create_back_buffer() +static void dx_create_back_buffer() { DDSCAPS caps; HRESULT error_code; @@ -160,7 +76,7 @@ void dx_create_back_buffer() ErrDlg(IDD_DIALOG1, error_code, "C:\\Src\\Diablo\\Source\\dx.cpp", 96); } -void dx_create_primary_surface() +static void dx_create_primary_surface() { DDSURFACEDESC ddsd; HRESULT error_code; @@ -178,7 +94,7 @@ void dx_create_primary_surface() ErrDlg(IDD_DIALOG1, error_code, "C:\\Src\\Diablo\\Source\\dx.cpp", 109); } -HRESULT dx_DirectDrawCreate(LPGUID guid, LPDIRECTDRAW *lplpDD, LPUNKNOWN pUnkOuter) +static HRESULT dx_DirectDrawCreate(LPGUID guid, LPDIRECTDRAW *lplpDD, LPUNKNOWN pUnkOuter) { HRESULT(WINAPI * DirectDrawCreate) (LPGUID lpGuid, LPDIRECTDRAW * lplpDD, LPUNKNOWN pUnkOuter); @@ -197,15 +113,91 @@ HRESULT dx_DirectDrawCreate(LPGUID guid, LPDIRECTDRAW *lplpDD, LPUNKNOWN pUnkOut return DirectDrawCreate(guid, lplpDD, pUnkOuter); } -void lock_buf(BYTE idx) +void dx_init(HWND hWnd) { -#ifdef _DEBUG - ++locktbl[idx]; + HRESULT hDDVal; + int winw, winh; + BOOL bSuccess; + GUID *lpGUID; + + /// ASSERT: assert(! gpBuffer); + /// ASSERT: assert(! sgdwLockCount); + /// ASSERT: assert(! sgpBackBuf); + + SetFocus(hWnd); + ShowWindow(hWnd, SW_SHOWNORMAL); + + lpGUID = NULL; + if (gbEmulate) { + lpGUID = (GUID *)DDCREATE_EMULATIONONLY; + } + hDDVal = dx_DirectDrawCreate(lpGUID, &lpDDInterface, NULL); + if (hDDVal != DD_OK) { + ErrDlg(IDD_DIALOG1, hDDVal, "C:\\Src\\Diablo\\Source\\dx.cpp", 149); + } + +#ifdef COLORFIX +#ifdef __DDRAWI_INCLUDED__ + ((LPDDRAWI_DIRECTDRAW_INT)lpDDInterface)->lpLcl->dwAppHackFlags |= 0x800; +#else + ((DWORD **)lpDDInterface)[1][18] |= 0x800; #endif - lock_buf_priv(); +#endif + +#ifndef _DEBUG + fullscreen = TRUE; +#endif + if (!fullscreen) { +#ifdef __cplusplus + hDDVal = lpDDInterface->SetCooperativeLevel(hWnd, DDSCL_NORMAL | DDSCL_ALLOWREBOOT); +#else + hDDVal = lpDDInterface->lpVtbl->SetCooperativeLevel(lpDDInterface, hWnd, DDSCL_NORMAL | DDSCL_ALLOWREBOOT); +#endif + if (hDDVal == DDERR_EXCLUSIVEMODEALREADYSET) { + TriggerBreak(); + } else if (hDDVal != DD_OK) { + ErrDlg(IDD_DIALOG1, hDDVal, "C:\\Diablo\\Direct\\dx.cpp", 155); + } + SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE); + } else { +#ifdef __cplusplus + hDDVal = lpDDInterface->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT | DDSCL_FULLSCREEN); +#else + hDDVal = lpDDInterface->lpVtbl->SetCooperativeLevel(lpDDInterface, hWnd, DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT | DDSCL_FULLSCREEN); +#endif + if (hDDVal == DDERR_EXCLUSIVEMODEALREADYSET) { + TriggerBreak(); + } else if (hDDVal != DD_OK) { + ErrDlg(IDD_DIALOG1, hDDVal, "C:\\Src\\Diablo\\Source\\dx.cpp", 170); + } +#ifdef __cplusplus + hDDVal = lpDDInterface->SetDisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP); +#else + hDDVal = lpDDInterface->lpVtbl->SetDisplayMode(lpDDInterface, SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP); +#endif + if (hDDVal != DD_OK) { + winw = GetSystemMetrics(SM_CXSCREEN); + winh = GetSystemMetrics(SM_CYSCREEN); +#ifdef __cplusplus + hDDVal = lpDDInterface->SetDisplayMode(winw, winh, SCREEN_BPP); +#else + hDDVal = lpDDInterface->lpVtbl->SetDisplayMode(lpDDInterface, winw, winh, SCREEN_BPP); +#endif + } + if (hDDVal != DD_OK) { + ErrDlg(IDD_DIALOG1, hDDVal, "C:\\Src\\Diablo\\Source\\dx.cpp", 183); + } + } + + dx_create_primary_surface(); + palette_init(); + GdiSetBatchLimit(1); + dx_create_back_buffer(); + bSuccess = SDrawManualInitialize(hWnd, lpDDInterface, lpDDSPrimary, NULL, NULL, lpDDSBackBuf, lpDDPalette, NULL); + /// ASSERT: assert(bSuccess); } -void lock_buf_priv() +static void lock_buf_priv() { DDSURFACEDESC ddsd; HRESULT error_code; @@ -244,17 +236,15 @@ void lock_buf_priv() sgdwLockCount++; } -void unlock_buf(BYTE idx) +void lock_buf(BYTE idx) { #ifdef _DEBUG - if (!locktbl[idx]) - app_fatal("Draw lock underflow: 0x%x", idx); - --locktbl[idx]; + ++locktbl[idx]; #endif - unlock_buf_priv(); + lock_buf_priv(); } -void unlock_buf_priv() +static void unlock_buf_priv() { HRESULT error_code; @@ -282,6 +272,16 @@ void unlock_buf_priv() #endif } +void unlock_buf(BYTE idx) +{ +#ifdef _DEBUG + if (!locktbl[idx]) + app_fatal("Draw lock underflow: 0x%x", idx); + --locktbl[idx]; +#endif + unlock_buf_priv(); +} + void dx_cleanup() { if (ghMainWnd) @@ -359,3 +359,9 @@ void dx_reinit() sgMemCrit.Leave(); #endif } + +/* check extern remove stub */ +void j_dx_reinit() +{ + dx_reinit(); +} diff --git a/Source/dx.h b/Source/dx.h index 91344a85d..39c0fbef1 100644 --- a/Source/dx.h +++ b/Source/dx.h @@ -12,13 +12,8 @@ extern char gbEmulate; extern HMODULE ghDiabMod; void dx_init(HWND hWnd); -void dx_create_back_buffer(); -void dx_create_primary_surface(); -HRESULT dx_DirectDrawCreate(LPGUID guid, LPDIRECTDRAW *lplpDD, LPUNKNOWN pUnkOuter); void lock_buf(BYTE idx); -void lock_buf_priv(); void unlock_buf(BYTE idx); -void unlock_buf_priv(); void dx_cleanup(); void dx_reinit(); void j_dx_reinit(); diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index 2e0a1ad6a..cae1da70b 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -2731,7 +2731,7 @@ static void DrawMain(int dwHgt, BOOL draw_desc, BOOL draw_hp, BOOL draw_mana, BO break; } retry = FALSE; - dx_reinit(); + j_dx_reinit(); ysize = SCREEN_HEIGHT; dwTicks = GetTickCount(); } From 92ab05ea13544cfa1872f86aabf6b1801655147c Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Wed, 23 Oct 2019 01:54:07 +0200 Subject: [PATCH 12/13] Decompose more magic numbers --- Source/control.cpp | 124 +++++++++++++------------- Source/control.h | 2 +- Source/cursor.cpp | 8 +- Source/diablo.cpp | 4 +- Source/error.cpp | 26 +++--- Source/gmenu.cpp | 14 +-- Source/help.cpp | 2 +- Source/inv.cpp | 208 ++++++++++++++++++++++---------------------- Source/minitext.cpp | 2 +- Source/player.cpp | 2 +- Source/scrollrt.cpp | 26 +++--- Source/stores.cpp | 24 ++--- Source/town.cpp | 6 +- defs.h | 11 ++- 14 files changed, 233 insertions(+), 226 deletions(-) diff --git a/Source/control.cpp b/Source/control.cpp index 5e267dc64..63841b89b 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -145,14 +145,14 @@ char SpellITbl[MAX_SPELLS] = { 39, 42, 41, 40, 10, 36, 30 }; int PanBtnPos[8][5] = { - { 9, 361, 71, 19, 1 }, - { 9, 387, 71, 19, 0 }, - { 9, 427, 71, 19, 1 }, - { 9, 453, 71, 19, 0 }, - { 560, 361, 71, 19, 1 }, - { 560, 387, 71, 19, 0 }, - { 87, 443, 33, 32, 1 }, - { 527, 443, 33, 32, 1 } + { PANEL_LEFT + 9, PANEL_TOP + 9, 71, 19, 1 }, // char button + { PANEL_LEFT + 9, PANEL_TOP + 35, 71, 19, 0 }, // quests button + { PANEL_LEFT + 9, PANEL_TOP + 75, 71, 19, 1 }, // map button + { PANEL_LEFT + 9, PANEL_TOP + 101, 71, 19, 0 }, // menu button + { PANEL_LEFT + 560, PANEL_TOP + 9, 71, 19, 1 }, // inv button + { PANEL_LEFT + 560, PANEL_TOP + 35, 71, 19, 0 }, // spells button + { PANEL_LEFT + 87, PANEL_TOP + 91, 33, 32, 1 }, // chat button + { PANEL_LEFT + 527, PANEL_TOP + 91, 33, 32, 1 }, // friendly fire button }; char *PanBtnHotKey[8] = { "'c'", "'q'", "Tab", "Esc", "'i'", "'b'", "Enter", NULL }; char *PanBtnStr[8] = { @@ -382,9 +382,9 @@ void DrawSpell() st = RSPLTYPE_INVALID; SetSpellTrans(st); if (spl != SPL_INVALID) - DrawSpellCel(629, 631, pSpellCels, SpellITbl[spl], 56); + DrawSpellCel(PANEL_X + 565, PANEL_Y + 119, pSpellCels, SpellITbl[spl], 56); else - DrawSpellCel(629, 631, pSpellCels, 27, 56); + DrawSpellCel(PANEL_X + 565, PANEL_Y + 119, pSpellCels, 27, 56); } void DrawSpellList() @@ -879,7 +879,7 @@ void DrawPanelBox(int x, int y, int w, int h, int sx, int sy) /// ASSERT: assert(gpBuffer); nSrcOff = x + PANEL_WIDTH * y; - nDstOff = sx + BUFFER_WIDTH * sy + (SCREEN_WIDTH - PANEL_WIDTH) / 2; + nDstOff = sx + BUFFER_WIDTH * sy + PANEL_LEFT; #ifdef USE_ASM __asm { @@ -950,14 +950,14 @@ void DrawPanelBox(int x, int y, int w, int h, int sx, int sy) /** * Draws parts of the flasks that are on the panel */ -void SetFlaskHeight(BYTE *pCelBuff, int min, int max, int c, int r) +void SetFlaskHeight(BYTE *pCelBuff, int min, int max, int sx, int sy) { int nSrcOff, nDstOff, w; /// ASSERT: assert(gpBuffer); nSrcOff = 88 * min; - nDstOff = c + BUFFER_WIDTH * r; + nDstOff = sx + BUFFER_WIDTH * sy; w = max - min; #ifdef USE_ASM @@ -1058,9 +1058,9 @@ void UpdateLifeFlask() else if (filled < 0) filled = 0; if (filled != 69) - SetFlaskHeight(pLifeBuff, 16, 85 - filled, 96 + SCREEN_X, 352 + SCREEN_Y); + SetFlaskHeight(pLifeBuff, 16, 85 - filled, 96 + PANEL_X, PANEL_Y); if (filled) - DrawPanelBox(96, 85 - filled, 88, filled, 96 + SCREEN_X, 421 + SCREEN_Y - filled); + DrawPanelBox(96, 85 - filled, 88, filled, 96 + PANEL_X, PANEL_Y + 69 - filled); } void DrawManaFlask() @@ -1115,9 +1115,9 @@ void UpdateManaFlask() if (filled > 69) filled = 69; if (filled != 69) - SetFlaskHeight(pManaBuff, 16, 85 - filled, 96 + SCREEN_X + 368, 352 + SCREEN_Y); + SetFlaskHeight(pManaBuff, 16, 85 - filled, 96 + PANEL_X + 368, PANEL_Y); if (filled) - DrawPanelBox(96 + 368, 85 - filled, 88, filled, 96 + SCREEN_X + 368, 421 + SCREEN_Y - filled); + DrawPanelBox(96 + 368, 85 - filled, 88, filled, 96 + PANEL_X + 368, PANEL_Y + 69 - filled); DrawSpell(); } @@ -1208,7 +1208,7 @@ void InitControlPan() void ClearCtrlPan() { - DrawPanelBox(0, sgbPlrTalkTbl + 16, PANEL_WIDTH, PANEL_HEIGHT, 64, 512); + DrawPanelBox(0, sgbPlrTalkTbl + 16, PANEL_WIDTH, PANEL_HEIGHT, PANEL_X, PANEL_Y); DrawInfoBox(); } @@ -1218,16 +1218,16 @@ void DrawCtrlPan() for (i = 0; i < 6; i++) { if (!panbtn[i]) - DrawPanelBox(PanBtnPos[i][0], PanBtnPos[i][1] - 336, 71, 20, PanBtnPos[i][0] + SCREEN_X, PanBtnPos[i][1] + SCREEN_Y); + DrawPanelBox(PanBtnPos[i][0] - PANEL_LEFT, PanBtnPos[i][1] - (PANEL_TOP - 16), 71, 20, PanBtnPos[i][0] + PANEL_X, PanBtnPos[i][1] + SCREEN_Y); else - CelDraw(PanBtnPos[i][0] + SCREEN_X, PanBtnPos[i][1] + SCREEN_Y + 18, pPanelButtons, i + 1, 71); + CelDraw(PanBtnPos[i][0] + PANEL_X, PanBtnPos[i][1] + (PANEL_Y - 334), pPanelButtons, i + 1, 71); } if (numpanbtns == 8) { - CelDraw(87 + SCREEN_X, 474 + SCREEN_Y, pMultiBtns, panbtn[6] + 1, 33); + CelDraw(87 + PANEL_X, 122 + PANEL_Y, pMultiBtns, panbtn[6] + 1, 33); if (FriendlyMode) - CelDraw(527 + SCREEN_X, 474 + SCREEN_Y, pMultiBtns, panbtn[7] + 3, 33); + CelDraw(527 + PANEL_X, 122 + PANEL_Y, pMultiBtns, panbtn[7] + 3, 33); else - CelDraw(527 + SCREEN_X, 474 + SCREEN_Y, pMultiBtns, panbtn[7] + 5, 33); + CelDraw(527 + PANEL_X, 122 + PANEL_Y, pMultiBtns, panbtn[7] + 5, 33); } } @@ -1297,7 +1297,7 @@ void DoPanBtn() } } } - if (!spselflag && MouseX >= 565 && MouseX < 621 && MouseY >= 416 && MouseY < 472) { + if (!spselflag && MouseX >= 565 + PANEL_LEFT && MouseX < 621 + PANEL_LEFT && MouseY >= 64 + PANEL_TOP && MouseY < 120 + PANEL_TOP) { DoSpeedBook(); gamemenu_off(); } @@ -1366,7 +1366,7 @@ void CheckPanelInfo() pinfoflag = TRUE; } } - if (!spselflag && MouseX >= 565 && MouseX < 621 && MouseY >= 416 && MouseY < 472) { + if (!spselflag && MouseX >= 565 + PANEL_LEFT && MouseX < 621 + PANEL_LEFT && MouseY >= 64 + PANEL_TOP && MouseY < 120 + PANEL_TOP) { strcpy(infostr, "Select current spell button"); infoclr = COL_WHITE; panelflag = TRUE; @@ -1428,7 +1428,7 @@ void CheckPanelInfo() } } } - if (MouseX > 190 && MouseX < 437 && MouseY > 356 && MouseY < 385) + if (MouseX > 190 + PANEL_LEFT && MouseX < 437 + PANEL_LEFT && MouseY > 4 + PANEL_TOP && MouseY < 33 + PANEL_TOP) pcursinvitem = CheckInvHLight(); } @@ -1548,7 +1548,7 @@ void DrawInfoBox() { int nGold; - DrawPanelBox(177, 62, 288, 60, 241, 558); + DrawPanelBox(177, 62, 288, 60, PANEL_X + 177, PANEL_Y + 46); if (!panelflag && !trigflag && pcursinvitem == -1 && !spselflag) { infostr[0] = '\0'; infoclr = COL_WHITE; @@ -1634,13 +1634,13 @@ void control_print_info_str(int y, char *str, BOOL center, int lines) int strWidth, lineOffset, lineStart; lineOffset = 0; - lineStart = lineOffsets[lines][y] + (SCREEN_WIDTH - PANEL_WIDTH) / 2; + lineStart = lineOffsets[lines][y] + PANEL_LEFT; if (center == 1) { strWidth = 0; tmp = str; while (*tmp) { c = gbFontTransTbl[(BYTE)*tmp++]; - strWidth += fontkern[fontframe[c]] + 1; + strWidth += fontkern[fontframe[c]] + 2; } if (strWidth < 288) lineOffset = (288 - strWidth) >> 1; @@ -1943,13 +1943,13 @@ void MY_PlrStringXY(int x, int y, int width, char *pszStr, char col, int base) void CheckLvlBtn() { - if (!lvlbtndown && MouseX >= 40 && MouseX <= 81 && MouseY >= 313 && MouseY <= 335) + if (!lvlbtndown && MouseX >= 40 + PANEL_LEFT && MouseX <= 81 + PANEL_LEFT && MouseY >= -39 + PANEL_TOP && MouseY <= -17 + PANEL_TOP) lvlbtndown = TRUE; } void ReleaseLvlBtn() { - if (MouseX >= 40 && MouseX <= 81 && MouseY >= 313 && MouseY <= 335) + if (MouseX >= 40 + PANEL_LEFT && MouseX <= 81 + PANEL_LEFT && MouseY >= -39 + PANEL_TOP && MouseY <= -17 + PANEL_TOP) chrflag = TRUE; lvlbtndown = FALSE; } @@ -1961,7 +1961,7 @@ void DrawLevelUpIcon() if (!stextflag) { nCel = lvlbtndown ? 3 : 2; ADD_PlrStringXY(0, 303, 120, "Level Up", COL_WHITE); - CelDraw(40 + SCREEN_X, 335 + SCREEN_Y, pChrButtons, nCel, 41); + CelDraw(40 + PANEL_X, -17 + PANEL_Y, pChrButtons, nCel, 41); } } @@ -2044,9 +2044,9 @@ void DrawDurIcon() int x1, x2, x3, x4; if (!chrflag && !questlog || !invflag && !sbookflag) { - x1 = 656; + x1 = 592 + PANEL_X; if (invflag || sbookflag) - x1 = 336; + x1 = 272 + PANEL_X; p = &plr[myplr]; x2 = DrawDurIcon4Item(&p->InvBody[INVLOC_HEAD], x1, 4); x3 = DrawDurIcon4Item(&p->InvBody[INVLOC_CHEST], x2, 3); @@ -2086,7 +2086,7 @@ int DrawDurIcon4Item(ItemStruct *pItem, int x, int c) } if (pItem->_iDurability > 2) c += 8; - CelDraw(x, 335 + SCREEN_Y, pDurIcons, c, 32); + CelDraw(x, -17 + PANEL_Y, pDurIcons, c, 32); return x - 40; } @@ -2198,8 +2198,8 @@ void DrawSpellBook() char st; unsigned __int64 spl; - CelDraw(PANEL_RIGHT, 351 + SCREEN_Y, pSpellBkCel, 1, 320); - CelDraw(PANEL_RIGHT + 76 * sbooktab + 7, 348 + SCREEN_Y, pSBkBtnCel, sbooktab + 1, 76); + CelDraw(RIGHT_PANEL_X, 351 + SCREEN_Y, pSpellBkCel, 1, 320); + CelDraw(RIGHT_PANEL_X + 76 * sbooktab + 7, 348 + SCREEN_Y, pSBkBtnCel, sbooktab + 1, 76); spl = plr[myplr]._pMemSpells | plr[myplr]._pISpells | plr[myplr]._pAblSpells; @@ -2209,10 +2209,10 @@ void DrawSpellBook() if (sn != -1 && spl & (__int64)1 << (sn - 1)) { st = GetSBookTrans(sn, TRUE); SetSpellTrans(st); - DrawSpellCel(SCREEN_WIDTH - 320 + 75, yp, pSBkIconCels, SpellITbl[sn], 37); + DrawSpellCel(RIGHT_PANEL + 75, yp, pSBkIconCels, SpellITbl[sn], 37); if (sn == plr[myplr]._pRSpell && st == plr[myplr]._pRSplType) { SetSpellTrans(RSPLTYPE_SKILL); - DrawSpellCel(SCREEN_WIDTH - 320 + 75, yp, pSBkIconCels, 43, 37); + DrawSpellCel(RIGHT_PANEL + 75, yp, pSBkIconCels, 43, 37); } PrintSBookStr(10, yp - 23, FALSE, spelldata[sn].sNameText, COL_WHITE); switch (GetSBookTrans(sn, FALSE)) { @@ -2257,7 +2257,7 @@ void PrintSBookStr(int x, int y, BOOL cjustflag, char *pszStr, char col) char *tmp; int screen_x, line, width; - width = PitchTbl[y] + x + SCREEN_WIDTH - 320 + 120; + width = PitchTbl[y] + x + RIGHT_PANEL + 120; line = 0; if (cjustflag) { screen_x = 0; @@ -2288,7 +2288,7 @@ void CheckSBook() char st; unsigned __int64 spl; - if (MouseX >= 331 && MouseX < 368 && MouseY >= 18 && MouseY < 314) { + if (MouseX >= RIGHT_PANEL + 11 && MouseX < RIGHT_PANEL + 48 && MouseY >= 18 && MouseY < 314) { spl = plr[myplr]._pMemSpells | plr[myplr]._pISpells | plr[myplr]._pAblSpells; sn = SpellPages[sbooktab][(MouseY - 18) / 43]; if (sn != -1 && spl & (__int64)1 << (sn - 1)) { @@ -2304,8 +2304,8 @@ void CheckSBook() drawpanflag = 255; } } - if (MouseX >= 327 && MouseX < 633 && MouseY >= 320 && MouseY < 349) { /// BUGFIX: change `< 633` to `< 631` - sbooktab = (MouseX - 327) / 76; + if (MouseX >= RIGHT_PANEL + 7 && MouseX < RIGHT_PANEL + 313 && MouseY >= 320 && MouseY < 349) { /// BUGFIX: change `< 313` to `< 311` + sbooktab = (MouseX - (RIGHT_PANEL + 7)) / 76; } } @@ -2428,20 +2428,20 @@ void DrawTalkPan() if (!talkflag) return; - DrawPanelBox(175, sgbPlrTalkTbl + 20, 294, 5, 239, 516); + DrawPanelBox(175, sgbPlrTalkTbl + 20, 294, 5, PANEL_X + 175, PANEL_Y + 4); off = 0; for (i = 293; i > 283; off++, i--) { - DrawPanelBox((off >> 1) + 175, sgbPlrTalkTbl + off + 25, i, 1, (off >> 1) + 239, off + 521); + DrawPanelBox((off >> 1) + 175, sgbPlrTalkTbl + off + 25, i, 1, (off >> 1) + PANEL_X + 175, off + PANEL_Y + 9); } - DrawPanelBox(185, sgbPlrTalkTbl + 35, 274, 30, 249, 531); - DrawPanelBox(180, sgbPlrTalkTbl + 65, 284, 5, 244, 561); + DrawPanelBox(185, sgbPlrTalkTbl + 35, 274, 30, PANEL_X + 185, PANEL_Y + 19); + DrawPanelBox(180, sgbPlrTalkTbl + 65, 284, 5, PANEL_X + 180, PANEL_Y + 49); for (i = 0; i < 10; i++) { - DrawPanelBox(180, sgbPlrTalkTbl + i + 70, i + 284, 1, 244, i + 566); + DrawPanelBox(180, sgbPlrTalkTbl + i + 70, i + 284, 1, PANEL_X + 180, i + PANEL_Y + 54); } - DrawPanelBox(170, sgbPlrTalkTbl + 80, 310, 55, 234, 576); + DrawPanelBox(170, sgbPlrTalkTbl + 80, 310, 55, PANEL_X + 170, PANEL_Y + 64); msg = sgszTalkMsg; for (i = 0; i < 39; i += 13) { - msg = control_print_talk_msg(msg, 0, i, &x, 0); + msg = control_print_talk_msg(msg, 0 + PANEL_LEFT, i, &x, 0); if (!msg) break; } @@ -2460,7 +2460,7 @@ void DrawTalkPan() nCel = 4; else nCel = 3; - CelDraw(172 + SCREEN_X, 436 + 18 * talk_btn + SCREEN_Y, pTalkBtns, nCel, 61); + CelDraw(172 + PANEL_X, 84 + 18 * talk_btn + PANEL_Y, pTalkBtns, nCel, 61); } } else { color = COL_RED; @@ -2470,10 +2470,10 @@ void DrawTalkPan() nCel = 1; if (talkbtndown[talk_btn]) nCel += 4; - CelDraw(172 + SCREEN_X, 436 + 18 * talk_btn + SCREEN_Y, pTalkBtns, nCel, 61); + CelDraw(172 + PANEL_X, 84 + 18 * talk_btn + PANEL_Y, pTalkBtns, nCel, 61); } if (plr[i].plractive) { - control_print_talk_msg(plr[i]._pName, 46, 60 + talk_btn * 18, &x, color); + control_print_talk_msg(plr[i]._pName, 46 + PANEL_LEFT, 60 + talk_btn * 18, &x, color); } talk_btn++; @@ -2487,12 +2487,12 @@ char *control_print_talk_msg(char *msg, int x, int y, int *nOffset, int color) x += 264; width = x; - *nOffset = PitchTbl[y + 534] + x; + *nOffset = PitchTbl[y + 182 + PANEL_TOP] + x; while (*msg) { c = fontframe[gbFontTransTbl[(BYTE)*msg]]; width += fontkern[c] + 1; - if (width > 514) + if (width > 514 + PANEL_LEFT) return msg; msg++; if (c) { @@ -2510,20 +2510,20 @@ BOOL control_check_talk_btn() if (!talkflag) return FALSE; - if (MouseX < 172) + if (MouseX < 172 + PANEL_LEFT) return FALSE; - if (MouseY < 421) + if (MouseY < 69 + PANEL_TOP) return FALSE; - if (MouseX > 233) + if (MouseX > 233 + PANEL_LEFT) return FALSE; - if (MouseY > 475) + if (MouseY > 123 + PANEL_TOP) return FALSE; for (i = 0; i < sizeof(talkbtndown) / sizeof(talkbtndown[0]); i++) { talkbtndown[i] = FALSE; } - talkbtndown[(MouseY - 421) / 18] = TRUE; + talkbtndown[(MouseY - (69 + PANEL_TOP)) / 18] = TRUE; return TRUE; } @@ -2535,8 +2535,8 @@ void control_release_talk_btn() if (talkflag) { for (i = 0; i < sizeof(talkbtndown) / sizeof(talkbtndown[0]); i++) talkbtndown[i] = FALSE; - if (MouseX >= 172 && MouseY >= 421 && MouseX <= 233 && MouseY <= 475) { - off = (MouseY - 421) / 18; + if (MouseX >= 172 + PANEL_LEFT && MouseY >= 421 + PANEL_LEFT && MouseX <= -119 + PANEL_TOP && MouseY <= 123 + PANEL_TOP) { + off = (MouseY - (69 + PANEL_TOP)) / 18; for (p = 0; p < MAX_PLRS && off != -1; p++) { if (p != myplr) diff --git a/Source/control.h b/Source/control.h index 181be4c5d..abe93be5f 100644 --- a/Source/control.h +++ b/Source/control.h @@ -65,7 +65,7 @@ void AddPanelString(char *str, BOOL just); void ClearPanel(); void DrawPanelBox(int x, int y, int w, int h, int sx, int sy); void InitPanelStr(); -void SetFlaskHeight(BYTE *pCelBuff, int min, int max, int c, int r); +void SetFlaskHeight(BYTE *pCelBuff, int min, int max, int sx, int sy); void DrawFlask(BYTE *pCelBuff, int w, int nSrcOff, BYTE *pBuff, int nDstOff, int h); void DrawLifeFlask(); void UpdateLifeFlask(); diff --git a/Source/cursor.cpp b/Source/cursor.cpp index adc9075e7..b3d1d0c08 100644 --- a/Source/cursor.cpp +++ b/Source/cursor.cpp @@ -223,7 +223,7 @@ void CheckCursMove() ty = sy >> 5; px = sx & 0x3F; py = sy & 0x1F; - mx = ViewX + tx + ty - (zoomflag ? 10 : 5); + mx = ViewX + tx + ty - (zoomflag ? (SCREEN_WIDTH / 64) : (SCREEN_WIDTH / 2 / 64)); my = ViewY + ty - tx; flipy = py < (px >> 1); @@ -278,14 +278,14 @@ void CheckCursMove() if (doomflag) { return; } - if (invflag && MouseX > 320) { + if (invflag && MouseX > RIGHT_PANEL) { pcursinvitem = CheckInvHLight(); return; } - if (sbookflag && MouseX > 320) { + if (sbookflag && MouseX > RIGHT_PANEL) { return; } - if ((chrflag || questlog) && MouseX < 320) { + if ((chrflag || questlog) && MouseX < RIGHT_PANEL) { return; } diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 010a976e7..203824312 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -794,10 +794,10 @@ BOOL LeftMouseDown(int wParam) sfx_stop(); } else if (chrflag && MouseX < 320) { CheckChrBtns(); - } else if (invflag && MouseX > 320) { + } else if (invflag && MouseX > RIGHT_PANEL) { if (!dropGoldFlag) CheckInvItem(); - } else if (sbookflag && MouseX > 320) { + } else if (sbookflag && MouseX > RIGHT_PANEL) { CheckSBook(); } else if (pcurs >= CURSOR_FIRSTITEM) { if (TryInvPut()) { diff --git a/Source/error.cpp b/Source/error.cpp index fd2df0a8c..557198b67 100644 --- a/Source/error.cpp +++ b/Source/error.cpp @@ -85,34 +85,34 @@ void DrawDiabloMsg() int i, len, off, width, sx, sy; BYTE c; - CelDraw(165, 318, pSTextSlidCels, 1, 12); - CelDraw(591, 318, pSTextSlidCels, 4, 12); - CelDraw(165, 366, pSTextSlidCels, 2, 12); - CelDraw(591, 366, pSTextSlidCels, 3, 12); + CelDraw(PANEL_X + 101, DIALOG_Y, pSTextSlidCels, 1, 12); + CelDraw(PANEL_X + 527, DIALOG_Y, pSTextSlidCels, 4, 12); + CelDraw(PANEL_X + 101, DIALOG_Y + 48, pSTextSlidCels, 2, 12); + CelDraw(PANEL_X + 527, DIALOG_Y + 48, pSTextSlidCels, 3, 12); - sx = 173; + sx = PANEL_X + 109; for (i = 0; i < 35; i++) { - CelDraw(sx, 318, pSTextSlidCels, 5, 12); - CelDraw(sx, 366, pSTextSlidCels, 7, 12); + CelDraw(sx, DIALOG_Y, pSTextSlidCels, 5, 12); + CelDraw(sx, DIALOG_Y + 48, pSTextSlidCels, 7, 12); sx += 12; } - sy = 330; + sy = DIALOG_Y + 12; for (i = 0; i < 3; i++) { - CelDraw(165, sy, pSTextSlidCels, 6, 12); - CelDraw(591, sy, pSTextSlidCels, 8, 12); + CelDraw(PANEL_X + 101, sy, pSTextSlidCels, 6, 12); + CelDraw(PANEL_X + 527, sy, pSTextSlidCels, 8, 12); sy += 12; } /// ASSERT: assert(gpBuffer); -#define TRANS_RECT_X 104 -#define TRANS_RECT_Y 150 +#define TRANS_RECT_X (PANEL_LEFT + 104) +#define TRANS_RECT_Y (DIALOG_TOP - 8) #define TRANS_RECT_WIDTH 432 #define TRANS_RECT_HEIGHT 54 #include "asm_trans_rect.inc" strcpy(tempstr, MsgStrings[msgflag]); - off = 165 + PitchTbl[342]; + off = PANEL_X + 101 + PitchTbl[DIALOG_Y + 24]; len = strlen(tempstr); width = 0; diff --git a/Source/gmenu.cpp b/Source/gmenu.cpp index b3f92f09b..314b58c2a 100644 --- a/Source/gmenu.cpp +++ b/Source/gmenu.cpp @@ -43,7 +43,7 @@ void gmenu_draw_pause() RedBack(); if (!sgpCurrentMenu) { light_table_index = 0; - gmenu_print_text(316, 336, "Pause"); + gmenu_print_text(316 + PANEL_LEFT, -16 + PANEL_TOP, "Pause"); } } @@ -179,14 +179,14 @@ void gmenu_draw_menu_item(TMenuItem *pItem, int y) w = gmenu_get_lfont(pItem); if (pItem->dwFlags & GMENU_SLIDER) { x = 16 + w / 2 + SCREEN_X; - CelDraw(x, t - 8, optbar_cel, 1, 287); + CelDraw(x + PANEL_LEFT, t - 8, optbar_cel, 1, 287); step = pItem->dwFlags & 0xFFF; nSteps = (pItem->dwFlags & 0xFFF000) >> 12; if (nSteps < 2) nSteps = 2; pos = step * 256 / nSteps; - gmenu_clear_buffer(x + 2, t - 10, pos + 13, 28); - CelDraw(x + 2 + pos, y - 12, option_cel, 1, 27); + gmenu_clear_buffer(x + 2 + PANEL_LEFT, t - 10, pos + 13, 28); + CelDraw(x + 2 + pos + PANEL_LEFT, y - 12, option_cel, 1, 27); } x = SCREEN_WIDTH / 2 - w / 2 + SCREEN_X; light_table_index = (pItem->dwFlags & GMENU_ENABLED) ? 0 : 15; @@ -299,15 +299,15 @@ BOOL gmenu_on_mouse_move() BOOLEAN gmenu_valid_mouse_pos(int *plOffset) { *plOffset = 282; - if (MouseX < 282) { + if (MouseX < 282 + PANEL_LEFT) { *plOffset = 0; return 0; } - if (MouseX > 538) { + if (MouseX > 538 + PANEL_LEFT) { *plOffset = 256; return 0; } - *plOffset = MouseX - 282; + *plOffset = MouseX - 282 - PANEL_LEFT; return 1; } diff --git a/Source/help.cpp b/Source/help.cpp index acd016417..5d6ed9401 100644 --- a/Source/help.cpp +++ b/Source/help.cpp @@ -537,7 +537,7 @@ void DrawHelpLine(int always_0, int help_line_nr, char *text, char color) BYTE c; width = 0; - off = PitchTbl[SStringY[help_line_nr] + 204] + always_0 + 96; + off = PitchTbl[SStringY[help_line_nr] + 204] + always_0 + 96 + PANEL_LEFT; while (*text) { c = gbFontTransTbl[(BYTE)*text]; text++; diff --git a/Source/inv.cpp b/Source/inv.cpp index 4928b7b82..fb65cf7ec 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -8,79 +8,79 @@ int sgdwLastTime; // check name const InvXY InvRect[73] = { // clang-format off // X, Y - { 452, 31 }, // helmet - { 480, 31 }, // helmet - { 452, 59 }, // helmet - { 480, 59 }, // helmet - { 365, 205 }, // left ring - { 567, 205 }, // right ring - { 524, 59 }, // amulet - { 337, 104 }, // left hand - { 366, 104 }, // left hand - { 337, 132 }, // left hand - { 366, 132 }, // left hand - { 337, 160 }, // left hand - { 366, 160 }, // left hand - { 567, 104 }, // right hand - { 596, 104 }, // right hand - { 567, 132 }, // right hand - { 596, 132 }, // right hand - { 567, 160 }, // right hand - { 596, 160 }, // right hand - { 452, 104 }, // chest - { 480, 104 }, // chest - { 452, 132 }, // chest - { 480, 132 }, // chest - { 452, 160 }, // chest - { 480, 160 }, // chest - { 337, 250 }, // inv row 1 - { 366, 250 }, // inv row 1 - { 394, 250 }, // inv row 1 - { 423, 250 }, // inv row 1 - { 451, 250 }, // inv row 1 - { 480, 250 }, // inv row 1 - { 509, 250 }, // inv row 1 - { 538, 250 }, // inv row 1 - { 567, 250 }, // inv row 1 - { 596, 250 }, // inv row 1 - { 337, 279 }, // inv row 2 - { 366, 279 }, // inv row 2 - { 394, 279 }, // inv row 2 - { 423, 279 }, // inv row 2 - { 451, 279 }, // inv row 2 - { 480, 279 }, // inv row 2 - { 509, 279 }, // inv row 2 - { 538, 279 }, // inv row 2 - { 567, 279 }, // inv row 2 - { 596, 279 }, // inv row 2 - { 337, 308 }, // inv row 3 - { 366, 308 }, // inv row 3 - { 394, 308 }, // inv row 3 - { 423, 308 }, // inv row 3 - { 451, 308 }, // inv row 3 - { 480, 308 }, // inv row 3 - { 509, 308 }, // inv row 3 - { 538, 308 }, // inv row 3 - { 567, 308 }, // inv row 3 - { 596, 308 }, // inv row 3 - { 337, 336 }, // inv row 4 - { 366, 336 }, // inv row 4 - { 394, 336 }, // inv row 4 - { 423, 336 }, // inv row 4 - { 451, 336 }, // inv row 4 - { 480, 336 }, // inv row 4 - { 509, 336 }, // inv row 4 - { 538, 336 }, // inv row 4 - { 567, 336 }, // inv row 4 - { 596, 336 }, // inv row 4 - { 205, 385 }, // belt - { 234, 385 }, // belt - { 263, 385 }, // belt - { 292, 385 }, // belt - { 321, 385 }, // belt - { 350, 385 }, // belt - { 379, 385 }, // belt - { 408, 385 } // belt + { RIGHT_PANEL + 132, 31 }, // helmet + { RIGHT_PANEL + 160, 31 }, // helmet + { RIGHT_PANEL + 132, 59 }, // helmet + { RIGHT_PANEL + 160, 59 }, // helmet + { RIGHT_PANEL + 45, 205 }, // left ring + { RIGHT_PANEL + 247, 205 }, // right ring + { RIGHT_PANEL + 204, 59 }, // amulet + { RIGHT_PANEL + 17, 104 }, // left hand + { RIGHT_PANEL + 46, 104 }, // left hand + { RIGHT_PANEL + 17, 132 }, // left hand + { RIGHT_PANEL + 46, 132 }, // left hand + { RIGHT_PANEL + 17, 160 }, // left hand + { RIGHT_PANEL + 46, 160 }, // left hand + { RIGHT_PANEL + 247, 104 }, // right hand + { RIGHT_PANEL + 276, 104 }, // right hand + { RIGHT_PANEL + 247, 132 }, // right hand + { RIGHT_PANEL + 276, 132 }, // right hand + { RIGHT_PANEL + 247, 160 }, // right hand + { RIGHT_PANEL + 276, 160 }, // right hand + { RIGHT_PANEL + 132, 104 }, // chest + { RIGHT_PANEL + 160, 104 }, // chest + { RIGHT_PANEL + 132, 132 }, // chest + { RIGHT_PANEL + 160, 132 }, // chest + { RIGHT_PANEL + 132, 160 }, // chest + { RIGHT_PANEL + 160, 160 }, // chest + { RIGHT_PANEL + 17, 250 }, // inv row 1 + { RIGHT_PANEL + 46, 250 }, // inv row 1 + { RIGHT_PANEL + 74, 250 }, // inv row 1 + { RIGHT_PANEL + 103, 250 }, // inv row 1 + { RIGHT_PANEL + 131, 250 }, // inv row 1 + { RIGHT_PANEL + 160, 250 }, // inv row 1 + { RIGHT_PANEL + 189, 250 }, // inv row 1 + { RIGHT_PANEL + 218, 250 }, // inv row 1 + { RIGHT_PANEL + 247, 250 }, // inv row 1 + { RIGHT_PANEL + 276, 250 }, // inv row 1 + { RIGHT_PANEL + 17, 279 }, // inv row 2 + { RIGHT_PANEL + 46, 279 }, // inv row 2 + { RIGHT_PANEL + 74, 279 }, // inv row 2 + { RIGHT_PANEL + 103, 279 }, // inv row 2 + { RIGHT_PANEL + 131, 279 }, // inv row 2 + { RIGHT_PANEL + 160, 279 }, // inv row 2 + { RIGHT_PANEL + 189, 279 }, // inv row 2 + { RIGHT_PANEL + 218, 279 }, // inv row 2 + { RIGHT_PANEL + 247, 279 }, // inv row 2 + { RIGHT_PANEL + 276, 279 }, // inv row 2 + { RIGHT_PANEL + 17, 308 }, // inv row 3 + { RIGHT_PANEL + 46, 308 }, // inv row 3 + { RIGHT_PANEL + 74, 308 }, // inv row 3 + { RIGHT_PANEL + 103, 308 }, // inv row 3 + { RIGHT_PANEL + 131, 308 }, // inv row 3 + { RIGHT_PANEL + 160, 308 }, // inv row 3 + { RIGHT_PANEL + 189, 308 }, // inv row 3 + { RIGHT_PANEL + 218, 308 }, // inv row 3 + { RIGHT_PANEL + 247, 308 }, // inv row 3 + { RIGHT_PANEL + 276, 308 }, // inv row 3 + { RIGHT_PANEL + 17, 336 }, // inv row 4 + { RIGHT_PANEL + 46, 336 }, // inv row 4 + { RIGHT_PANEL + 74, 336 }, // inv row 4 + { RIGHT_PANEL + 103, 336 }, // inv row 4 + { RIGHT_PANEL + 131, 336 }, // inv row 4 + { RIGHT_PANEL + 160, 336 }, // inv row 4 + { RIGHT_PANEL + 189, 336 }, // inv row 4 + { RIGHT_PANEL + 218, 336 }, // inv row 4 + { RIGHT_PANEL + 247, 336 }, // inv row 4 + { RIGHT_PANEL + 276, 336 }, // inv row 4 + { PANEL_LEFT + 205, PANEL_TOP + 33 }, // belt + { PANEL_LEFT + 234, PANEL_TOP + 33 }, // belt + { PANEL_LEFT + 263, PANEL_TOP + 33 }, // belt + { PANEL_LEFT + 292, PANEL_TOP + 33 }, // belt + { PANEL_LEFT + 321, PANEL_TOP + 33 }, // belt + { PANEL_LEFT + 350, PANEL_TOP + 33 }, // belt + { PANEL_LEFT + 379, PANEL_TOP + 33 }, // belt + { PANEL_LEFT + 408, PANEL_TOP + 33 } // belt // clang-format on }; @@ -172,10 +172,10 @@ void DrawInv() BOOL invtest[NUM_INV_GRID_ELEM]; int frame, frame_width, colour, screen_x, screen_y, i, j, ii; - CelDraw(PANEL_RIGHT, 351 + SCREEN_Y, pInvCels, 1, 320); + CelDraw(RIGHT_PANEL_X, 351 + SCREEN_Y, pInvCels, 1, 320); if (plr[myplr].InvBody[INVLOC_HEAD]._itype != ITYPE_NONE) { - InvDrawSlotBack(PANEL_RIGHT + 133, 59 + SCREEN_Y, 2 * INV_SLOT_SIZE_PX, 2 * INV_SLOT_SIZE_PX); + InvDrawSlotBack(RIGHT_PANEL_X + 133, 59 + SCREEN_Y, 2 * INV_SLOT_SIZE_PX, 2 * INV_SLOT_SIZE_PX); frame = plr[myplr].InvBody[INVLOC_HEAD]._iCurs + CURSOR_FIRSTITEM; frame_width = InvItemWidth[frame]; @@ -188,18 +188,18 @@ void DrawInv() if (!plr[myplr].InvBody[INVLOC_HEAD]._iStatFlag) { colour = ICOL_RED; } - CelBlitOutline(colour, PANEL_RIGHT + 133, 59 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); + CelBlitOutline(colour, RIGHT_PANEL_X + 133, 59 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); } if (plr[myplr].InvBody[INVLOC_HEAD]._iStatFlag) { - CelClippedDraw(PANEL_RIGHT + 133, 59 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); + CelClippedDraw(RIGHT_PANEL_X + 133, 59 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); } else { - CelDrawLightRed(PANEL_RIGHT + 133, 59 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8, 1); + CelDrawLightRed(RIGHT_PANEL_X + 133, 59 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8, 1); } } if (plr[myplr].InvBody[INVLOC_RING_LEFT]._itype != ITYPE_NONE) { - InvDrawSlotBack(PANEL_RIGHT + 48, 205 + SCREEN_Y, INV_SLOT_SIZE_PX, INV_SLOT_SIZE_PX); + InvDrawSlotBack(RIGHT_PANEL_X + 48, 205 + SCREEN_Y, INV_SLOT_SIZE_PX, INV_SLOT_SIZE_PX); frame = plr[myplr].InvBody[INVLOC_RING_LEFT]._iCurs + CURSOR_FIRSTITEM; frame_width = InvItemWidth[frame]; @@ -212,18 +212,18 @@ void DrawInv() if (!plr[myplr].InvBody[INVLOC_RING_LEFT]._iStatFlag) { colour = ICOL_RED; } - CelBlitOutline(colour, PANEL_RIGHT + 48, 205 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); + CelBlitOutline(colour, RIGHT_PANEL_X + 48, 205 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); } if (plr[myplr].InvBody[INVLOC_RING_LEFT]._iStatFlag) { - CelClippedDraw(PANEL_RIGHT + 48, 205 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); + CelClippedDraw(RIGHT_PANEL_X + 48, 205 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); } else { - CelDrawLightRed(PANEL_RIGHT + 48, 205 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8, 1); + CelDrawLightRed(RIGHT_PANEL_X + 48, 205 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8, 1); } } if (plr[myplr].InvBody[INVLOC_RING_RIGHT]._itype != ITYPE_NONE) { - InvDrawSlotBack(PANEL_RIGHT + 249, 205 + SCREEN_Y, INV_SLOT_SIZE_PX, INV_SLOT_SIZE_PX); + InvDrawSlotBack(RIGHT_PANEL_X + 249, 205 + SCREEN_Y, INV_SLOT_SIZE_PX, INV_SLOT_SIZE_PX); frame = plr[myplr].InvBody[INVLOC_RING_RIGHT]._iCurs + CURSOR_FIRSTITEM; frame_width = InvItemWidth[frame]; @@ -236,18 +236,18 @@ void DrawInv() if (!plr[myplr].InvBody[INVLOC_RING_RIGHT]._iStatFlag) { colour = ICOL_RED; } - CelBlitOutline(colour, PANEL_RIGHT + 249, 205 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); + CelBlitOutline(colour, RIGHT_PANEL_X + 249, 205 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); } if (plr[myplr].InvBody[INVLOC_RING_RIGHT]._iStatFlag) { - CelClippedDraw(PANEL_RIGHT + 249, 205 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); + CelClippedDraw(RIGHT_PANEL_X + 249, 205 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); } else { - CelDrawLightRed(PANEL_RIGHT + 249, 205 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8, 1); + CelDrawLightRed(RIGHT_PANEL_X + 249, 205 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8, 1); } } if (plr[myplr].InvBody[INVLOC_AMULET]._itype != ITYPE_NONE) { - InvDrawSlotBack(PANEL_RIGHT + 205, 60 + SCREEN_Y, INV_SLOT_SIZE_PX, INV_SLOT_SIZE_PX); + InvDrawSlotBack(RIGHT_PANEL_X + 205, 60 + SCREEN_Y, INV_SLOT_SIZE_PX, INV_SLOT_SIZE_PX); frame = plr[myplr].InvBody[INVLOC_AMULET]._iCurs + CURSOR_FIRSTITEM; frame_width = InvItemWidth[frame]; @@ -260,23 +260,23 @@ void DrawInv() if (!plr[myplr].InvBody[INVLOC_AMULET]._iStatFlag) { colour = ICOL_RED; } - CelBlitOutline(colour, PANEL_RIGHT + 205, 60 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); + CelBlitOutline(colour, RIGHT_PANEL_X + 205, 60 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); } if (plr[myplr].InvBody[INVLOC_AMULET]._iStatFlag) { - CelClippedDraw(PANEL_RIGHT + 205, 60 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); + CelClippedDraw(RIGHT_PANEL_X + 205, 60 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); } else { - CelDrawLightRed(PANEL_RIGHT + 205, 60 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8, 1); + CelDrawLightRed(RIGHT_PANEL_X + 205, 60 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8, 1); } } if (plr[myplr].InvBody[INVLOC_HAND_LEFT]._itype != ITYPE_NONE) { - InvDrawSlotBack(PANEL_RIGHT + 17, 160 + SCREEN_Y, 2 * INV_SLOT_SIZE_PX, 3 * INV_SLOT_SIZE_PX); + InvDrawSlotBack(RIGHT_PANEL_X + 17, 160 + SCREEN_Y, 2 * INV_SLOT_SIZE_PX, 3 * INV_SLOT_SIZE_PX); frame = plr[myplr].InvBody[INVLOC_HAND_LEFT]._iCurs + CURSOR_FIRSTITEM; frame_width = InvItemWidth[frame]; // calc item offsets for weapons smaller than 2x3 slots - screen_x = frame_width == INV_SLOT_SIZE_PX ? (PANEL_RIGHT + 31) : (PANEL_RIGHT + 17); + screen_x = frame_width == INV_SLOT_SIZE_PX ? (RIGHT_PANEL_X + 31) : (RIGHT_PANEL_X + 17); screen_y = InvItemHeight[frame] == (3 * INV_SLOT_SIZE_PX) ? (160 + SCREEN_Y) : (146 + SCREEN_Y); if (pcursinvitem == INVITEM_HAND_LEFT) { @@ -297,26 +297,26 @@ void DrawInv() } if (plr[myplr].InvBody[INVLOC_HAND_LEFT]._iLoc == ILOC_TWOHAND) { - InvDrawSlotBack(PANEL_RIGHT + 247, 160 + SCREEN_Y, 2 * INV_SLOT_SIZE_PX, 3 * INV_SLOT_SIZE_PX); + InvDrawSlotBack(RIGHT_PANEL_X + 247, 160 + SCREEN_Y, 2 * INV_SLOT_SIZE_PX, 3 * INV_SLOT_SIZE_PX); light_table_index = 0; cel_transparency_active = 1; CelClippedBlitLightTrans( frame_width == INV_SLOT_SIZE_PX - ? &gpBuffer[SCREENXY(PANEL_RIGHT + 197, SCREEN_Y)] - : &gpBuffer[SCREENXY(PANEL_RIGHT + 183, SCREEN_Y)], + ? &gpBuffer[SCREENXY(RIGHT_PANEL_X + 197, SCREEN_Y)] + : &gpBuffer[SCREENXY(RIGHT_PANEL_X + 183, SCREEN_Y)], pCursCels, frame, frame_width, 0, 8); cel_transparency_active = 0; } } if (plr[myplr].InvBody[INVLOC_HAND_RIGHT]._itype != ITYPE_NONE) { - InvDrawSlotBack(PANEL_RIGHT + 247, 160 + SCREEN_Y, 2 * INV_SLOT_SIZE_PX, 3 * INV_SLOT_SIZE_PX); + InvDrawSlotBack(RIGHT_PANEL_X + 247, 160 + SCREEN_Y, 2 * INV_SLOT_SIZE_PX, 3 * INV_SLOT_SIZE_PX); frame = plr[myplr].InvBody[INVLOC_HAND_RIGHT]._iCurs + CURSOR_FIRSTITEM; frame_width = InvItemWidth[frame]; // calc item offsets for weapons smaller than 2x3 slots - screen_x = frame_width == INV_SLOT_SIZE_PX ? (PANEL_RIGHT + 261) : (PANEL_RIGHT + 249); + screen_x = frame_width == INV_SLOT_SIZE_PX ? (RIGHT_PANEL_X + 261) : (RIGHT_PANEL_X + 249); screen_y = InvItemHeight[frame] == 3 * INV_SLOT_SIZE_PX ? (160 + SCREEN_Y) : (146 + SCREEN_Y); if (pcursinvitem == INVITEM_HAND_RIGHT) { @@ -338,7 +338,7 @@ void DrawInv() } if (plr[myplr].InvBody[INVLOC_CHEST]._itype != ITYPE_NONE) { - InvDrawSlotBack(PANEL_RIGHT + 133, 160 + SCREEN_Y, 2 * INV_SLOT_SIZE_PX, 3 * INV_SLOT_SIZE_PX); + InvDrawSlotBack(RIGHT_PANEL_X + 133, 160 + SCREEN_Y, 2 * INV_SLOT_SIZE_PX, 3 * INV_SLOT_SIZE_PX); frame = plr[myplr].InvBody[INVLOC_CHEST]._iCurs + CURSOR_FIRSTITEM; frame_width = InvItemWidth[frame]; @@ -351,13 +351,13 @@ void DrawInv() if (!plr[myplr].InvBody[INVLOC_CHEST]._iStatFlag) { colour = ICOL_RED; } - CelBlitOutline(colour, PANEL_RIGHT + 133, 160 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); + CelBlitOutline(colour, RIGHT_PANEL_X + 133, 160 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); } if (plr[myplr].InvBody[INVLOC_CHEST]._iStatFlag) { - CelClippedDraw(PANEL_RIGHT + 133, 160 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); + CelClippedDraw(RIGHT_PANEL_X + 133, 160 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); } else { - CelDrawLightRed(PANEL_RIGHT + 133, 160 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8, 1); + CelDrawLightRed(RIGHT_PANEL_X + 133, 160 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8, 1); } } @@ -419,7 +419,7 @@ void DrawInvBelt() return; } - DrawPanelBox(205, 21, 232, 28, 269, 517); + DrawPanelBox(205, 21, 232, 28, PANEL_X + 205, PANEL_Y + 5); for (i = 0; i < MAXBELTITEMS; i++) { if (plr[myplr].SpdList[i]._itype == ITYPE_NONE) { @@ -1359,8 +1359,8 @@ void CheckInvItem() */ void CheckInvScrn() { - if (MouseX > 190 && MouseX < 437 - && MouseY > PANEL_TOP && MouseY < 385) { + if (MouseX > 190 + PANEL_LEFT && MouseX < 437 + PANEL_LEFT + && MouseY > PANEL_TOP && MouseY < 33 + PANEL_TOP) { CheckInvItem(); } } diff --git a/Source/minitext.cpp b/Source/minitext.cpp index e7adc0f5e..4ad8bee65 100644 --- a/Source/minitext.cpp +++ b/Source/minitext.cpp @@ -69,7 +69,7 @@ void InitQTextMsg(int m) void DrawQTextBack() { - CelDraw(88, 487, pTextBoxCels, 1, 591); + CelDraw(PANEL_X + 24, 487, pTextBoxCels, 1, 591); #define TRANS_RECT_X 27 #define TRANS_RECT_Y 28 diff --git a/Source/player.cpp b/Source/player.cpp index 4ce8d5f3e..1d7dba16f 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -3663,7 +3663,7 @@ void CheckPlrSpell() if (pcurs != CURSOR_HAND || MouseY >= PANEL_TOP - || (chrflag && MouseX < 320 || invflag && MouseX > 320) + || (chrflag && MouseX < 320 || invflag && MouseX > RIGHT_PANEL) && rspell != SPL_HEAL && rspell != SPL_IDENTIFY && rspell != SPL_REPAIR diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index cae1da70b..9238a4738 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -2085,24 +2085,24 @@ static void DrawGame(int x, int y) dword_5C2FF8 = SCREEN_WIDTH / 64; dword_5C2FFC = VIEWPORT_HEIGHT / 32; - sx = ScrollInfo._sxoff + 64; - sy = ScrollInfo._syoff + 175; - x -= 10; + sx = ScrollInfo._sxoff + SCREEN_X; + sy = ScrollInfo._syoff + SCREEN_Y + 15; + x -= SCREEN_WIDTH / 64; y--; - chunks = 10; + chunks = SCREEN_WIDTH / 64; blocks = 8; if (chrflag || questlog) { x += 2; y -= 2; - sx += 288; - chunks = 6; + sx += (SCREEN_WIDTH / 2) - 32; + chunks = (SCREEN_WIDTH / 64) - 4; } if (invflag || sbookflag) { x += 2; y -= 2; sx -= 32; - chunks = 6; + chunks = (SCREEN_WIDTH / 64) - 4; } switch (ScrollInfo._sdir) { @@ -2189,15 +2189,15 @@ static void DrawZoom(int x, int y) int wdt, nSrcOff, nDstOff; scr_pix_width = ZOOM_WIDTH; - scr_pix_height = 192; + scr_pix_height = ZOOM_HEIGHT - 32; dword_5C2FF8 = ZOOM_WIDTH / 64; - dword_5C2FFC = 192 / 32; + dword_5C2FFC = (ZOOM_HEIGHT - 32) / 32; - sx = ScrollInfo._sxoff + 64; - sy = ScrollInfo._syoff + 143; - x -= 6; + sx = ScrollInfo._sxoff + SCREEN_X; + sy = ScrollInfo._syoff + SCREEN_Y - 17; + x -= ZOOM_WIDTH / 64; y--; - chunks = 6; + chunks = ZOOM_WIDTH / 64; blocks = 3; switch (ScrollInfo._sdir) { diff --git a/Source/stores.cpp b/Source/stores.cpp index 686b4ce0e..fd6bae1cd 100644 --- a/Source/stores.cpp +++ b/Source/stores.cpp @@ -130,7 +130,7 @@ void FreeStoreMem() void DrawSTextBack() { - CelDraw(408, 487, pSTextBoxCels, 1, 271); + CelDraw(PANEL_X + 344, 487, pSTextBoxCels, 1, 271); #define TRANS_RECT_X 347 #define TRANS_RECT_Y 28 @@ -148,9 +148,9 @@ void PrintSString(int x, int y, BOOL cjustflag, char *str, char col, int val) s = SStringY[y] + stext[y]._syoff; if (stextsize) - xx = 96; + xx = PANEL_X + 32; else - xx = 416; + xx = PANEL_X + 352; off = xx + x + PitchTbl[s + 204]; len = strlen(str); if (stextsize) @@ -248,16 +248,16 @@ void DrawSArrows(int y1, int y2) yd1 = SStringY[y1] + 204; yd2 = SStringY[y2] + 204; if (stextscrlubtn != -1) - CelDraw(665, yd1, pSTextSlidCels, 12, 12); + CelDraw(PANEL_X + 601, yd1, pSTextSlidCels, 12, 12); else - CelDraw(665, yd1, pSTextSlidCels, 10, 12); + CelDraw(PANEL_X + 601, yd1, pSTextSlidCels, 10, 12); if (stextscrldbtn != -1) - CelDraw(665, yd2, pSTextSlidCels, 11, 12); + CelDraw(PANEL_X + 601, yd2, pSTextSlidCels, 11, 12); else - CelDraw(665, yd2, pSTextSlidCels, 9, 12); + CelDraw(PANEL_X + 601, yd2, pSTextSlidCels, 9, 12); yd1 += 12; for (yd3 = yd1; yd3 < yd2; yd3 += 12) { - CelDraw(665, yd3, pSTextSlidCels, 14, 12); + CelDraw(PANEL_X + 601, yd3, pSTextSlidCels, 14, 12); } if (stextsel == 22) yd3 = stextlhold; @@ -267,7 +267,7 @@ void DrawSArrows(int y1, int y2) yd3 = 1000 * (stextsval + ((yd3 - stextup) >> 2)) / (storenumh - 1) * (SStringY[y2] - SStringY[y1] - 24) / 1000; else yd3 = 0; - CelDraw(665, SStringY[y1 + 1] + 204 + yd3, pSTextSlidCels, 13, 12); + CelDraw(PANEL_X + 601, SStringY[y1 + 1] + 204 + yd3, pSTextSlidCels, 13, 12); } void DrawSTextHelp() @@ -2765,14 +2765,14 @@ void CheckStoreBtn() sfx_stop(); } else if (stextsel != -1 && MouseY >= 32 && MouseY <= 320) { if (!stextsize) { - if (MouseX < 344 || MouseX > 616) + if (MouseX < 344 + PANEL_LEFT || MouseX > 616 + PANEL_LEFT) return; } else { - if (MouseX < 24 || MouseX > 616) + if (MouseX < 24 + PANEL_LEFT || MouseX > 616 + PANEL_LEFT) return; } y = (MouseY - 32) / 12; - if (stextscrl && MouseX > 600) { + if (stextscrl && MouseX > 600 + PANEL_LEFT) { if (y == 4) { if (stextscrlubtn <= 0) { STextUp(); diff --git a/Source/town.cpp b/Source/town.cpp index 4fed3ed10..de4ae49b6 100644 --- a/Source/town.cpp +++ b/Source/town.cpp @@ -1056,15 +1056,15 @@ void T_DrawGame(int x, int y) sx = ScrollInfo._sxoff + 64; sy = ScrollInfo._syoff + 175; - x -= 10; + x -= SCREEN_WIDTH / 64; y--; - chunks = 10; + chunks = SCREEN_WIDTH / 64; blocks = 5; if (chrflag || questlog) { x += 2; y -= 2; - sx += 288; + sx += (SCREEN_WIDTH / 2) - 32; chunks = 6; } if (invflag || sbookflag) { diff --git a/defs.h b/defs.h index 3be9e4c16..d1a88fdea 100644 --- a/defs.h +++ b/defs.h @@ -121,8 +121,12 @@ #define PANEL_WIDTH 640 #define PANEL_HEIGHT 128 #define PANEL_TOP (SCREEN_HEIGHT - PANEL_HEIGHT) -#define PANEL_Y (PANEL_TOP + SCREEN_Y) -#define PANEL_RIGHT (SCREEN_X + SCREEN_WIDTH - 320) +#define PANEL_LEFT (SCREEN_WIDTH - PANEL_WIDTH) / 2 +#define PANEL_X (SCREEN_X + PANEL_LEFT) +#define PANEL_Y (SCREEN_Y + PANEL_TOP) + +#define RIGHT_PANEL (SCREEN_WIDTH - 320) +#define RIGHT_PANEL_X (SCREEN_X + RIGHT_PANEL) #if SCREEN_WIDTH == PANEL_WIDTH #define VIEWPORT_HEIGHT (SCREEN_HEIGHT - PANEL_HEIGHT) @@ -130,6 +134,9 @@ #define VIEWPORT_HEIGHT SCREEN_HEIGHT #endif +#define DIALOG_TOP ((SCREEN_HEIGHT - PANEL_HEIGHT) / 2 - 18) +#define DIALOG_Y (SCREEN_Y + DIALOG_TOP) + #define SCREENXY(x, y) ((x) + SCREEN_X + ((y) + SCREEN_Y) * BUFFER_WIDTH) #define MemFreeDbg(p) \ From c65060ccadf58aeac13da413c1c48bc4b4013d47 Mon Sep 17 00:00:00 2001 From: falquinho Date: Fri, 25 Oct 2019 12:30:52 -0300 Subject: [PATCH 13/13] Some comments on control functions. --- Source/control.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 2 deletions(-) diff --git a/Source/control.cpp b/Source/control.cpp index 63841b89b..896f4ced5 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -181,6 +181,14 @@ int SpellPages[6][7] = { { -1, -1, -1, -1, -1, -1, -1 } }; +/** + * Draw spell cell onto the back buffer. + * @param xp Backbuffer coordinate + * @param yp Backbuffer coordinate + * @param Trans Pointer to the cel buffer. + * @param nCel Index of the cel frame to draw. 0 based. + * @param w Width of the frame. + */ void DrawSpellCel(int xp, int yp, BYTE *Trans, int nCel, int w) { BYTE *dst, *tbl, *end; @@ -362,6 +370,9 @@ void SetSpellTrans(char t) } } +/** + * Sets the spell frame to draw and its position then draws it. + */ void DrawSpell() { char spl, st; @@ -948,7 +959,14 @@ void DrawPanelBox(int x, int y, int w, int h, int sx, int sy) } /** - * Draws parts of the flasks that are on the panel + * Draws a section of the empty flask cel on top of the panel to create the illusion + * of the flask getting empty. This function takes a cel and draws a + * horizontal stripe of height (max-min) onto the back buffer. + * @param pCelBuff Buffer of the empty flask cel. + * @param min Top of the flask cel section to draw. + * @param max Bottom of the flask cel section to draw. + * @param c X Backbuffer coordinate + * @param r Y Backbuffer coordinate */ void SetFlaskHeight(BYTE *pCelBuff, int min, int max, int sx, int sy) { @@ -986,7 +1004,15 @@ void SetFlaskHeight(BYTE *pCelBuff, int min, int max, int sx, int sy) } /** - * Draws parts of the flasks that are above the panel + * Draws the dome of the flask that protrudes above the panel top line. + * It draws a rectangle of fixed width 59 and height 'h' from the source buffer + * into the target buffer. + * @param pCelBuff The flask cel buffer. + * @param w Width of the cel. + * @param nSrcOffset Offset of the source buffer from where the bytes will start to be copied from. + * @param pBuff Target buffer. + * @param nDstOff Offset of the target buffer where the bytes will start to be copied to. + * @param h How many lines of the source buffer that will be copied. */ void DrawFlask(BYTE *pCelBuff, int w, int nSrcOff, BYTE *pBuff, int nDstOff, int h) { @@ -1031,6 +1057,10 @@ void DrawFlask(BYTE *pCelBuff, int w, int nSrcOff, BYTE *pBuff, int nDstOff, int #endif } +/** + * Draws the top dome of the life flask (that part that protrudes out of the control panel). + * First it draws the empty flask cel and then draws the filled part on top if needed. + */ void DrawLifeFlask() { int filled = (double)plr[myplr]._pHitPoints / (double)plr[myplr]._pMaxHP * 80.0; @@ -1048,6 +1078,11 @@ void DrawLifeFlask() DrawFlask(pBtmBuff, PANEL_WIDTH, PANEL_WIDTH * filled + 2029, gpBuffer, BUFFER_WIDTH * filled + BUFFER_WIDTH * 499 + 173, 13 - filled); } +/** + * Controls the drawing of the area of the life flask within the control panel. + * First sets the fill amount then draws the empty flask cel portion then the filled + * flask portion. + */ void UpdateLifeFlask() { int filled = (double)plr[myplr]._pHitPoints / (double)plr[myplr]._pMaxHP * 80.0; @@ -1095,6 +1130,10 @@ void control_update_life_mana() plr[myplr]._pHPPer = (double)plr[myplr]._pHitPoints / (double)plr[myplr]._pMaxHP * 80.0; } +/** + * Controls the drawing of the area of the life flask within the control panel. + * Also for some reason draws the current right mouse button spell. + */ void UpdateManaFlask() { int filled; @@ -1212,6 +1251,10 @@ void ClearCtrlPan() DrawInfoBox(); } +/** + * Draws the control panel buttons in their current state. If the button is in the default + * state draw it from the panel cel(extract its sub-rect). Else draw it from the buttons cel. + */ void DrawCtrlPan() { int i; @@ -1231,6 +1274,10 @@ void DrawCtrlPan() } } +/** + * Draws the "Speed Book": the rows of known spells for quick-setting a spell that + * show up when you click the spell slot at the control panel. + */ void DoSpeedBook() { unsigned __int64 spells, spell; @@ -1284,6 +1331,9 @@ void DoSpeedBook() SetCursorPos(X, Y); } +/** + * Checks if the mouse cursor is within any of the panel buttons and flag it if so. + */ void DoPanBtn() { int i; @@ -1338,6 +1388,10 @@ void DoAutoMap() } } +/** + * Checks the mouse cursor position within the control panel and sets information + * strings if needed. + */ void CheckPanelInfo() { int i, c, v, s; @@ -1432,6 +1486,10 @@ void CheckPanelInfo() pcursinvitem = CheckInvHLight(); } +/** + * Check if the mouse is within a control panel button that's flagged. + * Takes apropiate action if so. + */ void CheckBtnUp() { int i; @@ -1544,6 +1602,9 @@ BOOL control_WriteStringToBuffer(BYTE *str) return TRUE; } +/** + * Sets a string to be drawn in the info box and then draws it. + */ void DrawInfoBox() { int nGold;