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

Comparing deliantra/server/server/init.C (file contents):
Revision 1.73 by root, Wed Nov 4 00:08:44 2009 UTC vs.
Revision 1.83 by root, Sat Apr 23 04:56:56 2011 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 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011 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.
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#include <loader.h>
28#include <sproto.h> 27#include <sproto.h>
29 28
30/* This loads the settings file. There could be debate whether this should 29/* 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 30 * be here or in the common directory - but since only the server needs this
32 * information, having it here probably makes more sense. 31 * information, having it here probably makes more sense.
33 */ 32 */
34void 33void
35load_settings (void) 34load_settings ()
36{ 35{
37 char buf[MAX_BUF], *cp; 36 object_thawer thawer (settings.confdir, "settings");
38 int has_val, comp;
39 FILE *fp;
40 37
41 sprintf (buf, "%s/settings", settings.confdir); 38 if (!thawer)
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 { 39 {
49 LOG (llevError, "Error: No settings file found\n"); 40 LOG (llevError, "Error: No settings file found\n");
50 exit (1); 41 exit (1);
51 } 42 }
52 43
53 while (fgets (buf, MAX_BUF - 1, fp) != NULL) 44 while (thawer.kw)
54 { 45 {
55 if (buf[0] == '#') 46 const char *buf = thawer.kw_str;
56 continue; 47 const char *cp = thawer.value_nn;
57 /* eliminate newline */
58 if ((cp = strrchr (buf, '\n')) != NULL)
59 *cp = '\0';
60 48
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")) 49 if (!strcmp (buf, "not_permadeth"))
81 { 50 {
82 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 51 if (!strcmp (cp, "on") || !strcmp (cp, "true"))
83 { 52 {
84 settings.not_permadeth = TRUE; 53 settings.not_permadeth = TRUE;
85 } 54 }
86 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) 55 else if (!strcmp (cp, "off") || !strcmp (cp, "false"))
87 { 56 {
88 settings.not_permadeth = FALSE; 57 settings.not_permadeth = FALSE;
89 } 58 }
90 else 59 else
91 { 60 {
92 LOG (llevError, "load_settings: Unknown value for not_permadeth" ": %s\n", cp); 61 LOG (llevError, "load_settings: Unknown value for not_permadeth" ": %s\n", cp);
93 } 62 }
94 } 63 }
95 else if (!strcasecmp (buf, "resurrection")) 64 else if (!strcmp (buf, "resurrection"))
96 { 65 {
97 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 66 if (!strcmp (cp, "on") || !strcmp (cp, "true"))
98 { 67 {
99 settings.resurrection = TRUE; 68 settings.resurrection = TRUE;
100 } 69 }
101 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) 70 else if (!strcmp (cp, "off") || !strcmp (cp, "false"))
102 { 71 {
103 settings.resurrection = FALSE; 72 settings.resurrection = FALSE;
104 } 73 }
105 else 74 else
106 { 75 {
107 LOG (llevError, "load_settings: Unknown value for resurrection" ": %s\n", cp); 76 LOG (llevError, "load_settings: Unknown value for resurrection" ": %s\n", cp);
108 } 77 }
109 } 78 }
110 else if (!strcasecmp (buf, "set_title")) 79 else if (!strcmp (buf, "set_title"))
111 { 80 {
112 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 81 if (!strcmp (cp, "on") || !strcmp (cp, "true"))
113 { 82 {
114 settings.set_title = TRUE; 83 settings.set_title = TRUE;
115 } 84 }
116 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) 85 else if (!strcmp (cp, "off") || !strcmp (cp, "false"))
117 { 86 {
118 settings.set_title = FALSE; 87 settings.set_title = FALSE;
119 } 88 }
120 else 89 else
121 { 90 {
122 LOG (llevError, "load_settings: Unknown value for set_title" ": %s\n", cp); 91 LOG (llevError, "load_settings: Unknown value for set_title" ": %s\n", cp);
123 } 92 }
124 } 93 }
125 else if (!strcasecmp (buf, "search_items")) 94 else if (!strcmp (buf, "search_items"))
126 { 95 {
127 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 96 if (!strcmp (cp, "on") || !strcmp (cp, "true"))
128 { 97 {
129 settings.search_items = TRUE; 98 settings.search_items = TRUE;
130 } 99 }
131 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) 100 else if (!strcmp (cp, "off") || !strcmp (cp, "false"))
132 { 101 {
133 settings.search_items = FALSE; 102 settings.search_items = FALSE;
134 } 103 }
135 else 104 else
136 { 105 {
137 LOG (llevError, "load_settings: Unknown value for search_items" ": %s\n", cp); 106 LOG (llevError, "load_settings: Unknown value for search_items" ": %s\n", cp);
138 } 107 }
139 } 108 }
140 else if (!strcasecmp (buf, "spell_encumbrance")) 109 else if (!strcmp (buf, "spell_encumbrance"))
141 { 110 {
142 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 111 if (!strcmp (cp, "on") || !strcmp (cp, "true"))
143 { 112 {
144 settings.spell_encumbrance = TRUE; 113 settings.spell_encumbrance = TRUE;
145 } 114 }
146 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) 115 else if (!strcmp (cp, "off") || !strcmp (cp, "false"))
147 { 116 {
148 settings.spell_encumbrance = FALSE; 117 settings.spell_encumbrance = FALSE;
149 } 118 }
150 else 119 else
151 { 120 {
152 LOG (llevError, "load_settings: Unknown value for " "spell_encumbrance: %s\n", cp); 121 LOG (llevError, "load_settings: Unknown value for " "spell_encumbrance: %s\n", cp);
153 } 122 }
154 } 123 }
155 else if (!strcasecmp (buf, "spell_failure_effects")) 124 else if (!strcmp (buf, "spell_failure_effects"))
156 { 125 {
157 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 126 if (!strcmp (cp, "on") || !strcmp (cp, "true"))
158 { 127 {
159 settings.spell_failure_effects = TRUE; 128 settings.spell_failure_effects = TRUE;
160 } 129 }
161 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) 130 else if (!strcmp (cp, "off") || !strcmp (cp, "false"))
162 { 131 {
163 settings.spell_failure_effects = FALSE; 132 settings.spell_failure_effects = FALSE;
164 } 133 }
165 else 134 else
166 { 135 {
167 LOG (llevError, "load_settings: Unknown value for " "spell_failure_effects: %s\n", cp); 136 LOG (llevError, "load_settings: Unknown value for " "spell_failure_effects: %s\n", cp);
168 } 137 }
169 } 138 }
170 else if (!strcasecmp (buf, "spellpoint_level_depend")) 139 else if (!strcmp (buf, "spellpoint_level_depend"))
171 { 140 {
172 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 141 if (!strcmp (cp, "on") || !strcmp (cp, "true"))
173 { 142 {
174 settings.spellpoint_level_depend = TRUE; 143 settings.spellpoint_level_depend = TRUE;
175 } 144 }
176 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) 145 else if (!strcmp (cp, "off") || !strcmp (cp, "false"))
177 { 146 {
178 settings.spellpoint_level_depend = FALSE; 147 settings.spellpoint_level_depend = FALSE;
179 } 148 }
180 else 149 else
181 { 150 {
182 LOG (llevError, "load_settings: Unknown value for " "spellpoint_level_depend: %s\n", cp); 151 LOG (llevError, "load_settings: Unknown value for " "spellpoint_level_depend: %s\n", cp);
183 } 152 }
184 } 153 }
185 else if (!strcasecmp (buf, "stat_loss_on_death")) 154 else if (!strcmp (buf, "stat_loss_on_death"))
186 { 155 {
187 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 156 if (!strcmp (cp, "on") || !strcmp (cp, "true"))
188 { 157 {
189 settings.stat_loss_on_death = TRUE; 158 settings.stat_loss_on_death = TRUE;
190 } 159 }
191 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) 160 else if (!strcmp (cp, "off") || !strcmp (cp, "false"))
192 { 161 {
193 settings.stat_loss_on_death = FALSE; 162 settings.stat_loss_on_death = FALSE;
194 } 163 }
195 else 164 else
196 { 165 {
197 LOG (llevError, "load_settings: Unknown value for " "stat_loss_on_death: %s\n", cp); 166 LOG (llevError, "load_settings: Unknown value for " "stat_loss_on_death: %s\n", cp);
198 } 167 }
199 } 168 }
200 else if (!strcasecmp (buf, "use_permanent_experience")) 169 else if (!strcmp (buf, "use_permanent_experience"))
201 { 170 {
202 LOG (llevError, "use_permanent_experience is deprecated, use" "permenent_experience_percentage instead\n"); 171 LOG (llevError, "use_permanent_experience is deprecated, use" "permenent_experience_percentage instead\n");
203 } 172 }
204 else if (!strcasecmp (buf, "permanent_experience_percentage")) 173 else if (!strcmp (buf, "permanent_experience_percentage"))
205 { 174 {
206 int val = atoi (cp); 175 int val = atoi (cp);
207 176
208 if (val < 0 || val > 100) 177 if (val < 0 || val > 100)
209 LOG (llevError, "load_settings: permenent_experience_percentage" "must be between 0 and 100, %d is invalid\n", val); 178 LOG (llevError, "load_settings: permenent_experience_percentage" "must be between 0 and 100, %d is invalid\n", val);
210 else 179 else
211 settings.permanent_exp_ratio = val; 180 settings.permanent_exp_ratio = val;
212 } 181 }
213 else if (!strcasecmp (buf, "death_penalty_percentage")) 182 else if (!strcmp (buf, "death_penalty_percentage"))
214 { 183 {
215 int val = atoi (cp); 184 int val = atoi (cp);
216 185
217 if (val < 0 || val > 100) 186 if (val < 0 || val > 100)
218 LOG (llevError, "load_settings: death_penalty_percentage" "must be between 0 and 100, %d is invalid\n", val); 187 LOG (llevError, "load_settings: death_penalty_percentage" "must be between 0 and 100, %d is invalid\n", val);
219 else 188 else
220 settings.death_penalty_ratio = val; 189 settings.death_penalty_ratio = val;
221 } 190 }
222 else if (!strcasecmp (buf, "death_penalty_levels")) 191 else if (!strcmp (buf, "death_penalty_levels"))
223 { 192 {
224 int val = atoi (cp); 193 int val = atoi (cp);
225 194
226 if (val < 0 || val > 255) 195 if (val < 0 || val > 255)
227 LOG (llevError, "load_settings: death_penalty_levels" "can not be negative, %d is invalid\n", val); 196 LOG (llevError, "load_settings: death_penalty_levels" "can not be negative, %d is invalid\n", val);
228 else 197 else
229 settings.death_penalty_level = val; 198 settings.death_penalty_level = val;
230 } 199 }
231 else if (!strcasecmp (buf, "balanced_stat_loss")) 200 else if (!strcmp (buf, "balanced_stat_loss"))
232 { 201 {
233 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 202 if (!strcmp (cp, "on") || !strcmp (cp, "true"))
234 { 203 {
235 settings.balanced_stat_loss = TRUE; 204 settings.balanced_stat_loss = TRUE;
236 } 205 }
237 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) 206 else if (!strcmp (cp, "off") || !strcmp (cp, "false"))
238 { 207 {
239 settings.balanced_stat_loss = FALSE; 208 settings.balanced_stat_loss = FALSE;
240 } 209 }
241 else 210 else
242 { 211 {
243 LOG (llevError, "load_settings: Unknown value for " "balanced_stat_loss: %s\n", cp); 212 LOG (llevError, "load_settings: Unknown value for " "balanced_stat_loss: %s\n", cp);
244 } 213 }
245 } 214 }
246 else if (!strcasecmp (buf, "simple_exp")) 215 else if (!strcmp (buf, "simple_exp"))
247 { 216 {
248 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 217 if (!strcmp (cp, "on") || !strcmp (cp, "true"))
249 { 218 {
250 settings.simple_exp = TRUE; 219 settings.simple_exp = TRUE;
251 } 220 }
252 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) 221 else if (!strcmp (cp, "off") || !strcmp (cp, "false"))
253 { 222 {
254 settings.simple_exp = FALSE; 223 settings.simple_exp = FALSE;
255 } 224 }
256 else 225 else
257 { 226 {
258 LOG (llevError, "load_settings: Unknown value for simple_exp: %s\n", cp); 227 LOG (llevError, "load_settings: Unknown value for simple_exp: %s\n", cp);
259 } 228 }
260 } 229 }
261 else if (!strcasecmp (buf, "item_power_factor")) 230 else if (!strcmp (buf, "item_power_factor"))
262 { 231 {
263 float tmp = atof (cp); 232 float tmp = atof (cp);
264 233
265 if (tmp < 0) 234 if (tmp < 0)
266 LOG (llevError, "load_settings: item_power_factor must be a positive number (%f < 0)\n", tmp); 235 LOG (llevError, "load_settings: item_power_factor must be a positive number (%f < 0)\n", tmp);
267 else 236 else
268 settings.item_power_factor = tmp; 237 settings.item_power_factor = tmp;
269 } 238 }
270 else if (!strcasecmp (buf, "pk_luck_penalty")) 239 else if (!strcmp (buf, "pk_luck_penalty"))
271 { 240 {
272 sint16 val = atoi (cp); 241 sint16 val = atoi (cp);
273 242
274 if (val < -100 || val > 100) 243 if (val < -100 || val > 100)
275 LOG (llevError, "load_settings: pk_luck_penalty must be between -100 and 100" ", %d is invalid\n", val); 244 LOG (llevError, "load_settings: pk_luck_penalty must be between -100 and 100" ", %d is invalid\n", val);
276 else 245 else
277 settings.pk_luck_penalty = val; 246 settings.pk_luck_penalty = val;
278 } 247 }
279 else if (!strcasecmp (buf, "set_friendly_fire")) 248 else if (!strcmp (buf, "set_friendly_fire"))
280 { 249 {
281 int val = atoi (cp); 250 int val = atoi (cp);
282 251
283 if (val < 0 || val > 100) 252 if (val < 0 || val > 100)
284 LOG (llevError, "load_settings: set_friendly_fire must be between 0 an 100" ", %d is invalid\n", val); 253 LOG (llevError, "load_settings: set_friendly_fire must be between 0 an 100" ", %d is invalid\n", val);
285 else 254 else
286 settings.set_friendly_fire = val; 255 settings.set_friendly_fire = val;
287 } 256 }
288 else if (!strcasecmp (buf, "armor_max_enchant")) 257 else if (!strcmp (buf, "armor_max_enchant"))
289 { 258 {
290 int max_e = atoi (cp); 259 int max_e = atoi (cp);
291 260
292 if (max_e <= 0) 261 if (max_e <= 0)
293 LOG (llevError, "load_settings: armor_max_enchant is %d\n", max_e); 262 LOG (llevError, "load_settings: armor_max_enchant is %d\n", max_e);
294 else 263 else
295 settings.armor_max_enchant = max_e; 264 settings.armor_max_enchant = max_e;
296 } 265 }
297 else if (!strcasecmp (buf, "armor_weight_reduction")) 266 else if (!strcmp (buf, "armor_weight_reduction"))
298 { 267 {
299 int wr = atoi (cp); 268 int wr = atoi (cp);
300 269
301 if (wr < 0) 270 if (wr < 0)
302 LOG (llevError, "load_settings: armor_weight_reduction is %d\n", wr); 271 LOG (llevError, "load_settings: armor_weight_reduction is %d\n", wr);
303 else 272 else
304 settings.armor_weight_reduction = wr; 273 settings.armor_weight_reduction = wr;
305 } 274 }
306 else if (!strcasecmp (buf, "armor_weight_linear")) 275 else if (!strcmp (buf, "armor_weight_linear"))
307 { 276 {
308 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 277 if (!strcmp (cp, "on") || !strcmp (cp, "true"))
309 { 278 {
310 settings.armor_weight_linear = TRUE; 279 settings.armor_weight_linear = TRUE;
311 } 280 }
312 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) 281 else if (!strcmp (cp, "off") || !strcmp (cp, "false"))
313 { 282 {
314 settings.armor_weight_linear = FALSE; 283 settings.armor_weight_linear = FALSE;
315 } 284 }
316 else 285 else
317 { 286 {
318 LOG (llevError, "load_settings: unknown value for armor_weight_linear: %s\n", cp); 287 LOG (llevError, "load_settings: unknown value for armor_weight_linear: %s\n", cp);
319 } 288 }
320 289
321 } 290 }
322 else if (!strcasecmp (buf, "armor_speed_improvement")) 291 else if (!strcmp (buf, "armor_speed_improvement"))
323 { 292 {
324 int wr = atoi (cp); 293 int wr = atoi (cp);
325 294
326 if (wr < 0) 295 if (wr < 0)
327 LOG (llevError, "load_settings: armor_speed_improvement is %d\n", wr); 296 LOG (llevError, "load_settings: armor_speed_improvement is %d\n", wr);
328 else 297 else
329 settings.armor_speed_improvement = wr; 298 settings.armor_speed_improvement = wr;
330 } 299 }
331 else if (!strcasecmp (buf, "armor_speed_linear")) 300 else if (!strcmp (buf, "armor_speed_linear"))
332 { 301 {
333 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 302 if (!strcmp (cp, "on") || !strcmp (cp, "true"))
334 { 303 {
335 settings.armor_speed_linear = TRUE; 304 settings.armor_speed_linear = TRUE;
336 } 305 }
337 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) 306 else if (!strcmp (cp, "off") || !strcmp (cp, "false"))
338 { 307 {
339 settings.armor_speed_linear = FALSE; 308 settings.armor_speed_linear = FALSE;
340 } 309 }
341 else 310 else
342 { 311 {
343 LOG (llevError, "load_settings: unknown value for armor_speed_linear: %s\n", cp); 312 LOG (llevError, "load_settings: unknown value for armor_speed_linear: %s\n", cp);
344 } 313 }
345 314
346 } 315 }
347 else 316 else
348 LOG (llevError, "Unknown value in settings file: %s\n", buf); 317 thawer.parse_error ("settings file");
318
319 thawer.next ();
349 } 320 }
350
351 close_and_delete (fp, comp);
352} 321}
353 322
354/* 323/*
355 * init() is called only once, when starting the program. 324 * init() is called only once, when starting the program.
356 */ 325 */
360 init_done = 0; /* Must be done before init_signal() */ 329 init_done = 0; /* Must be done before init_signal() */
361 330
362 init_environ (); 331 init_environ ();
363 cfperl_init (); 332 cfperl_init ();
364 init_done = 1; 333 init_done = 1;
365}
366
367void
368usage (void)
369{
370 fprintf (stderr, "Usage: deliantra-server [-h] [-<flags>]...\n");
371}
372
373void
374help (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
418void
419init_beforeplay (void)
420{
421 init_artifacts (); /* If not called before, reads all artifacts from file */
422 init_races (); /* overwrite race designations using entries in lib/races file */
423 init_gods (); /* init linked list of gods from archs */
424 init_readable (); /* inits useful arrays for readable texts */
425 init_formulae (); /* If not called before, reads formulae from file */
426} 334}
427 335
428/* Signal handlers: */ 336/* Signal handlers: */
429 337
430static void 338static void
473 signal (SIGINT , SIG_DFL); 381 signal (SIGINT , SIG_DFL);
474 signal (SIGTERM, SIG_DFL); 382 signal (SIGTERM, SIG_DFL);
475} 383}
476 384
477void 385void
478init_signals (void) 386init_signals ()
479{ 387{
480 // large stack, but it's important data we want to save, and it is not usually 388 // large stack, but it's important data we want to save, and it is not usually
481 // being physically allocated anyways 389 // being physically allocated anyways
482 const size_t stacksize = 8 * 1024 * 1024 + SIGSTKSZ; 390 const size_t stacksize = 8 * 1024 * 1024 + SIGSTKSZ;
483 391
499 407
500 sa.sa_flags |= SA_ONSTACK; 408 sa.sa_flags |= SA_ONSTACK;
501 sa.sa_handler = rec_sigsegv; sigaction (SIGSEGV, &sa, 0); 409 sa.sa_handler = rec_sigsegv; sigaction (SIGSEGV, &sa, 0);
502} 410}
503 411
412static racelink *
413get_racelist ()
414{
415 racelink *list = new racelink;
416
417 list->name = 0;
418 list->nrof = 0;
419 list->next = 0;
420 list->member = get_objectlink ();
421
422 return list;
423}
424
425 racelink *
426find_racelink (const char *name)
427{
428 if (name)
429 for (racelink *link = first_race; link; link = link->next)
430 if (!link->name || !strcmp (name, link->name))
431 return link;
432
433 return 0;
434}
435
436static void
437add_to_racelist (const char *race_name, object *op)
438{
439 racelink *race;
440
441 if (!op || !race_name)
442 return;
443
444 race = find_racelink (race_name);
445
446 if (!race)
447 { /* add in a new race list */
448 race = get_racelist ();
449 race->next = first_race;
450 first_race = race;
451 race->name = race_name;
452 }
453
454 if (race->member->ob)
455 {
456 objectlink *tmp = get_objectlink ();
457
458 tmp->next = race->member;
459 race->member = tmp;
460 }
461
462 race->nrof++;
463 race->member->ob = op;
464}
465
504/* init_races() - reads the races file in the lib/ directory, then 466/* init_races() - reads the races file in the lib/ directory, then
505 * overwrites old 'race' entries. This routine allow us to quickly 467 * overwrites old 'race' entries. This routine allow us to quickly
506 * re-configure the 'alignment' of monsters, objects. Useful for 468 * re-configure the 'alignment' of monsters, objects. Useful for
507 * putting together lists of creatures, etc that belong to gods. 469 * putting together lists of creatures, etc that belong to gods.
508 */ 470 */
509void 471static void
510init_races (void) 472init_races ()
511{ 473{
512 FILE *file; 474 FILE *file;
513 char race[MAX_BUF], fname[MAX_BUF], buf[MAX_BUF], *cp, variable[MAX_BUF]; 475 char race[MAX_BUF], fname[MAX_BUF], buf[MAX_BUF], *cp, variable[MAX_BUF];
514 archetype *mon = NULL; 476 archetype *mon = NULL;
515 static int init_done = 0; 477 static int init_done = 0;
579 541
580 mon->race = race; 542 mon->race = race;
581 } 543 }
582 544
583 /* if the arch is a monster, add it to the race list */ 545 /* if the arch is a monster, add it to the race list */
584 if (set_list && QUERY_FLAG (mon, FLAG_MONSTER)) 546 if (set_list && mon->flag [FLAG_MONSTER])
585 add_to_racelist (race, mon); 547 add_to_racelist (race, mon);
586 } 548 }
587 } 549 }
588 } 550 }
589 551
590 fclose (file); 552 fclose (file);
591 LOG (llevDebug, "done.\n"); 553 LOG (llevDebug, "done.\n");
592} 554}
593 555
594void 556void
595dump_races (void) 557init_beforeplay ()
596{ 558{
597 racelink *list; 559 init_artifacts (); /* If not called before, reads all artifacts from file */
598 objectlink *tmp; 560 init_races (); /* overwrite race designations using entries in lib/races file */
599 561 init_gods (); /* init linked list of gods from archs */
600 for (list = first_race; list; list = list->next) 562 init_readable (); /* inits useful arrays for readable texts */
601 { 563 init_formulae (); /* If not called before, reads formulae from file */
602 fprintf (stderr, "\nRACE %s:\t", &list->name);
603 for (tmp = list->member; tmp; tmp = tmp->next)
604 fprintf (stderr, "%s(%d), ", &tmp->ob->arch->archname, tmp->ob->level);
605 }
606
607 fprintf (stderr, "\n");
608} 564}
609 565
610void
611add_to_racelist (const char *race_name, object *op)
612{
613 racelink *race;
614
615 if (!op || !race_name)
616 return;
617
618 race = find_racelink (race_name);
619
620 if (!race)
621 { /* add in a new race list */
622 race = get_racelist ();
623 race->next = first_race;
624 first_race = race;
625 race->name = race_name;
626 }
627
628 if (race->member->ob)
629 {
630 objectlink *tmp = get_objectlink ();
631
632 tmp->next = race->member;
633 race->member = tmp;
634 }
635
636 race->nrof++;
637 race->member->ob = op;
638}
639
640racelink *
641get_racelist ()
642{
643 racelink *list = new racelink;
644
645 list->name = 0;
646 list->nrof = 0;
647 list->next = 0;
648 list->member = get_objectlink ();
649
650 return list;
651}
652
653racelink *
654find_racelink (const char *name)
655{
656 if (name)
657 for (racelink *link = first_race; link; link = link->next)
658 if (!link->name || !strcmp (name, link->name))
659 return link;
660
661 return 0;
662}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines