mirror of
https://github.com/vcmi/vcmi.git
synced 2025-04-13 11:40:38 +02:00
Refactor duplicated code as suggested by SonarCloud
This commit is contained in:
parent
afc9bd908c
commit
253f1dc7e6
@ -464,6 +464,19 @@ void TreasurePlacer::addAllPossibleObjects()
|
|||||||
|
|
||||||
RandomGeneratorUtil::randomShuffle(creatures, zone.getRand());
|
RandomGeneratorUtil::randomShuffle(creatures, zone.getRand());
|
||||||
|
|
||||||
|
auto setRandomArtifact = [qap, &oi](CGSeerHut * obj)
|
||||||
|
{
|
||||||
|
ArtifactID artid = qap->drawRandomArtifact();
|
||||||
|
oi.destroyObject = [artid, qap]()
|
||||||
|
{
|
||||||
|
// Artifact can be used again
|
||||||
|
qap->addRandomArtifact(artid);
|
||||||
|
qap->removeQuestArtifact(artid);
|
||||||
|
};
|
||||||
|
obj->quest->mission.artifacts.push_back(artid);
|
||||||
|
qap->addQuestArtifact(artid);
|
||||||
|
};
|
||||||
|
|
||||||
for(int i = 0; i < static_cast<int>(creatures.size()); i++)
|
for(int i = 0; i < static_cast<int>(creatures.size()); i++)
|
||||||
{
|
{
|
||||||
auto * creature = creatures[i];
|
auto * creature = creatures[i];
|
||||||
@ -475,7 +488,7 @@ void TreasurePlacer::addAllPossibleObjects()
|
|||||||
int randomAppearance = chooseRandomAppearance(zone.getRand(), Obj::SEER_HUT, zone.getTerrainType());
|
int randomAppearance = chooseRandomAppearance(zone.getRand(), Obj::SEER_HUT, zone.getTerrainType());
|
||||||
|
|
||||||
// FIXME: Remove duplicated code for gold, exp and creaure reward
|
// FIXME: Remove duplicated code for gold, exp and creaure reward
|
||||||
oi.generateObject = [creature, creaturesAmount, randomAppearance, qap, &oi]() -> CGObjectInstance *
|
oi.generateObject = [creature, creaturesAmount, randomAppearance, qap, &oi, setRandomArtifact]() -> CGObjectInstance *
|
||||||
{
|
{
|
||||||
auto factory = VLC->objtypeh->getHandlerFor(Obj::SEER_HUT, randomAppearance);
|
auto factory = VLC->objtypeh->getHandlerFor(Obj::SEER_HUT, randomAppearance);
|
||||||
auto * obj = dynamic_cast<CGSeerHut *>(factory->create());
|
auto * obj = dynamic_cast<CGSeerHut *>(factory->create());
|
||||||
@ -485,16 +498,7 @@ void TreasurePlacer::addAllPossibleObjects()
|
|||||||
reward.visitType = Rewardable::EEventType::EVENT_FIRST_VISIT;
|
reward.visitType = Rewardable::EEventType::EVENT_FIRST_VISIT;
|
||||||
obj->configuration.info.push_back(reward);
|
obj->configuration.info.push_back(reward);
|
||||||
|
|
||||||
ArtifactID artid = qap->drawRandomArtifact();
|
setRandomArtifact(obj);
|
||||||
oi.destroyObject = [artid, qap]()
|
|
||||||
{
|
|
||||||
// Artifact can be used again
|
|
||||||
qap->addRandomArtifact(artid);
|
|
||||||
qap->removeQuestArtifact(artid);
|
|
||||||
};
|
|
||||||
obj->quest->mission.artifacts.push_back(artid);
|
|
||||||
|
|
||||||
qap->addQuestArtifact(artid);
|
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
@ -528,7 +532,7 @@ void TreasurePlacer::addAllPossibleObjects()
|
|||||||
oi.probability = 10;
|
oi.probability = 10;
|
||||||
oi.maxPerZone = 1;
|
oi.maxPerZone = 1;
|
||||||
|
|
||||||
oi.generateObject = [i, randomAppearance, this, qap, &oi]() -> CGObjectInstance *
|
oi.generateObject = [i, randomAppearance, this, qap, &oi, setRandomArtifact]() -> CGObjectInstance *
|
||||||
{
|
{
|
||||||
auto factory = VLC->objtypeh->getHandlerFor(Obj::SEER_HUT, randomAppearance);
|
auto factory = VLC->objtypeh->getHandlerFor(Obj::SEER_HUT, randomAppearance);
|
||||||
auto * obj = dynamic_cast<CGSeerHut *>(factory->create());
|
auto * obj = dynamic_cast<CGSeerHut *>(factory->create());
|
||||||
@ -537,25 +541,16 @@ void TreasurePlacer::addAllPossibleObjects()
|
|||||||
reward.reward.heroExperience = generator.getConfig().questRewardValues[i];
|
reward.reward.heroExperience = generator.getConfig().questRewardValues[i];
|
||||||
reward.visitType = Rewardable::EEventType::EVENT_FIRST_VISIT;
|
reward.visitType = Rewardable::EEventType::EVENT_FIRST_VISIT;
|
||||||
obj->configuration.info.push_back(reward);
|
obj->configuration.info.push_back(reward);
|
||||||
|
|
||||||
ArtifactID artid = qap->drawRandomArtifact();
|
setRandomArtifact(obj);
|
||||||
oi.destroyObject = [artid, qap]()
|
|
||||||
{
|
|
||||||
// Artifact can be used again
|
|
||||||
qap->addRandomArtifact(artid);
|
|
||||||
qap->removeQuestArtifact(artid);
|
|
||||||
};
|
|
||||||
obj->quest->mission.artifacts.push_back(artid);
|
|
||||||
|
|
||||||
qap->addQuestArtifact(artid);
|
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
|
|
||||||
if(!oi.templates.empty())
|
if(!oi.templates.empty())
|
||||||
possibleSeerHuts.push_back(oi);
|
possibleSeerHuts.push_back(oi);
|
||||||
|
|
||||||
oi.generateObject = [i, randomAppearance, this, qap, &oi]() -> CGObjectInstance *
|
oi.generateObject = [i, randomAppearance, this, qap, &oi, setRandomArtifact]() -> CGObjectInstance *
|
||||||
{
|
{
|
||||||
auto factory = VLC->objtypeh->getHandlerFor(Obj::SEER_HUT, randomAppearance);
|
auto factory = VLC->objtypeh->getHandlerFor(Obj::SEER_HUT, randomAppearance);
|
||||||
auto * obj = dynamic_cast<CGSeerHut *>(factory->create());
|
auto * obj = dynamic_cast<CGSeerHut *>(factory->create());
|
||||||
@ -565,16 +560,7 @@ void TreasurePlacer::addAllPossibleObjects()
|
|||||||
reward.visitType = Rewardable::EEventType::EVENT_FIRST_VISIT;
|
reward.visitType = Rewardable::EEventType::EVENT_FIRST_VISIT;
|
||||||
obj->configuration.info.push_back(reward);
|
obj->configuration.info.push_back(reward);
|
||||||
|
|
||||||
ArtifactID artid = qap->drawRandomArtifact();
|
setRandomArtifact(obj);
|
||||||
oi.destroyObject = [artid, qap]()
|
|
||||||
{
|
|
||||||
// Artifact can be used again
|
|
||||||
qap->addRandomArtifact(artid);
|
|
||||||
qap->removeQuestArtifact(artid);
|
|
||||||
};
|
|
||||||
obj->quest->mission.artifacts.push_back(artid);
|
|
||||||
|
|
||||||
qap->addQuestArtifact(artid);
|
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user