1 |
/* |
2 |
* static char *rcsid_init_c = |
3 |
* "$Id: init.c,v 1.2 2006/02/03 07:25:25 root Exp $"; |
4 |
*/ |
5 |
|
6 |
/* |
7 |
CrossFire, A Multiplayer game for X-windows |
8 |
|
9 |
Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
10 |
Copyright (C) 1992 Frank Tore Johansen |
11 |
|
12 |
This program is free software; you can redistribute it and/or modify |
13 |
it under the terms of the GNU General Public License as published by |
14 |
the Free Software Foundation; either version 2 of the License, or |
15 |
(at your option) any later version. |
16 |
|
17 |
This program is distributed in the hope that it will be useful, |
18 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
19 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20 |
GNU General Public License for more details. |
21 |
|
22 |
You should have received a copy of the GNU General Public License |
23 |
along with this program; if not, write to the Free Software |
24 |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
25 |
|
26 |
The authors can be reached via e-mail at crossfire-devel@real-time.com |
27 |
*/ |
28 |
|
29 |
#include <global.h> |
30 |
#include <loader.h> |
31 |
#ifndef __CEXTRACT__ |
32 |
#include <sproto.h> |
33 |
#endif |
34 |
|
35 |
/* global weathermap */ |
36 |
weathermap_t **weathermap; |
37 |
|
38 |
void set_logfile(char *val) { settings.logfilename=val; } |
39 |
void call_version(void) { version(NULL); exit(0); } |
40 |
void showscores(void) { display_high_score(NULL,9999,NULL); exit(0); } |
41 |
void set_debug(void) { settings.debug=llevDebug; } |
42 |
void unset_debug(void) { settings.debug=llevInfo; } |
43 |
void set_mondebug(void) { settings.debug=llevMonster; } |
44 |
void set_dumpmon1(void) {settings.dumpvalues=1; } |
45 |
void set_dumpmon2(void) {settings.dumpvalues=2; } |
46 |
void set_dumpmon3(void) {settings.dumpvalues=3; } |
47 |
void set_dumpmon4(void) {settings.dumpvalues=4; } |
48 |
void set_dumpmon5(void) {settings.dumpvalues=5; } |
49 |
void set_dumpmon6(void) {settings.dumpvalues=6; } |
50 |
void set_dumpmon7(void) {settings.dumpvalues=7; } |
51 |
void set_dumpmon8(void) {settings.dumpvalues=8; } |
52 |
void set_dumpmon9(void) {settings.dumpvalues=9; } |
53 |
void set_dumpmont(char *name) {settings.dumpvalues=10; settings.dumparg=name; } |
54 |
void set_daemon(void) {settings.daemonmode=1; } |
55 |
void set_datadir(char *path) { settings.datadir=path; } |
56 |
void set_confdir(char *path) { settings.confdir=path; } |
57 |
void set_localdir(char *path) { settings.localdir=path; } |
58 |
void set_mapdir(char *path) { settings.mapdir=path; } |
59 |
void set_archetypes(char *path) { settings.archetypes=path; } |
60 |
void set_regions(char *path) { settings.regions=path; } |
61 |
void set_treasures(char *path) { settings.treasures=path; } |
62 |
void set_uniquedir(char *path) { settings.uniquedir=path; } |
63 |
void set_templatedir(char *path) { settings.templatedir=path; } |
64 |
void set_playerdir(char *path) { settings.playerdir=path; } |
65 |
void set_tmpdir(char *path) { settings.tmpdir=path; } |
66 |
|
67 |
void showscoresparm(char *data) { |
68 |
display_high_score(NULL,9999,data); |
69 |
exit(0); |
70 |
} |
71 |
|
72 |
void set_csport(char *val) |
73 |
{ |
74 |
settings.csport=atoi(val); |
75 |
#ifndef WIN32 /* ***win32: set_csport: we remove csport error secure check here, do this later */ |
76 |
if (settings.csport<=0 || settings.csport>32765 || |
77 |
(settings.csport<1024 && getuid()!=0)) { |
78 |
LOG(llevError, "%d is an invalid csport number.\n", settings.csport); |
79 |
exit(1); |
80 |
} |
81 |
#endif /* win32 */ |
82 |
} |
83 |
|
84 |
/* Most of this is shamelessly stolen from XSysStats. But since that is |
85 |
* also my program, no problem. |
86 |
*/ |
87 |
struct Command_Line_Options { |
88 |
char *cmd_option; /* how it is called on the command line */ |
89 |
uint8 num_args; /* Number or args it takes */ |
90 |
uint8 pass; /* What pass this should be processed on. */ |
91 |
void (*func)(); /* function to call when we match this. |
92 |
* if num_args is true, than that gets passed |
93 |
* to the function, otherwise nothing is passed |
94 |
*/ |
95 |
}; |
96 |
|
97 |
/* The way this system works is pretty simple - parse_args takes |
98 |
* the options passed to the program and a pass number. If an option |
99 |
* matches both in name and in pass (and we have enough options), |
100 |
* we call the associated function. This makes writing a multi |
101 |
* pass system very easy, and it is very easy to add in new options. |
102 |
*/ |
103 |
struct Command_Line_Options options[] = { |
104 |
|
105 |
/* Pass 1 functions - STuff that can/should be called before we actually |
106 |
* initialize any data. |
107 |
*/ |
108 |
{"-h", 0, 1, help}, |
109 |
/* Honor -help also, since it is somewhat common */ |
110 |
{"-help", 0, 1, help}, |
111 |
{"-v", 0, 1, call_version}, |
112 |
{"-d", 0, 1, set_debug}, |
113 |
{"+d", 0, 1, unset_debug}, |
114 |
{"-mon", 0, 1, set_mondebug}, |
115 |
{"-data",1,1, set_datadir}, |
116 |
{"-conf",1,1, set_confdir}, |
117 |
{"-local",1,1, set_localdir}, |
118 |
{"-maps", 1, 1, set_mapdir}, |
119 |
{"-arch", 1, 1, set_archetypes}, |
120 |
{"-regions", 1, 1, set_regions}, |
121 |
{"-playerdir", 1, 1, set_playerdir}, |
122 |
{"-treasures", 1, 1, set_treasures}, |
123 |
{"-uniquedir", 1, 1, set_uniquedir}, |
124 |
{"-templatedir", 1, 1, set_templatedir}, |
125 |
{"-tmpdir", 1, 1, set_tmpdir}, |
126 |
{"-log", 1, 1, set_logfile}, |
127 |
|
128 |
#ifdef WIN32 |
129 |
/* Windows service stuff */ |
130 |
{"-regsrv", 0, 1, service_register}, |
131 |
{"-unregsrv", 0, 1, service_unregister}, |
132 |
{"-srv", 0, 1, service_handle}, |
133 |
#endif |
134 |
|
135 |
/* Pass 2 functions. Most of these could probably be in pass 1, |
136 |
* as they don't require much of anything to bet set up. |
137 |
*/ |
138 |
{"-csport", 1, 2, set_csport}, |
139 |
{"-detach", 0, 2, set_daemon}, |
140 |
|
141 |
/* Start of pass 3 information. In theory, by pass 3, all data paths |
142 |
* and defaults should have been set up. |
143 |
*/ |
144 |
{"-o", 0, 3, compile_info}, |
145 |
{"-m", 0, 3, set_dumpmon1}, |
146 |
{"-m2", 0, 3, set_dumpmon2}, |
147 |
{"-m3", 0, 3, set_dumpmon3}, |
148 |
{"-m4", 0, 3, set_dumpmon4}, |
149 |
{"-m5", 0, 3, set_dumpmon5}, |
150 |
{"-m6", 0, 3, set_dumpmon6}, |
151 |
{"-m7", 0, 3, set_dumpmon7}, |
152 |
{"-m8", 0, 3, set_dumpmon8}, |
153 |
{"-m9", 0, 3, set_dumpmon9}, |
154 |
{"-mt", 1, 3, set_dumpmont}, |
155 |
{"-mexp", 0, 3, dump_experience}, |
156 |
{"-s", 0, 3, showscores}, |
157 |
{"-score", 1, 3, showscoresparm} |
158 |
}; |
159 |
|
160 |
|
161 |
/* Note since this may be called before the library has been set up, |
162 |
* we don't use any of crossfires built in logging functions. |
163 |
*/ |
164 |
static void parse_args(int argc, char *argv[], int pass) |
165 |
{ |
166 |
size_t i; |
167 |
int on_arg=1; |
168 |
|
169 |
while (on_arg<argc) { |
170 |
for (i=0; i<sizeof(options)/sizeof(struct Command_Line_Options); i++) { |
171 |
if (!strcmp(options[i].cmd_option, argv[on_arg])) { |
172 |
/* Found a matching option, but should not be processed on |
173 |
* this pass. Just skip over it |
174 |
*/ |
175 |
if (options[i].pass != pass) { |
176 |
on_arg += options[i].num_args+1; |
177 |
break; |
178 |
} |
179 |
if (options[i].num_args) { |
180 |
if ((on_arg+options[i].num_args)>=argc) { |
181 |
fprintf(stderr,"%s requires an argument.\n", options[i].cmd_option); |
182 |
exit(1); |
183 |
} |
184 |
else { |
185 |
if (options[i].num_args==1) |
186 |
options[i].func(argv[on_arg+1]); |
187 |
if (options[i].num_args==2) |
188 |
options[i].func(argv[on_arg+1],argv[on_arg+2]); |
189 |
on_arg +=options[i].num_args+1; |
190 |
} |
191 |
} |
192 |
else { /* takes no args */ |
193 |
options[i].func(); |
194 |
on_arg++; |
195 |
} |
196 |
break; |
197 |
} |
198 |
} |
199 |
if (i==sizeof(options)/sizeof(struct Command_Line_Options)) { |
200 |
fprintf(stderr,"Unknown option: %s\n", argv[on_arg]); |
201 |
usage(); |
202 |
exit(1); |
203 |
} |
204 |
} |
205 |
} |
206 |
|
207 |
materialtype_t *materialt; |
208 |
|
209 |
static materialtype_t *get_empty_mat(void) { |
210 |
materialtype_t *mt; |
211 |
int i; |
212 |
|
213 |
mt = (materialtype_t *)malloc(sizeof(materialtype_t)); |
214 |
if (mt == NULL) |
215 |
fatal(OUT_OF_MEMORY); |
216 |
mt->name = NULL; |
217 |
mt->description = NULL; |
218 |
for (i=0; i < NROFATTACKS; i++) { |
219 |
mt->save[i] = 0; |
220 |
mt->mod[i] = 0; |
221 |
} |
222 |
mt->chance = 0; |
223 |
mt->difficulty = 0; |
224 |
mt->magic = 0; |
225 |
mt->damage = 0; |
226 |
mt->wc = 0; |
227 |
mt->ac = 0; |
228 |
mt->sp = 0; |
229 |
mt->weight = 100; |
230 |
mt->value = 100; |
231 |
mt->next = NULL; |
232 |
return mt; |
233 |
} |
234 |
|
235 |
static void load_materials(void) |
236 |
{ |
237 |
char buf[MAX_BUF], filename[MAX_BUF], *cp, *next; |
238 |
FILE *fp; |
239 |
materialtype_t *mt; |
240 |
int i, value; |
241 |
|
242 |
sprintf(filename, "%s/materials", settings.datadir); |
243 |
LOG(llevDebug, "Reading material type data from %s...", filename); |
244 |
if ((fp = fopen(filename, "r")) == NULL) { |
245 |
LOG(llevError, "Cannot open %s for reading\n", filename); |
246 |
mt = get_empty_mat(); |
247 |
mt->next = NULL; |
248 |
materialt = mt; |
249 |
return; |
250 |
} |
251 |
mt = get_empty_mat(); |
252 |
materialt = mt; |
253 |
while (fgets(buf, MAX_BUF, fp) != NULL) { |
254 |
if (*buf=='#') |
255 |
continue; |
256 |
if ((cp=strchr(buf, '\n'))!=NULL) |
257 |
*cp='\0'; |
258 |
cp=buf; |
259 |
while(*cp==' ') /* Skip blanks */ |
260 |
cp++; |
261 |
if (!strncmp(cp, "name", 4)) { |
262 |
/* clean up the previous entry */ |
263 |
if (mt->next != NULL) { |
264 |
if (mt->description == NULL) |
265 |
mt->description = add_string(mt->name); |
266 |
mt = mt->next; |
267 |
} |
268 |
mt->next = get_empty_mat(); |
269 |
mt->name = add_string(strchr(cp, ' ') + 1); |
270 |
} else if (!strncmp(cp, "description", 11)) { |
271 |
mt->description = add_string(strchr(cp, ' ') + 1); |
272 |
} else if (sscanf(cp, "material %d", &value)) { |
273 |
mt->material = value; |
274 |
} else if (!strncmp(cp, "saves", 5)) { |
275 |
cp = strchr(cp, ' ') + 1; |
276 |
for (i=0; i < NROFATTACKS; i++) { |
277 |
if (cp == NULL) { |
278 |
mt->save[i] = 0; |
279 |
continue; |
280 |
} |
281 |
if ((next=strchr(cp,',')) != NULL) |
282 |
*(next++) = '\0'; |
283 |
sscanf(cp, "%d", &value); |
284 |
mt->save[i] = (sint8)value; |
285 |
cp = next; |
286 |
} |
287 |
} else if (!strncmp(cp, "mods", 4)) { |
288 |
cp = strchr(cp, ' ') + 1; |
289 |
for (i=0; i < NROFATTACKS; i++) { |
290 |
if (cp == NULL) { |
291 |
mt->save[i] = 0; |
292 |
continue; |
293 |
} |
294 |
if ((next=strchr(cp,',')) != NULL) |
295 |
*(next++) = '\0'; |
296 |
sscanf(cp, "%d", &value); |
297 |
mt->mod[i] = (sint8)value; |
298 |
cp = next; |
299 |
} |
300 |
} else if (sscanf(cp, "chance %d\n", &value)) { |
301 |
mt->chance = (sint8)value; |
302 |
} else if (sscanf(cp, "diff %d\n", &value)) { |
303 |
mt->difficulty = (sint8)value; |
304 |
} else if (sscanf(cp, "magic %d\n", &value)) { |
305 |
mt->magic = (sint8)value; |
306 |
} else if (sscanf(cp, "damage %d\n", &value)) { |
307 |
mt->damage= (sint8)value; |
308 |
} else if (sscanf(cp, "wc %d\n", &value)) { |
309 |
mt->wc = (sint8)value; |
310 |
} else if (sscanf(cp, "ac %d\n", &value)) { |
311 |
mt->ac = (sint8)value; |
312 |
} else if (sscanf(cp, "sp %d\n", &value)) { |
313 |
mt->sp = (sint8)value; |
314 |
} else if (sscanf(cp, "weight %d\n", &value)) { |
315 |
mt->weight = value; |
316 |
} else if (sscanf(cp, "value %d\n", &value)) { |
317 |
mt->value = value; |
318 |
} |
319 |
} |
320 |
mt->next = NULL; |
321 |
LOG(llevDebug, "Done.\n"); |
322 |
fclose(fp); |
323 |
} |
324 |
|
325 |
/* This loads the settings file. There could be debate whether this should |
326 |
* be here or in the common directory - but since only the server needs this |
327 |
* information, having it here probably makes more sense. |
328 |
*/ |
329 |
static void load_settings(void) |
330 |
{ |
331 |
char buf[MAX_BUF],*cp; |
332 |
int has_val,comp; |
333 |
FILE *fp; |
334 |
|
335 |
sprintf(buf,"%s/settings",settings.confdir); |
336 |
|
337 |
/* We don't require a settings file at current time, but down the road, |
338 |
* there will probably be so many values that not having a settings file |
339 |
* will not be a good thing. |
340 |
*/ |
341 |
if ((fp = open_and_uncompress(buf, 0, &comp)) == NULL) { |
342 |
LOG(llevError,"Warning: No settings file found\n"); |
343 |
return; |
344 |
} |
345 |
while (fgets(buf, MAX_BUF-1, fp) != NULL) { |
346 |
if (buf[0] == '#') continue; |
347 |
/* eliminate newline */ |
348 |
if ((cp=strrchr(buf,'\n'))!=NULL) *cp='\0'; |
349 |
|
350 |
/* Skip over empty lines */ |
351 |
if (buf[0] == 0) continue; |
352 |
|
353 |
/* Skip all the spaces and set them to nulls. If not space, |
354 |
* set cp to "" to make strcpy's and the like easier down below. |
355 |
*/ |
356 |
if ((cp = strchr(buf,' '))!=NULL) { |
357 |
while (*cp==' ') *cp++=0; |
358 |
has_val=1; |
359 |
} else { |
360 |
cp=""; |
361 |
has_val=0; |
362 |
} |
363 |
|
364 |
if (!strcasecmp(buf,"metaserver_notification")) { |
365 |
if (!strcasecmp(cp,"on") || !strcasecmp(cp,"true")) { |
366 |
settings.meta_on=TRUE; |
367 |
} else if (!strcasecmp(cp,"off") || !strcasecmp(cp,"false")) { |
368 |
settings.meta_on=FALSE; |
369 |
} else { |
370 |
LOG(llevError,"load_settings: Unknown value for metaserver_notification: %s\n", |
371 |
cp); |
372 |
} |
373 |
} else if (!strcasecmp(buf,"metaserver_server")) { |
374 |
if (has_val) strcpy(settings.meta_server, cp); |
375 |
else |
376 |
LOG(llevError,"load_settings: metaserver_server must have a value.\n"); |
377 |
} else if (!strcasecmp(buf,"motd")) { |
378 |
if (has_val) |
379 |
strcpy(settings.motd, cp); |
380 |
else |
381 |
LOG(llevError,"load_settings: motd must have a value.\n"); |
382 |
} else if (!strcasecmp(buf,"dm_mail")) { |
383 |
if (has_val) |
384 |
strcpy(settings.dm_mail, cp); |
385 |
else |
386 |
LOG(llevError,"load_settings: dm_mail must have a value.\n"); |
387 |
} else if (!strcasecmp(buf,"metaserver_host")) { |
388 |
if (has_val) strcpy(settings.meta_host, cp); |
389 |
else |
390 |
LOG(llevError,"load_settings: metaserver_host must have a value.\n"); |
391 |
} else if (!strcasecmp(buf,"metaserver_port")) { |
392 |
int port = atoi(cp); |
393 |
|
394 |
if (port<1 || port>65535) |
395 |
LOG(llevError,"load_settings: metaserver_port must be between 1 and 65535, %d is invalid\n", |
396 |
port); |
397 |
else settings.meta_port = port; |
398 |
} else if (!strcasecmp(buf,"metaserver_comment")) { |
399 |
strcpy(settings.meta_comment, cp); |
400 |
} else if (!strcasecmp(buf, "worldmapstartx")) { |
401 |
int size = atoi(cp); |
402 |
|
403 |
if (size < 0) |
404 |
LOG(llevError, "load_settings: worldmapstartx must be at least " |
405 |
"0, %d is invalid\n", size); |
406 |
else |
407 |
settings.worldmapstartx = size; |
408 |
} else if (!strcasecmp(buf, "worldmapstarty")) { |
409 |
int size = atoi(cp); |
410 |
|
411 |
if (size < 0) |
412 |
LOG(llevError, "load_settings: worldmapstarty must be at least " |
413 |
"0, %d is invalid\n", size); |
414 |
else |
415 |
settings.worldmapstarty = size; |
416 |
} else if (!strcasecmp(buf, "worldmaptilesx")) { |
417 |
int size = atoi(cp); |
418 |
|
419 |
if (size < 1) |
420 |
LOG(llevError, "load_settings: worldmaptilesx must be greater " |
421 |
"than 1, %d is invalid\n", size); |
422 |
else |
423 |
settings.worldmaptilesx = size; |
424 |
} else if (!strcasecmp(buf, "worldmaptilesy")) { |
425 |
int size = atoi(cp); |
426 |
|
427 |
if (size < 1) |
428 |
LOG(llevError, "load_settings: worldmaptilesy must be greater " |
429 |
"than 1, %d is invalid\n", size); |
430 |
else |
431 |
settings.worldmaptilesy = size; |
432 |
} else if (!strcasecmp(buf, "worldmaptilesizex")) { |
433 |
int size = atoi(cp); |
434 |
|
435 |
if (size < 1) |
436 |
LOG(llevError, "load_settings: worldmaptilesizex must be " |
437 |
"greater than 1, %d is invalid\n", size); |
438 |
else |
439 |
settings.worldmaptilesizex = size; |
440 |
} else if (!strcasecmp(buf, "worldmaptilesizey")) { |
441 |
int size = atoi(cp); |
442 |
|
443 |
if (size < 1) |
444 |
LOG(llevError, "load_settings: worldmaptilesizey must be " |
445 |
"greater than 1, %d is invalid\n", size); |
446 |
else |
447 |
settings.worldmaptilesizey = size; |
448 |
} else if (!strcasecmp(buf, "dynamiclevel")) { |
449 |
int lev = atoi(cp); |
450 |
|
451 |
if (lev < 0) |
452 |
LOG(llevError, "load_settings: dynamiclevel must be " |
453 |
"at least 0, %d is invalid\n", lev); |
454 |
else |
455 |
settings.dynamiclevel = lev; |
456 |
} else if (!strcasecmp(buf, "fastclock")) { |
457 |
int lev = atoi(cp); |
458 |
|
459 |
if (lev < 0) |
460 |
LOG(llevError, "load_settings: fastclock must be at least 0" |
461 |
", %d is invalid\n", lev); |
462 |
else |
463 |
settings.fastclock = lev; |
464 |
} else if (!strcasecmp(buf, "not_permadeth")) { |
465 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
466 |
settings.not_permadeth=TRUE; |
467 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
468 |
settings.not_permadeth=FALSE; |
469 |
} else { |
470 |
LOG(llevError, "load_settings: Unknown value for not_permadeth" |
471 |
": %s\n", cp); |
472 |
} |
473 |
} else if (!strcasecmp(buf, "resurrection")) { |
474 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
475 |
settings.resurrection=TRUE; |
476 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
477 |
settings.resurrection=FALSE; |
478 |
} else { |
479 |
LOG(llevError, "load_settings: Unknown value for resurrection" |
480 |
": %s\n", cp); |
481 |
} |
482 |
} else if (!strcasecmp(buf, "set_title")) { |
483 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
484 |
settings.set_title=TRUE; |
485 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
486 |
settings.set_title=FALSE; |
487 |
} else { |
488 |
LOG(llevError, "load_settings: Unknown value for set_title" |
489 |
": %s\n", cp); |
490 |
} |
491 |
} else if (!strcasecmp(buf, "search_items")) { |
492 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
493 |
settings.search_items=TRUE; |
494 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
495 |
settings.search_items=FALSE; |
496 |
} else { |
497 |
LOG(llevError, "load_settings: Unknown value for search_items" |
498 |
": %s\n", cp); |
499 |
} |
500 |
} else if (!strcasecmp(buf, "spell_encumbrance")) { |
501 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
502 |
settings.spell_encumbrance=TRUE; |
503 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
504 |
settings.spell_encumbrance=FALSE; |
505 |
} else { |
506 |
LOG(llevError, "load_settings: Unknown value for " |
507 |
"spell_encumbrance: %s\n", cp); |
508 |
} |
509 |
} else if (!strcasecmp(buf, "spell_failure_effects")) { |
510 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
511 |
settings.spell_failure_effects=TRUE; |
512 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
513 |
settings.spell_failure_effects=FALSE; |
514 |
} else { |
515 |
LOG(llevError, "load_settings: Unknown value for " |
516 |
"spell_failure_effects: %s\n", cp); |
517 |
} |
518 |
} else if (!strcasecmp(buf, "casting_time")) { |
519 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
520 |
settings.casting_time=TRUE; |
521 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
522 |
settings.casting_time=FALSE; |
523 |
} else { |
524 |
LOG(llevError, "load_settings: Unknown value for " |
525 |
"casting_time: %s\n", cp); |
526 |
} |
527 |
} else if (!strcasecmp(buf, "real_wiz")) { |
528 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
529 |
settings.real_wiz=TRUE; |
530 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
531 |
settings.real_wiz=FALSE; |
532 |
} else { |
533 |
LOG(llevError, "load_settings: Unknown value for " |
534 |
"real_wiz: %s\n", cp); |
535 |
} |
536 |
} else if (!strcasecmp(buf, "recycle_tmp_maps")) { |
537 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
538 |
settings.recycle_tmp_maps=TRUE; |
539 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
540 |
settings.recycle_tmp_maps=FALSE; |
541 |
} else { |
542 |
LOG(llevError, "load_settings: Unknown value for " |
543 |
"recycle_tmp_maps: %s\n", cp); |
544 |
} |
545 |
} else if (!strcasecmp(buf, "explore_mode")) { |
546 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
547 |
settings.explore_mode=TRUE; |
548 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
549 |
settings.explore_mode=FALSE; |
550 |
} else { |
551 |
LOG(llevError, "load_settings: Unknown value for " |
552 |
"explore_mode: %s\n", cp); |
553 |
} |
554 |
} else if (!strcasecmp(buf,"who_format")) { |
555 |
if (has_val) |
556 |
strcpy(settings.who_format, cp); |
557 |
} else if (!strcasecmp(buf,"who_wiz_format")) { |
558 |
if (has_val) |
559 |
strcpy(settings.who_wiz_format, cp); |
560 |
} else if (!strcasecmp(buf, "spellpoint_level_depend")) { |
561 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
562 |
settings.spellpoint_level_depend=TRUE; |
563 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
564 |
settings.spellpoint_level_depend=FALSE; |
565 |
} else { |
566 |
LOG(llevError, "load_settings: Unknown value for " |
567 |
"spellpoint_level_depend: %s\n", cp); |
568 |
} |
569 |
} else if (!strcasecmp(buf, "stat_loss_on_death")) { |
570 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
571 |
settings.stat_loss_on_death=TRUE; |
572 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
573 |
settings.stat_loss_on_death=FALSE; |
574 |
} else { |
575 |
LOG(llevError, "load_settings: Unknown value for " |
576 |
"stat_loss_on_death: %s\n", cp); |
577 |
} |
578 |
} else if (!strcasecmp(buf, "use_permanent_experience")) { |
579 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
580 |
settings.use_permanent_experience=TRUE; |
581 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
582 |
settings.use_permanent_experience=FALSE; |
583 |
} else { |
584 |
LOG(llevError, "load_settings: Unknown value for " |
585 |
"use_permanent_experience: %s\n", cp); |
586 |
} |
587 |
} else if (!strcasecmp(buf, "balanced_stat_loss")) { |
588 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
589 |
settings.balanced_stat_loss=TRUE; |
590 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
591 |
settings.balanced_stat_loss=FALSE; |
592 |
} else { |
593 |
LOG(llevError, "load_settings: Unknown value for " |
594 |
"balanced_stat_loss: %s\n", cp); |
595 |
} |
596 |
} else if (!strcasecmp(buf,"simple_exp")) { |
597 |
if (!strcasecmp(cp,"on") || !strcasecmp(cp,"true")) { |
598 |
settings.simple_exp=TRUE; |
599 |
} else if (!strcasecmp(cp,"off") || !strcasecmp(cp,"false")) { |
600 |
settings.simple_exp=FALSE; |
601 |
} else { |
602 |
LOG(llevError,"load_settings: Unknown value for simple_exp: %s\n", |
603 |
cp); |
604 |
} |
605 |
} else if (!strcasecmp(buf, "item_power_factor")) { |
606 |
float tmp = atof(cp); |
607 |
if (tmp < 0) |
608 |
LOG(llevError, "load_settings: item_power_factor must be a positive number (%f < 0)\n", |
609 |
tmp); |
610 |
else |
611 |
settings.item_power_factor = tmp; |
612 |
} else if (!strcasecmp(buf, "pk_luck_penalty")) { |
613 |
sint16 val = atoi(cp); |
614 |
|
615 |
if (val < -100 || val >100) |
616 |
LOG(llevError, "load_settings: pk_luck_penalty must be between -100 and 100" |
617 |
", %d is invalid\n", val); |
618 |
else |
619 |
settings.pk_luck_penalty = val; |
620 |
} else if (!strcasecmp(buf, "set_friendly_fire")) { |
621 |
int val = atoi(cp); |
622 |
|
623 |
#if COZY_SERVER |
624 |
if (val < 0 || val >100) |
625 |
LOG(llevError, "load_settings: set_friendly_fire must be between 0 an 100" |
626 |
", %d is invalid\n", val); |
627 |
#else |
628 |
if (val < 1 || val >100) |
629 |
LOG(llevError, "load_settings: set_friendly_fire must be between 1 an 100" |
630 |
", %d is invalid\n", val); |
631 |
#endif |
632 |
else |
633 |
settings.set_friendly_fire = val; |
634 |
} else if ( !strcasecmp( buf, "armor_max_enchant" ) ) { |
635 |
int max_e = atoi( cp ); |
636 |
if ( max_e <= 0 ) |
637 |
LOG( llevError, "load_settings: armor_max_enchant is %d\n", max_e ); |
638 |
else |
639 |
settings.armor_max_enchant = max_e; |
640 |
} else if ( !strcasecmp( buf, "armor_weight_reduction" ) ) { |
641 |
int wr = atoi( cp ); |
642 |
if ( wr < 0 ) |
643 |
LOG( llevError, "load_settings: armor_weight_reduction is %d\n", wr ); |
644 |
else |
645 |
settings.armor_weight_reduction = wr; |
646 |
} else if ( !strcasecmp( buf, "armor_weight_linear" ) ) { |
647 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
648 |
settings.armor_weight_linear=TRUE; |
649 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
650 |
settings.armor_weight_linear=FALSE; |
651 |
} else { |
652 |
LOG(llevError, "load_settings: unknown value for armor_weight_linear: %s\n", cp); |
653 |
} |
654 |
|
655 |
} else if ( !strcasecmp( buf, "armor_speed_improvement" ) ) { |
656 |
int wr = atoi( cp ); |
657 |
if ( wr < 0 ) |
658 |
LOG( llevError, "load_settings: armor_speed_improvement is %d\n", wr ); |
659 |
else |
660 |
settings.armor_speed_improvement = wr; |
661 |
} else if ( !strcasecmp( buf, "armor_speed_linear" ) ) { |
662 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
663 |
settings.armor_speed_linear = TRUE; |
664 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
665 |
settings.armor_speed_linear = FALSE; |
666 |
} else { |
667 |
LOG(llevError, "load_settings: unknown value for armor_speed_linear: %s\n", cp); |
668 |
} |
669 |
|
670 |
} else if ( !strcasecmp( buf, "no_player_stealing" ) ) { |
671 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
672 |
settings.no_player_stealing = TRUE; |
673 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
674 |
settings.no_player_stealing = FALSE; |
675 |
} else { |
676 |
LOG(llevError, "load_settings: unknown value for no_player_stealing: %s\n", cp); |
677 |
} |
678 |
|
679 |
} else { |
680 |
LOG(llevError,"Unknown value in settings file: %s\n", buf); |
681 |
} |
682 |
} |
683 |
close_and_delete(fp, comp); |
684 |
} |
685 |
|
686 |
|
687 |
/* |
688 |
* init() is called only once, when starting the program. |
689 |
*/ |
690 |
|
691 |
void init(int argc, char **argv) { |
692 |
|
693 |
init_done=0; /* Must be done before init_signal() */ |
694 |
logfile=stderr; |
695 |
parse_args(argc, argv, 1); /* First arg pass - right now it does |
696 |
* nothing, but in future specifying the |
697 |
* LibDir in this pass would be reasonable*/ |
698 |
|
699 |
init_library(); /* Must be called early */ |
700 |
load_settings(); /* Load the settings file */ |
701 |
init_weather(); |
702 |
load_materials(); |
703 |
parse_args(argc, argv, 2); |
704 |
fprintf(logfile,"Welcome to CrossFire, v%s\n",VERSION); |
705 |
fprintf(logfile,"Copyright (C) 1994 Mark Wedel.\n"); |
706 |
fprintf(logfile,"Copyright (C) 1992 Frank Tore Johansen.\n"); |
707 |
|
708 |
if (strcmp(settings.dm_mail, "") != 0) { |
709 |
fprintf(logfile,"Maintained locally by: %s\n", settings.dm_mail); |
710 |
fprintf(logfile,"Questions and bugs should be mailed to above address.\n"); |
711 |
} |
712 |
SRANDOM(time(NULL)); |
713 |
|
714 |
init_startup(); /* Write (C), check shutdown/forbid files */ |
715 |
init_signals(); /* Sets up signal interceptions */ |
716 |
init_commands(); /* Sort command tables */ |
717 |
read_map_log(); /* Load up the old temp map files */ |
718 |
init_skills(); |
719 |
|
720 |
parse_args(argc, argv, 3); |
721 |
|
722 |
#ifndef WIN32 /* ***win32: no BecomeDaemon in windows */ |
723 |
if (settings.daemonmode) |
724 |
logfile = BecomeDaemon(settings.logfilename[0]=='\0'?"logfile":settings.logfilename); |
725 |
#endif |
726 |
|
727 |
init_beforeplay(); |
728 |
init_ericserver(); |
729 |
metaserver_init(); |
730 |
reset_sleep(); |
731 |
init_done=1; |
732 |
} |
733 |
|
734 |
void usage(void) { |
735 |
(void) fprintf(logfile, |
736 |
"Usage: crossfire [-h] [-<flags>]...\n"); |
737 |
} |
738 |
|
739 |
void help(void) { |
740 |
/* The information in usage is redundant with what is given below, so why call it? */ |
741 |
/* usage();*/ |
742 |
printf("Flags:\n"); |
743 |
printf(" -csport <port> Specifies the port to use for the new client/server code.\n"); |
744 |
printf(" -d Turns on some debugging.\n"); |
745 |
printf(" +d Turns off debugging (useful if server compiled with debugging\n"); |
746 |
printf(" as default).\n"); |
747 |
printf(" -detach The server will go in the background, closing all\n"); |
748 |
printf(" connections to the tty.\n"); |
749 |
printf(" -h Display this information.\n"); |
750 |
printf(" -log <file> Specifies which file to send output to.\n"); |
751 |
printf(" Only has meaning if -detach is specified.\n"); |
752 |
printf(" -mon Turns on monster debugging.\n"); |
753 |
printf(" -o Prints out info on what was defined at compile time.\n"); |
754 |
printf(" -s Display the high-score list.\n"); |
755 |
printf(" -score <name or class> Displays all high scores with matching name/class.\n"); |
756 |
printf(" -v Print version and contributors.\n"); |
757 |
printf(" -data Sets the lib dir (archetypes, treasures, etc.)\n"); |
758 |
printf(" -local Read/write local data (hiscore, unique items, etc.)\n"); |
759 |
printf(" -maps Sets the directory for maps.\n"); |
760 |
printf(" -arch Sets the archetype file to use.\n"); |
761 |
printf(" -regions Sets the regions file to use.\n"); |
762 |
printf(" -playerdir Sets the directory for the player files.\n"); |
763 |
printf(" -templatedir Sets the directory for template generate maps.\n"); |
764 |
printf(" -treasures Sets the treasures file to use.\n"); |
765 |
printf(" -uniquedir Sets the unique items/maps directory.\n"); |
766 |
printf(" -tmpdir Sets the directory for temporary files (mostly maps.)\n"); |
767 |
printf(" -m Lists out suggested experience for all monsters.\n"); |
768 |
printf(" -m2 Dumps out abilities.\n"); |
769 |
printf(" -m3 Dumps out artifact information.\n"); |
770 |
printf(" -m4 Dumps out spell information.\n"); |
771 |
printf(" -m5 Dumps out skill information.\n"); |
772 |
printf(" -m6 Dumps out race information.\n"); |
773 |
printf(" -m7 Dumps out alchemy information.\n"); |
774 |
printf(" -m8 Dumps out gods information.\n"); |
775 |
printf(" -m9 Dumps out more alchemy information (formula checking).\n"); |
776 |
printf(" -mt <name> Dumps out list of treasures for a monster.\n"); |
777 |
exit(0); |
778 |
} |
779 |
|
780 |
void init_beforeplay(void) { |
781 |
init_archetypes(); /* If not called before, reads all archetypes from file */ |
782 |
init_artifacts(); /* If not called before, reads all artifacts from file */ |
783 |
init_spells(); /* If not called before, links archtypes used by spells */ |
784 |
init_regions(); /* If not called before, reads all regions from file */ |
785 |
init_archetype_pointers(); /* Setup global pointers to archetypes */ |
786 |
init_races(); /* overwrite race designations using entries in lib/races file */ |
787 |
init_gods(); /* init linked list of gods from archs*/ |
788 |
init_readable(); /* inits useful arrays for readable texts */ |
789 |
init_formulae(); /* If not called before, reads formulae from file */ |
790 |
|
791 |
switch(settings.dumpvalues) { |
792 |
case 1: |
793 |
print_monsters(); |
794 |
exit(0); |
795 |
case 2: |
796 |
dump_abilities(); |
797 |
exit(0); |
798 |
case 3: |
799 |
dump_artifacts(); |
800 |
exit(0); |
801 |
case 4: |
802 |
dump_spells(); |
803 |
exit(0); |
804 |
case 5: |
805 |
exit(0); |
806 |
case 6: |
807 |
dump_races(); |
808 |
exit(0); |
809 |
case 7: |
810 |
dump_alchemy(); |
811 |
exit(0); |
812 |
case 8: |
813 |
dump_gods(); |
814 |
exit(0); |
815 |
case 9: |
816 |
dump_alchemy_costs(); |
817 |
exit(0); |
818 |
case 10: |
819 |
dump_monster_treasure(settings.dumparg); |
820 |
exit(0); |
821 |
} |
822 |
} |
823 |
|
824 |
void init_startup(void) { |
825 |
char buf[MAX_BUF]; |
826 |
FILE *fp; |
827 |
int comp; |
828 |
|
829 |
#ifdef SHUTDOWN_FILE |
830 |
sprintf(buf,"%s/%s",settings.confdir,SHUTDOWN_FILE); |
831 |
if ((fp = open_and_uncompress(buf, 0, &comp)) != NULL) { |
832 |
while (fgets(buf, MAX_BUF-1, fp) != NULL) |
833 |
printf("%s", buf); |
834 |
close_and_delete(fp, comp); |
835 |
exit(1); |
836 |
} |
837 |
#endif |
838 |
|
839 |
if (forbid_play()) { /* Maybe showing highscore should be allowed? */ |
840 |
LOG(llevError, "CrossFire: Playing not allowed.\n"); |
841 |
exit(-1); |
842 |
} |
843 |
} |
844 |
|
845 |
/* |
846 |
* compile_info(): activated with the -o flag. |
847 |
* It writes out information on how Imakefile and config.h was configured |
848 |
* at compile time. |
849 |
*/ |
850 |
|
851 |
void compile_info(void) { |
852 |
int i=0; |
853 |
printf("Non-standard include files:\n"); |
854 |
#if !defined (__STRICT_ANSI__) || defined (__sun__) |
855 |
#if !defined (Mips) |
856 |
printf("<stdlib.h>\n"); |
857 |
i=1; |
858 |
#endif |
859 |
#if !defined (MACH) && !defined (sony) |
860 |
printf("<malloc.h>\n"); |
861 |
i=1; |
862 |
#endif |
863 |
#endif |
864 |
#ifndef __STRICT_ANSI__ |
865 |
#ifndef MACH |
866 |
printf("<memory.h\n"); |
867 |
i=1; |
868 |
#endif |
869 |
#endif |
870 |
#ifndef sgi |
871 |
printf("<sys/timeb.h>\n"); |
872 |
i=1; |
873 |
#endif |
874 |
if(!i) |
875 |
printf("(none)\n"); |
876 |
printf("Datadir:\t\t%s\n",settings.datadir); |
877 |
printf("Localdir:\t\t%s\n",settings.localdir); |
878 |
#ifdef PERM_FILE |
879 |
printf("Perm file:\t<ETC>/%s\n",PERM_FILE); |
880 |
#endif |
881 |
#ifdef SHUTDOWN_FILE |
882 |
printf("Shutdown file:\t<ETC>/%s\n",SHUTDOWN_FILE); |
883 |
#endif |
884 |
printf("Save player:\t<true>\n"); |
885 |
printf("Save mode:\t%4.4o\n",SAVE_MODE); |
886 |
printf("Playerdir:\t<VAR>/%s\n",settings.playerdir); |
887 |
printf("Itemsdir:\t<VAR>/%s\n", settings.uniquedir); |
888 |
printf("Tmpdir:\t\t%s\n",settings.tmpdir); |
889 |
printf("Map max timeout:\t%d\n",MAP_MAXTIMEOUT); |
890 |
printf("Max objects:\t%d\n",MAX_OBJECTS); |
891 |
#ifdef USE_CALLOC |
892 |
printf("Use_calloc:\t<true>\n"); |
893 |
#else |
894 |
printf("Use_calloc:\t<false>\n"); |
895 |
#endif |
896 |
|
897 |
#ifdef X_EDITOR |
898 |
printf("Editor:\t\t%s\n",X_EDITOR); |
899 |
#endif |
900 |
|
901 |
printf("Max_time:\t%d\n",MAX_TIME); |
902 |
|
903 |
#ifdef WIN32 /* ***win32 compile_info(): remove execl... */ |
904 |
printf("Logfilename:\t%s\n",settings.logfilename); |
905 |
exit(0); |
906 |
#else |
907 |
execl("/bin/uname", "uname", "-a", NULL); |
908 |
LOG(llevError, "Oops, shouldn't have gotten here: execl(/bin/uname) failed: %s\n", strerror_local(errno)); |
909 |
exit(-1); |
910 |
#endif |
911 |
} |
912 |
|
913 |
/* Signal handlers: */ |
914 |
|
915 |
void rec_sigsegv(int i) { |
916 |
LOG(llevError,"\nSIGSEGV received.\n"); |
917 |
fatal_signal(1, 1); |
918 |
} |
919 |
|
920 |
void rec_sigint(int i) { |
921 |
LOG(llevInfo,"\nSIGINT received.\n"); |
922 |
fatal_signal(0, 1); |
923 |
} |
924 |
|
925 |
void rec_sighup(int i) { |
926 |
LOG(llevInfo,"\nSIGHUP received\n"); |
927 |
if(init_done) { |
928 |
emergency_save(0); |
929 |
cleanup(); |
930 |
} |
931 |
exit(0); |
932 |
} |
933 |
|
934 |
void rec_sigquit(int i) { |
935 |
LOG(llevInfo,"\nSIGQUIT received\n"); |
936 |
fatal_signal(1, 1); |
937 |
} |
938 |
|
939 |
void rec_sigpipe(int i) { |
940 |
|
941 |
/* Keep running if we receive a sigpipe. Crossfire should really be able |
942 |
* to handle this signal (at least at some point in the future if not |
943 |
* right now). By causing a dump right when it is received, it is not |
944 |
* doing much good. However, if it core dumps later on, at least it can |
945 |
* be looked at later on, and maybe fix the problem that caused it to |
946 |
* dump core. There is no reason that SIGPIPES should be fatal |
947 |
*/ |
948 |
LOG(llevError,"\nSIGPIPE--------------\n------------\n--------\n---\n"); |
949 |
#if 1 && !defined(WIN32) /* ***win32: we don't want send SIGPIPE */ |
950 |
LOG(llevInfo,"\nReceived SIGPIPE, ignoring...\n"); |
951 |
signal(SIGPIPE,rec_sigpipe);/* hocky-pux clears signal handlers */ |
952 |
#else |
953 |
LOG(llevError,"\nSIGPIPE received, not ignoring...\n"); |
954 |
fatal_signal(1, 1); /*Might consider to uncomment this line */ |
955 |
#endif |
956 |
} |
957 |
|
958 |
void rec_sigbus(int i) { |
959 |
#ifdef SIGBUS |
960 |
LOG(llevError,"\nSIGBUS received\n"); |
961 |
fatal_signal(1, 1); |
962 |
#endif |
963 |
} |
964 |
|
965 |
void rec_sigterm(int i) { |
966 |
LOG(llevInfo,"\nSIGTERM received\n"); |
967 |
fatal_signal(0, 1); |
968 |
} |
969 |
|
970 |
void fatal_signal(int make_core, int close_sockets) { |
971 |
if(init_done) { |
972 |
emergency_save(0); |
973 |
clean_tmp_files(); |
974 |
} |
975 |
if(make_core) |
976 |
abort(); |
977 |
exit(0); |
978 |
} |
979 |
|
980 |
void init_signals(void) { |
981 |
#ifndef WIN32 /* init_signals() remove signals */ |
982 |
signal(SIGHUP,rec_sighup); |
983 |
signal(SIGINT,rec_sigint); |
984 |
#ifndef DEBUG |
985 |
signal(SIGQUIT,rec_sigquit); |
986 |
signal(SIGSEGV,rec_sigsegv); |
987 |
LOG(llevInfo,"\n---------registering SIGPIPE\n"); |
988 |
signal(SIGPIPE,rec_sigpipe); |
989 |
#ifdef SIGBUS |
990 |
signal(SIGBUS,rec_sigbus); |
991 |
#endif |
992 |
signal(SIGTERM,rec_sigterm); |
993 |
#endif |
994 |
#endif /* win32 */ |
995 |
} |
996 |
|
997 |
/* init_races() - reads the races file in the lib/ directory, then |
998 |
* overwrites old 'race' entries. This routine allow us to quickly |
999 |
* re-configure the 'alignment' of monsters, objects. Useful for |
1000 |
* putting together lists of creatures, etc that belong to gods. |
1001 |
*/ |
1002 |
|
1003 |
void init_races (void) { |
1004 |
FILE *file; |
1005 |
char race[MAX_BUF], fname[MAX_BUF], buf[MAX_BUF], *cp, variable[MAX_BUF]; |
1006 |
archetype *mon=NULL; |
1007 |
static int init_done=0; |
1008 |
|
1009 |
if (init_done) return; |
1010 |
init_done=1; |
1011 |
first_race=NULL; |
1012 |
|
1013 |
sprintf(fname,"%s/races",settings.datadir); |
1014 |
LOG(llevDebug, "Reading races from %s...",fname); |
1015 |
if(! (file=fopen(fname,"r"))) { |
1016 |
LOG(llevError, "Cannot open races file %s: %s\n", fname, strerror_local(errno)); |
1017 |
return; |
1018 |
} |
1019 |
|
1020 |
while(fgets(buf,MAX_BUF,file)!=NULL) { |
1021 |
int set_race=1,set_list=1; |
1022 |
if(*buf=='#') continue; |
1023 |
if((cp=strchr(buf,'\n'))!=NULL) |
1024 |
*cp='\0'; |
1025 |
cp=buf; |
1026 |
while(*cp==' '||*cp=='!'||*cp=='@') { |
1027 |
if(*cp=='!') set_race=0; |
1028 |
if(*cp=='@') set_list=0; |
1029 |
cp++; |
1030 |
} |
1031 |
if(sscanf(cp,"RACE %s",variable)) { /* set new race value */ |
1032 |
strcpy(race,variable); |
1033 |
} else { |
1034 |
char *cp1; |
1035 |
/* Take out beginning spaces */ |
1036 |
for (cp1 = cp; *cp1==' '; cp1++); |
1037 |
/* Remove newline and trailing spaces */ |
1038 |
for (cp1 = cp + strlen(cp) -1; *cp1 == '\n' || *cp1 == ' '; cp1 --) { |
1039 |
*cp1='\0'; |
1040 |
if (cp==cp1) break; |
1041 |
} |
1042 |
|
1043 |
if (cp[strlen(cp)-1]=='\n') cp[strlen(cp)-1]='\0'; |
1044 |
/* set creature race to race value */ |
1045 |
if((mon=find_archetype(cp))==NULL) |
1046 |
LOG(llevError,"\nCreature %s in race file lacks archetype",cp); |
1047 |
else { |
1048 |
if(set_race&&(!mon->clone.race||strcmp(mon->clone.race,race))) { |
1049 |
if(mon->clone.race) { |
1050 |
LOG(llevDebug,"\n Resetting race to %s from %s for archetype %s", |
1051 |
race,mon->clone.race,mon->name); |
1052 |
free_string(mon->clone.race); |
1053 |
} |
1054 |
mon->clone.race=add_string(race); |
1055 |
} |
1056 |
/* if the arch is a monster, add it to the race list */ |
1057 |
if(set_list&&QUERY_FLAG(&mon->clone,FLAG_MONSTER)) |
1058 |
add_to_racelist(race, &mon->clone); |
1059 |
} |
1060 |
} |
1061 |
} |
1062 |
fclose(file); |
1063 |
LOG(llevDebug,"done.\n"); |
1064 |
} |
1065 |
|
1066 |
void dump_races(void) |
1067 |
{ |
1068 |
racelink *list; |
1069 |
objectlink *tmp; |
1070 |
for(list=first_race;list;list=list->next) { |
1071 |
fprintf(stderr,"\nRACE %s:\t",list->name); |
1072 |
for(tmp=list->member;tmp;tmp=tmp->next) |
1073 |
fprintf(stderr,"%s(%d), ",tmp->ob->arch->name,tmp->ob->level); |
1074 |
} |
1075 |
fprintf(stderr,"\n"); |
1076 |
} |
1077 |
|
1078 |
void add_to_racelist (const char *race_name, object *op) { |
1079 |
racelink *race; |
1080 |
|
1081 |
if(!op||!race_name) return; |
1082 |
race=find_racelink(race_name); |
1083 |
|
1084 |
if(!race) { /* add in a new race list */ |
1085 |
race = get_racelist(); |
1086 |
race->next = first_race; |
1087 |
first_race = race; |
1088 |
race->name=add_string(race_name); |
1089 |
} |
1090 |
|
1091 |
if(race->member->ob) { |
1092 |
objectlink *tmp = get_objectlink(); |
1093 |
tmp->next=race->member; |
1094 |
race->member = tmp; |
1095 |
} |
1096 |
race->nrof++; |
1097 |
race->member->ob = op; |
1098 |
} |
1099 |
|
1100 |
racelink * get_racelist ( ) { |
1101 |
racelink *list; |
1102 |
|
1103 |
list = (racelink *) malloc(sizeof(racelink )); |
1104 |
list->name=NULL; |
1105 |
list->nrof=0; |
1106 |
list->member=get_objectlink(); |
1107 |
list->next=NULL; |
1108 |
|
1109 |
return list; |
1110 |
} |
1111 |
|
1112 |
racelink * find_racelink( const char *name ) { |
1113 |
racelink *test=NULL; |
1114 |
|
1115 |
if(name&&first_race) |
1116 |
for(test=first_race;test&&test!=test->next;test=test->next) |
1117 |
if(!test->name||!strcmp(name,test->name)) break; |
1118 |
|
1119 |
return test; |
1120 |
} |