ratcatcher/scripts/fixlevel.awk

64 lines
979 B
Awk
Raw Normal View History

2008-09-16 12:40:09 +10:00
BEGIN {
state = 0;
nummons = 0;
montype[0] = "c";
montype[1] = "r";
montype[2] = "S";
montype[3] = "a";
montype[4] = "s";
montype[5] = "?";
montype[6] = "1";
montypes = 7;
}
{
if (state == 0) {
if (length($0) == 40) {
state = 1;
curline = 0;
} else {
print;
}
}
if (state == 1) {
pos = 1;
# any monsters?
for (mon = 0; mon < montypes; mon++) {
# record locations
for (pos = 1; pos <= length($0); pos++) {
if (substr($0,pos,1) == montype[mon]) {
monx[nummons] = pos-1;
mony[nummons] = curline;
monchar[nummons] = montype[mon];
nummons++;
}
}
# remove
if (montype[mon] == "?") {
gsub("\\?","0");
} else {
gsub(montype[mon],"0");
}
}
line[curline] = $0;
curline++;
}
}
END {
printf("monsters\n");
for (m = 0; m < nummons; m++) {
printf("%s %d %d\n",monchar[m],monx[m],mony[m]);
}
printf("endmonsters\n");
for (l = 0; l < curline; l++) {
printf("%s\n",line[l]);
}
}