Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
trigger.c
Go to the documentation of this file.
1/* The map's triggers: exits, climbs, warps, slides and the other things the
2 player sets off on a cell. Their rodata, at 0x800825E0 (USA), starts
3 FIELDSTG.PRO's fifth object (see data/fieldstg.c). */
4
5#include "field/field_mode.h"
6
7/* Finds the slot under the player (FIELD_MAP_TRIGGERS); those up to SLOT_GAUGE
8 count only while the player faces them */
10 Actor *actor = task->actor;
11 Vec2 tile;
12 u32 cell;
13 s32 type;
14
15 tile = actor->tile;
17 if (cell == 0) {
18 return 0;
19 }
20 task->dir = cell >> 5;
21 task->index = cell & 0x1F;
22 task->entry = &task->entries[task->index];
23 type = task->entry->type;
24 switch (type) {
25 case SLOT_DEPTH:
26 case SLOT_MAP:
27 case SLOT_EVENT:
28 case SLOT_WARP1:
29 case SLOT_WARP0:
30 case SLOT_SLIDE:
31 case SLOT_STOP_SLIDE:
32 case SLOT_LAUNCH:
33 case SLOT_LAUNCH_OUT:
34 return 1;
35 }
36 return FIELDSTG_nearDirs[task->dir][actor->dir] != 0;
37}
38
39/* Acts at once on a slot that does (SLOT_DEPTH...), or shows the balloon of
40 one that waits for a button and returns 1; returns 0 when its conditions
41 don't hold */
43#if VERSION_EU || VERSION_JP
44 s32 arg;
45#endif
46
47 if (task->entry->conditions[0][0] != 0xFFFF
48 && FLAGS_00.checkCondition(task->entry->conditions[0][0], task->entry->conditions[0][1]) == 0) {
49 return 0;
50 }
51 if (task->entry->conditions[1][0] != 0xFFFF
52 && FLAGS_00.checkCondition(task->entry->conditions[1][0], task->entry->conditions[1][1]) == 0) {
53 return 0;
54 }
55 switch (task->entry->type) {
56 case SLOT_DEPTH:
57 task->actor->depth = task->entry->arg;
58 GAME.playerDepth = task->entry->arg;
59 return 0;
60 case SLOT_MAP:
62 return 0;
63 case SLOT_EVENT:
64 if (children->script == NULL) {
65 children->script = FIELDSTG_startEvent(task->entry->arg);
66 }
67 return 0;
68 case SLOT_SLIDE:
69 task->actor->startSlide(task->actor, task->dir);
70 return 0;
71 case SLOT_STOP_SLIDE:
72 task->actor->stopSlide(task->actor);
73 return 0;
74 case SLOT_LAUNCH:
75 task->actor->launch(task->actor, SLOT_DEST(task->entry));
76 return 0;
77 }
78#if VERSION_US
79 if (children->balloon != NULL) {
80 children->balloon->setState(children->balloon, TASK_RUN);
81 return 1;
82 }
83 switch (task->entry->type) {
84 default:
85 children->balloon = FIELDSTG_createBalloon(0, 0, 6);
86 break;
87 case SLOT_CLIMB_UP:
88 case SLOT_CLIMB_DOWN:
89 children->balloon = FIELDSTG_createBalloon(0, 2, 6);
90 break;
91 case SLOT_DROP:
92 children->balloon = FIELDSTG_createBalloon(0, 4, 6);
93 break;
94 case SLOT_GAUGE:
95 children->balloon = FIELDSTG_createBalloon(0, 5, 6);
96 break;
97 case SLOT_EXIT:
98 if (task->dir == 4) {
99 children->balloon = FIELDSTG_createBalloon(0, 10, 6);
100 } else {
101 children->balloon = FIELDSTG_createBalloon(0, (task->dir >> 1) + 6, 6);
102 }
103 break;
104 }
105#elif VERSION_EU || VERSION_JP
106 /* the European version restarts a running animation on the new row */
107 switch (task->entry->type) {
108 default:
109 arg = 0;
110 break;
111 case SLOT_CLIMB_UP:
112 case SLOT_CLIMB_DOWN:
113 arg = 2;
114 break;
115 case SLOT_DROP:
116 arg = 4;
117 break;
118 case SLOT_GAUGE:
119 arg = 5;
120 break;
121 case SLOT_EXIT:
122 if (task->dir == 4) {
123 arg = 10;
124 } else {
125 arg = (task->dir >> 1) + 6;
126 }
127 break;
128 }
129 if (children->balloon != NULL) {
130 children->balloon->setState(children->balloon, TASK_RUN);
131 children->balloon->key2 = arg;
132 children->balloon->frame = 0;
133 children->balloon->time = 0;
134 } else {
135 children->balloon = FIELDSTG_createBalloon(0, arg, 6);
136 }
137#endif
138 return 1;
139}
140
141const Vec2 FIELDSTG_noOffset = {0, 0};
142
143/* Sets off the slot the player pressed cross on */
145 StageTile *object;
146 s32 id;
147
148 switch (task->entry->type) {
149 case SLOT_EXIT:
150 task->actor->walkInDir(task->actor, task->dir);
151 FIELDSTG_leaveField(task->entry->arg, -1, task->entry->x << 8, task->entry->y << 8, task->entry->dir);
152 if (task->entry->hideAnim != 0) {
153 object = FIELDSTG_state.objects;
154 id = task->entry->hideAnim;
155 for (; object->margin != 0; object++) {
156 if (object->anim == id) {
157 object->visible = 0;
158 }
159 }
160 }
161 GAME.place = task->entry->place;
162 GAME.placeArg = task->entry->placeArg;
163 break;
164 case SLOT_LAUNCH_OUT:
165 task->actor->launch(task->actor, SLOT_DEST(task->entry));
166 FIELDSTG_leaveFieldAfter(task->entry->arg, -1, task->entry->x << 8, task->entry->y << 8, task->entry->dir,
167 0x3C);
168 break;
169 case SLOT_CLIMB_UP:
170 task->actor->climbUp(task->actor, task->dir, task->entry->x, task->entry->y,
171 (task->entry->arg - 1) * 16);
172 break;
173 case SLOT_CLIMB_DOWN:
174 task->actor->climbDown(task->actor, task->dir == 1 ? 5 : 3, task->entry->x, task->entry->y,
175 (task->entry->arg - 1) * 16);
176 break;
177 case SLOT_DROP:
178 task->actor->dropDown(task->actor, task->dir, FIELDSTG_noOffset, task->entry->arg * 16);
179 break;
180 case SLOT_GAUGE:
181 task->actor->playGauge(task->actor, task->dir, (Vec2){task->entry->arg, task->entry->x});
182 break;
183 case SLOT_WARP0:
184 task->actor->warp(task->actor, SLOT_DEST(task->entry), 0);
185 break;
186 case SLOT_WARP1:
187 task->actor->warp(task->actor, SLOT_DEST(task->entry), 1);
188 break;
189 }
190}
191
192/* The triggers' update: offers the slot under the player while the field
193 isn't busy, and sets it off on cross */
196 switch (task->state) {
197 default:
198 case TASK_INIT:
200 if (task->actor != NULL) {
201 task->nextState(task);
202 }
203 break;
204 case TASK_RUN:
205 if (FIELDSTG_state.busy != 0 || FIELDSTG_state.frozen != 0) {
206 break;
207 }
208 switch (task->substate) {
209 default:
210 case 0:
211 if (FIELDSTG_findTrigger(task) != 0 && FIELDSTG_offerTrigger(task, children) != 0) {
212 task->nextSubstate(task);
213 }
214 break;
215 case 1:
216 if (FIELDSTG_findTrigger(task) == 0) {
217 task->setSubstate(task, 0);
218 children->balloon->setState(children->balloon, TASK_DONE);
219 } else if ((PAD.getPressed(0) & (1 << PAD_CROSS)) && FIELDSTG_state.frozen == 0) {
220 children->balloon->setState(children->balloon, TASK_KILL);
222 task->nextSubstate(task);
223 }
224 break;
225 case 2:
226 if (task->actor->substate < ACTOR_WALK_OUT) {
227 task->setSubstate(task, 0);
228 }
229 break;
230 }
231 break;
232 case TASK_DONE:
233 case TASK_KILL:
234 break;
235 }
236}
237
238/* Creates the triggers */
241
242 task->sheetEntry = sheetEntry;
243 return task;
244}
Balloon * FIELDSTG_createBalloon(s32 kind, s32 anim, s32 id)
Creates a balloon of a kind (its sprites) with an animation, under a task id.
Definition balloon.c:99
#define NULL
Definition common.h:17
signed int s32
Definition common.h:11
unsigned int u32
Definition common.h:12
unsigned char u8
Definition common.h:8
GameFlags FLAGS_00
The flag bitset FLAGS_00 and the event functions.
Definition events.c:701
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
EventTask * FIELDSTG_startEvent(s32 id)
Starts the event id of FieldState.events: its script, start and end, and its text; the player stands ...
Definition event.c:250
void FIELDSTG_leaveField(s32 mode, s32 arg, s32 x, s32 y, s32 dir)
Leaves the field for a mode now (the executable calls it by this name)
Definition field.c:702
void FIELDSTG_leaveFieldAfter(s32 mode, s32 arg, s32 x, s32 y, s32 dir, s32 delay)
Leaves the field for a mode after a delay: the field task (FIELD_TASK_FIELD) goes to TASK_DONE,...
Definition field.c:687
#define ACTOR_WALK_OUT
walks off through an exit (FIELDSTG_walkActorInDir)
Definition field_map.h:310
#define SLOT_CLIMB_UP
Definition field_map.h:256
#define SLOT_DEPTH
the player's depth, arg
Definition field_map.h:259
#define SLOT_LAUNCH
sends the player flying (FIELDSTG_launchActor)
Definition field_map.h:267
#define SLOT_WARP1
a warp (FieldWarp at arg) with effect and cutscene 1
Definition field_map.h:263
#define SLOT_MAP
the map the player is on, arg (FieldMap.setMap)
Definition field_map.h:260
#define SLOT_DEST(slot)
A slot's destination: its arg on, read as signed halfwords.
Definition field_map.h:302
#define SLOT_CLIMB_DOWN
Definition field_map.h:257
#define SLOT_STOP_SLIDE
Definition field_map.h:266
#define FIELD_TASK_ACTOR
every character (FIELDSTG_createActor)
Definition field_map.h:26
#define SLOT_SLIDE
Definition field_map.h:265
#define SLOT_EVENT
starts the event arg
Definition field_map.h:262
#define SLOT_GAUGE
the gauge game
Definition field_map.h:261
#define SLOT_LAUNCH_OUT
the same, then leaves for mode arg
Definition field_map.h:268
#define SLOT_EXIT
The kinds of StageSlot (type).
Definition field_map.h:255
#define FIELD_MAP_TRIGGERS
a cell's value: a direction (3 bits) and a StageSlot (5)
Definition field_map.h:88
#define SLOT_WARP0
the same with effect and cutscene 0
Definition field_map.h:264
#define SLOT_DROP
Definition field_map.h:258
FIELDSTG.PRO: the field mode, where the player walks around the map.
FieldMap FIELDSTG_map
Definition fieldstg.c:3660
FieldState FIELDSTG_state
Definition fieldstg.c:2641
u8 FIELDSTG_nearDirs[][8]
whether two directions are at most 45 degrees apart
Definition fieldstg.c:1794
PadState PAD
Controller input: cleared by initPad, then the methods.
Definition pad.c:168
#define PAD_CROSS
Definition pad.h:31
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
void(* walkInDir)(struct Actor *, s32 dir)
Definition field_map.h:378
void(* warp)(struct Actor *, SlotDest *dest, s32 kind)
Definition field_map.h:383
void(* climbDown)()
Definition field_map.h:380
void(* dropDown)()
Definition field_map.h:381
s32 depth
the layer's ordering table entry
Definition field_map.h:344
void(* launch)(struct Actor *, SlotDest *dest)
Definition field_map.h:397
s32 substate
Definition field_map.h:335
void(* playGauge)()
Definition field_map.h:382
Vec2 tile
Definition field_map.h:337
void(* startSlide)(struct Actor *, s32 dir)
Definition field_map.h:395
s32 dir
Definition field_map.h:338
void(* stopSlide)(struct Actor *)
Definition field_map.h:396
void(* climbUp)()
Definition field_map.h:379
s32 frame
into its FIELDSTG_triggerAnims row
Definition field_mode.h:180
void(* setState)(struct Balloon *task, s32 state)
Definition field_mode.h:174
s32(* getCell)(s32 index, Vec2 *pos)
FIELDSTG_getMapCell.
Definition field_map.h:101
void(* setMap)(s32 index)
FIELDSTG_setMap: the map the player is on.
Definition field_map.h:106
s32 frozen
no control, triggers or encounters for the player: while the area name banner shows (FIELDSTG_createB...
Definition field_map.h:466
s32 busy
an event, a warp, a launch or a battle has the player
Definition field_map.h:468
StageTile * objects
the map objects, up to the first margin 0
Definition field_map.h:446
StageSlot * slots
up to the first type 0
Definition field_map.h:447
s32(* checkCondition)(u16 code, u16 value)
Definition game_state.h:53
u16 place
where the last warp or trigger put the player (FieldBattles.id)
Definition game_state.h:506
u16 placeArg
the place's argument, which the stage reads with it
Definition game_state.h:507
s32 playerDepth
Definition game_state.h:577
s32(* getPressed)(s32 pad)
Definition pad.h:125
What the player can trigger on a map (FIELDSTG_updateTriggers): a record of the table at FieldState....
Definition field_map.h:276
u16 arg
by type: a mode, a depth, a map, an event or a height (in 16 pixels, plus 1 for a climb); a warp's an...
Definition field_map.h:279
u16 conditions[2][2]
flag code and value, or code 0xFFFF
Definition field_map.h:277
u16 place
copied to GAME.place, the place (FieldBattles.id)
Definition field_map.h:285
u16 type
SLOT_EXIT...
Definition field_map.h:278
u16 hideAnim
the animation of the map objects to hide, or 0
Definition field_map.h:284
u16 placeArg
copied to GAME.placeArg: with place, the next stage's place points
Definition field_map.h:286
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
The children of an Triggers.
Definition field_mode.h:530
struct Balloon * balloon
Definition field_mode.h:531
EventTask * script
Definition field_mode.h:532
The map's triggers (FIELDSTG_createTriggers): on a trigger's cell (layer 7: index and direction) the ...
Definition field_mode.h:519
s32 dir
the trigger's direction
Definition field_mode.h:525
s32 sheetEntry
the stage's sprite sheet (FieldState.sheetEntry); nothing reads it
Definition field_mode.h:521
void(* nextSubstate)(struct Triggers *task)
Definition field_mode.h:520
StageSlot * entry
Definition field_mode.h:526
StageSlot * entries
FieldState.slots.
Definition field_mode.h:522
Actor * actor
the player
Definition field_mode.h:523
s32 index
the trigger under it
Definition field_mode.h:524
s32 substate
Definition field_mode.h:520
void(* nextState)(struct Triggers *task)
Definition field_mode.h:520
void(* setSubstate)(struct Triggers *task, s32 substate)
Definition field_mode.h:520
Definition gfx.h:352
void * createTask(void(*update)(), s32 size, s32 childrenSize)
createTaskWithId for a task nothing needs to find
Definition task.c:105
s32 FIELDSTG_findTrigger(Triggers *task)
Finds the slot under the player (FIELD_MAP_TRIGGERS); those up to SLOT_GAUGE count only while the pla...
Definition trigger.c:9
void FIELDSTG_setOffTrigger(Triggers *task)
Sets off the slot the player pressed cross on.
Definition trigger.c:144
Triggers * FIELDSTG_createTriggers(s32 sheetEntry, StageSlot *slots)
Creates the triggers.
Definition trigger.c:239
s32 FIELDSTG_offerTrigger(Triggers *task, TriggerChildren *children)
Acts at once on a slot that does (SLOT_DEPTH...), or shows the balloon of one that waits for a button...
Definition trigger.c:42
const Vec2 FIELDSTG_noOffset
Definition trigger.c:141
void FIELDSTG_updateTriggers(Triggers *task, TriggerChildren *children)
The triggers' update: offers the slot under the player while the field isn't busy,...
Definition trigger.c:194