Advertisement
Guest User

Cloak.uc

a guest
Mar 31st, 2018
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // Cloak.uc
  3. // $Author: Deb $
  4. // $Date: 4/23/99 12:13p $
  5. // $Revision: 1 $
  6. //=============================================================================
  7. class Cloak expands Pickup;
  8.  
  9. #exec TEXTURE IMPORT NAME=I_Cloak FILE=TEXTURES\CLOAK\i_invisi.PCX GROUP="Icons"  MIPS=OFF
  10. #exec TEXTURE IMPORT NAME=CloakTexture FILE=TEXTURES\CLOAK\CloakTexture.PCX GROUP="CloakTex"
  11.  
  12. #forceexec AUDIO IMPORT FILE="Sounds\Cloak\CloakOn.WAV" NAME="CloakOn" GROUP="CloakSounds"
  13. #forceexec AUDIO IMPORT FILE="Sounds\Cloak\CloakOff.WAV" NAME="CloakOff" GROUP="CloakSounds"
  14. #forceexec AUDIO IMPORT FILE="Sounds\Cloak\CloakLoop2.WAV" NAME="CloakLoop2" GROUP="CloakSounds"
  15. #forceexec AUDIO IMPORT FILE="Sounds\Cloak\CloakLoop3.WAV" NAME="CloakLoop3" GROUP="CloakSounds"
  16. #forceexec AUDIO IMPORT FILE="Sounds\Cloak\CloakLoop1a.WAV" NAME="CloakLoop1a" GROUP="CloakSounds"
  17. #forceexec AUDIO IMPORT FILE="Sounds\Cloak\CloakLoop1b.WAV" NAME="CloakLoop1b" GROUP="CloakSounds"
  18. // add fade-in effect for respawning?
  19.  
  20. var Weapon LastWeapon;          // Last Weapon wielded by owner
  21. var int CountDown;              // Used in timing the "back to visible" routine
  22. var rotator LastOwnerRotation;  // Used in checking owner's rotation vs last rotation
  23. var bool bExpanding, bEngaging; // Used in going invis routines (tick)
  24. var bool bEngagingCompleted;    // Used in Timer
  25. var float OwnerFatnessDelta;    // Used in going invis routines (tick)
  26. var Weapon InvisWeaponList[25]; // Array holding all affected weapons
  27. var int ArrayCounter;           // Counter for array
  28. var Actor EffectsActor;         // Actor that plays sound when the cloaking device is active
  29. var() float JumpZAdjustment;
  30. var() float AirControlAdjustment;
  31.  
  32. function PostBeginPlay()
  33. {
  34.     if (JumpZAdjustment <= 1)
  35.         JumpZAdjustment = 1.5;
  36. }
  37.  
  38. event float BotDesireability(Pawn Bot)
  39. {
  40.     local Cloak AlreadyHas;
  41.  
  42.     AlreadyHas = Cloak(Bot.FindInventoryType(class));
  43.     if (AlreadyHas == none)
  44.         return MaxDesireability;
  45.     else
  46.         return 0;
  47. }
  48.  
  49. function PickupFunction(Pawn Other)
  50. {
  51.     if (Other.IsA('Bots'))
  52.     {
  53.         // Small chance of activating on Pickup, else it heads to Idle2 state.
  54.         if (FRand() < 0.13)
  55.             GotoState('Activated');
  56.     }
  57. }
  58.  
  59. // ================================================================================================
  60. // Activated State
  61. // ================================================================================================
  62.  
  63. state Activated
  64. {
  65.     function BeginState()
  66.     {
  67.         bActive = true;
  68.         DisableInventoryEffects();
  69.         Enable('Tick');
  70.        
  71.         // new sound stuff:
  72.         Owner.PlaySound(sound'CloakOn');
  73.  
  74.         CloakOwner();
  75.        
  76.         // "Turn on" the bEngaging part of the Tick function below..
  77.         bEngaging = true;
  78.  
  79.         // Set their current weapon to be invisible
  80.         if (Pawn(Owner).Weapon != none)
  81.             InvisWeapons(Pawn(Owner).Weapon);
  82.        
  83.         SetTimer(0.7, true);
  84.     }
  85.  
  86.     function EndState()
  87.     {
  88.         bActive = false;
  89.     }
  90.    
  91.     function Activate()
  92.     {
  93.         if (!Level.Game.IsA('CloakMatch'))
  94.             super.Activate();  
  95.     }
  96.  
  97.     function Timer()
  98.     {
  99.         local Bots SP;
  100.        
  101.         if (Pawn(Owner) == none || Owner.bDeleteMe)
  102.             return;
  103.  
  104.         EnableInventoryEffects();
  105.    
  106.         if (!Level.Game.IsA('CloakMatch'))
  107.             Charge--;
  108.         foreach AllActors(class'Bots', SP)
  109.         {
  110.             if (SP.Enemy == Owner)
  111.             {
  112.                 SP.Enemy = none;
  113.                 SP.Target = none;
  114.             }
  115.         }
  116.        
  117.         // If the charge is <= 0, use the bEngaging routine in TICK for the flicker effect again..
  118.         // Run the bEngaging routine for about 5 seconds, then destroy it.
  119.         if (Charge <= 0)
  120.         {
  121.             if (++CountDown >= 10)
  122.             {
  123.                 Pawn(Owner).ClientMessage(ItemName $ M_Deactivated);
  124.                 Destroy();
  125.             }
  126.             else
  127.                 bEngaging = true;  
  128.         }
  129.         else if (bEngaging && bEngagingCompleted)
  130.             GotoState(, 'Begin');
  131.     }  
  132.  
  133.     function Tick(float DeltaTime)
  134.     {
  135.         local Pawn OwnerPawn;
  136.         local bool bFlicker;
  137.         local float TimeFactor;
  138.  
  139.         OwnerPawn = Pawn(Owner);
  140.         if (OwnerPawn == none)
  141.             return;
  142.  
  143.         CloakOwner();
  144.  
  145.         if (bEngaging)
  146.         {
  147.             OwnerPawn.Fatness = Rand(254);
  148.  
  149.             if (FRand() < 0.5)
  150.             {
  151.                 OwnerPawn.bMeshEnviroMap = true;
  152.                 if (OwnerPawn.Texture == none || OwnerPawn.Texture.Name != 'Invis')
  153.                     OwnerPawn.Texture = Texture'CloakTexture';
  154.                 OwnerPawn.ScaleGlow = 0.08;
  155.             }
  156.             else
  157.             {
  158.                 OwnerPawn.Fatness = OwnerPawn.default.Fatness;
  159.                 if (OwnerPawn.Texture == none || OwnerPawn.Texture.Name != 'Invis')
  160.                 {
  161.                     OwnerPawn.bMeshEnviroMap = OwnerPawn.default.bMeshEnviroMap;
  162.                     OwnerPawn.Texture = OwnerPawn.default.Texture;
  163.                 }
  164.                 OwnerPawn.ScaleGlow = 0.95;
  165.             }
  166.         }
  167.         else // Normal checks for normal invisible state. Firing, rotation, speed.
  168.         {
  169.             TimeFactor = DeltaTime * 60; // 60 ticks per second is taken as the normal rate
  170.  
  171.             OwnerPawn.bMeshEnviroMap = true;
  172.             if (OwnerPawn.Texture == OwnerPawn.default.Texture)
  173.                 OwnerPawn.Texture = Texture'CloakTexture';
  174.  
  175.             if (OwnerPawn.bFire != 0 || OwnerPawn.bAltFire != 0)
  176.                 OwnerPawn.ScaleGlow = 0.13;
  177.  
  178.             if (OwnerPawn.Rotation != LastOwnerRotation && OwnerPawn.ScaleGlow <= 0.14 )
  179.             {
  180.                 OwnerPawn.ScaleGlow = 0.4;
  181.                 LastOwnerRotation = OwnerPawn.Rotation;
  182.             }
  183.             else if (VSize(OwnerPawn.Velocity) == 0 && OwnerPawn.ScaleGlow > 0.02)
  184.                 OwnerPawn.ScaleGlow = FMax(0.02, OwnerPawn.ScaleGlow - 0.01 * TimeFactor)
  185.             else
  186.                 bFlicker = true;
  187.  
  188.             // Extra subtle flickering/slight expanding for effect.
  189.             if (bFlicker)
  190.             {
  191.                 if (OwnerFatnessDelta > -14 && !bExpanding)
  192.                 {
  193.                     OwnerFatnessDelta = FMax(-14, OwnerFatnessDelta - 2 * TimeFactor);
  194.                     OwnerPawn.ScaleGlow = FMax(0.01, OwnerPawn.ScaleGlow - 0.01 * TimeFactor);
  195.                 }
  196.                 else
  197.                 {
  198.                     bExpanding = true;
  199.                     if (OwnerFatnessDelta < 0)
  200.                     {
  201.                         if (VSize(OwnerPawn.Velocity) > 0)
  202.                         {
  203.                             OwnerFatnessDelta = FMin(0, OwnerFatnessDelta + 2 * TimeFactor);
  204.                             OwnerPawn.ScaleGlow = FMin(0.19, OwnerPawn.ScaleGlow + 0.01 * TimeFactor);
  205.                         }
  206.                         else
  207.                             OwnerFatnessDelta = FMin(0, OwnerFatnessDelta + TimeFactor);
  208.                     }
  209.                     else
  210.                         bExpanding = false;
  211.                 }
  212.             }
  213.             else
  214.                 OwnerFatnessDelta = FMin(0, OwnerFatnessDelta + 2 * TimeFactor);
  215.             OwnerPawn.Fatness = OwnerPawn.default.Fatness + OwnerFatnessDelta;
  216.         }
  217.  
  218.         UpdateWeapons();
  219.     }
  220.  
  221.     // Set a weapon to invis stats, and add it to the affected weapon array.
  222.     function InvisWeapons(Weapon ChangeWeapon)
  223.     {
  224.         CloakOwnerWeapon(ChangeWeapon);
  225.     }
  226.  
  227.     // Search the array, make sure no weapon is duplicated in it; if no match, add it to the array and
  228.     // increment arraycounter.
  229.     function AddWeaponToList(Weapon AddWeapon)
  230.     {
  231.         AddToInvisWeaponList(AddWeapon);
  232.     }
  233.  
  234. Begin:
  235.  
  236.     bEngagingCompleted = false;
  237.     Sleep(2.0 + FRand());
  238.     bEngaging = false;
  239.     bEngagingCompleted = true;
  240.     Disable('Tick');
  241.     OwnerFatnessDelta = 0;
  242.     if (Pawn(Owner) != none)
  243.     {
  244.         Owner.Fatness = Owner.default.Fatness;
  245.         if (Owner.Texture == none || Owner.Texture.Name != 'Invis')
  246.             Owner.Texture = Texture'CloakTexture';
  247.         Owner.bMeshEnviroMap = true;
  248.         Owner.ScaleGlow = 0.75;
  249.  
  250.         if (Pawn(Owner).Weapon != none)
  251.         {
  252.             AddWeaponToList(Pawn(Owner).Weapon);
  253.             Pawn(Owner).Weapon.ScaleGlow = 0.75;
  254.         }
  255.  
  256.         Sleep(0.5);
  257.         Enable('Tick');
  258.     }
  259. }
  260.  
  261. function CloakOwner()
  262. {
  263.     local Pawn OwnerPawn;
  264.     local float JumpZ;
  265.  
  266.     OwnerPawn = Pawn(Owner);
  267.     if (OwnerPawn == none || OwnerPawn.bDeleteMe)
  268.         return;
  269.  
  270.     OwnerPawn.Style = STY_Translucent;
  271.  
  272.     // Invisible to bots/scriptedpawns
  273.     if (Level.Game.IsA('CloakMatch'))
  274.         Pawn(Owner).Visibility = Min(100, Pawn(Owner).Visibility);
  275.     else
  276.         Pawn(Owner).Visibility = 0;
  277.  
  278.     if (OwnerPawn.AirControl < AirControlAdjustment)
  279.         OwnerPawn.AirControl = AirControlAdjustment;
  280.  
  281.     JumpZ = OwnerPawn.default.JumpZ * JumpZAdjustment;
  282.     if (OwnerPawn.JumpZ < JumpZ)
  283.         OwnerPawn.JumpZ = JumpZ;
  284. }
  285.  
  286. function UpdateOwnerWeapon(Weapon Weap)
  287. {
  288.     if (Weap == none)
  289.         return;
  290.     if (Weap != LastWeapon ||
  291.         Weap.Style != STY_Translucent ||
  292.         !Weap.bMeshEnviroMap ||
  293.         Weap.Texture == Weap.default.Texture)
  294.     {
  295.         CloakOwnerWeapon(Weap);
  296.     }
  297.     Weap.ScaleGlow = Owner.ScaleGlow;
  298. }
  299.  
  300. function CloakOwnerWeapon(Weapon Weap)
  301. {
  302.     if (Weap == none)
  303.         return;
  304.     Weap.Style = STY_Translucent;
  305.     Weap.bMeshEnviroMap = true;
  306.     Weap.Texture = Texture'CloakTexture';
  307.     Weap.ScaleGlow = 0.12;
  308.     AddToInvisWeaponList(Weap);
  309.     LastWeapon = Weap;
  310. }
  311.  
  312. function AddToInvisWeaponList(Weapon Weap)
  313. {
  314.     local int i;
  315.    
  316.     for (i = 0; i < ArrayCounter; ++i)
  317.         if (InvisWeaponList[i] == Weap)
  318.             return;
  319.  
  320.     for (i = 0; i < ArrayCounter; ++i)
  321.         if (InvisWeaponList[i] == none)
  322.         {
  323.             InvisWeaponList[i] = Weap;
  324.             return;
  325.         }
  326.  
  327.     if (ArrayCounter < ArrayCount(InvisWeaponList))
  328.         InvisWeaponList[ArrayCounter++] = Weap;
  329. }
  330.  
  331. function UpdateWeapons()
  332. {
  333.     local Weapon Weap;
  334.     local int i;
  335.  
  336.     if (Pawn(Owner) == none)
  337.         return;
  338.  
  339.     UpdateOwnerWeapon(Pawn(Owner).Weapon);
  340.     UpdateOwnerWeapon(Pawn(Owner).PendingWeapon);
  341.  
  342.     for (i = 0; i < ArrayCounter; ++i)
  343.         if (InvisWeaponList[i] != none &&
  344.             InvisWeaponList[i] != Pawn(Owner).Weapon &&
  345.             InvisWeaponList[i] != Pawn(Owner).PendingWeapon)
  346.         {
  347.             RestoreWeaponVisibility(InvisWeaponList[i]);
  348.         }
  349. }
  350.  
  351. function RestoreVis()
  352. {
  353.     local Pawn OwnerPawn;
  354.  
  355.     OwnerPawn = Pawn(Owner);
  356.     if (OwnerPawn == none)
  357.         return;
  358.  
  359.     OwnerPawn.AirControl = OwnerPawn.default.AirControl;
  360.     OwnerPawn.JumpZ = OwnerPawn.default.JumpZ * Level.Game.PlayerJumpZScaling();
  361.     OwnerPawn.bCountJumps = false; // signal for JumpBoots to adjust JumpZ
  362.  
  363.     OwnerPawn.ScaleGlow = OwnerPawn.default.ScaleGlow;
  364.     OwnerPawn.Fatness = OwnerPawn.default.Fatness;
  365.     if (Owner.Texture == none || Owner.Texture.Name != 'Invis')
  366.     {
  367.         OwnerPawn.Style = OwnerPawn.default.Style;
  368.         OwnerPawn.bMeshEnviroMap = OwnerPawn.default.bMeshEnviroMap;
  369.         OwnerPawn.Visibility = OwnerPawn.default.Visibility;
  370.     }
  371.     if (OwnerPawn.Texture == Texture'CloakTexture')
  372.         OwnerPawn.Texture = OwnerPawn.default.Texture;
  373. }
  374.  
  375. function bool UseSpecialEffectsActor()
  376. {
  377.     return Class == class'Cloak';
  378. }
  379.  
  380. function EnableInventoryEffects()
  381. {
  382.     if (!UseSpecialEffectsActor())
  383.         EffectsActor = Owner;
  384.     else if (EffectsActor == none)
  385.     {
  386.         EffectsActor = Spawn(class'Triggers', Owner, 'Cloak_EffectsActor', Owner.Location);
  387.         if (EffectsActor != none)
  388.         {
  389.             EffectsActor.SetPhysics(PHYS_Trailer);
  390.             EffectsActor.RemoteRole = ROLE_SimulatedProxy;
  391.         }
  392.         else
  393.             EffectsActor = Owner;
  394.     }
  395.  
  396.     EffectsActor.AmbientSound = sound'CloakLoop3';
  397.     EffectsActor.SoundRadius = 500;
  398.     EffectsActor.SoundVolume = 250;
  399. }
  400.  
  401. function DisableInventoryEffects()
  402. {
  403.     if (Owner != none && (!UseSpecialEffectsActor() || EffectsActor == Owner))
  404.     {
  405.         Owner.AmbientSound = none;
  406.         Owner.SoundRadius = Owner.default.SoundRadius;
  407.         Owner.SoundVolume = Owner.default.SoundVolume;
  408.     }
  409.     if (EffectsActor != none && EffectsActor != Owner)
  410.         EffectsActor.Destroy();
  411.     EffectsActor = none;
  412. }
  413.  
  414. static function RestoreWeaponVisibility(out Weapon Weap)
  415. {
  416.     if (Weap == none || Weap.bDeleteMe)
  417.         return;
  418.     Weap.Texture = Weap.default.Texture;
  419.     Weap.ScaleGlow = Weap.default.ScaleGlow;
  420.     Weap.bMeshEnviroMap = Weap.default.bMeshEnviroMap;
  421.     Weap.Style = Weap.default.Style;
  422.     Weap = none;
  423. }
  424.  
  425. function WeaponRestore()
  426. {
  427.     local int i;
  428.  
  429.     for (i = 0; i < ArrayCounter; ++i)
  430.         RestoreWeaponVisibility(InvisWeaponList[i]);
  431.     ArrayCounter = 0;
  432. }
  433.  
  434. // Important! This makes sure that the weapon list and player are both restored when the Cloak item is destroyed.
  435. // It's destroyed when a player dies (natural to Unreal pickup inv items) or when it's expired.
  436.  
  437. event Destroyed()
  438. {
  439.     DisableInventoryEffects();
  440.     RestoreVis();
  441.     WeaponRestore();
  442.     Super.Destroyed();
  443. }
  444.  
  445. // ================================================================================================
  446. // Deactivated State
  447. // ================================================================================================
  448.  
  449. state Deactivated
  450. {
  451.     function BeginState()
  452.     {
  453.         Enable('Tick');
  454.         bEngaging = true;
  455.         SetTimer(0.5, true);
  456.     }
  457.     function Timer()
  458.     {
  459.         CountDown++;
  460.  
  461.         if (CountDown >= 10)
  462.         {
  463.             RestoreVis();
  464.             WeaponRestore();
  465.             DisableInventoryEffects();
  466.             if (Owner != none)
  467.                 Owner.PlaySound(sound'CloakOff');
  468.             Disable('Tick');
  469.             SetTimer(0, false);
  470.         }
  471.         else
  472.             bEngaging = true;
  473.     }
  474.     function Tick(float DeltaTime)
  475.     {
  476.         local Pawn OwnerPawn;
  477.  
  478.         if (bEngaging && Pawn(Owner) != none)
  479.         {
  480.             OwnerPawn = Pawn(Owner);
  481.             CloakOwner();
  482.  
  483.             // Keep the weapon's scaleglow at the same level the players' is..
  484.             OwnerPawn.Weapon.ScaleGlow = OwnerPawn.ScaleGlow;
  485.             OwnerPawn.Fatness = Rand(254);
  486.  
  487.             if (FRand() < 0.5)
  488.             {
  489.                 OwnerPawn.bMeshEnviroMap = true;
  490.                 if (OwnerPawn.Texture == none || OwnerPawn.Texture.Name != 'Invis')
  491.                     OwnerPawn.Texture = Texture'CloakTexture';
  492.                 OwnerPawn.ScaleGlow = 0.12;
  493.             }
  494.             else
  495.             {
  496.                 OwnerPawn.Fatness = OwnerPawn.default.Fatness;
  497.                 if (OwnerPawn.Texture == none || OwnerPawn.Texture.Name != 'Invis')
  498.                 {
  499.                     OwnerPawn.bMeshEnviroMap = OwnerPawn.default.bMeshEnviroMap;
  500.                     OwnerPawn.Texture = OwnerPawn.default.Texture;
  501.                 }
  502.                 OwnerPawn.ScaleGlow = 0.95;
  503.             }
  504.  
  505.             UpdateWeapons();
  506.         }      
  507.     }
  508. }
  509.  
  510. // ================================================================================================
  511. // Idle2 State
  512. // ================================================================================================
  513.  
  514. // If a bot owns this, this stuff executes to determine when it activates the item
  515. state Idle2
  516. {
  517.     function BeginState()
  518.     {
  519.         if (Pawn(Owner) != none && Owner.IsA('Bots'))
  520.             SetTimer(1 + FRand(), True);
  521.     }
  522.    
  523.     // Scan the Radius every 1 + FRand() seconds for any other targets, if any are found, activate the item.
  524.     function Timer()
  525.     {
  526.         local Pawn P;
  527.  
  528.         if (Pawn(Owner) == none)
  529.         {
  530.             SetTimer(0, false);
  531.             return;
  532.         }
  533.         // Radius could use tweaking
  534.         foreach Owner.RadiusActors(class'Pawn', P, 10000)
  535.         {
  536.             if (P != Owner && P.Visibility > 0)
  537.             {
  538.                 GotoState('Activated');
  539.                 return;
  540.             }
  541.         }
  542.     }
  543. }
  544.  
  545. //=============================================================================
  546. // Sleeping state: Sitting hidden waiting to respawn.
  547.  
  548. state Sleeping
  549. {
  550.     ignores Touch;
  551.  
  552.     function BeginState()
  553.     {
  554.         BecomePickup();
  555.         LightType = LT_None;
  556.         bUnlit = false;
  557.         bHidden = true;
  558.     }
  559.  
  560.     function EndState()
  561.     {
  562.         local Pawn P;
  563.  
  564.         LightType = default.LightType;
  565.         bUnlit = true;
  566.        
  567.         bSleepTouch = false;
  568.         foreach TouchingActors(class'Pawn', P)
  569.             bSleepTouch = true;
  570.     }          
  571. Begin:
  572.     Sleep(ReSpawnTime);
  573.     PlaySound(RespawnSound);
  574.     Level.Game.PlaySpawnEffect(self);
  575.     Sleep(0.3);
  576.     GoToState('Pickup');
  577. }
  578.  
  579. defaultproperties
  580. {
  581.     JumpZAdjustment=3.000000
  582.     AirControlAdjustment=6.000000
  583.     bCanActivate=True
  584.     ExpireMessage="disengaged."
  585.     bActivatable=True
  586.     bDisplayableInv=True
  587.     bAmbientGlow=False
  588.     PickupMessage="You got the Cloaking Device."
  589.     ItemName="Cloaking Device"
  590.     RespawnTime=30.000000
  591.     PickupViewMesh=LodMesh'UPak.pyramid'
  592.     Charge=100
  593.     PickupSound=Sound'UnrealShare.Pickups.GenPickSnd'
  594.     Icon=Texture'UPak.Icons.I_Cloak'
  595.     M_Activated=" engaged"
  596.     M_Deactivated=" disengaged"
  597.     Mesh=LodMesh'UPak.pyramid'
  598.     SoundRadius=64
  599.     SoundVolume=96
  600.     CollisionRadius=19.799999
  601.     CollisionHeight=13.700000
  602.     LightRadius=4
  603.     LightPeriod=5
  604.     LightPhase=5
  605.     LightCone=8
  606. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement