1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Partial solution to #2206

TODO: add serialized field that contains custom guard config
This commit is contained in:
DjWarmonger 2015-06-05 11:28:14 +02:00
parent 3f1bc7e21c
commit 9e7b459882
4 changed files with 111 additions and 41 deletions

View File

@ -10,58 +10,58 @@
},
"types" : {
"basiliskPit" : { "index" : 0, "creatures" : [ [ "basilisk" ] ] },
"behemothCrag" : { "index" : 1, "creatures" : [ [ "behemoth" ] ], "guards" : true },
"behemothCrag" : { "index" : 1, "creatures" : [ [ "behemoth" ] ]},
"pillarOfEyes" : { "index" : 2, "creatures" : [ [ "beholder" ] ] },
"hallOfDarkness" : { "index" : 3, "creatures" : [ [ "blackKnight" ] ], "guards" : true },
"dragonVault" : { "index" : 4, "creatures" : [ [ "boneDragon" ] ], "guards" : true },
"trainingGrounds" : { "index" : 5, "creatures" : [ [ "cavalier" ] ], "guards" : true },
"hallOfDarkness" : { "index" : 3, "creatures" : [ [ "blackKnight" ] ]},
"dragonVault" : { "index" : 4, "creatures" : [ [ "boneDragon" ] ]},
"trainingGrounds" : { "index" : 5, "creatures" : [ [ "cavalier" ] ]},
"centaurStables" : { "index" : 6, "creatures" : [ [ "centaur" ] ] },
"airConflux" : { "index" : 7, "creatures" : [ [ "airElemental" ] ] },
"portalOfGlory" : { "index" : 8, "creatures" : [ [ "angel" ] ], "guards" : true },
"cyclopsCave" : { "index" : 9, "creatures" : [ [ "cyclop" ] ], "guards" : true },
"forsakenPalace" : { "index" : 10, "creatures" : [ [ "devil" ] ], "guards" : true },
"portalOfGlory" : { "index" : 8, "creatures" : [ [ "angel" ] ]},
"cyclopsCave" : { "index" : 9, "creatures" : [ [ "cyclop" ] ]},
"forsakenPalace" : { "index" : 10, "creatures" : [ [ "devil" ] ]},
"serpentFlyHive" : { "index" : 11, "creatures" : [ [ "serpentFly" ] ] },
"dwarfCottage" : { "index" : 12, "creatures" : [ [ "dwarf" ] ] },
"earthConflux" : { "index" : 13, "creatures" : [ [ "earthElemental" ] ], "guards" : true },
"fireLake" : { "index" : 14, "creatures" : [ [ "efreet" ] ], "guards" : true },
"earthConflux" : { "index" : 13, "creatures" : [ [ "earthElemental" ] ]},
"fireLake" : { "index" : 14, "creatures" : [ [ "efreet" ] ]},
"homestead" : { "index" : 15, "creatures" : [ [ "woodElf" ] ] },
"fireConflux" : { "index" : 16, "creatures" : [ [ "fireElemental" ] ] },
"parapet" : { "index" : 17, "creatures" : [ [ "stoneGargoyle" ] ] },
"altarOfWishes" : { "index" : 18, "creatures" : [ [ "genie" ] ], "guards" : true },
"altarOfWishes" : { "index" : 18, "creatures" : [ [ "genie" ] ]},
"wolfPen" : { "index" : 19, "creatures" : [ [ "goblinWolfRider" ] ] },
"gnollHut" : { "index" : 20, "creatures" : [ [ "gnoll" ] ] },
"goblinBarracks" : { "index" : 21, "creatures" : [ [ "goblin" ] ] },
"hallOfSins" : { "index" : 22, "creatures" : [ [ "gog" ] ] },
"gorgonLair" : { "index" : 23, "creatures" : [ [ "gorgon" ] ], "guards" : true },
"dragonCliffs" : { "index" : 24, "creatures" : [ [ "greenDragon" ] ], "guards" : true },
"gorgonLair" : { "index" : 23, "creatures" : [ [ "gorgon" ] ]},
"dragonCliffs" : { "index" : 24, "creatures" : [ [ "greenDragon" ] ]},
"griffinTower" : { "index" : 25, "creatures" : [ [ "griffin" ] ] },
"harpyLoft" : { "index" : 26, "creatures" : [ [ "harpy" ] ] },
"kennels" : { "index" : 27, "creatures" : [ [ "hellHound" ] ] },
"hydraPond" : { "index" : 28, "creatures" : [ [ "hydra" ] ], "guards" : true },
"hydraPond" : { "index" : 28, "creatures" : [ [ "hydra" ] ]},
"impCrucible" : { "index" : 29, "creatures" : [ [ "imp" ] ] },
"lizardDen" : { "index" : 30, "creatures" : [ [ "lizardman" ] ] },
"mageTower" : { "index" : 31, "creatures" : [ [ "mage" ] ] },
"manticoreLair" : { "index" : 32, "creatures" : [ [ "manticore" ] ], "guards" : true },
"manticoreLair" : { "index" : 32, "creatures" : [ [ "manticore" ] ]},
"medusaChapel" : { "index" : 33, "creatures" : [ [ "medusa" ] ] },
"labyrinth" : { "index" : 34, "creatures" : [ [ "minotaur" ] ], "guards" : true },
"monastery" : { "index" : 35, "creatures" : [ [ "monk" ] ], "guards" : true },
"goldenPavilion" : { "index" : 36, "creatures" : [ [ "naga" ] ], "guards" : true },
"labyrinth" : { "index" : 34, "creatures" : [ [ "minotaur" ] ]},
"monastery" : { "index" : 35, "creatures" : [ [ "monk" ] ]},
"goldenPavilion" : { "index" : 36, "creatures" : [ [ "naga" ] ]},
"demonGate" : { "index" : 37, "creatures" : [ [ "demon" ] ] },
"ogreFort" : { "index" : 38, "creatures" : [ [ "ogre" ] ] },
"orcTower" : { "index" : 39, "creatures" : [ [ "orc" ] ] },
"hellHole" : { "index" : 40, "creatures" : [ [ "pitFiend" ] ], "guards" : true },
"dragonCave" : { "index" : 41, "creatures" : [ [ "redDragon" ] ], "guards" : true },
"cliffNest" : { "index" : 42, "creatures" : [ [ "roc" ] ], "guards" : true },
"hellHole" : { "index" : 40, "creatures" : [ [ "pitFiend" ] ]},
"dragonCave" : { "index" : 41, "creatures" : [ [ "redDragon" ] ]},
"cliffNest" : { "index" : 42, "creatures" : [ [ "roc" ] ]},
"workshop" : { "index" : 43, "creatures" : [ [ "gremlin" ] ] },
"cloudTemple" : { "index" : 44, "creatures" : [ [ "giant" ] ], "guards" : true },
"dendroidArches" : { "index" : 45, "creatures" : [ [ "dendroidGuard" ] ], "guards" : true },
"cloudTemple" : { "index" : 44, "creatures" : [ [ "giant" ] ]},
"dendroidArches" : { "index" : 45, "creatures" : [ [ "dendroidGuard" ] ]},
"warren" : { "index" : 46, "creatures" : [ [ "troglodyte" ] ] },
"waterConflux" : { "index" : 47, "creatures" : [ [ "waterElemental" ] ] },
"tombOfSouls" : { "index" : 48, "creatures" : [ [ "wight" ] ] },
"wyvernNest" : { "index" : 49, "creatures" : [ [ "wyvern" ] ], "guards" : true },
"wyvernNest" : { "index" : 49, "creatures" : [ [ "wyvern" ] ]},
"enchantedSpring" : { "index" : 50, "creatures" : [ [ "pegasus" ] ] },
"unicornGladeBig" : { "index" : 51, "creatures" : [ [ "unicorn" ] ], "guards" : true },
"mausoleum" : { "index" : 52, "creatures" : [ [ "lich" ] ], "guards" : true },
"unicornGladeBig" : { "index" : 51, "creatures" : [ [ "unicorn" ] ]},
"mausoleum" : { "index" : 52, "creatures" : [ [ "lich" ] ]},
"estate" : { "index" : 53, "creatures" : [ [ "vampire" ] ] },
"cursedTemple" : { "index" : 54, "creatures" : [ [ "skeleton" ] ] },
"graveyard" : { "index" : 55, "creatures" : [ [ "walkingDead" ] ] },
@ -69,17 +69,17 @@
"archersTower" : { "index" : 57, "creatures" : [ [ "archer" ] ] },
"barracks" : { "index" : 58, "creatures" : [ [ "swordsman" ] ] },
"magicLantern" : { "index" : 59, "creatures" : [ [ "pixie" ] ] },
"altarOfThought" : { "index" : 60, "creatures" : [ [ "psychicElemental" ] ], "guards" : true },
"pyre" : { "index" : 61, "creatures" : [ [ "firebird" ] ], "guards" : true },
"frozenCliffs" : { "index" : 62, "creatures" : [ [ "azureDragon" ] ], "guards" : true },
"crystalCavern" : { "index" : 63, "creatures" : [ [ "crystalDragon" ] ], "guards" : true },
"magicForest" : { "index" : 64, "creatures" : [ [ "fairieDragon" ] ], "guards" : true },
"sulfurousLair" : { "index" : 65, "creatures" : [ [ "rustDragon" ] ], "guards" : true },
"enchantersHollow" : { "index" : 66, "creatures" : [ [ "enchanter" ] ], "guards" : true },
"treetopTower" : { "index" : 67, "creatures" : [ [ "sharpshooter" ] ], "guards" : true },
"unicornGlade" : { "index" : 68, "creatures" : [ [ "unicorn" ] ], "guards" : true },
"altarOfThought" : { "index" : 60, "creatures" : [ [ "psychicElemental" ] ]},
"pyre" : { "index" : 61, "creatures" : [ [ "firebird" ] ]},
"frozenCliffs" : { "index" : 62, "creatures" : [ [ "azureDragon" ] ]},
"crystalCavern" : { "index" : 63, "creatures" : [ [ "crystalDragon" ] ]},
"magicForest" : { "index" : 64, "creatures" : [ [ "fairieDragon" ] ]},
"sulfurousLair" : { "index" : 65, "creatures" : [ [ "rustDragon" ] ]},
"enchantersHollow" : { "index" : 66, "creatures" : [ [ "enchanter" ] ]},
"treetopTower" : { "index" : 67, "creatures" : [ [ "sharpshooter" ] ]},
"unicornGlade" : { "index" : 68, "creatures" : [ [ "unicorn" ] ]},
"altarOfAir" : { "index" : 69, "creatures" : [ [ "airElemental" ] ] },
"altarOfEarth" : { "index" : 70, "creatures" : [ [ "earthElemental" ] ], "guards" : true },
"altarOfEarth" : { "index" : 70, "creatures" : [ [ "earthElemental" ] ]},
"altarOfFire" : { "index" : 71, "creatures" : [ [ "fireElemental" ] ] },
"altarOfWater" : { "index" : 72, "creatures" : [ [ "waterElemental" ] ] },
"thatchedHut" : { "index" : 73, "creatures" : [ [ "halfling" ] ] },
@ -88,7 +88,7 @@
"tombOfCurses" : { "index" : 76, "creatures" : [ [ "mummy" ] ] },
"nomadTent" : { "index" : 77, "creatures" : [ [ "nomad" ] ] },
"rogueCavern" : { "index" : 78, "creatures" : [ [ "rogue" ] ] },
"trollBridge" : { "index" : 79, "creatures" : [ [ "troll" ] ], "guards" : true }
"trollBridge" : { "index" : 79, "creatures" : [ [ "troll" ] ] }
}
},
// subtype: unique special dwellings - golem factory and elemental conflux

View File

@ -171,6 +171,51 @@ void CGDwelling::newTurn() const
if(change)
cb->sendAndApply(&sac);
updateGuards();
}
void CGDwelling::updateGuards() const
{
//TODO: store custom guard config and use it
//TODO: store boolean flag for guards
bool guarded = false;
//default condition - creatures are of level 5 or higher
for (auto creatureEntry : creatures)
{
if (VLC->creh->creatures[creatureEntry.second.at(0)]->level >= 5)
{
guarded = true;
break;
}
}
if (guarded)
{
for (auto creatureEntry : creatures)
{
const CCreature * crea = VLC->creh->creatures[creatureEntry.second.at(0)];
SlotID slot = getSlotFor(crea->idNumber);
StackLocation stackLocation = StackLocation(this, slot);;
if (hasStackAtSlot(slot)) //stack already exists, overwrite it
{
ChangeStackCount csc;
csc.sl = stackLocation;
csc.count = crea->growth * 3;
csc.absoluteValue = true;
cb->sendAndApply(&csc);
}
else //slot is empty, create whole new stack
{
InsertNewStack ns;
ns.sl = stackLocation;
ns.stack = CStackBasicDescriptor(crea->idNumber, crea->growth * 3);
cb->sendAndApply(&ns);
}
}
}
}
void CGDwelling::heroAcceptsCreatures( const CGHeroInstance *h) const

View File

@ -65,6 +65,7 @@ public:
void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
private:
void updateGuards() const;
void heroAcceptsCreatures(const CGHeroInstance *h) const;
};

View File

@ -196,17 +196,41 @@ void CDwellingInstanceConstructor::configureObject(CGObjectInstance * object, CR
dwelling->creatures.back().second.push_back(cre->idNumber);
}
if (guards.getType() == JsonNode::DATA_BOOL)
bool guarded = false; //TODO: serialize for sanity
if (guards.getType() == JsonNode::DATA_BOOL) //simple switch
{
if (guards.Bool())
{
const CCreature * crea = availableCreatures.at(0).at(0);
dwelling->putStack(SlotID(0), new CStackInstance(crea->idNumber, crea->growth * 3 ));
guarded = true;
}
}
else for (auto & stack : JsonRandom::loadCreatures(guards, rng))
else if (guards.getType() == JsonNode::DATA_VECTOR) //custom guards (eg. Elemental Conflux)
{
dwelling->putStack(SlotID(dwelling->stacksCount()), new CStackInstance(stack.type->idNumber, stack.count));
for (auto & stack : JsonRandom::loadCreatures(guards, rng))
{
dwelling->putStack(SlotID(dwelling->stacksCount()), new CStackInstance(stack.type->idNumber, stack.count));
}
}
else //default condition - creatures are of level 5 or higher
{
for (auto creatureEntry : availableCreatures)
{
if (creatureEntry.at(0)->level >= 5)
{
guarded = true;
break;
}
}
}
if (guarded)
{
for (auto creatureEntry : availableCreatures)
{
const CCreature * crea = creatureEntry.at(0);
dwelling->putStack (SlotID(dwelling->stacksCount()), new CStackInstance(crea->idNumber, crea->growth * 3));
}
}
}