| 1 |
# stats-extract - parse the archetypes-file and output the |
| 2 |
# player's stats in a structured format. |
| 3 |
|
| 4 |
# Variables passed when invoked: |
| 5 |
# living_c - filename where the array attacks is defined. |
| 6 |
|
| 7 |
BEGIN { |
| 8 |
# These stats will be added to the "magik" string according |
| 9 |
# to the pattern. "%s" should be "%+d", but that isn't |
| 10 |
# portable. |
| 11 |
magic["luck"] = "luck %s"; |
| 12 |
magic["exp"] = "speed %s"; |
| 13 |
magic["sp"] = "spell-point regeneration %s"; |
| 14 |
magic["hp"] = "hit-point regeneration %s"; |
| 15 |
magic["dam"] = "damage %s"; |
| 16 |
magic["ac"] = "ac %d"; |
| 17 |
magic["armour"] = "armour %s"; |
| 18 |
|
| 19 |
magic["reflect_spell"] = "reflect spells"; |
| 20 |
magic["xrays"] = "X-ray vision"; |
| 21 |
magic["stealth"] = "stealth"; |
| 22 |
magic["flying"] = "flying"; |
| 23 |
|
| 24 |
# Read the attack-types (and immune/protection) |
| 25 |
while ((getline buff < living_c) == 1) { |
| 26 |
if (buff ~ /attacks\[/) { |
| 27 |
att = 0; |
| 28 |
while (1) { |
| 29 |
getline buff < living_c; |
| 30 |
if (buff ~ "^}") |
| 31 |
break; |
| 32 |
gsub("[ \t]*\"", "", buff); |
| 33 |
nr = split(buff, arr, ","); |
| 34 |
for (i = 1; i <= nr && arr[i]; i++) |
| 35 |
attack[++att] = arr[i]; |
| 36 |
} |
| 37 |
break; |
| 38 |
} |
| 39 |
} |
| 40 |
close(living_c); |
| 41 |
} |
| 42 |
|
| 43 |
/^Object/ { |
| 44 |
slay = magik = ""; |
| 45 |
name = obj = $2; |
| 46 |
type = weight = last_sp = 0; |
| 47 |
att = prot = immune = 0; |
| 48 |
stat["Str"] = stat["Dex"] = stat["Con"] = 0; |
| 49 |
stat["Int"] = stat["Wis"] = stat["Cha"] = 0; |
| 50 |
stat["Pow"] = 0; |
| 51 |
|
| 52 |
} |
| 53 |
|
| 54 |
/^Str|^Dex|^Con|^Int|^Wis|^Cha|^Pow/ { stat[$1] = $2; next } |
| 55 |
|
| 56 |
$1 in magic { add_magik(magic[$1], $2) } |
| 57 |
|
| 58 |
/^type/ { type = $2 } |
| 59 |
/^last_sp/ { last_sp = $2 } |
| 60 |
/^weight/ { weight = $2 } |
| 61 |
/^attacktype/ { att = $2 } |
| 62 |
/^protected/ { prot = $2 } |
| 63 |
/^immune/ { immune = $2 } |
| 64 |
/^slaying/ { slay = $2; } |
| 65 |
/^name/ { name = substr($0, 6) } |
| 66 |
|
| 67 |
/^end/ { |
| 68 |
if (type == 1) { # Players |
| 69 |
if (att % 2) --att; # Skip physical attack |
| 70 |
magik = magik attacktype(att , "Attacks:"); |
| 71 |
magik = magik attacktype(prot, "Protected:"); |
| 72 |
magik = magik attacktype(immune, "Immune:"); |
| 73 |
if (slay) |
| 74 |
magik = magik "<br> " capitalize(slay=="wall" ? "excavation" : slay "-slaying"); |
| 75 |
|
| 76 |
# sub("^\\\\newline ", "", magik); |
| 77 |
magik = capitalize(magik); |
| 78 |
name = capitalize(name); |
| 79 |
sub("_", " ", name); |
| 80 |
printf("<tr><th>%s</th><td>~~%s~~</td><td>%d</td><td>%d</td><td>%d</td><td>%d</td><td>%d</td><td>%d</td><td>%d</td><td>%s</td></tr>\n", |
| 81 |
name, obj, |
| 82 |
20+stat["Str"], 20+stat["Dex"], 20+stat["Con"], |
| 83 |
20+stat["Int"], 20+stat["Wis"], 20+stat["Cha"], |
| 84 |
20+stat["Pow"], magik); |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
END { |
| 89 |
close("items"); |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
# Given a bitmask, give a string enumerating the meaning of the bits. |
| 94 |
function attacktype(at, type, i, str) { |
| 95 |
for (i = 1; i in attack; i++) { |
| 96 |
if (at % 2) |
| 97 |
str = (str ? str ", " : "") attack[i]; |
| 98 |
at = int(at/2); |
| 99 |
} |
| 100 |
return str ? "<br> " type " " str : ""; |
| 101 |
} |
| 102 |
|
| 103 |
function add_magik(str, val) { |
| 104 |
str = sprintf(str, val < 0 ? val : "+" val); |
| 105 |
if (str) |
| 106 |
magik = magik ? magik ", " str : str; |
| 107 |
} |
| 108 |
|
| 109 |
function capitalize(str) { |
| 110 |
return toupper(substr(str, 1, 1)) substr(str, 2); |
| 111 |
} |