Browse Source

* bugfixes and refactorings

mateuszb 16 years ago
parent
commit
4f30bde636
4 changed files with 64 additions and 56 deletions
  1. 58 1
      CGameState.cpp
  2. 2 0
      CGameState.h
  3. 1 1
      CPlayerInterface.cpp
  4. 3 54
      server/CGameHandler.cpp

+ 58 - 1
CGameState.cpp

@@ -968,7 +968,7 @@ void CGameState::init(StartInfo * si, Mapa * map, int Seed)
 			int3 hpos = map->players[i].posOfMainTown;
 			hpos.x+=1;// hpos.y+=1;
 			int j;
-			for(unsigned j=0; j<scenarioOps->playerInfos.size(); j++)
+			for(j=0; j<scenarioOps->playerInfos.size(); j++) //don't add unsigned here - we are refering to the variable above
 				if(scenarioOps->playerInfos[j].color == i)
 					break;
 			if(j == scenarioOps->playerInfos.size())
@@ -1949,6 +1949,63 @@ void BattleInfo::calculateCasualties( std::set<std::pair<ui32,si32> > *casualtie
 	}
 }
 
+std::set<CStack*> BattleInfo::getAttackedCreatures(const CSpell * s, const CGHeroInstance * caster, int destinationTile)
+{
+	std::set<ui16> attackedHexes = s->rangeInHexes(destinationTile, caster->getSpellSchoolLevel(s));
+	std::set<CStack*> attackedCres; /*std::set to exclude multiple occurences of two hex creatures*/
+	if(s->id == 24 || s->id == 25 || s->id == 26) //death ripple, destroy undead and armageddon
+	{
+		for(int it=0; it<stacks.size(); ++it)
+		{
+			if((s->id == 24 && !stacks[it]->creature->isUndead()) //death ripple
+				|| (s->id == 25 && stacks[it]->creature->isUndead()) //destroy undead
+				|| (s->id == 26) //armageddon
+				)
+			{
+				attackedCres.insert(stacks[it]);
+			}
+		}
+	}
+	else if(VLC->spellh->spells[s->id].attributes.find("CREATURE_TARGET_2") != std::string::npos) //spell to be cast on a specific creature but massive on expert
+	{
+		if(caster->getSpellSchoolLevel(s) < 3)  /*not expert */
+		{
+			CStack * st = getStackT(destinationTile);
+			if(st)
+				attackedCres.insert(st);
+		}
+		else
+		{
+			for(int it=0; it<stacks.size(); ++it)
+			{
+				/*if it's non negative spell and our unit or non positive spell and hostile unit */
+				if((VLC->spellh->spells[s->id].positiveness >= 0 && stacks[it]->owner == caster->tempOwner)
+					||(VLC->spellh->spells[s->id].positiveness <= 0 && stacks[it]->owner != caster->tempOwner )
+					)
+				{
+					attackedCres.insert(stacks[it]);
+				}
+			}
+		} //if(caster->getSpellSchoolLevel(s) < 3)
+	}
+	else if(VLC->spellh->spells[s->id].attributes.find("CREATURE_TARGET") != std::string::npos) //spell to be cast on one specific creature
+	{
+		CStack * st = getStackT(destinationTile);
+		if(st)
+			attackedCres.insert(st);
+	}
+	else //custom range from attackedHexes
+	{
+		for(std::set<ui16>::iterator it = attackedHexes.begin(); it != attackedHexes.end(); ++it)
+		{
+			CStack * st = getStackT(*it);
+			if(st)
+				attackedCres.insert(st);
+		}
+	}
+	return attackedCres;
+}
+
 CStack * BattleInfo::getNextStack()
 {
 	CStack *current = getStack(activeStack);

+ 2 - 0
CGameState.h

@@ -46,6 +46,7 @@ class CPathfinder;
 struct SetObjectProperty;
 struct MetaString;
 struct CPack;
+class CSpell;
 
 
 std::string DLL_EXPORT toString(MetaString &ms);
@@ -137,6 +138,7 @@ struct DLL_EXPORT BattleInfo
 	static std::vector<int> neighbouringTiles(int hex);
 	static int calculateDmg(const CStack* attacker, const CStack* defender, const CGHeroInstance * attackerHero, const CGHeroInstance * defendingHero, bool shooting); //TODO: add additional conditions and require necessary data
 	void calculateCasualties(std::set<std::pair<ui32,si32> > *casualties);
+	std::set<CStack*> getAttackedCreatures(const CSpell * s, const CGHeroInstance * caster, int destinationTile); //calculates stack affected by given spell
 };
 
 class DLL_EXPORT CStack

