Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
move.c
Go to the documentation of this file.
1/* FIGHTSTG's jumps and moves of a fighter's model. */
2
4
5/* The jump's task: lifts its model and drops it along ease curves at its
6 speed; kind 4 also moves it forward from home, 5 back home and 6 drops it
7 to its home height, mirrored for the enemy */
9 s32 y;
10
11 switch (task->state) {
12 case TASK_INIT:
13 default:
14 task->zTravel = 0;
15 switch (task->kind) {
16 case 4:
17 task->zTravel = task->distance + 0x2800;
18 break;
19 case 5:
20 task->zTravel = task->control->pos.z - task->control->homePos.z;
21 if (task->zTravel < 0) {
22 task->zTravel = -task->zTravel;
23 }
24 break;
25 }
26 if (task->control->id == 0x10) {
27 task->zTravel = -task->zTravel;
28 }
29 task->t = FIGHTSTG_battle.frames * task->speed;
30 task->nextState(task);
31 /* fallthrough */
32 case TASK_RUN:
33 switch (task->kind) {
34 default:
35 y = FIGHTSTG_interp.ease(2, task->t, task->height);
36 task->control->pos.y = FIGHTSTG_interp.ease(1, task->t, task->y) - y;
37 break;
38 case 4:
39 case 5:
40 task->control->pos.y = task->control->homePos.y - FIGHTSTG_interp.ease(2, task->t, task->height);
41 break;
42 case 6:
43 task->control->pos.y = FIGHTSTG_interp.ease(0, task->t, task->control->homePos.y);
44 break;
45 }
46 if (task->kind == 4) {
47 task->control->pos.z = task->control->homePos.z + FIGHTSTG_interp.ease(0, task->t, task->zTravel);
48 }
49 if (task->kind == 5) {
50 task->control->pos.z = task->control->homePos.z + task->zTravel - FIGHTSTG_interp.ease(0, task->t, task->zTravel);
51 }
52 task->t += FIGHTSTG_battle.frames * task->speed;
53 if (task->t < 0x1000) {
54 break;
55 }
56 task->nextState(task);
57 break;
58 case TASK_DONE:
59 switch (task->kind) {
60 default:
61 task->control->pos.y = 0;
62 break;
63 case 4:
64 case 5:
65 case 6:
66 task->control->pos.y = task->control->homePos.y;
67 break;
68 }
69 if (task->kind == 4) {
70 task->control->pos.z = task->control->homePos.z + task->zTravel;
71 }
72 if (task->kind == 5) {
73 task->control->pos.z = task->control->homePos.z;
74 }
75 task->nextState(task);
76 break;
77 case TASK_KILL:
78 break;
79 }
80}
81
82/* the jumps of FIGHTSTG_startJump, by kind from 1 */
84 { 640, 136 }, { 1280, 102 }, { 1920, 81 }, { 2560, 64 }, { 1280, 64 }, { 0, 42 },
85};
86
87/* Starts a jump of control's model of kind 1-6 (FIGHTSTG_jumps), forward by
88 distance for kind 4 */
89Jump *FIGHTSTG_startJump(ModelControl *control, s32 kind, s32 distance) {
90 Jump *task = createTask(FIGHTSTG_updateJump, sizeof(Jump), 0);
91
92 task->kind = kind;
93 task->control = control;
94 task->distance = distance;
95 task->y = control->pos.y;
96 task->height = FIGHTSTG_jumps[kind - 1].height;
97 task->speed = FIGHTSTG_jumps[kind - 1].speed;
98 return task;
99}
100
101/* The move's task: takes the model from from to to along tStep, a step each
102 frame, and dies there */
104 SVECTOR from;
105 SVECTOR to;
106 SVECTOR out;
107 s32 t;
108
109 switch (task->state) {
110 case TASK_INIT:
111 default:
112 task->t = FIGHTSTG_battle.frames * task->tStep;
113 task->nextState(task);
114 /* fallthrough */
115 case TASK_RUN:
116 t = task->t;
117 from.vx = task->from.x;
118 from.vy = task->from.y;
119 from.vz = task->from.z;
120 to.vx = task->to.x;
121 to.vy = task->to.y;
122 to.vz = task->to.z;
123 FIGHTSTG_interp.lerp(&from, &to, t, &out);
124 task->control->pos.x = out.vx;
125 task->control->pos.y = out.vy;
126 task->control->pos.z = out.vz;
127 task->t += FIGHTSTG_battle.frames * task->tStep;
128 if (task->t >= 0x1000) {
129 task->control->pos.x = task->to.x;
130 task->control->pos.y = task->to.y;
131 task->control->pos.z = task->to.z;
132 task->setState(task, TASK_KILL);
133 }
134 break;
135 case TASK_DONE:
136 case TASK_KILL:
137 break;
138 }
139}
140
141/* Moves control's model from where it is to to over time frames */
143 MoveTask *task = createTask(FIGHTSTG_updateMove, sizeof(MoveTask), 0);
144
145 task->control = control;
146 task->to = *to;
147 task->from = control->pos;
148 task->t = 0;
149 task->tStep = 0x1000 / time;
150 return task;
151}
Battle FIGHTSTG_battle
the battle: its fighters, speed and drawing functions
Definition battle.c:16
FIGHTSTG.PRO: the battle.
signed int s32
Definition common.h:11
#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
InterpFuncs FIGHTSTG_interp
the functions that go between values
Definition interp.c:44
JumpParams FIGHTSTG_jumps[]
the jumps of FIGHTSTG_startJump, by kind from 1
Definition move.c:83
void FIGHTSTG_updateJump(Jump *task)
The jump's task: lifts its model and drops it along ease curves at its speed; kind 4 also moves it fo...
Definition move.c:8
Jump * FIGHTSTG_startJump(ModelControl *control, s32 kind, s32 distance)
Starts a jump of control's model of kind 1-6 (FIGHTSTG_jumps), forward by distance for kind 4.
Definition move.c:89
void FIGHTSTG_updateMove(MoveTask *task)
The move's task: takes the model from from to to along tStep, a step each frame, and dies there.
Definition move.c:103
MoveTask * FIGHTSTG_startMove(ModelControl *control, ShortVec3 *to, s32 time)
Moves control's model from where it is to to over time frames.
Definition move.c:142
s32 frames
since the last update
Definition battle.h:239
s32(* ease)(s32 curve, s32 t, s32 value)
value scaled by a curve of t
Definition model.h:196
void(* lerp)(SVECTOR *from, SVECTOR *to, s32 t, SVECTOR *out)
t: 0-0x1000
Definition model.h:195
The jump heights and speeds (t per frame) of the Jump kinds 1-6.
Definition model.h:325
s32 speed
Definition model.h:327
s32 height
Definition model.h:326
A ModelControl's jump (FIGHTSTG_startJump): up and down from its y, or for kinds 4 and 5 also forward...
Definition model.h:332
s32 speed
Definition model.h:340
s32 state
Definition model.h:333
s32 kind
Definition model.h:334
ModelControl * control
Definition model.h:337
s32 y
Definition model.h:339
s32 t
0-0x1000
Definition model.h:341
void(* nextState)(struct Jump *task)
Definition model.h:333
s32 height
Definition model.h:338
s32 zTravel
kinds 4 and 5: the z it moves from home, negated for the enemy
Definition model.h:336
s32 distance
kind 4: past 0x2800
Definition model.h:335
What drives a Model, owned by whoever created it.
Definition model.h:99
ShortVec3 pos
Definition model.h:107
s32 id
the Models task's
Definition model.h:101
ShortVec3 homePos
Definition model.h:109
FIGHTSTG_startMove's task: moves a ModelControl to a position.
Definition model.h:200
s32 tStep
Definition model.h:206
void(* setState)(struct MoveTask *task, s32 state)
Definition model.h:201
ShortVec3 from
Definition model.h:203
ModelControl * control
Definition model.h:202
s32 t
0-0x1000
Definition model.h:205
s32 state
Definition model.h:201
void(* nextState)(struct MoveTask *task)
Definition model.h:201
ShortVec3 to
Definition model.h:204
A position or rotation, without the SVECTOR pad.
Definition model.h:14
s16 x
Definition model.h:15
s16 z
Definition model.h:17
s16 y
Definition model.h:16
void * createTask(void(*update)(), s32 size, s32 childrenSize)
createTaskWithId for a task nothing needs to find
Definition task.c:105