Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
map_objects.c
Go to the documentation of this file.
1/* The map's objects: animated, drawn and found by their animation */
2
3#include "field/field_mode.h"
4
5/* The layer's sorted callback that draws a map object */
6void FIELDSTG_drawMapObject(MapObjects *task, Layer *layer, s32 index) {
7 StageTile *object = &task->objects[index];
8 SpriteDrawer sprite;
9
10 if (task->state == TASK_RUN) {
11 initSpriteDrawer(&sprite);
13 sprite.setLayer(layer, object->depth);
14 if (object->anim != 0xFF) {
16 sprite.setClutRow(object->clutRow);
17 if (FIELDSTG_state.spriteColor.cd != 0) {
19 }
20 sprite.draw(FILE_CACHE.getEntry(task->sprites), object->frame, object->x, object->y);
21 } else {
23 sprite.setClutRow(object->clutRow);
24 sprite.draw(FILE_CACHE.getEntry(FIELD_SPRITES_FILE << 16), object->frame, object->x, object->y);
25 }
26 }
27}
28
29/* Animates and draws the map's objects that are in view */
31 StageTile *object;
32 StageTile *entry;
33 Layer *layer;
34 SpriteDrawer sprite;
35 RECT view;
36 s32 count;
37 s32 i;
38 s32 x;
39 s32 y;
40 u8 margin;
41 s32 back;
42
43 switch (task->state) {
44 case TASK_INIT:
45 default:
46 count = 0;
47 for (entry = task->objects; entry->y != 0; entry++) {
48 if (entry->anim == 0xFF) {
49 count++;
50 }
51 }
52 if (count != 0) {
53 *children = FIELDSTG_createHiddenSpots(count);
54 }
55 task->nextState(task);
56 break;
57 case TASK_RUN:
58 object = task->objects;
60 layer->getViewRect(layer, &view);
61 initSpriteDrawer(&sprite);
64 for (i = 0; object->margin != 0; object++, i++) {
65 if (object->visible == 0) {
66 continue;
67 }
68 x = object->anim == 0xFF ? object->x - 50 : object->x;
69 y = object->anim == 0xFF ? object->y - 100 : object->y;
70 margin = object->margin;
71 if (x >= view.x - margin && view.x + view.w >= x && y >= view.y - margin && view.y + view.h >= y) {
72 switch (object->cycle) {
73 case 1:
74 if (object->cycleTime < 0x100) {
75 object->frame++;
76 if (object->frame > object->cycleLast) {
77 object->frame = object->cycleFirst;
78 }
79 object->cycleTime = object->cycleDelay << 8;
80 } else {
81 object->cycleTime -= 0x100;
82 }
83 break;
84 case 2:
85 if (object->cycleTime < 0x100) {
86 object->clutRow++;
87 if (object->clutRow > object->cycleLast) {
88 object->clutRow = object->cycleFirst;
89 }
90 object->cycleTime = object->cycleDelay << 8;
91 } else {
92 object->cycleTime -= 0x100;
93 }
94 break;
95 case 3:
96 if (object->cycleTime & 0x8000) {
97 back = 0x8000;
98 object->cycleTime &= 0x7FFF;
99 if (object->cycleTime < 0x100) {
100 object->clutRow--;
101 object->cycleTime = object->cycleDelay << 8;
102 if (object->clutRow == (u8)(object->cycleFirst - 1)) {
103 object->clutRow = object->cycleFirst + 1;
104 back = 0;
105 }
106 } else {
107 object->cycleTime -= 0x100;
108 }
109 object->cycleTime |= back;
110 } else if (object->cycleTime < 0x100) {
111 object->clutRow++;
112 object->cycleTime = object->cycleDelay << 8;
113 if (object->clutRow == object->cycleLast + 1) {
114 object->clutRow = object->cycleLast - 1;
115 object->cycleTime |= 0x8000;
116 }
117 } else {
118 object->cycleTime -= 0x100;
119 }
120 break;
121 }
122 if (object->sortY != 0) {
123 layer->addSortedCallback(layer, FIELDSTG_drawMapObject, task, object->sortY, i);
124 } else {
125 sprite.setLayerId(FIELD_LAYER_MAP, object->depth);
126 sprite.setClutRow(object->clutRow);
127 if (FIELDSTG_state.spriteColor.cd != 0) {
129 }
130 sprite.draw(FILE_CACHE.getEntry(task->sprites), object->frame, object->x, object->y);
131 }
132 }
133 }
134 break;
135 case TASK_DONE:
136 case TASK_KILL:
137 break;
138 }
139}
140
141/* Creates the map's objects, with their sprites */
144
145 task->objects = objects;
146 task->sprites = sprites;
147 return task;
148}
149
150/* The next map object of the animation FIELDSTG_findObject looks for, or
151 NULL */
154 s32 found = 0;
155
156 for (; entry->margin != 0; entry++) {
157 if (entry->anim == FIELDSTG_objectId) {
158 found = 1;
159 break;
160 }
161 }
162 FIELDSTG_objectCursor = entry + 1;
163 if (found) {
164 return entry;
165 }
166 return NULL;
167}
168
169/* The first map object of an animation, or NULL (FIELDSTG_findNextObject
170 goes on) */
#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
#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
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 FIELD_OBJECTS_CLUT_Y
Definition field_mode.h:32
#define FIELD_SPRITES_Y
Definition field_mode.h:29
#define FIELD_OBJECTS_Y
Definition field_mode.h:31
#define FIELD_OBJECTS_X
Definition field_mode.h:30
StageTile * FIELDSTG_objectCursor
FIELDSTG_findNextObject's search of the map objects.
Definition fieldstg.c:3756
s32 FIELDSTG_objectId
and the id it looks for
Definition fieldstg.c:3757
FieldState FIELDSTG_state
Definition fieldstg.c:2641
FileCache FILE_CACHE
The file cache.
Definition file_cache.c:7
HiddenSpots * FIELDSTG_createHiddenSpots(s32 count)
Creates the hidden spots, the map objects of animation 0xFF, and hides the prize in one (or where it ...
MapObjects * FIELDSTG_createMapObjects(s32 sprites, StageTile *objects)
Creates the map's objects, with their sprites.
StageTile * FIELDSTG_findNextObject(void)
The next map object of the animation FIELDSTG_findObject looks for, or NULL.
void FIELDSTG_updateMapObjects(MapObjects *task, HiddenSpots **children)
Animates and draws the map's objects that are in view.
Definition map_objects.c:30
void FIELDSTG_drawMapObject(MapObjects *task, Layer *layer, s32 index)
The layer's sorted callback that draws a map object.
Definition map_objects.c:6
StageTile * FIELDSTG_findObject(s32 anim)
The first map object of an animation, or NULL (FIELDSTG_findNextObject goes on)
void initSpriteDrawer(SpriteDrawer *obj)
Clears a sprite drawer to neutral (no scale, gray tint, follows the scroll), gives it its methods and...
StageTile * objects
the map objects, up to the first margin 0
Definition field_map.h:446
CVECTOR spriteColor
the field's sprites' color, unless cd is 0
Definition field_map.h:458
void *(* getEntry)(u32 fileAndIndex)
Definition file.h:96
struct Layer *(* getLayer)(s32 id)
Definition gfx.h:28
GfxFuncs funcs
Definition gfx.h:77
The map's hidden spots (FIELD_TASK_HIDDEN_SPOTS, FIELDSTG_createHiddenSpots): one of them,...
Definition field_mode.h:558
A drawing layer (GFX.funcs.createLayer): a DRAWENV with a pair of ordering tables,...
Definition gfx.h:128
void(* addSortedCallback)()
Definition gfx.h:160
void(* getViewRect)()
Definition gfx.h:151
Animates and draws the map's objects (FIELDSTG_createMapObjects)
Definition field_mode.h:508
struct StageTile * objects
Definition field_mode.h:511
void(* nextState)(struct MapObjects *task)
Definition field_mode.h:509
s32 sprites
their sprite file and entry
Definition field_mode.h:510
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(* setLayer)()
(layer, depth)
Definition gfx.h:245
void(* setColor)()
(CVECTOR *)
Definition gfx.h:252
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
An object of a map, which FIELDSTG draws: a record of the table at FieldState.objects,...
Definition field_map.h:208
u8 margin
how far off the view it is still drawn; 0 ends the table
Definition field_map.h:214
s16 cycleTime
in 1/256 frames; bit 15: going back
Definition field_map.h:225
u8 anim
which of a stage's animations sets frame (1-3); FIELDSTG finds objects by it (its lift,...
Definition field_map.h:210
u8 cycle
1 cycles the frame, 2 the CLUT row, 3 the row back and forth
Definition field_map.h:217
u8 cycleFirst
Definition field_map.h:218
s16 sortY
drawn sorted at this y, or 0
Definition field_map.h:224
void * createTask(void(*update)(), s32 size, s32 childrenSize)
createTaskWithId for a task nothing needs to find
Definition task.c:105