From b5a2d781480d7d58592eaa2759a976d6d2bebcae Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Thu, 11 Apr 2019 17:37:29 +0200 Subject: [PATCH 01/10] Clean up InitItems --- Source/items.cpp | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/Source/items.cpp b/Source/items.cpp index 510516298..668a5f07d 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -703,30 +703,28 @@ void AddInitItems() void InitItems() { - int *v0; // eax - int v1; // edx + int i; GetItemAttrs(0, IDI_GOLD, 1); - numitems = 0; - qmemcpy(&golditem, item, sizeof(golditem)); + golditem = *item; golditem._iStatFlag = 1; - v0 = &item[0]._ix; - do { - *(v0 - 1) = 0; - *v0 = 0; - v0[1] = 0; - v0[2] = 0; - *((_BYTE *)v0 + 36) = 0; - v0[11] = 0; - v0[10] = 0; - v0 += 92; - } while ((signed int)v0 < (signed int)&item[MAXITEMS + 1]._ix); - v1 = 0; - memset(itemactive, 0, sizeof(itemactive)); - do { - itemavail[v1] = v1; - ++v1; - } while (v1 < MAXITEMS); + numitems = 0; + + for (i = 0; i < MAXITEMS; i++) { + item[i]._itype = 0; + item[i]._ix = 0; + item[i]._iy = 0; + item[i]._isin = 0; + item[i]._iSelFlag = 0; + item[i]._iIdentified = 0; + item[i]._iPostDraw = 0; + } + + for (i = 0; i < MAXITEMS; i++) { + itemavail[i] = i; + itemactive[i] = 0; + } + if (!setlevel) { GetRndSeed(); if (QuestStatus(QTYPE_INFRA)) @@ -736,6 +734,7 @@ void InitItems() if (currlevel > 0u && currlevel < 0x10u) AddInitItems(); } + uitemflag = 0; } // 5CF31D: using guessed type char setlevel; From 3c618a9b8a8d164dabce987d36a4332cc607f8ac Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Thu, 11 Apr 2019 17:45:08 +0200 Subject: [PATCH 02/10] Clean up PrintItemDetails --- Source/items.cpp | 55 ++++++++++++++++++------------------------------ 1 file changed, 21 insertions(+), 34 deletions(-) diff --git a/Source/items.cpp b/Source/items.cpp index 668a5f07d..cda99084c 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -3812,14 +3812,6 @@ void PrintItemMisc(ItemStruct *x) void PrintItemDetails(ItemStruct *x) { - ItemStruct *v1; // ebp - char v2; // cl - char v3; // cl - char v4; // al - unsigned char v5; // al - char v6; // al - - v1 = x; if (x->_iClass == 1) { if (x->_iMaxDur == 255) sprintf(tempstr, "damage: %i-%i Indestructible", x->_iMinDam, x->_iMaxDam); @@ -3827,45 +3819,40 @@ void PrintItemDetails(ItemStruct *x) sprintf(tempstr, "damage: %i-%i Dur: %i/%i", x->_iMinDam, x->_iMaxDam, x->_iDurability, x->_iMaxDur); AddPanelString(tempstr, 1); } - if (v1->_iClass == 2) { - if (v1->_iMaxDur == 255) - sprintf(tempstr, "armor: %i Indestructible", v1->_iAC); + if (x->_iClass == 2) { + if (x->_iMaxDur == 255) + sprintf(tempstr, "armor: %i Indestructible", x->_iAC); else - sprintf(tempstr, "armor: %i Dur: %i/%i", v1->_iAC, v1->_iDurability, v1->_iMaxDur); + sprintf(tempstr, "armor: %i Dur: %i/%i", x->_iAC, x->_iDurability, x->_iMaxDur); AddPanelString(tempstr, 1); } - if (v1->_iMiscId == IMISC_STAFF && v1->_iMaxCharges) { - sprintf(tempstr, "dam: %i-%i Dur: %i/%i", v1->_iMinDam, v1->_iMaxDam, v1->_iDurability, v1->_iMaxDur); - sprintf(tempstr, "Charges: %i/%i", v1->_iCharges, v1->_iMaxCharges); + if (x->_iMiscId == IMISC_STAFF && x->_iMaxCharges) { + sprintf(tempstr, "dam: %i-%i Dur: %i/%i", x->_iMinDam, x->_iMaxDam, x->_iDurability, x->_iMaxDur); + sprintf(tempstr, "Charges: %i/%i", x->_iCharges, x->_iMaxCharges); AddPanelString(tempstr, 1); } - v2 = v1->_iPrePower; - if (v2 != -1) { - PrintItemPower(v2, v1); + if (x->_iPrePower != -1) { + PrintItemPower(x->_iPrePower, x); AddPanelString(tempstr, 1); } - v3 = v1->_iSufPower; - if (v3 != -1) { - PrintItemPower(v3, v1); + if (x->_iSufPower != -1) { + PrintItemPower(x->_iSufPower, x); AddPanelString(tempstr, 1); } - if (v1->_iMagical == ITEM_QUALITY_UNIQUE) { + if (x->_iMagical == ITEM_QUALITY_UNIQUE) { AddPanelString("unique item", 1); uitemflag = 1; - qmemcpy(&curruitem, v1, sizeof(curruitem)); + curruitem = *x; } - PrintItemMisc(v1); - if ((unsigned char)v1->_iMinMag + v1->_iMinDex + v1->_iMinStr) { + PrintItemMisc(x); + if (x->_iMinMag + x->_iMinDex + x->_iMinStr) { strcpy(tempstr, "Required:"); - v4 = v1->_iMinStr; - if (v4) - sprintf(tempstr, "%s %i Str", tempstr, v4); - v5 = v1->_iMinMag; - if (v5) - sprintf(tempstr, "%s %i Mag", tempstr, v5); - v6 = v1->_iMinDex; - if (v6) - sprintf(tempstr, "%s %i Dex", tempstr, v6); + if (x->_iMinStr) + sprintf(tempstr, "%s %i Str", tempstr, x->_iMinStr); + if (x->_iMinMag) + sprintf(tempstr, "%s %i Mag", tempstr, x->_iMinMag); + if (x->_iMinDex) + sprintf(tempstr, "%s %i Dex", tempstr, x->_iMinDex); AddPanelString(tempstr, 1); } pinfoflag = TRUE; From 3da0da2e25836564c0b2e02a4acd80c40d58dc26 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Thu, 11 Apr 2019 17:48:50 +0200 Subject: [PATCH 03/10] Clean up BubbleSwapItem --- Source/items.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/items.cpp b/Source/items.cpp index cda99084c..06e5401fc 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -4133,11 +4133,11 @@ int RndSmithItem(int lvl) void BubbleSwapItem(ItemStruct *a, ItemStruct *b) { - ItemStruct h; // [esp+8h] [ebp-170h] + ItemStruct h; - qmemcpy(&h, a, sizeof(h)); - qmemcpy(a, b, sizeof(ItemStruct)); - qmemcpy(b, &h, sizeof(ItemStruct)); + h = *a; + *a = *b; + *b = h; } void SortSmith() From a71bab2ce190a6f01c28d486c79dce2bdb8e5adb Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Thu, 11 Apr 2019 18:03:11 +0200 Subject: [PATCH 04/10] Clean up SpawnSmith --- Source/items.cpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/Source/items.cpp b/Source/items.cpp index 06e5401fc..4664c3f17 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -4167,26 +4167,23 @@ void SortSmith() void SpawnSmith(int lvl) { - ItemStruct *holdItem; - int i, nsi, idata; + int i, iCnt; - nsi = random(50, 10) + 10; - for (i = 0; i < nsi; i++) { - holdItem = &smithitem[i]; + iCnt = random(50, 10) + 10; + for (i = 0; i < iCnt; ++i) { do { item[0]._iSeed = GetRndSeed(); SetRndSeed(item[0]._iSeed); - idata = RndSmithItem(lvl) - 1; - GetItemAttrs(0, idata, lvl); + GetItemAttrs(0, RndSmithItem(lvl) - 1, lvl); } while (item[0]._iIvalue > 140000); - qmemcpy(holdItem, item, sizeof(ItemStruct)); - holdItem->_iCreateInfo = lvl | 0x400; - holdItem->_iIdentified = TRUE; - holdItem->_iStatFlag = StoreStatOk(holdItem); + smithitem[i] = *item; + smithitem[i]._iCreateInfo = lvl | 0x400; + smithitem[i]._iIdentified = 1; + smithitem[i]._iStatFlag = StoreStatOk(&smithitem[i]); } - for (i = nsi; i < 20; i++) { + for (i = iCnt; i < 20; ++i) smithitem[i]._itype = -1; - } + SortSmith(); } From 95afc8d131734ffa6deba0bc862e2b9cef50b9e1 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Thu, 11 Apr 2019 18:11:28 +0200 Subject: [PATCH 05/10] Clean up SpawnOnePremium --- Source/items.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/items.cpp b/Source/items.cpp index 4664c3f17..e0bb7085d 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -4233,10 +4233,10 @@ int RndPremiumItem(int minlvl, int maxlvl) void SpawnOnePremium(int i, int plvl) { - int itype; // esi - ItemStruct holditem; // [esp+Ch] [ebp-178h] + int itype; + ItemStruct holditem; - qmemcpy(&holditem, item, sizeof(ItemStruct)); + holditem = *item; if (plvl > 30) plvl = 30; if (plvl < 1) @@ -4248,11 +4248,11 @@ void SpawnOnePremium(int i, int plvl) GetItemAttrs(0, itype, plvl); GetItemBonus(0, itype, plvl >> 1, plvl, 1); } while (item[0]._iIvalue > 140000); - qmemcpy(&premiumitem[i], item, sizeof(ItemStruct)); + premiumitem[i] = *item; premiumitem[i]._iCreateInfo = plvl | 0x800; premiumitem[i]._iIdentified = TRUE; premiumitem[i]._iStatFlag = StoreStatOk(&premiumitem[i]); - qmemcpy(item, &holditem, sizeof(ItemStruct)); + *item = holditem; } void SpawnPremium(int lvl) From e81a2e573d581b072d1680abe781cc9f83d1b7f5 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Thu, 11 Apr 2019 18:18:47 +0200 Subject: [PATCH 06/10] Clean up SpawnPremium --- Source/items.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Source/items.cpp b/Source/items.cpp index e0bb7085d..ad700bd30 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -4257,7 +4257,7 @@ void SpawnOnePremium(int i, int plvl) void SpawnPremium(int lvl) { - int i; // eax + int i; if (numpremium < 6) { for (i = 0; i < 6; i++) { @@ -4266,14 +4266,14 @@ void SpawnPremium(int lvl) } numpremium = 6; } - for (i = premiumlevel; premiumlevel < lvl; i = premiumlevel) { - qmemcpy(premiumitem, &premiumitem[2], sizeof(ItemStruct)); - qmemcpy(&premiumitem[1], &premiumitem[3], sizeof(ItemStruct)); - qmemcpy(&premiumitem[2], &premiumitem[4], sizeof(ItemStruct)); - premiumlevel = i + 1; - SpawnOnePremium(3, premiumlvladd[3] + i + 1); - qmemcpy(&premiumitem[4], &premiumitem[5], sizeof(ItemStruct)); - SpawnOnePremium(5, premiumlvladd[5] + premiumlevel); + while (premiumlevel < lvl) { + premiumlevel++; + premiumitem[0] = premiumitem[2]; + premiumitem[1] = premiumitem[3]; + premiumitem[2] = premiumitem[4]; + SpawnOnePremium(3, premiumlevel + premiumlvladd[3]); + premiumitem[4] = premiumitem[5]; + SpawnOnePremium(5, premiumlevel + premiumlvladd[5]); } } // 69FB38: using guessed type int talker; From 2bdfb4896bf374f5ba3fbebb7790e4c1b4eb4aca Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Thu, 11 Apr 2019 18:20:26 +0200 Subject: [PATCH 07/10] Clean up SpawnStoreGold --- Source/items.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/items.cpp b/Source/items.cpp index ad700bd30..5893f5abe 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -4613,7 +4613,7 @@ void SpawnHealer(int lvl) void SpawnStoreGold() { GetItemAttrs(0, IDI_GOLD, 1); - qmemcpy(&golditem, item, sizeof(golditem)); + golditem = *item; golditem._iStatFlag = 1; } From ee857f308c692cbb904066e8f7c181147afb40e1 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Thu, 11 Apr 2019 18:47:36 +0200 Subject: [PATCH 08/10] Clean up SpawnWitch --- Source/items.cpp | 73 ++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 43 deletions(-) diff --git a/Source/items.cpp b/Source/items.cpp index 5893f5abe..a1ae16632 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -4170,7 +4170,7 @@ void SpawnSmith(int lvl) int i, iCnt; iCnt = random(50, 10) + 10; - for (i = 0; i < iCnt; ++i) { + for (i = 0; i < iCnt; i++) { do { item[0]._iSeed = GetRndSeed(); SetRndSeed(item[0]._iSeed); @@ -4181,7 +4181,7 @@ void SpawnSmith(int lvl) smithitem[i]._iIdentified = 1; smithitem[i]._iStatFlag = StoreStatOk(&smithitem[i]); } - for (i = iCnt; i < 20; ++i) + for (i = iCnt; i < 20; i++) smithitem[i]._itype = -1; SortSmith(); @@ -4369,60 +4369,47 @@ void WitchBookLevel(int ii) void SpawnWitch(int lvl) { - int v2; // ebp - int itype; // esi - int iblvl; // eax - signed int ii; // [esp+10h] [ebp-8h] - ItemStruct *itm; // [esp+14h] [ebp-4h] + int i, iCnt; + int idata, maxlvl; GetItemAttrs(0, IDI_MANA, 1); - qmemcpy(witchitem, item, sizeof(ItemStruct)); + witchitem[0] = *item; witchitem[0]._iCreateInfo = lvl; witchitem[0]._iStatFlag = 1; GetItemAttrs(0, IDI_FULLMANA, 1); - qmemcpy(&witchitem[1], item, sizeof(ItemStruct)); + witchitem[1] = *item; witchitem[1]._iCreateInfo = lvl; witchitem[1]._iStatFlag = 1; GetItemAttrs(0, IDI_PORTAL, 1); - qmemcpy(&witchitem[2], item, sizeof(ItemStruct)); + witchitem[2] = *item; witchitem[2]._iCreateInfo = lvl; witchitem[2]._iStatFlag = 1; - v2 = random(51, 8) + 10; - ii = 3; - if (v2 > 3) { - itm = &witchitem[3]; - while (1) { + iCnt = random(51, 8) + 10; + + for (i = 3; i < iCnt; i++) { + do { item[0]._iSeed = GetRndSeed(); SetRndSeed(item[0]._iSeed); - itype = RndWitchItem(lvl) - 1; - GetItemAttrs(0, itype, lvl); - if (random(51, 100) > 5 || (iblvl = 2 * lvl, iblvl == -1)) { - if (item[0]._iMiscId != IMISC_STAFF) - continue; - iblvl = 2 * lvl; - if (iblvl == -1) - continue; - } - GetItemBonus(0, itype, iblvl >> 1, iblvl, 1); - if (item[0]._iIvalue <= 140000) { - qmemcpy(itm, item, sizeof(ItemStruct)); - itm->_iIdentified = TRUE; - itm->_iCreateInfo = lvl | 0x2000; - WitchBookLevel(ii); - ++ii; - itm->_iStatFlag = StoreStatOk(itm); - ++itm; - if (ii >= v2) - break; - } - } - } - if (v2 < 20) { - do { - witchitem[v2]._itype = -1; - v2++; - } while (v2 < 20); + idata = RndWitchItem(lvl) - 1; + GetItemAttrs(0, idata, lvl); + maxlvl = -1; + if (random(51, 100) <= 5) + maxlvl = 2 * lvl; + if (maxlvl == -1 && item[0]._iMiscId == IMISC_STAFF) + maxlvl = 2 * lvl; + if (maxlvl != -1) + GetItemBonus(0, idata, maxlvl >> 1, maxlvl, 1); + } while (item[0]._iIvalue > 140000); + witchitem[i] = *item; + witchitem[i]._iCreateInfo = lvl | 0x2000; + witchitem[i]._iIdentified = TRUE; + WitchBookLevel(i); + witchitem[i]._iStatFlag = StoreStatOk(&witchitem[i]); } + + for (i = iCnt; i < 20; i++) + witchitem[i]._itype = -1; + SortWitch(); } From a5496dd9d7b038ee18178c7afbaa700b6571c686 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Thu, 11 Apr 2019 18:48:57 +0200 Subject: [PATCH 09/10] Clean up SpawnBoy --- Source/items.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/items.cpp b/Source/items.cpp index a1ae16632..e5ed25d4d 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -4442,7 +4442,7 @@ void SpawnBoy(int lvl) GetItemAttrs(0, itype, lvl); GetItemBonus(0, itype, lvl, 2 * lvl, 1); } while (item[0]._iIvalue > 90000); - qmemcpy(&boyitem, item, sizeof(boyitem)); + boyitem = *item; boyitem._iCreateInfo = lvl | 0x1000; boyitem._iIdentified = TRUE; boyitem._iStatFlag = StoreStatOk(&boyitem); From 06aadacd1b538241ff03ed641e20d501a7f5b8e5 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Thu, 11 Apr 2019 19:40:00 +0200 Subject: [PATCH 10/10] Clean up code style in items.cpp --- Source/items.cpp | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/Source/items.cpp b/Source/items.cpp index e5ed25d4d..434f0a966 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -706,7 +706,7 @@ void InitItems() int i; GetItemAttrs(0, IDI_GOLD, 1); - golditem = *item; + golditem = item[0]; golditem._iStatFlag = 1; numitems = 0; @@ -716,7 +716,7 @@ void InitItems() item[i]._iy = 0; item[i]._isin = 0; item[i]._iSelFlag = 0; - item[i]._iIdentified = 0; + item[i]._iIdentified = FALSE; item[i]._iPostDraw = 0; } @@ -4167,18 +4167,19 @@ void SortSmith() void SpawnSmith(int lvl) { - int i, iCnt; + int i, iCnt, idata; iCnt = random(50, 10) + 10; for (i = 0; i < iCnt; i++) { do { item[0]._iSeed = GetRndSeed(); SetRndSeed(item[0]._iSeed); - GetItemAttrs(0, RndSmithItem(lvl) - 1, lvl); + idata = RndSmithItem(lvl) - 1; + GetItemAttrs(0, idata, lvl); } while (item[0]._iIvalue > 140000); - smithitem[i] = *item; + smithitem[i] = item[0]; smithitem[i]._iCreateInfo = lvl | 0x400; - smithitem[i]._iIdentified = 1; + smithitem[i]._iIdentified = TRUE; smithitem[i]._iStatFlag = StoreStatOk(&smithitem[i]); } for (i = iCnt; i < 20; i++) @@ -4236,7 +4237,7 @@ void SpawnOnePremium(int i, int plvl) int itype; ItemStruct holditem; - holditem = *item; + holditem = item[0]; if (plvl > 30) plvl = 30; if (plvl < 1) @@ -4248,11 +4249,11 @@ void SpawnOnePremium(int i, int plvl) GetItemAttrs(0, itype, plvl); GetItemBonus(0, itype, plvl >> 1, plvl, 1); } while (item[0]._iIvalue > 140000); - premiumitem[i] = *item; + premiumitem[i] = item[0]; premiumitem[i]._iCreateInfo = plvl | 0x800; premiumitem[i]._iIdentified = TRUE; premiumitem[i]._iStatFlag = StoreStatOk(&premiumitem[i]); - *item = holditem; + item[0] = holditem; } void SpawnPremium(int lvl) @@ -4373,15 +4374,15 @@ void SpawnWitch(int lvl) int idata, maxlvl; GetItemAttrs(0, IDI_MANA, 1); - witchitem[0] = *item; + witchitem[0] = item[0]; witchitem[0]._iCreateInfo = lvl; witchitem[0]._iStatFlag = 1; GetItemAttrs(0, IDI_FULLMANA, 1); - witchitem[1] = *item; + witchitem[1] = item[0]; witchitem[1]._iCreateInfo = lvl; witchitem[1]._iStatFlag = 1; GetItemAttrs(0, IDI_PORTAL, 1); - witchitem[2] = *item; + witchitem[2] = item[0]; witchitem[2]._iCreateInfo = lvl; witchitem[2]._iStatFlag = 1; iCnt = random(51, 8) + 10; @@ -4400,7 +4401,7 @@ void SpawnWitch(int lvl) if (maxlvl != -1) GetItemBonus(0, idata, maxlvl >> 1, maxlvl, 1); } while (item[0]._iIvalue > 140000); - witchitem[i] = *item; + witchitem[i] = item[0]; witchitem[i]._iCreateInfo = lvl | 0x2000; witchitem[i]._iIdentified = TRUE; WitchBookLevel(i); @@ -4442,7 +4443,7 @@ void SpawnBoy(int lvl) GetItemAttrs(0, itype, lvl); GetItemBonus(0, itype, lvl, 2 * lvl, 1); } while (item[0]._iIvalue > 90000); - boyitem = *item; + boyitem = item[0]; boyitem._iCreateInfo = lvl | 0x1000; boyitem._iIdentified = TRUE; boyitem._iStatFlag = StoreStatOk(&boyitem); @@ -4600,7 +4601,7 @@ void SpawnHealer(int lvl) void SpawnStoreGold() { GetItemAttrs(0, IDI_GOLD, 1); - golditem = *item; + golditem = item[0]; golditem._iStatFlag = 1; }