Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
lift.c
Go to the documentation of this file.
1/* The lift of the map objects 2 and 3. Its rodata, at 0x800824C4 (USA),
2 starts FIELDSTG.PRO's second object (see data/fieldstg.c). */
3
4#include "field/field_mode.h"
5
6/*
7 * A lift made of the map objects 3 and 2: in TASK_DONE it shakes, moves the
8 * objects and the player 0x7F pixels up or down a pixel every other frame,
9 * shakes again and flips raised. WSTAG261 and WSTAG934 have a copy of it
10 * (common/update_tile_lift.inc.c).
11 */
13 StageTile *object;
14 StageTile *tile0;
15 StageTile *tile1;
16 Actor *player;
17 s32 offset;
18
19 switch (task->state) {
20 case TASK_INIT:
21 default:
22 task->nextState(task);
23 for (object = FIELDSTG_state.objects; object->margin != 0; object++) {
24 switch (object->anim) {
25 case 2:
26 task->tiles[1] = object;
27 task->homeY[1] = object->y;
28 if (task->raised) {
29 object->y -= 0x7F;
30 }
31 object->visible = 0;
32 break;
33 case 3:
34 task->tiles[0] = object;
35 task->homeY[0] = object->y;
36 if (task->raised) {
37 object->y -= 0x7F;
38 }
39 object->visible = 1;
40 break;
41 }
42 }
43 task->raised = 0;
44 break;
45 case TASK_RUN:
46 break;
47 case TASK_DONE:
48 tile0 = task->tiles[0];
49 tile1 = task->tiles[1];
51 switch (task->substate) {
52 case 0:
53 default:
54 tile1->visible = 1;
55 task->timer = 0;
56 task->y[0] = tile0->y;
57 task->y[1] = tile1->y;
58 task->playerY = player->pos.y;
60 task->nextSubstate(task);
61 break;
62 case 1:
63 task->timer += GFX.funcs.getFrameTime();
64 if (task->timer >= 30) {
65 task->shake = 0;
66 task->nextSubstate(task);
68 }
69 break;
70 case 2:
71 case 4:
72 offset = FIELDSTG_liftShake[task->shake];
73 if (offset != 1000) {
74 tile0->y = task->y[0] + offset;
75 tile1->y = task->y[1] + offset;
76 player->pos.y = task->playerY + offset;
77 task->shake++;
78 } else {
79 task->nextSubstate(task);
80 task->shake = 0;
81 }
82 break;
83 case 3:
84 task->shake++;
85 if (task->shake >= 0xFE) {
86 if (task->raised) {
87 tile0->y = task->homeY[0];
88 tile1->y = task->homeY[1];
89 player->pos.y = task->playerY + 0x7F00;
90 } else {
91 tile0->y = task->homeY[0] - 0x7F;
92 tile1->y = task->homeY[1] - 0x7F;
93 player->pos.y = task->playerY - 0x7F00;
94 }
95 task->y[0] = tile0->y;
96 task->y[1] = tile1->y;
97 task->playerY = player->pos.y;
98 task->nextSubstate(task);
99 task->shake = 0;
100 } else if (task->shake & 1) {
101 if (task->raised) {
102 tile0->y++;
103 tile1->y++;
104 player->pos.y += 0x100;
105 } else {
106 tile0->y--;
107 tile1->y--;
108 player->pos.y -= 0x100;
109 }
110 }
111 break;
112 case 5:
113 tile1->visible = 0;
114 task->setState(task, TASK_RUN);
115 task->raised ^= 1;
116 break;
117 }
118 break;
119 case TASK_KILL:
120 break;
121 }
122}
123
124/* Runs a script command of the lift's: moves it up or down */
125void FIELDSTG_moveLift(Lift *task, s32 command) {
126 if (task != NULL) {
127 switch (command) {
128 case LIFT_UP:
129 task->setState(task, TASK_DONE);
130 task->raised = 0;
131 break;
132 case LIFT_DOWN:
133 task->setState(task, TASK_DONE);
134 task->raised = 1;
135 break;
136 }
137 }
138}
139
140/* Creates the lift, raised when flag 0x1C3D is set */
142 Lift *task = createTaskWithId(FIELDSTG_updateLift, sizeof(Lift), 0, id);
143
145 task->raised = 1;
146 } else {
147 task->raised = 0;
148 }
149 return task;
150}
#define NULL
Definition common.h:17
signed int s32
Definition common.h:11
GfxState GFX
GFX: the graphics state and its methods.
Definition display.c:209
GameFlags FLAGS_00
The flag bitset FLAGS_00 and the event functions.
Definition events.c:701
#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_TASK_ACTOR
every character (FIELDSTG_createActor)
Definition field_map.h:26
#define LIFT_DOWN
and back down to the objects' place on the map
Definition field_map.h:236
#define LIFT_UP
The lift: the map objects 3 (always shown) and 2 (shown while it moves), which move 0x7F pixels up or...
Definition field_map.h:235
FIELDSTG.PRO: the field mode, where the player walks around the map.
s16 FIELDSTG_liftShake[]
FIELDSTG_updateLift's shakes, up to 1000.
Definition fieldstg.c:1286
FieldState FIELDSTG_state
Definition fieldstg.c:2641
void FIELDSTG_updateLift(Lift *task)
A lift made of the map objects 3 and 2: in TASK_DONE it shakes, moves the objects and the player 0x7F...
Definition lift.c:12
void FIELDSTG_moveLift(Lift *task, s32 command)
Runs a script command of the lift's: moves it up or down.
Definition lift.c:125
Lift * FIELDSTG_createLift(s32 id)
Creates the lift, raised when flag 0x1C3D is set.
Definition lift.c:141
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
#define SOUND_SWITCH01
Definition sound.h:50
#define SOUND_ELEVATER
Definition sound.h:60
#define FLAG_LIFT_RAISED
lift.c / wstag261 Cargo Tower: "There's a switch here! Let's push it." sets it, "let's go downstairs"...
Definition story.h:1245
A character on the field (FIELDSTG_createActor): the player (kind 0) and the other characters.
Definition field_map.h:334
Vec2 pos
Definition field_map.h:336
StageTile * objects
the map objects, up to the first margin 0
Definition field_map.h:446
s32(* checkCondition)(u16 code, u16 value)
Definition game_state.h:53
s32(* getFrameTime)(void)
Definition gfx.h:32
GfxFuncs funcs
Definition gfx.h:77
void(* setState)(struct Lift *task, s32 state)
Definition field_map.h:239
void(* nextSubstate)(struct Lift *task)
Definition field_map.h:239
s32 substate
Definition field_map.h:239
s16 y[2]
the objects' y when the move started
Definition field_map.h:246
s16 raised
the objects are 0x7F up from their place, and the next move takes them down (LIFT_DOWN; flag 0x1C3D a...
Definition field_map.h:241
s16 shake
the step of the shake table, then a frame count
Definition field_map.h:244
StageTile * tiles[2]
the map objects 3 and 2
Definition field_map.h:240
void(* nextState)(struct Lift *task)
Definition field_map.h:239
s16 timer
Definition field_map.h:243
s16 homeY[2]
the objects' place on the map
Definition field_map.h:248
s32 state
Definition field_map.h:239
s32 playerY
Definition field_map.h:247
short(* playSound)(s32 id)
returns the voice of a key-on
Definition sound.h:187
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
s32 y
Definition gfx.h:354
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