class UltimaProtos expands NaliWeapons;

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

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

//Pickup
#exec MESH IMPORT MESH=UltimaProtosPick ANIVFILE=MODELS\UltimaProtos_a.3d DATAFILE=MODELS\UltimaProtos_d.3d X=0 Y=0 Z=0 UNMIRROR=1
//#exec MESH LODPARAMS MESH=UltimaProtosPick STRENGTH=0
#exec MESH ORIGIN MESH=UltimaProtosPick X=0 Y=0 Z=0

//3rd person
#exec MESH IMPORT MESH=UltimaProtosM ANIVFILE=MODELS\UltimaProtos_a.3d DATAFILE=MODELS\UltimaProtos_d.3d X=0 Y=0 Z=0 UNMIRROR=1
#exec MESH LODPARAMS MESH=UltimaProtosM STRENGTH=0
#exec MESH ORIGIN MESH=UltimaProtosM X=-310 Y=0 Z=-40

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

//Animations
#exec MESH SEQUENCE MESH=UltimaProtos SEQ=All STARTFRAME=0 NUMFRAMES=21
#exec MESH SEQUENCE MESH=UltimaProtos SEQ=Still STARTFRAME=0 NUMFRAMES=1
#exec MESH SEQUENCE MESH=UltimaProtos SEQ=Fire STARTFRAME=0 NUMFRAMES=12 RATE=6.0
#exec MESH SEQUENCE MESH=UltimaProtos SEQ=Select STARTFRAME=12 NUMFRAMES=5 RATE=7.0 GROUP=Select
#exec MESH SEQUENCE MESH=UltimaProtos SEQ=Down STARTFRAME=16 NUMFRAMES=5 RATE=14.0

#exec MESH SEQUENCE MESH=UltimaProtosR SEQ=All STARTFRAME=0 NUMFRAMES=21
#exec MESH SEQUENCE MESH=UltimaProtosR SEQ=Still STARTFRAME=0 NUMFRAMES=1
#exec MESH SEQUENCE MESH=UltimaProtosR SEQ=Fire STARTFRAME=0 NUMFRAMES=12 RATE=6.0
#exec MESH SEQUENCE MESH=UltimaProtosR SEQ=Select STARTFRAME=12 NUMFRAMES=5 RATE=7.0 GROUP=Select
#exec MESH SEQUENCE MESH=UltimaProtosR SEQ=Down STARTFRAME=16 NUMFRAMES=5 RATE=14.0

#exec MESH SEQUENCE MESH=UltimaProtosPick SEQ=All STARTFRAME=0 NUMFRAMES=21
#exec MESH SEQUENCE MESH=UltimaProtosPick SEQ=Still STARTFRAME=0 NUMFRAMES=1

#exec MESH SEQUENCE MESH=UltimaProtosM SEQ=All STARTFRAME=0 NUMFRAMES=21
#exec MESH SEQUENCE MESH=UltimaProtosM SEQ=Still STARTFRAME=0 NUMFRAMES=1
#exec MESH SEQUENCE MESH=UltimaProtosM SEQ=Fire STARTFRAME=0 NUMFRAMES=12 RATE=6.0

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

//Scale
#exec MESHMAP NEW MESHMAP=UltimaProtos MESH=UltimaProtos
#exec MESHMAP SCALE MESHMAP=UltimaProtos X=0.1 Y=0.1 Z=0.2

#exec MESHMAP NEW MESHMAP=UltimaProtosR MESH=UltimaProtosR
#exec MESHMAP SCALE MESHMAP=UltimaProtosR X=0.1 Y=0.1 Z=0.2

#exec MESHMAP NEW MESHMAP=UltimaProtosPick MESH=UltimaProtosPick
#exec MESHMAP SCALE MESHMAP=UltimaProtosPick X=0.1 Y=0.1 Z=0.2

#exec MESHMAP NEW MESHMAP=UltimaProtosM MESH=UltimaProtosM
#exec MESHMAP SCALE MESHMAP=UltimaProtosM X=0.1 Y=0.1 Z=0.2

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

//Skins
#exec TEXTURE IMPORT NAME=Sk_UltimaProtos_01 FILE=SKINS\Sk_UltimaProtos_01.bmp GROUP=Skins FLAGS=2 LODSET=2
#exec MESHMAP SETTEXTURE MESHMAP=UltimaProtos NUM=1 TEXTURE=Sk_UltimaProtos_01
#exec MESHMAP SETTEXTURE MESHMAP=UltimaProtosR NUM=1 TEXTURE=Sk_UltimaProtos_01
#exec MESHMAP SETTEXTURE MESHMAP=UltimaProtosPick NUM=1 TEXTURE=Sk_UltimaProtos_01
#exec MESHMAP SETTEXTURE MESHMAP=UltimaProtosM NUM=1 TEXTURE=Sk_UltimaProtos_01

