Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
map.c
Go to the documentation of this file.
1/* FieldMap's methods: the cells of the map's levels, the free tiles and the
2 steps of a walk or a flight */
3
4#include "field/field_mode.h"
5
6/* Part i of a map file, at the offset from its start that its word i holds */
7#define MAP_PART(entry, i) ((void *)((entry)[i] + (s32)(entry)))
8
9/*
10 * Points the map at the file of map index: the grid, whose first two bytes
11 * are its width and height, the levels of cells and the pixels, at the
12 * offsets the file's entry starts with. Returns 0 when no file is set. The
13 * match depends on the file's check being an early exit, a do-while (0)
14 * that breaks once the file is set, with file declared in it: the block's
15 * note stops stmt.c from rolling the exit test to the loop's end, and the
16 * loop notes keep the prologue's stores of ra and s0 ahead of the load in
17 * the second scheduler.
18 */
20 s32 *entry;
21 u8 *grid;
22
23 do {
24 s32 file = FIELDSTG_map.files[index];
25
26 if (file != 0) {
27 break;
28 }
29 return 0;
30 } while (0);
31 entry = FILE_CACHE.getEntry(FIELDSTG_map.files[index]);
32 FIELDSTG_map.grid = MAP_PART(entry, 0);
33 FIELDSTG_map.cells64 = MAP_PART(entry, 1);
34 FIELDSTG_map.cells32 = MAP_PART(entry, 2);
35 FIELDSTG_map.cells16 = MAP_PART(entry, 3);
36 FIELDSTG_map.cells8 = MAP_PART(entry, 4);
37 FIELDSTG_map.pixels = MAP_PART(entry, 5);
38 grid = FIELDSTG_map.grid;
39 FIELDSTG_map.width = grid[0];
40 FIELDSTG_map.height = grid[1];
41 FIELDSTG_map.grid = grid + 2;
42 return 1;
43}
44
45/* Sets the file of map index (FieldMap.setFile) */
46void FIELDSTG_setMapFile(s32 index, s32 value) {
47 FIELDSTG_map.files[index] = value;
48}
49
50/* Puts the player on map index when the mode is new (FieldMap.setFirstMap) */
52 if (GAME.clearTempFlags != 0) {
53 GAME.mapIndex = index;
54 }
55}
56
57/* Puts the player on map index (FieldMap.setMap) */
58void FIELDSTG_setMap(s32 index) {
59 GAME.mapIndex = index;
60}
61
62/* The cell of map index at pos, down the tree from the grid to the pixel
63 (FieldMap.getCell); 1 without a file */
65 s32 x;
66 s32 y;
67 s32 i;
68
69 if (FIELDSTG_selectMap(index) == 0) {
70 return 1;
71 }
72 y = pos->y;
73 x = pos->x;
74 /* the match depends on the * 4 being a statement of its own */
75 i = FIELDSTG_map.grid[y / 128 * FIELDSTG_map.width + x / 128];
76 i *= 4;
77 if (y & 0x40) {
78 i += 2;
79 }
80 i = FIELDSTG_map.cells64[(x & 0x40) ? i + 1 : i];
81 i *= 4;
82 if (y & 0x20) {
83 i += 2;
84 }
85 i = FIELDSTG_map.cells32[(x & 0x20) ? i + 1 : i];
86 i *= 4;
87 if (y & 0x10) {
88 i += 2;
89 }
90 i = FIELDSTG_map.cells16[(x & 0x10) ? i + 1 : i];
91 i *= 4;
92 if (y & 8) {
93 i += 2;
94 }
95 i = FIELDSTG_map.cells8[(x & 8) ? i + 1 : i];
96 return FIELDSTG_map.pixels[i * 64 + (y & 7) * 8 + (x & 7)];
97}
98
99/* Whether nothing stands at pos: no character's box (gathered once a frame)
100 and no object. The match depends on the two widths, the gathered box's and
101 the tested one's, being variables of their own: one width for both blocks
102 gives GCC 2.8.1 other registers. */
104 s32 frame = GFX.funcs.getFrameCount();
105 Actor *actor;
106 s32 i;
107
108 if (frame != FIELDSTG_boxFrame) {
110 for (i = 0; actor != NULL; i++) {
111 s32 width = actor->halfWidth;
112
113 FIELDSTG_boxes[i].left = actor->tile.x - width;
114 FIELDSTG_boxes[i].right = actor->tile.x + width;
115 width /= 2;
116 FIELDSTG_boxes[i].top = actor->tile.y - width;
117 FIELDSTG_boxes[i].bottom = actor->tile.y + width;
118 actor = TASK_REGISTRY.funcs.findNext();
119 }
121 FIELDSTG_boxFrame = frame;
122 }
123 for (i = 0; i < FIELDSTG_boxCount; i++) {
124 if (pos->x >= FIELDSTG_boxes[i].left && FIELDSTG_boxes[i].right >= pos->x && pos->y >= FIELDSTG_boxes[i].top
125 && FIELDSTG_boxes[i].bottom >= pos->y) {
126 s32 dx = pos->x - FIELDSTG_boxes[i].left;
127 s32 dy = pos->y - FIELDSTG_boxes[i].top;
129 s32 height = FIELDSTG_boxes[i].bottom - FIELDSTG_boxes[i].top;
130 s32 halfWidth = width / 2;
131 s32 halfHeight = height / 2;
132 s32 ratio = width / height;
133
134 if (halfWidth < dx) {
135 dx = halfWidth - (dx - halfWidth);
136 }
137 if (halfHeight < dy) {
138 dy = halfHeight - (dy - halfHeight);
139 }
140 if (dx >= halfWidth - dy * ratio) {
141 return 0;
142 }
143 }
144 }
145 return FIELDSTG_findHiddenSpot(pos, 0) == NULL;
146}
147
148/* A step of scale in a direction on the map the player is on, along the
149 slope of its cell (FieldMap.getWalkStep) */
150void FIELDSTG_getWalkStep(Vec2 *pos, s32 scale, s32 dir, Vec2 *out) {
151 s32 cell = (u8)FIELDSTG_getMapCell(GAME.mapIndex, pos);
152 s32 row = cell & 0xF;
153 s32 slopeDir;
154 s32 sign;
155
156 row -= row != 0;
157 slopeDir = (cell & 0x10) ? FIELDSTG_mirrorDirs[dir] : dir;
158 sign = (cell & 0x10) ? -1 : 1;
159 out->x = FIELDSTG_dirVectors[row][slopeDir].x * scale * sign / 4096;
160 out->y = FIELDSTG_dirVectors[row][slopeDir].y * scale / 4096;
161}
162
163/* A step of scale in a direction, on the flat (FieldMap.getFlyStep) */
164void FIELDSTG_getFlyStep(Vec2 *pos, s32 scale, s32 dir, Vec2 *out) {
165 out->x = FIELDSTG_dirVectors[0][dir].x * scale / 4096;
166 out->y = FIELDSTG_dirVectors[0][dir].y * scale / 4096;
167}
#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 FIELD_TASK_ACTOR
every character (FIELDSTG_createActor)
Definition field_map.h:26
FIELDSTG.PRO: the field mode, where the player walks around the map.
FieldMap FIELDSTG_map
Definition fieldstg.c:3660
s32 FIELDSTG_boxCount
and their number
Definition fieldstg.c:3771
u8 FIELDSTG_mirrorDirs[]
Definition fieldstg.c:3751
s32 FIELDSTG_boxFrame
the frame FIELDSTG_boxes was filled in
Definition fieldstg.c:3678
Box FIELDSTG_boxes[20]
the characters' boxes (FIELDSTG_isTileFree)
Definition fieldstg.c:3770
Vec2 FIELDSTG_dirVectors[][8]
a direction's vector, scaled by 4096
Definition fieldstg.c:3679
FileCache FILE_CACHE
The file cache.
Definition file_cache.c:7
HiddenSpots * FIELDSTG_findHiddenSpot(Vec2 *pos, s32 select)
The hidden spots, when one is within 10 pixels of pos (selecting it if select), or NULL.
#define MAP_PART(entry, i)
Part i of a map file, at the offset from its start that its word i holds.
Definition map.c:7
void FIELDSTG_setMapFile(s32 index, s32 value)
Sets the file of map index (FieldMap.setFile)
Definition map.c:46
s32 FIELDSTG_isTileFree(Vec2 *pos)
Whether nothing stands at pos: no character's box (gathered once a frame) and no object.
Definition map.c:103
void FIELDSTG_setFirstMap(s32 index)
Puts the player on map index when the mode is new (FieldMap.setFirstMap)
Definition map.c:51
void FIELDSTG_getWalkStep(Vec2 *pos, s32 scale, s32 dir, Vec2 *out)
A step of scale in a direction on the map the player is on, along the slope of its cell (FieldMap....
Definition map.c:150
s32 FIELDSTG_selectMap(s32 index)
Points the map at the file of map index: the grid, whose first two bytes are its width and height,...
Definition map.c:19
void FIELDSTG_getFlyStep(Vec2 *pos, s32 scale, s32 dir, Vec2 *out)
A step of scale in a direction, on the flat (FieldMap.getFlyStep)
Definition map.c:164
s32 FIELDSTG_getMapCell(s32 index, Vec2 *pos)
The cell of map index at pos, down the tree from the grid to the pixel (FieldMap.getCell); 1 without ...
Definition map.c:64
void FIELDSTG_setMap(s32 index)
Puts the player on map index (FieldMap.setMap)
Definition map.c:58
TaskRegistry TASK_REGISTRY
Definition registry.c:122
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 halfWidth
half its width (FIELDSTG_actorWidths): its box's half width, and half that its half height
Definition field_map.h:346
s32 left
Definition field_mode.h:404
s32 bottom
Definition field_mode.h:407
s32 top
Definition field_mode.h:406
s32 right
Definition field_mode.h:405
s16 * cells16
Definition field_map.h:97
s32 files[8]
the file entry of each map, set by setFile
Definition field_map.h:91
u8 * grid
Definition field_map.h:94
u8 * pixels
Definition field_map.h:99
s32 width
of the grid, in cells
Definition field_map.h:92
s16 * cells8
Definition field_map.h:98
s32 height
Definition field_map.h:93
u8 * cells64
Definition field_map.h:95
s16 * cells32
Definition field_map.h:96
void *(* getEntry)(u32 fileAndIndex)
Definition file.h:96
s32 clearTempFlags
Definition game_state.h:573
s32(* getFrameCount)(void)
Definition gfx.h:30
GfxFuncs funcs
Definition gfx.h:77
void *(* findNext)(void)
Definition task.h:19
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