1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-06 09:09:40 +02:00

Refactoring: random spells

This commit is contained in:
DjWarmonger
2015-08-12 16:40:08 +02:00
parent 3863756009
commit 237d3f2624
4 changed files with 17 additions and 8 deletions

View File

@@ -406,7 +406,6 @@ public:
int3 grailPos; int3 grailPos;
int grailRadious; int grailRadious;
//Central lists of items in game. Position of item in the vectors below is their (instance) id. //Central lists of items in game. Position of item in the vectors below is their (instance) id.
std::vector< ConstTransitivePtr<CGObjectInstance> > objects; std::vector< ConstTransitivePtr<CGObjectInstance> > objects;
std::vector< ConstTransitivePtr<CGTownInstance> > towns; std::vector< ConstTransitivePtr<CGTownInstance> > towns;

View File

@@ -659,6 +659,17 @@ CTileInfo CMapGenerator::getTile(const int3& tile) const
return tiles[tile.x][tile.y][tile.z]; 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) void CMapGenerator::setNearestObjectDistance(int3 &tile, float value)
{ {
checkIsOnMap(tile); checkIsOnMap(tile);

View File

@@ -79,6 +79,7 @@ public:
void setRoad(const int3 &tile, ERoadType::ERoadType roadType); void setRoad(const int3 &tile, ERoadType::ERoadType roadType);
CTileInfo getTile(const int3 & tile) const; CTileInfo getTile(const int3 & tile) const;
bool isAllowedSpell(SpellID sid) const;
float getNearestObjectDistance(const int3 &tile) const; float getNearestObjectDistance(const int3 &tile) const;
void setNearestObjectDistance(int3 &tile, float value); void setNearestObjectDistance(int3 &tile, float value);

View File

@@ -2467,11 +2467,9 @@ void CRmgTemplateZone::addAllPossibleObjects(CMapGenerator* gen)
obj->subID = 0; obj->subID = 0;
std::vector<SpellID> out; std::vector<SpellID> out;
//TODO: unify with cb->getAllowedSpells? for (auto spell : VLC->spellh->objects) //spellh size appears to be greater (?)
for (ui32 spellid = 0; spellid < gen->map->allowedSpell.size(); spellid++) //spellh size appears to be greater (?)
{ {
const CSpell *spell = SpellID(spellid).toSpell(); if (gen->isAllowedSpell(spell->id) && spell->level == i + 1)
if (gen->map->allowedSpell[spell->id] && spell->level == i + 1)
{ {
out.push_back(spell->id); out.push_back(spell->id);
} }
@@ -2582,7 +2580,7 @@ void CRmgTemplateZone::addAllPossibleObjects(CMapGenerator* gen)
std::vector <CSpell *> spells; std::vector <CSpell *> spells;
for (auto spell : VLC->spellh->objects) 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); spells.push_back(spell);
} }
@@ -2613,7 +2611,7 @@ void CRmgTemplateZone::addAllPossibleObjects(CMapGenerator* gen)
for (auto spell : VLC->spellh->objects) 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); spells.push_back(spell);
} }
@@ -2642,7 +2640,7 @@ void CRmgTemplateZone::addAllPossibleObjects(CMapGenerator* gen)
std::vector <CSpell *> spells; std::vector <CSpell *> spells;
for (auto spell : VLC->spellh->objects) for (auto spell : VLC->spellh->objects)
{ {
if (!spell->isSpecialSpell() && !spell->isCreatureAbility()) if (gen->isAllowedSpell(spell->id))
spells.push_back(spell); spells.push_back(spell);
} }