Alchemy
Loading...
Searching...
No Matches

encounter.c File Reference

Random encounters, and each scene's music, place name and backdrop. More...

Go to the source code of this file.

Data Structures

struct  BattleLocationRule
 A field scene's encounter zones (gBattle_LocationRules, location_rules.s), ended by scene -1. More...
struct  TerrainRule
 The world map's encounter zone for each kind of terrain (gWorldMap_EncounterRules, zonedata.c), ended by kind -1. More...
struct  EncounterZone
 An encounter zone, a row of encounter.tsv: its rate, the level it is made for, and the enemy groups that can appear with their chances. More...
struct  SceneInteractionEntry
 A rule choosing a scene's field music (gScene_InteractionRuleTable, scene_rules.s), ended by id -1. More...
struct  SceneAreaNameRule
 A rule naming the place a scene is in (gScene_AreaNameRules, scene_rules.s), ended by id -1. More...

Typedefs

typedef struct TerrainRule TerrainRule
 The world map's encounter zone for each kind of terrain (gWorldMap_EncounterRules, zonedata.c), ended by kind -1.

Enumerations

enum  { ENCOUNTER_GROUP_COUNT = 8 }
 The number of enemy groups an encounter zone can hold. More...

Functions

void Encounter_SelectSceneZones (s32 useRules)
 Chooses the current scene's encounter zones, one for each kind of ground the party can stand on (gEventWork->encounterGroups, read by EffectRuntime_LookupByTableEntry), from the first rule matching the scene and entrance.
s32 Encounter_ResolveWorldMapZoneAndBackdrop (void *pos)
 Returns the world map encounter zone for the terrain at pos (0 for none), and chooses the battle backdrop for that terrain (gGameState.special).
s32 Encounter_SelectEnemyGroup (s32 zone, s32 steps)
 Advances the encounter counter for zone and returns the enemy group to fight, or 0 for no battle.
s32 Encounter_RollTerrain (u32 terrain, s32 steps)
 Rolls a random battle on the encounter zone of the ground underfoot.
s32 Encounter_RollWorldMap (s32 pos, s32 steps)
 Rolls a random battle on the world map, taking the zone from the tile at pos.
u16 Encounter_GetEnemyGroupAtSlot (s32 zone, s32 slot)
 Returns the enemy group in slot (0 to 7) of zone; 14 halfwords make a zone.
s16 Encounter_GetDjinnEnemyGroup (s32 djinni)
 Returns the enemy group of Djinni battle djinni, which the table gives as a zone and slot.
void Scene_ResolveInteractionResult (void)
 Chooses the current scene's field music (gGameState.cue) from the first rule matching the scene or its group and the entrance; MUS_018 when none does.
s32 Scene_GetAreaNameIndex (s32 scene, s32 entrance)
 Returns the place name of scene and entrance, from the first rule matching the scene or its group; 0 when none does.
void Scene_SetDefeatReturnPoint (void)
 Sets the scene the party returns to after a defeat (gGameState.savedScene and savedEntrance), from the first rule of gParty_PairResolveRules that matches the current scene and entrance: {scene, entrance (-1 for any), return scene, return entrance}, ended by scene -1.
s16 Event_GetSpecialValue (void)
 Returns the battle backdrop chosen for the current scene.
void Battle_SelectSceneBackdrop (void)
 Chooses the battle backdrop for the current scene.
