unit: Added unit fine at
authorLukas Krickl <lukas@krickl.dev>
Fri, 15 Aug 2025 04:20:50 +0000 (06:20 +0200)
committerLukas Krickl <lukas@krickl.dev>
Fri, 15 Aug 2025 04:20:50 +0000 (06:20 +0200)
src/unit.s

index 7fc1d74b432abf840ee6d4793ceeb104a8b47e16..d3b8f480f6b08daeb7989bc89f5cc97c141671ee 100644 (file)
@@ -797,6 +797,43 @@ unit_set_draw:
        ;       returns:
        ;               hl: unit ptr or NULL if not found
 unit_find_at:
+       ld hl, p0_units
+
+       ; a = loop counter
+       ld a, UNITS_MAX
+
+@loop:
+               push af
+               push hl
+
+               ld de, act_pos_y
+               add hl, de 
+               ; hl = y pos
+
+               ; check if positions match      
+               ld a, [hl+]
+               cp a, b ; does y match?
+               jr nz, @no_match REL
+
+               ld a, [hl]
+               cp a, c ; does x match?
+               jp z, @found 
+
+@no_match:
+               pop hl ; back to start
+               pop af ; restore loop counter
+               ; next unit
+               ld de, act_size
+               add hl, de
+               dec a
+       jp nz, @loop
+       
+       ldnull hl 
+       ret
+
+@found:
+       pop hl ; hl = start of found act
+       pop af ; af was also saved so we need to pop 
        ret
 
 st_unit_idle: