class MultiMissile expands NaliWeapons;

//1st person
#exec MESH IMPORT MESH=MultiMissile ANIVFILE=MODELS\MultiMissile_a.3d DATAFILE=MODELS\MultiMissile_d.3d X=0 Y=0 Z=0
#exec MESH LODPARAMS MESH=MultiMissile STRENGTH=0
#exec MESH ORIGIN MESH=MultiMissile X=0 Y=0 Z=0 Yaw=128

//1st person right handed
#exec MESH IMPORT MESH=MultiMissileR ANIVFILE=MODELS\MultiMissile_a.3d DATAFILE=MODELS\MultiMissile_d.3d X=0 Y=0 Z=0 UNMIRROR=1 UNMIRRORTEX=4
#exec MESH LODPARAMS MESH=MultiMissileR STRENGTH=0
#exec MESH ORIGIN MESH=MultiMissileR X=0 Y=0 Z=0

//Pickup
#exec MESH IMPORT MESH=MultiMissilePick ANIVFILE=MODELS\MultiMissile_a.3d DATAFILE=MODELS\MultiMissile_d.3d X=0 Y=0 Z=0
//#exec MESH LODPARAMS MESH=MultiMissilePick STRENGTH=0
#exec MESH ORIGIN MESH=MultiMissilePick X=0 Y=0 Z=0 Yaw=128

//3rd person
#exec MESH IMPORT MESH=MultiMissileM ANIVFILE=MODELS\MultiMissile_a.3d DATAFILE=MODELS\MultiMissile_d.3d X=0 Y=0 Z=0
#exec MESH LODPARAMS MESH=MultiMissileM STRENGTH=0
#exec MESH ORIGIN MESH=MultiMissileM X=400 Y=0 Z=-70 Yaw=128

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

//Animations
#exec MESH SEQUENCE MESH=MultiMissile SEQ=All STARTFRAME=0 NUMFRAMES=20
#exec MESH SEQUENCE MESH=MultiMissile SEQ=Still STARTFRAME=0 NUMFRAMES=1
#exec MESH SEQUENCE MESH=MultiMissile SEQ=Fire STARTFRAME=0 NUMFRAMES=5 RATE=5.0
#exec MESH SEQUENCE MESH=MultiMissile SEQ=Select STARTFRAME=5 NUMFRAMES=7 RATE=10.0 GROUP=Select
#exec MESH SEQUENCE MESH=MultiMissile SEQ=Down STARTFRAME=11 NUMFRAMES=7 RATE=20.0
#exec MESH SEQUENCE MESH=MultiMissile SEQ=AltFire STARTFRAME=18 NUMFRAMES=2 RATE=1.0

#exec MESH SEQUENCE MESH=MultiMissileR SEQ=All STARTFRAME=0 NUMFRAMES=20
#exec MESH SEQUENCE MESH=MultiMissileR SEQ=Still STARTFRAME=0 NUMFRAMES=1
#exec MESH SEQUENCE MESH=MultiMissileR SEQ=Fire STARTFRAME=0 NUMFRAMES=5 RATE=5.0
#exec MESH SEQUENCE MESH=MultiMissileR SEQ=Select STARTFRAME=5 NUMFRAMES=7 RATE=10.0 GROUP=Select
#exec MESH SEQUENCE MESH=MultiMissileR SEQ=Down STARTFRAME=11 NUMFRAMES=7 RATE=20.0
#exec MESH SEQUENCE MESH=MultiMissileR SEQ=AltFire STARTFRAME=18 NUMFRAMES=2 RATE=1.0

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

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

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

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

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

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

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

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

//Skins
#exec TEXTURE IMPORT NAME=Sk_MultiML_01 FILE=SKINS\Sk_MultiML_01.bmp GROUP=Skins FLAGS=2 LODSET=2
#exec MESHMAP SETTEXTURE MESHMAP=MultiMissile NUM=1 TEXTURE=Sk_MultiML_01
#exec MESHMAP SETTEXTURE MESHMAP=MultiMissileR NUM=1 TEXTURE=Sk_MultiML_01
#exec MESHMAP SETTEXTURE MESHMAP=MultiMissilePick NUM=1 TEXTURE=Sk_MultiML_01
#exec MESHMAP SETTEXTURE MESHMAP=MultiMissileM NUM=1 TEXTURE=Sk_MultiML_01

#exec TEXTURE IMPORT NAME=Sk_MultiML_02 FILE=SKINS\Sk_MultiML_02.bmp GROUP=Skins FLAGS=2 LODSET=2
#exec MESHMAP SETTEXTURE MESHMAP=MultiMissile NUM=2 TEXTURE=Sk_MultiML_02
#exec MESHMAP SETTEXTURE MESHMAP=MultiMissileR NUM=2 TEXTURE=Sk_MultiML_02
#exec MESHMAP SETTEXTURE MESHMAP=MultiMissilePick NUM=2 TEXTURE=Sk_MultiML_02
#exec MESHMAP SETTEXTURE MESHMAP=MultiMissileM NUM=2 TEXTURE=Sk_MultiML_02

#exec TEXTURE IMPORT NAME=Sk_MultiML_03 FILE=SKINS\Sk_MultiML_03.bmp GROUP=Skins FLAGS=2 LODSET=2
#exec MESHMAP SETTEXTURE MESHMAP=MultiMissile NUM=3 TEXTURE=Sk_MultiML_03
#exec MESHMAP SETTEXTURE MESHMAP=MultiMissileR NUM=3 TEXTURE=Sk_MultiML_03
#exec MESHMAP SETTEXTURE MESHMAP=MultiMissilePick NUM=3 TEXTURE=Sk_MultiML_03
#exec MESHMAP SETTEXTURE MESHMAP=MultiMissileM NUM=3 TEXTURE=Sk_MultiML_03

#exec TEXTURE IMPORT NAME=Screen_R_True FILE=SCREENS\Screen_R_True.bmp GROUP=Skins FLAGS=2 LODSET=0 MIPS=OFF
#exec MESHMAP SETTEXTURE MESHMAP=MultiMissile NUM=4 TEXTURE=Screen_R_True
#exec MESHMAP SETTEXTURE MESHMAP=MultiMissileR NUM=4 TEXTURE=Screen_R_True
#exec MESHMAP SETTEXTURE MESHMAP=MultiMissilePick NUM=4 TEXTURE=Screen_R_True
#exec MESHMAP SETTEXTURE MESHMAP=MultiMissileM NUM=4 TEXTURE=Screen_R_True

#exec TEXTURE IMPORT NAME=Sk_MultiML_05 FILE=SKINS\Sk_MultiML_05.bmp GROUP=Skins FLAGS=2 LODSET=2
#exec MESHMAP SETTEXTURE MESHMAP=MultiMissile NUM=5 TEXTURE=Sk_MultiML_05
#exec MESHMAP SETTEXTURE MESHMAP=MultiMissileR NUM=5 TEXTURE=Sk_MultiML_05
#exec MESHMAP SETTEXTURE MESHMAP=MultiMissilePick NUM=5 TEXTURE=Sk_MultiML_05
#exec MESHMAP SETTEXTURE MESHMAP=MultiMissileM NUM=5 TEXTURE=Sk_MultiML_05

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

//Screens
#exec TEXTURE IMPORT NAME=Screen_A_False FILE=SCREENS\Screen_A_False.bmp GROUP=Skins FLAGS=2 LODSET=0 MIPS=OFF
#exec TEXTURE IMPORT NAME=Screen_A_True FILE=SCREENS\Screen_A_True.bmp GROUP=Skins FLAGS=2 LODSET=0 MIPS=OFF
#exec TEXTURE IMPORT NAME=Screen_H_False FILE=SCREENS\Screen_H_False.bmp GROUP=Skins FLAGS=2 LODSET=0 MIPS=OFF
#exec TEXTURE IMPORT NAME=Screen_H_True FILE=SCREENS\Screen_H_True.bmp GROUP=Skins FLAGS=2 LODSET=0 MIPS=OFF
#exec TEXTURE IMPORT NAME=Screen_T_False FILE=SCREENS\Screen_T_False.bmp GROUP=Skins FLAGS=2 LODSET=0 MIPS=OFF
#exec TEXTURE IMPORT NAME=Screen_T_True FILE=SCREENS\Screen_T_True.bmp GROUP=Skins FLAGS=2 LODSET=0 MIPS=OFF
#exec TEXTURE IMPORT NAME=Screen_X_False FILE=SCREENS\Screen_X_False.bmp GROUP=Skins FLAGS=2 LODSET=0 MIPS=OFF
#exec TEXTURE IMPORT NAME=Screen_X_True FILE=SCREENS\Screen_X_True.bmp GROUP=Skins FLAGS=2 LODSET=0 MIPS=OFF

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

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

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

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

