Selaa lähdekoodia

Mostly fixed battle animations.
Added proper ending for duel mode.

Michał W. Urbańczyk 15 vuotta sitten
vanhempi
sitoutus
c1bd81abdd

+ 1 - 1
AI/StupidAI/StupidAI.cpp

@@ -99,7 +99,7 @@ static bool willSecondHexBlockMoreEnemyShooters(const THex &h1, const THex &h2)
 
 BattleAction CStupidAI::activeStack( const CStack * stack )
 {
-	boost::this_thread::sleep(boost::posix_time::seconds(2));
+	//boost::this_thread::sleep(boost::posix_time::seconds(2));
 	print("activeStack called");
 	std::vector<THex> avHexes = cb->battleGetAvailableHexes(stack, false);
 	std::vector<int> dists = cb->battleGetDistances(stack);

+ 17 - 0
client/CBattleInterface.cpp

@@ -2254,6 +2254,7 @@ void CBattleInterface::stackActivated(const CStack * stack)
 void CBattleInterface::stackMoved(const CStack * stack, THex destHex, bool endMoving, int distance)
 {
 	addNewAnim(new CBattleStackMoved(this, stack, destHex, endMoving, distance));
+	waitForAnims();
 }
 
 void CBattleInterface::stacksAreAttacked(std::vector<SStackAttackedInfo> attackedInfos)
@@ -2262,6 +2263,7 @@ void CBattleInterface::stacksAreAttacked(std::vector<SStackAttackedInfo> attacke
 	{
 		addNewAnim(new CDefenceAnim(attackedInfos[h], this));
 	}
+	waitForAnims();
 }
 
 void CBattleInterface::stackAttacking( const CStack * attacker, THex dest, const CStack * attacked, bool shooting )
@@ -2274,6 +2276,7 @@ void CBattleInterface::stackAttacking( const CStack * attacker, THex dest, const
 	{
 		addNewAnim(new CMeleeAttack(this, attacker, dest, attacked));
 	}
+	waitForAnims();
 }
 
 void CBattleInterface::newRoundFirst( int round )
@@ -2297,6 +2300,7 @@ void CBattleInterface::newRoundFirst( int round )
 		if( s->hasBonusOfType(Bonus::FULL_HP_REGENERATION, 1) && s->alive() )
 			displayEffect(74, s->position);
 	}
+	waitForAnims();
 }
 
 void CBattleInterface::newRound(int number)
@@ -2645,6 +2649,7 @@ void CBattleInterface::stackIsCatapulting(const CatapultAttack & ca)
 		siegeH->walls[it->first.first + 2] = BitmapHandler::loadBitmap(
 			siegeH->getSiegeName(it->first.first + 2, curInt->cb->battleGetWallState(it->first.first)) );
 	}
+	waitForAnims();
 }
 
 void CBattleInterface::battleFinished(const BattleResult& br)
@@ -2798,6 +2803,7 @@ void CBattleInterface::spellCast( const BattleSpellCast * sc )
 		boost::algorithm::replace_first(dmgInfo, "%d", boost::lexical_cast<std::string>(sc->dmgToDisplay));
 		console->addText(dmgInfo);
 	}
+	waitForAnims();
 }
 
 void CBattleInterface::battleStacksEffectsSet(const SetStackEffect & sse)
@@ -3343,6 +3349,12 @@ void CBattleInterface::startAction(const BattleAction* action)
 	}
 }
 
+void CBattleInterface::waitForAnims()
+{
+	LOCPLINT->pim->unlock();
+	animsAreDisplayed.waitWhileTrue();
+	LOCPLINT->pim->lock();
+}
 
 void CBattleHero::show(SDL_Surface *to)
 {
@@ -3891,6 +3903,11 @@ void CBattleResultWindow::show(SDL_Surface *to)
 
 void CBattleResultWindow::bExitf()
 {
+	if(LOCPLINT->cb->getStartInfo()->mode == StartInfo::DUEL)
+	{
+		std::exit(0);
+	}
+
 	CPlayerInterface * intTmp = owner->curInt;
 	GH.popInts(2); //first - we; second - battle interface
 	intTmp->showingDialog->setn(false);

+ 1 - 0
client/CBattleInterface.h

@@ -494,6 +494,7 @@ public:
 	void stackRemoved(const CStack * stack); //stack disappeared from batlefiled
 	void stackActivated(const CStack * stack); //active stack has been changed
 	void stackMoved(const CStack * stack, THex destHex, bool endMoving, int distance); //stack with id number moved to destHex
+	void waitForAnims();
 	void stacksAreAttacked(std::vector<SStackAttackedInfo> attackedInfos); //called when a certain amount of stacks has been attacked
 	void stackAttacking(const CStack * attacker, THex dest, const CStack * attacked, bool shooting); //called when stack with id ID is attacking something on hex dest
 	void newRoundFirst( int round );

+ 1 - 1
client/CMT.cpp

@@ -490,9 +490,9 @@ void playIntro()
 
 void dispose()
 {
-	delete logfile;
 	if (console)
 		delete console;
+	delete logfile;
 }
 
 static void setScreenRes(int w, int h, int bpp, bool fullscreen)

+ 9 - 1
client/NetPacksClient.cpp

@@ -605,7 +605,15 @@ void StacksInjured::applyCl( CClient *cl )
 
 void BattleResultsApplied::applyCl( CClient *cl )
 {
-	BATTLE_INTERFACE_CALL_IF_PRESENT_FOR_BOTH_SIDES(battleResultsApplied);
+	INTERFACE_CALL_IF_PRESENT(player1, battleResultsApplied);
+	INTERFACE_CALL_IF_PRESENT(player2, battleResultsApplied);
+	INTERFACE_CALL_IF_PRESENT(254, battleResultsApplied);
+	if(GS(cl)->initialOpts->mode == StartInfo::DUEL)
+	{
+		cl->terminate = true;
+		CloseServer cs;
+		*cl->serv << &cs;
+	}
 }
 
 void StacksHealedOrResurrected::applyCl( CClient *cl )

+ 2 - 1
lib/CGameState.cpp

@@ -906,11 +906,12 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed )
 			h->initHero(1);
 			h->initObj();
 			h->setCreature(0, 110, 1);
+			h->setCreature(1, 69, 61);
 
 			CGCreature *c = new CGCreature();
 			c->setOwner(1);
 			c->putStack(0, new CStackInstance(69, 6));
-			c->putStack(1, new CStackInstance(11, 3));
+			//c->putStack(1, new CStackInstance(11, 3));
 			c->subID = 34;
 			c->initObj();
 

+ 44 - 21
server/CGameHandler.cpp

@@ -318,6 +318,7 @@ void CGameHandler::startBattle( const CArmedInstance *armies[2], int3 tile, cons
 
 void CGameHandler::endBattle(int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2)
 {
+	bool duel = gs->initialOpts->mode == StartInfo::DUEL;
 	BattleResultsApplied resultsApplied;
 
 	const CArmedInstance *bEndArmy1 = gs->curB->belligerents[0];
@@ -325,11 +326,14 @@ void CGameHandler::endBattle(int3 tile, const CGHeroInstance *hero1, const CGHer
 	resultsApplied.player1 = bEndArmy1->tempOwner;
 	resultsApplied.player2 = bEndArmy2->tempOwner;
 
-	//unblock engaged players
-	if(bEndArmy1->tempOwner<PLAYER_LIMIT)
-		states.setFlag(bEndArmy1->tempOwner, &PlayerStatus::engagedIntoBattle, false);
-	if(bEndArmy2 && bEndArmy2->tempOwner<PLAYER_LIMIT)
-		states.setFlag(bEndArmy2->tempOwner, &PlayerStatus::engagedIntoBattle, false);	
+	if(!duel)
+	{
+		//unblock engaged players
+		if(bEndArmy1->tempOwner<PLAYER_LIMIT)
+			states.setFlag(bEndArmy1->tempOwner, &PlayerStatus::engagedIntoBattle, false);
+		if(bEndArmy2 && bEndArmy2->tempOwner<PLAYER_LIMIT)
+			states.setFlag(bEndArmy2->tempOwner, &PlayerStatus::engagedIntoBattle, false);	
+	}
 
 	//end battle, remove all info, free memory
 	giveExp(*battleResult.data);
@@ -345,25 +349,29 @@ void CGameHandler::endBattle(int3 tile, const CGHeroInstance *hero1, const CGHer
 
 	CasualtiesAfterBattle cab1(bEndArmy1, gs->curB), cab2(bEndArmy2, gs->curB); //calculate casualties before deleting battle
 	sendAndApply(battleResult.data);
-	cab1.takeFromArmy(this); cab2.takeFromArmy(this); //take casualties after battle is deleted
 
-	//if one hero has lost we will erase him
-	if(battleResult.data->winner!=0 && hero1)
-	{
-		RemoveObject ro(hero1->id);
-		sendAndApply(&ro);
-	}
-	if(battleResult.data->winner!=1 && hero2)
+	if(!duel)
 	{
-		RemoveObject ro(hero2->id);
-		sendAndApply(&ro);
-	}
+		cab1.takeFromArmy(this); cab2.takeFromArmy(this); //take casualties after battle is deleted
+
+		//if one hero has lost we will erase him
+		if(battleResult.data->winner!=0 && hero1)
+		{
+			RemoveObject ro(hero1->id);
+			sendAndApply(&ro);
+		}
+		if(battleResult.data->winner!=1 && hero2)
+		{
+			RemoveObject ro(hero2->id);
+			sendAndApply(&ro);
+		}
 
-	//give exp
-	if(battleResult.data->exp[0] && hero1)
-		changePrimSkill(hero1->id,4,battleResult.data->exp[0]);
-	if(battleResult.data->exp[1] && hero2)
-		changePrimSkill(hero2->id,4,battleResult.data->exp[1]);
+		//give exp
+		if(battleResult.data->exp[0] && hero1)
+			changePrimSkill(hero1->id,4,battleResult.data->exp[0]);
+		if(battleResult.data->exp[1] && hero2)
+			changePrimSkill(hero2->id,4,battleResult.data->exp[1]);
+	}
 
 	sendAndApply(&resultsApplied);
 
@@ -374,6 +382,14 @@ void CGameHandler::endBattle(int3 tile, const CGHeroInstance *hero1, const CGHer
 		battleEndCallback = 0;
 	}
 
+
+	if(duel)
+	{
+		CSaveFile resultFile("result.vdrst");
+		resultFile << battleResult.data;
+		return;
+	}
+
 	// Necromancy if applicable.
 	const CGHeroInstance *winnerHero = battleResult.data->winner != 0 ? hero2 : hero1;
 	const CGHeroInstance *loserHero = battleResult.data->winner != 0 ? hero1 : hero2;
@@ -645,6 +661,7 @@ CGameHandler::CGameHandler(void)
 	applier = new CApplier<CBaseForGHApply>;
 	registerTypes3(*applier);
 	visitObjectAfterVictory = false; 
+	battleEndCallback = NULL;
 }
 
 CGameHandler::~CGameHandler(void)
@@ -1934,6 +1951,12 @@ void CGameHandler::save( const std::string &fname )
 void CGameHandler::close()
 {
 	tlog0 << "We have been requested to close.\n";	
+
+	if(gs->initialOpts->mode == StartInfo::DUEL)
+	{
+		exit(0);
+	}
+
 	//BOOST_FOREACH(CConnection *cc, conns)
 	//	if(cc && cc->socket && cc->socket->is_open())
 	//		cc->socket->close();