Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
hidden_spots.c
Go to the documentation of this file.
1/* The map's hidden spots, one of which holds a prize, and their effects */
2
3#include "field/field_mode.h"
4
5/* The hint after a search without the prize: a sprite that flashes faster
6 the closer the prize is */
8 SpriteDrawer sprite;
9 s32 dx;
10 s32 dy;
11 void *sprites;
12
13 switch (task->state) {
14 default:
15 case TASK_INIT:
16 dx = task->from.x - task->to.x;
17 if (dx < 0) {
18 dx = -dx;
19 }
20 dy = task->from.y - task->to.y;
21 if (dy < 0) {
22 dy = -dy;
23 }
24 if (dx < 0x80 && dy < 0x80) {
25 task->speed = 3;
26 task->frame = 0x52;
27 } else if (dx < 0x100 && dy < 0x100) {
28 task->speed = 6;
29 task->frame = 0x51;
30 } else {
31 task->speed = 0xC;
32 task->frame = 0x50;
33 }
34 task->nextState(task);
35 /* fallthrough */
36 case TASK_RUN:
37 sprites = FILE_CACHE.getEntry(FIELD_SPRITES_FILE << 16 | 1);
38 initSpriteDrawer(&sprite);
39 sprite.setLayerId(FIELD_LAYER_MAP, 0);
41 sprite.setFollowScroll(0);
42 sprite.setClutRow(task->time / task->speed % 10);
43 sprite.draw(sprites, task->frame, 0xF8, 0xA8);
44 sprite.draw(sprites, 0x4F, 0xF8, 0xA8);
45 task->time += GFX.funcs.getFrameTime();
46 if (task->time >= 0x78) {
47 task->setState(task, TASK_KILL);
48 }
49 break;
50 case TASK_DONE:
51 case TASK_KILL:
52 break;
53 }
54}
55
56/* Creates the hint for a search at to, from the prize at from */
59
60 task->from = from;
61 task->to = to;
62 return task;
63}
64
65/* Hides the prize in one of the hidden spots at random (GAME.prizeSpot keeps
66 it) */
68 s32 index = RANDOM.next() % task->count;
69
70 GAME.prizeSpot = index;
71 task->entries[index].hasPrize = 1;
72 task->pos = task->entries[index].pos;
73}
74
75/* The hidden spots' update: a search plays its effect, then starts a battle
76 where the prize is (and hides it again) or shows a hint, and animates the
77 searched spot's object */
79 StageTile *objects;
80 s32 step;
81 s32 time;
82 s32 i;
83
84 switch (task->state) {
85 default:
86 case TASK_INIT:
88 task->nextState(task);
89 break;
90 case TASK_RUN:
91 break;
92 case TASK_DONE:
93 if (task->substate == 0) {
94 children->effect = FIELDSTG_createSpotEffect(task->forEvent);
95 task->nextSubstate(task);
96 } else if (task->substate != 0x80) {
97 if (task->substate < 0x14) {
98 task->substate = task->substate + GFX.funcs.getFrameTime() + 1;
99 } else {
100 if (task->forEvent == 0) {
101 if (task->entries[task->selected].hasPrize != 0) {
102 if ((RANDOM.next() & 0x7F) < 0x66) {
104 } else {
106 }
107 FIELDSTG_hidePrize(task);
108 } else {
109 if (children->hint != NULL) {
110 children->hint->destroy(children->hint);
111 }
112 children->hint = FIELDSTG_createSpotHint(task->pos, task->entries[task->selected].pos);
113 }
114 }
115 task->setSubstate(task, 0x80);
116 }
117 }
118 step = task->step;
119 time = task->counter;
120 time += GFX.funcs.getFrameTime();
121 if (FIELDSTG_spotAnim[step][1] < time) {
122 time -= FIELDSTG_spotAnim[step][1];
123 step++;
124 if (FIELDSTG_spotAnim[step][0] == 0xFF) {
125 task->setState(task, TASK_RUN);
126 return;
127 }
128 task->entries[task->selected].frame = FIELDSTG_spotAnim[step][0];
129 task->step = step;
130 }
131 task->counter = time;
132 objects = FIELDSTG_state.objects;
133 for (i = 0; i < task->count; i++) {
134 if (task->entries[i].frame != 0) {
135 if (task->selected == i) {
136 objects[task->entries[i].object].frame = task->entries[i].frame;
137 } else {
138 objects[task->entries[i].object].frame = 0x38;
139 }
140 }
141 }
142 break;
143 case TASK_KILL:
144 if (task->entries != NULL) {
145 HEAP.free(task->entries);
146 }
147 break;
148 }
149}
150
151/* Creates the hidden spots, the map objects of animation 0xFF, and hides the
152 prize in one (or where it was, in the same mode) */
155 StageTile *object;
156 s32 i;
157 s32 n;
158 s32 index;
159
160 task->count = count;
161 object = FIELDSTG_state.objects;
162 task->entries = HEAP.alloc(count * sizeof(HiddenSpot), 2);
163 i = 0;
164 n = 0;
165 for (; object->y != 0; object++, i++) {
166 if (object->anim == 0xFF) {
167 task->entries[n].pos.x = object->x;
168 task->entries[n].pos.y = object->y;
169 task->entries[n].object = i;
170 task->entries[n].frame = 0x38;
171 task->entries[n].hasPrize = 0;
172 n++;
173 }
174 }
175 if (n != 0) {
176 if (GAME.clearTempFlags != 0) {
177 FIELDSTG_hidePrize(task);
178 } else {
179 index = GAME.prizeSpot;
180 task->entries[index].hasPrize = 1;
181 task->pos = task->entries[index].pos;
182 }
183 }
184 return task;
185}
186
187/* The hidden spots, when one is within 10 pixels of pos (selecting it if
188 select), or NULL */
191 s32 i;
192
193 if (task != NULL) {
194 for (i = 0; i < task->count; i++) {
195 if (pos->x >= task->entries[i].pos.x - 10 && task->entries[i].pos.x + 10 >= pos->x
196 && pos->y >= task->entries[i].pos.y - 10 && task->entries[i].pos.y + 10 >= pos->y) {
197 if (select) {
198 task->selected = i;
199 task->forEvent = 0;
200 }
201 return task;
202 }
203 }
204 }
205 return NULL;
206}
207
208/* Searches the hidden spots off the map (x 1000 and up), for an event */
211 s32 i;
212
213 if (task != NULL) {
214 for (i = 0; i < task->count; i++) {
215 if (task->entries[i].pos.x >= 1000) {
216 task->selected = i;
217 task->forEvent = 1;
218 task->setState(task, TASK_DONE);
219 }
220 }
221 }
222}
223
224/* The layer's sorted callback that draws a search's effect */
226 SpriteDrawer sprite;
227
228 if (task->state == TASK_RUN) {
229 initSpriteDrawer(&sprite);
231 sprite.setLayer(layer, 4);
232 sprite.draw(FILE_CACHE.getEntry(FIELD_SPRITES_FILE << 16), task->frame, task->x, task->y);
233 }
234}
235
236/* A search's effect, over the player or, for an event, its actor 0x11B */
239 Actor *actor;
240 s32 step;
241 s32 time;
242 u8 *anim;
243
244 switch (task->state) {
245 default:
246 case TASK_INIT:
247 if (task->key1 != 0) {
248 actor = TASK_REGISTRY.funcs.find(FIELD_TASK_ACTOR, 0x11B, -1);
249 } else {
251 }
252 if (actor == NULL) {
253 break;
254 }
255 task->x = actor->tile.x;
256 task->y = actor->tile.y;
257 task->dir = actor->dir;
258 task->anim = FIELDSTG_dirAnims[task->dir];
259 task->nextState(task);
261 /* fallthrough */
262 case TASK_RUN:
263 step = task->step;
264 time = task->counter;
265 time += GFX.funcs.getFrameTime();
266 anim = task->anim;
267 if (anim[step * 2 + 1] < time) {
268 time -= anim[step * 2 + 1];
269 step++;
270 if (anim[step * 2] == 0xFF) {
271 task->setState(task, TASK_KILL);
272 break;
273 }
274 task->frame = anim[step * 2];
275 task->step = step;
276 }
277 task->counter = time;
278 if (task->frame != 0) {
279 layer->addSortedCallback(layer, FIELDSTG_drawSpotEffect, task, task->y + FIELDSTG_dirDepths[task->dir], 0);
280 }
281 break;
282 case TASK_DONE:
283 case TASK_KILL:
284 break;
285 }
286}
287
288/* Creates a search's effect, over the event's actor 0x11B if forEvent, else
289 over the player */
292
293 task->key1 = forEvent;
294 return task;
295}
#define NULL
Definition common.h:17
signed int s32
Definition common.h:11
unsigned char u8
Definition common.h:8
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 FIELD_LAYER_MAP
the map, its objects and characters, and the menus
Definition field_map.h:20
#define FIELD_TASK_ACTOR
every character (FIELDSTG_createActor)
Definition field_map.h:26
#define FIELD_TASK_HIDDEN_SPOTS
Definition field_map.h:29
FIELDSTG.PRO: the field mode, where the player walks around the map.
#define FIELD_SPRITES_X
Where the field keeps its textures in VRAM: the two images of FIELD_SPRITES_FILE (its entries 2 and 3...
Definition field_mode.h:27
#define FIELD_SPRITES_FILE
The field's effect sprites (FIELDSTG_drawSpotEffect): the discs number their files differently.
Definition field_mode.h:591
#define SOUND_PLAYER08
Definition field_mode.h:60
#define FIELD_SPRITES_Y
Definition field_mode.h:29
#define FIELD_SPRITES2_X
Definition field_mode.h:28
#define FIELD_SEARCH_FILE
the hidden spots'
Definition field_mode.h:603
u8 FIELDSTG_spotAnim[][2]
animation of FIELDSTG_updateHiddenSpots: (frame, time) pairs up to 0xFF
Definition fieldstg.c:1931
u8 * FIELDSTG_dirAnims[]
FIELDSTG_updateSpotEffect's animation for each direction.
Definition fieldstg.c:1980
FieldState FIELDSTG_state
Definition fieldstg.c:2641
s32 FIELDSTG_dirDepths[]
and its depth offset
Definition fieldstg.c:1984
FieldBattleFuncs FIELDSTG_battleFuncs
Definition fieldstg.c:3653
FileCache FILE_CACHE
The file cache.
Definition file_cache.c:7
Heap HEAP
The functions that return what a call left in v0 (allocMemHigh, findTask) and the ones that take othe...
Definition heap.c:184
SpotHint * FIELDSTG_createSpotHint(Vec2 from, Vec2 to)
Creates the hint for a search at to, from the prize at from.
void FIELDSTG_hidePrize(HiddenSpots *task)
Hides the prize in one of the hidden spots at random (GAME.prizeSpot keeps it)
HiddenSpots * FIELDSTG_findHiddenSpot(Vec2 *pos, s32 select)
The hidden spots, when one is within 10 pixels of pos (selecting it if select), or NULL.
void FIELDSTG_drawSpotEffect(SpotEffect *task, Layer *layer)
The layer's sorted callback that draws a search's effect.
HiddenSpots * FIELDSTG_createHiddenSpots(s32 count)
Creates the hidden spots, the map objects of animation 0xFF, and hides the prize in one (or where it ...
SpotEffect * FIELDSTG_createSpotEffect(s32 forEvent)
Creates a search's effect, over the event's actor 0x11B if forEvent, else over the player.
void FIELDSTG_showSpotHint(SpotHint *task)
The hint after a search without the prize: a sprite that flashes faster the closer the prize is.
Definition hidden_spots.c:7
void FIELDSTG_updateSpotEffect(SpotEffect *task)
A search's effect, over the player or, for an event, its actor 0x11B.
void FIELDSTG_searchEventSpot(void)
Searches the hidden spots off the map (x 1000 and up), for an event.
void FIELDSTG_updateHiddenSpots(HiddenSpots *task, HiddenSpotsChildren *children)
The hidden spots' update: a search plays its effect, then starts a battle where the prize is (and hid...
Random RANDOM
Definition random.c:533
TaskRegistry TASK_REGISTRY
Definition registry.c:122
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
void initSpriteDrawer(SpriteDrawer *obj)
Clears a sprite drawer to neutral (no scale, gray tint, follows the scroll), gives it its methods and...
A character on the field (FIELDSTG_createActor): the player (kind 0) and the other characters.
Definition field_map.h:334
Vec2 tile
Definition field_map.h:337
s32 dir
Definition field_map.h:338
void(* startEventBattle)(s32 index)
FIELDSTG_startEventBattle.
Definition field_map.h:502
StageTile * objects
the map objects, up to the first margin 0
Definition field_map.h:446
void(* request)(s32 file)
Definition file.h:90
void *(* getEntry)(u32 fileAndIndex)
Definition file.h:96
s32 clearTempFlags
Definition game_state.h:573
s32 prizeSpot
Definition game_state.h:578
s32(* getFrameTime)(void)
Definition gfx.h:32
struct Layer *(* getLayer)(s32 id)
Definition gfx.h:28
GfxFuncs funcs
Definition gfx.h:77
void *(* alloc)(s32 size, s32 tag)
Definition heap.h:29
void(* free)(void *ptr)
Definition heap.h:27
A hidden spot: a map object with anim 0xFF.
Definition field_mode.h:549
s32 frame
its object's
Definition field_mode.h:550
s32 hasPrize
the one picked at random (GAME.prizeSpot)
Definition field_mode.h:553
s32 object
its index in FieldState.objects
Definition field_mode.h:551
The children of an HiddenSpots.
Definition field_mode.h:568
struct SpotHint * hint
Definition field_mode.h:570
struct SpotEffect * effect
Definition field_mode.h:569
The map's hidden spots (FIELD_TASK_HIDDEN_SPOTS, FIELDSTG_createHiddenSpots): one of them,...
Definition field_mode.h:558
void(* setSubstate)(struct HiddenSpots *task, s32 substate)
Definition field_mode.h:559
void(* nextState)(struct HiddenSpots *task)
Definition field_mode.h:559
HiddenSpot * entries
Definition field_mode.h:561
s32 forEvent
an event's search, without the prize or a hint
Definition field_mode.h:563
Vec2 pos
the prize's
Definition field_mode.h:564
s32 selected
the spot searched
Definition field_mode.h:562
void(* setState)(struct HiddenSpots *task, s32 state)
Definition field_mode.h:559
void(* nextSubstate)(struct HiddenSpots *task)
Definition field_mode.h:559
A drawing layer (GFX.funcs.createLayer): a DRAWENV with a pair of ordering tables,...
Definition gfx.h:128
void(* addSortedCallback)()
Definition gfx.h:160
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
The effect of searching a hidden spot, in front of the actor that searches (FIELDSTG_createSpotEffect...
Definition field_mode.h:575
void(* setState)(struct SpotEffect *task, s32 state)
Definition field_mode.h:576
void(* nextState)(struct SpotEffect *task)
Definition field_mode.h:576
The hint of a hidden spot that held nothing (FIELDSTG_createSpotHint): its sprite and its palette cyc...
Definition field_mode.h:539
void(* nextState)(struct SpotHint *task)
Definition field_mode.h:540
void(* setState)(struct SpotHint *task, s32 state)
Definition field_mode.h:540
s32 speed
frames per palette step
Definition field_mode.h:542
void(* destroy)(struct SpotHint *task)
Definition field_mode.h:540
Vec2 from
Definition field_mode.h:544
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(* setLayer)()
(layer, depth)
Definition gfx.h:245
void(* setLayerId)()
(id, depth)
Definition gfx.h:244
void(* setFollowScroll)()
(on)
Definition gfx.h:251
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
An object of a map, which FIELDSTG draws: a record of the table at FieldState.objects,...
Definition field_map.h:208
u8 anim
which of a stage's animations sets frame (1-3); FIELDSTG finds objects by it (its lift,...
Definition field_map.h:210
void *(* find)(s32 id, s32 key1, s32 key2)
Definition task.h:18
TaskFuncs funcs
Definition task.h:76
Definition gfx.h:352
s32 y
Definition gfx.h:354
s32 x
Definition gfx.h:353
void * createTask(void(*update)(), s32 size, s32 childrenSize)
createTaskWithId for a task nothing needs to find
Definition task.c:105
void * createTaskWithId(void(*update)(), s32 size, s32 childrenSize, s32 id)
Allocates a zeroed task of size bytes (header included) with room for childrenSize / 4 child tasks.
Definition task.c:80