class Vulcan expands NaliWeapons;

//1st person
#exec MESH IMPORT MESH=Vulcan ANIVFILE=MODELS\Vulcan_a.3d DATAFILE=MODELS\Vulcan_d.3d X=0 Y=0 Z=0
#exec MESH LODPARAMS MESH=Vulcan STRENGTH=0
#exec MESH ORIGIN MESH=Vulcan X=0 Y=0 Z=0 YAW=128

//1st person right handed
#exec MESH IMPORT MESH=VulcanR ANIVFILE=MODELS\Vulcan_a.3d DATAFILE=MODELS\Vulcan_d.3d X=0 Y=0 Z=0 UNMIRROR=1
#exec MESH LODPARAMS MESH=VulcanR STRENGTH=0
#exec MESH ORIGIN MESH=VulcanR X=0 Y=0 Z=0

//Pickup
#exec MESH IMPORT MESH=VulcanPick ANIVFILE=MODELS\Vulcan_a.3d DATAFILE=MODELS\Vulcan_d.3d X=0 Y=0 Z=0
//#exec MESH LODPARAMS MESH=VulcanPick STRENGTH=0
#exec MESH ORIGIN MESH=VulcanPick X=0 Y=0 Z=0 YAW=128

//3rd person
#exec MESH IMPORT MESH=VulcanM ANIVFILE=MODELS\Vulcan_a.3d DATAFILE=MODELS\Vulcan_d.3d X=0 Y=0 Z=0
#exec MESH LODPARAMS MESH=VulcanM STRENGTH=0
#exec MESH ORIGIN MESH=VulcanM X=420 Y=0 Z=80 YAW=128

//-----------------------------------------------------------------------------------

//Animations
#exec MESH SEQUENCE MESH=Vulcan SEQ=All STARTFRAME=0 NUMFRAMES=59
#exec MESH SEQUENCE MESH=Vulcan SEQ=Still STARTFRAME=0 NUMFRAMES=1
#exec MESH SEQUENCE MESH=Vulcan SEQ=Fire STARTFRAME=0 NUMFRAMES=16 RATE=32.0
#exec MESH SEQUENCE MESH=Vulcan SEQ=PostFire STARTFRAME=16 NUMFRAMES=28 RATE=32.0
#exec MESH SEQUENCE MESH=Vulcan SEQ=AltFire STARTFRAME=44 NUMFRAMES=6 RATE=12.0
#exec MESH SEQUENCE MESH=Vulcan SEQ=Select STARTFRAME=50 NUMFRAMES=5 RATE=8.0 GROUP=Select
#exec MESH SEQUENCE MESH=Vulcan SEQ=Down STARTFRAME=54 NUMFRAMES=5 RATE=16.0

#exec MESH SEQUENCE MESH=VulcanR SEQ=All STARTFRAME=0 NUMFRAMES=59
#exec MESH SEQUENCE MESH=VulcanR SEQ=Still STARTFRAME=0 NUMFRAMES=1
#exec MESH SEQUENCE MESH=VulcanR SEQ=Fire STARTFRAME=0 NUMFRAMES=16 RATE=32.0
#exec MESH SEQUENCE MESH=VulcanR SEQ=PostFire STARTFRAME=16 NUMFRAMES=28 RATE=32.0
#exec MESH SEQUENCE MESH=VulcanR SEQ=AltFire STARTFRAME=44 NUMFRAMES=6 RATE=12.0
#exec MESH SEQUENCE MESH=VulcanR SEQ=Select STARTFRAME=50 NUMFRAMES=5 RATE=8.0 GROUP=Select
#exec MESH SEQUENCE MESH=VulcanR SEQ=Down STARTFRAME=54 NUMFRAMES=5 RATE=16.0

#exec MESH SEQUENCE MESH=VulcanPick SEQ=Still STARTFRAME=0 NUMFRAMES=1

