Advertisement
Guest User

Snow/Classes/SnowDrop.uc

a guest
Sep 16th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class SnowDrop expands Effects;
  2.  
  3. const MinDesiredFPS = 55;
  4.  
  5. var float MeltingTime;
  6.  
  7. var SnowActor Snowy;
  8. var float AirResistanceFactor;
  9. var vector InitialVelocity, WindVelocity;
  10. var bool bHitWall;
  11.  
  12. event PostBeginPlay()
  13. {
  14.     bCollideWorld = true;
  15. }
  16.  
  17. event FellOutOfWorld();
  18.  
  19.  
  20. auto state Resetting
  21. {
  22.     event BeginState()
  23.     {
  24.         bHidden = true;
  25.     }
  26.  
  27.     function SetupSnow()
  28.     {
  29.         const MaxSetLocationAttempts = 16;
  30.         local vector NewLoc, RandomDir;
  31.         local float RandomAngle;
  32.         local int i;
  33.  
  34.         Snowy = SnowActor(Owner);
  35.         if (Snowy == none || Snowy.bDeleteMe)
  36.         {
  37.             Destroy();
  38.             return;
  39.         }
  40.  
  41.         for (i = 0; i < MaxSetLocationAttempts; ++i)
  42.         {
  43.             RandomAngle = FRand() * 2 * Pi;
  44.             RandomDir.X = Cos(RandomAngle);
  45.             RandomDir.Y = Sin(RandomAngle);
  46.             RandomDir.Z = 0;
  47.             NewLoc = Snowy.Location + Snowy.Radius * FRand() * RandomDir;
  48.             if (SetLocation(NewLoc) && !Region.Zone.bWaterZone)
  49.                 break;
  50.         }
  51.         bHidden = i == MaxSetLocationAttempts;
  52.  
  53.         if (bHidden)
  54.             GotoState('Resetting');
  55.         else
  56.         {
  57.             AirResistanceFactor = Square(
  58.                 Sqrt(Snowy.MinAirResistanceFactor) +
  59.                 FRand() * (Sqrt(Snowy.MaxAirResistanceFactor) - Sqrt(Snowy.MinAirResistanceFactor)));
  60.             InitialVelocity = Snowy.InitialVelocity(AirResistanceFactor);
  61.             SetCollision(Snowy.bBlockByActors, false, false);
  62.             GotoState('FallingDown');
  63.         }
  64.     }
  65.  
  66. Begin:
  67.     Sleep(0);
  68.     SetupSnow();
  69. }
  70.  
  71. state FallingDown
  72. {
  73.     event BeginState()
  74.     {
  75.         SetTimer(0.5, true);
  76.         SetPhysics(PHYS_Projectile);
  77.     }
  78.  
  79.     event EndState()
  80.     {
  81.         Velocity = vect(0, 0, 0);
  82.         SetCollision(false);
  83.         SetPhysics(PHYS_None);
  84.     }
  85.  
  86.     event HitWall(vector HitNormal, actor HitWall)
  87.     {
  88.         bHitWall = true;
  89.         if (Abs(Velocity.Z) < 16 ||
  90.             vect(0, 0, 1) * int(Velocity.Z < 0) Dot HitNormal > Sqrt(2) / 2)
  91.         {
  92.             GotoState('Melting');
  93.         }
  94.         else
  95.         {
  96.             Velocity = (0.9 * Velocity + MirrorVectorByNormal(Velocity, HitNormal)) / 2;
  97.             if (Abs(Velocity.Z) < 16)
  98.                 GotoState('Melting');
  99.         }
  100.     }
  101.  
  102.     event Touch(Actor A)
  103.     {
  104.         if (A.bCollideActors && A.bBlockActors)
  105.             GotoState('Resetting');
  106.     }
  107.  
  108.     event ZoneChange(ZoneInfo NewZone)
  109.     {
  110.         if (NewZone.bWaterZone)
  111.             GotoState('Resetting');
  112.     }
  113.  
  114.     event Tick(float DeltaTime)
  115.     {
  116.         if (Snowy != none && !Snowy.bDeleteMe)
  117.             WindVelocity = Snowy.WindVelocity;
  118.         if (bHitWall)
  119.             bHitWall = false;
  120.         else
  121.             Velocity = class'SnowActor'.static.AdjustVelocity(Velocity + CalcAcceleration() * DeltaTime, Region.Zone);
  122.         if (DeltaTime > Level.TimeDilation / MinDesiredFPS && FRand() < 0.1)
  123.         {
  124.             bHidden = true;
  125.             SetCollision(false);
  126.         }
  127.     }
  128.  
  129.     function vector CalcAcceleration()
  130.     {
  131.         local vector RelationalVelocity; // velocity of the snow particle in relation to the wind
  132.         local vector AirResistance;
  133.  
  134.         RelationalVelocity = Velocity - WindVelocity;
  135.         AirResistance = -RelationalVelocity * VSize(RelationalVelocity) * AirResistanceFactor;
  136.  
  137.         return Region.Zone.ZoneGravity + AirResistance;
  138.     }
  139.  
  140. Begin:
  141.     Velocity = InitialVelocity;
  142. }
  143.  
  144. state Melting
  145. {
  146. Begin:
  147.     Sleep(MeltingTime);
  148.     GotoState('Resetting');
  149. }
  150.  
  151. defaultproperties
  152. {
  153.     RemoteRole=ROLE_None
  154.     DrawType=DT_Sprite
  155.     Style=STY_Translucent
  156.     Texture=Texture'S_Actor'
  157.     DrawScale=0.2
  158.     bBounce=True
  159.     CollisionRadius=1
  160.     CollisionHeight=1
  161.     MeltingTime=1
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement