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

Fixed #768. More logging for #774.
Fixed crash on town time event (-1 and -2 "structures" present on buildings list).

Michał W. Urbańczyk пре 14 година
родитељ
комит
4c3ed24fe1
8 измењених фајлова са 25 додато и 14 уклоњено
  1. 1 0
      CCallback.cpp
  2. 0 1
      client/CPlayerInterface.cpp
  3. 1 0
      client/Client.h
  4. 2 1
      client/NetPacksClient.cpp
  5. 1 1
      lib/CCreatureHandler.h
  6. 8 5
      lib/CGameState.cpp
  7. 8 5
      lib/map.cpp
  8. 4 1
      server/CGameHandler.cpp

+ 1 - 0
CCallback.cpp

@@ -363,6 +363,7 @@ CBattleCallback::CBattleCallback(CGameState *GS, int Player, CClient *C )
 
 bool CBattleCallback::battleMakeTacticAction( BattleAction * action )
 {
+	assert(cl->gs->curB->tacticDistance);
 	MakeAction ma;
 	ma.ba = *action;
 	sendRequest(&ma);

+ 0 - 1
client/CPlayerInterface.cpp

@@ -1334,7 +1334,6 @@ void CPlayerInterface::showShipyardDialog(const IShipyard *obj)
 void CPlayerInterface::newObject( const CGObjectInstance * obj )
 {
 	boost::unique_lock<boost::recursive_mutex> un(*pim);
-	CGI->mh->printObject(obj);
 	//we might have built a boat in shipyard in opened town screen
 	if(obj->ID == 8
 		&& LOCPLINT->castleInt

+ 1 - 0
client/Client.h

@@ -161,6 +161,7 @@ public:
 
 	//////////////////////////////////////////////////////////////////////////
 	friend class CCallback; //handling players actions
+	friend class CBattleCallback; //handling players actions
 	friend void processCommand(const std::string &message, CClient *&client); //handling console
 	
 	void handlePack( CPack * pack ); //applies the given pack and deletes it

+ 2 - 1
client/NetPacksClient.cpp

@@ -864,7 +864,8 @@ void NewObject::applyCl(CClient *cl)
 	cl->updatePaths();
 
 	const CGObjectInstance *obj = cl->getObj(id);
-	//notify interfaces about move
+	CGI->mh->printObject(obj);
+
 	for(std::map<ui8, CGameInterface*>::iterator i=cl->playerint.begin();i!=cl->playerint.end();i++)
 	{
 		//TODO: check if any covered tile is visible

+ 1 - 1
lib/CCreatureHandler.h

@@ -68,7 +68,7 @@ public:
 	//void getParents(TCNodes &out, const CBonusSystemNode *root /*= NULL*/) const;
 
 	template<typename RanGen>
-	int getRandomAmount(RanGen &ranGen)
+	int getRandomAmount(RanGen &ranGen) const
 	{
 		if(ammMax == ammMin)
 			return ammMax;

+ 8 - 5
lib/CGameState.cpp

@@ -1466,16 +1466,19 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed )
 				}
 			}
 			
-		for (std::list<CCastleEvent*>::iterator ev=vti->events.begin(); ev!=vti->events.end(); ev++)
+		//town events
+		BOOST_FOREACH(CCastleEvent *ev, vti->events)
+		{
 			for (int i = 0; i<CREATURES_PER_TOWN; i++)
-				if (vstd::contains((*ev)->buildings,(-31-i))) //if we have horde for this level
+				if (vstd::contains(ev->buildings,(-31-i))) //if we have horde for this level
 				{
-					(*ev)->buildings.erase(-31-i);
+					ev->buildings.erase(-31-i);
 					if (vti->town->hordeLvl[0] == i)
-						(*ev)->buildings.insert(18);
+						ev->buildings.insert(18);
 					if (vti->town->hordeLvl[1] == i)
-						(*ev)->buildings.insert(24);
+						ev->buildings.insert(24);
 				}
+		}
 		//init spells
 		vti->spells.resize(SPELL_LEVELS);
 		CSpell *s;

+ 8 - 5
lib/map.cpp

@@ -24,7 +24,7 @@
  *
  */
 
-static std::set<si32> convertBuildings(const std::set<si32> h3m, int castleID)
+static std::set<si32> convertBuildings(const std::set<si32> h3m, int castleID, bool addAuxiliary = true)
 {
 	std::map<int,int> mapa;
 	std::set<si32> ret;
@@ -51,9 +51,12 @@ static std::set<si32> convertBuildings(const std::set<si32> h3m, int castleID)
 		}
 	}
 
-	ret.insert(10); //village hall is always present
-	ret.insert(-1); //houses near v.hall / eyecandies
-	ret.insert(-2); //terrain eyecandy, if -1 is used
+	if(addAuxiliary)
+	{
+		ret.insert(10); //village hall is always present
+		ret.insert(-1); //houses near v.hall / eyecandies
+		ret.insert(-2); //terrain eyecandy, if -1 is used
+	}
 
 	if(ret.find(11)!=ret.end())
 		ret.insert(27);
@@ -752,7 +755,7 @@ void Mapa::loadTown( CGObjectInstance * &nobj, const unsigned char * bufor, int
 					nce->buildings.insert(byte*8+bit);
 			i++;
 		}
-		nce->buildings = convertBuildings(nce->buildings,subid);
+		nce->buildings = convertBuildings(nce->buildings,subid, false);
 		
 		nce->creatures.resize(7);
 		for(int vv=0; vv<7; ++vv)

+ 4 - 1
server/CGameHandler.cpp

@@ -1049,10 +1049,13 @@ void CGameHandler::newTurn()
 			getFreeTiles(tiles);
 			ui32 amount = (tiles.size()) >> 6;
 			std::random_shuffle(tiles.begin(), tiles.end(), p_myrandom);
+			tlog5 << "Spawning wandering monsters. Found " << tiles.size() << " free tiles. Creature type: " << n.creatureid << std::endl;
+			const CCreature *cre = VLC->creh->creatures[n.creatureid];
 			for (int i = 0; i < amount; ++i)
 			{
 				tile = tiles.begin();
-				putNewMonster(n.creatureid, VLC->creh->creatures[n.creatureid]->getRandomAmount(std::rand), *tile);
+				tlog5 << "\tSpawning monster at " << *tile << std::endl;
+				putNewMonster(n.creatureid, cre->getRandomAmount(std::rand), *tile);
 				tiles.erase(tile); //not use it again
 			}
 		}