+ 1 - 1
CPlayerInterface.cpp

@@ -4440,7 +4440,7 @@ CSystemOptionsWindow::CSystemOptionsWindow(const SDL_Rect &pos, CPlayerInterface
 	musicVolume = new CHighlightableButtonsGroup(0, true);
 	for(int i=1; i<=10; ++i)
 	{
-		musicVolume->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[359+i].first),CGI->generaltexth->zelp[359+i].second, "syslb.def", 188 + 19*(i-1), 415, i*10);
+		musicVolume->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[325+i].first),CGI->generaltexth->zelp[325+i].second, "syslb.def", 188 + 19*(i-1), 415, i*10);
 	}
 	musicVolume->select(CGI->audioh->getMusicVolume(), 1);
 	musicVolume->onChange = boost::bind(&CAudioHandler::setMusicVolume, CGI->audioh, _1);

+ 3 - 54
server/CGameHandler.cpp

@@ -2409,60 +2409,9 @@ bool CGameHandler::makeCustomAction( BattleAction &ba )
 			sc.tile = ba.destinationTile;
 			sendAndApply(&sc);
 
-			//calculating affected creatures for all spells ///////////////////
-			std::set<ui16> attackedHexes = s->rangeInHexes(ba.destinationTile, h->getSpellSchoolLevel(s));
-			std::set<CStack*> attackedCres; /*std::set to exclude multiple occurences of two hex creatures*/
-			if(ba.additionalInfo == 24 || ba.additionalInfo == 25 || ba.additionalInfo == 26) //death ripple, destroy undead and armageddon
-			{
-				for(int it=0; it<gs->curB->stacks.size(); ++it)
-				{
-					if((ba.additionalInfo == 24 && !gs->curB->stacks[it]->creature->isUndead()) //death ripple
-						|| (ba.additionalInfo == 25 && gs->curB->stacks[it]->creature->isUndead()) //destroy undead
-						|| (ba.additionalInfo == 26) //armageddon
-						)
-					{
-						attackedCres.insert(gs->curB->stacks[it]);
-					}
-				}
-			}
-			else if(VLC->spellh->spells[ba.additionalInfo].attributes.find("CREATURE_TARGET_2") != std::string::npos) //spell to be cast on a specific creature but massive on expert
-			{
-				if(h->getSpellSchoolLevel(s) < 3)  /*not expert */
-				{
-					CStack * st = gs->curB->getStackT(ba.destinationTile);
-					if(st)
-						attackedCres.insert(st);
-				}
-				else
-				{
-					for(int it=0; it<gs->curB->stacks.size(); ++it)
-					{
-						/*if it's non negative spell and our unit or non positive spell and hostile unit */
-						if((VLC->spellh->spells[ba.additionalInfo].positiveness >= 0 && gs->curB->stacks[it]->owner == h->tempOwner)
-							||(VLC->spellh->spells[ba.additionalInfo].positiveness <= 0 && gs->curB->stacks[it]->owner != h->tempOwner )
-							)
-						{
-							attackedCres.insert(gs->curB->stacks[it]);
-						}
-					}
-				} //if(h->getSpellSchoolLevel(s) < 3)
-			}
-			else if(VLC->spellh->spells[ba.additionalInfo].attributes.find("CREATURE_TARGET") != std::string::npos) //spell to be cast on one specific creature
-			{
-				CStack * st = gs->curB->getStackT(ba.destinationTile);
-				if(st)
-					attackedCres.insert(st);
-			}
-			else //custom range from attackedHexes
-			{
-				for(std::set<ui16>::iterator it = attackedHexes.begin(); it != attackedHexes.end(); ++it)
-				{
-					CStack * st = gs->curB->getStackT(*it);
-					if(st)
-						attackedCres.insert(st);
-				}
-			}
-			//affected creatures calculated
+			//calculating affected creatures for all spells
+			std::set<CStack*> attackedCres = gs->curB->getAttackedCreatures(s, h, ba.destinationTile);
+
 			//applying effects
 			switch(ba.additionalInfo) //spell id
 			{