summaryrefslogtreecommitdiff
path: root/Add-spinner-tiles-from-Generation-I-Rocket-Hideout.md
blob: cf5f7e98cd4116565a97a48f1ca44b3987a0e8ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
This tutorial will cover adding new collision types for spinner tiles in all four cardinal directions as well as a stopper tile to stop the player from spinning. Credit to Rangi42 for implementing this in Pokemon Polished Crystal

## Contents

1. [Create Constants for the New Collision Types](#1-create-constants-for-the-new-collision-types)
2. [Implement New Movement Functionality](#2-implement-new-movement-functionality)
3. [Prevent Oddities When Losing Battles](#3-prevent-oddities-when-losing-battles)


## 1. Create Constants for the New Collision Types

In order to add new collision types to use on maps, we'll have to define constants for them.

Edit [constants/collision_constants.asm](../blob/master/constants/collision_constants.asm)

```diff
 COLL_DOOR_7D           EQU $7d ; unused
 COLL_WARP_CARPET_RIGHT EQU $7e
 COLL_WARP_7F           EQU $7f ; unused
+COLL_STOP_SPIN         EQU $80
+COLL_SPIN_UP           EQU $81
+COLL_SPIN_DOWN         EQU $82
+COLL_SPIN_LEFT         EQU $83
+COLL_SPIN_RIGHT        EQU $84
 COLL_COUNTER           EQU $90
 COLL_BOOKSHELF         EQU $91
 COLL_PC                EQU $93
```

Edit [constants/map_object_constants.asm](../blob/master/constants/map_object_constants.asm)

```diff
 	const STEP_TURN          ; 5
 	const STEP_BACK_LEDGE    ; 6
 	const STEP_WALK_IN_PLACE ; 7
+	const STEP_SPIN          ; 8
```

Edit [data/collision/collision_permissions.asm](../blob/master/data/collision/collision_permissions.asm) (data/collision_permissions.asm on older versions of pokecrystal)

```diff
 	db LAND_TILE         ; COLL_DOOR_7D
 	db LAND_TILE         ; COLL_WARP_CARPET_RIGHT
 	db LAND_TILE         ; COLL_WARP_7F
-	db WALL_TILE         ; 80
-	db WALL_TILE         ; 81
-	db WALL_TILE         ; 82
-	db WALL_TILE         ; 83
-	db WALL_TILE         ; 84
+	db LAND_TILE         ; COLL_STOP_SPIN
+	db LAND_TILE         ; COLL_SPIN_UP
+	db LAND_TILE         ; COLL_SPIN_DOWN
+	db LAND_TILE         ; COLL_SPIN_LEFT
+	db LAND_TILE         ; COLL_SPIN_RIGHT
 	db LAND_TILE         ; 85
 	db LAND_TILE         ; 86
 	db LAND_TILE         ; 87
```

We'll need to add a flag in WRAM to denote whether we are currently spinning.

Edit [wram.asm](../blob/master/wram.asm)
```diff
 wScrollingMenuListSize:: db
 
-	ds 1
-
 ; used when following a map warp
 wNextWarp:: db
 wNextMapGroup:: db

 ...

 wPlayerStepFlags:: db
 wPlayerStepDirection:: db
 
+wSpinning:: db
+
 wBGMapAnchor:: dw
 
 UNION
```

## 2. Implement New Movement Functionality

Now that we have our constants in order, we have to add functionality specific to these tiles.

Edit [engine/overworld/player_movement.asm](../blob/master/engine/overworld/player_movement.asm)
```diff
DoPlayerMovement::

 ...

 	jr z, .bump
 	cp 2
 	jr z, .bump
+	
+	ld a, [wSpinning]
+	and a
+	jr nz, .spin
 
 	ld a, [wPlayerStandingTile]
 	call CheckIceTile
 
 ...
 
 	xor a
 	ret
 
+.spin
+	ld de, SFX_SQUEAK
+	call PlaySFX
+	ld a, STEP_SPIN
+	call .DoStep
+	scf
+	ret
+
 .bump
 	xor a
+	ld [wSpinning], a
 	ret
 
 .TrySurf:
 
 ...

 	dw .TurningStep
  	dw .BackJumpStep
 	dw .FinishFacing
+	dw .SpinStep
 
 .SlowStep:
 	slow_step DOWN
 
 ...
 
 	db $80 | UP
 	db $80 | LEFT
 	db $80 | RIGHT
+.SpinStep
+	turn_in_down
+	turn_in_up
+	turn_in_left
+	turn_in_right
 
 .StandInPlace:
 	ld a, 0
 
 ...

 .CheckForced:
-; When sliding on ice, input is forced to remain in the same direction.
+; When sliding on ice or spinning, input is forced to remain in the same direction.
 
+	call CheckSpinning
+	jr z, .not_spinning
+	dec a
+	jr .force
+
+.not_spinning
 	call CheckStandingOnIce
 	ret nc
 
 ...
 
 	cp 0
 	ret z
 
+.force
 	maskbits NUM_DIRECTIONS
 	ld e, a
 	ld d, 0

 ...

.not_ice
 	and a
 	ret
 
+CheckSpinning::
+	ld a, [wPlayerStandingTile]
+	cp COLL_STOP_SPIN
+	jr z, .stop_spin
+	call CheckSpinTile
+	jr z, .start_spin
+	ld a, [wSpinning]
+	and a
+	ret
+
+.start_spin
+	ld a, c
+	inc a
+	ld [wSpinning], a
+	and a
+	ret
+
+.stop_spin
+	xor a
+	ld [wSpinning], a
+	ret
+
+CheckSpinTile:
+	cp COLL_SPIN_UP
+	ld c, UP
+	ret z
+	cp COLL_SPIN_DOWN
+	ld c, DOWN
+	ret z
+	cp COLL_SPIN_LEFT
+	ld c, LEFT
+	ret z
+	cp COLL_SPIN_RIGHT
+	ld c, RIGHT
+	ret z
+	ld c, STANDING
+	ret
+
 StopPlayerForEvent::
 	ld hl, wPlayerNextMovement
 	ld a, movement_step_sleep
```

## 3. Prevent Oddities When Losing Battles

Since it is possible for battles to begin if trainers spot you while you are spinning, a slight addition must be made to the whiteout engine event script to account for a scenario where the player would never stop spinning.

Edit [engine/events/whiteout.asm](../blob/master/engine/events/whiteout.asm)

```diff
 HalveMoney:
 	farcall StubbedTrainerRankings_WhiteOuts
 
 ; Halve the player's money.
+	xor a
+	ld [wSpinning], a
 	ld hl, wMoney
 	ld a, [hl]
 	srl a
```

This edit can still be made if you've adjusted the money reduction function, just add the two new lines before loading wMoney into hl.

That's the hardest part! All that's left to do is edit blocksets as desired in Polished Map to include tiles with the types SPIN_LEFT, SPIN_UP, SPIN_DOWN, SPIN_RIGHT, and STOP_SPIN.

![Example: Recreation of Rocket Hideout B2F maze](https://i.imgur.com/VLVkebt.png)