Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
switch_menu.c
Go to the documentation of this file.
1/* FIGHTSTG's switch menu, the partners that can come in. */
2
4
5/* Returns the Digimon fighter index has a pair technique with (its pairPartner, a
6 1-based DIGIMON_DATA entry) when party member member has it among its
7 digivolutions, else 0 */
9 BattleFighter *fighter;
10 s32 partner;
11 s32 next;
12 s32 count;
13 s32 i;
14
16 partner = GAME.funcs.getPartyMember(member);
17 fighter = &FIGHTSTG_battle.state.fighters[0][index];
18 next = GET_DIGIMON(fighter->id)->pairPartner;
19 count = GAME.funcs.getPartnerSlots(partner, task->slots);
20 if (count <= 0 || next == 0) {
21 return 0;
22 }
23 for (i = 0; i < count; i++) {
24 if (task->slots[i] == DIGIMON_DATA[next - 1].id) {
25 return next;
26 }
27 }
28 return 0;
29}
30
31/* Draws the pair technique icon by the fighters that have one with the active
32 fighter */
34 SpriteDrawer drawer;
35 void *sheet;
36 s32 i;
37
38 initSpriteDrawer(&drawer);
41 drawer.setTexture(0x200, 0);
42 for (i = 0; i < task->count; i++) {
43 if (task->pairs[i] != 0) {
44 drawer.draw(sheet, 0x30, 0x5A, 0x45 + i * 0x1F);
45 }
46 }
47}
48
49/* Makes the switch menu's windows, two lines a fighter: the name, HP over max
50 HP and MP over max MP */
52 char *text;
53 s32 i;
54
56 for (i = 0; i < task->count; i++) {
57 w->hpLabel[i] = createTextWindow(BATTLE_LAYER_MENUS, 3, 0x6C, 0x4E + i * 0x20);
58 w->hpLabel[i]->setString(w->hpLabel[i], text, 14);
59 w->hpSlash[i] = createTextWindow(BATTLE_LAYER_MENUS, 3, 0x99, 0x4E + i * 0x20);
60 w->hpSlash[i]->setString(w->hpSlash[i], text, 16);
61 w->mpLabel[i] = createTextWindow(BATTLE_LAYER_MENUS, 3, 0x6C, 0x5C + i * 0x20);
62 w->mpLabel[i]->setString(w->mpLabel[i], text, 13);
63 w->mpSlash[i] = createTextWindow(BATTLE_LAYER_MENUS, 3, 0x99, 0x5C + i * 0x20);
64 w->mpSlash[i]->setString(w->mpSlash[i], text, 16);
65 w->hp[i] = createTextWindow(BATTLE_LAYER_MENUS, 3, 0x98, 0x4E + i * 0x20);
66 w->maxHp[i] = createTextWindow(BATTLE_LAYER_MENUS, 3, 0xBB, 0x4E + i * 0x20);
67 w->mp[i] = createTextWindow(BATTLE_LAYER_MENUS, 3, 0x98, 0x5C + i * 0x20);
68 w->maxMp[i] = createTextWindow(BATTLE_LAYER_MENUS, 3, 0xBB, 0x5C + i * 0x20);
69 w->name[i] = createTextWindow(BATTLE_LAYER_MENUS, 1, 0x24, 0x4C + i * 0x20);
70 }
71}
72
73/* Shows the switch menu's fighters' names, HP and MP, the knocked out ones'
74 names in palette 7 */
76 BattleFighter *fighter;
77 s32 i;
78
79 for (i = 0; i < task->count; i++) {
80 fighter = &FIGHTSTG_battle.state.fighters[0][task->others[i]];
81 w->hp[i]->setNumber(w->hp[i], 0, fighter->hp);
82 w->hp[i]->setRightAlign(w->hp[i], 1);
83 w->maxHp[i]->setNumber(w->maxHp[i], 0, fighter->maxHp);
84 w->maxHp[i]->setRightAlign(w->maxHp[i], 1);
85 w->mp[i]->setNumber(w->mp[i], 0, fighter->mp);
86 w->mp[i]->setRightAlign(w->mp[i], 1);
87 w->maxMp[i]->setNumber(w->maxMp[i], 0, fighter->maxMp);
88 w->maxMp[i]->setRightAlign(w->maxMp[i], 1);
90 if (fighter->hp == 0) {
91 w->name[i]->setPalette(w->name[i], PALETTE_GREY);
92 } else {
93 w->name[i]->setPalette(w->name[i], PALETTE_WHITE);
94 }
95 }
96}
97
98/* The switch menu's task: puts a cursor on the other fighters, starting on
99 *line; cross picks one with HP into *result, triangle gives -2 when it
100 can cancel. With none to pick it shows message 0x14 and its blinking
101 arrow until cross gives -2 */
103 SpriteDrawer drawer;
104 BattleFighter *fighters;
105 BattleFighter *fighter;
106 s32 pressed;
107 s32 sel;
108 s32 active;
109 s32 temporary;
110 s32 i;
111
112 switch (task->state) {
113 case TASK_INIT:
114 default:
115 active = FIGHTSTG_battle.state.active[0];
116 fighters = FIGHTSTG_battle.state.fighters[0];
117 temporary = fighters[active].temporary;
118 for (i = 0; i < 3; i++) {
119 if (fighters[i].id != 0 && i != FIGHTSTG_battle.state.active[0]) {
120 task->others[task->count] = i;
121 if (task->canCancel != 0 && temporary == 0) {
123 }
124 task->count++;
125 }
126 }
127 if (task->count > 0) {
130 w->cursor->sel = *task->line;
133 task->nextState(task);
134 } else {
135 w->message = createTextWindow(BATTLE_LAYER_MENUS, 1, 0x14, 0xC2);
136 w->message->setVisible(w->message, 0);
137 task->setState(task, 2);
138 }
139 break;
140 case TASK_RUN:
142 /* the match depends on the do-while and its break, the stages' early exit */
143 do {
144 pressed = PAD.getPressed(0);
145 if (task->canCancel != 0 && (pressed & (1 << PAD_TRIANGLE))) {
147 *task->result = -2;
148 task->setState(task, 3);
149 break;
150 }
151 if (pressed & (1 << PAD_CROSS)) {
153 sel = w->cursor->sel;
154 fighter = &FIGHTSTG_battle.state.fighters[0][task->others[sel]];
155 if (fighter->hp != 0) {
156 *task->line = sel;
157 *task->result = task->others[w->cursor->sel];
158 task->setState(task, 3);
159 w->cursor->locked = 1;
160 }
161 }
162 } while (0);
163 break;
164 case 2:
165 if (PAD.getPressed(0) & (1 << PAD_CROSS)) {
167 *task->result = -2;
168 task->setState(task, 3);
169 w->message->setVisible(w->message, 0);
170 break;
171 }
172 initSpriteDrawer(&drawer);
174 if (task->arrowShown != 0) {
175 if (GFX.funcs.getTime() - task->arrowTime >= 4) {
176 task->arrowTime = GFX.funcs.getTime();
177 task->arrowPalette++;
178 if (task->arrowPalette >= 5) {
179 task->arrowPalette = 0;
180 }
181 }
182 drawer.setTexture(0x140, 0);
183 drawer.setClutRow(task->arrowPalette);
184 drawer.draw(FILE_CACHE.getEntry(FILE_MENU_SPRITES << 16), 10, 0x123, 0xD0);
185 drawer.setClutRow(0);
186 } else {
187 task->arrowShown = 1;
188 }
189 drawer.setTexture(0x200, 0);
190 drawer.draw(FILE_CACHE.getEntry(FILE_BATTLE_MENU << 16), 0x31, 0xB, 0xBC);
191 if (!w->message->isVisible(w->message)) {
193 }
194 break;
195 case 3:
196 break;
197 }
198}
199
200/* Opens the switch menu; *result gets the fighter to bring in, or -2 */
201SwitchMenu *FIGHTSTG_createSwitchMenu(s32 *result, s32 *line, s32 canCancel) {
203
204 task->result = result;
205 *result = -1;
206 task->line = line;
207 task->canCancel = canCancel;
208 return task;
209}
Battle FIGHTSTG_battle
the battle: its fighters, speed and drawing functions
Definition battle.c:16
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.
signed int s32
Definition common.h:11
DigimonData DIGIMON_DATA[55]
55 entries: the 52 Digimon, then three placeholders (0x1D4-0x1D6)
Definition digimon.c:7
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_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 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
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
CursorLayout FIGHTSTG_switchCursor
FIGHTSTG_updateSwitchMenu's cursor.
Definition item_menu.c:98
PadState PAD
Controller input: cleared by initPad, then the methods.
Definition pad.c:168
#define PAD_CROSS
Definition pad.h:31
#define PAD_TRIANGLE
Definition pad.h:32
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
#define SOUND_MENU_CANCEL
SYSTEM01.
Definition sound.h:39
void initSpriteDrawer(SpriteDrawer *obj)
Clears a sprite drawer to neutral (no scale, gray tint, follows the scroll), gives it its methods and...
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 temporary
id is a temporary Digimon
Definition battle.h:202
s16 id
the Digimon (DIGIMON_DATA)
Definition battle.h:192
s32 active[2]
each side's fighter
Definition battle.h:226
BattleFighter fighters[2][3]
Definition battle.h:227
BattleState state
Definition battle.h:240
s32 count
Definition menu.h:289
u8 pairPartner
the Digimon (from 1) it does pairTech with, 0 for none
Definition game_state.h:96
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
s32(* getPartnerSlots)()
(partner, s16 *out): the count
Definition game_state.h:32
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
s32 locked
Definition menu.h:305
s32(* getPressed)(s32 pad)
Definition pad.h:125
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
FIGHTSTG_updateSwitchMenu's children: two of each window, one per fighter.
Definition menu.h:239
TextWindow * maxHp[2]
Definition menu.h:244
TextWindow * mpSlash[2]
Definition menu.h:247
TextWindow * message
Definition menu.h:250
struct MenuCursor * cursor
Definition menu.h:240
TextWindow * mp[2]
Definition menu.h:246
TextWindow * mpLabel[2]
Definition menu.h:245
TextWindow * hpLabel[2]
Definition menu.h:241
TextWindow * hp[2]
Definition menu.h:242
TextWindow * maxMp[2]
Definition menu.h:248
TextWindow * hpSlash[2]
Definition menu.h:243
TextWindow * name[2]
Definition menu.h:249
The battle's switch menu (FIGHTSTG_createSwitchMenu): the player's other fighters,...
Definition menu.h:224
s16 slots[6]
GAME.funcs.getPartnerSlots's.
Definition menu.h:235
s32 * line
the cursor's line, kept for the next time
Definition menu.h:227
void(* nextState)(struct SwitchMenu *task)
Definition menu.h:225
s32 canCancel
triangle goes back (not after a knockout)
Definition menu.h:228
s32 * result
-1 until it is done, then the fighter or -2
Definition menu.h:226
s32 arrowPalette
Definition menu.h:233
s32 count
Definition menu.h:230
void(* setState)(struct SwitchMenu *task, s32 state)
Definition menu.h:225
s32 pairs[2]
FIGHTSTG_getPairDigimon's, marked with an icon.
Definition menu.h:234
s32 arrowTime
Definition menu.h:232
s32 state
Definition menu.h:225
s32 arrowShown
the message's arrow, from its second frame
Definition menu.h:231
s32 others[2]
the other fighters of the player's side
Definition menu.h:229
void(* setPalette)(struct TextWindow *obj, u8 arg)
Definition text.h:174
s32(* isVisible)()
s32: callers don't truncate the result to a byte
Definition text.h:187
void(* setRightAlign)()
no prototype: callers would truncate u8 args
Definition text.h:178
void(* setNumber)()
Definition text.h:166
void(* setString)()
Definition text.h:165
void(* setVisible)(struct TextWindow *obj, u8 arg)
Definition text.h:177
void FIGHTSTG_drawSwitchMenu(SwitchMenu *task)
Draws the pair technique icon by the fighters that have one with the active fighter.
Definition switch_menu.c:33
SwitchMenu * FIGHTSTG_createSwitchMenu(s32 *result, s32 *line, s32 canCancel)
Opens the switch menu; *result gets the fighter to bring in, or -2.
void FIGHTSTG_updateSwitchMenu(SwitchMenu *task, SwitchMenuWindows *w)
The switch menu's task: puts a cursor on the other fighters, starting on line; cross picks one with H...
s32 FIGHTSTG_getPairDigimon(SwitchMenu *task, s32 index, s32 member)
Returns the Digimon fighter index has a pair technique with (its pairPartner, a 1-based DIGIMON_DATA ...
Definition switch_menu.c:8
void FIGHTSTG_createSwitchWindows(SwitchMenu *task, SwitchMenuWindows *w)
Makes the switch menu's windows, two lines a fighter: the name, HP over max HP and MP over max MP.
Definition switch_menu.c:51
void FIGHTSTG_showSwitchFighters(SwitchMenu *task, SwitchMenuWindows *w)
Shows the switch menu's fighters' names, HP and MP, the knocked out ones' names in palette 7.
Definition switch_menu.c:75
void * createTask(void(*update)(), s32 size, s32 childrenSize)
createTaskWithId for a task nothing needs to find
Definition task.c:105
#define PALETTE_WHITE
The text windows' palettes (TextWindow.palette, setPalette): rows of the font's CLUTs,...
Definition text.h:112
#define PALETTE_GREY
what is unavailable
Definition text.h:119
TextWindow * createTextWindow(s16 layerId, s16 style, s16 x, s16 y)
A text window on a layer, in a font style, at (x, y)