shithub: pokered

Download patch

ref: bfd9f617c96af851ad4100b752ea967ef8989edc
parent: 70eac3a1f7a27d5b71b968708f423dbbff6b146c
author: Rangi <remy.oukaour+rangi42@gmail.com>
date: Mon Aug 31 06:23:19 EDT 2020

Use constants to delineate map types, and factor out more data

--- a/constants/map_constants.asm
+++ b/constants/map_constants.asm
@@ -13,6 +13,7 @@
 ; - MapSpriteSets (see data/maps/sprite_sets.asm)
 ; - ExternalMapEntries (see data/maps/town_map_entries.asm)
 ; Each map also has associated data in maps.asm.
+; Order: towns/cities, then routes, then indoor/dungeon maps
 	const_def
 	mapconst PALLET_TOWN,                    9, 10 ; $00
 	mapconst VIRIDIAN_CITY,                 18, 20 ; $01
@@ -25,7 +26,9 @@
 	mapconst CINNABAR_ISLAND,                9, 10 ; $08
 	mapconst INDIGO_PLATEAU,                 9, 10 ; $09
 	mapconst SAFFRON_CITY,                  18, 20 ; $0A
+NUM_CITY_MAPS EQU const_value
 	mapconst UNUSED_MAP_0B,                  0,  0 ; $0B
+FIRST_ROUTE_MAP EQU const_value
 	mapconst ROUTE_1,                       18, 10 ; $0C
 	mapconst ROUTE_2,                       36, 10 ; $0D
 	mapconst ROUTE_3,                        9, 35 ; $0E
@@ -51,6 +54,7 @@
 	mapconst ROUTE_23,                      72, 10 ; $22
 	mapconst ROUTE_24,                      18, 10 ; $23
 	mapconst ROUTE_25,                       9, 30 ; $24
+FIRST_INDOOR_MAP EQU const_value
 	mapconst REDS_HOUSE_1F,                  4,  4 ; $25
 	mapconst REDS_HOUSE_2F,                  4,  4 ; $26
 	mapconst BLUES_HOUSE,                    4,  4 ; $27
@@ -262,7 +266,6 @@
 	mapconst LORELEIS_ROOM,                  6,  5 ; $F5
 	mapconst BRUNOS_ROOM,                    6,  5 ; $F6
 	mapconst AGATHAS_ROOM,                   6,  5 ; $F7
-
 
 ; Indoor maps, such as houses, use this as the Map ID in their exit warps
 ; This map ID takes the player back to the last outdoor map they were on, stored in wLastMap
--- /dev/null
+++ b/data/events/bench_guys.asm
@@ -1,0 +1,20 @@
+bench_guy_text: MACRO
+	db \1, \2
+	db_tx_pre \3
+ENDM
+
+BenchGuyTextPointers:
+	; map id, player facing direction, predef text
+	bench_guy_text VIRIDIAN_POKECENTER,    SPRITE_FACING_LEFT, ViridianCityPokecenterBenchGuyText
+	bench_guy_text PEWTER_POKECENTER,      SPRITE_FACING_LEFT, PewterCityPokecenterBenchGuyText
+	bench_guy_text CERULEAN_POKECENTER,    SPRITE_FACING_LEFT, CeruleanCityPokecenterBenchGuyText
+	bench_guy_text LAVENDER_POKECENTER,    SPRITE_FACING_LEFT, LavenderCityPokecenterBenchGuyText
+	bench_guy_text VERMILION_POKECENTER,   SPRITE_FACING_LEFT, VermilionCityPokecenterBenchGuyText
+	bench_guy_text CELADON_POKECENTER,     SPRITE_FACING_LEFT, CeladonCityPokecenterBenchGuyText
+	bench_guy_text CELADON_HOTEL,          SPRITE_FACING_LEFT, CeladonCityHotelText
+	bench_guy_text FUCHSIA_POKECENTER,     SPRITE_FACING_LEFT, FuchsiaCityPokecenterBenchGuyText
+	bench_guy_text CINNABAR_POKECENTER,    SPRITE_FACING_LEFT, CinnabarIslandPokecenterBenchGuyText
+	bench_guy_text SAFFRON_POKECENTER,     SPRITE_FACING_LEFT, SaffronCityPokecenterBenchGuyText
+	bench_guy_text MT_MOON_POKECENTER,     SPRITE_FACING_LEFT, MtMoonPokecenterBenchGuyText
+	bench_guy_text ROCK_TUNNEL_POKECENTER, SPRITE_FACING_LEFT, RockTunnelPokecenterBenchGuyText
+	db -1 ; end
--- /dev/null
+++ b/data/events/card_key_coords.asm
@@ -1,0 +1,36 @@
+; These tables are probably supposed to be door locations in Silph Co.,
+; but they are unused.
+; The reason there are 3 tables is unknown.
+
+; Format: map ID, Y, X, gate ID?
+
+CardKeyTable1:
+	db  SILPH_CO_2F, $04, $04, 0
+	db  SILPH_CO_2F, $04, $05, 1
+	db  SILPH_CO_4F, $0C, $04, 2
+	db  SILPH_CO_4F, $0C, $05, 3
+	db  SILPH_CO_7F, $06, $0A, 4
+	db  SILPH_CO_7F, $06, $0B, 5
+	db  SILPH_CO_9F, $04, $12, 6
+	db  SILPH_CO_9F, $04, $13, 7
+	db SILPH_CO_10F, $08, $0A, 8
+	db SILPH_CO_10F, $08, $0B, 9
+	db -1 ; end
+
+CardKeyTable2:
+	db SILPH_CO_3F, $08, $09, 10
+	db SILPH_CO_3F, $09, $09, 11
+	db SILPH_CO_5F, $04, $07, 12
+	db SILPH_CO_5F, $05, $07, 13
+	db SILPH_CO_6F, $0C, $05, 14
+	db SILPH_CO_6F, $0D, $05, 15
+	db SILPH_CO_8F, $08, $07, 16
+	db SILPH_CO_8F, $09, $07, 17
+	db SILPH_CO_9F, $08, $03, 18
+	db SILPH_CO_9F, $09, $03, 19
+	db -1 ; end
+
+CardKeyTable3:
+	db SILPH_CO_11F, $08, $09, 20
+	db SILPH_CO_11F, $09, $09, 21
+	db -1 ; end
--- /dev/null
+++ b/data/events/card_key_maps.asm
@@ -1,0 +1,12 @@
+SilphCoMapList:
+	db SILPH_CO_2F
+	db SILPH_CO_3F
+	db SILPH_CO_4F
+	db SILPH_CO_5F
+	db SILPH_CO_6F
+	db SILPH_CO_7F
+	db SILPH_CO_8F
+	db SILPH_CO_9F
+	db SILPH_CO_10F
+	db SILPH_CO_11F
+	db -1 ; end
--- a/data/maps/dungeon_maps.asm
+++ b/data/maps/dungeon_maps.asm
@@ -1,3 +1,8 @@
+; GetBattleTransitionID_IsDungeonMap fails to recognize
+; VICTORY_ROAD_2F, VICTORY_ROAD_3F, all ROCKET_HIDEOUT maps,
+; POKEMON_MANSION_1F, SEAFOAM_ISLANDS_[B1F-B4F], POWER_PLANT,
+; DIGLETTS_CAVE, and SILPH_CO_[9-11]F as dungeon maps
+
 ; GetBattleTransitionID_IsDungeonMap checks if wCurMap
 ; is equal to one of these maps
 DungeonMaps1:
--- a/engine/battle/battle_transitions.asm
+++ b/engine/battle/battle_transitions.asm
@@ -118,9 +118,6 @@
 	ld [wBattleTransitionSpiralDirection], a
 	ret
 
-; fails to recognize VICTORY_ROAD_2F, VICTORY_ROAD_3F, all ROCKET_HIDEOUT maps,
-; POKEMON_MANSION_1F, SEAFOAM_ISLANDS_[B1F-B4F], POWER_PLANT, DIGLETTS_CAVE
-; and SILPH_CO_[9-11]F as dungeon maps
 GetBattleTransitionID_IsDungeonMap:
 	ld a, [wCurMap]
 	ld e, a
--- a/engine/battle/wild_encounters.asm
+++ b/engine/battle/wild_encounters.asm
@@ -39,7 +39,7 @@
 ; so long as the map is "indoor" and has wild pokemon defined.
 ; ...as long as it's not Viridian Forest or Safari Zone.
 	ld a, [wCurMap]
-	cp REDS_HOUSE_1F ; is this an indoor map?
+	cp FIRST_INDOOR_MAP ; is this an indoor map?
 	jr c, .CantEncounter2
 	ld a, [wCurMapTileset]
 	cp FOREST ; Viridian Forest/Safari Zone
--- a/engine/events/card_key.asm
+++ b/engine/events/card_key.asm
@@ -4,7 +4,7 @@
 	ld b, a
 .silphCoMapListLoop
 	ld a, [hli]
-	cp $ff
+	cp -1
 	ret z
 	cp b
 	jr nz, .silphCoMapListLoop
@@ -58,18 +58,7 @@
 	ldh [hSpriteIndexOrTextID], a
 	jp PrintPredefTextID
 
-SilphCoMapList:
-	db SILPH_CO_2F
-	db SILPH_CO_3F
-	db SILPH_CO_4F
-	db SILPH_CO_5F
-	db SILPH_CO_6F
-	db SILPH_CO_7F
-	db SILPH_CO_8F
-	db SILPH_CO_9F
-	db SILPH_CO_10F
-	db SILPH_CO_11F
-	db $FF
+INCLUDE "data/events/card_key_maps.asm"
 
 CardKeySuccessText::
 	text_far _CardKeySuccessText1
--- a/engine/events/diploma.asm
+++ b/engine/events/diploma.asm
@@ -83,17 +83,18 @@
 	dec c
 	jr .loop
 
+diploma_text: MACRO
+	dw \3
+	dwcoord \1, \2
+ENDM
+
 DiplomaTextPointersAndCoords:
-	dw DiplomaText
-	dwcoord 5, 2
-	dw DiplomaPlayer
-	dwcoord 3, 4
-	dw DiplomaEmptyText
-	dwcoord 15, 4
-	dw DiplomaCongrats
-	dwcoord 2, 6
-	dw DiplomaGameFreak
-	dwcoord 9, 16
+	; x, y, text
+	diploma_text  5,  2, DiplomaText
+	diploma_text  3,  4, DiplomaPlayer
+	diploma_text 15,  4, DiplomaEmptyText
+	diploma_text  2,  6, DiplomaCongrats
+	diploma_text  9, 16, DiplomaGameFreak
 
 DiplomaText:
 	db CIRCLE_TILE_ID, "Diploma", CIRCLE_TILE_ID, "@"
--- a/engine/events/hidden_objects/bench_guys.asm
+++ b/engine/events/hidden_objects/bench_guys.asm
@@ -17,30 +17,11 @@
 	ld b, a
 	ld a, [wSpritePlayerStateData1FacingDirection]
 	cp b
-	jr nz, .loop ; player isn't facing left at the bench guy
+	jr nz, .loop ; player isn't facing the bench guy
 	ld a, [hl]
 	jp PrintPredefTextID
 
-bench_guy_text: MACRO
-	db \1, \2
-	db_tx_pre \3
-ENDM
-
-BenchGuyTextPointers:
-	; map id, player facing direction, predef text
-	bench_guy_text VIRIDIAN_POKECENTER,    SPRITE_FACING_LEFT, ViridianCityPokecenterBenchGuyText
-	bench_guy_text PEWTER_POKECENTER,      SPRITE_FACING_LEFT, PewterCityPokecenterBenchGuyText
-	bench_guy_text CERULEAN_POKECENTER,    SPRITE_FACING_LEFT, CeruleanCityPokecenterBenchGuyText
-	bench_guy_text LAVENDER_POKECENTER,    SPRITE_FACING_LEFT, LavenderCityPokecenterBenchGuyText
-	bench_guy_text VERMILION_POKECENTER,   SPRITE_FACING_LEFT, VermilionCityPokecenterBenchGuyText
-	bench_guy_text CELADON_POKECENTER,     SPRITE_FACING_LEFT, CeladonCityPokecenterBenchGuyText
-	bench_guy_text CELADON_HOTEL,          SPRITE_FACING_LEFT, CeladonCityHotelText
-	bench_guy_text FUCHSIA_POKECENTER,     SPRITE_FACING_LEFT, FuchsiaCityPokecenterBenchGuyText
-	bench_guy_text CINNABAR_POKECENTER,    SPRITE_FACING_LEFT, CinnabarIslandPokecenterBenchGuyText
-	bench_guy_text SAFFRON_POKECENTER,     SPRITE_FACING_LEFT, SaffronCityPokecenterBenchGuyText
-	bench_guy_text MT_MOON_POKECENTER,     SPRITE_FACING_LEFT, MtMoonPokecenterBenchGuyText
-	bench_guy_text ROCK_TUNNEL_POKECENTER, SPRITE_FACING_LEFT, RockTunnelPokecenterBenchGuyText
-	db -1 ; end
+INCLUDE "data/events/bench_guys.asm"
 
 ViridianCityPokecenterBenchGuyText::
 	text_far _ViridianCityPokecenterGuyText
--- a/engine/events/pokedex_rating.asm
+++ b/engine/events/pokedex_rating.asm
@@ -56,38 +56,22 @@
 	text_end
 
 DexRatingsTable:
-	db 10
-	dw PokedexRatingText_44201
-	db 20
-	dw PokedexRatingText_44206
-	db 30
-	dw PokedexRatingText_4420b
-	db 40
-	dw PokedexRatingText_44210
-	db 50
-	dw PokedexRatingText_44215
-	db 60
-	dw PokedexRatingText_4421a
-	db 70
-	dw PokedexRatingText_4421f
-	db 80
-	dw PokedexRatingText_44224
-	db 90
-	dw PokedexRatingText_44229
-	db 100
-	dw PokedexRatingText_4422e
-	db 110
-	dw PokedexRatingText_44233
-	db 120
-	dw PokedexRatingText_44238
-	db 130
-	dw PokedexRatingText_4423d
-	db 140
-	dw PokedexRatingText_44242
-	db 150
-	dw PokedexRatingText_44247
-	db NUM_POKEMON + 1
-	dw PokedexRatingText_4424c
+	dbw 10, PokedexRatingText_44201
+	dbw 20, PokedexRatingText_44206
+	dbw 30, PokedexRatingText_4420b
+	dbw 40, PokedexRatingText_44210
+	dbw 50, PokedexRatingText_44215
+	dbw 60, PokedexRatingText_4421a
+	dbw 70, PokedexRatingText_4421f
+	dbw 80, PokedexRatingText_44224
+	dbw 90, PokedexRatingText_44229
+	dbw 100, PokedexRatingText_4422e
+	dbw 110, PokedexRatingText_44233
+	dbw 120, PokedexRatingText_44238
+	dbw 130, PokedexRatingText_4423d
+	dbw 140, PokedexRatingText_44242
+	dbw 150, PokedexRatingText_44247
+	dbw NUM_POKEMON + 1, PokedexRatingText_4424c
 
 PokedexRatingText_44201:
 	text_far _OaksLabText_44201
--- a/engine/gfx/palettes.asm
+++ b/engine/gfx/palettes.asm
@@ -145,11 +145,11 @@
 	cp CAVERN
 	jr z, .caveOrBruno
 	ld a, [wCurMap]
-	cp REDS_HOUSE_1F
+	cp FIRST_INDOOR_MAP
 	jr c, .townOrRoute
 	cp CERULEAN_CAVE_2F
 	jr c, .normalDungeonOrBuilding
-	cp NAME_RATERS_HOUSE
+	cp CERULEAN_CAVE_1F + 1
 	jr c, .caveOrBruno
 	cp LORELEIS_ROOM
 	jr z, .Lorelei
@@ -158,7 +158,7 @@
 .normalDungeonOrBuilding
 	ld a, [wLastMap] ; town or route that current dungeon or building is located
 .townOrRoute
-	cp SAFFRON_CITY + 1
+	cp NUM_CITY_MAPS
 	jr c, .town
 	ld a, PAL_ROUTE - 1
 .town
--- a/engine/items/item_effects.asm
+++ b/engine/items/item_effects.asm
@@ -1573,7 +1573,7 @@
 	ld b, a
 .loop
 	ld a, [hli]
-	cp $ff
+	cp -1
 	jp z, ItemUseNotTime
 	cp b
 	jr nz, .nextEntry1
@@ -1600,46 +1600,7 @@
 	set 7, [hl]
 	ret
 
-; These tables are probably supposed to be door locations in Silph Co.,
-; but they are unused.
-; The reason there are 3 tables is unknown.
-
-; Format:
-; 00: Map ID
-; 01: Y
-; 02: X
-; 03: ID?
-
-CardKeyTable1:
-	db  SILPH_CO_2F,$04,$04,$00
-	db  SILPH_CO_2F,$04,$05,$01
-	db  SILPH_CO_4F,$0C,$04,$02
-	db  SILPH_CO_4F,$0C,$05,$03
-	db  SILPH_CO_7F,$06,$0A,$04
-	db  SILPH_CO_7F,$06,$0B,$05
-	db  SILPH_CO_9F,$04,$12,$06
-	db  SILPH_CO_9F,$04,$13,$07
-	db SILPH_CO_10F,$08,$0A,$08
-	db SILPH_CO_10F,$08,$0B,$09
-	db $ff
-
-CardKeyTable2:
-	db SILPH_CO_3F,$08,$09,$0A
-	db SILPH_CO_3F,$09,$09,$0B
-	db SILPH_CO_5F,$04,$07,$0C
-	db SILPH_CO_5F,$05,$07,$0D
-	db SILPH_CO_6F,$0C,$05,$0E
-	db SILPH_CO_6F,$0D,$05,$0F
-	db SILPH_CO_8F,$08,$07,$10
-	db SILPH_CO_8F,$09,$07,$11
-	db SILPH_CO_9F,$08,$03,$12
-	db SILPH_CO_9F,$09,$03,$13
-	db $ff
-
-CardKeyTable3:
-	db SILPH_CO_11F,$08,$09,$14
-	db SILPH_CO_11F,$09,$09,$15
-	db $ff
+INCLUDE "data/events/card_key_coords.asm"
 
 ItemUsePokedoll:
 	ld a, [wIsInBattle]
--- a/engine/items/town_map.asm
+++ b/engine/items/town_map.asm
@@ -1,3 +1,5 @@
+NOT_VISITED EQU $fe
+
 DisplayTownMap:
 	call LoadTownMap
 	ld hl, wUpdateSpritesEnabled
@@ -224,7 +226,7 @@
 	ld a, [hl]
 	cp $ff
 	jr z, .wrapToStartOfList
-	cp $fe
+	cp NOT_VISITED
 	jr z, .pressedUp ; skip past unvisited towns
 	jp .townMapFlyLoop
 .wrapToStartOfList
@@ -236,11 +238,11 @@
 	ld a, [hl]
 	cp $ff
 	jr z, .wrapToEndOfList
-	cp $fe
+	cp NOT_VISITED
 	jr z, .pressedDown ; skip past unvisited towns
 	jp .townMapFlyLoop
 .wrapToEndOfList
-	ld hl, wFlyLocationsList + 11
+	ld hl, wFlyLocationsList + NUM_CITY_MAPS
 	jr .pressedDown
 
 ToText:
@@ -254,11 +256,11 @@
 	ld e, a
 	ld a, [wTownVisitedFlag + 1]
 	ld d, a
-	ld bc, SAFFRON_CITY + 1
+	lb bc, 0, NUM_CITY_MAPS
 .loop
 	srl d
 	rr e
-	ld a, $fe ; store $fe if the town hasn't been visited
+	ld a, NOT_VISITED
 	jr nc, .notVisited
 	ld a, b ; store the map number of the town if it has been visited
 .notVisited
@@ -554,7 +556,7 @@
 LoadTownMapEntry:
 ; in: a = map number
 ; out: lower nybble of [de] = x, upper nybble of [de] = y, hl = address of name
-	cp REDS_HOUSE_1F
+	cp FIRST_INDOOR_MAP
 	jr c, .external
 	ld bc, 4
 	ld hl, InternalMapEntries
--- a/engine/overworld/map_sprites.asm
+++ b/engine/overworld/map_sprites.asm
@@ -255,7 +255,7 @@
 ; sets carry if the map is a city or route, unsets carry if not
 InitOutsideMapSprites:
 	ld a, [wCurMap]
-	cp REDS_HOUSE_1F ; is the map a city or a route (map ID less than $25)?
+	cp FIRST_INDOOR_MAP ; is the map a city or a route?
 	ret nc ; if not, return
 	ld hl, MapSpriteSets
 	add l
--- a/engine/overworld/missable_objects.asm
+++ b/engine/overworld/missable_objects.asm
@@ -1,6 +1,6 @@
 MarkTownVisitedAndLoadMissableObjects::
 	ld a, [wCurMap]
-	cp ROUTE_1
+	cp FIRST_ROUTE_MAP
 	jr nc, .notInTown
 	ld c, a
 	ld b, FLAG_SET
--- a/wram.asm
+++ b/wram.asm
@@ -897,7 +897,7 @@
 ; first tile ID of the name being drawn
 
 wFlyLocationsList::
-; 11 bytes plus $ff sentinel values at each end
+; NUM_CITY_MAPS bytes plus $ff sentinel values at each end
 
 wSlotMachineWheel1Offset::
 
@@ -2818,7 +2818,7 @@
 	ds 10
 
 wTownVisitedFlag::
-	flag_array 13
+	flag_array NUM_CITY_MAPS
 
 wSafariSteps::
 ; starts at 502