mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-29 23:07:48 +02:00
Make IObjectInterface::cb non-static
This commit is contained in:
@@ -37,15 +37,16 @@ void CBankInstanceConstructor::initTypeData(const JsonNode & input)
|
||||
BankConfig CBankInstanceConstructor::generateConfig(const JsonNode & level, CRandomGenerator & rng) const
|
||||
{
|
||||
BankConfig bc;
|
||||
JsonRandom randomizer(nullptr);
|
||||
JsonRandom::Variables emptyVariables;
|
||||
|
||||
bc.chance = static_cast<ui32>(level["chance"].Float());
|
||||
bc.guards = JsonRandom::loadCreatures(level["guards"], rng, emptyVariables);
|
||||
bc.guards = randomizer.loadCreatures(level["guards"], rng, emptyVariables);
|
||||
|
||||
bc.resources = ResourceSet(level["reward"]["resources"]);
|
||||
bc.creatures = JsonRandom::loadCreatures(level["reward"]["creatures"], rng, emptyVariables);
|
||||
bc.artifacts = JsonRandom::loadArtifacts(level["reward"]["artifacts"], rng, emptyVariables);
|
||||
bc.spells = JsonRandom::loadSpells(level["reward"]["spells"], rng, emptyVariables);
|
||||
bc.creatures = randomizer.loadCreatures(level["reward"]["creatures"], rng, emptyVariables);
|
||||
bc.artifacts = randomizer.loadArtifacts(level["reward"]["artifacts"], rng, emptyVariables);
|
||||
bc.spells = randomizer.loadSpells(level["reward"]["spells"], rng, emptyVariables);
|
||||
|
||||
return bc;
|
||||
}
|
||||
@@ -82,80 +83,16 @@ CBankInfo::CBankInfo(const JsonVector & Config) :
|
||||
assert(!Config.empty());
|
||||
}
|
||||
|
||||
static void addStackToArmy(IObjectInfo::CArmyStructure & army, const CCreature * crea, si32 amount)
|
||||
{
|
||||
army.totalStrength += crea->getFightValue() * amount;
|
||||
|
||||
bool walker = true;
|
||||
if(crea->hasBonusOfType(BonusType::SHOOTER))
|
||||
{
|
||||
army.shootersStrength += crea->getFightValue() * amount;
|
||||
walker = false;
|
||||
}
|
||||
if(crea->hasBonusOfType(BonusType::FLYING))
|
||||
{
|
||||
army.flyersStrength += crea->getFightValue() * amount;
|
||||
walker = false;
|
||||
}
|
||||
if(walker)
|
||||
army.walkersStrength += crea->getFightValue() * amount;
|
||||
}
|
||||
|
||||
IObjectInfo::CArmyStructure CBankInfo::minGuards() const
|
||||
{
|
||||
JsonRandom::Variables emptyVariables;
|
||||
|
||||
std::vector<IObjectInfo::CArmyStructure> armies;
|
||||
for(auto configEntry : config)
|
||||
{
|
||||
auto stacks = JsonRandom::evaluateCreatures(configEntry["guards"], emptyVariables);
|
||||
IObjectInfo::CArmyStructure army;
|
||||
for(auto & stack : stacks)
|
||||
{
|
||||
assert(!stack.allowedCreatures.empty());
|
||||
auto weakest = boost::range::min_element(stack.allowedCreatures, [](const CCreature * a, const CCreature * b)
|
||||
{
|
||||
return a->getFightValue() < b->getFightValue();
|
||||
});
|
||||
addStackToArmy(army, *weakest, stack.minAmount);
|
||||
}
|
||||
armies.push_back(army);
|
||||
}
|
||||
return *boost::range::min_element(armies);
|
||||
}
|
||||
|
||||
IObjectInfo::CArmyStructure CBankInfo::maxGuards() const
|
||||
{
|
||||
JsonRandom::Variables emptyVariables;
|
||||
|
||||
std::vector<IObjectInfo::CArmyStructure> armies;
|
||||
for(auto configEntry : config)
|
||||
{
|
||||
auto stacks = JsonRandom::evaluateCreatures(configEntry["guards"], emptyVariables);
|
||||
IObjectInfo::CArmyStructure army;
|
||||
for(auto & stack : stacks)
|
||||
{
|
||||
assert(!stack.allowedCreatures.empty());
|
||||
auto strongest = boost::range::max_element(stack.allowedCreatures, [](const CCreature * a, const CCreature * b)
|
||||
{
|
||||
return a->getFightValue() < b->getFightValue();
|
||||
});
|
||||
addStackToArmy(army, *strongest, stack.maxAmount);
|
||||
}
|
||||
armies.push_back(army);
|
||||
}
|
||||
return *boost::range::max_element(armies);
|
||||
}
|
||||
|
||||
TPossibleGuards CBankInfo::getPossibleGuards() const
|
||||
TPossibleGuards CBankInfo::getPossibleGuards(IGameCallback * cb) const
|
||||
{
|
||||
JsonRandom::Variables emptyVariables;
|
||||
JsonRandom randomizer(cb);
|
||||
TPossibleGuards out;
|
||||
|
||||
for(const JsonNode & configEntry : config)
|
||||
{
|
||||
const JsonNode & guardsInfo = configEntry["guards"];
|
||||
auto stacks = JsonRandom::evaluateCreatures(guardsInfo, emptyVariables);
|
||||
auto stacks = randomizer.evaluateCreatures(guardsInfo, emptyVariables);
|
||||
IObjectInfo::CArmyStructure army;
|
||||
|
||||
|
||||
@@ -191,12 +128,13 @@ std::vector<PossibleReward<TResources>> CBankInfo::getPossibleResourcesReward()
|
||||
std::vector<PossibleReward<CStackBasicDescriptor>> CBankInfo::getPossibleCreaturesReward() const
|
||||
{
|
||||
JsonRandom::Variables emptyVariables;
|
||||
JsonRandom randomizer(nullptr);
|
||||
std::vector<PossibleReward<CStackBasicDescriptor>> aproximateReward;
|
||||
|
||||
for(const JsonNode & configEntry : config)
|
||||
{
|
||||
const JsonNode & guardsInfo = configEntry["reward"]["creatures"];
|
||||
auto stacks = JsonRandom::evaluateCreatures(guardsInfo, emptyVariables);
|
||||
auto stacks = randomizer.evaluateCreatures(guardsInfo, emptyVariables);
|
||||
|
||||
for(auto stack : stacks)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user