author | Wuzzy <Wuzzy2@mail.ru> |
Tue, 04 Sep 2018 16:26:15 +0200 | |
changeset 13764 | bef952489e0e |
parent 13069 | 6766b900ab13 |
permissions | -rwxr-xr-x |
13068
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
1 |
#!/bin/sh - |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
2 |
# === HWMAP-to-Lua converter === |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
3 |
# This script allows you to put arbitrary HWMAPs into your missions! |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
4 |
# |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
5 |
# Usage: |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
6 |
# It expects a .hwmap file of name "map.hwmap" to be in |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
7 |
# its directory and creates a Lua file (map.lua) containing code to |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
8 |
# draw the map. |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
9 |
# In Lua, call drawMap() in onGameInit. And don't forget |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
10 |
# to set MapGen to mgDrawn. Then your map should be ready to go! :-) |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
11 |
|
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
12 |
# FILE NAMES |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
13 |
IN="./map.hwmap"; |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
14 |
OUT="./map.lua"; |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
15 |
|
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
16 |
# TEMPORARY FILES |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
17 |
TEMP_UNBASE=$(mktemp); |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
18 |
TEMP_GZIP=$(mktemp); |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
19 |
TEMP_OCTETS=$(mktemp); |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
20 |
base64 -d $IN | tail -c +7 | head -c -4 > $TEMP_UNBASE; |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
21 |
echo -ne "\x1f\x8b\x08\0\0\0\0\0\x02\xff" > $TEMP_GZIP; |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
22 |
# Suppress gunzip warning: "gzip: stdin: unexpected end of file" |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
23 |
cat $TEMP_GZIP $TEMP_UNBASE | gunzip 2> /dev/null > $TEMP_OCTETS; |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
24 |
C=0; |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
25 |
echo -n '-- Map definition automatically converted from HWMAP file by hwmap2lua.sh |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
26 |
local map = {' > $OUT; |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
27 |
od -w240 -t u1 $TEMP_OCTETS | grep -Ev "^[0-9]*[[:space:]]*$" | while read f; |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
28 |
do C=$((C+1)); |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
29 |
if ((C!=1)); |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
30 |
then |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
31 |
echo "," >> $OUT; |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
32 |
fi; |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
33 |
echo -n $f | sed "s/^......./'/;s/ */\\\\/g;s/$/'/" >> $OUT; |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
34 |
done; |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
35 |
echo '} |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
36 |
|
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
37 |
local function drawMap() |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
38 |
for m=1, #map do |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
39 |
ParseCommand("draw "..map[m]) |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
40 |
end |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
41 |
end' >> $OUT; |
dc77c2c679b2
Add szczur's script to convert .hwmap to Lua code
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
42 |
rm $TEMP_UNBASE $TEMP_GZIP $TEMP_OCTETS; |