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

Comparing deliantra/server/server/init.C (file contents):
Revision 1.5 by root, Wed Aug 30 16:30:37 2006 UTC vs.
Revision 1.8 by elmex, Sun Sep 3 14:33:46 2006 UTC

1/* 1/*
2 * static char *rcsid_init_c = 2 * static char *rcsid_init_c =
3 * "$Id: init.C,v 1.5 2006/08/30 16:30:37 root Exp $"; 3 * "$Id: init.C,v 1.8 2006/09/03 14:33:46 elmex 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
203 exit(1); 203 exit(1);
204 } 204 }
205 } 205 }
206} 206}
207 207
208//TODO: make this a constructor
208static materialtype_t *get_empty_mat(void) { 209static materialtype_t *get_empty_mat(void) {
209 materialtype_t *mt; 210 materialtype_t *mt;
210 int i; 211 int i;
211 212
212 mt = (materialtype_t *)malloc(sizeof(materialtype_t)); 213 mt = new materialtype_t;
213 if (mt == NULL) 214
214 fatal(OUT_OF_MEMORY);
215 mt->name = NULL; 215 mt->name = NULL;
216 mt->description = NULL; 216 mt->description = NULL;
217 for (i=0; i < NROFATTACKS; i++) { 217 for (i=0; i < NROFATTACKS; i++) {
218 mt->save[i] = 0; 218 mt->save[i] = 0;
219 mt->mod[i] = 0; 219 mt->mod[i] = 0;
259 cp++; 259 cp++;
260 if (!strncmp(cp, "name", 4)) { 260 if (!strncmp(cp, "name", 4)) {
261 /* clean up the previous entry */ 261 /* clean up the previous entry */
262 if (mt->next != NULL) { 262 if (mt->next != NULL) {
263 if (mt->description == NULL) 263 if (mt->description == NULL)
264 mt->description = add_string(mt->name); 264 mt->description = mt->name;
265 mt = mt->next; 265 mt = mt->next;
266 } 266 }
267 mt->next = get_empty_mat(); 267 mt->next = get_empty_mat ();
268 mt->name = add_string(strchr(cp, ' ') + 1); 268 mt->name = strchr(cp, ' ') + 1;
269 } else if (!strncmp(cp, "description", 11)) { 269 } else if (!strncmp(cp, "description", 11)) {
270 mt->description = add_string(strchr(cp, ' ') + 1); 270 mt->description = strchr(cp, ' ') + 1;
271 } else if (sscanf(cp, "material %d", &value)) { 271 } else if (sscanf(cp, "material %d", &value)) {
272 mt->material = value; 272 mt->material = value;
273 } else if (!strncmp(cp, "saves", 5)) { 273 } else if (!strncmp(cp, "saves", 5)) {
274 cp = strchr(cp, ' ') + 1; 274 cp = strchr(cp, ' ') + 1;
275 for (i=0; i < NROFATTACKS; i++) { 275 for (i=0; i < NROFATTACKS; i++) {
316 mt->value = value; 316 mt->value = value;
317 } 317 }
318 } 318 }
319 if (mt->next) 319 if (mt->next)
320 { 320 {
321 free(mt->next); 321 delete mt->next;
322 mt->next = NULL; 322 mt->next = NULL;
323 } 323 }
324 LOG(llevDebug, "Done.\n"); 324 LOG(llevDebug, "Done.\n");
325 fclose(fp); 325 fclose(fp);
326} 326}
833 dump_races(); 833 dump_races();
834 exit(0); 834 exit(0);
835 case 7: 835 case 7:
836 dump_alchemy(); 836 dump_alchemy();
837 exit(0); 837 exit(0);
838 case 8:
839 dump_gods();
840 exit(0);
841 case 9: 838 case 9:
842 dump_alchemy_costs(); 839 dump_alchemy_costs();
843 exit(0); 840 exit(0);
844 case 10: 841 case 10:
845 dump_monster_treasure(settings.dumparg); 842 dump_monster_treasure(settings.dumparg);
1002 * overwrites old 'race' entries. This routine allow us to quickly 999 * overwrites old 'race' entries. This routine allow us to quickly
1003 * re-configure the 'alignment' of monsters, objects. Useful for 1000 * re-configure the 'alignment' of monsters, objects. Useful for
1004 * putting together lists of creatures, etc that belong to gods. 1001 * putting together lists of creatures, etc that belong to gods.
1005 */ 1002 */
1006 1003
1007void init_races (void) { 1004void init_races (void)
1005{
1008 FILE *file; 1006 FILE *file;
1009 char race[MAX_BUF], fname[MAX_BUF], buf[MAX_BUF], *cp, variable[MAX_BUF]; 1007 char race[MAX_BUF], fname[MAX_BUF], buf[MAX_BUF], *cp, variable[MAX_BUF];
1010 archetype *mon=NULL; 1008 archetype *mon = NULL;
1011 static int init_done=0; 1009 static int init_done = 0;
1012 1010
1013 if (init_done) return; 1011 if (init_done)
1014 init_done=1;
1015 first_race=NULL;
1016
1017 sprintf(fname,"%s/races",settings.datadir);
1018 LOG(llevDebug, "Reading races from %s...",fname);
1019 if(! (file=fopen(fname,"r"))) {
1020 LOG(llevError, "Cannot open races file %s: %s\n", fname, strerror(errno));
1021 return; 1012 return;
1022 } 1013 init_done = 1;
1014 first_race = NULL;
1023 1015
1024 while(fgets(buf,MAX_BUF,file)!=NULL) { 1016 sprintf (fname, "%s/races", settings.datadir);
1025 int set_race=1,set_list=1; 1017 LOG (llevDebug, "Reading races from %s...", fname);
1026 if(*buf=='#') continue; 1018 if (!(file = fopen (fname, "r")))
1027 if((cp=strchr(buf,'\n'))!=NULL) 1019 {
1028 *cp='\0'; 1020 LOG (llevError, "Cannot open races file %s: %s\n", fname,
1029 cp=buf; 1021 strerror (errno));
1030 while(*cp==' '||*cp=='!'||*cp=='@') { 1022 return;
1031 if(*cp=='!') set_race=0;
1032 if(*cp=='@') set_list=0;
1033 cp++;
1034 } 1023 }
1035 if(sscanf(cp,"RACE %s",variable)) { /* set new race value */ 1024
1036 strcpy(race,variable); 1025 while (fgets (buf, MAX_BUF, file) != NULL)
1037 } else { 1026 {
1038 char *cp1; 1027 int set_race = 1, set_list = 1;
1039 /* Take out beginning spaces */ 1028 if (*buf == '#')
1040 for (cp1 = cp; *cp1==' '; cp1++); 1029 continue;
1041 /* Remove newline and trailing spaces */ 1030 if ((cp = strchr (buf, '\n')) != NULL)
1042 for (cp1 = cp + strlen(cp) -1; *cp1 == '\n' || *cp1 == ' '; cp1 --) {
1043 *cp1='\0'; 1031 *cp = '\0';
1044 if (cp==cp1) break; 1032 cp = buf;
1033 while (*cp == ' ' || *cp == '!' || *cp == '@')
1034 {
1035 if (*cp == '!')
1036 set_race = 0;
1037 if (*cp == '@')
1038 set_list = 0;
1039 cp++;
1045 } 1040 }
1041 if (sscanf (cp, "RACE %s", variable))
1042 { /* set new race value */
1043 strcpy (race, variable);
1046 1044 }
1047 if (cp[strlen(cp)-1]=='\n') cp[strlen(cp)-1]='\0'; 1045 else
1046 {
1047 char *cp1;
1048 /* Take out beginning spaces */
1049 for (cp1 = cp; *cp1 == ' '; cp1++)
1050 ;
1051 /* Remove newline and trailing spaces */
1052 for (cp1 = cp + strlen (cp) - 1; *cp1 == '\n' || *cp1 == ' '; cp1--)
1053 {
1054 *cp1 = '\0';
1055 if (cp == cp1)
1056 break;
1057 }
1058
1059 if (cp[strlen (cp) - 1] == '\n')
1060 cp[strlen (cp) - 1] = '\0';
1048 /* set creature race to race value */ 1061 /* set creature race to race value */
1049 if((mon=find_archetype(cp))==NULL) 1062 if ((mon = find_archetype (cp)) == NULL)
1050 LOG(llevError,"\nCreature %s in race file lacks archetype",cp); 1063 LOG (llevError, "\nCreature %s in race file lacks archetype", cp);
1051 else { 1064 else
1065 {
1066 if (set_race
1052 if(set_race&&(!mon->clone.race||strcmp(mon->clone.race,race))) { 1067 && (!mon->clone.race || strcmp (mon->clone.race, race)))
1068 {
1053 if(mon->clone.race) { 1069 if (mon->clone.race)
1070 {
1071 LOG (llevDebug,
1054 LOG(llevDebug,"\n Resetting race to %s from %s for archetype %s", 1072 "\n Resetting race to %s from %s for archetype %s",
1055 race,mon->clone.race,mon->name); 1073 race, &mon->clone.race, &mon->name);
1074 }
1056 free_string(mon->clone.race); 1075 mon->clone.race = race;
1057 } 1076 }
1058 mon->clone.race=add_string(race);
1059 }
1060 /* if the arch is a monster, add it to the race list */ 1077 /* if the arch is a monster, add it to the race list */
1061 if(set_list&&QUERY_FLAG(&mon->clone,FLAG_MONSTER)) 1078 if (set_list && QUERY_FLAG (&mon->clone, FLAG_MONSTER))
1062 add_to_racelist(race, &mon->clone); 1079 add_to_racelist (race, &mon->clone);
1080 }
1063 } 1081 }
1064 } 1082 }
1065 }
1066 fclose(file); 1083 fclose (file);
1067 LOG(llevDebug,"done.\n"); 1084 LOG (llevDebug, "done.\n");
1068} 1085}
1069 1086
1070void dump_races(void) 1087void dump_races(void)
1071{ 1088{
1072 racelink *list; 1089 racelink *list;
1073 objectlink *tmp; 1090 objectlink *tmp;
1074 for(list=first_race;list;list=list->next) { 1091 for(list=first_race;list;list=list->next) {
1075 fprintf(stderr,"\nRACE %s:\t",list->name); 1092 fprintf(stderr,"\nRACE %s:\t",list->name);
1076 for(tmp=list->member;tmp;tmp=tmp->next) 1093 for(tmp=list->member;tmp;tmp=tmp->next)
1077 fprintf(stderr,"%s(%d), ",tmp->ob->arch->name,tmp->ob->level); 1094 fprintf(stderr,"%s(%d), ",&tmp->ob->arch->name,tmp->ob->level);
1078 } 1095 }
1079 fprintf(stderr,"\n"); 1096 fprintf(stderr,"\n");
1080} 1097}
1081 1098
1082void add_to_racelist (const char *race_name, object *op) { 1099void add_to_racelist (const char *race_name, object *op) {
1087 1104
1088 if(!race) { /* add in a new race list */ 1105 if(!race) { /* add in a new race list */
1089 race = get_racelist(); 1106 race = get_racelist();
1090 race->next = first_race; 1107 race->next = first_race;
1091 first_race = race; 1108 first_race = race;
1092 race->name=add_string(race_name); 1109 race->name = race_name;
1093 } 1110 }
1094 1111
1095 if(race->member->ob) { 1112 if(race->member->ob) {
1096 objectlink *tmp = get_objectlink(); 1113 objectlink *tmp = get_objectlink();
1097 tmp->next=race->member; 1114 tmp->next=race->member;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines