Alchemy
Loading...
Searching...
No Matches

reveal.c

Go to the documentation of this file.
1/// @file
2/// Reveal.
3/// Part of psynergy_effects.c, compiled only through it.
4
6
7/// Passes value (as animation timer steps) to every one of the 64 objects
8/// whose first sprite part shows sprite 200.
10 struct ObjectRuntime *object = gObjectSlots;
11 s32 remainingActors = 63;
12
13 do {
14 if (object->script != NULL) {
15 u8 kind = object->animationKind;
16
17 if (kind == 1) {
18 struct AnimationObject *animation = object->animation;
19 struct AnimationEntry *entry = animation->entries[0];
20
21 if (entry->animId == 200) {
22 entry->param = value;
23 animation->dirty = kind;
24 }
25 }
26 }
27 remainingActors--;
28 object++;
29 } while (remainingActors >= 0);
30}
31
32/// Scheduler callback of the timed effect (kind 8): asks for it to end once
33/// the leader is 60 pixels from its centre or its time has run out. The
34/// centre and the time are in the event work from 0xcb8 on
35/// (FieldFx_RunReveal).
37 struct FieldWork *work;
38 struct ObjectRuntime *actor;
39 s16 *timer;
40 s32 distanceX;
41 s32 distanceZ;
42
43 work = (struct FieldWork *)gEventWork;
45 if (work->effectTimerRunning != 0) {
46 timer = &work->revealFrames;
47 if (*timer != 0)
48 (*timer)--;
49 }
50
51 // x is scaled by 0xd105 (about 0.82) for the comparison.
52 distanceX = Iwram_MulQ16(work->revealCenterX - actor->x / 0x10000, 0xd105);
53 distanceZ = work->revealCenterY - (actor->z - actor->y) / 0x10000;
54 if (distanceX * distanceX + distanceZ * distanceZ >= 3600 ||
55 work->revealFrames == 0) {
56 u16 *slot = (u16 *)&work->command; // psynergyRequest
57 u32 request = 0x2090;
58
59 *slot = request;
60 }
61}
62
63/// Starts a screen transition centred on the leader, runs the matching event if
64/// there is one, and puts markers round the leader.
65///
66/// Abilities: Reveal (field kind 8).
68 struct FieldWork *field;
69 struct DisplayTransitionState *transition;
70 struct FieldActor *target;
71 s32 eventTarget;
72 void *event;
73 s32 frame;
74
78 transition = WORK_SLOT(HEAP_SLOT_TRANSITION);
80 transition->centreX = target->x.fixed;
81 transition->centreY = target->z.fixed - target->y.fixed;
85 // Not in the English release.
86#if !(TBS_PATCH_1 && !TBS_PATCH_2)
87 field->revealActive = 0;
88#endif
89 WaitFrames(1);
90 event = BattleFx_FindMatchingEvent(0x50000005, 8, &eventTarget);
91 if (event != NULL)
94
95 // Record the centre (in pixels) and the time in the event work, and put
96 // markers nearby.
97 field->revealActive = 1;
98 field->revealCenterX = transition->centreX / 0x10000;
99 field->revealCenterY = transition->centreY / 0x10000;
100 field->revealFrames = 600;
101 field->effectTimerRunning = 1;
103 frame = 0;
104 do {
105 WaitFrames(1);
106 transition->value = frame;
107 frame++;
108 } while (frame <= 18);
110}
111
112#define REVEAL_END_EVENT 0x40000005 ///< Psynergy event, stage 4
113
114/// Ends Reveal if it is running: stops its watch, brings the colours back
115/// from black over 30 frames and runs stage 4 of the Psynergy event.
117#ifdef UBFIX
118 struct BattleFxScene *work = gEffectWork;
120 struct FieldWork *state = (struct FieldWork *)gEventWork;
121#else
122 // Named slots avoid stepping outside gEffectWork. They add 8 bytes to this
123 // function in the forced native EN build (0xe8 -> 0xf0).
124 struct BattleFxScene **cell = &gEffectWork;
125 struct BattleFxScene *work = *cell;
126 struct DisplayTransitionState *scene =
127 *(struct DisplayTransitionState **)((u8 *)cell - 0x64);
128 struct FieldWork *state = *(struct FieldWork **)((u8 *)cell - 0x74);
129#endif
130 s16 zero;
131 s32 eventTarget;
132 void *event;
133
134 if (state->revealActive != 0) {
137
138 zero = 0;
139 state->revealActive = zero;
140 state->revealFrames = zero;
142
148 WaitFrames(1);
149
151 &eventTarget);
152 if (event != NULL)
154
155 if (work->childOption == 0) {
156 scene->nextMode = 0;
157 scene->duration = 1;
158 scene->step = 1;
159 WaitFrames(10);
160 }
161 }
162}
163
164#undef REVEAL_END_EVENT
void * ObjectTable_Get(u32 actorIndex)
Returns the actor in slot index (0 to 65), or NULL.
Definition actors.c:462
void BattleFx_ApplyColorToTargetBuffer(s32 mode, s32 half)
Sets the colours the buffer moves toward (see BattleFx_BuildBuffer); does nothing without a colour bu...
Definition color.c:398
void BattleFx_StartBufferInterpolation(s32 frames)
Starts moving the shown colours to the target colours over frames frames: sets work->duration,...
Definition color.c:431
void BattleFx_ApplyColorToSourceBuffer(s32 mode, s32 half)
Sets the colours the buffer shows now (see BattleFx_BuildBuffer).
Definition color.c:409
void AudioCommand_PlayFar(s32 id)
void FieldEffect_SpawnNearbyMarkers(void)
Reveal: marks with sparkles the hidden things within 8 cells left or right and 5 up or down of the le...
Definition field_fx.c:380
void WaitFrames(s32 frames)
The game's frame loop: runs frames frames and returns.
Definition frame.c:97
struct GameState gGameState
struct DisplayTransitionState * gDisplayTransition
Slot 31.
void * gEffectWork
Slot 56: points to a scene-specific structure.
@ HEAP_SLOT_TRANSITION
Definition heap_state.h:41
@ HEAP_SLOT_EVENT
Definition heap_state.h:40
#define WORK_SLOT(n)
Reads slots through their own addresses; adjacent slots are reached by offsets.
Definition heap_state.h:14
void * BattleFx_FindMatchingEvent(s32 eventFlags, s32 group, void *target)
Returns the scene's Psynergy event (kind 5) for Psynergy of the given group that applies to what the ...
Definition items.c:206
#define Iwram_MulQ16(left, right)
Definition iwram_call.h:127
void DisplayTransition_InitializeBattleEffectState(s32 mode)
Starts window transition mode at value 0, with no duration: the caller moves it.
Definition transition.c:559
s32 Field_RunEventAction(const void *event, s32 param, s32 target)
Runs the event tied to an effect: a result below 0x10000 is a message, shown at target; a larger one ...
Definition dispatch.c:242
@ PALETTE_TRANSFORM_PLAIN
each colour unchanged
Definition palbuf.h:72
@ FIELD_KIND_REVEAL
What every part of psynergy_effects.c shares: its includes and the macros and types more than one par...
void FieldEffect_WatchLeaderDistance(void)
Scheduler callback of the timed effect (kind 8): asks for it to end once the leader is 60 pixels from...
Definition reveal.c:36
void FieldFx_RunReveal(void)
Starts a screen transition centred on the leader, runs the matching event if there is one,...
Definition reveal.c:67
void ResetSceneTransitionEffect(void)
Ends Reveal if it is running: stops its watch, brings the colours back from black over 30 frames and ...
Definition reveal.c:116
#define REVEAL_END_EVENT
Psynergy event, stage 4.
Definition reveal.c:112
void ObjectDispatch_ApplyValueToKind200Children(s32 value)
Passes value (as animation timer steps) to every one of the 64 objects whose first sprite part shows ...
Definition reveal.c:9
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_SCENE_TRANSITION
Definition songs.h:162
#define SE_131
Definition songs.h:124
struct EventWork * gEventWork
#define NULL
Definition bilibin.h:6
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
u8 kind
The facing table its frames follow (from the metadata, or ANIM_CMD_SET_KIND); zero marks a free layer...
Definition animspr.h:44
s16 animId
the sprite id whose metadata and frames it uses
Definition animspr.h:38
An animated sprite: its image and shadow, scale, rotation, size and up to four animation layers.
Definition animspr.h:108
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
The work of a Psynergy effect scene: its caster and target, where it takes place, the map state it re...
Definition fx_scene.h:31
s8 childOption
Set by some scenes before an effect; Carry, Frost, Force and Reveal treat the target differently with...
Definition fx_scene.h:52
The display transition state (heap block 31): two pages of window edges for every line,...
u16 value
The progress, moved from start to end over duration frames: bit 5 says whether the transition opens o...
s8 nextMode
The mode taken when the value reaches its end; 0 ends the transition.
s32 centreX
16.16 fixed-point pixels: the centre of the ellipse around a point (mode 8), set by the Reveal effect...
s8 duration
frames; 0 when the value is not moving
s32 centreY
as centreX: the target's z less its y
A field actor: a person or thing on the field with a position, motion toward a target,...
Definition field_obj.h:30
union FieldCoordinate x
16.16 fixed-point pixels
Definition field_obj.h:35
union FieldCoordinate y
16.16 fixed-point pixels
Definition field_obj.h:36
union FieldCoordinate z
16.16 fixed-point pixels
Definition field_obj.h:37
Full event work allocated by Field_RunScene (heap slot 27).
s16 event
A raised event for Scene_RunRaisedEvent, or -1 when characters fell to poison or hazard damage,...
s16 command
a field Psynergy to use, as owner << 10 | Psynergy
s16 revealActive
nonzero while Reveal is active
s16 effectTimerRunning
Nonzero lets the Reveal countdown advance; menus and other effects pause it.
s16 revealCenterX
where Reveal was cast, in pixels
s16 revealFrames
the frames Reveal has left
s32 selectedActor
the leader: its unit and its actor
Definition game_state.h:59
One of the 64 field objects in the object pool (heap slot 5): its script, position,...
s32 z
16.16 fixed-point pixels
s32 * script
the object script it runs; null when the object is free
s32 x
16.16 fixed-point pixels
s32 y
16.16 fixed-point pixels
signed int s32
Definition types.h:14
unsigned int u32
Definition types.h:15
signed short s16
Definition types.h:12
unsigned short u16
Definition types.h:13
unsigned char u8
Definition types.h:11
s32 fixed
16.16 fixed-point pixels
struct ScriptMotionObject * gObjectSlots