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 (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
8 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify |
9 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * it under the terms of the GNU General Public License as published by |
10 | * the terms of the Affero GNU General Public License as published by the |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * (at your option) any later version. |
12 | * option) any later version. |
12 | * |
13 | * |
13 | * This program is distributed in the hope that it will be useful, |
14 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
17 | * GNU General Public License for more details. |
17 | * |
18 | * |
18 | * You should have received a copy of the GNU General Public License |
19 | * You should have received a copy of the Affero GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | * and the GNU General Public License along with this program. If not, see |
|
|
21 | * <http://www.gnu.org/licenses/>. |
20 | * |
22 | * |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
24 | */ |
23 | |
25 | |
24 | #include <global.h> |
26 | #include <global.h> |
25 | #include <material.h> |
27 | #include <material.h> |
26 | #include <loader.h> |
|
|
27 | #include <sproto.h> |
28 | #include <sproto.h> |
28 | |
|
|
29 | //TODO: make this a constructor |
|
|
30 | static materialtype_t * |
|
|
31 | get_empty_mat (void) |
|
|
32 | { |
|
|
33 | materialtype_t *mt; |
|
|
34 | int i; |
|
|
35 | |
|
|
36 | mt = new materialtype_t; |
|
|
37 | |
|
|
38 | mt->name = shstr_unknown; |
|
|
39 | mt->description = 0; |
|
|
40 | |
|
|
41 | for (i = 0; i < NROFATTACKS; i++) |
|
|
42 | { |
|
|
43 | mt->save[i] = 0; |
|
|
44 | mt->mod[i] = 0; |
|
|
45 | } |
|
|
46 | |
|
|
47 | mt->chance = 0; |
|
|
48 | mt->difficulty = 0; |
|
|
49 | mt->magic = 0; |
|
|
50 | mt->damage = 0; |
|
|
51 | mt->wc = 0; |
|
|
52 | mt->ac = 0; |
|
|
53 | mt->sp = 0; |
|
|
54 | mt->weight = 100; |
|
|
55 | mt->value = 100; |
|
|
56 | mt->density = 1; |
|
|
57 | mt->next = 0; |
|
|
58 | |
|
|
59 | return mt; |
|
|
60 | } |
|
|
61 | |
|
|
62 | void |
|
|
63 | load_materials (void) |
|
|
64 | { |
|
|
65 | char filename[MAX_BUF]; |
|
|
66 | |
|
|
67 | sprintf (filename, "%s/materials", settings.datadir); |
|
|
68 | LOG (llevDebug, "Reading material type data from %s...\n", filename); |
|
|
69 | |
|
|
70 | //TODO: somehow free old materials, or update them in-place |
|
|
71 | materialt = 0; |
|
|
72 | |
|
|
73 | object_thawer thawer (filename); |
|
|
74 | |
|
|
75 | if (!thawer) |
|
|
76 | { |
|
|
77 | LOG (llevError, "Cannot open %s for reading\n", filename); |
|
|
78 | goto done; |
|
|
79 | } |
|
|
80 | |
|
|
81 | while (thawer.kw != KW_name) |
|
|
82 | { |
|
|
83 | thawer.next (); |
|
|
84 | |
|
|
85 | if (thawer.kw == KW_EOF) |
|
|
86 | goto done; |
|
|
87 | } |
|
|
88 | |
|
|
89 | materialtype_t *mt; |
|
|
90 | |
|
|
91 | for (;;) |
|
|
92 | { |
|
|
93 | switch (thawer.kw) |
|
|
94 | { |
|
|
95 | case KW_name: |
|
|
96 | mt = get_empty_mat (); |
|
|
97 | mt->next = materialt; |
|
|
98 | materialt = mt; |
|
|
99 | |
|
|
100 | thawer.get (mt->name); |
|
|
101 | mt->description = mt->name; |
|
|
102 | break; |
|
|
103 | |
|
|
104 | case KW_description: |
|
|
105 | thawer.get (mt->description); |
|
|
106 | break; |
|
|
107 | |
|
|
108 | case KW_material: |
|
|
109 | thawer.get (mt->material); |
|
|
110 | break; |
|
|
111 | |
|
|
112 | case KW_saves: |
|
|
113 | { |
|
|
114 | const char *cp = thawer.get_str () - 1; |
|
|
115 | |
|
|
116 | for (int i = 0; i < NROFATTACKS; i++) |
|
|
117 | { |
|
|
118 | if (!cp) |
|
|
119 | { |
|
|
120 | mt->save[i] = 0; |
|
|
121 | continue; |
|
|
122 | } |
|
|
123 | |
|
|
124 | int value; |
|
|
125 | ++cp; |
|
|
126 | sscanf (cp, "%d", &value); |
|
|
127 | mt->save[i] = (sint8) value; |
|
|
128 | cp = strchr (cp, ','); |
|
|
129 | } |
|
|
130 | } |
|
|
131 | break; |
|
|
132 | |
|
|
133 | case KW_mods: |
|
|
134 | { |
|
|
135 | const char *cp = thawer.get_str () - 1; |
|
|
136 | |
|
|
137 | for (int i = 0; i < NROFATTACKS; i++) |
|
|
138 | { |
|
|
139 | if (!cp) |
|
|
140 | { |
|
|
141 | mt->save[i] = 0; |
|
|
142 | continue; |
|
|
143 | } |
|
|
144 | |
|
|
145 | ++cp; |
|
|
146 | int value; |
|
|
147 | sscanf (cp, "%d", &value); |
|
|
148 | mt->mod[i] = (sint8) value; |
|
|
149 | cp = strchr (cp, ','); |
|
|
150 | } |
|
|
151 | } |
|
|
152 | break; |
|
|
153 | |
|
|
154 | case KW_chance: thawer.get (mt->chance); break; |
|
|
155 | case KW_difficulty: // cf+ alias, not original cf |
|
|
156 | case KW_diff: thawer.get (mt->difficulty); break; |
|
|
157 | case KW_magic: thawer.get (mt->magic); break; |
|
|
158 | case KW_dam: // cf+ alias, not original cf |
|
|
159 | case KW_damage: thawer.get (mt->damage); break; |
|
|
160 | case KW_wc: thawer.get (mt->wc); break; |
|
|
161 | case KW_ac: thawer.get (mt->ac); break; |
|
|
162 | case KW_sp: thawer.get (mt->sp); break; |
|
|
163 | case KW_weight: thawer.get (mt->weight); break; |
|
|
164 | case KW_value: thawer.get (mt->value); break; |
|
|
165 | case KW_density: thawer.get (mt->density); break; |
|
|
166 | |
|
|
167 | case KW_EOF: |
|
|
168 | goto done; |
|
|
169 | |
|
|
170 | default: |
|
|
171 | if (!thawer.parse_error ("materials file", "materials")) |
|
|
172 | goto done; |
|
|
173 | break; |
|
|
174 | } |
|
|
175 | |
|
|
176 | thawer.next (); |
|
|
177 | } |
|
|
178 | |
|
|
179 | done: |
|
|
180 | if (!materialt) |
|
|
181 | materialt = get_empty_mat (); |
|
|
182 | |
|
|
183 | LOG (llevDebug, "Done.\n"); |
|
|
184 | } |
|
|
185 | |
29 | |
186 | /* This loads the settings file. There could be debate whether this should |
30 | /* This loads the settings file. There could be debate whether this should |
187 | * be here or in the common directory - but since only the server needs this |
31 | * be here or in the common directory - but since only the server needs this |
188 | * information, having it here probably makes more sense. |
32 | * information, having it here probably makes more sense. |
189 | */ |
33 | */ |
190 | void |
34 | void |
191 | load_settings (void) |
35 | load_settings () |
192 | { |
36 | { |
193 | char buf[MAX_BUF], *cp; |
37 | object_thawer thawer (settings.confdir, "settings"); |
194 | int has_val, comp; |
|
|
195 | FILE *fp; |
|
|
196 | |
38 | |
197 | sprintf (buf, "%s/settings", settings.confdir); |
39 | if (!thawer) |
198 | |
|
|
199 | /* We don't require a settings file at current time, but down the road, |
|
|
200 | * there will probably be so many values that not having a settings file |
|
|
201 | * will not be a good thing. |
|
|
202 | */ |
|
|
203 | if (!(fp = open_and_uncompress (buf, 0, &comp))) |
|
|
204 | { |
40 | { |
205 | LOG (llevError, "Error: No settings file found\n"); |
41 | LOG (llevError, "Error: No settings file found\n"); |
206 | exit (1); |
42 | exit (1); |
207 | } |
43 | } |
208 | |
44 | |
209 | while (fgets (buf, MAX_BUF - 1, fp) != NULL) |
45 | while (thawer.kw) |
210 | { |
46 | { |
211 | if (buf[0] == '#') |
47 | const char *buf = thawer.kw_str; |
212 | continue; |
48 | const char *cp = thawer.value_nn; |
213 | /* eliminate newline */ |
|
|
214 | if ((cp = strrchr (buf, '\n')) != NULL) |
|
|
215 | *cp = '\0'; |
|
|
216 | |
49 | |
217 | /* Skip over empty lines */ |
|
|
218 | if (buf[0] == 0) |
|
|
219 | continue; |
|
|
220 | |
|
|
221 | /* Skip all the spaces and set them to nulls. If not space, |
|
|
222 | * set cp to "" to make strcpy's and the like easier down below. |
|
|
223 | */ |
|
|
224 | if ((cp = strchr (buf, ' ')) != NULL) |
|
|
225 | { |
|
|
226 | while (*cp == ' ') |
|
|
227 | *cp++ = 0; |
|
|
228 | has_val = 1; |
|
|
229 | } |
|
|
230 | else |
|
|
231 | { |
|
|
232 | cp = (char *)""; |
|
|
233 | has_val = 0; |
|
|
234 | } |
|
|
235 | |
|
|
236 | if (!strcasecmp (buf, "motd")) |
|
|
237 | { |
|
|
238 | if (has_val) |
|
|
239 | strcpy (settings.motd, cp); |
|
|
240 | else |
|
|
241 | LOG (llevError, "load_settings: motd must have a value.\n"); |
|
|
242 | } |
|
|
243 | else if (!strcasecmp (buf, "dm_mail")) |
|
|
244 | { |
|
|
245 | if (has_val) |
|
|
246 | strcpy (settings.dm_mail, cp); |
|
|
247 | else |
|
|
248 | LOG (llevError, "load_settings: dm_mail must have a value.\n"); |
|
|
249 | } |
|
|
250 | else if (!strcasecmp (buf, "worldmapstartx")) |
|
|
251 | { |
|
|
252 | int size = atoi (cp); |
|
|
253 | |
|
|
254 | if (size < 0) |
|
|
255 | LOG (llevError, "load_settings: worldmapstartx must be at least " "0, %d is invalid\n", size); |
|
|
256 | else |
|
|
257 | settings.worldmapstartx = size; |
|
|
258 | } |
|
|
259 | else if (!strcasecmp (buf, "worldmapstarty")) |
|
|
260 | { |
|
|
261 | int size = atoi (cp); |
|
|
262 | |
|
|
263 | if (size < 0) |
|
|
264 | LOG (llevError, "load_settings: worldmapstarty must be at least " "0, %d is invalid\n", size); |
|
|
265 | else |
|
|
266 | settings.worldmapstarty = size; |
|
|
267 | } |
|
|
268 | else if (!strcasecmp (buf, "worldmaptilesx")) |
|
|
269 | { |
|
|
270 | int size = atoi (cp); |
|
|
271 | |
|
|
272 | if (size < 1) |
|
|
273 | LOG (llevError, "load_settings: worldmaptilesx must be greater " "than 1, %d is invalid\n", size); |
|
|
274 | else |
|
|
275 | settings.worldmaptilesx = size; |
|
|
276 | } |
|
|
277 | else if (!strcasecmp (buf, "worldmaptilesy")) |
|
|
278 | { |
|
|
279 | int size = atoi (cp); |
|
|
280 | |
|
|
281 | if (size < 1) |
|
|
282 | LOG (llevError, "load_settings: worldmaptilesy must be greater " "than 1, %d is invalid\n", size); |
|
|
283 | else |
|
|
284 | settings.worldmaptilesy = size; |
|
|
285 | } |
|
|
286 | else if (!strcasecmp (buf, "worldmaptilesizex")) |
|
|
287 | { |
|
|
288 | int size = atoi (cp); |
|
|
289 | |
|
|
290 | if (size < 1) |
|
|
291 | LOG (llevError, "load_settings: worldmaptilesizex must be " "greater than 1, %d is invalid\n", size); |
|
|
292 | else |
|
|
293 | settings.worldmaptilesizex = size; |
|
|
294 | } |
|
|
295 | else if (!strcasecmp (buf, "worldmaptilesizey")) |
|
|
296 | { |
|
|
297 | int size = atoi (cp); |
|
|
298 | |
|
|
299 | if (size < 1) |
|
|
300 | LOG (llevError, "load_settings: worldmaptilesizey must be " "greater than 1, %d is invalid\n", size); |
|
|
301 | else |
|
|
302 | settings.worldmaptilesizey = size; |
|
|
303 | } |
|
|
304 | else if (!strcasecmp (buf, "dynamiclevel")) |
|
|
305 | { |
|
|
306 | int lev = atoi (cp); |
|
|
307 | |
|
|
308 | if (lev < 0) |
|
|
309 | LOG (llevError, "load_settings: dynamiclevel must be " "at least 0, %d is invalid\n", lev); |
|
|
310 | else |
|
|
311 | settings.dynamiclevel = lev; |
|
|
312 | } |
|
|
313 | else if (!strcasecmp (buf, "fastclock")) |
|
|
314 | { |
|
|
315 | int lev = atoi (cp); |
|
|
316 | |
|
|
317 | if (lev < 0) |
|
|
318 | LOG (llevError, "load_settings: fastclock must be at least 0" ", %d is invalid\n", lev); |
|
|
319 | else |
|
|
320 | settings.fastclock = lev; |
|
|
321 | } |
|
|
322 | else if (!strcasecmp (buf, "not_permadeth")) |
50 | if (!strcmp (buf, "not_permadeth")) |
323 | { |
51 | { |
324 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
52 | if (!strcmp (cp, "on") || !strcmp (cp, "true")) |
325 | { |
53 | { |
326 | settings.not_permadeth = TRUE; |
54 | settings.not_permadeth = TRUE; |
327 | } |
55 | } |
328 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
56 | else if (!strcmp (cp, "off") || !strcmp (cp, "false")) |
329 | { |
57 | { |
330 | settings.not_permadeth = FALSE; |
58 | settings.not_permadeth = FALSE; |
331 | } |
59 | } |
332 | else |
60 | else |
333 | { |
61 | { |
334 | LOG (llevError, "load_settings: Unknown value for not_permadeth" ": %s\n", cp); |
62 | LOG (llevError, "load_settings: Unknown value for not_permadeth" ": %s\n", cp); |
335 | } |
63 | } |
336 | } |
64 | } |
337 | else if (!strcasecmp (buf, "resurrection")) |
65 | else if (!strcmp (buf, "resurrection")) |
338 | { |
66 | { |
339 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
67 | if (!strcmp (cp, "on") || !strcmp (cp, "true")) |
340 | { |
68 | { |
341 | settings.resurrection = TRUE; |
69 | settings.resurrection = TRUE; |
342 | } |
70 | } |
343 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
71 | else if (!strcmp (cp, "off") || !strcmp (cp, "false")) |
344 | { |
72 | { |
345 | settings.resurrection = FALSE; |
73 | settings.resurrection = FALSE; |
346 | } |
74 | } |
347 | else |
75 | else |
348 | { |
76 | { |
349 | LOG (llevError, "load_settings: Unknown value for resurrection" ": %s\n", cp); |
77 | LOG (llevError, "load_settings: Unknown value for resurrection" ": %s\n", cp); |
350 | } |
78 | } |
351 | } |
79 | } |
352 | else if (!strcasecmp (buf, "set_title")) |
80 | else if (!strcmp (buf, "set_title")) |
353 | { |
81 | { |
354 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
82 | if (!strcmp (cp, "on") || !strcmp (cp, "true")) |
355 | { |
83 | { |
356 | settings.set_title = TRUE; |
84 | settings.set_title = TRUE; |
357 | } |
85 | } |
358 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
86 | else if (!strcmp (cp, "off") || !strcmp (cp, "false")) |
359 | { |
87 | { |
360 | settings.set_title = FALSE; |
88 | settings.set_title = FALSE; |
361 | } |
89 | } |
362 | else |
90 | else |
363 | { |
91 | { |
364 | LOG (llevError, "load_settings: Unknown value for set_title" ": %s\n", cp); |
92 | LOG (llevError, "load_settings: Unknown value for set_title" ": %s\n", cp); |
365 | } |
93 | } |
366 | } |
94 | } |
367 | else if (!strcasecmp (buf, "search_items")) |
95 | else if (!strcmp (buf, "search_items")) |
368 | { |
96 | { |
369 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
97 | if (!strcmp (cp, "on") || !strcmp (cp, "true")) |
370 | { |
98 | { |
371 | settings.search_items = TRUE; |
99 | settings.search_items = TRUE; |
372 | } |
100 | } |
373 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
101 | else if (!strcmp (cp, "off") || !strcmp (cp, "false")) |
374 | { |
102 | { |
375 | settings.search_items = FALSE; |
103 | settings.search_items = FALSE; |
376 | } |
104 | } |
377 | else |
105 | else |
378 | { |
106 | { |
379 | LOG (llevError, "load_settings: Unknown value for search_items" ": %s\n", cp); |
107 | LOG (llevError, "load_settings: Unknown value for search_items" ": %s\n", cp); |
380 | } |
108 | } |
381 | } |
109 | } |
382 | else if (!strcasecmp (buf, "spell_encumbrance")) |
110 | else if (!strcmp (buf, "spell_encumbrance")) |
383 | { |
111 | { |
384 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
112 | if (!strcmp (cp, "on") || !strcmp (cp, "true")) |
385 | { |
113 | { |
386 | settings.spell_encumbrance = TRUE; |
114 | settings.spell_encumbrance = TRUE; |
387 | } |
115 | } |
388 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
116 | else if (!strcmp (cp, "off") || !strcmp (cp, "false")) |
389 | { |
117 | { |
390 | settings.spell_encumbrance = FALSE; |
118 | settings.spell_encumbrance = FALSE; |
391 | } |
119 | } |
392 | else |
120 | else |
393 | { |
121 | { |
394 | LOG (llevError, "load_settings: Unknown value for " "spell_encumbrance: %s\n", cp); |
122 | LOG (llevError, "load_settings: Unknown value for " "spell_encumbrance: %s\n", cp); |
395 | } |
123 | } |
396 | } |
124 | } |
397 | else if (!strcasecmp (buf, "spell_failure_effects")) |
125 | else if (!strcmp (buf, "spell_failure_effects")) |
398 | { |
126 | { |
399 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
127 | if (!strcmp (cp, "on") || !strcmp (cp, "true")) |
400 | { |
128 | { |
401 | settings.spell_failure_effects = TRUE; |
129 | settings.spell_failure_effects = TRUE; |
402 | } |
130 | } |
403 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
131 | else if (!strcmp (cp, "off") || !strcmp (cp, "false")) |
404 | { |
132 | { |
405 | settings.spell_failure_effects = FALSE; |
133 | settings.spell_failure_effects = FALSE; |
406 | } |
134 | } |
407 | else |
135 | else |
408 | { |
136 | { |
409 | LOG (llevError, "load_settings: Unknown value for " "spell_failure_effects: %s\n", cp); |
137 | LOG (llevError, "load_settings: Unknown value for " "spell_failure_effects: %s\n", cp); |
410 | } |
138 | } |
411 | } |
139 | } |
412 | else if (!strcasecmp (buf, "spellpoint_level_depend")) |
140 | else if (!strcmp (buf, "spellpoint_level_depend")) |
413 | { |
141 | { |
414 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
142 | if (!strcmp (cp, "on") || !strcmp (cp, "true")) |
415 | { |
143 | { |
416 | settings.spellpoint_level_depend = TRUE; |
144 | settings.spellpoint_level_depend = TRUE; |
417 | } |
145 | } |
418 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
146 | else if (!strcmp (cp, "off") || !strcmp (cp, "false")) |
419 | { |
147 | { |
420 | settings.spellpoint_level_depend = FALSE; |
148 | settings.spellpoint_level_depend = FALSE; |
421 | } |
149 | } |
422 | else |
150 | else |
423 | { |
151 | { |
424 | LOG (llevError, "load_settings: Unknown value for " "spellpoint_level_depend: %s\n", cp); |
152 | LOG (llevError, "load_settings: Unknown value for " "spellpoint_level_depend: %s\n", cp); |
425 | } |
153 | } |
426 | } |
154 | } |
427 | else if (!strcasecmp (buf, "stat_loss_on_death")) |
155 | else if (!strcmp (buf, "stat_loss_on_death")) |
428 | { |
156 | { |
429 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
157 | if (!strcmp (cp, "on") || !strcmp (cp, "true")) |
430 | { |
158 | { |
431 | settings.stat_loss_on_death = TRUE; |
159 | settings.stat_loss_on_death = TRUE; |
432 | } |
160 | } |
433 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
161 | else if (!strcmp (cp, "off") || !strcmp (cp, "false")) |
434 | { |
162 | { |
435 | settings.stat_loss_on_death = FALSE; |
163 | settings.stat_loss_on_death = FALSE; |
436 | } |
164 | } |
437 | else |
165 | else |
438 | { |
166 | { |
439 | LOG (llevError, "load_settings: Unknown value for " "stat_loss_on_death: %s\n", cp); |
167 | LOG (llevError, "load_settings: Unknown value for " "stat_loss_on_death: %s\n", cp); |
440 | } |
168 | } |
441 | } |
169 | } |
442 | else if (!strcasecmp (buf, "use_permanent_experience")) |
170 | else if (!strcmp (buf, "use_permanent_experience")) |
443 | { |
171 | { |
444 | LOG (llevError, "use_permanent_experience is deprecated, use" "permenent_experience_percentage instead\n"); |
172 | LOG (llevError, "use_permanent_experience is deprecated, use" "permenent_experience_percentage instead\n"); |
445 | } |
173 | } |
446 | else if (!strcasecmp (buf, "permanent_experience_percentage")) |
174 | else if (!strcmp (buf, "permanent_experience_percentage")) |
447 | { |
175 | { |
448 | int val = atoi (cp); |
176 | int val = atoi (cp); |
449 | |
177 | |
450 | if (val < 0 || val > 100) |
178 | if (val < 0 || val > 100) |
451 | LOG (llevError, "load_settings: permenent_experience_percentage" "must be between 0 and 100, %d is invalid\n", val); |
179 | LOG (llevError, "load_settings: permenent_experience_percentage" "must be between 0 and 100, %d is invalid\n", val); |
452 | else |
180 | else |
453 | settings.permanent_exp_ratio = val; |
181 | settings.permanent_exp_ratio = val; |
454 | } |
182 | } |
455 | else if (!strcasecmp (buf, "death_penalty_percentage")) |
183 | else if (!strcmp (buf, "death_penalty_percentage")) |
456 | { |
184 | { |
457 | int val = atoi (cp); |
185 | int val = atoi (cp); |
458 | |
186 | |
459 | if (val < 0 || val > 100) |
187 | if (val < 0 || val > 100) |
460 | LOG (llevError, "load_settings: death_penalty_percentage" "must be between 0 and 100, %d is invalid\n", val); |
188 | LOG (llevError, "load_settings: death_penalty_percentage" "must be between 0 and 100, %d is invalid\n", val); |
461 | else |
189 | else |
462 | settings.death_penalty_ratio = val; |
190 | settings.death_penalty_ratio = val; |
463 | } |
191 | } |
464 | else if (!strcasecmp (buf, "death_penalty_levels")) |
192 | else if (!strcmp (buf, "death_penalty_levels")) |
465 | { |
193 | { |
466 | int val = atoi (cp); |
194 | int val = atoi (cp); |
467 | |
195 | |
468 | if (val < 0 || val > 255) |
196 | if (val < 0 || val > 255) |
469 | LOG (llevError, "load_settings: death_penalty_levels" "can not be negative, %d is invalid\n", val); |
197 | LOG (llevError, "load_settings: death_penalty_levels" "can not be negative, %d is invalid\n", val); |
470 | else |
198 | else |
471 | settings.death_penalty_level = val; |
199 | settings.death_penalty_level = val; |
472 | } |
200 | } |
473 | else if (!strcasecmp (buf, "balanced_stat_loss")) |
201 | else if (!strcmp (buf, "balanced_stat_loss")) |
474 | { |
202 | { |
475 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
203 | if (!strcmp (cp, "on") || !strcmp (cp, "true")) |
476 | { |
204 | { |
477 | settings.balanced_stat_loss = TRUE; |
205 | settings.balanced_stat_loss = TRUE; |
478 | } |
206 | } |
479 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
207 | else if (!strcmp (cp, "off") || !strcmp (cp, "false")) |
480 | { |
208 | { |
481 | settings.balanced_stat_loss = FALSE; |
209 | settings.balanced_stat_loss = FALSE; |
482 | } |
210 | } |
483 | else |
211 | else |
484 | { |
212 | { |
485 | LOG (llevError, "load_settings: Unknown value for " "balanced_stat_loss: %s\n", cp); |
213 | LOG (llevError, "load_settings: Unknown value for " "balanced_stat_loss: %s\n", cp); |
486 | } |
214 | } |
487 | } |
215 | } |
488 | else if (!strcasecmp (buf, "simple_exp")) |
216 | else if (!strcmp (buf, "simple_exp")) |
489 | { |
217 | { |
490 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
218 | if (!strcmp (cp, "on") || !strcmp (cp, "true")) |
491 | { |
219 | { |
492 | settings.simple_exp = TRUE; |
220 | settings.simple_exp = TRUE; |
493 | } |
221 | } |
494 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
222 | else if (!strcmp (cp, "off") || !strcmp (cp, "false")) |
495 | { |
223 | { |
496 | settings.simple_exp = FALSE; |
224 | settings.simple_exp = FALSE; |
497 | } |
225 | } |
498 | else |
226 | else |
499 | { |
227 | { |
500 | LOG (llevError, "load_settings: Unknown value for simple_exp: %s\n", cp); |
228 | LOG (llevError, "load_settings: Unknown value for simple_exp: %s\n", cp); |
501 | } |
229 | } |
502 | } |
230 | } |
503 | else if (!strcasecmp (buf, "item_power_factor")) |
231 | else if (!strcmp (buf, "item_power_factor")) |
504 | { |
232 | { |
505 | float tmp = atof (cp); |
233 | float tmp = atof (cp); |
506 | |
234 | |
507 | if (tmp < 0) |
235 | if (tmp < 0) |
508 | LOG (llevError, "load_settings: item_power_factor must be a positive number (%f < 0)\n", tmp); |
236 | LOG (llevError, "load_settings: item_power_factor must be a positive number (%f < 0)\n", tmp); |
509 | else |
237 | else |
510 | settings.item_power_factor = tmp; |
238 | settings.item_power_factor = tmp; |
511 | } |
239 | } |
512 | else if (!strcasecmp (buf, "pk_luck_penalty")) |
240 | else if (!strcmp (buf, "pk_luck_penalty")) |
513 | { |
241 | { |
514 | sint16 val = atoi (cp); |
242 | sint16 val = atoi (cp); |
515 | |
243 | |
516 | if (val < -100 || val > 100) |
244 | if (val < -100 || val > 100) |
517 | LOG (llevError, "load_settings: pk_luck_penalty must be between -100 and 100" ", %d is invalid\n", val); |
245 | LOG (llevError, "load_settings: pk_luck_penalty must be between -100 and 100" ", %d is invalid\n", val); |
518 | else |
246 | else |
519 | settings.pk_luck_penalty = val; |
247 | settings.pk_luck_penalty = val; |
520 | } |
248 | } |
521 | else if (!strcasecmp (buf, "set_friendly_fire")) |
249 | else if (!strcmp (buf, "set_friendly_fire")) |
522 | { |
250 | { |
523 | int val = atoi (cp); |
251 | int val = atoi (cp); |
524 | |
252 | |
525 | if (val < 0 || val > 100) |
253 | if (val < 0 || val > 100) |
526 | LOG (llevError, "load_settings: set_friendly_fire must be between 0 an 100" ", %d is invalid\n", val); |
254 | LOG (llevError, "load_settings: set_friendly_fire must be between 0 an 100" ", %d is invalid\n", val); |
527 | else |
255 | else |
528 | settings.set_friendly_fire = val; |
256 | settings.set_friendly_fire = val; |
529 | } |
257 | } |
530 | else if (!strcasecmp (buf, "armor_max_enchant")) |
258 | else if (!strcmp (buf, "armor_max_enchant")) |
531 | { |
259 | { |
532 | int max_e = atoi (cp); |
260 | int max_e = atoi (cp); |
533 | |
261 | |
534 | if (max_e <= 0) |
262 | if (max_e <= 0) |
535 | LOG (llevError, "load_settings: armor_max_enchant is %d\n", max_e); |
263 | LOG (llevError, "load_settings: armor_max_enchant is %d\n", max_e); |
536 | else |
264 | else |
537 | settings.armor_max_enchant = max_e; |
265 | settings.armor_max_enchant = max_e; |
538 | } |
266 | } |
539 | else if (!strcasecmp (buf, "armor_weight_reduction")) |
267 | else if (!strcmp (buf, "armor_weight_reduction")) |
540 | { |
268 | { |
541 | int wr = atoi (cp); |
269 | int wr = atoi (cp); |
542 | |
270 | |
543 | if (wr < 0) |
271 | if (wr < 0) |
544 | LOG (llevError, "load_settings: armor_weight_reduction is %d\n", wr); |
272 | LOG (llevError, "load_settings: armor_weight_reduction is %d\n", wr); |
545 | else |
273 | else |
546 | settings.armor_weight_reduction = wr; |
274 | settings.armor_weight_reduction = wr; |
547 | } |
275 | } |
548 | else if (!strcasecmp (buf, "armor_weight_linear")) |
276 | else if (!strcmp (buf, "armor_weight_linear")) |
549 | { |
277 | { |
550 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
278 | if (!strcmp (cp, "on") || !strcmp (cp, "true")) |
551 | { |
279 | { |
552 | settings.armor_weight_linear = TRUE; |
280 | settings.armor_weight_linear = TRUE; |
553 | } |
281 | } |
554 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
282 | else if (!strcmp (cp, "off") || !strcmp (cp, "false")) |
555 | { |
283 | { |
556 | settings.armor_weight_linear = FALSE; |
284 | settings.armor_weight_linear = FALSE; |
557 | } |
285 | } |
558 | else |
286 | else |
559 | { |
287 | { |
560 | LOG (llevError, "load_settings: unknown value for armor_weight_linear: %s\n", cp); |
288 | LOG (llevError, "load_settings: unknown value for armor_weight_linear: %s\n", cp); |
561 | } |
289 | } |
562 | |
290 | |
563 | } |
291 | } |
564 | else if (!strcasecmp (buf, "armor_speed_improvement")) |
292 | else if (!strcmp (buf, "armor_speed_improvement")) |
565 | { |
293 | { |
566 | int wr = atoi (cp); |
294 | int wr = atoi (cp); |
567 | |
295 | |
568 | if (wr < 0) |
296 | if (wr < 0) |
569 | LOG (llevError, "load_settings: armor_speed_improvement is %d\n", wr); |
297 | LOG (llevError, "load_settings: armor_speed_improvement is %d\n", wr); |
570 | else |
298 | else |
571 | settings.armor_speed_improvement = wr; |
299 | settings.armor_speed_improvement = wr; |
572 | } |
300 | } |
573 | else if (!strcasecmp (buf, "armor_speed_linear")) |
301 | else if (!strcmp (buf, "armor_speed_linear")) |
574 | { |
302 | { |
575 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
303 | if (!strcmp (cp, "on") || !strcmp (cp, "true")) |
576 | { |
304 | { |
577 | settings.armor_speed_linear = TRUE; |
305 | settings.armor_speed_linear = TRUE; |
578 | } |
306 | } |
579 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
307 | else if (!strcmp (cp, "off") || !strcmp (cp, "false")) |
580 | { |
308 | { |
581 | settings.armor_speed_linear = FALSE; |
309 | settings.armor_speed_linear = FALSE; |
582 | } |
310 | } |
583 | else |
311 | else |
584 | { |
312 | { |
585 | LOG (llevError, "load_settings: unknown value for armor_speed_linear: %s\n", cp); |
313 | LOG (llevError, "load_settings: unknown value for armor_speed_linear: %s\n", cp); |
586 | } |
314 | } |
587 | |
315 | |
588 | } |
316 | } |
589 | else |
317 | else |
590 | LOG (llevError, "Unknown value in settings file: %s\n", buf); |
318 | thawer.parse_error ("settings file"); |
|
|
319 | |
|
|
320 | thawer.next (); |
591 | } |
321 | } |
592 | |
|
|
593 | close_and_delete (fp, comp); |
|
|
594 | } |
322 | } |
595 | |
323 | |
596 | /* |
324 | /* |
597 | * init() is called only once, when starting the program. |
325 | * init() is called only once, when starting the program. |
598 | */ |
326 | */ |
… | |
… | |
604 | init_environ (); |
332 | init_environ (); |
605 | cfperl_init (); |
333 | cfperl_init (); |
606 | init_done = 1; |
334 | init_done = 1; |
607 | } |
335 | } |
608 | |
336 | |
609 | void |
|
|
610 | usage (void) |
|
|
611 | { |
|
|
612 | fprintf (stderr, "Usage: deliantra-server [-h] [-<flags>]...\n"); |
|
|
613 | } |
|
|
614 | |
|
|
615 | void |
|
|
616 | help (void) |
|
|
617 | { |
|
|
618 | |
|
|
619 | /* The information in usage is redundant with what is given below, so why call it? */ |
|
|
620 | |
|
|
621 | /* usage();*/ |
|
|
622 | printf ("Flags:\n"); |
|
|
623 | printf (" -csport <port> Specifies the port to use for the new client/server code.\n"); |
|
|
624 | printf (" -d Turns on some debugging.\n"); |
|
|
625 | printf (" +d Turns off debugging (useful if server compiled with debugging\n"); |
|
|
626 | printf (" as default).\n"); |
|
|
627 | printf (" -detach The server will go in the background, closing all\n"); |
|
|
628 | printf (" connections to the tty.\n"); |
|
|
629 | printf (" -h Display this information.\n"); |
|
|
630 | printf (" -log <file> Specifies which file to send output to.\n"); |
|
|
631 | printf (" Only has meaning if -detach is specified.\n"); |
|
|
632 | printf (" -mon Turns on monster debugging.\n"); |
|
|
633 | printf (" -o Prints out info on what was defined at compile time.\n"); |
|
|
634 | printf (" -s Display the high-score list.\n"); |
|
|
635 | printf (" -score <name or class> Displays all high scores with matching name/class.\n"); |
|
|
636 | printf (" -v Print version and contributors.\n"); |
|
|
637 | printf (" -data Sets the lib dir (archetypes, treasures, etc.)\n"); |
|
|
638 | printf (" -local Read/write local data (hiscore, unique items, etc.)\n"); |
|
|
639 | printf (" -maps Sets the directory for maps.\n"); |
|
|
640 | printf (" -arch Sets the archetype file to use.\n"); |
|
|
641 | printf (" -regions Sets the regions file to use.\n"); |
|
|
642 | printf (" -playerdir Sets the directory for the player files.\n"); |
|
|
643 | printf (" -templatedir Sets the directory for template generate maps.\n"); |
|
|
644 | printf (" -treasures Sets the treasures file to use.\n"); |
|
|
645 | printf (" -uniquedir Sets the unique items/maps directory.\n"); |
|
|
646 | printf (" -tmpdir Sets the directory for temporary files (mostly maps.)\n"); |
|
|
647 | printf (" -m Lists out suggested experience for all monsters.\n"); |
|
|
648 | printf (" -m2 Dumps out abilities.\n"); |
|
|
649 | printf (" -m3 Dumps out artifact information.\n"); |
|
|
650 | printf (" -m4 Dumps out spell information.\n"); |
|
|
651 | printf (" -m5 Dumps out skill information.\n"); |
|
|
652 | printf (" -m6 Dumps out race information.\n"); |
|
|
653 | printf (" -m7 Dumps out alchemy information.\n"); |
|
|
654 | printf (" -m8 Dumps out gods information.\n"); |
|
|
655 | printf (" -m9 Dumps out more alchemy information (formula checking).\n"); |
|
|
656 | printf (" -mt <name> Dumps out list of treasures for a monster.\n"); |
|
|
657 | exit (0); |
|
|
658 | } |
|
|
659 | |
|
|
660 | void |
|
|
661 | init_beforeplay (void) |
|
|
662 | { |
|
|
663 | init_artifacts (); /* If not called before, reads all artifacts from file */ |
|
|
664 | init_races (); /* overwrite race designations using entries in lib/races file */ |
|
|
665 | init_gods (); /* init linked list of gods from archs */ |
|
|
666 | init_readable (); /* inits useful arrays for readable texts */ |
|
|
667 | init_formulae (); /* If not called before, reads formulae from file */ |
|
|
668 | } |
|
|
669 | |
|
|
670 | /* Signal handlers: */ |
337 | /* Signal handlers: */ |
671 | |
338 | |
672 | static void |
339 | static void |
673 | rec_sigabrt (int i) |
340 | rec_sigabrt (int i) |
674 | { |
341 | { |
… | |
… | |
677 | LOG (llevError, "SIGABRT received.\n"); |
344 | LOG (llevError, "SIGABRT received.\n"); |
678 | cleanup ("SIGABRT received", 1); |
345 | cleanup ("SIGABRT received", 1); |
679 | } |
346 | } |
680 | |
347 | |
681 | static void |
348 | static void |
|
|
349 | rec_sigquit (int i) |
|
|
350 | { |
|
|
351 | signal (SIGQUIT, SIG_IGN); |
|
|
352 | |
|
|
353 | LOG (llevInfo, "SIGQUIT received\n"); |
|
|
354 | cleanup ("SIGQUIT received", 1); |
|
|
355 | } |
|
|
356 | |
|
|
357 | static void |
682 | rec_sigsegv (int i) |
358 | rec_sigsegv (int i) |
683 | { |
359 | { |
684 | signal (SIGSEGV, SIG_DFL); |
360 | signal (SIGSEGV, SIG_DFL); |
685 | |
361 | |
686 | LOG (llevError, "SIGSEGV received.\n"); |
362 | LOG (llevError, "SIGSEGV received.\n"); |
687 | cleanup ("SIGSEGV received", 1); |
363 | cleanup ("SIGSEGV received", 1); |
688 | } |
364 | } |
689 | |
365 | |
690 | static void |
366 | static void |
691 | rec_sigquit (int i) |
|
|
692 | { |
|
|
693 | signal (SIGQUIT, SIG_IGN); |
|
|
694 | |
|
|
695 | LOG (llevInfo, "SIGQUIT received\n"); |
|
|
696 | cleanup ("SIGQUIT received", 1); |
|
|
697 | } |
|
|
698 | |
|
|
699 | static void |
|
|
700 | rec_sigbus (int i) |
367 | rec_sigbus (int i) |
701 | { |
368 | { |
702 | signal (SIGBUS, SIG_DFL); |
369 | signal (SIGBUS, SIG_DFL); |
703 | |
370 | |
704 | LOG (llevError, "SIGBUS received\n"); |
371 | LOG (llevError, "SIGBUS received\n"); |
705 | cleanup ("SIGBUS received", 1); |
372 | cleanup ("SIGBUS received", 1); |
|
|
373 | } |
|
|
374 | |
|
|
375 | static void |
|
|
376 | rec_sigfpe (int i) |
|
|
377 | { |
|
|
378 | signal (SIGFPE, SIG_DFL); |
|
|
379 | |
|
|
380 | LOG (llevError, "SIGFPE received.\n"); |
|
|
381 | cleanup ("SIGFPE received", 1); |
706 | } |
382 | } |
707 | |
383 | |
708 | void |
384 | void |
709 | reset_signals () |
385 | reset_signals () |
710 | { |
386 | { |
711 | signal (SIGABRT, SIG_DFL); |
387 | signal (SIGABRT, SIG_DFL); |
712 | signal (SIGQUIT, SIG_DFL); |
388 | signal (SIGQUIT, SIG_DFL); |
713 | signal (SIGSEGV, SIG_DFL); |
389 | signal (SIGSEGV, SIG_DFL); |
|
|
390 | #ifdef SIGBUS |
714 | signal (SIGBUS , SIG_DFL); |
391 | signal (SIGBUS , SIG_DFL); |
|
|
392 | #endif |
|
|
393 | signal (SIGFPE , SIG_DFL); |
715 | signal (SIGINT , SIG_DFL); |
394 | signal (SIGINT , SIG_DFL); |
716 | signal (SIGTERM, SIG_DFL); |
395 | signal (SIGTERM, SIG_DFL); |
717 | } |
396 | } |
718 | |
397 | |
719 | void |
398 | void |
720 | init_signals (void) |
399 | init_signals () |
721 | { |
400 | { |
722 | // large stack, but it's important data we want to save, and it is not usually |
401 | // large stack, but it's important data we want to save, and it is not usually |
723 | // being physically allocated anyways |
402 | // being physically allocated anyways |
724 | const size_t stacksize = 8 * 1024 * 1024 + SIGSTKSZ; |
403 | const size_t stacksize = 8 * 1024 * 1024 + SIGSTKSZ; |
725 | |
404 | |
… | |
… | |
735 | sa.sa_flags = SA_RESTART; |
414 | sa.sa_flags = SA_RESTART; |
736 | |
415 | |
737 | sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0); |
416 | sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0); |
738 | sa.sa_handler = rec_sigabrt; sigaction (SIGABRT, &sa, 0); |
417 | sa.sa_handler = rec_sigabrt; sigaction (SIGABRT, &sa, 0); |
739 | sa.sa_handler = rec_sigquit; sigaction (SIGQUIT, &sa, 0); |
418 | sa.sa_handler = rec_sigquit; sigaction (SIGQUIT, &sa, 0); |
|
|
419 | #ifdef SIGBUS |
740 | sa.sa_handler = rec_sigbus; sigaction (SIGBUS, &sa, 0); |
420 | sa.sa_handler = rec_sigbus; sigaction (SIGBUS, &sa, 0); |
|
|
421 | #endif |
|
|
422 | sa.sa_handler = rec_sigfpe; sigaction (SIGFPE, &sa, 0); |
741 | |
423 | |
742 | sa.sa_flags |= SA_ONSTACK; |
424 | sa.sa_flags |= SA_ONSTACK; |
743 | sa.sa_handler = rec_sigsegv; sigaction (SIGSEGV, &sa, 0); |
425 | sa.sa_handler = rec_sigsegv; sigaction (SIGSEGV, &sa, 0); |
|
|
426 | } |
|
|
427 | |
|
|
428 | static racelink * |
|
|
429 | get_racelist () |
|
|
430 | { |
|
|
431 | racelink *list = new racelink; |
|
|
432 | |
|
|
433 | list->name = 0; |
|
|
434 | list->nrof = 0; |
|
|
435 | list->next = 0; |
|
|
436 | list->member = get_objectlink (); |
|
|
437 | |
|
|
438 | return list; |
|
|
439 | } |
|
|
440 | |
|
|
441 | racelink * |
|
|
442 | find_racelink (const char *name) |
|
|
443 | { |
|
|
444 | if (name) |
|
|
445 | for (racelink *link = first_race; link; link = link->next) |
|
|
446 | if (!link->name || !strcmp (name, link->name)) |
|
|
447 | return link; |
|
|
448 | |
|
|
449 | return 0; |
|
|
450 | } |
|
|
451 | |
|
|
452 | static void |
|
|
453 | add_to_racelist (const char *race_name, object *op) |
|
|
454 | { |
|
|
455 | racelink *race; |
|
|
456 | |
|
|
457 | if (!op || !race_name) |
|
|
458 | return; |
|
|
459 | |
|
|
460 | race = find_racelink (race_name); |
|
|
461 | |
|
|
462 | if (!race) |
|
|
463 | { /* add in a new race list */ |
|
|
464 | race = get_racelist (); |
|
|
465 | race->next = first_race; |
|
|
466 | first_race = race; |
|
|
467 | race->name = race_name; |
|
|
468 | } |
|
|
469 | |
|
|
470 | if (race->member->ob) |
|
|
471 | { |
|
|
472 | objectlink *tmp = get_objectlink (); |
|
|
473 | |
|
|
474 | tmp->next = race->member; |
|
|
475 | race->member = tmp; |
|
|
476 | } |
|
|
477 | |
|
|
478 | race->nrof++; |
|
|
479 | race->member->ob = op; |
744 | } |
480 | } |
745 | |
481 | |
746 | /* init_races() - reads the races file in the lib/ directory, then |
482 | /* init_races() - reads the races file in the lib/ directory, then |
747 | * overwrites old 'race' entries. This routine allow us to quickly |
483 | * overwrites old 'race' entries. This routine allow us to quickly |
748 | * re-configure the 'alignment' of monsters, objects. Useful for |
484 | * re-configure the 'alignment' of monsters, objects. Useful for |
749 | * putting together lists of creatures, etc that belong to gods. |
485 | * putting together lists of creatures, etc that belong to gods. |
750 | */ |
486 | */ |
751 | void |
487 | static void |
752 | init_races (void) |
488 | init_races () |
753 | { |
489 | { |
754 | FILE *file; |
490 | FILE *file; |
755 | char race[MAX_BUF], fname[MAX_BUF], buf[MAX_BUF], *cp, variable[MAX_BUF]; |
491 | char race[MAX_BUF], fname[MAX_BUF], buf[MAX_BUF], *cp, variable[MAX_BUF]; |
756 | archetype *mon = NULL; |
492 | archetype *mon = NULL; |
757 | static int init_done = 0; |
493 | static int init_done = 0; |
… | |
… | |
821 | |
557 | |
822 | mon->race = race; |
558 | mon->race = race; |
823 | } |
559 | } |
824 | |
560 | |
825 | /* if the arch is a monster, add it to the race list */ |
561 | /* if the arch is a monster, add it to the race list */ |
826 | if (set_list && QUERY_FLAG (mon, FLAG_MONSTER)) |
562 | if (set_list && mon->flag [FLAG_MONSTER]) |
827 | add_to_racelist (race, mon); |
563 | add_to_racelist (race, mon); |
828 | } |
564 | } |
829 | } |
565 | } |
830 | } |
566 | } |
831 | |
567 | |
832 | fclose (file); |
568 | fclose (file); |
833 | LOG (llevDebug, "done.\n"); |
569 | LOG (llevDebug, "done.\n"); |
834 | } |
570 | } |
835 | |
571 | |
836 | void |
572 | void |
837 | dump_races (void) |
573 | init_beforeplay () |
838 | { |
574 | { |
839 | racelink *list; |
575 | init_artifacts (); /* If not called before, reads all artifacts from file */ |
840 | objectlink *tmp; |
576 | init_races (); /* overwrite race designations using entries in lib/races file */ |
841 | |
577 | init_gods (); /* init linked list of gods from archs */ |
842 | for (list = first_race; list; list = list->next) |
578 | init_readable (); /* inits useful arrays for readable texts */ |
843 | { |
579 | init_formulae (); /* If not called before, reads formulae from file */ |
844 | fprintf (stderr, "\nRACE %s:\t", &list->name); |
|
|
845 | for (tmp = list->member; tmp; tmp = tmp->next) |
|
|
846 | fprintf (stderr, "%s(%d), ", &tmp->ob->arch->archname, tmp->ob->level); |
|
|
847 | } |
|
|
848 | |
|
|
849 | fprintf (stderr, "\n"); |
|
|
850 | } |
580 | } |
851 | |
581 | |
852 | void |
|
|
853 | add_to_racelist (const char *race_name, object *op) |
|
|
854 | { |
|
|
855 | racelink *race; |
|
|
856 | |
|
|
857 | if (!op || !race_name) |
|
|
858 | return; |
|
|
859 | |
|
|
860 | race = find_racelink (race_name); |
|
|
861 | |
|
|
862 | if (!race) |
|
|
863 | { /* add in a new race list */ |
|
|
864 | race = get_racelist (); |
|
|
865 | race->next = first_race; |
|
|
866 | first_race = race; |
|
|
867 | race->name = race_name; |
|
|
868 | } |
|
|
869 | |
|
|
870 | if (race->member->ob) |
|
|
871 | { |
|
|
872 | objectlink *tmp = get_objectlink (); |
|
|
873 | |
|
|
874 | tmp->next = race->member; |
|
|
875 | race->member = tmp; |
|
|
876 | } |
|
|
877 | |
|
|
878 | race->nrof++; |
|
|
879 | race->member->ob = op; |
|
|
880 | } |
|
|
881 | |
|
|
882 | racelink * |
|
|
883 | get_racelist () |
|
|
884 | { |
|
|
885 | racelink *list = new racelink; |
|
|
886 | |
|
|
887 | list->name = 0; |
|
|
888 | list->nrof = 0; |
|
|
889 | list->next = 0; |
|
|
890 | list->member = get_objectlink (); |
|
|
891 | |
|
|
892 | return list; |
|
|
893 | } |
|
|
894 | |
|
|
895 | racelink * |
|
|
896 | find_racelink (const char *name) |
|
|
897 | { |
|
|
898 | if (name) |
|
|
899 | for (racelink *link = first_race; link; link = link->next) |
|
|
900 | if (!link->name || !strcmp (name, link->name)) |
|
|
901 | return link; |
|
|
902 | |
|
|
903 | return 0; |
|
|
904 | } |
|
|