battle.h 6.9 KB

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