battle.h (3064B)
1 #ifndef PH_ENGINE_BATTLE_H 2 #define PH_ENGINE_BATTLE_H 3 4 #include "engine/world.h" 5 6 enum { PH_BATTLE_ORDER_COUNT = 6, PH_SPELL_MAX = 16 }; 7 8 typedef enum { 9 PH_BATTLE_COMMAND, 10 PH_BATTLE_MAGIC, 11 PH_BATTLE_TARGET, 12 PH_BATTLE_PLAYER_ACTION, 13 PH_BATTLE_ENEMY_ACTION, 14 } PhBattlePhase; 15 16 typedef enum { 17 PH_BATTLE_CONTINUE, 18 PH_BATTLE_READY, 19 PH_BATTLE_VICTORY, 20 PH_BATTLE_DEFEAT, 21 } PhBattleResult; 22 23 typedef enum { 24 PH_BATTLE_FIGHT, 25 PH_BATTLE_MAGICK, 26 PH_BATTLE_ITEM, 27 PH_BATTLE_COMMAND_COUNT, 28 } PhBattleCommand; 29 30 typedef enum { 31 PH_BATTLE_EVENT_NONE, 32 PH_BATTLE_EVENT_ATTACK, 33 PH_BATTLE_EVENT_HIT, 34 PH_BATTLE_EVENT_SPELL, 35 } PhBattleEvent; 36 37 typedef enum { 38 PH_SPELL_BATTLE_NONE, 39 PH_SPELL_BATTLE_DAMAGE, 40 PH_SPELL_BATTLE_HEAL, 41 } PhSpellBattleUse; 42 43 typedef enum { 44 PH_SPELL_FIELD_NONE, 45 PH_SPELL_FIELD_HEAL, 46 } PhSpellFieldUse; 47 48 typedef enum { 49 PH_SPELL_TARGET_NONE, 50 PH_SPELL_TARGET_OPPONENT, 51 PH_SPELL_TARGET_ALLY, 52 } PhSpellTarget; 53 54 typedef struct { 55 int id; 56 const char *name; 57 const char *description; 58 PhSpellBattleUse battle_use; 59 PhSpellFieldUse field_use; 60 PhSpellTarget target; 61 int mp_cost; 62 int power; 63 int delay_percent; 64 int buy_value; 65 PhTimedEffect accuracy; 66 } PhSpellDef; 67 68 typedef struct { 69 const PhSpellDef *defs; 70 int learned[PH_SPELL_MAX]; 71 int def_count; 72 int learned_count; 73 } PhSpellBook; 74 75 typedef struct { 76 PhBattleCommand command; 77 int spell; 78 int item_id; 79 int target_index; 80 } PhBattleChoice; 81 82 typedef struct { 83 int player_ctb; 84 int enemy_ctb; 85 int current_actor; 86 int action_delay; 87 } PhBattleTurn; 88 89 typedef struct { 90 int enemy_index; 91 PhBattleChoice choice; 92 PhBattleTurn turn; 93 int resolved; 94 PhReward reward; 95 float timer; 96 PhBattlePhase phase; 97 char message[64]; 98 PhSpellBook spells; 99 PhBattleEvent event; 100 } PhBattle; 101 102 void ph_battle_begin(PhBattle *battle, PhWorld *world, int enemy_index, 103 PhSpellBook spells); 104 void ph_battle_select(PhBattle *battle, PhWorld *world); 105 int ph_battle_spell_step(PhBattle *battle, int direction); 106 void ph_battle_cast(PhBattle *battle, PhWorld *world); 107 int ph_battle_target_step(PhBattle *battle, const PhWorld *world, int direction); 108 void ph_battle_confirm_target(PhBattle *battle, PhWorld *world); 109 void ph_battle_cancel(PhBattle *battle); 110 PhBattleResult ph_battle_update(PhBattle *battle, PhWorld *world, float dt, 111 int transition); 112 void ph_battle_order(const PhBattle *battle, const PhWorld *world, 113 int order[PH_BATTLE_ORDER_COUNT]); 114 const PhSpellDef *ph_spell_def(const PhBattle *battle, int id); 115 const PhSpellDef *ph_spellbook_def(const PhSpellBook *spells, int id); 116 int ph_spellbook_has(const PhSpellBook *spells, int id); 117 int ph_spellbook_learn(PhSpellBook *spells, int id); 118 int ph_spellbook_buy(PhSpellBook *spells, PhWorld *world, int entity_index, 119 int spell_id); 120 int ph_spellbook_use(const PhSpellBook *spells, PhWorld *world, int entity_index, 121 int spell_id); 122 const PhSpellDef *ph_battle_spell(const PhBattle *battle); 123 int ph_spell_battle_usable(const PhSpellDef *spell); 124 float ph_battle_lunge(const PhBattle *battle, PhBattlePhase phase); 125 PhBattleEvent ph_battle_take_event(PhBattle *battle); 126 127 #endif