#exec TEXTURE IMPORT NAME=Sk_UltimaProtos_02 FILE=SKINS\Sk_UltimaProtos_02.bmp GROUP=Skins FLAGS=2 LODSET=2
#exec MESHMAP SETTEXTURE MESHMAP=UltimaProtos NUM=2 TEXTURE=Sk_UltimaProtos_02
#exec MESHMAP SETTEXTURE MESHMAP=UltimaProtosR NUM=2 TEXTURE=Sk_UltimaProtos_02
#exec MESHMAP SETTEXTURE MESHMAP=UltimaProtosPick NUM=2 TEXTURE=Sk_UltimaProtos_02
#exec MESHMAP SETTEXTURE MESHMAP=UltimaProtosM NUM=2 TEXTURE=Sk_UltimaProtos_02

#exec TEXTURE IMPORT NAME=Sk_UltimaProtos_03 FILE=SKINS\Sk_UltimaProtos_03.bmp GROUP=Skins FLAGS=2 LODSET=2
#exec MESHMAP SETTEXTURE MESHMAP=UltimaProtos NUM=3 TEXTURE=Sk_UltimaProtos_03
#exec MESHMAP SETTEXTURE MESHMAP=UltimaProtosR NUM=3 TEXTURE=Sk_UltimaProtos_03
#exec MESHMAP SETTEXTURE MESHMAP=UltimaProtosPick NUM=3 TEXTURE=Sk_UltimaProtos_03
#exec MESHMAP SETTEXTURE MESHMAP=UltimaProtosM NUM=3 TEXTURE=Sk_UltimaProtos_03

#exec TEXTURE IMPORT NAME=Sk_UltimaProtos_04 FILE=SKINS\Sk_UltimaProtos_04.bmp GROUP=Skins FLAGS=2 LODSET=2
#exec MESHMAP SETTEXTURE MESHMAP=UltimaProtos NUM=4 TEXTURE=Sk_UltimaProtos_04
#exec MESHMAP SETTEXTURE MESHMAP=UltimaProtosR NUM=4 TEXTURE=Sk_UltimaProtos_04
#exec MESHMAP SETTEXTURE MESHMAP=UltimaProtosPick NUM=4 TEXTURE=Sk_UltimaProtos_04
#exec MESHMAP SETTEXTURE MESHMAP=UltimaProtosM NUM=4 TEXTURE=Sk_UltimaProtos_04

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

//Icons
#exec TEXTURE IMPORT NAME=UltimaPIcon FILE=ICONS\UltimaPIcon.bmp GROUP=Icons MIPS=OFF
#exec TEXTURE IMPORT NAME=UltimaScreen FILE=ICONS\UltimaScreen.bmp GROUP=Icons LODSET=0

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

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

//Sounds
#exec AUDIO IMPORT NAME="UltimaP_Fire" FILE=SOUNDS\UltimaP_Fire.wav GROUP="UltimaProtos"
#exec AUDIO IMPORT NAME="UltimaP_Pickup" FILE=SOUNDS\UltimaP_Pickup.wav GROUP="UltimaProtos"
#exec AUDIO IMPORT NAME="UltimaP_Select" FILE=SOUNDS\UltimaP_Select.wav GROUP="UltimaProtos"
#exec AUDIO IMPORT NAME="Ultima_ScreenOn" FILE=SOUNDS\Ultima_ScreenOn.wav GROUP="UltimaProtos"
#exec AUDIO IMPORT NAME="Ultima_ScreenOff" FILE=SOUNDS\Ultima_ScreenOff.wav GROUP="UltimaProtos"

var bool bZoomIn;
var UltimaDistCross Udc;

replication
{
	reliable if (Role == ROLE_Authority && bNetOwner)
		Udc;
}

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

function Fire( float Value )
{

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

    if (AmmoType.UseAmmo(1))
    {
	GotoState('NormalFire');
        bPointing=True;
        bCanClientFire = true;
        ClientFire(Value);
    }
}


simulated function PlayFiring()
{
	PlayOwnedSound(FireSound, SLOT_None, Pawn(Owner).SoundDampening*9.0);
	SpawnAccum();
	SetTimer(2.0, False);
}

function SpawnAccum()
{
local UltimaAccum ua;

	ua = Spawn(Class'UltimaAccum', Pawn(Owner));
	ua.UP = Self;
}


simulated function Timer()
{
local Projectile pj;

	ProjectileFire(ProjectileClass, ProjectileSpeed, bWarnTarget);
	SpawnFireEffect();
	PlayAnim('Fire', 4.0, 0.0);
}

function SpawnFireEffect()
{
local vector X, Y, Z, Start;

	GetAxes(Pawn(Owner).ViewRotation, X, Y, Z);

	Start = Owner.Location + CalcDrawOffset() + FireOffset.X * X + FireOffset.Y * Y + FireOffset.Z * Z;

	Spawn(Class'RingTypeAII',,, Start + 64*X + 16*Z, Pawn(Owner).ViewRotation);
	Spawn(Class'RingTypeAIII',,, Start + 200*X + 16*Z, Pawn(Owner).ViewRotation);
	Spawn(Class'RingTypeAIV',,, Start + 340*X + 16*Z, Pawn(Owner).ViewRotation);
}

simulated function bool ClientAltFire( float Value )
{
	if (!bZoomIn)
		PlayOwnedSound(Sound'Ultima_ScreenOn', SLOT_None, Pawn(Owner).SoundDampening*5.0);
	else
		PlayOwnedSound(Sound'Ultima_ScreenOff', SLOT_None, Pawn(Owner).SoundDampening*5.0);

	GotoState('Zooming');
	return true;
}

function AltFire( float Value )
{
	ClientAltFire(Value);
}



simulated function Tick(float DeltaTime)
{
local Actor LTarget;
local vector StartTrace, EndTrace, HitLocation, HitNormal, X, Y, Z;
local rotator RotAim;

		if (Pawn(Owner) != None)
		{
			if ( Pawn(Owner).bAltFire == 0 )
			{
				if ( PlayerPawn(Owner).Player.IsA('ViewPort') )
					PlayerPawn(Owner).StopZoom();
			}
		}

		if (Udc == None && PlayerPawn(Owner) != None)
		{
			if (PlayerPawn(Owner).DesiredFOV != PlayerPawn(Owner).DefaultFOV)
				Udc = Spawn(Class'UltimaDistCross');
		}
		else if (PlayerPawn(Owner) != None)
		{
			if (Level.NetMode != NM_DedicatedServer && PlayerPawn(Owner).DesiredFOV != PlayerPawn(Owner).DefaultFOV)
			{

				GetAxes(Pawn(Owner).ViewRotation,X,Y,Z);
				StartTrace = Owner.Location + Pawn(Owner).Eyeheight * Z;
				EndTrace = StartTrace + (32000 * X);
				LTarget = Trace( HitLocation, HitNormal, EndTrace, StartTrace, False);

				if (LTarget == None)
				{
					HitLocation = EndTrace;
					HitNormal = vector(PlayerPawn(Owner).ViewRotation);
				}

				if (Udc!=None)
				{
					RotAim = rotator(HitNormal);
					Udc.SetLocation(HitLocation);
					Udc.SetRotation(RotAim);
				}
			}
			else if (PlayerPawn(Owner).DesiredFOV == PlayerPawn(Owner).DefaultFOV && Udc!=None)
			{
				Udc.Destroy();
				Udc = None;
			}
		}
		else if (PlayerPawn(Owner) == None && Udc!=None)
		{
			Udc.Destroy();
			Udc = None;
		}
}


simulated function PostRender( canvas Canvas )
{
	local PlayerPawn P;
	local float Scale, ZoomS;
	local int i;

	P = PlayerPawn(Owner);

	if ( (P != None) && (P.DesiredFOV != P.DefaultFOV) ) 
	{
		bOwnsCrossHair = True;
		Scale = Canvas.ClipX/640;
		Canvas.SetPos(0, 0);

		if (Udc != None)
			Canvas.DrawActor( Udc, False, True);

		Canvas.Style = ERenderStyle.STY_Modulated;
		Canvas.DrawRect(Texture'UltimaScreen', Canvas.ClipX, Canvas.ClipY);

		Canvas.Style = ERenderStyle.STY_Normal;
		Canvas.SetPos(0.5 * Canvas.ClipX, 0.9 * Canvas.ClipY);
		Canvas.DrawColor.R = 255;
		Canvas.DrawColor.G = 0;
		Canvas.DrawColor.B = 0;
		Canvas.Font = Class'IRPR'.default.NeoF;
		ZoomS = P.DefaultFOV/P.DesiredFOV;
		Canvas.DrawText(int(ZoomS)$" . "$int(10 * ZoomS - 10 * int(ZoomS))$"  X");

		bZoomIn = True;

		Super(TournamentWeapon).PostRender(Canvas);
	}
	else
	{
		bZoomIn = False;
		bOwnsCrosshair = class'NaliWeapons'.default.bCustomCrosshair;
		Super.PostRender(Canvas);
	}
	
}


//////////////////////////////////////////////////////////////////////////////////////////////////
state Zooming
{
	simulated function Tick(float DeltaTime)
	{
	local Actor LTarget;
	local vector StartTrace, EndTrace, HitLocation, HitNormal, X, Y, Z;
	local rotator RotAim;

		if ( Pawn(Owner).bAltFire == 0 )
		{
			if ( (PlayerPawn(Owner) != None) && PlayerPawn(Owner).Player.IsA('ViewPort') )
				PlayerPawn(Owner).StopZoom();
			GoToState('Idle');
		}	

		if (Udc == None && PlayerPawn(Owner) != None && PlayerPawn(Owner).DesiredFOV != PlayerPawn(Owner).DefaultFOV)
			Udc = Spawn(Class'UltimaDistCross');
		else if (PlayerPawn(Owner) != None && PlayerPawn(Owner).DesiredFOV != PlayerPawn(Owner).DefaultFOV)
		{
			if (Level.NetMode != NM_DedicatedServer)
			{

				GetAxes(Pawn(Owner).ViewRotation,X,Y,Z);
				StartTrace = Owner.Location + Pawn(Owner).Eyeheight * Z;
				EndTrace = StartTrace + (32000 * X);
				LTarget = Trace( HitLocation, HitNormal, EndTrace, StartTrace, False);

				if (LTarget == None)
				{
					HitLocation = EndTrace;
					HitNormal = vector(PlayerPawn(Owner).ViewRotation);
				}

				RotAim = rotator(HitNormal);
				Udc.SetLocation(HitLocation);
				Udc.SetRotation(RotAim);
			}
		}
		else if (PlayerPawn(Owner) == None || PlayerPawn(Owner).DesiredFOV == PlayerPawn(Owner).DefaultFOV && Udc!=None)
		{
			Udc.Destroy();
			Udc = None;
		}
	}

	simulated function BeginState()
	{
		if ( Owner.IsA('PlayerPawn') )
		{
			if ( PlayerPawn(Owner).Player.IsA('ViewPort') )
				PlayerPawn(Owner).ToggleZoom();
		}
		else
		{
			Pawn(Owner).bFire = 1;
			Pawn(Owner).bAltFire = 0;
			Global.Fire(0);
		}
	}
}


state Idle
{
    function Fire( float Value )
    {
        if ( AmmoType == None )
        {
            // ammocheck
            GiveAmmo(Pawn(Owner));
        }

        if (AmmoType.UseAmmo(1))
        {
            	GotoState('NormalFire');
        	bPointing=True;
        	bCanClientFire = true;
        	ClientFire(Value);
        }
    }


    function BeginState()
    {
        bPointing = false;
        Super.BeginState();
    }
    
Begin:
    bPointing=False;
    if ( AmmoType.AmmoAmount<=0 ) 
        Pawn(Owner).SwitchToBestWeapon();  //Goto Weapon that has Ammo
    if ( Pawn(Owner).bFire!=0 ) Fire(0.0);
    Disable('AnimEnd');
    PlayIdleAnim();
}


defaultproperties
{
	DrawType=DT_Mesh
	Mesh=UltimaProtosPick
	CollisionHeight=20.000000
	CollisionRadius=20.000000
	AutoSwitchPriority=10
	Icon=UltimaPIcon
	InventoryGroup=10
	ItemArticle="an"
	ItemName="UltimaProtos"
	MaxDesireability=4.000000
	PickupMessage="You got the UltimaProtos."
	PickupSound=UltimaP_Pickup
	PickupViewMesh=UltimaProtosPick
	PickupViewScale=1.000000
	PlayerViewMesh=UltimaProtosR
	PlayerViewOffset=(X=30.000000,Y=-31.000000,Z=-18.000000)
	PlayerViewScale=1.000000
	RespawnTime=300.000000
	StatusIcon=UltimaPIcon
	ThirdPersonMesh=UltimaProtosM
	ThirdPersonScale=0.700000
	AltDamageType=None
	AltFireSound=None
	AltProjectileClass=None
	bInstantHit=False
	AmmoName=Class'UltimaPAmmo'
	bRapidFire=False
	DeathMessage="Poor little %o was atomically vaporized by %k's ownage %w."
	FireOffset=(X=0.000000,Y=0.000000,Z=0.000000)
	FireSound=UltimaP_Fire
	FiringSpeed=1.000000
	MaxTargetRange=4096.000000
	MyDamageType=UltimaNuke
	NameColor=(R=32,G=0,B=0)
	PickupAmmoCount=1
	ProjectileClass=Class'UltimaProj'
	SelectSound=UltimaP_Select
	shakemag=0.000000
	shaketime=0.300000
	shakevert=0.000000
	AIRating=2.100000
	AltRefireRate=1.000000
	bAltWarnTarget=False
	bRecommendAltSplashDamage=False
	bRecommendSplashDamage=True
	bSplashDamage=True
	bWarnTarget=False
	RefireRate=1.200000
	Mass=350.000000
	bNoSmooth=False
	bOwnsCrossHair=True
	CustomCross=UltimaPCross
	CrossHairSize=64
	bMegaWeapon=True
}
