Skip to content

Commit

Permalink
Actor: get rid of redundant Equipped and EquippedHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
fizzet committed Jul 6, 2013
1 parent c16d691 commit 4edef35
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 23 deletions.
6 changes: 6 additions & 0 deletions gemrb/core/Inventory.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1285,6 +1285,12 @@ int Inventory::GetEquippedHeader() const
return EquippedHeader; return EquippedHeader;
} }


void Inventory::SetEquipped(ieWordSigned slot, ieWord header)
{
Equipped = slot;
EquippedHeader = header;
}

//returns the fist weapon if there is nothing else //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 //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 CREItem *Inventory::GetUsedWeapon(bool leftorright, int &slot) const
Expand Down
1 change: 1 addition & 0 deletions gemrb/core/Inventory.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ class GEM_EXPORT Inventory {
bool SetEquippedSlot(ieWordSigned slotcode, ieWord header); bool SetEquippedSlot(ieWordSigned slotcode, ieWord header);
int GetEquipped() const; int GetEquipped() const;
int GetEquippedHeader() const; int GetEquippedHeader() const;
void SetEquipped(ieWordSigned slot, ieWord header);
//right hand //right hand
int GetEquippedSlot() const; int GetEquippedSlot() const;
//left hand //left hand
Expand Down
26 changes: 7 additions & 19 deletions gemrb/core/Scriptable/Actor.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -476,8 +476,6 @@ Actor::Actor()
nextBored = 0; nextBored = 0;


inventory.SetInventoryType(INVENTORY_CREATURE); inventory.SetInventoryType(INVENTORY_CREATURE);
Equipped = 0;
EquippedHeader = 0;


fxqueue.SetOwner( this ); fxqueue.SetOwner( this );
inventory.SetOwner( this ); inventory.SetOwner( this );
Expand Down Expand Up @@ -4267,12 +4265,8 @@ void Actor::SetMap(Map *map)
//case of quivers. (weird IE magic) //case of quivers. (weird IE magic)
//The other word is the equipped header. //The other word is the equipped header.
//find a quiver for the bow, etc //find a quiver for the bow, etc
if (Equipped!=IW_NO_EQUIPPED) { inventory.EquipItem(inventory.GetEquippedSlot());
inventory.EquipItem( Equipped+inventory.GetWeaponSlot()); SetEquippedQuickSlot(inventory.GetEquipped(), inventory.GetEquippedHeader());
} else {
inventory.EquipItem(inventory.GetFistSlot());
}
SetEquippedQuickSlot( inventory.GetEquipped(), EquippedHeader );
} }
} }


Expand Down Expand Up @@ -5659,7 +5653,7 @@ ieDword Actor::GetNumberOfAttacks()
bonus = 2 * IsDualWielding(); bonus = 2 * IsDualWielding();
return base + bonus; return base + bonus;
} else { } else {
if (monkbon != NULL && Equipped == IW_NO_EQUIPPED) { if (monkbon != NULL && inventory.GetEquipped() == IW_NO_EQUIPPED) {
unsigned int level = GetMonkLevel(); unsigned int level = GetMonkLevel();
if (level>=monkbon_cols) level=monkbon_cols-1; if (level>=monkbon_cols) level=monkbon_cols-1;
if (level>0) { if (level>0) {
Expand Down Expand Up @@ -5726,7 +5720,7 @@ int Actor::SetBaseAPRandAB(bool CheckRapidShot)
// act as a rogue unless barefisted and without armor // act as a rogue unless barefisted and without armor
// multiclassed monks only use their monk levels when determining barefisted bab // 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 // 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); pBAB += SetLevelBAB(MonkLevel, ISTHIEF);
} else { } else {
pBABDecrement = 3; pBABDecrement = 3;
Expand Down Expand Up @@ -5926,7 +5920,7 @@ bool Actor::GetCombatDetails(int &tohit, bool leftorright, WeaponInfo& wi, ITMEx
prof += -4; prof += -4;
} else { } else {
// everyone is proficient with fists // everyone is proficient with fists
if (Equipped != IW_NO_EQUIPPED) { if (inventory.GetEquipped() != IW_NO_EQUIPPED) {
prof += wspecial[stars][0]; prof += wspecial[stars][0];
} }
} }
Expand All @@ -5940,7 +5934,7 @@ bool Actor::GetCombatDetails(int &tohit, bool leftorright, WeaponInfo& wi, ITMEx
//Is it a PC class? //Is it a PC class?
if (clss < (ieDword) classcount) { if (clss < (ieDword) classcount) {
// but skip fists, since they don't have a proficiency // but skip fists, since they don't have a proficiency
if (Equipped != IW_NO_EQUIPPED) { if (inventory.GetEquipped() != IW_NO_EQUIPPED) {
prof += defaultprof[clss]; prof += defaultprof[clss];
} }
} else { } else {
Expand Down Expand Up @@ -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 it is the fist slot and not currently used, then set it up
if (i==MAX_QUICKWEAPONSLOT) { if (i==MAX_QUICKWEAPONSLOT) {
Equipped = IW_NO_EQUIPPED; inventory.SetEquippedSlot(IW_NO_EQUIPPED, 0);
EquippedHeader = 0;
inventory.SetEquippedSlot(Equipped, EquippedHeader);
return 0; return 0;
} }
} }
Expand All @@ -7946,8 +7938,6 @@ int Actor::SetEquippedQuickSlot(int slot, int header)
PCStats->QuickWeaponHeaders[slot]=header; PCStats->QuickWeaponHeaders[slot]=header;
} }
slot = inventory.GetWeaponQuickSlot(PCStats->QuickWeaponSlots[slot]); slot = inventory.GetWeaponQuickSlot(PCStats->QuickWeaponSlots[slot]);
Equipped = (ieWordSigned) slot;
EquippedHeader = (ieWord) header;
if (inventory.SetEquippedSlot(slot, header)) { if (inventory.SetEquippedSlot(slot, header)) {
return 0; return 0;
} }
Expand Down Expand Up @@ -8784,8 +8774,6 @@ Actor *Actor::CopySelf(bool mislead) const
newActor->inventory.SetSlotCount(inventory.GetSlotCount()); newActor->inventory.SetSlotCount(inventory.GetSlotCount());
} else { } else {
newActor->inventory.CopyFrom(this); newActor->inventory.CopyFrom(this);
newActor->Equipped = Equipped;
newActor->EquippedHeader = EquippedHeader;
if (PCStats) { if (PCStats) {
newActor->CreateStats(); newActor->CreateStats();
memcpy(newActor->PCStats, PCStats, sizeof(PCStatsStruct)); memcpy(newActor->PCStats, PCStats, sizeof(PCStatsStruct));
Expand Down
2 changes: 0 additions & 2 deletions gemrb/core/Scriptable/Actor.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -303,8 +303,6 @@ class GEM_EXPORT Actor : public Movable {
ieByte SetDeathVar, IncKillCount, UnknownField; // boolean fields from iwd1 and iwd2 ieByte SetDeathVar, IncKillCount, UnknownField; // boolean fields from iwd1 and iwd2


Inventory inventory; Inventory inventory;
ieWordSigned Equipped; //the equipped weapon slot
ieWord EquippedHeader; //the used extended header
Spellbook spellbook; Spellbook spellbook;
//savefile version (creatures embedded in area) //savefile version (creatures embedded in area)
int version; int version;
Expand Down
7 changes: 5 additions & 2 deletions gemrb/plugins/CREImporter/CREImporter.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1243,6 +1243,8 @@ void CREImporter::ReadInventory(Actor *act, unsigned int Inventory_Size)
ieWord *indices = (ieWord *) calloc(Inventory_Size, sizeof(ieWord)); ieWord *indices = (ieWord *) calloc(Inventory_Size, sizeof(ieWord));
//CREItem** items; //CREItem** items;
unsigned int i,j,k; unsigned int i,j,k;
ieWordSigned eqslot;
ieWord eqheader;


act->inventory.SetSlotCount(Inventory_Size+1); act->inventory.SetSlotCount(Inventory_Size+1);
str->Seek( ItemSlotsOffset+CREOffset, GEM_STREAM_START ); str->Seek( ItemSlotsOffset+CREOffset, GEM_STREAM_START );
Expand All @@ -1256,9 +1258,10 @@ void CREImporter::ReadInventory(Actor *act, unsigned int Inventory_Size)
// 1000 - fist // 1000 - fist
// -24,-23,-22,-21 - quiver // -24,-23,-22,-21 - quiver
//the equipping effects are delayed until the actor gets an area //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 //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 //read the item entries based on the previously read indices
//an item entry may be read multiple times if the indices are repeating //an item entry may be read multiple times if the indices are repeating
Expand Down

0 comments on commit 4edef35

Please sign in to comment.