void Battle_SelectTerrainBackdrop (s32 behavior)
 Chooses the battle backdrop for a world map terrain behavior (1 to 7; any other gives Sol Sanctum's) and sets gGameState.special.
void BattleFx_SelectBattleCue (s32 zone, s32 slot)
 Chooses the battle music for slot of zone (gGameState.sceneCue).

Variables

const struct BattleLocationRule gBattle_LocationRules []
const struct SceneInteractionEntry gScene_InteractionRuleTable []
const struct SceneAreaNameRule gScene_AreaNameRules []

Detailed Description

Random encounters, and each scene's music, place name and backdrop.

Part of object.c, the field object, compiled only through it.

Definition in file encounter.c.

Typedef Documentation

◆ TerrainRule

typedef struct TerrainRule TerrainRule

The world map's encounter zone for each kind of terrain (gWorldMap_EncounterRules, zonedata.c), ended by kind -1.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

The number of enemy groups an encounter zone can hold.

Enumerator
ENCOUNTER_GROUP_COUNT 

Definition at line 29 of file encounter.c.

Function Documentation

◆ Encounter_SelectSceneZones()

void Encounter_SelectSceneZones ( s32 useRules)

Chooses the current scene's encounter zones, one for each kind of ground the party can stand on (gEventWork->encounterGroups, read by EffectRuntime_LookupByTableEntry), from the first rule matching the scene and entrance.

Ground 0 has none, and grounds 1 to 7 take consecutive zones from the rule's first one. With useRules 0, or no matching rule, no ground has encounters. Also resets the encounter counters and chooses the battle backdrop. Called by Field_RunScene on scene load, with useRules 0 on the world map and 1 in a field scene; writes work->encounterGroups, encounterBias and encounterThreshold, and gGameState.special.

Definition at line 49 of file encounter.c.

Referenced by Encounter_SelectSceneZones(), and Field_RunScene().

◆ Encounter_ResolveWorldMapZoneAndBackdrop()

s32 Encounter_ResolveWorldMapZoneAndBackdrop ( void * pos)

Returns the world map encounter zone for the terrain at pos (0 for none), and chooses the battle backdrop for that terrain (gGameState.special).

Called by Encounter_RollWorldMap on each step, and by Field_RequestBattleFromEncounterTable and Field_RequestDjinnBattle on the world map, which use only the backdrop.

Definition at line 103 of file encounter.c.

Referenced by Encounter_ResolveWorldMapZoneAndBackdrop(), Encounter_RollWorldMap(), Field_RequestBattleFromEncounterTable(), and Field_RequestDjinnBattle().

◆ Encounter_SelectEnemyGroup()

s32 Encounter_SelectEnemyGroup ( s32 zone,
s32 steps )

Advances the encounter counter for zone and returns the enemy group to fight, or 0 for no battle.

steps (16.16) scales how far the counter moves; a battle starts once it reaches encounterThreshold. FLAG_NO_ENCOUNTERS, flag 353 and gGameState.cloaked prevent battles. Flag 351 skips the checks and the counting and draws a group at once. Called by Encounter_RollTerrain and Encounter_RollWorldMap; adds to gGameState.encounterSteps, sets or clears work->encounterBias, and on a battle sets gGameState.sceneCue.

Definition at line 130 of file encounter.c.

Referenced by Encounter_RollTerrain(), Encounter_RollWorldMap(), and Encounter_SelectEnemyGroup().

◆ Encounter_RollTerrain()

s32 Encounter_RollTerrain ( u32 terrain,
s32 steps )

Rolls a random battle on the encounter zone of the ground underfoot.

terrain: the terrain number, 0 for ordinary ground. steps: the step weight, passed on to Encounter_SelectEnemyGroup. Returns the enemy group to fight, or 0 for no battle. Called by Field_ProcessStep in a field scene, which stores the result in work->battle; steps is the leader's speed limit, doubled with FLAG_LURE_CAP.

Definition at line 226 of file encounter.c.

Referenced by Encounter_RollTerrain(), and Field_ProcessStep().

◆ Encounter_RollWorldMap()

s32 Encounter_RollWorldMap ( s32 pos,
s32 steps )

Rolls a random battle on the world map, taking the zone from the tile at pos.

Returns the enemy group to fight, or 0 for no battle. Called by Field_ProcessStep on the world map.

Definition at line 236 of file encounter.c.

Referenced by Encounter_RollWorldMap(), and Field_ProcessStep().

◆ Encounter_GetEnemyGroupAtSlot()

u16 Encounter_GetEnemyGroupAtSlot ( s32 zone,
s32 slot )

Returns the enemy group in slot (0 to 7) of zone; 14 halfwords make a zone.

Called by Field_RequestBattleFromEncounterTable, Encounter_GetDjinnEnemyGroup and the scene event runner (events.c, zone 99).

Definition at line 244 of file encounter.c.

Referenced by Encounter_GetDjinnEnemyGroup(), Encounter_GetEnemyGroupAtSlot(), Field_RequestBattleFromEncounterTable(), and Field_SearchTile().

◆ Encounter_GetDjinnEnemyGroup()

s16 Encounter_GetDjinnEnemyGroup ( s32 djinni)

Returns the enemy group of Djinni battle djinni, which the table gives as a zone and slot.

Called by Field_RequestDjinnBattle.

Definition at line 251 of file encounter.c.

Referenced by Encounter_GetDjinnEnemyGroup(), and Field_RequestDjinnBattle().

◆ Scene_ResolveInteractionResult()

void Scene_ResolveInteractionResult ( void )

Chooses the current scene's field music (gGameState.cue) from the first rule matching the scene or its group and the entrance; MUS_018 when none does.

Called by Game_ResetForNewGame on entering each field scene, before Audio_PlayCueFromEventWork plays it.

Definition at line 279 of file encounter.c.

Referenced by Game_ResetForNewGame(), and Scene_ResolveInteractionResult().

◆ Scene_GetAreaNameIndex()

s32 Scene_GetAreaNameIndex ( s32 scene,
s32 entrance )

Returns the place name of scene and entrance, from the first rule matching the scene or its group; 0 when none does.

Called by the save, debug and location windows through Scene_GetAreaNameIndexFar, and by Map_UpdateWorldMapMarkers; most add it to MsgDebugEntryName for the message. The save stores it as its area (save_state.h).

Definition at line 326 of file encounter.c.

Referenced by Map_UpdateWorldMapMarkers(), and Scene_GetAreaNameIndex().

◆ Scene_SetDefeatReturnPoint()

void Scene_SetDefeatReturnPoint ( void )

Sets the scene the party returns to after a defeat (gGameState.savedScene and savedEntrance), from the first rule of gParty_PairResolveRules that matches the current scene and entrance: {scene, entrance (-1 for any), return scene, return entrance}, ended by scene -1.

Without a match the return point stays as it was. Called by Field_RunScene on scene load.

Definition at line 357 of file encounter.c.

Referenced by Field_RunScene(), and Scene_SetDefeatReturnPoint().

◆ Event_GetSpecialValue()

s16 Event_GetSpecialValue ( void )

Returns the battle backdrop chosen for the current scene.

The battle setup (battle/encounter.c) reads it through Event_GetSpecialValueFar as the battle's background.

Definition at line 375 of file encounter.c.

Referenced by Event_GetSpecialValue().

◆ Battle_SelectSceneBackdrop()

void Battle_SelectSceneBackdrop ( void )

Chooses the battle backdrop for the current scene.

gBattle_BackdropScenes lists each backdrop (a word with bit 31 set) followed by the scenes that use it, ended by 0; a scene takes the backdrop listed last before it, and a scene not listed takes the last backdrop. Called by Encounter_SelectSceneZones; sets gGameState.special.

Definition at line 382 of file encounter.c.

Referenced by Battle_SelectSceneBackdrop(), and Encounter_SelectSceneZones().

◆ Battle_SelectTerrainBackdrop()

void Battle_SelectTerrainBackdrop ( s32 behavior)

Chooses the battle backdrop for a world map terrain behavior (1 to 7; any other gives Sol Sanctum's) and sets gGameState.special.

Called by Encounter_ResolveWorldMapZoneAndBackdrop.

Definition at line 404 of file encounter.c.

Referenced by Battle_SelectTerrainBackdrop(), and Encounter_ResolveWorldMapZoneAndBackdrop().

◆ BattleFx_SelectBattleCue()

void BattleFx_SelectBattleCue ( s32 zone,
s32 slot )

Chooses the battle music for slot of zone (gGameState.sceneCue).

gEncounter_BattleMusic lists each song (with bit 15 set) followed by the (zone << 4) + slot keys that use it, ended by 0; a key takes the song listed last before it. Link battles always use MUS_018. Called by Encounter_SelectEnemyGroup for a random battle, by the battle requests (Field_RequestBattleFromEncounterTable, Field_RequestDjinnBattle with zone 0) and by the scene event runner (events.c).

Definition at line 439 of file encounter.c.

Referenced by BattleFx_SelectBattleCue(), Encounter_SelectEnemyGroup(), Field_RequestBattleFromEncounterTable(), Field_RequestDjinnBattle(), and Field_SearchTile().

Variable Documentation

◆ gBattle_LocationRules

const struct BattleLocationRule gBattle_LocationRules[]
extern

◆ gScene_InteractionRuleTable

const struct SceneInteractionEntry gScene_InteractionRuleTable[]
extern

◆ gScene_AreaNameRules

const struct SceneAreaNameRule gScene_AreaNameRules[]
extern

Referenced by Scene_GetAreaNameIndex().