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.5 by root, Tue Nov 10 04:38:45 2009 UTC vs.
Revision 1.14 by root, Thu Apr 29 12:24:04 2010 UTC

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;
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
81static materialtype_t *
82dummy_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 */
81materialtype_t * 100materialtype_t *
82name_to_material (const shstr_tmp name) 101name_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 mt->next = materialt; 112void
95 materialt = mt; 113object_thawer::get (materialtype_t *&m) const
114{
115 shstr name;
116 get (name);
96 117
97 return mt; 118 for (materialtype_t *mt = materialt; mt; mt = mt->next)
119 if (name == mt->name)
120 {
121 m = mt;
122 return;
123 }
124
125 parse_error (format ("material called %s requested, but not found, creating dummy material.\n", &name));
126
127 m = dummy_material (name);
98} 128}
99 129
100/* when doing transmutation of objects, we have to recheck the resistances, 130/* when doing transmutation of objects, we have to recheck the resistances,
101 * as some that did not apply previously, may apply now. 131 * as some that did not apply previously, may apply now.
102 */ 132 */
103void 133void
104transmute_materialname (object *op, const object *change) 134transmute_materialname (object *op, const object *change)
105{ 135{
106 int j; 136 if (!op->is_armor ())
137 return;
138
139 if (op->material == MATERIAL_NULL)
140 return;
107 141
108 if (op->material != change->material) 142 if (op->material != change->material)
109 return; 143 return;
110 144
111 if (!op->is_armor ())
112 return;
113
114 materialtype_t *mt = op->material; 145 materialtype_t *mt = op->material;
115 146
116 for (j = 0; j < NROFATTACKS; j++) 147 for (int j = 0; j < NROFATTACKS; j++)
117 if (op->resist[j] == 0 && change->resist[j] != 0) 148 if (op->resist[j] == 0 && change->resist[j] != 0)
118 { 149 {
119 op->resist[j] += mt->mod[j]; 150 op->resist[j] += mt->mod[j];
120 151
121 if (op->resist[j] > 100) op->resist[j] = 100; 152 if (op->resist[j] > 100) op->resist[j] = 100;
125 156
126/* set the materialname and type for an item */ 157/* set the materialname and type for an item */
127void 158void
128select_material (object *op, int difficulty) 159select_material (object *op, int difficulty)
129{ 160{
130 if (op->material != &material_null || !op->materials) 161 if (op->material != MATERIAL_NULL || !op->materials)
131 return; 162 return;
132 163
133 materialtype_t *lmt = 0; 164 materialtype_t *lmt = 0;
134 165
135 //TODL: dead code? 166 //TODL: dead code?
183} 214}
184 215
185//-GPL 216//-GPL
186 217
187void 218void
188load_materials (void) 219load_materials ()
189{ 220{
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 221 //TODO: somehow free old materials, or update them in-place
196 material_null.next = 0; 222 // currently we effectively leak them.
197 materialt = &material_null; 223 material_null.next = 0; materialt = &material_null;
198 224
199 object_thawer thawer (filename); 225 object_thawer thawer (settings.datadir, "materials");
200 226
201 if (!thawer) 227 if (!thawer)
202 { 228 {
203 LOG (llevError, "Cannot open %s for reading\n", filename); 229 LOG (llevError, "Cannot open %s for reading\n", thawer.name);
204 goto done; 230 goto done;
205 } 231 }
206 232
207 while (thawer.kw != KW_name) 233 while (thawer.kw != KW_name)
208 { 234 {
221 case KW_name: 247 case KW_name:
222 mt = new materialtype_t; 248 mt = new materialtype_t;
223 thawer.get (mt->name); 249 thawer.get (mt->name);
224 mt->description = mt->name; 250 mt->description = mt->name;
225 251
226 mt->next = materialt; 252 mt->next = materialt; materialt = mt;
227 materialt = mt;
228 break; 253 break;
229 254
230 case KW_description: 255 case KW_description:
231 thawer.get (mt->description); 256 thawer.get (mt->description);
232 break; 257 break;
292 317
293 case KW_EOF: 318 case KW_EOF:
294 goto done; 319 goto done;
295 320
296 default: 321 default:
297 if (!thawer.parse_error ("materials file", "materials")) 322 if (!thawer.parse_error ("materials file"))
298 goto done; 323 goto done;
299 break; 324 break;
300 } 325 }
301 326
302 thawer.next (); 327 thawer.next ();
303 } 328 }
304 329
305done: 330done:
306 if (!materialt)
307 materialt = new materialtype_t;
308
309 LOG (llevDebug, "Done.\n"); 331 LOG (llevDebug, "Done.\n");
310} 332}
311 333

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines