shithub: pokecrystal

Download patch

ref: 40766b9a76582c6472959e6ff99ba088b150baca
parent: b24cd55f968909c3ec29c6455a32463c987f3063
author: mid-kid <esteve.varela@gmail.com>
date: Thu May 2 15:31:45 EDT 2019

Magnet train fixes

Should make the code slightly easier to read, at least

--- a/engine/events/magnet_train.asm
+++ b/engine/events/magnet_train.asm
@@ -3,14 +3,14 @@
 	and a
 	jr nz, .ToGoldenrod
 	ld a, 1 ; forwards
-	lb bc,  $40,  $60
-	lb de, (11 * 8) - (11 * 8 + 4), -$60
+	lb bc, 8 * TILE_WIDTH, 12 * TILE_WIDTH
+	lb de, (11 * TILE_WIDTH) - (11 * TILE_WIDTH + 4), -12 * TILE_WIDTH
 	jr .continue
 
 .ToGoldenrod:
 	ld a, -1 ; backwards
-	lb bc, -$40, -$60
-	lb de, (11 * 8) + (11 * 8 + 4), $60
+	lb bc, -8 * TILE_WIDTH, -12 * TILE_WIDTH
+	lb de, (11 * TILE_WIDTH) + (11 * TILE_WIDTH + 4), 12 * TILE_WIDTH
 
 .continue
 	ld h, a
@@ -34,11 +34,11 @@
 	push af
 	ldh a, [hSCY]
 	push af
-	call MagntTrain_LoadGFX_PlayMusic
+	call MagnetTrain_LoadGFX_PlayMusic
 	ld hl, hVBlank
 	ld a, [hl]
 	push af
-	ld [hl], $1
+	ld [hl], 1
 .loop
 	ld a, [wJumptableIndex]
 	and a
@@ -84,18 +84,19 @@
 
 MagnetTrain_UpdateLYOverrides:
 	ld hl, wLYOverridesBackup
-	ld c, $2f
+	ld c, 6 * TILE_WIDTH - 1
 	ld a, [wMagnetTrainOffset]
 	add a
 	ldh [hSCX], a
 	call .loadloop
-	ld c, $30
+	ld c, 6 * TILE_WIDTH
 	ld a, [wMagnetTrainPosition]
 	call .loadloop
-	ld c, $31
+	ld c, 6 * TILE_WIDTH + 1
 	ld a, [wMagnetTrainOffset]
 	add a
 	call .loadloop
+
 	ld a, [wMagnetTrainDirection]
 	ld d, a
 	ld hl, wMagnetTrainOffset
@@ -111,7 +112,7 @@
 	jr nz, .loadloop
 	ret
 
-MagntTrain_LoadGFX_PlayMusic:
+MagnetTrain_LoadGFX_PlayMusic:
 	call ClearBGPalettes
 	call ClearSprites
 	call DisableLCD
@@ -118,7 +119,7 @@
 	callfar ClearSpriteAnims
 	call SetMagnetTrainPals
 	call DrawMagnetTrain
-	ld a, $90
+	ld a, SCREEN_HEIGHT_PX
 	ldh [hWY], a
 	call EnableLCD
 	xor a
@@ -125,6 +126,8 @@
 	ldh [hBGMapMode], a
 	ldh [hSCX], a
 	ldh [hSCY], a
+
+	; Load the player sprite
 	ldh a, [rSVBK]
 	push af
 	ld a, BANK(wPlayerGender)
@@ -135,6 +138,8 @@
 	ld hl, vTiles0
 	ld c, 4
 	call Request2bpp
+
+	; Load the trainer walking frame
 	ld hl, 12 tiles
 	add hl, de
 	ld d, h
@@ -142,7 +147,9 @@
 	ld hl, vTiles0 tile $04
 	ld c, 4
 	call Request2bpp
+
 	call MagnetTrain_InitLYOverrides
+
 	ld hl, wJumptableIndex
 	xor a
 	ld [hli], a ; wJumptableIndex
@@ -150,6 +157,7 @@
 	ld [hli], a ; wMagnetTrainOffset
 	ld [hli], a ; wMagnetTrainPosition
 	ld [hli], a ; wMagnetTrainWaitCounter
+
 	ld de, MUSIC_MAGNET_TRAIN
 	call PlayMusic2
 	ret
@@ -159,25 +167,26 @@
 	xor a
 .loop
 	call GetMagnetTrainBGTiles
-	ld b, 32 / 2
+	ld b, BG_MAP_WIDTH / 2
 	call .FillAlt
 	inc a
-	cp $12
+	cp SCREEN_HEIGHT
 	jr c, .loop
+
 	hlbgcoord 0, 6
-	ld de, MagnetTrainTilemap1
+	ld de, MagnetTrainTilemap
 	ld c, 20
 	call .FillLine
 	hlbgcoord 0, 7
-	ld de, MagnetTrainTilemap2
+	ld de, MagnetTrainTilemap + 20
 	ld c, 20
 	call .FillLine
 	hlbgcoord 0, 8
-	ld de, MagnetTrainTilemap3
+	ld de, MagnetTrainTilemap + (20 * 2)
 	ld c, 20
 	call .FillLine
 	hlbgcoord 0, 9
-	ld de, MagnetTrainTilemap4
+	ld de, MagnetTrainTilemap + (20 * 3)
 	ld c, 20
 	call .FillLine
 	ret
@@ -247,7 +256,7 @@
 	ret
 
 SetMagnetTrainPals:
-	ld a, $1
+	ld a, 1
 	ldh [rVBK], a
 
 	; bushes
@@ -274,7 +283,7 @@
 	ld a, PAL_BG_YELLOW
 	call ByteFill
 
-	ld a, $0
+	ld a, 0
 	ldh [rVBK], a
 	ret
 
@@ -305,7 +314,7 @@
 	ret
 
 .InitPlayerSpriteAnim:
-	ld d, 10 * 8 + 5
+	ld d, (8 + 2) * TILE_WIDTH + 5
 	ld a, [wMagnetTrainPlayerSpriteInitX]
 	ld e, a
 	ld b, SPRITE_ANIM_INDEX_MAGNET_TRAIN_RED
@@ -317,7 +326,6 @@
 	bit PLAYERGENDER_FEMALE_F, a
 	jr z, .got_gender
 	ld b, SPRITE_ANIM_INDEX_MAGNET_TRAIN_BLUE
-
 .got_gender
 	pop af
 	ldh [rSVBK], a
@@ -325,9 +333,9 @@
 	call _InitSpriteAnimStruct
 	ld hl, SPRITEANIMSTRUCT_TILE_ID
 	add hl, bc
-	ld [hl], $0
+	ld [hl], 0
 	call .Next
-	ld a, $80
+	ld a, 128
 	ld [wMagnetTrainWaitCounter], a
 	ret
 
@@ -350,7 +358,7 @@
 
 .PrepareToHoldTrain:
 	call .Next
-	ld a, $80
+	ld a, 128
 	ld [wMagnetTrainWaitCounter], a
 	ret
 
@@ -408,6 +416,7 @@
 	call MagnetTrain_UpdateLYOverrides
 	call PushLYOverrides
 	call DelayFrame
+
 	ldh a, [rSVBK]
 	push af
 	ld a, BANK(wEnvironment)
@@ -416,14 +425,16 @@
 	push af
 	ld a, [wEnvironment]
 	push af
+
 	ld a, [wTimeOfDay]
 	maskbits NUM_DAYTIMES
 	ld [wTimeOfDayPal], a
-	ld a, $1
+	ld a, TOWN
 	ld [wEnvironment], a
 	ld b, SCGB_MAPPALS
 	call GetSGBLayout
 	call UpdateTimePals
+
 	ldh a, [rBGP]
 	ld [wBGP], a
 	ldh a, [rOBP0]
@@ -430,6 +441,7 @@
 	ld [wOBP0], a
 	ldh a, [rOBP1]
 	ld [wOBP1], a
+
 	pop af
 	ld [wEnvironment], a
 	pop af
@@ -438,11 +450,8 @@
 	ldh [rSVBK], a
 	ret
 
-MagnetTrainTilemap1:
+MagnetTrainTilemap:
 	db $1f, $05, $06, $0a, $0a, $0a, $09, $0a, $0a, $0a, $0a, $0a, $0a, $09, $0a, $0a, $0a, $0b, $0c, $1f
-MagnetTrainTilemap2:
 	db $14, $15, $16, $1a, $1a, $1a, $19, $1a, $1a, $1a, $1a, $1a, $1a, $19, $1a, $1a, $1a, $1b, $1c, $1d
-MagnetTrainTilemap3:
 	db $24, $25, $26, $27, $07, $2f, $29, $28, $28, $28, $28, $28, $28, $29, $07, $2f, $2a, $2b, $2c, $2d
-MagnetTrainTilemap4:
 	db $20, $1f, $2e, $1f, $17, $00, $2e, $1f, $1f, $1f, $1f, $1f, $1f, $2e, $17, $00, $1f, $2e, $1f, $0f