--- deliantra/server/common/init.C 2006/08/13 17:16:00 1.1 +++ deliantra/server/common/init.C 2006/09/07 13:52:08 1.8 @@ -1,6 +1,6 @@ /* * static char *rcsid_init_c = - * "$Id: init.C,v 1.1 2006/08/13 17:16:00 elmex Exp $"; + * "$Id: init.C,v 1.8 2006/09/07 13:52:08 root Exp $"; */ /* @@ -26,11 +26,41 @@ The authors can be reached via e-mail at crossfire-devel@real-time.com */ -#define EXTERN -#define INIT_C +#define EXTERN // horrible hack + #include #include +extern const char* const attacktype_desc[NROFATTACKS] = { +# define def(uc, name, lc, plus, change) # name, +# include "attackinc.h" +# undef def +}; + +extern const keyword resist_save[NROFATTACKS] = { +# define def(uc, name, lc, plus, change) KW_resist_ ## lc, +# include "attackinc.h" +# undef def +}; + +extern const char* const resist_plus[NROFATTACKS] = { +# define def(uc, name, lc, plus, change) # plus, +# include "attackinc.h" +# undef def +}; + +extern const char* const change_resist_msg[NROFATTACKS] = { +# define def(uc, name, lc, plus, change) # change, +# include "attackinc.h" +# undef def +}; + +int resist_table[NROFATTACKS] = { +# define def(uc, name, lc, plus, change) ATNR_ ## uc, +# include "attackinc.h" +# undef def +}; + /* You unforunately need to looking in include/global.h to see what these * correspond to. */ @@ -143,28 +173,28 @@ /* If this file doesn't exist, not a big deal */ sprintf(filename,"%s/%s/.emergency",settings.datadir, settings.mapdir); if ((fp = fopen(filename, "r"))!=NULL) { - while (fgets(tmpbuf, MAX_BUF-1, fp)) { - if (tmpbuf[0] == '#') continue; /* ignore comments */ - - if (online == 0) { - tmpbuf[strlen(tmpbuf)-1] = 0; /* kill newline */ - settings.emergency_mapname = strdup_local(tmpbuf); - } - else if (online == 1) { - settings.emergency_x = atoi(tmpbuf); - } - - else if (online == 2) { - settings.emergency_y = atoi(tmpbuf); - } - online++; - if (online>2) break; - } - fclose(fp); - if (online<=2) - LOG(llevError,"Online read partial data from %s\n", filename); - LOG(llevDebug,"Emergency mappath reset to %s (%d, %d)\n", settings.emergency_mapname, - settings.emergency_x, settings.emergency_y); + while (fgets(tmpbuf, MAX_BUF-1, fp)) { + if (tmpbuf[0] == '#') continue; /* ignore comments */ + + if (online == 0) { + tmpbuf[strlen(tmpbuf)-1] = 0; /* kill newline */ + settings.emergency_mapname = strdup_local(tmpbuf); + } + else if (online == 1) { + settings.emergency_x = atoi(tmpbuf); + } + + else if (online == 2) { + settings.emergency_y = atoi(tmpbuf); + } + online++; + if (online>2) break; + } + fclose(fp); + if (online<=2) + LOG(llevError,"Online read partial data from %s\n", filename); + LOG(llevDebug,"Emergency mappath reset to %s (%d, %d)\n", settings.emergency_mapname, + settings.emergency_x, settings.emergency_y); } } @@ -181,7 +211,6 @@ void init_library(void) { init_environ(); init_globals(); - init_hash_table(); init_objects(); init_vars(); init_block(); @@ -232,15 +261,15 @@ void init_globals(void) { if (settings.logfilename[0] == 0) { - logfile = stderr; + logfile = stderr; } else if ((logfile=fopen(settings.logfilename, "a"))==NULL) { - fprintf(stderr,"Unable to open %s as the logfile - will use stderr instead\n", - settings.logfilename); - logfile = stderr; + fprintf(stderr,"Unable to open %s as the logfile - will use stderr instead\n", + settings.logfilename); + logfile = stderr; } else { - setvbuf(logfile, NULL, _IOLBF, 0); + setvbuf(logfile, NULL, _IOLBF, 0); } exiting = 0; first_player=NULL; @@ -257,10 +286,8 @@ ring_arch = NULL; amulet_arch = NULL; staff_arch = NULL; - undead_name = add_string("undead"); trying_emergency_save = 0; num_animations=0; - animations=NULL; animations_allocated=0; init_defaults(); } @@ -271,31 +298,12 @@ * Called by init_library(); */ -void init_objects(void) { - int i; -/* Initialize all objects: */ - objects=NULL; +void +init_objects(void) +{ + /* Initialize all objects: */ + objects = NULL; active_objects = NULL; - -#ifdef MEMORY_DEBUG - free_objects=NULL; -#else - free_objects=objarray; - objarray[0].prev=NULL, - objarray[0].next= &objarray[1], - SET_FLAG(&objarray[0], FLAG_REMOVED); - SET_FLAG(&objarray[0], FLAG_FREED); - for(i=1;iclone.type == MAP) { + if (at->clone.type == MAP) { if (at->clone.race) { strcpy (first_map_ext_path, at->clone.race); } @@ -320,8 +328,8 @@ strcpy (first_map_path, EXIT_PATH (&at->clone)); return; } - } - at = at->next; + } + at = at->next; } LOG(llevDebug,"You Need a archetype called 'map' and it have to contain start map\n"); exit (-1); @@ -341,8 +349,8 @@ sprintf(filename, "%s/clockdata", settings.localdir); if ((fp = fopen(filename, "w")) == NULL) { - LOG(llevError, "Cannot open %s for writing\n", filename); - return; + LOG(llevError, "Cannot open %s for writing\n", filename); + return; } fprintf(fp, "%lu", todtick); fclose(fp); @@ -368,9 +376,9 @@ LOG(llevDebug, "Reading clockdata from %s...", filename); if ((fp = fopen(filename, "r")) == NULL) { LOG(llevError, "Can't open %s.\n", filename); - todtick = 0; - write_todclock(); - return; + todtick = 0; + write_todclock(); + return; } fscanf(fp, "%lu", &todtick); LOG(llevDebug, "todtick=%lu\n", todtick); @@ -402,65 +410,65 @@ LOG(llevDebug, "Reading attack messages from %s...", filename); if ((fp = open_and_uncompress(filename, 0, &comp)) == NULL) { LOG(llevError, "Can't open %s.\n", filename); - return; + return; } level = 0; while (fgets(buf, MAX_BUF, fp)!=NULL) { if (*buf=='#') continue; - if((cp=strchr(buf,'\n'))!=NULL) + if((cp=strchr(buf,'\n'))!=NULL) *cp='\0'; - cp=buf; - while(*cp==' ') /* Skip blanks */ - cp++; - - if (strncmp(cp, "TYPE:", 5)==0) { - p = strtok(buf, ":"); - p = strtok(NULL, ":"); - if (mode == 1) { - attack_mess[mess][level].level = -1; - attack_mess[mess][level].buf1 = NULL; - attack_mess[mess][level].buf2 = NULL; - attack_mess[mess][level].buf3 = NULL; - } - level = 0; - mess = atoi(p); - mode = 1; - continue; - } - if (mode==1) { - p = strtok(buf, "="); - attack_mess[mess][level].level = atoi(buf); - p = strtok(NULL, "="); - if (p != NULL) - attack_mess[mess][level].buf1 = strdup_local(p); - else - attack_mess[mess][level].buf1 = strdup_local(""); - mode = 2; - continue; - } else if (mode==2) { - p = strtok(buf, "="); - attack_mess[mess][level].level = atoi(buf); - p = strtok(NULL, "="); - if (p != NULL) - attack_mess[mess][level].buf2 = strdup_local(p); - else - attack_mess[mess][level].buf2 = strdup_local(""); - mode = 3; - continue; - } else if (mode==3) { - p = strtok(buf, "="); - attack_mess[mess][level].level = atoi(buf); - p = strtok(NULL, "="); - if (p != NULL) - attack_mess[mess][level].buf3 = strdup_local(p); - else - attack_mess[mess][level].buf3 = strdup_local(""); - mode = 1; - level++; - total++; - continue; - } + cp=buf; + while(*cp==' ') /* Skip blanks */ + cp++; + + if (strncmp(cp, "TYPE:", 5)==0) { + p = strtok(buf, ":"); + p = strtok(NULL, ":"); + if (mode == 1) { + attack_mess[mess][level].level = -1; + attack_mess[mess][level].buf1 = NULL; + attack_mess[mess][level].buf2 = NULL; + attack_mess[mess][level].buf3 = NULL; + } + level = 0; + mess = atoi(p); + mode = 1; + continue; + } + if (mode==1) { + p = strtok(buf, "="); + attack_mess[mess][level].level = atoi(buf); + p = strtok(NULL, "="); + if (p != NULL) + attack_mess[mess][level].buf1 = strdup_local(p); + else + attack_mess[mess][level].buf1 = strdup_local(""); + mode = 2; + continue; + } else if (mode==2) { + p = strtok(buf, "="); + attack_mess[mess][level].level = atoi(buf); + p = strtok(NULL, "="); + if (p != NULL) + attack_mess[mess][level].buf2 = strdup_local(p); + else + attack_mess[mess][level].buf2 = strdup_local(""); + mode = 3; + continue; + } else if (mode==3) { + p = strtok(buf, "="); + attack_mess[mess][level].level = atoi(buf); + p = strtok(NULL, "="); + if (p != NULL) + attack_mess[mess][level].buf3 = strdup_local(p); + else + attack_mess[mess][level].buf3 = strdup_local(""); + mode = 1; + level++; + total++; + continue; + } } LOG(llevDebug, "got %d messages in %d categories.\n", total, mess+1); close_and_delete(fp, comp);