Преглед изворни кода

* fixed bug in campaigns
* turned off artifacts.json creation
* minor changes

mateuszb пре 13 година
родитељ
комит
657ed41088
5 измењених фајлова са 43 додато и 34 уклоњено
  1. 14 1
      Global.h
  2. 7 7
      client/Client.cpp
  3. 16 16
      lib/CArtHandler.cpp
  4. 3 7
      lib/CCampaignHandler.cpp
  5. 3 3
      lib/CObjectHandler.cpp

+ 14 - 1
Global.h

@@ -371,7 +371,6 @@ namespace vstd
 		vec.erase(boost::remove_if(vec, pred),vec.end());
 	}
 
-	//set has its own order, so remove_if won't work. TODO - reuse for map
 	template<typename Elem, typename Predicate>
 	void erase_if(std::set<Elem> &setContainer, Predicate pred)
 	{
@@ -385,6 +384,20 @@ namespace vstd
 		}
 	}
 
+	//works for map and bmap, maybe something else
+	template<typename Key, typename Val, typename Predicate>
+	void erase_if(std::map<Key, Val> &container, Predicate pred)
+	{
+		auto itr = container.begin();
+		auto endItr = container.end(); 
+		while(itr != endItr)
+		{
+			auto tmpItr = itr++;
+			if(pred(*tmpItr))
+				container.erase(tmpItr);
+		}
+	}
+
 	template<typename InputRange, typename OutputIterator, typename Predicate>
 	OutputIterator copy_if(const InputRange &input, OutputIterator result, Predicate pred)
 	{

+ 7 - 7
client/Client.cpp

@@ -274,7 +274,7 @@ void CClient::loadGame( const std::string & fname )
 	{
 		*serv << ui8(it->first); //players
 	}
-	*serv << ui8(255); // neutrals
+	*serv << ui8(GameConstants::NEUTRAL_PLAYER);
 	tlog0 <<"Sent info to server: "<<tmh.getDiff()<<std::endl;
 
 	serv->enableStackSendingByID();
@@ -312,7 +312,7 @@ void CClient::newGame( CConnection *con, StartInfo *si )
 		}
 	}
 	if(networkMode != GUEST)
-		myPlayers.insert(255); //neutral
+		myPlayers.insert(GameConstants::NEUTRAL_PLAYER);
 
 	CStopWatch tmh;
 	const_cast<CGameInfo*>(CGI)->state = new CGameState();
@@ -466,7 +466,7 @@ void CClient::serialize( Handler &h, const int version )
 			CGameInterface *nInt = NULL;
 			if(dllname.length())
 			{
-				if(pid == 255)
+				if(pid == GameConstants::NEUTRAL_PLAYER)
 				{
 					//CBattleCallback * cbc = new CBattleCallback(gs, pid, this);//FIXME: unused?
 					CBattleGameInterface *cbgi = CDynLibHandler::getNewBattleAI(dllname);
@@ -617,10 +617,10 @@ void CClient::battleFinished()
 
 void CClient::loadNeutralBattleAI()
 {
-	battleints[255] = CDynLibHandler::getNewBattleAI(settings["server"]["neutralAI"].String());
-	auto cbc = make_shared<CBattleCallback>(gs, 255, this);
-	battleCallbacks[255] = cbc;
-	battleints[255]->init(cbc.get());
+	battleints[GameConstants::NEUTRAL_PLAYER] = CDynLibHandler::getNewBattleAI(settings["server"]["neutralAI"].String());
+	auto cbc = make_shared<CBattleCallback>(gs, GameConstants::NEUTRAL_PLAYER, this);
+	battleCallbacks[GameConstants::NEUTRAL_PLAYER] = cbc;
+	battleints[GameConstants::NEUTRAL_PLAYER]->init(cbc.get());
 }
 
 void CClient::commitPackage( CPackForClient *pack )

+ 16 - 16
lib/CArtHandler.cpp

@@ -910,22 +910,22 @@ void CArtHandler::addBonuses()
 		ART_PRIM_SKILL (154, 0, +6); //Hardened Shield
 	}
 
-	JsonNode cfg;
-	BOOST_FOREACH(auto art, artifacts)
-	{
-		JsonNode jn;
-		jn["id"].Float() = art->id;
-		BOOST_FOREACH (auto b, art->getBonusList())
-		{
-			JsonNode bn;
-			UnparseBonus(bn, b);
-			jn["bonuses"].Vector().push_back(bn);
-		}
-		cfg.Vector().push_back(jn);
-	}
-
-	std::ofstream artconfigOutput("config/artifacts.json");
- 	JsonWriter(artconfigOutput, cfg);
+// 	JsonNode cfg;
+// 	BOOST_FOREACH(auto art, artifacts)
+// 	{
+// 		JsonNode jn;
+// 		jn["id"].Float() = art->id;
+// 		BOOST_FOREACH (auto b, art->getBonusList())
+// 		{
+// 			JsonNode bn;
+// 			UnparseBonus(bn, b);
+// 			jn["bonuses"].Vector().push_back(bn);
+// 		}
+// 		cfg.Vector().push_back(jn);
+// 	}
+// 
+// 	std::ofstream artconfigOutput("config/artifacts.json");
+//  	JsonWriter(artconfigOutput, cfg);
 }
 
 void CArtHandler::clear()

+ 3 - 7
lib/CCampaignHandler.cpp

@@ -390,14 +390,10 @@ void CCampaignScenario::prepareCrossoverHeroes( std::vector<CGHeroInstance *> he
 	//trimming creatures
 	BOOST_FOREACH(CGHeroInstance * cgh, crossoverHeroes)
 	{
-		for (TSlots::const_iterator j = cgh->Slots().begin(); j != cgh->Slots().end(); j++)
+		vstd::erase_if(cgh->stacks, [&](const std::pair<TSlot, CStackInstance *> & j)
 		{
-			if (!(travelOptions.monstersKeptByHero[j->first / 8] & (1 << (j->first%8)) ))
-			{
-				cgh->eraseStack(j->first);
-				j = cgh->Slots().begin();
-			}
-		}
+			return !(travelOptions.monstersKeptByHero[j.first / 8] & (1 << (j.first%8)) );
+		});
 	}
 }
 

+ 3 - 3
lib/CObjectHandler.cpp

@@ -1535,7 +1535,7 @@ void CGDwelling::initObj()
 			hoverName = VLC->generaltexth->creGens[subID];
 			if(crs->level > 4)
 				putStack(0, new CStackInstance(crs, (crs->growth) * 3));
-			if (getOwner() != 255)
+			if (getOwner() != GameConstants::NEUTRAL_PLAYER)
 				cb->gameState()->players[getOwner()].dwellings.push_back (this);
 		}
 		break;
@@ -2167,7 +2167,7 @@ ui8 CGTownInstance::getPassableness() const
 {
 	if (!armedGarrison())//empty castle - anyone can visit
 		return GameConstants::ALL_PLAYERS;
-	if ( tempOwner == 255 )//neutral guarded - no one can visit
+	if ( tempOwner == GameConstants::NEUTRAL_PLAYER )//neutral guarded - no one can visit
 		return 0;
 
 	ui8 mask = 0;
@@ -5623,7 +5623,7 @@ ui8 CGGarrison::getPassableness() const
 {
 	if ( !stacksCount() )//empty - anyone can visit
 		return GameConstants::ALL_PLAYERS;
-	if ( tempOwner == 255 )//neutral guarded - no one can visit
+	if ( tempOwner == GameConstants::NEUTRAL_PLAYER )//neutral guarded - no one can visit
 		return 0;
 
 	ui8 mask = 0;