Alchemy
Loading...
Searching...
No Matches

avoid.c

Go to the documentation of this file.
1/// @file
2/// Avoid.
3/// Part of psynergy_effects.c, compiled only through it.
4
6
7/// End of the effect: switches the caster's display flags between 3 and 1 on
8/// a 5-frame cycle. FieldFx_RunAvoid schedules it (order 0xc80) for its last
9/// 70 frames and removes it again.
11 struct ArcEffectObject *caster;
12 struct AnimationObject *rec;
13 struct AnimationEntry *entry;
14 s32 phase;
15
17 rec = caster->records;
18 entry = rec->entries[0];
19 phase = gFrameCount % 5;
20 if (phase == 0) {
21 rec->dirty = 1;
22 rec->flags = 3;
23 } else if (phase == 2) {
24 entry->param = 0; // restore its colours
25 rec->dirty = 1;
26 rec->flags = 1;
27 }
28}
29
30/// The caster during the effect: sheds a pair of falling arcs every 5 frames
31/// (7 on the world map), and spins in phase 1. FieldFx_RunAvoid makes it the
32/// caster's callback; it counts the caster's step and turns its angle.
34 struct ArcEffectObject *caster = (struct ArcEffectObject *)fieldObject;
35 s16 phase;
36 s32 elapsedFrames;
37
38 phase = caster->phase;
39 elapsedFrames = caster->step++;
40
42 if (elapsedFrames % 7 == 0)
44 } else if (elapsedFrames % 5 == 0) {
46 }
47
48 if (phase == 1)
49 caster->angle += 0xc00;
50}
51
52/// Avoid (or the Sacred Feather) has worn off, and the game says so.
53/// "Avoid's effects wore off." (or "Sacred Feather's ...").
54///
55/// Clears gGameState.avoidDistance. Reached through FieldEvent_RunTypeHandler
56/// when the Psynergy request the leader's steps raise as Avoid runs out
57/// (object/step.c) is handled.
60 if (gGameState.avoidByItem == 0) {
62 UiText_ShowPositionedMessageAndWaitFar(MsgAbilityWoreOff, 1);
63 return;
64 }
67}
68
69/// The caster spins and flashes, then blinks, and encounters are kept away
70/// until Avoid wears off.
71///
72/// Abilities: Avoid (field kind 16), and the Sacred Feather.
73///
74/// The caster spins shedding falling arcs and flashes 20 times, then blinks for
75/// 55 frames; encounters are kept away (avoidDistance 0x9600000) until it wears
76/// off, and the game says "Monsters won't attack so often now.". FLAG_ITEM_USE
77/// marks it as cast from the Sacred Feather.
78///
79/// Called by BattleFx_Run and BattleFx_DispatchRequestKind. Sets
80/// gGameState.avoidDistance and avoidByItem; the leader's steps count the
81/// distance down by their speed (object/step.c), 2,400 pixels in all.
82void FieldFx_RunAvoid(void) {
83 struct BattleFxScene *scene;
84 struct ArcEffectObject *object;
85 struct AnimationObject *group;
86 struct AnimationEntry *entry;
87 u32 angle;
88 s32 slot;
89 s32 count;
90
91 scene = gEffectWork;
92 object = scene->mainObject;
93 group = object->records;
94 entry = group->entries[0];
95 angle = object->angle;
97 {
98 s16 *tileSlot = &scene->arcTileSlot;
99 s32 zero = 0;
100
101 *tileSlot = slot;
103 gGameState.avoidDistance = 0x09600000;
105 Animation_ApplyChildValuesFar((struct DispatchObject *)object, zero);
106 object->callback = BattleFx_UpdatePairedArcSpawner;
107 object->phase = zero;
108 object->step = zero;
109 }
111 WaitFrames(15);
112 object->phase = 1;
113 WaitFrames(10);
114 // Flash white for 2 frames in every 5.
115 for (count = 0; count < 20; count++) {
116 entry->param = SPRITE_COLOR_WHITE;
117 group->dirty = 1;
118 WaitFrames(2);
119 group->dirty = 1;
120 entry->param = 0;
121 group->flags = 1;
122 WaitFrames(3);
123 }
124 object->callback = NULL;
125 object->angle = angle;
127 WaitFrames(15);
129 WaitFrames(55);
131 // Back to the caster's own look: flags 2 while Cloak is on, else 1.
132 if (gGameState.cloaked != 0)
134 else
138 UiText_ShowPositionedMessageAndWaitFar(MsgMonstersAttackLess, 1);
139}
@ ABILITY_AVOID
Definition ability_ids.h:25
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
void FieldFx_RunAvoid(void)
The caster spins and flashes, then blinks, and encounters are kept away until Avoid wears off.
Definition avoid.c:82
void FieldEvent_ShowStatusMessage(void)
Avoid (or the Sacred Feather) has worn off, and the game says so.
Definition avoid.c:58
void FieldFx_BlinkAvoidCaster(void)
End of the effect: switches the caster's display flags between 3 and 1 on a 5-frame cycle.
Definition avoid.c:10
void BattleFx_UpdatePairedArcSpawner(union FieldObject *fieldObject)
The caster during the effect: sheds a pair of falling arcs every 5 frames (7 on the world map),...
Definition avoid.c:33
const u8 gBattleFx_ArcSparkTiles[]
void ObjectDispatch_SetSingleChildFlagsFar(struct DispatchObject *obj, u32 flags)
void Animation_ApplyChildValuesFar(struct DispatchObject *obj, u32 val)
s32 GameFlag_TestFar(s32 flag)
void AudioCommand_PlayFar(s32 id)
void UiText_ShowPositionedMessageAndWaitFar(s32 no, s32 flags)
void UiWork_PushValueSlotFar(u32 value, u32 kind)
#define FLAG_ITEM_USE
the Psynergy comes from an item
Definition flags.h:56
void WaitFrames(s32 frames)
The game's frame loop: runs frames frames and returns.
Definition frame.c:97
volatile u32 gFrameCount
Frames WaitFrames has finished.
struct GameState gGameState
void * gEffectWork
Slot 56: points to a scene-specific structure.
@ ITEM_SACRED_FEATHER
Definition item_ids.h:77
What every part of psynergy_effects.c shares: its includes and the macros and types more than one par...
void BattleFx_SpawnDescendingArcParticles(struct FieldActor *arc)
Spawns a pair of falling arcs (one upside down) on arc.
Definition retreat.c:254
char SceneId_Clear
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_174
Definition songs.h:169
#define SE_140
Definition songs.h:133
#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
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
A field object as Avoid's caster: its facing, its animation records and the phase and frame count of ...
Definition fx_scene.h:17
s16 phase
1 spins the caster 0xc00 a frame
Definition fx_scene.h:23
struct AnimationObject * records
the caster's sprite
Definition fx_scene.h:21
s16 step
frames since the arcs started
Definition fx_scene.h:24
u16 angle
1/65536 turns
Definition fx_scene.h:19
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
s16 arcTileSlot
resource entry of Avoid's and Retreat's arcs
Definition fx_scene.h:75
void * mainObject
the caster's object
Definition fx_scene.h:36
A field object as the object dispatcher's far calls take it.
A field actor: a person or thing on the field with a position, motion toward a target,...
Definition field_obj.h:30
s16 cloaked
1 under Cloak, which prevents battles
Definition game_state.h:114
s16 map
the scene's map; SceneId_Clear for the world map
Definition game_state.h:49
s32 avoidDistance
distance left of Avoid, 16.16 pixels; 0 when off
Definition game_state.h:110
s8 avoidByItem
Avoid came from an item (the Sacred Feather).
Definition game_state.h:111
s32 selectedActor
the leader: its unit and its actor
Definition game_state.h:59
signed int s32
Definition types.h:14
unsigned int u32
Definition types.h:15
signed short s16
Definition types.h:12
An object on the field, read as an actor or as an effect.
s32 Resource_ResetEntry(u32 no)
Frees cache entry no: its blocks go back and the entry is marked free (offset 0xffff).
Definition vram_cache.c:106
s32 Resource_FindFreeEntry(void)
Returns the number of the first free cache entry, or VRAM_CACHE_ENTRY_COUNT when all are taken.
Definition vram_cache.c:211
s32 VramCache_Load(u32 no, u32 size, const void *src)
Gives cache entry no size bytes of sprite VRAM and copies src there.
Definition vram_cache.c:143