Alchemy
Loading...
Searching...
No Matches

cloak.c

Go to the documentation of this file.
1/// @file
2/// Cloak.
3/// Part of psynergy_effects.c, compiled only through it.
4
6
7#define CLOAK_TILE 0xfb ///< the tile attribute Cloak can stay hidden on
8#define CLOAK_END 0x2092 ///< field command when Cloak can no longer hide
9
10/// Scheduler callback of Cloak: when the tile under the leader is not
11/// CLOAK_TILE, requests CLOAK_END. On the world map (event mode 3) it reads
12/// the 32-pixel gMapBlocks, elsewhere the 16-pixel terrain map.
14#ifndef UBFIX
15 u32 slot;
16#endif
17 struct FieldWork *field;
18 struct ObjectRuntime *leader;
19 u8 *tile;
20 s32 x;
21 s32 y;
22
23#ifndef UBFIX
24 slot = (u32)&gEventWork;
25#endif
26 field = (struct FieldWork *)gEventWork;
28#ifdef UBFIX
29 tile = gMapWork[0];
30#else
31 // The named map slot avoids reading outside gEventWork. It adds 4 bytes
32 // to this function in the forced native EN build (0xc0 -> 0xc4).
33 tile = (u8 *)*(struct MapState **)(slot - 76); // gMapWork[0]
34#endif
35
36 if (field->mode == MODE_WORLD_MAP) {
37 u32 tx;
38 u32 ty;
39
40 x = leader->x;
41 if (x < 0)
42 x += 0x1fffff;
43 tx = (x >> 21) & 31;
44
45 y = leader->z;
46 if (y < 0)
47 y += 0x1fffff;
48 ty = (y >> 21) & 31;
49
50 tile = (u8 *)gMapBlocks + ((tx + (ty << 5)) << 2);
51 } else {
52 if (leader->terrainId <= 2) {
53 tile = (u8 *)((struct MapState *)tile)->layers[leader->terrainId].cells;
54 } else
56
57 x = leader->x;
58 if (x < 0)
59 x += 0xfffff;
60 {
61 u32 tx = x >> 20;
62
63 y = leader->z;
64 if (y < 0)
65 y += 0xfffff;
66
67 tile = (u8 *)(tile + ((tx + ((y >> 20) << 7)) << 2));
68 }
69 }
70
71 if (tile[2] != CLOAK_TILE)
72 field->command = CLOAK_END;
73}
74
75/// Ends Cloak: stops the tile check and makes the leader blink back into
76/// sight, clearing cloaked.
77void FieldFx_EndCloak(void) {
78 struct ObjectRuntime *obj;
79 struct AnimationObject *anim;
80 struct AnimationEntry *entry;
81 u32 i;
82
84 anim = obj->animation;
85 entry = anim->entries[0];
86
90 ((struct ScriptMotionObject *)obj)->hook = 0;
91
92 for (i = 0; i < 5; ++i) {
94 anim->dirty = 1;
95 anim->flags = 2;
96 WaitFrames(2);
97 anim->dirty = 1;
98 anim->flags = 0;
99 WaitFrames(2);
100 }
101
102 for (i = 0; i < 5; ++i) {
103 entry->param = SPRITE_COLOR_WHITE;
104 anim->dirty = 1;
105 anim->flags = 0;
106 WaitFrames(2);
107 entry->param = 0;
108 anim->dirty = 1;
109 WaitFrames(2);
110 }
111
112 anim->flags = 1;
114}
115
116/// Starts the Cloak tile check if the leader is hidden.
118 if (gGameState.cloaked != 0) {
120 }
121}
122
123/// The leader blinks 10 times and hides (cloaked set), and the tile check
124/// starts; where the leader cannot hide it shows again at once.
125///
126/// Abilities: Cloak (field kind 10).
128 struct FieldWork *field = (struct FieldWork *)gEventWork;
130 struct AnimationObject *animation = leader->animation;
131 struct AnimationEntry *entry = animation->entries[0];
132 u32 n;
133 void (*check)(void);
134
137 ((struct ScriptMotionObject *)leader)->hook = 0;
138 n = 0;
139 do {
140 entry->param = SPRITE_COLOR_WHITE;
141 animation->dirty = 1;
142 animation->flags = 2;
143 WaitFrames(2);
144 animation->dirty = 1;
145 animation->flags = 0;
146 WaitFrames(2);
147 n++;
148 } while (n <= 9);
149 n = 0;
150 entry->param = n;
151 animation->flags = 2;
152 animation->dirty = 1;
154 Scheduler_AddOrUpdateCallback(check, 0xc80);
156 check();
157 if (field->command == CLOAK_END) {
159 field->command = n;
160 }
161}
162
163#undef CLOAK_TILE
164#undef CLOAK_END
void * ObjectTable_Get(u32 actorIndex)
Returns the actor in slot index (0 to 65), or NULL.
Definition actors.c:462
@ SPRITE_COLOR_WHITE
solid colour 15, white
Definition animspr.h:26
#define CLOAK_TILE
the tile attribute Cloak can stay hidden on
Definition cloak.c:7
void FieldFx_StartCloak(void)
The leader blinks 10 times and hides (cloaked set), and the tile check starts; where the leader canno...
Definition cloak.c:127
void FieldFx_ResumeCloakCheck(void)
Starts the Cloak tile check if the leader is hidden.
Definition cloak.c:117
#define CLOAK_END
field command when Cloak can no longer hide
Definition cloak.c:8
void FieldFx_EndCloak(void)
Ends Cloak: stops the tile check and makes the leader blink back into sight, clearing cloaked.
Definition cloak.c:77
void FieldFx_CheckCloakTile(void)
Scheduler callback of Cloak: when the tile under the leader is not CLOAK_TILE, requests CLOAK_END.
Definition cloak.c:13
void ObjectDispatch_SelectAnimationFar(void *raw, s32 no)
void AudioCommand_PlayFar(s32 id)
void WaitFrames(s32 frames)
The game's frame loop: runs frames frames and returns.
Definition frame.c:97
struct GameState gGameState
struct EffectStep gMapCellBuffer[]
Map cells; battle effects reuse this as a particle array.
void * gMapWork[]
u32 gMapBlocks[]
What every part of psynergy_effects.c shares: its includes and the macros and types more than one par...
s32 Scheduler_AddOrUpdateCallback(SchedulerCallback callback, s32 order)
Schedules callback with order, or gives a task already running it the new order, and re-sorts the tab...
Definition scheduler.c:102
s32 Scheduler_RemoveCallback(SchedulerCallback callback)
Unschedules the task running callback: clears its routine and gives it order 0x7fff,...
Definition scheduler.c:146
#define SE_CAST
Definition songs.h:149
#define SE_130
Definition songs.h:123
struct EventWork * gEventWork
One animation layer of a sprite: its animation id, frames, running script and timer.
Definition animspr.h:37
u8 param
SpriteColorMode its pixels are drawn with; 0 when taken.
Definition animspr.h:45
An animated sprite: its image and shadow, scale, rotation, size and up to four animation layers.
Definition animspr.h:108
u8 flags
bits: 1 outlined in ObjectSystemWork's edge and fill colours | 0 shadow drawn (set when created)
Definition animspr.h:128
struct AnimationEntry * entries[4]
its layers; empty ones null
Definition animspr.h:130
u8 dirty
nonzero redraws its pixels into VRAM when next drawn
Definition animspr.h:125
Full event work allocated by Field_RunScene (heap slot 27).
s16 command
a field Psynergy to use, as owner << 10 | Psynergy
s16 tile
a tile's collision code, for Field_SearchTile
s16 mode
MODE_WORLD_MAP (3) on the world map.
s16 cloaked
1 under Cloak, which prevents battles
Definition game_state.h:114
s32 selectedActor
the leader: its unit and its actor
Definition game_state.h:59
The map work in heap slot 8 (struct MapScrollWork), seen as its tile animation channels,...
Definition map.h:49
One of the 64 field objects in the object pool (heap slot 5): its script, position,...
s32 z
16.16 fixed-point pixels
void * animation
its sprite, or its list of four, by animationKind
s32 x
16.16 fixed-point pixels
s32 y
16.16 fixed-point pixels
u8 terrainId
the map layer its ground height is read from
A field object as the motion code sees it: its script, position, motion toward a target,...
void(*) hook(union FieldObject *object)
Called each frame before its script.
signed int s32
Definition types.h:14
unsigned int u32
Definition types.h:15
unsigned char u8
Definition types.h:11
#define MODE_WORLD_MAP
the world map
Definition object.h:78