class WRE expands NaliWeapons;

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

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

//Pickup
#exec MESH IMPORT MESH=WREPick ANIVFILE=MODELS\WRE_a.3d DATAFILE=MODELS\WRE_d.3d X=0 Y=0 Z=0
//#exec MESH LODPARAMS MESH=WREPick STRENGTH=0
#exec MESH ORIGIN MESH=WREPick X=0 Y=0 Z=0 YAW=128

//3rd person
#exec MESH IMPORT MESH=WREM ANIVFILE=MODELS\WRE_a.3d DATAFILE=MODELS\WRE_d.3d X=0 Y=0 Z=0
#exec MESH LODPARAMS MESH=WREM STRENGTH=0
#exec MESH ORIGIN MESH=WREM X=160 Y=0 Z=-80 YAW=128

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

//Animations
#exec MESH SEQUENCE MESH=WRE SEQ=All STARTFRAME=0 NUMFRAMES=12
#exec MESH SEQUENCE MESH=WRE SEQ=Still STARTFRAME=0 NUMFRAMES=1
#exec MESH SEQUENCE MESH=WRE SEQ=AltFire STARTFRAME=0 NUMFRAMES=6 RATE=12.0
#exec MESH SEQUENCE MESH=WRE SEQ=Fire STARTFRAME=5 NUMFRAMES=3 RATE=3.0
#exec MESH SEQUENCE MESH=WRE SEQ=Select STARTFRAME=8 NUMFRAMES=4 RATE=7.0 GROUP=Select
#exec MESH SEQUENCE MESH=WRE SEQ=Down STARTFRAME=11 NUMFRAMES=4 RATE=14.0

#exec MESH SEQUENCE MESH=WRER SEQ=All STARTFRAME=0 NUMFRAMES=12
#exec MESH SEQUENCE MESH=WRER SEQ=Still STARTFRAME=0 NUMFRAMES=1
#exec MESH SEQUENCE MESH=WRER SEQ=AltFire STARTFRAME=0 NUMFRAMES=6 RATE=12.0
#exec MESH SEQUENCE MESH=WRER SEQ=Fire STARTFRAME=5 NUMFRAMES=3 RATE=3.0
#exec MESH SEQUENCE MESH=WRER SEQ=Select STARTFRAME=8 NUMFRAMES=4 RATE=7.0 GROUP=Select
#exec MESH SEQUENCE MESH=WRER SEQ=Down STARTFRAME=11 NUMFRAMES=4 RATE=14.0

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

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

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

//Scale
#exec MESHMAP NEW MESHMAP=WRE MESH=WRE
#exec MESHMAP SCALE MESHMAP=WRE X=0.05 Y=0.05 Z=0.1

#exec MESHMAP NEW MESHMAP=WRER MESH=WRER
#exec MESHMAP SCALE MESHMAP=WRER X=0.05 Y=0.05 Z=0.1

#exec MESHMAP NEW MESHMAP=WREPick MESH=WREPick
#exec MESHMAP SCALE MESHMAP=WREPick X=0.05 Y=0.05 Z=0.1

#exec MESHMAP NEW MESHMAP=WREM MESH=WREM
#exec MESHMAP SCALE MESHMAP=WREM X=0.05 Y=0.05 Z=0.1

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

//Skins
#exec TEXTURE IMPORT NAME=Sk_WRE_01 FILE=SKINS\Sk_WRE_01.bmp GROUP=Skins FLAGS=2 LODSET=2
#exec MESHMAP SETTEXTURE MESHMAP=WRE NUM=1 TEXTURE=Sk_WRE_01
#exec MESHMAP SETTEXTURE MESHMAP=WRER NUM=1 TEXTURE=Sk_WRE_01
#exec MESHMAP SETTEXTURE MESHMAP=WREPick NUM=1 TEXTURE=Sk_WRE_01
#exec MESHMAP SETTEXTURE MESHMAP=WREM NUM=1 TEXTURE=Sk_WRE_01
 
#exec TEXTURE IMPORT NAME=Sk_WRE_02 FILE=SKINS\Sk_WRE_02.bmp GROUP=Skins FLAGS=2 LODSET=2
#exec MESHMAP SETTEXTURE MESHMAP=WRE NUM=2 TEXTURE=Sk_WRE_02
#exec MESHMAP SETTEXTURE MESHMAP=WRER NUM=2 TEXTURE=Sk_WRE_02
#exec MESHMAP SETTEXTURE MESHMAP=WREPick NUM=2 TEXTURE=Sk_WRE_02
#exec MESHMAP SETTEXTURE MESHMAP=WREM NUM=2 TEXTURE=Sk_WRE_02

#exec TEXTURE IMPORT NAME=Sk_WRE_03 FILE=SKINS\Sk_WRE_03.bmp GROUP=Skins FLAGS=2 LODSET=2
#exec MESHMAP SETTEXTURE MESHMAP=WRE NUM=3 TEXTURE=Sk_WRE_03
#exec MESHMAP SETTEXTURE MESHMAP=WRER NUM=3 TEXTURE=Sk_WRE_03
#exec MESHMAP SETTEXTURE MESHMAP=WREPick NUM=3 TEXTURE=Sk_WRE_03
#exec MESHMAP SETTEXTURE MESHMAP=WREM NUM=3 TEXTURE=Sk_WRE_03

#exec TEXTURE IMPORT NAME=Sk_WRE_04 FILE=SKINS\Sk_WRE_04.bmp GROUP=Skins FLAGS=2 LODSET=2
#exec MESHMAP SETTEXTURE MESHMAP=WRE NUM=4 TEXTURE=Sk_WRE_04
#exec MESHMAP SETTEXTURE MESHMAP=WRER NUM=4 TEXTURE=Sk_WRE_04
#exec MESHMAP SETTEXTURE MESHMAP=WREPick NUM=4 TEXTURE=Sk_WRE_04
#exec MESHMAP SETTEXTURE MESHMAP=WREM NUM=4 TEXTURE=Sk_WRE_04

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

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

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

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

//Sounds
#exec AUDIO IMPORT NAME="WRE_AltFire" FILE=SOUNDS\WRE_AltFire.wav GROUP="WRE"
#exec AUDIO IMPORT NAME="WRE_Fire" FILE=SOUNDS\WRE_Fire.wav GROUP="WRE"
#exec AUDIO IMPORT NAME="WRE_Pickup" FILE=SOUNDS\WRE_Pickup.wav GROUP="WRE"
#exec AUDIO IMPORT NAME="WRE_Select" FILE=SOUNDS\WRE_Select.wav GROUP="WRE"


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_WRE;
	}
}

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

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.0);
	else
        	TraceFire(0.7);
    }
    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()
{

	PlayOwnedSound(FireSound, SLOT_None, Pawn(Owner).SoundDampening*3.0);
	PlayAnim('Fire', FireRateChange * 2.5, 0.0);

	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);

        /*if ( bRapidFire || (FiringSpeed > 0) )
            Pawn(Owner).PlayRecoil(FiringSpeed);*/

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

        /*if ( bRapidFire || (FiringSpeed > 0) )
            Pawn(Owner).PlayRecoil(FiringSpeed);*/

	pj = ProjectileFire(AltProjectileClass, AltProjectileSpeed, bAltWarnTarget);

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


simulated function PlayAltFiring()
{

	PlayOwnedSound(AltFireSound, SLOT_None, Pawn(Owner).SoundDampening*3.0);
	PlayAnim('AltFire', FireRateChange * 1.0, 0.0);
}


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

	PawnOwner = Pawn(Owner);

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

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

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



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

	s = Spawn(class'WREShellCase',, '', Owner.Location + CalcDrawOffset() + 30 * X + (2.8 * 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'WREHitEffect',,, HitLocation+HitNormal, Rotator(HitNormal));
	else if ( (Other != self) && (Other != Owner) && (Other != None) ) 
	{
		if ( Other.bIsPawn )
		{
			Other.PlaySound(Sound 'ChunkHit',, 4.0,,100);
		}

		
		if ( Other.bIsPawn && (HitLocation.Z - Other.Location.Z > 0.62 * Other.CollisionHeight) 
			&& (instigator.IsA('PlayerPawn') || (instigator.IsA('Bot') && !Bot(Instigator).bNovice)) )
		{
			
			if (HealthGiver && (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 += 50 * FMax(1.0,MoreDamage);
					if (Pawn(Other).Health > Class'NWMutator'.default.MaxHealth)
						Pawn(Other).Health = Class'NWMutator'.default.MaxHealth;
			}

			Other.TakeDamage(50 * FMax(1.0,MoreDamage), Pawn(Owner), HitLocation, 35000 * X + (MirrorVectorByNormal(HitNormal, HitNormal) * (KickBack * 1000 + 1)), 'Decapitated');
		}
		else
		{
		
			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 += 15 * FMax(1.0,MoreDamage);
						if (Pawn(Other).Health > Class'NWMutator'.default.MaxHealth)
							Pawn(Other).Health = Class'NWMutator'.default.MaxHealth;
				}
			}

			Other.TakeDamage(15 * FMax(1.0,MoreDamage),  Pawn(Owner), HitLocation, 30000.0 * X + (MirrorVectorByNormal(HitNormal, HitNormal) * (KickBack * 1000 + 1)), MyDamageType);	
		}
		if ( !Other.bIsPawn && !Other.IsA('Carcass') )
			spawn(class'UT_SpriteSmokePuff',,,HitLocation+HitNormal*9);	
	}
}


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;

	EnemyDir = P.Enemy.Location - Owner.Location; 
	EnemyDist = VSize(EnemyDir);

	//Don't recommend second mode if it hasn't ammo for it and other conditions
	if (AmmoType.AmmoAmount < 10 || EnemyDist < 360 || 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=WREPick
	CollisionHeight=10.000000
	CollisionRadius=15.000000
	AutoSwitchPriority=2
	Icon=WREIcon
	InventoryGroup=2
	ItemArticle="a"
	ItemName="W.R.E."
	MaxDesireability=0.500000
	PickupMessage="You got the War Ready Enforcer (W.R.E.)."
	PickupSound=WRE_Pickup
	PickupViewMesh=WREPick
	PickupViewScale=1.000000
	PlayerViewMesh=WRER
	PlayerViewOffset=(X=30.000000,Y=-16.000000,Z=-15.000000)
	PlayerViewScale=1.000000
	RespawnTime=30.000000
	StatusIcon=WREIcon
	ThirdPersonMesh=WREM
	ThirdPersonScale=0.750000
	AltDamageType="Ionized"
	AltFireSound=WRE_AltFire
	AltProjectileClass=WREGrenade
	AmmoName=WREAmmo
	bInstantHit=True
	bOwnsCrosshair=False
	bRapidFire=True
	DeathMessage="%o was owned by %k's %w."
	FireOffset=(X=0.000000,Y=-10.000000,Z=0.000000)
	FireSound=WRE_Fire
	FiringSpeed=1.000000
	MaxTargetRange=4096.000000
	MyDamageType=Bullets
	NameColor=(R=64,G=0,B=64)
	PickupAmmoCount=35
	ProjectileClass=None
	SelectSound=WRE_Select
	shakemag=300.000000
	shaketime=0.100000
	shakevert=5.000000
	AIRating=0.200000
	AltRefireRate=1.000000
	bAltWarnTarget=False
	bRecommendAltSplashDamage=True
	bRecommendSplashDamage=False
	bSplashDamage=False
	bWarnTarget=False
	RefireRate=0.600000
	bNoSmooth=False
	bDrawMuzzleFlash=True
	bMuzzleFlashParticles=True
	FlashC=0.031000
	FlashLength=0.0400000
	FlashO=0.014000
	FlashS=128
	FlashY=0.100000
	MFTexture=Texture'Botpack.Skins.Muz7'
	MuzzleFlashMesh=LodMesh'Botpack.muzzEF3'
	MuzzleFlashScale=0.100000
	MuzzleFlashStyle=STY_Translucent
	MuzzleFlashTexture=Texture'Botpack.Skins.Muzzy2'
	MuzzleScale=2.00000
	bOwnsCrossHair=True
	CustomCross=WRECross
	CrossHairSize=64
	Mass=15.000000
}
