RoomBuilder (rbr) is a pure POSIX sh library to create "rooms" for the upcoming mia roguelike
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

769 lines
25 KiB

#!/bin/sh
FILE="$1"
. ${RPATH:-.}/rbase # pull in the base values
. ${RPATH:-.}/env
. ${RPATH:-.}/gen.env
# some example code for producing an empty screen
# for i in $(seq $LINES); do
# for i in $(seq $COLUMNS); do
# print ' '
# done; echo
# done
s() { # s acts as seq replacement
n=$(($1)); while [ "$n" -le $(($2)) ]; do
echo "$n"; : $((n+=1))
done
}
listgen(){ # generate typelist
unset typelist
# gen.env now handles max counter's
# how many times they /SHOULD/ appear in the list
nsdoor=0;nswall=0;ntopwall=0;ncorner=0;nblank=0;nfloor=0 # set all counters to 0
IFS=";"; tln=0; for i in ${types}; do # produce a number stating how many should be in the list
: $((tln+=$(printf 'mn%s' "$i")))
done
unset IFS
for i in $(s 1 ${tln}); do
ran=6;
unset IFS
until [ "$ran" -le $(listSz "${types}" ';') -a "$ran" -gt 0 ]; do
ran=$(${RPATH:-.}/rng/ran)
until [ "${#ran}" -eq 1 ]; do
ran="${ran%?}"
done
done
IFS=";"; set -- ${types}; unset IFS
eval $(printf 'rann=$%s' "$ran")
case "$rann" in
floor)
typelist="${typelist+$typelist;}floor"
: $((nfloor+=1))
[ $nfloor -eq $mnfloor ] && types=$(listr "floor" "${types}" ";")
;;
blank)
typelist="${typelist+$typelist;}blank"
: $((nblank+=1))
[ $nblank -eq $mnblank ] && types=$(listr "blank" "${types}" ";")
;; # blank
corner)
typelist="${typelist+$typelist;}corner"
: $((ncorner+=1))
[ $ncorner -eq $mncorner ] && types=$(listr "corner" "${types}" ";")
;; # corner
topwall)
typelist="${typelist+$typelist;}topwall"
: $((ntopwall+=1))
[ $ntopwall -eq $mntopwall ] && types=$(listr "topwall" "${types}" ";")
;; # topwall
swall)
typelist="${typelist+$typelist;}swall"
: $((nswall+=1))
[ $nswall -eq $mnswall ] && types=$(listr "swall" "${types}" ";")
;; # wall
topdoor)
typelist="${typelist+$typelist;}topdoor"
: $((ntopdoor+=1))
[ $ntopdoor -eq $mntopdoor ] && types=$(listr "topdoor" "${types}" ";")
;; # topdoor
sdoor)
typelist="${typelist+$typelist;}sdoor"
: $((nsdoor+=1))
[ $nsdoor -eq $mnsdoor ] && types=$(listr "sdoor" "${types}" ";")
;; # sdoor
esac # this is simply faster than a loop
done
printf 'new typelist: %s\n' "$typelist" >> ./debug
unset IFS
}
clist() { # correct errors and edge cases in typelist
IFS=";"
[ ! "${#1}" -gt 1 ] && {
printf 'empty typelist!!! -- ' >> ./debug
case "$vpos" in
?"b c"?) inchance "blank" "2" ";" ;;
?"t "??) typelist=$(listr "blank" "${typelist}" ";") ;;
*)
printf 'COULD NOT CORRECT...\n' >> ./debug
printf 'pos: %s | original typelist: %s\n' "$vpos & $vdpos" "$otypelist" >> ./debug
exit 12
esac
printf 'corrected...\n' >> ./debug
}
case "$vpos" in
?'t '??|?'c '??) : ;;
??" f"?) inchance "floor" "5" ";"
case "$vpos" in
??" ft") typelist=$(listr "blank" "${typelist}" ";")
esac ;;
esac
case "$vpos" in
??" t-"|?"f tb"|"fc "??) typelist=$(listr "blank" "${typelist}" ";")
esac
case "$vpos" in
?"t "??|?"_ "??) typelist=$(listr "floor" "${typelist}" ";")
esac
case "$vpos" in
?"t fc") inchance "corner" "3" ";" ;; # end walls in corners
esac
case "$vpos" in
?"f f"?) inchance "floor" "3" ";"
esac
case "$vpos" in
"bf "??) typelist=$(listr "corner" "${typelist}" ";")
esac
case "$vpos" in
?"f _"?) typelist=$(listr "blank" "${typelist}" ";")
esac
case "$vpos" in
?"t "??)
[ $(inlist "swall" "${typelist}") = ':' ] && {
inchance "corner" "2" ";"
typelist=$(listr "swall" "${typelist}" ";")
}
esac
case "$vpos" in
"ct "??) typelist=$(listr "corner" "${typelist}" ";")
esac
case "$vpos" in
??" #"?) typelist=$(listr "topdoor" "${typelist}" ";")
esac
case "$vpos" in
?"f _"?) inchance "floor" "1" ";"
esac
case "$vpos" in
?"t #"?) inchance "corner" "1" ";"
esac
# BORDER CASE
if [ "$c" -gt $((COLUMNS-10 -2)) ]; then
typelist=$(listr "topdoor" "${typelist}" ";")
case "$vpos" in
?"t "??)
typelist=$(listr "topwall" "${typelist}" ";")
inchance "corner" "2" ";";;
?"b "??)
typelist=$(listr "corner" "${typelist}" ";") ;;
?"f #"?|?"f c"?)
inchance "swall" "2" ";"
inchance "corner" "2" ";" ;;
esac
fi
# EMPTY CASE
case "$vpos" in
?"f c"?)
[ "${#typelist}" -le 1 ] && {
inchance "swall" "5" ";"
inchance "floor" "3" ";"
inchance "blank" "1" ";"
} || : ;;
?"t c"?|"t d"?)
[ "${#typelist}" -le 1 ] && {
inchance "corner" "1" ";"
} || : ;;
esac # ignore BORDER case if typelist is empty
for i in ${typelist}; do
[ "${#i}" -gt 1 ] && {
typelist="${typelist+${typelist};}$i"
}
done # this corrects... something ... (?) ... /NEEDED/ for l1c1 (l3c3)
# typelist can contain a ';;' -- idk why this happens but this corrects it as it can cause `$` to be "chosen"
IFS=""; p="${typelist}"; unset typelist
n=0; while [ "$p" ]; do
next="${p#?}" # current is ${p%$next}
[ "${p%$next}" = ";" -a "${next%${next#?}}" = ";" -o "$n" -eq 0 -a "${p%$next}" = ";" ] && {
echo 'typelist error!!! -- correcting...' >> ./debug
} || typelist="${typelist}${p%$next}"
p="${next}"; unset next
: $((n+=1))
done; unset n
}
sgrid() { # print $1 # $3 l $2 c
case "$1" in
't'|'_') topwallc=$((${topwallc:-0}+1)) ;;
'#'|'d') swallc=$((${swallc:-0}+1)); [ "$((swallc%2))" -eq 0 -a "$swallc" -ge 2 ] && swallc=$((swallc/2)) ;;
'c') unset topwallc; unset swallc ;;
' ') unset room
esac # counter logic
# DEBUG
printf 'list length: %s | pos: %s | l %s c %s | room: %s ' "$tln" "$vpos & $vdpos" "$l" "$c" "${room:-false}" >> ./debug
case "$1" in
't') printf '| topwall counter: %s ' "${topwallc:-0}" >> ./debug ;;
'#'|'|') printf '| wall counter: %s ' "${swallc:-0}" >> ./debug
esac
[ "$1" != "#" -a "$1" != "d" -a "$room" ] && printf '| wall counter: %s ' "${swallc:-0}" >> ./debug
printf '| typelist: %s | picked #%s (' "$typelist" "$ran" >> ./debug
printf '%s)\n' "$1" >> ./debug; [ "$FILE" ] || printf '%s' "$1" >> state
eval $(printf 'l%sc%s="%s"' "$3" "$2" "$1")
eval $(printf 'printf $l%sc%s' "$3" "$2")
}
# L = lines; C = COLUMNS
inlist() { # checks if $1 is in $2 returns ":" for yes; "!" for no
case "$2" in
*"${1}"*) echo ':' ;;
*) echo '!'
esac
}
listr() { # create a new typelist using the items in $2; MUST not contain $1
oIFS="${IFS}" IFS=";"
ctypelist="${2}"
[ "${#2}" -gt 1 ] || {
printf '\n'
exit 13 # list error
}
[ "$(inlist $1 "$2")" = '!' ] && {
echo "$2"; return # listr always runs in a subshell -- thus this exit will NOT close $0
} || { # if inlist returns '!' do nothing and exit
for i in ${2}; do
[ "$i" != "$1" -a "${#i}" -gt 1 ] && {
o="${o+${o};}$i"
}
done
}
[ "$ctypelist" = "$o" ] && {
printf 'listr failed to change typelist... | %s = %s | rm: %s \n' "$ctypelist" "$o" "$1" >> ./debug
exit 13
}
IFS="${oIFS}" # IFS should be set before calling
# unset to prevent later issues
echo "$o"
} # remove an item from $2
listS(){ # return a number that determines the legth of the number of items
IFS="${2:-;}"
n=0; for i in ${1:-${typelist}}; do
: $((n+=1))
done
unset IFS
echo "${#n}"
}
listSz(){ # list ($1) size; uses $2 as IFS or unset
[ "$2" ] && {
IFS="$2"
} || unset IFS
n=0; for i in ${1}; do
: $((n+=1))
done
echo "$n"
unset IFS
}
## POS
# if there are 4 items in $1/$typelist this will return `1`
pos() { # $1 l $2 c # case statements are present to replace spaces or unicode
oIFS="${IFS}"; IFS=""
if [ "$1" -eq 3 ]; then
A=--
else
case "$(eval $(printf 'printf $l%sc%s' "$(($1-1))" "$2") 2>/dev/null)" in
"${blank}") A="b" ;;
"${floor}") A="f" ;;
"${topwall}") A="t" ;;
"${corner}") A="c" ;;
"${sdoor}") A="d" ;;
"${topdoor}") A='_' ;;
"${swall}") A="#" ;;
*) A="$(eval $(printf 'printf $l%sc%s' "$(($1-1))" "$2") 2>/dev/null)$A"
esac
if [ "$1" -eq 4 ]; then
A="${A}-"
else
case "$(eval $(printf 'printf $l%sc%s' "$(($1-2))" "$2") 2>/dev/null)" in
"${blank}") A="${A}b" ;;
"${floor}") A="${A}f" ;;
"${topwall}") A="${A}t" ;;
"${corner}") A="${A}c" ;;
"${sdoor}") A="${A}d" ;;
"${topdoor}") A="${A}_" ;;
"${swall}") A="${A}#" ;;
*) A="$A$(eval $(printf 'printf $l%sc%s' "$(($1-2))" "$2") 2>/dev/null)"
esac
fi
fi
if [ "$2" -eq 3 ]; then
L=-- # - is placeholder
else
case "$(eval $(printf 'printf $l%sc%s' "$1" "$(($2-1))") 2>/dev/null)" in
"${blank}") L="b" ;; # replace ' ' (blank) with b
"${floor}") L="f" ;;
"${topwall}") L="t" ;;
"${corner}") L="c" ;;
"${sdoor}") L="d" ;;
"${topdoor}") L='_' ;;
"${swall}") L="#" ;;
*) L="$(eval $(printf 'printf $l%sc%s' "$1" "$(($2-1))") 2>/dev/null)"
esac
if [ "$2" -eq 4 ]; then
L="-${L}"
else
case "$(eval $(printf 'printf $l%sc%s' "$1" "$(($2-2))") 2>/dev/null)" in
"${blank}") L="b$L" ;;
"${floor}") L="f$L" ;;
"${topwall}") L="t$L" ;;
"${corner}") L="c$L" ;;
"${sdoor}") L="d$L" ;;
"${topdoor}") L="_$L" ;;
"${swall}") L="#$L" ;;
*) L="$(eval $(printf 'printf $l%sc%s' "$1" "$(($2-2))") 2>/dev/null)$L"
esac
fi
fi
echo "$L $A"; IFS="${oIFS}"
} # output 2 values; leftleft aboveabove # not possible for right or below to be set
dpos() { # diagonal pos # $1 l $2 c
oIFS="${IFS}"; IFS=""
if [ "$1" -le 3 ]; then
R=-; L=-
else
case "$(eval $(printf 'printf $l%sc%s' "$(($1-1))" "$(($2+1))") 2>/dev/null)" in
"${blank}") R=b ;;
"${floor}") R=f ;;
"${topwall}") R=t ;;
"${corner}") R=c ;;
"${sdoor}") R=d ;;
"${topdoor}") R='_' ;;
"${swall}") R='#' ;;
*) R="$(eval $(printf 'printf $l%sc%s' "$(($1-1))" "$(($2+1))") 2>/dev/null)"
esac
case "$(eval $(printf 'printf $l%sc%s' "$(($1-1))" "$(($2-1))") 2>/dev/null)" in
"${blank}") L=b ;;
"${floor}") L=f ;;
"${topwall}") L=t ;;
"${corner}") L=c ;;
"${sdoor}") L=d ;;
"${topdoor}") L='_' ;; # topdoors will use `_` as their non unicode case charaecter
"${swall}") L='#' ;;
*) L="$(eval $(printf 'printf $l%sc%s' "$(($1-1))" "$(($2-1))") 2>/dev/null)"
esac
fi
[ "$2" -le 3 ] && L=-
echo "$L $R"; IFS="${oIFS}"
} # output 2 values; RightCorner LeftCorner
inchance() { # increase the chance of $1 being picked $2 times # $3 should be `;` or IFS
oIFS="${IFS}"; unset IFS
for i in $(s 1 ${2:-1}); do
[ "$(($(${RPATH:-.}/rng/ran)%2))" -eq 0 ] && {
typelist="${1+$1${3:-;}}${typelist}"
} || {
typelist="${typelist+${typelist}${3:-;}}$1"
}
done
IFS="${oIFS}"
}
# ALWAYS
[ "$LINES" -a "$COLUMNS" ] || exit 10 # exit code 10 will be for rgrid errors
unset IFS otypelist
# CON
cont() { # continue reading from a state file -- given as $1 or `-` for STDIN
oIFS="${IFS}"; IFS=""; #l=3
: $((l-=1))
while read -r p || [ -n "$p" ]; do
c=3; vdpost"$(dpos $l $c)"; vpost"$(pos $l $c)"
: $((l+=1)); [ "$l" -gt 3 ] && {
echo; [ "$c" -eq $((COLUMNS-2)) ] || c=1
bord; [ "$bord" ] && {
printf '%s' "$bord"
: $((c+=2))
}
printf ' '
}
while [ "$p" ]; do
nextt"${p#?}" # current is ${p%$next}
sgrid "${p%$next}" "$c" "$l"
: $((c+=1))
pt"${next}"; unset next
done
done
export Fc=$c
unset FILE
IFS="${oIFS}"
}
bord() {
case "$l" in
'1'|"$LINES")
[ "$c" -eq 1 -o "$c" -eq $COLUMNS ] && {
bord="$corner"
} || bord="$topwall" ;;
'2'|"$((LINES-1))")
bord="$blank" ;;
*)
unset bord
esac
case "$c" in
'1'|$COLUMNS)
[ "$l" -eq 1 -o "$l" -eq $LINES ] || bord="$swall" ;;
'2'|"$((COLUMNS-1))")
[ "$bord" ] || bord="$blank" ;;
*)
[ "$bord" ] || unset bord
esac
}
# DEFAULT
:>./debug # write `true` to debug (empty)
[ "$1" -a "$FILE" ] && {
case "${FILE}" in
'help'|'-h'|'--h'*|'?')
while read -r p || [ "$p" ] ; do
echo "$p"
done << 'EOF'
rgrid: Generates a "level" layout using a drunkard walk algo
Usage:
./rgrid
-- generate starting from l1c1
./rgrid ./state
-- read from ./state using cont() then resume generation at its end
./rgrid help
-- prints this silly
EOF
exit 0;;
esac
}
# POSITIONAL FUNCTIONS
##D
diapos() {
case "$vdpos" in
?' c'|'c '?|?' #')
typelist=$(listr "corner" "${typelist}" ";") ;;
??'b'|??' ')
case "$vpos" in
?'b '??)
typelist=$(listr "sdoor" "${typelist}" ";")
typelist=$(listr "swall" "${typelist}" ";")
esac; : ;;
??'d')
typelist=$(listr "corner" "${typelist}" ";")
esac
case "$vdpos" in
??'f'|'f'??)
case "$vpos" in
??" b"?) inchance "swall" "6" ";"
esac
esac
case "$vdpos" in
'# '?) typelist=$(listr "corner" "${typelist}" ";")
esac
}
##R
roompos() {
case "$vdpos $vpos" in
?' '?' '?'t '??|?????'b '??)
unset room
case "$vpos" in
??" f"?) room="true"
esac ;;
'c '????' t'?|'c '???'c '??|'t '???'b '??|?????"f t"?|??????" f"?|?" f "??' b'?|?" f "??' c'?|?" f "??' t'?|?' t '?"f "??|?????"| t"?)
room="true" ;;
*)
unset room
esac
}
##B
sidepos() {
case "$vpos" in # ? is any /single/ char
"fc "??)
typelist=$(listr "topdoor" "${typelist}" ";")
typelist=$(listr "floor" "${typelist}" ";") && unset room
typelist=$(listr "blank" "${typelist}" ";")
typelist=$(listr "corner" "${typelist}" ";") ;;
"#f "??|"df "??|"cf "??)
typelist=$(listr "topdoor" "${typelist}" ";")
typelist=$(listr "blank" "${typelist}" ";")
typelist=$(listr "sdoor" "${typelist}" ";")
typelist=$(listr "swall" "${typelist}" ";")
typelist=$(listr "topwall" "${typelist}" ";")
typelist=$(listr "corner" "${typelist}" ";") ;;
"bd "??)
inchance "floor" "1" ";"
typelist=$(listr "blank" "${typelist}" ";")
typelist=$(listr "topdoor" "${typelist}" ";")
typelist=$(listr "corner" "${typelist}" ";")
typelist=$(listr "topwall" "${typelist}" ";") ;;
?"d "??)
typelist=$(listr "topdoor" "${typelist}" ";")
typelist=$(listr "corner" "${typelist}" ";")
typelist=$(listr "topwall" "${typelist}" ";") ;;
"cb "??)
typelist=$(listr "topdoor" "${typelist}" ";")
typelist=$(listr "topwall" "${typelist}" ";")
typelist=$(listr "sdoor" "${typelist}" ";") ;;
"bc "??)
typelist=$(listr "topdoor" "${typelist}" ";")
typelist=$(listr "sdoor" "${typelist}" ";")
typelist=$(listr "corner" "${typelist}" ";")
typelist=$(listr "blank" "${typelist}" ";") ;;
?"b "??|?"f "??|"ff "??)
typelist=$(listr "topdoor" "${typelist}" ";")
typelist=$(listr "topwall" "${typelist}" ";") ;;
"tc "??)
inchance "blank" "3" ";"
typelist=$(listr "topdoor" "${typelist}" ";")
typelist=$(listr "sdoor" "${typelist}" ";")
typelist=$(listr "corner" "${typelist}" ";")
typelist=$(listr "swall" "${typelist}" ";") ;;
?"c "??)
typelist=$(listr "topdoor" "${typelist}" ";")
typelist=$(listr "blank" "${typelist}" ";")
typelist=$(listr "sdoor" "${typelist}" ";")
typelist=$(listr "corner" "${typelist}" ";")
typelist=$(listr "swall" "${typelist}" ";")
[ "$c" -eq $COLUMNS ] && {
typelist=$(listr "topwall" "${typelist}" ";")
} || : ;;
# corner logic
?"t "??|?"_ "??)
typelist=$(listr "sdoor" "${typelist}" ";")
typelist=$(listr "blank" "${typelist}" ";")
[ "$topwallc" -a "${topwallc:-0}" -gt "$MC" ] && { # $MC is max columns (length) -- see rbase
typelist=$(listr "topwall" "${typelist}" ";")
typelist=$(listr "blank" "${typelist}" ";")
} || {
[ "$topwallc" -lt $((MiC+1)) ] 2>/dev/null && {
typelist=$(listr "corner" "${typelist}" ";")
}
}
case "$vpos" in
?"_ "??)
typelist=$(listr "topdoor" "${typelist}" ";")
typelist=$(listr "corner" "${typelist}" ";") ;;
"_t "??) typelist=$(listr "topdoor" "${typelist}" ";")
esac
typelist=$(listr "floor" "${typelist}" ";")
inchance "topwall" "3" ";" ;; # increase the chance of topwall
# topwall logic
"b# "??)
room="true"; inchance "floor" "1" ";"
typelist=$(listr "topdoor" "${typelist}" ";")
typelist=$(listr "sdoor" "${typelist}" ";")
typelist=$(listr "blank" "${typelist}" ";")
typelist=$(listr "corner" "${typelist}" ";")
typelist=$(listr "topwall" "${typelist}" ";")
typelist=$(listr "swall" "${typelist}" ";") ;;
?"# "??|"#"?" "??)
typelist=$(listr "topdoor" "${typelist}" ";")
typelist=$(listr "sdoor" "${typelist}" ";")
typelist=$(listr "corner" "${typelist}" ";")
typelist=$(listr "topwall" "${typelist}" ";")
typelist=$(listr "swall" "${typelist}" ";") ;;
?"- "??)
typelist=$(listr "topdoor" "${typelist}" ";")
typelist=$(listr "topwall" "${typelist}" ";")
esac
}
##A
apos() {
case "$vpos" in
??" cc")
typelist=$(listr "topdoor" "${typelist}" ";")
typelist=$(listr "corner" "${typelist}" ";")
typelist=$(listr "sdoor" "${typelist}" ";")
typelist=$(listr "swall" "${typelist}" ";") ;;
??" #"?)
[ "${swallc:-0}" -lt $((MiL+1)) ] && {
typelist=$(listr "corner" "${typelist}" ";")
} || inchance "corner" "2" ";"
[ "${swallc:-0}" -gt $ML ] && typelist=$(listr "swall" "${typelist}" ";")
case "$vpos" in
??" #c") typelist=$(listr "corner" "${typelist}" ";")
esac
case "$vpos" in
?"b "??) : ;;
*)
typelist=$(listr "blank" "${typelist}" ";")
esac
[ "$(inlist wall "${typelist}")" = ":" ] && inchance "swall" "4" ";"
typelist=$(listr "topwall" "${typelist}" ";") ;;
??" d"?)
inchance "swall" "2" ";"
[ "${swallc:-0}" -lt $((MiL+1)) ] && {
typelist=$(listr "corner" "${typelist}" ";")
}
[ "${swallc:-0}" -gt $ML ] && typelist=$(listr "swall" "${typelist}" ";")
typelist=$(listr "topwall" "${typelist}" ";")
typelist=$(listr "topdoor" "${typelist}" ";")
typelist=$(listr "sdoor" "${typelist}" ";")
typelist=$(listr "blank" "${typelist}" ";") ;;
??" bb")
typelist=$(listr "sdoor" "${typelist}" ";")
typelist=$(listr "swall" "${typelist}" ";") ;;
??" t"?|??" f"?|??" _"?)
case "$vpos" in
??" ff"|?"c ff"|"ct ff"|"tt ff"|?"c cf"|"ct cf"|"tt cf"|"c_ cf"|"t_ cf"|"t_ ff"|"_t ff") : ;;
*)
typelist=$(listr "corner" "${typelist}" ";")
typelist=$(listr "topdoor" "${typelist}" ";")
typelist=$(listr "topwall" "${typelist}" ";")
inchance "blank" "2" ";"
esac
typelist=$(listr "swall" "${typelist}" ";")
typelist=$(listr "sdoor" "${typelist}" ";")
case "$vpos" in
?"c tb") typelist=$(listr "blank" "${typelist}" ";")
esac
case "$vpos" in
?"t "??) : ;;
??" f"?) inchance "floor" "4" ";"
esac ;;
??" b"?)
typelist=$(listr "sdoor" "${typelist}" ";")
typelist=$(listr "swall" "${typelist}" ";") ;;
??" c-"|??" cb")
case "$vpos" in
'#'????|?'# '??|?'| '??) typelist=$(listr "swall" "${typelist}" ";") ;; # cannot be wall if wall is 2 blocks over
?"b "??|?"f "??)
inchance "swall" "2" ";"
esac
typelist=$(listr "topdoor" "${typelist}" ";")
typelist=$(listr "topwall" "${typelist}" ";")
typelist=$(listr "corner" "${typelist}" ";")
typelist=$(listr "blank" "${typelist}" ";") ;;
??" c"?)
case "$vpos" in
'#'????|?'# '??|?'d '??|"df "??) typelist=$(listr "swall" "${typelist}" ";") ;; # cannot be wall if wall is 2 blocks over
?"b "??|?"f "??)
inchance "swall" "3" ";"
esac
typelist=$(listr "topdoor" "${typelist}" ";")
typelist=$(listr "topwall" "${typelist}" ";")
typelist=$(listr "corner" "${typelist}" ";") ;;
??" t"?|??" bt")
typelist=$(listr "topdoor" "${typelist}" ";")
typelist=$(listr "topwall" "${typelist}" ";")
typelist=$(listr "swall" "${typelist}" ";")
typelist=$(listr "corner" "${typelist}" ";")
typelist=$(listr "sdoor" "${typelist}" ";") ;;
??" -"?)
typelist=$(listr "sdoor" "${typelist}" ";")
typelist=$(listr "swall" "${typelist}" ";")
esac
}
[ "$FILE" ] || :>./state
## LOOP
ml=0; for l in $(s 1 $LINES); do # for each line
[ "$l" -gt 3 ] && printf '\n' >> ./state
mc=0; for c in $(s 1 $COLUMNS); do # left to right across screen
[ "$Fc" ] && {
: $((c+=Fc))
[ "$Fc" -ge 3 ] && : $((c-=3))
}
bord; [ "$bord" ] && {
printf '%s' "$bord"
continue
} # draw borders
typelist=$(listr "floor" "${typelist}" ";")
[ "$otypelist" ] && {
typelist="$otypelist"
} || {
listgen; otypelist="$typelist"
otypelist=$(listr "floor" "${otypelist}" ";")
}
[ "$FILE" ] && {
case "$FILE" in
'-') cont <&0 ;;
*) cont < "${FILE}"
esac
unset FILE
}
# generate the typelist
# basically the idea here is have a list of all possible things a 1x1 space can be
# wall,sdoor,blank,etc; these are ofc effected by the blocks around them and the current pos
# basically use ran() and some pain to have it pick what a block should be
# the list should be dynamic based on the pos and blocks around it
# ie; placing a sdoor when there is no where for it to lead makes no sense
if [ "$l3c3" ]; then # counter logic is handled in sgrid() as items are handed off to it after being picked
#printf 'start positional logic...\n' >> ./debug
# do logic if indexes are set
vdpos="$(dpos $l $c)"
vpos="$(pos $l $c)"
## POSITIONAL LOGIC
## ROOM/SMART
roompos
## BESIDE
sidepos
# one case for beside, one for above
## BELOW/ABOVE
apos
case "$vpos" in
?'t #'?|?'t d'?|?'t c'?|?'c #'?|?'c c'?)
typelist=$(listr "swall" "${typelist}" ";")
inchance "corner" "2" ";"
esac
## DIAGONAL
diapos
## FLOOR
[ "$room" ] && {
case "$vpos" in
?"b tf"|"f# tf") inchance "blank" "2" ";" ;;
*)
typelist=$(listr "blank" "${typelist}" ";")
case "$vpos" in
?"t "??) : ;;
*) inchance "floor" "5" ";"
esac
esac
} || typelist=$(listr "floor" "${typelist}" ";")
#[ "$l" -gt 3 ] && {
# printf 'finished positional logic... checking for errors...\n' >> ./debug
#}
else # below may run if last exit code is !0 and not handled
typelist=$(listr "topdoor" "${typelist}" ";")
typelist=$(listr "floor" "${typelist}" ";")
typelist=$(listr "sdoor" "${typelist}" ";")
typelist=$(listr "topwall" "${typelist}" ";")
typelist=$(listr "swall" "${typelist}" ";")
[ "$l" -gt 3 ] && {
printf 'failed to preform positional logic... $l3c3 likely unset\n' >> ./debug
}
fi
[ "$c" -le 3 -o "$l" -lt 2 ] && { # must be at least 3 over on C to create a sdoor
# must also be at least 1 L down; this should also be effected by the surrounding blocks
typelist=$(listr "sdoor" "${typelist}" ";")
}
clist "${typelist}" # correct any errors in the list
# $tln is not globally adjusted by listr -- since it runs in a subshell; below is the simplest fix
IFS=";"; set -- ${typelist}; tln=${#}; unset IFS ran
ran=0; until [ "$ran" -gt 0 -a "$ran" -eq "$ran" -a "$ran" -le "$tln" ]; do
ran=$(${RPATH:-.}/rng/ran)
until [ "${ran%0}" = "$ran" ]; do
ran=${ran%0}
done # make sure the last digit is NOT a 0
until [ "${#ran}" -le $(listS) ]; do
ran=${ran#?};
until [ "${ran#0}" = "${ran}" ]; do
ran="${ran#0}"
done
done # shorten $ran until it is the length of the number of items in $typelist
done
# generate random number less than or equal to the number of items in $typelist
IFS=";"
n=0; for i in ${typelist}; do
: $((n+=1))
[ "$n" -eq "$ran" ] && {
[ "$i" = "topwall" -o "$i" = "corner" ] && {
: $((mc+=1))
} || mc=0
eval $(printf 'sgrid "$%s" %s %s' "$i" "$c" "$l")
# sgrid here is not called within a subshell
break
}
done; unset IFS # now select the item and print it
done
echo; unset topwallc # reset counter on now line
[ "$bord" ] || echo 'NEW LINE' >> ./debug && unset Fc
[ "$bord" ] || printf '\n' >> ./state
done # this prob makes mparse/rparse obsolete lmao