2
0
Эх сурвалжийг харах

* First Aid Tent won't get move
* presumably fixed crash occurring sometimes on battle end
* fixed problems when attacking with two-hex creature another two-hex creature, when tile before our destination was blocked
* minor changes

Michał W. Urbańczyk 16 жил өмнө
parent
commit
2710017049

+ 1 - 1
AI/GeniusAI/CGeniusAI.cpp

@@ -136,7 +136,7 @@ void CGeniusAI::battleNewRound(int round)
 /**
  *
  */
-void CGeniusAI::battleStackMoved(int ID, int dest)
+void CGeniusAI::battleStackMoved(int ID, int dest, int distance, bool end)
 {
 	std::string message("\t\t\tCGeniusAI::battleStackMoved ID(");
 	message += boost::lexical_cast<std::string>(ID);

+ 1 - 1
AI/GeniusAI/CGeniusAI.h

@@ -200,7 +200,7 @@ public:
 	virtual void battleStacksAttacked(std::set<BattleStackAttacked> & bsa); //called when stack receives damage (after battleAttack())
 	virtual void battleEnd(BattleResult *br);
 	virtual void battleNewRound(int round); //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn
-	virtual void battleStackMoved(int ID, int dest);
+	virtual void battleStackMoved(int ID, int dest, int distance, bool end);
 	virtual void battleSpellCasted(SpellCasted *sc);
 	virtual void battleStart(CCreatureSet *army1, CCreatureSet *army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, bool side); //called by engine when battle starts; side=0 - left, side=1 - right
 	virtual void battlefieldPrepared(int battlefieldType, std::vector<CObstacle*> obstacles); //called when battlefield is prepared, prior the battle beginning

+ 3 - 3
CGameInterface.h

@@ -69,8 +69,8 @@ public:
 	virtual void init(ICallback * CB){};
 	virtual void receivedResource(int type, int val){};
 	virtual void showInfoDialog(const std::string &text, const std::vector<Component*> &components){};
-	virtual void showSelDialog(std::string &text, const std::vector<Component*> &components, ui32 askID){};
-	virtual void showYesNoDialog(std::string &text, const std::vector<Component*> &components, ui32 askID){};
+	virtual void showSelDialog(const std::string &text, const std::vector<Component*> &components, ui32 askID){};
+	virtual void showYesNoDialog(const std::string &text, const std::vector<Component*> &components, ui32 askID){};
 	virtual void tileHidden(const std::set<int3> &pos){};
 	virtual void tileRevealed(const std::set<int3> &pos){};
 	virtual void yourTurn(){};
@@ -87,7 +87,7 @@ public:
 	virtual void battleStacksAttacked(std::set<BattleStackAttacked> & bsa){}; //called when stack receives damage (after battleAttack())
 	virtual void battleEnd(BattleResult *br){};
 	virtual void battleNewRound(int round){}; //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn
-	virtual void battleStackMoved(int ID, int dest, int distance){};
+	virtual void battleStackMoved(int ID, int dest, int distance, bool end){};
 	virtual void battleSpellCasted(SpellCasted *sc){};
 	virtual void battleStacksEffectsSet(SetStackEffect & sse){};//called when a specific effect is set to stacks
 	virtual void battleStart(CCreatureSet *army1, CCreatureSet *army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, bool side){}; //called by engine when battle starts; side=0 - left, side=1 - right

+ 8 - 8
CPlayerInterface.cpp

@@ -2018,7 +2018,7 @@ void CPlayerInterface::receivedResource(int type, int val)
 		castleInt->resdatabar->draw();
 }
 
-void CPlayerInterface::showSelDialog(std::string &text, const std::vector<Component*> &components, ui32 askID)
+void CPlayerInterface::showSelDialog(const std::string &text, const std::vector<Component*> &components, ui32 askID)
 //void CPlayerInterface::showSelDialog(std::string text, std::vector<CSelectableComponent*> & components, int askID)
 {
 	boost::unique_lock<boost::recursive_mutex> un(*pim);
@@ -2301,10 +2301,10 @@ void CPlayerInterface::battleResultQuited()
 	LOCPLINT->showingDialog->setn(false);
 }
 
-void CPlayerInterface::battleStackMoved(int ID, int dest, int distance)
+void CPlayerInterface::battleStackMoved(int ID, int dest, int distance, bool end)
 {
 	boost::unique_lock<boost::recursive_mutex> un(*pim);
-	battleInt->stackMoved(ID, dest, dest==curAction->destinationTile, distance);
+	battleInt->stackMoved(ID, dest, end, distance);
 }
 void CPlayerInterface::battleSpellCasted(SpellCasted *sc)
 {
@@ -2391,7 +2391,7 @@ void CPlayerInterface::showInfoDialog(const std::string &text, const std::vector
 
 	std::vector<std::pair<std::string,CFunctionList<void()> > > pom;
 	pom.push_back(std::pair<std::string,CFunctionList<void()> >("IOKAY.DEF",0));
-	CInfoWindow * temp = new CInfoWindow(text,playerID,32,components,pom);
+	CInfoWindow * temp = new CInfoWindow(text,playerID,36,components,pom);
 
 	if(makingTurn && curint)
 	{
@@ -2409,7 +2409,7 @@ void CPlayerInterface::showInfoDialog(const std::string &text, const std::vector
 		dialogs.push_back(temp);
 	}
 }
-void CPlayerInterface::showYesNoDialog(std::string &text, const std::vector<SComponent*> & components, CFunctionList<void()> onYes, CFunctionList<void()> onNo, bool deactivateCur, bool DelComps)
+void CPlayerInterface::showYesNoDialog(const std::string &text, const std::vector<SComponent*> & components, CFunctionList<void()> onYes, CFunctionList<void()> onNo, bool deactivateCur, bool DelComps)
 {
 	boost::unique_lock<boost::recursive_mutex> un(*pim);
 	LOCPLINT->showingDialog->setn(true);
@@ -2418,7 +2418,7 @@ void CPlayerInterface::showYesNoDialog(std::string &text, const std::vector<SCom
 	std::vector<std::pair<std::string,CFunctionList<void()> > > pom;
 	pom.push_back(std::pair<std::string,CFunctionList<void()> >("IOKAY.DEF",0));
 	pom.push_back(std::pair<std::string,CFunctionList<void()> >("ICANCEL.DEF",0));
-	CInfoWindow * temp = new CInfoWindow(text,playerID,32,components,pom);
+	CInfoWindow * temp = new CInfoWindow(text,playerID,36,components,pom);
 	temp->delComps = DelComps;
 	for(int i=0;i<onYes.funcs.size();i++)
 		temp->buttons[0]->callback += onYes.funcs[i];
@@ -2433,7 +2433,7 @@ void CPlayerInterface::showYesNoDialog(std::string &text, const std::vector<SCom
 	LOCPLINT->objsToBlit.push_back(temp);
 }
 
-void CPlayerInterface::showYesNoDialog( std::string &text, const std::vector<Component*> &components, ui32 askID )
+void CPlayerInterface::showYesNoDialog(const  std::string &text, const std::vector<Component*> &components, ui32 askID )
 {
 	boost::unique_lock<boost::recursive_mutex> un(*pim);
 	LOCPLINT->showingDialog->setn(false);
@@ -2446,7 +2446,7 @@ void CPlayerInterface::showYesNoDialog( std::string &text, const std::vector<Com
 	pom.push_back(std::pair<std::string,CFunctionList<void()> >("IOKAY.DEF",0));
 	pom.push_back(std::pair<std::string,CFunctionList<void()> >("ICANCEL.DEF",0));
 
-	CInfoWindow * temp = new CInfoWindow(text,playerID,32,intComps,pom);
+	CInfoWindow * temp = new CInfoWindow(text,playerID,36,intComps,pom);
 	temp->buttons[0]->callback += boost::bind(&IActivable::activate,curint);
 	temp->buttons[1]->callback += boost::bind(&IActivable::activate,curint);
 	temp->buttons[0]->callback += boost::bind(&CCallback::selectionMade,cb,0,askID);

+ 4 - 4
CPlayerInterface.h

@@ -539,8 +539,8 @@ public:
 	void heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town);
 	void receivedResource(int type, int val);
 	void showInfoDialog(const std::string &text, const std::vector<Component*> &components);
-	void showSelDialog(std::string &text, const std::vector<Component*> &components, ui32 askID);
-	void showYesNoDialog(std::string &text, const std::vector<Component*> &components, ui32 askID);
+	void showSelDialog(const std::string &text, const std::vector<Component*> &components, ui32 askID);
+	void showYesNoDialog(const std::string &text, const std::vector<Component*> &components, ui32 askID);
 	void tileHidden(const std::set<int3> &pos);
 	void tileRevealed(const std::set<int3> &pos);
 	void yourTurn();
@@ -557,7 +557,7 @@ public:
 	void battleEnd(BattleResult *br); //end of battle
 	void battleResultQuited();
 	void battleNewRound(int round); //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn
-	void battleStackMoved(int ID, int dest, int distance);
+	void battleStackMoved(int ID, int dest, int distance, bool end);
 	void battleSpellCasted(SpellCasted *sc);
 	void battleStacksEffectsSet(SetStackEffect & sse); //called when a specific effect is set to stacks
 	void battleStacksAttacked(std::set<BattleStackAttacked> & bsa);
@@ -581,7 +581,7 @@ public:
 	int3 repairScreenPos(int3 pos); //returns position closest to pos we can center screen on
 	void removeObjToBlit(IShowable* obj);
 	void showInfoDialog(const std::string &text, const std::vector<SComponent*> & components, bool deactivateCur=true);
-	void showYesNoDialog(std::string &text, const std::vector<SComponent*> & components, CFunctionList<void()> onYes, CFunctionList<void()> onNo, bool deactivateCur, bool DelComps); //deactivateCur - whether current main interface should be deactivated; delComps - if components will be deleted on window close
+	void showYesNoDialog(const std::string &text, const std::vector<SComponent*> & components, CFunctionList<void()> onYes, CFunctionList<void()> onNo, bool deactivateCur, bool DelComps); //deactivateCur - whether current main interface should be deactivated; delComps - if components will be deleted on window close
 	bool moveHero(const CGHeroInstance *h, CPath * path);
 
 	CPlayerInterface(int Player, int serial);//c-tor

+ 2 - 2
client/NetPacksClient.cpp

@@ -330,8 +330,8 @@ void BattleResult::applyFirstCl( CClient *cl )
 
 void BattleStackMoved::applyFirstCl( CClient *cl )
 {
-	INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side1,battleStackMoved,stack,tile,distance);
-	INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side2,battleStackMoved,stack,tile,distance);
+	INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side1,battleStackMoved,stack,tile,distance,ending);
+	INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side2,battleStackMoved,stack,tile,distance,ending);
 }
 
 void BattleStackAttacked::applyCl( CClient *cl )

+ 2 - 1
hch/CCreatureHandler.cpp

@@ -464,8 +464,9 @@ void CCreatureHandler::loadCreatures()
 
 	creatures[47].abilities += MULTI_HEAD_ATTACK; //cerberus
 
-	creatures[88].abilities += TWICE_ATTACK; //wolf raider
+	creatures[87].abilities += TWICE_ATTACK; //wolf raider
 
+	creatures[147].abilities += NOT_ACTIVE; //First Aid Tent //TODO: remove when support is added
 	creatures[148].abilities += NOT_ACTIVE; //Ammo Cart
 }
 

+ 3 - 2
lib/NetPacks.h

@@ -647,13 +647,14 @@ struct BattleResult : public CPackForClient//3003
 
 struct BattleStackMoved : public CPackForClient//3004
 {
-	ui32 stack, tile, distance;
+	ui32 stack, tile;
+	ui8 ending, distance;
 	BattleStackMoved(){type = 3004;};
 	void applyFirstCl(CClient *cl);
 	void applyGs(CGameState *gs);
 	template <typename Handler> void serialize(Handler &h, const int version)
 	{
-		h & stack & tile & distance;
+		h & stack & tile & ending & distance;
 	}
 };
 

+ 0 - 9
map.cpp

@@ -1041,15 +1041,6 @@ void Mapa::readHeader( unsigned char * bufor, int &i)
 			for (int zz=0; zz<lenbuf; zz++)
 				disposedHeroes[g].name+=bufor[i++];
 			disposedHeroes[g].players = bufor[i++];
-			//int players = bufor[i++];
-			//for(int zz=0;zz<8;zz++)
-			//{
-			//	int por = (1<<zz);
-			//	if(players & por)
-			//		disposedHeroes[g].players[zz] = true;
-			//	else 
-			//		disposedHeroes[g].players[zz] = false;
-			//}
 		}
 	}
 

+ 11 - 82
server/CGameHandler.cpp

@@ -114,17 +114,7 @@ void giveExp(BattleResult &r)
 		r.exp[r.winner] += VLC->creh->creatures[i->first].hitPoints * i->second;
 	}
 }
-//bool CGameState::checkFunc(int obid, std::string name)
-//{
-//	if (objscr.find(obid)!=objscr.end())
-//	{
-//		if(objscr[obid].find(name)!=objscr[obid].end())
-//		{
-//			return true;
-//		}
-//	}
-//	return false;
-//}
+
 PlayerStatus PlayerStatuses::operator[](ui8 player)
 {
 	boost::unique_lock<boost::mutex> l(mx);
@@ -205,15 +195,7 @@ void PlayerStatuses::removeQuery(ui8 player, ui32 id)
 	}
 	cv.notify_all();
 }
-//void CGameHandler::handleCPPObjS(std::map<int,CCPPObjectScript*> * mapa, CCPPObjectScript * script)
-//{
-//	std::vector<int> tempv = script->yourObjects();
-//	for (unsigned i=0;i<tempv.size();i++)
-//	{
-//		(*mapa)[tempv[i]]=script;
-//	}
-//	cppscripts.insert(script);
-//}
+
 template <typename T>
 void callWith(std::vector<T> args, boost::function<void(T)> fun, ui32 which)
 {
@@ -387,6 +369,7 @@ void CGameHandler::startBattle(CCreatureSet army1, CCreatureSet army2, int3 tile
 
 askInterfaceForMove:
 			//ask interface and wait for answer
+			if(!battleResult.get())
 			{
 				BattleSetActiveStack sas;
 				sas.stack = next->ID;
@@ -396,6 +379,11 @@ askInterfaceForMove:
 					battleMadeAction.cond.wait(lock);
 				battleMadeAction.data = false;
 			}
+			else
+			{
+				break;
+			}
+
 			//we're after action, all results applied
 			checkForBattleEnd(stacks); //check if this action ended the battle
 
@@ -571,6 +559,7 @@ void CGameHandler::moveStack(int stack, int dest)
 			sm.stack = curStack->ID;
 			sm.tile = path.first[0];
 			sm.distance = path.second;
+			sm.ending = true;
 			sendAndApply(&sm);
 		}
 	}
@@ -584,6 +573,7 @@ void CGameHandler::moveStack(int stack, int dest)
 			sm.stack = curStack->ID;
 			sm.tile = path.first[v];
 			sm.distance = path.second;
+			sm.ending = v==tilesToMove;
 			sendAndApply(&sm);
 		}
 	}
@@ -610,32 +600,6 @@ void CGameHandler::init(StartInfo *si, int Seed)
 	gs->init(si,map,Seed);	
 	tlog0 << "Gamestate initialized!" << std::endl;
 
-	/****************************LUA OBJECT SCRIPTS************************************************/
-	//std::vector<std::string> * lf = CLuaHandler::searchForScripts("scripts/lua/objects"); //files
-	//for (int i=0; i<lf->size(); i++)
-	//{
-	//	try
-	//	{
-	//		std::vector<std::string> * temp =  CLuaHandler::functionList((*lf)[i]);
-	//		CLuaObjectScript * objs = new CLuaObjectScript((*lf)[i]);
-	//		CLuaCallback::registerFuncs(objs->is);
-	//		//objs
-	//		for (int j=0; j<temp->size(); j++)
-	//		{
-	//			int obid ; //obj ID
-	//			int dspos = (*temp)[j].find_first_of('_');
-	//			obid = atoi((*temp)[j].substr(dspos+1,(*temp)[j].size()-dspos-1).c_str());
-	//			std::string fname = (*temp)[j].substr(0,dspos);
-	//			if (skrypty->find(obid)==skrypty->end())
-	//				skrypty->insert(std::pair<int, std::map<std::string, CObjectScript*> >(obid,std::map<std::string,CObjectScript*>()));
-	//			(*skrypty)[obid].insert(std::pair<std::string, CObjectScript*>(fname,objs));
-	//		}
-	//		delete temp;
-	//	}HANDLE_EXCEPTION
-	//}
-
-	//delete lf;
-
 	for(std::map<ui8,PlayerState>::iterator i = gs->players.begin(); i != gs->players.end(); i++)
 		states.addPlayer(i->first);
 }
@@ -768,42 +732,6 @@ void CGameHandler::run(bool resume)
 		boost::thread(boost::bind(&CGameHandler::handleConnection,this,pom,boost::ref(**i)));
 	}
 
-	/****************************SCRIPTS************************************************/
-	//std::map<int, std::map<std::string, CObjectScript*> > * skrypty = &objscr; //alias for easier access
-	/****************************C++ OBJECT SCRIPTS************************************************/
-	//std::map<int,CCPPObjectScript*> scripts;
-	//CScriptCallback * csc = new CScriptCallback();
-	//csc->gh = this;
-	//handleCPPObjS(&scripts,new CVisitableOPH(csc));
-	//handleCPPObjS(&scripts,new CVisitableOPW(csc));
-	//handleCPPObjS(&scripts,new CPickable(csc));
-	//handleCPPObjS(&scripts,new CMines(csc));
-	//handleCPPObjS(&scripts,new CTownScript(csc));
-	//handleCPPObjS(&scripts,new CHeroScript(csc));
-	//handleCPPObjS(&scripts,new CMonsterS(csc));
-	//handleCPPObjS(&scripts,new CCreatureGen(csc));
-	//handleCPPObjS(&scripts,new CTeleports(csc));
-
-	/****************************INITIALIZING OBJECT SCRIPTS************************************************/
-	//std::string temps("newObject");
-	//for (unsigned i=0; i<gs->map->objects.size(); i++)
-	//{
-		//c++ scripts
-		//if (scripts.find(gs->map->objects[i]->ID) != scripts.end())
-		//{
-		//	gs->map->objects[i]->state = scripts[gs->map->objects[i]->ID];
-		//	gs->map->objects[i]->state->newObject(gs->map->objects[i]->id);
-		//}
-		//else 
-		//{
-		//	gs->map->objects[i]->state = NULL;
-		//}
-
-		//// lua scripts
-		//if(checkFunc(map->objects[i]->ID,temps))
-		//	(*skrypty)[map->objects[i]->ID][temps]->newObject(map->objects[i]);
-	//}
-
 	while (!end2)
 	{
 		if(!resume)
@@ -1450,6 +1378,7 @@ void CGameHandler::ask( Query * sel, ui8 player, const CFunctionList<void(ui32)>
 
 void CGameHandler::sendToAllClients( CPackForClient * info )
 {
+	tlog5 << "Sending to all clients a package of type " << typeid(*info).name() << std::endl;
 	for(std::set<CConnection*>::iterator i=conns.begin(); i!=conns.end();i++)
 	{
 		(*i)->wmx->lock();