浏览代码

Removed bonus system loop in GameState.

Moved some game settings to global.h
DjWarmonger 15 年之前
父节点
当前提交
e481a4375b
共有 5 个文件被更改,包括 19 次插入30 次删除
  1. 3 1
      global.h
  2. 2 2
      hch/CObjectHandler.cpp
  3. 1 1
      hch/CObjectHandler.h
  4. 6 24
      lib/CGameState.cpp
  5. 7 2
      lib/HeroBonus.cpp

+ 3 - 1
global.h

@@ -102,9 +102,11 @@ const int NAMES_PER_TOWN=16;
 const int CREATURES_PER_TOWN = 7; //without upgrades
 const int MAX_BUILDING_PER_TURN = 1;
 const int SPELL_LEVELS = 5;
-const int CREEP_SIZE = 4000; // neutral stacks won't grow beyon this number
+//const int CREEP_SIZE = 4000; // neutral stacks won't grow beyon this number
+const int CREEP_SIZE = 2000000000;
 const int WEEKLY_GROWTH = 10; //percent
 const int AVAILABLE_HEROES_PER_PLAYER = 2;
+const bool DWELLINGS_ACCUMULATE_CREATURES = true;
 
 const int BFIELD_WIDTH = 17;
 const int BFIELD_HEIGHT = 11;

+ 2 - 2
hch/CObjectHandler.cpp

@@ -1495,7 +1495,7 @@ void CGHeroInstance::getParents(TCNodes &out, const CBonusSystemNode *root /*= N
 {
 	CArmedInstance::getParents(out, root);
 
-	if((root == this || contains(static_cast<const CStackInstance *>(root))) &&  visitedTown)
+	if((root == this || contains(static_cast<const CStackInstance *>(root))) &&  visitedTown && !dynamic_cast<const PlayerState*>(root))
 	{
 			out.insert(visitedTown);
 	}
@@ -1749,7 +1749,7 @@ void CGDwelling::newTurn() const
 		{
 			CCreature *cre = VLC->creh->creatures[creatures[i].second[0]];
 			TQuantity amount = cre->growth * (1 + cre->valOfBonuses(Bonus::CREATURE_GROWTH_PERCENT)/100) + cre->valOfBonuses(Bonus::CREATURE_GROWTH);
-			if(false /*accumulate creatures*/)
+			if (DWELLINGS_ACCUMULATE_CREATURES)
 				sac.creatures[i].first += amount;
 			else
 				sac.creatures[i].first = amount;

+ 1 - 1
hch/CObjectHandler.h

@@ -635,7 +635,7 @@ public:
 	si32 gainedArtifact; //ID of artifact gained to hero, -1 if none
 	ui8 neverFlees; //if true, the troops will never flee
 	ui8 notGrowingTeam; //if true, number of units won't grow
-	ui32 temppower; //used to handle fractional stack growth for tiny stacks
+	ui64 temppower; //used to handle fractional stack growth for tiny stacks
 
 	void fight(const CGHeroInstance *h) const;
 	void onHeroVisit(const CGHeroInstance * h) const;

+ 6 - 24
lib/CGameState.cpp

@@ -4479,34 +4479,16 @@ PlayerState::PlayerState()
 
 void PlayerState::getParents(TCNodes &out, const CBonusSystemNode *root /*= NULL*/) const
 {
-	//an issue - this way we get quadratic complexity at the moment all objects are called
-	for (std::vector<CGHeroInstance *>::const_iterator it = heroes.begin(); it != heroes.end(); it++)
-	{
-		out.insert(*it);
-	}
-	/*
-	for (std::vector<CGTownInstance *>::const_iterator it = towns.begin(); it != towns.end(); it++)
-	{
-			out.insert(*it);
-	}
-	*/
-	if (root != this) 
-	{
-		out.erase(out.find(root)); //don't use yourself
-		root = this; //get all nodes ONLY once - see Armed Instance::getParents
-	}
+	return; //no loops possible
 }
 
 void PlayerState::getBonuses(BonusList &out, const CSelector &selector, const CBonusSystemNode *root /*= NULL*/) const
 {
-	if (Selector::matchesType(selector, Bonus::CREATURE_GROWTH_PERCENT))
-		CBonusSystemNode::getBonuses(out, selector, this); //no recursive loops for PlayerState
-	/* //universal solution
-	if (root == this) // called directly
-		CBonusSystemNode::getBonuses(out, selector, this); //no recursive loops for PlayerState
-	else //unused yet
-		CBonusSystemNode::getBonuses(out, selector && Selector::effectRange(Bonus::GLOBAL), root); //only very specific bonuses can be propagated this way
-	*/
+	for (std::vector<CGHeroInstance *>::const_iterator it = heroes.begin(); it != heroes.end(); it++)
+	{
+		if (*it != root)
+			(*it)->getBonuses(out, selector, this);
+	}
 }
 
 InfoAboutHero::InfoAboutHero()

+ 7 - 2
lib/HeroBonus.cpp

@@ -181,9 +181,14 @@ Bonus * CBonusSystemNode::getBonus(const CSelector &selector)
 	if(ret)
 		return ret;
 
-	FOREACH_PARENT(p, this)
-		if(ret = p->getBonus(selector))
+	//FOREACH_PARENT(p, this)
+	TNodes parents;
+	getParents (parents, this);
+	BOOST_FOREACH (CBonusSystemNode *pname, parents)
+	{
+		if(ret = pname->getBonus(selector))
 			return ret;
+	}
 
 	return NULL;
 }