Advertisement
Guest User

PawnShadowX.uc

a guest
Apr 12th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class PawnShadowX extends Projector
  2.     NoUserCreate;
  3.  
  4. #exec TEXTURE IMPORT NAME=BlobShadow FILE=Textures\BlobShadow.pcx LODSET=2
  5.  
  6. var transient vector OldOwnerLocation;
  7. var transient int OldShadowDetail;
  8. var transient bool bOptionalUpdate;
  9. var transient ShadowBitMap PLShadow;
  10.  
  11. simulated function PostBeginPlay()
  12. {
  13.     SetRotation(rot(-16384,0,0));
  14. }
  15.  
  16. simulated final function bool IsViewActor()
  17. {
  18.     local PlayerPawn P;
  19.  
  20.     P = Level.GetLocalPlayerPawn();
  21.     return (P!=None && (P.ViewTarget==Owner || P==Owner));
  22. }
  23.  
  24. simulated event Tick( float Delta )
  25. {
  26.     UpdateShadow();
  27. }
  28.  
  29. simulated function UpdateShadow()
  30. {
  31.     local Actor HitActor;
  32.     local vector HitNormal, HitLocation, ShadowStart;
  33.     local float ShadowDetail;
  34.     local float Distance;
  35.     local bool bInvisible, bHitMovingBrush;
  36.  
  37.     if ( Owner==None || Owner.bDeleteMe )
  38.     {
  39.         Destroy();
  40.         Return;
  41.     }
  42.  
  43.     if( (Level.TimeSeconds-LastRenderedTime)>1.f && (Level.TimeSeconds-Owner.LastRenderedTime)>1.f && !IsViewActor() )
  44.     {
  45.         if( bHasAttached )
  46.         {
  47.             DeattachPrjDecal();
  48.             bOptionalUpdate = false;
  49.         }
  50.         return;
  51.     }
  52.  
  53.     if (!class'GameInfo'.default.bCastShadow ||
  54.         Owner.Style == STY_Translucent ||
  55.         Owner.bHidden ||
  56.         Owner.DrawType == DT_None)
  57.     {
  58.         if (bHasAttached)
  59.             DeattachPrjDecal();
  60.         bOptionalUpdate = false;
  61.         return;
  62.     }
  63.  
  64.     if (class'GameInfo'.Default.bUseRealtimeShadow)
  65.         ShadowDetail = class'PawnShadow'.default.ShadowDetailRes; // else keep the initial value - zero
  66.     if (class'PawnShadow'.default.bOptimizeTracing && bOptionalUpdate && Owner.Location == OldOwnerLocation && ShadowDetail == OldShadowDetail)
  67.         return;
  68.  
  69.     OldOwnerLocation = Owner.Location;
  70.     OldShadowDetail = ShadowDetail;
  71.     if (bHasAttached)
  72.         DeattachPrjDecal();
  73.  
  74.     ShadowStart = Owner.Location;
  75.     ShadowStart.Z-=(Owner.CollisionHeight-5);
  76.     HitActor = Trace(HitLocation, HitNormal, ShadowStart - vect(0, 0, 200), ShadowStart, false, vect(0.9, 0.9, 0) * Owner.CollisionRadius);
  77.  
  78.     if (HitActor == none)
  79.     {
  80.         bOptionalUpdate = true;
  81.         return;
  82.     }
  83.  
  84.     if (class'GameInfo'.default.bUseRealtimeShadow && PLShadow == none)
  85.     {
  86.         PLShadow = ShadowBitMap(Level.AllocateObj(Class'ShadowBitMap'));
  87.         if (PLShadow == none)
  88.             PLShadow = new(Outer) class'ShadowBitMap';
  89.         PLShadow.ProjectingActor = Owner;
  90.         PLShadow.ProjectDirection = rot(16384,0,0);
  91.         ProjectTexture = PLShadow;
  92.         if (PLShadow.USize != class'PawnShadow'.default.ShadowDetailRes)
  93.             PLShadow.SetShadowRes(class'PawnShadow'.default.ShadowDetailRes, class'PawnShadow'.default.ShadowDetailRes);
  94.         PLShadow.Softness = class'PawnShadow'.static.GetShadowSoftness();
  95.         PLShadow.StaticLevel = 0;
  96.         ProjectStyle = STY_AlphaBlend;
  97.     }
  98.     else if (!class'GameInfo'.default.bUseRealtimeShadow && PLShadow != none)
  99.     {
  100.         PLShadow.ProjectingActor = none;
  101.         Level.FreeObject(PLShadow);
  102.         PLShadow = none;
  103.         ProjectTexture = default.ProjectTexture;
  104.         ProjectStyle = default.ProjectStyle;
  105.     }
  106.  
  107.     Distance = FMax(Owner.Location.Z - Owner.CollisionHeight - HitLocation.Z, 0.f);
  108.  
  109.     if (PLShadow != none)
  110.     {
  111.         if (PLShadow.USize != class'PawnShadow'.default.ShadowDetailRes)
  112.         {
  113.             PLShadow.SetShadowRes(class'PawnShadow'.default.ShadowDetailRes, class'PawnShadow'.default.ShadowDetailRes);
  114.             PLShadow.Softness = class'PawnShadow'.static.GetShadowSoftness();
  115.         }
  116.         ProjectorScale = FMax(Owner.CollisionRadius, 16.f) * (12.f / class'PawnShadow'.default.ShadowDetailRes);
  117.         PLShadow.ShadowScale = 0.8f / ProjectorScale;
  118.         PLShadow.Gradience = Min(Distance + 100, 255);
  119.         if (PLShadow.Gradience == 255)
  120.             bInvisible = true;
  121.     }
  122.     else
  123.     {
  124.         ProjectorScale = Owner.CollisionRadius/70.f * class'PawnShadow'.default.ShadowScaling *
  125.             (1.f - Distance / FMin(2 * Owner.CollisionRadius, 155.0));
  126.         if (ProjectorScale <= 0)
  127.             bInvisible = true;
  128.     }
  129.  
  130.     HitLocation += vect(0, 0, 20);
  131.     bHitMovingBrush = HitActor.bIsMover && HitActor.Brush != none;
  132.     bOptionalUpdate = Location == HitLocation && !bHitMovingBrush;
  133.  
  134.     SetLocation(HitLocation);
  135.  
  136.     if (bInvisible)
  137.         return;
  138.     AttachPrjDecal();
  139.    
  140.     if (HitActor != Level && !bHitMovingBrush)
  141.         AttachActor(HitActor);
  142. }
  143.  
  144. simulated function Destroyed()
  145. {
  146.     if( PLShadow!=None )
  147.     {
  148.         PLShadow.ProjectingActor = None;
  149.         Level.FreeObject(PLShadow);
  150.         PLShadow = None;
  151.     }
  152.     Super.Destroyed();
  153. }
  154.  
  155. simulated function Touch( Actor Other )
  156. {
  157.     if( bProjectActors && !Other.bHidden && Other.DrawType==DT_Mesh && Other.Mesh!=None && Other!=Owner )
  158.         AttachActor(Other);
  159. }
  160.  
  161. defaultproperties
  162. {
  163.     ProjectTexture=Texture'BlobShadow'
  164.     DrawScale=0.50
  165.     RemoteRole=ROLE_None
  166.     ProjectStyle=STY_Modulated
  167.     bCollideActors=false
  168.     MaxDistance=155.0
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement