battle.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /* -*- mode: c; tab-width: 4; c-basic-offset: 4; c-file-style: "linux" -*- */
  2. //
  3. // Copyright (c) 2009-2011, Wei Mingzhi <whistler_wmz@users.sf.net>.
  4. // Copyright (c) 2011-2017, SDLPAL development team.
  5. // All rights reserved.
  6. //
  7. // This file is part of SDLPAL.
  8. //
  9. // SDLPAL is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU General Public License as published by
  11. // the Free Software Foundation, either version 3 of the License, or
  12. // (at your option) any later version.
  13. //
  14. // This program is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. // GNU General Public License for more details.
  18. //
  19. // You should have received a copy of the GNU General Public License
  20. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. //
  22. #ifndef BATTLE_H
  23. #define BATTLE_H
  24. #include "global.h"
  25. #include "uibattle.h"
  26. #define BATTLE_FPS 25
  27. #define BATTLE_FRAME_TIME (1000 / BATTLE_FPS)
  28. typedef enum tagBATTLERESULT
  29. {
  30. kBattleResultWon = 3, // player won the battle
  31. kBattleResultLost = 1, // player lost the battle
  32. kBattleResultFleed = 0xFFFF, // player fleed from the battle
  33. kBattleResultTerminated = 0, // battle terminated with scripts
  34. kBattleResultOnGoing = 1000, // the battle is ongoing
  35. kBattleResultPreBattle = 1001, // running pre-battle scripts
  36. kBattleResultPause = 1002, // battle pause
  37. } BATTLERESULT;
  38. typedef enum tagFIGHTERSTATE
  39. {
  40. kFighterWait, // waiting time
  41. kFighterCom, // accepting command
  42. kFighterAct, // doing the actual move
  43. } FIGHTERSTATE;
  44. typedef enum tagBATTLEACTIONTYPE
  45. {
  46. kBattleActionPass, // do nothing
  47. kBattleActionDefend, // defend
  48. kBattleActionAttack, // physical attack
  49. kBattleActionMagic, // use magic
  50. kBattleActionCoopMagic, // use cooperative magic
  51. kBattleActionFlee, // flee from the battle
  52. kBattleActionThrowItem, // throw item onto enemy
  53. kBattleActionUseItem, // use item
  54. kBattleActionAttackMate, // attack teammate (confused only)
  55. } BATTLEACTIONTYPE;
  56. typedef struct tagBATTLEACTION
  57. {
  58. BATTLEACTIONTYPE ActionType;
  59. WORD wActionID; // item/magic to use
  60. SHORT sTarget; // -1 for everyone
  61. FLOAT flRemainingTime; // remaining waiting time before the action start
  62. } BATTLEACTION;
  63. typedef struct tagBATTLEENEMY
  64. {
  65. WORD wObjectID; // Object ID of this enemy
  66. ENEMY e; // detailed data of this enemy
  67. WORD rgwStatus[kStatusAll]; // status effects
  68. FLOAT flTimeMeter; // time-charging meter (0 = empty, 100 = full).
  69. POISONSTATUS rgPoisons[MAX_POISONS]; // poisons
  70. LPSPRITE lpSprite;
  71. PAL_POS pos; // current position on the screen
  72. PAL_POS posOriginal; // original position on the screen
  73. WORD wCurrentFrame; // current frame number
  74. FIGHTERSTATE state; // state of this enemy
  75. BOOL fTurnStart;
  76. BOOL fFirstMoveDone;
  77. BOOL fDualMove;
  78. WORD wScriptOnTurnStart;
  79. WORD wScriptOnBattleEnd;
  80. WORD wScriptOnReady;
  81. WORD wPrevHP; // HP value prior to action
  82. INT iColorShift;
  83. } BATTLEENEMY;
  84. // We only put some data used in battle here; other data can be accessed in the global data.
  85. typedef struct tagBATTLEPLAYER
  86. {
  87. INT iColorShift;
  88. FLOAT flTimeMeter; // time-charging meter (0 = empty, 100 = full).
  89. FLOAT flTimeSpeedModifier;
  90. WORD wHidingTime; // remaining hiding time
  91. LPSPRITE lpSprite;
  92. PAL_POS pos; // current position on the screen
  93. PAL_POS posOriginal; // original position on the screen
  94. WORD wCurrentFrame; // current frame number
  95. FIGHTERSTATE state; // state of this player
  96. BATTLEACTION action; // action to perform
  97. BATTLEACTION prevAction; // action of the previous turn
  98. BOOL fDefending; // TRUE if player is defending
  99. WORD wPrevHP; // HP value prior to action
  100. WORD wPrevMP; // MP value prior to action
  101. #ifndef PAL_CLASSIC
  102. SHORT sTurnOrder; // turn order
  103. #endif
  104. } BATTLEPLAYER;
  105. typedef struct tagSUMMON
  106. {
  107. LPSPRITE lpSprite;
  108. WORD wCurrentFrame;
  109. } SUMMON;
  110. #define MAX_BATTLE_ACTIONS 256
  111. #define MAX_KILLED_ENEMIES 256
  112. #ifdef PAL_CLASSIC
  113. typedef enum tabBATTLEPHASE
  114. {
  115. kBattlePhaseSelectAction,
  116. kBattlePhasePerformAction
  117. } BATTLEPHASE;
  118. typedef struct tagACTIONQUEUE
  119. {
  120. BOOL fIsEnemy;
  121. WORD wDexterity;
  122. WORD wIndex;
  123. } ACTIONQUEUE;
  124. #define MAX_ACTIONQUEUE_ITEMS (MAX_PLAYERS_IN_PARTY + MAX_ENEMIES_IN_TEAM * 2)
  125. #endif
  126. typedef struct tagBATTLE
  127. {
  128. BATTLEPLAYER rgPlayer[MAX_PLAYERS_IN_PARTY];
  129. BATTLEENEMY rgEnemy[MAX_ENEMIES_IN_TEAM];
  130. WORD wMaxEnemyIndex;
  131. SDL_Surface *lpSceneBuf;
  132. SDL_Surface *lpBackground;
  133. SHORT sBackgroundColorShift;
  134. LPSPRITE lpSummonSprite; // sprite of summoned god
  135. PAL_POS posSummon;
  136. INT iSummonFrame; // current frame of the summoned god
  137. INT iExpGained; // total experience value gained
  138. INT iCashGained; // total cash gained
  139. BOOL fIsBoss; // TRUE if boss fight
  140. BOOL fEnemyCleared; // TRUE if enemies are cleared
  141. BATTLERESULT BattleResult;
  142. FLOAT flTimeChargingUnit; // the base waiting time unit
  143. BATTLEUI UI;
  144. LPBYTE lpEffectSprite;
  145. BOOL fEnemyMoving; // TRUE if enemy is moving
  146. INT iHidingTime; // Time of hiding
  147. WORD wMovingPlayerIndex; // current moving player index
  148. int iBlow;
  149. #ifdef PAL_CLASSIC
  150. BATTLEPHASE Phase;
  151. ACTIONQUEUE ActionQueue[MAX_ACTIONQUEUE_ITEMS];
  152. int iCurAction;
  153. BOOL fRepeat; // TRUE if player pressed Repeat
  154. BOOL fForce; // TRUE if player pressed Force
  155. BOOL fFlee; // TRUE if player pressed Flee
  156. BOOL fPrevAutoAtk; // TRUE if auto-attack was used in the previous turn
  157. BOOL fPrevPlayerAutoAtk; // TRUE if auto-attack was used by previous player in the same turn
  158. #endif
  159. } BATTLE;
  160. PAL_C_LINKAGE_BEGIN
  161. extern BATTLE g_Battle;
  162. VOID
  163. PAL_LoadBattleSprites(
  164. VOID
  165. );
  166. VOID
  167. PAL_BattleMakeScene(
  168. VOID
  169. );
  170. VOID
  171. PAL_BattleFadeScene(
  172. VOID
  173. );
  174. VOID
  175. PAL_BattleEnemyEscape(
  176. VOID
  177. );
  178. VOID
  179. PAL_BattlePlayerEscape(
  180. VOID
  181. );
  182. BATTLERESULT
  183. PAL_StartBattle(
  184. WORD wEnemyTeam,
  185. BOOL fIsBoss
  186. );
  187. PAL_C_LINKAGE_END
  188. #endif