#exec MESH SEQUENCE MESH=VulcanM SEQ=Still STARTFRAME=0 NUMFRAMES=1
#exec MESH SEQUENCE MESH=VulcanM SEQ=Fire STARTFRAME=0 NUMFRAMES=16 RATE=32.0
#exec MESH SEQUENCE MESH=VulcanM SEQ=PostFire STARTFRAME=16 NUMFRAMES=28 RATE=32.0
#exec MESH SEQUENCE MESH=VulcanM SEQ=AltFire STARTFRAME=44 NUMFRAMES=6 RATE=12.0

//-----------------------------------------------------------------------------------

//Scale
#exec MESHMAP NEW MESHMAP=Vulcan MESH=Vulcan
#exec MESHMAP SCALE MESHMAP=Vulcan X=0.05625 Y=0.05625 Z=0.1125

#exec MESHMAP NEW MESHMAP=VulcanR MESH=VulcanR
#exec MESHMAP SCALE MESHMAP=VulcanR X=0.05625 Y=0.05625 Z=0.1125

#exec MESHMAP NEW MESHMAP=VulcanPick MESH=VulcanPick
#exec MESHMAP SCALE MESHMAP=VulcanPick X=0.05625 Y=0.05625 Z=0.1125

#exec MESHMAP NEW MESHMAP=VulcanM MESH=VulcanM
#exec MESHMAP SCALE MESHMAP=VulcanM X=0.05625 Y=0.05625 Z=0.1125

//-----------------------------------------------------------------------------------

//Skins
#exec TEXTURE IMPORT NAME=Sk_Vulcan_01 FILE=SKINS\Sk_Vulcan_01.bmp GROUP=Skins FLAGS=2 LODSET=2
#exec MESHMAP SETTEXTURE MESHMAP=Vulcan NUM=1 TEXTURE=Sk_Vulcan_01
#exec MESHMAP SETTEXTURE MESHMAP=VulcanR NUM=1 TEXTURE=Sk_Vulcan_01
#exec MESHMAP SETTEXTURE MESHMAP=VulcanPick NUM=1 TEXTURE=Sk_Vulcan_01
#exec MESHMAP SETTEXTURE MESHMAP=VulcanM NUM=1 TEXTURE=Sk_Vulcan_01

#exec TEXTURE IMPORT NAME=Sk_Vulcan_02 FILE=SKINS\Sk_Vulcan_02.bmp GROUP=Skins FLAGS=2 LODSET=2
#exec MESHMAP SETTEXTURE MESHMAP=Vulcan NUM=2 TEXTURE=Sk_Vulcan_02
#exec MESHMAP SETTEXTURE MESHMAP=VulcanR NUM=2 TEXTURE=Sk_Vulcan_02
#exec MESHMAP SETTEXTURE MESHMAP=VulcanPick NUM=2 TEXTURE=Sk_Vulcan_02
#exec MESHMAP SETTEXTURE MESHMAP=VulcanM NUM=2 TEXTURE=Sk_Vulcan_02

#exec TEXTURE IMPORT NAME=Sk_Vulcan_03 FILE=SKINS\Sk_Vulcan_03.bmp GROUP=Skins FLAGS=2 LODSET=2
#exec MESHMAP SETTEXTURE MESHMAP=Vulcan NUM=3 TEXTURE=Sk_Vulcan_03
#exec MESHMAP SETTEXTURE MESHMAP=VulcanR NUM=3 TEXTURE=Sk_Vulcan_03
#exec MESHMAP SETTEXTURE MESHMAP=VulcanPick NUM=3 TEXTURE=Sk_Vulcan_03
#exec MESHMAP SETTEXTURE MESHMAP=VulcanM NUM=3 TEXTURE=Sk_Vulcan_03

#exec TEXTURE IMPORT NAME=Sk_Vulcan_04 FILE=SKINS\Sk_Vulcan_04.bmp GROUP=Skins FLAGS=2 LODSET=2
#exec MESHMAP SETTEXTURE MESHMAP=Vulcan NUM=4 TEXTURE=Sk_Vulcan_04
#exec MESHMAP SETTEXTURE MESHMAP=VulcanR NUM=4 TEXTURE=Sk_Vulcan_04
#exec MESHMAP SETTEXTURE MESHMAP=VulcanPick NUM=4 TEXTURE=Sk_Vulcan_04
#exec MESHMAP SETTEXTURE MESHMAP=VulcanM NUM=4 TEXTURE=Sk_Vulcan_04

//--------------------------------------------------------------

//Icons
#exec TEXTURE IMPORT NAME=VulcanIcon FILE=ICONS\VulcanIcon.bmp GROUP=Icons MIPS=OFF

#exec OBJ LOAD FILE=Textures\NaliIcons.utx PACKAGE=NaliWeaponsII.Icons

//--------------------------------------------------------------

//MuzzleFlash
#exec TEXTURE IMPORT NAME=VulcanMuz01 FILE=EFFECTS\VulcanMuz01.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=VulcanMuz02 FILE=EFFECTS\VulcanMuz02.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=VulcanMuz03 FILE=EFFECTS\VulcanMuz03.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=VulcanMuz04 FILE=EFFECTS\VulcanMuz04.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=VulcanMuz05 FILE=EFFECTS\VulcanMuz05.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=VulcanMuz06 FILE=EFFECTS\VulcanMuz06.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=VulcanMuz07 FILE=EFFECTS\VulcanMuz07.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=VulcanMuz08 FILE=EFFECTS\VulcanMuz08.bmp GROUP=Effects FLAGS=2
#exec TEXTURE IMPORT NAME=VulcanMuz09 FILE=EFFECTS\VulcanMuz09.bmp GROUP=Effects FLAGS=2


//--------------------------------------------------------------

//Sounds
#exec AUDIO IMPORT NAME="Vulcan_Fire" FILE=SOUNDS\Vulcan_Fire.wav GROUP="Vulcan"
#exec AUDIO IMPORT NAME="Vulcan_EndSpin" FILE=SOUNDS\Vulcan_EndSpin.wav GROUP="Vulcan"
#exec AUDIO IMPORT NAME="Vulcan_LoopSpin" FILE=SOUNDS\Vulcan_LoopSpin.wav GROUP="Vulcan"
#exec AUDIO IMPORT NAME="Vulcan_Pick" FILE=SOUNDS\Vulcan_Pick.wav GROUP="Vulcan"
#exec AUDIO IMPORT NAME="Vulcan_Select" FILE=SOUNDS\Vulcan_Select.wav GROUP="Vulcan"
#exec AUDIO IMPORT NAME="Vulcan_AltFire" FILE=SOUNDS\Vulcan_AltFire.wav GROUP="Vulcan"


var() texture RandMuzzle[9];
var int Count;

function PreBeginPlay()
{
	Super.PreBeginPlay();
	if ((Level.Game.IsA('MonsterHunt') && Class'NWMutator'.Default.EnableMonsterHuntMode && Class'NWMutator'.Default.MonsterHuntOnly) || (Class'NWMutator'.Default.EnableMonsterHuntMode && !Class'NWMutator'.Default.MonsterHuntOnly))
	{
		PickupAmmoCount *= Class'NWMutator'.default.ammo_Vulcan;
	}
}

function setHand(float Hand)
{
	Super.SetHand(Hand);
	if ( Hand == 1 )
		Mesh = mesh'Vulcan';
	else
		Mesh = mesh'VulcanR';
}


function Fire( float Value )
{
    if ( (AmmoType == None) && (AmmoName != None) )
    {
        // ammocheck
        GiveAmmo(Pawn(Owner));
    }

    if (bInfinity)
    {
	GotoState('NormalFire');
        bPointing=True;
        bCanClientFire = true;
        ClientFire(Value);
        if ( bRapidFire || (FiringSpeed > 0) )
            Pawn(Owner).PlayRecoil(FiringSpeed);

	If (Pawn(Owner).bDuck != 0 || Pawn(Owner).bRun == 0)
		TraceFire(0.6);
	else
        	TraceFire(2.0);
    }
    else if ( AmmoType.UseAmmo(1) )
    {
        GotoState('NormalFire');
        bPointing=True;
        bCanClientFire = true;
        ClientFire(Value);
        if ( bRapidFire || (FiringSpeed > 0) )
            Pawn(Owner).PlayRecoil(FiringSpeed);

	If (Pawn(Owner).bDuck != 0 || Pawn(Owner).bRun == 0)
		TraceFire(0.6);
	else
        	TraceFire(2.0);
    }
}


