Prev: A017 Up: Map Next: A11A
A07A: Actor : Check distance of nearest junctions.
Finds nearest junctions, both sides of actor, and calculates the distance.
Input
($a195) Address of actor Actor_CurrentPtr.
A Direction actor is facing.
IX Address of path actor is on.
Output
Actor_NearestJunctions A07A PUSH IX Copy path axis / vector into temporary memory.
A07C POP HL
A07D LD DE,TempBl
A080 LD BC,$0006
A083 LDIR
A085 LD IX,(Actor_CurrentPtr) Get address of current actor.
A089 BIT 0,A Check compass
A08B JR NZ,Actor_NearestJunctions_0
Compass N/S
A08D LD L,(IX+$07) Get actors E/W coord.
A090 LD H,(IX+$08)
A093 LD IX,(_5be8_PathNS) Check for paths running N/S.
A097 JR Actor_NearestJunctions_1
Compass E/W
Actor_NearestJunctions_0 A099 LD L,(IX+$05) Get actors N/W coord.
A09C LD H,(IX+$06)
A09F LD IX,(_5be6_PathEW) Check for paths running E/W.
Actor_NearestJunctions_1 A0A3 LD DE,$0004 Offset actors coords.
A0A6 AND A
A0A7 SBC HL,DE
A0A9 LD (TempAl),HL
A0AC LD HL,$0000
A0AF LD (DistanceA),HL
A0B2 LD (DistanceB),HL
A0B5 LD DE,(Bitmap_PtrTableOffHeight) Get end of path (A) being tested.
See if a path's axis intersects the actors path.
Actor_NearestJunctions_2 A0B9 LD BC,(Bitmap_PtrTable) Get start of path (A) being tested.
A0BD LD L,(IX+$00) Get next path (B) axis to test with.
A0C0 LD H,(IX+$01)
A0C3 AND A See if axis is greater than path A start.
A0C4 SBC HL,BC
A0C6 JR C,Actor_NearestJunctions_3 No; move onto next path in list.
A0C8 ADD HL,BC See if axis is less than path A end.
A0C9 SCF
A0CA SBC HL,DE If not then all further paths will also be greater than path A's end.
A0CC RET NC
A0CD LD BC,(TempBl) See if path (A) axis intersects with path (B) start and end.
A0D1 LD L,(IX+$02)
A0D4 LD H,(IX+$03)
A0D7 SCF
A0D8 SBC HL,BC
A0DA JR NC,Actor_NearestJunctions_3
A0DC LD L,(IX+$04)
A0DF LD H,(IX+$05)
A0E2 AND A
A0E3 SBC HL,BC
A0E5 JR NC,Actor_NearestJunctions_4 Paths intersect...
Next path.
Actor_NearestJunctions_3 A0E7 LD BC,$000C Move onto next path in list.
A0EA ADD IX,BC
A0EC JR Actor_NearestJunctions_2
Path found.
Actor_NearestJunctions_4 A0EE LD BC,(TempAl) Get actors coords in direction of travel.
A0F2 LD L,(IX+$00) Get axis for intersecting path.
A0F5 LD H,(IX+$01)
A0F8 AND A Calculate difference and position.
A0F9 SBC HL,BC
A0FB JR NC,Actor_NearestJunctions_5
Path before actor.
A0FD LD C,L
A0FE LD B,H
A0FF LD HL,$0004
A102 AND A
A103 SBC HL,BC
A105 LD (DistanceA),HL
A108 JR Actor_NearestJunctions_3
Path after actor.
Actor_NearestJunctions_5 A10A LD BC,$0009
A10D AND A
A10E SBC HL,BC
A110 JR C,Actor_NearestJunctions_3
A112 LD BC,$0005
A115 ADD HL,BC
A116 LD (DistanceB),HL
A119 RET
Prev: A017 Up: Map Next: A11A