AI fix and optimization

This commit is contained in:
2022-07-03 13:22:44 -04:00
parent 2a5595f3c9
commit 3fb83583c3
4 changed files with 36 additions and 59 deletions
+28 -45
View File
@@ -42,6 +42,13 @@ loop
pha pha
lda AIRoutines,x lda AIRoutines,x
pha pha
ldx TankNr ; common values used in AI routines
; address of weapons table (for future use)
lda TanksWeaponsTableL,x
sta temp
lda TanksWeaponsTableH,x
sta temp+1
rts rts
.endp .endp
;---------------- ;----------------
@@ -57,7 +64,6 @@ AIRoutines
;---------------------------------------------- ;----------------------------------------------
.proc Moron .proc Moron
ldx TankNr
jsr RandomizeAngle jsr RandomizeAngle
sta NewAngle sta NewAngle
mwa #80 RandBoundaryLow mwa #80 RandBoundaryLow
@@ -68,7 +74,6 @@ AIRoutines
;---------------------------------------------- ;----------------------------------------------
.proc Shooter .proc Shooter
ldx TankNr
lda PreviousAngle,x lda PreviousAngle,x
ora PreviousEnergyL,x ora PreviousEnergyL,x
ora PreviousEnergyH,x ora PreviousEnergyH,x
@@ -94,36 +99,30 @@ AIRoutines
firstShoot firstShoot
; compare the x position with the middle of the screen ; compare the x position with the middle of the screen
lda xTanksTableH,x
cmp #>(screenwidth/2)
bne @+
lda xTanksTableL,x lda xTanksTableL,x
sta temp cmp #<(screenwidth/2)
lda xTanksTableH,x @ bcc tankIsOnTheRight
sta temp+1
cpw temp #(screenwidth/2)
bcs tankIsOnTheRight
lda RANDOM
and #$1F
clc
adc #5
; enemy tank is on the left
randomize 95 125
sta NewAngle sta NewAngle
jmp forceNow bne forceNow
tankIsOnTheRight tankIsOnTheRight
lda RANDOM randomize 55 85
and #$1F sta NewAngle
clc
adc #(-85)
;lda #-45
sta NewAngle
forceNow forceNow
mwa #100 RandBoundaryLow mwa #100 RandBoundaryLow
mwa #800 RandBoundaryHigh mwa #800 RandBoundaryHigh
ldx TankNr ;this is possibly not necessary ;ldx TankNr ;this is possibly not necessary
jsr RandomizeForce jsr RandomizeForce
endo endo
ldx TankNr ;this is possibly not necessary ;ldx TankNr ;this is possibly not necessary
jsr RandomizeForce.LimitForce jsr RandomizeForce.LimitForce
lda NewAngle lda NewAngle
sta PreviousAngle,x sta PreviousAngle,x
@@ -134,14 +133,10 @@ endo
; choose the best weapon ; choose the best weapon
lda TanksWeaponsTableL,x
sta temp
lda TanksWeaponsTableH,x
sta temp+1
ldy #32 ;the last weapon ldy #32 ;the last weapon
loop loop
dey dey
lda (temp),y lda (temp),y ; this is set up before calling the routine, has address of TanksWeaponsTable
beq loop beq loop
tya tya
sta ActiveWeapon,x sta ActiveWeapon,x
@@ -150,19 +145,13 @@ loop
;---------------------------------------------- ;----------------------------------------------
.proc Poolshark .proc Poolshark
; defensives ; defensives
ldx TankNr
; address of weapons table (for future use)
lda TanksWeaponsTableL,x
sta temp
lda TanksWeaponsTableH,x
sta temp+1
; if low energy ten use battery ; if low energy ten use battery
lda Energy,x lda Energy,x
cmp #30 cmp #30
bcs EnoughEnergy bcs EnoughEnergy
; lower than 30 units - check battery ; lower than 30 units - check battery
ldy #ind_Battery________ ldy #ind_Battery________
lda (temp),y lda (temp),y ; has address of TanksWeaponsTable
beq NoBatteries beq NoBatteries
; we have batteries - use one ; we have batteries - use one
clc clc
@@ -180,12 +169,12 @@ EnoughEnergy
; first check check if any is in use ; first check check if any is in use
lda ActiveDefenceWeapon,x lda ActiveDefenceWeapon,x
bne DefensiveInUse bne DefensiveInUse
ldy #64 ;the last defensive weapon ldy #ind_Nuclear_Winter_+1 ;the last defensive weapon
@ @
dey dey
cpy #ind_Battery________ ;first defensive weapon (White Flag nad Battery - never use) cpy #ind_Battery________ ;first defensive weapon (White Flag nad Battery - never use)
beq NoUseDefensive beq NoUseDefensive
lda (temp),y lda (temp),y ; has address of TanksWeaponsTable
beq @- beq @-
tya tya
; activate defensive weapon ; activate defensive weapon
@@ -195,7 +184,7 @@ EnoughEnergy
; decrease in inventory ; decrease in inventory
clc clc
sbc #1 sbc #1
sta (temp),y sta (temp),y ; has address of TanksWeaponsTable
NoUseDefensive NoUseDefensive
DefensiveInUse DefensiveInUse
firstShoot firstShoot
@@ -203,7 +192,7 @@ firstShoot
jsr MakeLowResDistances jsr MakeLowResDistances
mva #$ff temp2 ; min possible distance mva #$ff temp2 ; min possible distance
ldx TankNr ;ldx TankNr
ldy NumberOfPlayers ldy NumberOfPlayers
dey dey
@@ -264,7 +253,7 @@ forceNow
jsr RandomizeForce jsr RandomizeForce
endo endo
ldx TankNr ;this is possibly not necessary ;ldx TankNr ;this is possibly not necessary
; choose the best weapon ; choose the best weapon
@@ -288,12 +277,6 @@ AngleTable ; 16 bytes ;ba w $348b L$3350
.endp .endp
;---------------------------------------------- ;----------------------------------------------
.proc Toosser .proc Toosser
ldx TankNr
; address of weapons table
lda TanksWeaponsTableL,x
sta temp
lda TanksWeaponsTableH,x
sta temp+1
; use best defensive :) ; use best defensive :)
; allways ; allways
; first check check if any is in use ; first check check if any is in use
@@ -304,7 +287,7 @@ AngleTable ; 16 bytes ;ba w $348b L$3350
dey dey
cpy #ind_Battery________ ;first defensive weapon (White Flag nad Battery - never use) cpy #ind_Battery________ ;first defensive weapon (White Flag nad Battery - never use)
beq NoUseDefensive beq NoUseDefensive
lda (temp),y lda (temp),y ; has address of TanksWeaponsTable
beq @- beq @-
tya tya
; activate defensive weapon ; activate defensive weapon
+4 -4
View File
@@ -609,13 +609,13 @@ DrawNextTank
ldx tankNr ldx tankNr
; let's check the energy ; let's check the energy
lda eXistenZ,x lda eXistenZ,x
bne SkipRemovigPM ; if energy=0 then no tank bne SkipHidingPM ; if energy=0 then no tank
; hide P/M ; hide P/M
lda #0 lda #0
sta hposp0,x sta hposp0,x
jmp DoNotDrawTankNr jmp DoNotDrawTankNr
SkipRemovigPM SkipHidingPM
lda AngleTable,x lda AngleTable,x
@@ -731,11 +731,11 @@ tankflash_loop
sne:mva #1 fs ; finish it sne:mva #1 fs ; finish it
mva #1 Erase mva #1 Erase
ldx TankNr ldx TankNr
jsr DrawTankNr.SkipRemovigPM ; it's necessary becouse DrawTankNr skips tanks with no energy ! jsr DrawTankNr.SkipHidingPM ; it's necessary becouse DrawTankNr skips tanks with no energy !
PAUSE 2 PAUSE 2
mva #0 Erase mva #0 Erase
ldx TankNr ldx TankNr
jsr DrawTankNr.SkipRemovigPM jsr DrawTankNr.SkipHidingPM
PAUSE 2 PAUSE 2
dec fs dec fs
jne tankflash_loop jne tankflash_loop
+4 -10
View File
@@ -380,6 +380,7 @@ DoNotFinishTheRound
mva #0 noDeathCounter mva #0 noDeathCounter
mva #sfx_seppuku sfx_effect mva #sfx_seppuku sfx_effect
jsr DisplaySeppuku jsr DisplaySeppuku
jmp Seppuku jmp Seppuku
@@ -751,6 +752,9 @@ NotNegativeShieldEnergy
sta ydraw+1 sta ydraw+1
; get position of the tank ; get position of the tank
ldx TankNr ldx TankNr
lda #0 ; turn off defense weapons when hara-kiring
sta ActiveDefenceWeapon,x
sta ShieldEnergy,x
lda xtankstableL,x lda xtankstableL,x
sta xdraw sta xdraw
lda xtankstableH,x lda xtankstableH,x
@@ -1148,20 +1152,10 @@ LimitForce
bcc rotateLeft ; older is bigger bcc rotateLeft ; older is bigger
rotateRight;older is lower rotateRight;older is lower
inc angleTable,x inc angleTable,x
bne MoveBarrelToNewPosition
mva #$30 CharCode ; if angle goes through 0 we clear the barrel
jsr DrawTankNr.drawtankNrX
jmp MoveBarrelToNewPosition jmp MoveBarrelToNewPosition
rotateLeft rotateLeft
dec angleTable,x dec angleTable,x
bpl MoveBarrelToNewPosition
mva #$2e CharCode
jsr DrawTankNr.drawtankNrX
jmp MoveBarrelToNewPosition jmp MoveBarrelToNewPosition
BarrelPositionIsFine BarrelPositionIsFine
rts rts
BIN
View File
Binary file not shown.