//Sounds
#exec AUDIO IMPORT NAME="MultiML_Select" FILE=SOUNDS\MultiML_Select.wav GROUP="MultiML"
#exec AUDIO IMPORT NAME="MultiML_Pickup" FILE=SOUNDS\MultiML_Pickup.wav GROUP="MultiML"
#exec AUDIO IMPORT NAME="MultiML_TargetOn" FILE=SOUNDS\MultiML_TargetOn.wav GROUP="MultiML"
#exec AUDIO IMPORT NAME="MultiML_Fire" FILE=SOUNDS\MultiML_Fire.wav GROUP="MultiML"
#exec AUDIO IMPORT NAME="MultiML_TargetOff" FILE=SOUNDS\MultiML_TargetOff.wav GROUP="MultiML"
#exec AUDIO IMPORT NAME="MultiML_AltFire" FILE=SOUNDS\MultiML_AltFire.wav GROUP="MultiML"

var() texture ScreenOK[5], ScreenFault[5];
var() Class<projectile> MissileProj[5];
var() int AmmoUsage[5];
var byte SelectedM;
var bool bInUse;
var float Count, CountB;

var actor LTarget, OldLTarget;
var vector LocPoint;
var bool bUseX;

replication
{
	reliable if(ROLE == Role_Authority && bNetOwner)
		SelectedM, bInUse;

	reliable if(ROLE == Role_Authority)
		LTarget, OldLTarget, LocPoint, bUseX;
}

function DropFrom(vector StartLocation)
{
	bInUse = False;
	Super.DropFrom(StartLocation);
}


simulated function PlaySelect()
{
	bInUse = True;
	Super.PlaySelect();   
}

simulated function TweenDown()
{
	bInUse = False;
	Super.TweenDown();
}



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

	bUseX = Class'NWMutator'.Default.EnableXMissile;
}

