RuneI
Class Torch

source: c:\runehov\RuneI\Classes\Torch.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.Inventory
         |
         +--Engine.Weapon
            |
            +--RuneI.NonStow
               |
               +--RuneI.Torch
Direct Known Subclasses:HelTorch

class Torch
extends RuneI.NonStow

//============================================================================= // Torch. //=============================================================================
Variables
 float DouseTime
 int HitCount
           Number of hits before the torch goes out
 Actor TorchFire
 bool bIgnitedAtStartup

States
Active

Function Summary
 void Douse()
 bool FindFire(out vector)
     
//=============================================================================
//
// FindFire
//
// Locates the nearest source of fire for relighting the torch
//
// Checks for particle fire directly in front of the player
//=============================================================================
 name GetLightAnim(Actor Other, vector fireLoc)
     
//=============================================================================
//
// GetLightAnim
//
// Returns the necessary animation (and sets anim blend) for Torch relighting
//=============================================================================
 void Ignite()
     
//=============================================================================
//
// Ignite
//
//=============================================================================
 void InventorySpecial1()
     
//=============================================================================
//
// InventorySpecial1
//
// Generic Inventory function (called from an animation notify)
//
// For the torch, this notify ignites the torch
//=============================================================================
 void PostBeginPlay()
     
//=============================================================================
//
// PostBeginPlay
//
//=============================================================================
 void SpawnHitEffect(vector HitLoc, vector HitNorm, int LowMask, int HighMask, Actor HitActor)
     
//=============================================================================
//
// SpawnHitEffect
//
// Spawns an effect based upon what was struck
//=============================================================================
 void Tick(float DeltaSeconds)
     
//=============================================================================
//
// Douse
//
//=============================================================================
 bool UseTrigger(Actor Other)
     
//=============================================================================
//
// UseTrigger
//
//=============================================================================
 void ZoneChange(ZoneInfo newZone)
     
//=============================================================================
//
// ZoneChange
//
//=============================================================================


State Active Function Summary
 void BeginState()



Source Code


