Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
tech_effects.c
Go to the documentation of this file.
1/* FIGHTSTG's technique effects and the start of an action. */
2
4
5/* TECH_EFFECT_POISON: poisons the target when rollPoison lets it, twice as
6 strongly when the acting fighter is special */
8 s32 side = FIGHTSTG_action.side != 0;
11
12 if (value != 0) {
13 if (fighter->special) {
14 value *= 2;
15 }
17 }
18}
19
20/* TECH_EFFECT_PARALYSIS: paralyzes the target when rollParalysis lets it, with
21 the technique's effectPower or the accessory's, twice as strongly when the acting
22 fighter is special */
26 s32 side = action->side != 0;
28 TechData *entry;
29 s32 value;
30
31 if (funcs->rollParalysis(action->side, action->tech)) {
32 entry = &TECHS[action->tech - 1];
33 if (entry->effect < TECH_EFFECT_FIRST) {
34 value = funcs->stats[0].statuses[HIT_PARALYSIS].power;
35 } else {
36 value = entry->effectPower;
37 }
38 if (fighter->special) {
39 value *= 2;
40 }
42 }
43}
44
45/* TECH_EFFECT_CONFUSION: confuses the target when rollConfusion lets it, with
46 the technique's effectPower or the accessory's, twice as strongly when the acting
47 fighter is special */
51 s32 side = action->side != 0;
53 TechData *entry;
54 s32 value;
55
56 if (funcs->rollConfusion(action->side, action->tech)) {
57 entry = &TECHS[action->tech - 1];
58 if (entry->effect < TECH_EFFECT_FIRST) {
59 value = funcs->stats[0].statuses[HIT_CONFUSION].power;
60 } else {
61 value = entry->effectPower;
62 }
63 if (fighter->special) {
64 value *= 2;
65 }
67 }
68}
69
70/* TECH_EFFECT_SLEEP: puts the target to sleep when rollSleep lets it, twice
71 as strongly when the acting fighter is special */
73 s32 side = FIGHTSTG_action.side != 0;
75 TechData *entry;
76 s32 value;
77
79 entry = &TECHS[FIGHTSTG_action.tech - 1];
80 value = entry->effectPower;
81 if (fighter->special) {
82 value *= 2;
83 }
84 FIGHTSTG_action.effects[entry->effect] = value;
85 }
86}
87
88/* TECH_EFFECT_KNOCK_OUT: knocks the target out when rollKnockOut lets it */
91
92 if (FIGHTSTG_battleFuncs.rollKnockOut(action->side, action->tech)) {
93 action->effects[TECH_EFFECT_KNOCK_OUT] = 1;
94 }
95}
96
97/* TECH_EFFECT_MULTI_HIT and the triple-hit accessory: rolls the other hits, 3
98 or the technique's hitCount in all; in BATTLE_KIND_FINAL_LAST the player's
99 missed first hit makes them all miss */
101 s32 count = 3;
102 BattleAction *action = &FIGHTSTG_action;
103 Battle *battle = &FIGHTSTG_battle;
104 TechData *entry = &TECHS[action->tech - 1];
105 s32 i;
106 s32 side;
107
108 side = action->side;
109 if (entry->effect >= TECH_EFFECT_FIRST) {
110 count = entry->hitCount;
111 }
112#if VERSION_US
113 action->hitsLanded = 0;
114 action->hitCount = 0;
115#elif VERSION_EU || VERSION_JP
116 action->hitsLanded = action->hits[0];
117 action->hitCount = 1;
118#endif
119 if (side == 0 && battle->state.kind == BATTLE_KIND_FINAL_LAST && action->hits[0] == 0) {
120 action->hitCount = count;
121 } else {
122#if VERSION_US
123 for (i = 0; i < count; i++) {
124#elif VERSION_EU || VERSION_JP
125 for (i = 1; i < count; i++) {
126#endif
130 } else {
132 }
133 }
134 }
136}
137
138/* When rollDrain allows it, the action's drain becomes its damage times a 128th of
139 * the technique's effectPower (effect 8) or the player's HIT_DRAIN power, doubled when the
140 * acting fighter is special. The match depends on each branch doubling
141 * and scaling its own value. */
143 BattleAction *action = &FIGHTSTG_action;
145 s32 side = action->side != 0;
147 TechData *entry;
148 s32 value;
149
150 if (funcs->rollDrain(action->side, action->tech)) {
151 entry = &TECHS[action->tech - 1];
152 if (entry->effect == TECH_EFFECT_DRAIN) {
153 value = entry->effectPower;
154 if (fighter->special) {
155 value *= 2;
156 }
157 action->drain = action->damage * value / 128;
158 } else {
159 value = funcs->stats[0].statuses[HIT_DRAIN].power;
160 if (fighter->special) {
161 value *= 2;
162 }
163 action->drain = action->damage * value / 128;
164 }
166 }
167}
168
169/* Marks the action's technique's effect with the effect itself */
170static inline void markTechEffect(void) {
171 BattleAction *action = &FIGHTSTG_action;
172 TechData *entry = &TECHS[action->tech - 1];
173
174 action->effects[entry->effect] = entry->effect;
175}
176
177/* TECH_EFFECT_ENEMY_ONLY outside its own enemy's hands: marks the effect,
178 which takes the place of the hit */
181}
182
183/* TECH_EFFECT_CRITICAL: marks the effect, which rollCritical has used */
186}
187
188/* TECH_EFFECT_STEAL: when the enemy's active fighter holds an
189 * item and rollSteal lets the player take it, marks the effect and loads the item
190 * names. The match depends on funcs being a const pointer: the front end puts
191 * its value in the call, so only the %hi of its own initialization is left
192 * for CSE to share with the call's address. */
194 BattleFuncs *const funcs = &FIGHTSTG_battleFuncs;
196 TechData *entry;
197
198 if (enemies[FIGHTSTG_battle.state.active[1]].item > 0) {
199 if (funcs->rollSteal(0, FIGHTSTG_action.tech) != 0) {
200 entry = &TECHS[FIGHTSTG_action.tech - 1];
201 FIGHTSTG_action.effects[entry->effect] = 1;
203 }
204 }
205}
206
207/* TECH_EFFECT_LOWER_ATTACK: lowers the attack of the other side's active
208 * fighter by the technique's effectPower in 128ths and starts its event (not when
209 * side 0 acts with BATTLE_BLOCK_LOWER_ATTACK set). The match depends on team
210 * being a u8. */
223
224/* TECH_EFFECT_LOWER_DEFENSE: lowers the defense of the other side's active fighter
225 by the technique's effectPower in 128ths and starts its event */
234
235/* TECH_EFFECT_DRAIN_MP: takes the technique's effectPower in 128ths of the player's
236 fighter's max MP, at most what it has, as the action's drain */
239 TechData *entry = &TECHS[FIGHTSTG_action.tech - 1];
240
241 if (fighter->mp != 0) {
242 FIGHTSTG_action.drain = fighter->maxMp * entry->effectPower / 128;
243 if (fighter->mp < FIGHTSTG_action.drain) {
244 FIGHTSTG_action.drain = fighter->mp;
245 }
247 }
248}
249
250/* TECH_EFFECT_RAISE_ONE_STATUS: when rollStatusRaise lets it, raises one of
251 the partner's status values at random by the technique's effectPower */
253 s32 i = RANDOM.next() % 2;
254 TechData *entry;
255 PartnerStats *stats;
256
258 entry = &TECHS[FIGHTSTG_action.tech - 1];
260 stats->status[i] += entry->effectPower;
261 FIGHTSTG_action.effects[entry->effect] = 1 << i;
262 }
263}
264
265/* TECH_EFFECT_RAISE_EACH_STATUS: raises each of the partner's status values
266 that rollStatusRaise lets by the technique's effectPower */
268 TechData *entry = &TECHS[FIGHTSTG_action.tech - 1];
270 s32 i;
271
272 for (i = 0; i < 3; i++) {
274 stats->status[i] += entry->effectPower;
275 FIGHTSTG_action.effects[entry->effect] |= 1 << i;
276 }
277 }
278}
279
280/* TECH_EFFECT_RAISE_ALL_STATUS: when rollStatusRaise lets it, raises all of
281 the partner's status values by the technique's effectPower */
283 BattleAction *action = &FIGHTSTG_action;
284 TechData *entry = &TECHS[action->tech - 1];
286 s32 i;
287
288 if (FIGHTSTG_battleFuncs.rollStatusRaise(action->side, action->tech)) {
289 for (i = 0; i < 3; i++) {
290 stats->status[i] += entry->effectPower;
291 }
292 FIGHTSTG_action.effects[entry->effect] = 7;
293 }
294}
295
296/* TECH_EFFECT_NO_SWITCH: marks the effect when rollNoSwitch lets it */
298 TechData *entry;
299
301 entry = &TECHS[FIGHTSTG_action.tech - 1];
302 FIGHTSTG_action.effects[entry->effect] = 1;
303 }
304}
305
306/* Starts a TECH_EFFECT_DOUBLE_MAGIC technique: two magic hits, each with the
307 damage of technique 0x1B9 or 0x1BA */
309#if VERSION_EU || VERSION_JP
310 s32 files[2] = { 0x1B9, 0x1BA };
311#endif
312 s32 i;
313
316 for (i = 0; i < 2; i++) {
318 FIGHTSTG_action.hits[i] = 1;
319#if VERSION_EU || VERSION_JP
321#endif
323 }
324 }
325#if VERSION_US
328#endif
330}
331
332/* Starts a TECH_EFFECT_END_BATTLE technique: in BATTLE_KIND_UNK2 its effect,
333 elsewhere a plain physical hit */
346
347/* Carries out the effect of a technique whose hit landed */
349 TechData *entry = &TECHS[FIGHTSTG_action.tech - 1];
350
351 switch (entry->effect) {
354 break;
357 break;
360 break;
363 break;
366 break;
369 break;
372 break;
375 break;
378 break;
381 break;
384 break;
387 break;
390 break;
393 break;
396 break;
397 }
398}
399
400
401/* Starts side's technique: rolls its hits and damage, then its effect or, for
402 the player's plain techniques, the accessories' effects; outside normal
403 battles WFIGHTMN_limitDamage caps the damage */
404void FIGHTSTG_startAction(u8 side, s32 tech) {
405 TechData *entry;
406
408 entry = &TECHS[tech - 1];
409 FIGHTSTG_action.side = side;
410 FIGHTSTG_action.tech = tech;
411 if (entry->effect == TECH_EFFECT_DOUBLE_MAGIC) {
413 } else if (entry->effect == TECH_EFFECT_END_BATTLE) {
415 } else {
416 if (entry->effect == TECH_EFFECT_ENEMY_ONLY &&
417 (side == 0 || FIGHTSTG_battleTableFunc(ACTIVE_FIGHTER(1)->id)->techs[0] != tech)) {
419 return;
420 }
421 switch (entry->icon) {
422 case TECH_PHYSICAL:
426 /* the match depends on the second test of TECH_EFFECT_MULTI_HIT,
427 which the compiler merges with the first and with case 3's */
428 if (side == 0) {
429 if (entry->effect < TECH_EFFECT_FIRST) {
430 if (entry->script == 11 || entry->script == 12) {
431 break;
432 }
435 break;
436 }
437 if (FIGHTSTG_action.hits[0] == 0) {
438 break;
439 }
442 }
445 }
448 }
451 }
454 }
455 } else if (entry->effect == TECH_EFFECT_MULTI_HIT) {
457 } else if (FIGHTSTG_action.hits[0]) {
459 }
460 } else if (entry->effect >= TECH_EFFECT_FIRST) {
461 if (entry->effect == TECH_EFFECT_MULTI_HIT) {
463 } else if (FIGHTSTG_action.hits[0]) {
465 }
466 }
467 break;
468 case TECH_MAGIC:
472 if (entry->effect < TECH_EFFECT_FIRST) {
473 break;
474 }
475 if (entry->effect == TECH_EFFECT_MULTI_HIT) {
477 } else if (FIGHTSTG_action.hits[0]) {
479 }
480 break;
481 }
482 }
485 }
486}
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
#define TECH_EFFECT_POISON
Definition battle.h:252
#define HIT_CONFUSION
Definition battle.h:291
#define BATTLE_ACTION_STATE_SIZE
FIGHTSTG_action's bytes before start, which a new action clears.
Definition battle.h:386
#define TECH_EFFECT_DOUBLE_MAGIC
two magic hits, as techniques 0x1B9 and 0x1BA
Definition battle.h:267
#define HIT_DRAIN
its power is in 128ths of the damage
Definition battle.h:293
#define TECH_EFFECT_MULTI_HIT
Definition battle.h:258
#define TECH_EFFECT_FIRST
A technique's effect (TechData.effect), which FIGHTSTG_applyTechEffect carries out when its hit lands...
Definition battle.h:251
#define TECH_EFFECT_SLEEP
Definition battle.h:255
#define TECH_EFFECT_CONFUSION
Definition battle.h:254
#define BATTLE_KIND_NORMAL
The kinds of battle (Battle.kind), which WFIGHTMN picks by the battle and the mode it came from.
Definition battle.h:124
#define TECH_EFFECT_PARALYSIS
Definition battle.h:253
#define TECH_MAGIC
FIGHTSTG_rollMagicHit and FIGHTSTG_computeMagicDamage.
Definition battle.h:43
#define BATTLE_KIND_UNK2
the enemy keeps an eleventh of its HP
Definition battle.h:126
#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_KNOCK_OUT
Definition battle.h:256
#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 HIT_POISON
The statuses a weapon's hits can inflict (BattleStats.statuses)
Definition battle.h:289
#define TECH_EFFECT_RAISE_ALL_STATUS
Definition battle.h:270
#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 TECH_PHYSICAL
TechData.icon's kinds of attack.
Definition battle.h:42
#define HIT_KNOCK_OUT
its power is read by nothing
Definition battle.h:292
#define BATTLE_KIND_FINAL_LAST
its third enemy; winning plays the ending
Definition battle.h:130
#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 HIT_PARALYSIS
Definition battle.h:290
#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 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_queueBoostEnd(u8 side, s32 fighter, s32 kind, s32 tech)
Queues the end of a fighter's boost of stat kind, 12 frames on when a technique (tech) gave it and 8 ...
Definition events.c:565
FIGHTSTG.PRO: the battle.
BattleTableEntry *(* FIGHTSTG_battleTableFunc)(s32 id)
how the fight stage and WFIGHTMN read the battle table
signed int s32
Definition common.h:11
unsigned char u8
Definition common.h:8
GameState GAME
The save data, the game mode and the methods.
Definition state.c:64
#define TEXT_FILE(file)
Definition file.h:190
#define TEXT_ITEM_NAMES
ITMNAM.
Definition file.h:215
FileCache FILE_CACHE
The file cache.
Definition file_cache.c:7
#define BATTLE_BLOCK_LOWER_ATTACK
to 10: attack, defense, speed (a technique's boost stat + 8)
Definition game_state.h:371
Heap HEAP
The functions that return what a call left in v0 (allocMemHigh, findTask) and the ones that take othe...
Definition heap.c:184
TechData TECHS[443]
The techniques, from 1: technique n is TECHS[n - 1].
Definition items.c:906
BattleSetup BATTLE_SETUP
Definition items.c:886
Random RANDOM
Definition random.c:533
FIGHTSTG_action: the technique being carried out.
Definition battle.h:274
s32 tech
the technique
Definition battle.h:277
u8 side
the acting side, SIDE_PLAYER or SIDE_ENEMY
Definition battle.h:276
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
s16 hitCount
rolled in hits
Definition battle.h:282
s16 hitsLanded
Definition battle.h:281
s32 damage
per hit
Definition battle.h:278
u8 hits[4]
whether each hit lands
Definition battle.h:280
s32 hitDamage[2]
TECH_EFFECT_DOUBLE_MAGIC's.
Definition battle.h:284
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
s16 item
an enemy's
Definition battle.h:201
u8 special
the partner's special state (EVENT_SPECIAL_END): doubles its effects
Definition battle.h:203
FIGHTSTG_battleFuncs.
Definition battle.h:329
s32(* rollMagicHit)(u8 side, s32 id)
Definition battle.h:339
s32(* rollSleep)(u8 side, s32 id)
Definition battle.h:343
void(* changeBoost)(u8 side, s32 index, s32 stat, s32 percent)
changes a fighter's stat boost
Definition battle.h:359
s32(* rollKnockOut)(u8 side, s32 id)
Definition battle.h:344
BattleStats stats[2]
the player's, then the enemy's
Definition battle.h:330
s32(* rollNoSwitch)(s32 actor, s32 id)
Definition battle.h:349
s32(* rollConfusion)(u8 side, s32 id)
Definition battle.h:342
s32(* rollPoison)(u8 side, s32 id)
Definition battle.h:340
s32(* rollHit)(u8 side, s32 tech)
whether a hit lands
Definition battle.h:338
s32(* computeMagicDamage)(u8 side, s32 id)
Definition battle.h:333
s32(* rollDrain)(u8 side, s32 id)
Definition battle.h:346
s32(* rollSteal)(u8 side, s32 id)
Definition battle.h:345
s32(* rollStatusRaise)(s32 actor, s32 id)
Definition battle.h:348
s32(* computeDamage)(u8 side, s32 tech)
of each hit
Definition battle.h:332
s32(* rollParalysis)(u8 side, s32 id)
Definition battle.h:341
u8 blocks[12]
by BATTLE_BLOCK_*: what the player can't do in the battle
Definition game_state.h:389
s32 active[2]
each side's fighter
Definition battle.h:226
BattleFighter fighters[2][3]
Definition battle.h:227
s16 kind
the kind of battle
Definition battle.h:230
u8 tripleHit
plain physical techniques hit 3 times for 0.4 of the damage
Definition battle.h:317
HitStatus statuses[5]
by HIT_*, from the weapon
Definition battle.h:316
FIGHTSTG_battle: the battle.
Definition battle.h:237
BattleState state
Definition battle.h:240
void(* request)(s32 file)
Definition file.h:90
struct PartnerStats *(* getPartnerStats)(s32 partner)
Definition game_state.h:38
s32(* getPartyMember)(u32 index)
Definition game_state.h:24
GameFuncs funcs
Definition game_state.h:582
void(* zero)(void *ptr, s32 size)
Definition heap.h:32
u8 chance
in 128ths
Definition battle.h:298
u8 power
Definition battle.h:299
A partner Digimon from its name on (Partner.info), as getPartnerStats gives it.
Definition game_state.h:303
s16 status[3]
Definition game_state.h:307
s32(* next)(void)
0 to RANDOM_COUNT - 1
Definition random.h:15
A technique (TECHS, from 1: technique n is TECHS[n - 1])
Definition game_state.h:110
u8 effect
TECH_EFFECT_* (fightstg/battle.h), under TECH_EFFECT_FIRST none.
Definition game_state.h:119
u8 effectPower
the effect's strength (a boost's amount, a drain's 128ths)
Definition game_state.h:121
u8 icon
a frame of the menu sprites, from 0x37
Definition game_state.h:113
u8 script
its script in the user's archive (BattleScript.index); 5 and 12 are special
Definition game_state.h:125
void FIGHTSTG_trySleep(void)
TECH_EFFECT_SLEEP: puts the target to sleep when rollSleep lets it, twice as strongly when the acting...
void FIGHTSTG_raiseOneStatus(void)
TECH_EFFECT_RAISE_ONE_STATUS: when rollStatusRaise lets it, raises one of the partner's status values...
void FIGHTSTG_tryDrain(void)
When rollDrain allows it, the action's drain becomes its damage times a 128th of the technique's effe...
void FIGHTSTG_markEnemyOnly(void)
TECH_EFFECT_ENEMY_ONLY outside its own enemy's hands: marks the effect, which takes the place of the ...
void FIGHTSTG_tryConfusion(void)
TECH_EFFECT_CONFUSION: confuses the target when rollConfusion lets it, with the technique's effectPow...
void FIGHTSTG_tryNoSwitch(void)
TECH_EFFECT_NO_SWITCH: marks the effect when rollNoSwitch lets it.
void FIGHTSTG_tryKnockOut(void)
TECH_EFFECT_KNOCK_OUT: knocks the target out when rollKnockOut lets it.
static void markTechEffect(void)
Marks the action's technique's effect with the effect itself.
void FIGHTSTG_markCritical(void)
TECH_EFFECT_CRITICAL: marks the effect, which rollCritical has used.
void FIGHTSTG_startAction(u8 side, s32 tech)
Starts side's technique: rolls its hits and damage, then its effect or, for the player's plain techni...
void FIGHTSTG_tryPoison(void)
TECH_EFFECT_POISON: poisons the target when rollPoison lets it, twice as strongly when the acting fig...
Definition tech_effects.c:7
void FIGHTSTG_startDoubleMagic(void)
Starts a TECH_EFFECT_DOUBLE_MAGIC technique: two magic hits, each with the damage of technique 0x1B9 ...
void FIGHTSTG_drainMp(void)
TECH_EFFECT_DRAIN_MP: takes the technique's effectPower in 128ths of the player's fighter's max MP,...
void FIGHTSTG_lowerAttack(void)
TECH_EFFECT_LOWER_ATTACK: lowers the attack of the other side's active fighter by the technique's eff...
void FIGHTSTG_lowerDefense(void)
TECH_EFFECT_LOWER_DEFENSE: lowers the defense of the other side's active fighter by the technique's e...
void FIGHTSTG_trySteal(void)
TECH_EFFECT_STEAL: when the enemy's active fighter holds an item and rollSteal lets the player take i...
void FIGHTSTG_tryParalysis(void)
TECH_EFFECT_PARALYSIS: paralyzes the target when rollParalysis lets it, with the technique's effectPo...
void FIGHTSTG_applyTechEffect(void)
Carries out the effect of a technique whose hit landed.
void FIGHTSTG_startEndBattle(void)
Starts a TECH_EFFECT_END_BATTLE technique: in BATTLE_KIND_UNK2 its effect, elsewhere a plain physical...
void FIGHTSTG_rollMultiHit(void)
TECH_EFFECT_MULTI_HIT and the triple-hit accessory: rolls the other hits, 3 or the technique's hitCou...
void FIGHTSTG_raiseAllStatus(void)
TECH_EFFECT_RAISE_ALL_STATUS: when rollStatusRaise lets it, raises all of the partner's status values...
void FIGHTSTG_raiseEachStatus(void)
TECH_EFFECT_RAISE_EACH_STATUS: raises each of the partner's status values that rollStatusRaise lets b...
s32 WFIGHTMN_limitDamage(u8 side, s32 damage, s32 hits)
In BATTLE_KIND_ESCAPE and BATTLE_KIND_UNK2, cuts the damage that the partner's hits do so that the en...
Definition techs.c:321