Breeding

*For how to set up a Day Care Center, see Day Care.*
This page describes how **breeding** works, both deciding when to do it and what the resultant Pokémon egg will be.

## Deciding when an egg is available

Every 256 steps the player takes, the game checks whether it should generate an egg in the Day Care Center. The code that does this is in the script section **Overworld\_DayCare** in `def update_on_step_taken`. It first checks various criteria, which are:

* There must be exactly 2 Pokémon deposited in the Day Care (neither of which are Shadow Pokémon).
* There is no egg already waiting to be collected by the player.
* The two deposited Pokémon are in compatible egg groups.
	+ Either they share an egg group, or exactly one is in the Ditto egg group. Neither can be in the Undiscovered egg group.
* The two deposited Pokémon are of compatible genders.
	+ Either one is male and the other female, or exactly one is in the Ditto egg group.

Assuming all of the above criteria are met, the game calculates an egg generation probability, which is higher if the two Pokémon are of the same species and/or have different original trainers. The probability is also increased by the Oval Charm item.

The egg generation probability is then used to decide if an egg should be generated. If so, the value of `$PokemonGlobal.day_care.egg_generated` is set to `true` to indicate that an egg is waiting to be collected (a value of `false` means no egg is available), and this can be checked with `DayCare.egg_generated?`.

Note that the egg itself is not yet created. The only thing determined at this time is whether the player will be given an egg when they talk to the old man at the Day Care Center. The egg itself is generated during that conversation, when it is given to the player.

## Generating an egg

If an egg is waiting at the Day Care Center for the player to collect, interacting with the old man outside will allow the player to receive it. The egg is generated at this time. Generating the egg is done in `module EggGenerator`, and in `def DayCare.collect_egg` the egg is given to the player.

The first step is to decide which of the two deposited Pokémon is the mother and which is the father. The mother is either the female Pokémon, or is the non-Ditto if one of the two is in the Ditto egg group. The father is the other Pokémon (the one that isn't determined to be the mother). The roles of mother and father will not necessarily match up with the genders of the Pokémon (i.e. when breeding a male Pokémon with Ditto).

The species of Pokémon in the egg is inherited from the mother. The lowest prevolution of the mother's species is chosen for this. However, if a prevolution is defined with an Incense item and neither parent is holding that item, the next evolved species in the evolutionary family is used instead. Then, if the species decided upon has an "Offspring" property defined in the PBS file "pokemon.txt", the egg's species will instead be one of those offspring species (chosen randomly and with an equal chance of each). Nidoran, Volbeat/Illumise and Manaphy make use of the "Offspring" property.

The egg Pokémon can then inherit a number of properties from one or both of its parents. These include:

* Form (the flags "InheritFormFromMother" and "InheritFormWithEverStone" apply here if defined in the PBS file "pokemon.txt" for the egg's species; also, Sinistea's form is always set to 0)
* Moves (including Volt Tackle for a baby Pichu if either parent is holding a Light Ball)
* Nature (from any parent that is holding an Ever Stone)
* Ability (from the mother or non-Ditto parent)
* IVs (from either parent, 3 of them, or 5 if either parent is holding a Destiny Knot)
* Poké Ball (from the mother, if it is not a Cherish Ball or Master Ball)

Some parts of the above inheritances depend on whether certain settings are true or false.

The following things also happen:

* The Shiny Charm has its effect on the egg, if the player owns it.
* The egg's level is set to the value of the setting `EGG_LEVEL`.
* The egg's nickname is set to "Egg" (which is erased once it hatches).
* The egg's `obtain_text` (seen in its summary screens) is set to "Day-Care Couple".
* The egg has a chance of contracting Pokérus.
* The number of steps required for the egg to hatch (as defined in the PBS file "pokemon.txt") is set.
* The egg's happiness is set to 120.

## Giving the egg to the player

An egg from the Day Care can only be added to the player's party, meaning there needs to be an empty space in their party.

As mentioned above, the script `DayCare.collect_egg` calls code that generates the egg and then gives it to the player. This is done silently, without displaying any messages. You will therefore need to add messages to the event in which you call this script, to indicate what has happened.

When an egg is given to the player in this way, the step counter used when deciding if an egg can become available is automatically reset to 0. to make sure that another egg cannot become available almost immediately.

## Tips

* Give the player a phone number for the Day Care. The Day Care can call when an egg becomes available.
* The Day Care supports having any number of Pokémon in it at once, but egg generation only occurs if there are *exactly* two Pokémon there. You will need to significantly modify the breeding code if you want any pair of deposited Pokémon to be able to breed. The bulk of the changes required will be in deciding which two deposited Pokémon are the parents, and dealing with having two or more possible breeding pairs existing at the same time (note that a single Pokémon could be in several of these pairs at once).
	+ If you don't want that hassle, you could leave the code as it is. Your explanation of why breeding doesn't occur with three or more deposited Pokémon could be that a pair of Pokémon can't get enough privacy from the other(s) to allow them to breed.
* You could define one or more Pokémon that are owned by the Day Care itself, which are able to breed with the deposited Pokémon. This can provide access to useful inherited properties, although the player may or may not be outright told what is available. As above, doing this would require major changes to the code.
	+ (One of) the Day Care Pokémon could be a Ditto, meaning breeding is allowed with any deposited Pokémon that can breed.