Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
enemy_attack.c
Go to the documentation of this file.
1/* FIGHTSTG's enemy attacks, which WFIGHTMN starts for the enemy's turns. */
2
4
5/* Queues the enemy's next turn and says the technique it uses (the weakened
6 enemy's own one, or ends the attack while its weakness lasts), noting
7 whether the player's fighter was asleep. */
8static inline void announceEnemyTech(EnemyAttack *task, BattleChild *children, BattleTableEntry *entry) {
12 task->setState(task, 3);
13 } else {
14 children[0].message = FIGHTSTG_createMessage();
15 task->lines[0] = 8;
16 task->lines[1] = 0x10;
17 task->tech = entry->techs[2];
18 children[0].message->show(children[0].message, 2, task->lines);
21 task->resetIdleMotion = 1;
22 }
23 } else {
24 children[0].message = FIGHTSTG_createMessage();
25 task->lines[0] = 0x10;
26 task->lines[1] = FIGHTSTG_battle.state.tech != 0 ? FIGHTSTG_battle.state.tech : entry->techs[0];
27 children[0].message->show(children[0].message, 3, task->lines);
28 task->tech = entry->techs[0];
29 }
30 if (ACTIVE_FIGHTER(0)->flags & FIGHTER_ASLEEP) {
31 task->asleep = 1;
32 }
33}
34
35/* Shows the technique's damage and takes it from the player's active
36 fighter's HP (the European version's instant knockout takes it all). */
37static inline void damagePlayer(EnemyAttack *task, BattleChild *children) {
38 BattleFighter *player;
39
40#if VERSION_EU || VERSION_JP
42 /* the European version's instant knockout */
44 player->hp = 0;
45 children[0].task->state = 3;
46 } else {
47 task->lines[0] = 0;
48 task->lines[1] = FIGHTSTG_action.damage;
49 children[0].message->show(children[0].message, 4, task->lines);
50 player->hp -= FIGHTSTG_action.damage;
51 if (player->hp <= 0) {
52 player->hp = 0;
53 }
54 }
55#else
56 task->lines[0] = 0;
57 task->lines[1] = FIGHTSTG_action.damage;
58 children[0].message->show(children[0].message, 4, task->lines);
60 player->hp -= FIGHTSTG_action.damage;
61 if (player->hp <= 0) {
62 player->hp = 0;
63 }
64#endif
65}
66
67/* Wakes the player's sleeping FIGHTER up and says so, ending its sleep's
68 event. */
69static inline void wakePlayerUp(EnemyAttack *task, BattleChild *children, BattleFighter *fighter) {
70 s32 index;
71
72 task->lines[0] = 0x2B;
73 task->lines[1] = 0;
74 task->lines[2] = FIGHTSTG_battle.state.active[0];
75 children[0].message = FIGHTSTG_createMessage();
76 children[0].message->show(children[0].message, 7, task->lines);
77 fighter->flags &= ~FIGHTER_ASLEEP;
79 if (index >= 0) {
80 FIGHTSTG_events.events[index].type = 0;
81 }
82}
83
84/* The other attack's result: its damage (queueing the player's knockout at
85 0 HP unless the attack was started without, else charging the enemy's
86 gauge) or its miss message. */
87static inline void showOtherAttackResult(EnemyAttack *task, BattleChild *children) {
88 BattleFighter *struck;
89
90 if (FIGHTSTG_action.hits[0]) {
91 task->lines[0] = 0;
92 task->lines[1] = FIGHTSTG_action.damage;
93 children[0].message->show(children[0].message, 4, task->lines);
95 struck->hp -= FIGHTSTG_action.damage;
96 if (struck->hp <= 0) {
97 struck->hp = 0;
98 if (task->noKnockout == 0) {
100 }
101 } else {
103 }
104 } else {
105 task->lines[0] = 0x1D;
106 task->lines[1] = 0;
107 children[0].message->show(children[0].message, 2, task->lines);
108 }
109}
110
111/* An attack on the player's active fighter (FIGHTSTG_startEnemyAttack): state 1 is the
112 enemy's technique, 2 another attack, each with its messages, motion and
113 damage. The match depends on each case advancing substate itself and on
114 a fighter variable of its own in each case. */
117 BattleFighter *fighter;
118 BattleFighter *target;
119
120 switch (task->state) {
121 case TASK_INIT:
122 default:
123 task->setState(task, task->kind + 1);
124 break;
125 case TASK_RUN:
126 switch (task->substate) {
127 case 0:
128 default:
129 announceEnemyTech(task, children, entry);
130 task->substate++;
131 break;
132 case 1:
133 if (children[0].task == NULL) {
134 FIGHTSTG_action.start(0x10, task->tech);
135 children[0].script = WFIGHTMN_startTech(0x10, task->tech);
136 if (task->resetIdleMotion != 0) {
138 task->resetIdleMotion = 0;
139 }
140 task->substate++;
141 }
142 break;
143 case 2:
144 if (children[0].task == NULL) {
145 children[0].message = FIGHTSTG_createMessage();
146 if (FIGHTSTG_action.hits[0]) {
147 damagePlayer(task, children);
148 task->substate++;
149 } else {
150 task->lines[0] = 0x1D;
151 task->lines[1] = 0;
152 children[0].message->show(children[0].message, 2, task->lines);
153 task->substate = 5;
154 }
155 }
156 break;
157 case 3:
158 if (children[0].task == NULL) {
160#if VERSION_EU || VERSION_JP
162 target->hp = 0;
164 task->state = 3;
165 } else
166#endif
167 if (target->hp <= 0) {
168 target->hp = 0;
170 task->state = 3;
171 } else {
172 children[0].events = FIGHTSTG_startActionEvents(0x10);
173 task->substate++;
174 }
175 }
176 break;
177 case 4:
178 if (children[0].task == NULL) {
180 if (fighter->flags & FIGHTER_ASLEEP) {
181 if (task->asleep != 0 && FIGHTSTG_battleFuncs.testWakeUp(0, FIGHTSTG_action.damage) != 0) {
182 wakePlayerUp(task, children, fighter);
183 task->substate = 5;
184 } else {
185 task->state = 3;
186 }
187 } else {
188 task->substate = 5;
189 }
190 }
191 break;
192 case 5:
193 if (children[0].task == NULL) {
195 task->state = 3;
196 }
197 break;
198 }
199 break;
200 case 2:
201 if (children[0].task == NULL) {
202 switch (task->substate) {
203 case 0:
204 default:
205 children[0].message = FIGHTSTG_createMessage();
206 task->lines[0] = 0x10;
207 children[0].message->show(children[0].message, 6, task->lines);
208 task->substate++;
209 break;
210 case 1:
211 FIGHTSTG_action.start(0x10, entry->techs[1]);
212 children[0].script = WFIGHTMN_startTech(0x10, entry->techs[1]);
213 task->substate++;
214 break;
215 case 2:
216 children[0].message = FIGHTSTG_createMessage();
217 showOtherAttackResult(task, children);
218 task->substate++;
219 break;
220 case 3:
222 task->state = 3;
223 break;
224 }
225 }
226 break;
227 case 3:
228 break;
229 }
230}
231
232/* Starts an attack on the player's active fighter (FIGHTSTG_updateEnemyAttack):
233 kind 0 for the enemy's technique, 1 for another attack */
236
237 task->kind = kind;
238 task->noKnockout = noKnockout;
239 return task;
240}
ActionEvents * FIGHTSTG_startActionEvents(s32 side)
Starts running the current action's events for SIDE (FIGHTSTG_updateActionEvents)
BattleAction FIGHTSTG_action
the command being carried out
Definition battle.c:12
Battle FIGHTSTG_battle
the battle: its fighters, speed and drawing functions
Definition battle.c:16
BattleFuncs FIGHTSTG_battleFuncs
the battle's stats and the functions that compute with them
Definition battle.c:25
void FIGHTSTG_queueKnockOut(u8 side)
Queues the fall of side's active fighter (event 20), first.
Definition battle.c:107
void FIGHTSTG_endEnemyWeakness(void)
Ends the enemy's weakness now: its queued event 24 runs next.
Definition battle.c:173
#define EVENT_WEAKNESS_END
the end of the enemy's weakness (BATTLE_KIND_FINAL_LAST)
Definition battle.h:99
#define TECH_EFFECT_KNOCK_OUT
Definition battle.h:256
#define ACTIVE_FIGHTER(side)
SIDE's active fighter as its row plus the index, which GCC adds with the row's address first.
Definition battle.h:493
#define EVENT_STATUS_END
10-12: the end of FIGHTER_PARALYZED, FIGHTER_CONFUSED or FIGHTER_ASLEEP
Definition battle.h:90
#define FIGHTER_ASLEEP
can't act or run away; a hit may wake it up
Definition battle.h:185
#define SIDE_ENEMY
Definition battle.h:178
EventQueue FIGHTSTG_events
the battle's events and their functions
Definition events.c:43
void FIGHTSTG_queueEnemyTurn(s32 delay)
Queues the enemy's turn (event 3) in delay.
Definition events.c:368
FIGHTSTG.PRO: the battle.
BattleTableEntry *(* FIGHTSTG_battleTableFunc)(s32 id)
how the fight stage and WFIGHTMN read the battle table
#define NULL
Definition common.h:17
signed int s32
Definition common.h:11
static void wakePlayerUp(EnemyAttack *task, BattleChild *children, BattleFighter *fighter)
Wakes the player's sleeping FIGHTER up and says so, ending its sleep's event.
void FIGHTSTG_updateEnemyAttack(EnemyAttack *task, BattleChild *children)
An attack on the player's active fighter (FIGHTSTG_startEnemyAttack): state 1 is the enemy's techniqu...
static void announceEnemyTech(EnemyAttack *task, BattleChild *children, BattleTableEntry *entry)
Queues the enemy's next turn and says the technique it uses (the weakened enemy's own one,...
Definition enemy_attack.c:8
static void showOtherAttackResult(EnemyAttack *task, BattleChild *children)
The other attack's result: its damage (queueing the player's knockout at 0 HP unless the attack was s...
static void damagePlayer(EnemyAttack *task, BattleChild *children)
Shows the technique's damage and takes it from the player's active fighter's HP (the European version...
EnemyAttack * FIGHTSTG_startEnemyAttack(s32 kind, s32 noKnockout)
Starts an attack on the player's active fighter (FIGHTSTG_updateEnemyAttack): kind 0 for the enemy's ...
#define TASK_RUN
Definition task.h:35
#define TASK_INIT
Tasks: every game object is a task, a heap block that starts with this header and is updated once per...
Definition task.h:34
BattleMessageBox * FIGHTSTG_createMessage(void)
Creates a battle message box (FIGHTSTG_updateMessage)
Definition message.c:440
u8 effects[0x28]
by TECH_EFFECT_*: what each one does, 0 for none
Definition battle.h:283
void(* start)(u8 side, s32 tech)
FIGHTSTG_startAction.
Definition battle.h:285
s32 damage
per hit
Definition battle.h:278
u8 hits[4]
whether each hit lands
Definition battle.h:280
One of the battle's fighters, three on each side (WFIGHTMN's BattleUnit): a partner's HP and MP go ba...
Definition battle.h:191
u8 flags
FIGHTER_*.
Definition battle.h:204
s16 id
the Digimon (DIGIMON_DATA)
Definition battle.h:192
s32(* testWakeUp)(u8 side, s32 value)
Definition battle.h:356
void(* show)()
FIGHTSTG_showMessage: (task, type, data)
Definition menu.h:182
s8 hitCount
BATTLE_KIND_FINAL_LAST: the partner's hits that did damage.
Definition battle.h:232
s32 active[2]
each side's fighter
Definition battle.h:226
BattleFighter fighters[2][3]
Definition battle.h:227
u8 weakened
BATTLE_KIND_FINAL_LAST: the enemy is weakened (FIGHTSTG_weakenEnemy)
Definition battle.h:233
s16 tech
a technique id, set by WFIGHTMN
Definition battle.h:231
s16 techs[3]
its first, then those of FIGHTSTG_getEnemyAction's kinds 2 and 3
Definition battle.h:63
BattleState state
Definition battle.h:240
FIGHTSTG_updateEnemyAttack's task (FIGHTSTG_startEnemyAttack): an attack on the player's active fight...
Definition action.h:79
s32 noKnockout
don't knock the fighter out at 0 HP
Definition action.h:86
void(* setState)(struct EnemyAttack *task, s32 state)
Definition action.h:80
s32 state
Definition action.h:80
s32 substate
Definition action.h:80
s32 resetIdleMotion
the weakness ended: WFIGHTMN_setIdleMotion once the technique starts
Definition action.h:82
s32 tech
the technique
Definition action.h:84
s32 asleep
the fighter was asleep
Definition action.h:87
s32 kind
0 the enemy's technique, 1 another attack
Definition action.h:85
s32 lines[4]
FIGHTSTG_updateMessage's.
Definition action.h:81
s32(* first)(s32 type)
Definition battle.h:144
s32(* getDelay)(u8 side, s32 kind)
FIGHTSTG_getEventDelay: when an event of side's runs.
Definition battle.h:148
s32(* find)(s32 type, u8 side, s32 fighter)
Definition battle.h:146
EventQueueFuncs funcs
Definition battle.h:171
QueuedEvent events[99]
Definition battle.h:165
s16 type
0 for a free entry
Definition battle.h:110
Any task, seen through its header.
Definition task.h:62
s32 state
Definition task.h:63
void * createTask(void(*update)(), s32 size, s32 childrenSize)
createTaskWithId for a task nothing needs to find
Definition task.c:105
BattleScript * WFIGHTMN_startTech(u8 actor, s32 id)
Starts the effect of actor's move id (FIGHTSTG's FIGHTSTG_createBattleScript): its kind and motions f...
Definition techs.c:150
void WFIGHTMN_chargeGauge(u8 side, s32 damage)
Adds what damage gives to the current partner's gauge (BATTLE_SETUP.gauges), up to 1000.
Definition techs.c:35
s32 WFIGHTMN_setIdleMotion(u8 id, s32 damage)
Sets the idle motion of side id >> 4's fighter: 1 (weak) if damage leaves it with a quarter of its HP...
Definition techs.c:280
A turn's or a counterattack's one child, and what WFIGHTMN's battle menu waits for (NULL when it is d...
Definition task.h:16
ActionEvents * events
the queued events (FIGHTSTG_startActionEvents)
Definition task.h:33
BattleMessageBox * message
FIGHTSTG_createMessage.
Definition task.h:18
Task * task
Definition task.h:17
BattleScript * script
a technique's (FIGHTSTG_createBattleScript)
Definition task.h:19