CBattleInterface.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #pragma once
  2. #include "global.h"
  3. #include "CPlayerInterface.h"
  4. class CCreatureSet;
  5. class CGHeroInstance;
  6. class CDefHandler;
  7. class CStack;
  8. class CCallback;
  9. class AdventureMapButton;
  10. class CBattleHero : public IShowable, public CIntObject
  11. {
  12. public:
  13. bool flip; //false if it's attacking hero, true otherwise
  14. CDefHandler * dh, *flag; //animation and flag
  15. int phase; //stage of animation
  16. int image; //frame of animation
  17. unsigned char flagAnim, flagAnimCount; //for flag animation
  18. void show(SDL_Surface * to); //prints next frame of animation to to
  19. CBattleHero(std::string defName, int phaseG, int imageG, bool filpG, unsigned char player); //c-tor
  20. ~CBattleHero(); //d-tor
  21. };
  22. class CBattleInterface;
  23. class CBattleHex : public Hoverable, public MotionInterested, public ClickableL, public ClickableR
  24. {
  25. private:
  26. bool setAlterText; //if true, this hex has set alternative text in console and will clean it
  27. public:
  28. unsigned int myNumber;
  29. bool accesible;
  30. //CStack * ourStack;
  31. bool hovered, strictHovered;
  32. CBattleInterface * myInterface; //interface that owns me
  33. static std::pair<int, int> getXYUnitAnim(int hexNum, bool attacker, CCreature * creature); //returns (x, y) of left top corner of animation
  34. static signed char mutualPosition(int hex1, int hex2); //returns info about mutual position of given hexes (-1 - they distant, 0 - left top, 1 - right top, 2 - right, 3 - right bottom, 4 - left bottom, 5 - left)
  35. //for user interactions
  36. void hover (bool on);
  37. void activate();
  38. void deactivate();
  39. void mouseMoved (SDL_MouseMotionEvent & sEvent);
  40. void clickLeft(boost::logic::tribool down);
  41. void clickRight(boost::logic::tribool down);
  42. CBattleHex();
  43. };
  44. class CBattleObstacle
  45. {
  46. std::vector<int> lockedHexes;
  47. };
  48. class CBattleConsole : public IShowable, public CIntObject
  49. {
  50. private:
  51. std::vector< std::string > texts; //a place where texts are stored
  52. int lastShown; //last shown line of text
  53. public:
  54. std::string alterTxt; //if it's not empty, this text is displayed
  55. CBattleConsole(); //c-tor
  56. ~CBattleConsole(); //d-tor
  57. void show(SDL_Surface * to = 0);
  58. bool addText(std::string text); //adds text at the last position; returns false if failed (e.g. text longer than 70 characters)
  59. void eraseText(unsigned int pos); //erases added text at position pos
  60. void changeTextAt(std::string text, unsigned int pos); //if we have more than pos texts, pos-th is changed to given one
  61. void scrollUp(unsigned int by = 1); //scrolls console up by 'by' positions
  62. void scrollDown(unsigned int by = 1); //scrolls console up by 'by' positions
  63. };
  64. class CBattleInterface : public IActivable, public IShowable
  65. {
  66. private:
  67. SDL_Surface * background, * menu, * amountBasic, * amountNormal;
  68. AdventureMapButton * bOptions, * bSurrender, * bFlee, * bAutofight, * bSpell,
  69. * bWait, * bDefence, * bConsoleUp, * bConsoleDown;
  70. CBattleConsole * console;
  71. CBattleHero * attackingHero, * defendingHero;
  72. CCreatureSet * army1, * army2; //fighting armies
  73. CGHeroInstance * attackingHeroInstance, * defendingHeroInstance;
  74. std::map< int, CCreatureAnimation * > creAnims; //animations of creatures from fighting armies (order by BattleInfo's stacks' ID)
  75. std::map< int, bool > creDir; // <creatureID, if false reverse creature's animation>
  76. unsigned char animCount;
  77. int activeStack; //number of active stack; -1 - no one
  78. void showRange(SDL_Surface * to, int ID); //show helper funtion ot mark range of a unit
  79. class CAttHelper
  80. {
  81. public:
  82. int ID; //attacking stack
  83. int dest; //atacked hex
  84. int frame, maxframe; //frame of animation, number of frames of animation
  85. bool reversing;
  86. } * attackingInfo;
  87. void attackingShowHelper();
  88. void printConsoleAttacked(int ID, int dmg, int killed, int IDby);
  89. public:
  90. CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2); //c-tor
  91. ~CBattleInterface(); //d-tor
  92. //std::vector<TimeInterested*> timeinterested; //animation handling
  93. bool printCellBorders; //if true, cell borders will be printed
  94. CBattleHex bfield[187]; //11 lines, 17 hexes on each
  95. std::vector< CBattleObstacle * > obstacles; //vector of obstacles on the battlefield
  96. static SDL_Surface * cellBorder, * cellShade;
  97. BattleAction * givenCommand; //true if we have i.e. moved current unit
  98. //button handle funcs:
  99. void bOptionsf();
  100. void bSurrenderf();
  101. void bFleef();
  102. void bAutofightf();
  103. void bSpellf();
  104. void bWaitf();
  105. void bDefencef();
  106. void bConsoleUpf();
  107. void bConsoleDownf();
  108. //end of button handle funcs
  109. //napisz tu klase odpowiadajaca za wyswietlanie bitwy i obsluge uzytkownika, polecenia ma przekazywac callbackiem
  110. void activate();
  111. void deactivate();
  112. void show(SDL_Surface * to = NULL);
  113. bool reverseCreature(int number, int hex, bool wideTrick = false); //reverses animation of given creature playing animation of reversing
  114. //call-ins
  115. void newStack(CStack stack); //new stack appeared on battlefield
  116. void stackRemoved(CStack stack); //stack disappeared from batlefiled
  117. void stackKilled(int ID, int dmg, int killed, int IDby); //stack has been killed (but corpses remain)
  118. void stackActivated(int number); //active stack has been changed
  119. void stackMoved(int number, int destHex, bool startMoving, bool endMoving); //stack with id number moved to destHex
  120. void stackIsAttacked(int ID, int dmg, int killed, int IDby); //called when stack id attacked by stack with id IDby
  121. void stackAttacking(int ID, int dest); //called when stack with id ID is attacking something on hex dest
  122. void newRound(int number); //caled when round is ended; number is the number of round
  123. void hexLclicked(int whichOne); //hex only call-in
  124. friend CBattleHex;
  125. };