Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
confused_menu.c
Go to the documentation of this file.
1/* FIGHTSTG's confused menu, the commands of a confused partner. */
2
4
5/* Shows the confused menu's six lines once, in FIGHTSTG_confusedLines's order */
8 char *text;
9 s32 i;
10
11 if (w->lines[0] == NULL) {
13 for (i = 0; i < 6; i++) {
14 w->lines[i] = createTextWindow(BATTLE_LAYER_MENUS, 1, 0x24, i * 0x13 + 0x6D);
15 w->lines[i]->setString(w->lines[i], text, FIGHTSTG_confusedLines[i] + 0x6B);
16 }
17 }
18}
19
20/* Draws the confused menu's message box and, once its lines are out, its
21 blinking arrow */
23 SpriteDrawer drawer;
24 void *sheet;
25
26 initSpriteDrawer(&drawer);
28 if (task->showArrow != 0) {
29 if (GFX.funcs.getTime() - task->arrowTime >= 4) {
30 task->arrowTime = GFX.funcs.getTime();
31 task->arrowPalette++;
32 if (task->arrowPalette >= 5) {
33 task->arrowPalette = 0;
34 }
35 }
36 drawer.setTexture(0x140, 0);
37 drawer.setClutRow(task->arrowPalette);
38 drawer.draw(FILE_CACHE.getEntry(FILE_MENU_SPRITES << 16), 10, 0x123, 0xD0);
39 drawer.setClutRow(0);
40 }
42 drawer.setTexture(0x200, 0);
43 drawer.draw(sheet, 0x31, 0xB, 0xBC);
44}
45
46/* Shows the confused message's lines one by one, 3 frames apart, then ends on
47 cross */
49 s32 pressed = PAD.getPressed(0);
50
51 switch (task->substate) {
52 case 0:
53 default:
54 if (task->started != 0) {
55 task->substate++;
56 }
57 break;
58 case 1:
59 task->time = GFX.funcs.getTime();
60 task->delay = 3;
61 w->lines[task->line]->setVisible(w->lines[task->line], 1);
62 task->substate++;
63 break;
64 case 2:
65 if (task->delay < GFX.funcs.getTime() - task->time) {
66 if (++task->line >= task->lineCount) {
67 task->showArrow = 1;
68 if (pressed & (1 << PAD_CROSS)) {
70 if (task->queue[++task->next] == 0) {
71 task->state = 3;
72 } else {
73 task->show(task, task->queue[task->next], 0);
74 task->setSubstate(task, 0);
75 }
76 task->showArrow = 0;
77 }
78 } else {
79 task->substate = 1;
80 }
81 }
82 break;
83 }
84}
85
86/* Puts the active partner's name into the message's first line (side 0 only) */
88 if (side == 0) {
90 }
91}
92
93/* the confused menu's (FIGHTSTG_updateConfusedMenu) results, two per line,
94 each a message (task->queue[0]) and its line of text 0x80 */
96 { 1, 0x73 }, { 2, 0x74 }, { 3, 0x75 }, { 4, 0x76 },
97 { 5, 0x77 }, { 6, 0x78 }, { 7, 0x79 }, { 8, 0x7A },
98 { 9, 0x7B }, { 10, 0x7C }, { 11, 0x7D }, { 12, 0x7E },
99 { 13, 0x7F }, { 14, 0x80 }, { 15, 0x81 }, { 16, 0x82 },
100};
101/* the confused menu's lines, which it shuffles */
103 7, 1, 0, 3, 2, 5, 4, 6,
104};
105
106/* Sets up confused message index (FIGHTSTG_confusedMessages) with the
107 partner's name and starts showing it */
109 ConfusedMenuWindows *w = task->children;
110
111 task->started = 1;
112 if (w->lines[0] == NULL) {
113 w->lines[0] = createTextWindow(BATTLE_LAYER_MENUS, 1, 0x14, 0xC2);
114 }
115 if (w->lines[1] == NULL) {
116 w->lines[1] = createTextWindow(BATTLE_LAYER_MENUS, 1, 0x14, 0xD0);
117 }
118 task->queue[0] = FIGHTSTG_confusedMessages[index].result;
121 task->lineCount = 2;
122 FIGHTSTG_setConfusedName(task, w, 0);
123 w->lines[0]->setVisible(w->lines[0], 0);
124 w->lines[1]->setVisible(w->lines[1], 0);
125}
126
127/* the confused menu's cursor */
129 6, 17, 110, 19, 34, 16, 109, 19,
130};
131
132/* The confused menu's task: shuffles the lines, then on cross attacks
133 (*result 0) when FIGHTSTG_battleFuncs.testConfusion fails; else closes the
134 lines, the partner view and the camera and shows one of the picked line's
135 two messages at random, giving 1 when it is done */
137 s32 i;
138 s32 j;
139 s16 line;
140
141 switch (task->state) {
142 case TASK_INIT:
143 default:
145 w->cursor->sel = task->firstLine;
146 for (i = 0; i < 8; i++) {
147 j = RANDOM.next() % 8;
148 line = FIGHTSTG_confusedLines[i];
150 FIGHTSTG_confusedLines[j] = line;
151 }
153 task->nextState(task);
154 break;
155 case TASK_RUN:
156 switch (task->substate) {
157 case 0:
158 if (PAD.getPressed(0) & (1 << PAD_CROSS)) {
161 *task->result = 0;
162 task->setState(task, 3);
163 } else {
164 task->picked = w->cursor->sel;
165 for (i = 0; i < 6; i++) {
166 w->lines[i]->setState(w->lines[i], 3);
167 }
168 w->cursor->setState(w->cursor, 3);
169 task->partnerView->state = 3;
170 task->shotCamera->state = 3;
171 task->nextSubstate(task);
172 }
173 w->cursor->locked = 1;
174 }
175 break;
176 case 1:
177 if (w->lines[0] == NULL && w->lines[1] == NULL) {
178 FIGHTSTG_showConfusedMessage(task, (FIGHTSTG_confusedLines[task->picked] << 1) | (RANDOM.next() & 1), 0);
179 task->setState(task, 2);
180 }
181 break;
182 }
183 break;
184 case TASK_DONE:
187 if (task->state == 3) {
188 *task->result = 1;
189 }
190 break;
191 case TASK_KILL:
192 break;
193 }
194}
195
196/* Opens a confused partner's command menu; *result gets 0 for an attack
197 or 1 for a lost turn */
198ConfusedMenu *FIGHTSTG_createConfusedMenu(s32 *result, Task *partnerView, Task *shotCamera) {
200
201 task->result = result;
202 *result = -1;
203 task->firstLine = 0;
204 task->partnerView = partnerView;
205 task->shotCamera = shotCamera;
206 return task;
207}
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
MenuCursor * FIGHTSTG_createCursor(CursorLayout *layout)
Creates a menu cursor laid out by layout.
Definition cursor.c:136
#define BATTLE_LAYER_MENUS
the HUD, the menus and the messages
Definition types.h:31
FIGHTSTG.PRO: the battle.
#define NULL
Definition common.h:17
signed int s32
Definition common.h:11
signed short s16
Definition common.h:9
void FIGHTSTG_showConfusedMessage(ConfusedMenu *task, s32 index, s32 unused)
Sets up confused message index (FIGHTSTG_confusedMessages) with the partner's name and starts showing...
void FIGHTSTG_setConfusedName(ConfusedMenu *task, ConfusedMenuWindows *windows, s32 side)
Puts the active partner's name into the message's first line (side 0 only)
void FIGHTSTG_stepConfusedMessage(ConfusedMenu *task, ConfusedMenuWindows *w)
Shows the confused message's lines one by one, 3 frames apart, then ends on cross.
ConfusedMessage FIGHTSTG_confusedMessages[16]
the confused menu's (FIGHTSTG_updateConfusedMenu) results, two per line, each a message (task->queue[...
CursorLayout FIGHTSTG_confusedCursor
the confused menu's cursor
void FIGHTSTG_updateConfusedMenu(ConfusedMenu *task, ConfusedMenuWindows *w)
The confused menu's task: shuffles the lines, then on cross attacks (*result 0) when FIGHTSTG_battleF...
void FIGHTSTG_drawConfusedMessageBox(ConfusedMenu *task)
Draws the confused menu's message box and, once its lines are out, its blinking arrow.
void FIGHTSTG_showConfusedCommands(ConfusedMenu *task)
Shows the confused menu's six lines once, in FIGHTSTG_confusedLines's order.
s16 FIGHTSTG_confusedLines[8]
the confused menu's lines, which it shuffles
ConfusedMenu * FIGHTSTG_createConfusedMenu(s32 *result, Task *partnerView, Task *shotCamera)
Opens a confused partner's command menu; *result gets 0 for an attack or 1 for a lost turn.
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_BATTLE_MENU
MFIGHT: WFIGHTMN's.
Definition file.h:218
#define TEXT_FILE(file)
Definition file.h:190
#define FILE_BATTLE_MENU
The battle menu's files (WFIGHTMN, WFIGHTTS): FILE_BATTLE_IMAGES is an archive whose entries go throu...
Definition file.h:294
#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
PadState PAD
Controller input: cleared by initPad, then the methods.
Definition pad.c:168
#define PAD_CROSS
Definition pad.h:31
Random RANDOM
Definition random.c:533
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...
s32(* testConfusion)(u8 side)
Definition battle.h:357
s32 active[2]
each side's fighter
Definition battle.h:226
BattleState state
Definition battle.h:240
Its children: the cursor, then its six lines; the first two are the message's after a pick.
Definition menu.h:281
TextWindow * lines[6]
Definition menu.h:283
struct MenuCursor * cursor
Definition menu.h:282
A confused partner's command menu (FIGHTSTG_createConfusedMenu): a cursor over six of the shuffled li...
Definition menu.h:257
void * children
Definition menu.h:258
void(* nextState)(struct ConfusedMenu *task)
Definition menu.h:258
s32 picked
Definition menu.h:260
void(* setState)(struct ConfusedMenu *task, s32 state)
Definition menu.h:258
Task * shotCamera
Definition menu.h:263
s32 next
in queue
Definition menu.h:270
s32 state
Definition menu.h:258
s32 arrowTime
when it last changed
Definition menu.h:273
s32 showArrow
Definition menu.h:274
s32 substate
Definition menu.h:258
s32 line
the window being shown
Definition menu.h:266
s32 firstLine
the cursor's first line
Definition menu.h:259
s32 * result
-1 until it is done
Definition menu.h:261
s32 queue[9]
like BattleMessageBox's: the message picked, then 0
Definition menu.h:264
Task * partnerView
the PartnerView, stopped with shotCamera on a pick
Definition menu.h:262
s32 delay
the time between them
Definition menu.h:268
void(* show)()
like BattleMessageBox's, but never set: the queue ends first
Definition menu.h:276
s32 started
set by FIGHTSTG_showConfusedMessage
Definition menu.h:265
s32 lineCount
Definition menu.h:267
s32 arrowPalette
0-4
Definition menu.h:272
void(* nextSubstate)(struct ConfusedMenu *task)
Definition menu.h:258
void(* setSubstate)(struct ConfusedMenu *task, s32 substate)
Definition menu.h:258
s32 time
Definition menu.h:269
A result of FIGHTSTG_updateConfusedMenu.
Definition menu.h:409
s16 result
for ConfusedMenu.queue[0]
Definition menu.h:410
A menu cursor's layout, which FIGHTSTG_createCursor copies into its task: a highlight bar over count ...
Definition menu.h:288
void *(* load)(u32 file)
Definition file.h:92
void *(* getEntry)(u32 fileAndIndex)
Definition file.h:96
struct PartnerStats *(* getPartnerStats)(s32 partner)
Definition game_state.h:38
s32(* getPartyMember)(u32 index)
Definition game_state.h:24
GameFuncs funcs
Definition game_state.h:582
s32(* getTime)(void)
Definition gfx.h:31
GfxFuncs funcs
Definition gfx.h:77
s32 sel
Definition menu.h:304
void(* setState)(struct MenuCursor *task, s32 state)
Definition menu.h:303
s32 locked
Definition menu.h:305
s32(* getPressed)(s32 pad)
Definition pad.h:125
s32(* next)(void)
0 to RANDOM_COUNT - 1
Definition random.h:15
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(* 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
Any task, seen through its header.
Definition task.h:62
s32 state
Definition task.h:63
void(* setState)(struct TextWindow *task, s32 state)
Definition text.h:132
void(* setSubString)()
Definition text.h:168
void(* setString)()
Definition text.h:165
void(* setVisible)(struct TextWindow *obj, u8 arg)
Definition text.h:177
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)