simulated function PlayFiring()
{
	if (!IsAnimating())
		LoopAnim('Fire', 5.0);

	if (AmbientSound == None)
		AmbientSound = Sound'Vulcan_LoopSpin';

	PlayOwnedSound(FireSound, SLOT_None, Pawn(Owner).SoundDampening*3.0);
	MFTexture = RandMuzzle[Rand(9)];

	bMuzzleFlash++;
}


function AltFire( float Value )
{
local Projectile pj;

    if ( (AmmoType == None) && (AmmoName != None) )
    {
        // ammocheck
        GiveAmmo(Pawn(Owner));
    }

    if (bInfinity)
    {
	GotoState('AltFiring');
        bPointing=True;
        bCanClientFire = true;
        ClientAltFire(Value);

        pj = ProjectileFire(AltProjectileClass, AltProjectileSpeed, bAltWarnTarget);
	
	if (pj.IsA('VulcanRock'))
	{
		VulcanRock(pj).Kickback = Kickback;
		VulcanRock(pj).MoreDamage = MoreDamage;
		VulcanRock(pj).HealthGiver = HealthGiver;
	}
		
    }	
    else if (AmmoType.UseAmmo(12))
    {
        GotoState('AltFiring');
        bPointing=True;
        bCanClientFire = true;
        ClientAltFire(Value);

	pj = ProjectileFire(AltProjectileClass, AltProjectileSpeed, bAltWarnTarget);

        if (pj.IsA('VulcanRock'))
	{
		VulcanRock(pj).Kickback = Kickback;
		VulcanRock(pj).MoreDamage = MoreDamage;
		VulcanRock(pj).HealthGiver = HealthGiver;
	}
    }
	else PlayAltFiring();
	
}


simulated function PlayAltFiring()
{
	PlayOwnedSound(AltFireSound, SLOT_None, Pawn(Owner).SoundDampening*3.0);
	PlayAnim('AltFire', FireRateChange * 0.3, 0.0);
}


function TraceFire( float Accuracy )
{
    local vector HitLocation, HitNormal, StartTrace, EndTrace, X,Y,Z, AimDir;
    local actor Other;
    local vector RealOffset;

	RealOffset = FireOffset;
	FireOffset = vect(0,-1,10);

    Owner.MakeNoise(Pawn(Owner).SoundDampening);
    GetAxes(Pawn(owner).ViewRotation,X,Y,Z);
    StartTrace = Owner.Location + CalcDrawOffset() + FireOffset.Y * Y + FireOffset.Z * Z; 
    AdjustedAim = pawn(owner).AdjustAim(1000000, StartTrace, 2.75*AimError, False, False);  
    EndTrace = StartTrace + Accuracy * (FRand() - 0.5 )* Y * 1000
        + Accuracy * (FRand() - 0.5 ) * Z * 1000;
    AimDir = vector(AdjustedAim);
    EndTrace += (10000 * AimDir); 
    Other = Pawn(Owner).TraceShot(HitLocation,HitNormal,EndTrace,StartTrace);

    Count++;
    if ( Count == 4 )
    {
        Count = 0;
        if ( VSize(HitLocation - StartTrace) > 250 )
            Spawn(class'VulcanTracer',,, StartTrace + 192 * AimDir,rotator(EndTrace - StartTrace));
    }

	FireOffset = RealOffset;
    ProcessTraceHit(Other, HitLocation, HitNormal, vector(AdjustedAim),Y,Z);
}


function ProcessTraceHit(Actor Other, Vector HitLocation, Vector HitNormal, Vector X, Vector Y, Vector Z)
{
	local VulcanBulletC s;

	s = Spawn(class'VulcanBulletC',, '', Owner.Location + CalcDrawOffset() + 10 * X + (1.1 * FireOffset.Y+5.0) * Y - Z * 1);
	if ( s != None ) 
	{
		s.DrawScale = 2.0;
		s.Eject(((FRand()*0.3+0.4)*X + (FRand()*0.2+0.2)*Y + (FRand()*0.3+1.0) * Z)*160);              
	}
	if (Other == Level) 
		Spawn(class'VulcanHitEffect',,, HitLocation+HitNormal, Rotator(HitNormal));

	else if ( (Other != self) && (Other != Owner) && (Other != None) ) 
	{
		if ( Other.bIsPawn )
		{
			Other.PlaySound(Sound 'ChunkHit',, 4.0,,100);
		}
		
		if (HealthGiver && Other.bIsPawn)
		{
				if ((Pawn(Other).PlayerReplicationInfo.Team == Instigator.PlayerReplicationInfo.Team && Level.Game.IsA('TeamGamePlus') && !Level.Game.IsA('MonsterHunt')) ||
		(Level.Game.IsA('MonsterHunt') && !Pawn(Other).IsA('ScriptedPawn')) && Pawn(Other).Health < Class'NWMutator'.default.MaxHealth)
			{
				Pawn(Other).Health += (11 + Rand(6)) * FMax(1.0,MoreDamage) * FireRateChange;
					if (Pawn(Other).Health > Class'NWMutator'.default.MaxHealth)
						Pawn(Other).Health = Class'NWMutator'.default.MaxHealth;
			}
		}

		Other.TakeDamage((11 + Rand(6)) * FMax(1.0,MoreDamage) * FireRateChange,  Pawn(Owner), HitLocation, 30000.0 * X + (MirrorVectorByNormal(HitNormal, HitNormal) * (KickBack * 1000 + 1)), MyDamageType);
	}

	Spawn(class'VulcanHitExpl',,,HitLocation+HitNormal*9);	
}


function Projectile ProjectileFire(class<projectile> ProjClass, float ProjSpeed, bool bWarn)
{
    local Vector Start, X,Y,Z, RealOffset;
    local Pawn PawnOwner;

	RealOffset = FireOffset;
	FireOffset = vect(0,-7,-2);

    PawnOwner = Pawn(Owner);
    Owner.MakeNoise(PawnOwner.SoundDampening);
    GetAxes(PawnOwner.ViewRotation,X,Y,Z);
    Start = Owner.Location + CalcDrawOffset() + FireOffset.X * X + FireOffset.Y * Y + FireOffset.Z * Z; 
    AdjustedAim = PawnOwner.AdjustAim(ProjSpeed, Start, AimError, True, bWarn);

	FireOffset = RealOffset;
    return Spawn(ProjClass,,, Start,AdjustedAim);   
}





simulated function PlayIdleAnim()
{
	if (AnimSequence == 'Fire')
	{
		AmbientSound = None;
		PlayAnim('PostFire', 0.7, 0.0);
		PlayOwnedSound(Sound'Vulcan_EndSpin', SLOT_None, Pawn(Owner).SoundDampening*3.0);
	}
}

function DropFrom(vector StartLocation)
{
	Super.DropFrom(StartLocation);
	AmbientSound = None;
}

simulated function TweenDown()
{
	Super.TweenDown();
	AmbientSound = None;
}


simulated function Tick( float DeltaTime)
{
	If (Owner == None)
		AmbientSound = None;
	else if (Pawn(Owner).bFire == 0)
		AmbientSound = None;
	
	Super.Tick(DeltaTime);
}


simulated function TweenToStill();

function float RateSelf( out int bUseAltMode )
{
	local float EnemyDist, Rating;
	local bool bRetreating;
	local vector EnemyDir;
	local Pawn P;

	P = Pawn(Owner);

	//No enemy, ready to fire
	if ( P.Enemy == None )
        	return AIRating;

	//Don't recommend self if out of ammo
	if ( AmmoType.AmmoAmount <=0 )
        	return -2;

	//Don't recommend second mode if it hasn't ammo for it and other conditions
	if (AmmoType.AmmoAmount < 12 || P.Enemy.Region.Zone.bWaterZone || P.Region.Zone.bWaterZone)
		bUseAltMode = 0;
	else
		bUseAltMode = int(FRand() + 0.5);

	return (AIRating + FRand() * 0.05);
}


/////////////////////////////////////////////////////////////////
state NormalFire
{
	function EndState()
	{
		Super.EndState();
		OldFlashCount = FlashCount;
	}
		
Begin:
	FlashCount++;
}



defaultproperties
{
	DrawType=DT_Mesh
	Mesh=Vulcan
	CollisionHeight=10.000000
	CollisionRadius=15.000000
	AutoSwitchPriority=7
	Icon=VulcanIcon
	InventoryGroup=7
	ItemArticle="a"
	ItemName="Vulcan"
	MaxDesireability=0.500000
	PickupMessage="You got the Vulcan."
	PickupSound=Vulcan_Pick
	PickupViewMesh=VulcanPick
	PickupViewScale=1.000000
	PlayerViewMesh=VulcanR
	PlayerViewOffset=(X=35.000000,Y=-20.000000,Z=-17.000000)
	PlayerViewScale=1.000000
	RespawnTime=30.000000
	StatusIcon=VulcanIcon
	ThirdPersonMesh=VulcanM
	ThirdPersonScale=0.750000
	AltDamageType=Rock
	AltFireSound=Vulcan_AltFire
	AltProjectileClass=Class'VulcanRock'
	AmmoName=VulcanAmmo
	bInstantHit=True
	bOwnsCrosshair=False
	bRapidFire=True
	DeathMessage="%o was perfurated by %k's %w."
	FireOffset=(X=0.000000,Y=-10.000000,Z=0.000000)
	FireSound=Vulcan_Fire
	FiringSpeed=1.000000
	MaxTargetRange=4096.000000
	MyDamageType=Bullets
	NameColor=(R=128,G=128,B=0)
	PickupAmmoCount=40
	ProjectileClass=None
	SelectSound=Vulcan_Select
	shakemag=900.000000
	shaketime=0.150000
	shakevert=15.000000
	AIRating=0.700000
	AltRefireRate=1.000000
	bAltWarnTarget=False
	bRecommendAltSplashDamage=True
	bRecommendSplashDamage=False
	bSplashDamage=False
	bWarnTarget=False
	RefireRate=0.600000
	Mass=50.000000
	bNoSmooth=False
	bDrawMuzzleFlash=True
	bMuzzleFlashParticles=True
	FlashC=0.031000
	FlashLength=0.0400000
	FlashO=0.014000
	FlashS=128
	FlashY=0.150000
	MFTexture=VulcanMuz01
	MuzzleFlashMesh=LodMesh'Botpack.MuzzFlash3'
	MuzzleFlashScale=0.500000
	MuzzleFlashStyle=STY_Translucent
	MuzzleFlashTexture=Texture'Botpack.Skins.MuzzyFlak'
	MuzzleScale=2.000000
	bOwnsCrossHair=True
	CustomCross=VulcanCross
	CrossHairSize=64
	Texture=Sk_Vulcan_02
	CrossHairScale=0.750000
	RandMuzzle(0)=VulcanMuz01
	RandMuzzle(1)=VulcanMuz02
	RandMuzzle(2)=VulcanMuz03
	RandMuzzle(3)=VulcanMuz04
	RandMuzzle(4)=VulcanMuz05
	RandMuzzle(5)=VulcanMuz06
	RandMuzzle(6)=VulcanMuz07
	RandMuzzle(7)=VulcanMuz08
	RandMuzzle(8)=VulcanMuz09
}
