Roaming Pokémon

*For normal wild Pokémon encounters, see Wild encounters.*
This page describes how **roaming Pokémon** work. It explains how to define where and when a roaming Pokémon can go.

## Roaming Pokémon

Roaming Pokémon is the term given to Pokémon, typically legendaries, that randomly appear as wild encounters every so often, rather than appear as an event encounter. They will flee from battle at the earliest opportunity (but will fight if they cannot). Roaming Pokémon can travel between different maps.

If a roaming Pokémon is on the same map as the player, then the player may encounter that roaming Pokémon.

## Defining the roaming locations

Roaming Pokémon can be encountered on various different maps, but the pattern they roam in is not entirely random. Each map that a roaming Pokémon can be on will lead to one or more other maps, and the roamer will move to one of those (chosen at random) each time the player steps onto a new map.

The paths between maps can be quite a complex pattern.

Paths are defined in the setting `ROAMING_AREAS`, e.g.

```
ROAMING_AREAS = {
  20 => [21, 22],
  21 => [20, 22],
  22 => [20, 21]
}

```

In this example, a roaming Pokémon on map 20 can go to either map 21 or map 22, and so on. Map 20 is the path to maps 21 and 22.

When defining paths, it is important that there are no dead ends - any map that can be reached should be a path to at least one other map.

You should only make a map a path if it is reasonable that a roaming Pokémon will show up there. For example, land-based Pokémon shouldn't be able to go on a water route. On the other hand, you can make a map a path even if there cannot be a wild encounter on it, and even if the map doesn't exist at all.

As mentioned below, these paths are the "default" paths. If a roamer has no paths of its own, it will use these ones.

## Defining the roamers

Roaming Pokémon are listed in the setting `ROAMING_SPECIES` like so:

```
ROAMING_SPECIES = [
  [:LATIAS, 30, 53, 0, "Battle roaming"],
  [:LATIOS, 30, 53, 0, "Battle roaming"],
  [:KYOGRE, 40, 54, 2, nil, {
    2  => [21, 31],
    21 => [2, 31, 69],
    31 => [2, 21, 69],
    69 => [21, 31]
  }],
  [:ENTEI, 40, 55, 1]
]

```

Each array in here corresponds to one roaming Pokémon, where the information in each array is as follows:

1. Species of the roaming Pokémon.
2. Level of the roaming Pokémon.
3. A Game Switch number.
4. The kind of encounters the roamer can appear in - one of:
	* 0 - Walking in grass, walking in caves or surfing.
	* 1 - Walking in grass or walking in caves.
	* 2 - Surfing.
	* 3 - Fishing.
	* 4 - Surfing or fishing.
5. The name of a BGM file to play during the encounter. Optional.
6. A set of roaming paths unique to this roamer. Optional.

A Pokémon will only start roaming if its Game Switch is ON. Several roaming Pokémon can depend on the same Game Switch.

Roamers that do not have any paths defined specifically for them will use the default paths mentioned above. If the roamer has its own roaming paths, they should be laid out as in the example above. You can use unique paths to make sure a roamer will appear only where you want it to, e.g. in just one region, or only on one island/cave. It is recommended that you do this if you have multiple regions, to make sure the roamer stays in the intended region.

## Roaming behaviour

Roaming Pokémon only move to a different map when the player enters a new map. It will move to a random map that the map it is currently on is a path to (there is also a small chance that it will move to *any* possible map it could ever appear on). If a roamer doesn't have any valid destinations, then it will remain on its current map until it can move again.

If the player has a partner trainer, they will never encounter a roaming Pokémon. There is a 25% chance that any wild Pokémon encounter will be with a roamer on the current map, unless the player has already encountered a roamer on that map. The player can only encounter one roamer per map, regardless of how many roamers are currently on that map.

Different maps in the same region with the same name (e.g. ones depicting long routes) are considered to be the same map for the purpose of encountering a roamer.

Once a roaming Pokémon has been encountered, it will remain the exact same Pokémon in all subsequent encounters (i.e. with same personal ID/HP/status/shininess/moves/IVs/etc.). Its information is stored in the array `$PokemonGlobal.roamPokemon[index]`.

When a roaming Pokémon is defeated/captured, it can no longer be encountered.

## Resetting roamers

The method `pbResetAllRoamers` will erase the information of all fainted roamers that had not been caught. This starts them roaming again (assuming their Game Switches are still ON), as fresh Pokémon with new properties.