浏览代码

Refactoring: random spells

DjWarmonger 10 年之前
父节点
当前提交
237d3f2624
共有 4 个文件被更改,包括 17 次插入8 次删除
  1. 0 1
      lib/mapping/CMap.h
  2. 11 0
      lib/rmg/CMapGenerator.cpp
  3. 1 0
      lib/rmg/CMapGenerator.h
  4. 5 7
      lib/rmg/CRmgTemplateZone.cpp

+ 0 - 1
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<CGObjectInstance> > objects;
 	std::vector< ConstTransitivePtr<CGTownInstance> > towns;

+ 11 - 0
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);

+ 1 - 0
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);

+ 5 - 7
lib/rmg/CRmgTemplateZone.cpp

@@ -2467,11 +2467,9 @@ void CRmgTemplateZone::addAllPossibleObjects(CMapGenerator* gen)
 			obj->subID = 0;
 			std::vector<SpellID> 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 <CSpell *> 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 <CSpell *> spells;
 		for (auto spell : VLC->spellh->objects)
 		{
-			if (!spell->isSpecialSpell() && !spell->isCreatureAbility())
+			if (gen->isAllowedSpell(spell->id))
 				spells.push_back(spell);
 		}