simulated function Tick(float DeltaTime)
{
local vector HitLocation, HitNormal, StartTrace, EndTrace, X,Y,Z;
local bool bEnemyToLock;

	Count += DeltaTime;
	CountB += DeltaTime;

	If (AmmoType != None)
	{
	if (((AmmoType.AmmoAmount >= AmmoUsage[SelectedM]) || bInfinity) && MultiSkins[4] != ScreenOK[SelectedM] && ((bUseX && SelectedM==4) || SelectedM != 4))
		MultiSkins[4] = ScreenOK[SelectedM];
	else if ((AmmoType.AmmoAmount < AmmoUsage[SelectedM] && MultiSkins[4] != ScreenFault[SelectedM] && !bInfinity) || (!bUseX && SelectedM==4 && MultiSkins[4] != ScreenFault[SelectedM]))
		MultiSkins[4] = ScreenFault[SelectedM];
	}

	if (OldLTarget != None && PlayerPawn(Owner) != None)
	{
		GetAxes(Pawn(Owner).ViewRotation,X,Y,Z);
		if (PlayerPawn(Owner).bAltFire != 0)
			PlayerPawn(Owner).ViewRotation = rotator((OldLTarget.Location - Pawn(Owner).Eyeheight * Z) - PlayerPawn(Owner).Location);
	}

	if (bInUse && ((SelectedM == 1 && Count >= 0.1) || Count >= 0.6))
	{
		Count = 0;
		GetAxes(Pawn(Owner).ViewRotation,X,Y,Z);
		StartTrace = Owner.Location + Pawn(Owner).Eyeheight * Z;
		EndTrace = StartTrace + (32000 * X);

		LTarget = Trace( HitLocation, HitNormal, EndTrace, StartTrace, True);

		if (HitLocation == vect(0,0,0))
			HitLocation = EndTrace;

		LocPoint = HitLocation;

		//Lock On!
		if ((SelectedM == 2 || SelectedM == 4) && CountB > 0.5 && LTarget.IsA('Pawn') && LTarget.Tag != ('NoSeek') && LTarget.Tag != ('IsFriend'))
		{
			CountB = 0;

			if (Role == ROLE_Authority)
			{

			If (TeamGamePlus(Level.Game)!= None && !Level.Game.IsA('MonsterHunt'))
			{

			If (Pawn(LTarget).PlayerReplicationInfo.Team != Instigator.PlayerReplicationInfo.Team && OldLTarget != LTarget)
				OldLTarget = LTarget;

			}
			else if (LTarget.IsA('ScriptedPawn') && Level.Game.IsA('MonsterHunt') && OldLTarget != LTarget)
				OldLTarget = LTarget;
			else if (LTarget != Instigator && OldLTarget != LTarget && Level.Game.IsA('DeathMatchPlus') && !Level.Game.IsA('MonsterHunt'))
				OldLTarget = LTarget;
			
			else if (!Level.Game.IsA('DeathMatchPlus') && LTarget.IsA('Pawn'))
			{
				bEnemyToLock = True;

				if (LTarget == Instigator && OldLTarget != LTarget)
					bEnemyToLock = False;
				else if (LTarget.IsA('ScriptedPawn') && Instigator.IsA('ScriptedPawn'))
				{
				if (ScriptedPawn(LTarget).TeamTag == ScriptedPawn(Instigator).TeamTag && ScriptedPawn(LTarget).TeamTag != '' && OldLTarget != LTarget)
					bEnemyToLock = False;
				}
				else if (Instigator.IsA('PlayerPawn') && (Pawn(LTarget).AttitudeToPlayer == ATTITUDE_Friendly || Pawn(LTarget).AttitudeToPlayer == ATTITUDE_Follow) && OldLTarget != LTarget)
					bEnemyToLock = False;

				
				if (bEnemyToLock)
					OldLTarget = LTarget;
			}

			}

		}

		if ((SelectedM == 3 || SelectedM == 4) && CountB > 0.5 && (LTarget.IsA('Vehicle') || LTarget.IsA('StrangeShell') || 
		LTarget.IsA('WarShell') || LTarget.IsA('DumbRocket') || LTarget.IsA('Cybot') || LTarget.IsA('TranslocatorTarget')) && LTarget.Tag != ('NoSeek') && LTarget.Tag != ('IsFriend'))
		{
			CountB = 0;
			
			if (Role == ROLE_Authority)
			{
			if (LTarget.IsA('TranslocatorTarget') || LTarget.IsA('WarShell') || LTarget.IsA('DumbRocket'))
				OldLTarget = LTarget;
			else If (TeamGamePlus(Level.Game)!= None && !Level.Game.IsA('MonsterHunt'))
			{

			If ((LTarget.IsA('StrangeShell') || LTarget.IsA('Cybot')) && (LTarget.Instigator.PlayerReplicationInfo.Team != Instigator.PlayerReplicationInfo.Team || LTarget.Instigator==Instigator))
				OldLTarget = LTarget;
			else If (LTarget.Instigator.PlayerReplicationInfo.Team != Instigator.PlayerReplicationInfo.Team && OldLTarget != LTarget && LTarget.Instigator!=Instigator)
				OldLTarget = LTarget;
			else If (Pawn(LTarget.Owner).PlayerReplicationInfo.Team != Instigator.PlayerReplicationInfo.Team && OldLTarget != LTarget && Pawn(LTarget.Owner)!=Pawn(Owner))
				OldLTarget = LTarget;

			}
			else if (OldLTarget != LTarget)
				OldLTarget = LTarget;
			}
		}

		if (!LTarget.IsA('Pawn') && !LTarget.IsA('Vehicle') && !LTarget.IsA('StrangeShell') && 
		!LTarget.IsA('StrangeShell') && !LTarget.IsA('WarShell') && !LTarget.IsA('DumbRocket') && !LTarget.IsA('Cybot') && !LTarget.IsA('TranslocatorTarget') && CustomCross == Texture'MMLCross_Lock')
		{
			OldLTarget = None;
			PlayOwnedSound(Sound'MultiML_TargetOff', SLOT_None, Pawn(Owner).SoundDampening*3.0);
			bOwnsCrossHair = class'NaliWeapons'.default.bCustomCrosshair;
			CustomCross = Default.CustomCross;
		}

		if (OldLTarget != None && CustomCross != Texture'MMLCross_Lock')
		{
			PlayOwnedSound(Sound'MultiML_TargetOn', SLOT_None, Pawn(Owner).SoundDampening*3.0);
			bOwnsCrossHair = True;
			CustomCross = Texture'MMLCross_Lock';
		}
	}
}

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


