1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
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 |
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 |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * option) any later version. |
11 | * option) any later version. |
… | |
… | |
59 | description = shstr_unknown_material_description; |
59 | description = shstr_unknown_material_description; |
60 | material = 0; |
60 | material = 0; |
61 | |
61 | |
62 | for (int i = 0; i < NROFATTACKS; i++) |
62 | for (int i = 0; i < NROFATTACKS; i++) |
63 | { |
63 | { |
64 | save [i] = 10; |
64 | save [i] = 0; |
65 | mod [i] = 9; |
65 | mod [i] = 0; |
66 | } |
66 | } |
67 | |
67 | |
68 | chance = 0; |
68 | chance = 0; |
69 | difficulty = 0; |
69 | difficulty = 0; |
70 | magic = 0; |
70 | magic = 0; |
… | |
… | |
89 | |
89 | |
90 | // create a new material of the given name |
90 | // create a new material of the given name |
91 | materialtype_t *mt = new materialtype_t; |
91 | materialtype_t *mt = new materialtype_t; |
92 | mt->name = name; |
92 | mt->name = name; |
93 | |
93 | |
94 | mt->next = materialt; |
94 | // make it susceptible to attacks |
95 | materialt = mt; |
95 | for (int i = 0; i < NROFATTACKS; i++) |
|
|
96 | { |
|
|
97 | mt->save [i] = 10; |
|
|
98 | mt->mod [i] = 9; |
|
|
99 | } |
|
|
100 | |
|
|
101 | mt->next = materialt; materialt = mt; |
96 | |
102 | |
97 | return mt; |
103 | return mt; |
98 | } |
104 | } |
99 | |
105 | |
100 | /* when doing transmutation of objects, we have to recheck the resistances, |
106 | /* when doing transmutation of objects, we have to recheck the resistances, |
101 | * as some that did not apply previously, may apply now. |
107 | * as some that did not apply previously, may apply now. |
102 | */ |
108 | */ |
103 | void |
109 | void |
104 | transmute_materialname (object *op, const object *change) |
110 | transmute_materialname (object *op, const object *change) |
105 | { |
111 | { |
106 | int j; |
112 | if (!op->is_armor ()) |
|
|
113 | return; |
|
|
114 | |
|
|
115 | if (op->material == MATERIAL_NULL) |
|
|
116 | return; |
107 | |
117 | |
108 | if (op->material != change->material) |
118 | if (op->material != change->material) |
109 | return; |
119 | return; |
110 | |
120 | |
111 | if (!op->is_armor ()) |
|
|
112 | return; |
|
|
113 | |
|
|
114 | materialtype_t *mt = op->material; |
121 | materialtype_t *mt = op->material; |
115 | |
122 | |
116 | for (j = 0; j < NROFATTACKS; j++) |
123 | for (int j = 0; j < NROFATTACKS; j++) |
117 | if (op->resist[j] == 0 && change->resist[j] != 0) |
124 | if (op->resist[j] == 0 && change->resist[j] != 0) |
118 | { |
125 | { |
119 | op->resist[j] += mt->mod[j]; |
126 | op->resist[j] += mt->mod[j]; |
120 | |
127 | |
121 | if (op->resist[j] > 100) op->resist[j] = 100; |
128 | if (op->resist[j] > 100) op->resist[j] = 100; |
… | |
… | |
125 | |
132 | |
126 | /* set the materialname and type for an item */ |
133 | /* set the materialname and type for an item */ |
127 | void |
134 | void |
128 | select_material (object *op, int difficulty) |
135 | select_material (object *op, int difficulty) |
129 | { |
136 | { |
130 | if (op->material != &material_null || !op->materials) |
137 | if (op->material != MATERIAL_NULL || !op->materials) |
131 | return; |
138 | return; |
132 | |
139 | |
133 | materialtype_t *lmt = 0; |
140 | materialtype_t *lmt = 0; |
134 | |
141 | |
135 | //TODL: dead code? |
142 | //TODL: dead code? |
… | |
… | |
183 | } |
190 | } |
184 | |
191 | |
185 | //-GPL |
192 | //-GPL |
186 | |
193 | |
187 | void |
194 | void |
188 | load_materials (void) |
195 | load_materials () |
189 | { |
196 | { |
190 | char filename[MAX_BUF]; |
|
|
191 | |
|
|
192 | sprintf (filename, "%s/materials", settings.datadir); |
|
|
193 | LOG (llevDebug, "Reading material type data from %s...\n", filename); |
|
|
194 | |
|
|
195 | //TODO: somehow free old materials, or update them in-place |
197 | //TODO: somehow free old materials, or update them in-place |
196 | material_null.next = 0; |
198 | // currently we effectively leak them. |
197 | materialt = &material_null; |
199 | material_null.next = 0; materialt = &material_null; |
198 | |
200 | |
199 | object_thawer thawer (filename); |
201 | object_thawer thawer (settings.datadir, "materials"); |
200 | |
202 | |
201 | if (!thawer) |
203 | if (!thawer) |
202 | { |
204 | { |
203 | LOG (llevError, "Cannot open %s for reading\n", filename); |
205 | LOG (llevError, "Cannot open %s for reading\n", thawer.name); |
204 | goto done; |
206 | goto done; |
205 | } |
207 | } |
206 | |
208 | |
207 | while (thawer.kw != KW_name) |
209 | while (thawer.kw != KW_name) |
208 | { |
210 | { |
… | |
… | |
221 | case KW_name: |
223 | case KW_name: |
222 | mt = new materialtype_t; |
224 | mt = new materialtype_t; |
223 | thawer.get (mt->name); |
225 | thawer.get (mt->name); |
224 | mt->description = mt->name; |
226 | mt->description = mt->name; |
225 | |
227 | |
226 | mt->next = materialt; |
228 | mt->next = materialt; materialt = mt; |
227 | materialt = mt; |
|
|
228 | break; |
229 | break; |
229 | |
230 | |
230 | case KW_description: |
231 | case KW_description: |
231 | thawer.get (mt->description); |
232 | thawer.get (mt->description); |
232 | break; |
233 | break; |
… | |
… | |
292 | |
293 | |
293 | case KW_EOF: |
294 | case KW_EOF: |
294 | goto done; |
295 | goto done; |
295 | |
296 | |
296 | default: |
297 | default: |
297 | if (!thawer.parse_error ("materials file", "materials")) |
298 | if (!thawer.parse_error ("materials file")) |
298 | goto done; |
299 | goto done; |
299 | break; |
300 | break; |
300 | } |
301 | } |
301 | |
302 | |
302 | thawer.next (); |
303 | thawer.next (); |
303 | } |
304 | } |
304 | |
305 | |
305 | done: |
306 | done: |
306 | if (!materialt) |
|
|
307 | materialt = new materialtype_t; |
|
|
308 | |
|
|
309 | LOG (llevDebug, "Done.\n"); |
307 | LOG (llevDebug, "Done.\n"); |
310 | } |
308 | } |
311 | |
309 | |