src/magic.c
/*
 * Cast spells at targets using a magical object.
 */
Cast spells at targets using a magical object.
Cast spells at targets using a magical object .
void obj_cast_spell( int sn, int level, CHAR_DATA *ch, CHAR_DATA *victim, OBJ_DATA *obj )
{
    void *vo;
    int target = TARGET_NONE;
    if ( sn <= 0 )
	return;
    if ( sn >= MAX_SKILL || skill_table[sn].spell_fun == 0 )
    {
	bug( "Obj_cast_spell: bad sn %d.", sn );
	return;
    }
    switch ( skill_table[sn].target )
    {
    default:
	bug( "Obj_cast_spell: bad target for sn %d.", sn );
	return;
    case TAR_IGNORE:
	vo = NULL;
	break;
    case TAR_CHAR_OFFENSIVE:
	if ( victim == NULL )
	    victim = ch->fighting;
	if ( victim == NULL )
	{
	    send_to_char( "You can't do that.\n\r", ch );
	    return;
	}
	if (is_safe(ch,victim) && ch != victim)
	{
	    send_to_char("Something isn't right...\n\r",ch);
	    return;
	}
	vo = (void *) victim;
	target = TARGET_CHAR;
	break;
    case TAR_CHAR_DEFENSIVE:
    case TAR_CHAR_SELF:
	if ( victim == NULL )
	    victim = ch;
	vo = (void *) victim;
	target = TARGET_CHAR;
	break;
    case TAR_OBJ_INV:
	if ( obj == NULL )
	{
	    send_to_char( "You can't do that.\n\r", ch );
	    return;
	}
	vo = (void *) obj;
	target = TARGET_OBJ;
	break;
    case TAR_OBJ_CHAR_OFF:
        if ( victim == NULL && obj == NULL)
	    if (ch->fighting != NULL)
		victim = ch->fighting;
	    else
	    {
		send_to_char("You can't do that.\n\r",ch);
		return;
	    }
	    if (victim != NULL)
	    {
		if (is_safe_spell(ch,victim,FALSE) && ch != victim)
		{
		    send_to_char("Somehting isn't right...\n\r",ch);
		    return;
		}
		vo = (void *) victim;
		target = TARGET_CHAR;
	    }
	    else
	    {
	    	vo = (void *) obj;
	    	target = TARGET_OBJ;
	    }
        break;
    case TAR_OBJ_CHAR_DEF:
	if (victim == NULL && obj == NULL)
	{
	    vo = (void *) ch;
	    target = TARGET_CHAR;
	}
	else if (victim != NULL)
	{
	    vo = (void *) victim;
	    target = TARGET_CHAR;
	}
	else
	{
	    vo = (void *) obj;
	    target = TARGET_OBJ;
	}
	break;
    }
    target_name = "";
    (*skill_table[sn].spell_fun) ( sn, level, ch, vo,target);
    if ( (skill_table[sn].target == TAR_CHAR_OFFENSIVE
    ||   (skill_table[sn].target == TAR_OBJ_CHAR_OFF && target == TARGET_CHAR))
    &&   victim != ch
    &&   victim->master != ch )
    {
	CHAR_DATA *vch;
	CHAR_DATA *vch_next;
	for ( vch = ch->in_room->people; vch; vch = vch_next )
	{
	    vch_next = vch->next_in_room;
	    if ( victim == vch && victim->fighting == NULL )
	    {
		check_killer(victim,ch);
		multi_hit( victim, ch, TYPE_UNDEFINED );
		break;
	    }
	}
    }
    return;
}
void obj_cast_spell ( int sn , int level , CHAR_DATA * ch , CHAR_DATA * victim , OBJ_DATA * obj ) { void * vo ; int target = TARGET_NONE ; if ( sn <= 0 ) return ; if ( sn >= MAX_SKILL || skill_table [ sn ] . spell_fun == 0 ) { bug ( " " , sn ) ; return ; } switch ( skill_table [ sn ] . target ) { default : bug ( " " , sn ) ; return ; case TAR_IGNORE : vo = NULL ; break ; case TAR_CHAR_OFFENSIVE : if ( victim == NULL ) victim = ch -> fighting ; if ( victim == NULL ) { send_to_char ( " \n \r " , ch ) ; return ; } if ( is_safe ( ch , victim ) && ch != victim ) { send_to_char ( " \n \r " , ch ) ; return ; } vo = ( void * ) victim ; target = TARGET_CHAR ; break ; case TAR_CHAR_DEFENSIVE : case TAR_CHAR_SELF : if ( victim == NULL ) victim = ch ; vo = ( void * ) victim ; target = TARGET_CHAR ; break ; case TAR_OBJ_INV : if ( obj == NULL ) { send_to_char ( " \n \r " , ch ) ; return ; } vo = ( void * ) obj ; target = TARGET_OBJ ; break ; case TAR_OBJ_CHAR_OFF : if ( victim == NULL && obj == NULL ) if ( ch -> fighting != NULL ) victim = ch -> fighting ; else { send_to_char ( " \n \r " , ch ) ; return ; } if ( victim != NULL ) { if ( is_safe_spell ( ch , victim , FALSE ) && ch != victim ) { send_to_char ( " \n \r " , ch ) ; return ; } vo = ( void * ) victim ; target = TARGET_CHAR ; } else { vo = ( void * ) obj ; target = TARGET_OBJ ; } break ; case TAR_OBJ_CHAR_DEF : if ( victim == NULL && obj == NULL ) { vo = ( void * ) ch ; target = TARGET_CHAR ; } else if ( victim != NULL ) { vo = ( void * ) victim ; target = TARGET_CHAR ; } else { vo = ( void * ) obj ; target = TARGET_OBJ ; } break ; } target_name = " " ; ( * skill_table [ sn ] . spell_fun ) ( sn , level , ch , vo , target ) ; if ( ( skill_table [ sn ] . target == TAR_CHAR_OFFENSIVE || ( skill_table [ sn ] . target == TAR_OBJ_CHAR_OFF && target == TARGET_CHAR ) ) && victim != ch && victim -> master != ch ) { CHAR_DATA * vch ; CHAR_DATA * vch_next ; for ( vch = ch -> in_room -> people ; vch ; vch = vch_next ) { vch_next = vch -> next_in_room ; if ( victim == vch && victim -> fighting == NULL ) { check_killer ( victim , ch ) ; multi_hit ( victim , ch , TYPE_UNDEFINED ) ; break ; } } } return ; }
Cast spells at targets using a magical object.
Cast spells at targets using a magical object .