Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
map_screen.c
Go to the documentation of this file.
1/* The map screen, with the areas visited and the towns. It begins STSTATUS's
2 last object, which has no rodata: where its code starts is a guess */
3
4#include "menus/field_menu.h"
5
6/* Finds the area under the cursor and shows its name */
8 s32 wasHovering = screen->hovering;
9 StatusMapSpot *spots;
10 s32 spotX;
11 s32 spotY;
12 s32 x;
13 s32 y;
14 s32 i;
15
16 screen->hovering = 0;
17 x = screen->cursorX - screen->scrollX;
18 y = screen->cursorY - screen->scrollY;
19 spots = STSTATUS_data.spots;
20 for (i = 1; i < 47; i++) {
21 if (screen->visited[i - 1]) {
22 spotX = spots[i].x;
23 spotY = spots[i].y;
24 if (spotX + 6 < x && x <= spotX + 0x12 && spotY + 6 < y && y <= spotY + 0x12) {
25 screen->hovering = 1;
26 screen->spot = i;
27 break;
28 }
29 }
30 }
31 if (wasHovering != screen->hovering) {
32 if (screen->hovering) {
34#if VERSION_EU || VERSION_JP
35 screen->hoverX = screen->cursorX;
36#endif
37 screen->hoverY = screen->cursorY;
38 } else {
39 windows[0]->setVisible(windows[0], 0);
40 }
41 }
42 if (screen->hovering) {
43 if (screen->hoverY < screen->height / 2) {
44 windows[0]->setPos(windows[0], 0x10, 0xB9);
45 } else {
46 windows[0]->setPos(windows[0], 0x10, 0x19);
47 }
48 windows[0]->setString(windows[0], FILE_CACHE.load(screen->textFile), screen->spot);
49 }
50}
51
52/* Moves the cursor, or the map when the cursor is in the middle */
54 s32 middle;
55
56 if (dx < 0) {
57 if (screen->cursorX > 0xA0) {
58 screen->cursorX -= screen->speedX;
59 if (screen->cursorX < 0xA0) {
60 screen->cursorX = 0xA0;
61 }
62 } else if (screen->cursorX < 0xA0) {
63 screen->cursorX -= screen->speedX;
64 if (screen->cursorX < 0x16) {
65 screen->cursorX = 0x16;
66 }
67 } else {
68 screen->scrollX += screen->speedX;
69 if (screen->scrollX > 0) {
70 screen->scrollX = 0;
71 screen->cursorX = 0x9F;
72 }
73 }
74 } else if (dx > 0) {
75 if (screen->cursorX < 0xA0) {
76 screen->cursorX += screen->speedX;
77 if (screen->cursorX > 0xA0) {
78 screen->cursorX = 0xA0;
79 }
80 } else if (screen->cursorX > 0xA0) {
81 screen->cursorX += screen->speedX;
82 if (screen->cursorX > 0x12A) {
83 screen->cursorX = 0x12A;
84 }
85 } else {
86 screen->scrollX -= screen->speedX;
87 if (screen->scrollX < -0x48) {
88 screen->scrollX = -0x48;
89 screen->cursorX = 0xA1;
90 }
91 }
92 }
93 middle = screen->height / 2;
94 if (dy < 0) {
95 if (screen->cursorY > middle) {
96 screen->cursorY -= screen->speedY;
97 if (screen->cursorY < middle) {
98 screen->cursorY = middle;
99 }
100 } else if (screen->cursorY < middle) {
101 screen->cursorY -= screen->speedY;
102 if (screen->cursorY < 0xF) {
103 screen->cursorY = 0xF;
104 }
105 } else {
106 screen->scrollY += screen->speedY;
107 if (screen->scrollY > 0) {
108 screen->scrollY = 0;
109 screen->cursorY = middle - 1;
110 }
111 }
112 } else if (dy > 0) {
113 if (screen->cursorY < middle) {
114 screen->cursorY += screen->speedY;
115 if (screen->cursorY > middle) {
116 screen->cursorY = middle;
117 }
118 } else if (screen->cursorY > middle) {
119 screen->cursorY += screen->speedY;
120 if (screen->cursorY > screen->height - screen->top - 0x1E) {
121 screen->cursorY = screen->height - screen->top - 0x1E;
122 }
123 } else {
124 screen->scrollY -= screen->speedY;
125 if (screen->scrollY < -0x60) {
126 screen->scrollY = -0x60;
127 screen->cursorY = middle + 1;
128 }
129 }
130 }
131}
132
133/* Moves the cursor faster while the pad is held; triangle closes */
137 screen->speedX = 2;
139 screen->speedX++;
140 if (screen->speedX > 4) {
141 screen->speedX = 4;
142 }
143 }
144 } else {
145 screen->speedX = 0;
146 }
147 if (PAD_HELD(PAD_UP) || PAD_HELD(PAD_DOWN)) {
149 screen->speedY = 2;
150 } else if (PAD_REPEATED(PAD_UP) || PAD_REPEATED(PAD_DOWN)) {
151 screen->speedY++;
152 if (screen->speedY > 4) {
153 screen->speedY = 4;
154 }
155 }
156 } else {
157 screen->speedY = 0;
158 }
159 if (PAD_HELD(PAD_LEFT)) {
160 STSTATUS_moveMapCursor(screen, -1, 0);
161 } else if (PAD_HELD(PAD_RIGHT)) {
162 STSTATUS_moveMapCursor(screen, 1, 0);
163 }
164 if (PAD_HELD(PAD_UP)) {
165 STSTATUS_moveMapCursor(screen, 0, -1);
166 } else if (PAD_HELD(PAD_DOWN)) {
167 STSTATUS_moveMapCursor(screen, 0, 1);
168 }
171 screen->state = TASK_KILL;
172 }
173}
174
175/* Draws the map, the visited areas, the towns and the cursor */
177 SpriteDrawer sprite;
178 s32 *towns;
179#if VERSION_EU || VERSION_JP
180 s32 x;
181#endif
182 s32 frame;
183 s32 i;
184
185 if (screen->hovering) {
186 initSpriteDrawer(&sprite);
187 sprite.setLayerId(screen->layer, screen->depth - 2);
188 sprite.setTexture(0x280, 0x100);
189 if (screen->hoverY < screen->height / 2) {
190 sprite.draw(FILE_CACHE.getEntry(FILE_STATUS_SPRITES << 16), 0x3B, 0, 0xB4);
191 } else {
192 sprite.draw(FILE_CACHE.getEntry(FILE_STATUS_SPRITES << 16), 0x3B, 0, 0x14);
193 }
194 }
195 initSpriteDrawer(&sprite);
196 if (screen->ready) {
197 if (GFX.funcs.getTime() - screen->time >= 4) {
198 screen->time = GFX.funcs.getTime();
199 screen->cursorFrame++;
200 if (screen->cursorFrame >= 4) {
201 screen->cursorFrame = 0;
202 }
203 screen->homeFrame++;
204 if (screen->homeFrame >= 3) {
205 screen->homeFrame = 0;
206 }
207 }
208 sprite.setTexture(0x300, 0x100);
209 if (screen->hovering) {
210 sprite.setLayerId(screen->layer, screen->depth);
211 sprite.draw(FILE_CACHE.getEntry(screen->archive2), STSTATUS_cursorFrames[screen->cursorFrame] + 0x38,
212 STSTATUS_data.spots[screen->spot].x + 0xC + screen->scrollX,
213 STSTATUS_data.spots[screen->spot].y + 0xC + screen->scrollY + screen->top);
214 } else {
215 sprite.setLayerId(screen->layer, screen->depth - 1);
216 sprite.draw(FILE_CACHE.getEntry(screen->archive2), STSTATUS_cursorFrames[screen->cursorFrame] + 0x32,
217 screen->cursorX, screen->cursorY + screen->top);
218 }
219 sprite.setLayerId(screen->layer, screen->depth - 2);
220#if VERSION_EU || VERSION_JP
221 if (screen->hovering) {
222 x = screen->hoverX;
223 } else {
224 x = screen->cursorX;
225 }
226 /* the home mark faces the cursor */
227 frame = 0x3B;
228 if (x < screen->homeX + screen->scrollX) {
229 frame = 0x35;
230 }
231#else
232 frame = 0x35;
233#endif
234 sprite.draw(FILE_CACHE.getEntry(screen->archive2), frame + screen->homeFrame, screen->homeX + screen->scrollX,
235 screen->homeY + screen->scrollY + screen->top);
236 }
237 sprite.setLayerId(screen->layer, screen->depth - 1);
238 if (screen->ready) {
239 sprite.setTexture(0x300, 0x100);
240 for (i = 1; i < 47; i++) {
241 if (screen->visited[i - 1]) {
243 STSTATUS_data.spots[i].x + screen->scrollX,
244 STSTATUS_data.spots[i].y + screen->scrollY + screen->top);
245 }
246 }
247 }
248 sprite.setLayerId(screen->layer, screen->depth + 1);
249 towns = STSTATUS_data.funcs.getList(screen->gameHalf, screen->progress);
251 screen->progress = 0;
252 } else if (GAME.progress < STORY_DE_SINCERITY) {
253 screen->progress = 1;
254 } else if (GAME.progress < STORY_JUNGLE_SOUND) {
255 screen->progress = 2;
256 } else if (GAME.progress < STORY_DE_KNOWLEDGE) {
257 screen->progress = 3;
258 } else {
259 screen->progress = 4;
260 }
261 sprite.setTexture(0x380, 0x100);
262 /* the match depends on indexing the list rather than walking a pointer */
263 for (i = 0; towns[i] != 0; i++) {
264 sprite.draw(FILE_CACHE.getEntry(screen->archive1), towns[i] - 1, STSTATUS_data.towns[towns[i]].x + screen->scrollX,
265 STSTATUS_data.towns[towns[i]].y + screen->scrollY + screen->top);
266 }
267 sprite.setTexture(0x280, 0);
268 sprite.setAltClut(0x140, 0x100);
269 sprite.draw(FILE_CACHE.getEntry(screen->archive), 0, screen->scrollX, screen->scrollY + screen->top);
270}
271
272/* The map screen's update */
274 s32 area;
275
276 switch (screen->state) {
277 case TASK_INIT:
278 default:
279 switch (screen->substate) {
280 case 0:
281 default:
282 if (FILE_CACHE.isLoading(screen->textFile) == 0) {
283 screen->substate++;
284 }
285 break;
286 case 1:
287 windows[0] = createTextWindow(screen->layer, 1, 0x14, 0x16);
288 windows[0]->setLines(windows[0], 2);
289 screen->fade.duration = 10;
291 area = STSTATUS_areaFuncs.getArea() + 1;
292 screen->homeX = STSTATUS_data.spots[area].x + 0xC;
293 screen->homeY = STSTATUS_data.spots[area].y + 0xC;
294 screen->speedX = 1;
295 screen->speedY = 1;
296 while (screen->homeX + screen->scrollX != screen->cursorX) {
297 STSTATUS_moveMapCursor(screen, 1, 0);
298 }
299 while (screen->homeY + screen->scrollY != screen->cursorY) {
300 STSTATUS_moveMapCursor(screen, 0, 1);
301 }
302 screen->speedX = 0;
303 screen->speedY = 0;
304 screen->ready = 1;
305 screen->nextState(screen);
306 break;
307 }
308 break;
309 case TASK_RUN:
310 STSTATUS_runMapScreen(screen, windows);
311 STSTATUS_showMapArea(screen, windows);
313 break;
314 case TASK_DONE:
315 case TASK_KILL:
316 break;
317 }
318}
319
320/* Creates the map screen (task): the map of the first half of the game or, in the
321 late game, of the second (FILE_STATUS_BG + 2), and requests its area names */
324
325 screen->layer = SCREEN_LAYER;
326 screen->depth = 5;
327 screen->menu = menu;
329 if (screen->gameHalf == 0) {
330 screen->archive = FILE_STATUS_BG << 16;
331 screen->archive1 = (FILE_STATUS_BG << 16) + 1;
332 screen->archive2 = (FILE_STATUS_BG << 16) + 2;
334 screen->file = FILE_STATUS_BG;
335 } else {
336 screen->archive = (FILE_STATUS_BG + 2) << 16;
337 screen->archive1 = ((FILE_STATUS_BG + 2) << 16) + 1;
338 screen->archive2 = ((FILE_STATUS_BG + 2) << 16) + 2;
340 screen->file = FILE_STATUS_BG + 2;
341 }
342 FILE_CACHE.request(screen->textFile);
343 screen->height = 0xF0;
344 screen->top = 0x10;
345 return (Task *)screen;
346}
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
STSTATUS.PRO: the field menu's screens.
#define FILE_STATUS_SPRITES
The menu's sprite sheet; the next file is its texture archive.
Definition field_menu.h:20
#define FILE_STATUS_BG
Definition field_menu.h:21
#define TEXT_ASUKA_MAP
ASKMAP: the map screen's before.
Definition file.h:201
#define TEXT_FILE(file)
Definition file.h:190
#define TEXT_AMATERASU_MAP
The text files, by their USA disc names (US<name>.BIN), for TEXT_FILE()
Definition file.h:200
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
s32 STSTATUS_cursorFrames[]
The map cursor's frames.
Definition helpers.c:210
StatusAreaFuncs STSTATUS_areaFuncs
Where the game is.
Definition helpers.c:410
StatusData STSTATUS_data
Definition helpers.c:356
void STSTATUS_updateMapScreen(StatusMapScreen *screen, TextWindow **windows)
The map screen's update.
Definition map_screen.c:273
void STSTATUS_moveMapCursor(StatusMapScreen *screen, s32 dx, s32 dy)
Moves the cursor, or the map when the cursor is in the middle.
Definition map_screen.c:53
void STSTATUS_runMapScreen(StatusMapScreen *screen, TextWindow **windows)
Moves the cursor faster while the pad is held; triangle closes.
Definition map_screen.c:134
Task * STSTATUS_createMapScreen(FieldMenuScreen *menu, s32 extra)
Creates the map screen (task): the map of the first half of the game or, in the late game,...
Definition map_screen.c:322
void STSTATUS_showMapArea(StatusMapScreen *screen, TextWindow **windows)
Finds the area under the cursor and shows its name.
Definition map_screen.c:7
void STSTATUS_drawMapScreen(StatusMapScreen *screen)
Draws the map, the visited areas, the towns and the cursor.
Definition map_screen.c:176
#define PAD_DOWN
Definition pad.h:24
#define PAD_RIGHT
Definition pad.h:23
#define PAD_TRIANGLE
Definition pad.h:32
#define PAD_PRESSED(button)
One button of pad 1: newly pressed, auto-repeated while held, or held.
Definition pad.h:140
#define PAD_UP
Definition pad.h:22
#define PAD_LEFT
Definition pad.h:25
#define PAD_HELD(button)
Definition pad.h:142
#define PAD_REPEATED(button)
Definition pad.h:141
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...
@ STORY_JUNGLE_SOUND
WSTAG545 (Bug Maze Pit), event 711: Patamon heard a weird sound from the jungle, where its leader wen...
Definition story.h:106
@ STORY_SOUTH_STATION_GHOST
WSTAG440 (South Station), event 152: a ghost's voice in the empty station.
Definition story.h:45
@ STORY_DE_KNOWLEDGE
WSTAG526 (Zhu Que UG Lake), event 760: the fight with Zanbamon (the DE Knowledge)
Definition story.h:115
@ STORY_DE_SINCERITY
WSTAG460 (Reliability Spot), event 370: the Qing Long Chief, asked for the Digi-Egg of Knowledge,...
Definition story.h:70
The mode's main task (STSTATUS_createMenu)
Definition field_menu.h:25
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
s32(* getTime)(void)
Definition gfx.h:31
GfxFuncs funcs
Definition gfx.h:77
s32 duration
Definition menu.h:19
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(* setAltClut)()
(x, y)
Definition gfx.h:243
void(* setLayerId)()
(id, depth)
Definition gfx.h:244
void(* draw)()
(sheet, frame, x, y)
Definition gfx.h:246
void(* setTexture)()
(x, y)
Definition gfx.h:242
s32(* getGameHalf)(void)
0, 1, or -1 outside of the field
Definition field_menu.h:287
s32(* getArea)(void)
Definition field_menu.h:288
void(* getVisitedAreas)(s32 *out)
Definition field_menu.h:289
StatusMapPoint * towns
from 1
Definition field_menu.h:440
StatusMapSpot * spots
the map's areas, from 1
Definition field_menu.h:439
StatusFuncs funcs
Definition field_menu.h:445
s32 *(* getList)(s32 list, s32 index)
Definition field_menu.h:279
The map screen (STSTATUS_createMapScreen); the offsets are the European version's,...
Definition field_menu.h:305
s32 homeX
the current area's mark
Definition field_menu.h:326
void(* nextState)(struct StatusMapScreen *task)
Definition field_menu.h:306
s32 file
FILE_STATUS_BG or the next one but one.
Definition field_menu.h:316
s32 archive
entries of file: the map
Definition field_menu.h:320
PanelAnim fade
Definition field_menu.h:344
s32 archive1
the towns
Definition field_menu.h:321
s32 hoverX
where the cursor was when it got there
Definition field_menu.h:341
s32 top
where the map starts
Definition field_menu.h:311
s32 archive2
the marks
Definition field_menu.h:322
FieldMenuScreen * menu
Definition field_menu.h:307
s32 spot
the area under the cursor
Definition field_menu.h:339
s32 visited[47]
the areas, spot i at i - 1
Definition field_menu.h:330
s32 progress
which towns are drawn
Definition field_menu.h:319
An area on the map screen.
Definition field_menu.h:423
Any task, seen through its header.
Definition task.h:62
A text window (createTextWindow): up to six text buffers (0 is shown, 1-5 are "work" buffers that con...
Definition text.h:131
void(* setLines)()
no prototype: callers would truncate u8 args
Definition text.h:184
void(* setPos)(struct TextWindow *obj, s16 x, s16 y)
Definition text.h:173
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)