Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
damage.c
Go to the documentation of this file.
1/* FIGHTSTG's damage and healing. */
2
4
5/* the element whose boost (FIGHTSTG_getElementBoost) weakens each one */
7 0, 0, 4, 2,
8 5, 3, 7, 8,
9 6,
10};
11
12/* What the battle's element boost adds to value for a technique of the
13 given element: the boost's amount in 128ths of value for the boosted
14 element, half as much taken off for the element it weakens, nothing
15 otherwise */
18
19 if (boost->element < ELEMENT_FIRST) {
20 return 0;
21 }
22 if (element == boost->element) {
23 return value * boost->amount / 128;
24 }
25 if (FIGHTSTG_opposedElements[element] == boost->element) {
26 return -(value * boost->amount / 256);
27 }
28 return 0;
29}
30
31/* A hit's damage from its base value: the element boost, half again against
32 the target's family, the user's damage bonus, the element against the
33 target's resistance, the triple hit's 0.4, a critical hit and the target's
34 damage cut; at most 5 times value */
36 TechData *tech = &TECHS[id - 1];
39 s32 result = value;
40 s32 i;
41
42 result += FIGHTSTG_getElementBoost(result, tech->element);
43 if (tech->family >= FAMILY_FIRST) {
44 if (tech->family == target->family) {
45 result += result / 2;
46 }
47 } else {
48 for (i = 0; i < 3; i++) {
49 if (user->weaponFamilies[i] >= FAMILY_FIRST && user->weaponFamilies[i] == target->family) {
50 result += result / 2;
51 break;
52 }
53 }
54 }
55 if (user->damageBonus != 0) {
56 result += result * user->damageBonus / 64;
57 }
58 if (tech->element >= ELEMENT_FIRST) {
59 result += result * tech->elementPower * 2 / target->resist[tech->element - ELEMENT_FIRST];
60 } else if ((tech->script < 11 || tech->script > 12) && user->element != 0) {
61 result += result * user->elementPower * 2 / target->resist[user->element - ELEMENT_FIRST];
62 }
63 if (tech->effect < TECH_EFFECT_FIRST && user->tripleHit != 0 && (tech->script < 11 || tech->script > 12)) {
64 result = result * 4 / 10;
65 }
66 if (FIGHTSTG_rollCritical(side, id) != 0) {
67 result += result * ((RANDOM.next() & 0x3F) + 0x20) / 64;
68 }
69 if (target->damageCut != 0) {
70 result -= target->damageCut;
71 if (result <= 0) {
72 result = 0;
73 }
74 }
75 if (result > value * 5) {
76 result = value * 5;
77 }
78#if VERSION_EU || VERSION_JP
79 if (result >= 10000) {
80 result = 9999;
81 }
82#endif
83 return result;
84}
85
86/* A technique's power from the user's attack against the target's defense
87 * (an enemy's scaled by its unkA / 16), passed on to FIGHTSTG_adjustDamage. The match
88 * depends on the division in each branch. */
90 TechData *tech;
91 BattleStats *user;
92 BattleStats *target;
93 s32 value;
94 s32 enemy;
95
96 if (side == 0) {
99 } else {
102 }
103 user = &FIGHTSTG_battleFuncs.stats[0];
104 tech = &TECHS[id - 1];
105 target = &FIGHTSTG_battleFuncs.stats[1];
106 if (side == 0) {
107 value = tech->power * user->stats[BATTLE_STAT_ATTACK] / target->stats[BATTLE_STAT_DEFENSE];
108 } else {
109 /* the match depends on reading it first: indexed in place, the lui of
110 BATTLE_SETUP moves ahead of its load */
111 enemy = FIGHTSTG_battle.state.active[1];
112 value = tech->power * BATTLE_SETUP.enemies[enemy].strength / 16 * user->stats[BATTLE_STAT_ATTACK] /
113 target->stats[BATTLE_STAT_DEFENSE];
114 }
115 return FIGHTSTG_adjustDamage(side, id, value);
116}
117
118/* A magic technique's damage: its power by the user's spirit against the
119 target's (half to twice as much), the element boost and resistance, half
120 again against the target's family, a critical hit and the target's damage
121 cut; at most 5 times the power */
123 TechData *tech;
124 BattleStats *user;
125 BattleStats *target;
126 s32 base;
127 s32 enemy;
128 s32 power;
129 s32 result;
130 s16 resist;
131
132 if (side == 0) {
135 } else {
138 }
139 user = &FIGHTSTG_battleFuncs.stats[0];
140 tech = &TECHS[id - 1];
141 target = &FIGHTSTG_battleFuncs.stats[1];
142 if (side == 0) {
143 base = tech->power;
144 } else {
145 /* the match depends on reading it first: indexed in place, the lui of
146 BATTLE_SETUP moves ahead of its load */
147 enemy = FIGHTSTG_battle.state.active[1];
148 base = tech->power * BATTLE_SETUP.enemies[enemy].strength / 16;
149 }
150 power = base * (user->stats[BATTLE_STAT_SPIRIT] * 50 / target->stats[BATTLE_STAT_SPIRIT] + 50) / 100;
151 if (power > base * 2) {
152 power = base * 2;
153 }
154 if (power < base / 2) {
155 power = base / 2;
156 }
157 result = power;
158 result += FIGHTSTG_getElementBoost(result, tech->element);
159 if (tech->element >= ELEMENT_FIRST) {
160 resist = target->resist[tech->element - ELEMENT_FIRST];
161 if (resist < 100) {
162 result = result * (400 - resist * 3) / 100;
163 } else if (resist >= 300) {
164 result = result * (65 - resist / 20) / 100;
165 } else {
166 result = result * (125 - resist / 4) / 100;
167 }
168 }
169 if (tech->family >= FAMILY_FIRST && tech->family == target->family) {
170 result += result / 2;
171 }
172 if (FIGHTSTG_rollMagicCritical(side, id) != 0) {
173 result += result * (RANDOM.next() % 65 + 0x20) / 64;
174 }
175 if (target->damageCut != 0) {
176 result -= target->damageCut;
177 if (result <= 0) {
178 result = 0;
179 }
180 }
181 if (result > power * 5) {
182 result = power * 5;
183 }
184#if VERSION_EU || VERSION_JP
185 if (result >= 10000) {
186 result = 9999;
187 }
188#endif
189 return result;
190}
191
192/* getDamage: the damage of an event (args: the side, the fighter and the
193 * base damage) to the fighter if it is its side's active one, less a tenth of
194 * its resist[1] and resist[RESIST_POISON], as a part of its max HP: at least 1, at most
195 * half the max HP. The match depends on the fighter pointer. */
197 u8 side;
198 /* the match depends on a u8: side != 0 is computed into v0 and copied,
199 which keeps FIGHTSTG_battle's address until after it */
200 u8 team;
201 s32 index;
202 s32 damage;
203 BattleStats *stats;
204 s16 maxHp;
205 BattleFighter *fighter;
206 s32 result;
207
208 side = args[0];
209 index = args[1];
210 damage = args[2];
211 team = side != 0;
212 if (index != FIGHTSTG_battle.state.active[team]) {
213 return 0;
214 }
215 FIGHTSTG_computeStats(side, 0, index);
216 stats = &FIGHTSTG_battleFuncs.stats[1];
217 fighter = &FIGHTSTG_battle.state.fighters[team][index];
218 maxHp = fighter->maxHp;
219 result = (damage / 2 - (stats->resist[RESIST_POISON] + stats->resist[1]) / 10) * maxHp / 100;
220 if (result <= 0) {
221 result = 1;
222 }
223 if (result > maxHp / 2) {
224 result = maxHp / 2;
225 }
226 return result;
227}
228
229/* The damage of a counterattack on value: the partner's first skill deals
230 it as one hit (the triple hit set aside), another technique its power in
231 64ths of value (32nds when the fighter is special) */
233 BattleFighter *fighter;
234 s32 own;
235 u8 saved;
236 s32 result;
237 TechData *entry;
238
239 if (side == 0) {
241 own = id == GET_DIGIMON(fighter->id)->skills[0];
242 } else {
245 own = 0;
246 }
247 if (side == 0) {
250 } else {
253 }
254 if (own == 1) {
257 result = FIGHTSTG_adjustDamage(side, id, value);
259 return result;
260 }
261 entry = &TECHS[id - 1];
262 if (fighter->special) {
263 result = value * entry->effectPower / 32;
264 } else {
265 result = value * entry->effectPower / 64;
266 }
267 return FIGHTSTG_adjustDamage(side, id, result);
268}
269
270/* The HP a healing technique restores: 64 times its power, and an eighth of
271 it per point of the user's wisdom */
273 BattleStats *stats;
274 TechData *entry;
275 u16 value;
276 s32 flag;
277 s32 fighter;
278#if VERSION_EU || VERSION_JP
279 s32 result;
280#endif
281
282 if (side == 0) {
283 fighter = FIGHTSTG_battle.state.active[0];
284 flag = SIDE_PLAYER;
285 } else {
286 flag = SIDE_ENEMY;
287 fighter = FIGHTSTG_battle.state.active[1];
288 }
289 FIGHTSTG_computeStats(flag, 1, fighter);
290 stats = &FIGHTSTG_battleFuncs.stats[0];
291 entry = &TECHS[id - 1];
292 value = entry->power;
293#if VERSION_US
294 return (value << 6) + stats->stats[BATTLE_STAT_WISDOM] * value / 8;
295#elif VERSION_EU || VERSION_JP
296 result = (value << 6) + stats->stats[BATTLE_STAT_WISDOM] * value / 8;
297 if (result > 9999) {
298 result = 9999;
299 }
300 return result;
301#endif
302}
303
304/* The HP a fighter regains: 8 to 16 128ths of its max HP when big, 4 to 8
305 otherwise */
306s32 FIGHTSTG_getHeal(u8 side, s32 index, s32 big) {
307 BattleFighter *fighter;
308 s32 value;
309
310 if (side == 0) {
311 fighter = &FIGHTSTG_battle.state.fighters[0][index];
312 } else {
313 fighter = &FIGHTSTG_battle.state.fighters[1][index];
314 }
315 if (big) {
316 value = fighter->maxHp * (RANDOM.next() % 9 + 8) / 128;
317 } else {
318 value = fighter->maxHp * (RANDOM.next() % 5 + 4) / 128;
319 }
320#if VERSION_EU || VERSION_JP
321 if (value > 9999) {
322 value = 9999;
323 }
324#endif
325 return value;
326}
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_FIRST
A technique's effect (TechData.effect), which FIGHTSTG_applyTechEffect carries out when its hit lands...
Definition battle.h:251
#define BATTLE_STAT_ATTACK
BattleStats.stats' indices: the partner's first five battle stats.
Definition battle.h:29
#define FAMILY_FIRST
Definition battle.h:39
#define BATTLE_STAT_SPIRIT
magic damage, and against it
Definition battle.h:31
#define RESIST_POISON
BattleStats.resist's indices: against the elements (element - ELEMENT_FIRST), then against the status...
Definition battle.h:47
#define BATTLE_STAT_WISDOM
magic accuracy, statuses and heals
Definition battle.h:32
#define BATTLE_STAT_DEFENSE
against it
Definition battle.h:30
#define SIDE_PLAYER
The battle's sides, as the functions that take a side want them: side >> 4 is its row of FIGHTSTG_bat...
Definition battle.h:177
#define SIDE_ENEMY
Definition battle.h:178
#define ELEMENT_FIRST
The elements (TechData.element, BattleStats.element) and the families (TechData.family,...
Definition battle.h:37
BattleStats * FIGHTSTG_computeStats(u8 side, s32 which, s32 index)
Works out a side's stats into its BattleStats: the partner's totals with the fighter's boosts,...
Definition stats.c:42
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
signed short s16
Definition common.h:9
unsigned short u16
Definition common.h:10
unsigned char u8
Definition common.h:8
s32 FIGHTSTG_getHeal(u8 side, s32 index, s32 big)
The HP a fighter regains: 8 to 16 128ths of its max HP when big, 4 to 8 otherwise.
Definition damage.c:306
s32 FIGHTSTG_getDamage(s32 *args)
getDamage: the damage of an event (args: the side, the fighter and the base damage) to the fighter if...
Definition damage.c:196
s32 FIGHTSTG_opposedElements[]
the element whose boost (FIGHTSTG_getElementBoost) weakens each one
Definition damage.c:6
s32 FIGHTSTG_computeDamage(u8 side, s32 id)
A technique's power from the user's attack against the target's defense (an enemy's scaled by its unk...
Definition damage.c:89
s32 FIGHTSTG_getElementBoost(s32 value, s32 element)
What the battle's element boost adds to value for a technique of the given element: the boost's amoun...
Definition damage.c:16
s32 FIGHTSTG_adjustDamage(u8 side, s32 id, s32 value)
A hit's damage from its base value: the element boost, half again against the target's family,...
Definition damage.c:35
s32 FIGHTSTG_computeMagicDamage(u8 side, s32 id)
A magic technique's damage: its power by the user's spirit against the target's (half to twice as muc...
Definition damage.c:122
s32 FIGHTSTG_computeHeal(u8 side, s32 id)
The HP a healing technique restores: 64 times its power, and an eighth of it per point of the user's ...
Definition damage.c:272
s32 FIGHTSTG_computeCounterDamage(u8 side, s32 id, s32 value)
The damage of a counterattack on value: the partner's first skill deals it as one hit (the triple hit...
Definition damage.c:232
DigimonData *(* GET_DIGIMON)(s32 id)
getDigimon for the overlays, in the small data (.sdata) between game/items.c's and file/file_table....
Definition get_digimon.c:10
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
s32 FIGHTSTG_rollCritical(u8 side, s32 id)
Whether a physical hit is critical: a chance of 4 in 128 with the technique's critical boost or the a...
Definition rolls.c:9
s32 FIGHTSTG_rollMagicCritical(u8 side, s32 id)
Whether a magic hit is critical: a chance from the technique's element power against the target's res...
Definition rolls.c:72
s16 strength
its stats and techniques' power, in 16ths
Definition game_state.h:358
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 id
the Digimon (DIGIMON_DATA)
Definition battle.h:192
u8 special
the partner's special state (EVENT_SPECIAL_END): doubles its effects
Definition battle.h:203
BattleStats stats[2]
the player's, then the enemy's
Definition battle.h:330
BattleEnemy enemies[3]
Definition game_state.h:386
s32 active[2]
each side's fighter
Definition battle.h:226
BattleFighter fighters[2][3]
Definition battle.h:227
ElementBoost boost
Definition battle.h:228
A side's stats as FIGHTSTG_computeStats works them out.
Definition battle.h:305
u8 tripleHit
plain physical techniques hit 3 times for 0.4 of the damage
Definition battle.h:317
u8 weaponFamilies[3]
from the equipment, as are the ones after
Definition battle.h:313
s16 stats[5]
with the fighter's boosts
Definition battle.h:307
u8 damageCut
taken off each hit
Definition battle.h:312
s16 resist[12]
Definition battle.h:308
u8 elementPower
Definition battle.h:315
u8 damageBonus
in 64ths: the fighter's charge
Definition battle.h:311
u8 element
the accessory's, for techniques without one
Definition battle.h:314
BattleState state
Definition battle.h:240
u16 skills[7]
[1]-[6] are learnt at skillLevels
Definition game_state.h:90
The battle's element boost: one element's techniques do more damage, and the ones of the element it w...
Definition battle.h:218
s16 amount
in 128ths
Definition battle.h:220
s16 element
under ELEMENT_FIRST: none
Definition battle.h:219
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 family
FAMILY_FIRST and up, under it none.
Definition game_state.h:118
u8 effectPower
the effect's strength (a boost's amount, a drain's 128ths)
Definition game_state.h:121
u16 power
its damage, times the user's attack over the target's defense
Definition game_state.h:112
u8 element
ELEMENT_FIRST and up, under it none.
Definition game_state.h:116
u8 elementPower
how much the element adds, against the target's resistance
Definition game_state.h:117
u8 script
its script in the user's archive (BattleScript.index); 5 and 12 are special
Definition game_state.h:125