1 |
# treas-extract - parse the treasures-file and output the |
2 |
# player's stats in a structured format. |
3 |
|
4 |
# read in the list of player randomitems from randitem |
5 |
BEGIN { |
6 |
# yeah, its kludgey, but hey, I've been programming awk for |
7 |
# all of 1 day! |
8 |
|
9 |
ignoreitem["ability_fire"] = 1; |
10 |
ignoreitem["magic"] = 1; |
11 |
ignoreitem["more"] = 1; |
12 |
ignoreitem["basic_skills"] = 1; |
13 |
ignoreitem["wizard_skills"] = 1; |
14 |
ignoreitem["spell_skills"] = 1; |
15 |
ignoreitem["priest_skills"] = 1; |
16 |
ignoreitem["fighter_skills"] = 1; |
17 |
ignoreitem["random_knowledge"] = 1; |
18 |
ignoreitem["player_force"] = 1; |
19 |
ignoreitem["nrof"] = 1; |
20 |
ignoreitem["no_class_face_change"] = 1; |
21 |
|
22 |
plural["arrow"] = 1; |
23 |
|
24 |
newname["mage_skills"] = "talisman"; |
25 |
newname["nunchacu_1"] = "nunchacu"; |
26 |
newname["r_sack"] = "ruck sack"; |
27 |
newname["cleric_book"] = "prayer book"; |
28 |
newname["book"] = "spell book"; |
29 |
|
30 |
# Read the player treasure types |
31 |
pl = 0; |
32 |
while ((getline buff < eqitems) == 1) { |
33 |
nr = split(buff, line, ","); |
34 |
player[pl] = line[1]; |
35 |
list[pl] = line[2]; |
36 |
pl++; |
37 |
} |
38 |
close(playerlist); |
39 |
|
40 |
} |
41 |
|
42 |
$1 == "treasure" { |
43 |
for ( i=0; i < pl ; i++ ) { |
44 |
if ($2 == list[i]) { # matched players list |
45 |
nrloop=0; |
46 |
do { |
47 |
getline; |
48 |
if($1 in ignoreitem) continue; |
49 |
if($1 == ("yes"||"no")) { |
50 |
nrloop++; |
51 |
continue; |
52 |
} else if($1 == "end") { |
53 |
if(nrloop==0) { break; } else { nrloop--; } |
54 |
continue; |
55 |
} |
56 |
if($2 ~ "^skill") continue; |
57 |
if($2 ~ "force$") continue; |
58 |
if($2 in ignoreitem) continue; |
59 |
equip = $2; |
60 |
if(equip in plural) equip = sprintf("%ss",equip); |
61 |
if(equip in newname) equip = newname[equip]; |
62 |
equiplist[i] = sprintf("%s,%s",equiplist[i],equip); |
63 |
} while ( $1 != ("treasure" || "treasureone" || "list" ) ) |
64 |
} |
65 |
} |
66 |
} |
67 |
|
68 |
END { |
69 |
close("trease"); |
70 |
# now print this stuff out in correct order! |
71 |
for(i=0;i<pl;i++) { |
72 |
printf("<tr><td>%s</td><td>",capitalize(player[i])); |
73 |
nr = split(equiplist[i], eq, ","); |
74 |
if(nr==0) { |
75 |
# hmm. This can happen if 2 or more character classes |
76 |
# share the same treaure list. Lets find it. |
77 |
for(j=0;j<pl;j++) |
78 |
if(list[i]==list[j]) break; |
79 |
nr = split(equiplist[j], eq, ","); |
80 |
} |
81 |
sub("_", " ", eq[nr]); |
82 |
printf("%s",capitalize(eq[nr--])); |
83 |
do { |
84 |
printf(", "); |
85 |
sub("_", " ", eq[nr]); |
86 |
# printf("& %s\\\\\n",capitalize(eq[nr])); |
87 |
printf("%s",capitalize(eq[nr])); |
88 |
} while (--nr>1); |
89 |
printf("</td></tr>\n"); |
90 |
} |
91 |
} |
92 |
|
93 |
function capitalize(str) { |
94 |
return toupper(substr(str, 1, 1)) substr(str, 2); |
95 |
} |
96 |
|