mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-22 22:13:35 +02:00
Explicitly ban 'large' dwellings from random selection
Old code was relying on specific sorting order leading to easy to break logic
This commit is contained in:
parent
7d6b936a9d
commit
ffec4b9154
@ -65,6 +65,7 @@
|
||||
},
|
||||
"airConflux": {
|
||||
"index": 7,
|
||||
"bannedForRandomDwelling" : true,
|
||||
"creatures": [["airElemental"]],
|
||||
"sounds": {
|
||||
"ambient": ["LOOPAIR"]
|
||||
@ -107,6 +108,7 @@
|
||||
},
|
||||
"earthConflux": {
|
||||
"index": 13,
|
||||
"bannedForRandomDwelling" : true,
|
||||
"creatures": [["earthElemental"]],
|
||||
"sounds": {
|
||||
"ambient": ["LOOPEART"]
|
||||
@ -128,6 +130,7 @@
|
||||
},
|
||||
"fireConflux": {
|
||||
"index": 16,
|
||||
"bannedForRandomDwelling" : true,
|
||||
"creatures": [["fireElemental"]],
|
||||
"sounds": {
|
||||
"ambient": ["LOOPFIRE"]
|
||||
@ -345,6 +348,7 @@
|
||||
},
|
||||
"waterConflux": {
|
||||
"index": 47,
|
||||
"bannedForRandomDwelling" : true,
|
||||
"creatures": [["waterElemental"]],
|
||||
"sounds": {
|
||||
"ambient": ["LOOPFOUN"]
|
||||
@ -538,6 +542,7 @@
|
||||
"types" : {
|
||||
"elementalConflux" : {
|
||||
"index" : 0,
|
||||
"bannedForRandomDwelling" : true,
|
||||
"creatures" : [ // 4 separate "levels" to give them separate growth
|
||||
[ "airElemental" ],
|
||||
[ "waterElemental" ],
|
||||
|
@ -51,6 +51,12 @@ void DwellingInstanceConstructor::initTypeData(const JsonNode & input)
|
||||
assert(!availableCreatures[currentLevel].empty());
|
||||
}
|
||||
guards = input["guards"];
|
||||
bannedForRandomDwelling = input["bannedForRandomDwelling"].Bool();
|
||||
}
|
||||
|
||||
bool DwellingInstanceConstructor::isBannedForRandomDwelling() const
|
||||
{
|
||||
return bannedForRandomDwelling;
|
||||
}
|
||||
|
||||
bool DwellingInstanceConstructor::objectFilter(const CGObjectInstance * obj, std::shared_ptr<const ObjectTemplate> tmpl) const
|
||||
|
@ -23,6 +23,7 @@ class DwellingInstanceConstructor : public CDefaultObjectTypeHandler<CGDwelling>
|
||||
std::vector<std::vector<const CCreature *>> availableCreatures;
|
||||
|
||||
JsonNode guards;
|
||||
bool bannedForRandomDwelling = false;
|
||||
|
||||
protected:
|
||||
bool objectFilter(const CGObjectInstance * obj, std::shared_ptr<const ObjectTemplate> tmpl) const override;
|
||||
@ -34,6 +35,7 @@ public:
|
||||
void initializeObject(CGDwelling * object) const override;
|
||||
void randomizeObject(CGDwelling * object, CRandomGenerator & rng) const override;
|
||||
|
||||
bool isBannedForRandomDwelling() const;
|
||||
bool producesCreature(const CCreature * crea) const;
|
||||
std::vector<const CCreature *> getProducedCreatures() const;
|
||||
};
|
||||
|
@ -146,7 +146,7 @@ void CGDwelling::pickRandomObject(CRandomGenerator & rand)
|
||||
{
|
||||
const auto * handler = dynamic_cast<const DwellingInstanceConstructor *>(VLC->objtypeh->getHandlerFor(primaryID, entry).get());
|
||||
|
||||
if (handler->producesCreature(cid.toCreature()))
|
||||
if (!handler->isBannedForRandomDwelling() && handler->producesCreature(cid.toCreature()))
|
||||
return MapObjectSubID(entry);
|
||||
}
|
||||
return MapObjectSubID();
|
||||
|
Loading…
Reference in New Issue
Block a user