Skip to content

Commit

Permalink
More renamings & docs
Browse files Browse the repository at this point in the history
  • Loading branch information
captainurist committed Feb 9, 2025
1 parent 6ebd5c0 commit 597ba29
Show file tree
Hide file tree
Showing 20 changed files with 152 additions and 153 deletions.
2 changes: 1 addition & 1 deletion src/Application/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ void Game::processQueuedMessages() {
}
if (ptr_50C9A4_ItemToEnchant &&
ptr_50C9A4_ItemToEnchant->itemId != ITEM_NULL) {
ptr_50C9A4_ItemToEnchant->uAttributes &= ~ITEM_ENCHANT_ANIMATION_MASK;
ptr_50C9A4_ItemToEnchant->flags &= ~ITEM_ENCHANT_ANIMATION_MASK;
ItemEnchantmentTimer = 0_ticks;
ptr_50C9A4_ItemToEnchant = nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Engine/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,7 @@ void RegeneratePartyHealthMana() {
if (character.classType == CLASS_LICH) {
bool lich_has_jar = false;
for (const ItemGen &item : character.pInventoryItemList)
if (item.itemId == ITEM_QUEST_LICH_JAR_FULL && item.uHolderPlayer == character.getCharacterIndex())
if (item.itemId == ITEM_QUEST_LICH_JAR_FULL && item.lichJarCharacterIndex == character.getCharacterIndex())
lich_has_jar = true;

if (lich_has_jar) {
Expand Down
4 changes: 2 additions & 2 deletions src/Engine/Objects/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3579,8 +3579,8 @@ void Actor::LootActor() {
StatusBarItemFound(foundGold, pItemTable->pItems[Dst.itemId].pUnidentifiedName);

if (Dst.isWand()) {
Dst.uNumCharges = grng->random(6) + Dst.GetDamageMod() + 1;
Dst.uMaxCharges = Dst.uNumCharges;
Dst.numCharges = grng->random(6) + Dst.GetDamageMod() + 1;
Dst.maxCharges = Dst.numCharges;
}
if (Dst.isPotion() && Dst.itemId != ITEM_POTION_BOTTLE) {
Dst.potionPower = 2 * grng->random(4) + 2;
Expand Down
36 changes: 18 additions & 18 deletions src/Engine/Objects/Character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,14 +410,14 @@ void Character::ItemsPotionDmgBreak(int enchant_count) {
int indexbreak =
item_index_tabl[grng->random(avalible_items)]; // random item

if (!(pInventoryItemList[indexbreak].uAttributes &
if (!(pInventoryItemList[indexbreak].flags &
ITEM_HARDENED)) // if its not hardened
pInventoryItemList[indexbreak].uAttributes |=
pInventoryItemList[indexbreak].flags |=
ITEM_BROKEN; // break it
}
} else {
for (int i = 0; i < avalible_items; ++i) { // break everything
pInventoryItemList[item_index_tabl[i]].uAttributes |=
pInventoryItemList[item_index_tabl[i]].flags |=
ITEM_BROKEN;
}
}
Expand Down Expand Up @@ -676,7 +676,7 @@ void Character::WearItem(ItemId uItemID) {
pInventoryItemList[item_indx].itemId = uItemID;
ItemSlot item_body_anch = pEquipTypeToBodyAnchor[pItemTable->pItems[uItemID].uEquipType];
pEquipment[item_body_anch] = item_indx + 1;
pInventoryItemList[item_indx].uBodyAnchor = item_body_anch;
pInventoryItemList[item_indx].equippedSlot = item_body_anch;
}
}

Expand Down Expand Up @@ -1544,8 +1544,8 @@ StealResult Character::StealFromActor(unsigned int uActorID, int _steal_perm, in
actroPtr->carriedItemId = ITEM_NULL;
tempItem.itemId = carriedItemId;
if (pItemTable->pItems[carriedItemId].uEquipType == ITEM_TYPE_WAND) {
tempItem.uNumCharges = grng->random(6) + pItemTable->pItems[carriedItemId].uDamageMod + 1;
tempItem.uMaxCharges = tempItem.uNumCharges;
tempItem.numCharges = grng->random(6) + pItemTable->pItems[carriedItemId].uDamageMod + 1;
tempItem.maxCharges = tempItem.numCharges;
} else if (pItemTable->pItems[carriedItemId].uEquipType == ITEM_TYPE_POTION && carriedItemId != ITEM_POTION_BOTTLE) {
tempItem.potionPower = 2 * grng->random(4) + 2;
}
Expand Down Expand Up @@ -1608,7 +1608,7 @@ int Character::receiveDamage(signed int amount, DamageType dmg_type) {
if (health <= -10) { // break armor if health has dropped below -10
ItemGen *equippedArmor = GetArmorItem();
if (equippedArmor != nullptr) { // check there is some armor
if (!(equippedArmor->uAttributes &
if (!(equippedArmor->flags &
ITEM_HARDENED)) { // if its not hardened
equippedArmor->SetBroken(); // break it
}
Expand Down Expand Up @@ -1902,7 +1902,7 @@ int Character::ReceiveSpecialAttackEffect(SpecialAttackType attType, Actor *pAct
case SPECIAL_ATTACK_BREAK_ANY:
case SPECIAL_ATTACK_BREAK_ARMOR:
case SPECIAL_ATTACK_BREAK_WEAPON:
if (!(itemtobreak->uAttributes & ITEM_HARDENED)) {
if (!(itemtobreak->flags & ITEM_HARDENED)) {
playReaction(SPEECH_ITEM_BROKEN);
itemtobreak->SetBroken();
pAudioPlayer->playUISound(SOUND_metal_vs_metal03h);
Expand Down Expand Up @@ -4377,7 +4377,7 @@ void Character::SetVariable(EvtVariable var_type, signed int var_value) {
for (int i = 0; i < INVENTORY_SLOT_COUNT; i++) {
if (this->pInventoryItemList[i].itemId == ITEM_QUEST_LICH_JAR_EMPTY) {
this->pInventoryItemList[i].itemId = ITEM_QUEST_LICH_JAR_FULL;
this->pInventoryItemList[i].uHolderPlayer = getCharacterIndex();
this->pInventoryItemList[i].lichJarCharacterIndex = getCharacterIndex();
}
}
if (this->sResFireBase < 20) this->sResFireBase = 20;
Expand Down Expand Up @@ -4454,7 +4454,7 @@ void Character::SetVariable(EvtVariable var_type, signed int var_value) {
case VAR_PlayerItemInHands:
item.Reset();
item.itemId = ItemId(var_value);
item.uAttributes = ITEM_IDENTIFIED;
item.flags = ITEM_IDENTIFIED;
pParty->setHoldingItem(&item);
if (isSpawnableArtifact(ItemId(var_value)))
pParty->pIsArtifactFound[ItemId(var_value)] = true;
Expand Down Expand Up @@ -5063,13 +5063,13 @@ void Character::AddVariable(EvtVariable var_type, signed int val) {
return;
case VAR_PlayerItemInHands:
item.Reset();
item.uAttributes = ITEM_IDENTIFIED;
item.flags = ITEM_IDENTIFIED;
item.itemId = ItemId(val);
if (isSpawnableArtifact(ItemId(val))) {
pParty->pIsArtifactFound[ItemId(val)] = true;
} else if (isWand(ItemId(val))) {
item.uNumCharges = grng->random(6) + item.GetDamageMod() + 1;
item.uMaxCharges = item.uNumCharges;
item.numCharges = grng->random(6) + item.GetDamageMod() + 1;
item.maxCharges = item.numCharges;
}
pParty->setHoldingItem(&item);
return;
Expand Down Expand Up @@ -6101,16 +6101,16 @@ void Character::EquipBody(ItemType uEquipType) {
itemInvLocation = pParty->activeCharacter().pEquipment[itemAnchor];
if (itemInvLocation) { //переодеться в другую вещь
tempPickedItem = pParty->pPickedItem;
pParty->activeCharacter().pInventoryItemList[itemInvLocation - 1].uBodyAnchor = ITEM_SLOT_INVALID;
pParty->activeCharacter().pInventoryItemList[itemInvLocation - 1].equippedSlot = ITEM_SLOT_INVALID;
pParty->pPickedItem.Reset();
pParty->setHoldingItem(&pParty->activeCharacter().pInventoryItemList[itemInvLocation - 1]);
tempPickedItem.uBodyAnchor = itemAnchor;
tempPickedItem.equippedSlot = itemAnchor;
pParty->activeCharacter().pInventoryItemList[itemInvLocation - 1] = tempPickedItem;
pParty->activeCharacter().pEquipment[itemAnchor] = itemInvLocation;
} else { // одеть вещь
freeSlot = pParty->activeCharacter().findFreeInventoryListSlot();
if (freeSlot >= 0) {
pParty->pPickedItem.uBodyAnchor = itemAnchor;
pParty->pPickedItem.equippedSlot = itemAnchor;
pParty->activeCharacter().pInventoryItemList[freeSlot] = pParty->pPickedItem;
pParty->activeCharacter().pEquipment[itemAnchor] = freeSlot + 1;
mouse->RemoveHoldingItem();
Expand Down Expand Up @@ -6843,7 +6843,7 @@ void Character::_42ECB5_CharacterAttacksActor() {
// v28b = &v1->pInventoryItems[v4].uItemID;
// v6 = v1->pInventoryItems[v4].uItemID;//*((int *)v5 + 124);
if (item->isWand()) {
if (item->uNumCharges <= 0)
if (item->numCharges <= 0)
character->pEquipment[ITEM_SLOT_MAIN_HAND] =
0; // wand discharged - unequip
else
Expand Down Expand Up @@ -6898,7 +6898,7 @@ void Character::_42ECB5_CharacterAttacksActor() {
pushSpellOrRangedAttack(spellForWand(character->pInventoryItemList[main_hand_idx - 1].itemId),
pParty->activeCharacterIndex() - 1, WANDS_SKILL_VALUE, 0, pParty->activeCharacterIndex() + 8);

if (!--character->pInventoryItemList[main_hand_idx - 1].uNumCharges)
if (!--character->pInventoryItemList[main_hand_idx - 1].numCharges)
character->pEquipment[ITEM_SLOT_MAIN_HAND] = 0;
} else if (target_type == OBJECT_Actor && actor_distance <= 407.2) {
melee_attack = true;
Expand Down
6 changes: 3 additions & 3 deletions src/Engine/Objects/Chest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,10 @@ int Chest::PutItemInChest(int position, ItemGen *put_item, int uChestID) {
void Chest::PlaceItemAt(unsigned int put_cell_pos, unsigned int item_at_cell, int uChestID) { // only used for setup?
ItemId uItemID = vChests[uChestID].igChestItems[item_at_cell].itemId;
pItemTable->SetSpecialBonus(&vChests[uChestID].igChestItems[item_at_cell]);
if (isWand(uItemID) && !vChests[uChestID].igChestItems[item_at_cell].uNumCharges) {
if (isWand(uItemID) && !vChests[uChestID].igChestItems[item_at_cell].numCharges) {
int v6 = grng->random(21) + 10;
vChests[uChestID].igChestItems[item_at_cell].uNumCharges = v6;
vChests[uChestID].igChestItems[item_at_cell].uMaxCharges = v6;
vChests[uChestID].igChestItems[item_at_cell].numCharges = v6;
vChests[uChestID].igChestItems[item_at_cell].maxCharges = v6;
}

auto img = assets->getImage_Alpha(pItemTable->pItems[uItemID].iconName);
Expand Down
12 changes: 6 additions & 6 deletions src/Engine/Objects/Items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,19 @@ void ItemGen::Reset() {

//----- (00458260) --------------------------------------------------------
void ItemGen::UpdateTempBonus(Time time) {
if (this->uAttributes & ITEM_TEMP_BONUS) {
if (time > this->uExpireTime) {
if (this->flags & ITEM_TEMP_BONUS) {
if (time > this->enchantmentExpirationTime) {
this->attributeEnchantment = {};
this->specialEnchantment = ITEM_ENCHANTMENT_NULL;
this->uAttributes &= ~ITEM_TEMP_BONUS;
this->flags &= ~ITEM_TEMP_BONUS;
}
}
}

//----- (00456442) --------------------------------------------------------
int ItemGen::GetValue() const {
int uBaseValue = pItemTable->pItems[this->itemId].uValue;
if (uAttributes & ITEM_TEMP_BONUS || pItemTable->IsMaterialNonCommon(this))
if (flags & ITEM_TEMP_BONUS || pItemTable->IsMaterialNonCommon(this))
return uBaseValue;
if (potionPower || attributeEnchantment) // TODO(captainurist): can drop potionPower?
return uBaseValue + 100 * attributeEnchantmentStrength;
Expand Down Expand Up @@ -190,8 +190,8 @@ std::string ItemGen::GetIdentifiedName() {
}

if (itemId == ITEM_QUEST_LICH_JAR_FULL) { // Lich Jar
if (uHolderPlayer >= 0 && uHolderPlayer < pParty->pCharacters.size()) {
const std::string &player_name = pParty->pCharacters[uHolderPlayer].name;
if (lichJarCharacterIndex >= 0 && lichJarCharacterIndex < pParty->pCharacters.size()) {
const std::string &player_name = pParty->pCharacters[lichJarCharacterIndex].name;
if (player_name.back() == 's')
return localization->FormatString(LSTR_FMT_JAR_2, player_name);
else
Expand Down
45 changes: 22 additions & 23 deletions src/Engine/Objects/Items.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,31 @@ struct ItemGen { // 0x24
void GetItemBonusArtifact(const Character *owner, CharacterAttribute attrToGet, int *bonusSum) const;
void GetItemBonusSpecialEnchantment(const Character *owner, CharacterAttribute attrToGet, int *additiveBonus, int *halfSkillBonus) const;

inline void ResetEnchantAnimation() { uAttributes &= ~ITEM_ENCHANT_ANIMATION_MASK; }
inline void ResetEnchantAnimation() { flags &= ~ITEM_ENCHANT_ANIMATION_MASK; }
inline bool ItemEnchanted() const {
return uAttributes & ITEM_ENCHANT_ANIMATION_MASK;
return flags & ITEM_ENCHANT_ANIMATION_MASK;
}
inline bool AuraEffectRed() const {
return (uAttributes & ITEM_ENCHANT_ANIMATION_MASK) == ITEM_AURA_EFFECT_RED;
return (flags & ITEM_ENCHANT_ANIMATION_MASK) == ITEM_AURA_EFFECT_RED;
}
inline bool AuraEffectBlue() const {
return (uAttributes & ITEM_ENCHANT_ANIMATION_MASK) == ITEM_AURA_EFFECT_BLUE;
return (flags & ITEM_ENCHANT_ANIMATION_MASK) == ITEM_AURA_EFFECT_BLUE;
}
inline bool AuraEffectGreen() const {
return (uAttributes & ITEM_ENCHANT_ANIMATION_MASK) == ITEM_AURA_EFFECT_GREEN;
return (flags & ITEM_ENCHANT_ANIMATION_MASK) == ITEM_AURA_EFFECT_GREEN;
}
inline bool AuraEffectPurple() const {
return (uAttributes & ITEM_ENCHANT_ANIMATION_MASK) == ITEM_AURA_EFFECT_PURPLE;
return (flags & ITEM_ENCHANT_ANIMATION_MASK) == ITEM_AURA_EFFECT_PURPLE;
}

bool IsRegularEnchanmentForAttribute(CharacterAttribute attrToGet);

inline bool IsBroken() const { return uAttributes & ITEM_BROKEN; }
inline void SetBroken() { uAttributes |= ITEM_BROKEN; }
inline bool IsIdentified() const { return uAttributes & ITEM_IDENTIFIED; }
inline void SetIdentified() { uAttributes |= ITEM_IDENTIFIED; }
inline bool IsStolen() const { return uAttributes & ITEM_STOLEN; }
inline void SetStolen() { uAttributes |= ITEM_STOLEN; }
inline bool IsBroken() const { return flags & ITEM_BROKEN; }
inline void SetBroken() { flags |= ITEM_BROKEN; }
inline bool IsIdentified() const { return flags & ITEM_IDENTIFIED; }
inline void SetIdentified() { flags |= ITEM_IDENTIFIED; }
inline bool IsStolen() const { return flags & ITEM_STOLEN; }
inline void SetStolen() { flags |= ITEM_STOLEN; }

bool GenerateArtifact();
void generateGold(ItemTreasureLevel treasureLevel);
Expand Down Expand Up @@ -111,20 +111,19 @@ struct ItemGen { // 0x24

// TODO(captainurist): introduce ATTRIBUTE_NULL?
std::optional<CharacterAttribute> attributeEnchantment; // Attribute enchantment, if any.
int32_t attributeEnchantmentStrength = 0; // Attribute enchantment strength - bonus value for the attribute.

int attributeEnchantmentStrength = 0; // Attribute enchantment strength - bonus value for the attribute.
ItemEnchantment specialEnchantment = ITEM_ENCHANTMENT_NULL; // Special named enchantment, if any.
int32_t uNumCharges = 0; // Number of wand charges, wand disappears when this gets down to 0.
ItemFlags uAttributes = 0; // Item flags.
ItemSlot uBodyAnchor = ITEM_SLOT_INVALID; // For equipped items - where is it equipped.
uint8_t uMaxCharges = 0; // Max charges in a wand. This is used when recharging.
int8_t uHolderPlayer = -1; // Only for full lich jars. 0-based index of the character whose earthly remains are stored in it.
// Or whatever it is that's in the lich jar.
int numCharges = 0; // Number of wand charges, wand disappears when this gets down to 0.
int maxCharges = 0; // Max charges in a wand. This is used when recharging.
ItemFlags flags = 0; // Item flags.
ItemSlot equippedSlot = ITEM_SLOT_INVALID; // For equipped items - where is it equipped.
int lichJarCharacterIndex = -1; // Only for full lich jars. 0-based index of the character whose earthly remains are stored in it.
// Or whatever it is that's in the lich jar.
bool placedInChest = false; // OE addition, whether the item was placed in the chest inventory area. Some chests
// are generated with more items than chest space, and this flag is used to track it.
Time uExpireTime; // Enchantment expiration time, if this item is temporarily enchanted. Note that both special
// and attribute enchantments can be temporary, but in MM7 we only have special temporary
// enchantments.
Time enchantmentExpirationTime; // Enchantment expiration time, if this item is temporarily enchanted. Note that
// both special and attribute enchantments can be temporary, but in MM7 we only have
// special temporary enchantments.
};

struct ItemDesc { // 30h
Expand Down
2 changes: 1 addition & 1 deletion src/Engine/Party.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ void Party::restAndHeal() {
if (pPlayer->classType == CLASS_LICH) {
have_vessels_soul = false;
for (unsigned i = 0; i < Character::INVENTORY_SLOT_COUNT; i++) {
if (pPlayer->pInventoryItemList[i].itemId == ITEM_QUEST_LICH_JAR_FULL && pPlayer->pInventoryItemList[i].uHolderPlayer == pPlayerID)
if (pPlayer->pInventoryItemList[i].itemId == ITEM_QUEST_LICH_JAR_FULL && pPlayer->pInventoryItemList[i].lichJarCharacterIndex == pPlayerID)
have_vessels_soul = true;
}
if (!have_vessels_soul) {
Expand Down
Loading

0 comments on commit 597ba29

Please sign in to comment.