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

* more developed battle console (spell destination select info, shoot info, move/fly info)
* removed crash when siege weapon is attacked
* corrected animation of defender's two-hex creature reverse

mateuszb 16 жил өмнө
parent
commit
5c51992294

+ 27 - 8
AdventureMapButton.cpp

@@ -8,6 +8,7 @@
 #include "CCallback.h"
 #include "CCallback.h"
 #include "client/CConfigHandler.h"
 #include "client/CConfigHandler.h"
 #include "client/Graphics.h"
 #include "client/Graphics.h"
+#include "CBattleInterface.h"
 AdventureMapButton::AdventureMapButton ()
 AdventureMapButton::AdventureMapButton ()
 {
 {
 	type=2;
 	type=2;
@@ -80,10 +81,26 @@ void AdventureMapButton::hover (bool on)
 							: (vstd::contains(hoverTexts,0) ? (&hoverTexts[0]) : NULL);
 							: (vstd::contains(hoverTexts,0) ? (&hoverTexts[0]) : NULL);
 	if(name) //if there is no name, there is nohing to display also
 	if(name) //if there is no name, there is nohing to display also
 	{
 	{
-		if (on)
-			LOCPLINT->statusbar->print(*name);
-		else if ( LOCPLINT->statusbar->getCurrent()==(*name) )
-			LOCPLINT->statusbar->clear();
+		if (LOCPLINT->curint == static_cast<CMainInterface*>(LOCPLINT->battleInt)) //for battle buttons
+		{
+			if(on && LOCPLINT->battleInt->console->alterTxt == "")
+			{
+				LOCPLINT->battleInt->console->alterTxt = *name;
+				LOCPLINT->battleInt->console->whoSetAlter = 1;
+			}
+			else if (LOCPLINT->battleInt->console->alterTxt == *name)
+			{
+				LOCPLINT->battleInt->console->alterTxt = "";
+				LOCPLINT->battleInt->console->whoSetAlter = 0;
+			}
+		}
+		else //for other buttons
+		{
+			if (on)
+				LOCPLINT->statusbar->print(*name);
+			else if ( LOCPLINT->statusbar->getCurrent()==(*name) )
+				LOCPLINT->statusbar->clear();
+		}
 	}
 	}
 }
 }
 
 
@@ -125,9 +142,10 @@ void AdventureMapButton::init(const CFunctionList<void()> &Callback, const std::
 	{
 	{
 		imgs.resize(1);
 		imgs.resize(1);
 		imgs[0].push_back(temp->ourImages[i].bitmap);
 		imgs[0].push_back(temp->ourImages[i].bitmap);
-		if(playerColoredButton) {
+		if(playerColoredButton)
+		{
 			graphics->blueToPlayersAdv(imgs[curimg][i],LOCPLINT->playerID);
 			graphics->blueToPlayersAdv(imgs[curimg][i],LOCPLINT->playerID);
-                }
+		}
 	}
 	}
 	delete temp;
 	delete temp;
 	if (add && add->size())
 	if (add && add->size())
@@ -140,9 +158,10 @@ void AdventureMapButton::init(const CFunctionList<void()> &Callback, const std::
 			for (size_t j=0;j<temp->ourImages.size();j++)
 			for (size_t j=0;j<temp->ourImages.size();j++)
 			{
 			{
 				imgs[i+1].push_back(temp->ourImages[j].bitmap);
 				imgs[i+1].push_back(temp->ourImages[j].bitmap);
-				if(playerColoredButton) {
+				if(playerColoredButton)
+				{
 					graphics->blueToPlayersAdv(imgs[1+i][j],LOCPLINT->playerID);
 					graphics->blueToPlayersAdv(imgs[1+i][j],LOCPLINT->playerID);
-                                }
+				}
 			}
 			}
 			delete temp;
 			delete temp;
 		}
 		}

+ 106 - 12
CBattleInterface.cpp

@@ -127,13 +127,13 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C
 	CSDL_Ext::update();
 	CSDL_Ext::update();
 
 
 	//preparing buttons and console
 	//preparing buttons and console
-	bOptions = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bOptionsf,this), 3 + pos.x, 561 + pos.y, "icm003.def", SDLK_o);
-	bSurrender = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bSurrenderf,this), 54 + pos.x, 561 + pos.y, "icm001.def", SDLK_s);
-	bFlee = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bFleef,this), 105 + pos.x, 561 + pos.y, "icm002.def", SDLK_r);
-	bAutofight  = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bAutofightf,this), 157 + pos.x, 561 + pos.y, "icm004.def", SDLK_a);
-	bSpell = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bSpellf,this), 645 + pos.x, 561 + pos.y, "icm005.def", SDLK_c);
-	bWait = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bWaitf,this), 696 + pos.x, 561 + pos.y, "icm006.def", SDLK_w);
-	bDefence = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bDefencef,this), 747 + pos.x, 561 + pos.y, "icm007.def", SDLK_d);
+	bOptions = new AdventureMapButton (CGI->generaltexth->zelp[381].first, CGI->generaltexth->zelp[381].second, boost::bind(&CBattleInterface::bOptionsf,this), 3 + pos.x, 561 + pos.y, "icm003.def", SDLK_o);
+	bSurrender = new AdventureMapButton (CGI->generaltexth->zelp[379].first, CGI->generaltexth->zelp[379].second, boost::bind(&CBattleInterface::bSurrenderf,this), 54 + pos.x, 561 + pos.y, "icm001.def", SDLK_s);
+	bFlee = new AdventureMapButton (CGI->generaltexth->zelp[380].first, CGI->generaltexth->zelp[380].second, boost::bind(&CBattleInterface::bFleef,this), 105 + pos.x, 561 + pos.y, "icm002.def", SDLK_r);
+	bAutofight  = new AdventureMapButton (CGI->generaltexth->zelp[382].first, CGI->generaltexth->zelp[382].second, boost::bind(&CBattleInterface::bAutofightf,this), 157 + pos.x, 561 + pos.y, "icm004.def", SDLK_a);
+	bSpell = new AdventureMapButton (CGI->generaltexth->zelp[385].first, CGI->generaltexth->zelp[385].second, boost::bind(&CBattleInterface::bSpellf,this), 645 + pos.x, 561 + pos.y, "icm005.def", SDLK_c);
+	bWait = new AdventureMapButton (CGI->generaltexth->zelp[386].first, CGI->generaltexth->zelp[386].second, boost::bind(&CBattleInterface::bWaitf,this), 696 + pos.x, 561 + pos.y, "icm006.def", SDLK_w);
+	bDefence = new AdventureMapButton (CGI->generaltexth->zelp[387].first, CGI->generaltexth->zelp[387].second, boost::bind(&CBattleInterface::bDefencef,this), 747 + pos.x, 561 + pos.y, "icm007.def", SDLK_d);
 	bDefence->assignedKeys.insert(SDLK_SPACE);
 	bDefence->assignedKeys.insert(SDLK_SPACE);
 	bConsoleUp = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bConsoleUpf,this), 624 + pos.x, 561 + pos.y, "ComSlide.def", SDLK_UP);
 	bConsoleUp = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bConsoleUpf,this), 624 + pos.x, 561 + pos.y, "ComSlide.def", SDLK_UP);
 	bConsoleDown = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bConsoleDownf,this), 624 + pos.x, 580 + pos.y, "ComSlide.def", SDLK_DOWN);
 	bConsoleDown = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bConsoleDownf,this), 624 + pos.x, 580 + pos.y, "ComSlide.def", SDLK_DOWN);
