1 |
root |
1.1 |
/* |
2 |
|
|
* This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 |
|
|
* |
4 |
root |
1.17 |
* Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 |
root |
1.9 |
* Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 |
|
|
* Copyright (©) 1992 Frank Tore Johansen |
7 |
root |
1.1 |
* |
8 |
|
|
* Deliantra is free software: you can redistribute it and/or modify it under |
9 |
|
|
* the terms of the Affero GNU General Public License as published by the |
10 |
|
|
* Free Software Foundation, either version 3 of the License, or (at your |
11 |
|
|
* option) any later version. |
12 |
|
|
* |
13 |
|
|
* This program is distributed in the hope that it will be useful, |
14 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
|
|
* GNU General Public License for more details. |
17 |
|
|
* |
18 |
|
|
* You should have received a copy of the Affero GNU General Public License |
19 |
|
|
* and the GNU General Public License along with this program. If not, see |
20 |
|
|
* <http://www.gnu.org/licenses/>. |
21 |
|
|
* |
22 |
|
|
* The authors can be reached via e-mail to <support@deliantra.net> |
23 |
|
|
*/ |
24 |
|
|
|
25 |
|
|
#include <global.h> |
26 |
|
|
#include <material.h> |
27 |
|
|
|
28 |
root |
1.3 |
//+GPL |
29 |
|
|
|
30 |
root |
1.5 |
materialtype_t *materialt; |
31 |
|
|
|
32 |
|
|
/* |
33 |
|
|
materialtype material[NROFMATERIALS] = { |
34 |
|
|
* P M F E C C A D W G P S P T F C D D C C G H B I * |
35 |
|
|
* H A I L O O C R E H O L A U E A E E H O O O L N * |
36 |
|
|
* Y G R E L N I A A O I O R R A N P A A U D L I T * |
37 |
|
|
* S I E C D F D I P S S W A N R C L T O N Y N R * |
38 |
|
|
* I C T U N O T O L E E H S T P D N * |
39 |
|
|
{"paper", {15,10,17, 9, 5, 7,13, 0,20,15, 0,0,0,0,0,10,0,0,0,0,0,0,0,0}}, |
40 |
|
|
{"metal", { 2,12, 3,12, 2,10, 7, 0,20,15, 0,0,0,0,0,10,0,0,0,0,0,0,0,0}}, |
41 |
|
|
{"glass", {14,11, 8, 3,10, 5, 1, 0,20,15, 0,0,0,0,0, 0,0,0,0,0,0,0,0,0}}, |
42 |
|
|
{"leather", { 5,10,10, 3, 3,10,10, 0,20,15, 0,0,0,0,0,12,0,0,0,0,0,0,0,0}}, |
43 |
|
|
{"wood", {10,11,13, 2, 2,10, 9, 0,20,15, 0,0,0,0,0,12,0,0,0,0,0,0,0,0}}, |
44 |
|
|
{"organics", { 3,12, 9,11, 3,10, 9, 0,20,15, 0,0,0,0,0, 0,0,0,0,0,0,0,0,0}}, |
45 |
|
|
{"stone", { 2, 5, 2, 2, 2, 2, 1, 0,20,15, 0,0,0,0,0, 5,0,0,0,0,0,0,0,0}}, |
46 |
|
|
{"cloth", {14,11,13, 4, 4, 5,10, 0,20,15, 0,0,0,0,0, 5,0,0,0,0,0,0,0,0}}, |
47 |
|
|
{"adamant", { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0,0,0,0, 0,0,0,0,0,0,0,0,0}}, |
48 |
|
|
{"liquid", { 0, 8, 9, 6,17, 0,15, 0,20,15,12,0,0,0,0,11,0,0,0,0,0,0,0,0}}, |
49 |
|
|
{"soft metal",{ 6,12, 6,14, 2,10, 1, 0,20,15, 0,0,0,0,0,10,0,0,0,0,0,0,0,0}}, |
50 |
|
|
{"bone", {10, 9, 4, 5, 3,10,10, 0,20,15, 0,0,0,0,0, 2,0,0,0,0,0,0,0,0}}, |
51 |
|
|
{"ice", {14,11,16, 5, 0, 5, 6, 0,20,15, 0,0,0,0,0, 7,0,0,0,0,0,0,0,0}} |
52 |
|
|
}; |
53 |
|
|
*/ |
54 |
|
|
|
55 |
|
|
materialtype_t::materialtype_t () |
56 |
|
|
{ |
57 |
root |
1.15 |
next = 0; |
58 |
|
|
reset (); |
59 |
|
|
} |
60 |
|
|
|
61 |
|
|
void |
62 |
|
|
materialtype_t::reset () |
63 |
|
|
{ |
64 |
root |
1.5 |
name = shstr_unknown; |
65 |
|
|
description = shstr_unknown_material_description; |
66 |
|
|
material = 0; |
67 |
|
|
|
68 |
|
|
for (int i = 0; i < NROFATTACKS; i++) |
69 |
|
|
{ |
70 |
root |
1.6 |
save [i] = 0; |
71 |
|
|
mod [i] = 0; |
72 |
root |
1.5 |
} |
73 |
|
|
|
74 |
|
|
chance = 0; |
75 |
|
|
difficulty = 0; |
76 |
|
|
magic = 0; |
77 |
|
|
damage = 0; |
78 |
|
|
wc = 0; |
79 |
|
|
ac = 0; |
80 |
|
|
sp = 0; |
81 |
|
|
weight = 100; |
82 |
|
|
value = 100; |
83 |
|
|
density = 1000; |
84 |
|
|
} |
85 |
|
|
|
86 |
root |
1.14 |
// create a new material of the given name |
87 |
|
|
static materialtype_t * |
88 |
|
|
dummy_material (shstr_tmp name) |
89 |
root |
1.1 |
{ |
90 |
root |
1.5 |
materialtype_t *mt = new materialtype_t; |
91 |
|
|
mt->name = name; |
92 |
|
|
|
93 |
root |
1.6 |
// make it susceptible to attacks |
94 |
|
|
for (int i = 0; i < NROFATTACKS; i++) |
95 |
|
|
{ |
96 |
|
|
mt->save [i] = 10; |
97 |
|
|
mt->mod [i] = 9; |
98 |
|
|
} |
99 |
|
|
|
100 |
|
|
mt->next = materialt; materialt = mt; |
101 |
root |
1.5 |
|
102 |
|
|
return mt; |
103 |
root |
1.1 |
} |
104 |
|
|
|
105 |
root |
1.15 |
static materialtype_t * |
106 |
|
|
find (const shstr_tmp name) |
107 |
|
|
{ |
108 |
|
|
for (materialtype_t *mt = materialt; mt; mt = mt->next) |
109 |
|
|
if (name == mt->name) |
110 |
|
|
return mt; |
111 |
|
|
|
112 |
|
|
return 0; |
113 |
|
|
} |
114 |
|
|
|
115 |
root |
1.14 |
/* convert materialname to materialtype_t */ |
116 |
|
|
materialtype_t * |
117 |
|
|
name_to_material (const shstr_tmp name) |
118 |
|
|
{ |
119 |
root |
1.15 |
materialtype_t *mt = find (name); |
120 |
root |
1.14 |
|
121 |
root |
1.15 |
if (!mt) |
122 |
|
|
{ |
123 |
|
|
LOG (llevError, "name_to_material called with nonexistent material '%s'\n", &name); |
124 |
|
|
mt = dummy_material (name); |
125 |
|
|
} |
126 |
root |
1.14 |
|
127 |
root |
1.15 |
return mt; |
128 |
root |
1.14 |
} |
129 |
|
|
|
130 |
|
|
void |
131 |
root |
1.15 |
object_thawer::get (materialtype_t *&mt) const |
132 |
root |
1.14 |
{ |
133 |
|
|
shstr name; |
134 |
|
|
get (name); |
135 |
|
|
|
136 |
root |
1.15 |
mt = find (name); |
137 |
root |
1.14 |
|
138 |
root |
1.15 |
if (!mt) |
139 |
|
|
{ |
140 |
|
|
parse_error (format ("material called %s requested, but not found, creating dummy material.\n", &name)); |
141 |
|
|
mt = dummy_material (name); |
142 |
|
|
} |
143 |
root |
1.14 |
} |
144 |
|
|
|
145 |
root |
1.1 |
/* when doing transmutation of objects, we have to recheck the resistances, |
146 |
|
|
* as some that did not apply previously, may apply now. |
147 |
|
|
*/ |
148 |
|
|
void |
149 |
|
|
transmute_materialname (object *op, const object *change) |
150 |
|
|
{ |
151 |
root |
1.6 |
if (!op->is_armor ()) |
152 |
|
|
return; |
153 |
root |
1.1 |
|
154 |
root |
1.7 |
if (op->material == MATERIAL_NULL) |
155 |
root |
1.1 |
return; |
156 |
|
|
|
157 |
root |
1.6 |
if (op->material != change->material) |
158 |
root |
1.1 |
return; |
159 |
|
|
|
160 |
root |
1.5 |
materialtype_t *mt = op->material; |
161 |
root |
1.1 |
|
162 |
root |
1.6 |
for (int j = 0; j < NROFATTACKS; j++) |
163 |
root |
1.1 |
if (op->resist[j] == 0 && change->resist[j] != 0) |
164 |
|
|
{ |
165 |
|
|
op->resist[j] += mt->mod[j]; |
166 |
root |
1.5 |
|
167 |
|
|
if (op->resist[j] > 100) op->resist[j] = 100; |
168 |
|
|
if (op->resist[j] < -100) op->resist[j] = -100; |
169 |
root |
1.1 |
} |
170 |
|
|
} |
171 |
|
|
|
172 |
|
|
/* set the materialname and type for an item */ |
173 |
|
|
void |
174 |
root |
1.5 |
select_material (object *op, int difficulty) |
175 |
root |
1.1 |
{ |
176 |
root |
1.7 |
if (op->material != MATERIAL_NULL || !op->materials) |
177 |
root |
1.5 |
return; |
178 |
root |
1.1 |
|
179 |
root |
1.5 |
materialtype_t *lmt = 0; |
180 |
root |
1.1 |
|
181 |
root |
1.5 |
//TODL: dead code? |
182 |
|
|
for (materialtype_t *mt = materialt; mt; mt = mt->next) |
183 |
|
|
if (op->materials & mt->material |
184 |
|
|
&& difficulty >= mt->difficulty |
185 |
|
|
&& rndm (1, 100) <= mt->chance |
186 |
|
|
&& (op->magic >= mt->magic || mt->magic == 0)) |
187 |
|
|
{ |
188 |
|
|
lmt = mt; |
189 |
root |
1.1 |
|
190 |
root |
1.5 |
if (!(op->is_weapon () || op->is_armor ())) |
191 |
|
|
break; |
192 |
|
|
} |
193 |
root |
1.1 |
|
194 |
|
|
if (lmt) |
195 |
|
|
{ |
196 |
|
|
if (op->stats.dam && op->is_weapon ()) |
197 |
|
|
{ |
198 |
|
|
op->stats.dam += lmt->damage; |
199 |
|
|
if (op->stats.dam < 1) |
200 |
|
|
op->stats.dam = 1; |
201 |
|
|
} |
202 |
|
|
|
203 |
root |
1.5 |
if (op->stats.sp && op->type == BOW ) op->stats.sp += lmt->sp; |
204 |
|
|
if (op->stats.wc && op->is_weapon ()) op->stats.wc += lmt->wc; |
205 |
|
|
|
206 |
root |
1.1 |
if (op->is_armor ()) |
207 |
|
|
{ |
208 |
|
|
if (op->stats.ac) |
209 |
|
|
op->stats.ac += lmt->ac; |
210 |
|
|
|
211 |
|
|
for (int j = 0; j < NROFATTACKS; j++) |
212 |
|
|
if (op->resist[j] != 0) |
213 |
|
|
{ |
214 |
|
|
op->resist[j] += lmt->mod[j]; |
215 |
root |
1.5 |
if (op->resist[j] > 100) op->resist[j] = 100; |
216 |
|
|
if (op->resist[j] < -100) op->resist[j] = -100; |
217 |
root |
1.1 |
} |
218 |
|
|
} |
219 |
|
|
|
220 |
root |
1.5 |
op->material = lmt; |
221 |
|
|
|
222 |
root |
1.1 |
/* dont make it unstackable if it doesn't need to be */ |
223 |
|
|
if (op->is_weapon () || op->is_armor ()) |
224 |
|
|
{ |
225 |
root |
1.5 |
op->weight = op->weight * lmt->weight / 100; |
226 |
|
|
op->value = op->value * lmt->value / 100; |
227 |
root |
1.1 |
} |
228 |
|
|
} |
229 |
|
|
} |
230 |
|
|
|
231 |
root |
1.3 |
//-GPL |
232 |
|
|
|
233 |
root |
1.2 |
void |
234 |
root |
1.15 |
reload_materials () |
235 |
root |
1.2 |
{ |
236 |
root |
1.13 |
object_thawer thawer (settings.datadir, "materials"); |
237 |
root |
1.2 |
|
238 |
|
|
if (!thawer) |
239 |
|
|
{ |
240 |
root |
1.15 |
LOG (llevError, "unable to load %s for reading\n", thawer.name); |
241 |
|
|
return; |
242 |
root |
1.2 |
} |
243 |
|
|
|
244 |
|
|
while (thawer.kw != KW_name) |
245 |
|
|
{ |
246 |
|
|
thawer.next (); |
247 |
|
|
|
248 |
|
|
if (thawer.kw == KW_EOF) |
249 |
root |
1.15 |
return; |
250 |
root |
1.2 |
} |
251 |
|
|
|
252 |
|
|
materialtype_t *mt; |
253 |
|
|
|
254 |
|
|
for (;;) |
255 |
|
|
{ |
256 |
|
|
switch (thawer.kw) |
257 |
|
|
{ |
258 |
|
|
case KW_name: |
259 |
root |
1.15 |
coroapi::cede_to_tick (); |
260 |
|
|
|
261 |
|
|
{ |
262 |
|
|
// create a new dummy material, or find the existing material |
263 |
|
|
shstr name; |
264 |
|
|
thawer.get (name); |
265 |
|
|
|
266 |
|
|
mt = find (name); |
267 |
|
|
|
268 |
|
|
if (mt) |
269 |
|
|
mt->reset (); |
270 |
|
|
else |
271 |
|
|
{ |
272 |
|
|
mt = new materialtype_t; |
273 |
|
|
mt->next = materialt; materialt = mt; |
274 |
|
|
} |
275 |
root |
1.5 |
|
276 |
root |
1.15 |
mt->name = name; |
277 |
|
|
mt->description = name; |
278 |
|
|
} |
279 |
root |
1.2 |
break; |
280 |
|
|
|
281 |
|
|
case KW_description: |
282 |
|
|
thawer.get (mt->description); |
283 |
|
|
break; |
284 |
|
|
|
285 |
|
|
case KW_material: |
286 |
|
|
thawer.get (mt->material); |
287 |
|
|
break; |
288 |
|
|
|
289 |
|
|
case KW_saves: |
290 |
|
|
{ |
291 |
|
|
const char *cp = thawer.get_str () - 1; |
292 |
|
|
|
293 |
|
|
for (int i = 0; i < NROFATTACKS; i++) |
294 |
|
|
{ |
295 |
|
|
if (!cp) |
296 |
|
|
{ |
297 |
|
|
mt->save[i] = 0; |
298 |
|
|
continue; |
299 |
|
|
} |
300 |
|
|
|
301 |
|
|
int value; |
302 |
|
|
++cp; |
303 |
|
|
sscanf (cp, "%d", &value); |
304 |
|
|
mt->save[i] = (sint8) value; |
305 |
|
|
cp = strchr (cp, ','); |
306 |
|
|
} |
307 |
|
|
} |
308 |
|
|
break; |
309 |
|
|
|
310 |
|
|
case KW_mods: |
311 |
|
|
{ |
312 |
|
|
const char *cp = thawer.get_str () - 1; |
313 |
|
|
|
314 |
|
|
for (int i = 0; i < NROFATTACKS; i++) |
315 |
|
|
{ |
316 |
|
|
if (!cp) |
317 |
|
|
{ |
318 |
|
|
mt->save[i] = 0; |
319 |
|
|
continue; |
320 |
|
|
} |
321 |
|
|
|
322 |
|
|
++cp; |
323 |
|
|
int value; |
324 |
|
|
sscanf (cp, "%d", &value); |
325 |
|
|
mt->mod[i] = (sint8) value; |
326 |
|
|
cp = strchr (cp, ','); |
327 |
|
|
} |
328 |
|
|
} |
329 |
|
|
break; |
330 |
|
|
|
331 |
|
|
case KW_chance: thawer.get (mt->chance); break; |
332 |
|
|
case KW_difficulty: // cf+ alias, not original cf |
333 |
|
|
case KW_diff: thawer.get (mt->difficulty); break; |
334 |
|
|
case KW_magic: thawer.get (mt->magic); break; |
335 |
|
|
case KW_dam: // cf+ alias, not original cf |
336 |
|
|
case KW_damage: thawer.get (mt->damage); break; |
337 |
|
|
case KW_wc: thawer.get (mt->wc); break; |
338 |
|
|
case KW_ac: thawer.get (mt->ac); break; |
339 |
|
|
case KW_sp: thawer.get (mt->sp); break; |
340 |
|
|
case KW_weight: thawer.get (mt->weight); break; |
341 |
|
|
case KW_value: thawer.get (mt->value); break; |
342 |
|
|
case KW_density: thawer.get (mt->density); break; |
343 |
|
|
|
344 |
|
|
case KW_EOF: |
345 |
root |
1.15 |
return; |
346 |
root |
1.2 |
|
347 |
|
|
default: |
348 |
root |
1.12 |
if (!thawer.parse_error ("materials file")) |
349 |
root |
1.15 |
return; |
350 |
root |
1.2 |
break; |
351 |
|
|
} |
352 |
|
|
|
353 |
|
|
thawer.next (); |
354 |
|
|
} |
355 |
|
|
} |
356 |
|
|
|