CBattleInterface.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. template <typename T> 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
  24. {
  25. public:
  26. unsigned int myNumber;
  27. bool accesible;
  28. //CStack * ourStack;
  29. bool hovered, strictHovered;
  30. CBattleInterface * myInterface; //interface that owns me
  31. static std::pair<int, int> getXYUnitAnim(int hexNum, bool attacker, CCreature * creature); //returns (x, y) of left top corner of animation
  32. 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)
  33. //for user interactions
  34. void hover (bool on);
  35. void activate();
  36. void deactivate();
  37. void mouseMoved (SDL_MouseMotionEvent & sEvent);
  38. void clickLeft(boost::logic::tribool down);
  39. CBattleHex();
  40. };
  41. class CBattleObstacle
  42. {
  43. std::vector<int> lockedHexes;
  44. };
  45. class CBattleConsole : public IShowable, public CIntObject
  46. {
  47. private:
  48. std::vector< std::string > texts; //a place where texts are stored
  49. int lastShown; //las shown line of text
  50. public:
  51. CBattleConsole(); //c-tor
  52. ~CBattleConsole(); //d-tor
  53. void show(SDL_Surface * to = 0);
  54. bool addText(std::string text); //adds text at the last position; returns false if failed (e.g. text longer than 70 characters)
  55. void eraseText(unsigned int pos); //erases added text at position pos
  56. void changeTextAt(std::string text, unsigned int pos); //if we have more than pos texts, pos-th is changed to given one
  57. void scrollUp(unsigned int by = 1); //scrolls console up by 'by' positions
  58. void scrollDown(unsigned int by = 1); //scrolls console up by 'by' positions
  59. };
  60. class CBattleInterface : public IActivable, public IShowable
  61. {
  62. private:
  63. SDL_Surface * background, * menu, * amountBasic, * amountNormal;
  64. AdventureMapButton<CBattleInterface> * bOptions, * bSurrender, * bFlee, * bAutofight, * bSpell,
  65. * bWait, * bDefence, * bConsoleUp, * bConsoleDown;
  66. CBattleConsole * console;
  67. CBattleHero * attackingHero, * defendingHero;
  68. CCreatureSet * army1, * army2; //fighting armies
  69. CGHeroInstance * attackingHeroInstance, * defendingHeroInstance;
  70. std::map< int, CCreatureAnimation * > creAnims; //animations of creatures from fighting armies (order by BattleInfo's stacks' ID)
  71. std::map< int, bool > creDir; // <creatureID, if false reverse creature's animation>
  72. unsigned char animCount;
  73. int activeStack; //number of active stack; -1 - no one
  74. void showRange(SDL_Surface * to, int ID); //show helper funtion ot mark range of a unit
  75. public:
  76. CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2); //c-tor
  77. ~CBattleInterface(); //d-tor
  78. //std::vector<TimeInterested*> timeinterested; //animation handling
  79. bool printCellBorders; //if true, cell borders will be printed
  80. CBattleHex bfield[187]; //11 lines, 17 hexes on each
  81. std::vector< CBattleObstacle * > obstacles; //vector of obstacles on the battlefield
  82. static SDL_Surface * cellBorder, * cellShade;
  83. BattleAction * givenCommand; //true if we have i.e. moved current unit
  84. //button handle funcs:
  85. void bOptionsf();
  86. void bSurrenderf();
  87. void bFleef();
  88. void bAutofightf();
  89. void bSpellf();
  90. void bWaitf();
  91. void bDefencef();
  92. void bConsoleUpf();
  93. void bConsoleDownf();
  94. //end of button handle funcs
  95. //napisz tu klase odpowiadajaca za wyswietlanie bitwy i obsluge uzytkownika, polecenia ma przekazywac callbackiem
  96. void activate();
  97. void deactivate();
  98. void show(SDL_Surface * to = NULL);
  99. bool reverseCreature(int number, int hex, bool wideTrick = false); //reverses animation of given creature playing animation of reversing
  100. //call-ins
  101. void newStack(CStack stack); //new stack appeared on battlefield
  102. void stackRemoved(CStack stack); //stack disappeared from batlefiled
  103. void stackActivated(int number); //active stack has been changed
  104. void stackMoved(int number, int destHex, bool startMoving, bool endMoving); //stack with id number moved to destHex
  105. void stackAttacking(int ID, int dest); //called when stack with id ID is attacking something on hex dest
  106. void newRound(int number); //caled when round is ended; number is the number of round
  107. void hexLclicked(int whichOne); //hex only call-in
  108. };