battle.h 7.1 KB

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