home *** CD-ROM | disk | FTP | other *** search
/ Game Level Design / GLDesign.bin / Software / UnrealEngine2Runtime / UE2Runtime-22262001_Demo.exe / Engine / Classes / PhysicsVolume.uc < prev    next >
Text File  |  2003-06-23  |  6KB  |  241 lines

  1. //=============================================================================
  2. // PhysicsVolume:  a bounding volume which affects actor physics
  3. // Each Actor is affected at any time by one PhysicsVolume
  4. // This is a built-in Unreal class and it shouldn't be modified.
  5. //=============================================================================
  6. class PhysicsVolume extends Volume
  7.     native
  8.     nativereplication;
  9.  
  10. var()        bool        bPainCausing;     // Zone causes pain.
  11. var()        vector        ZoneVelocity;
  12. var()        vector        Gravity;
  13. var()        float        GroundFriction;
  14. var()        float        TerminalVelocity;
  15. var()        float        DamagePerSec;
  16. var() class<DamageType>    DamageType;
  17. var()        int            Priority;    // determines which PhysicsVolume takes precedence if they overlap
  18. var() sound  EntrySound;    //only if waterzone
  19. var() sound  ExitSound;        // only if waterzone
  20. var() class<actor> EntryActor;    // e.g. a splash (only if water zone)
  21. var() class<actor> ExitActor;    // e.g. a splash (only if water zone)
  22. var() float  FluidFriction;
  23. var() vector ViewFlash, ViewFog;
  24.  
  25. var()        bool    bDestructive; // Destroys most actors which enter it.
  26. var()        bool    bNoInventory;
  27. var()        bool    bMoveProjectiles;// this velocity zone should impart velocity to projectiles and effects
  28. var()        bool    bBounceVelocity;    // this velocity zone should bounce actors that land in it
  29. var()        bool    bNeutralZone; // Players can't take damage in this zone.
  30. var            bool    bWaterVolume;
  31. var    Info PainTimer;
  32.  
  33. // Distance Fog
  34. var(VolumeFog) bool   bDistanceFog;    // There is distance fog in this physicsvolume.
  35. var(VolumeFog) color DistanceFogColor;
  36. var(VolumeFog) float DistanceFogStart;
  37. var(VolumeFog) float DistanceFogEnd;
  38.  
  39. // Karma
  40. var(Karma)       float KExtraLinearDamping; // Extra damping applied to Karma actors in this volume.
  41. var(Karma)       float KExtraAngularDamping;
  42. var(Karma)       float KBuoyancy;              // How buoyant Karma things are in this volume (if bWaterVolume true). Multiplied by Actors KarmaParams->KBuoyancy.
  43.  
  44. var PhysicsVolume NextPhysicsVolume;
  45.  
  46. replication
  47. {
  48.     // Things the server should send to the client.
  49.     reliable if( bNetDirty && (Role==ROLE_Authority) )
  50.         Gravity;
  51. }
  52.  
  53. /* Called when an actor in this PhysicsVolume changes its physics mode
  54. */
  55. event PhysicsChangedFor(Actor Other);
  56.  
  57. event ActorEnteredVolume(Actor Other);
  58. event ActorLeavingVolume(Actor Other);
  59.  
  60. event PawnEnteredVolume(Pawn Other)
  61. {
  62.     if ( Other.IsPlayerPawn() )
  63.         TriggerEvent(Event,self, Other);
  64. }
  65.  
  66. event PawnLeavingVolume(Pawn Other)
  67. {
  68.     if ( Other.IsPlayerPawn() )
  69.         UntriggerEvent(Event,self, Other);
  70. }
  71.  
  72. /*
  73. TimerPop
  74. damage touched actors if pain causing.
  75. since PhysicsVolume is static, this function is actually called by a volumetimer
  76. */
  77. function TimerPop(VolumeTimer T)
  78. {
  79.     local actor A;
  80.     local bool bFound;
  81.  
  82.     if ( T == PainTimer )
  83.     {
  84.         if ( !bPainCausing )
  85.         {
  86.             PainTimer.Destroy();
  87.             return;
  88.         }
  89.         ForEach TouchingActors(class'Actor', A)
  90.             if ( A.bCanBeDamaged && !A.bStatic )
  91.             {
  92.             CausePainTo(A);
  93.                 bFound = true;
  94.             }
  95.             
  96.         if ( !bFound )
  97.             PainTimer.Destroy();
  98.     }
  99. }
  100.  
  101. function Trigger( actor Other, pawn EventInstigator )
  102. {
  103.     // turn zone damage on and off
  104.     if (DamagePerSec != 0)
  105.     {
  106.         bPainCausing = !bPainCausing;
  107.         if ( bPainCausing && (PainTimer == None) )
  108.             PainTimer = spawn(class'VolumeTimer', self);
  109.     }
  110. }
  111.  
  112. event touch(Actor Other)
  113. {
  114.     local Pawn P;
  115.     local bool bFoundPawn;
  116.     
  117.     Super.Touch(Other);
  118.     if ( Other == None )
  119.         return;
  120.     if ( bNoInventory && Other.IsA('Inventory') && (Other.Owner == None) )
  121.     {
  122.         Other.LifeSpan = 1.5;
  123.         return;
  124.     }
  125.     if ( bMoveProjectiles && (ZoneVelocity != vect(0,0,0)) )
  126.     {
  127.         if ( Other.Physics == PHYS_Projectile )
  128.             Other.Velocity += ZoneVelocity;
  129.         else if ( Other.IsA('Effects') && (Other.Physics == PHYS_None) )
  130.         {
  131.             Other.SetPhysics(PHYS_Projectile);
  132.             Other.Velocity += ZoneVelocity;
  133.         }
  134.     }
  135.     if ( bPainCausing )
  136.     {
  137.         if ( Other.bDestroyInPainVolume )
  138.         {
  139.             Other.Destroy();
  140.             return;
  141.         }
  142.         if ( Other.bCanBeDamaged && !Other.bStatic )
  143.         {
  144.         CausePainTo(Other);
  145.             if ( PainTimer == None )
  146.                 PainTimer = Spawn(class'VolumeTimer', self);
  147.             else if ( Pawn(Other) != None )
  148.             {
  149.                 ForEach TouchingActors(class'Pawn', P)
  150.                     if ( (P != Other) && P.bCanBeDamaged )
  151.                     {
  152.                         bFoundPawn = true;
  153.                         break;
  154.                     }
  155.                 if ( !bFoundPawn )
  156.                     PainTimer.SetTimer(1.0,true);
  157.             }
  158.         }
  159.     }
  160.     if ( bWaterVolume && Other.CanSplash() )
  161.         PlayEntrySplash(Other);
  162. }
  163.  
  164. function PlayEntrySplash(Actor Other)
  165. {
  166.     local float SplashSize;
  167.     local actor splash;
  168.  
  169.     splashSize = FClamp(0.00003 * Other.Mass * (250 - 0.5 * FMax(-600,Other.Velocity.Z)), 0.1, 1.0 );
  170.     if( EntrySound != None )
  171.     {
  172.         PlaySound(EntrySound, SLOT_Interact, splashSize);
  173.         if ( Other.Instigator != None )
  174.             MakeNoise(SplashSize);
  175.     }
  176.     if( EntryActor != None )
  177.     {
  178.         splash = Spawn(EntryActor); 
  179.         if ( splash != None )
  180.             splash.SetDrawScale(splashSize);
  181.     }
  182. }
  183.  
  184. event untouch(Actor Other)
  185. {
  186.     if ( bWaterVolume && Other.CanSplash() )
  187.         PlayExitSplash(Other);
  188. }
  189.  
  190. function PlayExitSplash(Actor Other)
  191. {
  192.     local float SplashSize;
  193.     local actor splash;
  194.  
  195.     splashSize = FClamp(0.003 * Other.Mass, 0.1, 1.0 );
  196.     if( ExitSound != None )
  197.         PlaySound(ExitSound, SLOT_Interact, splashSize);
  198.     if( ExitActor != None )
  199.     {
  200.         splash = Spawn(ExitActor); 
  201.         if ( splash != None )
  202.             splash.SetDrawScale(splashSize);
  203.     }
  204. }
  205.  
  206. function CausePainTo(Actor Other)
  207. {
  208.     local float depth;
  209.     local Pawn P;
  210.  
  211.     // FIXMEZONE figure out depth of actor, and base pain on that!!!
  212.     depth = 1;
  213.     P = Pawn(Other);
  214.  
  215.     if ( DamagePerSec > 0 )
  216.     {
  217.         if ( Region.Zone.bSoftKillZ && (Other.Physics != PHYS_Walking) )
  218.             return;
  219.         Other.TakeDamage(int(DamagePerSec * depth), None, Location, vect(0,0,0), DamageType); 
  220.         if ( (P != None) && (P.Controller != None) )
  221.             P.Controller.PawnIsInPain(self);
  222.     }    
  223.     else
  224.     {
  225.         if ( (P != None) && (P.Health < P.Default.Health) )
  226.         P.Health = Min(P.Default.Health, P.Health - depth * DamagePerSec);
  227.     }
  228. }
  229.  
  230. defaultproperties
  231. {
  232.     Gravity=(X=0.000000,Y=0.000000,Z=-1500.000000)
  233.     FluidFriction=+0.3
  234.     TerminalVelocity=+02500.000000
  235.     bAlwaysRelevant=true
  236.     bOnlyDirtyReplication=true
  237.     GroundFriction=+00008.000000
  238.     KBuoyancy=1.0
  239.     NetUpdateFrequency=5
  240.     bSkipActorPropertyReplication=true
  241. }