Browse Source

Clean up AllItemsList related code (#565)

* Clean up ItemMiscIdIdx

* Clean up RndItem

* Clean up RndUItem
pull/25/head
Anders Jenbo 7 years ago committed by Robin Eklind
parent
commit
3812287dd5
  1. 98
      Source/items.cpp
  2. 11
      Source/objects.cpp
  3. 2
      structs.h

98
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)];

11
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)

2
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;

Loading…
Cancel
Save