Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
action_events.c
Go to the documentation of this file.
1/* FIGHTSTG's action events: the task that runs the events an action queued. */
2
4
5/* Takes the enemy's item into the bag (up to 99) and says so. */
6static inline void stealEnemyItem(ActionEvents *task, BattleChild *children) {
8
9 task->args[0] = enemy->item;
10 children[0].message->show(children[0].message, 0x11, task->args);
11 GAME.items[enemy->item]++;
12 if (GAME.items[enemy->item] >= 100) {
13 GAME.items[enemy->item] = 99;
14 }
15 enemy->item = -1;
16}
17
18/* Heals FIGHTER by the drained HP (up to its max HP) and says so. */
19static inline void drainHp(ActionEvents *task, BattleChild *children, BattleFighter *fighter) {
20 task->args[0] = task->side;
21 if (fighter->maxHp < fighter->hp + FIGHTSTG_action.drain) {
22 task->args[1] = fighter->maxHp - fighter->hp;
23 } else {
24 task->args[1] = FIGHTSTG_action.drain;
25 }
26 task->args[2] = 0;
27 children[0].message->show(children[0].message, 0x12, task->args);
28 fighter->hp += task->args[1];
29}
30
31/* Moves the drained MP (as much as the partner has) from the partner to the
32 enemy, up to its max MP, and says so. */
33static inline void drainMp(ActionEvents *task, BattleChild *children) {
36
37 task->args[0] = 0x10;
38 if (fighter->mp < FIGHTSTG_action.drain) {
39 task->args[1] = fighter->mp;
40 } else {
41 task->args[1] = FIGHTSTG_action.drain;
42 }
43 task->args[2] = 1;
44 children[0].message->show(children[0].message, 0x12, task->args);
45 enemy->mp += task->args[1];
46 if (enemy->maxMp < enemy->mp) {
47 enemy->mp = enemy->maxMp;
48 }
49 fighter->mp -= task->args[1];
50}
51
52/* Says which status (bit 0, 1 or 2 of the event's flags) the technique
53 raises. */
54static inline void showRaisedStatus(ActionEvents *task, BattleChild *children) {
55 task->args[0] = SIDE_ENEMY - task->side;
57 task->args[1] = 0;
59 task->args[1] = 1;
61 task->args[1] = 2;
62 }
63 children[0].message->show(children[0].message, 0x13, task->args);
64}
65
66/* Says the next status the technique raises and clears its bit, so the event
67 runs again for the remaining ones. */
68static inline void showNextRaisedStatus(ActionEvents *task, BattleChild *children) {
69 task->args[0] = SIDE_ENEMY - task->side;
71 task->args[1] = 0;
72 FIGHTSTG_action.effects[task->step] &= ~1;
74 task->args[1] = 1;
75 FIGHTSTG_action.effects[task->step] &= ~2;
77 task->args[1] = 2;
78 FIGHTSTG_action.effects[task->step] &= ~4;
79 }
80 children[0].message->show(children[0].message, 0x13, task->args);
81}
82
83/* Applies event I's status or battle effect (a poison, a lowered stat, an
84 escape...) and shows its message. */
85static inline void applyStatusEvent(ActionEvents *task, BattleChild *children, s32 i) {
86 s32 other = task->side != 0;
87
88 switch (i) {
90 default:
92 task->args[0] = 0x1E;
93 break;
96 task->args[0] = 0x1F;
97 break;
100 task->args[0] = 0x20;
101 break;
104 task->args[0] = 0x21;
105 break;
108 task->args[0] = 0x44;
109 break;
111 task->args[0] = 0x33;
112 break;
114 task->args[0] = 0x34;
115 break;
117 task->args[0] = 0x4C;
118 break;
120 task->args[0] = 0x48;
122 break;
123 }
124 task->args[1] = (task->side == 0) << 4;
125 children[0].message->show(children[0].message, 2, task->args);
126}
127
128/* Runs the queued battle events: the first flag set in FIGHTSTG_action.effects
129 picks the step, which shows its message, applies its effect and clears
130 the flag (stealEnemyItem, drainHp, drainMp, showRaisedStatus,
131 showNextRaisedStatus or applyStatusEvent). The match depends on each event
132 branch ending with its own flag clear and `break` (the copies are merged
133 after reload, but they make the loop big enough that loop.c leaves 0x10 at
134 each use), on `case 2` written next to `default` in applyStatusEvent's
135 switch (it sets the jump table's base) and on drainMp setting its fighter
136 and enemy before args[0]. */
138 BattleFighter *fighter;
139 u32 side;
140 s32 i;
141 switch (task->state) {
142 case 0:
143 default:
147 task->nextState(task);
148 break;
149 case 1:
150 switch (task->substate) {
151 case 0:
152 default:
153 for (i = 0; i < 0x25; i++) {
154 if (FIGHTSTG_action.effects[i] != 0) {
155 task->step = i;
156 side = task->side >> 4;
157 task->substate++;
158 fighter = &FIGHTSTG_battle.state.fighters[1 - side][FIGHTSTG_battle.state.active[1 - side]];
159 if (i == TECH_EFFECT_SLEEP && (fighter->flags & FIGHTER_ASLEEP)) {
161 FIGHTSTG_action.effects[task->step] = 0;
162 break;
163 } else {
164 children[0].message = FIGHTSTG_createMessage();
165 if (i == TECH_EFFECT_STEAL) {
166 stealEnemyItem(task, children);
167 FIGHTSTG_action.effects[task->step] = 0;
168 break;
169 } else if (i == TECH_EFFECT_DRAIN) {
171 drainHp(task, children, fighter);
172 FIGHTSTG_action.effects[task->step] = 0;
173 break;
174 } else if (i == TECH_EFFECT_DRAIN_MP) {
175 drainMp(task, children);
176 FIGHTSTG_action.effects[task->step] = 0;
177 break;
178 } else if (i == TECH_EFFECT_RAISE_ONE_STATUS) {
179 showRaisedStatus(task, children);
180 FIGHTSTG_action.effects[task->step] = 0;
181 break;
182 } else if (i == TECH_EFFECT_RAISE_EACH_STATUS) {
183 showNextRaisedStatus(task, children);
184 break;
185 } else {
186 applyStatusEvent(task, children, i);
187 }
188 }
189 FIGHTSTG_action.effects[task->step] = 0;
190 break;
191 }
192 }
193 if (task->step == 0) {
194 task->state = 3;
195 }
196 break;
197 case 1:
198 if (children[0].task == NULL) {
199 task->setSubstate(task, 0);
200 }
201 break;
202 }
203 break;
204 case 2:
205 case 3:
206 break;
207 }
208}
209
210/* Starts running the current action's events for SIDE
211 (FIGHTSTG_updateActionEvents) */
214
215 task->side = side;
216 return task;
217}
ActionEvents * FIGHTSTG_startActionEvents(s32 side)
Starts running the current action's events for SIDE (FIGHTSTG_updateActionEvents)
static void stealEnemyItem(ActionEvents *task, BattleChild *children)
Takes the enemy's item into the bag (up to 99) and says so.
static void drainMp(ActionEvents *task, BattleChild *children)
Moves the drained MP (as much as the partner has) from the partner to the enemy, up to its max MP,...
static void showRaisedStatus(ActionEvents *task, BattleChild *children)
Says which status (bit 0, 1 or 2 of the event's flags) the technique raises.
static void showNextRaisedStatus(ActionEvents *task, BattleChild *children)
Says the next status the technique raises and clears its bit, so the event runs again for the remaini...
static void drainHp(ActionEvents *task, BattleChild *children, BattleFighter *fighter)
Heals FIGHTER by the drained HP (up to its max HP) and says so.
static void applyStatusEvent(ActionEvents *task, BattleChild *children, s32 i)
Applies event I's status or battle effect (a poison, a lowered stat, an escape...) and shows its mess...
void FIGHTSTG_updateActionEvents(ActionEvents *task, BattleChild *children)
Runs the queued battle events: the first flag set in FIGHTSTG_action.effects picks the step,...
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
void FIGHTSTG_startRestriction(s32 tech)
Restricts the partner with technique tech: sets FIGHTER_NO_SWITCH or FIGHTER_NO_DIGIVOLVE by the tech...
Definition battle.c:43
#define TECH_EFFECT_POISON
Definition battle.h:252
#define TECH_EFFECT_MULTI_HIT
Definition battle.h:258
#define TECH_EFFECT_SLEEP
Definition battle.h:255
#define TECH_EFFECT_CONFUSION
Definition battle.h:254
#define BATTLE_FLED
How a battle ends (FIGHTSTG_endBattle)
Definition battle.h:133
#define TECH_EFFECT_PARALYSIS
Definition battle.h:253
#define TECH_EFFECT_DRAIN_MP
the partner's, in 128ths of its max MP
Definition battle.h:266
#define TECH_EFFECT_ENEMY_ONLY
does nothing but for the enemy whose battle table entry lists it first
Definition battle.h:259
#define TECH_EFFECT_END_BATTLE
in BATTLE_KIND_UNK2: takes 70 percent of the partner's HP, ends as BATTLE_FLED
Definition battle.h:271
#define TECH_EFFECT_DRAIN
HP, in 128ths of the damage.
Definition battle.h:257
#define TECH_EFFECT_RAISE_ALL_STATUS
Definition battle.h:270
#define TECH_EFFECT_LOWER_DEFENSE
Definition battle.h:265
#define TECH_EFFECT_NO_SWITCH
FIGHTER_NO_SWITCH for a while.
Definition battle.h:262
#define TECH_EFFECT_LOWER_ATTACK
Definition battle.h:264
#define TECH_EFFECT_STEAL
the enemy's item
Definition battle.h:261
#define TECH_EFFECT_RAISE_EACH_STATUS
each one that a roll lets
Definition battle.h:269
#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
#define TECH_EFFECT_RAISE_ONE_STATUS
PartnerStats.status: one at random.
Definition battle.h:268
#define TECH_EFFECT_CRITICAL
raises the critical hit chance
Definition battle.h:260
void FIGHTSTG_inflictConfusion(u8 side, s32 fromTech, u8 strength)
Confuses side's active fighter (FIGHTER_CONFUSED) with a strength, and queues its end (put off by the...
Definition events.c:506
void FIGHTSTG_inflictParalysis(u8 side, s32 unused, u8 strength)
Paralyzes side's active fighter (FIGHTER_PARALYZED) with a strength, and queues its end,...
Definition events.c:481
void FIGHTSTG_inflictPoison(u8 side, s32 fighter, s32 damage)
Poisons a fighter (FIGHTER_POISONED), and queues its damage or updates the one already queued.
Definition events.c:456
void FIGHTSTG_inflictSleep(u8 side, s32 unused, u8 strength)
Puts side's active fighter to sleep (FIGHTER_ASLEEP) with a strength, and queues its end,...
Definition events.c:535
void FIGHTSTG_endBattle(s32 result)
Ends the battle: queues event 1 ahead of the others, with how it ended (BATTLE_FLED,...
Definition events.c:377
FIGHTSTG.PRO: the battle.
#define NULL
Definition common.h:17
signed int s32
Definition common.h:11
unsigned int u32
Definition common.h:12
GameState GAME
The save data, the game mode and the methods.
Definition state.c:64
BattleMessageBox * FIGHTSTG_createMessage(void)
Creates a battle message box (FIGHTSTG_updateMessage)
Definition message.c:440
FIGHTSTG_updateActionEvents's task (FIGHTSTG_startActionEvents)
Definition action.h:91
void(* setSubstate)(struct ActionEvents *task, s32 substate)
Definition action.h:92
s32 state
Definition action.h:92
u8 side
0 or 0x10
Definition action.h:93
s32 args[3]
Definition action.h:94
s32 substate
Definition action.h:92
void(* nextState)(struct ActionEvents *task)
Definition action.h:92
s32 tech
the technique
Definition battle.h:277
s32 drain
the HP or MP that TECH_EFFECT_DRAIN or TECH_EFFECT_DRAIN_MP takes
Definition battle.h:279
u8 effects[0x28]
by TECH_EFFECT_*: what each one does, 0 for none
Definition battle.h:283
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 item
an enemy's
Definition battle.h:201
void(* show)()
FIGHTSTG_showMessage: (task, type, data)
Definition menu.h:182
s32 active[2]
each side's fighter
Definition battle.h:226
BattleFighter fighters[2][3]
Definition battle.h:227
BattleState state
Definition battle.h:240
s8 items[0x193]
counts, up to 99
Definition game_state.h:512
Any task, seen through its header.
Definition task.h:62
void * createTask(void(*update)(), s32 size, s32 childrenSize)
createTaskWithId for a task nothing needs to find
Definition task.c:105
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
BattleMessageBox * message
FIGHTSTG_createMessage.
Definition task.h:18