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.1 by elmex, Sun Aug 13 17:16:00 2006 UTC vs.
Revision 1.8 by root, Thu Sep 7 13:52:08 2006 UTC

1/* 1/*
2 * static char *rcsid_init_c = 2 * static char *rcsid_init_c =
3 * "$Id: init.C,v 1.1 2006/08/13 17:16:00 elmex Exp $"; 3 * "$Id: init.C,v 1.8 2006/09/07 13:52:08 root Exp $";
4 */ 4 */
5 5
6/* 6/*
7 CrossFire, A Multiplayer game for X-windows 7 CrossFire, A Multiplayer game for X-windows
8 8
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 25
26 The authors can be reached via e-mail at crossfire-devel@real-time.com 26 The authors can be reached via e-mail at crossfire-devel@real-time.com
27*/ 27*/
28 28
29#define EXTERN 29#define EXTERN // horrible hack
30#define INIT_C 30
31#include <global.h> 31#include <global.h>
32#include <object.h> 32#include <object.h>
33
34extern const char* const attacktype_desc[NROFATTACKS] = {
35# define def(uc, name, lc, plus, change) # name,
36# include "attackinc.h"
37# undef def
38};
39
40extern const keyword resist_save[NROFATTACKS] = {
41# define def(uc, name, lc, plus, change) KW_resist_ ## lc,
42# include "attackinc.h"
43# undef def
44};
45
46extern const char* const resist_plus[NROFATTACKS] = {
47# define def(uc, name, lc, plus, change) # plus,
48# include "attackinc.h"
49# undef def
50};
51
52extern const char* const change_resist_msg[NROFATTACKS] = {
53# define def(uc, name, lc, plus, change) # change,
54# include "attackinc.h"
55# undef def
56};
57
58int resist_table[NROFATTACKS] = {
59# define def(uc, name, lc, plus, change) ATNR_ ## uc,
60# include "attackinc.h"
61# undef def
62};
33 63
34/* You unforunately need to looking in include/global.h to see what these 64/* You unforunately need to looking in include/global.h to see what these
35 * correspond to. 65 * correspond to.
36 */ 66 */
37struct Settings settings = { 67struct Settings settings = {
141 int online=0; 171 int online=0;
142 172
143 /* If this file doesn't exist, not a big deal */ 173 /* If this file doesn't exist, not a big deal */
144 sprintf(filename,"%s/%s/.emergency",settings.datadir, settings.mapdir); 174 sprintf(filename,"%s/%s/.emergency",settings.datadir, settings.mapdir);
145 if ((fp = fopen(filename, "r"))!=NULL) { 175 if ((fp = fopen(filename, "r"))!=NULL) {
146 while (fgets(tmpbuf, MAX_BUF-1, fp)) { 176 while (fgets(tmpbuf, MAX_BUF-1, fp)) {
147 if (tmpbuf[0] == '#') continue; /* ignore comments */ 177 if (tmpbuf[0] == '#') continue; /* ignore comments */
148 178
149 if (online == 0) { 179 if (online == 0) {
150 tmpbuf[strlen(tmpbuf)-1] = 0; /* kill newline */ 180 tmpbuf[strlen(tmpbuf)-1] = 0; /* kill newline */
151 settings.emergency_mapname = strdup_local(tmpbuf); 181 settings.emergency_mapname = strdup_local(tmpbuf);
152 } 182 }
153 else if (online == 1) { 183 else if (online == 1) {
154 settings.emergency_x = atoi(tmpbuf); 184 settings.emergency_x = atoi(tmpbuf);
155 } 185 }
156 186
157 else if (online == 2) { 187 else if (online == 2) {
158 settings.emergency_y = atoi(tmpbuf); 188 settings.emergency_y = atoi(tmpbuf);
159 } 189 }
160 online++; 190 online++;
161 if (online>2) break; 191 if (online>2) break;
162 } 192 }
163 fclose(fp); 193 fclose(fp);
164 if (online<=2) 194 if (online<=2)
165 LOG(llevError,"Online read partial data from %s\n", filename); 195 LOG(llevError,"Online read partial data from %s\n", filename);
166 LOG(llevDebug,"Emergency mappath reset to %s (%d, %d)\n", settings.emergency_mapname, 196 LOG(llevDebug,"Emergency mappath reset to %s (%d, %d)\n", settings.emergency_mapname,
167 settings.emergency_x, settings.emergency_y); 197 settings.emergency_x, settings.emergency_y);
168 } 198 }
169} 199}
170 200
171 201
172/* 202/*
179 */ 209 */
180 210
181void init_library(void) { 211void init_library(void) {
182 init_environ(); 212 init_environ();
183 init_globals(); 213 init_globals();
184 init_hash_table();
185 init_objects(); 214 init_objects();
186 init_vars(); 215 init_vars();
187 init_block(); 216 init_block();
188 ReadBmapNames (); 217 ReadBmapNames ();
189 ReadSmooth(); 218 ReadSmooth();
230 * Might use environment-variables as default for some of them. 259 * Might use environment-variables as default for some of them.
231 */ 260 */
232 261
233void init_globals(void) { 262void init_globals(void) {
234 if (settings.logfilename[0] == 0) { 263 if (settings.logfilename[0] == 0) {
235 logfile = stderr; 264 logfile = stderr;
236 } 265 }
237 else if ((logfile=fopen(settings.logfilename, "a"))==NULL) { 266 else if ((logfile=fopen(settings.logfilename, "a"))==NULL) {
238 fprintf(stderr,"Unable to open %s as the logfile - will use stderr instead\n", 267 fprintf(stderr,"Unable to open %s as the logfile - will use stderr instead\n",
239 settings.logfilename); 268 settings.logfilename);
240 logfile = stderr; 269 logfile = stderr;
241 } 270 }
242 else { 271 else {
243 setvbuf(logfile, NULL, _IOLBF, 0); 272 setvbuf(logfile, NULL, _IOLBF, 0);
244 } 273 }
245 exiting = 0; 274 exiting = 0;
246 first_player=NULL; 275 first_player=NULL;
247 first_friendly_object=NULL; 276 first_friendly_object=NULL;
248 first_map=NULL; 277 first_map=NULL;
255 nrofartifacts = 0; 284 nrofartifacts = 0;
256 nrofallowedstr=0; 285 nrofallowedstr=0;
257 ring_arch = NULL; 286 ring_arch = NULL;
258 amulet_arch = NULL; 287 amulet_arch = NULL;
259 staff_arch = NULL; 288 staff_arch = NULL;
260 undead_name = add_string("undead");
261 trying_emergency_save = 0; 289 trying_emergency_save = 0;
262 num_animations=0; 290 num_animations=0;
263 animations=NULL;
264 animations_allocated=0; 291 animations_allocated=0;
265 init_defaults(); 292 init_defaults();
266} 293}
267 294
268/* 295/*
269 * Sets up and initialises the linked list of free and used objects. 296 * Sets up and initialises the linked list of free and used objects.
270 * Allocates a certain chunk of objects and puts them on the free list. 297 * Allocates a certain chunk of objects and puts them on the free list.
271 * Called by init_library(); 298 * Called by init_library();
272 */ 299 */
273 300
301void
274void init_objects(void) { 302init_objects(void)
275 int i; 303{
276/* Initialize all objects: */ 304 /* Initialize all objects: */
277 objects=NULL; 305 objects = NULL;
278 active_objects = NULL; 306 active_objects = NULL;
279
280#ifdef MEMORY_DEBUG
281 free_objects=NULL;
282#else
283 free_objects=objarray;
284 objarray[0].prev=NULL,
285 objarray[0].next= &objarray[1],
286 SET_FLAG(&objarray[0], FLAG_REMOVED);
287 SET_FLAG(&objarray[0], FLAG_FREED);
288 for(i=1;i<STARTMAX-1;i++) {
289 objarray[i].next= &objarray[i+1];
290 objarray[i].prev= &objarray[i-1];
291 SET_FLAG(&objarray[i], FLAG_REMOVED);
292 SET_FLAG(&objarray[i], FLAG_FREED);
293 }
294 objarray[STARTMAX-1].next=NULL;
295 objarray[STARTMAX-1].prev= &objarray[STARTMAX-2];
296 SET_FLAG(&objarray[STARTMAX-1], FLAG_REMOVED);
297 SET_FLAG(&objarray[STARTMAX-1], FLAG_FREED);
298#endif
299} 307}
300 308
301/* 309/*
302 * Initialises global variables which can be changed by options. 310 * Initialises global variables which can be changed by options.
303 * Called by init_library(). 311 * Called by init_library().
310 318
311 319
312void init_dynamic (void) { 320void init_dynamic (void) {
313 archetype *at = first_archetype; 321 archetype *at = first_archetype;
314 while (at) { 322 while (at) {
315 if (at->clone.type == MAP) { 323 if (at->clone.type == MAP) {
316 if (at->clone.race) { 324 if (at->clone.race) {
317 strcpy (first_map_ext_path, at->clone.race); 325 strcpy (first_map_ext_path, at->clone.race);
318 } 326 }
319 if (EXIT_PATH (&at->clone)) { 327 if (EXIT_PATH (&at->clone)) {
320 strcpy (first_map_path, EXIT_PATH (&at->clone)); 328 strcpy (first_map_path, EXIT_PATH (&at->clone));
321 return; 329 return;
322 } 330 }
323 } 331 }
324 at = at->next; 332 at = at->next;
325 } 333 }
326 LOG(llevDebug,"You Need a archetype called 'map' and it have to contain start map\n"); 334 LOG(llevDebug,"You Need a archetype called 'map' and it have to contain start map\n");
327 exit (-1); 335 exit (-1);
328} 336}
329 337
339 char filename[MAX_BUF]; 347 char filename[MAX_BUF];
340 FILE *fp; 348 FILE *fp;
341 349
342 sprintf(filename, "%s/clockdata", settings.localdir); 350 sprintf(filename, "%s/clockdata", settings.localdir);
343 if ((fp = fopen(filename, "w")) == NULL) { 351 if ((fp = fopen(filename, "w")) == NULL) {
344 LOG(llevError, "Cannot open %s for writing\n", filename); 352 LOG(llevError, "Cannot open %s for writing\n", filename);
345 return; 353 return;
346 } 354 }
347 fprintf(fp, "%lu", todtick); 355 fprintf(fp, "%lu", todtick);
348 fclose(fp); 356 fclose(fp);
349} 357}
350 358
366 374
367 sprintf(filename, "%s/clockdata", settings.localdir); 375 sprintf(filename, "%s/clockdata", settings.localdir);
368 LOG(llevDebug, "Reading clockdata from %s...", filename); 376 LOG(llevDebug, "Reading clockdata from %s...", filename);
369 if ((fp = fopen(filename, "r")) == NULL) { 377 if ((fp = fopen(filename, "r")) == NULL) {
370 LOG(llevError, "Can't open %s.\n", filename); 378 LOG(llevError, "Can't open %s.\n", filename);
371 todtick = 0; 379 todtick = 0;
372 write_todclock(); 380 write_todclock();
373 return; 381 return;
374 } 382 }
375 fscanf(fp, "%lu", &todtick); 383 fscanf(fp, "%lu", &todtick);
376 LOG(llevDebug, "todtick=%lu\n", todtick); 384 LOG(llevDebug, "todtick=%lu\n", todtick);
377 fclose(fp); 385 fclose(fp);
378} 386}
400 408
401 sprintf(filename, "%s/attackmess", settings.datadir); 409 sprintf(filename, "%s/attackmess", settings.datadir);
402 LOG(llevDebug, "Reading attack messages from %s...", filename); 410 LOG(llevDebug, "Reading attack messages from %s...", filename);
403 if ((fp = open_and_uncompress(filename, 0, &comp)) == NULL) { 411 if ((fp = open_and_uncompress(filename, 0, &comp)) == NULL) {
404 LOG(llevError, "Can't open %s.\n", filename); 412 LOG(llevError, "Can't open %s.\n", filename);
405 return; 413 return;
406 } 414 }
407 415
408 level = 0; 416 level = 0;
409 while (fgets(buf, MAX_BUF, fp)!=NULL) { 417 while (fgets(buf, MAX_BUF, fp)!=NULL) {
410 if (*buf=='#') continue; 418 if (*buf=='#') continue;
411 if((cp=strchr(buf,'\n'))!=NULL) 419 if((cp=strchr(buf,'\n'))!=NULL)
412 *cp='\0'; 420 *cp='\0';
413 cp=buf; 421 cp=buf;
414 while(*cp==' ') /* Skip blanks */ 422 while(*cp==' ') /* Skip blanks */
415 cp++; 423 cp++;
416 424
417 if (strncmp(cp, "TYPE:", 5)==0) { 425 if (strncmp(cp, "TYPE:", 5)==0) {
418 p = strtok(buf, ":"); 426 p = strtok(buf, ":");
419 p = strtok(NULL, ":"); 427 p = strtok(NULL, ":");
420 if (mode == 1) { 428 if (mode == 1) {
421 attack_mess[mess][level].level = -1; 429 attack_mess[mess][level].level = -1;
422 attack_mess[mess][level].buf1 = NULL; 430 attack_mess[mess][level].buf1 = NULL;
423 attack_mess[mess][level].buf2 = NULL; 431 attack_mess[mess][level].buf2 = NULL;
424 attack_mess[mess][level].buf3 = NULL; 432 attack_mess[mess][level].buf3 = NULL;
425 } 433 }
426 level = 0; 434 level = 0;
427 mess = atoi(p); 435 mess = atoi(p);
428 mode = 1; 436 mode = 1;
429 continue; 437 continue;
430 } 438 }
431 if (mode==1) { 439 if (mode==1) {
432 p = strtok(buf, "="); 440 p = strtok(buf, "=");
433 attack_mess[mess][level].level = atoi(buf); 441 attack_mess[mess][level].level = atoi(buf);
434 p = strtok(NULL, "="); 442 p = strtok(NULL, "=");
435 if (p != NULL) 443 if (p != NULL)
436 attack_mess[mess][level].buf1 = strdup_local(p); 444 attack_mess[mess][level].buf1 = strdup_local(p);
437 else 445 else
438 attack_mess[mess][level].buf1 = strdup_local(""); 446 attack_mess[mess][level].buf1 = strdup_local("");
439 mode = 2; 447 mode = 2;
440 continue; 448 continue;
441 } else if (mode==2) { 449 } else if (mode==2) {
442 p = strtok(buf, "="); 450 p = strtok(buf, "=");
443 attack_mess[mess][level].level = atoi(buf); 451 attack_mess[mess][level].level = atoi(buf);
444 p = strtok(NULL, "="); 452 p = strtok(NULL, "=");
445 if (p != NULL) 453 if (p != NULL)
446 attack_mess[mess][level].buf2 = strdup_local(p); 454 attack_mess[mess][level].buf2 = strdup_local(p);
447 else 455 else
448 attack_mess[mess][level].buf2 = strdup_local(""); 456 attack_mess[mess][level].buf2 = strdup_local("");
449 mode = 3; 457 mode = 3;
450 continue; 458 continue;
451 } else if (mode==3) { 459 } else if (mode==3) {
452 p = strtok(buf, "="); 460 p = strtok(buf, "=");
453 attack_mess[mess][level].level = atoi(buf); 461 attack_mess[mess][level].level = atoi(buf);
454 p = strtok(NULL, "="); 462 p = strtok(NULL, "=");
455 if (p != NULL) 463 if (p != NULL)
456 attack_mess[mess][level].buf3 = strdup_local(p); 464 attack_mess[mess][level].buf3 = strdup_local(p);
457 else 465 else
458 attack_mess[mess][level].buf3 = strdup_local(""); 466 attack_mess[mess][level].buf3 = strdup_local("");
459 mode = 1; 467 mode = 1;
460 level++; 468 level++;
461 total++; 469 total++;
462 continue; 470 continue;
463 } 471 }
464 } 472 }
465 LOG(llevDebug, "got %d messages in %d categories.\n", total, mess+1); 473 LOG(llevDebug, "got %d messages in %d categories.\n", total, mess+1);
466 close_and_delete(fp, comp); 474 close_and_delete(fp, comp);
467} 475}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines