From: Lukas Krickl Date: Thu, 2 Jan 2025 20:01:36 +0000 (+0100) Subject: map: Added ability to re-roll exit if direction is already taken X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=2a2d583ba960b7f27216acece782926f1e577195;p=gbrg%2F.git map: Added ability to re-roll exit if direction is already taken This is still lacking a fallback in case all 4 directions are taken. This should not be possible right now anyway though. Added .sav to girignore :^) --- diff --git a/.gitignore b/.gitignore index f596bf3..9ee8adc 100644 --- a/.gitignore +++ b/.gitignore @@ -72,3 +72,5 @@ rg.lst testrg.gb testrg.mlb testrg.lst + +*.sav diff --git a/src/map.s b/src/map.s index 0b45d15..5f18769 100644 --- a/src/map.s +++ b/src/map.s @@ -563,12 +563,7 @@ map_gen_next: push de ; save it again ; for now just pick a direction - push hl - push de - call rand - pop de - pop hl - and a, 3 ; discard remaining bits + call map_gen_pick_direction push hl call map_gen_link_rooms @@ -606,6 +601,59 @@ map_gen_next: pop hl ret + ; picks a direction in mapgen + ; inputs: + ; hl: next room ptr + ; de: previous room ptr + ; returns: + ; a: direction + ; de/hl are preserved +map_gen_pick_direction: + push hl + push de + + ; TODO: add failure state if all 4 directions are taken + ; returns special value to indicate failure +@again: + call rand + and a, 3 ; discard remaining bits + + ; store result for now + ld [tmp], a + ld hl, map_gen_reverse_direction + ld d, 0 + ld e, a + add hl, de + ld a, [hl] ; get reverse direction of the chosen one + + ; now check if direction is already used + ; in previous room + pop de + push de ; push again + + ld hl, roomb_exits + add hl, de ; hl = room exit struct + + add a, a ; a * 2 = ptr offset + ld d, 0 + ld e, a + add hl, de ; hl = exit ptr + + ; add both bytes of ptr + ; to check if its NULL + ld a, [hl+] + ld e, a + ld a, [hl] + add a, e ; this must be 0 + cp a, 0 + jr nz, @again REL + + ; get original result + ld a, [tmp] + + pop de + pop hl + ret ; lut for reverse direction map_gen_reverse_direction: