Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
stats.c
Go to the documentation of this file.
1/* FIGHTSTG's battle stats (FIGHTSTG_computeStats). */
2
4
5/* Works out an enemy's stats from its table entry, its strength and the
6 fighter's boosts */
7static inline void computeEnemyStats(BattleStats *stats, BattleFighter *fighter, s32 index) {
8 BattleTableEntry *entry;
9 s32 j;
10
11 entry = FIGHTSTG_battleTableFunc(fighter->id);
12 stats->level = BATTLE_SETUP.enemies[index].level;
13 for (j = 0; j < 5; j++) {
14 stats->stats[j] = entry->stats[j] * BATTLE_SETUP.enemies[index].strength / 16;
15 }
16 for (j = 0; j < 12; j++) {
17 stats->resist[j] = entry->resist[j];
18 }
19 stats->flags = fighter->flags;
20 if (fighter->boosts[0] != 0) {
21 stats->stats[BATTLE_STAT_ATTACK] += fighter->boosts[0];
22 }
23 if (fighter->boosts[1] != 0) {
24 stats->stats[BATTLE_STAT_DEFENSE] += fighter->boosts[1];
25 }
26 if (fighter->boosts[2] != 0) {
27 stats->stats[BATTLE_STAT_SPEED] += fighter->boosts[2];
28 }
29 if (fighter->boosts[3] != 0) {
30 stats->stats[BATTLE_STAT_SPIRIT] += fighter->boosts[3];
31 }
32 stats->family = entry->family;
33 stats->damageBonus = fighter->charge;
34}
35
36/* Works out a side's stats into its BattleStats: the partner's totals with
37 the fighter's boosts, its resistances and what its equipment and
38 accessories add, or the enemy's (computeEnemyStats). The match depends on
39 one s16 pointer walking the totals, the accessories and the equipment
40 alike: its extra sets give it the references that put it before found in
41 the global allocator. */
43 PartnerTotals totals;
44 BattleStats *stats;
45 BattleFighter *fighter;
46 DigimonData *digimon;
47 DigimonData *other;
48 PartnerStats *partner;
49 ItemInfo *info;
50 ItemData *data;
51 AccessoryData *acc;
52 s32 member;
53 s16 *values;
54 s32 count;
55 s32 found;
56 s32 i;
57
58 if (which) {
59 stats = &FIGHTSTG_battleFuncs.stats[0];
60 } else {
61 stats = &FIGHTSTG_battleFuncs.stats[1];
62 }
63 HEAP.zero(stats, sizeof(BattleStats));
64 if (side == 0) {
65 fighter = &FIGHTSTG_battle.state.fighters[0][index];
66 member = GAME.funcs.getPartyMember(index);
67 digimon = &DIGIMON_DATA[member];
68 GAME.funcs.computeStats(member, &totals);
69 for (i = RESIST_POISON; i < RESIST_COUNT; i++) {
70 stats->resist[i] = digimon->statusResists[i - RESIST_POISON];
71 }
72 if (digimon->id != fighter->id) {
73 other = GET_DIGIMON(fighter->id);
74 for (i = 0; i < 5; i++) {
75 totals.fields.battle[i] += other->battleStats[i];
76 }
77 for (i = 0; i < 7; i++) {
78 totals.fields.resist[i] += other->resistances[i];
79 }
80 for (i = RESIST_POISON; i < RESIST_COUNT; i++) {
81 stats->resist[i] += other->statusResists[i - RESIST_POISON];
82 }
83 }
84 if (fighter->boosts[0] != 0) {
85 totals.fields.battle[0] += fighter->boosts[0];
86 }
87 if (fighter->boosts[1] != 0) {
88 totals.fields.battle[1] += fighter->boosts[1];
89 }
90 if (fighter->boosts[2] != 0) {
91 totals.fields.battle[4] += fighter->boosts[2];
92 }
93 stats->level = totals.fields.level;
94 values = totals.fields.battle;
95 for (i = 0; i < 5; i++) {
96#if VERSION_EU || VERSION_JP
97 if (values[i] > 0) {
98 stats->stats[i] = values[i];
99 } else {
100 stats->stats[i] = 1;
101 }
102#else
103 stats->stats[i] = values[i];
104#endif
105 }
106 values = totals.fields.resist;
107 for (i = 0; i < 7; i++) {
108#if VERSION_EU || VERSION_JP
109 if (values[i] > 0) {
110 stats->resist[i] = values[i];
111 } else {
112 stats->resist[i] = 1;
113 }
114#else
115 stats->resist[i] = values[i];
116#endif
117 }
118 stats->flags = fighter->flags;
119 partner = GAME.funcs.getPartnerStats(member);
120 values = &partner->equip[4];
121 for (i = 0; i < 2; i++) {
122 if (values[i] != 0) {
123 acc = ITEM_FUNCS.get(values[i])->data.acc;
124 if (acc->stat == 17) {
125 stats->resist[RESIST_POISON] = acc->amount;
126 } else if (acc->stat == 18) {
127 stats->resist[RESIST_PARALYSIS] = acc->amount;
128 } else if (acc->stat == 19) {
129 stats->resist[RESIST_CONFUSION] = acc->amount;
130 } else if (acc->stat == 20) {
131 stats->resist[RESIST_SLEEP] = acc->amount;
132 } else if (acc->stat == 21) {
133 stats->resist[RESIST_KNOCK_OUT] = acc->amount;
134 }
135 }
136 }
137 values = partner->equip;
138 stats->family = GET_DIGIMON(fighter->id)->family;
139 stats->damageBonus = fighter->charge;
140 count = 0;
141 for (i = 0; i < 4; i++) {
142 if (values[i] > 0) {
143 info = ITEM_FUNCS.get(values[i]);
144 if (info->type >= 2 && info->type <= 14) {
145 data = info->data.record;
146 stats->accuracy += data->weapon.accuracy;
147 if (data->weapon.family >= FAMILY_FIRST) {
148 stats->weaponFamilies[count++] = data->weapon.family;
149 }
150 } else {
151 data = info->data.record;
152 if (data->armor.evasion != 0) {
153 stats->evasion += data->armor.evasion;
154 }
155 }
156 }
157 }
158 found = 0;
159 for (i = 0; i < 4; i++) {
160 if (i != 1 && values[i] > 0) {
161 data = ITEM_FUNCS.get(values[i])->data.record;
162 if (values[i] == 0x97) {
165 found = 1;
166 } else if (values[i] == 0xD2) {
169 found = 1;
170 } else if (values[i] == 0xB4 || values[i] == 0xC2) {
173 found = 1;
174 } else if (values[i] == 0x6D || values[i] == 0xBA) {
177 found = 1;
178 } else if (values[i] == 0x5E || values[i] == 0x93 || values[i] == 0xAD) {
180 stats->statuses[HIT_DRAIN].power = data->weapon.statusPower;
181 found = 1;
182 } else if (values[i] == 0x96 || values[i] == 0xBF) {
183 stats->criticalBonus = data->weapon.statusPower;
184 found = 1;
185 }
186 }
187 }
188 if (!found) {
189 values = &partner->equip[4];
190 for (i = 0; i < 2; i++) {
191 if (values[i] == 0x13C) {
192 stats->tripleHit = 1;
193 } else if (values[i] == 0x13D) {
194 data = ITEM_FUNCS.get(0x13D)->data.record;
195 stats->criticalBonus = data->acc.amount;
196 } else if (values[i] == 0x13E) {
197 data = ITEM_FUNCS.get(0x13E)->data.record;
198 stats->counter = data->acc.amount;
199 }
200 }
201 }
202 values = &partner->equip[4];
203 for (i = 0; i < 2; i++) {
204 if (values[i] >= 0x153 && values[i] <= 0x167) {
205 data = ITEM_FUNCS.get(values[i])->data.record;
206 if (values[i] < 0x156) {
207 stats->element = 2;
208 } else if (values[i] < 0x159) {
209 stats->element = 3;
210 } else if (values[i] < 0x15C) {
211 stats->element = 4;
212 } else if (values[i] < 0x15F) {
213 stats->element = 5;
214 } else if (values[i] < 0x162) {
215 stats->element = 6;
216 } else if (values[i] < 0x165) {
217 stats->element = 7;
218 } else if (values[i] < 0x168) {
219 stats->element = 8;
220 }
221 stats->elementPower = data->acc.amount;
222 } else if (values[i] >= 0x145 && values[i] <= 0x146) {
223 data = ITEM_FUNCS.get(values[i])->data.record;
224 stats->damageCut = data->acc.amount;
225 } else if (values[i] >= 0x14B && values[i] <= 0x14C) {
226 data = ITEM_FUNCS.get(values[i])->data.record;
227 stats->accuracy += data->acc.amount;
228 } else if (values[i] >= 0x14D && values[i] <= 0x14E) {
229 data = ITEM_FUNCS.get(values[i])->data.record;
230 stats->evasion += data->acc.amount;
231 } else if (values[i] >= 0x14F && values[i] <= 0x150) {
232 data = ITEM_FUNCS.get(values[i])->data.record;
233 stats->runAwayBonus = data->acc.amount;
234 } else if (values[i] == 0x13F) {
235 data = ITEM_FUNCS.get(values[i])->data.record;
236 stats->runAwayGuard = 1;
237 } else if (values[i] >= 0x147 && values[i] <= 0x148) {
238 data = ITEM_FUNCS.get(values[i])->data.record;
239 stats->stealBonus = data->acc.amount;
240 }
241 }
242 } else {
243 fighter = &FIGHTSTG_battle.state.fighters[1][index];
244 computeEnemyStats(stats, fighter, index);
245 }
246 if (which) {
247 return &FIGHTSTG_battleFuncs.stats[0];
248 }
249 return &FIGHTSTG_battleFuncs.stats[1];
250}
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 HIT_CONFUSION
Definition battle.h:291
#define RESIST_KNOCK_OUT
Definition battle.h:51
#define HIT_DRAIN
its power is in 128ths of the damage
Definition battle.h:293
#define BATTLE_STAT_ATTACK
BattleStats.stats' indices: the partner's first five battle stats.
Definition battle.h:29
#define BATTLE_STAT_SPEED
physical accuracy, evasion and running away
Definition battle.h:33
#define FAMILY_FIRST
Definition battle.h:39
#define RESIST_COUNT
Definition battle.h:52
#define HIT_POISON
The statuses a weapon's hits can inflict (BattleStats.statuses)
Definition battle.h:289
#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 HIT_KNOCK_OUT
its power is read by nothing
Definition battle.h:292
#define BATTLE_STAT_DEFENSE
against it
Definition battle.h:30
#define RESIST_PARALYSIS
Definition battle.h:48
#define HIT_PARALYSIS
Definition battle.h:290
#define RESIST_SLEEP
Definition battle.h:50
#define RESIST_CONFUSION
Definition battle.h:49
static void computeEnemyStats(BattleStats *stats, BattleFighter *fighter, s32 index)
Works out an enemy's stats from its table entry, its strength and the fighter's boosts.
Definition stats.c:7
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 char u8
Definition common.h:8
DigimonData DIGIMON_DATA[55]
55 entries: the 52 Digimon, then three placeholders (0x1D4-0x1D6)
Definition digimon.c:7
GameState GAME
The save data, the game mode and the methods.
Definition state.c:64
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
Heap HEAP
The functions that return what a call left in v0 (allocMemHigh, findTask) and the ones that take othe...
Definition heap.c:184
ItemFuncs ITEM_FUNCS
Definition items.c:890
BattleSetup BATTLE_SETUP
Definition items.c:886
An accessory's (types 21-24, ACCESSORY_DATA)
Definition game_state.h:177
u8 evasion
added to the battle's (FIGHTSTG_computeStats)
Definition game_state.h:171
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
u8 flags
FIGHTER_*.
Definition battle.h:204
s16 charge
added in 64ths to its next technique's damage, which uses it up
Definition battle.h:199
s16 id
the Digimon (DIGIMON_DATA)
Definition battle.h:192
s16 boosts[4]
added to the stats FIGHTSTG_boostStats picks
Definition battle.h:200
BattleStats stats[2]
the player's, then the enemy's
Definition battle.h:330
BattleEnemy enemies[3]
Definition game_state.h:386
BattleFighter fighters[2][3]
Definition battle.h:227
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 runAwayGuard
halves the enemy's chance to run away
Definition battle.h:323
u8 runAwayBonus
to the player's chance to run away
Definition battle.h:322
u8 damageCut
taken off each hit
Definition battle.h:312
u8 criticalBonus
to plain techniques' critical chance, off their accuracy
Definition battle.h:318
s16 resist[12]
Definition battle.h:308
s16 level
Definition battle.h:306
u8 accuracy
Definition battle.h:320
u8 flags
the fighter's
Definition battle.h:309
u8 elementPower
Definition battle.h:315
u8 damageBonus
in 64ths: the fighter's charge
Definition battle.h:311
HitStatus statuses[5]
by HIT_*, from the weapon
Definition battle.h:316
u8 counter
answers hits with the partner's first skill
Definition battle.h:319
u8 element
the accessory's, for techniques without one
Definition battle.h:314
u8 stealBonus
Definition battle.h:324
s16 resist[12]
Definition battle.h:65
s16 stats[5]
by BATTLE_STAT_*, scaled by the enemy's strength / 16
Definition battle.h:64
u8 family
FAMILY_*, the enemy's stats'.
Definition battle.h:66
BattleState state
Definition battle.h:240
Digimon definition (DIGIMON_DATA, 52 of them; the first 8 are the partners)
Definition game_state.h:86
u8 statusResists[5]
against poison, paralysis, confusion, sleep and knock-outs
Definition game_state.h:92
u8 family
the family it fights as (BattleStats.family)
Definition game_state.h:106
u16 battleStats[6]
Definition game_state.h:88
u16 resistances[7]
Definition game_state.h:89
struct PartnerStats *(* getPartnerStats)(s32 partner)
Definition game_state.h:38
void(* computeStats)(s32 partner, union PartnerTotals *out)
Definition game_state.h:31
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
struct ItemInfo *(* get)(s32 item)
getItem
Definition game_state.h:670
An item (ITEMS, ITEM_FUNCS)
Definition game_state.h:225
u8 type
2-14 weapons, 15-20 armour, 21-24 accessories
Definition game_state.h:230
ItemRecord data
the type's record, or the usable items' effect
Definition game_state.h:226
A partner Digimon from its name on (Partner.info), as getPartnerStats gives it.
Definition game_state.h:303
u8 statusChance
of the status its hits inflict
Definition game_state.h:156
u8 family
its hits': FAMILY_FIRST and up, under it none
Definition game_state.h:158
u8 accuracy
added to the battle's (FIGHTSTG_computeStats)
Definition game_state.h:152
u8 statusPower
the status's, or the critical bonus
Definition game_state.h:157
ItemInfo.data's record, by ItemInfo.type.
Definition game_state.h:188
ArmorData armor
Definition game_state.h:190
AccessoryData acc
Definition game_state.h:191
WeaponData weapon
Definition game_state.h:189
ItemData * record
Definition game_state.h:210
AccessoryData * acc
Definition game_state.h:214
computeStats' result: the stats with the equipment added, by STAT_* or by name.
Definition game_state.h:409
s16 battle[6]
strength (raised by weapons), defense (by armour), spirit, wisdom, speed and charisma (by all equipme...
Definition game_state.h:418
struct PartnerTotals::@10 fields