/
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/
#pragma save_binary
#include "spells.h"

static mixed *effects;

void    create()
{
    effects = ({ });
}				/* create() */

/* temp for testing */
mixed   query_effects()
{
    return effects;
}

int     add_spell_effect( int no_rnds, string type, string name, object callee,
			  string func, mixed params )
{
    int     i, j;

    if( (i = member_array( type, effects )) != -1 )
	if( (j = member_array( name, effects[ i + 1 ] )) == -1 )
	    effects[ i + 1 ] += ({ name, ({ no_rnds, callee, func, params }) });
	else
	    effects[ i + 1 ][ j + 1 ] = ({ no_rnds, callee, func, params });
    else
	effects += ({ type, ({ name, ({ no_rnds, callee, func, params }) }) });
}				/* add_spell_effect() */

int     remove_spell_effect( string name )
{
    int     i, j;

    for( i = 0; i < sizeof( effects ); i += 2 )
	if( (j = member_array( name, effects[ i + 1 ] )) != -1 )
	{
	    effects[ i + 1 ] = delete( effects[ i + 1 ], j, 2 );
	    if( !sizeof( effects[ i + 1 ] ) )
	    {
		effects = delete( effects, i, 2 );
		i -= 2;
	    }
	}
    return 1;
}				/* remove_spell_effect() */

mixed   query_spell_effect( string name )
{
    int     i, j;

    if( (i = member_array( name, effects )) == -1 )
	return 0;
    if( sizeof( effects[ i + 1 ] ) )
	return effects[ i..i ] + effects[ 0..1 ];
    return 0;
}				/* query_spell_effect() */

mixed * query_spell_effects_type( string type )
{
    int     i, j;
    mixed * ret;

    if( (i = member_array( type, effects )) == -1 )
	return({ });
    ret = ({ });
    for( j = 0; j < sizeof( effects ); j += 2 )
	ret += ({ effects[ i ], effects[ i + 1 ][ j..j + 1 ] });
    return ret;
}				/* query_spell_effects_type() */

int     do_spell_effects( object attacker )
{
    int     i, j;

    this_object()->remove_property( "casting" );
    for( i = 0; i < sizeof( effects ); i += 2 )
	for( j = 0; j < sizeof( effects[ i + 1 ] ); j += 2 )
	{
	    call_out( "do_call_out_effect", 1, ({ effects[ i + 1 ][ j + 1 ], attacker }) );
	    if( !--effects[ i + 1 ][ j + 1 ][ SP_NO_RNDS ] )
	    {
		effects[ i + 1 ] = delete( effects[ i + 1 ], j, 2 );
		j -= 2;
	    }
	}
    return 0;
}				/* do_spell_effects() */

void    do_call_out_effect( mixed *params )
{
    this_object()->adjust_xp( call_other( params[ 0 ][ SP_OBJECT ],
					  params[ 0 ][ SP_FUNC ],
					  params[ 1 ],
					  params[ 0 ][ SP_PARAM ],
					  params[ 0 ][ SP_NO_RNDS ] ) );
}				/* do_effect() */