00001	//=============================================================================
00002	// Torch.
00003	//=============================================================================
00004	class Torch expands NonStow;
00005	
00006	
00007	var Actor TorchFire;
00008	var() bool bIgnitedAtStartup;
00009	var float DouseTime;
00010	var() int HitCount; // Number of hits before the torch goes out
00011	var(Sounds) sound IgniteSound;
00012	var(Sounds) sound ExtinguishSound;
00013	
00014	//=============================================================================
00015	//
00016	// Ignite
00017	//
00018	//=============================================================================
00019	function Ignite()
00020	{
00021		if (Region.Zone.bWaterZone)
00022			return;
00023	
00024		// Spawn fire on the torch
00025		TorchFire = Spawn(class'torchfire',,, GetJointPos(JointNamed('offset')),);
00026		PlaySound(IgniteSound, SLOT_Interface);
00027	
00028		// If Torches are stasis, the player can smack a wall and cause the particles to
00029		// "freeze" in space
00030		if(GetStateName() == 'Active')
00031			TorchFire.bStasis = false;
00032		
00033		AttachActorToJoint(TorchFire, JointNamed('offset'));
00034		
00035		SkelGroupSkins[1] = texture'torchtorchburn'; // Flaming torch
00036	
00037		DamageType = 'fire';
00038		bUnlit = true;
00039		ScaleGlow = 2.0;
00040		HitCount = 3.0;
00041		DouseTime = 0.0;
00042	
00043		// Reset weapon anims
00044		A_Idle = Default.A_Idle;
00045	    A_Forward = Default.A_Forward;
00046	    A_Backward = Default.A_Backward;
00047	    A_Backward45Right = Default.A_Backward45Right;
00048	    A_Backward45Left = Default.A_Backward45Left;
00049	    A_StrafeRight = Default.A_StrafeRight;
00050	    A_StrafeLeft = Default.A_StrafeLeft;
00051		A_Forward45Right = Default.A_Forward45Right;
00052		A_Forward45Left = Default.A_Forward45Left;
00053		A_AttackA = Default.A_AttackA;
00054		A_AttackStrafeRight = Default.A_AttackStrafeRight;
00055		A_AttackStrafeLeft = Default.A_AttackStrafeLeft;
00056		A_AttackStandA = Default.A_AttackStandA;
00057		A_AttackStandAReturn = Default.A_AttackStandAReturn;
00058		A_AttackStandB = Default.A_AttackStandB;
00059		A_AttackStandBReturn = Default.A_AttackStandBReturn;
00060		A_AttackBackupA = Default.A_AttackBackupA;
00061		A_AttackBackupAReturn = Default.A_AttackBackupAReturn;
00062		A_Defend = Default.A_Defend;
00063		A_DefendIdle= Default.A_DefendIdle;
00064		A_LeverTrigger = Default.A_LeverTrigger;
00065		A_Taunt = Default.A_Taunt;
00066	
00067	    LightType=LT_Steady;
00068	    LightEffect=LE_None;
00069	    LightBrightness=240;
00070	    LightHue=20;
00071	    LightSaturation=20;
00072	    LightRadius=16;
00073	
00074		// Put light on the torchfire as well, to 2x brighten the torch
00075	    TorchFire.LightType=LT_Steady;
00076	    TorchFire.LightEffect=LE_None;
00077	    TorchFire.LightBrightness=240;
00078	    TorchFire.LightHue=20;
00079	    TorchFire.LightSaturation=20;
00080	    TorchFire.LightRadius=16;
00081	}
00082	
00083	
00084	//=============================================================================
00085	//
00086	// Douse
00087	//
00088	//=============================================================================
00089	
00090	function Tick(float DeltaSeconds)
00091	{
00092		local float adjust;
00093	
00094		if(DouseTime > 0)
00095		{
00096			DouseTime -= DeltaSeconds;
00097			if(DouseTime <= 0)
00098			{
00099				PlaySound(ExtinguishSound, SLOT_Interface);
00100	
00101	//			SkelGroupSkins[1] = None; // Normal torch
00102				bUnlit = false;
00103				ScaleGlow = 0.1; // Burned out torch look
00104				Disable('Tick');
00105				LightType=LT_None;
00106				LightEffect=LE_None;
00107				LightBrightness=0;
00108				LightRadius=0;
00109				A_Idle = 't_outidle';
00110				A_Forward = 'S1_Walk';
00111				A_Backward = 'weapon1_backup';
00112				A_Forward45Right = 'S1_walk45Right';
00113				A_Forward45Left = 'S1_walk45Left';
00114				A_Backward45Right = 'weapon1_backup45Right';
00115				A_Backward45Left = 'weapon1_backup45Left';
00116				A_StrafeRight = 'StrafeRight';
00117				A_StrafeLeft = 'StrafeLeft';
00118				A_Jump = 'MOV_ALL_jump1_AA0S';
00119				A_AttackA = 'weapon1_attackA';
00120				A_AttackStrafeRight = 'S3_StrafeRightAttack';
00121				A_AttackStrafeLeft = 'S3_StrafeLeftAttack';
00122				A_AttackStandA = 'T_OUTStandingAttackA';
00123				A_AttackStandAReturn = 'T_OUTStandingAttackAReturn';
00124				A_AttackStandB = 'None';
00125				A_AttackStandBReturn = 'None';
00126				A_AttackBackupA = 'H3_BackupAttackA';
00127				A_AttackBackupAReturn = 'H3_BackupAttackAReturn';
00128				A_Defend = 'T_OUTDefendTO';
00129				A_DefendIdle= 'T_OUTDefendIdle';
00130				A_LeverTrigger = 'T_OutLeverTrigger';
00131				A_Taunt = 'T_OUTTaunt';
00132			}
00133			else
00134			{
00135				adjust = DouseTime / 4.0; // div by default dousetime
00136				ScaleGlow = 0.5 + 1.5 * adjust; 
00137				LightRadius = 16 * adjust;
00138			}
00139		}
00140	}
00141	
00142	function Douse()
00143	{
00144		local actor fire;
00145	
00146		if (ActorAttachedTo(JointNamed('offset')) != None)
00147		{
00148			DetachActorFromJoint(JointNamed('offset'));
00149			TorchFire.Destroy();
00150			TorchFire = None;
00151			DamageType = 'blunt';
00152	//		SkelGroupSkins[1] = None; // Normal torch
00153	//		bUnlit = false;
00154	//		ScaleGlow = 1.0;
00155			DouseTime = 4.0;
00156			Enable('Tick');
00157		}
00158	}
00159	
00160	
00161	//=============================================================================
00162	//
00163	// PostBeginPlay
00164	//
00165	//=============================================================================
00166	function PostBeginPlay()
00167	{
00168		Super.PostBeginPlay();
00169		if (bIgnitedAtStartup)
00170			Ignite();
00171	}
00172	
00173	//=============================================================================
00174	//
00175	// FindFire
00176	//
00177	// Locates the nearest source of fire for relighting the torch
00178	//
00179	// Checks for particle fire directly in front of the player
00180	//=============================================================================
00181	
00182	function bool FindFire(out vector fireLoc)
00183	{
00184		local Fire F;
00185		local vector v1, v2;
00186		local float dp;
00187	
00188		foreach Owner.RadiusActors(class'fire', F, 100, Owner.Location)
00189		{
00190			fireLoc = F.Location;
00191			return(true);
00192		}
00193		
00194		return(false);
00195	}
00196	
00197	//=============================================================================
00198	//
00199	// GetLightAnim
00200	//
00201	// Returns the necessary animation (and sets anim blend) for Torch relighting
00202	//=============================================================================
00203	
00204	function name GetLightAnim(Actor Other, vector fireLoc)
00205	{
00206		local float deltaZ;
00207		local name anim;
00208	
00209		if(Owner == None)
00210			return('T_Lite');
00211		
00212		deltaZ = (fireLoc.Z - Owner.Location.Z);
00213	
00214		if(deltaZ <= -35)
00215		{ // On the ground, no blend
00216			return('T_LightLow');
00217		}
00218		else if(deltaZ >= 65)
00219		{ // Overhead, no blend
00220			return('T_Lite');
00221		}
00222		else
00223		{ // Blend to fit the desired pickup location
00224			if(deltaZ < 35)
00225			{
00226				Owner.BlendAnimSequence = 'T_LightLow';
00227				Owner.BlendAnimAlpha = -(deltaZ - 35) / 70;
00228			}
00229			else
00230			{
00231				Owner.BlendAnimSequence = 'T_Lite';
00232				Owner.BlendAnimAlpha = (deltaZ - 35) / 30;
00233			}
00234	
00235			if(Owner.AnimProxy != None)
00236			{
00237				Owner.AnimProxy.BlendAnimSequence = Owner.BlendAnimSequence;
00238				Owner.AnimProxy.BlendAnimAlpha = Owner.BlendAnimAlpha;
00239			}
00240			
00241			return('T_LightMed'); // return medium, mid ranges are blended
00242		}
00243	}
00244	
00245	//=============================================================================
00246	//
00247	// UseTrigger
00248	//
00249	//=============================================================================
00250	
00251	function bool UseTrigger(Actor Other)
00252	{
00253		local RunePlayer p;
00254		local vector v;
00255		local vector fireLoc;
00256		
00257		if(Other == Owner && TorchFire == None)
00258		{
00259			if(Owner.IsA('RunePlayer') && Owner.Physics == PHYS_Walking
00260				&& (Owner.Velocity.X * Owner.Velocity.X + Owner.Velocity.Y * Owner.Velocity.Y < 1000)
00261				&& FindFire(fireLoc))
00262			{ // Only allow the ignite if standing still
00263				p = RunePlayer(Owner);
00264				p.PlayUninterruptedAnim(GetLightAnim(Other, fireLoc));		
00265				return true;
00266			}
00267			else
00268			{
00269				return false;
00270			}
00271		}
00272		return false;
00273	}
00274	
00275	//=============================================================================
00276	//
00277	// InventorySpecial1
00278	//
00279	// Generic Inventory function (called from an animation notify)
00280	//
00281	// For the torch, this notify ignites the torch
00282	//=============================================================================
00283	
00284	function InventorySpecial1()
00285	{
00286		Ignite();
00287	}
00288	
00289	//=============================================================================
00290	//
00291	// ZoneChange
00292	//
00293	//=============================================================================
00294	function ZoneChange(ZoneInfo newZone)
00295	{
00296		if ( newZone.bWaterZone )
00297		{
00298			Douse();
00299		}
00300	}
00301	
00302	
00303	//=============================================================================
00304	//
00305	// SpawnHitEffect
00306	//
00307	// Spawns an effect based upon what was struck
00308	//=============================================================================
00309	function SpawnHitEffect(vector HitLoc, vector HitNorm, int LowMask, int HighMask, Actor HitActor)
00310	{	
00311		local int i,j;
00312		local EMatterType matter;
00313	
00314		// Determine what kind of matter was hit
00315		if ((HitActor.Skeletal != None) && (LowMask!=0 || HighMask!=0))
00316		{
00317			for (j=0; j<HitActor.NumJoints(); j++)
00318			{
00319				if (((j <  32) && ((LowMask  & (1 <<  j      )) != 0)) ||
00320					((j >= 32) && (j < 64) && ((HighMask & (1 << (j - 32))) != 0)) )
00321				{	// Joint j was hit
00322					matter = HitActor.MatterForJoint(j);
00323					break;
00324				}
00325			}
00326		}
00327		else if(HitActor.IsA('LevelInfo') && TorchFire != None)
00328		{ // Leave a char mark on the wall if the torch is lit
00329			matter = HitActor.MatterTrace(HitLoc, Owner.Location, WeaponSweepExtent);
00330			Spawn(class'DecalChar',,,, rotator(HitNorm));
00331		}
00332		else
00333		{
00334			matter = HitActor.MatterForJoint(0);
00335		}
00336	
00337		// Create effects
00338		PlayHitMatterSound(matter);
00339	
00340		if (matter != MATTER_NONE)
00341		{
00342			HitNorm.Z += 0.65;
00343			Spawn(class'Sparks',,, HitLoc, rotator(HitNorm));
00344		}
00345	
00346		if(TorchFire != None)
00347		{
00348			HitCount--;
00349			if(HitCount <= 0)
00350			{
00351				Douse();
00352			}
00353		}	
00354	}
00355	
00356	state Active
00357	{
00358		function BeginState()
00359		{
00360			Super.BeginState();
00361	
00362			// If Torches are stasis, the player can smack a wall and cause the particles to
00363			// "freeze" in space
00364			if(TorchFire != None)
00365				TorchFire.bStasis = false;
00366		}
00367	}
00368	
00369	defaultproperties
00370	{
00371	     bIgnitedAtStartup=True
00372	     HitCount=3
00373	     IgniteSound=Sound'EnvironmentalSnd.Fire.fireignite01'
00374	     ExtinguishSound=Sound'EnvironmentalSnd.Fire.fireignite07'
00375	     Damage=10
00376	     DamageType=Blunt
00377	     rating=1
00378	     ThroughAir(0)=Sound'EnvironmentalSnd.Fire.fireignite09'
00379	     ThroughAir(1)=Sound'EnvironmentalSnd.Fire.fireignite03'
00380	     ThroughAir(2)=Sound'EnvironmentalSnd.Fire.fireignite09'
00381	     HitFlesh(0)=Sound'EnvironmentalSnd.Fire.fireignite04'
00382	     HitWood(0)=Sound'EnvironmentalSnd.Fire.fireignite04'
00383	     HitStone(0)=Sound'EnvironmentalSnd.Fire.fireignite04'
00384	     HitMetal(0)=Sound'EnvironmentalSnd.Fire.fireignite04'
00385	     HitDirt(0)=Sound'EnvironmentalSnd.Fire.fireignite04'
00386	     HitShield=Sound'EnvironmentalSnd.Fire.fireignite04'
00387	     HitWeapon=Sound'EnvironmentalSnd.Fire.fireignite04'
00388	     HitBreakableWood=Sound'EnvironmentalSnd.Fire.fireignite04'
00389	     HitBreakableStone=Sound'EnvironmentalSnd.Fire.fireignite04'
00390	     A_Idle=T_Idle
00391	     A_Forward=T_Walk
00392	     A_Backward=T_backup
00393	     A_Forward45Right=T_walk45right
00394	     A_Forward45Left=T_walk45left
00395	     A_Backward45Right=T_backup45Right
00396	     A_Backward45Left=T_backup45Left
00397	     A_StrafeRight=T_StrafeRight
00398	     A_StrafeLeft=T_StrafeLeft
00399	     A_AttackA=T_AttackA
00400	     A_AttackAReturn=T_AttackAreturn
00401	     A_AttackB=T_AttackB
00402	     A_AttackBReturn=T_AttackBreturn
00403	     A_AttackStandA=T_Standingattack
00404	     A_AttackStandAReturn=None
00405	     A_AttackBackupA=T_BackupAttack
00406	     A_AttackBackupAReturn=None
00407	     A_AttackStrafeRight=T_Standingattack
00408	     A_AttackStrafeLeft=T_Standingattack
00409	     A_Defend=T_DefendTo
00410	     A_DefendIdle=T_Defendidle
00411	     A_Taunt=T_Taunt
00412	     A_LeverTrigger=T_LeverTrigger
00413	     bExpireWhenTossed=False
00414	     PickupMessage="You wield a torch"
00415	     DropSound=Sound'EnvironmentalSnd.Fire.torchdrop'
00416	     SoundRadius=11
00417	     CollisionHeight=3.000000
00418	     Buoyancy=2.500000
00419	     Skeletal=SkelModel'objects.Torch'
00420	}

End Source Code