From 237d3f2624f1e1e9d0183e07af69e38fee3191a0 Mon Sep 17 00:00:00 2001 From: DjWarmonger Date: Wed, 12 Aug 2015 16:40:08 +0200 Subject: [PATCH] Refactoring: random spells --- lib/mapping/CMap.h | 1 - lib/rmg/CMapGenerator.cpp | 11 +++++++++++ lib/rmg/CMapGenerator.h | 1 + lib/rmg/CRmgTemplateZone.cpp | 12 +++++------- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/mapping/CMap.h b/lib/mapping/CMap.h index 2447789cb..df15775df 100644 --- a/lib/mapping/CMap.h +++ b/lib/mapping/CMap.h @@ -406,7 +406,6 @@ public: int3 grailPos; int grailRadious; - //Central lists of items in game. Position of item in the vectors below is their (instance) id. std::vector< ConstTransitivePtr > objects; std::vector< ConstTransitivePtr > towns; diff --git a/lib/rmg/CMapGenerator.cpp b/lib/rmg/CMapGenerator.cpp index e09a61cd8..587fb3d49 100644 --- a/lib/rmg/CMapGenerator.cpp +++ b/lib/rmg/CMapGenerator.cpp @@ -659,6 +659,17 @@ CTileInfo CMapGenerator::getTile(const int3& tile) const return tiles[tile.x][tile.y][tile.z]; } +bool CMapGenerator::isAllowedSpell(SpellID sid) const +{ + assert(sid >= 0); + if (sid < map->allowedSpell.size()) + { + return map->allowedSpell[sid]; + } + else + return false; +} + void CMapGenerator::setNearestObjectDistance(int3 &tile, float value) { checkIsOnMap(tile); diff --git a/lib/rmg/CMapGenerator.h b/lib/rmg/CMapGenerator.h index 41abdf74a..bdf340afe 100644 --- a/lib/rmg/CMapGenerator.h +++ b/lib/rmg/CMapGenerator.h @@ -79,6 +79,7 @@ public: void setRoad(const int3 &tile, ERoadType::ERoadType roadType); CTileInfo getTile(const int3 & tile) const; + bool isAllowedSpell(SpellID sid) const; float getNearestObjectDistance(const int3 &tile) const; void setNearestObjectDistance(int3 &tile, float value); diff --git a/lib/rmg/CRmgTemplateZone.cpp b/lib/rmg/CRmgTemplateZone.cpp index 66d3890f0..659bc7a7c 100644 --- a/lib/rmg/CRmgTemplateZone.cpp +++ b/lib/rmg/CRmgTemplateZone.cpp @@ -2467,11 +2467,9 @@ void CRmgTemplateZone::addAllPossibleObjects(CMapGenerator* gen) obj->subID = 0; std::vector out; - //TODO: unify with cb->getAllowedSpells? - for (ui32 spellid = 0; spellid < gen->map->allowedSpell.size(); spellid++) //spellh size appears to be greater (?) + for (auto spell : VLC->spellh->objects) //spellh size appears to be greater (?) { - const CSpell *spell = SpellID(spellid).toSpell(); - if (gen->map->allowedSpell[spell->id] && spell->level == i + 1) + if (gen->isAllowedSpell(spell->id) && spell->level == i + 1) { out.push_back(spell->id); } @@ -2582,7 +2580,7 @@ void CRmgTemplateZone::addAllPossibleObjects(CMapGenerator* gen) std::vector spells; for (auto spell : VLC->spellh->objects) { - if (!spell->isSpecialSpell() && !spell->isCreatureAbility() && spell->level == i) + if (gen->isAllowedSpell(spell->id) && spell->level == i) spells.push_back(spell); } @@ -2613,7 +2611,7 @@ void CRmgTemplateZone::addAllPossibleObjects(CMapGenerator* gen) for (auto spell : VLC->spellh->objects) { - if (!spell->isSpecialSpell() && !spell->isCreatureAbility() &&spell->school[(ESpellSchool)i]) + if (gen->isAllowedSpell(spell->id) && spell->school[(ESpellSchool)i]) spells.push_back(spell); } @@ -2642,7 +2640,7 @@ void CRmgTemplateZone::addAllPossibleObjects(CMapGenerator* gen) std::vector spells; for (auto spell : VLC->spellh->objects) { - if (!spell->isSpecialSpell() && !spell->isCreatureAbility()) + if (gen->isAllowedSpell(spell->id)) spells.push_back(spell); }