Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
stats.c
Go to the documentation of this file.
1#include "engine/game.h"
2#include "field/field_map.h"
3
4/* The partner id of party member `index` (its unlocked value - 3), or -1 */
6 if (index >= PARTY_SIZE) {
7 return -1;
8 }
9 return GAME.partners[GAME.party[index]].unlocked - 3;
10}
11
12/* Sets a partner's stat, kept within 0-99 (level, TP), 0-9999 (HP, MP) or 0-999 */
13void setStat(s32 partner, u32 stat, s16 value) {
14 PartnerStats *d = &GAME.partners[partner].info;
15 s16 *p = d->stats;
16
17 if (stat < STAT_COUNT) {
18 p += stat;
19 *p = value;
20 if (value < 0) {
21 *p = 0;
22 return;
23 }
24 if (stat < STAT_HP) {
25 if (value >= 100) {
26 *p = 99;
27 }
28 } else if (stat - STAT_HP < 4) {
29 if (value >= 10000) {
30 *p = 9999;
31 }
32 } else if (value >= 1000) {
33 *p = 999;
34 }
35 }
36}
37
38/* Adds to a partner's stat, kept within the same limits as setStat */
39void addStat(s32 partner, u32 stat, s32 delta) {
40 PartnerStats *d = &GAME.partners[partner].info;
41 s16 *stats = d->stats;
42 s16 value;
43
44 if (stat < STAT_COUNT) {
45 stats += stat;
46 value = *stats + delta;
47 *stats = value;
48 if (value < 0) {
49 *stats = 0;
50 } else if (stat < STAT_HP) {
51 if (value >= 100) {
52 *stats = 99;
53 }
54 } else if (stat - STAT_HP < 4) {
55 if (value >= 10000) {
56 *stats = 9999;
57 }
58 } else if (value >= 1000) {
59 *stats = 999;
60 }
61 }
62}
63
64/* A partner's stats with its equipment (and its equipment set bonus) added */
65void computeStats(s32 partner, PartnerTotals *out) {
66 s16 *equip;
67 s32 i;
68 s32 j;
69 ItemInfo *info;
70 ItemData *data;
71 u8 type;
72 u8 stat;
73 s32 amount;
74
75 GameState *save = &GAME;
76 PartnerStats *d;
77
78 out->block = *(StatBlock *)save->partners[partner].info.stats;
79 d = &GAME.partners[partner].info;
80 equip = d->equip;
81 for (i = 0; i < 6; i++) {
82 if (equip[i] > 0) {
83 info = ITEM_FUNCS.get(equip[i]);
84 type = info->type;
85 data = info->data.record;
86 if (IS_WEAPON_TYPE(type)) {
87 out->fields.battle[0] += data->weapon.atk;
88 if (out->fields.battle[0] >= 1000) {
89 out->fields.battle[0] = 999;
90 }
91 for (j = 0; j < 2; j++) {
92 stat = *(j + data->weapon.stats);
93 amount = data->weapon.amounts[j];
94 if (stat != 0) {
95 addStatBonus(out->stats, stat, (s16)amount);
96 }
97 }
98 } else if (IS_ARMOR_TYPE(type)) {
99 out->fields.battle[1] += data->armor.def;
100 if (out->fields.battle[1] >= 1000) {
101 out->fields.battle[1] = 999;
102 }
103 for (j = 0; j < 2; j++) {
104 stat = *(j + data->armor.stats);
105 amount = data->armor.amounts[j];
106 if (stat != 0) {
107 addStatBonus(out->stats, stat, (s16)amount);
108 }
109 }
110 } else if (IS_ACCESSORY_TYPE(type)) {
111 stat = data->acc.stat;
112 amount = data->acc.amount;
113 if (stat != 0) {
114 addStatBonus(out->stats, stat, (s16)amount);
115 }
116 } else {
117 continue;
118 }
119 out->fields.battle[5] += data->weapon.charisma;
120 if (out->fields.battle[5] >= 1000) {
121 out->fields.battle[5] = 999;
122 }
123 }
124 }
125 out->fields.battle[0] -= out->fields.lowered[0];
126 if (out->fields.battle[0] < 0) {
127 out->fields.battle[0] = 0;
128 }
129 out->fields.battle[1] -= out->fields.lowered[1];
130 if (out->fields.battle[1] < 0) {
131 out->fields.battle[1] = 0;
132 }
133 out->fields.battle[4] -= out->fields.lowered[2];
134 if (out->fields.battle[4] < 0) {
135 out->fields.battle[4] = 0;
136 }
137 if (equip[0] == EQUIP_SETS[partner].items[0] && equip[1] == EQUIP_SETS[partner].items[1] &&
138 equip[2] == EQUIP_SETS[partner].items[2] && equip[3] == EQUIP_SETS[partner].items[3]) {
139 for (i = 0; i < 6; i++) {
140 out->fields.battle[i] += EQUIP_SET_BONUSES[partner][i];
141 }
142 }
143}
144
145/* Adds an equipment bonus to a stat of computeStats' result (7 raises every battle stat) */
146void addStatBonus(s16 *p, s32 stat, s32 delta) {
147 s32 i;
148 s16 value;
149
150 if (stat == 7) {
151 for (i = 0; i < 6; i++) {
152 value = p[i + 6] + delta;
153 p[i + 6] = value;
154 if (value >= 1000) {
155 p[i + 6] = 999;
156 }
157 }
158 } else if (stat - 1 < 6U) {
159 value = p[stat + 5] + delta;
160 p[stat + 5] = value;
161 if (value >= 1000) {
162 p[stat + 5] = 999;
163 }
164 } else if (stat - 8 < 7U) {
165 value = p[stat + 4] + delta;
166 p[stat + 4] = value;
167 if (value >= 1000) {
168 p[stat + 4] = 999;
169 }
170 }
171}
172
173/* Each partner's equipment set and what wearing it whole adds (computeStats) */
175 { { 0x00F3, 0x010D, 0x0062, 0x011C } }, { { 0x00F2, 0x0102, 0x0070, 0x011D } },
176 { { 0x00DE, 0x0100, 0x007C, 0x011A } }, { { 0x00F4, 0x010F, 0x00A3, 0x011E } },
177 { { 0x00D3, 0x010C, 0x00CB, 0x0120 } }, { { 0x00F5, 0x010E, 0x0095, 0x011F } },
178 { { 0x00DD, 0x0101, 0x0089, 0x011B } }, { { 0x00E8, 0x00FF, 0x0088, 0x0119 } },
179};
181 { 4, 4, 4, 4, 4, 20 }, { 10, 10, 0, 0, 0, 20 }, { 10, 0, 0, 0, 10, 20 }, { 0, 10, 10, 0, 0, 20 },
182 { 10, 0, 0, 10, 0, 20 }, { 0, 0, 0, 10, 10, 20 }, { 10, 0, 10, 0, 0, 20 }, { 0, 10, 0, 10, 0, 20 },
183};
signed int s32
Definition common.h:11
unsigned int u32
Definition common.h:12
signed short s16
Definition common.h:9
unsigned char u8
Definition common.h:8
GameState GAME
The save data, the game mode and the methods.
Definition state.c:64
s32 getPartyPartner(u32 index)
The partner id of party member index (its unlocked value - 3), or -1.
Definition stats.c:5
void computeStats(s32 partner, PartnerTotals *out)
A partner's stats with its equipment (and its equipment set bonus) added.
Definition stats.c:65
s16 EQUIP_SET_BONUSES[][6]
Definition stats.c:180
void addStat(s32 partner, u32 stat, s32 delta)
Adds to a partner's stat, kept within the same limits as setStat.
Definition stats.c:39
EquipSet EQUIP_SETS[]
Each partner's equipment set and what wearing it whole adds (computeStats)
Definition stats.c:174
void addStatBonus(s16 *p, s32 stat, s32 delta)
Adds an equipment bonus to a stat of computeStats' result (7 raises every battle stat)
Definition stats.c:146
void setStat(s32 partner, u32 stat, s16 value)
Sets a partner's stat, kept within 0-99 (level, TP), 0-9999 (HP, MP) or 0-999.
Definition stats.c:13
What the stage overlays and the executable use of FIELDSTG (fieldstg.h has the rest): its layers and ...
#define IS_WEAPON_TYPE(type)
ItemInfo.type's ranges: 2-14 weapons, 15-20 armour, 21-24 accessories, each tested as one unsigned by...
Definition game_state.h:235
#define PARTY_SIZE
How many partners the party holds.
Definition game_state.h:475
#define IS_ARMOR_TYPE(type)
Definition game_state.h:236
#define STAT_HP
Definition game_state.h:281
#define STAT_COUNT
Definition game_state.h:293
#define IS_ACCESSORY_TYPE(type)
Definition game_state.h:237
ItemFuncs ITEM_FUNCS
Definition items.c:890
u16 amounts[2]
Definition game_state.h:167
u8 stats[2]
Definition game_state.h:168
A partner's equipment set: the four items computeStats compares with equip[0-3].
Definition game_state.h:268
The game state (GAME): the first 0x26BC bytes are what newGame clears (the save data),...
Definition game_state.h:491
Partner partners[PARTNER_COUNT]
Definition game_state.h:517
s32 party[3]
partner indices
Definition game_state.h:511
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
s16 stats[19]
Definition game_state.h:306
PartnerStats info
Definition game_state.h:349
s32 unlocked
partner id + 3, 0 while locked
Definition game_state.h:347
PartnerStats' stats[] and the status[] after them as one block, which computeStats and STITSHOP_compu...
Definition game_state.h:324
u16 amounts[2]
what it adds to stats[]
Definition game_state.h:149
u8 stats[2]
Definition game_state.h:151
s16 charisma
what it adds to STAT_CHARISMA (computeStats); armour and accessories too
Definition game_state.h:145
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
computeStats' result: the stats with the equipment added, by STAT_* or by name.
Definition game_state.h:409
StatBlock block
the first 0x2C bytes, which computeStats copies whole
Definition game_state.h:424
s16 lowered[3]
taken from battle[0], [1] and [4]
Definition game_state.h:421
s16 battle[6]
strength (raised by weapons), defense (by armour), spirit, wisdom, speed and charisma (by all equipme...
Definition game_state.h:418
s16 stats[24]
Definition game_state.h:410
struct PartnerTotals::@10 fields