Skip to content

Commit

Permalink
Moved gold generation code into ItemGen
Browse files Browse the repository at this point in the history
  • Loading branch information
captainurist committed Oct 15, 2023
1 parent ba6000b commit 0617544
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 55 deletions.
22 changes: 1 addition & 21 deletions src/Engine/Graphics/Indoor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2024,29 +2024,9 @@ void SpawnRandomTreasure(MapInfo *mapInfo, SpawnPoint *a2) {
return;
}

if (a2->uItemIndex == ITEM_TREASURE_LEVEL_1) {
a1a.containing_item.uItemID = ITEM_GOLD_SMALL;
v34 = grng->random(51) + 50;
} else if (a2->uItemIndex == ITEM_TREASURE_LEVEL_2) {
a1a.containing_item.uItemID = ITEM_GOLD_SMALL;
v34 = grng->random(101) + 100;
} else if (a2->uItemIndex == ITEM_TREASURE_LEVEL_3) {
a1a.containing_item.uItemID = ITEM_GOLD_MEDIUM;
v34 = grng->random(301) + 200;
} else if (a2->uItemIndex == ITEM_TREASURE_LEVEL_4) {
a1a.containing_item.uItemID = ITEM_GOLD_MEDIUM;
v34 = grng->random(501) + 500;
} else if (a2->uItemIndex == ITEM_TREASURE_LEVEL_5) {
a1a.containing_item.uItemID = ITEM_GOLD_LARGE;
v34 = grng->random(1001) + 1000;
} else if (a2->uItemIndex == ITEM_TREASURE_LEVEL_6) {
a1a.containing_item.uItemID = ITEM_GOLD_LARGE;
v34 = grng->random(3001) + 2000;
}
a1a.containing_item.generateGold(a2->uItemIndex);
a1a.uType = pItemTable->pItems[a1a.containing_item.uItemID].uSpriteID;
a1a.containing_item.SetIdentified();
a1a.uObjectDescID = pObjectList->ObjectIDByItemID(a1a.uType);
a1a.containing_item.goldAmount = v34;
} else {
if (!a1a.containing_item.GenerateArtifact())
return;
Expand Down
35 changes: 1 addition & 34 deletions src/Engine/Objects/Chest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,40 +560,7 @@ void GenerateItemsInChest() {
if (whatToGenerateProb < 20) {
currItem->Reset();
} else if (whatToGenerateProb < 60) { // generate gold
int goldAmount = 0;
currItem->Reset();
// TODO(captainurist): merge with the other implementation?
switch (resultTreasureLevel) {
case ITEM_TREASURE_LEVEL_1:
goldAmount = grng->random(51) + 50;
currItem->uItemID = ITEM_GOLD_SMALL;
break;
case ITEM_TREASURE_LEVEL_2:
goldAmount = grng->random(101) + 100;
currItem->uItemID = ITEM_GOLD_SMALL;
break;
case ITEM_TREASURE_LEVEL_3:
goldAmount = grng->random(301) + 200;
currItem->uItemID = ITEM_GOLD_MEDIUM;
break;
case ITEM_TREASURE_LEVEL_4:
goldAmount = grng->random(501) + 500;
currItem->uItemID = ITEM_GOLD_MEDIUM;
break;
case ITEM_TREASURE_LEVEL_5:
goldAmount = grng->random(1001) + 1000;
currItem->uItemID = ITEM_GOLD_LARGE;
break;
case ITEM_TREASURE_LEVEL_6:
goldAmount = grng->random(3001) + 2000;
currItem->uItemID = ITEM_GOLD_LARGE;
break;
default:
assert(false);
break;
}
currItem->SetIdentified();
currItem->goldAmount = goldAmount;
currItem->generateGold(resultTreasureLevel);
} else {
pItemTable->generateItem(resultTreasureLevel, RANDOM_ITEM_ANY, currItem);
}
Expand Down
37 changes: 37 additions & 0 deletions src/Engine/Objects/Items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,43 @@ bool ItemGen::GenerateArtifact() {
}
}

void ItemGen::generateGold(ItemTreasureLevel treasureLevel) {
assert(isRandomTreasureLevel(treasureLevel));

Reset();
SetIdentified();

switch (treasureLevel) {
case ITEM_TREASURE_LEVEL_1:
goldAmount = grng->random(51) + 50;
uItemID = ITEM_GOLD_SMALL;
break;
case ITEM_TREASURE_LEVEL_2:
goldAmount = grng->random(101) + 100;
uItemID = ITEM_GOLD_SMALL;
break;
case ITEM_TREASURE_LEVEL_3:
goldAmount = grng->random(301) + 200;
uItemID = ITEM_GOLD_MEDIUM;
break;
case ITEM_TREASURE_LEVEL_4:
goldAmount = grng->random(501) + 500;
uItemID = ITEM_GOLD_MEDIUM;
break;
case ITEM_TREASURE_LEVEL_5:
goldAmount = grng->random(1001) + 1000;
uItemID = ITEM_GOLD_LARGE;
break;
case ITEM_TREASURE_LEVEL_6:
goldAmount = grng->random(3001) + 2000;
uItemID = ITEM_GOLD_LARGE;
break;
default:
assert(false);
break;
}
}

template<class Key, class ActualKey>
static void AddToMap(std::map<Key, std::map<CharacterAttributeType, CEnchantment>> &map,
ActualKey key, CharacterAttributeType subkey, int bonusValue = 0, CharacterSkillType skill = CHARACTER_SKILL_INVALID) {
Expand Down
1 change: 1 addition & 0 deletions src/Engine/Objects/Items.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ struct ItemGen { // 0x24
inline void SetStolen() { uAttributes |= ITEM_STOLEN; }

bool GenerateArtifact();
void generateGold(ItemTreasureLevel treasureLevel);
unsigned int GetValue() const;
std::string GetDisplayName();
std::string GetIdentifiedName();
Expand Down

0 comments on commit 0617544

Please sign in to comment.