Botpack
Class TournamentWeapon

source: e:\games\UnrealTournament\Botpack\Classes\TournamentWeapon.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.Inventory
         |
         +--Engine.Weapon
            |
            +--Botpack.TournamentWeapon
Direct Known Subclasses:ChainSaw, Enforcer, ImpactHammer, Minigun2, PulseGun, Ripper, ShockRifle, SniperRifle, Translocator, UT_BioRifle, UT_Eightball, UT_FlakCannon, WarHeadLauncher

class TournamentWeapon
extends Engine.Weapon

//============================================================================= // TournamentWeapon. //=============================================================================
Variables
 TournamentPickup Affector
 FireTime, AltFireTime
           used to synch server and client firing up
 float FireAdjust
 float FireStartTime
           used to synch server and client firing up
 float InstFlash
 vector InstFog
 string WeaponDescription
 bool bCanClientFire
 bForceFire, bForceAltFire

States
DownWeapon, ClientDown, ClientActive, Active, AltFiring, NormalFire, ClientAltFiring, ClientFiring, Pickup

Function Summary
 void AltFire(float Value)
 
simulated
AnimEnd()
 void BecomeItem()
 bool ClientAltFire(float Value)
 bool ClientFire(float Value)
 
simulated
ClientPutDown(Weapon NextWeapon)
 void DropFrom(vector StartLocation)
     
//
// Toss this item out.
//
 void Finish()
     
// Finish a firing sequence
 void Fire(float Value)
 void ForceAltFire()
 
simulated
ForceClientAltFire()
 
simulated
ForceClientFire()
 void ForceFire()
 bool HandlePickupQuery(Inventory Item)
 
simulated
Landed(vector HitNormal)
 
simulated
PlayIdleAnim()
 
simulated
PlayPostSelect()
 
simulated
PlaySelect()
 void SetWeaponStay()
 
simulated
TweenDown()
 
simulated
TweenToStill()


State DownWeapon Function Summary
 void BeginState()


State ClientDown Function Summary
 bool ClientAltFire(float Value)
 bool ClientFire(float Value)


State ClientActive Function Summary
 bool ClientAltFire(float Value)
 bool ClientFire(float Value)


State Active Function Summary
 void EndState()
 void ForceAltFire()
 void ForceFire()


State AltFiring Function Summary
 void AnimEnd()
 void ForceAltFire()
 void ForceFire()
 void AltFire(float F)
 void Fire(float F)


State NormalFire Function Summary
 void AnimEnd()
 void AltFire(float F)
 void Fire(float F)
 void ForceAltFire()
 void ForceFire()


State ClientAltFiring Function Summary
 bool ClientAltFire(float Value)
 bool ClientFire(float Value)


State ClientFiring Function Summary
 bool ClientAltFire(float Value)
 bool ClientFire(float Value)


State Pickup Function Summary



Source Code


