Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
launch.c
Go to the documentation of this file.
1/* The launchers, which send an actor flying to a tile */
2
3#include "field/field_mode.h"
4#include "field/stages.h"
5
6/* radius times the sine of angle */
7s32 FIELDSTG_scaleSin(s32 angle, s32 radius) {
8 return rsin(angle >> 2) * radius / 4096;
9}
10
11/*
12 * The flight: the distances to the destination taken once, then the player
13 * moved along them on a sine curve, spinning and without a shadow, until
14 * counter reaches 0x1000 and the player lands on it
15 */
16static inline void flyToDest(Launch *task) {
17 s32 d;
18
19 switch (task->step) {
20 case 0:
21 default:
22 task->negX = 0;
23 task->dist.x = task->dest->x - task->start.x;
24 if (task->dist.x < 0) {
25 task->dist.x = -task->dist.x;
26 task->negX = 1;
27 }
28 task->negY = 0;
29 task->dist.y = task->dest->y - task->start.y;
30 if (task->dist.y < 0) {
31 task->dist.y = -task->dist.y;
32 task->negY = 1;
33 }
34 task->nextStep(task);
35 /* fallthrough */
36 case 1:
37 task->counter += GFX.funcs.getFrameTime() * 24;
38 if (task->counter > 0x1000) {
39 task->counter = 0x1000;
40 task->actor->tile.x = task->dest->x;
41 task->actor->pos.x = task->actor->tile.x << 8;
42 task->actor->tile.y = task->dest->y;
43 task->actor->pos.y = task->actor->tile.y << 8;
44 task->nextSubstate(task);
45 break;
46 }
47 d = FIELDSTG_scaleSin(task->counter, task->dist.x);
48 if (task->negX) {
49 task->actor->tile.x = task->start.x - d;
50 } else {
51 task->actor->tile.x = task->start.x + d;
52 }
53 task->actor->pos.x = task->actor->tile.x << 8;
54 d = FIELDSTG_scaleSin(task->counter, task->dist.y);
55 if (task->negY) {
56 task->actor->tile.y = task->start.y - d;
57 } else {
58 task->actor->tile.y = task->start.y + d;
59 }
60 task->actor->pos.y = task->actor->tile.y << 8;
61 task->actor->dir = (GFX.funcs.getTime() >> 1) & 7;
62 task->actor->hasShadow = 0;
63 break;
64 }
65}
66
67/* Sends an actor from the nearest FIELD_TASK_LAUNCHER (y counts twice in the
68 * distance) to its dest tile: the actor walks to the task, sets it to
69 * TASK_DONE, waits for it to leave that state, then moves along a quarter
70 * sine, spinning, until it lands; without such a task it ends at once. The
71 * match depends on the distance written twice. */
73 Vec2 pos;
74 Vec2 near;
75 Task *t;
76 Task *found;
77 s32 best;
78 s32 dx;
79 s32 dy;
80
81 switch (task->state) {
82 case TASK_INIT:
83 default:
84 best = 0x8000;
85 found = NULL;
86 pos.x = task->actor->tile.x;
87 pos.y = task->actor->tile.y;
89 dx = pos.x - t->key1;
90 if (dx < 0) {
91 dx = -dx;
92 }
93 dy = pos.y - t->key2;
94 if (dy < 0) {
95 dy = -dy;
96 }
97 if (dx + dy * 2 < best) {
98 found = t;
99 near.x = t->key1;
100 best = dx + dy * 2;
101 near.y = found->key2;
102 }
103 }
104 if (found == NULL) {
105 task->setState(task, TASK_KILL);
106 break;
107 }
108 task->from = found;
109 task->start.x = near.x + 0x14;
110 task->start.y = near.y + 0xD;
111 task->nextState(task);
112 /* fallthrough */
113 case TASK_RUN:
114 switch (task->substate) {
115 case 0:
116 switch (task->step) {
117 case 0:
118 task->actor->setGoal(task->actor, task->start.x, task->start.y, 0);
120 task->nextStep(task);
121 /* fallthrough */
122 case 1:
123 if (task->actor->isWalking(task->actor) == 0) {
124 task->nextSubstate(task);
125 }
126 break;
127 }
128 break;
129 case 1:
130 switch (task->step) {
131 case 0:
132 default:
133 task->from->setState(task->from, TASK_DONE);
135 task->nextStep(task);
136 /* fallthrough */
137 case 1:
138 if (task->from->state != TASK_DONE) {
139 task->nextSubstate(task);
140 }
141 break;
142 }
143 break;
144 case 2:
145 flyToDest(task);
146 break;
147 default:
148 task->setState(task, TASK_KILL);
149 break;
150 }
151 break;
152 case TASK_DONE:
153 break;
154 case TASK_KILL:
155 task->actor->dir = 0;
156 task->actor->hasShadow = 1;
158 task->actor->resetControl(task->actor);
160 break;
161 }
162}
163
164/* Creates the flight of an actor to the tile at dest; two stages' modes
165 (0x26C, 0x2D4) set theirs up */
167 Launch *task = createTask(FIELDSTG_runLaunch, sizeof(Launch), 0);
168
169 task->actor = actor;
170 task->dest = dest;
171 if (GAME.funcs.getMode() == 0x26C) {
173 }
174 if (GAME.funcs.getMode() == 0x2D4) {
176 }
177 return task;
178}
#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
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
void FIELDSTG_resumePartners(void)
Makes the partners follow the player again (FIELDSTG_followLeader)
Definition actor.c:20
void FIELDSTG_haltPartners(void)
Makes the partners stop following: each walks out the rest of its trail (FIELDSTG_drainTrail)
Definition actor.c:7
#define FIELD_TASK_LAUNCHER
a stage's launchers (FIELDSTG_runLaunch)
Definition field_map.h:32
FIELDSTG.PRO: the field mode, where the player walks around the map.
FieldState FIELDSTG_state
Definition fieldstg.c:2641
s32 FIELDSTG_scaleSin(s32 angle, s32 radius)
radius times the sine of angle
Definition launch.c:7
Launch * FIELDSTG_createLaunch(Actor *actor, SlotDest *dest)
Creates the flight of an actor to the tile at dest; two stages' modes (0x26C, 0x2D4) set theirs up.
Definition launch.c:166
void FIELDSTG_runLaunch(Launch *task)
Sends an actor from the nearest FIELD_TASK_LAUNCHER (y counts twice in the distance) to its dest tile...
Definition launch.c:72
static void flyToDest(Launch *task)
The flight: the distances to the destination taken once, then the player moved along them on a sine c...
Definition launch.c:16
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_TELEPORT
TELEPORT.
Definition sound.h:47
The stage overlays' symbols that FIELDSTG links against (the Makefile's CHILDREN_fieldstg): each stag...
void * WSTAG746_startEvent8000(void)
void * WSTAG745_startEvent8000(void)
A character on the field (FIELDSTG_createActor): the player (kind 0) and the other characters.
Definition field_map.h:334
void(* setGoal)(struct Actor *, s32, s32, s32)
Definition field_map.h:390
Vec2 pos
Definition field_map.h:336
s32(* isWalking)(struct Actor *)
Definition field_map.h:391
Vec2 tile
Definition field_map.h:337
void(* resetControl)(struct Actor *)
Definition field_map.h:387
s32 dir
Definition field_map.h:338
s32 hasShadow
drawn with a shadow
Definition field_map.h:343
s32 busy
an event, a warp, a launch or a battle has the player
Definition field_map.h:468
s32(* getMode)(void)
Definition game_state.h:19
GameFuncs funcs
Definition game_state.h:582
s32(* getFrameTime)(void)
Definition gfx.h:32
s32(* getTime)(void)
Definition gfx.h:31
GfxFuncs funcs
Definition gfx.h:77
Launches an actor, spinning, from the nearest launcher (FIELD_TASK_LAUNCHER) to a tile (FIELDSTG_crea...
Definition field_mode.h:208
void(* nextStep)(struct Launch *task)
Definition field_mode.h:209
void(* nextState)(struct Launch *task)
Definition field_mode.h:209
s32 negY
Definition field_mode.h:216
s32 state
Definition field_mode.h:209
void(* nextSubstate)(struct Launch *task)
Definition field_mode.h:209
SlotDest * dest
the tile it lands on
Definition field_mode.h:211
Vec2 start
Definition field_mode.h:213
s32 negX
Definition field_mode.h:215
Task * from
the nearest FIELD_TASK_LAUNCHER
Definition field_mode.h:212
s32 counter
Definition field_mode.h:209
void(* setState)(struct Launch *task, s32 state)
Definition field_mode.h:209
Actor * actor
Definition field_mode.h:210
s32 step
Definition field_mode.h:209
s32 substate
Definition field_mode.h:209
Vec2 dist
Definition field_mode.h:214
Where a slot leads: a StageSlot from its arg on, as the warps (FieldTask.warp) and the launches (Laun...
Definition field_map.h:291
s16 x
in pixels
Definition field_map.h:293
short(* playSound)(s32 id)
returns the voice of a key-on
Definition sound.h:187
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
Any task, seen through its header.
Definition task.h:62
s32 key1
Definition task.h:63
s32 key2
Definition task.h:63
void(* setState)(struct Task *task, s32 state)
Definition task.h:63
s32 state
Definition task.h:63
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