battle.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. #include "global.h"
  24. #include "uibattle.h"
  25. #define BATTLE_FPS 25
  26. #define BATTLE_FRAME_TIME (1000 / BATTLE_FPS)
  27. typedef enum tagBATTLERESULT
  28. {
  29. kBattleResultWon = 3, // player won the battle
  30. kBattleResultLost = 1, // player lost the battle
  31. kBattleResultFleed = 0xFFFF, // player fleed from the battle
  32. kBattleResultTerminated = 0, // battle terminated with scripts
  33. kBattleResultOnGoing = 1000, // the battle is ongoing
  34. kBattleResultPreBattle = 1001, // running pre-battle scripts
  35. kBattleResultPause = 1002, // battle pause
  36. } BATTLERESULT;
  37. typedef enum tagFIGHTERSTATE
  38. {
  39. kFighterWait, // waiting time
  40. kFighterCom, // accepting command
  41. kFighterAct, // doing the actual move
  42. } FIGHTERSTATE;
  43. typedef enum tagBATTLEACTIONTYPE
  44. {
  45. kBattleActionPass, // do nothing
  46. kBattleActionDefend, // defend
  47. kBattleActionAttack, // physical attack
  48. kBattleActionMagic, // use magic
  49. kBattleActionCoopMagic, // use cooperative magic
  50. kBattleActionFlee, // flee from the battle
  51. kBattleActionThrowItem, // throw item onto enemy
  52. kBattleActionUseItem, // use item
  53. kBattleActionAttackMate, // attack teammate (confused only)
  54. } BATTLEACTIONTYPE;
  55. typedef struct tagBATTLEACTION
  56. {
  57. BATTLEACTIONTYPE ActionType;
  58. WORD wActionID; // item/magic to use
  59. SHORT sTarget; // -1 for everyone
  60. FLOAT flRemainingTime; // remaining waiting time before the action start
  61. } BATTLEACTION;
  62. typedef struct tagBATTLEENEMY
  63. {
  64. WORD wObjectID; // Object ID of this enemy
  65. ENEMY e; // detailed data of this enemy
  66. WORD rgwStatus[kStatusAll]; // status effects
  67. FLOAT flTimeMeter; // time-charging meter (0 = empty, 100 = full).
  68. POISONSTATUS rgPoisons[MAX_POISONS]; // poisons
  69. LPSPRITE lpSprite;
  70. PAL_POS pos; // current position on the screen
  71. PAL_POS posOriginal; // original position on the screen
  72. WORD wCurrentFrame; // current frame number
  73. FIGHTERSTATE state; // state of this enemy
  74. BOOL fTurnStart;
  75. BOOL fFirstMoveDone;
  76. BOOL fDualMove;
  77. WORD wScriptOnTurnStart;
  78. WORD wScriptOnBattleEnd;
  79. WORD wScriptOnReady;
  80. WORD wPrevHP; // HP value prior to action
  81. INT iColorShift;
  82. } BATTLEENEMY;
  83. // We only put some data used in battle here; other data can be accessed in the global data.
  84. typedef struct tagBATTLEPLAYER
  85. {
  86. INT iColorShift;
  87. FLOAT flTimeMeter; // time-charging meter (0 = empty, 100 = full).
  88. FLOAT flTimeSpeedModifier;
  89. WORD wHidingTime; // remaining hiding time
  90. LPSPRITE lpSprite;
  91. PAL_POS pos; // current position on the screen
  92. PAL_POS posOriginal; // original position on the screen
  93. WORD wCurrentFrame; // current frame number
  94. FIGHTERSTATE state; // state of this player
  95. BATTLEACTION action; // action to perform
  96. BOOL fDefending; // TRUE if player is defending
  97. WORD wPrevHP; // HP value prior to action
  98. WORD wPrevMP; // MP value prior to action
  99. #ifndef PAL_CLASSIC
  100. SHORT sTurnOrder; // turn order
  101. #endif
  102. } BATTLEPLAYER;
  103. typedef struct tagSUMMON
  104. {
  105. LPSPRITE lpSprite;
  106. WORD wCurrentFrame;
  107. } SUMMON;
  108. #define MAX_BATTLE_ACTIONS 256
  109. #define MAX_KILLED_ENEMIES 256
  110. #ifdef PAL_CLASSIC
  111. typedef enum tabBATTLEPHASE
  112. {
  113. kBattlePhaseSelectAction,
  114. kBattlePhasePerformAction
  115. } BATTLEPHASE;
  116. typedef struct tagACTIONQUEUE
  117. {
  118. BOOL fIsEnemy;
  119. WORD wDexterity;
  120. WORD wIndex;
  121. } ACTIONQUEUE;
  122. #define MAX_ACTIONQUEUE_ITEMS (MAX_PLAYERS_IN_PARTY + MAX_ENEMIES_IN_TEAM * 2)
  123. #endif
  124. typedef struct tagBATTLE
  125. {
  126. BATTLEPLAYER rgPlayer[MAX_PLAYERS_IN_PARTY];
  127. BATTLEENEMY rgEnemy[MAX_ENEMIES_IN_TEAM];
  128. WORD wMaxEnemyIndex;
  129. SDL_Surface *lpSceneBuf;
  130. SDL_Surface *lpBackground;
  131. SHORT sBackgroundColorShift;
  132. LPSPRITE lpSummonSprite; // sprite of summoned god
  133. PAL_POS posSummon;
  134. INT iSummonFrame; // current frame of the summoned god
  135. INT iExpGained; // total experience value gained
  136. INT iCashGained; // total cash gained
  137. BOOL fIsBoss; // TRUE if boss fight
  138. BOOL fEnemyCleared; // TRUE if enemies are cleared
  139. BATTLERESULT BattleResult;
  140. FLOAT flTimeChargingUnit; // the base waiting time unit
  141. BATTLEUI UI;
  142. LPBYTE lpEffectSprite;
  143. BOOL fEnemyMoving; // TRUE if enemy is moving
  144. INT iHidingTime; // Time of hiding
  145. WORD wMovingPlayerIndex; // current moving player index
  146. int iBlow;
  147. #ifdef PAL_CLASSIC
  148. BATTLEPHASE Phase;
  149. ACTIONQUEUE ActionQueue[MAX_ACTIONQUEUE_ITEMS];
  150. int iCurAction;
  151. BOOL fRepeat; // TRUE if player pressed Repeat
  152. BOOL fForce; // TRUE if player pressed Force
  153. BOOL fFlee; // TRUE if player pressed Flee
  154. #endif
  155. } BATTLE;
  156. PAL_C_LINKAGE_BEGIN
  157. extern BATTLE g_Battle;
  158. VOID
  159. PAL_LoadBattleSprites(
  160. VOID
  161. );
  162. VOID
  163. PAL_BattleMakeScene(
  164. VOID
  165. );
  166. VOID
  167. PAL_BattleFadeScene(
  168. VOID
  169. );
  170. VOID
  171. PAL_BattleEnemyEscape(
  172. VOID
  173. );
  174. VOID
  175. PAL_BattlePlayerEscape(
  176. VOID
  177. );
  178. BATTLERESULT
  179. PAL_StartBattle(
  180. WORD wEnemyTeam,
  181. BOOL fIsBoss
  182. );
  183. PAL_C_LINKAGE_END
  184. #endif