ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/material.C
(Generate patch)

Comparing deliantra/server/common/material.C (file contents):
Revision 1.1 by root, Wed Nov 4 00:02:48 2009 UTC vs.
Revision 1.3 by root, Thu Nov 5 15:43:21 2009 UTC

22 * The authors can be reached via e-mail to <support@deliantra.net> 22 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 23 */
24 24
25#include <global.h> 25#include <global.h>
26#include <material.h> 26#include <material.h>
27
28//+GPL
27 29
28/* convert materialname to materialtype_t */ 30/* convert materialname to materialtype_t */
29 31
30materialtype_t * 32materialtype_t *
31name_to_material (const shstr_cmp name) 33name_to_material (const shstr_cmp name)
135 op->value = (op->value * lmt->value) / 100; 137 op->value = (op->value * lmt->value) / 100;
136 } 138 }
137 } 139 }
138} 140}
139 141
142//TODO: make this a constructor
143static materialtype_t *
144get_empty_mat (void)
145{
146 materialtype_t *mt;
147 int i;
148
149 mt = new materialtype_t;
150
151 mt->name = shstr_unknown;
152 mt->description = 0;
153
154 for (i = 0; i < NROFATTACKS; i++)
155 {
156 mt->save[i] = 0;
157 mt->mod[i] = 0;
158 }
159
160 mt->chance = 0;
161 mt->difficulty = 0;
162 mt->magic = 0;
163 mt->damage = 0;
164 mt->wc = 0;
165 mt->ac = 0;
166 mt->sp = 0;
167 mt->weight = 100;
168 mt->value = 100;
169 mt->density = 1;
170 mt->next = 0;
171
172 return mt;
173}
174
175//-GPL
176
177void
178load_materials (void)
179{
180 char filename[MAX_BUF];
181
182 sprintf (filename, "%s/materials", settings.datadir);
183 LOG (llevDebug, "Reading material type data from %s...\n", filename);
184
185 //TODO: somehow free old materials, or update them in-place
186 materialt = 0;
187
188 object_thawer thawer (filename);
189
190 if (!thawer)
191 {
192 LOG (llevError, "Cannot open %s for reading\n", filename);
193 goto done;
194 }
195
196 while (thawer.kw != KW_name)
197 {
198 thawer.next ();
199
200 if (thawer.kw == KW_EOF)
201 goto done;
202 }
203
204 materialtype_t *mt;
205
206 for (;;)
207 {
208 switch (thawer.kw)
209 {
210 case KW_name:
211 mt = get_empty_mat ();
212 mt->next = materialt;
213 materialt = mt;
214
215 thawer.get (mt->name);
216 mt->description = mt->name;
217 break;
218
219 case KW_description:
220 thawer.get (mt->description);
221 break;
222
223 case KW_material:
224 thawer.get (mt->material);
225 break;
226
227 case KW_saves:
228 {
229 const char *cp = thawer.get_str () - 1;
230
231 for (int i = 0; i < NROFATTACKS; i++)
232 {
233 if (!cp)
234 {
235 mt->save[i] = 0;
236 continue;
237 }
238
239 int value;
240 ++cp;
241 sscanf (cp, "%d", &value);
242 mt->save[i] = (sint8) value;
243 cp = strchr (cp, ',');
244 }
245 }
246 break;
247
248 case KW_mods:
249 {
250 const char *cp = thawer.get_str () - 1;
251
252 for (int i = 0; i < NROFATTACKS; i++)
253 {
254 if (!cp)
255 {
256 mt->save[i] = 0;
257 continue;
258 }
259
260 ++cp;
261 int value;
262 sscanf (cp, "%d", &value);
263 mt->mod[i] = (sint8) value;
264 cp = strchr (cp, ',');
265 }
266 }
267 break;
268
269 case KW_chance: thawer.get (mt->chance); break;
270 case KW_difficulty: // cf+ alias, not original cf
271 case KW_diff: thawer.get (mt->difficulty); break;
272 case KW_magic: thawer.get (mt->magic); break;
273 case KW_dam: // cf+ alias, not original cf
274 case KW_damage: thawer.get (mt->damage); break;
275 case KW_wc: thawer.get (mt->wc); break;
276 case KW_ac: thawer.get (mt->ac); break;
277 case KW_sp: thawer.get (mt->sp); break;
278 case KW_weight: thawer.get (mt->weight); break;
279 case KW_value: thawer.get (mt->value); break;
280 case KW_density: thawer.get (mt->density); break;
281
282 case KW_EOF:
283 goto done;
284
285 default:
286 if (!thawer.parse_error ("materials file", "materials"))
287 goto done;
288 break;
289 }
290
291 thawer.next ();
292 }
293
294done:
295 if (!materialt)
296 materialt = get_empty_mat ();
297
298 LOG (llevDebug, "Done.\n");
299}
300

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines