Skip to content

Commit

Permalink
working on #9, might have fixed it (unit moves calc)
Browse files Browse the repository at this point in the history
  • Loading branch information
anakrusis committed Sep 17, 2020
1 parent 4e9f4cb commit 2b1e772
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 73 deletions.
12 changes: 12 additions & 0 deletions ai.asm
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ ThreatenPositionLoop:
adc p1PiecesY, x
sta <param2
; todo make sure the tile is land lol... already seen a couple Lake Chickens spawning by the AI
; they're chickens not ducks
jsr checkUnitOnTile
; looking for the first space without a unit occupying it
Expand Down Expand Up @@ -341,6 +344,8 @@ FindRightmostTileLoop:
lda MapData, x
cmp #$02
bne FindRightmostTileLoopTail
; todo make sure no units on the tile where the farm is

jmp RightmostTileFound

Expand Down Expand Up @@ -379,6 +384,13 @@ RightmostTileFound:
jsr placeFarmAtCursorPos
jmp AiDone
; farmer, chicken, cow
UnitThreatOffsetsX:
.db $00, $00, $10
UnitThreatOffsetsY:
.db $00, $08, $18
UnitThreats:
; tile offsets where a unit can be threatened by a chicken
ChickenThreatX:
.db $01, $01, $ff, $ff, $02, $02, $fe, $fe
Expand Down
2 changes: 1 addition & 1 deletion main.asm
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ text_TheLicc:
.db $1d, $31, $2e, $24, $15, $32, $2c, $2c, $ff ; "THE LICC"
text_EngineTitle:
.db $1b, $1b, $28, $09, $27, $01, $03, $27, $02, $00, $02, $00, $ff ; rr.9/13/2020
.db $1b, $1b, $28, $09, $27, $01, $07, $27, $02, $00, $02, $00, $ff ; rr.9/17/2020
text_Icle:
.db $12, $0c, $15, $0e, $ff ; icle
Expand Down
Binary file modified main.nes
Binary file not shown.
203 changes: 131 additions & 72 deletions unit.asm
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,14 @@ calculateUnitMoves:
calcRange:
lda unitSelectedType
asl a
sta param8
sta <param8

lda attackMode ; attack is 01, move is 00
cmp #$00
beq calcMovesMoveMode
jmp calcMovesAttackMode
calcMovesMoveMode:
clc
adc param8
tay
Expand Down Expand Up @@ -280,20 +285,6 @@ calcMovesXLoop:
tya
pha
calcMovesCheckTerrain:
lda <param2
asl a
asl a
asl a
asl a
clc
adc <param1
tay
lda MapData, y
cmp #$02
beq calcMovesCheckUnit
jmp calcMovesXLoopTail
calcMovesCheckUnit:
; param1 and param2 already setup!
jsr checkUnitOnTile
Expand Down Expand Up @@ -326,74 +317,142 @@ calcMovesYLoopTail:
calcMovesDone:
rts
; input: whatever checkUnitOnTile outputs, and guiMode which is set before
; output: validity of move in A
mapDecideUnitMoveValid:

; special case for cow where:
; either unitSelectedX and param1 must match or unitSelectedY and param2 must match
; (both can't match because that would be matching the space of unitSelected and it would consider it friendly fire)
; so it has rook-type movement, only can go straight not diagonal
lda unitSelectedType
cmp #$02
beq CowMoveCheck
jmp ChickenMoveCheck
; attack mode functions differently from the other modes, it uses fixed (relative) tables to determine the attack pattern of each mob
calcMovesAttackMode:
ldx #$00
calcMovesAttackModeLoop:
ldy unitSelectedType
CowMoveCheck:
lda unitSelectedX
cmp param1
beq XEqual

lda unitSelectedY
cmp param2
beq YEqual
jmp MoveInvalid
; 11/12 store the beginning byte into UnitThreats, the spaces where a unit can threaten
lda UnitThreatOffsetsX, y
sta <param11
lda UnitThreatOffsetsY, y
sta <param12
XEqual:
lda unitSelectedY
cmp param2
bne AtkMoveModeEval
jmp MoveInvalid
; get the relative X value
txa
clc
adc <param11
tay
lda UnitThreats, y
; add on the units X
clc
adc <unitSelectedX
sta <param1
YEqual:
lda unitSelectedX
cmp param1
bne AtkMoveModeEval
jmp MoveInvalid
; get the relative Y value
txa
clc
adc <param12
tay
lda UnitThreats, y
; add on the units Y
clc
adc <unitSelectedY
sta <param2
; special case for chicken:
; can only shoot eggs diagonally, so the difference between the new and old position must be
; equal in both X and Y, positive or negative.
ChickenMoveCheck:
lda unitSelectedType
cmp #$01
bne AtkMoveModeEval
lda attackMode
cmp #$01
bne AtkMoveModeEval
; param1 and param2 already setup!
jsr checkUnitOnTile
jsr mapDecideUnitMoveValid
cmp #$00
beq calcMovesAttackModeLoopTail

ldy validMovesCount
lda <param1
sta validMovesX, y
lda <param2
sta validMovesY, y
lda param1
sec
sbc unitSelectedX
sta param8 ; x difference in param8
inc validMovesCount
lda param2
sec
sbc unitSelectedY
sta param9 ; y difference in param9
calcMovesAttackModeLoopTail:
inx
cpx #$08
bne calcMovesAttackModeLoop
cmp param8 ; compare x&y diff unaltered
beq AtkMoveModeEval
rts
eor #$ff ; now check the twos complement of y distance and try again
; input: whatever checkUnitOnTile outputs, and guiMode which is set before
; output: validity of move in A
mapDecideUnitMoveValid:
mapDecideCheckTerrain:
lda <param2
asl a
asl a
asl a
asl a
clc
adc #$01
cmp param8
beq AtkMoveModeEval
adc <param1
tay
lda MapData, y
cmp #$02
beq mapDecideModeEval
jmp MoveInvalid

AtkMoveModeEval:
; ; special case for cow where:
; ; either unitSelectedX and param1 must match or unitSelectedY and param2 must match
; ; (both can't match because that would be matching the space of unitSelected and it would consider it friendly fire)
; ; so it has rook-type movement, only can go straight not diagonal
; lda unitSelectedType
; cmp #$02
; beq CowMoveCheck
; jmp ChickenMoveCheck
; CowMoveCheck:
; lda unitSelectedX
; cmp param1
; beq XEqual

; lda unitSelectedY
; cmp param2
; beq YEqual
; jmp MoveInvalid
; XEqual:
; lda unitSelectedY
; cmp param2
; bne AtkMoveModeEval
; jmp MoveInvalid
; YEqual:
; lda unitSelectedX
; cmp param1
; bne AtkMoveModeEval
; jmp MoveInvalid
; ; special case for chicken:
; ; can only shoot eggs diagonally, so the difference between the new and old position must be
; ; equal in both X and Y, positive or negative.
; ChickenMoveCheck:
; lda unitSelectedType
; cmp #$01
; bne AtkMoveModeEval
; lda attackMode
; cmp #$01
; bne AtkMoveModeEval
; lda param1
; sec
; sbc unitSelectedX
; sta param8 ; x difference in param8
; lda param2
; sec
; sbc unitSelectedY
; sta param9 ; y difference in param9
; cmp param8 ; compare x&y diff unaltered
; beq AtkMoveModeEval
; eor #$ff ; now check the twos complement of y distance and try again
; clc
; adc #$01
; cmp param8
; beq AtkMoveModeEval
; jmp MoveInvalid

mapDecideModeEval:
; attack mode?
lda attackMode
cmp #$01
Expand Down

0 comments on commit 2b1e772

Please sign in to comment.