1 |
/* |
2 |
* This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 |
* |
4 |
* Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 |
* Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 |
* Copyright (©) 1992,2007 Frank Tore Johansen |
7 |
* |
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 |
10 |
* Free Software Foundation, either version 3 of the License, or (at your |
11 |
* option) any later version. |
12 |
* |
13 |
* This program is distributed in the hope that it will be useful, |
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
* GNU General Public License for more details. |
17 |
* |
18 |
* You should have received a copy of the Affero GNU General Public License |
19 |
* and the GNU General Public License along with this program. If not, see |
20 |
* <http://www.gnu.org/licenses/>. |
21 |
* |
22 |
* The authors can be reached via e-mail to <support@deliantra.net> |
23 |
*/ |
24 |
|
25 |
#include <global.h> |
26 |
#include <material.h> |
27 |
#include <loader.h> |
28 |
#include <sproto.h> |
29 |
|
30 |
/* This loads the settings file. There could be debate whether this should |
31 |
* be here or in the common directory - but since only the server needs this |
32 |
* information, having it here probably makes more sense. |
33 |
*/ |
34 |
void |
35 |
load_settings (void) |
36 |
{ |
37 |
char buf[MAX_BUF], *cp; |
38 |
int has_val, comp; |
39 |
FILE *fp; |
40 |
|
41 |
sprintf (buf, "%s/settings", settings.confdir); |
42 |
|
43 |
/* We don't require a settings file at current time, but down the road, |
44 |
* there will probably be so many values that not having a settings file |
45 |
* will not be a good thing. |
46 |
*/ |
47 |
if (!(fp = open_and_uncompress (buf, 0, &comp))) |
48 |
{ |
49 |
LOG (llevError, "Error: No settings file found\n"); |
50 |
exit (1); |
51 |
} |
52 |
|
53 |
while (fgets (buf, MAX_BUF - 1, fp) != NULL) |
54 |
{ |
55 |
if (buf[0] == '#') |
56 |
continue; |
57 |
/* eliminate newline */ |
58 |
if ((cp = strrchr (buf, '\n')) != NULL) |
59 |
*cp = '\0'; |
60 |
|
61 |
/* Skip over empty lines */ |
62 |
if (buf[0] == 0) |
63 |
continue; |
64 |
|
65 |
/* Skip all the spaces and set them to nulls. If not space, |
66 |
* set cp to "" to make strcpy's and the like easier down below. |
67 |
*/ |
68 |
if ((cp = strchr (buf, ' ')) != NULL) |
69 |
{ |
70 |
while (*cp == ' ') |
71 |
*cp++ = 0; |
72 |
has_val = 1; |
73 |
} |
74 |
else |
75 |
{ |
76 |
cp = (char *)""; |
77 |
has_val = 0; |
78 |
} |
79 |
|
80 |
if (!strcasecmp (buf, "not_permadeth")) |
81 |
{ |
82 |
if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
83 |
{ |
84 |
settings.not_permadeth = TRUE; |
85 |
} |
86 |
else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
87 |
{ |
88 |
settings.not_permadeth = FALSE; |
89 |
} |
90 |
else |
91 |
{ |
92 |
LOG (llevError, "load_settings: Unknown value for not_permadeth" ": %s\n", cp); |
93 |
} |
94 |
} |
95 |
else if (!strcasecmp (buf, "resurrection")) |
96 |
{ |
97 |
if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
98 |
{ |
99 |
settings.resurrection = TRUE; |
100 |
} |
101 |
else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
102 |
{ |
103 |
settings.resurrection = FALSE; |
104 |
} |
105 |
else |
106 |
{ |
107 |
LOG (llevError, "load_settings: Unknown value for resurrection" ": %s\n", cp); |
108 |
} |
109 |
} |
110 |
else if (!strcasecmp (buf, "set_title")) |
111 |
{ |
112 |
if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
113 |
{ |
114 |
settings.set_title = TRUE; |
115 |
} |
116 |
else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
117 |
{ |
118 |
settings.set_title = FALSE; |
119 |
} |
120 |
else |
121 |
{ |
122 |
LOG (llevError, "load_settings: Unknown value for set_title" ": %s\n", cp); |
123 |
} |
124 |
} |
125 |
else if (!strcasecmp (buf, "search_items")) |
126 |
{ |
127 |
if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
128 |
{ |
129 |
settings.search_items = TRUE; |
130 |
} |
131 |
else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
132 |
{ |
133 |
settings.search_items = FALSE; |
134 |
} |
135 |
else |
136 |
{ |
137 |
LOG (llevError, "load_settings: Unknown value for search_items" ": %s\n", cp); |
138 |
} |
139 |
} |
140 |
else if (!strcasecmp (buf, "spell_encumbrance")) |
141 |
{ |
142 |
if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
143 |
{ |
144 |
settings.spell_encumbrance = TRUE; |
145 |
} |
146 |
else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
147 |
{ |
148 |
settings.spell_encumbrance = FALSE; |
149 |
} |
150 |
else |
151 |
{ |
152 |
LOG (llevError, "load_settings: Unknown value for " "spell_encumbrance: %s\n", cp); |
153 |
} |
154 |
} |
155 |
else if (!strcasecmp (buf, "spell_failure_effects")) |
156 |
{ |
157 |
if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
158 |
{ |
159 |
settings.spell_failure_effects = TRUE; |
160 |
} |
161 |
else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
162 |
{ |
163 |
settings.spell_failure_effects = FALSE; |
164 |
} |
165 |
else |
166 |
{ |
167 |
LOG (llevError, "load_settings: Unknown value for " "spell_failure_effects: %s\n", cp); |
168 |
} |
169 |
} |
170 |
else if (!strcasecmp (buf, "spellpoint_level_depend")) |
171 |
{ |
172 |
if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
173 |
{ |
174 |
settings.spellpoint_level_depend = TRUE; |
175 |
} |
176 |
else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
177 |
{ |
178 |
settings.spellpoint_level_depend = FALSE; |
179 |
} |
180 |
else |
181 |
{ |
182 |
LOG (llevError, "load_settings: Unknown value for " "spellpoint_level_depend: %s\n", cp); |
183 |
} |
184 |
} |
185 |
else if (!strcasecmp (buf, "stat_loss_on_death")) |
186 |
{ |
187 |
if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
188 |
{ |
189 |
settings.stat_loss_on_death = TRUE; |
190 |
} |
191 |
else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
192 |
{ |
193 |
settings.stat_loss_on_death = FALSE; |
194 |
} |
195 |
else |
196 |
{ |
197 |
LOG (llevError, "load_settings: Unknown value for " "stat_loss_on_death: %s\n", cp); |
198 |
} |
199 |
} |
200 |
else if (!strcasecmp (buf, "use_permanent_experience")) |
201 |
{ |
202 |
LOG (llevError, "use_permanent_experience is deprecated, use" "permenent_experience_percentage instead\n"); |
203 |
} |
204 |
else if (!strcasecmp (buf, "permanent_experience_percentage")) |
205 |
{ |
206 |
int val = atoi (cp); |
207 |
|
208 |
if (val < 0 || val > 100) |
209 |
LOG (llevError, "load_settings: permenent_experience_percentage" "must be between 0 and 100, %d is invalid\n", val); |
210 |
else |
211 |
settings.permanent_exp_ratio = val; |
212 |
} |
213 |
else if (!strcasecmp (buf, "death_penalty_percentage")) |
214 |
{ |
215 |
int val = atoi (cp); |
216 |
|
217 |
if (val < 0 || val > 100) |
218 |
LOG (llevError, "load_settings: death_penalty_percentage" "must be between 0 and 100, %d is invalid\n", val); |
219 |
else |
220 |
settings.death_penalty_ratio = val; |
221 |
} |
222 |
else if (!strcasecmp (buf, "death_penalty_levels")) |
223 |
{ |
224 |
int val = atoi (cp); |
225 |
|
226 |
if (val < 0 || val > 255) |
227 |
LOG (llevError, "load_settings: death_penalty_levels" "can not be negative, %d is invalid\n", val); |
228 |
else |
229 |
settings.death_penalty_level = val; |
230 |
} |
231 |
else if (!strcasecmp (buf, "balanced_stat_loss")) |
232 |
{ |
233 |
if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
234 |
{ |
235 |
settings.balanced_stat_loss = TRUE; |
236 |
} |
237 |
else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
238 |
{ |
239 |
settings.balanced_stat_loss = FALSE; |
240 |
} |
241 |
else |
242 |
{ |
243 |
LOG (llevError, "load_settings: Unknown value for " "balanced_stat_loss: %s\n", cp); |
244 |
} |
245 |
} |
246 |
else if (!strcasecmp (buf, "simple_exp")) |
247 |
{ |
248 |
if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
249 |
{ |
250 |
settings.simple_exp = TRUE; |
251 |
} |
252 |
else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
253 |
{ |
254 |
settings.simple_exp = FALSE; |
255 |
} |
256 |
else |
257 |
{ |
258 |
LOG (llevError, "load_settings: Unknown value for simple_exp: %s\n", cp); |
259 |
} |
260 |
} |
261 |
else if (!strcasecmp (buf, "item_power_factor")) |
262 |
{ |
263 |
float tmp = atof (cp); |
264 |
|
265 |
if (tmp < 0) |
266 |
LOG (llevError, "load_settings: item_power_factor must be a positive number (%f < 0)\n", tmp); |
267 |
else |
268 |
settings.item_power_factor = tmp; |
269 |
} |
270 |
else if (!strcasecmp (buf, "pk_luck_penalty")) |
271 |
{ |
272 |
sint16 val = atoi (cp); |
273 |
|
274 |
if (val < -100 || val > 100) |
275 |
LOG (llevError, "load_settings: pk_luck_penalty must be between -100 and 100" ", %d is invalid\n", val); |
276 |
else |
277 |
settings.pk_luck_penalty = val; |
278 |
} |
279 |
else if (!strcasecmp (buf, "set_friendly_fire")) |
280 |
{ |
281 |
int val = atoi (cp); |
282 |
|
283 |
if (val < 0 || val > 100) |
284 |
LOG (llevError, "load_settings: set_friendly_fire must be between 0 an 100" ", %d is invalid\n", val); |
285 |
else |
286 |
settings.set_friendly_fire = val; |
287 |
} |
288 |
else if (!strcasecmp (buf, "armor_max_enchant")) |
289 |
{ |
290 |
int max_e = atoi (cp); |
291 |
|
292 |
if (max_e <= 0) |
293 |
LOG (llevError, "load_settings: armor_max_enchant is %d\n", max_e); |
294 |
else |
295 |
settings.armor_max_enchant = max_e; |
296 |
} |
297 |
else if (!strcasecmp (buf, "armor_weight_reduction")) |
298 |
{ |
299 |
int wr = atoi (cp); |
300 |
|
301 |
if (wr < 0) |
302 |
LOG (llevError, "load_settings: armor_weight_reduction is %d\n", wr); |
303 |
else |
304 |
settings.armor_weight_reduction = wr; |
305 |
} |
306 |
else if (!strcasecmp (buf, "armor_weight_linear")) |
307 |
{ |
308 |
if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
309 |
{ |
310 |
settings.armor_weight_linear = TRUE; |
311 |
} |
312 |
else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
313 |
{ |
314 |
settings.armor_weight_linear = FALSE; |
315 |
} |
316 |
else |
317 |
{ |
318 |
LOG (llevError, "load_settings: unknown value for armor_weight_linear: %s\n", cp); |
319 |
} |
320 |
|
321 |
} |
322 |
else if (!strcasecmp (buf, "armor_speed_improvement")) |
323 |
{ |
324 |
int wr = atoi (cp); |
325 |
|
326 |
if (wr < 0) |
327 |
LOG (llevError, "load_settings: armor_speed_improvement is %d\n", wr); |
328 |
else |
329 |
settings.armor_speed_improvement = wr; |
330 |
} |
331 |
else if (!strcasecmp (buf, "armor_speed_linear")) |
332 |
{ |
333 |
if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
334 |
{ |
335 |
settings.armor_speed_linear = TRUE; |
336 |
} |
337 |
else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
338 |
{ |
339 |
settings.armor_speed_linear = FALSE; |
340 |
} |
341 |
else |
342 |
{ |
343 |
LOG (llevError, "load_settings: unknown value for armor_speed_linear: %s\n", cp); |
344 |
} |
345 |
|
346 |
} |
347 |
else |
348 |
LOG (llevError, "Unknown value in settings file: %s\n", buf); |
349 |
} |
350 |
|
351 |
close_and_delete (fp, comp); |
352 |
} |
353 |
|
354 |
/* |
355 |
* init() is called only once, when starting the program. |
356 |
*/ |
357 |
void |
358 |
init (int argc, char **argv) |
359 |
{ |
360 |
init_done = 0; /* Must be done before init_signal() */ |
361 |
|
362 |
init_environ (); |
363 |
cfperl_init (); |
364 |
init_done = 1; |
365 |
} |
366 |
|
367 |
void |
368 |
usage (void) |
369 |
{ |
370 |
fprintf (stderr, "Usage: deliantra-server [-h] [-<flags>]...\n"); |
371 |
} |
372 |
|
373 |
void |
374 |
help (void) |
375 |
{ |
376 |
|
377 |
/* The information in usage is redundant with what is given below, so why call it? */ |
378 |
|
379 |
/* usage();*/ |
380 |
printf ("Flags:\n"); |
381 |
printf (" -csport <port> Specifies the port to use for the new client/server code.\n"); |
382 |
printf (" -d Turns on some debugging.\n"); |
383 |
printf (" +d Turns off debugging (useful if server compiled with debugging\n"); |
384 |
printf (" as default).\n"); |
385 |
printf (" -detach The server will go in the background, closing all\n"); |
386 |
printf (" connections to the tty.\n"); |
387 |
printf (" -h Display this information.\n"); |
388 |
printf (" -log <file> Specifies which file to send output to.\n"); |
389 |
printf (" Only has meaning if -detach is specified.\n"); |
390 |
printf (" -mon Turns on monster debugging.\n"); |
391 |
printf (" -o Prints out info on what was defined at compile time.\n"); |
392 |
printf (" -s Display the high-score list.\n"); |
393 |
printf (" -score <name or class> Displays all high scores with matching name/class.\n"); |
394 |
printf (" -v Print version and contributors.\n"); |
395 |
printf (" -data Sets the lib dir (archetypes, treasures, etc.)\n"); |
396 |
printf (" -local Read/write local data (hiscore, unique items, etc.)\n"); |
397 |
printf (" -maps Sets the directory for maps.\n"); |
398 |
printf (" -arch Sets the archetype file to use.\n"); |
399 |
printf (" -regions Sets the regions file to use.\n"); |
400 |
printf (" -playerdir Sets the directory for the player files.\n"); |
401 |
printf (" -templatedir Sets the directory for template generate maps.\n"); |
402 |
printf (" -treasures Sets the treasures file to use.\n"); |
403 |
printf (" -uniquedir Sets the unique items/maps directory.\n"); |
404 |
printf (" -tmpdir Sets the directory for temporary files (mostly maps.)\n"); |
405 |
printf (" -m Lists out suggested experience for all monsters.\n"); |
406 |
printf (" -m2 Dumps out abilities.\n"); |
407 |
printf (" -m3 Dumps out artifact information.\n"); |
408 |
printf (" -m4 Dumps out spell information.\n"); |
409 |
printf (" -m5 Dumps out skill information.\n"); |
410 |
printf (" -m6 Dumps out race information.\n"); |
411 |
printf (" -m7 Dumps out alchemy information.\n"); |
412 |
printf (" -m8 Dumps out gods information.\n"); |
413 |
printf (" -m9 Dumps out more alchemy information (formula checking).\n"); |
414 |
printf (" -mt <name> Dumps out list of treasures for a monster.\n"); |
415 |
exit (0); |
416 |
} |
417 |
|
418 |
/* Signal handlers: */ |
419 |
|
420 |
static void |
421 |
rec_sigabrt (int i) |
422 |
{ |
423 |
signal (SIGABRT, SIG_DFL); |
424 |
|
425 |
LOG (llevError, "SIGABRT received.\n"); |
426 |
cleanup ("SIGABRT received", 1); |
427 |
} |
428 |
|
429 |
static void |
430 |
rec_sigsegv (int i) |
431 |
{ |
432 |
signal (SIGSEGV, SIG_DFL); |
433 |
|
434 |
LOG (llevError, "SIGSEGV received.\n"); |
435 |
cleanup ("SIGSEGV received", 1); |
436 |
} |
437 |
|
438 |
static void |
439 |
rec_sigquit (int i) |
440 |
{ |
441 |
signal (SIGQUIT, SIG_IGN); |
442 |
|
443 |
LOG (llevInfo, "SIGQUIT received\n"); |
444 |
cleanup ("SIGQUIT received", 1); |
445 |
} |
446 |
|
447 |
static void |
448 |
rec_sigbus (int i) |
449 |
{ |
450 |
signal (SIGBUS, SIG_DFL); |
451 |
|
452 |
LOG (llevError, "SIGBUS received\n"); |
453 |
cleanup ("SIGBUS received", 1); |
454 |
} |
455 |
|
456 |
void |
457 |
reset_signals () |
458 |
{ |
459 |
signal (SIGABRT, SIG_DFL); |
460 |
signal (SIGQUIT, SIG_DFL); |
461 |
signal (SIGSEGV, SIG_DFL); |
462 |
signal (SIGBUS , SIG_DFL); |
463 |
signal (SIGINT , SIG_DFL); |
464 |
signal (SIGTERM, SIG_DFL); |
465 |
} |
466 |
|
467 |
void |
468 |
init_signals (void) |
469 |
{ |
470 |
// large stack, but it's important data we want to save, and it is not usually |
471 |
// being physically allocated anyways |
472 |
const size_t stacksize = 8 * 1024 * 1024 + SIGSTKSZ; |
473 |
|
474 |
stack_t ss; |
475 |
ss.ss_sp = malloc (stacksize); |
476 |
ss.ss_flags = 0; |
477 |
ss.ss_size = stacksize; |
478 |
sigaltstack (&ss, 0); |
479 |
|
480 |
struct sigaction sa; |
481 |
|
482 |
sigfillset (&sa.sa_mask); |
483 |
sa.sa_flags = SA_RESTART; |
484 |
|
485 |
sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0); |
486 |
sa.sa_handler = rec_sigabrt; sigaction (SIGABRT, &sa, 0); |
487 |
sa.sa_handler = rec_sigquit; sigaction (SIGQUIT, &sa, 0); |
488 |
sa.sa_handler = rec_sigbus; sigaction (SIGBUS, &sa, 0); |
489 |
|
490 |
sa.sa_flags |= SA_ONSTACK; |
491 |
sa.sa_handler = rec_sigsegv; sigaction (SIGSEGV, &sa, 0); |
492 |
} |
493 |
|
494 |
static racelink * |
495 |
get_racelist () |
496 |
{ |
497 |
racelink *list = new racelink; |
498 |
|
499 |
list->name = 0; |
500 |
list->nrof = 0; |
501 |
list->next = 0; |
502 |
list->member = get_objectlink (); |
503 |
|
504 |
return list; |
505 |
} |
506 |
|
507 |
racelink * |
508 |
find_racelink (const char *name) |
509 |
{ |
510 |
if (name) |
511 |
for (racelink *link = first_race; link; link = link->next) |
512 |
if (!link->name || !strcmp (name, link->name)) |
513 |
return link; |
514 |
|
515 |
return 0; |
516 |
} |
517 |
|
518 |
static void |
519 |
add_to_racelist (const char *race_name, object *op) |
520 |
{ |
521 |
racelink *race; |
522 |
|
523 |
if (!op || !race_name) |
524 |
return; |
525 |
|
526 |
race = find_racelink (race_name); |
527 |
|
528 |
if (!race) |
529 |
{ /* add in a new race list */ |
530 |
race = get_racelist (); |
531 |
race->next = first_race; |
532 |
first_race = race; |
533 |
race->name = race_name; |
534 |
} |
535 |
|
536 |
if (race->member->ob) |
537 |
{ |
538 |
objectlink *tmp = get_objectlink (); |
539 |
|
540 |
tmp->next = race->member; |
541 |
race->member = tmp; |
542 |
} |
543 |
|
544 |
race->nrof++; |
545 |
race->member->ob = op; |
546 |
} |
547 |
|
548 |
/* init_races() - reads the races file in the lib/ directory, then |
549 |
* overwrites old 'race' entries. This routine allow us to quickly |
550 |
* re-configure the 'alignment' of monsters, objects. Useful for |
551 |
* putting together lists of creatures, etc that belong to gods. |
552 |
*/ |
553 |
static void |
554 |
init_races (void) |
555 |
{ |
556 |
FILE *file; |
557 |
char race[MAX_BUF], fname[MAX_BUF], buf[MAX_BUF], *cp, variable[MAX_BUF]; |
558 |
archetype *mon = NULL; |
559 |
static int init_done = 0; |
560 |
|
561 |
if (init_done) |
562 |
return; |
563 |
init_done = 1; |
564 |
first_race = 0; |
565 |
|
566 |
sprintf (fname, "%s/races", settings.datadir); |
567 |
LOG (llevDebug, "Reading races from %s...\n", fname); |
568 |
if (!(file = fopen (fname, "r"))) |
569 |
{ |
570 |
LOG (llevError, "Cannot open races file %s: %s\n", fname, strerror (errno)); |
571 |
return; |
572 |
} |
573 |
|
574 |
while (fgets (buf, MAX_BUF, file) != NULL) |
575 |
{ |
576 |
int set_race = 1, set_list = 1; |
577 |
|
578 |
if (*buf == '#') |
579 |
continue; |
580 |
|
581 |
if ((cp = strchr (buf, '\n')) != NULL) |
582 |
*cp = '\0'; |
583 |
|
584 |
cp = buf; |
585 |
while (*cp == ' ' || *cp == '!' || *cp == '@') |
586 |
{ |
587 |
if (*cp == '!') set_race = 0; |
588 |
if (*cp == '@') set_list = 0; |
589 |
|
590 |
cp++; |
591 |
} |
592 |
|
593 |
if (sscanf (cp, "RACE %s", variable)) |
594 |
/* set new race value */ |
595 |
strcpy (race, variable); |
596 |
else |
597 |
{ |
598 |
char *cp1; |
599 |
|
600 |
/* Take out beginning spaces */ |
601 |
for (cp1 = cp; *cp1 == ' '; cp1++) |
602 |
; |
603 |
/* Remove newline and trailing spaces */ |
604 |
for (cp1 = cp + strlen (cp) - 1; *cp1 == '\n' || *cp1 == ' '; cp1--) |
605 |
{ |
606 |
*cp1 = '\0'; |
607 |
if (cp == cp1) |
608 |
break; |
609 |
} |
610 |
|
611 |
if (cp[strlen (cp) - 1] == '\n') |
612 |
cp[strlen (cp) - 1] = '\0'; |
613 |
|
614 |
/* set creature race to race value */ |
615 |
if ((mon = archetype::find (cp)) == NULL) |
616 |
LOG (llevError, "Creature %s in race file lacks archetype\n", cp); |
617 |
else |
618 |
{ |
619 |
if (set_race && (!mon->race || strcmp (&mon->race, race))) |
620 |
{ |
621 |
if (mon->race) |
622 |
LOG (llevDebug, "Resetting race to %s from %s for archetype %s\n", race, &mon->race, &mon->archname); |
623 |
|
624 |
mon->race = race; |
625 |
} |
626 |
|
627 |
/* if the arch is a monster, add it to the race list */ |
628 |
if (set_list && QUERY_FLAG (mon, FLAG_MONSTER)) |
629 |
add_to_racelist (race, mon); |
630 |
} |
631 |
} |
632 |
} |
633 |
|
634 |
fclose (file); |
635 |
LOG (llevDebug, "done.\n"); |
636 |
} |
637 |
|
638 |
void |
639 |
init_beforeplay (void) |
640 |
{ |
641 |
init_artifacts (); /* If not called before, reads all artifacts from file */ |
642 |
init_races (); /* overwrite race designations using entries in lib/races file */ |
643 |
init_gods (); /* init linked list of gods from archs */ |
644 |
init_readable (); /* inits useful arrays for readable texts */ |
645 |
init_formulae (); /* If not called before, reads formulae from file */ |
646 |
} |
647 |
|