battle.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. BOOL fDefending; // TRUE if player is defending
  98. WORD wPrevHP; // HP value prior to action
  99. WORD wPrevMP; // MP value prior to action
  100. #ifndef PAL_CLASSIC
  101. SHORT sTurnOrder; // turn order
  102. #endif
  103. } BATTLEPLAYER;
  104. typedef struct tagSUMMON
  105. {
  106. LPSPRITE lpSprite;
  107. WORD wCurrentFrame;
  108. } SUMMON;
  109. #define MAX_BATTLE_ACTIONS 256
  110. #define MAX_KILLED_ENEMIES 256
  111. #ifdef PAL_CLASSIC
  112. typedef enum tabBATTLEPHASE
  113. {
  114. kBattlePhaseSelectAction,
  115. kBattlePhasePerformAction
  116. } BATTLEPHASE;
  117. typedef struct tagACTIONQUEUE
  118. {
  119. BOOL fIsEnemy;
  120. WORD wDexterity;
  121. WORD wIndex;
  122. } ACTIONQUEUE;
  123. #define MAX_ACTIONQUEUE_ITEMS (MAX_PLAYERS_IN_PARTY + MAX_ENEMIES_IN_TEAM * 2)
  124. #endif
  125. typedef struct tagBATTLE
  126. {
  127. BATTLEPLAYER rgPlayer[MAX_PLAYERS_IN_PARTY];
  128. BATTLEENEMY rgEnemy[MAX_ENEMIES_IN_TEAM];
  129. WORD wMaxEnemyIndex;
  130. SDL_Surface *lpSceneBuf;
  131. SDL_Surface *lpBackground;
  132. SHORT sBackgroundColorShift;
  133. LPSPRITE lpSummonSprite; // sprite of summoned god
  134. PAL_POS posSummon;
  135. INT iSummonFrame; // current frame of the summoned god
  136. INT iExpGained; // total experience value gained
  137. INT iCashGained; // total cash gained
  138. BOOL fIsBoss; // TRUE if boss fight
  139. BOOL fEnemyCleared; // TRUE if enemies are cleared
  140. BATTLERESULT BattleResult;
  141. FLOAT flTimeChargingUnit; // the base waiting time unit
  142. BATTLEUI UI;
  143. LPBYTE lpEffectSprite;
  144. BOOL fEnemyMoving; // TRUE if enemy is moving
  145. INT iHidingTime; // Time of hiding
  146. WORD wMovingPlayerIndex; // current moving player index
  147. int iBlow;
  148. #ifdef PAL_CLASSIC
  149. BATTLEPHASE Phase;
  150. ACTIONQUEUE ActionQueue[MAX_ACTIONQUEUE_ITEMS];
  151. int iCurAction;
  152. BOOL fRepeat; // TRUE if player pressed Repeat
  153. BOOL fForce; // TRUE if player pressed Force
  154. BOOL fFlee; // TRUE if player pressed Flee
  155. #endif
  156. } BATTLE;
  157. PAL_C_LINKAGE_BEGIN
  158. extern BATTLE g_Battle;
  159. VOID
  160. PAL_LoadBattleSprites(
  161. VOID
  162. );
  163. VOID
  164. PAL_BattleMakeScene(
  165. VOID
  166. );
  167. VOID
  168. PAL_BattleFadeScene(
  169. VOID
  170. );
  171. VOID
  172. PAL_BattleEnemyEscape(
  173. VOID
  174. );
  175. VOID
  176. PAL_BattlePlayerEscape(
  177. VOID
  178. );
  179. BATTLERESULT
  180. PAL_StartBattle(
  181. WORD wEnemyTeam,
  182. BOOL fIsBoss
  183. );
  184. PAL_C_LINKAGE_END
  185. #endif