shithub: pokered

Download patch

ref: 25a3e67b940fc91c11ed9b408fa20762995e6948
parent: 405889193ed592174407599df0bfd08a2d707a1b
author: Rangi <remy.oukaour+rangi42@gmail.com>
date: Mon Jul 6 05:32:55 EDT 2020

add_tm and add_hm define TM##_MOVE and HM##_MOVE constants, to avoid repeating the move names twice

--- a/constants.asm
+++ b/constants.asm
@@ -16,12 +16,12 @@
 INCLUDE "constants/pokedex_constants.asm"
 INCLUDE "constants/pokemon_data_constants.asm"
 INCLUDE "constants/trainer_constants.asm"
-INCLUDE "constants/item_constants.asm"
 INCLUDE "constants/type_constants.asm"
 INCLUDE "constants/move_constants.asm"
 INCLUDE "constants/move_animation_constants.asm"
 INCLUDE "constants/move_effect_constants.asm"
 INCLUDE "constants/battle_constants.asm"
+INCLUDE "constants/item_constants.asm"
 INCLUDE "constants/icon_constants.asm"
 INCLUDE "constants/sprite_constants.asm"
 INCLUDE "constants/sprite_data_constants.asm"
--- a/constants/item_constants.asm
+++ b/constants/item_constants.asm
@@ -103,10 +103,27 @@
 const_value = $C4
 
 add_hm: MACRO
-if !DEF(HM01)
+; Defines three constants:
+; - HM_\1: the item id, starting at $C4
+; - \1_TMNUM: the learnable TM/HM flag, starting at 51
+; - HM##_MOVE: alias for the move id, equal to the value of \1
+; The first usage also defines HM01 as the first HM item id.
+;
+; HMs are defined before TMs, so the value of NUM_TMS is not
+; available here, and its value of 50 is hard-coded.
+IF !DEF(HM01)
 HM01 EQU const_value
 	enum_start 51 ; NUM_TMS + 1
-endc
+ENDC
+HM_VALUE EQU __enum__ - 50 ; __enum__ - NUM_TMS
+IF HM_VALUE < 10
+MOVE_FOR_HM EQUS "HM0{d:HM_VALUE}_MOVE"
+ELSE
+MOVE_FOR_HM EQUS "HM{d:HM_VALUE}_MOVE"
+ENDC
+MOVE_FOR_HM = \1
+PURGE MOVE_FOR_HM
+PURGE HM_VALUE
 	const HM_\1
 	enum \1_TMNUM
 ENDM
@@ -119,10 +136,22 @@
 NUM_HMS EQU const_value - HM01
 
 add_tm: MACRO
-if !DEF(TM01)
+; Defines three constants:
+; - TM_\1: the item id, starting at $C9
+; - \1_TMNUM: the learnable TM/HM flag, starting at 1
+; - TM##_MOVE: alias for the move id, equal to the value of \1
+; The first usage also defines TM01 as the first TM item id.
+IF !DEF(TM01)
 TM01 EQU const_value
 	enum_start 1
-endc
+ENDC
+IF __enum__ < 10
+MOVE_FOR_TM EQUS "TM0{d:__enum__}_MOVE"
+ELSE
+MOVE_FOR_TM EQUS "TM{d:__enum__}_MOVE"
+ENDC
+MOVE_FOR_TM = \1
+PURGE MOVE_FOR_TM
 	const TM_\1
 	enum \1_TMNUM
 ENDM
@@ -179,5 +208,7 @@
 	add_tm SUBSTITUTE   ; $FA
 NUM_TMS EQU const_value - TM01
 
+; 50 TMs + 5 HMs = 55 learnable TM/HM flags per Pokémon.
+; These fit in 7 bytes, with one unused bit left over.
 	enum_start NUM_TMS + NUM_HMS + 1
 	enum UNUSED_TMNUM
--- a/data/moves/tmhm_moves.asm
+++ b/data/moves/tmhm_moves.asm
@@ -1,56 +1,59 @@
+; The add_hm and add_tm macros in constants/item_constants.asm simultaneously
+; define constants for the item IDs and for the corresponding move values.
+
 TechnicalMachines:
-	db MEGA_PUNCH
-	db RAZOR_WIND
-	db SWORDS_DANCE
-	db WHIRLWIND
-	db MEGA_KICK
-	db TOXIC
-	db HORN_DRILL
-	db BODY_SLAM
-	db TAKE_DOWN
-	db DOUBLE_EDGE
-	db BUBBLEBEAM
-	db WATER_GUN
-	db ICE_BEAM
-	db BLIZZARD
-	db HYPER_BEAM
-	db PAY_DAY
-	db SUBMISSION
-	db COUNTER
-	db SEISMIC_TOSS
-	db RAGE
-	db MEGA_DRAIN
-	db SOLARBEAM
-	db DRAGON_RAGE
-	db THUNDERBOLT
-	db THUNDER
-	db EARTHQUAKE
-	db FISSURE
-	db DIG
-	db PSYCHIC_M
-	db TELEPORT
-	db MIMIC
-	db DOUBLE_TEAM
-	db REFLECT
-	db BIDE
-	db METRONOME
-	db SELFDESTRUCT
-	db EGG_BOMB
-	db FIRE_BLAST
-	db SWIFT
-	db SKULL_BASH
-	db SOFTBOILED
-	db DREAM_EATER
-	db SKY_ATTACK
-	db REST
-	db THUNDER_WAVE
-	db PSYWAVE
-	db EXPLOSION
-	db ROCK_SLIDE
-	db TRI_ATTACK
-	db SUBSTITUTE
-	db CUT
-	db FLY
-	db SURF
-	db STRENGTH
-	db FLASH
+	db TM01_MOVE
+	db TM02_MOVE
+	db TM03_MOVE
+	db TM04_MOVE
+	db TM05_MOVE
+	db TM06_MOVE
+	db TM07_MOVE
+	db TM08_MOVE
+	db TM09_MOVE
+	db TM10_MOVE
+	db TM11_MOVE
+	db TM12_MOVE
+	db TM13_MOVE
+	db TM14_MOVE
+	db TM15_MOVE
+	db TM16_MOVE
+	db TM17_MOVE
+	db TM18_MOVE
+	db TM19_MOVE
+	db TM20_MOVE
+	db TM21_MOVE
+	db TM22_MOVE
+	db TM23_MOVE
+	db TM24_MOVE
+	db TM25_MOVE
+	db TM26_MOVE
+	db TM27_MOVE
+	db TM28_MOVE
+	db TM29_MOVE
+	db TM30_MOVE
+	db TM31_MOVE
+	db TM32_MOVE
+	db TM33_MOVE
+	db TM34_MOVE
+	db TM35_MOVE
+	db TM36_MOVE
+	db TM37_MOVE
+	db TM38_MOVE
+	db TM39_MOVE
+	db TM40_MOVE
+	db TM41_MOVE
+	db TM42_MOVE
+	db TM43_MOVE
+	db TM44_MOVE
+	db TM45_MOVE
+	db TM46_MOVE
+	db TM47_MOVE
+	db TM48_MOVE
+	db TM49_MOVE
+	db TM50_MOVE
+	db HM01_MOVE
+	db HM02_MOVE
+	db HM03_MOVE
+	db HM04_MOVE
+	db HM05_MOVE