Permalink
Browse files

Actor: get rid of redundant Equipped and EquippedHeader

  • Loading branch information...
1 parent c16d691 commit 4edef35f989c902730e863a4ccebfd293432b4ff @fizzet fizzet committed Jul 6, 2013
View
@@ -1285,6 +1285,12 @@ int Inventory::GetEquippedHeader() const
return EquippedHeader;
}
+void Inventory::SetEquipped(ieWordSigned slot, ieWord header)
+{
+ Equipped = slot;
+ EquippedHeader = header;
+}
+
//returns the fist weapon if there is nothing else
//This will return the actual weapon, I mean the bow in the case of bow+arrow combination
CREItem *Inventory::GetUsedWeapon(bool leftorright, int &slot) const
View
@@ -277,6 +277,7 @@ class GEM_EXPORT Inventory {
bool SetEquippedSlot(ieWordSigned slotcode, ieWord header);
int GetEquipped() const;
int GetEquippedHeader() const;
+ void SetEquipped(ieWordSigned slot, ieWord header);
//right hand
int GetEquippedSlot() const;
//left hand
@@ -476,8 +476,6 @@ Actor::Actor()
nextBored = 0;
inventory.SetInventoryType(INVENTORY_CREATURE);
- Equipped = 0;
- EquippedHeader = 0;
fxqueue.SetOwner( this );
inventory.SetOwner( this );
@@ -4267,12 +4265,8 @@ void Actor::SetMap(Map *map)
//case of quivers. (weird IE magic)
//The other word is the equipped header.
//find a quiver for the bow, etc
- if (Equipped!=IW_NO_EQUIPPED) {
- inventory.EquipItem( Equipped+inventory.GetWeaponSlot());
- } else {
- inventory.EquipItem(inventory.GetFistSlot());
- }
- SetEquippedQuickSlot( inventory.GetEquipped(), EquippedHeader );
+ inventory.EquipItem(inventory.GetEquippedSlot());
+ SetEquippedQuickSlot(inventory.GetEquipped(), inventory.GetEquippedHeader());
}
}
@@ -5659,7 +5653,7 @@ ieDword Actor::GetNumberOfAttacks()
bonus = 2 * IsDualWielding();
return base + bonus;
} else {
- if (monkbon != NULL && Equipped == IW_NO_EQUIPPED) {
+ if (monkbon != NULL && inventory.GetEquipped() == IW_NO_EQUIPPED) {
unsigned int level = GetMonkLevel();
if (level>=monkbon_cols) level=monkbon_cols-1;
if (level>0) {
@@ -5726,7 +5720,7 @@ int Actor::SetBaseAPRandAB(bool CheckRapidShot)
// act as a rogue unless barefisted and without armor
// multiclassed monks only use their monk levels when determining barefisted bab
// check the spell failure instead of the skill penalty, since otherwise leather armor would also be treated as none
- if (Equipped != IW_NO_EQUIPPED || GetTotalArmorFailure()) {
+ if (inventory.GetEquipped() != IW_NO_EQUIPPED || GetTotalArmorFailure()) {
pBAB += SetLevelBAB(MonkLevel, ISTHIEF);
} else {
pBABDecrement = 3;
@@ -5926,7 +5920,7 @@ bool Actor::GetCombatDetails(int &tohit, bool leftorright, WeaponInfo& wi, ITMEx
prof += -4;
} else {
// everyone is proficient with fists
- if (Equipped != IW_NO_EQUIPPED) {
+ if (inventory.GetEquipped() != IW_NO_EQUIPPED) {
prof += wspecial[stars][0];
}
}
@@ -5940,7 +5934,7 @@ bool Actor::GetCombatDetails(int &tohit, bool leftorright, WeaponInfo& wi, ITMEx
//Is it a PC class?
if (clss < (ieDword) classcount) {
// but skip fists, since they don't have a proficiency
- if (Equipped != IW_NO_EQUIPPED) {
+ if (inventory.GetEquipped() != IW_NO_EQUIPPED) {
prof += defaultprof[clss];
}
} else {
@@ -7931,9 +7925,7 @@ int Actor::SetEquippedQuickSlot(int slot, int header)
}
//if it is the fist slot and not currently used, then set it up
if (i==MAX_QUICKWEAPONSLOT) {
- Equipped = IW_NO_EQUIPPED;
- EquippedHeader = 0;
- inventory.SetEquippedSlot(Equipped, EquippedHeader);
+ inventory.SetEquippedSlot(IW_NO_EQUIPPED, 0);
return 0;
}
}
@@ -7946,8 +7938,6 @@ int Actor::SetEquippedQuickSlot(int slot, int header)
PCStats->QuickWeaponHeaders[slot]=header;
}
slot = inventory.GetWeaponQuickSlot(PCStats->QuickWeaponSlots[slot]);
- Equipped = (ieWordSigned) slot;
- EquippedHeader = (ieWord) header;
if (inventory.SetEquippedSlot(slot, header)) {
return 0;
}
@@ -8784,8 +8774,6 @@ Actor *Actor::CopySelf(bool mislead) const
newActor->inventory.SetSlotCount(inventory.GetSlotCount());
} else {
newActor->inventory.CopyFrom(this);
- newActor->Equipped = Equipped;
- newActor->EquippedHeader = EquippedHeader;
if (PCStats) {
newActor->CreateStats();
memcpy(newActor->PCStats, PCStats, sizeof(PCStatsStruct));
@@ -303,8 +303,6 @@ class GEM_EXPORT Actor : public Movable {
ieByte SetDeathVar, IncKillCount, UnknownField; // boolean fields from iwd1 and iwd2
Inventory inventory;
- ieWordSigned Equipped; //the equipped weapon slot
- ieWord EquippedHeader; //the used extended header
Spellbook spellbook;
//savefile version (creatures embedded in area)
int version;
@@ -1243,6 +1243,8 @@ void CREImporter::ReadInventory(Actor *act, unsigned int Inventory_Size)
ieWord *indices = (ieWord *) calloc(Inventory_Size, sizeof(ieWord));
//CREItem** items;
unsigned int i,j,k;
+ ieWordSigned eqslot;
+ ieWord eqheader;
act->inventory.SetSlotCount(Inventory_Size+1);
str->Seek( ItemSlotsOffset+CREOffset, GEM_STREAM_START );
@@ -1256,9 +1258,10 @@ void CREImporter::ReadInventory(Actor *act, unsigned int Inventory_Size)
// 1000 - fist
// -24,-23,-22,-21 - quiver
//the equipping effects are delayed until the actor gets an area
- str->ReadWordSigned( &act->Equipped );
+ str->ReadWordSigned(&eqslot);
//the equipped slot's selected ability is stored here
- str->ReadWord( &act->EquippedHeader );
+ str->ReadWord(&eqheader);
+ act->inventory.SetEquipped(eqslot, eqheader);
//read the item entries based on the previously read indices
//an item entry may be read multiple times if the indices are repeating

0 comments on commit 4edef35

Please sign in to comment.