social
./mudtem/src/var/social · 2.0 KB
From the archive mudtem.tar.gz
Download the archive « Back to the archive contents
void load_social (FILE *fp, struct social_type *social)
{
social->name = fread_string (fp);
social->char_no_arg = fread_string (fp);
social->others_no_arg = fread_string (fp);
social->char_found = fread_string (fp);
social->others_found = fread_string (fp);
social->vict_found = fread_string (fp);
social->char_auto = fread_string (fp);
social->others_auto = fread_string (fp);
}
void load_social_table (void)
{
FILE *fp;
int i;
fp = fopen (SOCIAL_FILE, "r");
if (!fp)
{
bug ("Could not open " SOCIAL_FILE " for reading.",0);
exit(1);
}
fscanf (fp, "%d\n", &maxSocial);
/* IMPORTANT to use malloc so we can realloc later on */
social_table = malloc (sizeof(struct social_type) * (maxSocial+1));
for (i = 0; i < maxSocial; i++)
load_social (fp,&social_table[i]);
/* For backwards compatibility */
social_table[maxSocial].name = str_dup(""); /* empty! */
fclose (fp);
}
void save_social (const struct social_type *s, FILE *fp)
{
/* get rid of (null) */
fprintf (fp, "%s~\n%s~\n%s~\n%s~\n%s~\n%s~\n%s~\n%s~\n\n",
s->name ? s->name : "" ,
s->char_no_arg ? s->char_no_arg : "" ,
s->others_no_arg ? s->others_no_arg : "" ,
s->char_found ? s->char_found : "" ,
s->others_found ? s->others_found : "" ,
s->vict_found ? s->vict_found : "" ,
s->char_auto ? s->char_auto : "" ,
s->others_auto ? s->others_auto : ""
);
}
void save_social_table(void)
{
FILE *fp;
int i;
fp = fopen (SOCIAL_FILE, "w");
if (!fp)
{
bug ("Could not open " SOCIAL_FILE " for writing.",0);
return;
}
#ifdef CONST_SOCIAL /* If old table still in use, count socials first */
for (maxSocial = 0 ; social_table[maxSocial].name[0] ; maxSocial++)
; /* empty */
#endif
fprintf (fp, "%d\n", maxSocial);
for ( i = 0 ; i < maxSocial ; i++)
save_social (&social_table[i], fp);
fclose (fp);
}