/
rogue24b3/
rogue24b3/data/
/***************************************************************************
 *  Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer,        *
 *  Michael Seifert, Hans Henrik Starfeldt, Tom Madsen, and Katja Nyboe.   *
 *                                                                         *
 *  Merc Diku Mud improvments copyright (C) 1992, 1993 by Michael          *
 *  Chastain, Michael Quan, and Mitchell Tse.                              *
 *                                                                         *
 *  In order to use any part of this Merc Diku Mud, you must comply with   *
 *  both the original Diku license in 'license.doc' as well the Merc       *
 *  license in 'license.txt'.  In particular, you may not remove either of *
 *  these copyright notices.                                               *
 *                                                                         *
 *  Much time and thought has gone into this software and you are          *
 *  benefitting.  We hope that you share your changes too.  What goes      *
 *  around, comes around.                                                  *
 ***************************************************************************/
 
/* Online Social Editting Module, 
 * (c) 1996,97 Erwin S. Andreasen <erwin@pip.dknet.dk>
 * See the file "License" for important licensing information
 */ 

#include "merc.h"
#include "db.h"
#include "tables.h"
#include "lookup.h"

int	maxSocial;
struct	social_type	*social_table;

void load_social (FILE *fp, struct social_type *social)
{
	strcpy(social->name,	  fread_string (fp));
	social->min_pos		= position_lookup(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);
	social->char_obj_found	= fread_string (fp);
	social->others_obj_found= fread_string (fp);
}

void load_social_table()
{
    int i;
    FILE *fp;

    if (!(fp = fopen(SOCIAL_FILE, "r"))) {
	mudlogf(BRF, LVL_CODER, TRUE, "Could not open %s for reading.", SOCIAL_FILE);
	exit(1);
    }

    fscanf(fp, "%d\n", &maxSocial);
    social_table = (struct social_type *)malloc(sizeof(struct social_type) * (maxSocial+1));

    for (i = 0; i < maxSocial; i++)
	load_social(fp, &social_table[i]);

    /* For backwards compatibility */
    strcpy(social_table[maxSocial].name, str_dup(""));
    fclose(fp);
}

void save_social (const struct social_type *s, FILE *fp)
{
	fprintf (fp,
	"%s~\n"
	"%s~\n""%s~\n"
	"%s~\n""%s~\n"
	"%s~\n""%s~\n"
	"%s~\n""%s~\n"
	"%s~\n""%s~\n\n",
	s->name			? s->name		: "",
	position_table[s->min_pos].short_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	: "",
	s->char_obj_found	? s->char_obj_found	: "",
	s->others_obj_found	? s->others_obj_found	: "");
}


void save_social_table()
{
    int i;
    FILE *fp;

    if (!(fp = fopen(SOCIAL_FILE, "w"))) {
	mudlogf(BRF, LVL_CODER, TRUE, "Could not open %s for writing.", SOCIAL_FILE);
	return;
    }

    fprintf(fp, "%d\n", maxSocial);
    for (i = 0; i < maxSocial; i++)
	save_social(&social_table[i], fp);
    fclose(fp);
}

SOCIAL_DATA *get_social_data(char *name) {
    int i;
    for (i = 0; i < maxSocial; i++)
	if (!str_cmp(name, social_table[i].name))
		return &social_table[i];
    return NULL;
}

/* Find a social based on name */ 
int social_lookup(const char *name)
{
    int i;
    for (i = 0; i < maxSocial; i++)
	if (!str_cmp(name, social_table[i].name))
		return i;
    return -1;
}