mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
CArtifact getters setters
This commit is contained in:
parent
fd9c7352a0
commit
9b5f6ec7cf
@ -1000,7 +1000,7 @@ void AIGateway::pickBestArtifacts(const CGHeroInstance * h, const CGHeroInstance
|
||||
//FIXME: why are the above possible to be null?
|
||||
|
||||
bool emptySlotFound = false;
|
||||
for(auto slot : artifact->artType->possibleSlots.at(target->bearerType()))
|
||||
for(auto slot : artifact->artType->getPossibleSlots().at(target->bearerType()))
|
||||
{
|
||||
ArtifactLocation destLocation(target, slot);
|
||||
if(target->isPositionFree(slot) && artifact->canBePutAt(destLocation, true)) //combined artifacts are not always allowed to move
|
||||
@ -1013,7 +1013,7 @@ void AIGateway::pickBestArtifacts(const CGHeroInstance * h, const CGHeroInstance
|
||||
}
|
||||
if(!emptySlotFound) //try to put that atifact in already occupied slot
|
||||
{
|
||||
for(auto slot : artifact->artType->possibleSlots.at(target->bearerType()))
|
||||
for(auto slot : artifact->artType->getPossibleSlots().at(target->bearerType()))
|
||||
{
|
||||
auto otherSlot = target->getSlot(slot);
|
||||
if(otherSlot && otherSlot->artifact) //we need to exchange artifact for better one
|
||||
|
@ -306,10 +306,10 @@ bool compareArtifacts(const CArtifactInstance * a1, const CArtifactInstance * a2
|
||||
auto art1 = a1->artType;
|
||||
auto art2 = a2->artType;
|
||||
|
||||
if(art1->price == art2->price)
|
||||
if(art1->getPrice() == art2->getPrice())
|
||||
return art1->valOfBonuses(BonusType::PRIMARY_SKILL) > art2->valOfBonuses(BonusType::PRIMARY_SKILL);
|
||||
else
|
||||
return art1->price > art2->price;
|
||||
return art1->getPrice() > art2->getPrice();
|
||||
}
|
||||
|
||||
bool isWeeklyRevisitable(const CGObjectInstance * obj)
|
||||
|
@ -256,8 +256,8 @@ bool compareArtifacts(const CArtifactInstance * a1, const CArtifactInstance * a2
|
||||
auto art1 = a1->artType;
|
||||
auto art2 = a2->artType;
|
||||
|
||||
if(art1->price == art2->price)
|
||||
if(art1->getPrice() == art2->getPrice())
|
||||
return art1->valOfBonuses(BonusType::PRIMARY_SKILL) > art2->valOfBonuses(BonusType::PRIMARY_SKILL);
|
||||
else
|
||||
return art1->price > art2->price;
|
||||
return art1->getPrice() > art2->getPrice();
|
||||
}
|
||||
|
@ -1187,7 +1187,7 @@ void VCAI::pickBestArtifacts(const CGHeroInstance * h, const CGHeroInstance * ot
|
||||
//FIXME: why are the above possible to be null?
|
||||
|
||||
bool emptySlotFound = false;
|
||||
for(auto slot : artifact->artType->possibleSlots.at(target->bearerType()))
|
||||
for(auto slot : artifact->artType->getPossibleSlots().at(target->bearerType()))
|
||||
{
|
||||
ArtifactLocation destLocation(target, slot);
|
||||
if(target->isPositionFree(slot) && artifact->canBePutAt(destLocation, true)) //combined artifacts are not always allowed to move
|
||||
@ -1200,7 +1200,7 @@ void VCAI::pickBestArtifacts(const CGHeroInstance * h, const CGHeroInstance * ot
|
||||
}
|
||||
if(!emptySlotFound) //try to put that atifact in already occupied slot
|
||||
{
|
||||
for(auto slot : artifact->artType->possibleSlots.at(target->bearerType()))
|
||||
for(auto slot : artifact->artType->getPossibleSlots().at(target->bearerType()))
|
||||
{
|
||||
auto otherSlot = target->getSlot(slot);
|
||||
if(otherSlot && otherSlot->artifact) //we need to exchange artifact for better one
|
||||
|
@ -800,7 +800,7 @@ void CCastleBuildings::enterBlacksmith(ArtifactID artifactID)
|
||||
bool possible = LOCPLINT->cb->getResourceAmount(EGameResID::GOLD) >= price;
|
||||
if(possible)
|
||||
{
|
||||
for(auto slot : art->possibleSlots.at(ArtBearer::HERO))
|
||||
for(auto slot : art->getPossibleSlots().at(ArtBearer::HERO))
|
||||
{
|
||||
if(hero->getArt(slot) == nullptr)
|
||||
{
|
||||
|
@ -588,7 +588,7 @@ CStackWindow::MainSection::MainSection(CStackWindow * owner, int yOffset, bool s
|
||||
auto art = parent->info->stackNode->getArt(ArtifactPosition::CREATURE_SLOT);
|
||||
if(art)
|
||||
{
|
||||
parent->stackArtifactIcon = std::make_shared<CAnimImage>("ARTIFACT", art->artType->iconIndex, 0, pos.x, pos.y);
|
||||
parent->stackArtifactIcon = std::make_shared<CAnimImage>("ARTIFACT", art->artType->getIconIndex(), 0, pos.x, pos.y);
|
||||
parent->stackArtifactHelp = std::make_shared<LRClickableAreaWTextComp>(Rect(pos, Point(44, 44)), CComponent::artifact);
|
||||
parent->stackArtifactHelp->type = art->artType->getId();
|
||||
|
||||
|
@ -803,7 +803,7 @@ void CMarketplaceWindow::makeDeal()
|
||||
leftIdToSend = hLeft->serial;
|
||||
break;
|
||||
case EMarketMode::ARTIFACT_RESOURCE:
|
||||
leftIdToSend = hLeft->getArtInstance()->id.getNum();
|
||||
leftIdToSend = hLeft->getArtInstance()->getId().getNum();
|
||||
break;
|
||||
case EMarketMode::RESOURCE_ARTIFACT:
|
||||
if(!ArtifactID(hRight->id).toArtifact()->canBePutAt(hero))
|
||||
|
@ -22,7 +22,7 @@ VCMI_LIB_NAMESPACE_BEGIN
|
||||
DLL_LINKAGE ArtifactPosition ArtifactUtils::getArtAnyPosition(const CArtifactSet * target, const ArtifactID & aid)
|
||||
{
|
||||
const auto * art = aid.toArtifact();
|
||||
for(const auto & slot : art->possibleSlots.at(target->bearerType()))
|
||||
for(const auto & slot : art->getPossibleSlots().at(target->bearerType()))
|
||||
{
|
||||
if(art->canBePutAt(target, slot))
|
||||
return slot;
|
||||
|
@ -51,21 +51,11 @@ bool CCombinedArtifact::isCombined() const
|
||||
return !(constituents.empty());
|
||||
}
|
||||
|
||||
std::vector<CArtifact*> & CCombinedArtifact::getConstituents()
|
||||
{
|
||||
return constituents;
|
||||
}
|
||||
|
||||
const std::vector<CArtifact*> & CCombinedArtifact::getConstituents() const
|
||||
{
|
||||
return constituents;
|
||||
}
|
||||
|
||||
std::vector<CArtifact*> & CCombinedArtifact::getPartOf()
|
||||
{
|
||||
return partOf;
|
||||
}
|
||||
|
||||
const std::vector<CArtifact*> & CCombinedArtifact::getPartOf() const
|
||||
{
|
||||
return partOf;
|
||||
@ -263,6 +253,8 @@ bool CArtifact::canBePutAt(const CArtifactSet * artSet, ArtifactPosition slot, b
|
||||
}
|
||||
|
||||
CArtifact::CArtifact()
|
||||
: iconIndex(ArtifactID::NONE),
|
||||
price(0)
|
||||
{
|
||||
setNodeType(ARTIFACT);
|
||||
possibleSlots[ArtBearer::HERO]; //we want to generate map entry even if it will be empty
|
||||
@ -307,14 +299,21 @@ void CArtifact::addNewBonus(const std::shared_ptr<Bonus>& b)
|
||||
CBonusSystemNode::addNewBonus(b);
|
||||
}
|
||||
|
||||
const std::map<ArtBearer::ArtBearer, std::vector<ArtifactPosition>> & CArtifact::getPossibleSlots() const
|
||||
{
|
||||
return possibleSlots;
|
||||
}
|
||||
|
||||
void CArtifact::updateFrom(const JsonNode& data)
|
||||
{
|
||||
//TODO:CArtifact::updateFrom
|
||||
}
|
||||
|
||||
void CArtifact::serializeJson(JsonSerializeFormat & handler)
|
||||
void CArtifact::setImage(int32_t iconIndex, std::string image, std::string large)
|
||||
{
|
||||
|
||||
this->iconIndex = iconIndex;
|
||||
this->image = image;
|
||||
this->large = large;
|
||||
}
|
||||
|
||||
CArtHandler::~CArtHandler() = default;
|
||||
@ -876,11 +875,11 @@ ArtifactPosition CArtifactSet::getArtPos(const CArtifactInstance *art) const
|
||||
const CArtifactInstance * CArtifactSet::getArtByInstanceId(const ArtifactInstanceID & artInstId) const
|
||||
{
|
||||
for(auto i : artifactsWorn)
|
||||
if(i.second.artifact->id == artInstId)
|
||||
if(i.second.artifact->getId() == artInstId)
|
||||
return i.second.artifact;
|
||||
|
||||
for(auto i : artifactsInBackpack)
|
||||
if(i.artifact->id == artInstId)
|
||||
if(i.artifact->getId() == artInstId)
|
||||
return i.artifact;
|
||||
|
||||
return nullptr;
|
||||
@ -890,7 +889,7 @@ const ArtifactPosition CArtifactSet::getSlotByInstance(const CArtifactInstance *
|
||||
{
|
||||
if(artInst)
|
||||
{
|
||||
for(auto & slot : artInst->artType->possibleSlots.at(bearerType()))
|
||||
for(const auto & slot : artInst->artType->getPossibleSlots().at(bearerType()))
|
||||
if(getArt(slot) == artInst)
|
||||
return slot;
|
||||
|
||||
@ -934,7 +933,7 @@ void CArtifactSet::putArtifact(ArtifactPosition slot, CArtifactInstance * art)
|
||||
{
|
||||
const CArtifactInstance * mainPart = nullptr;
|
||||
for(const auto & part : art->getPartsInfo())
|
||||
if(vstd::contains(part.art->artType->possibleSlots.at(bearerType()), slot)
|
||||
if(vstd::contains(part.art->artType->getPossibleSlots().at(bearerType()), slot)
|
||||
&& (part.slot == ArtifactPosition::PRE_FIRST))
|
||||
{
|
||||
mainPart = part.art;
|
||||
|
@ -51,9 +51,7 @@ protected:
|
||||
std::vector<CArtifact*> partOf; // Reverse map of constituents - combined arts that include this art
|
||||
public:
|
||||
bool isCombined() const;
|
||||
std::vector<CArtifact*> & getConstituents();
|
||||
const std::vector<CArtifact*> & getConstituents() const;
|
||||
std::vector<CArtifact*> & getPartOf();
|
||||
const std::vector<CArtifact*> & getPartOf() const;
|
||||
|
||||
template <typename Handler> void serialize(Handler & h, const int version)
|
||||
@ -98,21 +96,21 @@ class DLL_LINKAGE CArtifact
|
||||
: public Artifact, public CBonusSystemNode, public CCombinedArtifact, public CScrollArtifact, public CGrowingArtifact
|
||||
{
|
||||
ArtifactID id;
|
||||
|
||||
std::string image;
|
||||
std::string large; // big image for custom artifacts, used in drag & drop
|
||||
std::string advMapDef; // used for adventure map object
|
||||
std::string modScope;
|
||||
std::string identifier;
|
||||
int32_t iconIndex;
|
||||
uint32_t price;
|
||||
CreatureID warMachine;
|
||||
// Bearer Type => ids of slots where artifact can be placed
|
||||
std::map<ArtBearer::ArtBearer, std::vector<ArtifactPosition>> possibleSlots;
|
||||
|
||||
public:
|
||||
enum EartClass {ART_SPECIAL=1, ART_TREASURE=2, ART_MINOR=4, ART_MAJOR=8, ART_RELIC=16}; //artifact classes
|
||||
|
||||
std::string image;
|
||||
std::string large; // big image for custom artifacts, used in drag & drop
|
||||
std::string advMapDef; //used for adventure map object
|
||||
si32 iconIndex = ArtifactID::NONE;
|
||||
ui32 price = 0;
|
||||
std::map<ArtBearer::ArtBearer, std::vector<ArtifactPosition> > possibleSlots; //Bearer Type => ids of slots where artifact can be placed
|
||||
EartClass aClass = ART_SPECIAL;
|
||||
CreatureID warMachine;
|
||||
|
||||
int32_t getIndex() const override;
|
||||
int32_t getIconIndex() const override;
|
||||
@ -137,11 +135,13 @@ public:
|
||||
int getArtClassSerial() const; //0 - treasure, 1 - minor, 2 - major, 3 - relic, 4 - spell scroll, 5 - other
|
||||
std::string nodeName() const override;
|
||||
void addNewBonus(const std::shared_ptr<Bonus>& b) override;
|
||||
const std::map<ArtBearer::ArtBearer, std::vector<ArtifactPosition>> & getPossibleSlots() const;
|
||||
|
||||
virtual bool canBePutAt(const CArtifactSet * artSet, ArtifactPosition slot = ArtifactPosition::FIRST_AVAILABLE,
|
||||
bool assumeDestRemoved = false) const;
|
||||
void updateFrom(const JsonNode & data);
|
||||
void serializeJson(JsonSerializeFormat & handler);
|
||||
// Is used for testing purposes only
|
||||
void setImage(int32_t iconIndex, std::string image, std::string large);
|
||||
|
||||
template <typename Handler> void serialize(Handler & h, const int version)
|
||||
{
|
||||
|
@ -46,6 +46,7 @@ bool CCombinedArtifactInstance::isPart(const CArtifactInstance * supposedPart) c
|
||||
|
||||
std::vector<CCombinedArtifactInstance::PartInfo> & CCombinedArtifactInstance::getPartsInfo()
|
||||
{
|
||||
// TODO romove this func. encapsulation violation
|
||||
return partsInfo;
|
||||
}
|
||||
|
||||
@ -140,6 +141,16 @@ ArtifactID CArtifactInstance::getTypeId() const
|
||||
return artType->getId();
|
||||
}
|
||||
|
||||
ArtifactInstanceID CArtifactInstance::getId() const
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
void CArtifactInstance::setId(ArtifactInstanceID id)
|
||||
{
|
||||
this->id = id;
|
||||
}
|
||||
|
||||
bool CArtifactInstance::canBePutAt(const ArtifactLocation & al, bool assumeDestRemoved) const
|
||||
{
|
||||
return artType->canBePutAt(al.getHolderArtSet(), al.slot, assumeDestRemoved);
|
||||
|
@ -68,9 +68,10 @@ class DLL_LINKAGE CArtifactInstance
|
||||
{
|
||||
protected:
|
||||
void init();
|
||||
|
||||
ArtifactInstanceID id;
|
||||
public:
|
||||
ConstTransitivePtr<CArtifact> artType;
|
||||
ArtifactInstanceID id;
|
||||
|
||||
CArtifactInstance(CArtifact * art);
|
||||
CArtifactInstance();
|
||||
@ -78,6 +79,8 @@ public:
|
||||
std::string nodeName() const override;
|
||||
std::string getDescription() const;
|
||||
ArtifactID getTypeId() const;
|
||||
ArtifactInstanceID getId() const;
|
||||
void setId(ArtifactInstanceID id);
|
||||
|
||||
bool canBePutAt(const ArtifactLocation & al, bool assumeDestRemoved = false) const;
|
||||
bool isCombined() const;
|
||||
|
@ -206,7 +206,7 @@ namespace JsonRandom
|
||||
{
|
||||
CArtifact * art = VLC->arth->objects[artID];
|
||||
|
||||
if(!vstd::iswithin(art->price, minValue, maxValue))
|
||||
if(!vstd::iswithin(art->getPrice(), minValue, maxValue))
|
||||
return false;
|
||||
|
||||
if(!allowedClasses.empty() && !allowedClasses.count(art->aClass))
|
||||
@ -217,7 +217,7 @@ namespace JsonRandom
|
||||
|
||||
if(!allowedPositions.empty())
|
||||
{
|
||||
for(const auto & pos : art->possibleSlots[ArtBearer::HERO])
|
||||
for(const auto & pos : art->getPossibleSlots().at(ArtBearer::HERO))
|
||||
{
|
||||
if(allowedPositions.count(pos))
|
||||
return true;
|
||||
|
@ -1949,8 +1949,8 @@ void AssembledArtifact::applyGs(CGameState *gs)
|
||||
constituentInstance->removeFrom(ArtifactLocation(al.artHolder, pos));
|
||||
if(combineEquipped)
|
||||
{
|
||||
if(!vstd::contains(combinedArt->artType->possibleSlots[artSet->bearerType()], al.slot)
|
||||
&& vstd::contains(combinedArt->artType->possibleSlots[artSet->bearerType()], pos))
|
||||
if(!vstd::contains(combinedArt->artType->getPossibleSlots().at(artSet->bearerType()), al.slot)
|
||||
&& vstd::contains(combinedArt->artType->getPossibleSlots().at(artSet->bearerType()), pos))
|
||||
al.slot = pos;
|
||||
if(al.slot == pos)
|
||||
pos = ArtifactPosition::PRE_FIRST;
|
||||
|
@ -378,7 +378,7 @@ BattleInfo * BattleInfo::setupBattle(const int3 & tile, TerrainId terrain, const
|
||||
|
||||
if(nullptr != warMachineArt)
|
||||
{
|
||||
CreatureID cre = warMachineArt->artType->warMachine;
|
||||
CreatureID cre = warMachineArt->artType->getWarMachine();
|
||||
|
||||
if(cre != CreatureID::NONE)
|
||||
curB->generateNewStack(curB->nextUnitId(), CStackBasicDescriptor(cre, 1), side, SlotID::WAR_MACHINES_SLOT, hex);
|
||||
|
@ -406,10 +406,10 @@ void CGHeroInstance::initArmy(CRandomGenerator & rand, IArmyDescriptor * dst)
|
||||
ArtifactID aid = creature->warMachine;
|
||||
const CArtifact * art = aid.toArtifact();
|
||||
|
||||
if(art != nullptr && !art->possibleSlots.at(ArtBearer::HERO).empty())
|
||||
if(art != nullptr && !art->getPossibleSlots().at(ArtBearer::HERO).empty())
|
||||
{
|
||||
//TODO: should we try another possible slots?
|
||||
ArtifactPosition slot = art->possibleSlots.at(ArtBearer::HERO).front();
|
||||
ArtifactPosition slot = art->getPossibleSlots().at(ArtBearer::HERO).front();
|
||||
|
||||
if(!getArt(slot))
|
||||
putArtifact(slot, ArtifactUtils::createNewArtifactInstance(aid));
|
||||
|
@ -820,7 +820,7 @@ void CGArtifact::afterAddToMap(CMap * map)
|
||||
//Artifacts from map objects are never removed
|
||||
//FIXME: This should be revertible in map editor
|
||||
|
||||
if(ID == Obj::SPELL_SCROLL && storedArtifact && storedArtifact->id.getNum() < 0)
|
||||
if(ID == Obj::SPELL_SCROLL && storedArtifact && storedArtifact->getId().getNum() < 0)
|
||||
map->addNewArtifactInstance(storedArtifact);
|
||||
}
|
||||
|
||||
|
@ -466,7 +466,7 @@ void CMap::checkForObjectives()
|
||||
|
||||
void CMap::addNewArtifactInstance(CArtifactInstance * art)
|
||||
{
|
||||
art->id = ArtifactInstanceID(static_cast<si32>(artInstances.size()));
|
||||
art->setId(static_cast<ArtifactInstanceID>(artInstances.size()));
|
||||
artInstances.emplace_back(art);
|
||||
}
|
||||
|
||||
@ -474,7 +474,7 @@ void CMap::eraseArtifactInstance(CArtifactInstance * art)
|
||||
{
|
||||
//TODO: handle for artifacts removed in map editor
|
||||
assert(artInstances[art->id.getNum()] == art);
|
||||
artInstances[art->id.getNum()].dellNull();
|
||||
artInstances[art->getId().getNum()].dellNull();
|
||||
}
|
||||
|
||||
void CMap::addNewQuestInstance(CQuest* quest)
|
||||
|
@ -33,7 +33,7 @@ void CSerializer::addStdVecItems(CGameState *gs, LibClasses *lib)
|
||||
registerVectoredType<CArtifact, ArtifactID>(&lib->arth->objects,
|
||||
[](const CArtifact &art){ return art.getId(); });
|
||||
registerVectoredType<CArtifactInstance, ArtifactInstanceID>(&gs->map->artInstances,
|
||||
[](const CArtifactInstance &artInst){ return artInst.id; });
|
||||
[](const CArtifactInstance &artInst){ return artInst.getId(); });
|
||||
registerVectoredType<CQuest, si32>(&gs->map->quests,
|
||||
[](const CQuest &q){ return q.qid; });
|
||||
|
||||
|
@ -140,7 +140,7 @@ std::list<Validator::Issue> Validator::validate(const CMap * map)
|
||||
{
|
||||
if(ins->storedArtifact)
|
||||
{
|
||||
if(!map->allowedSpell[ins->storedArtifact->id.getNum()])
|
||||
if(!map->allowedSpell[ins->storedArtifact->getId().getNum()])
|
||||
issues.emplace_back(QString("Spell scroll %1 is prohibited by map settings").arg(ins->getObjectName().c_str()), false);
|
||||
}
|
||||
else
|
||||
|
@ -4160,9 +4160,9 @@ bool CGameHandler::buyArtifact(ObjectInstanceID hid, ArtifactID aid)
|
||||
{
|
||||
const CArtifact * art = aid.toArtifact();
|
||||
COMPLAIN_RET_FALSE_IF(nullptr == art, "Invalid artifact index to buy");
|
||||
COMPLAIN_RET_FALSE_IF(art->warMachine == CreatureID::NONE, "War machine artifact required");
|
||||
COMPLAIN_RET_FALSE_IF(art->getWarMachine() == CreatureID::NONE, "War machine artifact required");
|
||||
COMPLAIN_RET_FALSE_IF(hero->hasArt(aid),"Hero already has this machine!");
|
||||
const int price = art->price;
|
||||
const int price = art->getPrice();
|
||||
COMPLAIN_RET_FALSE_IF(getPlayerState(hero->getOwner())->resources[EGameResID::GOLD] < price, "Not enough gold!");
|
||||
|
||||
if ((town->hasBuilt(BuildingID::BLACKSMITH) && town->town->warMachine == aid)
|
||||
|
@ -32,9 +32,7 @@ protected:
|
||||
|
||||
TEST_F(CArtifactTest, RegistersIcons)
|
||||
{
|
||||
subject->iconIndex = 4242;
|
||||
subject->image = "Test1";
|
||||
subject->large = "Test2";
|
||||
subject-> setImage(4242, "Test1", "Test2");
|
||||
|
||||
auto cb = [this](auto && PH1, auto && PH2, auto && PH3, auto && PH4)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user