//
// 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:
//      Grunt Human Script Object Class
//

#include "scripts/common.txt"

//-----------------------------------------------------------------------------
//
// Enemy Base Class
//
//-----------------------------------------------------------------------------

/*
==============================================================
TurokGrunt
==============================================================
*/

class TurokGrunt : TurokEnemy
{
    TurokGrunt(kActor @actor)
    {
        super(actor);
    }
    
    /*
    ==============================================================
    HighPriestSpellAttack
    ==============================================================
    */
    
    void HighPriestSpellAttack(kActor @instigator, const float w, const float x, const float y, const float z)
    {
        if(self.GetTarget() is null)
        {
            return;
        }
        
        self.SpawnFx("fx/spellcast.kfx", kVec3(x, y, z));
    }
    
    /*
    ==============================================================
    HighPriestSpellSound
    ==============================================================
    */
    
    void HighPriestSpellSound(kActor @instigator, const float w, const float x, const float y, const float z)
    {
        self.PlaySound("sounds/shaders/high_priest_spell_attack.ksnd");
    }
    
    /*
    ==============================================================
    SwooshTrail1
    ==============================================================
    */
    
    void SwooshTrail1(kActor @instigator, const float w, const float x, const float y, const float z)
    {
        switch(self.ModelVariation())
        {
        case GV_GENERIC_AXE:
        case GV_DEMON_AXE:
            self.RenderModel().AddTrailEffect("Trail_Axe", 17);
            break;
            
        case GV_GENERIC_CLUB:
        case GV_SHAMAN:
            self.RenderModel().AddTrailEffect("Trail_Mace", 17);
            break;
        
        case GV_COMMANDER_SPEAR:
        case GV_WARRIOR_SPEAR:
        case GV_DEMON_SPEAR:
            self.RenderModel().AddTrailEffect("Trail_Pole1", 17);
            break;
            
        case GV_COMMANDER_RIFLE1:
        case GV_COMMANDER_RIFLE2:
        case GV_COMMANDER_RIFLE3:
        case GV_COMMANDER_RIFLE4:
        case GV_POACHER_RIFLE:
        case GV_CYBORG_PULSE_RIFLE:
            self.RenderModel().AddTrailEffect("Trail_Shotgun", 17);
            break;
            
        case GV_POACHER_KNIFE:
            self.RenderModel().AddTrailEffect("Trail_Sword", 17);
            break;
            
        case GV_POACHER_PISTOL1:
        case GV_POACHER_PISTOL2:
            self.RenderModel().AddTrailEffect("Trail_Pistol", 17);
            break;
            
        case GV_POACHER_SHOTGUN:
            self.RenderModel().AddTrailEffect("Trail_Shotgun", 17);
            break;
            
        case GV_WARRIOR_BONE:
            self.RenderModel().AddTrailEffect("Trail_Bone", 17);
            break;
            
        case GV_WARRIOR_DART:
            self.RenderModel().AddTrailEffect("Trail_DartGun", 17);
            break;
        }
    }
    
    /*
    ==============================================================
    GunFire
    ==============================================================
    */
    
    void GunFire(kActor @instigator, const float w, const float x, const float y, const float z)
    {
        if(self.GetTarget() is null)
        {
            return;
        }
        
        if( self.ModelVariation() == GV_COMMANDER_RIFLE4 ||
            self.ModelVariation() == GV_CYBORG_PULSE_RIFLE)
        {
            self.PlaySound("sounds/shaders/machine_gun_shot_2.ksnd");
            self.SpawnProjectile("fx/enemy_longhunter.kfx", kVec3(x, y, z),
                self.GetTarget().Origin(), Math::Deg2Rad(45.0f));
                
            return;
        }
        
        self.PlaySound("sounds/shaders/generic_8_enemy_human_gunfire.ksnd");
        self.SpawnProjectile("fx/enemy_bullet.kfx", kVec3(x, y, z),
            self.GetTarget().Origin(), Math::Deg2Rad(45.0f));
    }
    
    /*
    ==============================================================
    ThrowGrenade
    ==============================================================
    */
    
    void ThrowGrenade(kActor @instigator, const float w, const float x, const float y, const float z)
    {
        self.SpawnFx("fx/generic_114.kfx", kVec3(x, y, z));
    }
    
    /*
    ==============================================================
    DemonAttack
    ==============================================================
    */
    
    void DemonAttack(kActor @instigator, const float w, const float x, const float y, const float z)
    {
        if(self.GetTarget() is null)
        {
            return;
        }
        
        self.SpawnProjectile("fx/generic_256.kfx", kVec3(x, y, z),
            self.GetTarget().Origin(), Math::Deg2Rad(45.0f));
    }
    
    /*
    ==============================================================
    TribalDart1
    ==============================================================
    */
    
    void TribalDart1(kActor @instigator, const float w, const float x, const float y, const float z)
    {
        if(self.GetTarget() is null)
        {
            return;
        }
        
        self.SpawnFx("fx/generic_193.kfx", kVec3(x, y, z));
    }
    
    /*
    ==============================================================
    TribalDart2
    ==============================================================
    */
    
    void TribalDart2(kActor @instigator, const float w, const float x, const float y, const float z)
    {
        self.SpawnFx("fx/generic_194.kfx", kVec3(x, y, z));
    }
    
    /*
    ==============================================================
    DeathSound
    ==============================================================
    */
    
    void DeathSound(kActor @instigator, const float w, const float x, const float y, const float z)
    {
        if( self.ModelVariation() >= GV_CYBORG_PULSE_RIFLE &&
            self.ModelVariation() <= GV_CYBORG_SPEAR)
        {
            self.PlaySound("sounds/shaders/ancient_warrior_death.ksnd");
            return;
        }
        else if(self.ModelVariation() >= GV_DEMON_AXE &&
                self.ModelVariation() <= GV_DEMON_LORD)
        {
            switch(Math::RandMax(3))
            {
            case 0:
                self.PlaySound("sounds/shaders/demon_death_scream_1.ksnd");
                break;
            case 1:
                self.PlaySound("sounds/shaders/demon_death_scream_2.ksnd");
                break;
            case 2:
                self.PlaySound("sounds/shaders/demon_death_scream_3.ksnd");
                break;
            }
            return;
        }
        
        switch(Math::RandMax(3))
        {
        case 0:
            self.PlaySound("sounds/shaders/human_death_scream_1.ksnd");
            break;
        case 1:
            self.PlaySound("sounds/shaders/human_death_scream_2.ksnd");
            break;
        case 2:
            self.PlaySound("sounds/shaders/human_death_scream_3.ksnd");
            break;
        }
    }
    
    /*
    ==============================================================
    InjurySound
    ==============================================================
    */
    
    void InjurySound(kActor @instigator, const float w, const float x, const float y, const float z)
    {
        if( self.ModelVariation() >= GV_CYBORG_PULSE_RIFLE &&
            self.ModelVariation() <= GV_CYBORG_SPEAR)
        {
            self.PlaySound("sounds/shaders/ancient_warrior_death.ksnd");
            return;
        }
        else if(self.ModelVariation() >= GV_DEMON_AXE &&
                self.ModelVariation() <= GV_DEMON_LORD)
        {
            switch(Math::RandMax(3))
            {
            case 0:
                self.PlaySound("sounds/shaders/demon_effort_injury_grunt_1.ksnd");
                break;
            case 1:
                self.PlaySound("sounds/shaders/demon_effort_injury_grunt_2.ksnd");
                break;
            case 2:
                self.PlaySound("sounds/shaders/demon_effort_injury_grunt_3.ksnd");
                break;
            }
            return;
        }
        
        switch(Math::RandMax(3))
        {
        case 0:
            self.PlaySound("sounds/shaders/human_effort_injury_grunt_1.ksnd");
            break;
        case 1:
            self.PlaySound("sounds/shaders/human_effort_injury_grunt_2.ksnd");
            break;
        case 2:
            self.PlaySound("sounds/shaders/human_effort_injury_grunt_3.ksnd");
            break;
        }
    }
    
    /*
    ==============================================================
    ViolentSound
    ==============================================================
    */
    
    void ViolentSound(kActor @instigator, const float w, const float x, const float y, const float z)
    {
        if( self.ModelVariation() >= GV_CYBORG_PULSE_RIFLE &&
            self.ModelVariation() <= GV_CYBORG_SPEAR)
        {
            self.PlaySound("sounds/shaders/ancient_warrior_death.ksnd");
            return;
        }
        else if(self.ModelVariation() >= GV_DEMON_AXE &&
                self.ModelVariation() <= GV_DEMON_LORD)
        {
            switch(Math::RandMax(3))
            {
            case 0:
                self.PlaySound("sounds/shaders/demon_violent_death_1.ksnd");
                break;
            case 1:
                self.PlaySound("sounds/shaders/demon_violent_death_2.ksnd");
                break;
            case 2:
                self.PlaySound("sounds/shaders/demon_violent_death_3.ksnd");
                break;
            }
            return;
        }
        
        switch(Math::RandMax(3))
        {
        case 0:
            self.PlaySound("sounds/shaders/human_violent_death_1.ksnd");
            break;
        case 1:
            self.PlaySound("sounds/shaders/human_violent_death_2.ksnd");
            break;
        case 2:
            self.PlaySound("sounds/shaders/human_violent_death_3.ksnd");
            break;
        }
    }
    
    /*
    ==============================================================
    OnBeginLevel
    ==============================================================
    */
    
