-
Notifications
You must be signed in to change notification settings - Fork 10
/
script08.s
409 lines (377 loc) · 13.4 KB
/
script08.s
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
include macros.s
include mainsym.s
; Script 8, elevator, following code
elevatorSound = toxinDelay
org scriptCodeStart
dc.w Elevator
dc.w ElevatorLoop
dc.w RadioUpperLabsElevator
dc.w RadioServicePass
dc.w EscortScientistsRefresh
dc.w EscortScientistsZone
dc.w HackerFollow
dc.w HackerFollowZone
; Enter elevator script
;
; Parameters: -
; Returns: -
; Modifies: various
Elevator: ldx #3
lda levelNum
E_FindLoop: cmp elevatorSrcLevel,x
beq E_Found
dex
bpl E_FindLoop
E_Found: lda elevatorPlotBit,x
jsr GetPlotBit
bne E_HasAccess
E_NoAccess: txa ;Only show message for the upper labs elevator, and only once
bne E_NoRadioMsg
lda lvlObjB+$2b ;No message if wall already opened with the laser
bmi E_NoRadioMsg
lda #PLOT_ELEVATORMSG
jsr GetPlotBit
bne E_NoRadioMsg
lda #PLOT_ELEVATORMSG
jsr SetPlotBit
lda #<EP_RADIOUPPERLABSELEVATOR ;Set a timed script, exec when text cleared
ldx #>EP_RADIOUPPERLABSELEVATOR
jsr SetScript
E_NoRadioMsg: lda #<txtElevatorLocked
ldx #>txtElevatorLocked
ldy #REQUIREMENT_TEXT_DURATION
jmp PrintPanelText
E_HasAccess: stx elevatorIndex
lda #$00
sta elevatorTime
sta elevatorSound
lda #<EP_ELEVATORLOOP
ldx #>EP_ELEVATORLOOP
jsr SetScript
ldy lvlObjNum
iny
tya
E_EnterDoor: jmp ULO_EnterDoorDest
; Enter elevator loop
;
; Parameters: -
; Returns: -
; Modifies: various
ElevatorLoop: ldx elevatorIndex
lda elevatorTime
bne EL_NotFirstFrame
sta charInfo-1 ;Reset elevator speed
EL_NotFirstFrame:
inc elevatorSound
lda elevatorSound
cmp #$03
bcc EL_NoSound
lda #SFX_GENERATOR
jsr PlaySfx
lda #$00
sta elevatorSound
EL_NoSound: lda charInfo-1 ;Accelerate until full speed
cmp elevatorSpeed,x
beq EL_HasFullSpeed
clc
adc elevatorAcc,x
sta charInfo-1
EL_HasFullSpeed:inc elevatorTime
bmi EL_Exit
rts
EL_Exit: jsr StopScript
ldx elevatorIndex
lda elevatorDestLevel,x
jsr ChangeLevel
ldx elevatorIndex
lda elevatorDestObject,x
bpl E_EnterDoor
; Radio speech for upper labs elevator
;
; Parameters: -
; Returns: -
; Modifies: various
RadioUpperLabsElevator:
lda textTime
cmp #35
bcs RULE_Wait
ldy #ITEM_AMPLIFIER
jsr FindItem
bcs RULE_HasAmplifier
lda #<EP_RADIOSECURITYPASS
ldx #>EP_RADIOSECURITYPASS
jsr SetScript
gettext txtRadioElevatorLocked
RadioMsg: ldy #ACT_PLAYER
jsr SpeakLine
lda #SFX_RADIO
jmp PlaySfx
RSP_HasItem:
ESS_WaitUntilClose:
RULE_Wait: rts
RULE_HasAmplifier:
jsr StopScript
gettext txtRadioElevatorLockedHasAmplifier
jmp RadioMsg
; Speech end part (search for service pass, if necessary)
;
; Parameters: -
; Returns: -
; Modifies: various
RadioServicePass:
lda textTime
bne RULE_Wait
jsr StopScript
ldy #ITEM_SERVICEPASS
jsr FindItem
bcs RSP_HasItem
ldy #ACT_PLAYER
gettext txtRadioServicePass
jmp SpeakLine
; Refresh escort scientists sequence (ensure they follow)
;
; Parameters: -
; Returns: -
; Modifies: various
EscortScientistsRefresh:
lda #<EP_ESCORTSCIENTISTSZONE ;Set zone script which keeps the scientists
ldx #>EP_ESCORTSCIENTISTSZONE ;warping to player
jsr SetZoneScript
ldx actIndex
lda #AIMODE_FOLLOW
sta actAIMode,x
lda actT,x
cmp #ACT_SCIENTIST3
beq ESR_FollowPlayer
lda #ACT_SCIENTIST3
jsr FindActor
bcc ESR_NoActor
txa
ldx actIndex
ESR_StoreTarget:sta actAITarget,x
ESR_InDialogue:
ESR_NoActor: rts
ESR_FollowPlayer:
lda actYH,x ;Check for reaching the operation room
cmp #$56
bne ESR_NoGoal
lda actXH,x
cmp #$4f
beq ESR_HasGoal
ESR_NoGoal: lda #ACTI_PLAYER
beq ESR_StoreTarget
ESR_HasGoal: lda #<EP_RADIOFINDFILTER
ldx #>EP_RADIOFINDFILTER
jsr SetZoneScript
lda #<EP_ESCORTSCIENTISTSFINISH
ldx #>EP_ESCORTSCIENTISTSFINISH
sta actScriptEP
stx actScriptF
sta actScriptEP+1
stx actScriptF+1
lda actScriptF+2
bne ESR_SkipJeffScript
lda #<EP_HACKER4 ;Reset Jeff script now that old tunnels trip is possible again
sta actScriptEP+2 ;but not if player didn't visit him in the meanwhile
lda #>EP_HACKER4
sta actScriptF+2
ESR_SkipJeffScript:
jsr AddQuestScore
lda #PLOT_ESCORTCOMPLETE
jmp SetPlotBit
; Escort scientists zone change (warp to player)
;
; Parameters: -
; Returns: -
; Modifies: various
EscortScientistsZone:
lda ECS_LoadedCharSet+1
cmp #$07
beq ESZ_LevelFail ;Do not go inside upgrade research labs
lda levelNum
cmp #$06
beq ESZ_LevelOk
cmp #$08
bne ESZ_LevelFail
lda actXH+ACTI_PLAYER
cmp #$1e ;Check X range in lower labs, don't allow going to the left side (wrong direction)
bcc ESZ_LevelFail ;or far right (contains acid and nether tunnels entry)
cmp #$5a
bcc ESZ_LevelOk
ESZ_LevelFail: jmp StopZoneScript ;Ventured outside valid levels for following, stop
ESZ_LevelOk: lda #ACT_SCIENTIST2
jsr TransportNPCToPlayer
lda #ACT_SCIENTIST3
jmp TransportNPCToPlayer
; To old tunnels follow script
;
; Parameters: -
; Returns: -
; Modifies: various
HF_Climbing: jmp HF_NoJump
HackerFollow: ldx actIndex
lda actF1,x ;Climbing = normal following
cmp #FR_CLIMB
bcs HF_Climbing
lda actMB,x ;Do not follow again until landed
lsr
bcs HF_NotInAir
lda actSY,x
bpl HF_Landing
jmp HF_NoFollow
HF_Landing: lda actMoveCtrl,x ;Clear jump control when landing
and #$7f-JOY_UP
bpl HF_StoreMoveCtrl
HF_NotInAir: lda ECS_LoadedCharSet+1 ;Try to jump over pits in service tunnels
cmp #$05
bne HF_NoChasmJump
ldy actYH,x ;Get block from current position
lda mapTblLo,y
sta zpDestLo
lda mapTblHi,y
sta zpDestHi
ldy actXH,x
lda (zpDestLo),y
cmp #109
beq HF_ChasmRight
cmp #156
beq HF_ChasmRight
cmp #110
beq HF_ChasmLeft
cmp #157
bne HF_NoJump
HF_ChasmLeft: lda actSX,x
bpl HF_NoJump
cmp #-2*8
bcs HF_NoJump
lda actXL,x
bmi HF_NoJump
bpl HF_DoJump
HF_ChasmRight: lda actSX,x
bmi HF_NoJump
cmp #2*8
bcc HF_NoJump
lda actXL,x
bpl HF_NoJump
bmi HF_DoJump
HF_NoChasmJump: lda levelNum
cmp #$08
bne HF_NoJump
lda actXH,x ;Scripted jump to access the old tunnels
cmp #$65 ;(in level8)
bne HF_NoJump
lda actYL,x ;Must be at top of block
bne HF_NoJump
lda actYH,x
cmp #$4a
bne HF_NoJump
lda actSX,x ;Must be going right at max. speed
cmp #4*8
bne HF_NoJump
HF_DoJump: lda actMoveCtrl,x
ora #JOY_UP ;Jump as far as possible
HF_StoreMoveCtrl:
sta actMoveCtrl,x
lda #AIMODE_IDLE
sta actAIMode,x
rts
HF_NoJump: lda #ACT_FIRE ;If standing next to a fire, put it out
jsr FindActor
bcc HF_NoFire
txa
tay
ldx actIndex
jsr GetActorDistance
lda temp8 ;Y-dist must be zero
bne HF_NoFire
lda temp6
cmp #$02
bcs HF_NoFire ;Too far away
cmp #$01 ;If 1 block distance, go next to it
bcc HF_FireXDistOK
tya
bcs HF_SetFollowTarget
HF_FireXDistOK: lda temp5 ;Check direction
bpl HF_FireRight
HF_FireLeft: lda #JOY_FIRE|JOY_LEFT
skip2
HF_FireRight: lda #JOY_FIRE|JOY_RIGHT
HF_FireCommon: ldy temp7 ;If fire is not above, aim down
bmi HF_FireAbove
ora #JOY_DOWN
HF_FireAbove: pha
lda #ITEM_EXTINGUISHER
sta actWpn,x
pla
sta actCtrl,x
lda #$00
beq HF_StoreMoveCtrl
HF_NoFire: ldx actIndex
lda #ACTI_PLAYER
HF_SetFollowTarget:
sta actAITarget,x
lda #AIMODE_FOLLOW
sta actAIMode,x
lda #$00
sta actWpn,x
sta actCtrl,x
HF_NoFollow: lda #<EP_HACKERFOLLOWZONE
ldx #>EP_HACKERFOLLOWZONE
jmp SetZoneScript
; To old tunnels follow zone script
;
; Parameters: -
; Returns: -
; Modifies: various
HackerFollowZone:
lda levelNum
cmp #$0f ;Success condition
beq HFZ_Finished
cmp #$08
bne HFZ_NotLowerLabs
lda actYH+ACTI_PLAYER ;In lower labs do not follow to the lowest level rooms (e.g. surgery room, nether tunnel entrance)
cmp #$55
bcc HFZ_LevelOK
bcs HFZ_LevelFail
HFZ_NotLowerLabs:
lsr
bcc HFZ_LevelOK
cmp #$02 ;Do go to odd-numbered levels 5,7,9,11 (caves, security centers, 2nd courtyard)
bcs HFZ_LevelFail
HFZ_LevelOK: lda #ACT_HACKER
jmp TransportNPCToPlayer
HFZ_Finished: jsr HFZ_LevelOK
jsr AddQuestScore
lda #<EP_HACKERFOLLOWFINISH
ldx #>EP_HACKERFOLLOWFINISH
sta actScriptEP+2
stx actScriptF+2
HFZ_LevelFail: jmp StopZoneScript ;No zone script
; Variables
elevatorIndex: dc.b 0
elevatorTime: dc.b 0
; Elevator tables
elevatorSrcLevel:
dc.b $06,$08,$0a,$0b
elevatorDestLevel:
dc.b $08,$06,$0b,$0a
elevatorDestObject:
dc.b $43,$3e,$0f,$39
elevatorPlotBit:
dc.b PLOT_ELEVATOR1,PLOT_ELEVATOR1,PLOT_ELEVATOR2,PLOT_ELEVATOR2
elevatorSpeed: dc.b 48,-48,-64,64
elevatorAcc: dc.b 2,-2,-2,2
; Messages
txtElevatorLocked:
dc.b "ELEVATOR "
textjump txtLocked
txtRadioElevatorLocked:
dc.b 34,"AMOS HERE AGAIN. YOU NEED A WAY AROUND. "
dc.b "THE LASER IN THE BASEMENT MIGHT CUT THROUGH THE WALL, IF ITS POWER IS BOOSTED. "
dc.b "OUR IT SPECIALIST JEFF COULD HAVE IDEAS. HE'S GOT A PRIVATE HIDEOUT "
dc.b "IN THE SERVICE TUNNELS. JUST WATCH OUT, HE'S A BIT STRANGE.",34,0
txtRadioServicePass:
dc.b 34,"SEARCH THE ENTRANCE OFFICES FOR THE SERVICE PASS.",34,0
txtRadioElevatorLockedHasAmplifier:
dc.b 34,"AMOS HERE. TRY TO INSTALL THE AMPLIFIER TO THE LASER. BOOSTED, IT MIGHT BREACH THE WALL.",34,0
checkscriptend