Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
actor.c
Go to the documentation of this file.
1/* A training's Digimon (TrainActor), animated from an image set */
2
3#include "menus/gym.h"
4
5/* Makes the Digimon's sprite from its loaded image set, and the effect's from
6 set 8, when the file has one */
7static inline void STGTRAIN_setUpActor(TrainActor *actor, TrainActorSprites *sprites) {
8 s32 filePos;
9 s32 x;
10 s32 y;
11
12 filePos = STGTRAIN_state.getFilePos(actor->file);
14 STGTRAIN_state.loadSet(actor->set, actor->pos);
15 if (sprites->sprite == NULL) {
16 sprites->sprite = STGTRAIN_createSprite();
17 }
18 x = filePos & 0xFFFF;
19 sprites->sprite->setBank(sprites->sprite, STGTRAIN_state.getBank(actor->set),
21 y = (u32)filePos >> 16;
22 sprites->sprite->setAnim(sprites->sprite, STGTRAIN_state.getAnim(actor->set, actor->anim));
23 sprites->sprite->setPos(sprites->sprite, x, y);
24 sprites->sprite->setImagePos(sprites->sprite, actor->pos[0], actor->pos[1]);
25 sprites->sprite->setClutPos(sprites->sprite, actor->pos[2], actor->pos[3]);
26 sprites->sprite->setLayer(sprites->sprite, actor->layerId, actor->depth);
27 if (STGTRAIN_state.readSet(8) != 0) {
28 actor->savedX = actor->pos[0];
29 actor->pos[0] = actor->pos[0] + 0x80;
30 STGTRAIN_state.loadSet(8, actor->pos);
31 actor->pos[0] = actor->savedX;
32 if (sprites->effect == NULL) {
33 sprites->effect = STGTRAIN_createSprite();
34 }
36 sprites->effect->setAnim(sprites->effect, STGTRAIN_state.getAnim(8, actor->anim));
37 sprites->effect->setPos(sprites->effect, x, y);
38 sprites->effect->setImagePos(sprites->effect, actor->pos[0], actor->pos[1]);
39 sprites->effect->setClutPos(sprites->effect, actor->pos[2], actor->pos[3]);
41 sprites->effect->setLayer(sprites->effect, actor->layerId, actor->depth - 1);
42 } else {
43 sprites->effect->setLayer(sprites->effect, actor->layerId, actor->depth);
44 }
45 } else if (sprites->effect != NULL) {
46 sprites->effect->setState(sprites->effect, TASK_KILL);
47 }
48 actor->result = -1;
49}
50
51/* Mode 2: grows or shrinks the Digimon by scaleStep a frame, about its
52 middle, until it is whole or gone */
53static inline void STGTRAIN_scaleActor(TrainActor *actor, TrainActorSprites *sprites) {
54 actor->scale += actor->scaleStep;
55 if (actor->scaleStep > 0) {
56 if (actor->scale > ONE) {
57 actor->scale = ONE;
58 actor->scaleStep = 0;
59 actor->mode = 1;
60 }
61 } else if (actor->scale < 0) {
62 actor->scale = 0;
63 actor->scaleStep = 0;
64 actor->mode = 1;
65 }
66 if (sprites->sprite != NULL) {
67 sprites->sprite->setScale(sprites->sprite, actor->scale, actor->scale, ONE);
68 sprites->sprite->setPivot(sprites->sprite, 0xCF, 0x7F);
69 }
70 if (sprites->effect != NULL) {
71 sprites->effect->setScale(sprites->effect, actor->scale, actor->scale, ONE);
72 sprites->effect->setPivot(sprites->effect, 0xCF, 0x7F);
73 }
74}
75
76/* Whether the Digimon's animation (and the effect's) has ended */
78 if (sprites->effect != NULL) {
79 return sprites->sprite->getFlags(sprites->sprite) & sprites->effect->getFlags(sprites->effect);
80 }
81 return sprites->sprite->getFlags(sprites->sprite);
82}
83
84/* Pauses the Digimon and its effect on their last frame and goes idle
85 (mode 1) */
86static inline void STGTRAIN_stopActor(TrainActor *actor, TrainActorSprites *sprites) {
87 if (sprites->sprite != NULL) {
88 sprites->sprite->setPaused(sprites->sprite, 1);
89 }
90 if (sprites->effect != NULL) {
91 sprites->effect->setPaused(sprites->effect, 1);
92 }
93 actor->anim = 0;
94 actor->setSubstate(actor, 0);
95 actor->mode = 1;
96}
97
98/* Mode 4: plays the training's two animations, then the one of whether it
99 worked, which the chance decides, then stops */
100static inline void STGTRAIN_playTraining(TrainActor *actor, TrainActorSprites *sprites) {
101 s32 worked;
102
103 if (!STGTRAIN_actorAnimDone(sprites)) {
104 return;
105 }
106 if (actor->substate != 0) {
107 STGTRAIN_stopActor(actor, sprites);
108 return;
109 }
110 actor->anim++;
111 if (actor->anim >= 2) {
112 worked = actor->chance >= RANDOM.next() % 100;
113 if (worked == 1) {
114 if (sprites->sprite != NULL) {
115 sprites->sprite->setAnim(sprites->sprite, STGTRAIN_state.getAnim(actor->set, 2));
116 }
117 if (sprites->effect != NULL) {
118 sprites->effect->setAnim(sprites->effect, STGTRAIN_state.getAnim(8, 2));
119 }
120 /* and on a 1 here: CSE puts worked's register
121 in, while worked itself leaves it a copy */
122 actor->result = 1;
123 } else {
124 if (sprites->sprite != NULL) {
125 sprites->sprite->setAnim(sprites->sprite, STGTRAIN_state.getAnim(actor->set, 3));
126 }
127 if (sprites->effect != NULL) {
128 sprites->effect->setAnim(sprites->effect, STGTRAIN_state.getAnim(8, 3));
129 }
130 actor->result = 0;
131 }
132 actor->nextSubstate(actor);
133 } else {
134 if (sprites->sprite != NULL) {
135 sprites->sprite->setAnim(sprites->sprite, STGTRAIN_state.getAnim(actor->set, actor->anim));
136 }
137 if (sprites->effect != NULL) {
138 sprites->effect->setAnim(sprites->effect, STGTRAIN_state.getAnim(8, actor->anim));
139 }
140 actor->result = -1;
141 }
142}
143
144/* Mode 8: plays the end of the training, worked (animation 4) or not (5),
145 then stops; without that animation the Digimon goes idle at once */
146static inline void STGTRAIN_playTrainingEnd(TrainActor *actor, TrainActorSprites *sprites) {
147 TrainAnim *anim;
148
149 if (actor->substate == 0) {
150 if (actor->result != 0) {
151 actor->anim = 4;
152 } else {
153 actor->anim = 5;
154 }
155 if (sprites->sprite != NULL) {
156 anim = STGTRAIN_state.getAnim(actor->set, actor->anim);
157 if (anim != NULL) {
158 sprites->sprite->setAnim(sprites->sprite, anim);
159 } else {
160 actor->mode = 1;
161 }
162 }
163 if (sprites->effect != NULL) {
164 anim = STGTRAIN_state.getAnim(8, actor->anim);
165 if (anim != NULL) {
166 sprites->effect->setAnim(sprites->effect, anim);
167 } else {
168 actor->mode = 1;
169 }
170 }
171 actor->substate++;
172 } else if (STGTRAIN_actorAnimDone(sprites)) {
173 STGTRAIN_stopActor(actor, sprites);
174 }
175}
176
177/*
178 * A training's Digimon (TrainActor): once its file is loaded and its
179 * positions set, makes its sprite (and the effect of set 8); then grows or
180 * shrinks (mode 2), plays the training (mode 4: two animations, then the
181 * chance decides between the worked and failed ones) or its end (mode 8).
182 */
184 switch (actor->state) {
185 case TASK_INIT:
186 default:
187 if (FILE_CACHE.isLoading(STGTRAIN_state.getFileId(actor->file)) == 0 && actor->posSet != 0 &&
188 actor->clutSet != 0) {
189 actor->nextState(actor);
190 STGTRAIN_setUpActor(actor, sprites);
191 }
192 break;
193 case TASK_RUN:
194 if (actor->scaleChanged != 0) {
195 if (sprites->sprite != NULL) {
196 sprites->sprite->setScale(sprites->sprite, actor->scale, actor->scale, ONE);
197 }
198 if (sprites->effect != NULL) {
199 sprites->effect->setScale(sprites->effect, actor->scale, actor->scale, ONE);
200 }
201 actor->scaleChanged = 0;
202 }
203 switch (actor->mode) {
204 case 1:
205 break;
206 case 2:
207 STGTRAIN_scaleActor(actor, sprites);
208 break;
209 case 4:
210 STGTRAIN_playTraining(actor, sprites);
211 break;
212 case 8:
213 STGTRAIN_playTrainingEnd(actor, sprites);
214 break;
215 }
216 break;
217 case TASK_DONE:
218 case TASK_KILL:
219 break;
220 }
221}
222
223/* Pauses the Digimon's sprite and effect */
225 TrainActorSprites *sprites = actor->children;
226
227 if (sprites->sprite != NULL) {
228 sprites->sprite->setPaused(sprites->sprite, 1);
229 }
230 if (sprites->effect != NULL) {
231 sprites->effect->setPaused(sprites->effect, 1);
232 }
233}
234
235/* Plays the training on (mode 4), unpausing the sprite and effect */
237 TrainActorSprites *sprites = actor->children;
238
239 if (sprites->sprite != NULL) {
240 sprites->sprite->setPaused(sprites->sprite, 0);
241 }
242 if (sprites->effect != NULL) {
243 sprites->effect->setPaused(sprites->effect, 0);
244 }
245 actor->mode = 4;
246}
247
248/* Sets where the Digimon's images go in VRAM */
250 actor->pos[0] = x;
251 actor->pos[1] = y;
252 actor->posSet = 1;
253}
254
255/* Sets where the Digimon's CLUTs go in VRAM */
257 actor->pos[2] = x;
258 actor->pos[3] = y;
259 actor->clutSet = 1;
260}
261
262/* Sets the chance that the training works */
264 actor->chance = chance;
265}
266
267/* Makes the Digimon grow from nothing (mode 2) */
269 actor->scaleStep = 0x199;
270 actor->scale = 0;
271 actor->mode = 2;
272}
273
274/* Makes the Digimon shrink to nothing (mode 2) */
276 actor->scale = ONE;
277 actor->scaleStep = -0x333;
278 actor->mode = 2;
279}
280
281/* Scales the Digimon (0x1000 is its size) */
283 actor->scaleChanged = 1;
284 actor->scale = scale;
285}
286
287/* Whether the training worked, once it is done (mode bit 0), else -1 */
289 if (actor->mode & 1) {
290 return actor->result;
291 }
292 return -1;
293}
294
295/* Plays the training's end (mode 8) */
297 actor->mode = 8;
298 actor->substate = 0;
299}
300
301/* Creates an animated sprite of an image set */
302TrainActor *STGTRAIN_createActor(s32 set, s32 file, s32 layerId, s32 depth) {
304
308 actor->grow = STGTRAIN_growActor;
310 actor->play = STGTRAIN_playActor;
311 actor->pause = STGTRAIN_pauseActor;
314 actor->set = set;
315 actor->file = file;
316 actor->layerId = layerId;
317 actor->depth = depth;
318 actor->end = STGTRAIN_endActor;
319 return actor;
320}
#define NULL
Definition common.h:17
signed int s32
Definition common.h:11
unsigned int u32
Definition common.h:12
#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
FileCache FILE_CACHE
The file cache.
Definition file_cache.c:7
TrainState STGTRAIN_state
Definition files.c:422
STGTRAIN.PRO: the gyms, where the partners train their stats.
void STGTRAIN_setActorClutPos(TrainActor *actor, s32 x, s32 y)
Sets where the Digimon's CLUTs go in VRAM.
Definition actor.c:256
void STGTRAIN_shrinkActor(TrainActor *actor)
Makes the Digimon shrink to nothing (mode 2)
Definition actor.c:275
void STGTRAIN_pauseActor(TrainActor *actor)
Pauses the Digimon's sprite and effect.
Definition actor.c:224
static void STGTRAIN_stopActor(TrainActor *actor, TrainActorSprites *sprites)
Pauses the Digimon and its effect on their last frame and goes idle (mode 1)
Definition actor.c:86
static void STGTRAIN_playTrainingEnd(TrainActor *actor, TrainActorSprites *sprites)
Mode 8: plays the end of the training, worked (animation 4) or not (5), then stops; without that anim...
Definition actor.c:146
TrainActor * STGTRAIN_createActor(s32 set, s32 file, s32 layerId, s32 depth)
Creates an animated sprite of an image set.
Definition actor.c:302
void STGTRAIN_playActor(TrainActor *actor)
Plays the training on (mode 4), unpausing the sprite and effect.
Definition actor.c:236
void STGTRAIN_endActor(TrainActor *actor)
Plays the training's end (mode 8)
Definition actor.c:296
static void STGTRAIN_playTraining(TrainActor *actor, TrainActorSprites *sprites)
Mode 4: plays the training's two animations, then the one of whether it worked, which the chance deci...
Definition actor.c:100
static void STGTRAIN_setUpActor(TrainActor *actor, TrainActorSprites *sprites)
Makes the Digimon's sprite from its loaded image set, and the effect's from set 8,...
Definition actor.c:7
void STGTRAIN_growActor(TrainActor *actor)
Makes the Digimon grow from nothing (mode 2)
Definition actor.c:268
void STGTRAIN_setActorChance(TrainActor *actor, s32 chance)
Sets the chance that the training works.
Definition actor.c:263
s32 STGTRAIN_getActorResult(TrainActor *actor)
Whether the training worked, once it is done (mode bit 0), else -1.
Definition actor.c:288
void STGTRAIN_setActorScale(TrainActor *actor, s32 scale)
Scales the Digimon (0x1000 is its size)
Definition actor.c:282
static s32 STGTRAIN_actorAnimDone(TrainActorSprites *sprites)
Whether the Digimon's animation (and the effect's) has ended.
Definition actor.c:77
void STGTRAIN_setActorPos(TrainActor *actor, s32 x, s32 y)
Sets where the Digimon's images go in VRAM.
Definition actor.c:249
void STGTRAIN_updateActor(TrainActor *actor, TrainActorSprites *sprites)
A training's Digimon (TrainActor): once its file is loaded and its positions set, makes its sprite (a...
Definition actor.c:183
static void STGTRAIN_scaleActor(TrainActor *actor, TrainActorSprites *sprites)
Mode 2: grows or shrinks the Digimon by scaleStep a frame, about its middle, until it is whole or gon...
Definition actor.c:53
Random RANDOM
Definition random.c:533
TrainSprite * STGTRAIN_createSprite(void)
Creates an animated sprite.
Definition sprite.c:287
s32(* isLoading)(s32 file)
Definition file.h:88
s32(* next)(void)
0 to RANDOM_COUNT - 1
Definition random.h:15
The children of a TrainActor.
Definition gym.h:243
TrainSprite * effect
of set 8
Definition gym.h:245
TrainSprite * sprite
Definition gym.h:244
An animated sprite of an image set, as a training shows it (STGTRAIN_createActor): mode 1 idle,...
Definition gym.h:209
void(* nextState)(struct TrainActor *task)
Definition gym.h:210
s32 scaleChanged
Definition gym.h:219
void(* play)(struct TrainActor *actor)
Definition gym.h:234
void(* setClutPos)(struct TrainActor *actor, s32 x, s32 y)
Definition gym.h:230
void(* setScale)(struct TrainActor *actor, s32 scale)
Definition gym.h:236
void(* grow)(struct TrainActor *actor)
Definition gym.h:232
void * children
Definition gym.h:210
s32 state
Definition gym.h:210
s32 layerId
Definition gym.h:220
s32 result
the training worked
Definition gym.h:215
s32 savedX
Definition gym.h:224
void(* pause)(struct TrainActor *actor)
Definition gym.h:235
s32 posSet
Definition gym.h:225
s32 substate
Definition gym.h:210
void(* end)(struct TrainActor *actor)
Definition gym.h:238
u32 mode
Definition gym.h:211
s32 anim
Definition gym.h:214
s32 clutSet
Definition gym.h:226
s32 pos[4]
x, y, clutX, clutY: for loadSet
Definition gym.h:223
s32 chance
of the training working, in %
Definition gym.h:227
void(* setChance)(struct TrainActor *actor, s32 chance)
Definition gym.h:231
s32(* getResult)(struct TrainActor *actor)
Definition gym.h:237
void(* setSubstate)(struct TrainActor *task, s32 substate)
Definition gym.h:210
s32 set
Definition gym.h:212
void(* setPos)(struct TrainActor *actor, s32 x, s32 y)
Definition gym.h:229
s32 scale
Definition gym.h:216
void(* shrink)(struct TrainActor *actor)
Definition gym.h:233
s32 depth
Definition gym.h:221
void(* nextSubstate)(struct TrainActor *task)
Definition gym.h:210
s32 scaleStep
Definition gym.h:217
s32 file
of STGTRAIN_files
Definition gym.h:213
A sprite animation: its frames follow the header.
Definition gym.h:34
void(* setBank)(struct TrainSprite *sprite, TrainSpriteBank *bank, s32 offset)
Definition gym.h:92
void(* setScale)(struct TrainSprite *sprite, s32 x, s32 y, s32 z)
Definition gym.h:98
void(* setAnim)(struct TrainSprite *sprite, TrainAnim *anim)
Definition gym.h:93
void(* setClutPos)(struct TrainSprite *sprite, s32 x, s32 y)
Definition gym.h:97
s32(* getFlags)(struct TrainSprite *sprite)
Definition gym.h:101
void(* setImagePos)(struct TrainSprite *sprite, s32 x, s32 y)
Definition gym.h:95
void(* setPivot)(struct TrainSprite *sprite, s32 x, s32 y)
Definition gym.h:99
void(* setState)(struct TrainSprite *task, s32 state)
Definition gym.h:65
void(* setPos)(struct TrainSprite *sprite, s32 x, s32 y)
Definition gym.h:94
void(* setLayer)(struct TrainSprite *sprite, s32 layerId, s32 depth)
Definition gym.h:96
void(* setPaused)(struct TrainSprite *sprite, s32 paused)
Definition gym.h:102
TrainAnim *(* getAnim)(s32 set, s32 i)
Definition gym.h:362
s32(* readSet)(s32 set)
Definition gym.h:354
s32(* getBankOffset)(s32 set)
Definition gym.h:360
TrainSpriteBank *(* getBank)(s32 set)
Definition gym.h:359
s32(* getFilePos)(s32 index)
y << 16 | x
Definition gym.h:357
s32(* loadSet)(s32 set, s32 *pos)
Definition gym.h:355
s32(* getFileEffectSameDepth)(s32 index)
Definition gym.h:358
s32(* getFileId)(s32 index)
Definition gym.h:356
void * createTask(void(*update)(), s32 size, s32 childrenSize)
createTaskWithId for a task nothing needs to find
Definition task.c:105