@@ -601,18 +601,37 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent)
 		if(myNumber == -1)
 		if(myNumber == -1)
 		{
 		{
 			CGI->curh->changeGraphic(1, 6);
 			CGI->curh->changeGraphic(1, 6);
+			if(console->whoSetAlter == 0)
+			{
+				console->alterTxt = "";
+			}
 		}
 		}
 		else
 		else
 		{
 		{
 			if(std::find(shadedHexes.begin(),shadedHexes.end(),myNumber) == shadedHexes.end())
 			if(std::find(shadedHexes.begin(),shadedHexes.end(),myNumber) == shadedHexes.end())
 			{
 			{
 				CStack *shere = LOCPLINT->cb->battleGetStackByPos(myNumber);
 				CStack *shere = LOCPLINT->cb->battleGetStackByPos(myNumber);
+				CStack *sactive = LOCPLINT->cb->battleGetStackByID(activeStack);
 				if(shere)
 				if(shere)
 				{
 				{
 					if(shere->owner == LOCPLINT->playerID) //our stack
 					if(shere->owner == LOCPLINT->playerID) //our stack
+					{
 						CGI->curh->changeGraphic(1,5);
 						CGI->curh->changeGraphic(1,5);
+						//setting console text
+						char buf[500];
+						sprintf(buf, CGI->generaltexth->allTexts[297].c_str(), shere->amount == 1 ? shere->creature->nameSing.c_str() : shere->creature->namePl.c_str());
+						console->alterTxt = buf;
+						console->whoSetAlter = 0;
+					}
 					else if(LOCPLINT->cb->battleCanShoot(activeStack,myNumber)) //we can shoot enemy
 					else if(LOCPLINT->cb->battleCanShoot(activeStack,myNumber)) //we can shoot enemy
+					{
 						CGI->curh->changeGraphic(1,3);
 						CGI->curh->changeGraphic(1,3);
+						//setting console text
+						char buf[500];
+						sprintf(buf, CGI->generaltexth->allTexts[296].c_str(), shere->amount == 1 ? shere->creature->nameSing.c_str() : shere->creature->namePl.c_str(), sactive->shots, "?");
+						console->alterTxt = buf;
+						console->whoSetAlter = 0;
+					}
 					else if(isTileAttackable(myNumber)) //available enemy (melee attackable)
 					else if(isTileAttackable(myNumber)) //available enemy (melee attackable)
 					{
 					{
 						int fromHex = previouslyHoveredHex;
 						int fromHex = previouslyHoveredHex;
@@ -642,17 +661,41 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent)
 						}
 						}
 					}
 					}
 					else //unavailable enemy
 					else //unavailable enemy
+					{
 						CGI->curh->changeGraphic(1,0);
 						CGI->curh->changeGraphic(1,0);
+						console->alterTxt = "";
+						console->whoSetAlter = 0;
+					}
 				}
 				}
 				else //empty unavailable tile
 				else //empty unavailable tile
+				{
 					CGI->curh->changeGraphic(1,0);
 					CGI->curh->changeGraphic(1,0);
+					console->alterTxt = "";
+					console->whoSetAlter = 0;
+				}
 			}
 			}
 			else //available tile
 			else //available tile
 			{
 			{
+				CStack *sactive = LOCPLINT->cb->battleGetStackByID(activeStack);
 				if(LOCPLINT->cb->battleGetStackByID(activeStack)->creature->isFlying())
 				if(LOCPLINT->cb->battleGetStackByID(activeStack)->creature->isFlying())
+				{
 					CGI->curh->changeGraphic(1,2);
 					CGI->curh->changeGraphic(1,2);
+					//setting console text
+					char buf[500];
+					sprintf(buf, CGI->generaltexth->allTexts[295].c_str(), sactive->amount == 1 ? sactive->creature->nameSing.c_str() : sactive->creature->namePl.c_str());
+					console->alterTxt = buf;
+					console->whoSetAlter = 0;
+				}
 				else
 				else
+				{
 					CGI->curh->changeGraphic(1,1);
 					CGI->curh->changeGraphic(1,1);
+					//setting console text
+					char buf[500];
+					sprintf(buf, CGI->generaltexth->allTexts[294].c_str(), sactive->amount == 1 ? sactive->creature->nameSing.c_str() : sactive->creature->namePl.c_str());
+					console->alterTxt = buf;
+					console->whoSetAlter = 0;
+				}
+
 			}
 			}
 		}
 		}
 	}
 	}
