Bläddra i källkod

* stack queue in battle (shows when 'c' key is pressed)
* minor fix of cursor image

mateuszb 17 år sedan
förälder
incheckning
b256f0ff43
3 ändrade filer med 81 tillägg och 1 borttagningar
  1. 64 1
      CBattleInterface.cpp
  2. 1 0
      CBattleInterface.h
  3. 16 0
      CPlayerInterface.cpp

+ 64 - 1
CBattleInterface.cpp

@@ -28,8 +28,17 @@ extern SDL_Surface * screen;
 extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM, *GEOR16;
 extern SDL_Color zwykly;
 
+class CMP_stack2
+{
+public:
+	bool operator ()(const CStack& a, const CStack& b)
+	{
+		return (a.creature->speed)>(b.creature->speed);
+	}
+} cmpst2 ;
+
 CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2)
-: printCellBorders(true), attackingHeroInstance(hero1), defendingHeroInstance(hero2), animCount(0), activeStack(-1), givenCommand(NULL), attackingInfo(NULL), myTurn(false), resWindow(NULL)
+: printCellBorders(true), attackingHeroInstance(hero1), defendingHeroInstance(hero2), animCount(0), activeStack(-1), givenCommand(NULL), attackingInfo(NULL), myTurn(false), resWindow(NULL), showStackQueue(false)
 {
 	givenCommand = new CondSh<BattleAction *>(NULL);
 	//initializing armies
@@ -360,6 +369,59 @@ void CBattleInterface::show(SDL_Surface * to)
 	//units shown
 	projectileShowHelper(to);//showing projectiles
 
+	//showing queue of stacks
+	if(showStackQueue)
+	{
+		int xPos = 400 - ( stacks.size() * 42 )/2;
+		int yPos = 10;
+
+		std::vector<CStack> stacksSorted;
+		for(int v=0; v<stacks.size(); ++v)
+		{
+			stacksSorted.push_back(stacks[v]);
+		}
+		std::stable_sort(stacksSorted.begin(), stacksSorted.end(), cmpst2);
+		int startFrom = -1;
+		for(int n=0; n<stacksSorted.size(); ++n)
+		{
+			if(stacksSorted[n].ID == activeStack)
+			{
+				startFrom = n;
+				break;
+			}
+		}
+		if(startFrom != -1)
+		{
+			for(int b=startFrom; b<stacksSorted.size()+startFrom; ++b)
+			{
+				SDL_BlitSurface(graphics->smallImgs[-2], NULL, to, &genRect(32, 32, xPos, yPos));
+				//printing colored border
+				for(int xFrom = xPos-1; xFrom<xPos+33; ++xFrom)
+				{
+					for(int yFrom = yPos-1; yFrom<yPos+33; ++yFrom)
+					{
+						if(xFrom == xPos-1 || xFrom == xPos+32 || yFrom == yPos-1 || yFrom == yPos+32)
+						{
+							SDL_Color pc;
+							if(stacksSorted[b % stacksSorted.size()].owner != 255)
+							{
+								pc = graphics->playerColors[stacksSorted[b % stacksSorted.size()].owner];
+							}
+							else
+							{
+								pc = *graphics->neutralColor;
+							}
+							CSDL_Ext::SDL_PutPixel(to, xFrom, yFrom, pc.r, pc.g, pc.b);
+						}
+					}
+				}
+				//colored border printed
+				SDL_BlitSurface(graphics->smallImgs[stacksSorted[b % stacksSorted.size()].creature->idNumber], NULL, to, &genRect(32, 32, xPos, yPos));
+				xPos += 42;
+			}
+		}
+	}
+
 	//showing window with result of battle
 	if(resWindow)
 	{
@@ -886,6 +948,7 @@ void CBattleInterface::stackIsShooting(int ID, int dest)
 void CBattleInterface::battleFinished(const BattleResult& br)
 {
 	deactivate();
+	CGI->curh->changeGraphic(0,0);
 
 	SDL_Rect temp_rect = genRect(561, 470, 165, 19);
 	resWindow = new CBattleReslutWindow(br, temp_rect, this);

+ 1 - 0
CBattleInterface.h

@@ -142,6 +142,7 @@ public:
 	CondSh<BattleAction *> *givenCommand; //data != NULL if we have i.e. moved current unit
 	bool myTurn; //if true, interface is active (commands can be ordered
 	CBattleReslutWindow * resWindow; //window of end of battle
+	bool showStackQueue; //if true, queue of stacks will be shown
 
 	//button handle funcs:
 	void bOptionsf();

+ 16 - 0
CPlayerInterface.cpp

@@ -1676,6 +1676,14 @@ void CPlayerInterface::handleKeyUp(SDL_Event *sEvent)
 			adventureInt->endTurn.clickLeft(false);
 			break;
 		}
+	case (SDLK_c):
+		{
+			if( dynamic_cast<CBattleInterface*> (curint) )
+			{
+				dynamic_cast<CBattleInterface*> (curint)->showStackQueue = false;
+			}
+			break;
+		}
 	}
 }
 void CPlayerInterface::handleKeyDown(SDL_Event *sEvent)
@@ -1723,6 +1731,14 @@ void CPlayerInterface::handleKeyDown(SDL_Event *sEvent)
 			adventureInt->endTurn.clickLeft(true);
 			break;
 		}
+	case (SDLK_c):
+		{
+			if( dynamic_cast<CBattleInterface*> (curint) )
+			{
+				dynamic_cast<CBattleInterface*> (curint)->showStackQueue = true;
+			}
+			break;
+		}
 	}
 }
 void CPlayerInterface::handleEvent(SDL_Event *sEvent)