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["Pow"] = stat["Cha"] = 0; |
50 |
} |
51 |
|
52 |
/^Str|^Dex|^Con|^Int|^Wis|^Pow|^Cha/ { stat[$1] = $2; next } |
53 |
|
54 |
$1 in magic { add_magik(magic[$1], $2) } |
55 |
|
56 |
/^type/ { type = $2 } |
57 |
/^last_sp/ { last_sp = $2 } |
58 |
/^weight/ { weight = $2 } |
59 |
/^attacktype/ { att = $2 } |
60 |
/^protected/ { prot = $2 } |
61 |
/^immune/ { immune = $2 } |
62 |
/^slaying/ { slay = $2; } |
63 |
/^name/ { name = substr($0, 6) } |
64 |
|
65 |
/^end/ { |
66 |
if (type == 1) { # Players |
67 |
if (att % 2) --att; # Skip physical attack |
68 |
magik = magik attacktype(att , "Attacks:"); |
69 |
magik = magik attacktype(prot, "Protected:"); |
70 |
magik = magik attacktype(immune, "Immune:"); |
71 |
if (slay) |
72 |
magik = magik "\\newline " capitalize(slay=="wall" ? "excavation" : slay "-slaying"); |
73 |
|
74 |
sub("^\\\\newline ", "", magik); |
75 |
magik = capitalize(magik); |
76 |
name = capitalize(name); |
77 |
sub("_", " ", name); |
78 |
printf("%s &~~%s~~ &%d &%d &%d &%d &%d &%d &%d &%s\\\\\n", |
79 |
name, obj, |
80 |
20+stat["Str"], 20+stat["Dex"], 20+stat["Con"], |
81 |
20+stat["Int"], 20+stat["Wis"], 20+stat["Pow"], |
82 |
20+stat["Cha"], magik); |
83 |
} |
84 |
} |
85 |
|
86 |
END { |
87 |
close("items"); |
88 |
} |
89 |
|
90 |
|
91 |
# Given a bitmask, give a string enumerating the meaning of the bits. |
92 |
function attacktype(at, type, i, str) { |
93 |
for (i = 1; i in attack; i++) { |
94 |
if (at % 2) |
95 |
str = (str ? str ", " : "") attack[i]; |
96 |
at = int(at/2); |
97 |
} |
98 |
return str ? "\\newline " type " " str : ""; |
99 |
} |
100 |
|
101 |
function add_magik(str, val) { |
102 |
str = sprintf(str, val < 0 ? val : "+" val); |
103 |
if (str) |
104 |
magik = magik ? magik ", " str : str; |
105 |
} |
106 |
|
107 |
function capitalize(str) { |
108 |
return toupper(substr(str, 1, 1)) substr(str, 2); |
109 |
} |