1 | /* |
1 | /* |
2 | * static char *rcsid_init_c = |
2 | * static char *rcsid_init_c = |
3 | * "$Id: init.C,v 1.7 2006/09/03 00:18:42 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 | |
… | |
… | |
999 | * overwrites old 'race' entries. This routine allow us to quickly |
999 | * overwrites old 'race' entries. This routine allow us to quickly |
1000 | * re-configure the 'alignment' of monsters, objects. Useful for |
1000 | * re-configure the 'alignment' of monsters, objects. Useful for |
1001 | * putting together lists of creatures, etc that belong to gods. |
1001 | * putting together lists of creatures, etc that belong to gods. |
1002 | */ |
1002 | */ |
1003 | |
1003 | |
1004 | void init_races (void) { |
1004 | void init_races (void) |
|
|
1005 | { |
1005 | FILE *file; |
1006 | FILE *file; |
1006 | 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]; |
1007 | archetype *mon=NULL; |
1008 | archetype *mon = NULL; |
1008 | static int init_done=0; |
1009 | static int init_done = 0; |
1009 | |
1010 | |
1010 | if (init_done) return; |
1011 | if (init_done) |
1011 | init_done=1; |
|
|
1012 | first_race=NULL; |
|
|
1013 | |
|
|
1014 | sprintf(fname,"%s/races",settings.datadir); |
|
|
1015 | LOG(llevDebug, "Reading races from %s...",fname); |
|
|
1016 | if(! (file=fopen(fname,"r"))) { |
|
|
1017 | LOG(llevError, "Cannot open races file %s: %s\n", fname, strerror(errno)); |
|
|
1018 | return; |
1012 | return; |
1019 | } |
1013 | init_done = 1; |
|
|
1014 | first_race = NULL; |
1020 | |
1015 | |
1021 | while(fgets(buf,MAX_BUF,file)!=NULL) { |
1016 | sprintf (fname, "%s/races", settings.datadir); |
1022 | int set_race=1,set_list=1; |
1017 | LOG (llevDebug, "Reading races from %s...", fname); |
1023 | if(*buf=='#') continue; |
1018 | if (!(file = fopen (fname, "r"))) |
1024 | if((cp=strchr(buf,'\n'))!=NULL) |
1019 | { |
1025 | *cp='\0'; |
1020 | LOG (llevError, "Cannot open races file %s: %s\n", fname, |
1026 | cp=buf; |
1021 | strerror (errno)); |
1027 | while(*cp==' '||*cp=='!'||*cp=='@') { |
1022 | return; |
1028 | if(*cp=='!') set_race=0; |
|
|
1029 | if(*cp=='@') set_list=0; |
|
|
1030 | cp++; |
|
|
1031 | } |
1023 | } |
1032 | if(sscanf(cp,"RACE %s",variable)) { /* set new race value */ |
1024 | |
1033 | strcpy(race,variable); |
1025 | while (fgets (buf, MAX_BUF, file) != NULL) |
1034 | } else { |
1026 | { |
1035 | char *cp1; |
1027 | int set_race = 1, set_list = 1; |
1036 | /* Take out beginning spaces */ |
1028 | if (*buf == '#') |
1037 | for (cp1 = cp; *cp1==' '; cp1++); |
1029 | continue; |
1038 | /* Remove newline and trailing spaces */ |
1030 | if ((cp = strchr (buf, '\n')) != NULL) |
1039 | for (cp1 = cp + strlen(cp) -1; *cp1 == '\n' || *cp1 == ' '; cp1 --) { |
|
|
1040 | *cp1='\0'; |
1031 | *cp = '\0'; |
1041 | 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++; |
1042 | } |
1040 | } |
|
|
1041 | if (sscanf (cp, "RACE %s", variable)) |
|
|
1042 | { /* set new race value */ |
|
|
1043 | strcpy (race, variable); |
1043 | |
1044 | } |
1044 | 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'; |
1045 | /* set creature race to race value */ |
1061 | /* set creature race to race value */ |
1046 | if((mon=find_archetype(cp))==NULL) |
1062 | if ((mon = find_archetype (cp)) == NULL) |
1047 | LOG(llevError,"\nCreature %s in race file lacks archetype",cp); |
1063 | LOG (llevError, "\nCreature %s in race file lacks archetype", cp); |
1048 | else { |
1064 | else |
|
|
1065 | { |
|
|
1066 | if (set_race |
1049 | if(set_race&&(!mon->clone.race||strcmp(mon->clone.race,race))) { |
1067 | && (!mon->clone.race || strcmp (mon->clone.race, race))) |
|
|
1068 | { |
1050 | if(mon->clone.race) { |
1069 | if (mon->clone.race) |
|
|
1070 | { |
|
|
1071 | LOG (llevDebug, |
1051 | LOG(llevDebug,"\n Resetting race to %s from %s for archetype %s", |
1072 | "\n Resetting race to %s from %s for archetype %s", |
1052 | race,&mon->clone.race,&mon->name); |
1073 | race, &mon->clone.race, &mon->name); |
|
|
1074 | } |
|
|
1075 | mon->clone.race = race; |
1053 | } |
1076 | } |
1054 | mon->clone.race = race; |
|
|
1055 | } |
|
|
1056 | /* 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 */ |
1057 | if(set_list&&QUERY_FLAG(&mon->clone,FLAG_MONSTER)) |
1078 | if (set_list && QUERY_FLAG (&mon->clone, FLAG_MONSTER)) |
1058 | add_to_racelist(race, &mon->clone); |
1079 | add_to_racelist (race, &mon->clone); |
|
|
1080 | } |
1059 | } |
1081 | } |
1060 | } |
1082 | } |
1061 | } |
|
|
1062 | fclose(file); |
1083 | fclose (file); |
1063 | LOG(llevDebug,"done.\n"); |
1084 | LOG (llevDebug, "done.\n"); |
1064 | } |
1085 | } |
1065 | |
1086 | |
1066 | void dump_races(void) |
1087 | void dump_races(void) |
1067 | { |
1088 | { |
1068 | racelink *list; |
1089 | racelink *list; |