-
Notifications
You must be signed in to change notification settings - Fork 10
/
actor.s
2280 lines (2127 loc) · 72.5 KB
/
actor.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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
MAX_ACTX = 14
MAX_ACTY = 9
AD_NUMSPRITES = 0
AD_SPRFILE = 1
AD_LEFTFRADD = 2
AD_NUMFRAMES = 3 ;For incrementing framepointer. Only significant if multiple sprites
AD_FRAMES = 4
ADD_SPRFILE = 1
ADD_BASEFRAME = 2
ADH_SPRFILE = 1
ADH_BASEFRAME = 2
ADH_BASEINDEX = 3 ;Index to a static 256-byte table for humanoid actor spriteframes
ADH_LEFTFRADD = 4
ADH_SPRFILE2 = 5
ADH_BASEFRAME2 = 6
ADH_BASEINDEX2 = 7 ;Index to a static 256-byte table for humanoid actor framenumbers
ADH_LEFTFRADD2 = 8
ONESPRITEDIRECT = $00
ONESPRITE = $01
TWOSPRITE = $02
THREESPRITE = $03
FOURSPRITE = $04
FIVESPRITE = $05
HUMANOID = $80
COLOR_FLICKER = $40
COLOR_INVISIBLE = $80
COLOR_ONETIMEFLASH = $fe
COLOR_ONETIMEFLASHDELAY = $ff
AL_UPDATEROUTINE = 0
AL_ACTORFLAGS = 2
AL_SIZEHORIZ = 3
AL_SIZEUP = 4
AL_SIZEDOWN = 5
AL_DESTROYROUTINE = 6
AL_INITIALHP = 8
AL_DMGMODIFY = 9
AL_SCORE = 10
AL_SPAWNAIMODE = 12
AL_DROPITEMTYPE = 13
AL_OFFENSE = 14
AL_DEFENSE = 15
AL_ATTACKDIRS = 16
AL_MOVEFLAGS = 17
AL_MOVESPEED = 18
AL_GROUNDACCEL = 19
AL_INAIRACCEL = 20
AL_FALLACCEL = 21 ;Gravity acceleration
AL_LONGJUMPACCEL = 22 ;Gravity acceleration in longjump
AL_BRAKING = 23
AL_HEIGHT = 24 ;Height for headbump check, negative
AL_JUMPSPEED = 25 ;Negative
AL_CLIMBSPEED = 26
AL_XMOVESPEED = 17
AL_XACCEL = 18
AL_YMOVESPEED = 19
AL_YACCEL = 20
AL_XCHECKOFFSET = 21
AL_YCHECKOFFSET = 22
GRP_HEROES = $00
GRP_ENEMIES = $01
GRP_ANIMALS = $02
AF_GROUPBITS = $03
AF_INITONLYSIZE = $10
AF_ORGANIC = $20
AF_NOREMOVECHECK = $40
AF_NOWEAPON = $80
AMF_JUMP = $01
AMF_DUCK = $02
AMF_CLIMB = $04
AMF_ROLL = $08
AMF_WALLFLIP = $10
AMF_FALLDAMAGE = $20
AMF_CUSTOMANIMATION = $80
ADDACTOR_LEFT_LIMIT = 1
ADDACTOR_RIGHT_LIMIT = 11
ADDACTOR_BOTTOM_LIMIT = 8
ORG_TEMP = $00 ;Temporary actor, may be overwritten by global or leveldata
ORG_GLOBAL = $40 ;Global important actor
ORG_LEVELDATA = $80 ;Leveldata actor, added/removed at level change
ORG_NOTPERSISTENT = $ff
ORG_LEVELNUM = $3f
DEFAULT_PICKUP = $ff
LVLOBJSEARCH = 32
LVLACTSEARCH = 32
NODAMAGESRC = $80
SPAWNINFRONT_PROBABILITY = $c0
SPAWN_GROUND = $00
SPAWN_AIR = $80
SPAWN_AIRTOP = $c0
SPAWN_AIRBOTTOM = $e0
DMG_SFX_DELAY = 2
LEFTFRAME_FLIP = $80
USESCRIPT = $8000
ACT_NONE = 0
ACT_PLAYER = 1
ACT_ITEM = 2
ACT_MELEEHIT = 3
ACT_LARGEMELEEHIT = 4
ACT_POWDER = 5
ACT_BULLET = 6
ACT_SHOTGUNBULLET = 7
ACT_RIFLEBULLET = 8
ACT_FLAME = 9
ACT_EMP = 10
ACT_LASER = 11
ACT_PLASMA = 12
ACT_LAUNCHERGRENADE = 13
ACT_GRENADE = 14
ACT_ROCKET = 15
ACT_MINE = 16
ACT_EXPLOSION = 17
ACT_SMOKETRAIL = 18
ACT_WATERSPLASH = 19
ACT_SMALLSPLASH = 20
ACT_OBJECTMARKER = 21
ACT_SPEECHBUBBLE = 22
ACT_EXPLOSIONGENERATOR = 23
ACT_SMALLDROID = 24
ACT_LARGEDROID = 25
ACT_EXPLOSIONGENERATORRISING = 26
ACT_FLYINGCRAFT = 27
ACT_SMALLWALKER = 28
ACT_SMALLTANK = 29
ACT_FLOATINGMINE = 30
ACT_ROLLINGMINE = 31
ACT_CEILINGTURRET = 32
ACT_FIRE = 33
ACT_SMOKECLOUD = 34
ACT_RAT = 35
ACT_SPIDER = 36
ACT_FLY = 37
ACT_BAT = 38
ACT_FISH = 39
ACT_ROCK = 40
ACT_FIREBALL = 41
ACT_STEAM = 42
ACT_ORGANICWALKER = 43
ACT_GUARD = 44
ACT_HEAVYGUARD = 45
ACT_LIGHTGUARD = 46
ACT_COMBATROBOT = 47
ACT_COMBATROBOTFAST = 48
ACT_LARGEWALKER = 49
ACT_SCRAPMETAL = 50
ACT_ROCKTRAP = 51
ACT_CPU = 52
ACT_SUPERCPU = 53
ACT_EYEINVISIBLE = 54
ACT_EYE = 55
ACT_JORMUNGANDR = 56
ACT_LARGETANK = 57
ACT_HIGHWALKER = 58
ACT_GENERATOR = 59
ACT_SECURITYCHIEF = 60
ACT_ROTORDRONE = 61
ACT_LARGESPIDER = 62
ACT_ACID = 63
ACT_SPIDERCHUNK = 64
ACT_ARMORER = 65
ACT_THRONECHIEF = 66
ACT_MEDIUMWALKER = 67
ACT_SCIENTIST1 = 68
ACT_SCIENTIST2 = 69
ACT_SCIENTIST3 = 70
ACT_HACKER = 71
ACT_HAZMAT = 72
ACT_COMBATROBOTSABOTEUR = 73
ACT_ENDINGSPRITES = 74
ACT_ENDINGSPRITES2 = 75
ACT_FIRSTPERSISTENTNPC = ACT_SCIENTIST2
HP_PLAYER = 56
HP_NONCOMBATANT = 0
HP_ACID = 1
HP_RAT = 4
HP_FLY = 4
HP_BAT = 4
HP_SPIDER = 6
HP_FLOATINGMINE = 7
HP_ROLLINGMINE = 7
HP_SCIENTIST1 = 8
HP_SMALLDROID = 8
HP_LIGHTGUARD = 10
HP_ROCK = 10
HP_SCIENTIST2 = 14
HP_FLYINGCRAFT = 14
HP_ORGANICWALKER = 14
HP_GUARD = 14
HP_LARGEDROID = 16
HP_SMALLWALKER = 16
HP_COMBATROBOT = 18
HP_HEAVYGUARD = 20
HP_HACKER = 22
HP_MEDIUMWALKER = 24
HP_SMALLTANK = 24
HP_CEILINGTURRET = 28
HP_CPU = 32
HP_ROTORDRONE = 36
HP_HIGHWALKER = 40
HP_ARMORER = 40
HP_LARGEWALKER = 48
HP_SUPERCPU = 48
HP_LARGETANK = 56
HP_SECURITYCHIEF = 64
HP_LARGESPIDER = 72
HP_JORMUNGANDR = 128
HP_EYE = 144
MOD_HEAVYROBOT = 7
MOD_BOSS = 3
; Draw actors as sprites
; Accesses the sprite cache to load/unpack new sprites as necessary
;
; Parameters: -
; Returns: -
; Modifies: A,X,Y,temp vars,actor ZP temp vars
DrawActors: lda scrollX ;Save this frame's finescrolling for InterpolateActors
sta IA_PrevScrollX+1
lda SL_CSSScrollY+1
sta IA_PrevScrollY+1
ldx GASS_CurrentFrame+1
stx GASS_LastFrame+1
DA_IncCacheFrame:
inx ;Increment framenumber for sprite cache
beq DA_IncCacheFrame ;(framenumber is never 0)
stx GASS_CurrentFrame+1
txa
DA_CheckCacheAge:
ldx #MAX_CACHESPRITES-1
sec ;If age stored in cache is older than significant, reset
sbc cacheSprAge,x ;to prevent overflow error (check one sprite per frame)
cmp #$04
bcc DA_CacheAgeOK
lda #$00
sta cacheSprAge,x
DA_CacheAgeOK: dex
txa
and #MAX_CACHESPRITES-1
sta DA_CheckCacheAge+1 ;Check next cache sprite on next frame
ldx #$00 ;Reset amount of used sprites
stx sprIndex
DA_Loop: lda actT,x
beq DA_ActorDone2
if SHOW_ACTOR_TIME > 0
lda #$02
sta $d020
endif
lda actYL,x ;Convert actor coordinates to screen
sta actPrevYL,x
sec
DA_SprSubYL: sbc #$00
sta temp3
lda actYH,x
sta actPrevYH,x
DA_SprSubYH: sbc #$00
cmp #MAX_ACTY
bcs DA_ActorDone
tay
lda temp3
lsr
lsr
lsr
ora coordTblLo+1,y
sta GASS_YLo+1 ;Y pos
lda coordTblHi+1,y
sta GASS_YHi+1
lda actXL,x
sta actPrevXL,x
sec
DA_SprSubXL: sbc #$00
sta temp1
lda actXH,x
sta actPrevXH,x
DA_SprSubXH: sbc #$00
cmp #MAX_ACTX ;Skip if significantly outside the screen
bcs DA_ActorDone
tay
lda temp1
lsr
lsr
lsr
ora coordTblLo,y
sta GASS_XLo+1 ;X add
lda coordTblHi,y
sta GASS_XHi+1
lda #$00
sta temp1 ;X current pos within actor
sta temp3 ;Y current pos within actor
stx actIndex
jsr DrawActorSub
stx sprIndex
ldx actIndex
DA_ActorDone: if SHOW_ACTOR_TIME > 0
lda #$00
sta $d020
endif
DA_ActorDone2: inx
cpx #MAX_ACT
bcc DA_Loop
DA_FillSprites: ldx sprIndex ;If less sprites used than last frame, set unused Y-coords to max.
txa
ldy #$ff
DA_FillSpritesLoop:
sty sprY,x
inx
DA_LastSprIndex:cpx #$00
bcc DA_FillSpritesLoop
DA_FillSpritesDone:
sta DA_LastSprIndex+1
rts
DA_Invisible: ldx sprIndex ;DrawActors expects sprIndex in X
rts ;even if no sprites were used
DA_HitFlash: inc actFlash,x
eor #$01
and #$01
bpl DA_NoFlicker
DrawActorSub: lda actFlash,x ;Get programmatic color override
bmi DA_HitFlash ;including one frame hit flash
cmp #COLOR_FLICKER
bcc DA_NoFlicker
txa ;Use actor index low bit to determine
and #$01
lsr ;which sprites flicker this frame
ror
ora #COLOR_FLICKER
DA_NoFlicker: sta GASS_ColorOr+1
ldy #$0f
and #$0f
beq DA_KeepSpriteColor
ldy #$00
DA_KeepSpriteColor:
sty GASS_ColorAnd+1
DrawActorSub_NoColor:
ldy actT,x
lda actDispTblHi-1,y ;Zero display address = invisible
beq DA_Invisible
sta actHi
lda actDispTblLo-1,y ;Get actor display structure address
sta actLo
ldy #AD_SPRFILE ;Get spritefile
lda (actLo),y
cmp sprFileNum
beq DA_SameSprFile
tay
lda fileHi,y
bne DA_SprFileLoaded
jsr LoadSpriteFile
DA_SprFileLoaded:
sta sprFileHi
lda fileLo,y
sta sprFileLo
sty sprFileNum
DA_SameSprFile: ldy #AD_NUMSPRITES ;Get number of sprites / humanoid flag
clc
lda (actLo),y
bpl DA_Normal
DA_Humanoid: lda actWpnF,x
sta DA_HumanWpnF+1
lda actF2,x
ldy actD,x
bpl DA_HumanRight2
ldy #ADH_LEFTFRADD2 ;Add left frame offset if necessary
adc (actLo),y
DA_HumanRight2: ldy #ADH_BASEINDEX2
adc (actLo),y
tay
lda humanUpperFrTbl,y ;Take sprite frame from the frametable
ldy #ADH_BASEFRAME2
adc (actLo),y
sta temp5
lda actF1,x
ldy actD,x
bpl DA_HumanRight1
ldy #ADH_LEFTFRADD ;Add left frame offset if necessary
adc (actLo),y
DA_HumanRight1: ldy #ADH_BASEINDEX
adc (actLo),y
tay
lda humanLowerFrTbl,y ;Take sprite frame from the frametable
ldy #ADH_BASEFRAME
adc (actLo),y
ldx sprIndex
jsr GetAndStoreSprite
ldy #ADH_SPRFILE2 ;Get second part spritefile
lda (actLo),y
cmp sprFileNum
beq DA_SameSprFile2
tay
lda fileHi,y
bne DA_SprFileLoaded2
jsr LoadSpriteFile
DA_SprFileLoaded2:
sta sprFileHi
lda fileLo,y
sta sprFileLo
sty sprFileNum
DA_SameSprFile2:lda temp5
jsr GetAndStoreSprite
DA_HumanWpnF: lda #$00
cmp #NOWEAPONFRAME
beq DA_HumanNoWeapon
ldy #$0f ;No color override for the weapon sprite
sty GASS_ColorAnd+1
ldy #$00
sty GASS_ColorOr+1
ldy #C_WEAPON ;Note: weapon sprites must always be loaded
sty sprFileNum ;into the memory
ldy fileLo+C_WEAPON
sty sprFileLo
ldy fileHi+C_WEAPON
sty sprFileHi
DA_NormalLast: jmp GetAndStoreSprite
DA_Normal: beq DA_Direct
sta temp5
lda actF1,x
ldy actD,x
bpl DA_NormalRight
ldy #AD_LEFTFRADD ;Add left frame offset if necessary
adc (actLo),y
DA_NormalRight: adc #AD_FRAMES
bmi DA_NormalFlipLeft
sta temp6 ;Store framepointer
ldx sprIndex
DA_NormalLoop: tay
lda (actLo),y
dec temp5 ;Decrement actor sprite count
beq DA_NormalLast
jsr GetAndStoreSprite
ldy #AD_NUMFRAMES
lda temp6 ;Advance framepointer
clc
adc (actLo),y
sta temp6
bcc DA_NormalLoop
DA_HumanNoWeapon:
AA_Paused:
rts
DA_Direct: ldy #ADD_BASEFRAME
lda actF1,x
adc (actLo),y
ldx sprIndex
bpl DA_NormalLast
DA_NormalFlipLeft:
sbc #$80-1 ;C=0
tay
lda (actLo),y
ora #$80
ldx sprIndex
bpl DA_NormalLast
; Add actors to screen and perform other miscellaneous tasks, like spawners and navigation AI
; Do nothing if game paused
;
; Parameters: -
; Returns: -
; Modifies: A,X,Y,temp regs
RedrawAndAddActors:
jsr RedrawScreen
jsr SetZoneColors
AddAllActors: lda #MAX_LVLACT
sta AA_EndCmp+1
lda #$00
sta AA_Start+1
AddActors: lda menuMode
cmp #MENU_PAUSE
bcs AA_Paused
; Get screen border map coordinates for adding/removing actors
GetActorBorders:lda SL_CSSMapX+1 ;Calculate borders for add/removechecks
sec
sbc #ADDACTOR_LEFT_LIMIT
bcs GAB_LeftOK1
lda #$00
GAB_LeftOK1: cmp limitL
bcs GAB_LeftOK2
lda limitL
GAB_LeftOK2: sta AA_LeftCheck+1
sec
sbc #$00
bcs GAB_LeftOK3
lda #$00
GAB_LeftOK3: sta UA_RALeftCheck+1
lda SL_CSSMapX+1
clc
adc #ADDACTOR_RIGHT_LIMIT
bcc GAB_RightOK1
lda #$ff
GAB_RightOK1: cmp limitR
bcc GAB_RightOK2
lda limitR
GAB_RightOK2: sta AA_RightCheck+1
clc
adc #$01
sta UA_RARightCheck+1
lda SL_CSSMapY+1
GAB_TopOK1: cmp limitU
bcs GAB_TopOK2
lda limitU
GAB_TopOK2: sta AA_TopCheck+1
lda SL_CSSMapY+1
clc
adc #ADDACTOR_BOTTOM_LIMIT
bpl GAB_BottomOK1
lda #$7f
GAB_BottomOK1: cmp limitD
bcc GAB_BottomOK2
lda limitD
GAB_BottomOK2: sta UA_RABottomCheck+1 ;Bottom border
sta AA_BottomCheck+1
; Add actors from leveldata to screen
AA_Start: ldx #$00
AA_Loop: lda lvlActT,x
beq AA_Skip
lda lvlActOrg,x ;Must be either a current level's leveldata actor,
bmi UA_LevelOK ;or a global/temp actor with matching level
and #ORG_LEVELNUM
cmp levelNum
bne AA_Skip
UA_LevelOK: lda lvlActX,x
AA_LeftCheck: cmp #$00
bcc AA_Skip
AA_RightCheck: cmp #$00
bcs AA_Skip
lda lvlActY,x
AA_TopCheck: cmp #$00
bcc AA_Skip
AA_BottomCheck: cmp #$00
bcs AA_Skip
jsr AddLevelActor
ldx temp8
AA_Skip: inx
AA_EndCmp: cpx #LVLACTSEARCH
bne AA_Loop
cpx #MAX_LVLACT
bcc AA_IndexNotOver
ldx #$00
clc
AA_IndexNotOver:stx AA_Start+1 ;Store search start & endpositions for next frame
txa
adc #LVLACTSEARCH
sta AA_EndCmp+1
; Process spawning
UA_DoSpawn: lda menuMode ;No new enemies during dialogue / interaction
bne UA_SpawnDone
ldy #ZONEH_SPAWNCOUNT
lda numSpawned
cmp (zoneLo),y
bcs UA_SpawnDone
dey
jsr Random
and (zoneLo),y
clc
UA_SpawnDelay: adc #$00 ;Spawn delay counting
bcc UA_SpawnNotOver
lda #$ff ;Clamp to maximum so that we will retry each frame
UA_SpawnNotOver:sta UA_SpawnDelay+1 ;until spawn actually successful
bcc UA_SpawnRandomize
dey
lda (zoneLo),y ;Take global spawnlist parameter
tay
UA_SpawnParam: lda #$00
and spawnListAndTbl,y
clc
adc spawnListAddTbl,y
jsr AttemptSpawn
jmp BuildTargetList
UA_SpawnRandomize:
jsr Random ;Do not re-randomize when retrying, otherwise
sta UA_SpawnParam+1 ;flying enemies would be greatly favored over groundbased
UA_SpawnDone:
; Build target list for AI & bullet collision
BuildTargetList:ldx #ACTI_LASTNPC
ldy #$00 ;Target list index
sty numSpawned
BTL_Loop: lda actT,x
beq BTL_Next
lda actLvlDataOrg,x
cmp #ORG_NOTPERSISTENT
bne BTL_NotSpawned
inc numSpawned
BTL_NotSpawned: lda actHp,x ;Actor must have nonzero health
beq BTL_Next
txa
sta targetList,y
iny
BTL_Next: dex
bpl BTL_Loop
lda #$ff ;Store endmark
sta targetList,y
sty numTargets
; Perform AI linecheck for one actor at a time + search for potential better target
CL_Current: ldx #ACTI_FIRSTNPC
CL_Loop: dex
bne CL_NotOver
ldx #ACTI_LASTNPC
CL_NotOver: stx CL_Current+1
lda actT,x
beq CL_Done
ldy actAITarget,x
bmi CL_Done
jsr PickTargetSub ;Check if another target is closer
cmp actAITarget,x
beq CL_NoBetterTarget
tay
lda actFlags,x ;Must not be in same group
eor actFlags,y
and #AF_GROUPBITS
beq CL_NoBetterTarget
sty temp1
ldy actAITarget,x
jsr GetActorDistanceCoarse
lda temp6
clc
adc temp8 ;Distance to old target
sta temp2
ldy temp1
jsr GetActorDistanceCoarse
lda temp6
sec ;Bias against the new target
adc temp8
cmp temp2
bcs CL_NoBetterTarget
jmp FT_SetNewTarget ;Set new target, reset linecheck
CL_Done: rts
CL_NoBetterTarget:
ldy actAITarget,x
LineCheck: lda actXH,x
sta temp1
lda actXH,y
sta LC_CmpX+1
cmp temp1 ;Check left side of block if going left
lda #$05 ;or vice versa to stop at narrow walls
adc #$00 ;(significant in Bio-dome level)
sta LC_BlockPos+1
lda actAIMode,x ;Special conditions for fish
cmp #AIMODE_FISH
bne LC_NotFish
lda actLine,x
bpl LC_FishCheckLine
LC_FishHasLine: lda actMB,x ;When fish already has line of sight, can lose it only
and #MB_HITWALL|MB_HITWALLVERTICAL ;by colliding to walls
beq CL_Done
jmp LC_NoLine
LC_FishCheckLine:
lda actYH,x
sta temp2
bcs LC_FishCheckLine2 ;C=1
LC_NotFish: cmp #AIMODE_FLYER
beq LC_NotHigher
lda actYL,x ;Check 1 block higher if own low Y-pos < $80
asl ;(except for flyer / ceiling turret AI)
LC_NotHigher: lda actYH,x
sbc #$00
sta temp2
lda actYL,y ;Check 1 block higher if target low Y-pos < $80
asl
LC_FishCheckLine2:
lda actYH,y
sbc #$00
sta LC_CmpY+1
sta LC_CmpY2+1
lda #MAX_LINE_STEPS
sta temp3
ldy temp2 ;Take initial maprow
lda mapTblLo,y
sta zpSrcLo
lda mapTblHi,y
sta zpSrcHi
bne LC_InitialCheck ;Check that isn't inside an obstacle (flyers)
LC_Loop: ldy temp1
LC_CmpX: cpy #$00
bcc LC_MoveRight
bne LC_MoveLeft
ldy temp2
LC_CmpY: cpy #$00
bcc LC_MoveDown
bne LC_MoveUp
LC_HasLine: lda #LINE_YES
LC_StoreLine: sta actLine,x
rts
LC_MoveRight: iny
bcc LC_MoveXDone
LC_MoveLeft: dey
LC_MoveXDone: sty temp1
ldy temp2
LC_CmpY2: cpy #$00
bcc LC_MoveDown
beq LC_MoveYDone2
LC_MoveUp: dey
bcs LC_MoveYDone
LC_MoveDown: iny
LC_MoveYDone: sty temp2
lda mapTblLo,y
sta zpSrcLo
lda mapTblHi,y
sta zpSrcHi
LC_MoveYDone2: dec temp3
beq LC_NoLine
LC_InitialCheck:ldy temp1
lda (zpSrcLo),y
tay
lda blkTblLo,y
sta zpDestLo
lda blkTblHi,y
sta zpDestHi
LC_BlockPos: ldy #$06 ;Check from upper middle of block
LC_Lda: lda (zpDestLo),y
tay
lda charInfo,y
and #CI_OBSTACLE
beq LC_Loop
LC_NoLine: ldy actAITarget,x ;Special hack: if target is standing at zone edge
lda temp1 ;and line check hit obstacle there, allow line of sight
cmp actXH,y
bne LC_NoLineNoEdge
cmp limitL
beq LC_HasLine
adc #$00
cmp limitR
beq LC_HasLine
LC_NoLineNoEdge:lda #LINE_NO
bne LC_StoreLine
; Call update routines of all actors, then interpolate. If game is paused, only interpolate
;
; Parameters: -
; Returns: -
; Modifies: A,X,Y,temp vars,actor temp vars
UA_Paused: stx scrollSX ;Stop scrolling when paused & only interpolate
stx scrollSY
jmp InterpolateActors
UA_Remove: jsr RemoveLevelActor
beq UA_Next
UpdateActors: ldx #$00
stx shakeScreen
lda menuMode
cmp #MENU_PAUSE
bcs UA_Paused
UA_NoShakeReset:lda wdMinigunDamage ;Hack: fluctuate minigun damage between 5 & 6
eor #$03
sta wdMinigunDamage
ldx #MAX_ACT-1
UA_Loop: ldy actT,x
beq UA_Next
UA_NotZero: stx actIndex
lda actLogicTblLo-1,y
sta actLo
lda actLogicTblHi-1,y
sta actHi
lda actFlags,x ;Perform remove check?
asl
bmi UA_NoRemoveCheck
lda actXH,x
UA_RALeftCheck: cmp #$00
bcc UA_Remove
UA_RARightCheck:cmp #$00
bcs UA_Remove
lda actYH,x ;Note: use mapY as the top remove border, as the zone
cmp SL_CSSMapY+1 ;may not be a full screen tall
bcc UA_Remove
UA_RABottomCheck:
cmp #$00
bcs UA_Remove
UA_NoRemoveCheck:
if SHOW_ACTOR_TIME > 0
lda #$0a
sta $d020
endif
cpx #MAX_COMPLEXACT ;Run AI for NPCs
bcs UA_NoAI
lda actCtrl,x
sta actPrevCtrl,x
ldy actAIMode,x
beq UA_NoAI
lda aiJumpTblLo-1,y
sta UA_AIJump+1
lda aiJumpTblHi-1,y
sta UA_AIJump+2
UA_AIJump: jsr $0000
UA_NoAI: ldy #AL_UPDATEROUTINE+1
jsr ActorCall
UA_Next: if SHOW_ACTOR_TIME > 0
lda #$00
sta $d020
endif
dex
bpl UA_Loop
UA_AllDone: inc UA_ItemFlashCounter+1
UA_ItemFlashCounter: ;Get color override for items + object marker
lda #$00
lsr
lsr
and #$03
tax
lda itemFlashTbl,x
sta FlashActor+1
ora #$08
tax
ldy actHp+ACTI_PLAYER ;Flash the H & B letters if health or battery low
cpy #LOW_HEALTH+1
bcc UA_FlashHealth
lda #$08
UA_FlashHealth: sta colors+PANELROW*40+49
txa
ldy battery+1
cpy #LOW_BATTERY+1
bcc UA_FlashBattery
lda #$08
UA_FlashBattery:sta colors+PANELROW*40+63
; Interpolate actors' movement each second frame
InterpolateActors:
stx Irq6_LevelUpdate+1 ;Enable/disable level char animation
lda scrollX
sec
IA_PrevScrollX: sbc #$00
bmi IA_ScrollXNeg
cmp #$05
bcc IA_ScrollXOk
sbc #$08
bcc IA_ScrollXOk
IA_ScrollXNeg: cmp #$fc
bcs IA_ScrollXOk
adc #$08
IA_ScrollXOk: sta IA_ScrollXAdjust+1
lda SL_CSSScrollY+1
sec
IA_PrevScrollY: sbc #$00
bmi IA_ScrollYNeg
cmp #$05
bcc IA_ScrollYOk
sbc #$08
bcc IA_ScrollYOk
IA_ScrollYNeg: cmp #$fc
bcs IA_ScrollYOk
adc #$08
IA_ScrollYOk: sta IA_ScrollYAdjust+1
ldx DA_LastSprIndex+1
dex
bpl IA_SprLoop
rts
IA_SprLoop: lda sprC,x ;Process flickering
cmp #COLOR_FLICKER
bcc IA_NoFlicker
eor #COLOR_INVISIBLE ;If sprite is invisible on this frame,
sta sprC,x ;no need to calculate & add offset
bmi IA_Next
IA_NoFlicker: ldy sprAct,x ;Take actor number associated with sprite
lda actPrevYH,y ;Offset already calculated?
cmp #$c0
beq IA_AddOffset
lda actXL,y ;Calculate average movement
sec ;of actor in X-direction
sbc actPrevXL,y
sta temp1
lda actXH,y
sbc actPrevXH,y
lsr
ror temp1
lda temp1
lsr
lsr
lsr
bit temp1
bpl IA_XMovePos
ora #$f0
adc #$00
IA_XMovePos: sec
IA_ScrollXAdjust:
sbc #$00 ;Add scrolling
sta actPrevXL,y
clc
bmi IA_XOffsetNeg
adc sprXL,x
sta sprXL,x ;Add offset to sprite
lda #$00
beq IA_XOffsetCommon
IA_XOffsetNeg: adc sprXL,x
sta sprXL,x
lda #$ff
IA_XOffsetCommon:
adc sprXH,x
sta sprXH,x
lda actYL,y ;Calculate average movement
sec ;of actor in Y-direction
sbc actPrevYL,y
sta temp1
lda actYH,y
sbc actPrevYH,y
lsr
ror temp1
lda temp1
lsr
lsr
lsr
bit temp1
bpl IA_YMovePos
ora #$e0
adc #$00
IA_YMovePos: sec
IA_ScrollYAdjust:
sbc #$00 ;Add scrolling
sta actPrevYL,y
clc
adc sprY,x
sta sprY,x ;Add offset to sprite
lda #$c0 ;Replace the Y-coord MSB with a marker
sta actPrevYH,y ;so we don't repeat this calculation
IA_Next: dex
bmi IA_Done
jmp IA_SprLoop
IA_AddOffset: lda actPrevXL,y ;Add offset to sprite coords
clc
bmi IA_XOffsetNeg2
adc sprXL,x
sta sprXL,x
lda #$00
beq IA_XOffsetCommon2
IA_XOffsetNeg2: adc sprXL,x
sta sprXL,x
lda #$ff
IA_XOffsetCommon2:
adc sprXH,x
sta sprXH,x
lda sprY,x
clc
adc actPrevYL,y
sta sprY,x
dex
bmi IA_Done
jmp IA_SprLoop
IA_Done: rts
; Disable actor interpolation for the current position
;
; Parameters: X actor index
; Returns: -
; Modifies: A
MoveActorCharUp:
lda #-8*8
skip2
MoveActorHalfBlockUp:
lda #-15*8
MoveActorYNoInterpolation:
jsr MoveActorY
NoInterpolation:lda actXL,x
sta actPrevXL,x
lda actXH,x
sta actPrevXH,x
lda actYL,x
sta actPrevYL,x
lda actYH,x
sta actPrevYH,x