class ACTION_DamagePawn extends ScriptedAction;

/**
 * Who damaged pawn?
 * DMG_None 		- nobody (none)
 * DMG_Instigator	- ScriptedController.Instigator.Controller
 * DMG_Myself		- ScriptedController
 * DMG_Himself		- Victim
 */
enum    EDamageInstigator
{
    DMG_None,
	DMG_Instigator,
    DMG_Myself,
	DMG_Himself
};

enum EDamageCalculation
{
	DCALC_Amount,		// damage is calculated using MinDamageAmount and MaxDamageAmount
	DCALC_HealthPct,	// damage is calculated using Victim's Health, MinDamagePct and MaxDamagePct
	DCALC_HealthMaxPct, // damage is calculated using Victim's HealthMax, MinDamagePct and MaxDamagePct
};

var(Action) class<Pawn> VictimClass;
var(Action) name VictimTag;
var(Action) EDamageInstigator DamageInstigator;
var(Action) class<DamageType> DamageType;
var(Action) EDamageCalculation DamageCalculation;
var(Action) int MinDamageAmount, MaxDamageAmount;
var(Action) float MinDamagePct, MaxDamagePct; // used if MinDamageAmount==MaxDamageAmount==0

function bool InitActionFor(ScriptedController C)
{
	local Actor A;
	local Pawn Victim, Instigator;
	local int Damage;

	switch ( DamageInstigator ) {
		case DMG_Instigator: 	Instigator = C.Instigator; 		break;
		case DMG_Myself: 		Instigator = C.Pawn; 				break;
	}
	
	ForEach C.DynamicActors(VictimClass, A, VictimTag) {
		Victim = Pawn(A);
		if ( DamageInstigator == DMG_Himself )
			Instigator = Victim;
			
		switch ( DamageCalculation )
		{
			case DCALC_Amount: 			Damage = RandRange(MinDamageAmount, MaxDamageAmount); break;
			case DCALC_HealthPct: 		Damage = Victim.Health * ( MinDamagePct + frand()*(MaxDamagePct - MinDamagePct) ); break;
			case DCALC_HealthMaxPct:	Damage = Victim.HealthMax * ( MinDamagePct + frand()*(MaxDamagePct - MinDamagePct) ); break;
		}
		
		Victim.TakeDamage(Damage, Instigator, Victim.Location, vect(0,0,0), DamageType);
	}

	return false;
}

function string GetActionString()
{
	return ActionString @ GetItemName(String(VictimClass)) @ VictimTag;
}

defaultproperties
{
     VictimClass=Class'Old2k4.Monster'
     ActionString="Damage pawn"
}
