Skip to content

Commit

Permalink
Clean up AllItemsList related code (#565)
Browse files Browse the repository at this point in the history
* Clean up ItemMiscIdIdx

* Clean up RndItem

* Clean up RndUItem
  • Loading branch information
AJenbo authored and mewmew committed Jan 14, 2019
1 parent b2532ab commit 3812287
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 61 deletions.
98 changes: 44 additions & 54 deletions Source/items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
Expand Down
11 changes: 5 additions & 6 deletions Source/objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ typedef struct ItemDataStruct {
char iItemId;
char *iName;
char *iSName;
int iMinMLvl;
char iMinMLvl;
int iDurability;
int iMinDam;
int iMaxDam;
Expand Down

0 comments on commit 3812287

Please sign in to comment.