Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
actor.c
Go to the documentation of this file.
1/* The actor task: the player, its partners and the other characters */
2
3#include "field/field_mode.h"
4
5/* Makes the partners stop following: each walks out the rest of its trail
6 (FIELDSTG_drainTrail) */
8 s32 i;
9 Actor *actor;
10
11 for (i = 0; i < 3; i++) {
13 if (actor != NULL) {
15 }
16 }
17}
18
19/* Makes the partners follow the player again (FIELDSTG_followLeader) */
21 s32 i;
22 Actor *actor;
23
24 for (i = 0; i < 3; i++) {
26 if (actor != NULL) {
28 }
29 }
30}
31
32/* The tile in front of an actor, one step in its direction */
33void FIELDSTG_getFacingTile(Actor *actor, Vec2 *out) {
34 Vec2 *delta = &FIELDSTG_dirSteps[actor->dir];
35
36 out->x = actor->tile.x + delta->x;
37 out->y = actor->tile.y + delta->y;
38}
39
40/* An actor's update: waits for its animation file (and gives the player its
41 icon), then runs its control and its action, moves its tile and draws it
42 sorted by y; in TASK_KILL, frees its trail */
43void FIELDSTG_updateActor(Actor *actor, ActorChildren *children) {
44 Layer *layer;
45
46 switch (actor->state) {
47 default:
48 case TASK_INIT:
49 if (actor->animFile == 0 || FILE_CACHE.isLoading(actor->animFile >> 16) == 0) {
50 if (actor->key2 == 0) {
51 children->icon = FIELDSTG_createActorIcon(actor);
52 }
53 actor->nextState(actor);
54 }
55 break;
56 case TASK_RUN:
57 if ((actor->key2 & 0xE) || FIELDSTG_state.frozen == 0) {
58 if (actor->control != NULL) {
59 actor->control(actor);
60 }
61 }
62 FIELDSTG_runActorAction(actor, children);
63 actor->tile.x = actor->pos.x >> 8;
64 actor->tile.y = (actor->pos.y - actor->climbHeight) >> 8;
65 if (actor->animFile != 0) {
67 if (actor->tile.x + actor->tile.y != 0) {
69 layer->addSortedCallback(layer, FIELDSTG_drawActor, actor, actor->tile.y, 0);
70 }
71 }
72 break;
73 case TASK_DONE:
74 break;
75 case TASK_KILL:
76 GAME.flightZ = actor->z;
77 if (actor->voice != -1) {
79 }
80 if (actor->trail != NULL) {
81 HEAP.free(actor->trail);
82 }
83 break;
84 }
85}
86
87/* Gives a new character its methods */
107
108/* Puts the player or a follower on GAME.playerDepth's layer, or on layer 4 and
109 back to it when the temporary flags are cleared */
110static inline void takePartyDepth(Actor *actor) {
111 if (GAME.clearTempFlags) {
112 actor->depth = 4;
113 GAME.playerDepth = 4;
114 } else {
115 actor->depth = GAME.playerDepth;
116 }
117}
118
119/*
120 * Creates a character (FIELD_TASK_ACTOR): key1 is the character, key2 its
121 * kind (0 the player, 2 to 8 a follower, the others the map's characters).
122 *
123 * The match depends on kind holding getModeArg's result in the player's
124 * branch, where kind is no longer needed: its second set keeps local-alloc
125 * from doubling its live length, which puts it before the constant 1 in the
126 * global allocator (the European version matches either way).
127 */
130 s32 keepsDir;
131
132 setActorMethods(actor);
133 actor->key1 = key1;
134 actor->key2 = kind;
136 actor->animFile = FIELDSTG_state.getFileEntry(key1);
137 actor->halfWidth = FIELDSTG_state.getActorWidth(key1) >> 1;
138 actor->animSet = ACTOR_ANIM_STAND;
139 actor->dir = 1;
140 actor->image = &FIELDSTG_state.images.actors[image + 2];
142 FILE_CACHE.request(actor->animFile >> 16);
143#if PAL_VIDEO
144 if (NTSC_MODE) {
145 actor->speed = 0x400;
146 } else {
147 actor->speed = 0x4CC;
148 }
149#else
150 actor->speed = 0x400;
151#endif
152 if (key1 == 0x146) {
153 actor->speed /= 2;
154 }
155 actor->voice = -1;
156 actor->depth = 4;
157 if (kind == 0) {
158 if (key1 == 0x147) {
160 if (GAME.clearTempFlags) {
161 actor->z = 0x3000;
162 } else {
163 actor->z = GAME.flightZ;
164 }
165 actor->flying = 1;
166 } else {
168 }
169 kind = GAME.funcs.getModeArg();
170 if (kind != -1) {
171 actor->pos = FIELDSTG_state.start;
172 actor->dir = FIELDSTG_state.startDir;
173 } else {
176 }
177 actor->tile.x = actor->pos.x >> 8;
178 actor->tile.y = actor->pos.y >> 8;
179 takePartyDepth(actor);
180 } else if (kind & 0xE) {
181 actor->trail = HEAP.allocZeroed(sizeof(Trail), 2);
183 if (kind == 2) {
184 actor->trail->tail = 0x37;
185 } else if (kind == 4) {
186 actor->trail->tail = 0x2E;
187 } else {
188 actor->trail->tail = 0x25;
189 }
190 takePartyDepth(actor);
191 } else {
192 keepsDir = key1 == 0x28;
193 if (key1 == 0x29) {
194 keepsDir = 1;
195 }
196 if (key1 == 0x2A) {
197 keepsDir = 1;
198 }
199 if (key1 == 0x3E) {
200 keepsDir = 1;
201 }
202 if (key1 == 0x11A) {
203 keepsDir = 1;
204 }
205 actor->keepsDir = keepsDir;
206 actor->hasShadow = 1;
207 if (key1 == 0x82) {
208 actor->hasShadow = 0;
209 }
210 if (key1 == 0x83) {
211 actor->hasShadow = 0;
212 }
213 if (key1 == 0x11F) {
214 actor->hasShadow = 0;
215 }
216 if (key1 == 0x13C) {
217 actor->hasShadow = 0;
218 }
219 if (key1 == 0x13F) {
220 actor->hasShadow = 0;
221 }
222 if (key1 == 0xD5) {
223 actor->hasShadow = 0;
224 }
225 actor->entry = entry;
226 }
227 return actor;
228}
void FIELDSTG_followLeader(Actor *actor)
A partner's control: records the leader's steps in the trail while it moves, and follows them.
void FIELDSTG_warpActor(Actor *actor, SlotDest *dest, s32 kind)
Warps the player (SLOT_WARP0 and SLOT_WARP1): the field task plays the warp's effect and cutscene of ...
void FIELDSTG_controlFlight(Actor *actor)
The player's flight: it rises unless triangle is held (ACTOR_FLY), left and right turn,...
void FIELDSTG_drawActor(void *data, void *drawLayer)
The layer's sorted callback that draws an actor: its frame from its image, mirrored for the direction...
void FIELDSTG_startActorGauge(Actor *actor, s32 dir, Vec2 offset)
Starts the gauge game at an offset from an actor, turning the partners its way.
void FIELDSTG_setActorPose(Actor *actor, s32 set, s32 dir)
Puts an actor in an event's pose: an animation set and a direction (ACTOR_POSED)
void FIELDSTG_startDrop(Actor *actor, s32 dir, Vec2 pos, s32 height)
Starts a drop from a ledge of height.
void FIELDSTG_runActorAction(Actor *actor, ActorChildren *children)
Runs an actor's action, its substate (ACTOR_STAND...): the walks, the climbs and the drop from ACTOR_...
void FIELDSTG_drainTrail(Actor *actor)
A follower's update while its trail runs out: it finds the leader (FIELD_TASK_ACTOR) if it has none,...
void FIELDSTG_launchActor(Actor *actor, SlotDest *dest)
Sends the player flying to the tile at dest from the nearest launcher (FIELDSTG_createLaunch)
void FIELDSTG_resetActorControl(Actor *actor)
Gives an actor its kind's control back: the pad for the player, none for kind 1, the trail for the pa...
void FIELDSTG_walkActorInDir(Actor *actor, s32 dir)
Walks an actor out through an exit, in a direction (ACTOR_WALK_OUT)
void FIELDSTG_startActorSlide(Actor *actor, s32 dir)
Starts an actor sliding in a direction (SLOT_SLIDE)
s32 FIELDSTG_isActorWalking(Actor *actor)
Whether an actor is still walking to its goal.
void FIELDSTG_startClimbDown(Actor *actor, s32 dir, s32 x, s32 y, s32 height)
Starts the climb down a wall of height from its top, at (x, y)
void FIELDSTG_startActorWalk(Actor *actor)
Starts an actor walking to its goal.
void FIELDSTG_setActorAnim(Actor *actor, s32 set)
Starts an actor's animation set from its first frame.
void FIELDSTG_controlPlayer(Actor *actor)
The player's update while it walks (Actor.control) when no menu, event or transition is running: the ...
void FIELDSTG_setActorDir(Actor *actor, s32 dir)
Turns an actor to a direction.
void FIELDSTG_animateActor(Actor *actor)
Plays an actor's animation: when its set (animSet) changes, it loads the set's animations for the fiv...
s32 FIELDSTG_isActorAnimDone(Actor *actor)
Whether an actor's animation has played to its end.
void FIELDSTG_startClimbUp(Actor *actor, s32 dir, s32 x, s32 y, s32 height)
The climbs (SLOT_CLIMB_UP and SLOT_CLIMB_DOWN) and the drop (SLOT_DROP): the actor goes onto the wall...
void FIELDSTG_stopActorSlide(Actor *actor)
Stops a sliding actor (SLOT_STOP_SLIDE)
void FIELDSTG_setActorGoal(Actor *actor, s32 x, s32 y, s32 dir)
Sets the tile an actor walks to and the direction it ends facing (FIELDSTG_walkToGoal)
ActorIcon * FIELDSTG_createActorIcon(Actor *actor)
Creates the player's icon, in the modes before MODE_NEW_GAME only.
Definition actor_icon.c:94
#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
s32 NTSC_MODE
The European version runs at 50 Hz (PAL) unless NTSC_MODE is set; its clocks then advance 0x133,...
Definition eu_settings.c:14
void FIELDSTG_resumePartners(void)
Makes the partners follow the player again (FIELDSTG_followLeader)
Definition actor.c:20
Actor * FIELDSTG_createActor(s32 key1, s32 kind, s32 image, FieldActorEntry *entry)
Creates a character (FIELD_TASK_ACTOR): key1 is the character, key2 its kind (0 the player,...
Definition actor.c:128
void FIELDSTG_updateActor(Actor *actor, ActorChildren *children)
An actor's update: waits for its animation file (and gives the player its icon), then runs its contro...
Definition actor.c:43
static void takePartyDepth(Actor *actor)
Puts the player or a follower on GAME.playerDepth's layer, or on layer 4 and back to it when the temp...
Definition actor.c:110
void FIELDSTG_getFacingTile(Actor *actor, Vec2 *out)
The tile in front of an actor, one step in its direction.
Definition actor.c:33
void FIELDSTG_haltPartners(void)
Makes the partners stop following: each walks out the rest of its trail (FIELDSTG_drainTrail)
Definition actor.c:7
static void setActorMethods(Actor *actor)
Gives a new character its methods.
Definition actor.c:88
#define FIELD_LAYER_MAP
the map, its objects and characters, and the menus
Definition field_map.h:20
#define FIELD_TASK_ACTOR
every character (FIELDSTG_createActor)
Definition field_map.h:26
FIELDSTG.PRO: the field mode, where the player walks around the map.
#define ACTOR_ANIM_STAND
The animation sets that the actions play (FIELDSTG_setActorAnim), by the substate that plays them.
Definition field_mode.h:80
#define SOUND_SUB_MOVE
held
Definition field_mode.h:71
s32 FIELDSTG_haltedPartners[]
Definition fieldstg.c:2107
s32 FIELDSTG_followingPartners[]
Definition fieldstg.c:2110
Vec2 FIELDSTG_dirSteps[]
tile offset of each direction
Definition fieldstg.c:2113
FieldState FIELDSTG_state
Definition fieldstg.c:2641
FileCache FILE_CACHE
The file cache.
Definition file_cache.c:7
Heap HEAP
The functions that return what a call left in v0 (allocMemHigh, findTask) and the ones that take othe...
Definition heap.c:184
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
The children of an actor (FIELDSTG_updateActor)
Definition field_mode.h:141
struct ActorIcon * icon
FIELDSTG_createActorIcon's.
Definition field_mode.h:142
A character on the field (FIELDSTG_createActor): the player (kind 0) and the other characters.
Definition field_map.h:334
s32 keepsDir
doesn't turn to the one who talks to it (characters 0x28-0x2A, 0x3E and 0x11A)
Definition field_map.h:373
s32 animSet
the animation set it plays (setAnim)
Definition field_map.h:354
void(* walkInDir)(struct Actor *, s32 dir)
Definition field_map.h:378
s32 z
how high it is off the ground, in 1/256 pixels (drawn that much higher)
Definition field_map.h:339
void(* setGoal)(struct Actor *, s32, s32, s32)
Definition field_map.h:390
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
struct ActorImage * image
Definition field_map.h:341
void(* startWalk)(struct Actor *)
Definition field_map.h:386
s32 depth
the layer's ordering table entry
Definition field_map.h:344
struct Trail * trail
a follower's: the leader's steps
Definition field_map.h:375
void(* getFacingTile)(struct Actor *, Vec2 *out)
Definition field_map.h:394
void(* launch)(struct Actor *, SlotDest *dest)
Definition field_map.h:397
s16 voice
a sound voice, or -1
Definition field_map.h:360
s32(* isAnimDone)(struct Actor *)
Definition field_map.h:389
s32 flying
the flying player (FIELDSTG_controlFlight)
Definition field_map.h:347
Vec2 pos
Definition field_map.h:336
s32 climbHeight
how high it has climbed, in 1/256 pixels (its shadow stays below)
Definition field_map.h:350
void(* playGauge)()
Definition field_map.h:382
s32(* isWalking)(struct Actor *)
Definition field_map.h:391
Vec2 tile
Definition field_map.h:337
void(* startSlide)(struct Actor *, s32 dir)
Definition field_map.h:395
s32 animFile
its animations' file and index (FIELDSTG_fileEntries), or 0
Definition field_map.h:353
struct FieldImage * fieldImage
the field's image, for the shadow
Definition field_map.h:342
void(* resetControl)(struct Actor *)
Definition field_map.h:387
s32 halfWidth
half its width (FIELDSTG_actorWidths): its box's half width, and half that its half height
Definition field_map.h:346
void(* setPose)(struct Actor *, s32, s32 dir)
Definition field_map.h:393
s32 dir
Definition field_map.h:338
s32 key2
Definition field_map.h:335
void(* control)(struct Actor *)
its update by kind, or NULL (resetControl)
Definition field_map.h:376
s32 key1
Definition field_map.h:335
s32 hasShadow
drawn with a shadow
Definition field_map.h:343
void(* nextState)(struct Actor *task)
Definition field_map.h:335
s32 state
Definition field_map.h:335
void(* setDir)(struct Actor *, s32 dir)
Definition field_map.h:388
s32 speed
0x400, 0x4CC in PAL's 50 Hz
Definition field_map.h:340
void(* stopSlide)(struct Actor *)
Definition field_map.h:396
void(* climbUp)()
Definition field_map.h:379
struct FieldActorEntry * entry
what created it, or NULL
Definition field_map.h:345
void(* setAnim)(struct Actor *, s32)
Definition field_map.h:392
A character of the field (FieldState.actors, a list of pointers up to NULL), which FIELDSTG_updateFie...
Definition field_map.h:194
s32 frozen
no control, triggers or encounters for the player: while the area name banner shows (FIELDSTG_createB...
Definition field_map.h:466
s32 defaultStartDir
and its direction
Definition field_map.h:472
Vec2 start
where the player starts
Definition field_map.h:456
ActorImage * actors
then the actors', from actors[2]
Definition field_map.h:454
s32(* getFileEntry)(s32 character)
FIELDSTG_fileEntries's.
Definition field_map.h:474
s32(* getActorWidth)(s32 character)
FIELDSTG_actorWidths's.
Definition field_map.h:475
s32 startDir
and its direction
Definition field_map.h:457
Vec2 defaultStart
where the player starts without a mode argument
Definition field_map.h:471
union FieldState::@12 images
FieldImage * field
the field's image (the first two ActorImages)
Definition field_map.h:453
s32(* isLoading)(s32 file)
Definition file.h:88
void(* request)(s32 file)
Definition file.h:90
s32(* getModeArg)()
Definition game_state.h:20
s32 clearTempFlags
Definition game_state.h:573
s32 playerDepth
Definition game_state.h:577
GameFuncs funcs
Definition game_state.h:582
struct Layer *(* getLayer)(s32 id)
Definition gfx.h:28
GfxFuncs funcs
Definition gfx.h:77
void *(* allocZeroed)(s32 size, s32 tag)
Definition heap.h:31
void(* free)(void *ptr)
Definition heap.h:27
A drawing layer (GFX.funcs.createLayer): a DRAWENV with a pair of ordering tables,...
Definition gfx.h:128
void(* addSortedCallback)()
Definition gfx.h:160
void(* keyOff)(s32 id, s16 voice)
Definition sound.h:189
void *(* find)(s32 id, s32 key1, s32 key2)
Definition task.h:18
TaskFuncs funcs
Definition task.h:76
s32 tail
Definition field_mode.h:136
Definition gfx.h:352
s32 y
Definition gfx.h:354
s32 x
Definition gfx.h:353
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