Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
report.c
Go to the documentation of this file.
1/* The report: its windows, its drawing, its run through the partners, the
2 money and the item won, and its files. */
3
4#include "battle/report.h"
5
6/* Creates the report's text windows: the exp, its label and the two-line
7 message */
9 TextWindow *window;
10
11 children->exp = createTextWindow(report->layer, 3, 0x42, 0x17);
12 children->expLabel = createTextWindow(report->layer, 3, 0x45, 0x17);
13 window = createTextWindow(report->layer, 1, 0x14, 0xC2);
14 children->message = window;
15 window->setLines(window, 2);
16}
17
18/* Draws the report's message arrow, background, header and footer */
20 SpriteDrawer sprite;
21
22 if (report->arrowOn != 0) {
23 if (GFX.funcs.getTime() - report->arrowTime >= 5) {
24 report->arrowTime = GFX.funcs.getTime();
25 if (++report->arrowFrame >= 5) {
26 report->arrowFrame = 0;
27 }
28 }
29 initSpriteDrawer(&sprite);
30 sprite.setTexture(0x140, 0);
31 sprite.setLayerId(report->layer, report->depth - 2);
32 sprite.setClutRow(report->arrowFrame);
33 sprite.draw(FILE_CACHE.getEntry(FILE_MENU_SPRITES << 16), 10, 0x123, 0xD0);
34 }
35 initSpriteDrawer(&sprite);
36 sprite.setTexture(0x280, 0);
37 sprite.setLayerId(report->layer, report->depth);
38 if (report->bgSkip != 0) {
39 report->bgScroll++;
40 report->bgScroll = report->bgScroll < 0x60 ? report->bgScroll : 0;
41 report->bgSkip = 0;
42 } else {
43 report->bgSkip = 1;
44 }
45 sprite.draw(FILE_CACHE.getEntry((FILE_FGTREP_SPRITES - 1) << 16), 0x1E, report->bgScroll, report->bgScroll);
46 sprite.setLayerId(report->layer, report->depth - 1);
47 if (report->header.level != 0) {
48 if (report->header.level != 0x1000) {
49 sprite.setScale(report->header.level, 0x1000, 0x1000);
50 sprite.setPivot(0, 0x18);
51 }
52 sprite.draw(FILE_CACHE.getEntry((FILE_FGTREP_SPRITES - 1) << 16), 0x21, 0, 0xF);
53 }
54 if (report->footer.level != 0) {
55 sprite.setScale(0x1000, report->footer.level, 0x1000);
56 if (report->footer.level != 0x1000) {
57 sprite.setPivot(0xA0, 0xCE);
58 }
59 sprite.draw(FILE_CACHE.getEntry((FILE_FGTREP_SPRITES - 1) << 16), 0x1D, 0xB, 0xBC);
60 }
61}
62
63/* Selects the next partner that got exp and fades the header in; after the
64 last one goes on to the money */
65static inline void selectNextPartner(FightReport *report, FightReportChildren *children) {
66 if (report->step < report->count) {
67 if (report->exp[report->step] == 0) {
68 report->step++;
69 } else {
70 STFGTREP_funcs.startFade(&report->header, 1);
71 children->partners[report->step]->select(children->partners[report->step]);
72 report->substate++;
73 }
74 } else {
75 report->setSubstate(report, 0x14);
76 }
77}
78
79/* Shows the current partner's exp in the message and in the exp window */
80static inline void showExp(FightReport *report, FightReportChildren *children) {
82 children->message->setNumber(children->message, 1, report->exp[report->step]);
83 children->message->setTypeDelay(children->message, 6);
84 children->exp->setNumber(children->exp, 0, report->exp[report->step]);
85 children->exp->setRightAlign(children->exp, 1);
87}
88
89/* While the message types, cross shows its whole page; at a page end the
90 arrow shows until cross, which plays the confirm sound */
91static inline void turnMessagePage(FightReport *report, FightReportChildren *children) {
92 if (children->message->isWaitingForButton(children->message) != 0) {
95 } else {
96 report->arrowOn = 1;
97 }
98 } else if (PAD_PRESSED(PAD_CROSS)) {
99 children->message->showPage(children->message);
100 }
101}
102
103/* Fades the header out and hides the exp once the partner's raise is shown,
104 moving on to the next partner */
105static inline void hideExp(FightReport *report, FightReportChildren *children) {
106 STFGTREP_funcs.startFade(&report->header, 0);
107 children->exp->setVisible(children->exp, 0);
108 children->expLabel->setVisible(children->expLabel, 0);
109 report->substate++;
110 report->step++;
111}
112
113/* Gives the money the battle won, a fifth more with item 0x142 equipped,
114 and shows it in the message */
115static inline void giveMoney(FightReport *report, FightReportChildren *children) {
116 PartnerStats *stats;
117 s32 money;
118
121 if (stats->equip[4] == 0x142 || stats->equip[5] == 0x142) {
123 }
125 children->message->setNumber(children->message, 1, money);
126 children->message->setTypeDelay(children->message, 6);
127 report->substate = 0x19;
128 report->step = 0;
129 GAME.money += money;
130 if (GAME.money > 9999999) {
131 GAME.money = 9999999;
132 }
133}
134
135/* Gives the item the battle won, up to 99, and shows it in the message;
136 with none the report ends */
137static inline void giveItem(FightReport *report, FightReportChildren *children) {
138 if (BATTLE_RESULT.item != 0) {
141 children->message->setTypeDelay(children->message, 6);
142 report->substate = 0x19;
143 report->step = 1;
145 if (GAME.items[BATTLE_RESULT.item] >= 100) {
147 }
148 } else {
149 report->substate = 0x32;
150 }
151}
152
153/* Starts fading the screen and the footer out and hides the message */
154static inline void startFadeOut(FightReport *report, FightReportChildren *children) {
155 children->fade = STFGTREP_createFader();
156 children->fade->start(children->fade, 0, 30);
157 STFGTREP_funcs.startFade(&report->footer, 0);
158 children->message->setVisible(children->message, 0);
159 report->substate++;
160}
161
162/* The report while it runs: shows the panels, then for each partner that
163 got exp its message and the raise (selectNextPartner, showExp, hideExp),
164 then the money and the item won (giveMoney, giveItem), and fades out
165 (startFadeOut) */
167 s32 shown;
168 s32 hidden;
169 s32 i;
170 s32 j;
171
172 switch (report->substate) {
173 case 1:
174 for (i = 0; i < report->count; i++) {
175 children->partners[i]->show(children->partners[i]);
176 }
177 /* fallthrough */
178 case 0:
179 default:
180 report->substate++;
181 break;
182 case 4:
183 shown = 1;
184 for (j = 0; j < report->count; j++) {
185 if (children->partners[j]->substate != 5) {
186 shown = 0;
187 break;
188 }
189 }
190 if (shown) {
191 STFGTREP_funcs.startFade(&report->footer, 1);
192 report->substate++;
193 }
194 break;
195 case 5:
196 if (STFGTREP_funcs.updateFade(&report->footer) != 0) {
197 report->substate++;
198 }
199 break;
200 case 6:
201 selectNextPartner(report, children);
202 break;
203 case 7:
204 if (STFGTREP_funcs.updateFade(&report->header) != 0) {
205 showExp(report, children);
206 report->substate++;
207 }
208 break;
209 case 8:
210 if (children->message->isFinished(children->message) != 0) {
211 report->arrowOn = 0;
212 children->message->setVisible(children->message, 0);
213 report->substate = 10;
214 } else {
215 turnMessagePage(report, children);
216 }
217 break;
218 case 10:
219 children->partners[report->step]->raise(children->partners[report->step]);
220 report->substate++;
221 break;
222 case 11:
223 if (children->partners[report->step]->substate == 5) {
224 hideExp(report, children);
225 }
226 break;
227 case 12:
228 if (STFGTREP_funcs.updateFade(&report->header) != 0) {
229 report->substate = 6;
230 }
231 break;
232 case 0x14:
233 giveMoney(report, children);
234 break;
235 case 0x15:
236 giveItem(report, children);
237 break;
238 case 0x19:
239 if (children->message->isFinished(children->message) != 0) {
240 children->message->setVisible(children->message, 0);
241 report->arrowOn = 0;
242 switch (report->step) {
243 case 0:
244 default:
245 report->substate = 0x15;
246 break;
247 case 1:
248 report->substate = 0x32;
249 break;
250 }
251 } else {
252 turnMessagePage(report, children);
253 }
254 break;
255 case 0x32:
256 startFadeOut(report, children);
257 break;
258 case 0x33:
259 if (STFGTREP_funcs.updateFade(&report->footer) != 0) {
260 for (i = 0; i < report->count; i++) {
261 children->partners[i]->hide(children->partners[i]);
262 }
263 report->substate++;
264 }
265 break;
266 case 0x34:
267 hidden = 1;
268 for (j = 0; j < report->count; j++) {
269 if (children->partners[j]->substate != 15) {
270 hidden = 0;
271 break;
272 }
273 }
274 if (hidden) {
275 report->substate++;
276 }
277 break;
278 case 0x35:
279 if (children->fade->state == TASK_DONE) {
280 report->state = TASK_KILL;
281 }
282 break;
283 }
284}
285
286/* The report's main task: loads the files, shares the battle's exp among the
287 partners who fought and creates their panels */
289 s32 fought;
290 s32 exp;
291 s32 i;
292 s32 j;
293
294 switch (report->state) {
295 case TASK_INIT:
296 default:
297 switch (report->substate) {
298 case 0:
299 default:
301 report->substate++;
302 break;
303 case 1:
304 if (STFGTREP_funcs.filesLoading() != 0) {
305 break;
306 }
307 report->nextState(report);
308 STFGTREP_createWindows(report, children);
309 for (i = 0; i < 3; i++) {
310 if (GAME.funcs.getPartyMember(i) >= 0) {
311 report->count++;
312 }
313 }
314 fought = 0;
315 for (i = 0; i < 3; i++) {
316 if (BATTLE_RESULT.partners[i].fought != 0) {
317 fought++;
318 for (j = 0; j < 3; j++) {
319 if (BATTLE_RESULT.partners[i].used[j] != 0) {
320 report->used++;
321 }
322 }
323 }
324 }
325 switch (fought) {
326 case 1:
327 default:
329 break;
330 case 2:
332 break;
333 case 3:
335 break;
336 }
337 for (i = 0; i < report->count; i++) {
338 if (BATTLE_RESULT.partners[i].fought != 0) {
339 children->partners[i] = STFGTREP_createPartner(report, i, exp);
340 report->exp[i] = children->partners[i]->boostExp(children->partners[i]);
341 } else {
342 children->partners[i] = STFGTREP_createPartner(report, i, 0);
343 }
344 }
345 report->header.duration = 10;
346 report->footer.duration = 10;
347 break;
348 }
349 break;
350 case TASK_RUN:
351 STFGTREP_runReport(report, children);
352 STFGTREP_drawReport(report);
353 break;
354 case TASK_DONE:
355 break;
356 case TASK_KILL:
358 break;
359 }
360}
361
362/* Creates the report (STFGTREP_updateReport) on the screen layer */
365
366 report->layer = SCREEN_LAYER;
367 report->depth = 7;
368 return report;
369}
370
371/* Loads the report's sprites and requests its texts, the Digimon names and
372 the item names */
383
384/* Whether STFGTREP_loadFiles's texts are still loading */
387 return 1;
388 }
390 return 1;
391 }
393}
ReportPartner * STFGTREP_createPartner(FightReport *report, s32 index, s32 exp)
Creates the panel of party member index, who gets exp.
Definition partner.c:511
signed int s32
Definition common.h:11
GfxState GFX
GFX: the graphics state and its methods.
Definition display.c:209
GameState GAME
The save data, the game mode and the methods.
Definition state.c:64
#define TASK_RUN
Definition task.h:35
#define TASK_KILL
Definition task.h:37
#define TASK_INIT
Tasks: every game object is a task, a heap block that starts with this header and is updated once per...
Definition task.h:34
#define TASK_DONE
Definition task.h:36
#define TEXT_FILE(file)
Definition file.h:190
#define TEXT_FIGHT_REPORT
FGTRPT: STFGTREP's.
Definition file.h:212
#define TEXT_DIGIMON_NAMES
DIGNAM.
Definition file.h:211
#define TEXT_ITEM_NAMES
ITMNAM.
Definition file.h:215
#define FILE_MENU_SPRITES
Files the engine loads by number.
Definition file.h:188
FileCache FILE_CACHE
The file cache.
Definition file_cache.c:7
#define SCREEN_LAYER
The layer over the whole screen that most modes create first and draw their menus on (FIELDSTG and ST...
Definition gfx.h:45
BattleResult BATTLE_RESULT
Definition items.c:888
#define PAD_CROSS
Definition pad.h:31
#define PAD_PRESSED(button)
One button of pad 1: newly pressed, auto-repeated while held, or held.
Definition pad.h:140
static void hideExp(FightReport *report, FightReportChildren *children)
Fades the header out and hides the exp once the partner's raise is shown, moving on to the next partn...
Definition report.c:105
static void giveItem(FightReport *report, FightReportChildren *children)
Gives the item the battle won, up to 99, and shows it in the message; with none the report ends.
Definition report.c:137
static void startFadeOut(FightReport *report, FightReportChildren *children)
Starts fading the screen and the footer out and hides the message.
Definition report.c:154
static void giveMoney(FightReport *report, FightReportChildren *children)
Gives the money the battle won, a fifth more with item 0x142 equipped, and shows it in the message.
Definition report.c:115
void STFGTREP_runReport(FightReport *report, FightReportChildren *children)
The report while it runs: shows the panels, then for each partner that got exp its message and the ra...
Definition report.c:166
static void showExp(FightReport *report, FightReportChildren *children)
Shows the current partner's exp in the message and in the exp window.
Definition report.c:80
FightReport * STFGTREP_createScreen(void)
Creates the report (STFGTREP_updateReport) on the screen layer.
Definition report.c:363
void STFGTREP_drawReport(FightReport *report)
Draws the report's message arrow, background, header and footer.
Definition report.c:19
static void turnMessagePage(FightReport *report, FightReportChildren *children)
While the message types, cross shows its whole page; at a page end the arrow shows until cross,...
Definition report.c:91
void STFGTREP_updateReport(FightReport *report, FightReportChildren *children)
The report's main task: loads the files, shares the battle's exp among the partners who fought and cr...
Definition report.c:288
s32 STFGTREP_filesLoading(void)
Whether STFGTREP_loadFiles's texts are still loading.
Definition report.c:385
void STFGTREP_loadFiles(void)
Loads the report's sprites and requests its texts, the Digimon names and the item names.
Definition report.c:373
static void selectNextPartner(FightReport *report, FightReportChildren *children)
Selects the next partner that got exp and fades the header in; after the last one goes on to the mone...
Definition report.c:65
void STFGTREP_createWindows(FightReport *report, FightReportChildren *children)
Creates the report's text windows: the exp, its label and the two-line message.
Definition report.c:8
STFGTREP.PRO: mode 0x1400, the report after a battle.
ScreenFade * STFGTREP_createFader(void)
#define FILE_FGTREP_SPRITES
The sprite archive the overlay loads.
Definition report.h:20
SoundState SOUND
rsin and rcos (libgte) read rsin_tbl[a - 0x800] and the like: their addresses before the table fall i...
Definition sound.c:180
#define SOUND_MENU_CONFIRM
SYSTEM07.
Definition sound.h:44
void initSpriteDrawer(SpriteDrawer *obj)
Clears a sprite drawer to neutral (no scale, gray tint, follows the scroll), gives it its methods and...
BattleReward STFGTREP_rewards[]
Definition stfgtrep.c:345
FightReportFuncs STFGTREP_funcs
Definition stfgtrep.c:1070
s16 member
the party member whose accessory adds money
Definition game_state.h:400
s16 battle
row of STFGTREP_rewards
Definition game_state.h:398
struct BattleResult::@9 partners[3]
u8 used[3]
the Digimon of each slot was used
Definition game_state.h:403
s16 item
the item won, 0 for none
Definition game_state.h:399
s32 exp
shared by the partners who fought
Definition report.h:26
s32 money
Definition report.h:27
The children of the main task.
Definition report.h:121
TextWindow * exp
Definition report.h:122
TextWindow * expLabel
Definition report.h:123
ScreenFade * fade
Definition report.h:126
ReportPartner * partners[3]
Definition report.h:125
TextWindow * message
Definition report.h:124
s32(* filesLoading)(void)
Definition report.h:132
void(* startFade)(PanelAnim *fade, s32 fadeIn)
Definition report.h:133
void(* loadFiles)(void)
Definition report.h:131
s32(* updateFade)(PanelAnim *fade)
Definition report.h:134
The main task of the screen (STFGTREP_createScreen)
Definition report.h:104
PanelAnim footer
Definition report.h:117
s32 arrowOn
the message waits for a button
Definition report.h:113
s32 depth
Definition report.h:107
s32 count
partners in the party
Definition report.h:110
void(* setSubstate)(struct FightReport *task, s32 substate)
Definition report.h:105
s32 exp[3]
what each one gets
Definition report.h:111
s32 used
Digimon used in the battle.
Definition report.h:112
s32 state
Definition report.h:105
void(* nextState)(struct FightReport *task)
Definition report.h:105
s32 bgSkip
the background moves every other frame
Definition report.h:109
s32 arrowTime
Definition report.h:114
s32 bgScroll
Definition report.h:108
s32 layer
Definition report.h:106
s32 substate
Definition report.h:105
s32 arrowFrame
Definition report.h:115
PanelAnim header
Definition report.h:116
void *(* load)(u32 file)
Definition file.h:92
s32(* isLoading)(s32 file)
Definition file.h:88
void(* request)(s32 file)
Definition file.h:90
void *(* getEntry)(u32 fileAndIndex)
Definition file.h:96
struct PartnerStats *(* getPartnerStats)(s32 partner)
Definition game_state.h:38
void(* requestMode)(s32 mode, s32 arg)
Definition game_state.h:21
s32(* getPartyMember)(u32 index)
Definition game_state.h:24
s8 items[0x193]
counts, up to 99
Definition game_state.h:512
s32 fieldMode
where the menu returns to
Definition game_state.h:503
GameFuncs funcs
Definition game_state.h:582
s32(* getTime)(void)
Definition gfx.h:31
GfxFuncs funcs
Definition gfx.h:77
s32 level
Definition menu.h:21
s32 duration
Definition menu.h:19
A partner Digimon from its name on (Partner.info), as getPartnerStats gives it.
Definition game_state.h:303
s32 substate
Definition report.h:52
void(* show)(struct ReportPartner *partner)
Definition report.h:82
void(* raise)(struct ReportPartner *partner)
Definition report.h:84
void(* select)(struct ReportPartner *partner)
Definition report.h:86
s32(* boostExp)(struct ReportPartner *partner)
Definition report.h:85
void(* hide)(struct ReportPartner *partner)
Definition report.h:83
void(* start)(struct ScreenFade *fade, s32 fadeIn, s32 frames)
TASK_DONE when done.
Definition gfx.h:368
s32 state
Definition gfx.h:362
short(* playSound)(s32 id)
returns the voice of a key-on
Definition sound.h:187
Draws sprites from a sprite sheet (such as file 0x277, the menu graphics): a sheet has a table of fra...
Definition gfx.h:223
void(* setPivot)()
(x, y)
Definition gfx.h:250
void(* setScale)()
(x, y, z), ONE = 1.0
Definition gfx.h:248
void(* setLayerId)()
(id, depth)
Definition gfx.h:244
void(* setClutRow)()
(row)
Definition gfx.h:247
void(* draw)()
(sheet, frame, x, y)
Definition gfx.h:246
void(* setTexture)()
(x, y)
Definition gfx.h:242
A text window (createTextWindow): up to six text buffers (0 is shown, 1-5 are "work" buffers that con...
Definition text.h:131
s32(* isWaitingForButton)()
Definition text.h:188
s32(* isFinished)()
s32: callers don't truncate the result to a byte
Definition text.h:186
void(* setRightAlign)()
no prototype: callers would truncate u8 args
Definition text.h:178
void(* setTypeDelay)()
Definition text.h:172
void(* setLines)()
no prototype: callers would truncate u8 args
Definition text.h:184
void(* setSubString)()
Definition text.h:168
void(* setNumber)()
Definition text.h:166
void(* setString)()
Definition text.h:165
void(* showPage)()
Definition text.h:170
void(* setVisible)(struct TextWindow *obj, u8 arg)
Definition text.h:177
Uploads TIM images to VRAM (initTimLoader); acts on TIM_LOADER.
Definition gfx.h:325
void(* setImagePos)()
(x, y)
Definition gfx.h:336
void(* loadArchive)()
(archive): each image 64 halfwords to the right
Definition gfx.h:338
void * createTask(void(*update)(), s32 size, s32 childrenSize)
createTaskWithId for a task nothing needs to find
Definition task.c:105
TextWindow * createTextWindow(s16 layerId, s16 style, s16 x, s16 y)
A text window on a layer, in a font style, at (x, y)
void initTimLoader(TimLoader *obj)
Clears a TIM loader, gives it its methods and binds it.
Definition tim_loader.c:119