Make the field move Headbutt work with Kanto trees - pret/pokecrystal GitHub Wiki

Generation 2 introduced the field move "Headbutt", which lets one shake small trees in the overworld for a chance to meet rare Pokémon.

This tutorial remedies the fact that Headbutt only works on trees that are found in Johto.

Contents

  1. Make Headbutt work on Kanto trees
  2. Design a custom shake animation
  3. Populate the trees with Pokémon species

1. Make Headbutt work on Kanto trees

When pressing A while facing a tree, we want the game to recognize this tree as compatible with Headbutt. To do so, let's start by editing the collision of a couple of blocks within data/tilesets/kanto_collision.asm.

Rather than directly edit this file, a more user-friendly approach would be using Polished Map and loading a map that uses the Kanto tileset, like CeruleanCity.blk. This will bring a visual of the corresponding blockset, which can then be more easily edited. Right-clicking on a block will bring up its respective collision data. We want to pick all the blocks that contain trees, and change the collisions associated to the trees from WALL to HEADBUTT_TREE.

You can now headbutt trees in Kanto. However, doing so at this point loads the Johto tree animation, and no Pokémon will ever fall from the tree.

Let's work on those issues.

2. Design a custom shake animation

For a custom animation to work we first need to:

  1. Design its graphics.
  2. Include it into the project.
  3. Edit the code to load it at the right moment, and under the right conditions.

Firstly, here is a "shaking" version of the vanilla Kanto tree:

gfx/overworld/headbutt_tree_kanto.png

headbutt_tree_kanto

Secondly, to reference this image in the project, edit engine/events/field_moves.asm:

HeadbuttTreeGFX:
INCBIN "gfx/overworld/headbutt_tree.2bpp"
+
+HeadbuttTreeKantoGFX:
+INCBIN "gfx/overworld/headbutt_tree_kanto.2bpp"

Now is the time to edit the code to load this specific shake animation when in Kanto. The animation is split in 2 parts:

  1. The 4 background tiles of the selected tree are replaced by 4 identical grass tiles.
  2. After the tree has been replaced by grass, the tree from the animation is loaded over it as a sprite whose frames will be animated.

KANTO has its grass tile at a different id when compared to the other Johto tilesets. Start by editing HideHeadbuttTree in engine/events/field_moves.asm:

	add hl, de
	ld a, [hli]
	ld h, [hl]
	ld l, a

+	ld a, [wMapTileset]
+	cp TILESET_KANTO
+	ld a, $2c ; grass tile
+	jr z, .replacement_tile_determined
+
	ld a, $05 ; grass tile	
+.replacement_tile_determined
	ld [hli], a
	ld [hld], a
	ld bc, SCREEN_WIDTH

The code is pretty self-explanatory: when the loaded tileset is KANTO, then use the tile at id $2c as the background tile.

Now we will load the tree animation. Still in engine/events/field_moves.asm, edit ShakeHeadbuttTree:

ShakeHeadbuttTree:
	farcall ClearSpriteAnims
-	ld de, CutGrassGFX
-	ld hl, vTiles0 tile FIELDMOVE_GRASS
-	lb bc, BANK(CutGrassGFX), 4
-	call Request2bpp
-	ld de, HeadbuttTreeGFX
+	ld de, HeadbuttTreeKantoGFX ; tree frames
+
+	ld a, [wMapTileset]
+	cp TILESET_KANTO
+	jr z, .tree_frames_determined
+
+	ld de, HeadbuttTreeGFX ; tree frames
+.tree_frames_determined
	ld hl, vTiles0 tile FIELDMOVE_TREE

CutGrassGFX is the little leaf that is used when using Cut to clear tall grass, or during the overworld Fly animation. It is unused during the overworld Headbutt animation, so we removed it.

Now that the animation is working fine, let's add some Pokémon into those trees.

3. Populate the trees with Pokémon species

Each map can have its own treemon set, which determines what Pokémon can be encountered with Headbutt. You can create a new set by adding a TREEMON_SET_* constant in constants/pokemon_data_constants.asm. The wild data is found in data/wild/treemons.asm, with data/wild/treemons_asleep.asm determining which Pokémon will be asleep during which specific time of day.

For the purpose of the tutorial, we will use the existing TREEMON_SET_KANTO (which is used by Routes 26 and 27, which are Kanto routes that use the JOHTO tileset).

The array that associates a treemon set to each route is located in data/wild/treemon_maps.asm. Edit this file and define whatever map as you please (here we will add Cerulean City as an example).

	treemon_map ILEX_FOREST,               TREEMON_SET_FOREST
+	treemon_map CERULEAN_CITY,             TREEMON_SET_KANTO
	db -1

And there you go! Kanto trees are now headbutt-able, with appropriate Pokémon data.

headbutt_tree_kantro