    void OnBeginLevel(void)
    {
        kRenderModel @model = self.RenderModel();
        
        if(model is null)
        {
            return;
        }
        
        if( self.ModelVariation() >= GV_CYBORG_PULSE_RIFLE &&
            self.ModelVariation() <= GV_CYBORG_SPEAR)
        {
            self.ImpactType() = IT_METAL;
        }
        
        // TODO: this could really benefit from a skin definition or something...
        
        switch(self.ModelVariation())
        {
        // common soldier
        case GV_GENERIC:
        case GV_GENERIC_AXE:
        case GV_GENERIC_CLUB:
            // face
            model.SetTexture(19, Math::SysRand() % 12);
            break;
        
        // commander
        case GV_COMMANDER_SPEAR:
        case GV_COMMANDER_RIFLE1:
        case GV_COMMANDER_RIFLE2:
        case GV_COMMANDER_RIFLE3:
        case GV_COMMANDER_RIFLE4:
            // chest
            model.SetTexture(0, 1);
            model.SetTexture(9, 1);
            
            // arms
            model.SetTexture(10, 1);
            model.SetTexture(11, 1);
            model.SetTexture(12, 1);
            model.SetTexture(13, 1);
            model.SetTexture(14, 1);
            model.SetTexture(15, 1);
            model.SetTexture(16, 1);
            model.SetTexture(17, 1);
            
            // face
            model.SetTexture(19, Math::SysRand() % 12);
            break;
            
        // poacher
        case GV_POACHER_KNIFE:
        case GV_POACHER_PISTOL1:
        case GV_POACHER_PISTOL2:
        case GV_POACHER_RIFLE:
        case GV_POACHER_SHOTGUN:
            // chest
            model.SetTexture(0, 5);
            model.SetTexture(9, 5);
            
            // legs
            model.SetTexture(1, 2);
            model.SetTexture(3, 2);
            model.SetTexture(4, 2);
            model.SetTexture(5, 2);
            model.SetTexture(7, 2);
            model.SetTexture(8, 2);
            
            // shin
            model.SetTexture(2, 2);
            model.SetTexture(6, 2);
            
            // face
            model.SetTexture(19, Math::SysRand() % 12);
            break;
            
        // warrior
        case GV_WARRIOR_BONE:
        case GV_WARRIOR_DART:
        case GV_WARRIOR_SPEAR:
            // hands
            model.SetTexture(17, 2);
            
            // chest
            model.SetTexture(0, 2);
            model.SetTexture(9, 2);
            
            // arms
            model.SetTexture(10, 2);
            model.SetTexture(11, 2);
            model.SetTexture(12, 2);
            model.SetTexture(13, 2);
            model.SetTexture(14, 2);
            model.SetTexture(15, 2);
            model.SetTexture(16, 2);
            
            // neck
            model.SetTexture(18, 1);
            break;
            
        // shaman
        case GV_SHAMAN:
            // chest
            model.SetTexture(0, 3);
            model.SetTexture(9, 3);
            
            // neck
            model.SetTexture(18, 2);
            
            // legs
            model.SetTexture(1, 1);
            model.SetTexture(3, 1);
            model.SetTexture(4, 1);
            model.SetTexture(5, 1);
            model.SetTexture(7, 1);
            model.SetTexture(8, 1);
            
            // shin
            model.SetTexture(2, 1);
            model.SetTexture(6, 1);
            
            // hands
            model.SetTexture(17, 3);
            
            // arms
            model.SetTexture(10, 3);
            model.SetTexture(11, 3);
            model.SetTexture(12, 3);
            model.SetTexture(13, 3);
            model.SetTexture(14, 3);
            model.SetTexture(15, 3);
            model.SetTexture(16, 3);
            break;
            
        // cyborg guard
        case GV_CYBORG_PULSE_RIFLE:
            // legs
            model.SetTexture(1, 1);
            model.SetTexture(3, 1);
            model.SetTexture(4, 1);
            model.SetTexture(5, 1);
            model.SetTexture(7, 1);
            model.SetTexture(8, 1);
            
            // shin
            model.SetTexture(2, 1);
            model.SetTexture(6, 1);
            
            // chest
            model.SetTexture(0, 4);
            model.SetTexture(9, 4);
            
            // arms
            model.SetTexture(10, 4);
            model.SetTexture(11, 4);
            model.SetTexture(12, 4);
            model.SetTexture(13, 4);
            model.SetTexture(14, 4);
            model.SetTexture(15, 4);
            model.SetTexture(16, 4);
            
            // neck
            model.SetTexture(18, 3);
            break;
            
        // demon
        case GV_DEMON_AXE:
        case GV_DEMON_SPEAR:
        case GV_DEMON_HANDS:
            // hands
            model.SetTexture(17, 6);
            model.SetTexture(13, 6);
            
            // legs
            model.SetTexture(1, 2);
            model.SetTexture(3, 2);
            model.SetTexture(4, 2);
            model.SetTexture(5, 2);
            model.SetTexture(7, 2);
            model.SetTexture(8, 2);
            
            // shin
            model.SetTexture(2, 2);
            model.SetTexture(6, 2);
            
            // chest
            model.SetTexture(0, 6);
            model.SetTexture(9, 6);
            
            // arms
            model.SetTexture(10, 6);
            model.SetTexture(11, 6);
            model.SetTexture(12, 6);
            model.SetTexture(13, 6);
            model.SetTexture(14, 6);
            model.SetTexture(15, 6);
            model.SetTexture(16, 6);
            
            // neck
            model.SetTexture(18, 4);
            break;
            
        // demon lord
        case GV_DEMON_LORD:
            // hands
            model.SetTexture(17, 7);
            model.SetTexture(13, 7);
            
            // legs
            model.SetTexture(1, 3);
            model.SetTexture(3, 3);
            model.SetTexture(4, 3);
            model.SetTexture(5, 3);
            model.SetTexture(7, 3);
            model.SetTexture(8, 3);
            
            // shin
            model.SetTexture(2, 3);
            model.SetTexture(6, 3);
            
            // chest
            model.SetTexture(0, 7);
            model.SetTexture(9, 7);
            
            // arms
            model.SetTexture(10, 7);
            model.SetTexture(11, 7);
            model.SetTexture(12, 7);
            model.SetTexture(13, 7);
            model.SetTexture(14, 7);
            model.SetTexture(15, 7);
            model.SetTexture(16, 7);
            
            // neck
            model.SetTexture(18, 5);
            break;
        }
    }
};
