From 3812287dd5ec72b308ad01ecc313a3a8ca0fbc17 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Mon, 14 Jan 2019 16:48:59 +0100 Subject: [PATCH] Clean up AllItemsList related code (#565) * Clean up ItemMiscIdIdx * Clean up RndItem * Clean up RndUItem --- Source/items.cpp | 98 +++++++++++++++++++++------------------------- Source/objects.cpp | 11 +++--- structs.h | 2 +- 3 files changed, 50 insertions(+), 61 deletions(-) diff --git a/Source/items.cpp b/Source/items.cpp index e7eb6a2ef..9e81e5bc5 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -2501,82 +2501,72 @@ void __fastcall SetupItem(int i) int __fastcall RndItem(int m) { - int ri; // esi - int i; // edx - int ril[512]; // [esp+4h] [ebp-800h] + int i, ri; + int ril[512]; if ((monster[m].MData->mTreasure & 0x8000) != 0) return -1 - (monster[m].MData->mTreasure & 0xFFF); + if (monster[m].MData->mTreasure & 0x4000) return 0; if (random(24, 100) > 40) return 0; + if (random(24, 100) > 25) return 1; ri = 0; - i = 0; - if (AllItemsList[0].iLoc != -1) { - do { - if (AllItemsList[i].iRnd == 2 && monster[m].mLevel >= AllItemsList[i].iMinMLvl) - ril[ri++] = i; - if (AllItemsList[i].iRnd && monster[m].mLevel >= AllItemsList[i].iMinMLvl) - ril[ri++] = i; - if (AllItemsList[i].iSpell == SPL_RESURRECT && gbMaxPlayers == 1) - --ri; - if (AllItemsList[i].iSpell == SPL_HEALOTHER && gbMaxPlayers == 1) - --ri; - ++i; - } while (AllItemsList[i].iLoc != -1); + for (i = 0; AllItemsList[i].iLoc != -1; i++) { + if (AllItemsList[i].iRnd == 2 && monster[m].mLevel >= AllItemsList[i].iMinMLvl) + ril[ri++] = i; + if (AllItemsList[i].iRnd && monster[m].mLevel >= AllItemsList[i].iMinMLvl) + ril[ri++] = i; + if (AllItemsList[i].iSpell == SPL_RESURRECT && gbMaxPlayers == 1) + ri--; + if (AllItemsList[i].iSpell == SPL_HEALOTHER && gbMaxPlayers == 1) + ri--; } return ril[random(24, ri)] + 1; } // 679660: using guessed type char gbMaxPlayers; -// 421A4B: using guessed type int var_800[512]; int __fastcall RndUItem(int m) { - int ri; // edx - int i; // ebp - BOOLEAN okflag; // edi - int ril[512]; // [esp+0h] [ebp-800h] + int i, ri; + int ril[512]; + BOOL okflag; + + if (m != -1 && (monster[m].MData->mTreasure & 0x8000) != 0 && gbMaxPlayers == 1) + return -1 - (monster[m].MData->mTreasure & 0xFFF); - if (m != -1) { - if ((monster[m].MData->mTreasure & 0x8000) != 0 && gbMaxPlayers == 1) - return -1 - (monster[m].MData->mTreasure & 0xFFF); - } ri = 0; - i = 0; - if (AllItemsList[0].iLoc != -1) { - do { - okflag = 1; - if (!AllItemsList[i].iRnd) - okflag = 0; - if (m == -1) { - if (2 * currlevel - AllItemsList[i].iMinMLvl < 0) - okflag = 0; - } else { - if (monster[m].mLevel - AllItemsList[i].iMinMLvl < 0) - okflag = 0; - } - if (!AllItemsList[i].itype) - okflag = 0; - if (AllItemsList[i].itype == ITYPE_GOLD) - okflag = 0; - if (AllItemsList[i].itype == ITYPE_0E) - okflag = 0; - if (AllItemsList[i].iMiscId == IMISC_BOOK) - okflag = 1; - if (AllItemsList[i].iSpell == SPL_RESURRECT && gbMaxPlayers == 1) - okflag = 0; - if (AllItemsList[i].iSpell == SPL_HEALOTHER && gbMaxPlayers == 1) - okflag = 0; - if (okflag) - ril[ri++] = i; - ++i; - } while (AllItemsList[i].iLoc != -1); + for (i = 0; AllItemsList[i].iLoc != -1; i++) { + okflag = TRUE; + if (!AllItemsList[i].iRnd) + okflag = FALSE; + if (m != -1) { + if (monster[m].mLevel < AllItemsList[i].iMinMLvl) + okflag = FALSE; + } else { + if (2 * currlevel < AllItemsList[i].iMinMLvl) + okflag = FALSE; + } + if (AllItemsList[i].itype == ITYPE_MISC) + okflag = FALSE; + if (AllItemsList[i].itype == ITYPE_GOLD) + okflag = FALSE; + if (AllItemsList[i].itype == ITYPE_0E) + okflag = FALSE; + if (AllItemsList[i].iMiscId == IMISC_BOOK) + okflag = TRUE; + if (AllItemsList[i].iSpell == SPL_RESURRECT && gbMaxPlayers == 1) + okflag = FALSE; + if (AllItemsList[i].iSpell == SPL_HEALOTHER && gbMaxPlayers == 1) + okflag = FALSE; + if (okflag) + ril[ri++] = i; } return ril[random(25, ri)]; diff --git a/Source/objects.cpp b/Source/objects.cpp index e1a811c9e..588440015 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -3916,13 +3916,12 @@ void __fastcall TryDisarm(int pnum, int i) int __fastcall ItemMiscIdIdx(int imiscid) { - int result; // eax - int *i; // edx + int i; - result = 0; - for (i = &AllItemsList[0].iMiscId; !*(i - 14) || *i != imiscid; i += 19) - ++result; - return result; + for (i = 0; AllItemsList[i].iRnd == 0 || AllItemsList[i].iMiscId != imiscid; i++) { + } + + return i; } void __fastcall OperateShrine(int pnum, int i, int sType) diff --git a/structs.h b/structs.h index 7395ef757..27851c6a4 100644 --- a/structs.h +++ b/structs.h @@ -52,7 +52,7 @@ typedef struct ItemDataStruct { char iItemId; char *iName; char *iSName; - int iMinMLvl; + char iMinMLvl; int iDurability; int iMinDam; int iMaxDam;