… | |
… | |
75 | weight = 100; |
75 | weight = 100; |
76 | value = 100; |
76 | value = 100; |
77 | density = 1000; |
77 | density = 1000; |
78 | } |
78 | } |
79 | |
79 | |
|
|
80 | // create a new material of the given name |
|
|
81 | static materialtype_t * |
|
|
82 | dummy_material (shstr_tmp name) |
|
|
83 | { |
|
|
84 | materialtype_t *mt = new materialtype_t; |
|
|
85 | mt->name = name; |
|
|
86 | |
|
|
87 | // make it susceptible to attacks |
|
|
88 | for (int i = 0; i < NROFATTACKS; i++) |
|
|
89 | { |
|
|
90 | mt->save [i] = 10; |
|
|
91 | mt->mod [i] = 9; |
|
|
92 | } |
|
|
93 | |
|
|
94 | mt->next = materialt; materialt = mt; |
|
|
95 | |
|
|
96 | return mt; |
|
|
97 | } |
|
|
98 | |
80 | /* convert materialname to materialtype_t */ |
99 | /* convert materialname to materialtype_t */ |
81 | materialtype_t * |
100 | materialtype_t * |
82 | name_to_material (const shstr_tmp name) |
101 | name_to_material (const shstr_tmp name) |
83 | { |
102 | { |
84 | for (materialtype_t *mt = materialt; mt; mt = mt->next) |
103 | for (materialtype_t *mt = materialt; mt; mt = mt->next) |
85 | if (name == mt->name) |
104 | if (name == mt->name) |
86 | return mt; |
105 | return mt; |
87 | |
106 | |
88 | LOG (llevError, "name_to_material called with nonexistent material '%s'\n", &name); |
107 | LOG (llevError, "name_to_material called with nonexistent material '%s'\n", &name); |
89 | |
108 | |
90 | // create a new material of the given name |
109 | return dummy_material (name); |
91 | materialtype_t *mt = new materialtype_t; |
110 | } |
92 | mt->name = name; |
|
|
93 | |
111 | |
94 | // make it susceptible to attacks |
112 | void |
95 | for (int i = 0; i < NROFATTACKS; i++) |
113 | object_thawer::get (materialtype_t *&m) const |
|
|
114 | { |
|
|
115 | shstr name; |
|
|
116 | get (name); |
|
|
117 | |
|
|
118 | for (materialtype_t *mt = materialt; mt; mt = mt->next) |
|
|
119 | if (name == mt->name) |
96 | { |
120 | { |
97 | mt->save [i] = 10; |
121 | m = mt; |
98 | mt->mod [i] = 9; |
122 | return; |
99 | } |
123 | } |
100 | |
124 | |
101 | mt->next = materialt; materialt = mt; |
125 | parse_error (format ("material called %s requested, but not found, creating dummy material.\n", &name)); |
102 | |
126 | |
103 | return mt; |
127 | m = dummy_material (name); |
104 | } |
128 | } |
105 | |
129 | |
106 | /* when doing transmutation of objects, we have to recheck the resistances, |
130 | /* when doing transmutation of objects, we have to recheck the resistances, |
107 | * as some that did not apply previously, may apply now. |
131 | * as some that did not apply previously, may apply now. |
108 | */ |
132 | */ |
… | |
… | |
192 | //-GPL |
216 | //-GPL |
193 | |
217 | |
194 | void |
218 | void |
195 | load_materials () |
219 | load_materials () |
196 | { |
220 | { |
197 | char filename[MAX_BUF]; |
|
|
198 | |
|
|
199 | sprintf (filename, "%s/materials", settings.datadir); |
|
|
200 | LOG (llevDebug, "Reading material type data from %s...\n", filename); |
|
|
201 | |
|
|
202 | //TODO: somehow free old materials, or update them in-place |
221 | //TODO: somehow free old materials, or update them in-place |
|
|
222 | // currently we effectively leak them. |
203 | material_null.next = 0; materialt = &material_null; |
223 | material_null.next = 0; materialt = &material_null; |
204 | |
224 | |
205 | object_thawer thawer (filename); |
225 | object_thawer thawer (settings.datadir, "materials"); |
206 | |
226 | |
207 | if (!thawer) |
227 | if (!thawer) |
208 | { |
228 | { |
209 | LOG (llevError, "Cannot open %s for reading\n", filename); |
229 | LOG (llevError, "Cannot open %s for reading\n", thawer.name); |
210 | goto done; |
230 | goto done; |
211 | } |
231 | } |
212 | |
232 | |
213 | while (thawer.kw != KW_name) |
233 | while (thawer.kw != KW_name) |
214 | { |
234 | { |
… | |
… | |
297 | |
317 | |
298 | case KW_EOF: |
318 | case KW_EOF: |
299 | goto done; |
319 | goto done; |
300 | |
320 | |
301 | default: |
321 | default: |
302 | if (!thawer.parse_error ("materials file", "materials")) |
322 | if (!thawer.parse_error ("materials file")) |
303 | goto done; |
323 | goto done; |
304 | break; |
324 | break; |
305 | } |
325 | } |
306 | |
326 | |
307 | thawer.next (); |
327 | thawer.next (); |