CBattleInterface.h 5.1 KB

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