-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenSeed.sh
More file actions
executable file
·110 lines (93 loc) · 2.77 KB
/
genSeed.sh
File metadata and controls
executable file
·110 lines (93 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\t\n'
: "${F7D2D:?Please export F7D2D with 7D2D install folder}"
usage() {
cat >&2 <<-USAGE
$0 [options] <size> <seed>
Options:
--towns None | Few | Default | Many
--wilderness None | Few | Default | Many
--rivers None | Few | Default | Many
--craters None | Few | Default | Many
--cracks None | Few | Default | Many
--lakes None | Few | Default | Many
--plains 0 .. 10
--hills 0 .. 10
--mountains 0 .. 10
--random 0 .. 10
USAGE
exit 1
}
declare -a ARGS
ARGS=( )
while [[ $# -gt 0 && $1 == -* ]]; do
case "$1" in
--towns | --wilderness | --rivers | --craters | --cracks | --lakes | --plains | --hills | --mountains | --random)
ARGS=( "${ARGS[@]}" "$1" "$2" )
shift 2
;;
*)
usage
;;
esac
done
if [[ $# -ne 2 ]]; then
usage
fi
SIZE="$1"
SEED="$2"
BIN="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
LOG="${F7D2D}/log.txt"
echo "*** Generating seed '$SEED' at $SIZE"
sleep 1 # Last chance to abort
SECONDS=0
#"${BIN}/startServer.sh" "$SIZE" "${SEED}" > log.startServer.txt
"${BIN}/startClient.sh" "${ARGS[@]}" "$SIZE" "${SEED}" > log.startClient.txt
duration=$SECONDS
if grep "Generation Complete" "$LOG"; then
echo "World generated in $((duration / 60)) minutes and $((duration % 60)) seconds"
# Get county name
# shellcheck disable=SC2012
if ! COUNTY=$( \
ls -1rt "${F7D2D}/UserData/GeneratedWorlds/" \
| tail -1 \
) && [[ -n $COUNTY ]]; then
echo >&2 "Cannot figure out generated world"
exit 1
fi
WORLD="${F7D2D}/UserData/GeneratedWorlds/$COUNTY"
echo "Rating (${RATE_OPTS:-defaults}):"
if [[ -v RATE_OPTS && -n "${RATE_OPTS}" ]]; then
IFS=' ' RATE_OPTS=( ${RATE_OPTS} )
else
RATE_OPTS=( )
fi
RATE=$("${BIN}/rate.py" "${RATE_OPTS[@]}" "${WORLD}/prefabs.xml")
echo "${RATE}"
RATING=$(tail -1 <<< "$RATE" | cut -d ' ' -f 1)
if [[ -n "${RATING_THRESHOLD-}" && "$RATING" -lt "${RATING_THRESHOLD}" ]]; then
echo "Rating ${RATING} below threshold ${RATING_THRESHOLD}; skipping after $((duration / 60)) minutes and $((duration % 60)) seconds"
else
mkdir -p "${F7D2D}/previews"
"${BIN}/savePreview.sh" \
--world "${WORLD}" \
--name "${COUNTY}" \
--output "${F7D2D}/previews/${SEED}-${SIZE}.zip" \
--rating "${RATING}" \
${RATING_THRESHOLD:+--base} \
--options "${ARGS[@]}" --endoptions \
"${SIZE}" "${SEED}" 2>&1 | tee log.savePreview.txt
echo "World preview saved"
fi
else
echo "Generation aborted after $((duration / 60)) minutes and $((duration % 60)) seconds"
exec "$0" "$@"
fi
TASK_LIST="$(tasklist.exe)"
if grep -q ^7DaysToDieServer.exe <<<"$TASK_LIST"; then
taskkill.exe /IM "7DaysToDieServer.exe" /F /T || :
fi
if grep -q ^7DaysToDie.exe <<<"$TASK_LIST"; then
taskkill.exe /IM "7DaysToDie.exe" /F /T || :
fi