ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/doc/playbook/char-extract
Revision: 1.2
Committed: Thu Sep 7 21:43:14 2006 UTC (17 years, 9 months ago) by pippijn
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +0 -0 lines
State: FILE REMOVED
Log Message:
Moved documents to doc/historic

File Contents

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