@@ -670,31 +713,80 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent)
 		if(myNumber == -1)
 		if(myNumber == -1)
 		{
 		{
 			CGI->curh->changeGraphic(1, 0);
 			CGI->curh->changeGraphic(1, 0);
+			//setting console text
+			console->alterTxt = CGI->generaltexth->allTexts[23];
+			console->whoSetAlter = 0;
 		}
 		}
 		else
 		else
 		{
 		{
+			CStack * stackUnder = LOCPLINT->cb->battleGetStackByPos(myNumber);
 			switch(spellSelMode)
 			switch(spellSelMode)
 			{
 			{
 			case 0:
 			case 0:
 				CGI->curh->changeGraphic(3, 0);
 				CGI->curh->changeGraphic(3, 0);
+				//setting console text
+				char buf[500];
+				sprintf(buf, CGI->generaltexth->allTexts[26].c_str(), CGI->spellh->spells[spellToCast->additionalInfo].name.c_str());
+				console->alterTxt = buf;
+				console->whoSetAlter = 0;
 				break;
 				break;
 			case 1:
 			case 1:
-				if(LOCPLINT->cb->battleGetStackByPos(myNumber) && LOCPLINT->playerID == LOCPLINT->cb->battleGetStackByPos(myNumber)->owner )
+				if(stackUnder && LOCPLINT->playerID == stackUnder->owner )
+				{
 					CGI->curh->changeGraphic(3, 0);
 					CGI->curh->changeGraphic(3, 0);
+					//setting console text
+					char buf[500];
+					std::string creName = stackUnder->amount > 1 ? stackUnder->creature->namePl : stackUnder->creature->nameSing;
+						sprintf(buf, CGI->generaltexth->allTexts[27].c_str(), CGI->spellh->spells[spellToCast->additionalInfo].name.c_str(), creName.c_str());
+					console->alterTxt = buf;
+					console->whoSetAlter = 0;
+					break;
+				}
 				else
 				else
+				{
 					CGI->curh->changeGraphic(1, 0);
 					CGI->curh->changeGraphic(1, 0);
+					//setting console text
+					console->alterTxt = CGI->generaltexth->allTexts[23];
+					console->whoSetAlter = 0;
+				}
 				break;
 				break;
 			case 2:
 			case 2:
-				if(LOCPLINT->cb->battleGetStackByPos(myNumber) && LOCPLINT->playerID != LOCPLINT->cb->battleGetStackByPos(myNumber)->owner )
+				if(stackUnder && LOCPLINT->playerID != stackUnder->owner )
+				{
 					CGI->curh->changeGraphic(3, 0);
 					CGI->curh->changeGraphic(3, 0);
+					//setting console text
+					char buf[500];
+					std::string creName = stackUnder->amount > 1 ? stackUnder->creature->namePl : stackUnder->creature->nameSing;
+						sprintf(buf, CGI->generaltexth->allTexts[27].c_str(), CGI->spellh->spells[spellToCast->additionalInfo].name.c_str(), creName.c_str());
+					console->alterTxt = buf;
+					console->whoSetAlter = 0;
+				}
 				else
 				else
+				{
 					CGI->curh->changeGraphic(1, 0);
 					CGI->curh->changeGraphic(1, 0);
+					//setting console text
+					console->alterTxt = CGI->generaltexth->allTexts[23];
+					console->whoSetAlter = 0;
+				}
 				break;
 				break;
 			case 3:
 			case 3:
-				if(LOCPLINT->cb->battleGetStackByPos(myNumber))
+				if(stackUnder)
+				{
 					CGI->curh->changeGraphic(3, 0);
 					CGI->curh->changeGraphic(3, 0);
+					//setting console text
+					char buf[500];
+					std::string creName = stackUnder->amount > 1 ? stackUnder->creature->namePl : stackUnder->creature->nameSing;
+						sprintf(buf, CGI->generaltexth->allTexts[27].c_str(), CGI->spellh->spells[spellToCast->additionalInfo].name.c_str(), creName.c_str());
+					console->alterTxt = buf;
+					console->whoSetAlter = 0;
+				}
 				else
 				else
+				{
 					CGI->curh->changeGraphic(1, 0);
 					CGI->curh->changeGraphic(1, 0);
+					//setting console text
+					console->alterTxt = CGI->generaltexth->allTexts[23];
+					console->whoSetAlter = 0;
+				}
 				break;
 				break;
 			case 4: //TODO: implement this case
 			case 4: //TODO: implement this case
 				break;
 				break;
@@ -948,8 +1040,10 @@ void CBattleInterface::stackMoved(int number, int destHex, bool endMoving)
 	}
 	}
 	std::pair <int, int> coords = CBattleHex::getXYUnitAnim(destHex, creDir[number], curs.creature);
 	std::pair <int, int> coords = CBattleHex::getXYUnitAnim(destHex, creDir[number], curs.creature);
 	creAnims[number]->pos.x = coords.first;
 	creAnims[number]->pos.x = coords.first;
-	if(!endMoving && twoTiles && (creDir[number] != (curs.owner == attackingHeroInstance->tempOwner))) //big creature is reversed
+	if(!endMoving && twoTiles && (curs.owner == attackingHeroInstance->tempOwner) && (creDir[number] != (curs.owner == attackingHeroInstance->tempOwner))) //big attacker creature is reversed
 		creAnims[number]->pos.x -= 44;
 		creAnims[number]->pos.x -= 44;
+	else if(!endMoving && twoTiles && (curs.owner != attackingHeroInstance->tempOwner) && (creDir[number] != (curs.owner == attackingHeroInstance->tempOwner))) //big defender creature is reversed
+		creAnims[number]->pos.x += 44;
 	creAnims[number]->pos.y = coords.second;
 	creAnims[number]->pos.y = coords.second;
 }
 }
 
 
@@ -2231,7 +2325,7 @@ void CBattleHex::clickRight(boost::logic::tribool down)
 	}
 	}
 }
 }
 
 
-CBattleConsole::CBattleConsole() : lastShown(-1), alterTxt("")
+CBattleConsole::CBattleConsole() : lastShown(-1), alterTxt(""), whoSetAlter(0)
 {
 {
 }
 }
 
 

+ 2 - 0
CBattleInterface.h

@@ -73,6 +73,7 @@ private:
 	int lastShown; //last shown line of text
 	int lastShown; //last shown line of text
 public:
 public:
 	std::string alterTxt; //if it's not empty, this text is displayed
 	std::string alterTxt; //if it's not empty, this text is displayed
+	int whoSetAlter; //who set alter text; 0 - battle interface or none, 1 - button
 	CBattleConsole(); //c-tor
 	CBattleConsole(); //c-tor
 	~CBattleConsole(); //d-tor
 	~CBattleConsole(); //d-tor
 	void show(SDL_Surface * to = 0);
 	void show(SDL_Surface * to = 0);
@@ -255,6 +256,7 @@ public:
 	friend class CBattleHex;
 	friend class CBattleHex;
 	friend class CBattleReslutWindow;
 	friend class CBattleReslutWindow;
 	friend class CPlayerInterface;
 	friend class CPlayerInterface;
+	friend class AdventureMapButton;
 };
 };
 
 
 #endif // __CBATTLEINTERFACE_H__
 #endif // __CBATTLEINTERFACE_H__

+ 2 - 0
hch/CCreatureHandler.cpp

@@ -313,6 +313,8 @@ void CCreatureHandler::loadCreatures()
 			ncre.abilities.insert(FLYING);
 			ncre.abilities.insert(FLYING);
 		if(boost::algorithm::find_first(ncre.abilityRefs, "SHOOTING_ARMY"))
 		if(boost::algorithm::find_first(ncre.abilityRefs, "SHOOTING_ARMY"))
 			ncre.abilities.insert(SHOOTER);
 			ncre.abilities.insert(SHOOTER);
+		if(boost::algorithm::find_first(ncre.abilityRefs, "SIEGE_WEAPON"))
+			ncre.abilities.insert(SIEGE_WEAPON);
 		if(boost::algorithm::find_first(ncre.abilityRefs, "const_two_attacks"))
 		if(boost::algorithm::find_first(ncre.abilityRefs, "const_two_attacks"))
 			ncre.abilities.insert(TWICE_ATTACK);
 			ncre.abilities.insert(TWICE_ATTACK);
 		if(boost::algorithm::find_first(ncre.abilityRefs, "const_free_attack"))
 		if(boost::algorithm::find_first(ncre.abilityRefs, "const_free_attack"))

+ 2 - 1
server/CGameHandler.cpp

@@ -1144,7 +1144,8 @@ upgend:
 							//counterattack
 							//counterattack
 							if(!vstd::contains(curStack->abilities,NO_ENEMY_RETALIATION)
 							if(!vstd::contains(curStack->abilities,NO_ENEMY_RETALIATION)
 								&& stackAtEnd->alive()
 								&& stackAtEnd->alive()
-								&& stackAtEnd->counterAttacks	) //TODO: support for multiple retaliatons per turn
+								&& stackAtEnd->counterAttacks
+								&& !vstd::contains(stackAtEnd->abilities, SIEGE_WEAPON)) //TODO: support for multiple retaliatons per turn
 							{
 							{
 								prepareAttack(bat,stackAtEnd,curStack);
 								prepareAttack(bat,stackAtEnd,curStack);
 								bat.flags |= 2;
 								bat.flags |= 2;