1 | |
|
|
2 | /* |
1 | /* |
3 | * static char *rcsid_init_c = |
|
|
4 | * "$Id: init.C,v 1.10 2006/09/10 16:00:23 root Exp $"; |
|
|
5 | */ |
|
|
6 | |
|
|
7 | /* |
|
|
8 | CrossFire, A Multiplayer game for X-windows |
2 | * CrossFire, A Multiplayer game for X-windows |
9 | |
3 | * |
|
|
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
10 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
11 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (C) 1992 Frank Tore Johansen |
12 | |
7 | * |
13 | This program is free software; you can redistribute it and/or modify |
8 | * This program is free software; you can redistribute it and/or modify |
14 | it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
15 | the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation; either version 2 of the License, or |
16 | (at your option) any later version. |
11 | * (at your option) any later version. |
17 | |
12 | * |
18 | This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
21 | GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
22 | |
17 | * |
23 | You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
24 | along with this program; if not, write to the Free Software |
19 | * along with this program; if not, write to the Free Software |
25 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
26 | |
21 | * |
27 | The authors can be reached via e-mail at crossfire-devel@real-time.com |
22 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
28 | */ |
23 | */ |
29 | |
24 | |
30 | #define EXTERN // horrible hack |
25 | #define EXTERN // horrible hack |
31 | |
26 | |
32 | #include <global.h> |
27 | #include <global.h> |
33 | #include <object.h> |
28 | #include <object.h> |
34 | |
29 | |
35 | extern const char *const attacktype_desc[NROFATTACKS] = { |
30 | extern const char *const attacktype_desc[NROFATTACKS] = { |
36 | #define def(uc, lc, name, plus, change) # name, |
31 | # define def(uc, lc, name, plus, change) # name, |
37 | #include "attackinc.h" |
32 | # include "attackinc.h" |
38 | #undef def |
33 | # undef def |
39 | }; |
|
|
40 | |
|
|
41 | extern const keyword resist_save[NROFATTACKS] = { |
|
|
42 | #define def(uc, lc, name, plus, change) KW_resist_ ## lc, |
|
|
43 | #include "attackinc.h" |
|
|
44 | #undef def |
|
|
45 | }; |
34 | }; |
46 | |
35 | |
47 | extern const char *const resist_plus[NROFATTACKS] = { |
36 | extern const char *const resist_plus[NROFATTACKS] = { |
48 | #define def(uc, lc, name, plus, change) # plus, |
37 | # define def(uc, lc, name, plus, change) # plus, |
49 | #include "attackinc.h" |
38 | # include "attackinc.h" |
50 | #undef def |
39 | # undef def |
51 | }; |
40 | }; |
52 | |
41 | |
53 | extern const char *const change_resist_msg[NROFATTACKS] = { |
42 | extern const char *const change_resist_msg[NROFATTACKS] = { |
54 | #define def(uc, lc, name, plus, change) # change, |
43 | # define def(uc, lc, name, plus, change) # change, |
55 | #include "attackinc.h" |
44 | # include "attackinc.h" |
56 | #undef def |
45 | # undef def |
57 | }; |
46 | }; |
58 | |
47 | |
59 | int resist_table[NROFATTACKS] = { |
48 | int resist_table[NROFATTACKS] = { |
60 | #define def(uc, lc, name, plus, change) ATNR_ ## uc, |
49 | # define def(uc, lc, name, plus, change) ATNR_ ## uc, |
61 | #include "attackinc.h" |
50 | # include "attackinc.h" |
62 | #undef def |
51 | # undef def |
63 | }; |
52 | }; |
64 | |
53 | |
65 | /* You unforunately need to looking in include/global.h to see what these |
54 | /* You unforunately need to looking in include/global.h to see what these |
66 | * correspond to. |
55 | * correspond to. |
67 | */ |
56 | */ |
… | |
… | |
99 | SEARCH_ITEMS, |
88 | SEARCH_ITEMS, |
100 | SPELL_ENCUMBRANCE, |
89 | SPELL_ENCUMBRANCE, |
101 | SPELL_FAILURE_EFFECTS, |
90 | SPELL_FAILURE_EFFECTS, |
102 | CASTING_TIME, |
91 | CASTING_TIME, |
103 | REAL_WIZ, |
92 | REAL_WIZ, |
104 | RECYCLE_TMP_MAPS, |
|
|
105 | EXPLORE_MODE, |
93 | EXPLORE_MODE, |
106 | SPELLPOINT_LEVEL_DEPEND, |
94 | SPELLPOINT_LEVEL_DEPEND, |
107 | SET_FRIENDLY_FIRE, |
95 | SET_FRIENDLY_FIRE, |
108 | "", /* Who format specifier */ |
|
|
109 | "", /* who wiz format specifier */ |
|
|
110 | MOTD, |
96 | MOTD, |
111 | "rules", |
97 | "rules", |
112 | "news", |
98 | "news", |
113 | "", /* DM_MAIL */ |
99 | "", /* DM_MAIL */ |
114 | 0, /* This and the next 3 values are metaserver values */ |
|
|
115 | "", |
|
|
116 | "", |
|
|
117 | 0, |
|
|
118 | "", |
|
|
119 | 0, 0, 0, 0, 0, 0, 0, 0, /* worldmap settings */ |
100 | 0, 0, 0, 0, 0, 0, 0, 0, /* worldmap settings */ |
120 | EMERGENCY_MAPPATH, EMERGENCY_X, EMERGENCY_Y, |
|
|
121 | 0, |
101 | 0, |
122 | 1.0, |
102 | 1.0, |
123 | |
103 | |
124 | /* Armor enchantment stuff */ |
104 | /* Armor enchantment stuff */ |
125 | ARMOR_MAX_ENCHANT, |
105 | ARMOR_MAX_ENCHANT, |
… | |
… | |
156 | "Wounding", |
136 | "Wounding", |
157 | "Death", |
137 | "Death", |
158 | "Light" |
138 | "Light" |
159 | }; |
139 | }; |
160 | |
140 | |
161 | |
|
|
162 | /* This loads the emergency map information from a |
|
|
163 | * .emergency file in the map directory. Doing this makes |
|
|
164 | * it easier to switch between map distributions (don't need |
|
|
165 | * to recompile. Note that there is no reason I see that |
|
|
166 | * this could not be re-loaded during play, but it seems |
|
|
167 | * like there should be little reason to do that. |
|
|
168 | */ |
|
|
169 | static void |
|
|
170 | init_emergency_mappath (void) |
|
|
171 | { |
|
|
172 | char filename[MAX_BUF], tmpbuf[MAX_BUF]; |
|
|
173 | FILE *fp; |
|
|
174 | int online = 0; |
|
|
175 | |
|
|
176 | /* If this file doesn't exist, not a big deal */ |
|
|
177 | sprintf (filename, "%s/%s/.emergency", settings.datadir, settings.mapdir); |
|
|
178 | if ((fp = fopen (filename, "r")) != NULL) |
|
|
179 | { |
|
|
180 | while (fgets (tmpbuf, MAX_BUF - 1, fp)) |
|
|
181 | { |
|
|
182 | if (tmpbuf[0] == '#') |
|
|
183 | continue; /* ignore comments */ |
|
|
184 | |
|
|
185 | if (online == 0) |
|
|
186 | { |
|
|
187 | tmpbuf[strlen (tmpbuf) - 1] = 0; /* kill newline */ |
|
|
188 | settings.emergency_mapname = strdup_local (tmpbuf); |
|
|
189 | } |
|
|
190 | else if (online == 1) |
|
|
191 | { |
|
|
192 | settings.emergency_x = atoi (tmpbuf); |
|
|
193 | } |
|
|
194 | |
|
|
195 | else if (online == 2) |
|
|
196 | { |
|
|
197 | settings.emergency_y = atoi (tmpbuf); |
|
|
198 | } |
|
|
199 | online++; |
|
|
200 | if (online > 2) |
|
|
201 | break; |
|
|
202 | } |
|
|
203 | fclose (fp); |
|
|
204 | if (online <= 2) |
|
|
205 | LOG (llevError, "Online read partial data from %s\n", filename); |
|
|
206 | LOG (llevDebug, "Emergency mappath reset to %s (%d, %d)\n", settings.emergency_mapname, settings.emergency_x, settings.emergency_y); |
|
|
207 | } |
|
|
208 | } |
|
|
209 | |
|
|
210 | |
|
|
211 | /* |
141 | /* |
212 | * It is vital that init_library() is called by any functions |
142 | * It is vital that init_library() is called by any functions |
213 | * using this library. |
143 | * using this library. |
214 | * If you want to lessen the size of the program using the library, |
144 | * If you want to lessen the size of the program using the library, |
215 | * you can replace the call to init_library() with init_globals() and |
145 | * you can replace the call to init_library() with init_globals() and |
216 | * init_function_pointers(). Good idea to also call init_vars and |
146 | * init_function_pointers(). Good idea to also call init_vars and |
217 | * init_hash_table if you are doing any object loading. |
147 | * init_hash_table if you are doing any object loading. |
218 | */ |
148 | */ |
219 | |
|
|
220 | void |
149 | void |
221 | init_library (void) |
150 | init_library (void) |
222 | { |
151 | { |
223 | init_environ (); |
|
|
224 | init_globals (); |
152 | init_globals (); |
225 | init_objects (); |
|
|
226 | init_vars (); |
|
|
227 | init_block (); |
153 | init_block (); |
228 | ReadBmapNames (); |
154 | ReadBmapNames (); |
229 | ReadSmooth (); |
155 | ReadSmooth (); |
230 | init_anim (); /* Must be after we read in the bitmaps */ |
156 | init_anim (); /* Must be after we read in the bitmaps */ |
231 | init_archetypes (); /* Reads all archetypes from file */ |
157 | init_archetypes (); /* Reads all archetypes from file */ |
232 | init_dynamic (); |
158 | init_dynamic (); |
233 | init_attackmess (); |
159 | init_attackmess (); |
234 | init_clocks (); |
160 | init_clocks (); |
235 | init_emergency_mappath (); |
|
|
236 | init_experience (); |
161 | init_experience (); |
237 | } |
162 | } |
238 | |
163 | |
239 | |
164 | |
240 | /* init_environ initializes values from the environmental variables. |
165 | /* init_environ initialises values from the environmental variables. |
241 | * it needs to be called very early, since command line options should |
166 | * it needs to be called very early, since command line options should |
242 | * overwrite these if specified. |
167 | * overwrite these if specified. |
243 | */ |
168 | */ |
244 | void |
169 | void |
245 | init_environ (void) |
170 | init_environ (void) |
… | |
… | |
283 | |
208 | |
284 | void |
209 | void |
285 | init_globals (void) |
210 | init_globals (void) |
286 | { |
211 | { |
287 | if (settings.logfilename[0] == 0) |
212 | if (settings.logfilename[0] == 0) |
288 | { |
|
|
289 | logfile = stderr; |
213 | logfile = stderr; |
290 | } |
|
|
291 | else if ((logfile = fopen (settings.logfilename, "a")) == NULL) |
214 | else if ((logfile = fopen (settings.logfilename, "a")) == NULL) |
292 | { |
215 | { |
293 | fprintf (stderr, "Unable to open %s as the logfile - will use stderr instead\n", settings.logfilename); |
216 | fprintf (stderr, "Unable to open %s as the logfile - will use stderr instead\n", settings.logfilename); |
294 | logfile = stderr; |
217 | logfile = stderr; |
295 | } |
218 | } |
296 | else |
219 | else |
297 | { |
|
|
298 | setvbuf (logfile, NULL, _IOLBF, 0); |
220 | setvbuf (logfile, NULL, _IOLBF, 0); |
299 | } |
|
|
300 | exiting = 0; |
|
|
301 | first_player = NULL; |
|
|
302 | first_friendly_object = NULL; |
|
|
303 | first_map = NULL; |
|
|
304 | first_treasurelist = NULL; |
|
|
305 | first_artifactlist = NULL; |
|
|
306 | first_archetype = NULL; |
|
|
307 | *first_map_ext_path = 0; |
|
|
308 | warn_archetypes = 0; |
|
|
309 | nroftreasures = 0; |
|
|
310 | nrofartifacts = 0; |
|
|
311 | nrofallowedstr = 0; |
|
|
312 | ring_arch = NULL; |
|
|
313 | amulet_arch = NULL; |
|
|
314 | staff_arch = NULL; |
|
|
315 | trying_emergency_save = 0; |
|
|
316 | num_animations = 0; |
|
|
317 | animations_allocated = 0; |
|
|
318 | init_defaults (); |
|
|
319 | } |
221 | } |
320 | |
|
|
321 | /* |
|
|
322 | * Sets up and initialises the linked list of free and used objects. |
|
|
323 | * Allocates a certain chunk of objects and puts them on the free list. |
|
|
324 | * Called by init_library(); |
|
|
325 | */ |
|
|
326 | |
|
|
327 | void |
|
|
328 | init_objects (void) |
|
|
329 | { |
|
|
330 | /* Initialize all objects: */ |
|
|
331 | objects = NULL; |
|
|
332 | active_objects = NULL; |
|
|
333 | } |
|
|
334 | |
|
|
335 | /* |
|
|
336 | * Initialises global variables which can be changed by options. |
|
|
337 | * Called by init_library(). |
|
|
338 | */ |
|
|
339 | |
|
|
340 | void |
|
|
341 | init_defaults (void) |
|
|
342 | { |
|
|
343 | editor = 0; |
|
|
344 | nroferrors = 0; |
|
|
345 | } |
|
|
346 | |
|
|
347 | |
222 | |
348 | void |
223 | void |
349 | init_dynamic (void) |
224 | init_dynamic (void) |
350 | { |
225 | { |
351 | archetype *at = first_archetype; |
226 | archetype *at = first_archetype; |
… | |
… | |
353 | while (at) |
228 | while (at) |
354 | { |
229 | { |
355 | if (at->clone.type == MAP) |
230 | if (at->clone.type == MAP) |
356 | { |
231 | { |
357 | if (at->clone.race) |
232 | if (at->clone.race) |
358 | { |
|
|
359 | strcpy (first_map_ext_path, at->clone.race); |
233 | first_map_ext_path = at->clone.race; |
360 | } |
234 | |
361 | if (EXIT_PATH (&at->clone)) |
235 | if (EXIT_PATH (&at->clone)) |
362 | { |
236 | { |
363 | strcpy (first_map_path, EXIT_PATH (&at->clone)); |
237 | first_map_path = EXIT_PATH (&at->clone); |
364 | return; |
238 | return; |
365 | } |
239 | } |
366 | } |
240 | } |
|
|
241 | |
367 | at = at->next; |
242 | at = at->next; |
368 | } |
243 | } |
|
|
244 | |
369 | LOG (llevDebug, "You Need a archetype called 'map' and it have to contain start map\n"); |
245 | LOG (llevDebug, "You Need a archetype called 'map' and it have to contain start map\n"); |
370 | exit (-1); |
246 | exit (-1); |
371 | } |
247 | } |
372 | |
248 | |
373 | unsigned long todtick; |
249 | unsigned long todtick; |
… | |
… | |
392 | fprintf (fp, "%lu", todtick); |
268 | fprintf (fp, "%lu", todtick); |
393 | fclose (fp); |
269 | fclose (fp); |
394 | } |
270 | } |
395 | |
271 | |
396 | /* |
272 | /* |
397 | * Initializes the gametime and TOD counters |
273 | * initialises the gametime and TOD counters |
398 | * Called by init_library(). |
274 | * Called by init_library(). |
399 | */ |
275 | */ |
400 | |
276 | |
401 | void |
277 | void |
402 | init_clocks (void) |
278 | init_clocks (void) |
… | |
… | |
409 | return; |
285 | return; |
410 | else |
286 | else |
411 | has_been_done = 1; |
287 | has_been_done = 1; |
412 | |
288 | |
413 | sprintf (filename, "%s/clockdata", settings.localdir); |
289 | sprintf (filename, "%s/clockdata", settings.localdir); |
414 | LOG (llevDebug, "Reading clockdata from %s...", filename); |
290 | LOG (llevDebug, "Reading clockdata from %s...\n", filename); |
415 | if ((fp = fopen (filename, "r")) == NULL) |
291 | if ((fp = fopen (filename, "r")) == NULL) |
416 | { |
292 | { |
417 | LOG (llevError, "Can't open %s.\n", filename); |
293 | LOG (llevError, "Can't open %s.\n", filename); |
418 | todtick = 0; |
294 | todtick = 0; |
419 | write_todclock (); |
295 | write_todclock (); |
… | |
… | |
423 | LOG (llevDebug, "todtick=%lu\n", todtick); |
299 | LOG (llevDebug, "todtick=%lu\n", todtick); |
424 | fclose (fp); |
300 | fclose (fp); |
425 | } |
301 | } |
426 | |
302 | |
427 | /* |
303 | /* |
428 | * Initializes the attack messages. |
304 | * initialises the attack messages. |
429 | * Called by init_library(). |
305 | * Called by init_library(). |
430 | */ |
306 | */ |
431 | |
307 | |
432 | //attackmess_t attack_mess[NROFATTACKMESS][MAXATTACKMESS]; |
308 | //attackmess_t attack_mess[NROFATTACKMESS][MAXATTACKMESS]; |
433 | |
309 | |
… | |
… | |
446 | return; |
322 | return; |
447 | else |
323 | else |
448 | has_been_done = 1; |
324 | has_been_done = 1; |
449 | |
325 | |
450 | sprintf (filename, "%s/attackmess", settings.datadir); |
326 | sprintf (filename, "%s/attackmess", settings.datadir); |
451 | LOG (llevDebug, "Reading attack messages from %s...", filename); |
327 | LOG (llevDebug, "Reading attack messages from %s...\n", filename); |
452 | if ((fp = open_and_uncompress (filename, 0, &comp)) == NULL) |
328 | if ((fp = open_and_uncompress (filename, 0, &comp)) == NULL) |
453 | { |
329 | { |
454 | LOG (llevError, "Can't open %s.\n", filename); |
330 | LOG (llevError, "Can't open %s.\n", filename); |
455 | return; |
331 | return; |
456 | } |
332 | } |
… | |
… | |
486 | { |
362 | { |
487 | p = strtok (buf, "="); |
363 | p = strtok (buf, "="); |
488 | attack_mess[mess][level].level = atoi (buf); |
364 | attack_mess[mess][level].level = atoi (buf); |
489 | p = strtok (NULL, "="); |
365 | p = strtok (NULL, "="); |
490 | if (p != NULL) |
366 | if (p != NULL) |
491 | attack_mess[mess][level].buf1 = strdup_local (p); |
367 | attack_mess[mess][level].buf1 = strdup (p); |
492 | else |
368 | else |
493 | attack_mess[mess][level].buf1 = strdup_local (""); |
369 | attack_mess[mess][level].buf1 = strdup (""); |
494 | mode = 2; |
370 | mode = 2; |
495 | continue; |
371 | continue; |
496 | } |
372 | } |
497 | else if (mode == 2) |
373 | else if (mode == 2) |
498 | { |
374 | { |
499 | p = strtok (buf, "="); |
375 | p = strtok (buf, "="); |
500 | attack_mess[mess][level].level = atoi (buf); |
376 | attack_mess[mess][level].level = atoi (buf); |
501 | p = strtok (NULL, "="); |
377 | p = strtok (NULL, "="); |
502 | if (p != NULL) |
378 | if (p != NULL) |
503 | attack_mess[mess][level].buf2 = strdup_local (p); |
379 | attack_mess[mess][level].buf2 = strdup (p); |
504 | else |
380 | else |
505 | attack_mess[mess][level].buf2 = strdup_local (""); |
381 | attack_mess[mess][level].buf2 = strdup (""); |
506 | mode = 3; |
382 | mode = 3; |
507 | continue; |
383 | continue; |
508 | } |
384 | } |
509 | else if (mode == 3) |
385 | else if (mode == 3) |
510 | { |
386 | { |
511 | p = strtok (buf, "="); |
387 | p = strtok (buf, "="); |
512 | attack_mess[mess][level].level = atoi (buf); |
388 | attack_mess[mess][level].level = atoi (buf); |
513 | p = strtok (NULL, "="); |
389 | p = strtok (NULL, "="); |
514 | if (p != NULL) |
390 | if (p != NULL) |
515 | attack_mess[mess][level].buf3 = strdup_local (p); |
391 | attack_mess[mess][level].buf3 = strdup (p); |
516 | else |
392 | else |
517 | attack_mess[mess][level].buf3 = strdup_local (""); |
393 | attack_mess[mess][level].buf3 = strdup (""); |
518 | mode = 1; |
394 | mode = 1; |
519 | level++; |
395 | level++; |
520 | total++; |
396 | total++; |
521 | continue; |
397 | continue; |
522 | } |
398 | } |