00001	//=============================================================================
00002	// TournamentWeapon.
00003	//=============================================================================
00004	class TournamentWeapon extends Weapon
00005		abstract;
00006	
00007	var TournamentPickup Affector;
00008	var float FireAdjust;
00009	var localized string WeaponDescription;
00010	var float InstFlash;
00011	var vector InstFog;
00012	var bool bCanClientFire;
00013	var bool bForceFire, bForceAltFire;
00014	var() float FireTime, AltFireTime; //used to synch server and client firing up
00015	var float FireStartTime;
00016	
00017	Replication
00018	{
00019		Reliable if ( bNetOwner && (Role == ROLE_Authority) )
00020			Affector, bCanClientFire;
00021	}
00022	
00023	function ForceFire()
00024	{
00025		Fire(0);
00026	}
00027	
00028	function ForceAltFire()
00029	{
00030		AltFire(0);
00031	}
00032	
00033	function SetWeaponStay()
00034	{
00035		if ( Level.NetMode != NM_Standalone && Level.Game.IsA('DeathMatchPlus') )
00036			bWeaponStay = bWeaponStay || DeathMatchPlus(Level.Game).bMultiWeaponStay;
00037		else		
00038			bWeaponStay = bWeaponStay || Level.Game.bCoopWeaponMode;
00039	}
00040	
00041	// Finish a firing sequence
00042	function Finish()
00043	{
00044		local Pawn PawnOwner;
00045		local bool bForce, bForceAlt;
00046	
00047		bForce = bForceFire;
00048		bForceAlt = bForceAltFire;
00049		bForceFire = false;
00050		bForceAltFire = false;
00051	
00052		if ( bChangeWeapon )
00053		{
00054			GotoState('DownWeapon');
00055			return;
00056		}
00057	
00058		PawnOwner = Pawn(Owner);
00059		if ( PawnOwner == None )
00060			return;
00061		if ( PlayerPawn(Owner) == None )
00062		{
00063			if ( (AmmoType != None) && (AmmoType.AmmoAmount<=0) )
00064			{
00065				PawnOwner.StopFiring();
00066				PawnOwner.SwitchToBestWeapon();
00067				if ( bChangeWeapon )
00068					GotoState('DownWeapon');
00069			}
00070			else if ( (PawnOwner.bFire != 0) && (FRand() < RefireRate) )
00071				Global.Fire(0);
00072			else if ( (PawnOwner.bAltFire != 0) && (FRand() < AltRefireRate) )
00073				Global.AltFire(0);	
00074			else 
00075			{
00076				PawnOwner.StopFiring();
00077				GotoState('Idle');
00078			}
00079			return;
00080		}
00081		if ( ((AmmoType != None) && (AmmoType.AmmoAmount<=0)) || (PawnOwner.Weapon != self) )
00082			GotoState('Idle');
00083		else if ( (PawnOwner.bFire!=0) || bForce )
00084			Global.Fire(0);
00085		else if ( (PawnOwner.bAltFire!=0) || bForceAlt )
00086			Global.AltFire(0);
00087		else 
00088			GotoState('Idle');
00089	}
00090	
00091	//
00092	// Toss this item out.
00093	//
00094	function DropFrom(vector StartLocation)
00095	{
00096		bCanClientFire = false;
00097		bSimFall = true;
00098		SimAnim.X = 0;
00099		SimAnim.Y = 0;
00100		SimAnim.Z = 0;
00101		SimAnim.W = 0;
00102		if ( !SetLocation(StartLocation) )
00103			return; 
00104		AIRating = Default.AIRating;
00105		bMuzzleFlash = 0;
00106		if ( AmmoType != None )
00107		{
00108			PickupAmmoCount = AmmoType.AmmoAmount;
00109			AmmoType.AmmoAmount = 0;
00110		}
00111		RespawnTime = 0.0; //don't respawn
00112		SetPhysics(PHYS_Falling);
00113		RemoteRole = ROLE_DumbProxy;
00114		BecomePickup();
00115		NetPriority = 2.5;
00116		bCollideWorld = true;
00117		if ( Pawn(Owner) != None )
00118			Pawn(Owner).DeleteInventory(self);
00119		Inventory = None;
00120		GotoState('PickUp', 'Dropped');
00121	}
00122	
00123	simulated function ClientPutDown(weapon NextWeapon)
00124	{
00125		if ( Level.NetMode == NM_Client )
00126		{
00127			bCanClientFire = false;
00128			bMuzzleFlash = 0;
00129			TweenDown();
00130			if ( TournamentPlayer(Owner) != None )
00131				TournamentPlayer(Owner).ClientPending = NextWeapon;
00132			GotoState('ClientDown');
00133		}
00134	}
00135	
00136	simulated function TweenToStill()
00137	{
00138		TweenAnim('Still', 0.1);
00139	}
00140	
00141	function BecomeItem()
00142	{
00143		local Bot B;
00144		local Pawn P;
00145	
00146		Super.BecomeItem();
00147		B = Bot(Instigator);
00148		if ( (B != None) && B.bNovice && (B.Skill < 2) )
00149			FireAdjust = B.Skill * 0.5;
00150		else
00151			FireAdjust = 1.0;
00152	
00153		if ( (B != None) || Level.Game.bTeamGame || !Level.Game.IsA('DeathMatchPlus')
00154			|| DeathMatchPlus(Level.Game).bNoviceMode
00155			|| (DeathMatchPlus(Level.Game).NumBots > 4) )
00156			return;
00157	
00158		// let high skill bots hear pickup if close enough
00159		for ( P=Level.PawnList; P!=None; P=P.NextPawn )
00160		{
00161			B = Bot(p);
00162			if ( (B != None)
00163				&& (VSize(B.Location - Instigator.Location) < 800 + 100 * B.Skill) )
00164			{
00165				B.HearPickup(Instigator);
00166				return;
00167			}
00168		}
00169	}
00170	
00171	simulated function AnimEnd()
00172	{
00173		if ( (Level.NetMode == NM_Client) && (Mesh != PickupViewMesh) )
00174			PlayIdleAnim();
00175	}
00176	
00177	simulated function ForceClientFire()
00178	{
00179		ClientFire(0);
00180	}
00181	
00182	simulated function ForceClientAltFire()
00183	{
00184		ClientAltFire(0);
00185	}
00186	
00187	simulated function bool ClientFire( float Value )
00188	{
00189		if ( bCanClientFire && ((Role == ROLE_Authority) || (AmmoType == None) || (AmmoType.AmmoAmount > 0)) )
00190		{
00191			if ( (PlayerPawn(Owner) != None) 
00192				&& ((Level.NetMode == NM_Standalone) || PlayerPawn(Owner).Player.IsA('ViewPort')) )
00193			{
00194				if ( InstFlash != 0.0 )
00195					PlayerPawn(Owner).ClientInstantFlash( InstFlash, InstFog);
00196				PlayerPawn(Owner).ShakeView(ShakeTime, ShakeMag, ShakeVert);
00197			}
00198			if ( Affector != None )
00199				Affector.FireEffect();
00200			PlayFiring();
00201			if ( Role < ROLE_Authority )
00202				GotoState('ClientFiring');
00203			return true;
00204		}
00205		return false;
00206	}		
00207	
00208	function Fire( float Value )
00209	{
00210		if ( (AmmoType == None) && (AmmoName != None) )
00211		{
00212			// ammocheck
00213			GiveAmmo(Pawn(Owner));
00214		}
00215		if ( AmmoType.UseAmmo(1) )
00216		{
00217			GotoState('NormalFire');
00218			bPointing=True;
00219			bCanClientFire = true;
00220			ClientFire(Value);
00221			if ( bRapidFire || (FiringSpeed > 0) )
00222				Pawn(Owner).PlayRecoil(FiringSpeed);
00223			if ( bInstantHit )
00224				TraceFire(0.0);
00225			else
00226				ProjectileFire(ProjectileClass, ProjectileSpeed, bWarnTarget);
00227		}
00228	}
00229	
00230	simulated function bool ClientAltFire( float Value )
00231	{
00232		if ( bCanClientFire && ((Role == ROLE_Authority) || (AmmoType == None) || (AmmoType.AmmoAmount > 0)) )
00233		{
00234			if ( (PlayerPawn(Owner) != None) 
00235				&& ((Level.NetMode == NM_Standalone) || PlayerPawn(Owner).Player.IsA('ViewPort')) )
00236			{
00237				if ( InstFlash != 0.0 )
00238					PlayerPawn(Owner).ClientInstantFlash( InstFlash, InstFog);
00239				PlayerPawn(Owner).ShakeView(ShakeTime, ShakeMag, ShakeVert);
00240			}
00241			if ( Affector != None )
00242				Affector.FireEffect();
00243			PlayAltFiring();
00244			if ( Role < ROLE_Authority )
00245				GotoState('ClientAltFiring');
00246			return true;
00247		}
00248		return false;
00249	}
00250	
00251	function AltFire( float Value )
00252	{
00253		if ( (AmmoType == None) && (AmmoName != None) )
00254		{
00255			// ammocheck
00256			GiveAmmo(Pawn(Owner));
00257		}
00258		if (AmmoType.UseAmmo(1))
00259		{
00260			GotoState('AltFiring');
00261			bPointing=True;
00262			bCanClientFire = true;
00263			ClientAltFire(Value);
00264			if ( bRapidFire || (FiringSpeed > 0) )
00265				Pawn(Owner).PlayRecoil(FiringSpeed);
00266			if ( bAltInstantHit )
00267				TraceFire(0.0);
00268			else
00269				ProjectileFire(AltProjectileClass, AltProjectileSpeed, bAltWarnTarget);
00270		}
00271	}
00272	
00273	
00274	simulated function PlaySelect()
00275	{
00276		bForceFire = false;
00277		bForceAltFire = false;
00278		bCanClientFire = false;
00279		if ( !IsAnimating() || (AnimSequence != 'Select') )
00280			PlayAnim('Select',1.0,0.0);
00281		Owner.PlaySound(SelectSound, SLOT_Misc, Pawn(Owner).SoundDampening);	
00282	}
00283	
00284	simulated function PlayPostSelect()
00285	{
00286		if ( Level.NetMode == NM_Client )
00287		{
00288			if ( (bForceFire || (PlayerPawn(Owner).bFire != 0)) && Global.ClientFire(0) )
00289				return;
00290			else if ( (bForceAltFire || (PlayerPawn(Owner).bAltFire != 0)) && Global.ClientAltFire(0) )
00291				return;
00292			GotoState('');
00293			AnimEnd();
00294		}
00295	}
00296	
00297	simulated function TweenDown()
00298	{
00299		if ( IsAnimating() && (AnimSequence != '') && (GetAnimGroup(AnimSequence) == 'Select') )
00300			TweenAnim( AnimSequence, AnimFrame * 0.4 );
00301		else
00302			PlayAnim('Down', 1.0, 0.05);
00303	}
00304	
00305	simulated function PlayIdleAnim()
00306	{
00307	}
00308	
00309	simulated function Landed(vector HitNormal)
00310	{
00311		local rotator newRot;
00312	
00313		newRot = Rotation;
00314		newRot.pitch = 0;
00315		SetRotation(newRot);
00316	}
00317	
00318	function bool HandlePickupQuery( inventory Item )
00319	{
00320		local int OldAmmo;
00321		local Pawn P;
00322	
00323		if (Item.Class == Class)
00324		{
00325			if ( Weapon(item).bWeaponStay && (!Weapon(item).bHeldItem || Weapon(item).bTossedOut) )
00326				return true;
00327			P = Pawn(Owner);
00328			if ( AmmoType != None )
00329			{
00330				OldAmmo = AmmoType.AmmoAmount;
00331				if ( AmmoType.AddAmmo(Weapon(Item).PickupAmmoCount) && (OldAmmo == 0) 
00332					&& (P.Weapon.class != item.class) && !P.bNeverSwitchOnPickup )
00333						WeaponSet(P);
00334			}
00335			P.ReceiveLocalizedMessage( class'PickupMessagePlus', 0, None, None, Self.Class );
00336			Item.PlaySound(Item.PickupSound);
00337			if (Level.Game.LocalLog != None)
00338				Level.Game.LocalLog.LogPickup(Item, Pawn(Owner));
00339			if (Level.Game.WorldLog != None)
00340				Level.Game.WorldLog.LogPickup(Item, Pawn(Owner));
00341			Item.SetRespawn();   
00342			return true;
00343		}
00344		if ( Inventory == None )
00345			return false;
00346	
00347		return Inventory.HandlePickupQuery(Item);
00348	}
00349	
00350	auto state Pickup
00351	{
00352		ignores AnimEnd;
00353	
00354		// Landed on ground.
00355		simulated function Landed(Vector HitNormal)
00356		{
00357			local rotator newRot;
00358	
00359			newRot = Rotation;
00360			newRot.pitch = 0;
00361			SetRotation(newRot);
00362			if ( Role == ROLE_Authority )
00363			{
00364				bSimFall = false;
00365				SetTimer(2.0, false);
00366			}
00367		}
00368	}
00369	
00370	state ClientFiring
00371	{
00372		simulated function bool ClientFire(float Value)
00373		{
00374			return false;
00375		}
00376	
00377		simulated function bool ClientAltFire(float Value)
00378		{
00379			return false;
00380		}
00381	
00382		simulated function AnimEnd()
00383		{
00384			if ( (Pawn(Owner) == None)
00385				|| ((AmmoType != None) && (AmmoType.AmmoAmount <= 0)) )
00386			{
00387				PlayIdleAnim();
00388				GotoState('');
00389			}
00390			else if ( !bCanClientFire )
00391				GotoState('');
00392			else if ( Pawn(Owner).bFire != 0 )
00393				Global.ClientFire(0);
00394			else if ( Pawn(Owner).bAltFire != 0 )
00395				Global.ClientAltFire(0);
00396			else
00397			{
00398				PlayIdleAnim();
00399				GotoState('');
00400			}
00401		}
00402	
00403		simulated function EndState()
00404		{
00405			AmbientSound = None;
00406		}
00407	}
00408	
00409	state ClientAltFiring
00410	{
00411		simulated function bool ClientFire(float Value)
00412		{
00413			return false;
00414		}
00415	
00416		simulated function bool ClientAltFire(float Value)
00417		{
00418			return false;
00419		}
00420		simulated function AnimEnd()
00421		{
00422			if ( (Pawn(Owner) == None)
00423				|| ((AmmoType != None) && (AmmoType.AmmoAmount <= 0)) )
00424			{
00425				PlayIdleAnim();
00426				GotoState('');
00427			}
00428			else if ( !bCanClientFire )
00429				GotoState('');
00430			else if ( Pawn(Owner).bFire != 0 )
00431				Global.ClientFire(0);
00432			else if ( Pawn(Owner).bAltFire != 0 )
00433				Global.ClientAltFire(0);
00434			else
00435			{
00436				PlayIdleAnim();
00437				GotoState('');
00438			}
00439		}
00440	
00441		simulated function EndState()
00442		{
00443			AmbientSound = None;
00444		}
00445	}
00446	
00447	///////////////////////////////////////////////////////
00448	state NormalFire
00449	{
00450		function ForceFire()
00451		{
00452			bForceFire = true;
00453		}
00454	
00455		function ForceAltFire()
00456		{
00457			bForceAltFire = true;
00458		}
00459	
00460		function Fire(float F) 
00461		{
00462		}
00463		function AltFire(float F) 
00464		{
00465		}
00466	
00467		function AnimEnd()
00468		{
00469			Finish();
00470		}
00471	
00472	Begin:
00473		Sleep(0.0);
00474	}
00475	
00476	////////////////////////////////////////////////////////
00477	state AltFiring
00478	{
00479		function Fire(float F) 
00480		{
00481		}
00482	
00483		function AltFire(float F) 
00484		{
00485		}
00486	
00487		function ForceFire()
00488		{
00489			bForceFire = true;
00490		}
00491	
00492		function ForceAltFire()
00493		{
00494			bForceAltFire = true;
00495		}
00496	
00497		function AnimEnd()
00498		{
00499			Finish();
00500		}
00501	
00502	Begin:
00503		Sleep(0.0);
00504	}
00505	
00506	state Active
00507	{
00508		ignores animend;
00509	
00510		function ForceFire()
00511		{
00512			bForceFire = true;
00513		}
00514	
00515		function ForceAltFire()
00516		{
00517			bForceAltFire = true;
00518		}
00519	
00520		function EndState()
00521		{
00522			Super.EndState();
00523			bForceFire = false;
00524			bForceAltFire = false;
00525		}
00526	
00527	Begin:
00528		FinishAnim();
00529		if ( bChangeWeapon )
00530			GotoState('DownWeapon');
00531		bWeaponUp = True;
00532		PlayPostSelect();
00533		FinishAnim();
00534		bCanClientFire = true;
00535		
00536		if ( (Level.Netmode != NM_Standalone) && Owner.IsA('TournamentPlayer')
00537			&& (PlayerPawn(Owner).Player != None)
00538			&& !PlayerPawn(Owner).Player.IsA('ViewPort') )
00539		{
00540			if ( bForceFire || (Pawn(Owner).bFire != 0) )
00541				TournamentPlayer(Owner).SendFire(self);
00542			else if ( bForceAltFire || (Pawn(Owner).bAltFire != 0) )
00543				TournamentPlayer(Owner).SendAltFire(self);
00544			else if ( !bChangeWeapon )
00545				TournamentPlayer(Owner).UpdateRealWeapon(self);
00546		} 
00547		Finish();
00548	}
00549	
00550	State ClientActive
00551	{
00552		simulated function ForceClientFire()
00553		{
00554			Global.ClientFire(0);
00555		}
00556	
00557		simulated function ForceClientAltFire()
00558		{
00559			Global.ClientAltFire(0);
00560		}
00561	
00562		simulated function bool ClientFire(float Value)
00563		{
00564			bForceFire = true;
00565			return bForceFire;
00566		}
00567	
00568		simulated function bool ClientAltFire(float Value)
00569		{
00570			bForceAltFire = true;
00571			return bForceAltFire;
00572		}
00573	
00574		simulated function AnimEnd()
00575		{
00576			if ( Owner == None )
00577			{
00578				Global.AnimEnd();
00579				GotoState('');
00580			}
00581			else if ( Owner.IsA('TournamentPlayer') 
00582				&& (TournamentPlayer(Owner).ClientPending != None) )
00583				GotoState('ClientDown');
00584			else if ( bWeaponUp )
00585			{
00586				if ( (bForceFire || (PlayerPawn(Owner).bFire != 0)) && Global.ClientFire(0) )
00587					return;
00588				else if ( (bForceAltFire || (PlayerPawn(Owner).bAltFire != 0)) && Global.ClientAltFire(0) )
00589					return;
00590				PlayIdleAnim();
00591				GotoState('');
00592			}
00593			else
00594			{
00595				PlayPostSelect();
00596				bWeaponUp = true;
00597			}
00598		}
00599	
00600		simulated function BeginState()
00601		{
00602			bForceFire = false;
00603			bForceAltFire = false;
00604			bWeaponUp = false;
00605			PlaySelect();
00606		}
00607	
00608		simulated function EndState()
00609		{
00610			bForceFire = false;
00611			bForceAltFire = false;
00612		}
00613	}
00614	
00615	State ClientDown
00616	{
00617		simulated function ForceClientFire()
00618		{
00619			Global.ClientFire(0);
00620		}
00621	
00622		simulated function ForceClientAltFire()
00623		{
00624			Global.ClientAltFire(0);
00625		}
00626	
00627		simulated function bool ClientFire(float Value)
00628		{
00629			return false;
00630		}
00631	
00632		simulated function bool ClientAltFire(float Value)
00633		{
00634			return false;
00635		}
00636	
00637		simulated function Tick(float DeltaTime)
00638		{
00639			local TournamentPlayer T;
00640	
00641			T = TournamentPlayer(Owner);
00642			if ( !T.bNeedActivate || ((T.Weapon != self) && (T.Weapon != None)) )
00643				GotoState('');
00644		}
00645			
00646		simulated function AnimEnd()
00647		{
00648			local TournamentPlayer T;
00649	
00650			T = TournamentPlayer(Owner);
00651			if ( T != None )
00652			{
00653				if ( (T.ClientPending != None) 
00654					&& (T.ClientPending.Owner == Owner) )
00655				{
00656					T.Weapon = T.ClientPending;
00657					T.Weapon.GotoState('ClientActive');
00658					T.ClientPending = None;
00659					GotoState('');
00660				}
00661				else
00662				{
00663					Enable('Tick');
00664					T.NeedActivate();
00665				}
00666			}
00667		}
00668	
00669		simulated function BeginState()
00670		{
00671			Disable('Tick');
00672		}
00673	}
00674	
00675	State DownWeapon
00676	{
00677	ignores Fire, AltFire, AnimEnd;
00678	
00679		function BeginState()
00680		{
00681			Super.BeginState();
00682			bCanClientFire = false;
00683		}
00684	}
00685	
00686	defaultproperties
00687	{
00688	     FireAdjust=1.000000
00689	     MyDamageType=Unspecified
00690	     AltDamageType=Unspecified
00691	     PickupMessageClass=Class'Botpack.PickupMessagePlus'
00692	     bClientAnim=True
00693	}

End Source Code