View Single Post
Old June 25, 2020, 07:29   #5
Celiend
Rookie
 
Join Date: Jun 2020
Posts: 8
Celiend is on a distinguished road
Problem solved!!! Thank you wobbly!

The code is sinfully ugly; but mechanically, it's doing exactly what I want it to! (To be clear... the sinfully ugly part is "MY FAULT" not due to your suggestion)

Using wobbly's suggested approach:

Code:
/**
 * Draw energy from a nearby undead
 */
bool effect_handler_TAP_UNLIFE(effect_handler_context_t *context)
{
	int amount = effect_calculate_value(context, false);
	struct loc target;
	struct monster *mon = NULL;
	char m_name[80];
        
        // Hardcoded to affect Undead?
        int typ = 40;
        
        int flg = PROJECT_JUMP | PROJECT_KILL | PROJECT_HIDE;

	if (context->aware) flg |= PROJECT_AWARE;
        
	int drain = 0;
	bool fear = false;
	bool dead = false;
        
        msg("XXXCalled Tap Unlife:  amount: %i.",amount);

	context->ident = true;

	/* Closest living monster */
	if (!target_set_closest(TARGET_KILL, monster_is_undead)) {
		return false;
	}
	target_get(&target);
	mon = target_get_monster();
        
        struct loc origin = origin_get_loc(context->origin);
        
        int i = 0;
        
        for (i = 1; i < cave_monster_max(cave); i++) {
            
            struct monster *mon = cave_monster(cave, i);

            struct loc grid;

            /* Location */
            grid = mon->grid;
            
        	/* Paranoia -- Skip dead monsters */
            if (!mon->race) continue;

	    /* Require line of sight */
            if (!los(cave, origin, mon->grid)) continue;

	    /* Jump directly to the monster */
            	/* Hurt the monster */
            
            /*
            if(monster_is_undead)
            {
                monster_desc(m_name, sizeof(m_name), mon, MDESC_TARG);
                msg("You draw power from the %s.", m_name);
                drain = MIN(mon->hp, amount) / 4;
                dead = mon_take_hit(mon, amount, &fear, " is destroyed!");        
            } 
             */
            
            (void)project(source_player(), 0, grid, amount, typ, flg, 0, 0, context->obj);
	    
            context->ident = true;
	}
I will be trying Nick's suggested approach next to see if it works... (somehow, it didn't occur to me that 'monster_is_undead' is a function)

Thank you to the both of you for responding.
Celiend is offline   Reply With Quote