ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/init.C
Revision: 1.72
Committed: Thu Oct 15 21:40:42 2009 UTC (14 years, 7 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-2_82
Changes since 1.71: +1 -87 lines
Log Message:
cleanups

File Contents

# Content
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 //TODO: make this a constructor
31 static materialtype_t *
32 get_empty_mat (void)
33 {
34 materialtype_t *mt;
35 int i;
36
37 mt = new materialtype_t;
38
39 mt->name = shstr_unknown;
40 mt->description = 0;
41
42 for (i = 0; i < NROFATTACKS; i++)
43 {
44 mt->save[i] = 0;
45 mt->mod[i] = 0;
46 }
47
48 mt->chance = 0;
49 mt->difficulty = 0;
50 mt->magic = 0;
51 mt->damage = 0;
52 mt->wc = 0;
53 mt->ac = 0;
54 mt->sp = 0;
55 mt->weight = 100;
56 mt->value = 100;
57 mt->density = 1;
58 mt->next = 0;
59
60 return mt;
61 }
62
63 void
64 load_materials (void)
65 {
66 char filename[MAX_BUF];
67
68 sprintf (filename, "%s/materials", settings.datadir);
69 LOG (llevDebug, "Reading material type data from %s...\n", filename);
70
71 //TODO: somehow free old materials, or update them in-place
72 materialt = 0;
73
74 object_thawer thawer (filename);
75
76 if (!thawer)
77 {
78 LOG (llevError, "Cannot open %s for reading\n", filename);
79 goto done;
80 }
81
82 while (thawer.kw != KW_name)
83 {
84 thawer.next ();
85
86 if (thawer.kw == KW_EOF)
87 goto done;
88 }
89
90 materialtype_t *mt;
91
92 for (;;)
93 {
94 switch (thawer.kw)
95 {
96 case KW_name:
97 mt = get_empty_mat ();
98 mt->next = materialt;
99 materialt = mt;
100
101 thawer.get (mt->name);
102 mt->description = mt->name;
103 break;
104
105 case KW_description:
106 thawer.get (mt->description);
107 break;
108
109 case KW_material:
110 thawer.get (mt->material);
111 break;
112
113 case KW_saves:
114 {
115 const char *cp = thawer.get_str () - 1;
116
117 for (int i = 0; i < NROFATTACKS; i++)
118 {
119 if (!cp)
120 {
121 mt->save[i] = 0;
122 continue;
123 }
124
125 int value;
126 ++cp;
127 sscanf (cp, "%d", &value);
128 mt->save[i] = (sint8) value;
129 cp = strchr (cp, ',');
130 }
131 }
132 break;
133
134 case KW_mods:
135 {
136 const char *cp = thawer.get_str () - 1;
137
138 for (int i = 0; i < NROFATTACKS; i++)
139 {
140 if (!cp)
141 {
142 mt->save[i] = 0;
143 continue;
144 }
145
146 ++cp;
147 int value;
148 sscanf (cp, "%d", &value);
149 mt->mod[i] = (sint8) value;
150 cp = strchr (cp, ',');
151 }
152 }
153 break;
154
155 case KW_chance: thawer.get (mt->chance); break;
156 case KW_difficulty: // cf+ alias, not original cf
157 case KW_diff: thawer.get (mt->difficulty); break;
158 case KW_magic: thawer.get (mt->magic); break;
159 case KW_dam: // cf+ alias, not original cf
160 case KW_damage: thawer.get (mt->damage); break;
161 case KW_wc: thawer.get (mt->wc); break;
162 case KW_ac: thawer.get (mt->ac); break;
163 case KW_sp: thawer.get (mt->sp); break;
164 case KW_weight: thawer.get (mt->weight); break;
165 case KW_value: thawer.get (mt->value); break;
166 case KW_density: thawer.get (mt->density); break;
167
168 case KW_EOF:
169 goto done;
170
171 default:
172 if (!thawer.parse_error ("materials file", "materials"))
173 goto done;
174 break;
175 }
176
177 thawer.next ();
178 }
179
180 done:
181 if (!materialt)
182 materialt = get_empty_mat ();
183
184 LOG (llevDebug, "Done.\n");
185 }
186
187 /* This loads the settings file. There could be debate whether this should
188 * be here or in the common directory - but since only the server needs this
189 * information, having it here probably makes more sense.
190 */
191 void
192 load_settings (void)
193 {
194 char buf[MAX_BUF], *cp;
195 int has_val, comp;
196 FILE *fp;
197
198 sprintf (buf, "%s/settings", settings.confdir);
199
200 /* We don't require a settings file at current time, but down the road,
201 * there will probably be so many values that not having a settings file
202 * will not be a good thing.
203 */
204 if (!(fp = open_and_uncompress (buf, 0, &comp)))
205 {
206 LOG (llevError, "Error: No settings file found\n");
207 exit (1);
208 }
209
210 while (fgets (buf, MAX_BUF - 1, fp) != NULL)
211 {
212 if (buf[0] == '#')
213 continue;
214 /* eliminate newline */
215 if ((cp = strrchr (buf, '\n')) != NULL)
216 *cp = '\0';
217
218 /* Skip over empty lines */
219 if (buf[0] == 0)
220 continue;
221
222 /* Skip all the spaces and set them to nulls. If not space,
223 * set cp to "" to make strcpy's and the like easier down below.
224 */
225 if ((cp = strchr (buf, ' ')) != NULL)
226 {
227 while (*cp == ' ')
228 *cp++ = 0;
229 has_val = 1;
230 }
231 else
232 {
233 cp = (char *)"";
234 has_val = 0;
235 }
236
237 if (!strcasecmp (buf, "not_permadeth"))
238 {
239 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true"))
240 {
241 settings.not_permadeth = TRUE;
242 }
243 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false"))
244 {
245 settings.not_permadeth = FALSE;
246 }
247 else
248 {
249 LOG (llevError, "load_settings: Unknown value for not_permadeth" ": %s\n", cp);
250 }
251 }
252 else if (!strcasecmp (buf, "resurrection"))
253 {
254 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true"))
255 {
256 settings.resurrection = TRUE;
257 }
258 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false"))
259 {
260 settings.resurrection = FALSE;
261 }
262 else
263 {
264 LOG (llevError, "load_settings: Unknown value for resurrection" ": %s\n", cp);
265 }
266 }
267 else if (!strcasecmp (buf, "set_title"))
268 {
269 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true"))
270 {
271 settings.set_title = TRUE;
272 }
273 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false"))
274 {
275 settings.set_title = FALSE;
276 }
277 else
278 {
279 LOG (llevError, "load_settings: Unknown value for set_title" ": %s\n", cp);
280 }
281 }
282 else if (!strcasecmp (buf, "search_items"))
283 {
284 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true"))
285 {
286 settings.search_items = TRUE;
287 }
288 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false"))
289 {
290 settings.search_items = FALSE;
291 }
292 else
293 {
294 LOG (llevError, "load_settings: Unknown value for search_items" ": %s\n", cp);
295 }
296 }
297 else if (!strcasecmp (buf, "spell_encumbrance"))
298 {
299 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true"))
300 {
301 settings.spell_encumbrance = TRUE;
302 }
303 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false"))
304 {
305 settings.spell_encumbrance = FALSE;
306 }
307 else
308 {
309 LOG (llevError, "load_settings: Unknown value for " "spell_encumbrance: %s\n", cp);
310 }
311 }
312 else if (!strcasecmp (buf, "spell_failure_effects"))
313 {
314 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true"))
315 {
316 settings.spell_failure_effects = TRUE;
317 }
318 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false"))
319 {
320 settings.spell_failure_effects = FALSE;
321 }
322 else
323 {
324 LOG (llevError, "load_settings: Unknown value for " "spell_failure_effects: %s\n", cp);
325 }
326 }
327 else if (!strcasecmp (buf, "spellpoint_level_depend"))
328 {
329 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true"))
330 {
331 settings.spellpoint_level_depend = TRUE;
332 }
333 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false"))
334 {
335 settings.spellpoint_level_depend = FALSE;
336 }
337 else
338 {
339 LOG (llevError, "load_settings: Unknown value for " "spellpoint_level_depend: %s\n", cp);
340 }
341 }
342 else if (!strcasecmp (buf, "stat_loss_on_death"))
343 {
344 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true"))
345 {
346 settings.stat_loss_on_death = TRUE;
347 }
348 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false"))
349 {
350 settings.stat_loss_on_death = FALSE;
351 }
352 else
353 {
354 LOG (llevError, "load_settings: Unknown value for " "stat_loss_on_death: %s\n", cp);
355 }
356 }
357 else if (!strcasecmp (buf, "use_permanent_experience"))
358 {
359 LOG (llevError, "use_permanent_experience is deprecated, use" "permenent_experience_percentage instead\n");
360 }
361 else if (!strcasecmp (buf, "permanent_experience_percentage"))
362 {
363 int val = atoi (cp);
364
365 if (val < 0 || val > 100)
366 LOG (llevError, "load_settings: permenent_experience_percentage" "must be between 0 and 100, %d is invalid\n", val);
367 else
368 settings.permanent_exp_ratio = val;
369 }
370 else if (!strcasecmp (buf, "death_penalty_percentage"))
371 {
372 int val = atoi (cp);
373
374 if (val < 0 || val > 100)
375 LOG (llevError, "load_settings: death_penalty_percentage" "must be between 0 and 100, %d is invalid\n", val);
376 else
377 settings.death_penalty_ratio = val;
378 }
379 else if (!strcasecmp (buf, "death_penalty_levels"))
380 {
381 int val = atoi (cp);
382
383 if (val < 0 || val > 255)
384 LOG (llevError, "load_settings: death_penalty_levels" "can not be negative, %d is invalid\n", val);
385 else
386 settings.death_penalty_level = val;
387 }
388 else if (!strcasecmp (buf, "balanced_stat_loss"))
389 {
390 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true"))
391 {
392 settings.balanced_stat_loss = TRUE;
393 }
394 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false"))
395 {
396 settings.balanced_stat_loss = FALSE;
397 }
398 else
399 {
400 LOG (llevError, "load_settings: Unknown value for " "balanced_stat_loss: %s\n", cp);
401 }
402 }
403 else if (!strcasecmp (buf, "simple_exp"))
404 {
405 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true"))
406 {
407 settings.simple_exp = TRUE;
408 }
409 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false"))
410 {
411 settings.simple_exp = FALSE;
412 }
413 else
414 {
415 LOG (llevError, "load_settings: Unknown value for simple_exp: %s\n", cp);
416 }
417 }
418 else if (!strcasecmp (buf, "item_power_factor"))
419 {
420 float tmp = atof (cp);
421
422 if (tmp < 0)
423 LOG (llevError, "load_settings: item_power_factor must be a positive number (%f < 0)\n", tmp);
424 else
425 settings.item_power_factor = tmp;
426 }
427 else if (!strcasecmp (buf, "pk_luck_penalty"))
428 {
429 sint16 val = atoi (cp);
430
431 if (val < -100 || val > 100)
432 LOG (llevError, "load_settings: pk_luck_penalty must be between -100 and 100" ", %d is invalid\n", val);
433 else
434 settings.pk_luck_penalty = val;
435 }
436 else if (!strcasecmp (buf, "set_friendly_fire"))
437 {
438 int val = atoi (cp);
439
440 if (val < 0 || val > 100)
441 LOG (llevError, "load_settings: set_friendly_fire must be between 0 an 100" ", %d is invalid\n", val);
442 else
443 settings.set_friendly_fire = val;
444 }
445 else if (!strcasecmp (buf, "armor_max_enchant"))
446 {
447 int max_e = atoi (cp);
448
449 if (max_e <= 0)
450 LOG (llevError, "load_settings: armor_max_enchant is %d\n", max_e);
451 else
452 settings.armor_max_enchant = max_e;
453 }
454 else if (!strcasecmp (buf, "armor_weight_reduction"))
455 {
456 int wr = atoi (cp);
457
458 if (wr < 0)
459 LOG (llevError, "load_settings: armor_weight_reduction is %d\n", wr);
460 else
461 settings.armor_weight_reduction = wr;
462 }
463 else if (!strcasecmp (buf, "armor_weight_linear"))
464 {
465 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true"))
466 {
467 settings.armor_weight_linear = TRUE;
468 }
469 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false"))
470 {
471 settings.armor_weight_linear = FALSE;
472 }
473 else
474 {
475 LOG (llevError, "load_settings: unknown value for armor_weight_linear: %s\n", cp);
476 }
477
478 }
479 else if (!strcasecmp (buf, "armor_speed_improvement"))
480 {
481 int wr = atoi (cp);
482
483 if (wr < 0)
484 LOG (llevError, "load_settings: armor_speed_improvement is %d\n", wr);
485 else
486 settings.armor_speed_improvement = wr;
487 }
488 else if (!strcasecmp (buf, "armor_speed_linear"))
489 {
490 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true"))
491 {
492 settings.armor_speed_linear = TRUE;
493 }
494 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false"))
495 {
496 settings.armor_speed_linear = FALSE;
497 }
498 else
499 {
500 LOG (llevError, "load_settings: unknown value for armor_speed_linear: %s\n", cp);
501 }
502
503 }
504 else
505 LOG (llevError, "Unknown value in settings file: %s\n", buf);
506 }
507
508 close_and_delete (fp, comp);
509 }
510
511 /*
512 * init() is called only once, when starting the program.
513 */
514 void
515 init (int argc, char **argv)
516 {
517 init_done = 0; /* Must be done before init_signal() */
518
519 init_environ ();
520 cfperl_init ();
521 init_done = 1;
522 }
523
524 void
525 usage (void)
526 {
527 fprintf (stderr, "Usage: deliantra-server [-h] [-<flags>]...\n");
528 }
529
530 void
531 help (void)
532 {
533
534 /* The information in usage is redundant with what is given below, so why call it? */
535
536 /* usage();*/
537 printf ("Flags:\n");
538 printf (" -csport <port> Specifies the port to use for the new client/server code.\n");
539 printf (" -d Turns on some debugging.\n");
540 printf (" +d Turns off debugging (useful if server compiled with debugging\n");
541 printf (" as default).\n");
542 printf (" -detach The server will go in the background, closing all\n");
543 printf (" connections to the tty.\n");
544 printf (" -h Display this information.\n");
545 printf (" -log <file> Specifies which file to send output to.\n");
546 printf (" Only has meaning if -detach is specified.\n");
547 printf (" -mon Turns on monster debugging.\n");
548 printf (" -o Prints out info on what was defined at compile time.\n");
549 printf (" -s Display the high-score list.\n");
550 printf (" -score <name or class> Displays all high scores with matching name/class.\n");
551 printf (" -v Print version and contributors.\n");
552 printf (" -data Sets the lib dir (archetypes, treasures, etc.)\n");
553 printf (" -local Read/write local data (hiscore, unique items, etc.)\n");
554 printf (" -maps Sets the directory for maps.\n");
555 printf (" -arch Sets the archetype file to use.\n");
556 printf (" -regions Sets the regions file to use.\n");
557 printf (" -playerdir Sets the directory for the player files.\n");
558 printf (" -templatedir Sets the directory for template generate maps.\n");
559 printf (" -treasures Sets the treasures file to use.\n");
560 printf (" -uniquedir Sets the unique items/maps directory.\n");
561 printf (" -tmpdir Sets the directory for temporary files (mostly maps.)\n");
562 printf (" -m Lists out suggested experience for all monsters.\n");
563 printf (" -m2 Dumps out abilities.\n");
564 printf (" -m3 Dumps out artifact information.\n");
565 printf (" -m4 Dumps out spell information.\n");
566 printf (" -m5 Dumps out skill information.\n");
567 printf (" -m6 Dumps out race information.\n");
568 printf (" -m7 Dumps out alchemy information.\n");
569 printf (" -m8 Dumps out gods information.\n");
570 printf (" -m9 Dumps out more alchemy information (formula checking).\n");
571 printf (" -mt <name> Dumps out list of treasures for a monster.\n");
572 exit (0);
573 }
574
575 void
576 init_beforeplay (void)
577 {
578 init_artifacts (); /* If not called before, reads all artifacts from file */
579 init_races (); /* overwrite race designations using entries in lib/races file */
580 init_gods (); /* init linked list of gods from archs */
581 init_readable (); /* inits useful arrays for readable texts */
582 init_formulae (); /* If not called before, reads formulae from file */
583 }
584
585 /* Signal handlers: */
586
587 static void
588 rec_sigabrt (int i)
589 {
590 signal (SIGABRT, SIG_DFL);
591
592 LOG (llevError, "SIGABRT received.\n");
593 cleanup ("SIGABRT received", 1);
594 }
595
596 static void
597 rec_sigsegv (int i)
598 {
599 signal (SIGSEGV, SIG_DFL);
600
601 LOG (llevError, "SIGSEGV received.\n");
602 cleanup ("SIGSEGV received", 1);
603 }
604
605 static void
606 rec_sigquit (int i)
607 {
608 signal (SIGQUIT, SIG_IGN);
609
610 LOG (llevInfo, "SIGQUIT received\n");
611 cleanup ("SIGQUIT received", 1);
612 }
613
614 static void
615 rec_sigbus (int i)
616 {
617 signal (SIGBUS, SIG_DFL);
618
619 LOG (llevError, "SIGBUS received\n");
620 cleanup ("SIGBUS received", 1);
621 }
622
623 void
624 reset_signals ()
625 {
626 signal (SIGABRT, SIG_DFL);
627 signal (SIGQUIT, SIG_DFL);
628 signal (SIGSEGV, SIG_DFL);
629 signal (SIGBUS , SIG_DFL);
630 signal (SIGINT , SIG_DFL);
631 signal (SIGTERM, SIG_DFL);
632 }
633
634 void
635 init_signals (void)
636 {
637 // large stack, but it's important data we want to save, and it is not usually
638 // being physically allocated anyways
639 const size_t stacksize = 8 * 1024 * 1024 + SIGSTKSZ;
640
641 stack_t ss;
642 ss.ss_sp = malloc (stacksize);
643 ss.ss_flags = 0;
644 ss.ss_size = stacksize;
645 sigaltstack (&ss, 0);
646
647 struct sigaction sa;
648
649 sigfillset (&sa.sa_mask);
650 sa.sa_flags = SA_RESTART;
651
652 sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0);
653 sa.sa_handler = rec_sigabrt; sigaction (SIGABRT, &sa, 0);
654 sa.sa_handler = rec_sigquit; sigaction (SIGQUIT, &sa, 0);
655 sa.sa_handler = rec_sigbus; sigaction (SIGBUS, &sa, 0);
656
657 sa.sa_flags |= SA_ONSTACK;
658 sa.sa_handler = rec_sigsegv; sigaction (SIGSEGV, &sa, 0);
659 }
660
661 /* init_races() - reads the races file in the lib/ directory, then
662 * overwrites old 'race' entries. This routine allow us to quickly
663 * re-configure the 'alignment' of monsters, objects. Useful for
664 * putting together lists of creatures, etc that belong to gods.
665 */
666 void
667 init_races (void)
668 {
669 FILE *file;
670 char race[MAX_BUF], fname[MAX_BUF], buf[MAX_BUF], *cp, variable[MAX_BUF];
671 archetype *mon = NULL;
672 static int init_done = 0;
673
674 if (init_done)
675 return;
676 init_done = 1;
677 first_race = 0;
678
679 sprintf (fname, "%s/races", settings.datadir);
680 LOG (llevDebug, "Reading races from %s...\n", fname);
681 if (!(file = fopen (fname, "r")))
682 {
683 LOG (llevError, "Cannot open races file %s: %s\n", fname, strerror (errno));
684 return;
685 }
686
687 while (fgets (buf, MAX_BUF, file) != NULL)
688 {
689 int set_race = 1, set_list = 1;
690
691 if (*buf == '#')
692 continue;
693
694 if ((cp = strchr (buf, '\n')) != NULL)
695 *cp = '\0';
696
697 cp = buf;
698 while (*cp == ' ' || *cp == '!' || *cp == '@')
699 {
700 if (*cp == '!') set_race = 0;
701 if (*cp == '@') set_list = 0;
702
703 cp++;
704 }
705
706 if (sscanf (cp, "RACE %s", variable))
707 /* set new race value */
708 strcpy (race, variable);
709 else
710 {
711 char *cp1;
712
713 /* Take out beginning spaces */
714 for (cp1 = cp; *cp1 == ' '; cp1++)
715 ;
716 /* Remove newline and trailing spaces */
717 for (cp1 = cp + strlen (cp) - 1; *cp1 == '\n' || *cp1 == ' '; cp1--)
718 {
719 *cp1 = '\0';
720 if (cp == cp1)
721 break;
722 }
723
724 if (cp[strlen (cp) - 1] == '\n')
725 cp[strlen (cp) - 1] = '\0';
726
727 /* set creature race to race value */
728 if ((mon = archetype::find (cp)) == NULL)
729 LOG (llevError, "Creature %s in race file lacks archetype\n", cp);
730 else
731 {
732 if (set_race && (!mon->race || strcmp (&mon->race, race)))
733 {
734 if (mon->race)
735 LOG (llevDebug, "Resetting race to %s from %s for archetype %s\n", race, &mon->race, &mon->archname);
736
737 mon->race = race;
738 }
739
740 /* if the arch is a monster, add it to the race list */
741 if (set_list && QUERY_FLAG (mon, FLAG_MONSTER))
742 add_to_racelist (race, mon);
743 }
744 }
745 }
746
747 fclose (file);
748 LOG (llevDebug, "done.\n");
749 }
750
751 void
752 dump_races (void)
753 {
754 racelink *list;
755 objectlink *tmp;
756
757 for (list = first_race; list; list = list->next)
758 {
759 fprintf (stderr, "\nRACE %s:\t", &list->name);
760 for (tmp = list->member; tmp; tmp = tmp->next)
761 fprintf (stderr, "%s(%d), ", &tmp->ob->arch->archname, tmp->ob->level);
762 }
763
764 fprintf (stderr, "\n");
765 }
766
767 void
768 add_to_racelist (const char *race_name, object *op)
769 {
770 racelink *race;
771
772 if (!op || !race_name)
773 return;
774
775 race = find_racelink (race_name);
776
777 if (!race)
778 { /* add in a new race list */
779 race = get_racelist ();
780 race->next = first_race;
781 first_race = race;
782 race->name = race_name;
783 }
784
785 if (race->member->ob)
786 {
787 objectlink *tmp = get_objectlink ();
788
789 tmp->next = race->member;
790 race->member = tmp;
791 }
792
793 race->nrof++;
794 race->member->ob = op;
795 }
796
797 racelink *
798 get_racelist ()
799 {
800 racelink *list = new racelink;
801
802 list->name = 0;
803 list->nrof = 0;
804 list->next = 0;
805 list->member = get_objectlink ();
806
807 return list;
808 }
809
810 racelink *
811 find_racelink (const char *name)
812 {
813 if (name)
814 for (racelink *link = first_race; link; link = link->next)
815 if (!link->name || !strcmp (name, link->name))
816 return link;
817
818 return 0;
819 }