From: Lukas Krickl Date: Fri, 15 Aug 2025 04:20:50 +0000 (+0200) Subject: unit: Added unit fine at X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=81745e84197f7433bdced6268ee21ce95bdcef48;p=gbrg%2F.git unit: Added unit fine at --- diff --git a/src/unit.s b/src/unit.s index 7fc1d74..d3b8f48 100644 --- a/src/unit.s +++ b/src/unit.s @@ -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: