Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
setup.c
Go to the documentation of this file.
1/* WFIGHTMN's display layers and the battle's fighters: their stats, the
2 ambush roll, the WFIGHTMN_RECOVERY_ITEM checks and the record of who fought. */
3
5
6/* Sets up the display and the battle's layers */
10
11/* Sets a stat and its maximum. The match depends on the pointers: stores
12 through them aren't struct accesses to GCC, so the load of
13 FIGHTSTG_battleTableFunc stays after them */
14static inline void WFIGHTMN_setStat(s16 *cur, s16 *max, s16 value) {
15 *cur = *max = value;
16}
17
18/* Fills the battle's fighters: the party's partners (the first one with the
19 id DIGIMON) and the encounter's enemies, with their battle table items */
21 PartnerStats *stats;
22 BattleTableEntry *entry;
23 BattleFighter *fighter;
24 BattleFighter *units;
25 s32 partner;
26 s32 i;
28 for (i = 0; i < 3; i++) {
29 partner = GAME.funcs.getPartyMember(i);
30 if (partner >= 0) {
31 stats = GAME.funcs.getPartnerStats(partner);
32 if (i == 0) {
33 units[0].id = digimon;
34 } else {
35 units[i].id = DIGIMON_DATA[partner].id;
36 }
37 units[i].hp = stats->stats[STAT_HP];
38 units[i].maxHp = stats->stats[STAT_MAX_HP];
39 units[i].mp = stats->stats[STAT_MP];
40 units[i].maxMp = stats->stats[STAT_MAX_MP];
41 }
42 }
44 for (i = 0; i < 3; i++) {
45 fighter = &units[i];
46 fighter->id = BATTLE_SETUP.enemies[i].fighter;
47 if (BATTLE_SETUP.enemies[i].fighter != 0) {
48 WFIGHTMN_setStat(&fighter->hp, &fighter->maxHp, BATTLE_SETUP.enemies[i].hp);
49 WFIGHTMN_setStat(&fighter->mp, &fighter->maxMp, BATTLE_SETUP.enemies[i].mp);
50 entry = FIGHTSTG_battleTableFunc(fighter->id);
51 if (entry->item != 0) {
52 fighter->item = entry->item;
53 }
54 }
55 }
56}
57
58/* Checks the chance in BATTLE_SETUP.ambushChance, scaled by how far the first
59 partner's level and the first enemy's level are under 32 */
61 s32 chance;
62 s32 gap;
63 s32 r;
64
65 if (BATTLE_SETUP.ambushChance == 0) {
66 return 0;
67 }
68 /* gap on its own line: the match depends on it, which loads the level
69 before the enemy's */
71 chance = BATTLE_SETUP.ambushChance * (gap - BATTLE_SETUP.enemies[0].level) / 32;
72 r = RANDOM.next() % 128;
73 if (r == 0) {
74 return 1;
75 }
76 return r < chance;
77}
78
79/* Queues a recovery (FIGHTSTG_queueRecovery) for party member MEMBER's
80 partner when it has WFIGHTMN_RECOVERY_ITEM in one of its last two equipment slots */
82 s32 partner = GAME.funcs.getPartyMember(member);
83 s16 *equip;
84 s32 i;
85
86 if (partner >= 0) {
87 equip = &GAME.funcs.getPartnerStats(partner)->equip[4];
88 for (i = 0; i < 2; i++) {
89 if (equip[i] == WFIGHTMN_RECOVERY_ITEM) {
90 FIGHTSTG_queueRecovery(0, member, 0);
91 return;
92 }
93 }
94 }
95}
96
97/* Checks each of the party's three partners for WFIGHTMN_RECOVERY_ITEM
98 (WFIGHTMN_checkEquip) */
100 s32 i;
101
102 for (i = 0; i < 3; i++) {
104 }
105}
106
107/* Marks in BATTLE_RESULT that the current partner fought, and with which of
108 its slots' Digimon if it isn't in its own form */
110 s16 slots[4];
111 DigimonData *digimon;
112 s32 partner;
113 BattleFighter *unit;
114 s32 i;
115
119 digimon = &DIGIMON_DATA[partner];
120 if (digimon->id != unit->id && GAME.funcs.getPartnerSlots(partner, slots) > 0) {
121 for (i = 0; i < 3; i++) {
122 if (slots[i] == unit->id) {
124 return;
125 }
126 }
127 }
128}
129
130/* Records in BATTLE_RESULT that the partner of the player's turn fought, and
131 which of its digivolution slots it fought as */
133 s16 slots[4];
134 s32 i;
135 s32 member;
136 s32 partner;
137
138 i = 0;
139 member = -1;
140 partner = GAME.funcs.getPartyMember(children->commands->arg);
141 for (; i < 3; i++) {
142 if (GAME.funcs.getPartyMember(i) == partner) {
143 member = i;
144 break;
145 }
146 }
147 BATTLE_RESULT.partners[member].fought = 1;
148 if (GAME.funcs.getPartnerSlots(GAME.funcs.getPartyMember(member), slots) > 0) {
149 for (i = 0; i < 3; i++) {
150 if (slots[i] == children->commands->digimon) {
151 BATTLE_RESULT.partners[member].used[i] = 1;
152 return;
153 }
154 }
155 }
156}
Battle FIGHTSTG_battle
the battle: its fighters, speed and drawing functions
Definition battle.c:16
void FIGHTSTG_queueRecovery(u8 side, s32 fighter, s32 big)
Queues a fighter's recovery of HP (event 6, with what getHeal takes as big), or sets the one already ...
Definition events.c:417
#define FIGHTSTG_CREATE_LAYERS(screen, frontCallbacks)
The body of WFIGHTMN's and WFIGHTTS's layer setups: the display and the battle's layers on SCREEN (a ...
Definition types.h:38
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
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
#define STAT_MP
Definition game_state.h:283
#define STAT_MAX_HP
Definition game_state.h:282
#define STAT_HP
Definition game_state.h:281
#define STAT_LEVEL
Indices of a partner's stats (PartnerStats.stats, computeStats, setStat)
Definition game_state.h:279
#define STAT_MAX_MP
Definition game_state.h:284
BattleSetup BATTLE_SETUP
Definition items.c:886
BattleResult BATTLE_RESULT
Definition items.c:888
WFIGHTMN.PRO: the battle's sub-overlay.
#define WFIGHTMN_RECOVERY_ITEM
The item a partner can equip that makes FIGHTSTG's FIGHTSTG_queueRecovery act on it at the start of t...
Random RANDOM
Definition random.c:533
void WFIGHTMN_createLayers(void)
Sets up the display and the battle's layers.
Definition setup.c:7
s32 WFIGHTMN_rollAmbush(void)
Checks the chance in BATTLE_SETUP.ambushChance, scaled by how far the first partner's level and the f...
Definition setup.c:60
void WFIGHTMN_markFought(void)
Marks in BATTLE_RESULT that the current partner fought, and with which of its slots' Digimon if it is...
Definition setup.c:109
void WFIGHTMN_checkEquip(s32 member)
Queues a recovery (FIGHTSTG_queueRecovery) for party member MEMBER's partner when it has WFIGHTMN_REC...
Definition setup.c:81
static void WFIGHTMN_setStat(s16 *cur, s16 *max, s16 value)
Sets a stat and its maximum.
Definition setup.c:14
void WFIGHTMN_markPicked(BattleMenu *task, BattleMenuChildren *children)
Records in BATTLE_RESULT that the partner of the player's turn fought, and which of its digivolution ...
Definition setup.c:132
void WFIGHTMN_initFighters(s32 digimon)
Fills the battle's fighters: the party's partners (the first one with the id DIGIMON) and the encount...
Definition setup.c:20
void WFIGHTMN_checkParty(void)
Checks each of the party's three partners for WFIGHTMN_RECOVERY_ITEM (WFIGHTMN_checkEquip)
Definition setup.c:99
s32 fighter
0 for none
Definition game_state.h:354
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
s16 id
the Digimon (DIGIMON_DATA)
Definition battle.h:192
The battle menu's children.
PlayerTurn * commands
the player's turn (FIGHTSTG_startPlayerTurn)
The battle menu (WFIGHTMN_start), registered as BATTLE_TASK_MENU.
struct BattleResult::@9 partners[3]
u8 used[3]
the Digimon of each slot was used
Definition game_state.h:403
u8 ambushChance
a chance that WFIGHTMN scales by level
Definition game_state.h:387
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
s16 item
what the enemy may leave
Definition battle.h:60
BattleState state
Definition battle.h:240
Digimon definition (DIGIMON_DATA, 52 of them; the first 8 are the partners)
Definition game_state.h:86
struct PartnerStats *(* getPartnerStats)(s32 partner)
Definition game_state.h:38
s32(* getPartyMember)(u32 index)
Definition game_state.h:24
s32(* getPartnerSlots)()
(partner, s16 *out): the count
Definition game_state.h:32
Partner partners[PARTNER_COUNT]
Definition game_state.h:517
GameFuncs funcs
Definition game_state.h:582
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 arg
the action's: the item, the technique, or the party slot of the partner that digivolves or switches o...
Definition menu.h:38
s32 digimon
the Digimon a partner changes into, or the one it switches to
Definition menu.h:39
s32(* next)(void)
0 to RANDOM_COUNT - 1
Definition random.h:15
RECT WFIGHTMN_screen
The screen its layers cover.
Definition wfightmn_2.c:6