mud++0.35/etc/
mud++0.35/etc/guilds/
mud++0.35/help/propert/
mud++0.35/mudC/
mud++0.35/player/
mud++0.35/src/interface/
mud++0.35/src/os/cygwin32/
mud++0.35/src/os/win32/
mud++0.35/src/os/win32/bcppbuilder/
mud++0.35/src/osaddon/
mud++0.35/src/util/
/*
....[@@@..[@@@..............[@.................. MUD++ is a written from
....[@..[@..[@..[@..[@..[@@@@@....[@......[@.... scratch multi-user swords and
....[@..[@..[@..[@..[@..[@..[@..[@@@@@..[@@@@@.. sorcery game written in C++.
....[@......[@..[@..[@..[@..[@....[@......[@.... This server is an ongoing
....[@......[@..[@@@@@..[@@@@@.................. development project.  All 
................................................ contributions are welcome. 
....Copyright(C).1995.Melvin.Smith.............. Enjoy. 
------------------------------------------------------------------------------
Melvin Smith (aka Fusion)         msmith@hom.net 
MUD++ development mailing list    mudpp@van.ml.org
------------------------------------------------------------------------------
social.cc
*/

#include "config.h"
#include "social.h"
#include "io.h"

LList<Social> social_table[26];

const char * he_she[] = { "it", "he", "she" };
const char * him_her[] = { "it", "him", "her" };
const char * his_her[] = { "its", "his", "her" };


void loadSocials()
{
	int count = 0;
	int ihash;
	String str;
	char buf[256];
	Social * social;
	InputFile in( "../etc/socials.db" );

	if( !in )
	{
		Cout << "Error loading socials database.\n";
		return;
	}

	while( 1 )
	{
		in.getword( buf );
		if( buf[0] == '#' )
		{
			Cout << "Socials database loaded with " << count << " entries.\n";
			return;
		}

		if( !isalpha( buf[0] ) )
			in.error( "Social name has illegal name." );

		social = new Social( buf );
		in.getword( buf );
		if( buf[0] != '{' )
			in.error( "Invalid social syntax: missing {" );

		social->selftargnone << "\n\r" << in.getstring( buf ) << "\n\r";
		social->roomtargnone << "\n\r" << in.getstring( buf ) << "\n\r";
		social->selftargself << "\n\r" << in.getstring( buf ) << "\n\r";
		social->roomtargself << "\n\r" << in.getstring( buf ) << "\n\r";
		social->selftargother << "\n\r" << in.getstring( buf ) << "\n\r";
		social->roomtargother << "\n\r" << in.getstring( buf ) << "\n\r";
		social->targother << "\n\r" << in.getstring( buf ) << "\n\r";

		in.getword( buf );
		if( buf[0] != '}' )
			in.error( "Invalid social syntax: missing }" );

		ihash = tolower( social->getName()[0] ) - 'a';
		social_table[ ihash ].add( social );

		count++;
	}
}


const Social * lookupSocial( const String & name )
{
	const Social *social;

	int ihash = tolower( name[0] ) - 'a';
	if( ihash < 0 || ihash > 25 )
		return 0;

	social_table[ihash].reset();
	while( ( social = social_table[ihash].peek() ) )
	{
		social_table[ihash].next();

		if( name.isAbbrev( social->getName() ) )
			return social;
	}	

	return 0;
}