function AltFire( float Value )
{
	if (OldLTarget == None)
	{
        	GotoState('AltFiring');
        	bPointing=True;
        	bCanClientFire = true;
        	ClientAltFire(Value);
	}
}


simulated function PlayAltFiring()
{
	if (OldLTarget == None)
	{
	PlayAnim('AltFire', 4.0, 0.0);

	SelectedM++;

	if (SelectedM >= 5)
		SelectedM = 0;

	PlayOwnedSound(AltFireSound, SLOT_None, Pawn(Owner).SoundDampening*3.0);

	OldLTarget = None;
	bOwnsCrossHair = class'NaliWeapons'.default.bCustomCrosshair;
	CustomCross = Default.CustomCross;
	}
}

function Fire( float Value )
{
local Projectile pj;

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

    if ((bUseX && SelectedM==4) || SelectedM != 4)
    {
    if (bInfinity)
    {
	GotoState('NormalFire');
        bPointing=True;
        bCanClientFire = true;
        ClientFire(Value);

        pj = ProjectileFire(MissileProj[SelectedM], ProjectileSpeed, bWarnTarget);
	
	if (pj.IsA('NormalRocket'))
	{
		NormalRocket(pj).Kickback = Kickback;
		NormalRocket(pj).MoreDamage = MoreDamage;
		NormalRocket(pj).HealthGiver = HealthGiver;
		NormalRocket(pj).Splasher = Splasher;
	}

	if (pj.IsA('AMissile'))
	{
		AMissile(pj).Kickback = Kickback;
		AMissile(pj).MoreDamage = MoreDamage;
		AMissile(pj).HealthGiver = HealthGiver;
		AMissile(pj).Splasher = Splasher;
		GiveMaster(AMissile(pj));
	}

	if (pj.IsA('HMissile'))
	{
		HMissile(pj).Kickback = Kickback;
		HMissile(pj).MoreDamage = MoreDamage;
		HMissile(pj).HealthGiver = HealthGiver;
		HMissile(pj).Splasher = Splasher;

		GiveTarget(pj);
	}

	if (pj.IsA('TMissile'))
	{
		TMissile(pj).Kickback = Kickback;
		TMissile(pj).MoreDamage = MoreDamage;
		TMissile(pj).HealthGiver = HealthGiver;
		TMissile(pj).Splasher = Splasher;

		GiveTarget(pj);
	}

	if (pj.IsA('XMissile'))
	{
		XMissile(pj).Kickback = Kickback;
		XMissile(pj).MoreDamage = MoreDamage;
		XMissile(pj).Splasher = Splasher;

		GiveTarget(pj);;
	}
	
		
    }
    else if (AmmoType.UseAmmo(AmmoUsage[SelectedM]))
    {
        GotoState('NormalFire');
        bPointing=True;
        bCanClientFire = true;
        ClientFire(Value);

	if (AmmoType.AmmoAmount < AmmoUsage[SelectedM])
		MultiSkins[4] = ScreenFault[SelectedM];

	pj = ProjectileFire(MissileProj[SelectedM], ProjectileSpeed, bWarnTarget);

        if (pj.IsA('NormalRocket'))
	{
		NormalRocket(pj).Kickback = Kickback;
		NormalRocket(pj).MoreDamage = MoreDamage;
		NormalRocket(pj).HealthGiver = HealthGiver;
		NormalRocket(pj).Splasher = Splasher;
	}

	if (pj.IsA('AMissile'))
	{
		AMissile(pj).Kickback = Kickback;
		AMissile(pj).MoreDamage = MoreDamage;
		AMissile(pj).HealthGiver = HealthGiver;
		AMissile(pj).Splasher = Splasher;
		GiveMaster(AMissile(pj));
	}

	if (pj.IsA('HMissile'))
	{
		HMissile(pj).Kickback = Kickback;
		HMissile(pj).MoreDamage = MoreDamage;
		HMissile(pj).HealthGiver = HealthGiver;
		HMissile(pj).Splasher = Splasher;

		GiveTarget(pj);
	}

	if (pj.IsA('TMissile'))
	{
		TMissile(pj).Kickback = Kickback;
		TMissile(pj).MoreDamage = MoreDamage;
		TMissile(pj).HealthGiver = HealthGiver;
		TMissile(pj).Splasher = Splasher;

		GiveTarget(pj);
	}

	if (pj.IsA('XMissile'))
	{
		XMissile(pj).Kickback = Kickback;
		XMissile(pj).MoreDamage = MoreDamage;
		XMissile(pj).Splasher = Splasher;

		GiveTarget(pj);
	}
    }
    }
	else
		PlayFiring();
}

function GiveTarget( projectile ProjT)
{
	if (OldLTarget != None)
	{
		if (ProjT.IsA('HMissile'))
			HMissile(ProjT).LTarget = OldLTarget;
		else if (ProjT.IsA('TMissile'))
			TMissile(ProjT).LTarget = OldLTarget;
		else if (ProjT.IsA('XMissile'))
			XMissile(ProjT).LTarget = OldLTarget;
	}
}

function GiveMaster( AMissile AMProj)
{
	AMProj.WeaponMaster = Self;
}



simulated function PlayFiring()
{
	PlayAnim('Fire', 0.9 * FireRateChange, 0.0);
	PlayOwnedSound(FireSound, SLOT_None, Pawn(Owner).SoundDampening*8.0);
}


function Finish()
{
    local Pawn PawnOwner;
    local bool bForce, bForceAlt;

    bForce = bForceFire;
    bForceAlt = bForceAltFire;
    bForceFire = false;
    bForceAltFire = false;

    if ( bChangeWeapon )
    {
        GotoState('DownWeapon');
        return;
    }

    PawnOwner = Pawn(Owner);
    if ( PawnOwner == None )
        return;
    if ( PlayerPawn(Owner) == None )
    {
        if ( (AmmoType != None) && (AmmoType.AmmoAmount<=0) )
        {
            PawnOwner.StopFiring();
            PawnOwner.SwitchToBestWeapon();
            if ( bChangeWeapon )
                GotoState('DownWeapon');
        }
        else if ( (PawnOwner.bFire != 0) && (FRand() < RefireRate) )
            Global.Fire(0);
        else if ( (PawnOwner.bAltFire != 0) && (FRand() < AltRefireRate) && OldLTarget == None)
            Global.AltFire(0);  
        else 
        {
            PawnOwner.StopFiring();
            GotoState('Idle');
        }
        return;
    }
    if ( ((AmmoType != None) && (AmmoType.AmmoAmount<=0)) || (PawnOwner.Weapon != self) )
        GotoState('Idle');
    else if ( (PawnOwner.bFire!=0) || bForce )
        Global.Fire(0);
    else if ( ((PawnOwner.bAltFire!=0) || bForceAlt) && OldLTarget == None )
        Global.AltFire(0);
    else 
        GotoState('Idle');
}


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

	//Choose missile
	if (AmmoType.AmmoAmount < AmmoUsage[SelectedM])
		bUseAltMode = 1;
	else if (AmmoUsage[SelectedM] == 100 && EnemyDist > 3000 && bUseX)
		bUseAltMode = 0;
	else if (AmmoUsage[SelectedM] == 30 && EnemyDist > 1500)
		bUseAltMode = int(FRand() + 0.5);
	else if (AmmoUsage[SelectedM] == 10 && EnemyDist > 800)
		bUseAltMode = int(FRand() + 0.5);
	else if (AmmoUsage[SelectedM] == 3 && EnemyDist > 500)
		bUseAltMode = int(FRand() + 0.5);
	else if (EnemyDist > 360)
		bUseAltMode = int(FRand() + 0.5);

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



state ClientFiring
{
    simulated function AnimEnd()
    {
        if ( (Pawn(Owner) == None)
            || ((AmmoType != None) && (AmmoType.AmmoAmount <= 0)) )
        {
            PlayIdleAnim();
            GotoState('');
        }
        else if ( !bCanClientFire )
            GotoState('');
        else if ( Pawn(Owner).bFire != 0 )
            Global.ClientFire(0);
        else
        {
            PlayIdleAnim();
            GotoState('');
        }
    }
}





defaultproperties
{
	DrawType=DT_Mesh
	Mesh=MultiMissilePick
	CollisionHeight=10.000000
	CollisionRadius=15.000000
	AutoSwitchPriority=9
	Icon=MMLIcon
	InventoryGroup=9
	ItemArticle="a"
	ItemName="MultiMissile Launcher"
	MaxDesireability=0.800000
	PickupMessage="You got the MultiMissile Launcher."
	PickupSound=MultiML_Pickup
	PickupViewMesh=MultiMissilePick
	PickupViewScale=1.000000
	PlayerViewMesh=MultiMissileR
	PlayerViewOffset=(X=30.000000,Y=-10.000000,Z=-12.000000)
	PlayerViewScale=1.000000
	RespawnTime=30.000000
	StatusIcon=MMLIcon
	ThirdPersonMesh=MultiMissileM
	ThirdPersonScale=0.750000
	AltDamageType=None
	AltFireSound=MultiML_AltFire
	AltProjectileClass=None
	AmmoName=Class'MultiMAmmo'
	bInstantHit=False
	bRapidFire=False
	DeathMessage="%o was blown up to nothing by %k's %w."
	FireOffset=(X=0.000000,Y=-4.000000,Z=0.000000)
	FireSound=MultiML_Fire
	FiringSpeed=1.000000
	MaxTargetRange=4096.000000
	MyDamageType=MissileBlast
	NameColor=(R=32,G=0,B=0)
	PickupAmmoCount=10
	ProjectileClass=None
	SelectSound=MultiML_Select
	shakemag=0.000000
	shaketime=0.000000
	shakevert=0.000000
	AIRating=0.900000
	AltRefireRate=1.000000
	bAltWarnTarget=False
	bRecommendAltSplashDamage=False
	bRecommendSplashDamage=True
	bSplashDamage=True
	bWarnTarget=True
	RefireRate=0.600000
	Mass=50.000000
	bNoSmooth=False
	bOwnsCrossHair=True
	CustomCross=MMLCross
	CrossHairSize=64
	CrossHairScale=0.800000
	ScreenOK(0)=Screen_R_True
	ScreenOK(1)=Screen_A_True
	ScreenOK(2)=Screen_H_True
	ScreenOK(3)=Screen_T_True
	ScreenOK(4)=Screen_X_True
	ScreenFault(0)=Screen_R_True
	ScreenFault(1)=Screen_A_False
	ScreenFault(2)=Screen_H_False
	ScreenFault(3)=Screen_T_False
	ScreenFault(4)=Screen_X_False
	MissileProj(0)=Class'NormalRocket'
	MissileProj(1)=Class'AMissile'
	MissileProj(2)=Class'HMissile'
	MissileProj(3)=Class'TMissile'
	MissileProj(4)=Class'XMissile'
	AmmoUsage(0)=1
	AmmoUsage(1)=3
	AmmoUsage(2)=10
	AmmoUsage(3)=30
	AmmoUsage(4)=100
}
