mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
- Mod artifacts can have components
- Mod artifacts can be for commander / stack - Commander / stack artifacts will be automatically disabled from random spawning is related module is disabled
This commit is contained in:
parent
e023b7d6bc
commit
c0e09679f1
@ -437,10 +437,10 @@ CArtifact * CArtHandler::loadArtifact(const JsonNode & node)
|
||||
case ArtBearer::HERO: //TODO: allow arts having several possible bearers
|
||||
break;
|
||||
case ArtBearer::COMMANDER:
|
||||
makeItCommanderArt(art->id); //TODO: when id is deduced?
|
||||
makeItCommanderArt (art, false); //do not erase already existing slots
|
||||
break;
|
||||
case ArtBearer::CREATURE:
|
||||
makeItCreatureArt(art->id);
|
||||
makeItCreatureArt (art, false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -475,6 +475,8 @@ CArtifact * CArtHandler::loadArtifact(const JsonNode & node)
|
||||
}
|
||||
}
|
||||
|
||||
readComponents (node, art);
|
||||
|
||||
BOOST_FOREACH (const JsonNode &bonus, node["bonuses"].Vector())
|
||||
{
|
||||
auto b = JsonUtils::parseBonus(bonus);
|
||||
@ -660,10 +662,8 @@ void CArtHandler::giveArtBonus(TArtifactID aid, Bonus *bonus)
|
||||
|
||||
artifacts[aid]->addNewBonus(bonus);
|
||||
}
|
||||
|
||||
void CArtHandler::makeItCreatureArt (TArtifactInstanceID aid, bool onlyCreature /*=true*/)
|
||||
void CArtHandler::makeItCreatureArt (CArtifact * a, bool onlyCreature /*=true*/)
|
||||
{
|
||||
CArtifact *a = artifacts[aid];
|
||||
if (onlyCreature)
|
||||
{
|
||||
a->possibleSlots[ArtBearer::HERO].clear();
|
||||
@ -672,9 +672,14 @@ void CArtHandler::makeItCreatureArt (TArtifactInstanceID aid, bool onlyCreature
|
||||
a->possibleSlots[ArtBearer::CREATURE].push_back(ArtifactPosition::CREATURE_SLOT);
|
||||
}
|
||||
|
||||
void CArtHandler::makeItCommanderArt( TArtifactInstanceID aid, bool onlyCommander /*= true*/ )
|
||||
void CArtHandler::makeItCreatureArt (TArtifactInstanceID aid, bool onlyCreature /*=true*/)
|
||||
{
|
||||
CArtifact *a = artifacts[aid];
|
||||
makeItCreatureArt (a, onlyCreature);
|
||||
}
|
||||
|
||||
void CArtHandler::makeItCommanderArt (CArtifact * a, bool onlyCommander /*= true*/ )
|
||||
{
|
||||
if (onlyCommander)
|
||||
{
|
||||
a->possibleSlots[ArtBearer::HERO].clear();
|
||||
@ -684,6 +689,12 @@ void CArtHandler::makeItCommanderArt( TArtifactInstanceID aid, bool onlyCommande
|
||||
a->possibleSlots[ArtBearer::COMMANDER].push_back(i);
|
||||
}
|
||||
|
||||
void CArtHandler::makeItCommanderArt( TArtifactInstanceID aid, bool onlyCommander /*= true*/ )
|
||||
{
|
||||
CArtifact *a = artifacts[aid];
|
||||
makeItCommanderArt (a, onlyCommander);
|
||||
}
|
||||
|
||||
void CArtHandler::addBonuses()
|
||||
{
|
||||
const JsonNode config(ResourceID("config/artifacts.json"));
|
||||
@ -702,23 +713,29 @@ void CArtHandler::addBonuses()
|
||||
else if(artifact.second["type"].String() == "Commander")
|
||||
makeItCommanderArt(ga->id);
|
||||
|
||||
const JsonNode *value;
|
||||
value = &artifact.second["components"];
|
||||
if (!value->isNull())
|
||||
{
|
||||
ga->constituents = new std::vector<ui32>();
|
||||
BOOST_FOREACH (auto component, value->Vector())
|
||||
{
|
||||
VLC->modh->identifiers.requestIdentifier(std::string("artifact.") + component.String(),
|
||||
boost::bind (&CArtifact::addConstituent, ga, _1)
|
||||
);
|
||||
}
|
||||
}
|
||||
readComponents (artifact.second, ga);
|
||||
|
||||
VLC->modh->identifiers.registerObject ("artifact." + artifact.first, ga->id);
|
||||
}
|
||||
}
|
||||
|
||||
void CArtHandler::readComponents (const JsonNode & node, CArtifact * art)
|
||||
{
|
||||
const JsonNode *value;
|
||||
value = &node["components"];
|
||||
if (!value->isNull())
|
||||
{
|
||||
art->constituents = new std::vector<ui32>();
|
||||
BOOST_FOREACH (auto component, value->Vector())
|
||||
{
|
||||
VLC->modh->identifiers.requestIdentifier(std::string("artifact.") + component.String(),
|
||||
boost::bind (&CArtifact::addConstituent, art, _1)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CArtHandler::clear()
|
||||
{
|
||||
BOOST_FOREACH(CArtifact *art, artifacts)
|
||||
@ -755,7 +772,15 @@ void CArtHandler::initAllowedArtifactsList(const std::vector<ui8> &allowed)
|
||||
}
|
||||
for (int i = GameConstants::ARTIFACTS_QUANTITY; i < artifacts.size(); ++i) //allow all new artifacts by default
|
||||
{
|
||||
allowedArtifacts.push_back(artifacts[i]);
|
||||
if (artifacts[i]->possibleSlots[ArtBearer::HERO].size())
|
||||
allowedArtifacts.push_back(artifacts[i]);
|
||||
else //check if active modules allow artifact to be every used
|
||||
{
|
||||
if (artifacts[i]->possibleSlots[ArtBearer::COMMANDER].size() && VLC->modh->modules.COMMANDERS ||
|
||||
artifacts[i]->possibleSlots[ArtBearer::CREATURE].size() && VLC->modh->modules.STACK_ARTIFACT)
|
||||
allowedArtifacts.push_back(artifacts[i]);
|
||||
//keep im mind that artifact can be worn by more than one type of bearer
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -234,6 +234,8 @@ public:
|
||||
void load(const JsonNode & node);
|
||||
/// load one artifact from json config
|
||||
CArtifact * loadArtifact(const JsonNode & node);
|
||||
///read (optional) components of combined artifact
|
||||
void readComponents (const JsonNode & node, CArtifact * art);
|
||||
|
||||
void sortArts();
|
||||
void addBonuses();
|
||||
@ -247,7 +249,9 @@ public:
|
||||
bool isBigArtifact (TArtifactID artID) const {return bigArtifacts.find(artID) != bigArtifacts.end();}
|
||||
void initAllowedArtifactsList(const std::vector<ui8> &allowed); //allowed[art_id] -> 0 if not allowed, 1 if allowed
|
||||
static int convertMachineID(int id, bool creToArt);
|
||||
void makeItCreatureArt (CArtifact * a, bool onlyCreature = true);
|
||||
void makeItCreatureArt (TArtifactInstanceID aid, bool onlyCreature = true);
|
||||
void makeItCommanderArt (CArtifact * a, bool onlyCommander = true);
|
||||
void makeItCommanderArt (TArtifactInstanceID aid, bool onlyCommander = true);
|
||||
CArtHandler();
|
||||
~CArtHandler();
|
||||
|
Loading…
Reference in New Issue
Block a user