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

Comparing deliantra/server/common/init.C (file contents):
Revision 1.10 by root, Sun Sep 10 16:00:23 2006 UTC vs.
Revision 1.55 by root, Fri Mar 26 01:04:44 2010 UTC

1
2/* 1/*
3 * static char *rcsid_init_c = 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
4 * "$Id: init.C,v 1.10 2006/09/10 16:00:23 root Exp $"; 3 *
5 */ 4 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
6
7/*
8 CrossFire, A Multiplayer game for X-windows
9
10 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
11 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
12 7 *
13 This program is free software; you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify it under
14 it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
15 the Free Software Foundation; either version 2 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
16 (at your option) any later version. 11 * 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 Affero GNU General Public License
24 along with this program; if not, write to the Free Software 19 * and the GNU General Public License along with this program. If not, see
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * <http://www.gnu.org/licenses/>.
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 to <support@deliantra.net>
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
30dynbuf_text msg_dynbuf (65536, 65536);
31
35extern const char *const attacktype_desc[NROFATTACKS] = { 32extern const char *const attacktype_desc[NROFATTACKS] = {
36#define def(uc, lc, name, plus, change) # name, 33# define def(uc, lc, name, plus, change) # name,
37#include "attackinc.h" 34# include "attackinc.h"
38#undef def 35# undef def
39};
40
41extern const keyword resist_save[NROFATTACKS] = {
42#define def(uc, lc, name, plus, change) KW_resist_ ## lc,
43#include "attackinc.h"
44#undef def
45}; 36};
46 37
47extern const char *const resist_plus[NROFATTACKS] = { 38extern const char *const resist_plus[NROFATTACKS] = {
48#define def(uc, lc, name, plus, change) # plus, 39# define def(uc, lc, name, plus, change) # plus,
49#include "attackinc.h" 40# include "attackinc.h"
50#undef def 41# undef def
51}; 42};
52 43
53extern const char *const change_resist_msg[NROFATTACKS] = { 44extern const char *const change_resist_msg[NROFATTACKS] = {
54#define def(uc, lc, name, plus, change) # change, 45# define def(uc, lc, name, plus, change) # change,
55#include "attackinc.h" 46# include "attackinc.h"
56#undef def 47# undef def
57}; 48};
58 49
59int resist_table[NROFATTACKS] = { 50int resist_table[NROFATTACKS] = {
60#define def(uc, lc, name, plus, change) ATNR_ ## uc, 51# define def(uc, lc, name, plus, change) ATNR_ ## uc,
61#include "attackinc.h" 52# include "attackinc.h"
62#undef def 53# undef def
63}; 54};
64 55
65/* You unforunately need to looking in include/global.h to see what these 56/* You unforunately need to looking in include/global.h to see what these
66 * correspond to. 57 * correspond to.
67 */ 58 */
81 NULL, /* argv */ 72 NULL, /* argv */
82 CONFDIR, 73 CONFDIR,
83 DATADIR, 74 DATADIR,
84 LOCALDIR, 75 LOCALDIR,
85 PLAYERDIR, MAPDIR, ARCHETYPES, REGIONS, TREASURES, 76 PLAYERDIR, MAPDIR, ARCHETYPES, REGIONS, TREASURES,
86 UNIQUE_DIR, TEMPLATE_DIR, 77 UNIQUE_DIR, "",
87 TMPDIR, 78 TMPDIR,
79 PK_LUCK_PENALTY,
88 STAT_LOSS_ON_DEATH, 80 STAT_LOSS_ON_DEATH,
89 PK_LUCK_PENALTY,
90 PERMANENT_EXPERIENCE_RATIO, 81 PERMANENT_EXPERIENCE_RATIO,
91 DEATH_PENALTY_RATIO, 82 DEATH_PENALTY_RATIO,
92 DEATH_PENALTY_LEVEL, 83 DEATH_PENALTY_LEVEL,
93 BALANCED_STAT_LOSS, 84 BALANCED_STAT_LOSS,
94 NOT_PERMADETH, 85 NOT_PERMADETH,
95 SIMPLE_EXP, 86 SIMPLE_EXP,
96 RESET_LOCATION_TIME,
97 SET_TITLE, 87 SET_TITLE,
98 RESURRECTION, 88 RESURRECTION,
99 SEARCH_ITEMS, 89 SEARCH_ITEMS,
100 SPELL_ENCUMBRANCE, 90 SPELL_ENCUMBRANCE,
101 SPELL_FAILURE_EFFECTS, 91 SPELL_FAILURE_EFFECTS,
102 CASTING_TIME, 92 SET_FRIENDLY_FIRE,
103 REAL_WIZ, 93 0,
104 RECYCLE_TMP_MAPS, 94 0,
105 EXPLORE_MODE, 95 EXPLORE_MODE,
106 SPELLPOINT_LEVEL_DEPEND, 96 SPELLPOINT_LEVEL_DEPEND,
107 SET_FRIENDLY_FIRE,
108 "", /* Who format specifier */
109 "", /* who wiz format specifier */
110 MOTD,
111 "rules",
112 "news",
113 "", /* 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 */
120 EMERGENCY_MAPPATH, EMERGENCY_X, EMERGENCY_Y,
121 0, 97 0,
122 1.0, 98 1.0,
123 99
124/* Armor enchantment stuff */ 100/* Armor enchantment stuff */
125 ARMOR_MAX_ENCHANT, 101 ARMOR_MAX_ENCHANT,
126 ARMOR_WEIGHT_REDUCTION, 102 ARMOR_WEIGHT_REDUCTION,
127 ARMOR_WEIGHT_LINEAR, 103 ARMOR_WEIGHT_LINEAR,
128 ARMOR_SPEED_IMPROVEMENT, 104 ARMOR_SPEED_IMPROVEMENT,
129 ARMOR_SPEED_LINEAR, 105 ARMOR_SPEED_LINEAR,
130 1, /* no_player_stealing */
131 1, /* create_home_portals */
132}; 106};
133 107
134/* perhaps not the best place for this, but needs to be 108/* perhaps not the best place for this, but needs to be
135 * in some file in the common area so that standalone 109 * in some file in the common area so that standalone
136 * programs, like the random map generator, can be built. 110 * programs, like the random map generator, can be built.
156 "Wounding", 130 "Wounding",
157 "Death", 131 "Death",
158 "Light" 132 "Light"
159}; 133};
160 134
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 */
169static void
170init_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/*
212 * It is vital that init_library() is called by any functions
213 * using this library.
214 * 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
216 * init_function_pointers(). Good idea to also call init_vars and
217 * init_hash_table if you are doing any object loading.
218 */
219
220void
221init_library (void)
222{
223 init_environ ();
224 init_globals ();
225 init_objects ();
226 init_vars ();
227 init_block ();
228 ReadBmapNames ();
229 ReadSmooth ();
230 init_anim (); /* Must be after we read in the bitmaps */
231 init_archetypes (); /* Reads all archetypes from file */
232 init_dynamic ();
233 init_attackmess ();
234 init_clocks ();
235 init_emergency_mappath ();
236 init_experience ();
237}
238
239
240/* init_environ initializes values from the environmental variables. 135/* init_environ initialises values from the environmental variables.
241 * it needs to be called very early, since command line options should 136 * it needs to be called very early, since command line options should
242 * overwrite these if specified. 137 * overwrite these if specified.
243 */ 138 */
244void 139void
245init_environ (void) 140init_environ ()
246{ 141{
247 char *cp; 142 const char *cp;
248 143
249 cp = getenv ("CROSSFIRE_LIBDIR"); 144 if (cp = getenv ("DELIANTRA_CONFDIR" )) settings.confdir = cp;
250 if (cp) 145 if (cp = getenv ("DELIANTRA_LIBDIR" )) settings.datadir = cp;
251 settings.datadir = cp; 146 if (cp = getenv ("DELIANTRA_LOCALDIR" )) settings.localdir = cp;
252 cp = getenv ("CROSSFIRE_LOCALDIR"); 147 if (cp = getenv ("DELIANTRA_PLAYERDIR" )) settings.playerdir = cp;
253 if (cp) 148 if (cp = getenv ("DELIANTRA_MAPDIR" )) settings.mapdir = cp;
254 settings.localdir = cp; 149 if (cp = getenv ("DELIANTRA_ARCHETYPES" )) settings.archetypes = cp;
255 cp = getenv ("CROSSFIRE_PLAYERDIR"); 150 if (cp = getenv ("DELIANTRA_TREASURES" )) settings.treasures = cp;
256 if (cp) 151 if (cp = getenv ("DELIANTRA_UNIQUEDIR" )) settings.uniquedir = cp;
257 settings.playerdir = cp; 152 if (cp = getenv ("DELIANTRA_TEMPLATEDIR")) settings.templatedir = cp;
258 cp = getenv ("CROSSFIRE_MAPDIR"); 153 if (cp = getenv ("DELIANTRA_TMPDIR" )) settings.tmpdir = cp;
259 if (cp)
260 settings.mapdir = cp;
261 cp = getenv ("CROSSFIRE_ARCHETYPES");
262 if (cp)
263 settings.archetypes = cp;
264 cp = getenv ("CROSSFIRE_TREASURES");
265 if (cp)
266 settings.treasures = cp;
267 cp = getenv ("CROSSFIRE_UNIQUEDIR");
268 if (cp)
269 settings.uniquedir = cp;
270 cp = getenv ("CROSSFIRE_TEMPLATEDIR");
271 if (cp)
272 settings.templatedir = cp;
273 cp = getenv ("CROSSFIRE_TMPDIR");
274 if (cp)
275 settings.tmpdir = cp;
276}
277 154
155 if (cp = getenv ("DELIANTRA_LOGFILE" )) settings.logfilename = cp;
156}
278 157
279/* 158/*
280 * Initialises all global variables. 159 * Initialises all global variables.
281 * Might use environment-variables as default for some of them. 160 * Might use environment-variables as default for some of them.
282 */ 161 */
283
284void 162void
285init_globals (void) 163init_globals ()
286{ 164{
287 if (settings.logfilename[0] == 0) 165 if (settings.logfilename[0] == 0)
166 set_logfd (-1);
167 else
288 { 168 {
289 logfile = stderr; 169 int logfd = open (settings.logfilename, O_CREAT|O_WRONLY|O_APPEND, 0666);
170
171 if (logfd >= 0)
172 set_logfd (logfd);
173 else
174 {
175 set_logfd (-1);
176 LOG (llevError, "Unable to open %s as the logfile - will use stderr instead", settings.logfilename);
177 }
290 } 178 }
291 else if ((logfile = fopen (settings.logfilename, "a")) == NULL) 179}
292 { 180
293 fprintf (stderr, "Unable to open %s as the logfile - will use stderr instead\n", settings.logfilename); 181void
294 logfile = stderr; 182init_dynamic ()
295 } 183{
296 else 184 first_map_ext_path = "/start/HallsOfSelection";
297 { 185 first_map_path = "/HallOfSelection";
298 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} 186}
320 187
321/* 188/*
322 * Sets up and initialises the linked list of free and used objects. 189 * initialises the attack messages.
323 * Allocates a certain chunk of objects and puts them on the free list.
324 * Called by init_library();
325 */
326
327void
328init_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(). 190 * Called by init_library().
338 */ 191 */
339 192
340void
341init_defaults (void)
342{
343 editor = 0;
344 nroferrors = 0;
345}
346
347
348void
349init_dynamic (void)
350{
351 archetype *at = first_archetype;
352
353 while (at)
354 {
355 if (at->clone.type == MAP)
356 {
357 if (at->clone.race)
358 {
359 strcpy (first_map_ext_path, at->clone.race);
360 }
361 if (EXIT_PATH (&at->clone))
362 {
363 strcpy (first_map_path, EXIT_PATH (&at->clone));
364 return;
365 }
366 }
367 at = at->next;
368 }
369 LOG (llevDebug, "You Need a archetype called 'map' and it have to contain start map\n");
370 exit (-1);
371}
372
373unsigned long todtick;
374
375/*
376 * Write out the current time to the file so time does not
377 * reset every time the server reboots.
378 */
379
380void
381write_todclock (void)
382{
383 char filename[MAX_BUF];
384 FILE *fp;
385
386 sprintf (filename, "%s/clockdata", settings.localdir);
387 if ((fp = fopen (filename, "w")) == NULL)
388 {
389 LOG (llevError, "Cannot open %s for writing\n", filename);
390 return;
391 }
392 fprintf (fp, "%lu", todtick);
393 fclose (fp);
394}
395
396/*
397 * Initializes the gametime and TOD counters
398 * Called by init_library().
399 */
400
401void
402init_clocks (void)
403{
404 char filename[MAX_BUF];
405 FILE *fp;
406 static int has_been_done = 0;
407
408 if (has_been_done)
409 return;
410 else
411 has_been_done = 1;
412
413 sprintf (filename, "%s/clockdata", settings.localdir);
414 LOG (llevDebug, "Reading clockdata from %s...", filename);
415 if ((fp = fopen (filename, "r")) == NULL)
416 {
417 LOG (llevError, "Can't open %s.\n", filename);
418 todtick = 0;
419 write_todclock ();
420 return;
421 }
422 fscanf (fp, "%lu", &todtick);
423 LOG (llevDebug, "todtick=%lu\n", todtick);
424 fclose (fp);
425}
426
427/*
428 * Initializes the attack messages.
429 * Called by init_library().
430 */
431
432//attackmess_t attack_mess[NROFATTACKMESS][MAXATTACKMESS]; 193//attackmess_t attack_mess[NROFATTACKMESS][MAXATTACKMESS];
433 194
434void 195void
435init_attackmess (void) 196init_attackmess ()
436{ 197{
437 char buf[MAX_BUF]; 198 char buf[MAX_BUF];
438 char filename[MAX_BUF]; 199 char filename[MAX_BUF];
439 char *cp, *p; 200 char *cp, *p;
440 FILE *fp; 201 FILE *fp;
441 static int has_been_done = 0; 202 static int has_been_done = 0;
442 int mess, level, comp; 203 int msgnum, level, comp;
443 int mode = 0, total = 0; 204 int mode = 0, total = 0;
444 205
445 if (has_been_done) 206 if (has_been_done)
446 return; 207 return;
447 else 208 else
448 has_been_done = 1; 209 has_been_done = 1;
449 210
450 sprintf (filename, "%s/attackmess", settings.datadir); 211 sprintf (filename, "%s/attackmess", settings.datadir);
451 LOG (llevDebug, "Reading attack messages from %s...", filename); 212 LOG (llevDebug, "Reading attack messages from %s...\n", filename);
452 if ((fp = open_and_uncompress (filename, 0, &comp)) == NULL) 213 if ((fp = open_and_uncompress (filename, 0, &comp)) == NULL)
453 { 214 {
454 LOG (llevError, "Can't open %s.\n", filename); 215 LOG (llevError, "Can't open %s.\n", filename);
455 return; 216 return;
456 } 217 }
458 level = 0; 219 level = 0;
459 while (fgets (buf, MAX_BUF, fp) != NULL) 220 while (fgets (buf, MAX_BUF, fp) != NULL)
460 { 221 {
461 if (*buf == '#') 222 if (*buf == '#')
462 continue; 223 continue;
224
463 if ((cp = strchr (buf, '\n')) != NULL) 225 if ((cp = strchr (buf, '\n')) != NULL)
464 *cp = '\0'; 226 *cp = '\0';
227
465 cp = buf; 228 cp = buf;
466 while (*cp == ' ') /* Skip blanks */ 229 while (*cp == ' ') /* Skip blanks */
467 cp++; 230 cp++;
468 231
469 if (strncmp (cp, "TYPE:", 5) == 0) 232 if (strncmp (cp, "TYPE:", 5) == 0)
470 { 233 {
471 p = strtok (buf, ":"); 234 p = strtok (buf, ":");
472 p = strtok (NULL, ":"); 235 p = strtok (NULL, ":");
236
473 if (mode == 1) 237 if (mode == 1)
474 { 238 {
475 attack_mess[mess][level].level = -1; 239 attack_mess[msgnum][level].level = -1;
476 attack_mess[mess][level].buf1 = NULL; 240 attack_mess[msgnum][level].buf1 = NULL;
477 attack_mess[mess][level].buf2 = NULL; 241 attack_mess[msgnum][level].buf2 = NULL;
478 attack_mess[mess][level].buf3 = NULL; 242 attack_mess[msgnum][level].buf3 = NULL;
479 } 243 }
244
480 level = 0; 245 level = 0;
481 mess = atoi (p); 246 msgnum = atoi (p);
482 mode = 1; 247 mode = 1;
483 continue;
484 } 248 }
485 if (mode == 1) 249 else if (mode == 1)
486 { 250 {
487 p = strtok (buf, "="); 251 p = strtok (buf, "=");
488 attack_mess[mess][level].level = atoi (buf); 252 attack_mess[msgnum][level].level = atoi (buf);
489 p = strtok (NULL, "="); 253 p = strtok (NULL, "=");
254
490 if (p != NULL) 255 if (p != NULL)
491 attack_mess[mess][level].buf1 = strdup_local (p); 256 attack_mess[msgnum][level].buf1 = strdup (p);
492 else 257 else
493 attack_mess[mess][level].buf1 = strdup_local (""); 258 attack_mess[msgnum][level].buf1 = strdup ("");
259
494 mode = 2; 260 mode = 2;
495 continue;
496 } 261 }
497 else if (mode == 2) 262 else if (mode == 2)
498 { 263 {
499 p = strtok (buf, "="); 264 p = strtok (buf, "=");
500 attack_mess[mess][level].level = atoi (buf); 265 attack_mess[msgnum][level].level = atoi (buf);
501 p = strtok (NULL, "="); 266 p = strtok (NULL, "=");
267
502 if (p != NULL) 268 if (p != NULL)
503 attack_mess[mess][level].buf2 = strdup_local (p); 269 attack_mess[msgnum][level].buf2 = strdup (p);
504 else 270 else
505 attack_mess[mess][level].buf2 = strdup_local (""); 271 attack_mess[msgnum][level].buf2 = strdup ("");
272
506 mode = 3; 273 mode = 3;
507 continue;
508 } 274 }
509 else if (mode == 3) 275 else if (mode == 3)
510 { 276 {
511 p = strtok (buf, "="); 277 p = strtok (buf, "=");
512 attack_mess[mess][level].level = atoi (buf); 278 attack_mess[msgnum][level].level = atoi (buf);
513 p = strtok (NULL, "="); 279 p = strtok (NULL, "=");
280
514 if (p != NULL) 281 if (p != NULL)
515 attack_mess[mess][level].buf3 = strdup_local (p); 282 attack_mess[msgnum][level].buf3 = strdup (p);
516 else 283 else
517 attack_mess[mess][level].buf3 = strdup_local (""); 284 attack_mess[msgnum][level].buf3 = strdup ("");
285
518 mode = 1; 286 mode = 1;
519 level++; 287 level++;
520 total++; 288 total++;
521 continue;
522 } 289 }
523 } 290 }
291
524 LOG (llevDebug, "got %d messages in %d categories.\n", total, mess + 1); 292 LOG (llevDebug, "got %d messages in %d categories.\n", total, msgnum + 1);
525 close_and_delete (fp, comp); 293 close_and_delete (fp, comp);
526} 294}
295

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines