CBattleInterface.h 6.6 KB

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