src/field/field_engine_encounter.c
Random encounters, and each scene's music, area name and battle background. More…
Included by field_engine.c.
Macros
| Name | Description | |
|---|---|---|
#define | JENNA_ENCOUNTERS_EXPERIENCE_MAX 130 | With Jenna in the party, random battles stop once her experience is past this. |
#define | BATTLE_BACKGROUND_RULE 0x80000000 | A battle background rule's word (battle_background_rules.c's BATTLE_BACKGROUND): bit 31 marks a battle background, its resource id below; any other word is a scene. |
#define | BATTLE_BACKGROUND_RULE_RESOURCE 0xffff | |
#define | ENCOUNTER_ZONE_HALFWORDS | A ENCOUNTER_ZONE in halfwords, and where its formations start. |
#define | ENCOUNTER_ZONE_FORMATIONS |
Functions
| Name | Description | |
|---|---|---|
void | fdEncounterSelectMapZones (Sint32 useRules) | Chooses the current scene's encounter zones, one for each kind of ground the party can stand on (FieldStateWork->encounterZones, read by fdEncounterRollMapStep), from the first rule matching the scene and entrance. |
Sint32 | fdEncounterResolveWorldMapZoneAndBackdrop (void *pos) | Returns the World Map encounter zone for the ground at pos (0 for none), and chooses the battle background for its battle environment (MainRoutineStateWork.battleBg). |
Sint32 | fdEncounterCountStepsAndSelectFormation (Sint32 zone, FIXED steps) | Advances the encounter counter for zone and returns the formation to fight (a row of formations.c), or 0 for no battle. steps (16.16) scales how far the counter moves; a battle starts once it reaches encounterThreshold. |
Sint32 | fdEncounterRollMapStep (Uint32 terrain, FIXED steps) | Rolls a random battle on the encounter zone of the ground underfoot. terrain: the ground, an index into state->encounterZones: 0 for ordinary ground, 1 and 2 for METATILE_BEHAVIOR_ENCOUNTER_GROUND_A and _B metatiles. steps: the step weight, passed on to fdEncounterCountStepsAndSelectFormation. |
Sint32 | fdEncounterRollWorldMap (Sint32 pos, FIXED steps) | Rolls a random battle on the World Map, taking the zone from the metatile at pos. |
Uint16 | fdEncounterGetFormationAtSlot (Sint32 zone, Sint32 slot) | Returns the formation in slot (0 to 7) of zone, read from EncounterZones as halfwords. |
Sint16 | fdEncounterGetDjinnFormation (Sint32 djinni) | Returns the formation of Djinni battle djinni, which the table gives as a zone and slot. |
void | fdChooseMusic (void) | Chooses the current scene's field music (MainRoutineStateWork.sound) from the first rule matching the scene or its area and the entrance; SOUND_KEEP_BGM when none does. |
Sint32 | fdAreaGetNameIndex (Sint32 sceneId, Sint32 entrance) | Returns the area name of sceneId and entrance, from the first rule matching the scene or its area; 0, the Title's name, when none does. |
void | fdSetRestartPoint (void) | Sets the scene the party returns to after a defeat (MainRoutineStateWork.restartScene and restartEntrance), from the first rule of SceneRestartRules that matches the current scene and entrance: {scene, entrance (-1 for any), return scene, return entrance}, ended by scene -1. |
Sint16 | fdBattleBackgroundGetSelected (void) | Returns the battle background chosen for the current scene. |
void | fdBattleBackgroundSelectForMap (void) | Chooses the battle background for the current scene. |
void | fdBattleBackgroundSelectForEnvironment (Sint32 environment) | Chooses the battle background for a World Map battle environment (enum BATTLE_ENVIRONMENT; any other gives Sol Sanctum's) and sets MainRoutineStateWork.battleBg. |
void | fdEncounterSelectBattleMusic (Sint32 zone, Sint32 slot) | Chooses the battle music for slot of zone (MainRoutineStateWork.battleMusic). |
Description
Random encounters, and each scene's music, area name and battle background.
Part of field_engine.c.
Macros in detail
JENNA_ENCOUNTERS_EXPERIENCE_MAX
#define JENNA_ENCOUNTERS_EXPERIENCE_MAX 130
With Jenna in the party, random battles stop once her experience is past this.
Referenced by fdEncounterCountStepsAndSelectFormation().
Definition at line 90 of file field_engine_encounter.c.
BATTLE_BACKGROUND_RULE
#define BATTLE_BACKGROUND_RULE 0x80000000
A battle background rule's word (battle_background_rules.c's
BATTLE_BACKGROUND): bit 31 marks a battle background, its resource id below;
any other word is a scene.
Referenced by fdBattleBackgroundSelectForMap().
Definition at line 94 of file field_engine_encounter.c.
BATTLE_BACKGROUND_RULE_RESOURCE
#define BATTLE_BACKGROUND_RULE_RESOURCE 0xffff
Referenced by fdBattleBackgroundSelectForMap().
Definition at line 95 of file field_engine_encounter.c.
ENCOUNTER_ZONE_HALFWORDS
#define ENCOUNTER_ZONE_HALFWORDS
A ENCOUNTER_ZONE in halfwords, and where its formations start.
Referenced by fdEncounterGetFormationAtSlot().
Definition at line 221 of file field_engine_encounter.c.
ENCOUNTER_ZONE_FORMATIONS
#define ENCOUNTER_ZONE_FORMATIONS
Referenced by fdEncounterGetFormationAtSlot().
Definition at line 223 of file field_engine_encounter.c.
Functions in detail
fdEncounterSelectMapZones
void fdEncounterSelectMapZones(Sint32 useRules)
Chooses the current scene's encounter zones, one for each kind of ground the
party can stand on (FieldStateWork->encounterZones, read by
fdEncounterRollMapStep), from the first rule matching the scene and entrance.
References fdBattleBackgroundSelectForMap(), gmFlagGetStub(), MainRoutineStateWork, SceneEncounterRules, Sint32 and state.
Referenced by fdEngineRun().
Definition at line 9 of file field_engine_encounter.c.
fdEncounterResolveWorldMapZoneAndBackdrop
Sint32 fdEncounterResolveWorldMapZoneAndBackdrop(void *pos)
Returns the World Map encounter zone for the ground at pos (0 for none), and
chooses the battle background for its battle environment
(MainRoutineStateWork.battleBg).
References fdBattleBackgroundSelectForEnvironment(), fdWorldMapGetBattleEnvironmentStub(), gmFlagGetStub(), Sint32 and WorldMapEncounterRules.
Referenced by fdEncounterRollWorldMap(), fdRequestBattleFromEncounterTable() and fdRequestDjinnBattle().
Definition at line 67 of file field_engine_encounter.c.
fdEncounterCountStepsAndSelectFormation
Sint32 fdEncounterCountStepsAndSelectFormation(Sint32 zone, FIXED steps)
Advances the encounter counter for zone and returns the formation to fight (a
row of formations.c), or 0 for no battle. steps (16.16) scales how far the
counter moves; a battle starts once it reaches encounterThreshold.
References EncounterZones, fdEncounterSelectBattleMusic(), gmFlagGetStub(), gmPartyGetAverageLevelStub(), gmUnitGetStub(), MainRoutineStateWork, Sint32, state, syDivFX(), syMulFX() and syRandom().
Referenced by fdEncounterRollMapStep() and fdEncounterRollWorldMap().
Definition at line 100 of file field_engine_encounter.c.
fdEncounterRollMapStep
Sint32 fdEncounterRollMapStep(Uint32 terrain, FIXED steps)
Rolls a random battle on the encounter zone of the ground underfoot. terrain:
the ground, an index into state->encounterZones: 0 for ordinary ground, 1 and
2 for METATILE_BEHAVIOR_ENCOUNTER_GROUND_A and _B metatiles. steps: the step
weight, passed on to fdEncounterCountStepsAndSelectFormation.
References fdEncounterCountStepsAndSelectFormation() and Sint32.
Referenced by fdUpdateWalking().
Definition at line 204 of file field_engine_encounter.c.
fdEncounterRollWorldMap
Sint32 fdEncounterRollWorldMap(Sint32 pos, FIXED steps)
Rolls a random battle on the World Map, taking the zone from the metatile at pos. Returns the formation to fight, or 0 for no battle.
References fdEncounterCountStepsAndSelectFormation(), fdEncounterResolveWorldMapZoneAndBackdrop() and Sint32.
Referenced by fdUpdateWalking().
Definition at line 214 of file field_engine_encounter.c.
fdEncounterGetFormationAtSlot
Uint16 fdEncounterGetFormationAtSlot(Sint32 zone, Sint32 slot)
Returns the formation in slot (0 to 7) of zone, read from EncounterZones as
halfwords.
References EncounterZones and Sint32.
Referenced by fdEncounterGetDjinnFormation(), fdExamineMetatile() and fdRequestBattleFromEncounterTable().
Definition at line 228 of file field_engine_encounter.c.
fdEncounterGetDjinnFormation
Sint16 fdEncounterGetDjinnFormation(Sint32 djinni)
Returns the formation of Djinni battle djinni, which the table gives as a zone and slot.
References EncounterDjinnBattles, fdEncounterGetFormationAtSlot() and Sint32.
Referenced by fdRequestDjinnBattle().
Definition at line 236 of file field_engine_encounter.c.
fdChooseMusic
void fdChooseMusic(void)
Chooses the current scene's field music (MainRoutineStateWork.sound) from the
first rule matching the scene or its area and the entrance; SOUND_KEEP_BGM
when none does.
References gmFlagGetStub(), MainRoutineStateWork and SceneMusicRules.
Referenced by gmMainRoutineRun().
Definition at line 252 of file field_engine_encounter.c.
fdAreaGetNameIndex
Sint32 fdAreaGetNameIndex(Sint32 sceneId, Sint32 entrance)
Returns the area name of sceneId and entrance, from the first rule matching the scene or its area; 0, the Title's name, when none does.
References AreaNameRules, gmGetArea() and Sint32.
Referenced by fdMapScreenUpdateMarkers().
Definition at line 288 of file field_engine_encounter.c.
fdSetRestartPoint
void fdSetRestartPoint(void)
Sets the scene the party returns to after a defeat
(MainRoutineStateWork.restartScene and restartEntrance), from the first rule
of SceneRestartRules that matches the current scene and entrance: {scene,
entrance (-1 for any), return scene, return entrance}, ended by scene -1.
References MainRoutineStateWork and SceneRestartRules.
Referenced by fdEngineRun().
Definition at line 326 of file field_engine_encounter.c.
fdBattleBackgroundGetSelected
Sint16 fdBattleBackgroundGetSelected(void)
Returns the battle background chosen for the current scene.
References MainRoutineStateWork.
Definition at line 344 of file field_engine_encounter.c.
fdBattleBackgroundSelectForMap
void fdBattleBackgroundSelectForMap(void)
Chooses the battle background for the current scene.
SceneBattleBackgroundRules lists each battle background (a word with bit 31
set) followed by the scenes that use it, ended by 0; a scene takes the one
listed last before it, and a scene not listed takes the last one.
References MainRoutineStateWork, SceneBattleBackgroundRules and Sint32.
Referenced by fdEncounterSelectMapZones().
Definition at line 353 of file field_engine_encounter.c.
fdBattleBackgroundSelectForEnvironment
void fdBattleBackgroundSelectForEnvironment(Sint32 environment)
Chooses the battle background for a World Map battle environment (enum
BATTLE_ENVIRONMENT; any other gives Sol Sanctum's) and sets
MainRoutineStateWork.battleBg.
References MainRoutineStateWork and Sint32.
Referenced by fdEncounterResolveWorldMapZoneAndBackdrop().
Definition at line 375 of file field_engine_encounter.c.
fdEncounterSelectBattleMusic
void fdEncounterSelectBattleMusic(Sint32 zone, Sint32 slot)
Chooses the battle music for slot of zone (MainRoutineStateWork.battleMusic).
References EncounterBattleMusic, gmFlagGetStub(), MainRoutineStateWork and Sint32.
Referenced by fdEncounterCountStepsAndSelectFormation(), fdExamineMetatile(), fdRequestBattleFromEncounterTable() and fdRequestDjinnBattle().
Definition at line 404 of file field_engine_encounter.c.