/
LIB3/
LIB3/D/ADMIN/
LIB3/D/ADMIN/OBJ/
LIB3/D/ADMIN/ROOM/W/
LIB3/D/HOME/
LIB3/D/HOME/CITY/ARENA/
LIB3/D/HOME/CITY/ITEMS/
LIB3/D/HOME/CITY/POSTOFFI/
LIB3/DOC/
LIB3/GLOBAL/SPECIAL/
LIB3/GLOBAL/VIRTUAL/
LIB3/NET/
LIB3/NET/CONFIG/
LIB3/NET/DAEMON/CHARS/
LIB3/NET/GOPHER/
LIB3/NET/INHERIT/
LIB3/NET/OBJ/
LIB3/NET/SAVE/
LIB3/NET/VIRTUAL/
LIB3/OBJ/B_DAY/
LIB3/OBJ/HANDLERS/TERM_TYP/
LIB3/PLAYERS/B/
LIB3/PLAYERS/N/
LIB3/ROOM/
LIB3/SAVE/
LIB3/SAVE/BOARDS/
LIB3/SAVE/ENVIRON/
LIB3/SAVE/POST/
LIB3/STD/COMMANDS/SHADOWS/
LIB3/STD/CREATOR/
LIB3/STD/DOM/
LIB3/STD/EFFECTS/
LIB3/STD/EFFECTS/HEALING/
LIB3/STD/EFFECTS/OTHER/
LIB3/STD/EFFECTS/POISONS/
LIB3/STD/ENVIRON/
LIB3/STD/GUILDS/
LIB3/STD/LIQUIDS/
LIB3/STD/ROOM/
LIB3/STD/TRIGGER/SHADOW/
LIB3/W/
LIB3/W/BANNOR/
LIB3/W/NEWSTYLE/
#include "spells.h"
mixed   spells;

void    create()
{
    spells = ([ ]);
}

void    spell_commands()
{
    add_action( "show_spells", "spells" );
    add_action( "cast", "cast" );
}

string  help_spell( string str )
{
    if( !mappingp( spells ) )
	spells = ([ ]);
    if( !m_sizeof( spells ) )
	return 0;
    if( !spells[ str ] )
	return 0;
    return( string ) spells[ str ][ S_OBJECT ]->help( str );
}

/*
 * all the spells stuff from here to the next silly comment
 */
int     show_spells( string str )
{
    string *frog;
    int     i;

    if( !mappingp( spells ) )
	spells = ([ ]);
    if( !m_sizeof( spells ) )
    {
	write( "You don't know any spells.\n" );
	return 1;
    }

    frog = m_indices( spells );
    write( "You know the following spells:\n" );
    printf( "%#-*s\n", this_player()->query_cols(), implode( frog, "\n" ) );
/* the above will use printf... but it is broken at the moment. */
    return 1;
}

int     cast( string str )
{
    int     i, j;
    string *s, s1;

    if( !str )
    {
	notify_fail( "Usage: cast <spell> [<target>]\n" );
	return 0;
    }
    s = explode( str, " " );
    s1 = s[ 0 ];
    j = 1;
    while( !spells[ s1 ] && j < sizeof( s ) )
	s1 = implode( s[ 0..j++ ], " " );
    if( !spells[ s1 ] )
    {
	notify_fail( "There is no such spell as " + str + "\n" );
	return 0;
    }
/* ok we found our spell...
 * cast it...
 * Or, at least try to ;)
 */
    return( int ) call_other( spells[ s1 ][ S_OBJECT ], spells[ s1 ][ S_FUNC ],
			      implode ( s[ j..sizeof( s ) ], " " ) );
}

mixed   query_spells()
{
    return spells + ([ ]);
}

int     add_spell( string name, mixed ob, mixed func )
{
    int     i;
    mapping tmp;

    if( pointerp( spells ) )
    {
	tmp = ([ ]);
	for( i = 0; i < sizeof( spells ); i += 2 )
	    tmp[ spells[ i ] ] = spells[ i + 1 ];
	spells = tmp;
    }
    if( !mappingp( spells ) )
	spells = ([ ]);
    spells[ name ] = ({ ob, func });
    return 1;
}

int     remove_spell( string name )
{
    int     i;

    spells = m_delete( spells, name );
    return 1;
}

int     query_spell( string type )
{
    if( !mappingp( spells ) )
	return 0;
    return spells[ type ];
}

int     spell_teach( object *obs, string spell )
{
    int     i;
    object *succ, *me_low, *him_low;
    string  ret;

    if( !mappingp( spells ) )
	spells = ([ ]);
    if( !spells[ spell ] )
	return 0;
    succ = me_low = him_low = ({ });
    for( i = 0; i < sizeof( obs ); i++ )
    {
	if( !living( obs[ i ] ) )
	    continue;
	switch( spells[ spell ][ 0 ]->teach( obs[ i ], spell ) )
	{
	    case 1:
		succ += ({ obs[ i ] });
		break;
	    case -1:
		me_low += ({ obs[ i ] });
		break;
	    case -2:
		him_low += ({ obs[ i ] });
		break;
	}
    }
    if( !succ )
    {
	ret = "";
	if( sizeof( me_low ) )
	    ret += "You are too low a level to teach " + query_multiple_short( obs ) +
		" " + spell + ".\n";
	if( sizeof( him_low ) )
	    ret += query_multiple_short( obs ) + " is too low a level to learn " +
		spell + ".\n";
	write( ret );
	return 1;
    }
    write( "You successfuly teach " + query_multiple_short( succ ) + " " + spell + ".\n" );
    if( sizeof( me_low ) )
	write( "You are to low a level to teach " + query_multiple_short( obs - succ ) +
	       " " + spell + ".\n" );
    if( sizeof( him_low ) )
	write( query_multiple_short( obs ) + " is too low a level to learn " +
	       spell + ".\n" );
    return 1;
}