//
// Copyright(C) 2014-2015 Samuel Villarreal
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// DESCRIPTION:
//      Purlin Script Object Classes
//

#include "scripts/common.txt"

//-----------------------------------------------------------------------------
//
// Purlin
//
//-----------------------------------------------------------------------------

/*
==============================================================
TurokPurlin
==============================================================
*/

final class TurokPurlin : TurokEnemy
{
    TurokPurlin(kActor @actor)
    {
        super(actor);
    }
    
    /*
    ==============================================================
    PurlinStomp
    ==============================================================
    */
    
    void PurlinStomp(kActor @instigator, const float w, const float x, const float y, const float z)
    {
        self.PlaySound("sounds/shaders/generic_139.ksnd");
    }
    
    /*
    ==============================================================
    GunFire
    ==============================================================
    */
    
    void GunFire(kActor @instigator, const float w, const float x, const float y, const float z)
    {
        if(self.GetTarget() is null)
        {
            return;
        }
        
        self.PlaySound("sounds/shaders/explosion_1.ksnd");
        
        self.SpawnProjectile("fx/hulk_blaster.kfx", kVec3(x, y, z),
            self.GetTarget().Origin(), Math::Deg2Rad(45.0f));
    }
    
    /*
    ==============================================================
    OnActivate
    ==============================================================
    */
    
    void OnActivate(void)
    {
        self.PlaySound("sounds/shaders/hulk_alert.ksnd");
    }
    
    /*
    ==============================================================
    DeathSound
    ==============================================================
    */
    
    void DeathSound(kActor @instigator, const float w, const float x, const float y, const float z)
    {
        self.PlaySound("sounds/shaders/hulk_death.ksnd");
    }
    
    /*
    ==============================================================
    InjurySound
    ==============================================================
    */
    
    void InjurySound(kActor @instigator, const float w, const float x, const float y, const float z)
    {
        self.PlaySound("sounds/shaders/hulk_injury.ksnd");
    }
    
    /*
    ==============================================================
    ViolentSound
    ==============================================================
    */
    
    void ViolentSound(kActor @instigator, const float w, const float x, const float y, const float z)
    {
        self.PlaySound("sounds/shaders/hulk_violent_death.ksnd");
    }
    
    /*
    ==============================================================
    Shockwave
    ==============================================================
    */
    
    void Shockwave(kActor @instigator, const float w, const float x, const float y, const float z)
    {
        if(self.GetTarget() is null)
        {
            return;
        }
        
        self.SpawnProjectile("fx/shockwave.kfx", kVec3(x, y, z),
            self.GetTarget().Origin(), Math::Deg2Rad(45.0f));
    }
    
    /*
    ==============================================================
    ShockwaveDamage
    ==============================================================
    */
    
    void ShockwaveDamage(kActor @instigator, const float r, const float x, const float y, const float z)
    {
        kActor @targ;
        kVec3 pos;
        
        if(self.GetTarget() is null)
        {
            return;
        }
        
        @targ = self.GetTarget();
        
        if(!targ.OnGround())
        {
            return;
        }
        
        pos = self.GetTransformedVector(kVec3(x, y, z));
        
        if(Math::Fabs(targ.Origin().z - pos.z) > 30.72f)
        {
            return;
        }
        
        float range = targ.DistanceToPoint(pos);
        float radius = r * 10.24f * r * 10.24f;
        
        if(range >= radius)
        {
            return;
        }
        
        radius = (radius - range) / radius;
        targ.InflictGenericDamage(instigator, int(10.0f * radius));
    }
};
