mirror of
https://github.com/vcmi/vcmi.git
synced 2025-02-03 13:01:33 +02:00
Minor refactorings, fixes & improvements.
Moved CArtifactSet to ArtHandler. ObjectHandler is already too messed.
This commit is contained in:
parent
e41d2f6e87
commit
bdce46ab60
@ -142,8 +142,8 @@ void CCreatureWindow::init(const CStackInstance *Stack, const CBonusSystemNode *
|
||||
Bonus * b = node.bonuses.front();
|
||||
|
||||
bl.push_back (new Bonus(*b));
|
||||
bl.back()->val = node.valOfBonuses(Selector::typeSybtype(b->type, b->subtype)); //merge multiple bonuses into one
|
||||
node.bonuses.remove_if (Selector::typeSybtype(b->type, b->subtype)); //remove used bonuses
|
||||
bl.back()->val = node.valOfBonuses(Selector::typeSubtype(b->type, b->subtype)); //merge multiple bonuses into one
|
||||
node.bonuses.remove_if (Selector::typeSubtype(b->type, b->subtype)); //remove used bonuses
|
||||
}
|
||||
|
||||
std::string text;
|
||||
|
@ -166,18 +166,10 @@ CKingdomInterface::CKingdomInterface()
|
||||
incomesVal[7] = incomesVal[6]*1000;//gold mines -> total income
|
||||
std::vector<const CGHeroInstance*> heroes = LOCPLINT->cb->getHeroesInfo(true);
|
||||
for(size_t i=0; i<heroes.size();i++)
|
||||
switch(heroes[i]->getSecSkillLevel(CGHeroInstance::ESTATES))//some heroes may have estates
|
||||
{
|
||||
case 1: //basic
|
||||
incomesVal[7] += 125;
|
||||
break;
|
||||
case 2: //advanced
|
||||
incomesVal[7] += 250;
|
||||
break;
|
||||
case 3: //expert
|
||||
incomesVal[7] += 500;
|
||||
break;
|
||||
}
|
||||
{ //TODO: what about artifacts generating resources?
|
||||
incomesVal[7] += heroes[i]->valOfBonuses(Selector::typeSubtype(Bonus::SECONDARY_SKILL, CGHeroInstance::ESTATES));
|
||||
incomesVal[7] += heroes[i]->valOfBonuses(Selector::typeSubtype(Bonus::GENERATE_RESOURCE, Res::GOLD));
|
||||
}
|
||||
std::vector<const CGTownInstance*> towns = LOCPLINT->cb->getTownsInfo(true);
|
||||
for(size_t i=0; i<towns.size();i++)
|
||||
incomesVal[7] += towns[i]->dailyIncome();
|
||||
|
@ -582,7 +582,7 @@ void CPlayerInterface::battleStacksHealedRes(const std::vector<std::pair<ui32, u
|
||||
|
||||
if (attacker)
|
||||
{
|
||||
battleInt->displayEffect(50, attacker->position);
|
||||
battleInt->displayEffect(52, attacker->position);
|
||||
if (attacker->count > 1)
|
||||
{
|
||||
textOff += 1;
|
||||
|
@ -476,9 +476,9 @@ TDmgRange BattleInfo::calculateDmgRange( const CStack* attacker, const CStack* d
|
||||
//calculating total attack/defense skills modifier
|
||||
|
||||
if(shooting) //precision handling (etc.)
|
||||
attackDefenceDifference += attacker->getBonuses(Selector::typeSybtype(Bonus::PRIMARY_SKILL, PrimarySkill::ATTACK), Selector::effectRange(Bonus::ONLY_DISTANCE_FIGHT)).totalValue();
|
||||
attackDefenceDifference += attacker->getBonuses(Selector::typeSubtype(Bonus::PRIMARY_SKILL, PrimarySkill::ATTACK), Selector::effectRange(Bonus::ONLY_DISTANCE_FIGHT)).totalValue();
|
||||
else //bloodlust handling (etc.)
|
||||
attackDefenceDifference += attacker->getBonuses(Selector::typeSybtype(Bonus::PRIMARY_SKILL, PrimarySkill::ATTACK), Selector::effectRange(Bonus::ONLY_MELEE_FIGHT)).totalValue();
|
||||
attackDefenceDifference += attacker->getBonuses(Selector::typeSubtype(Bonus::PRIMARY_SKILL, PrimarySkill::ATTACK), Selector::effectRange(Bonus::ONLY_MELEE_FIGHT)).totalValue();
|
||||
|
||||
|
||||
if(attacker->getEffect(55)) //slayer handling
|
||||
|
@ -673,9 +673,9 @@ void CArtHandler::addBonuses()
|
||||
giveArtBonus(112,Bonus::GENERATE_RESOURCE,+1,2); //Inexhaustible Cart of Ore
|
||||
giveArtBonus(113,Bonus::GENERATE_RESOURCE,+1,3); //Eversmoking Ring of Sulfur
|
||||
giveArtBonus(114,Bonus::GENERATE_RESOURCE,+1,0); //Inexhaustible Cart of Lumber
|
||||
giveArtBonus(115,Bonus::GENERATE_RESOURCE,+1000,6); //Endless Sack of Gold
|
||||
giveArtBonus(116,Bonus::GENERATE_RESOURCE,+750,6); //Endless Bag of Gold
|
||||
giveArtBonus(117,Bonus::GENERATE_RESOURCE,+500,6); //Endless Purse of Gold
|
||||
giveArtBonus(115,Bonus::GENERATE_RESOURCE,+1000, Res::GOLD); //Endless Sack of Gold
|
||||
giveArtBonus(116,Bonus::GENERATE_RESOURCE,+750, Res::GOLD); //Endless Bag of Gold
|
||||
giveArtBonus(117,Bonus::GENERATE_RESOURCE,+500, Res::GOLD); //Endless Purse of Gold
|
||||
|
||||
giveArtBonus(118,Bonus::CREATURE_GROWTH,+5,1); //Legs of Legion
|
||||
giveArtBonus(119,Bonus::CREATURE_GROWTH,+4,2); //Loins of Legion
|
||||
@ -746,10 +746,10 @@ void CArtHandler::addBonuses()
|
||||
giveArtBonus(139, Bonus::SPELL_DURATION, +50);
|
||||
|
||||
//Cornucopia
|
||||
giveArtBonus(140, Bonus::GENERATE_RESOURCE, +4, 1);
|
||||
giveArtBonus(140, Bonus::GENERATE_RESOURCE, +4, 3);
|
||||
giveArtBonus(140, Bonus::GENERATE_RESOURCE, +4, 4);
|
||||
giveArtBonus(140, Bonus::GENERATE_RESOURCE, +4, 5);
|
||||
giveArtBonus(140, Bonus::GENERATE_RESOURCE, +4, Res::MERCURY);
|
||||
giveArtBonus(140, Bonus::GENERATE_RESOURCE, +4, Res::SULFUR);
|
||||
giveArtBonus(140, Bonus::GENERATE_RESOURCE, +4, Res::CRYSTAL);
|
||||
giveArtBonus(140, Bonus::GENERATE_RESOURCE, +4, Res::GEMS);
|
||||
}
|
||||
|
||||
void CArtHandler::clear()
|
||||
@ -1195,4 +1195,137 @@ CCombinedArtifactInstance::ConstituentInfo::ConstituentInfo(CArtifactInstance *A
|
||||
{
|
||||
art = Art;
|
||||
slot = Slot;
|
||||
}
|
||||
|
||||
const CArtifactInstance* CArtifactSet::getArt(ui16 pos, bool excludeLocked /*= true*/) const
|
||||
{
|
||||
if(const ArtSlotInfo *si = getSlot(pos))
|
||||
{
|
||||
if(si->artifact && (!excludeLocked || !si->locked))
|
||||
return si->artifact;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CArtifactInstance* CArtifactSet::getArt(ui16 pos, bool excludeLocked /*= true*/)
|
||||
{
|
||||
return const_cast<CArtifactInstance*>((const_cast<const CArtifactSet*>(this))->getArt(pos, excludeLocked));
|
||||
}
|
||||
|
||||
si32 CArtifactSet::getArtPos(int aid, bool onlyWorn /*= true*/) const
|
||||
{
|
||||
for(std::map<ui16, ArtSlotInfo>::const_iterator i = artifactsWorn.begin(); i != artifactsWorn.end(); i++)
|
||||
if(i->second.artifact->artType->id == aid)
|
||||
return i->first;
|
||||
|
||||
if(onlyWorn)
|
||||
return -1;
|
||||
|
||||
for(int i = 0; i < artifactsInBackpack.size(); i++)
|
||||
if(artifactsInBackpack[i].artifact->artType->id == aid)
|
||||
return Arts::BACKPACK_START + i;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
si32 CArtifactSet::getArtPos(const CArtifactInstance *art) const
|
||||
{
|
||||
for(std::map<ui16, ArtSlotInfo>::const_iterator i = artifactsWorn.begin(); i != artifactsWorn.end(); i++)
|
||||
if(i->second.artifact == art)
|
||||
return i->first;
|
||||
|
||||
for(int i = 0; i < artifactsInBackpack.size(); i++)
|
||||
if(artifactsInBackpack[i].artifact == art)
|
||||
return Arts::BACKPACK_START + i;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
const CArtifactInstance * CArtifactSet::getArtByInstanceId(int artInstId) const
|
||||
{
|
||||
for(std::map<ui16, ArtSlotInfo>::const_iterator i = artifactsWorn.begin(); i != artifactsWorn.end(); i++)
|
||||
if(i->second.artifact->id == artInstId)
|
||||
return i->second.artifact;
|
||||
|
||||
for(int i = 0; i < artifactsInBackpack.size(); i++)
|
||||
if(artifactsInBackpack[i].artifact->id == artInstId)
|
||||
return artifactsInBackpack[i].artifact;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool CArtifactSet::hasArt(ui32 aid, bool onlyWorn /*= false*/) const
|
||||
{
|
||||
return getArtPos(aid, onlyWorn) != -1;
|
||||
}
|
||||
|
||||
const ArtSlotInfo * CArtifactSet::getSlot(ui16 pos) const
|
||||
{
|
||||
if(vstd::contains(artifactsWorn, pos))
|
||||
return &artifactsWorn[pos];
|
||||
if(pos >= Arts::AFTER_LAST )
|
||||
{
|
||||
int backpackPos = (int)pos - Arts::BACKPACK_START;
|
||||
if(backpackPos < 0 || backpackPos >= artifactsInBackpack.size())
|
||||
return NULL;
|
||||
else
|
||||
return &artifactsInBackpack[backpackPos];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool CArtifactSet::isPositionFree(ui16 pos, bool onlyLockCheck /*= false*/) const
|
||||
{
|
||||
if(const ArtSlotInfo *s = getSlot(pos))
|
||||
return (onlyLockCheck || !s->artifact) && !s->locked;
|
||||
|
||||
return true; //no slot means not used
|
||||
}
|
||||
|
||||
si32 CArtifactSet::getArtTypeId(ui16 pos) const
|
||||
{
|
||||
const CArtifactInstance * const a = getArt(pos);
|
||||
if(!a)
|
||||
{
|
||||
tlog2 << (dynamic_cast<const CGHeroInstance*>(this))->name << " has no artifact at " << pos << " (getArtTypeId)\n";
|
||||
return -1;
|
||||
}
|
||||
return a->artType->id;
|
||||
}
|
||||
|
||||
CArtifactSet::~CArtifactSet()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ArtSlotInfo & CArtifactSet::retreiveNewArtSlot(ui16 slot)
|
||||
{
|
||||
assert(!vstd::contains(artifactsWorn, slot));
|
||||
ArtSlotInfo &ret = slot < Arts::BACKPACK_START
|
||||
? artifactsWorn[slot]
|
||||
: *artifactsInBackpack.insert(artifactsInBackpack.begin() + (slot - Arts::BACKPACK_START), ArtSlotInfo());
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void CArtifactSet::setNewArtSlot(ui16 slot, CArtifactInstance *art, bool locked)
|
||||
{
|
||||
ArtSlotInfo &asi = retreiveNewArtSlot(slot);
|
||||
asi.artifact = art;
|
||||
asi.locked = locked;
|
||||
}
|
||||
|
||||
void CArtifactSet::eraseArtSlot(ui16 slot)
|
||||
{
|
||||
if(slot < Arts::BACKPACK_START)
|
||||
{
|
||||
artifactsWorn.erase(slot);
|
||||
}
|
||||
else
|
||||
{
|
||||
slot -= Arts::BACKPACK_START;
|
||||
artifactsInBackpack.erase(artifactsInBackpack.begin() + slot);
|
||||
}
|
||||
}
|
@ -227,5 +227,49 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
struct DLL_EXPORT ArtSlotInfo
|
||||
{
|
||||
ConstTransitivePtr<CArtifactInstance> artifact;
|
||||
ui8 locked; //if locked, then artifact points to the combined artifact
|
||||
|
||||
ArtSlotInfo()
|
||||
{
|
||||
locked = false;
|
||||
}
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & artifact & locked;
|
||||
}
|
||||
};
|
||||
|
||||
class DLL_EXPORT CArtifactSet
|
||||
{
|
||||
public:
|
||||
std::vector<ArtSlotInfo> artifactsInBackpack; //hero's artifacts from bag
|
||||
bmap<ui16, ArtSlotInfo> artifactsWorn; //map<position,artifact_id>; positions: 0 - head; 1 - shoulders; 2 - neck; 3 - right hand; 4 - left hand; 5 - torso; 6 - right ring; 7 - left ring; 8 - feet; 9 - misc1; 10 - misc2; 11 - misc3; 12 - misc4; 13 - mach1; 14 - mach2; 15 - mach3; 16 - mach4; 17 - spellbook; 18 - misc5
|
||||
|
||||
ArtSlotInfo &retreiveNewArtSlot(ui16 slot);
|
||||
void setNewArtSlot(ui16 slot, CArtifactInstance *art, bool locked);
|
||||
void eraseArtSlot(ui16 slot);
|
||||
|
||||
const ArtSlotInfo *getSlot(ui16 pos) const;
|
||||
const CArtifactInstance* getArt(ui16 pos, bool excludeLocked = true) const; //NULL - no artifact
|
||||
CArtifactInstance* getArt(ui16 pos, bool excludeLocked = true); //NULL - no artifact
|
||||
si32 getArtPos(int aid, bool onlyWorn = true) const; //looks for equipped artifact with given ID and returns its slot ID or -1 if none(if more than one such artifact lower ID is returned)
|
||||
si32 getArtPos(const CArtifactInstance *art) const;
|
||||
const CArtifactInstance *getArtByInstanceId(int artInstId) const;
|
||||
bool hasArt(ui32 aid, bool onlyWorn = false) const; //checks if hero possess artifact of given id (either in backack or worn)
|
||||
bool isPositionFree(ui16 pos, bool onlyLockCheck = false) const;
|
||||
si32 getArtTypeId(ui16 pos) const;
|
||||
|
||||
|
||||
virtual ~CArtifactSet();
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & artifactsInBackpack & artifactsWorn;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif // __CARTHANDLER_H__
|
||||
|
@ -601,7 +601,7 @@ std::string CStackInstance::bonusToString(Bonus *bonus, bool description) const
|
||||
case Bonus::ADDITIONAL_RETALIATION:
|
||||
case Bonus::DOUBLE_DAMAGE_CHANCE:
|
||||
case Bonus::DARKNESS: //Darkness Dragons any1?
|
||||
boost::algorithm::replace_first(text, "%d", boost::lexical_cast<std::string>(valOfBonuses(Selector::typeSybtype(bonus->type, bonus->subtype))));
|
||||
boost::algorithm::replace_first(text, "%d", boost::lexical_cast<std::string>(valOfBonuses(Selector::typeSubtype(bonus->type, bonus->subtype))));
|
||||
break;
|
||||
//Complex descriptions
|
||||
case Bonus::SECONDARY_SKILL_PREMY: //only if there's no simple MR
|
||||
@ -615,12 +615,12 @@ std::string CStackInstance::bonusToString(Bonus *bonus, bool description) const
|
||||
boost::algorithm::replace_first(text, "%d", boost::lexical_cast<std::string>( magicResistance() ));
|
||||
break;
|
||||
case Bonus::HATE:
|
||||
boost::algorithm::replace_first(text, "%d", boost::lexical_cast<std::string>(valOfBonuses(Selector::typeSybtype(bonus->type, bonus->subtype))));
|
||||
boost::algorithm::replace_first(text, "%d", boost::lexical_cast<std::string>(valOfBonuses(Selector::typeSubtype(bonus->type, bonus->subtype))));
|
||||
boost::algorithm::replace_first(text, "%s", VLC->creh->creatures[bonus->subtype]->namePl);
|
||||
break;
|
||||
case Bonus::SPELL_AFTER_ATTACK:
|
||||
{
|
||||
boost::algorithm::replace_first(text, "%d", boost::lexical_cast<std::string>(valOfBonuses(Selector::typeSybtype(bonus->type, bonus->subtype))));
|
||||
boost::algorithm::replace_first(text, "%d", boost::lexical_cast<std::string>(valOfBonuses(Selector::typeSubtype(bonus->type, bonus->subtype))));
|
||||
boost::algorithm::replace_first(text, "%s", VLC->spellh->spells[bonus->subtype]->name);
|
||||
break;
|
||||
}
|
||||
@ -639,7 +639,7 @@ std::string CStackInstance::bonusToString(Bonus *bonus, bool description) const
|
||||
case Bonus::CHANGES_SPELL_COST_FOR_ENEMY:
|
||||
case Bonus::ENEMY_DEFENCE_REDUCTION:
|
||||
case Bonus::DEATH_STARE:
|
||||
boost::algorithm::replace_first(text, "%d", boost::lexical_cast<std::string>(valOfBonuses(Selector::typeSybtype(bonus->type, bonus->subtype))));
|
||||
boost::algorithm::replace_first(text, "%d", boost::lexical_cast<std::string>(valOfBonuses(Selector::typeSubtype(bonus->type, bonus->subtype))));
|
||||
break;
|
||||
case Bonus::HATE:
|
||||
boost::algorithm::replace_first(text, "%s", VLC->creh->creatures[bonus->subtype]->namePl);
|
||||
|
@ -1678,7 +1678,7 @@ UpgradeInfo CGameState::getUpgradeInfo(const CStackInstance &stack)
|
||||
t = static_cast<const CGTownInstance *>(stack.armyObj);
|
||||
else if(h)
|
||||
{ //hero speciality
|
||||
BonusList lista = h->speciality.getBonuses(Selector::typeSybtype(Bonus::SPECIAL_UPGRADE, base->idNumber));
|
||||
BonusList lista = h->speciality.getBonuses(Selector::typeSubtype(Bonus::SPECIAL_UPGRADE, base->idNumber));
|
||||
BOOST_FOREACH(const Bonus *it, lista)
|
||||
{
|
||||
ui16 nid = it->additionalInfo;
|
||||
@ -1813,7 +1813,7 @@ int CGameState::getMovementCost(const CGHeroInstance *h, const int3 &src, const
|
||||
|
||||
if(d.blocked && h->hasBonusOfType(Bonus::FLYING_MOVEMENT))
|
||||
{
|
||||
bool freeFlying = h->getBonusesCount(Selector::typeSybtype(Bonus::FLYING_MOVEMENT, 1)) > 0;
|
||||
bool freeFlying = h->getBonusesCount(Selector::typeSubtype(Bonus::FLYING_MOVEMENT, 1)) > 0;
|
||||
|
||||
if(!freeFlying)
|
||||
{
|
||||
@ -1824,7 +1824,7 @@ int CGameState::getMovementCost(const CGHeroInstance *h, const int3 &src, const
|
||||
{
|
||||
if(h->boat && s.siodmyTajemniczyBajt & 128 && d.siodmyTajemniczyBajt & 128) //Favourable Winds
|
||||
ret *= 0.666f;
|
||||
else if (!h->boat && h->getBonusesCount(Selector::typeSybtype(Bonus::WATER_WALKING, 1)) > 0)
|
||||
else if (!h->boat && h->getBonusesCount(Selector::typeSubtype(Bonus::WATER_WALKING, 1)) > 0)
|
||||
ret *= 1.4f; //40% penalty for water walking
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,6 @@
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/random/linear_congruential.hpp>
|
||||
#include "CTownHandler.h"
|
||||
#include "CArtHandler.h"
|
||||
#include "CCreatureHandler.h"
|
||||
#include "VCMI_Lib.h"
|
||||
#include "IGameCallback.h"
|
||||
@ -1229,7 +1228,7 @@ void CGHeroInstance::updateSkill(int which, int val)
|
||||
|
||||
|
||||
int skillValType = skillVal ? Bonus::BASE_NUMBER : Bonus::INDEPENDENT_MIN;
|
||||
if(Bonus * b = bonuses.getFirst(Selector::typeSybtype(Bonus::SECONDARY_SKILL_PREMY, which) && Selector::sourceType(Bonus::SECONDARY_SKILL))) //only local hero bonus
|
||||
if(Bonus * b = bonuses.getFirst(Selector::typeSubtype(Bonus::SECONDARY_SKILL_PREMY, which) && Selector::sourceType(Bonus::SECONDARY_SKILL))) //only local hero bonus
|
||||
{
|
||||
b->val = skillVal;
|
||||
b->valType = skillValType;
|
||||
@ -7054,136 +7053,3 @@ void CGUniversity::onHeroVisit(const CGHeroInstance * h) const
|
||||
ow.window = OpenWindow::UNIVERSITY_WINDOW;
|
||||
cb->sendAndApply(&ow);
|
||||
}
|
||||
|
||||
const CArtifactInstance* CArtifactSet::getArt(ui16 pos, bool excludeLocked /*= true*/) const
|
||||
{
|
||||
if(const ArtSlotInfo *si = getSlot(pos))
|
||||
{
|
||||
if(si->artifact && (!excludeLocked || !si->locked))
|
||||
return si->artifact;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CArtifactInstance* CArtifactSet::getArt(ui16 pos, bool excludeLocked /*= true*/)
|
||||
{
|
||||
return const_cast<CArtifactInstance*>((const_cast<const CArtifactSet*>(this))->getArt(pos, excludeLocked));
|
||||
}
|
||||
|
||||
si32 CArtifactSet::getArtPos(int aid, bool onlyWorn /*= true*/) const
|
||||
{
|
||||
for(std::map<ui16, ArtSlotInfo>::const_iterator i = artifactsWorn.begin(); i != artifactsWorn.end(); i++)
|
||||
if(i->second.artifact->artType->id == aid)
|
||||
return i->first;
|
||||
|
||||
if(onlyWorn)
|
||||
return -1;
|
||||
|
||||
for(int i = 0; i < artifactsInBackpack.size(); i++)
|
||||
if(artifactsInBackpack[i].artifact->artType->id == aid)
|
||||
return Arts::BACKPACK_START + i;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
si32 CArtifactSet::getArtPos(const CArtifactInstance *art) const
|
||||
{
|
||||
for(std::map<ui16, ArtSlotInfo>::const_iterator i = artifactsWorn.begin(); i != artifactsWorn.end(); i++)
|
||||
if(i->second.artifact == art)
|
||||
return i->first;
|
||||
|
||||
for(int i = 0; i < artifactsInBackpack.size(); i++)
|
||||
if(artifactsInBackpack[i].artifact == art)
|
||||
return Arts::BACKPACK_START + i;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
const CArtifactInstance * CArtifactSet::getArtByInstanceId(int artInstId) const
|
||||
{
|
||||
for(std::map<ui16, ArtSlotInfo>::const_iterator i = artifactsWorn.begin(); i != artifactsWorn.end(); i++)
|
||||
if(i->second.artifact->id == artInstId)
|
||||
return i->second.artifact;
|
||||
|
||||
for(int i = 0; i < artifactsInBackpack.size(); i++)
|
||||
if(artifactsInBackpack[i].artifact->id == artInstId)
|
||||
return artifactsInBackpack[i].artifact;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool CArtifactSet::hasArt(ui32 aid, bool onlyWorn /*= false*/) const
|
||||
{
|
||||
return getArtPos(aid, onlyWorn) != -1;
|
||||
}
|
||||
|
||||
const ArtSlotInfo * CArtifactSet::getSlot(ui16 pos) const
|
||||
{
|
||||
if(vstd::contains(artifactsWorn, pos))
|
||||
return &artifactsWorn[pos];
|
||||
if(pos >= Arts::AFTER_LAST )
|
||||
{
|
||||
int backpackPos = (int)pos - Arts::BACKPACK_START;
|
||||
if(backpackPos < 0 || backpackPos >= artifactsInBackpack.size())
|
||||
return NULL;
|
||||
else
|
||||
return &artifactsInBackpack[backpackPos];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool CArtifactSet::isPositionFree(ui16 pos, bool onlyLockCheck /*= false*/) const
|
||||
{
|
||||
if(const ArtSlotInfo *s = getSlot(pos))
|
||||
return (onlyLockCheck || !s->artifact) && !s->locked;
|
||||
|
||||
return true; //no slot means not used
|
||||
}
|
||||
|
||||
si32 CArtifactSet::getArtTypeId(ui16 pos) const
|
||||
{
|
||||
const CArtifactInstance * const a = getArt(pos);
|
||||
if(!a)
|
||||
{
|
||||
tlog2 << (dynamic_cast<const CGHeroInstance*>(this))->name << " has no artifact at " << pos << " (getArtTypeId)\n";
|
||||
return -1;
|
||||
}
|
||||
return a->artType->id;
|
||||
}
|
||||
|
||||
CArtifactSet::~CArtifactSet()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ArtSlotInfo & CArtifactSet::retreiveNewArtSlot(ui16 slot)
|
||||
{
|
||||
assert(!vstd::contains(artifactsWorn, slot));
|
||||
ArtSlotInfo &ret = slot < Arts::BACKPACK_START
|
||||
? artifactsWorn[slot]
|
||||
: *artifactsInBackpack.insert(artifactsInBackpack.begin() + (slot - Arts::BACKPACK_START), ArtSlotInfo());
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void CArtifactSet::setNewArtSlot(ui16 slot, CArtifactInstance *art, bool locked)
|
||||
{
|
||||
ArtSlotInfo &asi = retreiveNewArtSlot(slot);
|
||||
asi.artifact = art;
|
||||
asi.locked = locked;
|
||||
}
|
||||
|
||||
void CArtifactSet::eraseArtSlot(ui16 slot)
|
||||
{
|
||||
if(slot < Arts::BACKPACK_START)
|
||||
{
|
||||
artifactsWorn.erase(slot);
|
||||
}
|
||||
else
|
||||
{
|
||||
slot -= Arts::BACKPACK_START;
|
||||
artifactsInBackpack.erase(artifactsInBackpack.begin() + slot);
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "../lib/VCMI_Lib.h"
|
||||
#endif
|
||||
#include "../lib/CCreatureSet.h"
|
||||
#include "CArtHandler.h"
|
||||
#include "../lib/ConstTransitivePtr.h"
|
||||
#include <boost/unordered_set.hpp>
|
||||
|
||||
@ -53,6 +54,7 @@ struct BankConfig;
|
||||
struct UpdateHeroSpeciality;
|
||||
struct NewArtifact;
|
||||
class CGBoat;
|
||||
class CArtifactSet;
|
||||
|
||||
class DLL_EXPORT CQuest
|
||||
{
|
||||
@ -248,50 +250,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
struct DLL_EXPORT ArtSlotInfo
|
||||
{
|
||||
ConstTransitivePtr<CArtifactInstance> artifact;
|
||||
ui8 locked; //if locked, then artifact points to the combined artifact
|
||||
|
||||
ArtSlotInfo()
|
||||
{
|
||||
locked = false;
|
||||
}
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & artifact & locked;
|
||||
}
|
||||
};
|
||||
|
||||
class DLL_EXPORT CArtifactSet
|
||||
{
|
||||
public:
|
||||
std::vector<ArtSlotInfo> artifactsInBackpack; //hero's artifacts from bag
|
||||
bmap<ui16, ArtSlotInfo> artifactsWorn; //map<position,artifact_id>; positions: 0 - head; 1 - shoulders; 2 - neck; 3 - right hand; 4 - left hand; 5 - torso; 6 - right ring; 7 - left ring; 8 - feet; 9 - misc1; 10 - misc2; 11 - misc3; 12 - misc4; 13 - mach1; 14 - mach2; 15 - mach3; 16 - mach4; 17 - spellbook; 18 - misc5
|
||||
|
||||
ArtSlotInfo &retreiveNewArtSlot(ui16 slot);
|
||||
void setNewArtSlot(ui16 slot, CArtifactInstance *art, bool locked);
|
||||
void eraseArtSlot(ui16 slot);
|
||||
|
||||
const ArtSlotInfo *getSlot(ui16 pos) const;
|
||||
const CArtifactInstance* getArt(ui16 pos, bool excludeLocked = true) const; //NULL - no artifact
|
||||
CArtifactInstance* getArt(ui16 pos, bool excludeLocked = true); //NULL - no artifact
|
||||
si32 getArtPos(int aid, bool onlyWorn = true) const; //looks for equipped artifact with given ID and returns its slot ID or -1 if none(if more than one such artifact lower ID is returned)
|
||||
si32 getArtPos(const CArtifactInstance *art) const;
|
||||
const CArtifactInstance *getArtByInstanceId(int artInstId) const;
|
||||
bool hasArt(ui32 aid, bool onlyWorn = false) const; //checks if hero possess artifact of given id (either in backack or worn)
|
||||
bool isPositionFree(ui16 pos, bool onlyLockCheck = false) const;
|
||||
si32 getArtTypeId(ui16 pos) const;
|
||||
|
||||
|
||||
virtual ~CArtifactSet();
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & artifactsInBackpack & artifactsWorn;
|
||||
}
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGHeroInstance : public CArmedInstance, public IBoatGenerator, public CArtifactSet
|
||||
{
|
||||
public:
|
||||
|
@ -176,7 +176,7 @@ bool IBonusBearer::hasBonusOfType(Bonus::BonusType type, int subtype /*= -1*/) c
|
||||
|
||||
void IBonusBearer::getModifiersWDescr(TModDescr &out, Bonus::BonusType type, int subtype /*= -1 */) const
|
||||
{
|
||||
getModifiersWDescr(out, subtype != -1 ? Selector::typeSybtype(type, subtype) : Selector::type(type));
|
||||
getModifiersWDescr(out, subtype != -1 ? Selector::typeSubtype(type, subtype) : Selector::type(type));
|
||||
}
|
||||
|
||||
void IBonusBearer::getModifiersWDescr(TModDescr &out, const CSelector &selector) const
|
||||
@ -294,11 +294,11 @@ ui16 IBonusBearer::MaxHealth() const
|
||||
|
||||
ui32 IBonusBearer::getMinDamage() const
|
||||
{
|
||||
return valOfBonuses(Selector::typeSybtype(Bonus::CREATURE_DAMAGE, 0) || Selector::typeSybtype(Bonus::CREATURE_DAMAGE, 1));
|
||||
return valOfBonuses(Selector::typeSubtype(Bonus::CREATURE_DAMAGE, 0) || Selector::typeSubtype(Bonus::CREATURE_DAMAGE, 1));
|
||||
}
|
||||
ui32 IBonusBearer::getMaxDamage() const
|
||||
{
|
||||
return valOfBonuses(Selector::typeSybtype(Bonus::CREATURE_DAMAGE, 0) || Selector::typeSybtype(Bonus::CREATURE_DAMAGE, 2));
|
||||
return valOfBonuses(Selector::typeSubtype(Bonus::CREATURE_DAMAGE, 0) || Selector::typeSubtype(Bonus::CREATURE_DAMAGE, 2));
|
||||
}
|
||||
|
||||
si32 IBonusBearer::manaLimit() const
|
||||
@ -761,12 +761,12 @@ namespace Selector
|
||||
DLL_EXPORT CSelectFieldEqual<ui8> effectRange(&Bonus::effectRange, Bonus::NO_LIMIT);
|
||||
DLL_EXPORT CWillLastTurns turns;
|
||||
|
||||
CSelector DLL_EXPORT typeSybtype(TBonusType Type, TBonusSubtype Subtype)
|
||||
CSelector DLL_EXPORT typeSubtype(TBonusType Type, TBonusSubtype Subtype)
|
||||
{
|
||||
return type(Type) && subtype(Subtype);
|
||||
}
|
||||
|
||||
CSelector DLL_EXPORT typeSybtypeInfo(TBonusType type, TBonusSubtype subtype, si32 info)
|
||||
CSelector DLL_EXPORT typeSubtypeInfo(TBonusType type, TBonusSubtype subtype, si32 info)
|
||||
{
|
||||
return CSelectFieldEqual<TBonusType>(&Bonus::type, type) && CSelectFieldEqual<TBonusSubtype>(&Bonus::subtype, subtype) && CSelectFieldEqual<si32>(&Bonus::additionalInfo, info);
|
||||
}
|
||||
|
@ -712,8 +712,8 @@ namespace Selector
|
||||
extern DLL_EXPORT CSelectFieldEqual<ui8> effectRange;
|
||||
extern DLL_EXPORT CWillLastTurns turns;
|
||||
|
||||
CSelector DLL_EXPORT typeSybtype(TBonusType Type, TBonusSubtype Subtype);
|
||||
CSelector DLL_EXPORT typeSybtypeInfo(TBonusType type, TBonusSubtype subtype, si32 info);
|
||||
CSelector DLL_EXPORT typeSubtype(TBonusType Type, TBonusSubtype Subtype);
|
||||
CSelector DLL_EXPORT typeSubtypeInfo(TBonusType type, TBonusSubtype subtype, si32 info);
|
||||
CSelector DLL_EXPORT source(ui8 source, ui32 sourceID);
|
||||
CSelector DLL_EXPORT durationType(ui16 duration);
|
||||
CSelector DLL_EXPORT sourceTypeSel(ui8 source);
|
||||
|
@ -1206,7 +1206,7 @@ DLL_EXPORT void SetStackEffect::applyGs( CGameState *gs )
|
||||
CStack *s = gs->curB->getStack(para.first);
|
||||
if (s)
|
||||
{
|
||||
if (!s->hasBonus(Selector::source(Bonus::SPELL_EFFECT, spellid) && Selector::typeSybtype(para.second.type, para.second.subtype)))
|
||||
if (!s->hasBonus(Selector::source(Bonus::SPELL_EFFECT, spellid) && Selector::typeSubtype(para.second.type, para.second.subtype)))
|
||||
s->addNewBonus(new Bonus(para.second));
|
||||
else
|
||||
actualizeEffect(s, effect);
|
||||
|
@ -981,6 +981,8 @@ void Mapa::readHeader( const unsigned char * bufor, int &i)
|
||||
allowedArtifact[artifact->id] = false;
|
||||
}
|
||||
}
|
||||
if (version = RoE)
|
||||
allowedArtifact[128] = false; //Armageddon's Blade
|
||||
}
|
||||
|
||||
allowedSpell.resize(SPELLS_QUANTITY);
|
||||
|
@ -867,7 +867,7 @@ void CGameHandler::newTurn()
|
||||
else if(i->first >= PLAYER_LIMIT)
|
||||
assert(0); //illegal player number!
|
||||
|
||||
std::pair<ui8,si32> playerGold(i->first,i->second.resources[6]);
|
||||
std::pair<ui8,si32> playerGold(i->first,i->second.resources[Res::GOLD]);
|
||||
hadGold.insert(playerGold);
|
||||
|
||||
if(gs->getDate(1)==7) //first day of week - new heroes in tavern
|
||||
@ -916,7 +916,7 @@ void CGameHandler::newTurn()
|
||||
|
||||
if(gs->day) //not first day
|
||||
{
|
||||
n.res[i->first][6] += h->valOfBonuses(Selector::typeSybtype(Bonus::SECONDARY_SKILL, 13)); //estates
|
||||
n.res[i->first][Res::GOLD] += h->valOfBonuses(Selector::typeSubtype(Bonus::SECONDARY_SKILL, CGHeroInstance::ESTATES)); //estates
|
||||
|
||||
for (int k = 0; k < RESOURCE_QUANTITY; k++)
|
||||
{
|
||||
@ -938,7 +938,7 @@ void CGameHandler::newTurn()
|
||||
setPortalDwelling(*j, true, (n.specialWeek == NewTurn::PLAGUE ? true : false)); //set creatures for Portal of Summoning
|
||||
|
||||
if ((**j).subID == 1 && gs->getDate(0) && player < PLAYER_LIMIT && vstd::contains((**j).builtBuildings, 22))//dwarven treasury
|
||||
n.res[player][6] += hadGold[player]/10; //give 10% of starting gold
|
||||
n.res[player][Res::GOLD] += hadGold[player]/10; //give 10% of starting gold
|
||||
}
|
||||
if(gs->day && player < PLAYER_LIMIT)//not the first day and town not neutral
|
||||
{
|
||||
@ -948,8 +948,8 @@ void CGameHandler::newTurn()
|
||||
{
|
||||
if((**j).town->primaryRes == 127) //we'll give wood and ore
|
||||
{
|
||||
n.res[player][0] += 1;
|
||||
n.res[player][2] += 1;
|
||||
n.res[player][Res::WOOD] += 1;
|
||||
n.res[player][Res::ORE] += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -3498,7 +3498,7 @@ void CGameHandler::handleSpellCasting( int spellID, int spellLvl, int destinatio
|
||||
CStack::stackEffectToFeature(sse.effect, pseudoBonus);
|
||||
const Bonus * bonus = NULL;
|
||||
if (caster)
|
||||
bonus = caster->getBonus(Selector::typeSybtype(Bonus::SPECIAL_PECULIAR_ENCHANT, spellID));
|
||||
bonus = caster->getBonus(Selector::typeSubtype(Bonus::SPECIAL_PECULIAR_ENCHANT, spellID));
|
||||
|
||||
si32 power = 0;
|
||||
for(std::set<CStack*>::iterator it = attackedCres.begin(); it != attackedCres.end(); ++it)
|
||||
@ -4285,14 +4285,14 @@ void CGameHandler::handleAfterAttackCasting( const BattleAttack & bat )
|
||||
if(oneOfAttacked == NULL) //all attacked creatures have been killed
|
||||
return;
|
||||
int spellLevel = 0;
|
||||
BOOST_FOREACH(const Bonus *sf, attacker->getBonuses(Selector::typeSybtype(Bonus::SPELL_AFTER_ATTACK, spellID)))
|
||||
BOOST_FOREACH(const Bonus *sf, attacker->getBonuses(Selector::typeSubtype(Bonus::SPELL_AFTER_ATTACK, spellID)))
|
||||
{
|
||||
amax(spellLevel, sf->additionalInfo % 1000); //pick highest level
|
||||
meleeRanged = sf->additionalInfo / 1000;
|
||||
if (meleeRanged == 0 || (meleeRanged == 1 && bat.shot()) || (meleeRanged == 2 && !bat.shot()))
|
||||
castMe = true;
|
||||
}
|
||||
int chance = attacker->valOfBonuses((Selector::typeSybtype(Bonus::SPELL_AFTER_ATTACK, spellID)));
|
||||
int chance = attacker->valOfBonuses((Selector::typeSubtype(Bonus::SPELL_AFTER_ATTACK, spellID)));
|
||||
amin (chance, 100);
|
||||
int destination = oneOfAttacked->position;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user