ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/doc/spoiler/items-extract
Revision: 1.1
Committed: Fri Feb 3 07:12:45 2006 UTC (18 years, 4 months ago) by root
Branch: MAIN
Branch point for: UPSTREAM
Log Message:
Initial revision

File Contents

# Content
1 # items-extract - parse the archetypes-file and output the
2 # artifacts 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["Str"] = "strength %s";
12 magic["Dex"] = "dexterity %s";
13 magic["Con"] = "constitution %s";
14 magic["Int"] = "intelligence %s";
15 magic["Wis"] = "wisdom %s";
16 magic["Cha"] = "charisma %s";
17 magic["Pow"] = "power %s";
18
19 magic["luck"] = "luck %s";
20 magic["exp"] = "speed %s";
21 magic["sp"] = "spell-point regeneration %s";
22 magic["hp"] = "hit-point regeneration %s";
23 # magic["dam"] = "damage %s";
24
25 magic["reflect_spell"] = "reflect spells";
26 magic["xrays"] = "X-ray vision";
27 magic["stealth"] = "stealth";
28 magic["flying"] = "flying";
29
30 # Read the attack-types (and immune/protection)
31 while ((getline buff < living_c) == 1) {
32 if (buff ~ /attacks\[/) {
33 att = 0;
34 while (1) {
35 getline buff < living_c;
36 if (buff ~ "^}")
37 break;
38 gsub("[ \t]*\"", "", buff);
39 nr = split(buff, arr, ",");
40 for (i = 1; i <= nr && arr[i]; i++)
41 attack[++att] = arr[i];
42 }
43 break;
44 }
45 }
46 close(living_c);
47
48 # These types are always artifacts:
49 artifact[99] = artifact[14] = artifact[16] = artifact[33] = 1;
50 artifact[34] = artifact[100] = artifact[113] = artifact[915] = 1;
51
52 weapons[15] = weapons[915] = 1;
53 armours[16] = armours[33] = armours[34] = armours[99] = 1;
54
55 worthless["chair"] = worthless["table"] = worthless["bed"] = 1;
56 }
57
58 /^Object/ {
59 slay = magik = "";
60 name = obj = $2;
61 x = y = 0;
62 xmin = xmax = ymin = ymax = 0;
63 More = 0;
64 dam = type = magical = ac = armour = weight = last_sp = 0;
65 att = prot = immune = 0;
66 }
67
68 $1 in magic {
69 if ($1 == "sp" && type == 14)
70 ac = $2;
71 else
72 add_magik(magic[$1], $2);
73 }
74
75 /^type/ { type = $2 }
76 /^last_sp/ { last_sp = $2 }
77 /^dam/ { dam = $2 }
78 /^ac/ { ac = $2 }
79 /^armour/ { armour = $2 }
80 /^weight/ { weight = $2 }
81 /^attacktype/ { att = $2 }
82 /^protected/ { prot = $2 }
83 /^immune/ { immune = $2 }
84 /^slaying/ { slay = $2; }
85 /^magic/ { magical = $2 }
86 /^name / { name = substr($0, 6) }
87
88 /^end/ {
89 # Type 15 are artifacts if they are magical
90 if (type == 15 && magical)
91 type += 900;
92 # It can also be chairs and beds, but they are in the worthless
93 # array...
94 if (artifact[type] || (type == 15 && !worthless[name])) {
95 if (dam && ! (type in weapons))
96 add_magik("damage %s", dam);
97 if (ac && ! (type in armours))
98 add_magik("ac %s", ac);
99 if (armour && ! (type in armours))
100 add_magik("armour %s", armour);
101
102 magik = magik attacktype(att, "Attacks:");
103 magik = magik attacktype(prot, "Protected:");
104 magik = magik attacktype(immune, "Immune:");
105 if (slay)
106 magik = magik "\\newline " capitalize(slay=="wall" ? "excavation" : slay "-slaying");
107
108 if (magical)
109 name = name " +" magical;
110
111 sub("^\\\\newline ", "", magik);
112 magik = capitalize(magik);
113 name = capitalize(name);
114 sub("_", " ", name);
115
116 if (type in armours)
117 speed = last_sp/10;
118 else if (type in weapons) {
119 # Horrible, I know. Blame vidarl@ifi.uio.no -- Fy Vidar!
120 # I assume the player has max Str and Dex
121 # and speed of 6 here.
122
123 # weapon_speed = (last_sp*2 - magical) / 2;
124 # if (weapon_speed < 0) weapon_speed = 0;
125
126 # M = (300-121)/121.0;
127 # M2 = 300/100.0;
128 # W = weight/20000.0;
129 # s = 2 - weapon_speed/10.0;
130
131 # D = (30-14)/14.0;
132 # K = 1 + M/3.0 - W/(3*M2) + 6/5.0 + D/2.0;
133 # K *= (4 + 99)/(6 + 99) * 1.2;
134 # if ( K <= 0) K = 0.01
135
136 # W = weight/20000; s = 2 - ((last_sp*2 - magical) / 2)/10;
137 # K = 1.177*(4 - W/30 + 6/5)
138 # if (K <= 0) K = 0.01;
139
140 # speed = 6/(K*s);
141
142 speed = last_sp;
143 } else
144 speed = 0;
145
146 printf("%d &%s &%s &%s &%d &%.1f &%d &%d &%d &~~%s~~ &%.2f\n",
147 type, obj, name, magik, dam, (weight/1000), ac,
148 armour, magical, obj, speed);
149 }
150 }
151
152 END {
153 close("items");
154 }
155
156
157 # Given a bitmask, give a string enumerating the meaning of the bits.
158 function attacktype(at, type, i, str) {
159 for (i = 1; i in attack; i++) {
160 if (at % 2)
161 str = (str ? str ", " : "") attack[i];
162 at = int(at/2);
163 }
164 return str ? "\\newline " type " " str : "";
165 }
166
167 function add_magik(str, val) {
168 if (str ~ /%[0-9-]*s/)
169 str = sprintf(str, val < 0 ? val : "+" val);
170 magik = magik ? magik ", " str : str;
171 }
172
173 function capitalize(str) {
174 return toupper(substr(str, 1, 1)) substr(str, 2);
175 }