Guest User

PlayerPawn

a guest
Jan 4th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // PlayerPawn.
  3. // player controlled pawns
  4. // Note that Pawns which implement functions for the PlayerTick messages
  5. // must handle player control in these functions
  6. //=============================================================================
  7. class PlayerPawn extends Pawn
  8.     config(user)
  9.         native
  10.             NativeReplication;
  11.  
  12. // Player info.
  13. var const player Player;
  14. var globalconfig string Password;   // for restarting coop savegames
  15.  
  16. var travel    float DodgeClickTimer; // max double click interval for dodge move
  17. var(Movement) globalconfig float    DodgeClickTime;
  18. var(Movement) globalconfig float Bob;
  19. var float bobtime;
  20.  
  21. // Camera info.
  22. var int ShowFlags;
  23. var int RendMap;
  24. var int Misc1;
  25. var int Misc2;
  26.  
  27. var actor ViewTarget;
  28. var vector FlashScale, FlashFog;
  29. var vector CurrentFlashFog; // Used because FlashFog gets reset if under a threshold.
  30. var HUD myHUD;
  31. var ScoreBoard Scoring;
  32. var class<hud> HUDType;
  33. var class<scoreboard> ScoringType;
  34.  
  35. var float DesiredFlashScale, ConstantGlowScale, InstantFlash;
  36. var vector DesiredFlashFog, ConstantGlowFog, InstantFog;
  37. var float DesiredFOV;
  38. var float DefaultFOV;
  39.  
  40. // Music info.
  41. var music Song;
  42. var byte  SongSection;
  43. var byte  CdTrack;
  44. var EMusicTransition Transition;
  45.  
  46. var float shaketimer; // player uses this for shaking view
  47. var int shakemag;   // max magnitude in degrees of shaking
  48. var float shakevert; // max vertical shake magnitude
  49. var float maxshake;
  50. var float verttimer;
  51. var(Pawn) class<carcass> CarcassType;
  52. var travel globalconfig float MyAutoAim;
  53. var travel globalconfig float Handedness;
  54. var(Sounds) sound JumpSound;
  55.  
  56. // Player control flags
  57. var bool        bAdmin;
  58. var() globalconfig bool         bLookUpStairs;  // look up/down stairs (player)
  59. var() globalconfig bool     bSnapToLevel;   // Snap to level eyeheight when not mouselooking
  60. var() globalconfig bool     bAlwaysMouseLook;
  61. var globalconfig bool       bKeyboardLook;  // no snapping when true
  62. var bool        bWasForward;    // used for dodge move
  63. var bool        bWasBack;
  64. var bool        bWasLeft;
  65. var bool        bWasRight;
  66. var bool        bEdgeForward;
  67. var bool        bEdgeBack;
  68. var bool        bEdgeLeft;
  69. var bool        bEdgeRight;
  70. var bool        bIsCrouching;
  71. var bool        bShakeDir;
  72. var bool        bAnimTransition;
  73. var bool        bIsTurning;
  74. var bool        bFrozen;
  75. var globalconfig bool   bInvertMouse;
  76. var bool        bShowScores;
  77. var bool        bShowMenu;
  78. var bool        bSpecialMenu;
  79. var bool        bWokeUp;
  80. var bool        bPressedJump;
  81. var bool        bUpdatePosition;
  82. var bool        bDelayedCommand;
  83. var bool        bRising;
  84. var bool        bReducedVis;
  85. var bool        bCenterView;
  86. var() globalconfig bool bMaxMouseSmoothing;
  87. var bool        bMouseZeroed;
  88. var bool        bReadyToPlay;
  89. var globalconfig bool bNoFlash;
  90. var globalconfig bool bNoVoices;
  91. var globalconfig bool bMessageBeep;
  92. var bool        bZooming;
  93. var() bool      bSinglePlayer;      // this class allowed in single player
  94. var bool        bJustFired;
  95. var bool        bJustAltFired;
  96. var bool        bIsTyping;
  97. var bool        bFixedCamera;
  98. var globalconfig float MainFOV;
  99. var transient bool bConsoleCommandMessage; // When calling PlayerPawn.ConsoleCommand, all engine commands will output in clientmessages.
  100. var float       ZoomLevel;
  101.  
  102. var class<menu> SpecialMenu;
  103. var string DelayedCommand;
  104. var globalconfig float  MouseSensitivity;
  105.  
  106. var globalconfig name   WeaponPriority[30]; //weapon class priorities (9 is highest)
  107.  
  108. var globalconfig int NetSpeed, LanSpeed;
  109. var float SmoothMouseX, SmoothMouseY, KbdAccel;
  110. var globalconfig bool bMouseSmoothing;
  111. var() globalconfig float MouseSmoothThreshold;
  112.  
  113. // Unreal 227 additions
  114. var globalconfig bool bNeverAutoSwitch;
  115. var bool bIgnoreMusicChange;
  116. var PointRegion CameraRegion; // Player camera location
  117. var(Collision) float CrouchHeightPct;
  118. var bool bIsReducedCrouch;
  119. var transient float CrouchCheckTime;
  120. var transient bool bDistanceFogEnabled, // Client render distance fog now.
  121.         bBlendingDistanceFog;
  122. var transient plane DistanceFogColor, // Client distance fog color.
  123.         DistanceFogBlend;
  124. var transient float DistanceFogDistance[2], // Client distance fog render distance.
  125.         DistanceFogStart[2],
  126.         DistanceFogBlendTimer[2];
  127. var transient ZoneInfo DistanceFogOld; // Tracking camera zonechanges.
  128. var transient float FogDensity; // Client FogDensity. For exponential fog.
  129. var transient int FogMode; // 0 = Linear, 1 = Exponential, 2 = Exponential 2
  130.  
  131. // Input axes.
  132. var input float
  133. aBaseX, aBaseY, aBaseZ,
  134. aMouseX, aMouseY,
  135. aForward, aTurn, aStrafe, aUp,
  136. aLookUp, aExtra4, aExtra3, aExtra2,
  137. aExtra1, aExtra0;
  138.  
  139. // Move Buffering.
  140. var SavedMove SavedMoves;
  141. var SavedMove FreeMoves;
  142. var float CurrentTimeStamp;
  143. var float LastUpdateTime;
  144. var float ServerTimeStamp;
  145. var float TimeMargin;
  146. var float MaxTimeMargin;
  147.  
  148. // Progess Indicator.
  149. var string ProgressMessage[5];
  150. var color ProgressColor[5];
  151. var float ProgressTimeOut;
  152.  
  153. // Localized strings
  154. var localized string QuickSaveString;
  155. var localized string NoPauseMessage;
  156. var localized string ViewingFrom;
  157. var localized string OwnCamera;
  158. var localized string FailedView;
  159. var localized string CantChangeNameMsg;
  160.  
  161. // ReplicationInfo
  162. var GameReplicationInfo GameReplicationInfo;
  163.  
  164. // ngWorldStats Logging
  165. var() globalconfig string ngWorldSecret;
  166.  
  167. // Remote Pawn ViewTargets
  168. var rotator TargetViewRotation;
  169. var float TargetEyeHeight;
  170. var vector TargetWeaponViewOffset;
  171.  
  172. // CameraLocation
  173. var vector CalcCameraLocation;
  174. var rotator CalcCameraRotation;
  175. var float LastCameraUpdate;
  176.  
  177. var LadderTrigger ActiveLadder;
  178.  
  179. replication
  180. {
  181.     // Things the server should send to the client.
  182.     reliable if ( Role==ROLE_Authority && bNetOwner )
  183.         ViewTarget, ScoringType, HUDType, GameReplicationInfo, bFixedCamera;
  184.     unreliable if ( Role==ROLE_Authority && bNetOwner )
  185.         TargetViewRotation, TargetEyeHeight, TargetWeaponViewOffset;
  186.  
  187.     // Things the client should send to the server
  188.     reliable if ( Role<ROLE_Authority )
  189.         WeaponPriority, Password, bReadyToPlay;
  190.  
  191.     // Functions client can call.
  192.     unreliable if ( Role<ROLE_Authority )
  193.         CallForHelp;
  194.     reliable if ( Role<ROLE_Authority )
  195.         ShowPath, RememberSpot, Speech, Say, TeamSay, RestartLevel, SwitchWeapon, Pause, SetPause, ServerSetHandedness,
  196.         PrevItem, ActivateItem, ShowInventory, Grab, ServerFeignDeath, ServerSetWeaponPriority,
  197.         ChangeName, ChangeTeam, God, Suicide, ViewClass, ViewPlayerNum, ViewSelf, ViewPlayer, ServerSetSloMo, ServerAddBots,
  198.         PlayersOnly, ThrowWeapon, ServerRestartPlayer, NeverSwitchOnPickup,
  199.         PrevWeapon, NextWeapon, ServerReStartGame, ServerUpdateWeapons, ServerTaunt, ServerChangeSkin,
  200.         SwitchLevel, SwitchCoopLevel, Kick, KillAll, Summon, ActivateTranslator, Admin, Typing;
  201.     unreliable if ( Role==ROLE_AutonomousProxy )
  202.         ServerMove, Fly, Walk, Ghost;
  203.  
  204.  
  205.     // Functions server can call.
  206.     reliable if ( Role==ROLE_Authority )
  207.         ClientAdjustGlow, ClientTravel, ClientSetMusic, StartZoom, ToggleZoom, StopZoom, EndZoom, SetDesiredFOV, ClearProgressMessages, SetProgressColor, SetProgressMessage, SetProgressTime;
  208.     unreliable if ( Role==ROLE_Authority )
  209.         SetFOVAngle, ClientShake, ClientFlash, ClientInstantFlash;
  210.     unreliable if ( Role==ROLE_Authority && !bDemoRecording )
  211.         ClientPlaySound;
  212.     unreliable if ( Role==ROLE_Authority && (RemoteRole==ROLE_AutonomousProxy) )
  213.         ClientAdjustPosition;
  214.  
  215.     // Input variables.
  216.     unreliable if ( Role<ROLE_AutonomousProxy )
  217.         aBaseX, aBaseY, aBaseZ,
  218.         aMouseX, aMouseY,
  219.         aForward, aTurn, aStrafe, aUp,
  220.         aLookUp, aExtra4, aExtra3, aExtra2,
  221.         aExtra1, aExtra0;
  222. }
  223.  
  224. //
  225. // native client-side functions.
  226. //
  227. native event ClientTravel( string URL, ETravelType TravelType, bool bItems );
  228. native(544) final function ResetKeyboard();
  229. native(546) final function UpdateURL(string NewOption, string NewValue, bool bSaveDefault);
  230. native(549) final function bool IsPressing( byte KeyNum ); // Returns true if player is holding down key.
  231. native final function LevelInfo GetEntryLevel();
  232. native final function int GetClientVersion(); // Return the client version.
  233. native final function int GetClientSubVersion(); // Return the client version.
  234. native final function string GetCompileTime(); // Return the time and date when this version was built.
  235.  
  236. // Execute a console command in the context of this player, then forward to Actor.ConsoleCommand.
  237. // 227 added command: ConsoleCommand("UGetIP"); for returning desired client's IP
  238. native function string ConsoleCommand( string Command );
  239.  
  240. /* Clipboard functions, no Linux support yet, sorry. */
  241. static final native function CopyToClipboard( string Text );
  242. static final native function string PasteFromClipboard();
  243.  
  244. // Called from native command 'UGetFullClientList <validation code>'/'UGetBanList <validation code>'/'UGetTBanList <validation code>'
  245. // Used by Unreal 227 Admin GUI interface.
  246. event UPlayerListResponse( string Resp, string PlayerNm, int ID, string PlayerIP, string ClientID )
  247. {
  248.     ClientMessage("@"$Resp$ID@PlayerIP@ClientID@PlayerNm,'Log',False);
  249. }
  250.  
  251.  
  252. event PreClientTravel()
  253. {
  254. }
  255.  
  256. exec function Ping()
  257. {
  258.     ClientMessage("Current ping is"@PlayerReplicationInfo.Ping);
  259. }
  260.  
  261. simulated event RenderOverlays( canvas Canvas )
  262. {
  263.     if ( Weapon != None )
  264.         Weapon.RenderOverlays(Canvas);
  265.  
  266.     if ( myHUD != None )
  267.         myHUD.RenderOverlays(Canvas);
  268. }
  269.  
  270. exec function ViewPlayerNum(optional int num)
  271. {
  272.     local Pawn P;
  273.  
  274.     if ( num >= 0 )
  275.     {
  276.         P = Pawn(ViewTarget);
  277.         if ( P != None && P.PlayerReplicationInfo != none && P.PlayerReplicationInfo.TeamID == num
  278.                 || PlayerReplicationInfo.TeamID == num )
  279.         {
  280.             ViewTarget = None;
  281.             bBehindView = false;
  282.             ClientMessage(ViewingFrom $ OwnCamera, 'Event', true);
  283.             return;
  284.         }
  285.         for ( P=Level.PawnList; P!=None; P=P.NextPawn )
  286.             if ( P.PlayerReplicationInfo != none
  287.                     && Level.Game.CanSpectate(self, P)
  288.                     && P.PlayerReplicationInfo.Team == PlayerReplicationInfo.Team
  289.                     && P.PlayerReplicationInfo.TeamID == num )
  290.             {
  291.                 ViewTarget = P;
  292.                 bBehindView = true;
  293.                 ClientMessage(ViewingFrom $ Pawn(ViewTarget).PlayerReplicationInfo.PlayerName, 'Event', true);
  294.                 return;
  295.             }
  296.         ClientMessage(FailedView);
  297.         return;
  298.     }
  299.     if ( Role == ROLE_Authority )
  300.     {
  301.         ViewClass(class'Pawn', true);
  302.         While ( (ViewTarget != None)
  303.                 && (Pawn(ViewTarget).PlayerReplicationInfo == none || Pawn(ViewTarget).PlayerReplicationInfo.bIsSpectator) )
  304.             ViewClass(class'Pawn', true);
  305.  
  306.         if ( ViewTarget != None )
  307.             ClientMessage(ViewingFrom$Pawn(ViewTarget).PlayerReplicationInfo.PlayerName, 'Event', true);
  308.         else
  309.             ClientMessage(ViewingFrom$OwnCamera, 'Event', true);
  310.     }
  311. }
  312.  
  313. exec function Profile()
  314. {
  315.     //TEMP for performance measurement
  316.  
  317.     ClientMessage("Average AI Time"@Level.AvgAITime);
  318.     ClientMessage(" < 5% "$Level.AIProfile[0]);
  319.     ClientMessage(" < 10% "$Level.AIProfile[1]);
  320.     ClientMessage(" < 15% "$Level.AIProfile[2]);
  321.     ClientMessage(" < 20% "$Level.AIProfile[3]);
  322.     ClientMessage(" < 25% "$Level.AIProfile[4]);
  323.     ClientMessage(" < 30% "$Level.AIProfile[5]);
  324.     ClientMessage(" < 35% "$Level.AIProfile[6]);
  325.     ClientMessage(" > 35% "$Level.AIProfile[7]);
  326. }
  327.  
  328. // Execute an administrative console command on the server.
  329. exec function Admin( string CommandLine )
  330. {
  331.     local string Result;
  332.  
  333.     if ( Level.Game.GetAccessManager().CanExecuteCheatStr(Self,'Admin',CommandLine) )
  334.     {
  335.         bConsoleCommandMessage = true;
  336.         if ( Level.Game.GameRules!=None )
  337.             Result = Level.Game.GameRules.ExecAdminCmd(Self,CommandLine);
  338.         else Result = ConsoleCommand( CommandLine );
  339.         bConsoleCommandMessage = false;
  340.         if ( Len(Result)>0 )
  341.             ClientMessage( Result );
  342.     }
  343. }
  344. exec function PlayerList()
  345. {
  346.     local PlayerReplicationInfo PRI;
  347.  
  348.     log("Player List:");
  349.     ForEach AllActors(class'PlayerReplicationInfo', PRI)
  350.     log(PRI.PlayerName@"( ping"@PRI.Ping$")");
  351. }
  352. //
  353. // native server-side functions
  354. //
  355. event ClientMessage( coerce string S, optional Name Type, optional bool bBeep )
  356. {
  357.     if (Player == None)
  358.         return;
  359.  
  360.     if (Type == '')
  361.         Type = 'Event';
  362.  
  363.     if (Player.Console != None)
  364.         Player.Console.Message( PlayerReplicationInfo, S, Type );
  365.     if (bBeep && bMessageBeep)
  366.         PlayBeepSound();
  367.     if ( myHUD != None )
  368.         myHUD.Message( PlayerReplicationInfo, S, Type );
  369. }
  370.  
  371. event TeamMessage( PlayerReplicationInfo PRI, coerce string S, name Type )
  372. {
  373.     Class'GameInfo'.Static.StripColorCodes(S);
  374.     if (Player.Console != None)
  375.         Player.Console.Message ( PRI, S, Type );
  376.     if (bMessageBeep)
  377.         PlayBeepSound();
  378.     if ( myHUD != None )
  379.         myHUD.Message( PRI, S, Type );
  380. }
  381.  
  382. function ClientVoiceMessage(PlayerReplicationInfo Sender, PlayerReplicationInfo Recipient, name messagetype, byte messageID)
  383. {
  384.     local VoicePack V;
  385.  
  386.     if ( Player==None || (Sender.voicetype==None) || (Player.Console==None) )
  387.         return;
  388.        
  389.     V = Spawn(Sender.voicetype, self);
  390.     if ( V != None )
  391.         V.ClientInitialize(Sender, Recipient, messagetype, messageID);
  392. }
  393.  
  394. simulated function PlayBeepSound();
  395.  
  396. // 227g: Moved from UpdateView/ServerMove to here.
  397. function UpdatePawnRotation( rotator Rot )
  398. {
  399.     if( Rotation!=Rot )
  400.         SetRotation(Rot);
  401. }
  402.  
  403. //
  404. // Send movement to the server.
  405. // Passes acceleration in components so it doesn't get rounded.
  406. //
  407. function ServerMove
  408. (
  409.     float TimeStamp,
  410.     vector InAccel,
  411.     vector ClientLoc,
  412.     bool NewbRun,
  413.     bool NewbDuck,
  414.     bool NewbPressedJump,
  415.     bool bFired,
  416.     bool bAltFired,
  417.     eDodgeDir DodgeMove,
  418.     byte ClientRoll,
  419.     int View
  420. )
  421. {
  422.     local float DeltaTime, clientErr;
  423.     local rotator DeltaRot, Rot;
  424.     local vector Accel, LocDiff;
  425.     local int maxPitch, ViewPitch, ViewYaw;
  426.     local actor OldBase;
  427.  
  428.     // View components
  429.     ViewPitch = View/32768;
  430.     ViewYaw = 2 * (View - 32768 * ViewPitch);
  431.     ViewPitch *= 2;
  432.     // Make acceleration.
  433.     Accel = InAccel/10;
  434.  
  435.     // If this move is outdated, discard it.
  436.     if ( CurrentTimeStamp >= TimeStamp )
  437.         return;
  438.  
  439.     // handle firing and alt-firing
  440.     if ( bFired )
  441.     {
  442.         if ( bFire == 0 )
  443.         {
  444.             Fire(0);
  445.             bFire = 1;
  446.         }
  447.     }
  448.     else
  449.         bFire = 0;
  450.  
  451.  
  452.     if ( bAltFired )
  453.     {
  454.         if ( bAltFire == 0 )
  455.         {
  456.             AltFire(0);
  457.             bAltFire = 1;
  458.         }
  459.     }
  460.     else
  461.         bAltFire = 0;
  462.  
  463.     // Save move parameters.
  464.     DeltaTime = TimeStamp - CurrentTimeStamp;
  465.     if ( ServerTimeStamp > 0 )
  466.     {
  467.         TimeMargin += DeltaTime - 1.01 * (Level.TimeSeconds - ServerTimeStamp);
  468.         if ( TimeMargin > MaxTimeMargin )
  469.         {
  470.             // player is too far ahead
  471.             TimeMargin -= DeltaTime;
  472.             if ( TimeMargin < 0.5 )
  473.                 MaxTimeMargin = 1.0;
  474.             else
  475.                 MaxTimeMargin = 0.5;
  476.             DeltaTime = 0;
  477.         }
  478.         else if ( TimeMargin < -MaxTimeMargin ) // player is too far behind.
  479.             TimeMargin = -MaxTimeMargin;
  480.     }
  481.  
  482.     CurrentTimeStamp = TimeStamp;
  483.     ServerTimeStamp = Level.TimeSeconds;
  484.     Rot.Roll = 256 * ClientRoll;
  485.     Rot.Yaw = ViewYaw;
  486.     if ( (Physics == PHYS_Swimming) || (Physics == PHYS_Flying) )
  487.         maxPitch = 2;
  488.     else
  489.         maxPitch = 1;
  490.     If ( (ViewPitch > maxPitch * RotationRate.Pitch) && (ViewPitch < 65536 - maxPitch * RotationRate.Pitch) )
  491.     {
  492.         If (ViewPitch < 32768)
  493.         Rot.Pitch = maxPitch * RotationRate.Pitch;
  494.         else
  495.             Rot.Pitch = 65536 - maxPitch * RotationRate.Pitch;
  496.     }
  497.     else
  498.         Rot.Pitch = ViewPitch;
  499.     DeltaRot = (Rotation - Rot);
  500.     ViewRotation.Pitch = ViewPitch;
  501.     ViewRotation.Yaw = ViewYaw;
  502.     ViewRotation.Roll = 0;
  503.     UpdatePawnRotation(Rot);
  504.  
  505.     OldBase = Base;
  506.  
  507.     // Perform actual movement.
  508.     if ( Len(Level.Pauser)==0 && (DeltaTime > 0) )
  509.         MoveAutonomous(DeltaTime, NewbRun, NewbDuck, NewbPressedJump, DodgeMove, Accel, DeltaRot);
  510.  
  511.     // Accumulate movement error.
  512.     if ( Level.TimeSeconds - LastUpdateTime > 0.3 )
  513.     {
  514.         ClientErr = 10000;
  515.     }
  516.     else if ( Level.TimeSeconds - LastUpdateTime > 0.07 )
  517.     {
  518.         LocDiff = Location - ClientLoc;
  519.         ClientErr = LocDiff Dot LocDiff;
  520.     }
  521.  
  522.     // If client has accumulated a noticeable positional error, correct him.
  523.     if ( ClientErr > 3 )
  524.     {
  525.         if ( Mover(Base) != None )
  526.             ClientLoc = Location - Base.Location;
  527.         else
  528.             ClientLoc = Location;
  529.         // log("Client Error at "$TimeStamp$" is "$ClientErr$" with Velocity "$Velocity$" LocDiff "$LocDiff$" Physics "$Physics);
  530.         LastUpdateTime = Level.TimeSeconds;
  531.         ClientAdjustPosition
  532.         (
  533.             TimeStamp,
  534.             GetStateName(),
  535.             Physics,
  536.             ClientLoc.X,
  537.             ClientLoc.Y,
  538.             ClientLoc.Z,
  539.             Velocity.X,
  540.             Velocity.Y,
  541.             Velocity.Z,
  542.             Base
  543.         );
  544.     }
  545.     //log("Server "$Role$" moved "$self$" stamp "$TimeStamp$" location "$Location$" Acceleration "$Acceleration$" Velocity "$Velocity);
  546. }
  547.  
  548. function ProcessMove ( float DeltaTime, vector newAccel, eDodgeDir DodgeMove, rotator DeltaRot)
  549. {
  550.     Acceleration = newAccel;
  551. }
  552.  
  553. final function MoveAutonomous
  554. (
  555.     float DeltaTime,
  556.     bool NewbRun,
  557.     bool NewbDuck,
  558.     bool NewbPressedJump,
  559.     eDodgeDir DodgeMove,
  560.     vector newAccel,
  561.     rotator DeltaRot
  562. )
  563. {
  564.     if ( NewbRun )
  565.         bRun = 1;
  566.     else
  567.         bRun = 0;
  568.  
  569.     if ( NewbDuck )
  570.         bDuck = 1;
  571.     else
  572.         bDuck = 0;
  573.     bPressedJump = NewbPressedJump;
  574.  
  575.     HandleWalking();
  576.     ProcessMove(DeltaTime, newAccel, DodgeMove, DeltaRot);
  577.     AutonomousPhysics(DeltaTime);
  578.     //log("Role "$Role$" moveauto time "$100 * DeltaTime$" ("$Level.TimeDilation$")");
  579. }
  580.  
  581. // ClientAdjustPosition - pass newloc and newvel in components so it doesn't get rounded
  582.  
  583. function ClientAdjustPosition
  584. (
  585.     float TimeStamp,
  586.     name newState,
  587.     EPhysics newPhysics,
  588.     float NewLocX,
  589.     float NewLocY,
  590.     float NewLocZ,
  591.     float NewVelX,
  592.     float NewVelY,
  593.     float NewVelZ,
  594.     Actor NewBase
  595. )
  596. {
  597.     local Decoration Carried;
  598.     local vector OldLoc, NewLocation;
  599.  
  600.     if ( CurrentTimeStamp > TimeStamp )
  601.         return;
  602.     CurrentTimeStamp = TimeStamp;
  603.  
  604.     NewLocation.X = NewLocX;
  605.     NewLocation.Y = NewLocY;
  606.     NewLocation.Z = NewLocZ;
  607.     Velocity.X = NewVelX;
  608.     Velocity.Y = NewVelY;
  609.     Velocity.Z = NewVelZ;
  610.  
  611.     SetBase(NewBase);
  612.     if ( Mover(NewBase) != None )
  613.         NewLocation += NewBase.Location;
  614.  
  615.     //log("Client "$Role$" adjust "$self$" stamp "$TimeStamp$" location "$Location$" new location "$NewLocation);
  616.     Carried = CarriedDecoration;
  617.     OldLoc = Location;
  618.     SetLocation(NewLocation);
  619.  
  620.     if ( Carried != None )
  621.     {
  622.         CarriedDecoration = Carried;
  623.         CarriedDecoration.SetLocation(NewLocation + CarriedDecoration.Location - OldLoc);
  624.         CarriedDecoration.SetPhysics(PHYS_None);
  625.         CarriedDecoration.SetBase(self);
  626.     }
  627.     SetPhysics(newPhysics);
  628.     //FIXME - don't do this state update if client dead???
  629.     if ( !IsInState(newState) )
  630.         GotoState(newState);
  631.  
  632.     bUpdatePosition = true;
  633. }
  634.  
  635. function ClientUpdatePosition()
  636. {
  637.     local SavedMove CurrentMove;
  638.     local int realbRun, realbDuck;
  639.     local bool bRealJump;
  640.  
  641.     realbRun = bRun;
  642.     realbDuck = bDuck;
  643.     bRealJump = bPressedJump;
  644.     CurrentMove = SavedMoves;
  645.     while ( CurrentMove != None )
  646.     {
  647.         if ( CurrentMove.TimeStamp <= CurrentTimeStamp )
  648.         {
  649.             SavedMoves = CurrentMove.NextMove;
  650.             CurrentMove.NextMove = FreeMoves;
  651.             FreeMoves = CurrentMove;
  652.             FreeMoves.Clear();
  653.             CurrentMove = SavedMoves;
  654.         }
  655.         else
  656.         {
  657.             CrouchCheckTime = -1;
  658.             MoveAutonomous(CurrentMove.Delta, CurrentMove.bRun, CurrentMove.bDuck, CurrentMove.bPressedJump, CurrentMove.DodgeMove, CurrentMove.Acceleration, rot(0,0,0));
  659.             CurrentMove = CurrentMove.NextMove;
  660.         }
  661.     }
  662.     bDuck = realbDuck;
  663.     bRun = realbRun;
  664.     bPressedJump = bRealJump;
  665.     CrouchCheckTime = -1;
  666.     bUpdatePosition = false;
  667.     //log("Client adjusted "$self$" stamp "$CurrentTimeStamp$" location "$Location$" dodge "$DodgeDir);
  668. }
  669.  
  670. final function SavedMove GetFreeMove()
  671. {
  672.     local SavedMove s;
  673.  
  674.     if ( FreeMoves == None )
  675.         return Spawn(class'SavedMove');
  676.     else
  677.     {
  678.         s = FreeMoves;
  679.         FreeMoves = FreeMoves.NextMove;
  680.         s.NextMove = None;
  681.         return s;
  682.     }
  683. }
  684.  
  685. //
  686. // Replicate this client's desired movement to the server.
  687. //
  688. final function ReplicateMove
  689. (
  690.     float DeltaTime,
  691.     vector NewAccel,
  692.     eDodgeDir DodgeMove,
  693.     rotator DeltaRot
  694. )
  695. {
  696.     local SavedMove NewMove;
  697.     local byte ClientRoll;
  698.  
  699.     // if am network client and am carrying flag -
  700.     //  make its position look good client side
  701.     if ( (PlayerReplicationInfo != None)
  702.             && (PlayerReplicationInfo.HasFlag != None) )
  703.         PlayerReplicationInfo.HasFlag.FollowHolder(self);
  704.  
  705.     // Get a SavedMove actor to store the movement in.
  706.     if ( SavedMoves == None )
  707.     {
  708.         SavedMoves = GetFreeMove();
  709.         NewMove = SavedMoves;
  710.     }
  711.     else
  712.     {
  713.         NewMove = SavedMoves;
  714.         while ( NewMove.NextMove != None )
  715.             NewMove = NewMove.NextMove;
  716.         if ( NewMove.bSent )
  717.         {
  718.             NewMove.NextMove = GetFreeMove();
  719.             NewMove = NewMove.NextMove;
  720.         }
  721.     }
  722.  
  723.     NewMove.Delta = DeltaTime;
  724.     if ( VSize(NewAccel) > 3072 )
  725.         NewAccel = 3072 * Normal(NewAccel);
  726.     NewMove.Acceleration = NewAccel;
  727.  
  728.     // Set this move's data.
  729.     NewMove.DodgeMove = DodgeMove;
  730.     NewMove.TimeStamp = Level.TimeSeconds;
  731.     NewMove.bRun = (bRun > 0);
  732.     NewMove.bDuck = (bDuck > 0);
  733.     NewMove.bIsReducedCrouch = bIsReducedCrouch;
  734.     NewMove.bPressedJump = bPressedJump;
  735.     if ( Weapon != None ) // approximate pointing so don't have to replicate
  736.         Weapon.bPointing = ((bFire != 0) || (bAltFire != 0));
  737.  
  738.     // Simulate the movement locally.
  739.     ProcessMove(DeltaTime, NewAccel, DodgeMove, DeltaRot);
  740.     AutonomousPhysics(DeltaTime);
  741.     //log("Role "$Role$" repmove at "$Level.TimeSeconds$" Move time "$100 * DeltaTime$" ("$Level.TimeDilation$")");
  742.  
  743.     // Send to the server
  744.     NewMove.bSent = true;
  745.     ClientRoll = (Rotation.Roll >> 8) & 255;
  746.     ServerMove
  747.     (
  748.         NewMove.TimeStamp,
  749.         NewMove.Acceleration * 10,
  750.         Location,
  751.         NewMove.bRun,
  752.         NewMove.bDuck,
  753.         NewMove.bPressedJump,
  754.         (bJustFired || (bFire != 0)),
  755.         (bJustAltFired || (bAltFire != 0)),
  756.         NewMove.DodgeMove,
  757.         ClientRoll,
  758.         (32767 & (ViewRotation.Pitch/2)) * 32768 + (32767 & (ViewRotation.Yaw/2))
  759.     );
  760.     bJustFired = false;
  761.     bJustAltFired = false;
  762.     //log("Replicated "$self$" stamp "$NewMove.TimeStamp$" location "$Location$" dodge "$NewMove.DodgeMove$" to "$DodgeDir);
  763. }
  764.  
  765. function HandleWalking()
  766. {
  767.     local rotator carried;
  768.  
  769.     bIsWalking = ((bRun != 0) || (bDuck != 0) || bIsReducedCrouch) && !Region.Zone.IsA('WarpZoneInfo');
  770.     bNoStopAtLedge = (bDuck==0 && bIsReducedCrouch);
  771.     if ( (Role == ROLE_Authority) && (standingcount == 0) )
  772.         CarriedDecoration = None;
  773.     if ( CarriedDecoration != None ) //verify its still in front
  774.     {
  775.         bIsWalking = true;
  776.         if ( Role == ROLE_Authority )
  777.         {
  778.             carried = Rotator(CarriedDecoration.Location - Location);
  779.             carried.Yaw = ((carried.Yaw & 65535) - (Rotation.Yaw & 65535)) & 65535;
  780.             if ( (carried.Yaw > 3072) && (carried.Yaw < 62463) )
  781.                 DropDecoration();
  782.         }
  783.     }
  784. }
  785.  
  786. //----------------------------------------------
  787.  
  788. event Destroyed()
  789. {
  790.     Super.Destroyed();
  791.     if ( myHud != None )
  792.         myHud.Destroy();
  793.     if ( Scoring != None )
  794.         Scoring.Destroy();
  795. }
  796.  
  797. function ServerReStartGame()
  798. {
  799.     local GameRules G;
  800.  
  801.     if ( Level.Game.GameRules!=None )
  802.     {
  803.         for ( G=Level.Game.GameRules; G!=None; G=G.NextRules )
  804.             if ( G.bHandleMapEvents && !G.CanRestartGame(Self) )
  805.                 Return;
  806.     }
  807.     if (IsInState('GameEnded'))
  808.         Level.Game.RestartGame();
  809. }
  810.  
  811. function PlayHit(float Damage, vector HitLocation, name damageType, float MomentumZ)
  812. {
  813.     Level.Game.SpecialDamageString = "";
  814. }
  815.  
  816. function SetFOVAngle(float newFOV)
  817. {
  818.     FOVAngle = newFOV;
  819. }
  820.  
  821. function ClientFlash( float scale, vector fog )
  822. {
  823.     DesiredFlashScale = scale;
  824.     DesiredFlashFog = 0.001 * fog;
  825. }
  826.  
  827. function ClientInstantFlash( float scale, vector fog )
  828. {
  829.     InstantFlash = scale;
  830.     InstantFog = 0.001 * fog;
  831. }
  832.  
  833. //Play a sound client side (so only client will hear it
  834. simulated function ClientPlaySound(sound ASound, optional ESoundSlot SlotType )
  835. {
  836.     if ( ViewTarget != None )
  837.         ViewTarget.PlaySound(ASound, SlotType, 255, true);
  838.     PlaySound(ASound, SlotType, 255, true);
  839. }
  840.  
  841. function ClientAdjustGlow( float scale, vector fog )
  842. {
  843.     ConstantGlowScale += scale;
  844.     ConstantGlowFog += 0.001 * fog;
  845. }
  846.  
  847. function ClientShake(vector shake)
  848. {
  849.     if ( (shakemag < shake.X) || (shaketimer <= 0.01 * shake.Y) )
  850.     {
  851.         shakemag = shake.X;
  852.         shaketimer = 0.01 * shake.Y;
  853.         maxshake = 0.01 * shake.Z;
  854.         verttimer = 0;
  855.         ShakeVert = -1.1 * maxshake;
  856.     }
  857. }
  858.  
  859. function ShakeView( float shaketime, float RollMag, float vertmag)
  860. {
  861.     local vector shake;
  862.  
  863.     shake.X = RollMag;
  864.     shake.Y = 100 * shaketime;
  865.     shake.Z = 100 * vertmag;
  866.     ClientShake(shake);
  867. }
  868.  
  869. function ClientSetMusic( music NewSong, byte NewSection, byte NewCdTrack, EMusicTransition NewTransition )
  870. {
  871.     if ( bIgnoreMusicChange )
  872.         Return;
  873.     Song        = NewSong;
  874.     SongSection = NewSection;
  875.     CdTrack     = NewCdTrack;
  876.     Transition  = NewTransition;
  877. }
  878.  
  879. function ServerFeignDeath()
  880. {
  881.     PendingWeapon = Weapon;
  882.     if ( Weapon != None )
  883.         Weapon.PutDown();
  884.     GotoState('FeigningDeath');
  885. }
  886.  
  887. function ServerSetHandedness( float hand)
  888. {
  889.     Handedness = hand;
  890.     if ( Weapon != None )
  891.         Weapon.SetHand(Handedness);
  892. }
  893.  
  894. function ServerReStartPlayer()
  895. {
  896.     local GameRules G;
  897.  
  898.     //log("calling restartplayer in dying with netmode "$Level.NetMode);
  899.     if ( Level.NetMode == NM_Client )
  900.         return;
  901.     if ( Level.Game.GameRules!=None )
  902.     {
  903.         for ( G=Level.Game.GameRules; G!=None; G=G.NextRules )
  904.             if ( G.bHandleMapEvents && !G.CanRestartPlayer(Self) )
  905.                 Return;
  906.     }
  907.     if ( Level.Game.RestartPlayer(self) )
  908.     {
  909.         //log("server restart client");
  910.         ServerTimeStamp = 0;
  911.         TimeMargin = 0;
  912.         Level.Game.StartPlayer(self);
  913.         BaseEyeHeight = Default.BaseEyeHeight;
  914.         EyeHeight = BaseEyeHeight;
  915.         PlayWaiting();
  916.         ClientReStart();
  917.     }
  918.     else
  919.         log("Restartplayer failed");
  920. }
  921.  
  922. function ServerChangeSkin( coerce string SkinName, coerce string FaceName, byte TeamNum )
  923. {
  924.     local string MeshName;
  925.  
  926.     MeshName = GetItemName(string(Mesh));
  927.     if ( Level.Game.bCanChangeSkin
  928.             /* && (SkinName == "" || Left(SkinName, Len(MeshName)) ~= MeshName) */)
  929.     {
  930.         Self.static.SetMultiSkin(Self, SkinName, FaceName, TeamNum );
  931.     }
  932. }
  933.  
  934. simulated final function plane ColorToPlane( Color C )
  935. {
  936.     local plane P;
  937.  
  938.     P.X = C.R/255.f;
  939.     P.Y = C.G/255.f;
  940.     P.Z = C.B/255.f;
  941.     P.W = C.A/255.f;
  942.     return P;
  943. }
  944.  
  945. // Called by Render Engine client side.
  946. simulated event UpdateDistanceFog()
  947. {
  948.     if( DistanceFogOld!=CameraRegion.Zone )
  949.     {
  950.         InitNewFogZone(CameraRegion.Zone);
  951.         DistanceFogOld = CameraRegion.Zone;
  952.     }
  953.     else if( bBlendingDistanceFog )
  954.         UpdateFogBlending(CameraRegion.Zone);
  955. }
  956. simulated final function InitNewFogZone( ZoneInfo Z )
  957. {
  958.     if( !bDistanceFogEnabled && !Z.bDistanceFog)
  959.         return; // No blending needed.
  960.  
  961.     FogMode = Z.FogMode;
  962.  
  963.     bBlendingDistanceFog = (Z.FadeTime>0.f);
  964.     if( !bBlendingDistanceFog )
  965.     {
  966.         // No blending needed.
  967.         DistanceFogColor = ColorToPlane(Z.FogColor);
  968.         DistanceFogDistance[0] = Z.FogDistanceStart;
  969.         DistanceFogDistance[1] = Z.FogDistance;
  970.         bDistanceFogEnabled = Z.bDistanceFog;
  971.         FogDensity = Z.FogDensity;
  972.     }
  973.     else
  974.     {
  975.         if( !bDistanceFogEnabled ) // Fade in from infinitive.
  976.         {
  977.             DistanceFogBlend = ColorToPlane(Z.FogColor);
  978.             DistanceFogColor = DistanceFogBlend;
  979.             DistanceFogStart[0] = Z.FogDistanceStart+5000.f;
  980.             DistanceFogStart[1] = Z.FogDistance+5000.f;
  981.             FogDensity = Z.FogDensity/10;
  982.         }
  983.         else
  984.         {
  985.             DistanceFogBlend = DistanceFogColor;
  986.             DistanceFogStart[0] = DistanceFogDistance[0];
  987.             DistanceFogStart[1] = DistanceFogDistance[1];
  988.             FogDensity = 0.01;
  989.         }
  990.         DistanceFogBlendTimer[0] = Level.TimeSeconds+Z.FadeTime;
  991.         DistanceFogBlendTimer[1] = Z.FadeTime;
  992.         bDistanceFogEnabled = true;
  993.     }
  994. }
  995. simulated final function UpdateFogBlending( ZoneInfo Z )
  996. {
  997.     local float A,NA;
  998.     local plane P;
  999.  
  1000.     A = (DistanceFogBlendTimer[0]-Level.TimeSeconds)/DistanceFogBlendTimer[1]; // Get alpha
  1001.     if( A<=0.f ) // Blending complete.
  1002.     {
  1003.         if( !Z.bDistanceFog )
  1004.             bDistanceFogEnabled = false;
  1005.         else
  1006.         {
  1007.             DistanceFogColor = ColorToPlane(Z.FogColor);
  1008.             DistanceFogDistance[0] = Z.FogDistanceStart;
  1009.             DistanceFogDistance[1] = Z.FogDistance;
  1010.             FogDensity = Z.FogDensity;
  1011.         }
  1012.         bBlendingDistanceFog = false;
  1013.         return;
  1014.     }
  1015.     NA = (1.f-A); // Get negative alpha.
  1016.  
  1017.     if( !Z.bDistanceFog ) // Fade out to infinitive distance.
  1018.     {
  1019.         DistanceFogDistance[0] = (5000.f*NA+DistanceFogStart[0]);
  1020.         DistanceFogDistance[1] = (5000.f*NA+DistanceFogStart[1]);
  1021.         FogDensity = A/1000;
  1022.     }
  1023.     else
  1024.     {
  1025.         P = ColorToPlane(Z.FogColor);
  1026.         DistanceFogColor.X = (P.X*NA+DistanceFogBlend.X*A);
  1027.         DistanceFogColor.Y = (P.Y*NA+DistanceFogBlend.Y*A);
  1028.         DistanceFogColor.Z = (P.Z*NA+DistanceFogBlend.Z*A);
  1029.         DistanceFogColor.W = (P.W*NA+DistanceFogBlend.W*A);
  1030.         DistanceFogDistance[0] = (Z.FogDistanceStart*NA+DistanceFogStart[0]*A);
  1031.         DistanceFogDistance[1] = (Z.FogDistance*NA+DistanceFogStart[1]*A);
  1032.         FogDensity =  Z.FogDensity-A/1000;
  1033.     }
  1034. }
  1035.  
  1036. //*************************************************************************************
  1037. // Normal gameplay execs
  1038. // Type the name of the exec function at the console to execute it
  1039.  
  1040. exec function ShowSpecialMenu( string ClassName )
  1041. {
  1042.     local class<menu> aMenu${1}< ${3} >
  1043.  
  1044.     aMenuClass = class<menu>( DynamicLoadObject( ClassName, class'Class' ) );
  1045.     if ( aMenuClass!=None )
  1046.     {
  1047.         bSpecialMenu = true;
  1048.         SpecialMenu = aMenu${1}< ${3} >
  1049.         ShowMenu();
  1050.     }
  1051. }
  1052.  
  1053. exec function Jump( optional float F )
  1054. {
  1055.     bPressedJump = true;
  1056. }
  1057.  
  1058. exec function CauseEvent( name N )
  1059. {
  1060.     if ( Level.NetMode==NM_Client )
  1061.     {
  1062.         Admin("CauseEvent"@N);
  1063.         Return; // We are a client, pass it to server.
  1064.     }
  1065.     if ( Level.Game.GetAccessManager().CanExecuteCheatStr(Self,'CauseEvent',string(N)) )
  1066.         TriggerEvent(N,Self,Self);
  1067. }
  1068.  
  1069. exec function Taunt( name Sequence )
  1070. {
  1071.     if ( HasAnim(Sequence) && GetAnimGroup(Sequence) == 'Gesture' )
  1072.     {
  1073.         ServerTaunt(Sequence);
  1074.         PlayAnim(Sequence, 0.7, 0.2);
  1075.     }
  1076. }
  1077.  
  1078. function ServerTaunt(name Sequence )
  1079. {
  1080.     if ( HasAnim(Sequence) && GetAnimGroup(Sequence)=='Gesture' )
  1081.         PlayAnim(Sequence, 0.7, 0.2);
  1082. }
  1083.  
  1084. exec function FeignDeath()
  1085. {
  1086. }
  1087.  
  1088. exec function CallForHelp()
  1089. {
  1090.     local Pawn P;
  1091.  
  1092.     if ( !Level.Game.bTeamGame || (Enemy == None) || (Enemy.Health <= 0) )
  1093.         return;
  1094.  
  1095.     for ( P=Level.PawnList; P!=None; P=P.NextPawn )
  1096.         if ( P.bIsPlayer && (P.PlayerReplicationInfo.Team == PlayerReplicationInfo.Team) )
  1097.             P.HandleHelpMessageFrom(self);
  1098. }
  1099.  
  1100. function damageAttitudeTo(pawn Other)
  1101. {
  1102.     if( Level.Game!=None && Other!=None && Other!=Self )
  1103.     {
  1104.         if( Level.Game.bTeamGame )
  1105.             if( GetTeamNum()!=Other.GetTeamNum() )
  1106.                 Enemy = Other;
  1107.         else if( Level.Game.bDeathMatch || !Other.bIsPlayer )
  1108.             Enemy = Other;
  1109.     }
  1110. }
  1111.  
  1112. exec function Grab()
  1113. {
  1114.  
  1115.     local GameRules G;
  1116.  
  1117.     for ( G = Level.Game.GameRules; G != None; G = G.NextRules )
  1118.         if ( G.bHandleGrab && !G.CanGrab(self) )
  1119.             return;
  1120.  
  1121.     if (CarriedDecoration == None)
  1122.         GrabDecoration();
  1123.     else
  1124.         DropDecoration();
  1125. }
  1126.  
  1127. // Send a voice message of a certain type to a certain player.
  1128. exec function Speech( int Type, int Index, int Callsign )
  1129. {
  1130.     local VoicePack V;
  1131.  
  1132.     if ( PlayerReplicationInfo.VoiceType == None || Level.TimeSeconds - OldMessageTime < 2.5 )
  1133.         return;
  1134.     else OldMessageTime = Level.TimeSeconds;
  1135.  
  1136.     V = Spawn( PlayerReplicationInfo.VoiceType, Self );
  1137.     if (V != None)
  1138.     {
  1139.         V.PlayerSpeech( Type, Index, Callsign );
  1140.         V.Destroy();
  1141.     }
  1142. }
  1143.  
  1144. function PlayChatting();
  1145.  
  1146. function Typing( bool bTyping )
  1147. {
  1148.     bIsTyping = bTyping;
  1149.     if (bTyping)
  1150.     {
  1151.         if (Level.Game.WorldLog != None)
  1152.             Level.Game.WorldLog.LogTypingEvent(True, Self);
  1153.         if (Level.Game.LocalLog != None)
  1154.             Level.Game.LocalLog.LogTypingEvent(True, Self);
  1155.         PlayChatting();
  1156.     }
  1157.     else
  1158.     {
  1159.         if (Level.Game.WorldLog != None)
  1160.             Level.Game.WorldLog.LogTypingEvent(False, Self);
  1161.         if (Level.Game.LocalLog != None)
  1162.             Level.Game.LocalLog.LogTypingEvent(False, Self);
  1163.     }
  1164. }
  1165.  
  1166. // Send a message to all players.
  1167. exec function Say( string Msg )
  1168. {
  1169.     local Pawn P;
  1170.     local GameRules G;
  1171.  
  1172.     if ( Level.Game.GameRules!=None )
  1173.     {
  1174.         for ( G=Level.Game.GameRules; G!=None; G=G.NextRules )
  1175.             if ( G.bNotifyMessages && !G.AllowChat(Self,Msg) )
  1176.                 Return;
  1177.     }
  1178.  
  1179.     if ( Level.Game.AllowsBroadcast(self, Len(Msg)) )
  1180.         for ( P=Level.PawnList; P!=None; P=P.nextPawn )
  1181.             if ( P.bIsPlayer )
  1182.                 P.TeamMessage( PlayerReplicationInfo, Msg, 'Say' );
  1183.     return;
  1184. }
  1185.  
  1186. exec function TeamSay( string Msg )
  1187. {
  1188.     local Pawn P;
  1189.     local GameRules G;
  1190.  
  1191.     if ( !Level.Game.bTeamGame )
  1192.     {
  1193.         Say(Msg);
  1194.         return;
  1195.     }
  1196.  
  1197.     if ( Level.Game.GameRules!=None )
  1198.     {
  1199.         for ( G=Level.Game.GameRules; G!=None; G=G.NextRules )
  1200.             if ( G.bNotifyMessages && !G.AllowChat(Self,Msg) )
  1201.                 Return;
  1202.     }
  1203.  
  1204.     if ( Msg ~= "Help" )
  1205.     {
  1206.         CallForHelp();
  1207.         return;
  1208.     }
  1209.  
  1210.     if ( Level.Game.AllowsBroadcast(self, Len(Msg)) )
  1211.         for ( P=Level.PawnList; P!=None; P=P.nextPawn )
  1212.             if ( P.bIsPlayer && (P.PlayerReplicationInfo.Team == PlayerReplicationInfo.Team) )
  1213.             {
  1214.                 if ( P.IsA('PlayerPawn') )
  1215.                     P.TeamMessage( PlayerReplicationInfo, Msg, 'TeamSay' );
  1216.             }
  1217. }
  1218.  
  1219. exec function RestartLevel()
  1220. {
  1221.     if( Level.Game.GetAccessManager().CanExecuteCheat(Self,'RestartLevel') )
  1222.         ClientTravel( "?restart", TRAVEL_Relative, false );
  1223. }
  1224.  
  1225. exec function LocalTravel( string URL )
  1226. {
  1227.     if( Level.Game.GetAccessManager().CanExecuteCheatStr(Self,'LocalTravel',URL) )
  1228.         ClientTravel( URL, TRAVEL_Relative, true );
  1229. }
  1230.  
  1231. exec function ThrowWeapon()
  1232. {
  1233.     if ( Level.NetMode == NM_Client )
  1234.         return;
  1235.     if ( Weapon==None || (Weapon.Class==Level.Game.DefaultWeapon) || !Weapon.bCanThrow )
  1236.         return;
  1237.     Weapon.Velocity = Vector(ViewRotation) * 500 + vect(0,0,220);
  1238.     Weapon.bTossedOut = true;
  1239.     TossWeapon();
  1240.     if ( Weapon == None )
  1241.         SwitchToBestWeapon();
  1242. }
  1243.  
  1244. function ToggleZoom()
  1245. {
  1246.     if ( DefaultFOV != DesiredFOV )
  1247.         EndZoom();
  1248.     else
  1249.         StartZoom();
  1250. }
  1251.  
  1252. function StartZoom()
  1253. {
  1254.     ZoomLevel = 0.0;
  1255.     bZooming = true;
  1256. }
  1257.  
  1258. function StopZoom()
  1259. {
  1260.     bZooming = false;
  1261. }
  1262.  
  1263. function EndZoom()
  1264. {
  1265.     bZooming = false;
  1266.     DesiredFOV = DefaultFOV;
  1267. }
  1268.  
  1269. exec function FOV(float F)
  1270. {
  1271.     SetDesiredFOV(F);
  1272. }
  1273.  
  1274. exec function UpdateWideScreen(float F)
  1275. {
  1276.     SetDesiredFOV(F);
  1277.     MainFOV=F;
  1278.     SaveConfig();
  1279. }
  1280.  
  1281. exec function SetDesiredFOV(float F)
  1282. {
  1283.     if ( !Level.bNoCheating || bAdmin || (Level.Netmode==NM_Standalone) )
  1284.     {
  1285.         DefaultFOV = FClamp(F, 1, 170);
  1286.         DesiredFOV = DefaultFOV;
  1287.     }
  1288.     else
  1289.     {
  1290.         DefaultFOV = FClamp(F, 90, 170);
  1291.         DesiredFOV = DefaultFOV;
  1292.     }
  1293. }
  1294.  
  1295. /* PrevWeapon()
  1296. - switch to previous inventory group weapon
  1297. */
  1298. exec function PrevWeapon()
  1299. {
  1300.     local int prevGroup;
  1301.     local Inventory inv;
  1302.     local Weapon realWeapon, w, Prev;
  1303.     local bool bFoundWeapon;
  1304.  
  1305.     if ( bShowMenu || Len(Level.Pauser)>0 )
  1306.         return;
  1307.     if ( Weapon == None )
  1308.     {
  1309.         SwitchToBestWeapon();
  1310.         return;
  1311.     }
  1312.     prevGroup = 0;
  1313.     realWeapon = Weapon;
  1314.     if ( PendingWeapon != None )
  1315.         Weapon = PendingWeapon;
  1316.     PendingWeapon = None;
  1317.  
  1318.     for (inv=Inventory; inv!=None; inv=inv.Inventory)
  1319.     {
  1320.         w = Weapon(inv);
  1321.         if ( w != None )
  1322.         {
  1323.             if ( w.InventoryGroup == Weapon.InventoryGroup )
  1324.             {
  1325.                 if ( w == Weapon )
  1326.                 {
  1327.                     bFoundWeapon = true;
  1328.                     if ( Prev != None )
  1329.                     {
  1330.                         PendingWeapon = Prev;
  1331.                         break;
  1332.                     }
  1333.                 }
  1334.                 else if ( !bFoundWeapon && ((w.AmmoType == None) || (w.AmmoType.AmmoAmount>0)) )
  1335.                     Prev = W;
  1336.             }
  1337.             else if ( (w.InventoryGroup < Weapon.InventoryGroup)
  1338.                       && ((w.AmmoType == None) || (w.AmmoType.AmmoAmount>0))
  1339.                       && (w.InventoryGroup >= prevGroup) )
  1340.             {
  1341.                 prevGroup = w.InventoryGroup;
  1342.                 PendingWeapon = w;
  1343.             }
  1344.         }
  1345.     }
  1346.     bFoundWeapon = false;
  1347.     prevGroup = Weapon.InventoryGroup;
  1348.     if ( PendingWeapon == None )
  1349.         for (inv=Inventory; inv!=None; inv=inv.Inventory)
  1350.         {
  1351.             w = Weapon(inv);
  1352.             if ( w != None )
  1353.             {
  1354.                 if ( w.InventoryGroup == Weapon.InventoryGroup )
  1355.                 {
  1356.                     if ( w == Weapon )
  1357.                         bFoundWeapon = true;
  1358.                     else if ( bFoundWeapon && (PendingWeapon == None) && ((w.AmmoType == None) || (w.AmmoType.AmmoAmount>0)) )
  1359.                         PendingWeapon = W;
  1360.                 }
  1361.                 else if ( (w.InventoryGroup > PrevGroup)
  1362.                           && ((w.AmmoType == None) || (w.AmmoType.AmmoAmount>0)) )
  1363.                 {
  1364.                     prevGroup = w.InventoryGroup;
  1365.                     PendingWeapon = w;
  1366.                 }
  1367.             }
  1368.         }
  1369.  
  1370.     Weapon = realWeapon;
  1371.     if ( PendingWeapon == None )
  1372.         return;
  1373.  
  1374.     if ( Weapon != PendingWeapon )
  1375.         Weapon.PutDown();
  1376. }
  1377.  
  1378. /* NextWeapon()
  1379. - switch to next inventory group weapon
  1380. */
  1381. exec function NextWeapon()
  1382. {
  1383.     local int nextGroup;
  1384.     local Inventory inv;
  1385.     local Weapon realWeapon, w, Prev;
  1386.     local bool bFoundWeapon;
  1387.  
  1388.     if ( bShowMenu || Len(Level.Pauser)>0 )
  1389.         return;
  1390.     if ( Weapon == None )
  1391.     {
  1392.         SwitchToBestWeapon();
  1393.         return;
  1394.     }
  1395.     nextGroup = 100;
  1396.     realWeapon = Weapon;
  1397.     if ( PendingWeapon != None )
  1398.         Weapon = PendingWeapon;
  1399.     PendingWeapon = None;
  1400.  
  1401.     for (inv=Inventory; inv!=None; inv=inv.Inventory)
  1402.     {
  1403.         w = Weapon(inv);
  1404.         if ( w != None )
  1405.         {
  1406.             if ( w.InventoryGroup == Weapon.InventoryGroup )
  1407.             {
  1408.                 if ( w == Weapon )
  1409.                     bFoundWeapon = true;
  1410.                 else if ( bFoundWeapon && ((w.AmmoType == None) || (w.AmmoType.AmmoAmount>0)) )
  1411.                 {
  1412.                     PendingWeapon = W;
  1413.                     break;
  1414.                 }
  1415.             }
  1416.             else if ( (w.InventoryGroup > Weapon.InventoryGroup)
  1417.                       && ((w.AmmoType == None) || (w.AmmoType.AmmoAmount>0))
  1418.                       && (w.InventoryGroup < nextGroup) )
  1419.             {
  1420.                 nextGroup = w.InventoryGroup;
  1421.                 PendingWeapon = w;
  1422.             }
  1423.         }
  1424.     }
  1425.  
  1426.     bFoundWeapon = false;
  1427.     nextGroup = Weapon.InventoryGroup;
  1428.     if ( PendingWeapon == None )
  1429.         for (inv=Inventory; inv!=None; inv=inv.Inventory)
  1430.         {
  1431.             w = Weapon(Inv);
  1432.             if ( w != None )
  1433.             {
  1434.                 if ( w.InventoryGroup == Weapon.InventoryGroup )
  1435.                 {
  1436.                     if ( w == Weapon )
  1437.                     {
  1438.                         bFoundWeapon = true;
  1439.                         if ( Prev != None )
  1440.                             PendingWeapon = Prev;
  1441.                     }
  1442.                     else if ( !bFoundWeapon && (PendingWeapon == None) && ((w.AmmoType == None) || (w.AmmoType.AmmoAmount>0)) )
  1443.                         Prev = W;
  1444.                 }
  1445.                 else if ( (w.InventoryGroup < nextGroup)
  1446.                           && ((w.AmmoType == None) || (w.AmmoType.AmmoAmount>0)) )
  1447.                 {
  1448.                     nextGroup = w.InventoryGroup;
  1449.                     PendingWeapon = w;
  1450.                 }
  1451.             }
  1452.         }
  1453.  
  1454.     Weapon = realWeapon;
  1455.     if ( PendingWeapon == None )
  1456.         return;
  1457.  
  1458.     if ( Weapon != PendingWeapon )
  1459.         Weapon.PutDown();
  1460. }
  1461.  
  1462. exec function QuickSave()
  1463. {
  1464.     if ( (Health > 0)
  1465.             && (Level.NetMode == NM_Standalone)
  1466.             && !Level.Game.bDeathMatch )
  1467.     {
  1468.         ClientMessage(QuickSaveString);
  1469.         ConsoleCommand("SaveGame 9");
  1470.     }
  1471. }
  1472.  
  1473. exec function QuickLoad()
  1474. {
  1475.     if ( (Level.NetMode == NM_Standalone)
  1476.             && !Level.Game.bDeathMatch )
  1477.         ClientTravel( "?load=9", TRAVEL_Absolute, false);
  1478. }
  1479.  
  1480. exec function Kick( string S )
  1481. {
  1482.     local Pawn aPawn;
  1483.  
  1484.     if ( !Level.Game.GetAccessManager().CanExecuteCheatStr(Self,'Kick',S) )
  1485.         return;
  1486.     for ( aPawn=Level.PawnList; aPawn!=None; aPawn=aPawn.NextPawn )
  1487.         if( aPawn.bIsPlayer
  1488.             &&  aPawn.PlayerReplicationInfo.PlayerName~=S
  1489.             &&  (PlayerPawn(aPawn)==None || Viewport(PlayerPawn(aPawn).Player)==None) )
  1490.         {
  1491.             aPawn.Destroy();
  1492.             return;
  1493.         }
  1494. }
  1495.  
  1496. // Try to set the pause state; returns success indicator.
  1497. function bool SetPause( BOOL bPause )
  1498. {
  1499.     return Level.Game.SetPause(bPause, self);
  1500. }
  1501.  
  1502. exec function SetMouseSmoothThreshold( float F )
  1503. {
  1504.     MouseSmoothThreshold = FClamp(F, 0, 1);
  1505.     SaveConfig();
  1506. }
  1507.  
  1508. exec function SetMaxMouseSmoothing( bool B )
  1509. {
  1510.     bMaxMouseSmoothing = B;
  1511.     SaveConfig();
  1512. }
  1513.  
  1514. // Try to pause the game.
  1515. exec function Pause()
  1516. {
  1517.     if ( bShowMenu )
  1518.         return;
  1519.     if ( !SetPause(Len(Level.Pauser)==0) )
  1520.         ClientMessage(NoPauseMessage);
  1521. }
  1522.  
  1523. // Activate specific inventory item
  1524. exec function ActivateInventoryItem( class InvItem )
  1525. {
  1526.     local Inventory Inv;
  1527.  
  1528.     Inv = FindInventoryType(InvItem);
  1529.     if ( Inv != None )
  1530.         Inv.Activate();
  1531. }
  1532.  
  1533. // Translator Hotkey
  1534. exec function ActivateTranslator()
  1535. {
  1536.     if ( bShowMenu || Len(Level.Pauser)>0 )
  1537.         return;
  1538.     If (Inventory!=None) Inventory.ActivateTranslator(False);
  1539. }
  1540.  
  1541. // Translator Hotkey
  1542. exec function ActivateHint()
  1543. {
  1544.     if ( bShowMenu || Len(Level.Pauser)>0 )
  1545.         return;
  1546.     If (Inventory!=None) Inventory.ActivateTranslator(True);
  1547. }
  1548.  
  1549. // HUD
  1550. exec function ChangeHud()
  1551. {
  1552.     if ( myHud != None )
  1553.         myHUD.ChangeHud(1);
  1554.     myHUD.SaveConfig();
  1555. }
  1556.  
  1557. // Crosshair
  1558. exec function ChangeCrosshair()
  1559. {
  1560.     if ( myHud != None )
  1561.         myHUD.ChangeCrosshair(1);
  1562.     myHUD.SaveConfig();
  1563. }
  1564.  
  1565. event PreRender( canvas Canvas )
  1566. {
  1567.     if( RendMap==1 )
  1568.     {
  1569.         Canvas.SetPos(0,0);
  1570.         Canvas.DrawColor.R = 0;
  1571.         Canvas.DrawColor.G = 0;
  1572.         Canvas.DrawColor.B = 0;
  1573.         Canvas.Style = 1;
  1574.         Canvas.Z = 1;
  1575.         Canvas.DrawTile(Texture'DefaultTexture',Canvas.ClipX,Canvas.ClipY,0,0,1,1);
  1576.         Canvas.DrawActor(None,False,True); // Clear Z
  1577.     }
  1578.     if ( myHud != None )
  1579.         myHUD.PreRender(Canvas);
  1580.     else if ( (Viewport(Player) != None) && (HUDType != None) )
  1581.         myHUD = spawn(HUDType, self);
  1582. }
  1583.  
  1584. event PostRender( canvas Canvas )
  1585. {
  1586.     if ( myHud != None )
  1587.         myHUD.PostRender(Canvas);
  1588.     else if ( (Viewport(Player) != None) && (HUDType != None) )
  1589.         myHUD = spawn(HUDType, self);
  1590. }
  1591.  
  1592. //=============================================================================
  1593. // Inventory-related input notifications.
  1594.  
  1595. // Handle function keypress for F1-F10.
  1596. exec function FunctionKey( byte Num )
  1597. {
  1598. }
  1599.  
  1600. // The player wants to switch to weapon group numer I.
  1601. exec function SwitchWeapon (byte F )
  1602. {
  1603.     local weapon newWeapon;
  1604.  
  1605.     if ( bShowMenu || Len(Level.Pauser)>0 )
  1606.     {
  1607.         if ( myHud != None )
  1608.             myHud.InputNumber(F);
  1609.         return;
  1610.     }
  1611.     if ( Inventory == None )
  1612.         return;
  1613.     if ( (Weapon != None) && (Weapon.Inventory != None) )
  1614.         newWeapon = Weapon.Inventory.WeaponChange(F);
  1615.     else
  1616.         newWeapon = None;
  1617.     if ( newWeapon == None )
  1618.         newWeapon = Inventory.WeaponChange(F);
  1619.     if ( newWeapon == None )
  1620.         return;
  1621.  
  1622.     if ( Weapon == None )
  1623.     {
  1624.         PendingWeapon = newWeapon;
  1625.         ChangedWeapon();
  1626.     }
  1627.     else if ( (Weapon != newWeapon) && Weapon.PutDown() )
  1628.         PendingWeapon = newWeapon;
  1629. }
  1630.  
  1631. exec function GetWeapon(class<Weapon> NewWeaponClass )
  1632. {
  1633.     local Inventory Inv;
  1634.  
  1635.     if ( Level.NetMode==NM_Client )
  1636.     {
  1637.         if ( NewWeaponClass!=None )
  1638.             SwitchWeapon(NewWeaponClass.Default.InventoryGroup); // Stupid workaround for clients...
  1639.         Return;
  1640.     }
  1641.     if ( (Inventory == None) || (NewWeaponClass == None)
  1642.             || ((Weapon != None) && (Weapon.Class == NewWeaponClass)) )
  1643.         return;
  1644.  
  1645.     for ( Inv=Inventory; Inv!=None; Inv=Inv.Inventory )
  1646.         if ( Inv.Class == NewWeaponClass )
  1647.         {
  1648.             PendingWeapon = Weapon(Inv);
  1649.             Weapon.PutDown();
  1650.             return;
  1651.         }
  1652. }
  1653.  
  1654. // The player wants to select previous item
  1655. exec function PrevItem()
  1656. {
  1657.     local Inventory Inv, LastItem;
  1658.  
  1659.     if ( bShowMenu || Len(Level.Pauser)>0 )
  1660.         return;
  1661.     if( Inventory==None )
  1662.     {
  1663.         SelectedItem = None;
  1664.         return;
  1665.     }
  1666.     if (SelectedItem==None)
  1667.     {
  1668.         SelectedItem = Inventory.SelectNext();
  1669.         Return;
  1670.     }
  1671.     if (SelectedItem.Inventory!=None)
  1672.         for ( Inv=SelectedItem.Inventory; Inv!=None; Inv=Inv.Inventory )
  1673.         {
  1674.             if (Inv==None) Break;
  1675.             if (Inv.bActivatable) LastItem=Inv;
  1676.         }
  1677.     for ( Inv=Inventory; Inv!=SelectedItem; Inv=Inv.Inventory )
  1678.     {
  1679.         if (Inv==None) Break;
  1680.         if (Inv.bActivatable) LastItem=Inv;
  1681.     }
  1682.     if (LastItem!=None)
  1683.     {
  1684.         SelectedItem = LastItem;
  1685.         ClientMessage(SelectedItem.ItemName$SelectedItem.M_Selected);
  1686.     }
  1687. }
  1688.  
  1689. // The player wants to active selected item
  1690. exec function ActivateItem()
  1691. {
  1692.     if ( bShowMenu || Len(Level.Pauser)>0 )
  1693.         return;
  1694.     if (SelectedItem!=None)
  1695.         SelectedItem.Activate();
  1696. }
  1697.  
  1698. // The player wants to fire.
  1699. exec function Fire( optional float F )
  1700. {
  1701.     bJustFired = true;
  1702.     if ( bShowMenu || Len(Level.Pauser)>0 || (Role < ROLE_Authority) )
  1703.         return;
  1704.     if ( Weapon!=None )
  1705.     {
  1706.         Weapon.bPointing = true;
  1707.         PlayFiring();
  1708.         Weapon.Fire(F);
  1709.     }
  1710. }
  1711.  
  1712. // The player wants to alternate-fire.
  1713. exec function AltFire( optional float F )
  1714. {
  1715.     bJustAltFired = true;
  1716.     if ( bShowMenu || Len(Level.Pauser)>0 || (Role < ROLE_Authority) )
  1717.         return;
  1718.     if ( Weapon!=None )
  1719.     {
  1720.         Weapon.bPointing = true;
  1721.         PlayFiring();
  1722.         Weapon.AltFire(F);
  1723.     }
  1724. }
  1725.  
  1726. //Player Jumped
  1727. function DoJump( optional float F )
  1728. {
  1729.     if ( CarriedDecoration != None )
  1730.         return;
  1731.     if ( !bIsCrouching && (Physics == PHYS_Walking) )
  1732.     {
  1733.         if ( Role == ROLE_Authority )
  1734.             PlaySound(JumpSound, SLOT_Talk, 1.5, true, 1200, 1.0 );
  1735.         if ( (Level.Game != None) && (Level.Game.Difficulty > 0) )
  1736.             MakeNoise(0.1 * Level.Game.Difficulty);
  1737.         PlayInAir();
  1738.         if ( bCountJumps && (Role == ROLE_Authority) )
  1739.             Inventory.OwnerJumped();
  1740.         Velocity.Z = JumpZ;
  1741.         if ( Base!=Level && Base!=None )
  1742.             Velocity.Z += Base.Velocity.Z;
  1743.         SetPhysics(PHYS_Falling);
  1744.     }
  1745. }
  1746.  
  1747. exec function Suicide()
  1748. {
  1749.     KilledBy( None );
  1750. }
  1751.  
  1752. exec function AlwaysMouseLook( Bool B )
  1753. {
  1754.     ChangeAlwaysMouseLook(B);
  1755.     SaveConfig();
  1756. }
  1757.  
  1758. function ChangeAlwaysMouseLook(Bool B)
  1759. {
  1760.     bAlwaysMouseLook = B;
  1761.     if ( bAlwaysMouseLook )
  1762.         bLookUpStairs = false;
  1763. }
  1764.  
  1765. exec function SnapView( bool B )
  1766. {
  1767.     ChangeSnapView(B);
  1768.     SaveConfig();
  1769. }
  1770.  
  1771. function ChangeSnapView( bool B )
  1772. {
  1773.     bSnapToLevel = B;
  1774. }
  1775.  
  1776. exec function StairLook( bool B )
  1777. {
  1778.     ChangeStairLook(B);
  1779.     SaveConfig();
  1780. }
  1781.  
  1782. function ChangeStairLook( bool B )
  1783. {
  1784.     bLookUpStairs = B;
  1785.     if ( bLookUpStairs )
  1786.         bAlwaysMouseLook = false;
  1787. }
  1788.  
  1789. exec function SetDodgeClickTime( float F )
  1790. {
  1791.     ChangeDodgeClickTime(F);
  1792.     SaveConfig();
  1793. }
  1794.  
  1795. function ChangeDodgeClickTime( float F )
  1796. {
  1797.     DodgeClickTime = FMin(0.3, F);
  1798. }
  1799.  
  1800. exec function SetName( coerce string S )
  1801. {
  1802.     S = Left(S,40);
  1803.     ChangeName(S);
  1804.     UpdateURL("Name", S, true);
  1805.     SaveConfig();
  1806. }
  1807.  
  1808. function ChangeName( coerce string S )
  1809. {
  1810.     if (Level.Game.WorldLog != None)
  1811.         ClientMessage(CantChangeNameMsg);
  1812.     else
  1813.         Level.Game.ChangeName( self, S, true );
  1814. }
  1815.  
  1816. function ChangeTeam( int N )
  1817. {
  1818.     local byte OldTeam;
  1819.  
  1820.     OldTeam = PlayerReplicationInfo.Team;
  1821.     if ( Level.Game.ChangeTeam(self,N) && Level.Game.bTeamGame && OldTeam!=PlayerReplicationInfo.Team )
  1822.         Died( None, '', Location );
  1823. }
  1824.  
  1825. exec function SetAutoAim( float F )
  1826. {
  1827.     ChangeAutoAim(F);
  1828.     SaveConfig();
  1829. }
  1830.  
  1831. function ChangeAutoAim( float F )
  1832. {
  1833.     MyAutoAim = FMax(Level.Game.AutoAim, F);
  1834. }
  1835.  
  1836. exec function PlayersOnly()
  1837. {
  1838.     if ( Level.Netmode != NM_Standalone )
  1839.         return;
  1840.  
  1841.     Level.bPlayersOnly = !Level.bPlayersOnly;
  1842. }
  1843.  
  1844. exec function SetHand( string S )
  1845. {
  1846.     ChangeSetHand(S);
  1847.     SaveConfig();
  1848. }
  1849.  
  1850. function ChangeSetHand( string S )
  1851. {
  1852.     if ( S ~= "Left" )
  1853.         Handedness = 1;
  1854.     else if ( S~= "Right" )
  1855.         Handedness = -1;
  1856.     else if ( S ~= "Center" )
  1857.         Handedness = 0;
  1858.     else if ( S ~= "Hidden" )
  1859.         Handedness = 2;
  1860.     ServerSetHandedness(Handedness);
  1861. }
  1862.  
  1863. exec function ViewPlayer( string S )
  1864. {
  1865.     local pawn P;
  1866.  
  1867.     for ( P=Level.pawnList; P!=None; P= P.NextPawn )
  1868.         if ( P.bIsPlayer && (P.PlayerReplicationInfo.PlayerName ~= S) )
  1869.             break;
  1870.  
  1871.     if ( (P != None) && Level.Game.CanSpectate(self, P) )
  1872.     {
  1873.         ClientMessage(ViewingFrom$P.PlayerReplicationInfo.PlayerName, 'Event', true);
  1874.         if ( P == self)
  1875.             ViewTarget = None;
  1876.         else
  1877.             ViewTarget = P;
  1878.     }
  1879.     else
  1880.         ClientMessage(FailedView);
  1881.  
  1882.     bBehindView = ( ViewTarget != None );
  1883.     if ( bBehindView )
  1884.         ViewTarget.BecomeViewTarget();
  1885. }
  1886.  
  1887. exec function CheatView( class<actor> aClass )
  1888. {
  1889.     local actor other, first;
  1890.     local bool bFound;
  1891.  
  1892.     if( !Level.Game.GetAccessManager().CanExecuteCheatStr(Self,'CheatView',string(aClass)) )
  1893.         return;
  1894.  
  1895.     first = None;
  1896.     ForEach AllActors( aClass, other )
  1897.     {
  1898.         if ( (first == None) && (other != self) )
  1899.         {
  1900.             first = other;
  1901.             bFound = true;
  1902.         }
  1903.         if ( other == ViewTarget )
  1904.             first = None;
  1905.     }
  1906.  
  1907.     if ( first != None )
  1908.     {
  1909.         if ( first.IsA('Pawn') && Pawn(first).bIsPlayer && (Pawn(first).PlayerReplicationInfo.PlayerName != "") )
  1910.             ClientMessage(ViewingFrom$Pawn(first).PlayerReplicationInfo.PlayerName, 'Event', true);
  1911.         else
  1912.             ClientMessage(ViewingFrom$first, 'Event', true);
  1913.         ViewTarget = first;
  1914.     }
  1915.     else
  1916.     {
  1917.         if ( bFound )
  1918.             ClientMessage(ViewingFrom$OwnCamera, 'Event', true);
  1919.         else
  1920.             ClientMessage(FailedView, 'Event', true);
  1921.         ViewTarget = None;
  1922.     }
  1923.  
  1924.     bBehindView = ( ViewTarget != None );
  1925.     if ( bBehindView )
  1926.         ViewTarget.BecomeViewTarget();
  1927. }
  1928.  
  1929. exec function ViewSelf()
  1930. {
  1931.     bBehindView = false;
  1932.     Viewtarget = None;
  1933.     ClientMessage("Now viewing from own camera", 'Event', true);
  1934. }
  1935.  
  1936. exec function ViewClass( class<actor> aClass, optional bool bQuiet )
  1937. {
  1938.     local actor other, first;
  1939.     local bool bFound;
  1940.  
  1941.     first = None;
  1942.     ForEach AllActors( aClass, other )
  1943.     {
  1944.         if ( (first == None) && (other != self)
  1945.                 && ( (bAdmin && Level.Game==None) || Level.Game.CanSpectate(self, other) ) )
  1946.         {
  1947.             first = other;
  1948.             bFound = true;
  1949.         }
  1950.         if ( other == ViewTarget )
  1951.             first = None;
  1952.     }
  1953.  
  1954.     if ( first != None )
  1955.     {
  1956.         if ( !bQuiet )
  1957.         {
  1958.             if ( first.IsA('Pawn') && Pawn(first).bIsPlayer && (Pawn(first).PlayerReplicationInfo.PlayerName != "") )
  1959.                 ClientMessage(ViewingFrom$Pawn(first).PlayerReplicationInfo.PlayerName, 'Event', true);
  1960.             else
  1961.                 ClientMessage(ViewingFrom$first, 'Event', true);
  1962.         }
  1963.         ViewTarget = first;
  1964.     }
  1965.     else
  1966.     {
  1967.         if ( !bQuiet )
  1968.         {
  1969.             if ( bFound )
  1970.                 ClientMessage(ViewingFrom$OwnCamera, 'Event', true);
  1971.             else
  1972.                 ClientMessage(FailedView, 'Event', true);
  1973.         }
  1974.         ViewTarget = None;
  1975.     }
  1976.  
  1977.     bBehindView = ( ViewTarget != None );
  1978.     if ( bBehindView )
  1979.         ViewTarget.BecomeViewTarget();
  1980. }
  1981.  
  1982. exec function NeverSwitchOnPickup( bool B )
  1983. {
  1984.     bNeverSwitchOnPickup = B;
  1985. }
  1986.  
  1987. exec function InvertMouse( bool B )
  1988. {
  1989.     bInvertMouse = B;
  1990.     SaveConfig();
  1991. }
  1992.  
  1993. exec function SwitchLevel( string URL )
  1994. {
  1995.     if( Level.Game.GetAccessManager().CanExecuteCheatStr(Self,'SwitchLevel',URL) )
  1996.         Level.ServerTravel( URL, false );
  1997. }
  1998.  
  1999. exec function SwitchCoopLevel( string URL )
  2000. {
  2001.     if( Level.Game.GetAccessManager().CanExecuteCheatStr(Self,'SwitchCoopLevel',URL) )
  2002.         Level.ServerTravel( URL, true );
  2003. }
  2004.  
  2005. exec function ShowScores()
  2006. {
  2007.     bShowScores = !bShowScores;
  2008. }
  2009.  
  2010. exec function ShowMenu()
  2011. {
  2012.     WalkBob = vect(0,0,0);
  2013.     bShowMenu = true; // menu is responsible for turning this off
  2014.     Player.Console.GotoState('Menuing');
  2015.  
  2016.     if ( Level.Netmode == NM_Standalone )
  2017.         SetPause(true);
  2018. }
  2019.  
  2020. exec function ShowLoadMenu()
  2021. {
  2022.     Player.Console.ShowLoadGameMenu();
  2023. }
  2024.  
  2025. exec function AddBots(int N)
  2026. {
  2027.     ServerAddBots(N);
  2028. }
  2029.  
  2030. function ServerAddBots(int N)
  2031. {
  2032.     local int i;
  2033.  
  2034.     if( !Level.Game.bDeathMatch || !Level.Game.GetAccessManager().CanExecuteCheatStr(Self,'AddBots',string(N)) )
  2035.         return;
  2036.  
  2037.     for ( i=0; i<N; i++ )
  2038.         Level.Game.AddBot();
  2039. }
  2040.  
  2041.  
  2042. //*************************************************************************************
  2043. // Special purpose/cheat execs
  2044.  
  2045. exec function ClearProgressMessages()
  2046. {
  2047.     local int i;
  2048.  
  2049.     for (i=0; i<5; i++)
  2050.     {
  2051.         ProgressMessage[i] = "";
  2052.         ProgressColor[i].R = 255;
  2053.         ProgressColor[i].G = 255;
  2054.         ProgressColor[i].B = 255;
  2055.     }
  2056. }
  2057.  
  2058. exec function SetProgressMessage( string S, int Index )
  2059. {
  2060.     if (Index < 5)
  2061.         ProgressMessage[Index] = S;
  2062. }
  2063.  
  2064. exec function SetProgressColor( color C, int Index )
  2065. {
  2066.     if (Index < 5)
  2067.         ProgressColor[Index] = C;
  2068. }
  2069.  
  2070. exec function SetProgressTime( float T )
  2071. {
  2072.     ProgressTimeOut = T + Level.TimeSeconds;
  2073. }
  2074.  
  2075. exec event ShowUpgradeMenu();
  2076.  
  2077. exec function Amphibious()
  2078. {
  2079.     if ( Level.NetMode==NM_Client )
  2080.     {
  2081.         Admin("Amphibious");
  2082.         Return; // We are a network client, pass to server.
  2083.     }
  2084.     if( Level.Game.GetAccessManager().CanExecuteCheat(Self,'Amphibious') )
  2085.         UnderwaterTime = +999999.0;
  2086. }
  2087.  
  2088. exec function Fly()
  2089. {
  2090.     if( !Level.Game.GetAccessManager().CanExecuteCheat(Self,'Fly') )
  2091.         return;
  2092.  
  2093.     UnderWaterTime = Default.UnderWaterTime;
  2094.     ClientMessage("You feel much lighter");
  2095.     SetCollision(true, true , true);
  2096.     bCollideWorld = true;
  2097.     GotoState('CheatFlying');
  2098. }
  2099.  
  2100. exec function Walk()
  2101. {
  2102.     if( !Level.Game.GetAccessManager().CanExecuteCheat(Self,'Walk') )
  2103.         return;
  2104.  
  2105.     bHidden = (Health<=0);
  2106.     Visibility = Default.Visibility;
  2107.     bProjTarget = True;
  2108.     Velocity = vect(0.0,0.0,0.0);
  2109.     Acceleration = vect(0.0,0.0,0.0);
  2110.     BaseEyeHeight = Default.BaseEyeHeight;
  2111.     EyeHeight = BaseEyeHeight;
  2112.     PlayWaiting();
  2113.     bPressedJump = false;
  2114.     if ( Region.Zone.bWaterZone )
  2115.     {
  2116.         if ( HeadRegion.Zone.bWaterZone )
  2117.             PainTime = UnderWaterTime;
  2118.         GotoState('PlayerSwimming');
  2119.     }
  2120.     else GotoState('PlayerWalking');
  2121.  
  2122.     StartWalk();
  2123. }
  2124.  
  2125. function StartWalk()
  2126. {
  2127.     UnderWaterTime = Default.UnderWaterTime;
  2128.     SetCollision(true, true , true);
  2129.     if ( Region.Zone.bWaterZone )
  2130.         SetPhysics(PHYS_swimming);
  2131.     else SetPhysics(PHYS_Walking);
  2132.     bCollideWorld = true;
  2133.     ClientReStart();
  2134. }
  2135.  
  2136. exec function Ghost()
  2137. {
  2138.     if( !Level.Game.GetAccessManager().CanExecuteCheat(Self,'Ghost') )
  2139.         return;
  2140.  
  2141.     UnderWaterTime = -1.0;
  2142.     ClientMessage("You feel ethereal");
  2143.     SetCollision(false, false, false);
  2144.     bCollideWorld = false;
  2145.     GotoState('CheatFlying');
  2146. }
  2147.  
  2148. exec function ShowInventory()
  2149. {
  2150.     local Inventory Inv;
  2151.  
  2152.     if (Level.Netmode != NM_Standalone)
  2153.         return;
  2154.  
  2155.     if ( Weapon!=None )
  2156.         log( "   Weapon: " $ Weapon.Class );
  2157.     for ( Inv=Inventory; Inv!=None; Inv=Inv.Inventory )
  2158.         log( "Inv: "$Inv );
  2159.     if ( SelectedItem != None )
  2160.         log( "Selected Item"@SelectedItem@"Charge"@SelectedItem.Charge );
  2161. }
  2162.  
  2163. exec function AllAmmo()
  2164. {
  2165.     local Inventory Inv;
  2166.  
  2167.     if ( Level.NetMode==NM_Client )
  2168.     {
  2169.         Admin("AllAmmo");
  2170.         Return; // We are a network client, pass to server.
  2171.     }
  2172.     if( !Level.Game.GetAccessManager().CanExecuteCheat(Self,'AllAmmo') )
  2173.         return;
  2174.  
  2175.     for ( Inv=Inventory; Inv!=None; Inv=Inv.Inventory )
  2176.         if (Ammo(Inv)!=None)
  2177.         {
  2178.             Ammo(Inv).AmmoAmount  = 999;
  2179.             Ammo(Inv).MaxAmmo  = 999;
  2180.         }
  2181. }
  2182.  
  2183.  
  2184. exec function Invisible(bool B)
  2185. {
  2186.     if ( Level.NetMode==NM_Client )
  2187.     {
  2188.         Admin("Invisible"@B);
  2189.         Return; // We are a network client, pass to server.
  2190.     }
  2191.     if( !Level.Game.GetAccessManager().CanExecuteCheatStr(Self,'Invisible',string(B)) )
  2192.         return;
  2193.  
  2194.     if (B)
  2195.     {
  2196.         bHidden = true;
  2197.         Visibility = 0;
  2198.     }
  2199.     else
  2200.     {
  2201.         bHidden = false;
  2202.         Visibility = Default.Visibility;
  2203.     }
  2204. }
  2205.  
  2206. exec function God()
  2207. {
  2208.     if( !Level.Game.GetAccessManager().CanExecuteCheat(Self,'God') )
  2209.         return;
  2210.  
  2211.     if ( ReducedDamageType == 'All' )
  2212.     {
  2213.         ReducedDamageType = '';
  2214.         ClientMessage("God mode off");
  2215.         return;
  2216.     }
  2217.  
  2218.     ReducedDamageType = 'All';
  2219.     ClientMessage("God Mode on");
  2220. }
  2221.  
  2222. exec function BehindView( Bool B )
  2223. {
  2224.     bBehindView = B;
  2225. }
  2226. exec function UToggleBehindView()
  2227. {
  2228.     BehindView(!bBehindView);
  2229. }
  2230.  
  2231. exec function SetBob(float F)
  2232. {
  2233.     UpdateBob(F);
  2234.     SaveConfig();
  2235. }
  2236.  
  2237. function UpdateBob(float F)
  2238. {
  2239.     Bob = FClamp(F,0,0.032);
  2240. }
  2241.  
  2242. exec function SetSensitivity(float F)
  2243. {
  2244.     UpdateSensitivity(F);
  2245.     SaveConfig();
  2246. }
  2247.  
  2248. function UpdateSensitivity(float F)
  2249. {
  2250.     MouseSensitivity = FMax(0,F);
  2251. }
  2252.  
  2253. exec function SloMo( float T )
  2254. {
  2255.     ServerSetSloMo(T);
  2256. }
  2257.  
  2258. function ServerSetSloMo(float T)
  2259. {
  2260.     if( Level.Game.GetAccessManager().CanExecuteCheatStr(Self,'SloMo',string(T)) )
  2261.     {
  2262.         Level.Game.SetGameSpeed(T);
  2263.         Level.Game.SaveConfig();
  2264.         Level.Game.GameReplicationInfo.SaveConfig();
  2265.     }
  2266. }
  2267.  
  2268. exec function SetJumpZ( float F )
  2269. {
  2270.     if ( Level.NetMode==NM_Client )
  2271.     {
  2272.         Admin("SetJumpZ"@F);
  2273.         Return; // We are a client, pass it to server.
  2274.     }
  2275.     if( Level.Game.GetAccessManager().CanExecuteCheatStr(Self,'SetJumpZ',string(F)) )
  2276.         JumpZ = F;
  2277. }
  2278.  
  2279. exec function SetSpeed( float F )
  2280. {
  2281.     if ( Level.NetMode==NM_Client )
  2282.     {
  2283.         Admin("SetSpeed"@F);
  2284.         Return; // We are a client, pass it to server.
  2285.     }
  2286.     if( !Level.Game.GetAccessManager().CanExecuteCheatStr(Self,'SetSpeed',string(F)) )
  2287.         return;
  2288.     GroundSpeed = Default.GroundSpeed * f;
  2289.     WaterSpeed = Default.WaterSpeed * f;
  2290. }
  2291.  
  2292. exec function KillAll(class<actor> aClass)
  2293. {
  2294.     local Actor A;
  2295.  
  2296.     if( !Level.Game.GetAccessManager().CanExecuteCheatStr(Self,'KillAll',string(aClass)) )
  2297.         return;
  2298.     ForEach AllActors(class 'Actor', A)
  2299.     if ( ClassIsChildOf(A.class, aClass) )
  2300.         A.Destroy();
  2301. }
  2302.  
  2303. exec function KillPawns()
  2304. {
  2305.     local Pawn P;
  2306.  
  2307.     if ( Level.NetMode==NM_Client )
  2308.     {
  2309.         Admin("KillPawns");
  2310.         Return; // We are a client, pass it to server.
  2311.     }
  2312.     if( !Level.Game.GetAccessManager().CanExecuteCheat(Self,'KillPawns') )
  2313.         return;
  2314.     ForEach AllActors(class 'Pawn', P)
  2315.     if (PlayerPawn(P) == None)
  2316.         P.Destroy();
  2317. }
  2318.  
  2319. exec function Summon( string ClassName )
  2320. {
  2321.     local class<actor> New${1}< ${3} >
  2322.     local string Orginal${1}< ${3} >
  2323.  
  2324.     if( !Level.Game.GetAccessManager().CanExecuteCheatStr(Self,'Summon',ClassName) )
  2325.         return;
  2326.     OrginalClass = ClassName;
  2327.     if ( InStr(ClassName,".")==-1 )
  2328.         ClassName = "UnrealI."$ClassName;
  2329.     log( "Fabricate " $ ClassName );
  2330.     NewClass = class<actor>( DynamicLoadObject( ClassName, class'Class',True) );
  2331.     if ( NewClass!=None )
  2332.     {
  2333.         if ( NewClass.Default.bStatic )
  2334.             ClientMessage("Can not spawn"@NewClass@"because actor has bStatic");
  2335.         else if ( NewClass.Default.bNoDelete )
  2336.             ClientMessage("Can not spawn"@NewClass@"because actor has bNoDelete");
  2337.         else if ( Spawn( NewClass,,,Location + (40+NewClass.Default.CollisionRadius) * Vector(Rotation) + vect(0,0,1) * 15,ViewRotation)==None )
  2338.             ClientMessage("Failed to spawn class:"@NewClass);
  2339.     }
  2340.     else ClientMessage("Unable to load class"@OrginalClass);
  2341. }
  2342.  
  2343. exec function TimeDemo( bool bActivate, optional bool bSaveToFile, optional int QuitAfterCycles )
  2344. {
  2345.     if (Player.Console != None)
  2346.     {
  2347.         if (bActivate)
  2348.         {
  2349.             if (Player.Console.TimeDemo == None)
  2350.                 Player.Console.TimeDemo = Spawn(class'TimeDemo');
  2351.             Player.Console.TimeDemo.DoSetup(Player.Console, bSaveToFile, QuitAfterCycles);
  2352.         }
  2353.         else
  2354.         {
  2355.             if (Player.Console.TimeDemo != None)
  2356.                 Player.Console.TimeDemo.DoShutdown();
  2357.         }
  2358.     }
  2359. }
  2360.  
  2361.  
  2362. //==============
  2363. // Navigation Aids
  2364. exec function ShowPath()
  2365. {
  2366.     //find next path to remembered spot
  2367.     local Actor node;
  2368.  
  2369.     if (Level.Netmode != NM_Standalone)
  2370.         return;
  2371.  
  2372.     node = FindPathTo(Destination);
  2373.     if (node != None)
  2374.     {
  2375.         log("found path");
  2376.         Spawn(class 'WayBeacon', self, '', node.location);
  2377.     }
  2378.     else
  2379.         log("didn't find path");
  2380. }
  2381.  
  2382. exec function RememberSpot()
  2383. {
  2384.     //remember spot
  2385.     Destination = Location;
  2386. }
  2387.  
  2388. //=============================================================================
  2389. // Input related functions.
  2390.  
  2391. // Postprocess the player's input.
  2392.  
  2393. event PlayerInput( float DeltaTime )
  2394. {
  2395.     local float SmoothTime, FOVScale, MouseScale, KbdScale, AbsSmooth, AbsInput;
  2396.  
  2397.     LastCameraUpdate = -1;
  2398.  
  2399.     if ( bShowMenu && (myHud != None) )
  2400.     {
  2401.         if ( myHud.MainMenu != None )
  2402.             myHud.MainMenu.MenuTick( DeltaTime );
  2403.         // clear inputs
  2404.         bEdgeForward = false;
  2405.         bEdgeBack = false;
  2406.         bEdgeLeft = false;
  2407.         bEdgeRight = false;
  2408.         bWasForward = false;
  2409.         bWasBack = false;
  2410.         bWasLeft = false;
  2411.         bWasRight = false;
  2412.         aStrafe = 0;
  2413.         aTurn = 0;
  2414.         aForward = 0;
  2415.         aLookUp = 0;
  2416.         return;
  2417.     }
  2418.     else if ( bDelayedCommand )
  2419.     {
  2420.         bDelayedCommand = false;
  2421.         ConsoleCommand(DelayedCommand);
  2422.     }
  2423.  
  2424.     // Check for Dodge move
  2425.     // flag transitions
  2426.     bEdgeForward = (bWasForward ^^ (aBaseY > 0));
  2427.     bEdgeBack = (bWasBack ^^ (aBaseY < 0));
  2428.     bEdgeLeft = (bWasLeft ^^ (aStrafe > 0));
  2429.     bEdgeRight = (bWasRight ^^ (aStrafe < 0));
  2430.     bWasForward = (aBaseY > 0);
  2431.     bWasBack = (aBaseY < 0);
  2432.     bWasLeft = (aStrafe > 0);
  2433.     bWasRight = (aStrafe < 0);
  2434.  
  2435.     // Smooth and amplify mouse movement
  2436.     SmoothTime = FMin(0.2, 3 * DeltaTime);
  2437.     FOVScale = DesiredFOV * 0.01111;
  2438.     MouseScale = MouseSensitivity * FOVScale;
  2439.     aMouseX *= MouseScale;
  2440.     aMouseY *= MouseScale;
  2441.  
  2442. //************************************************************************
  2443.     if (bMouseSmoothing)
  2444.     {
  2445.         if ( bMaxMouseSmoothing )
  2446.         {
  2447.             if ( !bMouseZeroed )
  2448.             {
  2449.                 bMouseZeroed = ((aMouseX == 0) && (aMouseY == 0));
  2450.                 if ( aMouseX == 0 )
  2451.                 {
  2452.                     if ( SmoothMouseX > 0 )
  2453.                         aMouseX = 1;
  2454.                     else if ( SmoothMouseX < 0 )
  2455.                         aMouseX = -1;
  2456.                 }
  2457.                 if ( aMouseY == 0 )
  2458.                 {
  2459.                     if ( SmoothMouseY > 0 )
  2460.                         aMouseY = 1;
  2461.                     else if ( SmoothMouseY < 0 )
  2462.                         aMouseY = -1;
  2463.                 }
  2464.             }
  2465.             else
  2466.                 bMouseZeroed = ((aMouseX == 0) && (aMouseY == 0));
  2467.         }
  2468.  
  2469.         if ( (SmoothMouseX == 0) || (aMouseX == 0)
  2470.                 || ((SmoothMouseX > 0) != (aMouseX > 0)) )
  2471.             SmoothMouseX = aMouseX;
  2472.         else
  2473.         {
  2474.             AbsSmooth = Abs(SmoothMouseX);
  2475.             AbsInput = Abs(aMouseX);
  2476.             if ( (AbsSmooth < 0.85 * AbsInput) || (AbsSmooth > 1.17 * AbsInput) )
  2477.                 SmoothMouseX = 5 * SmoothTime * aMouseX + (1 - 5 * SmoothTime) * SmoothMouseX;
  2478.             else
  2479.                 SmoothMouseX = SmoothTime * aMouseX + (1 - SmoothTime) * SmoothMouseX;
  2480.         }
  2481.  
  2482.         if ( (SmoothMouseY == 0) || (aMouseY == 0)
  2483.                 || ((SmoothMouseY > 0) != (aMouseY > 0)) )
  2484.             SmoothMouseY = aMouseY;
  2485.         else
  2486.         {
  2487.             AbsSmooth = Abs(SmoothMouseY);
  2488.             AbsInput = Abs(aMouseY);
  2489.             if ( (AbsSmooth < 0.85 * AbsInput) || (AbsSmooth > 1.17 * AbsInput) )
  2490.                 SmoothMouseY = 5 * SmoothTime * aMouseY + (1 - 5 * SmoothTime) * SmoothMouseY;
  2491.             else
  2492.                 SmoothMouseY = SmoothTime * aMouseY + (1 - SmoothTime) * SmoothMouseY;
  2493.         }
  2494.     }
  2495.     else
  2496.     {
  2497.         SmoothMouseX = aMouseX;
  2498.         SmoothMouseY = aMouseY;
  2499.     }
  2500.  
  2501.     // adjust keyboard and joystick movements
  2502.     /*
  2503.     if ( (aLookUp == 0) && (aBaseX == 0) && (aTurn == 0) )
  2504.         KbdAccel = 0.4;
  2505.     else if ( KbdAccel < 1.6 )
  2506.     {
  2507.         if ( KbdAccel < 0.7 )
  2508.             KbdAccel += deltatime;
  2509.         else
  2510.             KbdAccel = FMin(1.6, KbdAccel + 4 * deltatime);
  2511.     }
  2512.     */
  2513.     KbdAccel = 1.0;
  2514.     KbdScale = FOVScale * KbdAccel;
  2515.     aLookUp *= FOVScale;
  2516.     aTurn   *= KbdScale;
  2517.  
  2518.     // Remap raw x-axis movement.
  2519.     if ( bStrafe!=0 )
  2520.     {
  2521.         // Strafe.
  2522.         aStrafe += aBaseX + SmoothMouseX;
  2523.         aBaseX   = 0;
  2524.     }
  2525.     else
  2526.     {
  2527.         // Forward.
  2528.         aTurn  += aBaseX * KbdScale + SmoothMouseX;
  2529.         aBaseX  = 0;
  2530.     }
  2531.  
  2532.     // Remap mouse y-axis movement.
  2533.     if ( (bStrafe == 0) && (bAlwaysMouseLook || (bLook!=0)) )
  2534.     {
  2535.         // Look up/down.
  2536.         if ( bInvertMouse )
  2537.             aLookUp -= SmoothMouseY;
  2538.         else
  2539.             aLookUp += SmoothMouseY;
  2540.     }
  2541.     else
  2542.     {
  2543.         // Move forward/backward.
  2544.         aForward += SmoothMouseY;
  2545.     }
  2546.  
  2547.     if ( bSnapLevel != 0 )
  2548.     {
  2549.         bCenterView = true;
  2550.         bKeyboardLook = false;
  2551.     }
  2552.     else if (aLookUp != 0)
  2553.     {
  2554.         bCenterView = false;
  2555.         bKeyboardLook = true;
  2556.     }
  2557.     else if ( bSnapToLevel && !bAlwaysMouseLook )
  2558.     {
  2559.         bCenterView = true;
  2560.         bKeyboardLook = false;
  2561.     }
  2562.  
  2563.     // Remap other y-axis movement.
  2564.     if ( bFreeLook != 0 )
  2565.     {
  2566.         bKeyboardLook = true;
  2567.         aLookUp += 0.5 * aBaseY * KbdScale;
  2568.     }
  2569.     else
  2570.         aForward += aBaseY;
  2571.  
  2572.     aBaseY = 0;
  2573.  
  2574.     // Handle walking.
  2575.     HandleWalking();
  2576. }
  2577.  
  2578. //=============================================================================
  2579. // functions.
  2580.  
  2581. event UpdateEyeHeight(float DeltaTime)
  2582. {
  2583.     local float smooth, bound;
  2584.  
  2585.     if (bIsReducedCrouch && IsInState('PlayerWalking'))
  2586.         BaseEyeHeight = default.BaseEyeHeight + CollisionHeight - default.CollisionHeight;
  2587.  
  2588.     smooth = FMin(1.0, 10.0 * DeltaTime/Level.TimeDilation);
  2589.     // smooth up/down stairs
  2590.     If( (IsInState('PlayerSwimming') || Physics==PHYS_Walking) && !bJustLanded )
  2591.     {
  2592.         EyeHeight = (EyeHeight - Location.Z + OldLocation.Z) * (1 - smooth) + ( ShakeVert + BaseEyeHeight) * smooth;
  2593.         bound = -0.5 * CollisionHeight;
  2594.         if (EyeHeight < bound)
  2595.             EyeHeight = bound;
  2596.         else
  2597.         {
  2598.             bound = FMin(FMax(0.0,(OldLocation.Z - Location.Z)), MaxStepHeight);
  2599.             if (bIsReducedCrouch)
  2600.                 bound += default.CollisionHeight;
  2601.             else
  2602.                 bound += CollisionHeight;
  2603.             if ( EyeHeight > bound )
  2604.                 EyeHeight = bound;
  2605.         }
  2606.     }
  2607.     else
  2608.     {
  2609.         smooth = FMax(smooth, 0.35);
  2610.         bJustLanded = false;
  2611.         EyeHeight = EyeHeight * ( 1 - smooth) + (BaseEyeHeight + ShakeVert) * smooth;
  2612.     }
  2613.  
  2614.     // teleporters affect your FOV, so adjust it back down
  2615.     if ( FOVAngle != DesiredFOV )
  2616.     {
  2617.         if ( FOVAngle > DesiredFOV )
  2618.             FOVAngle = FOVAngle - FMax(7, 0.9 * DeltaTime * (FOVAngle - DesiredFOV));
  2619.         else
  2620.             FOVAngle = FOVAngle - FMin(-7, 0.9 * DeltaTime * (FOVAngle - DesiredFOV));
  2621.         if ( Abs(FOVAngle - DesiredFOV) <= 10 )
  2622.             FOVAngle = DesiredFOV;
  2623.     }
  2624.  
  2625.     // adjust FOV for weapon zooming
  2626.     if ( bZooming )
  2627.     {
  2628.         ZoomLevel += DeltaTime * 1.0;
  2629.         if (ZoomLevel > 0.9)
  2630.             ZoomLevel = 0.9;
  2631.         DesiredFOV = FClamp(90.0 - (ZoomLevel * 88.0), 1, 170);
  2632.     }
  2633. }
  2634.  
  2635. event PlayerTimeOut()
  2636. {
  2637.     if (Health > 0)
  2638.         Died(None, 'suicided', Location);
  2639. }
  2640.  
  2641. // Just changed to pendingWeapon
  2642. function ChangedWeapon()
  2643. {
  2644.     Super.ChangedWeapon();
  2645.     if ( Weapon != None )
  2646.         Weapon.SetHand(Handedness);
  2647. }
  2648.  
  2649. function JumpOffPawn()
  2650. {
  2651.     Velocity += 60 * VRand();
  2652.     Velocity.Z = 120;
  2653.     SetPhysics(PHYS_Falling);
  2654. }
  2655.  
  2656. event TravelPostAccept()
  2657. {
  2658.     if ( Health <= 0 )
  2659.         Health = Default.Health;
  2660. }
  2661.  
  2662. // This pawn was possessed by a player.
  2663. event Possess()
  2664. {
  2665.     local byte i;
  2666.  
  2667.     if ( Level.Netmode == NM_Client )
  2668.     {
  2669.         // replicate client weapon preferences to server
  2670.         ServerSetHandedness(Handedness);
  2671.         for ( i=0; i<ArrayCount(WeaponPriority); i++ )
  2672.             ServerSetWeaponPriority(i, WeaponPriority[i]);
  2673.     }
  2674.     else if ( ViewPort(Player)!=None )
  2675.         bAdmin = True;
  2676.     ServerUpdateWeapons();
  2677.     bIsPlayer = true;
  2678.     DodgeClickTime = FMin(0.3, DodgeClickTime);
  2679.     EyeHeight = BaseEyeHeight;
  2680.     NetPriority = 8;
  2681.     StartWalk();
  2682.     DefaultFOV = FClamp(MainFOV, 90, 170);
  2683.     DesiredFOV = DefaultFOV;
  2684.     NeverSwitchOnPickup(bNeverAutoSwitch);
  2685. }
  2686.  
  2687. function ServerSetWeaponPriority(byte i, name WeaponName)
  2688. {
  2689.     if (i < ArrayCount(WeaponPriority))
  2690.         WeaponPriority[i] = WeaponName;
  2691. }
  2692.  
  2693. // This pawn was unpossessed by a player.
  2694. event UnPossess()
  2695. {
  2696.     log(Self$" being unpossessed");
  2697.     if ( myHUD != None )
  2698.         myHUD.Destroy();
  2699.     bIsPlayer = false;
  2700.     EyeHeight = 0.8 * CollisionHeight;
  2701. }
  2702.  
  2703. singular function Carcass SpawnCarcass()
  2704. {
  2705.     local carcass carc;
  2706.  
  2707.     carc = Spawn(CarcassType);
  2708.     if ( carc != None )
  2709.     {
  2710.         carc.Initfor(self);
  2711.         if (Player != None)
  2712.             carc.bPlayerCarcass = true;
  2713.         MoveTarget = carc; //for Player 3rd person views
  2714.     }
  2715.     return carc;
  2716. }
  2717.  
  2718. function bool Gibbed(name damageType)
  2719. {
  2720.     if ( (damageType == 'decapitated') || (damageType == 'shot') )
  2721.         return false;
  2722.     if ( (Health < -80) || ((Health < -40) && (FRand() < 0.6)) )
  2723.         return true;
  2724.     return false;
  2725. }
  2726.  
  2727. singular function SpawnGibbedCarcass()
  2728. {
  2729.     local carcass carc;
  2730.  
  2731.     carc = Spawn(CarcassType);
  2732.     if ( carc != None )
  2733.     {
  2734.         carc.Initfor(self);
  2735.         carc.ChunkUp(-1 * Health);
  2736.         MoveTarget = carc; //for Player 3rd person views
  2737.     }
  2738. }
  2739.  
  2740. event PlayerTick( float Time );
  2741.  
  2742. //
  2743. // Called immediately before gameplay begins.
  2744. //
  2745. event PreBeginPlay()
  2746. {
  2747.     bIsPlayer = true;
  2748.     Super.PreBeginPlay();
  2749. }
  2750.  
  2751. event PostBeginPlay()
  2752. {
  2753.     Super.PostBeginPlay();
  2754.     if (Level.LevelEnterText != "" )
  2755.         ClientMessage(Level.LevelEnterText);
  2756.     if ( Level.NetMode != NM_Client )
  2757.     {
  2758.         HUDType = Level.Game.HUDType;
  2759.         ScoringType = Level.Game.ScoreboardType;
  2760.         MyAutoAim = FMax(MyAutoAim, Level.Game.AutoAim);
  2761.     }
  2762.     bIsPlayer = true;
  2763.     DodgeClickTime = FMin(0.3, DodgeClickTime);
  2764.     EyeHeight = BaseEyeHeight;
  2765.     if ( Level.Game.IsA('SinglePlayer') && (Level.NetMode == NM_Standalone) )
  2766.         FlashScale = vect(0,0,0);
  2767.     If (MainFOV < 90.0 || MainFOV >170.0)
  2768.     MainFOV = 90.0;
  2769.     DefaultFOV=MainFOV;
  2770. }
  2771.  
  2772. function ServerUpdateWeapons()
  2773. {
  2774.     local inventory Inv;
  2775.  
  2776.     For ( Inv=Inventory; Inv!=None; Inv=Inv.Inventory )
  2777.     if ( Inv.IsA('Weapon') )
  2778.         Weapon(Inv).SetSwitchPriority(self);
  2779. }
  2780.  
  2781. //=============================================================================
  2782. // Animation playing - should be implemented in subclass,
  2783. //
  2784.  
  2785. function PlayDodge(eDodgeDir DodgeMove)
  2786. {
  2787.     PlayDuck();
  2788. }
  2789.  
  2790. function PlayTurning();
  2791.  
  2792. function PlaySwimming()
  2793. {
  2794.     PlayRunning();
  2795. }
  2796.  
  2797. function PlayFeignDeath();
  2798. function PlayRising();
  2799.  
  2800. /* Adjust hit location - adjusts the hit location in for pawns, and returns
  2801. true if it was really a hit, and false if not (for ducking, etc.)
  2802. */
  2803. simulated function bool AdjustHitLocation(out vector HitLocation, vector TraceDir)
  2804. {
  2805.     local float adjZ, maxZ;
  2806.  
  2807.     TraceDir = Normal(TraceDir);
  2808.     HitLocation = HitLocation + 0.5 * CollisionRadius * TraceDir;
  2809.     if (BaseEyeHeight == default.BaseEyeHeight || bIsCrouching && bIsReducedCrouch)
  2810.         return true;
  2811.  
  2812.     maxZ = Location.Z + EyeHeight + 0.25 * CollisionHeight;
  2813.     if ( HitLocation.Z > maxZ )
  2814.     {
  2815.         if ( TraceDir.Z >= 0 )
  2816.             return false;
  2817.         adjZ = (maxZ - HitLocation.Z)/TraceDir.Z;
  2818.         HitLocation.Z = maxZ;
  2819.         HitLocation.X = HitLocation.X + TraceDir.X * adjZ;
  2820.         HitLocation.Y = HitLocation.Y + TraceDir.Y * adjZ;
  2821.         if ( VSize(HitLocation - Location) > CollisionRadius )
  2822.             return false;
  2823.     }
  2824.     return true;
  2825. }
  2826.  
  2827. /* AdjustAim()
  2828. Calls this version for player aiming help.
  2829. Aimerror not used in this version.
  2830. Only adjusts aiming at pawns
  2831. */
  2832.  
  2833. function rotator AdjustAim(float projSpeed, vector projStart, int aimerror, bool bLeadTarget, bool bWarnTarget)
  2834. {
  2835.     local vector FireDir, AimSpot, HitNormal, HitLocation;
  2836.     local actor BestTarget;
  2837.     local float bestAim, bestDist;
  2838.     local actor HitActor;
  2839.  
  2840.     FireDir = vector(ViewRotation);
  2841.     HitActor = Trace(HitLocation, HitNormal, projStart + 4000 * FireDir, projStart, true);
  2842.     if ( (HitActor != None) && HitActor.bProjTarget )
  2843.     {
  2844.         if ( bWarnTarget && HitActor.IsA('Pawn') )
  2845.             Pawn(HitActor).WarnTarget(self, projSpeed, FireDir);
  2846.         return ViewRotation;
  2847.     }
  2848.  
  2849.     bestAim = FMin(0.93, MyAutoAim);
  2850.     BestTarget = PickTarget(bestAim, bestDist, FireDir, projStart);
  2851.  
  2852.     if ( bWarnTarget && (Pawn(BestTarget) != None) )
  2853.         Pawn(BestTarget).WarnTarget(self, projSpeed, FireDir);
  2854.  
  2855.     if ( (Level.NetMode != NM_Standalone) || (Level.Game.Difficulty > 2)
  2856.             || bAlwaysMouseLook || ((BestTarget != None) && (bestAim < MyAutoAim)) || (MyAutoAim >= 1) )
  2857.         return ViewRotation;
  2858.  
  2859.     if ( BestTarget == None )
  2860.     {
  2861.         bestAim = MyAutoAim;
  2862.         BestTarget = PickAnyTarget(bestAim, bestDist, FireDir, projStart);
  2863.         if ( BestTarget == None )
  2864.             return ViewRotation;
  2865.     }
  2866.  
  2867.     AimSpot = projStart + FireDir * bestDist;
  2868.     AimSpot.Z = BestTarget.Location.Z + 0.3 * BestTarget.CollisionHeight;
  2869.  
  2870.     return rotator(AimSpot - projStart);
  2871. }
  2872.  
  2873. function Falling()
  2874. {
  2875.     //SetPhysics(PHYS_Falling); //Note - physics changes type to PHYS_Falling by default
  2876.     //log(class$" Falling");
  2877.     PlayInAir();
  2878. }
  2879.  
  2880. function Landed(vector HitNormal)
  2881. {
  2882.     //Note - physics changes type to PHYS_Walking by default for landed pawns
  2883.     PlayLanded(Velocity.Z);
  2884.     if (Velocity.Z < -1.4 * JumpZ)
  2885.     {
  2886.         MakeNoise(-0.5 * Velocity.Z/(FMax(JumpZ, 150.0)));
  2887.         ShakeView(0.175 - 0.00007 * Velocity.Z, -0.85 * Velocity.Z, -0.002 * Velocity.Z);
  2888.         if (Velocity.Z <= -1100)
  2889.         {
  2890.             if ( (Velocity.Z < -2000) && (ReducedDamageType != 'All') )
  2891.                 TakeDamage(1000, None, Location, vect(0,0,0), 'fell');
  2892.             else if ( Role == ROLE_Authority )
  2893.                 TakeDamage(-0.15 * (Velocity.Z + 1050), None, Location, vect(0,0,0), 'fell');
  2894.         }
  2895.     }
  2896.     else if ( (Level.Game != None) && (Level.Game.Difficulty > 1) && (Velocity.Z > 0.5 * JumpZ) )
  2897.         MakeNoise(0.1 * Level.Game.Difficulty);
  2898.     bJustLanded = true;
  2899. }
  2900.  
  2901. function Died(pawn Killer, name damageType, vector HitLocation)
  2902. {
  2903.     //Assert( Role = ROLE_Authority );
  2904.     // encroach problem may cause this
  2905.     // so temp
  2906.     if (Role != ROLE_Authority)
  2907.     {
  2908.         log("Non-authority tried to die");
  2909.         return;
  2910.     }
  2911.  
  2912.     StopZoom();
  2913.  
  2914.     Super.Died(Killer, damageType, HitLocation);
  2915. }
  2916.  
  2917. function eAttitude AttitudeTo(Pawn Other)
  2918. {
  2919.     if (Other.bIsPlayer)
  2920.         return AttitudeToPlayer;
  2921.     else
  2922.         return Other.AttitudeToPlayer;
  2923. }
  2924.  
  2925.  
  2926. function string KillMessage( name damageType, pawn Other )
  2927. {
  2928.     return ( Level.Game.PlayerKillMessage(damageType, Other)$PlayerReplicationInfo.PlayerName );
  2929. }
  2930.  
  2931. //=============================================================================
  2932. // Player Control
  2933.  
  2934. function KilledBy( pawn EventInstigator )
  2935. {
  2936.     Health = 0;
  2937.     Died( EventInstigator, 'suicided', Location );
  2938. }
  2939.  
  2940. // Player view.
  2941. // Compute the rendering viewpoint for the player.
  2942. //
  2943.  
  2944. function CalcBehindView(out vector CameraLocation, out rotator CameraRotation, float Dist)
  2945. {
  2946.     local vector View,HitLocation,HitNormal;
  2947.     local float ViewDist;
  2948.  
  2949.     CameraRotation = ViewRotation;
  2950.     View = vect(1,0,0) >> CameraRotation;
  2951.     if ( Trace( HitLocation, HitNormal, CameraLocation - (Dist + 30) * vector(CameraRotation), CameraLocation ) != None )
  2952.         ViewDist = FMin( (CameraLocation - HitLocation) Dot View, Dist );
  2953.     else
  2954.         ViewDist = Dist;
  2955.     CameraLocation -= (ViewDist - 30) * View;
  2956. }
  2957.  
  2958. event PlayerCalcView(out actor ViewActor, out vector CameraLocation, out rotator CameraRotation )
  2959. {
  2960.     local Pawn PTarget;
  2961.  
  2962.     if ( ViewTarget != None )
  2963.     {
  2964.         ViewActor = ViewTarget;
  2965.         CameraLocation = ViewTarget.Location;
  2966.         CameraRotation = ViewTarget.Rotation;
  2967.         PTarget = Pawn(ViewTarget);
  2968.         if ( PTarget != None )
  2969.         {
  2970.             if ( Level.NetMode == NM_Client )
  2971.             {
  2972.                 if ( PTarget.bIsPlayer )
  2973.                     PTarget.ViewRotation = TargetViewRotation;
  2974.                 PTarget.EyeHeight = TargetEyeHeight;
  2975.                 if ( PTarget.Weapon != None )
  2976.                     PTarget.Weapon.PlayerViewOffset = TargetWeaponViewOffset;
  2977.             }
  2978.             if ( PTarget.bIsPlayer )
  2979.                 CameraRotation = PTarget.ViewRotation;
  2980.             if ( !bBehindView )
  2981.                 CameraLocation.Z += PTarget.EyeHeight;
  2982.             else
  2983.                 CameraLocation.Z += PTarget.PrePivot.Z - PTarget.default.PrePivot.Z;
  2984.         }
  2985.         if ( bBehindView )
  2986.             CalcBehindView(CameraLocation, CameraRotation, 180);
  2987.         return;
  2988.     }
  2989.  
  2990.     ViewActor = Self;
  2991.     CameraLocation = Location;
  2992.  
  2993.     if ( bBehindView ) //up and behind
  2994.     {
  2995.         CameraLocation.Z += PrePivot.Z - default.PrePivot.Z;
  2996.         CalcBehindView(CameraLocation, CameraRotation, 150);
  2997.     }
  2998.     else
  2999.     {
  3000.         // First-person view.
  3001.         CameraRotation = ViewRotation;
  3002.         CameraLocation.Z += EyeHeight;
  3003.         CameraLocation += WalkBob;
  3004.     }
  3005. }
  3006.  
  3007. exec function SetViewFlash(bool B)
  3008. {
  3009.     bNoFlash = !B;
  3010. }
  3011.  
  3012. function ViewFlash(float DeltaTime)
  3013. {
  3014.     local vector goalFog;
  3015.     local float goalscale, delta;
  3016.  
  3017.     if ( bNoFlash )
  3018.     {
  3019.         InstantFlash = 0;
  3020.         InstantFog = vect(0,0,0);
  3021.     }
  3022.     delta = FMin(0.1, DeltaTime);
  3023.     goalScale = 1 + DesiredFlashScale + ConstantGlowScale;
  3024.     goalFog = DesiredFlashFog + ConstantGlowFog;
  3025.  
  3026.     if ( CameraRegion.Zone!=None )
  3027.     {
  3028.         goalScale+=CameraRegion.Zone.ViewFlash.X;
  3029.         goalFog+=CameraRegion.Zone.ViewFog;
  3030.     }
  3031.  
  3032.     DesiredFlashScale -= DesiredFlashScale * 2 * delta;
  3033.     DesiredFlashFog -= DesiredFlashFog * 2 * delta;
  3034.     FlashScale.X += (goalScale - FlashScale.X + InstantFlash) * 10 * delta;
  3035.     //FlashFog += (goalFog - FlashFog + InstantFog) * 10 * delta;
  3036.     CurrentFlashFog += (goalFog - CurrentFlashFog + InstantFog) * 10 * delta;
  3037.     InstantFlash = 0;
  3038.     InstantFog = vect(0,0,0);
  3039.  
  3040.     if ( FlashScale.X > 0.981 )
  3041.         FlashScale.X = 1;
  3042.     FlashScale = FlashScale.X * vect(1,1,1);
  3043.  
  3044.     FlashFog = CurrentFlashFog;
  3045.     if ( FlashFog.X < 0.019 )
  3046.         FlashFog.X = 0;
  3047.     if ( FlashFog.Y < 0.019 )
  3048.         FlashFog.Y = 0;
  3049.     if ( FlashFog.Z < 0.019 )
  3050.         FlashFog.Z = 0;
  3051. }
  3052.  
  3053. function ViewShake(float DeltaTime)
  3054. {
  3055.     if (shaketimer > 0.0) //shake view
  3056.     {
  3057.         Shaketimer=FClamp(Shaketimer,0.0,4.0); //4 seconds max
  3058.         shaketimer -= DeltaTime;
  3059.         if ( verttimer == 0 )
  3060.         {
  3061.             verttimer = 0.1;
  3062.             ShakeVert = -1.1 * maxshake;
  3063.         }
  3064.         else
  3065.         {
  3066.             verttimer -= DeltaTime;
  3067.             if ( verttimer < 0 )
  3068.             {
  3069.                 verttimer = 0.2 * FRand();
  3070.                 shakeVert = (2 * FRand() - 1) * maxshake;
  3071.             }
  3072.         }
  3073.         ViewRotation.Roll = ViewRotation.Roll & 65535;
  3074.         if (bShakeDir)
  3075.         {
  3076.             ViewRotation.Roll += Int( 10 * shakemag * FMin(0.1, DeltaTime));
  3077.             bShakeDir = (ViewRotation.Roll > 32768) || (ViewRotation.Roll < (0.5 + FRand()) * shakemag);
  3078.             if ( (ViewRotation.Roll < 32768) && (ViewRotation.Roll > 1.3 * shakemag) )
  3079.             {
  3080.                 ViewRotation.Roll = 1.3 * shakemag;
  3081.                 bShakeDir = false;
  3082.             }
  3083.             else if (FRand() < 3 * DeltaTime)
  3084.                 bShakeDir = !bShakeDir;
  3085.         }
  3086.         else
  3087.         {
  3088.             ViewRotation.Roll -= Int( 10 * shakemag * FMin(0.1, DeltaTime));
  3089.             bShakeDir = (ViewRotation.Roll > 32768) && (ViewRotation.Roll < 65535 - (0.5 + FRand()) * shakemag);
  3090.             if ( (ViewRotation.Roll > 32768) && (ViewRotation.Roll < 65535 - 1.3 * shakemag) )
  3091.             {
  3092.                 ViewRotation.Roll = 65535 - 1.3 * shakemag;
  3093.                 bShakeDir = true;
  3094.             }
  3095.             else if (FRand() < 3 * DeltaTime)
  3096.                 bShakeDir = !bShakeDir;
  3097.         }
  3098.     }
  3099.     else
  3100.     {
  3101.         ShakeVert = 0;
  3102.         ViewRotation.Roll = ViewRotation.Roll & 65535;
  3103.         if (ViewRotation.Roll < 32768)
  3104.         {
  3105.             if ( ViewRotation.Roll > 0 )
  3106.                 ViewRotation.Roll = Max(0, ViewRotation.Roll - (Max(ViewRotation.Roll,500) * 10 * FMin(0.1,DeltaTime)));
  3107.         }
  3108.         else
  3109.         {
  3110.             ViewRotation.Roll += ((65536 - Max(500,ViewRotation.Roll)) * 10 * FMin(0.1,DeltaTime));
  3111.             if ( ViewRotation.Roll > 65534 )
  3112.                 ViewRotation.Roll = 0;
  3113.         }
  3114.     }
  3115. }
  3116.  
  3117. function UpdateRotation(float DeltaTime, float maxPitch)
  3118. {
  3119.     local rotator newRotation;
  3120.  
  3121.     DesiredRotation = ViewRotation; //save old rotation
  3122.     ViewRotation.Pitch += 32.0 * DeltaTime * aLookUp;
  3123.     ViewRotation.Pitch = ViewRotation.Pitch & 65535;
  3124.     If ((ViewRotation.Pitch > 18000) && (ViewRotation.Pitch < 49152))
  3125.     {
  3126.         If (aLookUp > 0)
  3127.         ViewRotation.Pitch = 18000;
  3128.         else
  3129.             ViewRotation.Pitch = 49152;
  3130.     }
  3131.     ViewRotation.Yaw += 32.0 * DeltaTime * aTurn;
  3132.     ViewShake(deltaTime);
  3133.     ViewFlash(deltaTime);
  3134.  
  3135.     newRotation = Rotation;
  3136.     newRotation.Yaw = ViewRotation.Yaw;
  3137.     newRotation.Pitch = ViewRotation.Pitch;
  3138.     If ( (newRotation.Pitch > maxPitch * RotationRate.Pitch) && (newRotation.Pitch < 65536 - maxPitch * RotationRate.Pitch) )
  3139.     {
  3140.         If (ViewRotation.Pitch < 32768)
  3141.         newRotation.Pitch = maxPitch * RotationRate.Pitch;
  3142.         else
  3143.             newRotation.Pitch = 65536 - maxPitch * RotationRate.Pitch;
  3144.     }
  3145.     UpdatePawnRotation(newRotation);
  3146. }
  3147.  
  3148. function SwimAnimUpdate(bool bNotForward)
  3149. {
  3150.     if ( !bAnimTransition && (GetAnimGroup(AnimSequence) != 'Gesture') )
  3151.     {
  3152.         if ( bNotForward )
  3153.         {
  3154.             if ( GetAnimGroup(AnimSequence) != 'Waiting' )
  3155.                 TweenToWaiting(0.1);
  3156.         }
  3157.         else if ( GetAnimGroup(AnimSequence) == 'Waiting' )
  3158.             TweenToSwimming(0.1);
  3159.     }
  3160. }
  3161.  
  3162. // Player movement.
  3163. // Player Standing, walking, running, falling.
  3164. state PlayerWalking
  3165. {
  3166. ignores SeePlayer, HearNoise, Bump;
  3167.  
  3168.     exec function FeignDeath()
  3169.     {
  3170.         if ( Physics == PHYS_Walking )
  3171.         {
  3172.             ServerFeignDeath();
  3173.             Acceleration = vect(0,0,0);
  3174.             GotoState('FeigningDeath');
  3175.         }
  3176.     }
  3177.  
  3178.     function ZoneChange( ZoneInfo NewZone )
  3179.     {
  3180.         if (NewZone.bWaterZone)
  3181.         {
  3182.             setPhysics(PHYS_Swimming);
  3183.             GotoState('PlayerSwimming');
  3184.         }
  3185.     }
  3186.  
  3187.     function AnimEnd()
  3188.     {
  3189.         local name MyAnimGroup;
  3190.  
  3191.         bAnimTransition = false;
  3192.         if ( Physics == PHYS_Spider )
  3193.         {
  3194.             if ( VSize(Velocity)<10 )
  3195.                 PlayDuck();
  3196.             else PlayCrawling();
  3197.         }
  3198.         else if (Physics == PHYS_Walking)
  3199.         {
  3200.             if (bIsCrouching)
  3201.             {
  3202.                 if ( !bIsTurning && ((Velocity.X * Velocity.X + Velocity.Y * Velocity.Y) < 1000) )
  3203.                     PlayDuck();
  3204.                 else
  3205.                     PlayCrawling();
  3206.             }
  3207.             else
  3208.             {
  3209.                 MyAnimGroup = GetAnimGroup(AnimSequence);
  3210.                 if ((Velocity.X * Velocity.X + Velocity.Y * Velocity.Y) < 1000)
  3211.                 {
  3212.                     if ( MyAnimGroup == 'Waiting' )
  3213.                         PlayWaiting();
  3214.                     else
  3215.                     {
  3216.                         bAnimTransition = true;
  3217.                         TweenToWaiting(0.2);
  3218.                     }
  3219.                 }
  3220.                 else if (bIsWalking)
  3221.                 {
  3222.                     if ( (MyAnimGroup == 'Waiting') || (MyAnimGroup == 'Landing') || (MyAnimGroup == 'Gesture') || (MyAnimGroup == 'TakeHit')  )
  3223.                     {
  3224.                         TweenToWalking(0.1);
  3225.                         bAnimTransition = true;
  3226.                     }
  3227.                     else
  3228.                         PlayWalking();
  3229.                 }
  3230.                 else
  3231.                 {
  3232.                     if ( (MyAnimGroup == 'Waiting') || (MyAnimGroup == 'Landing') || (MyAnimGroup == 'Gesture') || (MyAnimGroup == 'TakeHit')  )
  3233.                     {
  3234.                         bAnimTransition = true;
  3235.                         TweenToRunning(0.1);
  3236.                     }
  3237.                     else
  3238.                         PlayRunning();
  3239.                 }
  3240.             }
  3241.         }
  3242.         else if (bIsReducedCrouch)
  3243.             PlayDuck();
  3244.         else
  3245.             PlayInAir();
  3246.     }
  3247.  
  3248.     function Landed(vector HitNormal)
  3249.     {
  3250.         Global.Landed(HitNormal);
  3251.         if (DodgeDir == DODGE_Active)
  3252.         {
  3253.             DodgeDir = DODGE_Done;
  3254.             DodgeClickTimer = 0.0;
  3255.             Velocity *= 0.1;
  3256.         }
  3257.         else
  3258.             DodgeDir = DODGE_None;
  3259.     }
  3260.  
  3261.     function Dodge(eDodgeDir DodgeMove)
  3262.     {
  3263.         local vector X,Y,Z;
  3264.  
  3265.         if ( bIsCrouching || (Physics != PHYS_Walking) )
  3266.             return;
  3267.  
  3268.         GetAxes(Rotation,X,Y,Z);
  3269.         if (DodgeMove == DODGE_Forward)
  3270.             Velocity = 1.5*GroundSpeed*X + (Velocity Dot Y)*Y;
  3271.         else if (DodgeMove == DODGE_Back)
  3272.             Velocity = -1.5*GroundSpeed*X + (Velocity Dot Y)*Y;
  3273.         else if (DodgeMove == DODGE_Left)
  3274.             Velocity = 1.5*GroundSpeed*Y + (Velocity Dot X)*X;
  3275.         else if (DodgeMove == DODGE_Right)
  3276.             Velocity = -1.5*GroundSpeed*Y + (Velocity Dot X)*X;
  3277.  
  3278.         Velocity.Z = 160;
  3279.         if ( Role == ROLE_Authority )
  3280.             PlaySound(JumpSound, SLOT_Talk, 1.0, true, 800, 1.0 );
  3281.         PlayDodge(DodgeMove);
  3282.         DodgeDir = DODGE_Active;
  3283.         SetPhysics(PHYS_Falling);
  3284.     }
  3285.  
  3286.     function ProcessMove(float DeltaTime, vector NewAccel, eDodgeDir DodgeMove, rotator DeltaRot)
  3287.     {
  3288.         local vector OldAccel;
  3289.  
  3290.         OldAccel = Acceleration;
  3291.         Acceleration = NewAccel;
  3292.         bIsTurning = ( Abs(DeltaRot.Yaw/DeltaTime) > 5000 );
  3293.         if ( (DodgeMove == DODGE_Active) && (Physics == PHYS_Falling) )
  3294.             DodgeDir = DODGE_Active;
  3295.         else if ( (DodgeMove != DODGE_None) && (DodgeMove < DODGE_Active) )
  3296.             Dodge(DodgeMove);
  3297.  
  3298.         if ( bPressedJump )
  3299.             DoJump();
  3300.         if ( (Physics == PHYS_Walking) && (GetAnimGroup(AnimSequence) != 'Dodge') )
  3301.         {
  3302.             if ( !bIsCrouching )
  3303.             {
  3304.                 if ( bDuck != 0 && TryToDuck(true) && IsInState('PlayerWalking') ) // Note: TryToDuck may change the state (e.g. to PlayerSwimming)
  3305.                 {
  3306.                     bIsCrouching = true;
  3307.                     PlayDuck();
  3308.                 }
  3309.             }
  3310.             else if ( bDuck == 0 && TryToDuck(false) )
  3311.             {
  3312.                 OldAccel = vect(0,0,0);
  3313.                 bIsCrouching = false;
  3314.             }
  3315.  
  3316.             if ( !bIsCrouching )
  3317.             {
  3318.                 if ( (!bAnimTransition || (AnimFrame > 0)) && (GetAnimGroup(AnimSequence) != 'Landing') )
  3319.                 {
  3320.                     if ( Acceleration != vect(0,0,0) )
  3321.                     {
  3322.                         if ( (GetAnimGroup(AnimSequence) == 'Waiting') || (GetAnimGroup(AnimSequence) == 'Gesture') || (GetAnimGroup(AnimSequence) == 'TakeHit') )
  3323.                         {
  3324.                             bAnimTransition = true;
  3325.                             TweenToRunning(0.1);
  3326.                         }
  3327.                     }
  3328.                     else if ( (Velocity.X * Velocity.X + Velocity.Y * Velocity.Y < 1000)
  3329.                               && (GetAnimGroup(AnimSequence) != 'Gesture') )
  3330.                     {
  3331.                         if ( GetAnimGroup(AnimSequence) == 'Waiting' )
  3332.                         {
  3333.                             if ( bIsTurning && (AnimFrame >= 0) )
  3334.                             {
  3335.                                 bAnimTransition = true;
  3336.                                 PlayTurning();
  3337.                             }
  3338.                         }
  3339.                         else if ( !bIsTurning )
  3340.                         {
  3341.                             bAnimTransition = true;
  3342.                             TweenToWaiting(0.2);
  3343.                         }
  3344.                     }
  3345.                 }
  3346.             }
  3347.             else
  3348.             {
  3349.                 if ( (OldAccel == vect(0,0,0)) && (Acceleration != vect(0,0,0)) )
  3350.                     PlayCrawling();
  3351.                 else if ( !bIsTurning && (Acceleration == vect(0,0,0)) && (AnimFrame > 0.1) )
  3352.                     PlayDuck();
  3353.             }
  3354.         }
  3355.     }
  3356.  
  3357.     event PlayerTick( float DeltaTime )
  3358.     {
  3359.         if ( bUpdatePosition )
  3360.             ClientUpdatePosition();
  3361.  
  3362.         PlayerMove(DeltaTime);
  3363.     }
  3364.  
  3365.     function PlayerMove( float DeltaTime )
  3366.     {
  3367.         local vector X,Y,Z, NewAccel;
  3368.         local EDodgeDir OldDodge;
  3369.         local eDodgeDir DodgeMove;
  3370.         local rotator OldRotation;
  3371.         local float Speed2D;
  3372.         local bool    bSaveJump;
  3373.         local name AnimGroupName;
  3374.  
  3375.         if ( Physics==PHYS_Spider )
  3376.             GetAxes(ViewRotation,X,Y,Z);
  3377.         else GetAxes(Rotation,X,Y,Z);
  3378.  
  3379.         aForward *= 0.4;
  3380.         aStrafe  *= 0.4;
  3381.         aLookup  *= 0.24;
  3382.         aTurn    *= 0.24;
  3383.  
  3384.         // Update acceleration.
  3385.         NewAccel = aForward*X + aStrafe*Y;
  3386.         if ( Physics!=PHYS_Spider )
  3387.             NewAccel.Z = 0;
  3388.         // Check for Dodge move
  3389.         if ( DodgeDir == DODGE_Active )
  3390.             DodgeMove = DODGE_Active;
  3391.         else DodgeMove = DODGE_None;
  3392.         if (DodgeClickTime > 0.0)
  3393.         {
  3394.             if ( DodgeDir < DODGE_Active )
  3395.             {
  3396.                 OldDodge = DodgeDir;
  3397.                 DodgeDir = DODGE_None;
  3398.                 if (bEdgeForward && bWasForward)
  3399.                     DodgeDir = DODGE_Forward;
  3400.                 if (bEdgeBack && bWasBack)
  3401.                     DodgeDir = DODGE_Back;
  3402.                 if (bEdgeLeft && bWasLeft)
  3403.                     DodgeDir = DODGE_Left;
  3404.                 if (bEdgeRight && bWasRight)
  3405.                     DodgeDir = DODGE_Right;
  3406.                 if ( DodgeDir == DODGE_None)
  3407.                     DodgeDir = OldDodge;
  3408.                 else if ( DodgeDir != OldDodge )
  3409.                     DodgeClickTimer = DodgeClickTime + 0.5 * DeltaTime;
  3410.                 else
  3411.                     DodgeMove = DodgeDir;
  3412.             }
  3413.  
  3414.             if (DodgeDir == DODGE_Done)
  3415.             {
  3416.                 DodgeClickTimer -= DeltaTime;
  3417.                 if (DodgeClickTimer < -0.35)
  3418.                 {
  3419.                     DodgeDir = DODGE_None;
  3420.                     DodgeClickTimer = DodgeClickTime;
  3421.                 }
  3422.             }
  3423.             else if ((DodgeDir != DODGE_None) && (DodgeDir != DODGE_Active))
  3424.             {
  3425.                 DodgeClickTimer -= DeltaTime;
  3426.                 if (DodgeClickTimer < 0)
  3427.                 {
  3428.                     DodgeDir = DODGE_None;
  3429.                     DodgeClickTimer = DodgeClickTime;
  3430.                 }
  3431.             }
  3432.         }
  3433.  
  3434.         AnimGroupName = GetAnimGroup(AnimSequence);
  3435.         if ( (Physics == PHYS_Walking) && (AnimGroupName != 'Dodge') )
  3436.         {
  3437.             //if walking, look up/down stairs - unless player is rotating view
  3438.             if ( !bKeyboardLook && (bLook == 0) )
  3439.             {
  3440.                 if ( bLookUpStairs )
  3441.                     ViewRotation.Pitch = FindStairRotation(deltaTime);
  3442.                 else if ( bCenterView )
  3443.                 {
  3444.                     ViewRotation.Pitch = ViewRotation.Pitch & 65535;
  3445.                     if (ViewRotation.Pitch > 32768)
  3446.                         ViewRotation.Pitch -= 65536;
  3447.                     ViewRotation.Pitch = ViewRotation.Pitch * (1 - 12 * FMin(0.0833, deltaTime));
  3448.                     if ( Abs(ViewRotation.Pitch) < 1000 )
  3449.                         ViewRotation.Pitch = 0;
  3450.                 }
  3451.             }
  3452.  
  3453.             Speed2D = Sqrt(Velocity.X * Velocity.X + Velocity.Y * Velocity.Y);
  3454.             //add bobbing when walking
  3455.             if ( !bShowMenu )
  3456.             {
  3457.                 if ( Speed2D < 10 || GroundSpeed == 0 )
  3458.                     BobTime += 0.2 * DeltaTime * FClamp(Region.Zone.ZoneTimeDilation,0.1,10.f);
  3459.                 else
  3460.                     BobTime += DeltaTime * FClamp(Region.Zone.ZoneTimeDilation,0.1,10.f) * (0.3 + 0.7 * Speed2D/GroundSpeed);
  3461.                 WalkBob = Y * 0.65 * Bob * Speed2D * sin(6.0 * BobTime);
  3462.                 if ( Speed2D < 10 )
  3463.                     WalkBob.Z = Bob * 30 * sin(12 * BobTime);
  3464.                 else WalkBob.Z = Bob * Speed2D * sin(12 * BobTime);
  3465.             }
  3466.         }
  3467.         else if ( !bShowMenu )
  3468.         {
  3469.             BobTime = 0;
  3470.             WalkBob = WalkBob * (1 - FMin(1, 8 * deltatime));
  3471.         }
  3472.  
  3473.         // Update rotation.
  3474.         OldRotation = Rotation;
  3475.         UpdateRotation(DeltaTime, 1);
  3476.  
  3477.         if ( bPressedJump && (AnimGroupName == 'Dodge') )
  3478.         {
  3479.             bSaveJump = true;
  3480.             bPressedJump = false;
  3481.         }
  3482.         else
  3483.             bSaveJump = false;
  3484.  
  3485.         if ( Role < ROLE_Authority ) // then save this move and replicate it
  3486.             ReplicateMove(DeltaTime, NewAccel, DodgeMove, OldRotation - Rotation);
  3487.         else
  3488.             ProcessMove(DeltaTime, NewAccel, DodgeMove, OldRotation - Rotation);
  3489.         bPressedJump = bSaveJump;
  3490.     }
  3491.  
  3492.     function BeginState()
  3493.     {
  3494.         WalkBob = vect(0,0,0);
  3495.         DodgeDir = DODGE_None;
  3496.         bIsCrouching = bIsReducedCrouch;
  3497.         bIsTurning = false;
  3498.         bPressedJump = false;
  3499.         if (Physics != PHYS_Falling)
  3500.             SetPhysics(PHYS_Walking);
  3501.         if ( !IsAnimating() )
  3502.         {
  3503.             if (bIsCrouching)
  3504.                 PlayDuck();
  3505.             else
  3506.                 PlayWaiting();
  3507.         }
  3508.     }
  3509.  
  3510.     function EndState()
  3511.     {
  3512.         WalkBob = vect(0,0,0);
  3513.         bIsCrouching = false;
  3514.     }
  3515. }
  3516.  
  3517. state FeigningDeath
  3518. {
  3519. ignores SeePlayer, HearNoise, Bump, Fire, AltFire, StartClimbing;
  3520.  
  3521.     function ZoneChange( ZoneInfo NewZone )
  3522.     {
  3523.         if (NewZone.bWaterZone)
  3524.         {
  3525.             setPhysics(PHYS_Swimming);
  3526.             GotoState('PlayerSwimming');
  3527.         }
  3528.     }
  3529.  
  3530.     function PlayChatting()
  3531.     {
  3532.     }
  3533.  
  3534.     exec function Taunt( name Sequence )
  3535.     {
  3536.     }
  3537.  
  3538.     function AnimEnd()
  3539.     {
  3540.         if ( (Role == ROLE_Authority) && (Health > 0) )
  3541.         {
  3542.             GotoState('PlayerWalking');
  3543.             ChangedWeapon();
  3544.         }
  3545.     }
  3546.  
  3547.     function Landed(vector HitNormal)
  3548.     {
  3549.         if ( Role == ROLE_Authority )
  3550.             PlaySound(Land, SLOT_Interact, 0.3, false, 800, 1.0);
  3551.         if (Velocity.Z < -1.4 * JumpZ)
  3552.         {
  3553.             MakeNoise(-0.5 * Velocity.Z/(FMax(JumpZ, 150.0)));
  3554.             if (Velocity.Z <= -1100)
  3555.             {
  3556.                 if ( (Velocity.Z < -2000) && (ReducedDamageType != 'All') )
  3557.                     TakeDamage(1000, None, Location, vect(0,0,0), 'fell');
  3558.                 else if ( Role == ROLE_Authority )
  3559.                     TakeDamage(-0.15 * (Velocity.Z + 1050), Self, Location, vect(0,0,0), 'fell');
  3560.             }
  3561.         }
  3562.         else if ( (Level.Game != None) && (Level.Game.Difficulty > 1) && (Velocity.Z > 0.5 * JumpZ) )
  3563.             MakeNoise(0.1 * Level.Game.Difficulty);
  3564.         bJustLanded = true;
  3565.     }
  3566.  
  3567.     function Rise()
  3568.     {
  3569.         if ( !bRising )
  3570.         {
  3571.             Enable('AnimEnd');
  3572.             bRising = true;
  3573.             if (TryToDuck(false))
  3574.             {
  3575.                 BaseEyeHeight = default.BaseEyeHeight;
  3576.                 PlayRising();
  3577.             }
  3578.             else
  3579.             {
  3580.                 PlayDuck();
  3581.                 BaseEyeHeight = default.BaseEyeHeight + CollisionHeight - default.CollisionHeight;
  3582.             }
  3583.         }
  3584.     }
  3585.  
  3586.     function ProcessMove(float DeltaTime, vector NewAccel, eDodgeDir DodgeMove, rotator DeltaRot)
  3587.     {
  3588.         if ( bPressedJump || (NewAccel.Z > 0) )
  3589.             Rise();
  3590.         Acceleration = vect(0,0,0);
  3591.     }
  3592.  
  3593.     event PlayerTick( float DeltaTime )
  3594.     {
  3595.         if ( bUpdatePosition )
  3596.             ClientUpdatePosition();
  3597.  
  3598.         PlayerMove(DeltaTime);
  3599.     }
  3600.  
  3601.     function ServerMove
  3602.     (
  3603.         float TimeStamp,
  3604.         vector Accel,
  3605.         vector ClientLoc,
  3606.         bool NewbRun,
  3607.         bool NewbDuck,
  3608.         bool NewbPressedJump,
  3609.         bool bFired,
  3610.         bool bAltFired,
  3611.         eDodgeDir DodgeMove,
  3612.         byte ClientRoll,
  3613.         int View
  3614.     )
  3615.     {
  3616.         Global.ServerMove(TimeStamp, Accel, ClientLoc, NewbRun, NewbDuck, NewbPressedJump,
  3617.                           bFired, bAltFired, DodgeMove, ClientRoll, (32767 & (Rotation.Pitch/2)) * 32768 + (32767 & (Rotation.Yaw/2)));
  3618.     }
  3619.  
  3620.     function PlayerMove( float DeltaTime)
  3621.     {
  3622.         local rotator currentRot;
  3623.         local vector NewAccel;
  3624.  
  3625.         aLookup  *= 0.24;
  3626.         aTurn    *= 0.24;
  3627.  
  3628.         // Update acceleration.
  3629.         if ( !IsAnimating() && (aForward != 0) || (aStrafe != 0) )
  3630.             NewAccel = vect(0,0,1);
  3631.         else
  3632.             NewAccel = vect(0,0,0);
  3633.  
  3634.         // Update view rotation.
  3635.         currentRot = Rotation;
  3636.         UpdateRotation(DeltaTime, 1);
  3637.         SetRotation(currentRot);
  3638.  
  3639.         if ( Role < ROLE_Authority ) // then save this move and replicate it
  3640.             ReplicateMove(DeltaTime, NewAccel, DODGE_None, Rot(0,0,0));
  3641.         else
  3642.             ProcessMove(DeltaTime, NewAccel, DODGE_None, Rot(0,0,0));
  3643.         bPressedJump = false;
  3644.     }
  3645.  
  3646.     function PlayTakeHit(float tweentime, vector HitLoc, int Damage)
  3647.     {
  3648.         if ( IsAnimating() )
  3649.         {
  3650.             Enable('AnimEnd');
  3651.             Global.PlayTakeHit(tweentime, HitLoc, Damage);
  3652.         }
  3653.     }
  3654.  
  3655.     function PlayDying(name DamageType, vector HitLocation)
  3656.     {
  3657.         BaseEyeHeight = Default.BaseEyeHeight;
  3658.     }
  3659.  
  3660.     function ChangedWeapon()
  3661.     {
  3662.         Inventory.ChangedWeapon();
  3663.         Weapon = None;
  3664.     }
  3665.  
  3666.     simulated function bool ShouldHaveReducedHeight()
  3667.     {
  3668.         return !bRising;
  3669.     }
  3670.  
  3671.     function EndState()
  3672.     {
  3673.         PlayerReplicationInfo.bFeigningDeath = false;
  3674.     }
  3675.  
  3676.     function BeginState()
  3677.     {
  3678.         local rotator NewRot;
  3679.         if ( carriedDecoration != None )
  3680.             DropDecoration();
  3681.         NewRot = Rotation;
  3682.         NewRot.Pitch = 0;
  3683.         SetRotation(NewRot);
  3684.         BaseEyeHeight = -0.5 * CollisionHeight;
  3685.         bIsCrouching = false;
  3686.         bPressedJump = false;
  3687.         bRising = false;
  3688.         Disable('AnimEnd');
  3689.         PlayFeignDeath();
  3690.         PlayerReplicationInfo.bFeigningDeath = true;
  3691.         TryToDuck(true);
  3692.     }
  3693. }
  3694.  
  3695. // Player movement.
  3696. // Player Swimming
  3697. state PlayerSwimming
  3698. {
  3699. ignores SeePlayer, HearNoise, Bump;
  3700.  
  3701.     event UpdateEyeHeight(float DeltaTime)
  3702.     {
  3703.         local float smooth, bound;
  3704.  
  3705.         // smooth up/down stairs
  3706.         if ( !bJustLanded )
  3707.         {
  3708.             smooth = FMin(1.0, 10.0 * DeltaTime/Level.TimeDilation);
  3709.             EyeHeight = (EyeHeight - Location.Z + OldLocation.Z) * (1 - smooth) + ( ShakeVert + BaseEyeHeight) * smooth;
  3710.             bound = -0.5 * CollisionHeight;
  3711.             if (EyeHeight < bound)
  3712.                 EyeHeight = bound;
  3713.             else
  3714.             {
  3715.                 bound = CollisionHeight + FClamp((OldLocation.Z - Location.Z), 0.0, MaxStepHeight);
  3716.                 if (bIsReducedCrouch)
  3717.                     bound += default.CollisionHeight - CollisionHeight;
  3718.                 if ( EyeHeight > bound )
  3719.                     EyeHeight = bound;
  3720.             }
  3721.         }
  3722.         else
  3723.         {
  3724.             smooth = FClamp(10.0 * DeltaTime/Level.TimeDilation, 0.35, 1.0);
  3725.             bJustLanded = false;
  3726.             EyeHeight = EyeHeight * ( 1 - smooth) + (BaseEyeHeight + ShakeVert) * smooth;
  3727.         }
  3728.  
  3729.         // teleporters affect your FOV, so adjust it back down
  3730.         if ( FOVAngle != DesiredFOV )
  3731.         {
  3732.             if ( FOVAngle > DesiredFOV )
  3733.                 FOVAngle = FOVAngle - FMax(7, 0.9 * DeltaTime * (FOVAngle - DesiredFOV));
  3734.             else
  3735.                 FOVAngle = FOVAngle - FMin(-7, 0.9 * DeltaTime * (FOVAngle - DesiredFOV));
  3736.             if ( Abs(FOVAngle - DesiredFOV) <= 10 )
  3737.                 FOVAngle = DesiredFOV;
  3738.         }
  3739.  
  3740.         // adjust FOV for weapon zooming
  3741.         if ( bZooming )
  3742.         {
  3743.             ZoomLevel += DeltaTime * 1.0;
  3744.             if (ZoomLevel > 0.9)
  3745.                 ZoomLevel = 0.9;
  3746.             DesiredFOV = FClamp(90.0 - (ZoomLevel * 88.0), 1, 170);
  3747.         }
  3748.     }
  3749.  
  3750.     function Landed(vector HitNormal)
  3751.     {
  3752.         //log(class$" Landed while swimming");
  3753.         PlayLanded(Velocity.Z);
  3754.         if (Velocity.Z < -1.2 * JumpZ)
  3755.         {
  3756.             MakeNoise(-0.5 * Velocity.Z/(FMax(JumpZ, 150.0)));
  3757.             if (Velocity.Z <= -1100)
  3758.             {
  3759.                 if ( (Velocity.Z < -2000) && (ReducedDamageType != 'All') )
  3760.                     TakeDamage(1000, None, Location, vect(0,0,0), 'fell');
  3761.                 else if ( Role == ROLE_Authority )
  3762.                     TakeDamage(-0.1 * (Velocity.Z + 1050), Self, Location, vect(0,0,0), 'fell');
  3763.             }
  3764.         }
  3765.         else if ( (Level.Game != None) && (Level.Game.Difficulty > 1) && (Velocity.Z > 0.5 * JumpZ) )
  3766.             MakeNoise(0.1 * Level.Game.Difficulty);
  3767.         bJustLanded = true;
  3768.         if ( Region.Zone.bWaterZone )
  3769.             SetPhysics(PHYS_Swimming);
  3770.         else
  3771.         {
  3772.             GotoState('PlayerWalking');
  3773.             AnimEnd();
  3774.         }
  3775.     }
  3776.  
  3777.     function AnimEnd()
  3778.     {
  3779.         local vector X,Y,Z;
  3780.         GetAxes(Rotation, X,Y,Z);
  3781.         if ( (Acceleration Dot X) <= 0 )
  3782.         {
  3783.             if ( GetAnimGroup(AnimSequence) == 'TakeHit' )
  3784.             {
  3785.                 bAnimTransition = true;
  3786.                 TweenToWaiting(0.2);
  3787.             }
  3788.             else
  3789.                 PlayWaiting();
  3790.         }
  3791.         else
  3792.         {
  3793.             if ( GetAnimGroup(AnimSequence) == 'TakeHit' )
  3794.             {
  3795.                 bAnimTransition = true;
  3796.                 TweenToSwimming(0.2);
  3797.             }
  3798.             else
  3799.                 PlaySwimming();
  3800.         }
  3801.     }
  3802.  
  3803.     function ZoneChange( ZoneInfo NewZone )
  3804.     {
  3805.         local actor HitActor;
  3806.         local vector HitLocation, HitNormal, checkpoint;
  3807.  
  3808.         if (!NewZone.bWaterZone)
  3809.         {
  3810.             SetPhysics(PHYS_Falling);
  3811.             if (bUpAndOut && CheckWaterJump(HitNormal)) //check for waterjump
  3812.             {
  3813.                 velocity.Z = 330 + 2 * CollisionRadius; //set here so physics uses this for remainder of tick
  3814.                 PlayDuck();
  3815.                 GotoState('PlayerWalking');
  3816.             }
  3817.             else if (!FootRegion.Zone.bWaterZone || (Velocity.Z > 160) )
  3818.             {
  3819.                 GotoState('PlayerWalking');
  3820.                 AnimEnd();
  3821.             }
  3822.             else //check if in deep water
  3823.             {
  3824.                 checkpoint = Location;
  3825.                 checkpoint.Z -= (CollisionHeight + 6.0);
  3826.                 HitActor = Trace(HitLocation, HitNormal, checkpoint, Location, false);
  3827.                 if (HitActor != None)
  3828.                 {
  3829.                     GotoState('PlayerWalking');
  3830.                     AnimEnd();
  3831.                 }
  3832.                 else
  3833.                 {
  3834.                     Enable('Timer');
  3835.                     SetTimer(0.7,false);
  3836.                 }
  3837.             }
  3838.             //log("Out of water");
  3839.         }
  3840.         else
  3841.         {
  3842.             Disable('Timer');
  3843.             SetPhysics(PHYS_Swimming);
  3844.         }
  3845.     }
  3846.  
  3847.     function ProcessMove(float DeltaTime, vector NewAccel, eDodgeDir DodgeMove, rotator DeltaRot)
  3848.     {
  3849.         local vector X,Y,Z, Temp;
  3850.  
  3851.         GetAxes(ViewRotation,X,Y,Z);
  3852.         Acceleration = NewAccel;
  3853.  
  3854.         SwimAnimUpdate( (X Dot Acceleration) <= 0 );
  3855.  
  3856.         bUpAndOut = ((X Dot Acceleration) > 0) && ((Acceleration.Z > 0) || (ViewRotation.Pitch > 2048));
  3857.         if ( bUpAndOut && !Region.Zone.bWaterZone && CheckWaterJump(Temp) ) //check for waterjump
  3858.         {
  3859.             velocity.Z = 330 + 2 * CollisionRadius; //set here so physics uses this for remainder of tick
  3860.             PlayDuck();
  3861.             GotoState('PlayerWalking');
  3862.         }
  3863.     }
  3864.  
  3865.     event PlayerTick( float DeltaTime )
  3866.     {
  3867.         if ( bUpdatePosition )
  3868.             ClientUpdatePosition();
  3869.  
  3870.         PlayerMove(DeltaTime);
  3871.     }
  3872.  
  3873.     function PlayerMove(float DeltaTime)
  3874.     {
  3875.         local rotator oldRotation;
  3876.         local vector X,Y,Z, NewAccel;
  3877.         local float Speed2D;
  3878.  
  3879.         GetAxes(ViewRotation,X,Y,Z);
  3880.  
  3881.         aForward *= 0.2;
  3882.         aStrafe  *= 0.1;
  3883.         aLookup  *= 0.24;
  3884.         aTurn    *= 0.24;
  3885.         aUp      *= 0.1;
  3886.  
  3887.         NewAccel = aForward*X + aStrafe*Y + aUp*vect(0,0,1);
  3888.  
  3889.         //add bobbing when swimming
  3890.         if ( !bShowMenu )
  3891.         {
  3892.             Speed2D = Sqrt(Velocity.X * Velocity.X + Velocity.Y * Velocity.Y);
  3893.             WalkBob = Y * Bob *  0.5 * Speed2D * sin(4.0 * Level.TimeSeconds);
  3894.             WalkBob.Z = Bob * 1.5 * Speed2D * sin(8.0 * Level.TimeSeconds);
  3895.         }
  3896.  
  3897.         // Update rotation.
  3898.         oldRotation = Rotation;
  3899.         UpdateRotation(DeltaTime, 2);
  3900.  
  3901.         if ( Role < ROLE_Authority ) // then save this move and replicate it
  3902.             ReplicateMove(DeltaTime, NewAccel, DODGE_None, OldRotation - Rotation);
  3903.         else
  3904.             ProcessMove(DeltaTime, NewAccel, DODGE_None, OldRotation - Rotation);
  3905.         bPressedJump = false;
  3906.     }
  3907.  
  3908.     function Timer()
  3909.     {
  3910.         if ( !Region.Zone.bWaterZone && (Role == ROLE_Authority) )
  3911.         {
  3912.             //log("timer out of water");
  3913.             GotoState('PlayerWalking');
  3914.             AnimEnd();
  3915.         }
  3916.  
  3917.         Disable('Timer');
  3918.     }
  3919.  
  3920.     function BeginState()
  3921.     {
  3922.         Disable('Timer');
  3923.         if (!IsAnimating())
  3924.             TweenToWaiting(0.3);
  3925.         else if (bIsReducedCrouch)
  3926.             TweenToSwimming(0.2);
  3927.         //log("player swimming");
  3928.     }
  3929. }
  3930.  
  3931. state PlayerInterpolate
  3932. {
  3933. Ignores AnimEnd,FellOutOfWorld;
  3934.  
  3935.     function BeginState()
  3936.     {
  3937.         WalkBob = vect(0,0,0);
  3938.         LastUpdateTime = -1;
  3939.         TweenToWalking(0.1f);
  3940.     }
  3941.     function EndState()
  3942.     {
  3943.         Target = None;
  3944.         if( Physics==PHYS_Interpolating )
  3945.             SetPhysics(PHYS_Falling);
  3946.         bInterpolating = false;
  3947.     }
  3948.  
  3949.     // Basicly do nothing.
  3950.     event PlayerTick( float DeltaTime )
  3951.     {
  3952.         if ( bUpdatePosition )
  3953.             ClientUpdatePosition();
  3954.         PlayerMove(DeltaTime);
  3955.     }
  3956.     function PlayerMove( float DeltaTime )
  3957.     {
  3958.         bPressedJump = false;
  3959.         if ( Role < ROLE_Authority )
  3960.             ReplicateMoveIP(DeltaTime);
  3961.     }
  3962.     function ProcessMove(float DeltaTime, vector NewAccel, eDodgeDir DodgeMove, rotator DeltaRot)
  3963.     {
  3964.     }
  3965.     final function ReplicateMoveIP( float DeltaTime )
  3966.     {
  3967.         local SavedMove NewMove;
  3968.  
  3969.         // if am network client and am carrying flag -
  3970.         //  make its position look good client side
  3971.         if ( (PlayerReplicationInfo != None) && (PlayerReplicationInfo.HasFlag != None) )
  3972.             PlayerReplicationInfo.HasFlag.FollowHolder(self);
  3973.  
  3974.         // Get a SavedMove actor to store the movement in.
  3975.         if ( SavedMoves == None )
  3976.         {
  3977.             SavedMoves = GetFreeMove();
  3978.             NewMove = SavedMoves;
  3979.         }
  3980.         else
  3981.         {
  3982.             NewMove = SavedMoves;
  3983.             while ( NewMove.NextMove != None )
  3984.                 NewMove = NewMove.NextMove;
  3985.             if ( NewMove.bSent )
  3986.             {
  3987.                 NewMove.NextMove = GetFreeMove();
  3988.                 NewMove = NewMove.NextMove;
  3989.             }
  3990.         }
  3991.  
  3992.         NewMove.Delta = DeltaTime;
  3993.         NewMove.Acceleration = vect(0,0,0);
  3994.  
  3995.         // Set this move's data.
  3996.         NewMove.DodgeMove = DODGE_None;
  3997.         NewMove.TimeStamp = Level.TimeSeconds;
  3998.         NewMove.bRun = false;
  3999.         NewMove.bDuck = false;
  4000.         NewMove.bPressedJump = false;
  4001.  
  4002.         // Simulate the movement locally.
  4003.         AutonomousPhysics(DeltaTime);
  4004.  
  4005.         // Send to the server
  4006.         NewMove.bSent = true;
  4007.         ServerMove(Level.TimeSeconds,vect(0,0,0),Location,false,false,false,(bJustFired || (bFire != 0)),(bJustAltFired || (bAltFire != 0)),DODGE_None,0,0);
  4008.        
  4009.         bJustFired = false;
  4010.         bJustAltFired = false;
  4011.     }
  4012.     function ServerMove( float TimeStamp, vector InAccel, vector ClientLoc, bool NewbRun, bool NewbDuck, bool NewbPressedJump,
  4013.         bool bFired, bool bAltFired, eDodgeDir DodgeMove, byte ClientRoll, int View )
  4014.     {
  4015.         local float DeltaTime;
  4016.  
  4017.         // If this move is outdated, discard it.
  4018.         if ( CurrentTimeStamp >= TimeStamp )
  4019.             return;
  4020.  
  4021.         // handle firing and alt-firing
  4022.         if ( bFired )
  4023.         {
  4024.             if ( bFire == 0 )
  4025.             {
  4026.                 Fire(0);
  4027.                 bFire = 1;
  4028.             }
  4029.         }
  4030.         else
  4031.             bFire = 0;
  4032.  
  4033.  
  4034.         if ( bAltFired )
  4035.         {
  4036.             if ( bAltFire == 0 )
  4037.             {
  4038.                 AltFire(0);
  4039.                 bAltFire = 1;
  4040.             }
  4041.         }
  4042.         else
  4043.             bAltFire = 0;
  4044.  
  4045.         // Save move parameters.
  4046.         DeltaTime = TimeStamp - CurrentTimeStamp;
  4047.         if ( ServerTimeStamp > 0 )
  4048.         {
  4049.             TimeMargin += DeltaTime - 1.01 * (Level.TimeSeconds - ServerTimeStamp);
  4050.             if ( TimeMargin > MaxTimeMargin )
  4051.             {
  4052.                 // player is too far ahead
  4053.                 TimeMargin -= DeltaTime;
  4054.                 if ( TimeMargin < 0.5 )
  4055.                     MaxTimeMargin = 1.0;
  4056.                 else
  4057.                     MaxTimeMargin = 0.5;
  4058.                 DeltaTime = 0;
  4059.             }
  4060.             else if ( TimeMargin < -MaxTimeMargin ) // player is too far behind.
  4061.                 TimeMargin = -MaxTimeMargin;
  4062.         }
  4063.  
  4064.         CurrentTimeStamp = TimeStamp;
  4065.         ServerTimeStamp = Level.TimeSeconds;
  4066.  
  4067.         // Perform actual movement.
  4068.         if ( Len(Level.Pauser)==0 && (DeltaTime > 0) )
  4069.             AutonomousPhysics(DeltaTime);
  4070.  
  4071.         if ( (Level.TimeSeconds-LastUpdateTime)>0.25 )
  4072.         {
  4073.             LastUpdateTime = Level.TimeSeconds;
  4074.             ClientAdjustPosition(TimeStamp,GetStateName(),PHYS_None,PhysRate,PhysAlpha,0,0,0,0,Target);
  4075.         }
  4076.     }
  4077.     function ClientAdjustPosition
  4078.     (
  4079.         float TimeStamp,
  4080.         name newState,
  4081.         EPhysics newPhysics,
  4082.         float NewLocX, // PhysRate
  4083.         float NewLocY, // PhysAlpha
  4084.         float NewLocZ,
  4085.         float NewVelX,
  4086.         float NewVelY,
  4087.         float NewVelZ,
  4088.         Actor NewBase // Interpolate target
  4089.     )
  4090.     {
  4091.         if ( CurrentTimeStamp > TimeStamp )
  4092.             return;
  4093.         CurrentTimeStamp = TimeStamp;
  4094.  
  4095.         if ( !IsInState(newState) )
  4096.         {
  4097.             GotoState(newState); // Client ended interpolating, go to new state.
  4098.             return;
  4099.         }
  4100.  
  4101.         if( NewBase!=None )
  4102.         {
  4103.             Target = NewBase;
  4104.             PhysRate = NewLocX;
  4105.             PhysAlpha = NewLocY;
  4106.             if( Physics!=PHYS_Interpolating )
  4107.                 SetPhysics(PHYS_Interpolating);
  4108.             bInterpolating = true;
  4109.         }
  4110.         bUpdatePosition = true;
  4111.     }
  4112.     function ClientUpdatePosition() // Do nothing more than let time flow by.
  4113.     {
  4114.         local SavedMove CurrentMove;
  4115.  
  4116.         bUpdatePosition = false;
  4117.         CurrentMove = SavedMoves;
  4118.         while ( CurrentMove != None )
  4119.         {
  4120.             if ( CurrentMove.TimeStamp <= CurrentTimeStamp )
  4121.             {
  4122.                 SavedMoves = CurrentMove.NextMove;
  4123.                 CurrentMove.NextMove = FreeMoves;
  4124.                 FreeMoves = CurrentMove;
  4125.                 FreeMoves.Clear();
  4126.                 CurrentMove = SavedMoves;
  4127.             }
  4128.             else
  4129.             {
  4130.                 AutonomousPhysics(CurrentMove.Delta);
  4131.                 CurrentMove = CurrentMove.NextMove;
  4132.             }
  4133.         }
  4134.     }
  4135. }
  4136.  
  4137. state PlayerInterpolateNI extends PlayerInterpolate
  4138. {
  4139. Ignores ActivateInventoryItem,NextWeapon,PrevWeapon,ActivateItem,PrevItem,NextItem,Fire,AltFire,TakeDamage,Died,ZoneChange,FootZoneChange,HeadZoneChange,AnimEnd,FellOutOfWorld,KilledBy;
  4140.  
  4141.     function ChangedWeapon()
  4142.     {
  4143.         Weapon = None;
  4144.     }
  4145.     simulated function RenderOverlays( canvas Canvas )
  4146.     {
  4147.         if ( myHUD != None )
  4148.             myHUD.RenderOverlays(Canvas);
  4149.     }
  4150.     function BeginState()
  4151.     {
  4152.         Super.BeginState();
  4153.         if( Level.NetMode!=NM_Client && Level.NetMode!=NM_StandAlone )
  4154.             bHidden = true;
  4155.     }
  4156.     function EndState()
  4157.     {
  4158.         Super.EndState();
  4159.         if( Level.NetMode!=NM_Client && Health>0 )
  4160.         {
  4161.             bHidden = false;
  4162.             if( Weapon==None && PendingWeapon!=None )
  4163.                 Global.ChangedWeapon();
  4164.         }
  4165.     }
  4166.     function PlayerMove( float DeltaTime )
  4167.     {
  4168.         bFire = 0;
  4169.         bAltFire = 0;
  4170.         Super.PlayerMove(DeltaTime);
  4171.     }
  4172. }
  4173.  
  4174. // 227g real crouching mode implemention:
  4175. simulated final function SetCrouch(bool bCrouching)
  4176. {
  4177.     local float NewCollisionHeight, VerticalOffset, MoveDistance;
  4178.     local bool bOldBlockActors, bOldBlockPlayers, bOldCollideWorld;
  4179.  
  4180.     if (bIsReducedCrouch == bCrouching || CrouchCheckTime == Level.TimeSeconds)
  4181.         return; // No-op.
  4182.     CrouchCheckTime = Level.TimeSeconds; // Avoid any possible runaway loops.
  4183.  
  4184.     bIsReducedCrouch = bCrouching;
  4185.     class'RealCrouchController'.static.GetRealCrouchController(self);
  4186.  
  4187.     if (bCrouching)
  4188.     {
  4189.         // Update collision size, prepivot height and location.
  4190.         NewCollisionHeight = default.CollisionHeight * CrouchHeightPct;
  4191.         MoveDistance = CollisionHeight - NewCollisionHeight;
  4192.         if (MoveDistance <= 0)
  4193.             return;
  4194.  
  4195.         VerticalOffset = default.CollisionHeight - NewCollisionHeight;
  4196.         SetCollisionSize(CollisionRadius, NewCollisionHeight);
  4197.         PrePivot.Z = default.PrePivot.Z + VerticalOffset;
  4198.         EyeHeight += MoveDistance;
  4199.         Move(vect(0, 0, -1) * MoveDistance);
  4200.     }
  4201.     else
  4202.     {
  4203.         // Reset collision size, prepivot height and location.
  4204.         NewCollisionHeight = default.CollisionHeight;
  4205.         MoveDistance = NewCollisionHeight - CollisionHeight;
  4206.  
  4207.         // Use the cached result when indirectly calling from TryToDuck or a newly calculated result otherwise
  4208.         if (MoveDistance <= 0 || !class'RealCrouchController'.static.CanStandUp(self, NewCollisionHeight))
  4209.             return;
  4210.  
  4211.         PrePivot.Z = default.PrePivot.Z;
  4212.         EyeHeight -= MoveDistance;
  4213.  
  4214.         bOldBlockActors = bBlockActors;
  4215.         bOldBlockPlayers = bBlockPlayers;
  4216.         bOldCollideWorld = bCollideWorld;
  4217.  
  4218.         SetCollision(bCollideActors, false, false);
  4219.         bCollideWorld = false;
  4220.         SetCollisionSize(CollisionRadius, NewCollisionHeight);
  4221.         Move(vect(0, 0, 1) * MoveDistance);
  4222.         SetLocation(Location);
  4223.         if (CarriedDecoration != none)
  4224.         {
  4225.             CarriedDecoration.SetPhysics(PHYS_None);
  4226.             CarriedDecoration.SetBase(self);
  4227.         }
  4228.         SetCollision(bCollideActors, bOldBlockActors, bOldBlockPlayers);
  4229.         bCollideWorld = bOldCollideWorld;
  4230.     }
  4231. }
  4232.  
  4233. simulated final function bool TryToDuck(bool bCrouching)
  4234. {
  4235.     if (!Level.bSupportsRealCrouching || bIsReducedCrouch == bCrouching)
  4236.         return true;
  4237.     if (bCrouching)
  4238.     {
  4239.         SetCrouch(true);
  4240.         return true;
  4241.     }
  4242.     // Make sure there is space to stand up
  4243.     if (!class'RealCrouchController'.static.CanStandUp(self, default.CollisionHeight))
  4244.         return false; // Not enough space to uncrouch
  4245.     SetCrouch(false);
  4246.     return true;
  4247. }
  4248.  
  4249. simulated function bool ShouldHaveReducedHeight()
  4250. {
  4251.     return bIsCrouching || bIsReducedCrouch && bDuck != 0;
  4252. }
  4253.  
  4254. simulated function bool IsHeadShot(vector HitLocation, vector TraceDir)
  4255. {
  4256.     return !bIsReducedCrouch && super.IsHeadShot(HitLocation, TraceDir);
  4257. }
  4258.  
  4259. state PlayerFlying
  4260. {
  4261. ignores SeePlayer, HearNoise, Bump, StartClimbing;
  4262.  
  4263.     function AnimEnd()
  4264.     {
  4265.         PlaySwimming();
  4266.     }
  4267.  
  4268.     event PlayerTick( float DeltaTime )
  4269.     {
  4270.         if ( bUpdatePosition )
  4271.             ClientUpdatePosition();
  4272.  
  4273.         PlayerMove(DeltaTime);
  4274.     }
  4275.  
  4276.     function PlayerMove(float DeltaTime)
  4277.     {
  4278.         local vector X,Y,Z;
  4279.  
  4280.         GetAxes(ViewRotation,X,Y,Z);
  4281.  
  4282.         aForward *= 0.2;
  4283.         aStrafe  *= 0.2;
  4284.         aLookup  *= 0.24;
  4285.         aTurn    *= 0.24;
  4286.  
  4287.         Acceleration = aForward*X + aStrafe*Y + aUp*Z;
  4288.         if ( bPressedJump && aUp<=0.01 )
  4289.             bPressedJump = False;
  4290.         // Update rotation.
  4291.         UpdateRotation(DeltaTime, 2);
  4292.  
  4293.         if ( Role < ROLE_Authority ) // then save this move and replicate it
  4294.             ReplicateMove(DeltaTime, Acceleration, DODGE_None, rot(0,0,0));
  4295.         else
  4296.             ProcessMove(DeltaTime, Acceleration, DODGE_None, rot(0,0,0));
  4297.     }
  4298.  
  4299.     function BeginState()
  4300.     {
  4301.         SetPhysics(PHYS_Flying);
  4302.         if  ( !IsAnimating() ) PlaySwimming();
  4303.         //log("player flying");
  4304.     }
  4305. }
  4306.  
  4307. state CheatFlying
  4308. {
  4309. ignores SeePlayer, HearNoise, Bump, TakeDamage, StartClimbing;
  4310.  
  4311.     function AnimEnd()
  4312.     {
  4313.         PlaySwimming();
  4314.     }
  4315.  
  4316.     function ProcessMove(float DeltaTime, vector NewAccel, eDodgeDir DodgeMove, rotator DeltaRot)
  4317.     {
  4318.         if ( VSize(NewAccel)<0.1 )
  4319.             Acceleration = vect(0,0,0);
  4320.         else Acceleration = Normal(NewAccel) * 550;
  4321.         MoveSmooth(Acceleration * DeltaTime);
  4322.         Velocity = Acceleration; // Fix for ghosting/flying players from falling down for other clients.
  4323.     }
  4324.  
  4325.     event PlayerTick( float DeltaTime )
  4326.     {
  4327.         if ( bUpdatePosition )
  4328.             ClientUpdatePosition();
  4329.  
  4330.         PlayerMove(DeltaTime);
  4331.     }
  4332.  
  4333.     function PlayerMove(float DeltaTime)
  4334.     {
  4335.         local vector X,Y,Z;
  4336.  
  4337.         GetAxes(ViewRotation,X,Y,Z);
  4338.  
  4339.         aForward    *= 0.1;
  4340.         aStrafe     *= 0.1;
  4341.         aLookup     *= 0.24;
  4342.         aTurn       *= 0.24;
  4343.         aUp     *= 0.1;
  4344.  
  4345.         Acceleration = aForward*X + aStrafe*Y + aUp*vect(0,0,1);
  4346.  
  4347.         UpdateRotation(DeltaTime, 1);
  4348.  
  4349.         if ( Role < ROLE_Authority ) // then save this move and replicate it
  4350.             ReplicateMove(DeltaTime, Acceleration, DODGE_None, rot(0,0,0));
  4351.         else
  4352.             ProcessMove(DeltaTime, Acceleration, DODGE_None, rot(0,0,0));
  4353.     }
  4354.  
  4355.     function BeginState()
  4356.     {
  4357.         EyeHeight = BaseEyeHeight;
  4358.         SetPhysics(PHYS_None);
  4359.         if( Base!=None )
  4360.             SetBase(Level);
  4361.         if( !IsAnimating() )
  4362.             PlaySwimming();
  4363.         bCanFly = True;
  4364.     }
  4365.     function EndState()
  4366.     {
  4367.         bCanFly = False;
  4368.     }  
  4369. }
  4370.  
  4371. state PlayerWaiting
  4372. {
  4373. ignores SeePlayer, HearNoise, Bump, TakeDamage, Died, StartClimbing;
  4374.  
  4375.     exec function Jump( optional float F )
  4376.     {
  4377.     }
  4378.  
  4379.     exec function Suicide()
  4380.     {
  4381.     }
  4382.  
  4383.     function ChangeTeam( int N )
  4384.     {
  4385.         Level.Game.ChangeTeam(self, N);
  4386.     }
  4387.  
  4388.     exec function Fire(optional float F)
  4389.     {
  4390.         bReadyToPlay = !bReadyToPlay;
  4391.     }
  4392.  
  4393.     exec function AltFire(optional float F)
  4394.     {
  4395.         bReadyToPlay = !bReadyToPlay;
  4396.     }
  4397.  
  4398.     function ProcessMove(float DeltaTime, vector NewAccel, eDodgeDir DodgeMove, rotator DeltaRot)
  4399.     {
  4400.         Acceleration = NewAccel;
  4401.         MoveSmooth(Acceleration * DeltaTime);
  4402.     }
  4403.  
  4404.     event PlayerTick( float DeltaTime )
  4405.     {
  4406.         if ( bUpdatePosition )
  4407.             ClientUpdatePosition();
  4408.  
  4409.         PlayerMove(DeltaTime);
  4410.     }
  4411.  
  4412.     function PlayerMove(float DeltaTime)
  4413.     {
  4414.         local vector X,Y,Z;
  4415.  
  4416.         GetAxes(ViewRotation,X,Y,Z);
  4417.  
  4418.         aForward *= 0.1;
  4419.         aStrafe  *= 0.1;
  4420.         aLookup  *= 0.24;
  4421.         aTurn    *= 0.24;
  4422.         aUp      *= 0.1;
  4423.  
  4424.         Acceleration = aForward*X + aStrafe*Y + aUp*vect(0,0,1);
  4425.  
  4426.         UpdateRotation(DeltaTime, 1);
  4427.  
  4428.         if ( Role < ROLE_Authority ) // then save this move and replicate it
  4429.             ReplicateMove(DeltaTime, Acceleration, DODGE_None, rot(0,0,0));
  4430.         else
  4431.             ProcessMove(DeltaTime, Acceleration, DODGE_None, rot(0,0,0));
  4432.     }
  4433.  
  4434.     function EndState()
  4435.     {
  4436.         Mesh = Default.Mesh;
  4437.         PlayerReplicationInfo.bIsSpectator = false;
  4438.         SetCollision(true,true,true);
  4439.     }
  4440.  
  4441.     function BeginState()
  4442.     {
  4443.         Mesh = None;
  4444.         PlayerReplicationInfo.bIsSpectator = true;
  4445.         SetCollision(false,false,false);
  4446.         EyeHeight = BaseEyeHeight;
  4447.         SetPhysics(PHYS_None);
  4448.     }
  4449. }
  4450.  
  4451. state PlayerSpectating
  4452. {
  4453. ignores SeePlayer, HearNoise, Bump, TakeDamage, Died, StartClimbing;
  4454.  
  4455.     exec function Suicide()
  4456.     {
  4457.     }
  4458.  
  4459.     function SendVoiceMessage(PlayerReplicationInfo Sender, PlayerReplicationInfo Recipient, name messagetype, byte messageID, name broadcasttype)
  4460.     {
  4461.     }
  4462.  
  4463.     exec function AltFire( optional float F )
  4464.     {
  4465.         if ( Role == ROLE_Authority )
  4466.         {
  4467.             bBehindView = false;
  4468.             Viewtarget = None;
  4469.             ClientMessage("Now viewing from own camera", 'Event', true);
  4470.         }
  4471.     }
  4472.  
  4473.     function ChangeTeam( int N )
  4474.     {
  4475.         Level.Game.ChangeTeam(self, N);
  4476.     }
  4477.  
  4478.     exec function Fire( optional float F )
  4479.     {
  4480.         if ( Role == ROLE_Authority )
  4481.         {
  4482.             ViewPlayerNum(-1);
  4483.             bBehindView = true;
  4484.         }
  4485.     }
  4486.  
  4487.     function ProcessMove(float DeltaTime, vector NewAccel, eDodgeDir DodgeMove, rotator DeltaRot)
  4488.     {
  4489.         Acceleration = NewAccel;
  4490.         MoveSmooth(Acceleration * DeltaTime);
  4491.     }
  4492.  
  4493.     event PlayerTick( float DeltaTime )
  4494.     {
  4495.         if ( bUpdatePosition )
  4496.             ClientUpdatePosition();
  4497.  
  4498.         PlayerMove(DeltaTime);
  4499.     }
  4500.  
  4501.     function PlayerMove(float DeltaTime)
  4502.     {
  4503.         local vector X,Y,Z;
  4504.  
  4505.         GetAxes(ViewRotation,X,Y,Z);
  4506.  
  4507.         aForward *= 0.1;
  4508.         aStrafe  *= 0.1;
  4509.         aLookup  *= 0.24;
  4510.         aTurn    *= 0.24;
  4511.         aUp      *= 0.1;
  4512.  
  4513.         Acceleration = aForward*X + aStrafe*Y + aUp*vect(0,0,1);
  4514.  
  4515.         UpdateRotation(DeltaTime, 1);
  4516.  
  4517.         if ( Role < ROLE_Authority ) // then save this move and replicate it
  4518.             ReplicateMove(DeltaTime, Acceleration, DODGE_None, rot(0,0,0));
  4519.         else
  4520.             ProcessMove(DeltaTime, Acceleration, DODGE_None, rot(0,0,0));
  4521.     }
  4522.  
  4523.     function EndState()
  4524.     {
  4525.         Mesh = Default.Mesh;
  4526.         SetCollision(true,true,true);
  4527.     }
  4528.  
  4529.     function BeginState()
  4530.     {
  4531.         Mesh = None;
  4532.         SetCollision(false,false,false);
  4533.         EyeHeight = BaseEyeHeight;
  4534.         SetPhysics(PHYS_None);
  4535.     }
  4536. }
  4537. //===============================================================================
  4538. state PlayerWaking
  4539. {
  4540.     ignores SeePlayer, HearNoise, KilledBy, Bump, HitWall, HeadZoneChange, FootZoneChange, ZoneChange, SwitchWeapon, Falling, StartClimbing;
  4541.  
  4542.     function Timer()
  4543.     {
  4544.         BaseEyeHeight = Default.BaseEyeHeight;
  4545.     }
  4546.  
  4547.     event PlayerTick( float DeltaTime )
  4548.     {
  4549.         if ( bUpdatePosition )
  4550.             ClientUpdatePosition();
  4551.  
  4552.         PlayerMove(DeltaTime);
  4553.     }
  4554.  
  4555.     function PlayerMove(Float DeltaTime)
  4556.     {
  4557.         ViewFlash(deltaTime * 0.5);
  4558.         if ( TimerRate == 0 )
  4559.         {
  4560.             ViewRotation.Pitch -= DeltaTime * 12000;
  4561.             if ( ViewRotation.Pitch < 0 )
  4562.             {
  4563.                 ViewRotation.Pitch = 0;
  4564.                 GotoState('PlayerWalking');
  4565.             }
  4566.         }
  4567.  
  4568.         if ( Role < ROLE_Authority ) // then save this move and replicate it
  4569.             ReplicateMove(DeltaTime, vect(0,0,0), DODGE_None, rot(0,0,0));
  4570.         else
  4571.             ProcessMove(DeltaTime, vect(0,0,0), DODGE_None, rot(0,0,0));
  4572.     }
  4573.  
  4574.     function BeginState()
  4575.     {
  4576.         if ( bWokeUp )
  4577.         {
  4578.             ViewRotation.Pitch = 0;
  4579.             SetTimer(0, false);
  4580.             return;
  4581.         }
  4582.         BaseEyeHeight = 0;
  4583.         EyeHeight = 0;
  4584.         SetTimer(3.0, false);
  4585.         bWokeUp = true;
  4586.     }
  4587. }
  4588.  
  4589. state Dying
  4590. {
  4591.     ignores SeePlayer, HearNoise, KilledBy, Bump, HitWall, HeadZoneChange, FootZoneChange, ZoneChange, SwitchWeapon, Falling, PainTimer, StartClimbing;
  4592.  
  4593.     exec function Fire( optional float F )
  4594.     {
  4595.         if ( Role < ROLE_Authority )
  4596.             return;
  4597.         if ( (Level.NetMode == NM_Standalone) && !Level.Game.bDeathMatch )
  4598.         {
  4599.             if ( bFrozen )
  4600.                 return;
  4601.             ShowLoadMenu();
  4602.         }
  4603.         else
  4604.             ServerReStartPlayer();
  4605.     }
  4606.  
  4607.     exec function AltFire( optional float F )
  4608.     {
  4609.         Fire(F);
  4610.     }
  4611.  
  4612.     function ServerMove
  4613.     (
  4614.         float TimeStamp,
  4615.         vector Accel,
  4616.         vector ClientLoc,
  4617.         bool NewbRun,
  4618.         bool NewbDuck,
  4619.         bool NewbPressedJump,
  4620.         bool bFired,
  4621.         bool bAltFired,
  4622.         eDodgeDir DodgeMove,
  4623.         byte ClientRoll,
  4624.         int View
  4625.     )
  4626.     {
  4627.         if ( NewbPressedJump )
  4628.             Fire(0);
  4629.  
  4630.         Global.ServerMove(
  4631.             TimeStamp,
  4632.             Accel,
  4633.             ClientLoc,
  4634.             NewbRun,
  4635.             NewbDuck,
  4636.             NewbPressedJump,
  4637.             bFired,
  4638.             bAltFired,
  4639.             DodgeMove,
  4640.             ClientRoll,
  4641.             View);
  4642.     }
  4643.  
  4644.     function PlayerCalcView(out actor ViewActor, out vector CameraLocation, out rotator CameraRotation )
  4645.     {
  4646.         local vector View,HitLocation,HitNormal, spot;
  4647.         local float ViewDist;
  4648.         local actor HitActor;
  4649.         local Pawn PTarget;
  4650.  
  4651.         if ( ViewTarget != None )
  4652.         {
  4653.             ViewActor = ViewTarget;
  4654.             CameraLocation = ViewTarget.Location;
  4655.             CameraRotation = ViewTarget.Rotation;
  4656.             PTarget = Pawn(ViewTarget);
  4657.             if ( PTarget != None )
  4658.             {
  4659.                 if ( Level.NetMode == NM_Client )
  4660.                 {
  4661.                     if ( PTarget.bIsPlayer )
  4662.                         PTarget.ViewRotation = TargetViewRotation;
  4663.                     PTarget.EyeHeight = TargetEyeHeight;
  4664.                     if ( PTarget.Weapon != None )
  4665.                         PTarget.Weapon.PlayerViewOffset = TargetWeaponViewOffset;
  4666.                 }
  4667.                 if ( PTarget.bIsPlayer )
  4668.                     CameraRotation = PTarget.ViewRotation;
  4669.                 CameraLocation.Z += PTarget.EyeHeight;
  4670.             }
  4671.  
  4672.             if ( Carcass(ViewTarget) != None )
  4673.             {
  4674.                 if ( ViewTarget.Physics == PHYS_None )
  4675.                     CameraRotation = ViewRotation;
  4676.                 else
  4677.                     ViewRotation = CameraRotation;
  4678.             }
  4679.             else if ( bBehindView )
  4680.                 CalcBehindView(CameraLocation, CameraRotation, 180);
  4681.  
  4682.             return;
  4683.         }
  4684.  
  4685.         // View rotation.
  4686.         CameraRotation = ViewRotation;
  4687.         DesiredFOV = DefaultFOV;
  4688.         ViewActor = self;
  4689.         if ( bBehindView ) //up and behind (for death scene)
  4690.         {
  4691.             ViewDist = 190;
  4692.             if (MoveTarget != None)
  4693.                 spot = MoveTarget.Location;
  4694.             else
  4695.                 spot = Location;
  4696.             View = vect(1,0,0) >> CameraRotation;
  4697.             HitActor = Trace( HitLocation, HitNormal,
  4698.                               spot - ViewDist * vector(CameraRotation), spot, false, vect(12,12,2));
  4699.             if ( HitActor != None )
  4700.                 CameraLocation = HitLocation;
  4701.             else
  4702.                 CameraLocation = spot - ViewDist * View;
  4703.         }
  4704.         else
  4705.         {
  4706.             // First-person view.
  4707.             CameraLocation = Location;
  4708.             CameraLocation.Z += Default.BaseEyeHeight;
  4709.         }
  4710.     }
  4711.  
  4712.     event PlayerTick( float DeltaTime )
  4713.     {
  4714.         if ( bUpdatePosition )
  4715.             ClientUpdatePosition();
  4716.  
  4717.         PlayerMove(DeltaTime);
  4718.     }
  4719.  
  4720.     function PlayerMove(float DeltaTime)
  4721.     {
  4722.         local vector X,Y,Z;
  4723.  
  4724.         if ( !bFrozen )
  4725.         {
  4726.             if ( bPressedJump )
  4727.                 Fire(0);
  4728.             GetAxes(ViewRotation,X,Y,Z);
  4729.             // Update view rotation.
  4730.             aLookup  *= 0.24;
  4731.             aTurn    *= 0.24;
  4732.             ViewRotation.Yaw += 32.0 * DeltaTime * aTurn;
  4733.             ViewRotation.Pitch += 32.0 * DeltaTime * aLookUp;
  4734.             ViewRotation.Pitch = ViewRotation.Pitch & 65535;
  4735.             If ((ViewRotation.Pitch > 18000) && (ViewRotation.Pitch < 49152))
  4736.             {
  4737.                 If (aLookUp > 0)
  4738.                 ViewRotation.Pitch = 18000;
  4739.                 else
  4740.                     ViewRotation.Pitch = 49152;
  4741.             }
  4742.             if ( Role < ROLE_Authority ) // then save this move and replicate it
  4743.                 ReplicateMove(DeltaTime, vect(0,0,0), DODGE_None, rot(0,0,0));
  4744.             bPressedJump = false;
  4745.         }
  4746.         ViewShake(DeltaTime);
  4747.         ViewFlash(DeltaTime);
  4748.     }
  4749.  
  4750.     function FindGoodView()
  4751.     {
  4752.         local vector cameraLoc;
  4753.         local rotator cameraRot;
  4754.         local int tries, besttry;
  4755.         local float bestdist, newdist;
  4756.         local int startYaw;
  4757.         local actor ViewActor;
  4758.  
  4759.         //fixme - try to pick view with killer visible
  4760.         //fixme - also try varying starting pitch
  4761.         ////log("Find good death scene view");
  4762.         ViewRotation.Pitch = 56000;
  4763.         tries = 0;
  4764.         besttry = 0;
  4765.         bestdist = 0.0;
  4766.         startYaw = ViewRotation.Yaw;
  4767.  
  4768.         for (tries=0; tries<16; tries++)
  4769.         {
  4770.             cameraLoc = Location;
  4771.             PlayerCalcView(ViewActor, cameraLoc, cameraRot);
  4772.             newdist = VSize(cameraLoc - Location);
  4773.             if (newdist > bestdist)
  4774.             {
  4775.                 bestdist = newdist;
  4776.                 besttry = tries;
  4777.             }
  4778.             ViewRotation.Yaw += 4096;
  4779.         }
  4780.  
  4781.         ViewRotation.Yaw = startYaw + besttry * 4096;
  4782.     }
  4783.  
  4784.     function TakeDamage( int Damage, Pawn instigatedBy, Vector hitlocation,
  4785.                          Vector momentum, name damageType)
  4786.     {
  4787.         if ( !bHidden )
  4788.             Super.TakeDamage(Damage, instigatedBy, hitlocation, momentum, damageType);
  4789.     }
  4790.  
  4791.     function Timer()
  4792.     {
  4793.         bFrozen = false;
  4794.         bShowScores = true;
  4795.         bPressedJump = false;
  4796.     }
  4797.  
  4798.     function BeginState()
  4799.     {
  4800.         bBehindView = true;
  4801.         bFrozen = true;
  4802.         bPressedJump = false;
  4803.         FindGoodView();
  4804.         if ( (Role == ROLE_Authority) && !bHidden )
  4805.             Super.Timer();
  4806.         SetTimer(1.0, false);
  4807.         //log(Self$" entering dying with remote role "$RemoteRole$" and role "$Role$" in state "$state);
  4808.     }
  4809.  
  4810.     function EndState()
  4811.     {
  4812.         bBehindView = false;
  4813.         bShowScores = false;
  4814.         if ( Carcass(ViewTarget) != None )
  4815.             ViewTarget = None;
  4816.         //Log(self$" exiting dying with remote role "$RemoteRole$" and role "$Role);
  4817.     }
  4818. }
  4819.  
  4820. state GameEnded
  4821. {
  4822. ignores SeePlayer, HearNoise, KilledBy, Bump, HitWall, HeadZoneChange, FootZoneChange, ZoneChange, Falling, TakeDamage, PainTimer, Died, Suicide, StartClimbing;
  4823.  
  4824.     // 227g: Prevent rotation updates for third person clients.
  4825.     function UpdatePawnRotation( rotator Rot );
  4826.  
  4827.     exec function ViewClass( class<actor> aClass, optional bool bQuiet )
  4828.     {
  4829.     }
  4830.     exec function ViewPlayer( string S )
  4831.     {
  4832.     }
  4833.     exec function Fire( optional float F )
  4834.     {
  4835.         if ( Role>=ROLE_Authority && !bFrozen )
  4836.             ServerReStartGame();
  4837.     }
  4838.  
  4839.     exec function AltFire( optional float F )
  4840.     {
  4841.         Fire(F);
  4842.     }
  4843.  
  4844.     event PlayerTick( float DeltaTime )
  4845.     {
  4846.         if ( bUpdatePosition )
  4847.             ClientUpdatePosition();
  4848.  
  4849.         PlayerMove(DeltaTime);
  4850.     }
  4851.  
  4852.     function PlayerMove(float DeltaTime)
  4853.     {
  4854.         local vector X,Y,Z;
  4855.  
  4856.         GetAxes(ViewRotation,X,Y,Z);
  4857.         // Update view rotation.
  4858.         if ( !bFrozen && (bPressedJump || (bFire == 1) || (bAltFire == 1)) )
  4859.             ServerReStartGame();
  4860.  
  4861.         if ( !bFixedCamera )
  4862.         {
  4863.             aLookup  *= 0.24;
  4864.             aTurn    *= 0.24;
  4865.             ViewRotation.Yaw += 32.0 * DeltaTime * aTurn;
  4866.             ViewRotation.Pitch += 32.0 * DeltaTime * aLookUp;
  4867.             ViewRotation.Pitch = ViewRotation.Pitch & 65535;
  4868.             If ((ViewRotation.Pitch > 18000) && (ViewRotation.Pitch < 49152))
  4869.             {
  4870.                 If (aLookUp > 0)
  4871.                 ViewRotation.Pitch = 18000;
  4872.                 else
  4873.                     ViewRotation.Pitch = 49152;
  4874.             }
  4875.         }
  4876.         ViewShake(DeltaTime);
  4877.         ViewFlash(DeltaTime);
  4878.  
  4879.         if ( Role < ROLE_Authority ) // then save this move and replicate it
  4880.             ReplicateMove(DeltaTime, vect(0,0,0), DODGE_None, rot(0,0,0));
  4881.         else
  4882.             ProcessMove(DeltaTime, vect(0,0,0), DODGE_None, rot(0,0,0));
  4883.         bPressedJump = false;
  4884.     }
  4885.  
  4886.     function FindGoodView()
  4887.     {
  4888.         local vector cameraLoc;
  4889.         local rotator cameraRot;
  4890.         local int tries, besttry;
  4891.         local float bestdist, newdist;
  4892.         local int startYaw;
  4893.         local actor ViewActor;
  4894.  
  4895.         ViewRotation.Pitch = 56000;
  4896.         tries = 0;
  4897.         besttry = 0;
  4898.         bestdist = 0.0;
  4899.         startYaw = ViewRotation.Yaw;
  4900.  
  4901.         for (tries=0; tries<16; tries++)
  4902.         {
  4903.             if ( ViewTarget != None )
  4904.                 cameraLoc = ViewTarget.Location;
  4905.             else
  4906.                 cameraLoc = Location;
  4907.             PlayerCalcView(ViewActor, cameraLoc, cameraRot);
  4908.             newdist = VSize(cameraLoc - Location);
  4909.             if (newdist > bestdist)
  4910.             {
  4911.                 bestdist = newdist;
  4912.                 besttry = tries;
  4913.             }
  4914.             ViewRotation.Yaw += 4096;
  4915.         }
  4916.  
  4917.         ViewRotation.Yaw = startYaw + besttry * 4096;
  4918.     }
  4919.  
  4920.     function Timer()
  4921.     {
  4922.         bFrozen = false;
  4923.     }
  4924.  
  4925.     function BeginState()
  4926.     {
  4927.         EndZoom();
  4928.         AnimRate = 0.0;
  4929.         bFire = 0;
  4930.         bAltFire = 0;
  4931.         // Freeze animation for third person clients.
  4932.         SimAnim.X = 10000 * AnimFrame;
  4933.         SimAnim.Y = 0;
  4934.         SimAnim.Z = 0;
  4935.         SimAnim.W = 10000 * AnimLast;
  4936.         SetCollision(false,false,false);
  4937.         bShowScores = true;
  4938.         bFrozen = true;
  4939.         if ( !bFixedCamera )
  4940.         {
  4941.             FindGoodView();
  4942.             bBehindView = true;
  4943.         }
  4944.         SetTimer(1.5, false);
  4945.         SetPhysics(PHYS_None);
  4946.     }
  4947. }
  4948.  
  4949. // New 227g state, Laddering
  4950. function StartClimbing( LadderTrigger Other )
  4951. {
  4952.     local int YDiff;
  4953.  
  4954.     if( Other.bDirectional )
  4955.     {
  4956.         YDiff = ((ViewRotation.Yaw - Other.Rotation.Yaw) & 65535);
  4957.         if( YDiff>16000 && YDiff<50000 )
  4958.             return; // Need to face at ladder to allow start climbing
  4959.     }
  4960.     if( Abs(Velocity.Z)>Other.MaxGrabVelocity )
  4961.         return;
  4962.  
  4963.     if( Other.ClimbingNoise!=None )
  4964.         PlaySound(Other.ClimbingNoise,SLOT_Misc,1.5);
  4965.     ActiveLadder = Other;
  4966.     if( Other.bUnarmedClimbing )
  4967.     {
  4968.         PendingWeapon = Weapon;
  4969.         if ( Weapon != None )
  4970.             Weapon.PutDown();
  4971.     }
  4972.     GoToState('PlayerClimbing');
  4973. }
  4974. function PlayClimbing( bool bMovement )
  4975. {
  4976.     if( bMovement )
  4977.         PlayCrawling();
  4978.     else PlayDuck();
  4979. }
  4980.  
  4981. State PlayerClimbing
  4982. {
  4983.     function ChangedWeapon()
  4984.     {
  4985.         if( ActiveLadder.bUnarmedClimbing )
  4986.         {
  4987.             Inventory.ChangedWeapon();
  4988.             Weapon = None;
  4989.         }
  4990.         else Global.ChangedWeapon();
  4991.     }
  4992.     function StartClimbing( LadderTrigger Other )
  4993.     {
  4994.         ActiveLadder = Other; // Begin next ladder.
  4995.         if( Other.bUnarmedClimbing && Weapon!=None )
  4996.         {
  4997.             PendingWeapon = Weapon;
  4998.             Weapon.PutDown();
  4999.         }
  5000.     }
  5001.     function EndClimbing( LadderTrigger Other )
  5002.     {
  5003.         local LadderTrigger L;
  5004.  
  5005.         if( ActiveLadder==Other )
  5006.         {
  5007.             ActiveLadder = None;
  5008.             foreach TouchingActors(Class'LadderTrigger',L)
  5009.                 if( L!=Other )
  5010.                     L.Touch(Self);
  5011.             if( ActiveLadder==None )
  5012.                 DropFromLadder();
  5013.         }
  5014.     }
  5015.     function DropFromLadder()
  5016.     {
  5017.         PlayInAir();
  5018.         Velocity = vector(ViewRotation)*Default.JumpZ*0.5f;
  5019.         if( Acceleration.Z>=0.f )
  5020.             Velocity.Z = Default.JumpZ*0.8f;
  5021.         else Velocity.Z = 0.f;
  5022.         if( Region.Zone.bWaterZone )
  5023.         {
  5024.             SetPhysics(PHYS_Swimming);
  5025.             GoToState('PlayerSwimming');
  5026.         }
  5027.         else
  5028.         {
  5029.             SetPhysics(PHYS_Falling);
  5030.             GoToState('PlayerWalking');
  5031.         }
  5032.         if( Weapon==None )
  5033.             ChangedWeapon();
  5034.     }
  5035.     function DoJump( optional float F )
  5036.     {
  5037.         if ( Role == ROLE_Authority && ActiveLadder!=None )
  5038.             PlaySound(ActiveLadder.ClimbingNoise, SLOT_Talk, 1.5, true, 1200, 1.0 );
  5039.         if ( (Level.Game != None) && (Level.Game.Difficulty > 0) )
  5040.             MakeNoise(0.1 * Level.Game.Difficulty);
  5041.         PlayInAir();
  5042.         Velocity = vector(ViewRotation)*Default.JumpZ;
  5043.         Velocity.Z = Default.JumpZ*0.8f;
  5044.         if( ActiveLadder!=None )
  5045.             Velocity+=vector(ActiveLadder.Rotation)*Default.JumpZ;
  5046.         if( Region.Zone.bWaterZone )
  5047.         {
  5048.             SetPhysics(PHYS_Swimming);
  5049.             GoToState('PlayerSwimming');
  5050.         }
  5051.         else
  5052.         {
  5053.             SetPhysics(PHYS_Falling);
  5054.             GoToState('PlayerWalking');
  5055.         }
  5056.         if( Weapon==None )
  5057.             ChangedWeapon();
  5058.     }
  5059.     function AnimEnd()
  5060.     {
  5061.         PlayClimbing(Acceleration!=vect(0,0,0));
  5062.     }
  5063.     function ProcessMove(float DeltaTime, vector NewAccel, eDodgeDir DodgeMove, rotator DeltaRot)
  5064.     {
  5065.         local vector OldAccel;
  5066.  
  5067.         if ( bPressedJump )
  5068.         {
  5069.             DoJump();
  5070.             return;
  5071.         }
  5072.         OldAccel = Acceleration;
  5073.         if ( VSize(NewAccel)<0.1 )
  5074.             Acceleration = vect(0,0,0);
  5075.         else Acceleration = Normal(NewAccel) * FMin(AirSpeed*0.4f,VSize(NewAccel));
  5076.         Velocity = Acceleration;
  5077.         if( OldAccel==vect(0,0,0) )
  5078.         {
  5079.             if( Acceleration!=vect(0,0,0) )
  5080.                 PlayClimbing(true);
  5081.         }
  5082.         else if( Acceleration==vect(0,0,0) )
  5083.             PlayClimbing(false);
  5084.         if( Level.NetMode!=NM_Client && ActiveLadder==None )
  5085.             DropFromLadder();
  5086.     }
  5087.     event PlayerTick( float DeltaTime )
  5088.     {
  5089.         if ( bUpdatePosition )
  5090.             ClientUpdatePosition();
  5091.         PlayerMove(DeltaTime);
  5092.     }
  5093.     function PlayerMove(float DeltaTime)
  5094.     {
  5095.         local vector X,Y,Z;
  5096.  
  5097.         GetAxes(ViewRotation,X,Y,Z);
  5098.  
  5099.         aForward    *= 0.1;
  5100.         aStrafe     *= 0.1;
  5101.         aLookup     *= 0.24;
  5102.         aTurn       *= 0.24;
  5103.         aUp     *= 0.1;
  5104.  
  5105.         Acceleration = aForward*X.Z*vect(0,0,1) + aUp*vect(0,0,1);
  5106.  
  5107.         UpdateRotation(DeltaTime, 1);
  5108.  
  5109.         if ( Role < ROLE_Authority ) // then save this move and replicate it
  5110.             ReplicateMove(DeltaTime, Acceleration, DODGE_None, rot(0,0,0));
  5111.         else
  5112.             ProcessMove(DeltaTime, Acceleration, DODGE_None, rot(0,0,0));
  5113.         bPressedJump = false;
  5114.     }
  5115.     function BeginState()
  5116.     {
  5117.         EyeHeight = BaseEyeHeight;
  5118.         SetPhysics(PHYS_Flying);
  5119.         if( Base!=None )
  5120.             SetBase(Level);
  5121.         PlayClimbing(false);
  5122.         if ( CarriedDecoration != None && Role==ROLE_Authority )
  5123.             DropDecoration();
  5124.     }
  5125.     function EndState()
  5126.     {
  5127.         WalkBob = vect(0,0,0);
  5128.         ActiveLadder = None;
  5129.         bIsWalking = false;
  5130.     }
  5131.     function HandleWalking()
  5132.     {
  5133.         bIsWalking = false;
  5134.     }
  5135. }
  5136.  
  5137. // To be returned for player info on serverlist.
  5138. function GetPlayerModelInfo( out string MeshName, out string SkinName )
  5139. {
  5140.     if( Mesh!=None )
  5141.         MeshName = string(Mesh.Name);
  5142.     else MeshName = MenuName;
  5143.     if( Skin!=None )
  5144.         SkinName = string(Skin.Name);
  5145.     else SkinName = "Default";
  5146. }
Add Comment
Please, Sign In to add comment