Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=============================================================================
- // PlayerPawn.
- // player controlled pawns
- // Note that Pawns which implement functions for the PlayerTick messages
- // must handle player control in these functions
- //=============================================================================
- class PlayerPawn extends Pawn
- config(user)
- native
- NativeReplication;
- // Player info.
- var const player Player;
- var globalconfig string Password; // for restarting coop savegames
- var travel float DodgeClickTimer; // max double click interval for dodge move
- var(Movement) globalconfig float DodgeClickTime;
- var(Movement) globalconfig float Bob;
- var float bobtime;
- // Camera info.
- var int ShowFlags;
- var int RendMap;
- var int Misc1;
- var int Misc2;
- var actor ViewTarget;
- var vector FlashScale, FlashFog;
- var vector CurrentFlashFog; // Used because FlashFog gets reset if under a threshold.
- var HUD myHUD;
- var ScoreBoard Scoring;
- var class<hud> HUDType;
- var class<scoreboard> ScoringType;
- var float DesiredFlashScale, ConstantGlowScale, InstantFlash;
- var vector DesiredFlashFog, ConstantGlowFog, InstantFog;
- var float DesiredFOV;
- var float DefaultFOV;
- // Music info.
- var music Song;
- var byte SongSection;
- var byte CdTrack;
- var EMusicTransition Transition;
- var float shaketimer; // player uses this for shaking view
- var int shakemag; // max magnitude in degrees of shaking
- var float shakevert; // max vertical shake magnitude
- var float maxshake;
- var float verttimer;
- var(Pawn) class<carcass> CarcassType;
- var travel globalconfig float MyAutoAim;
- var travel globalconfig float Handedness;
- var(Sounds) sound JumpSound;
- // Player control flags
- var bool bAdmin;
- var() globalconfig bool bLookUpStairs; // look up/down stairs (player)
- var() globalconfig bool bSnapToLevel; // Snap to level eyeheight when not mouselooking
- var() globalconfig bool bAlwaysMouseLook;
- var globalconfig bool bKeyboardLook; // no snapping when true
- var bool bWasForward; // used for dodge move
- var bool bWasBack;
- var bool bWasLeft;
- var bool bWasRight;
- var bool bEdgeForward;
- var bool bEdgeBack;
- var bool bEdgeLeft;
- var bool bEdgeRight;
- var bool bIsCrouching;
- var bool bShakeDir;
- var bool bAnimTransition;
- var bool bIsTurning;
- var bool bFrozen;
- var globalconfig bool bInvertMouse;
- var bool bShowScores;
- var bool bShowMenu;
- var bool bSpecialMenu;
- var bool bWokeUp;
- var bool bPressedJump;
- var bool bUpdatePosition;
- var bool bDelayedCommand;
- var bool bRising;
- var bool bReducedVis;
- var bool bCenterView;
- var() globalconfig bool bMaxMouseSmoothing;
- var bool bMouseZeroed;
- var bool bReadyToPlay;
- var globalconfig bool bNoFlash;
- var globalconfig bool bNoVoices;
- var globalconfig bool bMessageBeep;
- var bool bZooming;
- var() bool bSinglePlayer; // this class allowed in single player
- var bool bJustFired;
- var bool bJustAltFired;
- var bool bIsTyping;
- var bool bFixedCamera;
- var globalconfig float MainFOV;
- var transient bool bConsoleCommandMessage; // When calling PlayerPawn.ConsoleCommand, all engine commands will output in clientmessages.
- var float ZoomLevel;
- var class<menu> SpecialMenu;
- var string DelayedCommand;
- var globalconfig float MouseSensitivity;
- var globalconfig name WeaponPriority[30]; //weapon class priorities (9 is highest)
- var globalconfig int NetSpeed, LanSpeed;
- var float SmoothMouseX, SmoothMouseY, KbdAccel;
- var globalconfig bool bMouseSmoothing;
- var() globalconfig float MouseSmoothThreshold;
- // Unreal 227 additions
- var globalconfig bool bNeverAutoSwitch;
- var bool bIgnoreMusicChange;
- var PointRegion CameraRegion; // Player camera location
- var(Collision) float CrouchHeightPct;
- var bool bIsReducedCrouch;
- var transient float CrouchCheckTime;
- var transient bool bDistanceFogEnabled, // Client render distance fog now.
- bBlendingDistanceFog;
- var transient plane DistanceFogColor, // Client distance fog color.
- DistanceFogBlend;
- var transient float DistanceFogDistance[2], // Client distance fog render distance.
- DistanceFogStart[2],
- DistanceFogBlendTimer[2];
- var transient ZoneInfo DistanceFogOld; // Tracking camera zonechanges.
- var transient float FogDensity; // Client FogDensity. For exponential fog.
- var transient int FogMode; // 0 = Linear, 1 = Exponential, 2 = Exponential 2
- // Input axes.
- var input float
- aBaseX, aBaseY, aBaseZ,
- aMouseX, aMouseY,
- aForward, aTurn, aStrafe, aUp,
- aLookUp, aExtra4, aExtra3, aExtra2,
- aExtra1, aExtra0;
- // Move Buffering.
- var SavedMove SavedMoves;
- var SavedMove FreeMoves;
- var float CurrentTimeStamp;
- var float LastUpdateTime;
- var float ServerTimeStamp;
- var float TimeMargin;
- var float MaxTimeMargin;
- // Progess Indicator.
- var string ProgressMessage[5];
- var color ProgressColor[5];
- var float ProgressTimeOut;
- // Localized strings
- var localized string QuickSaveString;
- var localized string NoPauseMessage;
- var localized string ViewingFrom;
- var localized string OwnCamera;
- var localized string FailedView;
- var localized string CantChangeNameMsg;
- // ReplicationInfo
- var GameReplicationInfo GameReplicationInfo;
- // ngWorldStats Logging
- var() globalconfig string ngWorldSecret;
- // Remote Pawn ViewTargets
- var rotator TargetViewRotation;
- var float TargetEyeHeight;
- var vector TargetWeaponViewOffset;
- // CameraLocation
- var vector CalcCameraLocation;
- var rotator CalcCameraRotation;
- var float LastCameraUpdate;
- var LadderTrigger ActiveLadder;
- replication
- {
- // Things the server should send to the client.
- reliable if ( Role==ROLE_Authority && bNetOwner )
- ViewTarget, ScoringType, HUDType, GameReplicationInfo, bFixedCamera;
- unreliable if ( Role==ROLE_Authority && bNetOwner )
- TargetViewRotation, TargetEyeHeight, TargetWeaponViewOffset;
- // Things the client should send to the server
- reliable if ( Role<ROLE_Authority )
- WeaponPriority, Password, bReadyToPlay;
- // Functions client can call.
- unreliable if ( Role<ROLE_Authority )
- CallForHelp;
- reliable if ( Role<ROLE_Authority )
- ShowPath, RememberSpot, Speech, Say, TeamSay, RestartLevel, SwitchWeapon, Pause, SetPause, ServerSetHandedness,
- PrevItem, ActivateItem, ShowInventory, Grab, ServerFeignDeath, ServerSetWeaponPriority,
- ChangeName, ChangeTeam, God, Suicide, ViewClass, ViewPlayerNum, ViewSelf, ViewPlayer, ServerSetSloMo, ServerAddBots,
- PlayersOnly, ThrowWeapon, ServerRestartPlayer, NeverSwitchOnPickup,
- PrevWeapon, NextWeapon, ServerReStartGame, ServerUpdateWeapons, ServerTaunt, ServerChangeSkin,
- SwitchLevel, SwitchCoopLevel, Kick, KillAll, Summon, ActivateTranslator, Admin, Typing;
- unreliable if ( Role==ROLE_AutonomousProxy )
- ServerMove, Fly, Walk, Ghost;
- // Functions server can call.
- reliable if ( Role==ROLE_Authority )
- ClientAdjustGlow, ClientTravel, ClientSetMusic, StartZoom, ToggleZoom, StopZoom, EndZoom, SetDesiredFOV, ClearProgressMessages, SetProgressColor, SetProgressMessage, SetProgressTime;
- unreliable if ( Role==ROLE_Authority )
- SetFOVAngle, ClientShake, ClientFlash, ClientInstantFlash;
- unreliable if ( Role==ROLE_Authority && !bDemoRecording )
- ClientPlaySound;
- unreliable if ( Role==ROLE_Authority && (RemoteRole==ROLE_AutonomousProxy) )
- ClientAdjustPosition;
- // Input variables.
- unreliable if ( Role<ROLE_AutonomousProxy )
- aBaseX, aBaseY, aBaseZ,
- aMouseX, aMouseY,
- aForward, aTurn, aStrafe, aUp,
- aLookUp, aExtra4, aExtra3, aExtra2,
- aExtra1, aExtra0;
- }
- //
- // native client-side functions.
- //
- native event ClientTravel( string URL, ETravelType TravelType, bool bItems );
- native(544) final function ResetKeyboard();
- native(546) final function UpdateURL(string NewOption, string NewValue, bool bSaveDefault);
- native(549) final function bool IsPressing( byte KeyNum ); // Returns true if player is holding down key.
- native final function LevelInfo GetEntryLevel();
- native final function int GetClientVersion(); // Return the client version.
- native final function int GetClientSubVersion(); // Return the client version.
- native final function string GetCompileTime(); // Return the time and date when this version was built.
- // Execute a console command in the context of this player, then forward to Actor.ConsoleCommand.
- // 227 added command: ConsoleCommand("UGetIP"); for returning desired client's IP
- native function string ConsoleCommand( string Command );
- /* Clipboard functions, no Linux support yet, sorry. */
- static final native function CopyToClipboard( string Text );
- static final native function string PasteFromClipboard();
- // Called from native command 'UGetFullClientList <validation code>'/'UGetBanList <validation code>'/'UGetTBanList <validation code>'
- // Used by Unreal 227 Admin GUI interface.
- event UPlayerListResponse( string Resp, string PlayerNm, int ID, string PlayerIP, string ClientID )
- {
- ClientMessage("@"$Resp$ID@PlayerIP@ClientID@PlayerNm,'Log',False);
- }
- event PreClientTravel()
- {
- }
- exec function Ping()
- {
- ClientMessage("Current ping is"@PlayerReplicationInfo.Ping);
- }
- simulated event RenderOverlays( canvas Canvas )
- {
- if ( Weapon != None )
- Weapon.RenderOverlays(Canvas);
- if ( myHUD != None )
- myHUD.RenderOverlays(Canvas);
- }
- exec function ViewPlayerNum(optional int num)
- {
- local Pawn P;
- if ( num >= 0 )
- {
- P = Pawn(ViewTarget);
- if ( P != None && P.PlayerReplicationInfo != none && P.PlayerReplicationInfo.TeamID == num
- || PlayerReplicationInfo.TeamID == num )
- {
- ViewTarget = None;
- bBehindView = false;
- ClientMessage(ViewingFrom $ OwnCamera, 'Event', true);
- return;
- }
- for ( P=Level.PawnList; P!=None; P=P.NextPawn )
- if ( P.PlayerReplicationInfo != none
- && Level.Game.CanSpectate(self, P)
- && P.PlayerReplicationInfo.Team == PlayerReplicationInfo.Team
- && P.PlayerReplicationInfo.TeamID == num )
- {
- ViewTarget = P;
- bBehindView = true;
- ClientMessage(ViewingFrom $ Pawn(ViewTarget).PlayerReplicationInfo.PlayerName, 'Event', true);
- return;
- }
- ClientMessage(FailedView);
- return;
- }
- if ( Role == ROLE_Authority )
- {
- ViewClass(class'Pawn', true);
- While ( (ViewTarget != None)
- && (Pawn(ViewTarget).PlayerReplicationInfo == none || Pawn(ViewTarget).PlayerReplicationInfo.bIsSpectator) )
- ViewClass(class'Pawn', true);
- if ( ViewTarget != None )
- ClientMessage(ViewingFrom$Pawn(ViewTarget).PlayerReplicationInfo.PlayerName, 'Event', true);
- else
- ClientMessage(ViewingFrom$OwnCamera, 'Event', true);
- }
- }
- exec function Profile()
- {
- //TEMP for performance measurement
- ClientMessage("Average AI Time"@Level.AvgAITime);
- ClientMessage(" < 5% "$Level.AIProfile[0]);
- ClientMessage(" < 10% "$Level.AIProfile[1]);
- ClientMessage(" < 15% "$Level.AIProfile[2]);
- ClientMessage(" < 20% "$Level.AIProfile[3]);
- ClientMessage(" < 25% "$Level.AIProfile[4]);
- ClientMessage(" < 30% "$Level.AIProfile[5]);
- ClientMessage(" < 35% "$Level.AIProfile[6]);
- ClientMessage(" > 35% "$Level.AIProfile[7]);
- }
- // Execute an administrative console command on the server.
- exec function Admin( string CommandLine )
- {
- local string Result;
- if ( Level.Game.GetAccessManager().CanExecuteCheatStr(Self,'Admin',CommandLine) )
- {
- bConsoleCommandMessage = true;
- if ( Level.Game.GameRules!=None )
- Result = Level.Game.GameRules.ExecAdminCmd(Self,CommandLine);
- else Result = ConsoleCommand( CommandLine );
- bConsoleCommandMessage = false;
- if ( Len(Result)>0 )
- ClientMessage( Result );
- }
- }
- exec function PlayerList()
- {
- local PlayerReplicationInfo PRI;
- log("Player List:");
- ForEach AllActors(class'PlayerReplicationInfo', PRI)
- log(PRI.PlayerName@"( ping"@PRI.Ping$")");
- }
- //
- // native server-side functions
- //
- event ClientMessage( coerce string S, optional Name Type, optional bool bBeep )
- {
- if (Player == None)
- return;
- if (Type == '')
- Type = 'Event';
- if (Player.Console != None)
- Player.Console.Message( PlayerReplicationInfo, S, Type );
- if (bBeep && bMessageBeep)
- PlayBeepSound();
- if ( myHUD != None )
- myHUD.Message( PlayerReplicationInfo, S, Type );
- }
- event TeamMessage( PlayerReplicationInfo PRI, coerce string S, name Type )
- {
- Class'GameInfo'.Static.StripColorCodes(S);
- if (Player.Console != None)
- Player.Console.Message ( PRI, S, Type );
- if (bMessageBeep)
- PlayBeepSound();
- if ( myHUD != None )
- myHUD.Message( PRI, S, Type );
- }
- function ClientVoiceMessage(PlayerReplicationInfo Sender, PlayerReplicationInfo Recipient, name messagetype, byte messageID)
- {
- local VoicePack V;
- if ( Player==None || (Sender.voicetype==None) || (Player.Console==None) )
- return;
- V = Spawn(Sender.voicetype, self);
- if ( V != None )
- V.ClientInitialize(Sender, Recipient, messagetype, messageID);
- }
- simulated function PlayBeepSound();
- // 227g: Moved from UpdateView/ServerMove to here.
- function UpdatePawnRotation( rotator Rot )
- {
- if( Rotation!=Rot )
- SetRotation(Rot);
- }
- //
- // Send movement to the server.
- // Passes acceleration in components so it doesn't get rounded.
- //
- function ServerMove
- (
- float TimeStamp,
- vector InAccel,
- vector ClientLoc,
- bool NewbRun,
- bool NewbDuck,
- bool NewbPressedJump,
- bool bFired,
- bool bAltFired,
- eDodgeDir DodgeMove,
- byte ClientRoll,
- int View
- )
- {
- local float DeltaTime, clientErr;
- local rotator DeltaRot, Rot;
- local vector Accel, LocDiff;
- local int maxPitch, ViewPitch, ViewYaw;
- local actor OldBase;
- // View components
- ViewPitch = View/32768;
- ViewYaw = 2 * (View - 32768 * ViewPitch);
- ViewPitch *= 2;
- // Make acceleration.
- Accel = InAccel/10;
- // If this move is outdated, discard it.
- if ( CurrentTimeStamp >= TimeStamp )
- return;
- // handle firing and alt-firing
- if ( bFired )
- {
- if ( bFire == 0 )
- {
- Fire(0);
- bFire = 1;
- }
- }
- else
- bFire = 0;
- if ( bAltFired )
- {
- if ( bAltFire == 0 )
- {
- AltFire(0);
- bAltFire = 1;
- }
- }
- else
- bAltFire = 0;
- // Save move parameters.
- DeltaTime = TimeStamp - CurrentTimeStamp;
- if ( ServerTimeStamp > 0 )
- {
- TimeMargin += DeltaTime - 1.01 * (Level.TimeSeconds - ServerTimeStamp);
- if ( TimeMargin > MaxTimeMargin )
- {
- // player is too far ahead
- TimeMargin -= DeltaTime;
- if ( TimeMargin < 0.5 )
- MaxTimeMargin = 1.0;
- else
- MaxTimeMargin = 0.5;
- DeltaTime = 0;
- }
- else if ( TimeMargin < -MaxTimeMargin ) // player is too far behind.
- TimeMargin = -MaxTimeMargin;
- }
- CurrentTimeStamp = TimeStamp;
- ServerTimeStamp = Level.TimeSeconds;
- Rot.Roll = 256 * ClientRoll;
- Rot.Yaw = ViewYaw;
- if ( (Physics == PHYS_Swimming) || (Physics == PHYS_Flying) )
- maxPitch = 2;
- else
- maxPitch = 1;
- If ( (ViewPitch > maxPitch * RotationRate.Pitch) && (ViewPitch < 65536 - maxPitch * RotationRate.Pitch) )
- {
- If (ViewPitch < 32768)
- Rot.Pitch = maxPitch * RotationRate.Pitch;
- else
- Rot.Pitch = 65536 - maxPitch * RotationRate.Pitch;
- }
- else
- Rot.Pitch = ViewPitch;
- DeltaRot = (Rotation - Rot);
- ViewRotation.Pitch = ViewPitch;
- ViewRotation.Yaw = ViewYaw;
- ViewRotation.Roll = 0;
- UpdatePawnRotation(Rot);
- OldBase = Base;
- // Perform actual movement.
- if ( Len(Level.Pauser)==0 && (DeltaTime > 0) )
- MoveAutonomous(DeltaTime, NewbRun, NewbDuck, NewbPressedJump, DodgeMove, Accel, DeltaRot);
- // Accumulate movement error.
- if ( Level.TimeSeconds - LastUpdateTime > 0.3 )
- {
- ClientErr = 10000;
- }
- else if ( Level.TimeSeconds - LastUpdateTime > 0.07 )
- {
- LocDiff = Location - ClientLoc;
- ClientErr = LocDiff Dot LocDiff;
- }
- // If client has accumulated a noticeable positional error, correct him.
- if ( ClientErr > 3 )
- {
- if ( Mover(Base) != None )
- ClientLoc = Location - Base.Location;
- else
- ClientLoc = Location;
- // log("Client Error at "$TimeStamp$" is "$ClientErr$" with Velocity "$Velocity$" LocDiff "$LocDiff$" Physics "$Physics);
- LastUpdateTime = Level.TimeSeconds;
- ClientAdjustPosition
- (
- TimeStamp,
- GetStateName(),
- Physics,
- ClientLoc.X,
- ClientLoc.Y,
- ClientLoc.Z,
- Velocity.X,
- Velocity.Y,
- Velocity.Z,
- Base
- );
- }
- //log("Server "$Role$" moved "$self$" stamp "$TimeStamp$" location "$Location$" Acceleration "$Acceleration$" Velocity "$Velocity);
- }
- function ProcessMove ( float DeltaTime, vector newAccel, eDodgeDir DodgeMove, rotator DeltaRot)
- {
- Acceleration = newAccel;
- }
- final function MoveAutonomous
- (
- float DeltaTime,
- bool NewbRun,
- bool NewbDuck,
- bool NewbPressedJump,
- eDodgeDir DodgeMove,
- vector newAccel,
- rotator DeltaRot
- )
- {
- if ( NewbRun )
- bRun = 1;
- else
- bRun = 0;
- if ( NewbDuck )
- bDuck = 1;
- else
- bDuck = 0;
- bPressedJump = NewbPressedJump;
- HandleWalking();
- ProcessMove(DeltaTime, newAccel, DodgeMove, DeltaRot);
- AutonomousPhysics(DeltaTime);
- //log("Role "$Role$" moveauto time "$100 * DeltaTime$" ("$Level.TimeDilation$")");
- }
- // ClientAdjustPosition - pass newloc and newvel in components so it doesn't get rounded
- function ClientAdjustPosition
- (
- float TimeStamp,
- name newState,
- EPhysics newPhysics,
- float NewLocX,
- float NewLocY,
- float NewLocZ,
- float NewVelX,
- float NewVelY,
- float NewVelZ,
- Actor NewBase
- )
- {
- local Decoration Carried;
- local vector OldLoc, NewLocation;
- if ( CurrentTimeStamp > TimeStamp )
- return;
- CurrentTimeStamp = TimeStamp;
- NewLocation.X = NewLocX;
- NewLocation.Y = NewLocY;
- NewLocation.Z = NewLocZ;
- Velocity.X = NewVelX;
- Velocity.Y = NewVelY;
- Velocity.Z = NewVelZ;
- SetBase(NewBase);
- if ( Mover(NewBase) != None )
- NewLocation += NewBase.Location;
- //log("Client "$Role$" adjust "$self$" stamp "$TimeStamp$" location "$Location$" new location "$NewLocation);
- Carried = CarriedDecoration;
- OldLoc = Location;
- SetLocation(NewLocation);
- if ( Carried != None )
- {
- CarriedDecoration = Carried;
- CarriedDecoration.SetLocation(NewLocation + CarriedDecoration.Location - OldLoc);
- CarriedDecoration.SetPhysics(PHYS_None);
- CarriedDecoration.SetBase(self);
- }
- SetPhysics(newPhysics);
- //FIXME - don't do this state update if client dead???
- if ( !IsInState(newState) )
- GotoState(newState);
- bUpdatePosition = true;
- }
- function ClientUpdatePosition()
- {
- local SavedMove CurrentMove;
- local int realbRun, realbDuck;
- local bool bRealJump;
- realbRun = bRun;
- realbDuck = bDuck;
- bRealJump = bPressedJump;
- CurrentMove = SavedMoves;
- while ( CurrentMove != None )
- {
- if ( CurrentMove.TimeStamp <= CurrentTimeStamp )
- {
- SavedMoves = CurrentMove.NextMove;
- CurrentMove.NextMove = FreeMoves;
- FreeMoves = CurrentMove;
- FreeMoves.Clear();
- CurrentMove = SavedMoves;
- }
- else
- {
- CrouchCheckTime = -1;
- MoveAutonomous(CurrentMove.Delta, CurrentMove.bRun, CurrentMove.bDuck, CurrentMove.bPressedJump, CurrentMove.DodgeMove, CurrentMove.Acceleration, rot(0,0,0));
- CurrentMove = CurrentMove.NextMove;
- }
- }
- bDuck = realbDuck;
- bRun = realbRun;
- bPressedJump = bRealJump;
- CrouchCheckTime = -1;
- bUpdatePosition = false;
- //log("Client adjusted "$self$" stamp "$CurrentTimeStamp$" location "$Location$" dodge "$DodgeDir);
- }
- final function SavedMove GetFreeMove()
- {
- local SavedMove s;
- if ( FreeMoves == None )
- return Spawn(class'SavedMove');
- else
- {
- s = FreeMoves;
- FreeMoves = FreeMoves.NextMove;
- s.NextMove = None;
- return s;
- }
- }
- //
- // Replicate this client's desired movement to the server.
- //
- final function ReplicateMove
- (
- float DeltaTime,
- vector NewAccel,
- eDodgeDir DodgeMove,
- rotator DeltaRot
- )
- {
- local SavedMove NewMove;
- local byte ClientRoll;
- // if am network client and am carrying flag -
- // make its position look good client side
- if ( (PlayerReplicationInfo != None)
- && (PlayerReplicationInfo.HasFlag != None) )
- PlayerReplicationInfo.HasFlag.FollowHolder(self);
- // Get a SavedMove actor to store the movement in.
- if ( SavedMoves == None )
- {
- SavedMoves = GetFreeMove();
- NewMove = SavedMoves;
- }
- else
- {
- NewMove = SavedMoves;
- while ( NewMove.NextMove != None )
- NewMove = NewMove.NextMove;
- if ( NewMove.bSent )
- {
- NewMove.NextMove = GetFreeMove();
- NewMove = NewMove.NextMove;
- }
- }
- NewMove.Delta = DeltaTime;
- if ( VSize(NewAccel) > 3072 )
- NewAccel = 3072 * Normal(NewAccel);
- NewMove.Acceleration = NewAccel;
- // Set this move's data.
- NewMove.DodgeMove = DodgeMove;
- NewMove.TimeStamp = Level.TimeSeconds;
- NewMove.bRun = (bRun > 0);
- NewMove.bDuck = (bDuck > 0);
- NewMove.bIsReducedCrouch = bIsReducedCrouch;
- NewMove.bPressedJump = bPressedJump;
- if ( Weapon != None ) // approximate pointing so don't have to replicate
- Weapon.bPointing = ((bFire != 0) || (bAltFire != 0));
- // Simulate the movement locally.
- ProcessMove(DeltaTime, NewAccel, DodgeMove, DeltaRot);
- AutonomousPhysics(DeltaTime);
- //log("Role "$Role$" repmove at "$Level.TimeSeconds$" Move time "$100 * DeltaTime$" ("$Level.TimeDilation$")");
- // Send to the server
- NewMove.bSent = true;
- ClientRoll = (Rotation.Roll >> 8) & 255;
- ServerMove
- (
- NewMove.TimeStamp,
- NewMove.Acceleration * 10,
- Location,
- NewMove.bRun,
- NewMove.bDuck,
- NewMove.bPressedJump,
- (bJustFired || (bFire != 0)),
- (bJustAltFired || (bAltFire != 0)),
- NewMove.DodgeMove,
- ClientRoll,
- (32767 & (ViewRotation.Pitch/2)) * 32768 + (32767 & (ViewRotation.Yaw/2))
- );
- bJustFired = false;
- bJustAltFired = false;
- //log("Replicated "$self$" stamp "$NewMove.TimeStamp$" location "$Location$" dodge "$NewMove.DodgeMove$" to "$DodgeDir);
- }
- function HandleWalking()
- {
- local rotator carried;
- bIsWalking = ((bRun != 0) || (bDuck != 0) || bIsReducedCrouch) && !Region.Zone.IsA('WarpZoneInfo');
- bNoStopAtLedge = (bDuck==0 && bIsReducedCrouch);
- if ( (Role == ROLE_Authority) && (standingcount == 0) )
- CarriedDecoration = None;
- if ( CarriedDecoration != None ) //verify its still in front
- {
- bIsWalking = true;
- if ( Role == ROLE_Authority )
- {
- carried = Rotator(CarriedDecoration.Location - Location);
- carried.Yaw = ((carried.Yaw & 65535) - (Rotation.Yaw & 65535)) & 65535;
- if ( (carried.Yaw > 3072) && (carried.Yaw < 62463) )
- DropDecoration();
- }
- }
- }
- //----------------------------------------------
- event Destroyed()
- {
- Super.Destroyed();
- if ( myHud != None )
- myHud.Destroy();
- if ( Scoring != None )
- Scoring.Destroy();
- }
- function ServerReStartGame()
- {
- local GameRules G;
- if ( Level.Game.GameRules!=None )
- {
- for ( G=Level.Game.GameRules; G!=None; G=G.NextRules )
- if ( G.bHandleMapEvents && !G.CanRestartGame(Self) )
- Return;
- }
- if (IsInState('GameEnded'))
- Level.Game.RestartGame();
- }
- function PlayHit(float Damage, vector HitLocation, name damageType, float MomentumZ)
- {
- Level.Game.SpecialDamageString = "";
- }
- function SetFOVAngle(float newFOV)
- {
- FOVAngle = newFOV;
- }
- function ClientFlash( float scale, vector fog )
- {
- DesiredFlashScale = scale;
- DesiredFlashFog = 0.001 * fog;
- }
- function ClientInstantFlash( float scale, vector fog )
- {
- InstantFlash = scale;
- InstantFog = 0.001 * fog;
- }
- //Play a sound client side (so only client will hear it
- simulated function ClientPlaySound(sound ASound, optional ESoundSlot SlotType )
- {
- if ( ViewTarget != None )
- ViewTarget.PlaySound(ASound, SlotType, 255, true);
- PlaySound(ASound, SlotType, 255, true);
- }
- function ClientAdjustGlow( float scale, vector fog )
- {
- ConstantGlowScale += scale;
- ConstantGlowFog += 0.001 * fog;
- }
- function ClientShake(vector shake)
- {
- if ( (shakemag < shake.X) || (shaketimer <= 0.01 * shake.Y) )
- {
- shakemag = shake.X;
- shaketimer = 0.01 * shake.Y;
- maxshake = 0.01 * shake.Z;
- verttimer = 0;
- ShakeVert = -1.1 * maxshake;
- }
- }
- function ShakeView( float shaketime, float RollMag, float vertmag)
- {
- local vector shake;
- shake.X = RollMag;
- shake.Y = 100 * shaketime;
- shake.Z = 100 * vertmag;
- ClientShake(shake);
- }
- function ClientSetMusic( music NewSong, byte NewSection, byte NewCdTrack, EMusicTransition NewTransition )
- {
- if ( bIgnoreMusicChange )
- Return;
- Song = NewSong;
- SongSection = NewSection;
- CdTrack = NewCdTrack;
- Transition = NewTransition;
- }
- function ServerFeignDeath()
- {
- PendingWeapon = Weapon;
- if ( Weapon != None )
- Weapon.PutDown();
- GotoState('FeigningDeath');
- }
- function ServerSetHandedness( float hand)
- {
- Handedness = hand;
- if ( Weapon != None )
- Weapon.SetHand(Handedness);
- }
- function ServerReStartPlayer()
- {
- local GameRules G;
- //log("calling restartplayer in dying with netmode "$Level.NetMode);
- if ( Level.NetMode == NM_Client )
- return;
- if ( Level.Game.GameRules!=None )
- {
- for ( G=Level.Game.GameRules; G!=None; G=G.NextRules )
- if ( G.bHandleMapEvents && !G.CanRestartPlayer(Self) )
- Return;
- }
- if ( Level.Game.RestartPlayer(self) )
- {
- //log("server restart client");
- ServerTimeStamp = 0;
- TimeMargin = 0;
- Level.Game.StartPlayer(self);
- BaseEyeHeight = Default.BaseEyeHeight;
- EyeHeight = BaseEyeHeight;
- PlayWaiting();
- ClientReStart();
- }
- else
- log("Restartplayer failed");
- }
- function ServerChangeSkin( coerce string SkinName, coerce string FaceName, byte TeamNum )
- {
- local string MeshName;
- MeshName = GetItemName(string(Mesh));
- if ( Level.Game.bCanChangeSkin
- /* && (SkinName == "" || Left(SkinName, Len(MeshName)) ~= MeshName) */)
- {
- Self.static.SetMultiSkin(Self, SkinName, FaceName, TeamNum );
- }
- }
- simulated final function plane ColorToPlane( Color C )
- {
- local plane P;
- P.X = C.R/255.f;
- P.Y = C.G/255.f;
- P.Z = C.B/255.f;
- P.W = C.A/255.f;
- return P;
- }
- // Called by Render Engine client side.
- simulated event UpdateDistanceFog()
- {
- if( DistanceFogOld!=CameraRegion.Zone )
- {
- InitNewFogZone(CameraRegion.Zone);
- DistanceFogOld = CameraRegion.Zone;
- }
- else if( bBlendingDistanceFog )
- UpdateFogBlending(CameraRegion.Zone);
- }
- simulated final function InitNewFogZone( ZoneInfo Z )
- {
- if( !bDistanceFogEnabled && !Z.bDistanceFog)
- return; // No blending needed.
- FogMode = Z.FogMode;
- bBlendingDistanceFog = (Z.FadeTime>0.f);
- if( !bBlendingDistanceFog )
- {
- // No blending needed.
- DistanceFogColor = ColorToPlane(Z.FogColor);
- DistanceFogDistance[0] = Z.FogDistanceStart;
- DistanceFogDistance[1] = Z.FogDistance;
- bDistanceFogEnabled = Z.bDistanceFog;
- FogDensity = Z.FogDensity;
- }
- else
- {
- if( !bDistanceFogEnabled ) // Fade in from infinitive.
- {
- DistanceFogBlend = ColorToPlane(Z.FogColor);
- DistanceFogColor = DistanceFogBlend;
- DistanceFogStart[0] = Z.FogDistanceStart+5000.f;
- DistanceFogStart[1] = Z.FogDistance+5000.f;
- FogDensity = Z.FogDensity/10;
- }
- else
- {
- DistanceFogBlend = DistanceFogColor;
- DistanceFogStart[0] = DistanceFogDistance[0];
- DistanceFogStart[1] = DistanceFogDistance[1];
- FogDensity = 0.01;
- }
- DistanceFogBlendTimer[0] = Level.TimeSeconds+Z.FadeTime;
- DistanceFogBlendTimer[1] = Z.FadeTime;
- bDistanceFogEnabled = true;
- }
- }
- simulated final function UpdateFogBlending( ZoneInfo Z )
- {
- local float A,NA;
- local plane P;
- A = (DistanceFogBlendTimer[0]-Level.TimeSeconds)/DistanceFogBlendTimer[1]; // Get alpha
- if( A<=0.f ) // Blending complete.
- {
- if( !Z.bDistanceFog )
- bDistanceFogEnabled = false;
- else
- {
- DistanceFogColor = ColorToPlane(Z.FogColor);
- DistanceFogDistance[0] = Z.FogDistanceStart;
- DistanceFogDistance[1] = Z.FogDistance;
- FogDensity = Z.FogDensity;
- }
- bBlendingDistanceFog = false;
- return;
- }
- NA = (1.f-A); // Get negative alpha.
- if( !Z.bDistanceFog ) // Fade out to infinitive distance.
- {
- DistanceFogDistance[0] = (5000.f*NA+DistanceFogStart[0]);
- DistanceFogDistance[1] = (5000.f*NA+DistanceFogStart[1]);
- FogDensity = A/1000;
- }
- else
- {
- P = ColorToPlane(Z.FogColor);
- DistanceFogColor.X = (P.X*NA+DistanceFogBlend.X*A);
- DistanceFogColor.Y = (P.Y*NA+DistanceFogBlend.Y*A);
- DistanceFogColor.Z = (P.Z*NA+DistanceFogBlend.Z*A);
- DistanceFogColor.W = (P.W*NA+DistanceFogBlend.W*A);
- DistanceFogDistance[0] = (Z.FogDistanceStart*NA+DistanceFogStart[0]*A);
- DistanceFogDistance[1] = (Z.FogDistance*NA+DistanceFogStart[1]*A);
- FogDensity = Z.FogDensity-A/1000;
- }
- }
- //*************************************************************************************
- // Normal gameplay execs
- // Type the name of the exec function at the console to execute it
- exec function ShowSpecialMenu( string ClassName )
- {
- local class<menu> aMenu${1}< ${3} >
- aMenuClass = class<menu>( DynamicLoadObject( ClassName, class'Class' ) );
- if ( aMenuClass!=None )
- {
- bSpecialMenu = true;
- SpecialMenu = aMenu${1}< ${3} >
- ShowMenu();
- }
- }
- exec function Jump( optional float F )
- {
- bPressedJump = true;
- }
- exec function CauseEvent( name N )
- {
- if ( Level.NetMode==NM_Client )
- {
- Admin("CauseEvent"@N);
- Return; // We are a client, pass it to server.
- }
- if ( Level.Game.GetAccessManager().CanExecuteCheatStr(Self,'CauseEvent',string(N)) )
- TriggerEvent(N,Self,Self);
- }
- exec function Taunt( name Sequence )
- {
- if ( HasAnim(Sequence) && GetAnimGroup(Sequence) == 'Gesture' )
- {
- ServerTaunt(Sequence);
- PlayAnim(Sequence, 0.7, 0.2);
- }
- }
- function ServerTaunt(name Sequence )
- {
- if ( HasAnim(Sequence) && GetAnimGroup(Sequence)=='Gesture' )
- PlayAnim(Sequence, 0.7, 0.2);
- }
- exec function FeignDeath()
- {
- }
- exec function CallForHelp()
- {
- local Pawn P;
- if ( !Level.Game.bTeamGame || (Enemy == None) || (Enemy.Health <= 0) )
- return;
- for ( P=Level.PawnList; P!=None; P=P.NextPawn )
- if ( P.bIsPlayer && (P.PlayerReplicationInfo.Team == PlayerReplicationInfo.Team) )
- P.HandleHelpMessageFrom(self);
- }
- function damageAttitudeTo(pawn Other)
- {
- if( Level.Game!=None && Other!=None && Other!=Self )
- {
- if( Level.Game.bTeamGame )
- if( GetTeamNum()!=Other.GetTeamNum() )
- Enemy = Other;
- else if( Level.Game.bDeathMatch || !Other.bIsPlayer )
- Enemy = Other;
- }
- }
- exec function Grab()
- {
- local GameRules G;
- for ( G = Level.Game.GameRules; G != None; G = G.NextRules )
- if ( G.bHandleGrab && !G.CanGrab(self) )
- return;
- if (CarriedDecoration == None)
- GrabDecoration();
- else
- DropDecoration();
- }
- // Send a voice message of a certain type to a certain player.
- exec function Speech( int Type, int Index, int Callsign )
- {
- local VoicePack V;
- if ( PlayerReplicationInfo.VoiceType == None || Level.TimeSeconds - OldMessageTime < 2.5 )
- return;
- else OldMessageTime = Level.TimeSeconds;
- V = Spawn( PlayerReplicationInfo.VoiceType, Self );
- if (V != None)
- {
- V.PlayerSpeech( Type, Index, Callsign );
- V.Destroy();
- }
- }
- function PlayChatting();
- function Typing( bool bTyping )
- {
- bIsTyping = bTyping;
- if (bTyping)
- {
- if (Level.Game.WorldLog != None)
- Level.Game.WorldLog.LogTypingEvent(True, Self);
- if (Level.Game.LocalLog != None)
- Level.Game.LocalLog.LogTypingEvent(True, Self);
- PlayChatting();
- }
- else
- {
- if (Level.Game.WorldLog != None)
- Level.Game.WorldLog.LogTypingEvent(False, Self);
- if (Level.Game.LocalLog != None)
- Level.Game.LocalLog.LogTypingEvent(False, Self);
- }
- }
- // Send a message to all players.
- exec function Say( string Msg )
- {
- local Pawn P;
- local GameRules G;
- if ( Level.Game.GameRules!=None )
- {
- for ( G=Level.Game.GameRules; G!=None; G=G.NextRules )
- if ( G.bNotifyMessages && !G.AllowChat(Self,Msg) )
- Return;
- }
- if ( Level.Game.AllowsBroadcast(self, Len(Msg)) )
- for ( P=Level.PawnList; P!=None; P=P.nextPawn )
- if ( P.bIsPlayer )
- P.TeamMessage( PlayerReplicationInfo, Msg, 'Say' );
- return;
- }
- exec function TeamSay( string Msg )
- {
- local Pawn P;
- local GameRules G;
- if ( !Level.Game.bTeamGame )
- {
- Say(Msg);
- return;
- }
- if ( Level.Game.GameRules!=None )
- {
- for ( G=Level.Game.GameRules; G!=None; G=G.NextRules )
- if ( G.bNotifyMessages && !G.AllowChat(Self,Msg) )
- Return;
- }
- if ( Msg ~= "Help" )
- {
- CallForHelp();
- return;
- }
- if ( Level.Game.AllowsBroadcast(self, Len(Msg)) )
- for ( P=Level.PawnList; P!=None; P=P.nextPawn )
- if ( P.bIsPlayer && (P.PlayerReplicationInfo.Team == PlayerReplicationInfo.Team) )
- {
- if ( P.IsA('PlayerPawn') )
- P.TeamMessage( PlayerReplicationInfo, Msg, 'TeamSay' );
- }
- }
- exec function RestartLevel()
- {
- if( Level.Game.GetAccessManager().CanExecuteCheat(Self,'RestartLevel') )
- ClientTravel( "?restart", TRAVEL_Relative, false );
- }
- exec function LocalTravel( string URL )
- {
- if( Level.Game.GetAccessManager().CanExecuteCheatStr(Self,'LocalTravel',URL) )
- ClientTravel( URL, TRAVEL_Relative, true );
- }
- exec function ThrowWeapon()
- {
- if ( Level.NetMode == NM_Client )
- return;
- if ( Weapon==None || (Weapon.Class==Level.Game.DefaultWeapon) || !Weapon.bCanThrow )
- return;
- Weapon.Velocity = Vector(ViewRotation) * 500 + vect(0,0,220);
- Weapon.bTossedOut = true;
- TossWeapon();
- if ( Weapon == None )
- SwitchToBestWeapon();
- }
- function ToggleZoom()
- {
- if ( DefaultFOV != DesiredFOV )
- EndZoom();
- else
- StartZoom();
- }
- function StartZoom()
- {
- ZoomLevel = 0.0;
- bZooming = true;
- }
- function StopZoom()
- {
- bZooming = false;
- }
- function EndZoom()
- {
- bZooming = false;
- DesiredFOV = DefaultFOV;
- }
- exec function FOV(float F)
- {
- SetDesiredFOV(F);
- }
- exec function UpdateWideScreen(float F)
- {
- SetDesiredFOV(F);
- MainFOV=F;
- SaveConfig();
- }
- exec function SetDesiredFOV(float F)
- {
- if ( !Level.bNoCheating || bAdmin || (Level.Netmode==NM_Standalone) )
- {
- DefaultFOV = FClamp(F, 1, 170);
- DesiredFOV = DefaultFOV;
- }
- else
- {
- DefaultFOV = FClamp(F, 90, 170);
- DesiredFOV = DefaultFOV;
- }
- }
- /* PrevWeapon()
- - switch to previous inventory group weapon
- */
- exec function PrevWeapon()
- {
- local int prevGroup;
- local Inventory inv;
- local Weapon realWeapon, w, Prev;
- local bool bFoundWeapon;
- if ( bShowMenu || Len(Level.Pauser)>0 )
- return;
- if ( Weapon == None )
- {
- SwitchToBestWeapon();
- return;
- }
- prevGroup = 0;
- realWeapon = Weapon;
- if ( PendingWeapon != None )
- Weapon = PendingWeapon;
- PendingWeapon = None;
- for (inv=Inventory; inv!=None; inv=inv.Inventory)
- {
- w = Weapon(inv);
- if ( w != None )
- {
- if ( w.InventoryGroup == Weapon.InventoryGroup )
- {
- if ( w == Weapon )
- {
- bFoundWeapon = true;
- if ( Prev != None )
- {
- PendingWeapon = Prev;
- break;
- }
- }
- else if ( !bFoundWeapon && ((w.AmmoType == None) || (w.AmmoType.AmmoAmount>0)) )
- Prev = W;
- }
- else if ( (w.InventoryGroup < Weapon.InventoryGroup)
- && ((w.AmmoType == None) || (w.AmmoType.AmmoAmount>0))
- && (w.InventoryGroup >= prevGroup) )
- {
- prevGroup = w.InventoryGroup;
- PendingWeapon = w;
- }
- }
- }
- bFoundWeapon = false;
- prevGroup = Weapon.InventoryGroup;
- if ( PendingWeapon == None )
- for (inv=Inventory; inv!=None; inv=inv.Inventory)
- {
- w = Weapon(inv);
- if ( w != None )
- {
- if ( w.InventoryGroup == Weapon.InventoryGroup )
- {
- if ( w == Weapon )
- bFoundWeapon = true;
- else if ( bFoundWeapon && (PendingWeapon == None) && ((w.AmmoType == None) || (w.AmmoType.AmmoAmount>0)) )
- PendingWeapon = W;
- }
- else if ( (w.InventoryGroup > PrevGroup)
- && ((w.AmmoType == None) || (w.AmmoType.AmmoAmount>0)) )
- {
- prevGroup = w.InventoryGroup;
- PendingWeapon = w;
- }
- }
- }
- Weapon = realWeapon;
- if ( PendingWeapon == None )
- return;
- if ( Weapon != PendingWeapon )
- Weapon.PutDown();
- }
- /* NextWeapon()
- - switch to next inventory group weapon
- */
- exec function NextWeapon()
- {
- local int nextGroup;
- local Inventory inv;
- local Weapon realWeapon, w, Prev;
- local bool bFoundWeapon;
- if ( bShowMenu || Len(Level.Pauser)>0 )
- return;
- if ( Weapon == None )
- {
- SwitchToBestWeapon();
- return;
- }
- nextGroup = 100;
- realWeapon = Weapon;
- if ( PendingWeapon != None )
- Weapon = PendingWeapon;
- PendingWeapon = None;
- for (inv=Inventory; inv!=None; inv=inv.Inventory)
- {
- w = Weapon(inv);
- if ( w != None )
- {
- if ( w.InventoryGroup == Weapon.InventoryGroup )
- {
- if ( w == Weapon )
- bFoundWeapon = true;
- else if ( bFoundWeapon && ((w.AmmoType == None) || (w.AmmoType.AmmoAmount>0)) )
- {
- PendingWeapon = W;
- break;
- }
- }
- else if ( (w.InventoryGroup > Weapon.InventoryGroup)
- && ((w.AmmoType == None) || (w.AmmoType.AmmoAmount>0))
- && (w.InventoryGroup < nextGroup) )
- {
- nextGroup = w.InventoryGroup;
- PendingWeapon = w;
- }
- }
- }
- bFoundWeapon = false;
- nextGroup = Weapon.InventoryGroup;
- if ( PendingWeapon == None )
- for (inv=Inventory; inv!=None; inv=inv.Inventory)
- {
- w = Weapon(Inv);
- if ( w != None )
- {
- if ( w.InventoryGroup == Weapon.InventoryGroup )
- {
- if ( w == Weapon )
- {
- bFoundWeapon = true;
- if ( Prev != None )
- PendingWeapon = Prev;
- }
- else if ( !bFoundWeapon && (PendingWeapon == None) && ((w.AmmoType == None) || (w.AmmoType.AmmoAmount>0)) )
- Prev = W;
- }
- else if ( (w.InventoryGroup < nextGroup)
- && ((w.AmmoType == None) || (w.AmmoType.AmmoAmount>0)) )
- {
- nextGroup = w.InventoryGroup;
- PendingWeapon = w;
- }
- }
- }
- Weapon = realWeapon;
- if ( PendingWeapon == None )
- return;
- if ( Weapon != PendingWeapon )
- Weapon.PutDown();
- }
- exec function QuickSave()
- {
- if ( (Health > 0)
- && (Level.NetMode == NM_Standalone)
- && !Level.Game.bDeathMatch )
- {
- ClientMessage(QuickSaveString);
- ConsoleCommand("SaveGame 9");
- }
- }
- exec function QuickLoad()
- {
- if ( (Level.NetMode == NM_Standalone)
- && !Level.Game.bDeathMatch )
- ClientTravel( "?load=9", TRAVEL_Absolute, false);
- }
- exec function Kick( string S )
- {
- local Pawn aPawn;
- if ( !Level.Game.GetAccessManager().CanExecuteCheatStr(Self,'Kick',S) )
- return;
- for ( aPawn=Level.PawnList; aPawn!=None; aPawn=aPawn.NextPawn )
- if( aPawn.bIsPlayer
- && aPawn.PlayerReplicationInfo.PlayerName~=S
- && (PlayerPawn(aPawn)==None || Viewport(PlayerPawn(aPawn).Player)==None) )
- {
- aPawn.Destroy();
- return;
- }
- }
- // Try to set the pause state; returns success indicator.
- function bool SetPause( BOOL bPause )
- {
- return Level.Game.SetPause(bPause, self);
- }
- exec function SetMouseSmoothThreshold( float F )
- {
- MouseSmoothThreshold = FClamp(F, 0, 1);
- SaveConfig();
- }
- exec function SetMaxMouseSmoothing( bool B )
- {
- bMaxMouseSmoothing = B;
- SaveConfig();
- }
- // Try to pause the game.
- exec function Pause()
- {
- if ( bShowMenu )
- return;
- if ( !SetPause(Len(Level.Pauser)==0) )
- ClientMessage(NoPauseMessage);
- }
- // Activate specific inventory item
- exec function ActivateInventoryItem( class InvItem )
- {
- local Inventory Inv;
- Inv = FindInventoryType(InvItem);
- if ( Inv != None )
- Inv.Activate();
- }
- // Translator Hotkey
- exec function ActivateTranslator()
- {
- if ( bShowMenu || Len(Level.Pauser)>0 )
- return;
- If (Inventory!=None) Inventory.ActivateTranslator(False);
- }
- // Translator Hotkey
- exec function ActivateHint()
- {
- if ( bShowMenu || Len(Level.Pauser)>0 )
- return;
- If (Inventory!=None) Inventory.ActivateTranslator(True);
- }
- // HUD
- exec function ChangeHud()
- {
- if ( myHud != None )
- myHUD.ChangeHud(1);
- myHUD.SaveConfig();
- }
- // Crosshair
- exec function ChangeCrosshair()
- {
- if ( myHud != None )
- myHUD.ChangeCrosshair(1);
- myHUD.SaveConfig();
- }
- event PreRender( canvas Canvas )
- {
- if( RendMap==1 )
- {
- Canvas.SetPos(0,0);
- Canvas.DrawColor.R = 0;
- Canvas.DrawColor.G = 0;
- Canvas.DrawColor.B = 0;
- Canvas.Style = 1;
- Canvas.Z = 1;
- Canvas.DrawTile(Texture'DefaultTexture',Canvas.ClipX,Canvas.ClipY,0,0,1,1);
- Canvas.DrawActor(None,False,True); // Clear Z
- }
- if ( myHud != None )
- myHUD.PreRender(Canvas);
- else if ( (Viewport(Player) != None) && (HUDType != None) )
- myHUD = spawn(HUDType, self);
- }
- event PostRender( canvas Canvas )
- {
- if ( myHud != None )
- myHUD.PostRender(Canvas);
- else if ( (Viewport(Player) != None) && (HUDType != None) )
- myHUD = spawn(HUDType, self);
- }
- //=============================================================================
- // Inventory-related input notifications.
- // Handle function keypress for F1-F10.
- exec function FunctionKey( byte Num )
- {
- }
- // The player wants to switch to weapon group numer I.
- exec function SwitchWeapon (byte F )
- {
- local weapon newWeapon;
- if ( bShowMenu || Len(Level.Pauser)>0 )
- {
- if ( myHud != None )
- myHud.InputNumber(F);
- return;
- }
- if ( Inventory == None )
- return;
- if ( (Weapon != None) && (Weapon.Inventory != None) )
- newWeapon = Weapon.Inventory.WeaponChange(F);
- else
- newWeapon = None;
- if ( newWeapon == None )
- newWeapon = Inventory.WeaponChange(F);
- if ( newWeapon == None )
- return;
- if ( Weapon == None )
- {
- PendingWeapon = newWeapon;
- ChangedWeapon();
- }
- else if ( (Weapon != newWeapon) && Weapon.PutDown() )
- PendingWeapon = newWeapon;
- }
- exec function GetWeapon(class<Weapon> NewWeaponClass )
- {
- local Inventory Inv;
- if ( Level.NetMode==NM_Client )
- {
- if ( NewWeaponClass!=None )
- SwitchWeapon(NewWeaponClass.Default.InventoryGroup); // Stupid workaround for clients...
- Return;
- }
- if ( (Inventory == None) || (NewWeaponClass == None)
- || ((Weapon != None) && (Weapon.Class == NewWeaponClass)) )
- return;
- for ( Inv=Inventory; Inv!=None; Inv=Inv.Inventory )
- if ( Inv.Class == NewWeaponClass )
- {
- PendingWeapon = Weapon(Inv);
- Weapon.PutDown();
- return;
- }
- }
- // The player wants to select previous item
- exec function PrevItem()
- {
- local Inventory Inv, LastItem;
- if ( bShowMenu || Len(Level.Pauser)>0 )
- return;
- if( Inventory==None )
- {
- SelectedItem = None;
- return;
- }
- if (SelectedItem==None)
- {
- SelectedItem = Inventory.SelectNext();
- Return;
- }
- if (SelectedItem.Inventory!=None)
- for ( Inv=SelectedItem.Inventory; Inv!=None; Inv=Inv.Inventory )
- {
- if (Inv==None) Break;
- if (Inv.bActivatable) LastItem=Inv;
- }
- for ( Inv=Inventory; Inv!=SelectedItem; Inv=Inv.Inventory )
- {
- if (Inv==None) Break;
- if (Inv.bActivatable) LastItem=Inv;
- }
- if (LastItem!=None)
- {
- SelectedItem = LastItem;
- ClientMessage(SelectedItem.ItemName$SelectedItem.M_Selected);
- }
- }
- // The player wants to active selected item
- exec function ActivateItem()
- {
- if ( bShowMenu || Len(Level.Pauser)>0 )
- return;
- if (SelectedItem!=None)
- SelectedItem.Activate();
- }
- // The player wants to fire.
- exec function Fire( optional float F )
- {
- bJustFired = true;
- if ( bShowMenu || Len(Level.Pauser)>0 || (Role < ROLE_Authority) )
- return;
- if ( Weapon!=None )
- {
- Weapon.bPointing = true;
- PlayFiring();
- Weapon.Fire(F);
- }
- }
- // The player wants to alternate-fire.
- exec function AltFire( optional float F )
- {
- bJustAltFired = true;
- if ( bShowMenu || Len(Level.Pauser)>0 || (Role < ROLE_Authority) )
- return;
- if ( Weapon!=None )
- {
- Weapon.bPointing = true;
- PlayFiring();
- Weapon.AltFire(F);
- }
- }
- //Player Jumped
- function DoJump( optional float F )
- {
- if ( CarriedDecoration != None )
- return;
- if ( !bIsCrouching && (Physics == PHYS_Walking) )
- {
- if ( Role == ROLE_Authority )
- PlaySound(JumpSound, SLOT_Talk, 1.5, true, 1200, 1.0 );
- if ( (Level.Game != None) && (Level.Game.Difficulty > 0) )
- MakeNoise(0.1 * Level.Game.Difficulty);
- PlayInAir();
- if ( bCountJumps && (Role == ROLE_Authority) )
- Inventory.OwnerJumped();
- Velocity.Z = JumpZ;
- if ( Base!=Level && Base!=None )
- Velocity.Z += Base.Velocity.Z;
- SetPhysics(PHYS_Falling);
- }
- }
- exec function Suicide()
- {
- KilledBy( None );
- }
- exec function AlwaysMouseLook( Bool B )
- {
- ChangeAlwaysMouseLook(B);
- SaveConfig();
- }
- function ChangeAlwaysMouseLook(Bool B)
- {
- bAlwaysMouseLook = B;
- if ( bAlwaysMouseLook )
- bLookUpStairs = false;
- }
- exec function SnapView( bool B )
- {
- ChangeSnapView(B);
- SaveConfig();
- }
- function ChangeSnapView( bool B )
- {
- bSnapToLevel = B;
- }
- exec function StairLook( bool B )
- {
- ChangeStairLook(B);
- SaveConfig();
- }
- function ChangeStairLook( bool B )
- {
- bLookUpStairs = B;
- if ( bLookUpStairs )
- bAlwaysMouseLook = false;
- }
- exec function SetDodgeClickTime( float F )
- {
- ChangeDodgeClickTime(F);
- SaveConfig();
- }
- function ChangeDodgeClickTime( float F )
- {
- DodgeClickTime = FMin(0.3, F);
- }
- exec function SetName( coerce string S )
- {
- S = Left(S,40);
- ChangeName(S);
- UpdateURL("Name", S, true);
- SaveConfig();
- }
- function ChangeName( coerce string S )
- {
- if (Level.Game.WorldLog != None)
- ClientMessage(CantChangeNameMsg);
- else
- Level.Game.ChangeName( self, S, true );
- }
- function ChangeTeam( int N )
- {
- local byte OldTeam;
- OldTeam = PlayerReplicationInfo.Team;
- if ( Level.Game.ChangeTeam(self,N) && Level.Game.bTeamGame && OldTeam!=PlayerReplicationInfo.Team )
- Died( None, '', Location );
- }
- exec function SetAutoAim( float F )
- {
- ChangeAutoAim(F);
- SaveConfig();
- }
- function ChangeAutoAim( float F )
- {
- MyAutoAim = FMax(Level.Game.AutoAim, F);
- }
- exec function PlayersOnly()
- {
- if ( Level.Netmode != NM_Standalone )
- return;
- Level.bPlayersOnly = !Level.bPlayersOnly;
- }
- exec function SetHand( string S )
- {
- ChangeSetHand(S);
- SaveConfig();
- }
- function ChangeSetHand( string S )
- {
- if ( S ~= "Left" )
- Handedness = 1;
- else if ( S~= "Right" )
- Handedness = -1;
- else if ( S ~= "Center" )
- Handedness = 0;
- else if ( S ~= "Hidden" )
- Handedness = 2;
- ServerSetHandedness(Handedness);
- }
- exec function ViewPlayer( string S )
- {
- local pawn P;
- for ( P=Level.pawnList; P!=None; P= P.NextPawn )
- if ( P.bIsPlayer && (P.PlayerReplicationInfo.PlayerName ~= S) )
- break;
- if ( (P != None) && Level.Game.CanSpectate(self, P) )
- {
- ClientMessage(ViewingFrom$P.PlayerReplicationInfo.PlayerName, 'Event', true);
- if ( P == self)
- ViewTarget = None;
- else
- ViewTarget = P;
- }
- else
- ClientMessage(FailedView);
- bBehindView = ( ViewTarget != None );
- if ( bBehindView )
- ViewTarget.BecomeViewTarget();
- }
- exec function CheatView( class<actor> aClass )
- {
- local actor other, first;
- local bool bFound;
- if( !Level.Game.GetAccessManager().CanExecuteCheatStr(Self,'CheatView',string(aClass)) )
- return;
- first = None;
- ForEach AllActors( aClass, other )
- {
- if ( (first == None) && (other != self) )
- {
- first = other;
- bFound = true;
- }
- if ( other == ViewTarget )
- first = None;
- }
- if ( first != None )
- {
- if ( first.IsA('Pawn') && Pawn(first).bIsPlayer && (Pawn(first).PlayerReplicationInfo.PlayerName != "") )
- ClientMessage(ViewingFrom$Pawn(first).PlayerReplicationInfo.PlayerName, 'Event', true);
- else
- ClientMessage(ViewingFrom$first, 'Event', true);
- ViewTarget = first;
- }
- else
- {
- if ( bFound )
- ClientMessage(ViewingFrom$OwnCamera, 'Event', true);
- else
- ClientMessage(FailedView, 'Event', true);
- ViewTarget = None;
- }
- bBehindView = ( ViewTarget != None );
- if ( bBehindView )
- ViewTarget.BecomeViewTarget();
- }
- exec function ViewSelf()
- {
- bBehindView = false;
- Viewtarget = None;
- ClientMessage("Now viewing from own camera", 'Event', true);
- }
- exec function ViewClass( class<actor> aClass, optional bool bQuiet )
- {
- local actor other, first;
- local bool bFound;
- first = None;
- ForEach AllActors( aClass, other )
- {
- if ( (first == None) && (other != self)
- && ( (bAdmin && Level.Game==None) || Level.Game.CanSpectate(self, other) ) )
- {
- first = other;
- bFound = true;
- }
- if ( other == ViewTarget )
- first = None;
- }
- if ( first != None )
- {
- if ( !bQuiet )
- {
- if ( first.IsA('Pawn') && Pawn(first).bIsPlayer && (Pawn(first).PlayerReplicationInfo.PlayerName != "") )
- ClientMessage(ViewingFrom$Pawn(first).PlayerReplicationInfo.PlayerName, 'Event', true);
- else
- ClientMessage(ViewingFrom$first, 'Event', true);
- }
- ViewTarget = first;
- }
- else
- {
- if ( !bQuiet )
- {
- if ( bFound )
- ClientMessage(ViewingFrom$OwnCamera, 'Event', true);
- else
- ClientMessage(FailedView, 'Event', true);
- }
- ViewTarget = None;
- }
- bBehindView = ( ViewTarget != None );
- if ( bBehindView )
- ViewTarget.BecomeViewTarget();
- }
- exec function NeverSwitchOnPickup( bool B )
- {
- bNeverSwitchOnPickup = B;
- }
- exec function InvertMouse( bool B )
- {
- bInvertMouse = B;
- SaveConfig();
- }
- exec function SwitchLevel( string URL )
- {
- if( Level.Game.GetAccessManager().CanExecuteCheatStr(Self,'SwitchLevel',URL) )
- Level.ServerTravel( URL, false );
- }
- exec function SwitchCoopLevel( string URL )
- {
- if( Level.Game.GetAccessManager().CanExecuteCheatStr(Self,'SwitchCoopLevel',URL) )
- Level.ServerTravel( URL, true );
- }
- exec function ShowScores()
- {
- bShowScores = !bShowScores;
- }
- exec function ShowMenu()
- {
- WalkBob = vect(0,0,0);
- bShowMenu = true; // menu is responsible for turning this off
- Player.Console.GotoState('Menuing');
- if ( Level.Netmode == NM_Standalone )
- SetPause(true);
- }
- exec function ShowLoadMenu()
- {
- Player.Console.ShowLoadGameMenu();
- }
- exec function AddBots(int N)
- {
- ServerAddBots(N);
- }
- function ServerAddBots(int N)
- {
- local int i;
- if( !Level.Game.bDeathMatch || !Level.Game.GetAccessManager().CanExecuteCheatStr(Self,'AddBots',string(N)) )
- return;
- for ( i=0; i<N; i++ )
- Level.Game.AddBot();
- }
- //*************************************************************************************
- // Special purpose/cheat execs
- exec function ClearProgressMessages()
- {
- local int i;
- for (i=0; i<5; i++)
- {
- ProgressMessage[i] = "";
- ProgressColor[i].R = 255;
- ProgressColor[i].G = 255;
- ProgressColor[i].B = 255;
- }
- }
- exec function SetProgressMessage( string S, int Index )
- {
- if (Index < 5)
- ProgressMessage[Index] = S;
- }
- exec function SetProgressColor( color C, int Index )
- {
- if (Index < 5)
- ProgressColor[Index] = C;
- }
- exec function SetProgressTime( float T )
- {
- ProgressTimeOut = T + Level.TimeSeconds;
- }
- exec event ShowUpgradeMenu();
- exec function Amphibious()
- {
- if ( Level.NetMode==NM_Client )
- {
- Admin("Amphibious");
- Return; // We are a network client, pass to server.
- }
- if( Level.Game.GetAccessManager().CanExecuteCheat(Self,'Amphibious') )
- UnderwaterTime = +999999.0;
- }
- exec function Fly()
- {
- if( !Level.Game.GetAccessManager().CanExecuteCheat(Self,'Fly') )
- return;
- UnderWaterTime = Default.UnderWaterTime;
- ClientMessage("You feel much lighter");
- SetCollision(true, true , true);
- bCollideWorld = true;
- GotoState('CheatFlying');
- }
- exec function Walk()
- {
- if( !Level.Game.GetAccessManager().CanExecuteCheat(Self,'Walk') )
- return;
- bHidden = (Health<=0);
- Visibility = Default.Visibility;
- bProjTarget = True;
- Velocity = vect(0.0,0.0,0.0);
- Acceleration = vect(0.0,0.0,0.0);
- BaseEyeHeight = Default.BaseEyeHeight;
- EyeHeight = BaseEyeHeight;
- PlayWaiting();
- bPressedJump = false;
- if ( Region.Zone.bWaterZone )
- {
- if ( HeadRegion.Zone.bWaterZone )
- PainTime = UnderWaterTime;
- GotoState('PlayerSwimming');
- }
- else GotoState('PlayerWalking');
- StartWalk();
- }
- function StartWalk()
- {
- UnderWaterTime = Default.UnderWaterTime;
- SetCollision(true, true , true);
- if ( Region.Zone.bWaterZone )
- SetPhysics(PHYS_swimming);
- else SetPhysics(PHYS_Walking);
- bCollideWorld = true;
- ClientReStart();
- }
- exec function Ghost()
- {
- if( !Level.Game.GetAccessManager().CanExecuteCheat(Self,'Ghost') )
- return;
- UnderWaterTime = -1.0;
- ClientMessage("You feel ethereal");
- SetCollision(false, false, false);
- bCollideWorld = false;
- GotoState('CheatFlying');
- }
- exec function ShowInventory()
- {
- local Inventory Inv;
- if (Level.Netmode != NM_Standalone)
- return;
- if ( Weapon!=None )
- log( " Weapon: " $ Weapon.Class );
- for ( Inv=Inventory; Inv!=None; Inv=Inv.Inventory )
- log( "Inv: "$Inv );
- if ( SelectedItem != None )
- log( "Selected Item"@SelectedItem@"Charge"@SelectedItem.Charge );
- }
- exec function AllAmmo()
- {
- local Inventory Inv;
- if ( Level.NetMode==NM_Client )
- {
- Admin("AllAmmo");
- Return; // We are a network client, pass to server.
- }
- if( !Level.Game.GetAccessManager().CanExecuteCheat(Self,'AllAmmo') )
- return;
- for ( Inv=Inventory; Inv!=None; Inv=Inv.Inventory )
- if (Ammo(Inv)!=None)
- {
- Ammo(Inv).AmmoAmount = 999;
- Ammo(Inv).MaxAmmo = 999;
- }
- }
- exec function Invisible(bool B)
- {
- if ( Level.NetMode==NM_Client )
- {
- Admin("Invisible"@B);
- Return; // We are a network client, pass to server.
- }
- if( !Level.Game.GetAccessManager().CanExecuteCheatStr(Self,'Invisible',string(B)) )
- return;
- if (B)
- {
- bHidden = true;
- Visibility = 0;
- }
- else
- {
- bHidden = false;
- Visibility = Default.Visibility;
- }
- }
- exec function God()
- {
- if( !Level.Game.GetAccessManager().CanExecuteCheat(Self,'God') )
- return;
- if ( ReducedDamageType == 'All' )
- {
- ReducedDamageType = '';
- ClientMessage("God mode off");
- return;
- }
- ReducedDamageType = 'All';
- ClientMessage("God Mode on");
- }
- exec function BehindView( Bool B )
- {
- bBehindView = B;
- }
- exec function UToggleBehindView()
- {
- BehindView(!bBehindView);
- }
- exec function SetBob(float F)
- {
- UpdateBob(F);
- SaveConfig();
- }
- function UpdateBob(float F)
- {
- Bob = FClamp(F,0,0.032);
- }
- exec function SetSensitivity(float F)
- {
- UpdateSensitivity(F);
- SaveConfig();
- }
- function UpdateSensitivity(float F)
- {
- MouseSensitivity = FMax(0,F);
- }
- exec function SloMo( float T )
- {
- ServerSetSloMo(T);
- }
- function ServerSetSloMo(float T)
- {
- if( Level.Game.GetAccessManager().CanExecuteCheatStr(Self,'SloMo',string(T)) )
- {
- Level.Game.SetGameSpeed(T);
- Level.Game.SaveConfig();
- Level.Game.GameReplicationInfo.SaveConfig();
- }
- }
- exec function SetJumpZ( float F )
- {
- if ( Level.NetMode==NM_Client )
- {
- Admin("SetJumpZ"@F);
- Return; // We are a client, pass it to server.
- }
- if( Level.Game.GetAccessManager().CanExecuteCheatStr(Self,'SetJumpZ',string(F)) )
- JumpZ = F;
- }
- exec function SetSpeed( float F )
- {
- if ( Level.NetMode==NM_Client )
- {
- Admin("SetSpeed"@F);
- Return; // We are a client, pass it to server.
- }
- if( !Level.Game.GetAccessManager().CanExecuteCheatStr(Self,'SetSpeed',string(F)) )
- return;
- GroundSpeed = Default.GroundSpeed * f;
- WaterSpeed = Default.WaterSpeed * f;
- }
- exec function KillAll(class<actor> aClass)
- {
- local Actor A;
- if( !Level.Game.GetAccessManager().CanExecuteCheatStr(Self,'KillAll',string(aClass)) )
- return;
- ForEach AllActors(class 'Actor', A)
- if ( ClassIsChildOf(A.class, aClass) )
- A.Destroy();
- }
- exec function KillPawns()
- {
- local Pawn P;
- if ( Level.NetMode==NM_Client )
- {
- Admin("KillPawns");
- Return; // We are a client, pass it to server.
- }
- if( !Level.Game.GetAccessManager().CanExecuteCheat(Self,'KillPawns') )
- return;
- ForEach AllActors(class 'Pawn', P)
- if (PlayerPawn(P) == None)
- P.Destroy();
- }
- exec function Summon( string ClassName )
- {
- local class<actor> New${1}< ${3} >
- local string Orginal${1}< ${3} >
- if( !Level.Game.GetAccessManager().CanExecuteCheatStr(Self,'Summon',ClassName) )
- return;
- OrginalClass = ClassName;
- if ( InStr(ClassName,".")==-1 )
- ClassName = "UnrealI."$ClassName;
- log( "Fabricate " $ ClassName );
- NewClass = class<actor>( DynamicLoadObject( ClassName, class'Class',True) );
- if ( NewClass!=None )
- {
- if ( NewClass.Default.bStatic )
- ClientMessage("Can not spawn"@NewClass@"because actor has bStatic");
- else if ( NewClass.Default.bNoDelete )
- ClientMessage("Can not spawn"@NewClass@"because actor has bNoDelete");
- else if ( Spawn( NewClass,,,Location + (40+NewClass.Default.CollisionRadius) * Vector(Rotation) + vect(0,0,1) * 15,ViewRotation)==None )
- ClientMessage("Failed to spawn class:"@NewClass);
- }
- else ClientMessage("Unable to load class"@OrginalClass);
- }
- exec function TimeDemo( bool bActivate, optional bool bSaveToFile, optional int QuitAfterCycles )
- {
- if (Player.Console != None)
- {
- if (bActivate)
- {
- if (Player.Console.TimeDemo == None)
- Player.Console.TimeDemo = Spawn(class'TimeDemo');
- Player.Console.TimeDemo.DoSetup(Player.Console, bSaveToFile, QuitAfterCycles);
- }
- else
- {
- if (Player.Console.TimeDemo != None)
- Player.Console.TimeDemo.DoShutdown();
- }
- }
- }
- //==============
- // Navigation Aids
- exec function ShowPath()
- {
- //find next path to remembered spot
- local Actor node;
- if (Level.Netmode != NM_Standalone)
- return;
- node = FindPathTo(Destination);
- if (node != None)
- {
- log("found path");
- Spawn(class 'WayBeacon', self, '', node.location);
- }
- else
- log("didn't find path");
- }
- exec function RememberSpot()
- {
- //remember spot
- Destination = Location;
- }
- //=============================================================================
- // Input related functions.
- // Postprocess the player's input.
- event PlayerInput( float DeltaTime )
- {
- local float SmoothTime, FOVScale, MouseScale, KbdScale, AbsSmooth, AbsInput;
- LastCameraUpdate = -1;
- if ( bShowMenu && (myHud != None) )
- {
- if ( myHud.MainMenu != None )
- myHud.MainMenu.MenuTick( DeltaTime );
- // clear inputs
- bEdgeForward = false;
- bEdgeBack = false;
- bEdgeLeft = false;
- bEdgeRight = false;
- bWasForward = false;
- bWasBack = false;
- bWasLeft = false;
- bWasRight = false;
- aStrafe = 0;
- aTurn = 0;
- aForward = 0;
- aLookUp = 0;
- return;
- }
- else if ( bDelayedCommand )
- {
- bDelayedCommand = false;
- ConsoleCommand(DelayedCommand);
- }
- // Check for Dodge move
- // flag transitions
- bEdgeForward = (bWasForward ^^ (aBaseY > 0));
- bEdgeBack = (bWasBack ^^ (aBaseY < 0));
- bEdgeLeft = (bWasLeft ^^ (aStrafe > 0));
- bEdgeRight = (bWasRight ^^ (aStrafe < 0));
- bWasForward = (aBaseY > 0);
- bWasBack = (aBaseY < 0);
- bWasLeft = (aStrafe > 0);
- bWasRight = (aStrafe < 0);
- // Smooth and amplify mouse movement
- SmoothTime = FMin(0.2, 3 * DeltaTime);
- FOVScale = DesiredFOV * 0.01111;
- MouseScale = MouseSensitivity * FOVScale;
- aMouseX *= MouseScale;
- aMouseY *= MouseScale;
- //************************************************************************
- if (bMouseSmoothing)
- {
- if ( bMaxMouseSmoothing )
- {
- if ( !bMouseZeroed )
- {
- bMouseZeroed = ((aMouseX == 0) && (aMouseY == 0));
- if ( aMouseX == 0 )
- {
- if ( SmoothMouseX > 0 )
- aMouseX = 1;
- else if ( SmoothMouseX < 0 )
- aMouseX = -1;
- }
- if ( aMouseY == 0 )
- {
- if ( SmoothMouseY > 0 )
- aMouseY = 1;
- else if ( SmoothMouseY < 0 )
- aMouseY = -1;
- }
- }
- else
- bMouseZeroed = ((aMouseX == 0) && (aMouseY == 0));
- }
- if ( (SmoothMouseX == 0) || (aMouseX == 0)
- || ((SmoothMouseX > 0) != (aMouseX > 0)) )
- SmoothMouseX = aMouseX;
- else
- {
- AbsSmooth = Abs(SmoothMouseX);
- AbsInput = Abs(aMouseX);
- if ( (AbsSmooth < 0.85 * AbsInput) || (AbsSmooth > 1.17 * AbsInput) )
- SmoothMouseX = 5 * SmoothTime * aMouseX + (1 - 5 * SmoothTime) * SmoothMouseX;
- else
- SmoothMouseX = SmoothTime * aMouseX + (1 - SmoothTime) * SmoothMouseX;
- }
- if ( (SmoothMouseY == 0) || (aMouseY == 0)
- || ((SmoothMouseY > 0) != (aMouseY > 0)) )
- SmoothMouseY = aMouseY;
- else
- {
- AbsSmooth = Abs(SmoothMouseY);
- AbsInput = Abs(aMouseY);
- if ( (AbsSmooth < 0.85 * AbsInput) || (AbsSmooth > 1.17 * AbsInput) )
- SmoothMouseY = 5 * SmoothTime * aMouseY + (1 - 5 * SmoothTime) * SmoothMouseY;
- else
- SmoothMouseY = SmoothTime * aMouseY + (1 - SmoothTime) * SmoothMouseY;
- }
- }
- else
- {
- SmoothMouseX = aMouseX;
- SmoothMouseY = aMouseY;
- }
- // adjust keyboard and joystick movements
- /*
- if ( (aLookUp == 0) && (aBaseX == 0) && (aTurn == 0) )
- KbdAccel = 0.4;
- else if ( KbdAccel < 1.6 )
- {
- if ( KbdAccel < 0.7 )
- KbdAccel += deltatime;
- else
- KbdAccel = FMin(1.6, KbdAccel + 4 * deltatime);
- }
- */
- KbdAccel = 1.0;
- KbdScale = FOVScale * KbdAccel;
- aLookUp *= FOVScale;
- aTurn *= KbdScale;
- // Remap raw x-axis movement.
- if ( bStrafe!=0 )
- {
- // Strafe.
- aStrafe += aBaseX + SmoothMouseX;
- aBaseX = 0;
- }
- else
- {
- // Forward.
- aTurn += aBaseX * KbdScale + SmoothMouseX;
- aBaseX = 0;
- }
- // Remap mouse y-axis movement.
- if ( (bStrafe == 0) && (bAlwaysMouseLook || (bLook!=0)) )
- {
- // Look up/down.
- if ( bInvertMouse )
- aLookUp -= SmoothMouseY;
- else
- aLookUp += SmoothMouseY;
- }
- else
- {
- // Move forward/backward.
- aForward += SmoothMouseY;
- }
- if ( bSnapLevel != 0 )
- {
- bCenterView = true;
- bKeyboardLook = false;
- }
- else if (aLookUp != 0)
- {
- bCenterView = false;
- bKeyboardLook = true;
- }
- else if ( bSnapToLevel && !bAlwaysMouseLook )
- {
- bCenterView = true;
- bKeyboardLook = false;
- }
- // Remap other y-axis movement.
- if ( bFreeLook != 0 )
- {
- bKeyboardLook = true;
- aLookUp += 0.5 * aBaseY * KbdScale;
- }
- else
- aForward += aBaseY;
- aBaseY = 0;
- // Handle walking.
- HandleWalking();
- }
- //=============================================================================
- // functions.
- event UpdateEyeHeight(float DeltaTime)
- {
- local float smooth, bound;
- if (bIsReducedCrouch && IsInState('PlayerWalking'))
- BaseEyeHeight = default.BaseEyeHeight + CollisionHeight - default.CollisionHeight;
- smooth = FMin(1.0, 10.0 * DeltaTime/Level.TimeDilation);
- // smooth up/down stairs
- If( (IsInState('PlayerSwimming') || Physics==PHYS_Walking) && !bJustLanded )
- {
- EyeHeight = (EyeHeight - Location.Z + OldLocation.Z) * (1 - smooth) + ( ShakeVert + BaseEyeHeight) * smooth;
- bound = -0.5 * CollisionHeight;
- if (EyeHeight < bound)
- EyeHeight = bound;
- else
- {
- bound = FMin(FMax(0.0,(OldLocation.Z - Location.Z)), MaxStepHeight);
- if (bIsReducedCrouch)
- bound += default.CollisionHeight;
- else
- bound += CollisionHeight;
- if ( EyeHeight > bound )
- EyeHeight = bound;
- }
- }
- else
- {
- smooth = FMax(smooth, 0.35);
- bJustLanded = false;
- EyeHeight = EyeHeight * ( 1 - smooth) + (BaseEyeHeight + ShakeVert) * smooth;
- }
- // teleporters affect your FOV, so adjust it back down
- if ( FOVAngle != DesiredFOV )
- {
- if ( FOVAngle > DesiredFOV )
- FOVAngle = FOVAngle - FMax(7, 0.9 * DeltaTime * (FOVAngle - DesiredFOV));
- else
- FOVAngle = FOVAngle - FMin(-7, 0.9 * DeltaTime * (FOVAngle - DesiredFOV));
- if ( Abs(FOVAngle - DesiredFOV) <= 10 )
- FOVAngle = DesiredFOV;
- }
- // adjust FOV for weapon zooming
- if ( bZooming )
- {
- ZoomLevel += DeltaTime * 1.0;
- if (ZoomLevel > 0.9)
- ZoomLevel = 0.9;
- DesiredFOV = FClamp(90.0 - (ZoomLevel * 88.0), 1, 170);
- }
- }
- event PlayerTimeOut()
- {
- if (Health > 0)
- Died(None, 'suicided', Location);
- }
- // Just changed to pendingWeapon
- function ChangedWeapon()
- {
- Super.ChangedWeapon();
- if ( Weapon != None )
- Weapon.SetHand(Handedness);
- }
- function JumpOffPawn()
- {
- Velocity += 60 * VRand();
- Velocity.Z = 120;
- SetPhysics(PHYS_Falling);
- }
- event TravelPostAccept()
- {
- if ( Health <= 0 )
- Health = Default.Health;
- }
- // This pawn was possessed by a player.
- event Possess()
- {
- local byte i;
- if ( Level.Netmode == NM_Client )
- {
- // replicate client weapon preferences to server
- ServerSetHandedness(Handedness);
- for ( i=0; i<ArrayCount(WeaponPriority); i++ )
- ServerSetWeaponPriority(i, WeaponPriority[i]);
- }
- else if ( ViewPort(Player)!=None )
- bAdmin = True;
- ServerUpdateWeapons();
- bIsPlayer = true;
- DodgeClickTime = FMin(0.3, DodgeClickTime);
- EyeHeight = BaseEyeHeight;
- NetPriority = 8;
- StartWalk();
- DefaultFOV = FClamp(MainFOV, 90, 170);
- DesiredFOV = DefaultFOV;
- NeverSwitchOnPickup(bNeverAutoSwitch);
- }
- function ServerSetWeaponPriority(byte i, name WeaponName)
- {
- if (i < ArrayCount(WeaponPriority))
- WeaponPriority[i] = WeaponName;
- }
- // This pawn was unpossessed by a player.
- event UnPossess()
- {
- log(Self$" being unpossessed");
- if ( myHUD != None )
- myHUD.Destroy();
- bIsPlayer = false;
- EyeHeight = 0.8 * CollisionHeight;
- }
- singular function Carcass SpawnCarcass()
- {
- local carcass carc;
- carc = Spawn(CarcassType);
- if ( carc != None )
- {
- carc.Initfor(self);
- if (Player != None)
- carc.bPlayerCarcass = true;
- MoveTarget = carc; //for Player 3rd person views
- }
- return carc;
- }
- function bool Gibbed(name damageType)
- {
- if ( (damageType == 'decapitated') || (damageType == 'shot') )
- return false;
- if ( (Health < -80) || ((Health < -40) && (FRand() < 0.6)) )
- return true;
- return false;
- }
- singular function SpawnGibbedCarcass()
- {
- local carcass carc;
- carc = Spawn(CarcassType);
- if ( carc != None )
- {
- carc.Initfor(self);
- carc.ChunkUp(-1 * Health);
- MoveTarget = carc; //for Player 3rd person views
- }
- }
- event PlayerTick( float Time );
- //
- // Called immediately before gameplay begins.
- //
- event PreBeginPlay()
- {
- bIsPlayer = true;
- Super.PreBeginPlay();
- }
- event PostBeginPlay()
- {
- Super.PostBeginPlay();
- if (Level.LevelEnterText != "" )
- ClientMessage(Level.LevelEnterText);
- if ( Level.NetMode != NM_Client )
- {
- HUDType = Level.Game.HUDType;
- ScoringType = Level.Game.ScoreboardType;
- MyAutoAim = FMax(MyAutoAim, Level.Game.AutoAim);
- }
- bIsPlayer = true;
- DodgeClickTime = FMin(0.3, DodgeClickTime);
- EyeHeight = BaseEyeHeight;
- if ( Level.Game.IsA('SinglePlayer') && (Level.NetMode == NM_Standalone) )
- FlashScale = vect(0,0,0);
- If (MainFOV < 90.0 || MainFOV >170.0)
- MainFOV = 90.0;
- DefaultFOV=MainFOV;
- }
- function ServerUpdateWeapons()
- {
- local inventory Inv;
- For ( Inv=Inventory; Inv!=None; Inv=Inv.Inventory )
- if ( Inv.IsA('Weapon') )
- Weapon(Inv).SetSwitchPriority(self);
- }
- //=============================================================================
- // Animation playing - should be implemented in subclass,
- //
- function PlayDodge(eDodgeDir DodgeMove)
- {
- PlayDuck();
- }
- function PlayTurning();
- function PlaySwimming()
- {
- PlayRunning();
- }
- function PlayFeignDeath();
- function PlayRising();
- /* Adjust hit location - adjusts the hit location in for pawns, and returns
- true if it was really a hit, and false if not (for ducking, etc.)
- */
- simulated function bool AdjustHitLocation(out vector HitLocation, vector TraceDir)
- {
- local float adjZ, maxZ;
- TraceDir = Normal(TraceDir);
- HitLocation = HitLocation + 0.5 * CollisionRadius * TraceDir;
- if (BaseEyeHeight == default.BaseEyeHeight || bIsCrouching && bIsReducedCrouch)
- return true;
- maxZ = Location.Z + EyeHeight + 0.25 * CollisionHeight;
- if ( HitLocation.Z > maxZ )
- {
- if ( TraceDir.Z >= 0 )
- return false;
- adjZ = (maxZ - HitLocation.Z)/TraceDir.Z;
- HitLocation.Z = maxZ;
- HitLocation.X = HitLocation.X + TraceDir.X * adjZ;
- HitLocation.Y = HitLocation.Y + TraceDir.Y * adjZ;
- if ( VSize(HitLocation - Location) > CollisionRadius )
- return false;
- }
- return true;
- }
- /* AdjustAim()
- Calls this version for player aiming help.
- Aimerror not used in this version.
- Only adjusts aiming at pawns
- */
- function rotator AdjustAim(float projSpeed, vector projStart, int aimerror, bool bLeadTarget, bool bWarnTarget)
- {
- local vector FireDir, AimSpot, HitNormal, HitLocation;
- local actor BestTarget;
- local float bestAim, bestDist;
- local actor HitActor;
- FireDir = vector(ViewRotation);
- HitActor = Trace(HitLocation, HitNormal, projStart + 4000 * FireDir, projStart, true);
- if ( (HitActor != None) && HitActor.bProjTarget )
- {
- if ( bWarnTarget && HitActor.IsA('Pawn') )
- Pawn(HitActor).WarnTarget(self, projSpeed, FireDir);
- return ViewRotation;
- }
- bestAim = FMin(0.93, MyAutoAim);
- BestTarget = PickTarget(bestAim, bestDist, FireDir, projStart);
- if ( bWarnTarget && (Pawn(BestTarget) != None) )
- Pawn(BestTarget).WarnTarget(self, projSpeed, FireDir);
- if ( (Level.NetMode != NM_Standalone) || (Level.Game.Difficulty > 2)
- || bAlwaysMouseLook || ((BestTarget != None) && (bestAim < MyAutoAim)) || (MyAutoAim >= 1) )
- return ViewRotation;
- if ( BestTarget == None )
- {
- bestAim = MyAutoAim;
- BestTarget = PickAnyTarget(bestAim, bestDist, FireDir, projStart);
- if ( BestTarget == None )
- return ViewRotation;
- }
- AimSpot = projStart + FireDir * bestDist;
- AimSpot.Z = BestTarget.Location.Z + 0.3 * BestTarget.CollisionHeight;
- return rotator(AimSpot - projStart);
- }
- function Falling()
- {
- //SetPhysics(PHYS_Falling); //Note - physics changes type to PHYS_Falling by default
- //log(class$" Falling");
- PlayInAir();
- }
- function Landed(vector HitNormal)
- {
- //Note - physics changes type to PHYS_Walking by default for landed pawns
- PlayLanded(Velocity.Z);
- if (Velocity.Z < -1.4 * JumpZ)
- {
- MakeNoise(-0.5 * Velocity.Z/(FMax(JumpZ, 150.0)));
- ShakeView(0.175 - 0.00007 * Velocity.Z, -0.85 * Velocity.Z, -0.002 * Velocity.Z);
- if (Velocity.Z <= -1100)
- {
- if ( (Velocity.Z < -2000) && (ReducedDamageType != 'All') )
- TakeDamage(1000, None, Location, vect(0,0,0), 'fell');
- else if ( Role == ROLE_Authority )
- TakeDamage(-0.15 * (Velocity.Z + 1050), None, Location, vect(0,0,0), 'fell');
- }
- }
- else if ( (Level.Game != None) && (Level.Game.Difficulty > 1) && (Velocity.Z > 0.5 * JumpZ) )
- MakeNoise(0.1 * Level.Game.Difficulty);
- bJustLanded = true;
- }
- function Died(pawn Killer, name damageType, vector HitLocation)
- {
- //Assert( Role = ROLE_Authority );
- // encroach problem may cause this
- // so temp
- if (Role != ROLE_Authority)
- {
- log("Non-authority tried to die");
- return;
- }
- StopZoom();
- Super.Died(Killer, damageType, HitLocation);
- }
- function eAttitude AttitudeTo(Pawn Other)
- {
- if (Other.bIsPlayer)
- return AttitudeToPlayer;
- else
- return Other.AttitudeToPlayer;
- }
- function string KillMessage( name damageType, pawn Other )
- {
- return ( Level.Game.PlayerKillMessage(damageType, Other)$PlayerReplicationInfo.PlayerName );
- }
- //=============================================================================
- // Player Control
- function KilledBy( pawn EventInstigator )
- {
- Health = 0;
- Died( EventInstigator, 'suicided', Location );
- }
- // Player view.
- // Compute the rendering viewpoint for the player.
- //
- function CalcBehindView(out vector CameraLocation, out rotator CameraRotation, float Dist)
- {
- local vector View,HitLocation,HitNormal;
- local float ViewDist;
- CameraRotation = ViewRotation;
- View = vect(1,0,0) >> CameraRotation;
- if ( Trace( HitLocation, HitNormal, CameraLocation - (Dist + 30) * vector(CameraRotation), CameraLocation ) != None )
- ViewDist = FMin( (CameraLocation - HitLocation) Dot View, Dist );
- else
- ViewDist = Dist;
- CameraLocation -= (ViewDist - 30) * View;
- }
- event PlayerCalcView(out actor ViewActor, out vector CameraLocation, out rotator CameraRotation )
- {
- local Pawn PTarget;
- if ( ViewTarget != None )
- {
- ViewActor = ViewTarget;
- CameraLocation = ViewTarget.Location;
- CameraRotation = ViewTarget.Rotation;
- PTarget = Pawn(ViewTarget);
- if ( PTarget != None )
- {
- if ( Level.NetMode == NM_Client )
- {
- if ( PTarget.bIsPlayer )
- PTarget.ViewRotation = TargetViewRotation;
- PTarget.EyeHeight = TargetEyeHeight;
- if ( PTarget.Weapon != None )
- PTarget.Weapon.PlayerViewOffset = TargetWeaponViewOffset;
- }
- if ( PTarget.bIsPlayer )
- CameraRotation = PTarget.ViewRotation;
- if ( !bBehindView )
- CameraLocation.Z += PTarget.EyeHeight;
- else
- CameraLocation.Z += PTarget.PrePivot.Z - PTarget.default.PrePivot.Z;
- }
- if ( bBehindView )
- CalcBehindView(CameraLocation, CameraRotation, 180);
- return;
- }
- ViewActor = Self;
- CameraLocation = Location;
- if ( bBehindView ) //up and behind
- {
- CameraLocation.Z += PrePivot.Z - default.PrePivot.Z;
- CalcBehindView(CameraLocation, CameraRotation, 150);
- }
- else
- {
- // First-person view.
- CameraRotation = ViewRotation;
- CameraLocation.Z += EyeHeight;
- CameraLocation += WalkBob;
- }
- }
- exec function SetViewFlash(bool B)
- {
- bNoFlash = !B;
- }
- function ViewFlash(float DeltaTime)
- {
- local vector goalFog;
- local float goalscale, delta;
- if ( bNoFlash )
- {
- InstantFlash = 0;
- InstantFog = vect(0,0,0);
- }
- delta = FMin(0.1, DeltaTime);
- goalScale = 1 + DesiredFlashScale + ConstantGlowScale;
- goalFog = DesiredFlashFog + ConstantGlowFog;
- if ( CameraRegion.Zone!=None )
- {
- goalScale+=CameraRegion.Zone.ViewFlash.X;
- goalFog+=CameraRegion.Zone.ViewFog;
- }
- DesiredFlashScale -= DesiredFlashScale * 2 * delta;
- DesiredFlashFog -= DesiredFlashFog * 2 * delta;
- FlashScale.X += (goalScale - FlashScale.X + InstantFlash) * 10 * delta;
- //FlashFog += (goalFog - FlashFog + InstantFog) * 10 * delta;
- CurrentFlashFog += (goalFog - CurrentFlashFog + InstantFog) * 10 * delta;
- InstantFlash = 0;
- InstantFog = vect(0,0,0);
- if ( FlashScale.X > 0.981 )
- FlashScale.X = 1;
- FlashScale = FlashScale.X * vect(1,1,1);
- FlashFog = CurrentFlashFog;
- if ( FlashFog.X < 0.019 )
- FlashFog.X = 0;
- if ( FlashFog.Y < 0.019 )
- FlashFog.Y = 0;
- if ( FlashFog.Z < 0.019 )
- FlashFog.Z = 0;
- }
- function ViewShake(float DeltaTime)
- {
- if (shaketimer > 0.0) //shake view
- {
- Shaketimer=FClamp(Shaketimer,0.0,4.0); //4 seconds max
- shaketimer -= DeltaTime;
- if ( verttimer == 0 )
- {
- verttimer = 0.1;
- ShakeVert = -1.1 * maxshake;
- }
- else
- {
- verttimer -= DeltaTime;
- if ( verttimer < 0 )
- {
- verttimer = 0.2 * FRand();
- shakeVert = (2 * FRand() - 1) * maxshake;
- }
- }
- ViewRotation.Roll = ViewRotation.Roll & 65535;
- if (bShakeDir)
- {
- ViewRotation.Roll += Int( 10 * shakemag * FMin(0.1, DeltaTime));
- bShakeDir = (ViewRotation.Roll > 32768) || (ViewRotation.Roll < (0.5 + FRand()) * shakemag);
- if ( (ViewRotation.Roll < 32768) && (ViewRotation.Roll > 1.3 * shakemag) )
- {
- ViewRotation.Roll = 1.3 * shakemag;
- bShakeDir = false;
- }
- else if (FRand() < 3 * DeltaTime)
- bShakeDir = !bShakeDir;
- }
- else
- {
- ViewRotation.Roll -= Int( 10 * shakemag * FMin(0.1, DeltaTime));
- bShakeDir = (ViewRotation.Roll > 32768) && (ViewRotation.Roll < 65535 - (0.5 + FRand()) * shakemag);
- if ( (ViewRotation.Roll > 32768) && (ViewRotation.Roll < 65535 - 1.3 * shakemag) )
- {
- ViewRotation.Roll = 65535 - 1.3 * shakemag;
- bShakeDir = true;
- }
- else if (FRand() < 3 * DeltaTime)
- bShakeDir = !bShakeDir;
- }
- }
- else
- {
- ShakeVert = 0;
- ViewRotation.Roll = ViewRotation.Roll & 65535;
- if (ViewRotation.Roll < 32768)
- {
- if ( ViewRotation.Roll > 0 )
- ViewRotation.Roll = Max(0, ViewRotation.Roll - (Max(ViewRotation.Roll,500) * 10 * FMin(0.1,DeltaTime)));
- }
- else
- {
- ViewRotation.Roll += ((65536 - Max(500,ViewRotation.Roll)) * 10 * FMin(0.1,DeltaTime));
- if ( ViewRotation.Roll > 65534 )
- ViewRotation.Roll = 0;
- }
- }
- }
- function UpdateRotation(float DeltaTime, float maxPitch)
- {
- local rotator newRotation;
- DesiredRotation = ViewRotation; //save old rotation
- ViewRotation.Pitch += 32.0 * DeltaTime * aLookUp;
- ViewRotation.Pitch = ViewRotation.Pitch & 65535;
- If ((ViewRotation.Pitch > 18000) && (ViewRotation.Pitch < 49152))
- {
- If (aLookUp > 0)
- ViewRotation.Pitch = 18000;
- else
- ViewRotation.Pitch = 49152;
- }
- ViewRotation.Yaw += 32.0 * DeltaTime * aTurn;
- ViewShake(deltaTime);
- ViewFlash(deltaTime);
- newRotation = Rotation;
- newRotation.Yaw = ViewRotation.Yaw;
- newRotation.Pitch = ViewRotation.Pitch;
- If ( (newRotation.Pitch > maxPitch * RotationRate.Pitch) && (newRotation.Pitch < 65536 - maxPitch * RotationRate.Pitch) )
- {
- If (ViewRotation.Pitch < 32768)
- newRotation.Pitch = maxPitch * RotationRate.Pitch;
- else
- newRotation.Pitch = 65536 - maxPitch * RotationRate.Pitch;
- }
- UpdatePawnRotation(newRotation);
- }
- function SwimAnimUpdate(bool bNotForward)
- {
- if ( !bAnimTransition && (GetAnimGroup(AnimSequence) != 'Gesture') )
- {
- if ( bNotForward )
- {
- if ( GetAnimGroup(AnimSequence) != 'Waiting' )
- TweenToWaiting(0.1);
- }
- else if ( GetAnimGroup(AnimSequence) == 'Waiting' )
- TweenToSwimming(0.1);
- }
- }
- // Player movement.
- // Player Standing, walking, running, falling.
- state PlayerWalking
- {
- ignores SeePlayer, HearNoise, Bump;
- exec function FeignDeath()
- {
- if ( Physics == PHYS_Walking )
- {
- ServerFeignDeath();
- Acceleration = vect(0,0,0);
- GotoState('FeigningDeath');
- }
- }
- function ZoneChange( ZoneInfo NewZone )
- {
- if (NewZone.bWaterZone)
- {
- setPhysics(PHYS_Swimming);
- GotoState('PlayerSwimming');
- }
- }
- function AnimEnd()
- {
- local name MyAnimGroup;
- bAnimTransition = false;
- if ( Physics == PHYS_Spider )
- {
- if ( VSize(Velocity)<10 )
- PlayDuck();
- else PlayCrawling();
- }
- else if (Physics == PHYS_Walking)
- {
- if (bIsCrouching)
- {
- if ( !bIsTurning && ((Velocity.X * Velocity.X + Velocity.Y * Velocity.Y) < 1000) )
- PlayDuck();
- else
- PlayCrawling();
- }
- else
- {
- MyAnimGroup = GetAnimGroup(AnimSequence);
- if ((Velocity.X * Velocity.X + Velocity.Y * Velocity.Y) < 1000)
- {
- if ( MyAnimGroup == 'Waiting' )
- PlayWaiting();
- else
- {
- bAnimTransition = true;
- TweenToWaiting(0.2);
- }
- }
- else if (bIsWalking)
- {
- if ( (MyAnimGroup == 'Waiting') || (MyAnimGroup == 'Landing') || (MyAnimGroup == 'Gesture') || (MyAnimGroup == 'TakeHit') )
- {
- TweenToWalking(0.1);
- bAnimTransition = true;
- }
- else
- PlayWalking();
- }
- else
- {
- if ( (MyAnimGroup == 'Waiting') || (MyAnimGroup == 'Landing') || (MyAnimGroup == 'Gesture') || (MyAnimGroup == 'TakeHit') )
- {
- bAnimTransition = true;
- TweenToRunning(0.1);
- }
- else
- PlayRunning();
- }
- }
- }
- else if (bIsReducedCrouch)
- PlayDuck();
- else
- PlayInAir();
- }
- function Landed(vector HitNormal)
- {
- Global.Landed(HitNormal);
- if (DodgeDir == DODGE_Active)
- {
- DodgeDir = DODGE_Done;
- DodgeClickTimer = 0.0;
- Velocity *= 0.1;
- }
- else
- DodgeDir = DODGE_None;
- }
- function Dodge(eDodgeDir DodgeMove)
- {
- local vector X,Y,Z;
- if ( bIsCrouching || (Physics != PHYS_Walking) )
- return;
- GetAxes(Rotation,X,Y,Z);
- if (DodgeMove == DODGE_Forward)
- Velocity = 1.5*GroundSpeed*X + (Velocity Dot Y)*Y;
- else if (DodgeMove == DODGE_Back)
- Velocity = -1.5*GroundSpeed*X + (Velocity Dot Y)*Y;
- else if (DodgeMove == DODGE_Left)
- Velocity = 1.5*GroundSpeed*Y + (Velocity Dot X)*X;
- else if (DodgeMove == DODGE_Right)
- Velocity = -1.5*GroundSpeed*Y + (Velocity Dot X)*X;
- Velocity.Z = 160;
- if ( Role == ROLE_Authority )
- PlaySound(JumpSound, SLOT_Talk, 1.0, true, 800, 1.0 );
- PlayDodge(DodgeMove);
- DodgeDir = DODGE_Active;
- SetPhysics(PHYS_Falling);
- }
- function ProcessMove(float DeltaTime, vector NewAccel, eDodgeDir DodgeMove, rotator DeltaRot)
- {
- local vector OldAccel;
- OldAccel = Acceleration;
- Acceleration = NewAccel;
- bIsTurning = ( Abs(DeltaRot.Yaw/DeltaTime) > 5000 );
- if ( (DodgeMove == DODGE_Active) && (Physics == PHYS_Falling) )
- DodgeDir = DODGE_Active;
- else if ( (DodgeMove != DODGE_None) && (DodgeMove < DODGE_Active) )
- Dodge(DodgeMove);
- if ( bPressedJump )
- DoJump();
- if ( (Physics == PHYS_Walking) && (GetAnimGroup(AnimSequence) != 'Dodge') )
- {
- if ( !bIsCrouching )
- {
- if ( bDuck != 0 && TryToDuck(true) && IsInState('PlayerWalking') ) // Note: TryToDuck may change the state (e.g. to PlayerSwimming)
- {
- bIsCrouching = true;
- PlayDuck();
- }
- }
- else if ( bDuck == 0 && TryToDuck(false) )
- {
- OldAccel = vect(0,0,0);
- bIsCrouching = false;
- }
- if ( !bIsCrouching )
- {
- if ( (!bAnimTransition || (AnimFrame > 0)) && (GetAnimGroup(AnimSequence) != 'Landing') )
- {
- if ( Acceleration != vect(0,0,0) )
- {
- if ( (GetAnimGroup(AnimSequence) == 'Waiting') || (GetAnimGroup(AnimSequence) == 'Gesture') || (GetAnimGroup(AnimSequence) == 'TakeHit') )
- {
- bAnimTransition = true;
- TweenToRunning(0.1);
- }
- }
- else if ( (Velocity.X * Velocity.X + Velocity.Y * Velocity.Y < 1000)
- && (GetAnimGroup(AnimSequence) != 'Gesture') )
- {
- if ( GetAnimGroup(AnimSequence) == 'Waiting' )
- {
- if ( bIsTurning && (AnimFrame >= 0) )
- {
- bAnimTransition = true;
- PlayTurning();
- }
- }
- else if ( !bIsTurning )
- {
- bAnimTransition = true;
- TweenToWaiting(0.2);
- }
- }
- }
- }
- else
- {
- if ( (OldAccel == vect(0,0,0)) && (Acceleration != vect(0,0,0)) )
- PlayCrawling();
- else if ( !bIsTurning && (Acceleration == vect(0,0,0)) && (AnimFrame > 0.1) )
- PlayDuck();
- }
- }
- }
- event PlayerTick( float DeltaTime )
- {
- if ( bUpdatePosition )
- ClientUpdatePosition();
- PlayerMove(DeltaTime);
- }
- function PlayerMove( float DeltaTime )
- {
- local vector X,Y,Z, NewAccel;
- local EDodgeDir OldDodge;
- local eDodgeDir DodgeMove;
- local rotator OldRotation;
- local float Speed2D;
- local bool bSaveJump;
- local name AnimGroupName;
- if ( Physics==PHYS_Spider )
- GetAxes(ViewRotation,X,Y,Z);
- else GetAxes(Rotation,X,Y,Z);
- aForward *= 0.4;
- aStrafe *= 0.4;
- aLookup *= 0.24;
- aTurn *= 0.24;
- // Update acceleration.
- NewAccel = aForward*X + aStrafe*Y;
- if ( Physics!=PHYS_Spider )
- NewAccel.Z = 0;
- // Check for Dodge move
- if ( DodgeDir == DODGE_Active )
- DodgeMove = DODGE_Active;
- else DodgeMove = DODGE_None;
- if (DodgeClickTime > 0.0)
- {
- if ( DodgeDir < DODGE_Active )
- {
- OldDodge = DodgeDir;
- DodgeDir = DODGE_None;
- if (bEdgeForward && bWasForward)
- DodgeDir = DODGE_Forward;
- if (bEdgeBack && bWasBack)
- DodgeDir = DODGE_Back;
- if (bEdgeLeft && bWasLeft)
- DodgeDir = DODGE_Left;
- if (bEdgeRight && bWasRight)
- DodgeDir = DODGE_Right;
- if ( DodgeDir == DODGE_None)
- DodgeDir = OldDodge;
- else if ( DodgeDir != OldDodge )
- DodgeClickTimer = DodgeClickTime + 0.5 * DeltaTime;
- else
- DodgeMove = DodgeDir;
- }
- if (DodgeDir == DODGE_Done)
- {
- DodgeClickTimer -= DeltaTime;
- if (DodgeClickTimer < -0.35)
- {
- DodgeDir = DODGE_None;
- DodgeClickTimer = DodgeClickTime;
- }
- }
- else if ((DodgeDir != DODGE_None) && (DodgeDir != DODGE_Active))
- {
- DodgeClickTimer -= DeltaTime;
- if (DodgeClickTimer < 0)
- {
- DodgeDir = DODGE_None;
- DodgeClickTimer = DodgeClickTime;
- }
- }
- }
- AnimGroupName = GetAnimGroup(AnimSequence);
- if ( (Physics == PHYS_Walking) && (AnimGroupName != 'Dodge') )
- {
- //if walking, look up/down stairs - unless player is rotating view
- if ( !bKeyboardLook && (bLook == 0) )
- {
- if ( bLookUpStairs )
- ViewRotation.Pitch = FindStairRotation(deltaTime);
- else if ( bCenterView )
- {
- ViewRotation.Pitch = ViewRotation.Pitch & 65535;
- if (ViewRotation.Pitch > 32768)
- ViewRotation.Pitch -= 65536;
- ViewRotation.Pitch = ViewRotation.Pitch * (1 - 12 * FMin(0.0833, deltaTime));
- if ( Abs(ViewRotation.Pitch) < 1000 )
- ViewRotation.Pitch = 0;
- }
- }
- Speed2D = Sqrt(Velocity.X * Velocity.X + Velocity.Y * Velocity.Y);
- //add bobbing when walking
- if ( !bShowMenu )
- {
- if ( Speed2D < 10 || GroundSpeed == 0 )
- BobTime += 0.2 * DeltaTime * FClamp(Region.Zone.ZoneTimeDilation,0.1,10.f);
- else
- BobTime += DeltaTime * FClamp(Region.Zone.ZoneTimeDilation,0.1,10.f) * (0.3 + 0.7 * Speed2D/GroundSpeed);
- WalkBob = Y * 0.65 * Bob * Speed2D * sin(6.0 * BobTime);
- if ( Speed2D < 10 )
- WalkBob.Z = Bob * 30 * sin(12 * BobTime);
- else WalkBob.Z = Bob * Speed2D * sin(12 * BobTime);
- }
- }
- else if ( !bShowMenu )
- {
- BobTime = 0;
- WalkBob = WalkBob * (1 - FMin(1, 8 * deltatime));
- }
- // Update rotation.
- OldRotation = Rotation;
- UpdateRotation(DeltaTime, 1);
- if ( bPressedJump && (AnimGroupName == 'Dodge') )
- {
- bSaveJump = true;
- bPressedJump = false;
- }
- else
- bSaveJump = false;
- if ( Role < ROLE_Authority ) // then save this move and replicate it
- ReplicateMove(DeltaTime, NewAccel, DodgeMove, OldRotation - Rotation);
- else
- ProcessMove(DeltaTime, NewAccel, DodgeMove, OldRotation - Rotation);
- bPressedJump = bSaveJump;
- }
- function BeginState()
- {
- WalkBob = vect(0,0,0);
- DodgeDir = DODGE_None;
- bIsCrouching = bIsReducedCrouch;
- bIsTurning = false;
- bPressedJump = false;
- if (Physics != PHYS_Falling)
- SetPhysics(PHYS_Walking);
- if ( !IsAnimating() )
- {
- if (bIsCrouching)
- PlayDuck();
- else
- PlayWaiting();
- }
- }
- function EndState()
- {
- WalkBob = vect(0,0,0);
- bIsCrouching = false;
- }
- }
- state FeigningDeath
- {
- ignores SeePlayer, HearNoise, Bump, Fire, AltFire, StartClimbing;
- function ZoneChange( ZoneInfo NewZone )
- {
- if (NewZone.bWaterZone)
- {
- setPhysics(PHYS_Swimming);
- GotoState('PlayerSwimming');
- }
- }
- function PlayChatting()
- {
- }
- exec function Taunt( name Sequence )
- {
- }
- function AnimEnd()
- {
- if ( (Role == ROLE_Authority) && (Health > 0) )
- {
- GotoState('PlayerWalking');
- ChangedWeapon();
- }
- }
- function Landed(vector HitNormal)
- {
- if ( Role == ROLE_Authority )
- PlaySound(Land, SLOT_Interact, 0.3, false, 800, 1.0);
- if (Velocity.Z < -1.4 * JumpZ)
- {
- MakeNoise(-0.5 * Velocity.Z/(FMax(JumpZ, 150.0)));
- if (Velocity.Z <= -1100)
- {
- if ( (Velocity.Z < -2000) && (ReducedDamageType != 'All') )
- TakeDamage(1000, None, Location, vect(0,0,0), 'fell');
- else if ( Role == ROLE_Authority )
- TakeDamage(-0.15 * (Velocity.Z + 1050), Self, Location, vect(0,0,0), 'fell');
- }
- }
- else if ( (Level.Game != None) && (Level.Game.Difficulty > 1) && (Velocity.Z > 0.5 * JumpZ) )
- MakeNoise(0.1 * Level.Game.Difficulty);
- bJustLanded = true;
- }
- function Rise()
- {
- if ( !bRising )
- {
- Enable('AnimEnd');
- bRising = true;
- if (TryToDuck(false))
- {
- BaseEyeHeight = default.BaseEyeHeight;
- PlayRising();
- }
- else
- {
- PlayDuck();
- BaseEyeHeight = default.BaseEyeHeight + CollisionHeight - default.CollisionHeight;
- }
- }
- }
- function ProcessMove(float DeltaTime, vector NewAccel, eDodgeDir DodgeMove, rotator DeltaRot)
- {
- if ( bPressedJump || (NewAccel.Z > 0) )
- Rise();
- Acceleration = vect(0,0,0);
- }
- event PlayerTick( float DeltaTime )
- {
- if ( bUpdatePosition )
- ClientUpdatePosition();
- PlayerMove(DeltaTime);
- }
- function ServerMove
- (
- float TimeStamp,
- vector Accel,
- vector ClientLoc,
- bool NewbRun,
- bool NewbDuck,
- bool NewbPressedJump,
- bool bFired,
- bool bAltFired,
- eDodgeDir DodgeMove,
- byte ClientRoll,
- int View
- )
- {
- Global.ServerMove(TimeStamp, Accel, ClientLoc, NewbRun, NewbDuck, NewbPressedJump,
- bFired, bAltFired, DodgeMove, ClientRoll, (32767 & (Rotation.Pitch/2)) * 32768 + (32767 & (Rotation.Yaw/2)));
- }
- function PlayerMove( float DeltaTime)
- {
- local rotator currentRot;
- local vector NewAccel;
- aLookup *= 0.24;
- aTurn *= 0.24;
- // Update acceleration.
- if ( !IsAnimating() && (aForward != 0) || (aStrafe != 0) )
- NewAccel = vect(0,0,1);
- else
- NewAccel = vect(0,0,0);
- // Update view rotation.
- currentRot = Rotation;
- UpdateRotation(DeltaTime, 1);
- SetRotation(currentRot);
- if ( Role < ROLE_Authority ) // then save this move and replicate it
- ReplicateMove(DeltaTime, NewAccel, DODGE_None, Rot(0,0,0));
- else
- ProcessMove(DeltaTime, NewAccel, DODGE_None, Rot(0,0,0));
- bPressedJump = false;
- }
- function PlayTakeHit(float tweentime, vector HitLoc, int Damage)
- {
- if ( IsAnimating() )
- {
- Enable('AnimEnd');
- Global.PlayTakeHit(tweentime, HitLoc, Damage);
- }
- }
- function PlayDying(name DamageType, vector HitLocation)
- {
- BaseEyeHeight = Default.BaseEyeHeight;
- }
- function ChangedWeapon()
- {
- Inventory.ChangedWeapon();
- Weapon = None;
- }
- simulated function bool ShouldHaveReducedHeight()
- {
- return !bRising;
- }
- function EndState()
- {
- PlayerReplicationInfo.bFeigningDeath = false;
- }
- function BeginState()
- {
- local rotator NewRot;
- if ( carriedDecoration != None )
- DropDecoration();
- NewRot = Rotation;
- NewRot.Pitch = 0;
- SetRotation(NewRot);
- BaseEyeHeight = -0.5 * CollisionHeight;
- bIsCrouching = false;
- bPressedJump = false;
- bRising = false;
- Disable('AnimEnd');
- PlayFeignDeath();
- PlayerReplicationInfo.bFeigningDeath = true;
- TryToDuck(true);
- }
- }
- // Player movement.
- // Player Swimming
- state PlayerSwimming
- {
- ignores SeePlayer, HearNoise, Bump;
- event UpdateEyeHeight(float DeltaTime)
- {
- local float smooth, bound;
- // smooth up/down stairs
- if ( !bJustLanded )
- {
- smooth = FMin(1.0, 10.0 * DeltaTime/Level.TimeDilation);
- EyeHeight = (EyeHeight - Location.Z + OldLocation.Z) * (1 - smooth) + ( ShakeVert + BaseEyeHeight) * smooth;
- bound = -0.5 * CollisionHeight;
- if (EyeHeight < bound)
- EyeHeight = bound;
- else
- {
- bound = CollisionHeight + FClamp((OldLocation.Z - Location.Z), 0.0, MaxStepHeight);
- if (bIsReducedCrouch)
- bound += default.CollisionHeight - CollisionHeight;
- if ( EyeHeight > bound )
- EyeHeight = bound;
- }
- }
- else
- {
- smooth = FClamp(10.0 * DeltaTime/Level.TimeDilation, 0.35, 1.0);
- bJustLanded = false;
- EyeHeight = EyeHeight * ( 1 - smooth) + (BaseEyeHeight + ShakeVert) * smooth;
- }
- // teleporters affect your FOV, so adjust it back down
- if ( FOVAngle != DesiredFOV )
- {
- if ( FOVAngle > DesiredFOV )
- FOVAngle = FOVAngle - FMax(7, 0.9 * DeltaTime * (FOVAngle - DesiredFOV));
- else
- FOVAngle = FOVAngle - FMin(-7, 0.9 * DeltaTime * (FOVAngle - DesiredFOV));
- if ( Abs(FOVAngle - DesiredFOV) <= 10 )
- FOVAngle = DesiredFOV;
- }
- // adjust FOV for weapon zooming
- if ( bZooming )
- {
- ZoomLevel += DeltaTime * 1.0;
- if (ZoomLevel > 0.9)
- ZoomLevel = 0.9;
- DesiredFOV = FClamp(90.0 - (ZoomLevel * 88.0), 1, 170);
- }
- }
- function Landed(vector HitNormal)
- {
- //log(class$" Landed while swimming");
- PlayLanded(Velocity.Z);
- if (Velocity.Z < -1.2 * JumpZ)
- {
- MakeNoise(-0.5 * Velocity.Z/(FMax(JumpZ, 150.0)));
- if (Velocity.Z <= -1100)
- {
- if ( (Velocity.Z < -2000) && (ReducedDamageType != 'All') )
- TakeDamage(1000, None, Location, vect(0,0,0), 'fell');
- else if ( Role == ROLE_Authority )
- TakeDamage(-0.1 * (Velocity.Z + 1050), Self, Location, vect(0,0,0), 'fell');
- }
- }
- else if ( (Level.Game != None) && (Level.Game.Difficulty > 1) && (Velocity.Z > 0.5 * JumpZ) )
- MakeNoise(0.1 * Level.Game.Difficulty);
- bJustLanded = true;
- if ( Region.Zone.bWaterZone )
- SetPhysics(PHYS_Swimming);
- else
- {
- GotoState('PlayerWalking');
- AnimEnd();
- }
- }
- function AnimEnd()
- {
- local vector X,Y,Z;
- GetAxes(Rotation, X,Y,Z);
- if ( (Acceleration Dot X) <= 0 )
- {
- if ( GetAnimGroup(AnimSequence) == 'TakeHit' )
- {
- bAnimTransition = true;
- TweenToWaiting(0.2);
- }
- else
- PlayWaiting();
- }
- else
- {
- if ( GetAnimGroup(AnimSequence) == 'TakeHit' )
- {
- bAnimTransition = true;
- TweenToSwimming(0.2);
- }
- else
- PlaySwimming();
- }
- }
- function ZoneChange( ZoneInfo NewZone )
- {
- local actor HitActor;
- local vector HitLocation, HitNormal, checkpoint;
- if (!NewZone.bWaterZone)
- {
- SetPhysics(PHYS_Falling);
- if (bUpAndOut && CheckWaterJump(HitNormal)) //check for waterjump
- {
- velocity.Z = 330 + 2 * CollisionRadius; //set here so physics uses this for remainder of tick
- PlayDuck();
- GotoState('PlayerWalking');
- }
- else if (!FootRegion.Zone.bWaterZone || (Velocity.Z > 160) )
- {
- GotoState('PlayerWalking');
- AnimEnd();
- }
- else //check if in deep water
- {
- checkpoint = Location;
- checkpoint.Z -= (CollisionHeight + 6.0);
- HitActor = Trace(HitLocation, HitNormal, checkpoint, Location, false);
- if (HitActor != None)
- {
- GotoState('PlayerWalking');
- AnimEnd();
- }
- else
- {
- Enable('Timer');
- SetTimer(0.7,false);
- }
- }
- //log("Out of water");
- }
- else
- {
- Disable('Timer');
- SetPhysics(PHYS_Swimming);
- }
- }
- function ProcessMove(float DeltaTime, vector NewAccel, eDodgeDir DodgeMove, rotator DeltaRot)
- {
- local vector X,Y,Z, Temp;
- GetAxes(ViewRotation,X,Y,Z);
- Acceleration = NewAccel;
- SwimAnimUpdate( (X Dot Acceleration) <= 0 );
- bUpAndOut = ((X Dot Acceleration) > 0) && ((Acceleration.Z > 0) || (ViewRotation.Pitch > 2048));
- if ( bUpAndOut && !Region.Zone.bWaterZone && CheckWaterJump(Temp) ) //check for waterjump
- {
- velocity.Z = 330 + 2 * CollisionRadius; //set here so physics uses this for remainder of tick
- PlayDuck();
- GotoState('PlayerWalking');
- }
- }
- event PlayerTick( float DeltaTime )
- {
- if ( bUpdatePosition )
- ClientUpdatePosition();
- PlayerMove(DeltaTime);
- }
- function PlayerMove(float DeltaTime)
- {
- local rotator oldRotation;
- local vector X,Y,Z, NewAccel;
- local float Speed2D;
- GetAxes(ViewRotation,X,Y,Z);
- aForward *= 0.2;
- aStrafe *= 0.1;
- aLookup *= 0.24;
- aTurn *= 0.24;
- aUp *= 0.1;
- NewAccel = aForward*X + aStrafe*Y + aUp*vect(0,0,1);
- //add bobbing when swimming
- if ( !bShowMenu )
- {
- Speed2D = Sqrt(Velocity.X * Velocity.X + Velocity.Y * Velocity.Y);
- WalkBob = Y * Bob * 0.5 * Speed2D * sin(4.0 * Level.TimeSeconds);
- WalkBob.Z = Bob * 1.5 * Speed2D * sin(8.0 * Level.TimeSeconds);
- }
- // Update rotation.
- oldRotation = Rotation;
- UpdateRotation(DeltaTime, 2);
- if ( Role < ROLE_Authority ) // then save this move and replicate it
- ReplicateMove(DeltaTime, NewAccel, DODGE_None, OldRotation - Rotation);
- else
- ProcessMove(DeltaTime, NewAccel, DODGE_None, OldRotation - Rotation);
- bPressedJump = false;
- }
- function Timer()
- {
- if ( !Region.Zone.bWaterZone && (Role == ROLE_Authority) )
- {
- //log("timer out of water");
- GotoState('PlayerWalking');
- AnimEnd();
- }
- Disable('Timer');
- }
- function BeginState()
- {
- Disable('Timer');
- if (!IsAnimating())
- TweenToWaiting(0.3);
- else if (bIsReducedCrouch)
- TweenToSwimming(0.2);
- //log("player swimming");
- }
- }
- state PlayerInterpolate
- {
- Ignores AnimEnd,FellOutOfWorld;
- function BeginState()
- {
- WalkBob = vect(0,0,0);
- LastUpdateTime = -1;
- TweenToWalking(0.1f);
- }
- function EndState()
- {
- Target = None;
- if( Physics==PHYS_Interpolating )
- SetPhysics(PHYS_Falling);
- bInterpolating = false;
- }
- // Basicly do nothing.
- event PlayerTick( float DeltaTime )
- {
- if ( bUpdatePosition )
- ClientUpdatePosition();
- PlayerMove(DeltaTime);
- }
- function PlayerMove( float DeltaTime )
- {
- bPressedJump = false;
- if ( Role < ROLE_Authority )
- ReplicateMoveIP(DeltaTime);
- }
- function ProcessMove(float DeltaTime, vector NewAccel, eDodgeDir DodgeMove, rotator DeltaRot)
- {
- }
- final function ReplicateMoveIP( float DeltaTime )
- {
- local SavedMove NewMove;
- // if am network client and am carrying flag -
- // make its position look good client side
- if ( (PlayerReplicationInfo != None) && (PlayerReplicationInfo.HasFlag != None) )
- PlayerReplicationInfo.HasFlag.FollowHolder(self);
- // Get a SavedMove actor to store the movement in.
- if ( SavedMoves == None )
- {
- SavedMoves = GetFreeMove();
- NewMove = SavedMoves;
- }
- else
- {
- NewMove = SavedMoves;
- while ( NewMove.NextMove != None )
- NewMove = NewMove.NextMove;
- if ( NewMove.bSent )
- {
- NewMove.NextMove = GetFreeMove();
- NewMove = NewMove.NextMove;
- }
- }
- NewMove.Delta = DeltaTime;
- NewMove.Acceleration = vect(0,0,0);
- // Set this move's data.
- NewMove.DodgeMove = DODGE_None;
- NewMove.TimeStamp = Level.TimeSeconds;
- NewMove.bRun = false;
- NewMove.bDuck = false;
- NewMove.bPressedJump = false;
- // Simulate the movement locally.
- AutonomousPhysics(DeltaTime);
- // Send to the server
- NewMove.bSent = true;
- ServerMove(Level.TimeSeconds,vect(0,0,0),Location,false,false,false,(bJustFired || (bFire != 0)),(bJustAltFired || (bAltFire != 0)),DODGE_None,0,0);
- bJustFired = false;
- bJustAltFired = false;
- }
- function ServerMove( float TimeStamp, vector InAccel, vector ClientLoc, bool NewbRun, bool NewbDuck, bool NewbPressedJump,
- bool bFired, bool bAltFired, eDodgeDir DodgeMove, byte ClientRoll, int View )
- {
- local float DeltaTime;
- // If this move is outdated, discard it.
- if ( CurrentTimeStamp >= TimeStamp )
- return;
- // handle firing and alt-firing
- if ( bFired )
- {
- if ( bFire == 0 )
- {
- Fire(0);
- bFire = 1;
- }
- }
- else
- bFire = 0;
- if ( bAltFired )
- {
- if ( bAltFire == 0 )
- {
- AltFire(0);
- bAltFire = 1;
- }
- }
- else
- bAltFire = 0;
- // Save move parameters.
- DeltaTime = TimeStamp - CurrentTimeStamp;
- if ( ServerTimeStamp > 0 )
- {
- TimeMargin += DeltaTime - 1.01 * (Level.TimeSeconds - ServerTimeStamp);
- if ( TimeMargin > MaxTimeMargin )
- {
- // player is too far ahead
- TimeMargin -= DeltaTime;
- if ( TimeMargin < 0.5 )
- MaxTimeMargin = 1.0;
- else
- MaxTimeMargin = 0.5;
- DeltaTime = 0;
- }
- else if ( TimeMargin < -MaxTimeMargin ) // player is too far behind.
- TimeMargin = -MaxTimeMargin;
- }
- CurrentTimeStamp = TimeStamp;
- ServerTimeStamp = Level.TimeSeconds;
- // Perform actual movement.
- if ( Len(Level.Pauser)==0 && (DeltaTime > 0) )
- AutonomousPhysics(DeltaTime);
- if ( (Level.TimeSeconds-LastUpdateTime)>0.25 )
- {
- LastUpdateTime = Level.TimeSeconds;
- ClientAdjustPosition(TimeStamp,GetStateName(),PHYS_None,PhysRate,PhysAlpha,0,0,0,0,Target);
- }
- }
- function ClientAdjustPosition
- (
- float TimeStamp,
- name newState,
- EPhysics newPhysics,
- float NewLocX, // PhysRate
- float NewLocY, // PhysAlpha
- float NewLocZ,
- float NewVelX,
- float NewVelY,
- float NewVelZ,
- Actor NewBase // Interpolate target
- )
- {
- if ( CurrentTimeStamp > TimeStamp )
- return;
- CurrentTimeStamp = TimeStamp;
- if ( !IsInState(newState) )
- {
- GotoState(newState); // Client ended interpolating, go to new state.
- return;
- }
- if( NewBase!=None )
- {
- Target = NewBase;
- PhysRate = NewLocX;
- PhysAlpha = NewLocY;
- if( Physics!=PHYS_Interpolating )
- SetPhysics(PHYS_Interpolating);
- bInterpolating = true;
- }
- bUpdatePosition = true;
- }
- function ClientUpdatePosition() // Do nothing more than let time flow by.
- {
- local SavedMove CurrentMove;
- bUpdatePosition = false;
- CurrentMove = SavedMoves;
- while ( CurrentMove != None )
- {
- if ( CurrentMove.TimeStamp <= CurrentTimeStamp )
- {
- SavedMoves = CurrentMove.NextMove;
- CurrentMove.NextMove = FreeMoves;
- FreeMoves = CurrentMove;
- FreeMoves.Clear();
- CurrentMove = SavedMoves;
- }
- else
- {
- AutonomousPhysics(CurrentMove.Delta);
- CurrentMove = CurrentMove.NextMove;
- }
- }
- }
- }
- state PlayerInterpolateNI extends PlayerInterpolate
- {
- Ignores ActivateInventoryItem,NextWeapon,PrevWeapon,ActivateItem,PrevItem,NextItem,Fire,AltFire,TakeDamage,Died,ZoneChange,FootZoneChange,HeadZoneChange,AnimEnd,FellOutOfWorld,KilledBy;
- function ChangedWeapon()
- {
- Weapon = None;
- }
- simulated function RenderOverlays( canvas Canvas )
- {
- if ( myHUD != None )
- myHUD.RenderOverlays(Canvas);
- }
- function BeginState()
- {
- Super.BeginState();
- if( Level.NetMode!=NM_Client && Level.NetMode!=NM_StandAlone )
- bHidden = true;
- }
- function EndState()
- {
- Super.EndState();
- if( Level.NetMode!=NM_Client && Health>0 )
- {
- bHidden = false;
- if( Weapon==None && PendingWeapon!=None )
- Global.ChangedWeapon();
- }
- }
- function PlayerMove( float DeltaTime )
- {
- bFire = 0;
- bAltFire = 0;
- Super.PlayerMove(DeltaTime);
- }
- }
- // 227g real crouching mode implemention:
- simulated final function SetCrouch(bool bCrouching)
- {
- local float NewCollisionHeight, VerticalOffset, MoveDistance;
- local bool bOldBlockActors, bOldBlockPlayers, bOldCollideWorld;
- if (bIsReducedCrouch == bCrouching || CrouchCheckTime == Level.TimeSeconds)
- return; // No-op.
- CrouchCheckTime = Level.TimeSeconds; // Avoid any possible runaway loops.
- bIsReducedCrouch = bCrouching;
- class'RealCrouchController'.static.GetRealCrouchController(self);
- if (bCrouching)
- {
- // Update collision size, prepivot height and location.
- NewCollisionHeight = default.CollisionHeight * CrouchHeightPct;
- MoveDistance = CollisionHeight - NewCollisionHeight;
- if (MoveDistance <= 0)
- return;
- VerticalOffset = default.CollisionHeight - NewCollisionHeight;
- SetCollisionSize(CollisionRadius, NewCollisionHeight);
- PrePivot.Z = default.PrePivot.Z + VerticalOffset;
- EyeHeight += MoveDistance;
- Move(vect(0, 0, -1) * MoveDistance);
- }
- else
- {
- // Reset collision size, prepivot height and location.
- NewCollisionHeight = default.CollisionHeight;
- MoveDistance = NewCollisionHeight - CollisionHeight;
- // Use the cached result when indirectly calling from TryToDuck or a newly calculated result otherwise
- if (MoveDistance <= 0 || !class'RealCrouchController'.static.CanStandUp(self, NewCollisionHeight))
- return;
- PrePivot.Z = default.PrePivot.Z;
- EyeHeight -= MoveDistance;
- bOldBlockActors = bBlockActors;
- bOldBlockPlayers = bBlockPlayers;
- bOldCollideWorld = bCollideWorld;
- SetCollision(bCollideActors, false, false);
- bCollideWorld = false;
- SetCollisionSize(CollisionRadius, NewCollisionHeight);
- Move(vect(0, 0, 1) * MoveDistance);
- SetLocation(Location);
- if (CarriedDecoration != none)
- {
- CarriedDecoration.SetPhysics(PHYS_None);
- CarriedDecoration.SetBase(self);
- }
- SetCollision(bCollideActors, bOldBlockActors, bOldBlockPlayers);
- bCollideWorld = bOldCollideWorld;
- }
- }
- simulated final function bool TryToDuck(bool bCrouching)
- {
- if (!Level.bSupportsRealCrouching || bIsReducedCrouch == bCrouching)
- return true;
- if (bCrouching)
- {
- SetCrouch(true);
- return true;
- }
- // Make sure there is space to stand up
- if (!class'RealCrouchController'.static.CanStandUp(self, default.CollisionHeight))
- return false; // Not enough space to uncrouch
- SetCrouch(false);
- return true;
- }
- simulated function bool ShouldHaveReducedHeight()
- {
- return bIsCrouching || bIsReducedCrouch && bDuck != 0;
- }
- simulated function bool IsHeadShot(vector HitLocation, vector TraceDir)
- {
- return !bIsReducedCrouch && super.IsHeadShot(HitLocation, TraceDir);
- }
- state PlayerFlying
- {
- ignores SeePlayer, HearNoise, Bump, StartClimbing;
- function AnimEnd()
- {
- PlaySwimming();
- }
- event PlayerTick( float DeltaTime )
- {
- if ( bUpdatePosition )
- ClientUpdatePosition();
- PlayerMove(DeltaTime);
- }
- function PlayerMove(float DeltaTime)
- {
- local vector X,Y,Z;
- GetAxes(ViewRotation,X,Y,Z);
- aForward *= 0.2;
- aStrafe *= 0.2;
- aLookup *= 0.24;
- aTurn *= 0.24;
- Acceleration = aForward*X + aStrafe*Y + aUp*Z;
- if ( bPressedJump && aUp<=0.01 )
- bPressedJump = False;
- // Update rotation.
- UpdateRotation(DeltaTime, 2);
- if ( Role < ROLE_Authority ) // then save this move and replicate it
- ReplicateMove(DeltaTime, Acceleration, DODGE_None, rot(0,0,0));
- else
- ProcessMove(DeltaTime, Acceleration, DODGE_None, rot(0,0,0));
- }
- function BeginState()
- {
- SetPhysics(PHYS_Flying);
- if ( !IsAnimating() ) PlaySwimming();
- //log("player flying");
- }
- }
- state CheatFlying
- {
- ignores SeePlayer, HearNoise, Bump, TakeDamage, StartClimbing;
- function AnimEnd()
- {
- PlaySwimming();
- }
- function ProcessMove(float DeltaTime, vector NewAccel, eDodgeDir DodgeMove, rotator DeltaRot)
- {
- if ( VSize(NewAccel)<0.1 )
- Acceleration = vect(0,0,0);
- else Acceleration = Normal(NewAccel) * 550;
- MoveSmooth(Acceleration * DeltaTime);
- Velocity = Acceleration; // Fix for ghosting/flying players from falling down for other clients.
- }
- event PlayerTick( float DeltaTime )
- {
- if ( bUpdatePosition )
- ClientUpdatePosition();
- PlayerMove(DeltaTime);
- }
- function PlayerMove(float DeltaTime)
- {
- local vector X,Y,Z;
- GetAxes(ViewRotation,X,Y,Z);
- aForward *= 0.1;
- aStrafe *= 0.1;
- aLookup *= 0.24;
- aTurn *= 0.24;
- aUp *= 0.1;
- Acceleration = aForward*X + aStrafe*Y + aUp*vect(0,0,1);
- UpdateRotation(DeltaTime, 1);
- if ( Role < ROLE_Authority ) // then save this move and replicate it
- ReplicateMove(DeltaTime, Acceleration, DODGE_None, rot(0,0,0));
- else
- ProcessMove(DeltaTime, Acceleration, DODGE_None, rot(0,0,0));
- }
- function BeginState()
- {
- EyeHeight = BaseEyeHeight;
- SetPhysics(PHYS_None);
- if( Base!=None )
- SetBase(Level);
- if( !IsAnimating() )
- PlaySwimming();
- bCanFly = True;
- }
- function EndState()
- {
- bCanFly = False;
- }
- }
- state PlayerWaiting
- {
- ignores SeePlayer, HearNoise, Bump, TakeDamage, Died, StartClimbing;
- exec function Jump( optional float F )
- {
- }
- exec function Suicide()
- {
- }
- function ChangeTeam( int N )
- {
- Level.Game.ChangeTeam(self, N);
- }
- exec function Fire(optional float F)
- {
- bReadyToPlay = !bReadyToPlay;
- }
- exec function AltFire(optional float F)
- {
- bReadyToPlay = !bReadyToPlay;
- }
- function ProcessMove(float DeltaTime, vector NewAccel, eDodgeDir DodgeMove, rotator DeltaRot)
- {
- Acceleration = NewAccel;
- MoveSmooth(Acceleration * DeltaTime);
- }
- event PlayerTick( float DeltaTime )
- {
- if ( bUpdatePosition )
- ClientUpdatePosition();
- PlayerMove(DeltaTime);
- }
- function PlayerMove(float DeltaTime)
- {
- local vector X,Y,Z;
- GetAxes(ViewRotation,X,Y,Z);
- aForward *= 0.1;
- aStrafe *= 0.1;
- aLookup *= 0.24;
- aTurn *= 0.24;
- aUp *= 0.1;
- Acceleration = aForward*X + aStrafe*Y + aUp*vect(0,0,1);
- UpdateRotation(DeltaTime, 1);
- if ( Role < ROLE_Authority ) // then save this move and replicate it
- ReplicateMove(DeltaTime, Acceleration, DODGE_None, rot(0,0,0));
- else
- ProcessMove(DeltaTime, Acceleration, DODGE_None, rot(0,0,0));
- }
- function EndState()
- {
- Mesh = Default.Mesh;
- PlayerReplicationInfo.bIsSpectator = false;
- SetCollision(true,true,true);
- }
- function BeginState()
- {
- Mesh = None;
- PlayerReplicationInfo.bIsSpectator = true;
- SetCollision(false,false,false);
- EyeHeight = BaseEyeHeight;
- SetPhysics(PHYS_None);
- }
- }
- state PlayerSpectating
- {
- ignores SeePlayer, HearNoise, Bump, TakeDamage, Died, StartClimbing;
- exec function Suicide()
- {
- }
- function SendVoiceMessage(PlayerReplicationInfo Sender, PlayerReplicationInfo Recipient, name messagetype, byte messageID, name broadcasttype)
- {
- }
- exec function AltFire( optional float F )
- {
- if ( Role == ROLE_Authority )
- {
- bBehindView = false;
- Viewtarget = None;
- ClientMessage("Now viewing from own camera", 'Event', true);
- }
- }
- function ChangeTeam( int N )
- {
- Level.Game.ChangeTeam(self, N);
- }
- exec function Fire( optional float F )
- {
- if ( Role == ROLE_Authority )
- {
- ViewPlayerNum(-1);
- bBehindView = true;
- }
- }
- function ProcessMove(float DeltaTime, vector NewAccel, eDodgeDir DodgeMove, rotator DeltaRot)
- {
- Acceleration = NewAccel;
- MoveSmooth(Acceleration * DeltaTime);
- }
- event PlayerTick( float DeltaTime )
- {
- if ( bUpdatePosition )
- ClientUpdatePosition();
- PlayerMove(DeltaTime);
- }
- function PlayerMove(float DeltaTime)
- {
- local vector X,Y,Z;
- GetAxes(ViewRotation,X,Y,Z);
- aForward *= 0.1;
- aStrafe *= 0.1;
- aLookup *= 0.24;
- aTurn *= 0.24;
- aUp *= 0.1;
- Acceleration = aForward*X + aStrafe*Y + aUp*vect(0,0,1);
- UpdateRotation(DeltaTime, 1);
- if ( Role < ROLE_Authority ) // then save this move and replicate it
- ReplicateMove(DeltaTime, Acceleration, DODGE_None, rot(0,0,0));
- else
- ProcessMove(DeltaTime, Acceleration, DODGE_None, rot(0,0,0));
- }
- function EndState()
- {
- Mesh = Default.Mesh;
- SetCollision(true,true,true);
- }
- function BeginState()
- {
- Mesh = None;
- SetCollision(false,false,false);
- EyeHeight = BaseEyeHeight;
- SetPhysics(PHYS_None);
- }
- }
- //===============================================================================
- state PlayerWaking
- {
- ignores SeePlayer, HearNoise, KilledBy, Bump, HitWall, HeadZoneChange, FootZoneChange, ZoneChange, SwitchWeapon, Falling, StartClimbing;
- function Timer()
- {
- BaseEyeHeight = Default.BaseEyeHeight;
- }
- event PlayerTick( float DeltaTime )
- {
- if ( bUpdatePosition )
- ClientUpdatePosition();
- PlayerMove(DeltaTime);
- }
- function PlayerMove(Float DeltaTime)
- {
- ViewFlash(deltaTime * 0.5);
- if ( TimerRate == 0 )
- {
- ViewRotation.Pitch -= DeltaTime * 12000;
- if ( ViewRotation.Pitch < 0 )
- {
- ViewRotation.Pitch = 0;
- GotoState('PlayerWalking');
- }
- }
- if ( Role < ROLE_Authority ) // then save this move and replicate it
- ReplicateMove(DeltaTime, vect(0,0,0), DODGE_None, rot(0,0,0));
- else
- ProcessMove(DeltaTime, vect(0,0,0), DODGE_None, rot(0,0,0));
- }
- function BeginState()
- {
- if ( bWokeUp )
- {
- ViewRotation.Pitch = 0;
- SetTimer(0, false);
- return;
- }
- BaseEyeHeight = 0;
- EyeHeight = 0;
- SetTimer(3.0, false);
- bWokeUp = true;
- }
- }
- state Dying
- {
- ignores SeePlayer, HearNoise, KilledBy, Bump, HitWall, HeadZoneChange, FootZoneChange, ZoneChange, SwitchWeapon, Falling, PainTimer, StartClimbing;
- exec function Fire( optional float F )
- {
- if ( Role < ROLE_Authority )
- return;
- if ( (Level.NetMode == NM_Standalone) && !Level.Game.bDeathMatch )
- {
- if ( bFrozen )
- return;
- ShowLoadMenu();
- }
- else
- ServerReStartPlayer();
- }
- exec function AltFire( optional float F )
- {
- Fire(F);
- }
- function ServerMove
- (
- float TimeStamp,
- vector Accel,
- vector ClientLoc,
- bool NewbRun,
- bool NewbDuck,
- bool NewbPressedJump,
- bool bFired,
- bool bAltFired,
- eDodgeDir DodgeMove,
- byte ClientRoll,
- int View
- )
- {
- if ( NewbPressedJump )
- Fire(0);
- Global.ServerMove(
- TimeStamp,
- Accel,
- ClientLoc,
- NewbRun,
- NewbDuck,
- NewbPressedJump,
- bFired,
- bAltFired,
- DodgeMove,
- ClientRoll,
- View);
- }
- function PlayerCalcView(out actor ViewActor, out vector CameraLocation, out rotator CameraRotation )
- {
- local vector View,HitLocation,HitNormal, spot;
- local float ViewDist;
- local actor HitActor;
- local Pawn PTarget;
- if ( ViewTarget != None )
- {
- ViewActor = ViewTarget;
- CameraLocation = ViewTarget.Location;
- CameraRotation = ViewTarget.Rotation;
- PTarget = Pawn(ViewTarget);
- if ( PTarget != None )
- {
- if ( Level.NetMode == NM_Client )
- {
- if ( PTarget.bIsPlayer )
- PTarget.ViewRotation = TargetViewRotation;
- PTarget.EyeHeight = TargetEyeHeight;
- if ( PTarget.Weapon != None )
- PTarget.Weapon.PlayerViewOffset = TargetWeaponViewOffset;
- }
- if ( PTarget.bIsPlayer )
- CameraRotation = PTarget.ViewRotation;
- CameraLocation.Z += PTarget.EyeHeight;
- }
- if ( Carcass(ViewTarget) != None )
- {
- if ( ViewTarget.Physics == PHYS_None )
- CameraRotation = ViewRotation;
- else
- ViewRotation = CameraRotation;
- }
- else if ( bBehindView )
- CalcBehindView(CameraLocation, CameraRotation, 180);
- return;
- }
- // View rotation.
- CameraRotation = ViewRotation;
- DesiredFOV = DefaultFOV;
- ViewActor = self;
- if ( bBehindView ) //up and behind (for death scene)
- {
- ViewDist = 190;
- if (MoveTarget != None)
- spot = MoveTarget.Location;
- else
- spot = Location;
- View = vect(1,0,0) >> CameraRotation;
- HitActor = Trace( HitLocation, HitNormal,
- spot - ViewDist * vector(CameraRotation), spot, false, vect(12,12,2));
- if ( HitActor != None )
- CameraLocation = HitLocation;
- else
- CameraLocation = spot - ViewDist * View;
- }
- else
- {
- // First-person view.
- CameraLocation = Location;
- CameraLocation.Z += Default.BaseEyeHeight;
- }
- }
- event PlayerTick( float DeltaTime )
- {
- if ( bUpdatePosition )
- ClientUpdatePosition();
- PlayerMove(DeltaTime);
- }
- function PlayerMove(float DeltaTime)
- {
- local vector X,Y,Z;
- if ( !bFrozen )
- {
- if ( bPressedJump )
- Fire(0);
- GetAxes(ViewRotation,X,Y,Z);
- // Update view rotation.
- aLookup *= 0.24;
- aTurn *= 0.24;
- ViewRotation.Yaw += 32.0 * DeltaTime * aTurn;
- ViewRotation.Pitch += 32.0 * DeltaTime * aLookUp;
- ViewRotation.Pitch = ViewRotation.Pitch & 65535;
- If ((ViewRotation.Pitch > 18000) && (ViewRotation.Pitch < 49152))
- {
- If (aLookUp > 0)
- ViewRotation.Pitch = 18000;
- else
- ViewRotation.Pitch = 49152;
- }
- if ( Role < ROLE_Authority ) // then save this move and replicate it
- ReplicateMove(DeltaTime, vect(0,0,0), DODGE_None, rot(0,0,0));
- bPressedJump = false;
- }
- ViewShake(DeltaTime);
- ViewFlash(DeltaTime);
- }
- function FindGoodView()
- {
- local vector cameraLoc;
- local rotator cameraRot;
- local int tries, besttry;
- local float bestdist, newdist;
- local int startYaw;
- local actor ViewActor;
- //fixme - try to pick view with killer visible
- //fixme - also try varying starting pitch
- ////log("Find good death scene view");
- ViewRotation.Pitch = 56000;
- tries = 0;
- besttry = 0;
- bestdist = 0.0;
- startYaw = ViewRotation.Yaw;
- for (tries=0; tries<16; tries++)
- {
- cameraLoc = Location;
- PlayerCalcView(ViewActor, cameraLoc, cameraRot);
- newdist = VSize(cameraLoc - Location);
- if (newdist > bestdist)
- {
- bestdist = newdist;
- besttry = tries;
- }
- ViewRotation.Yaw += 4096;
- }
- ViewRotation.Yaw = startYaw + besttry * 4096;
- }
- function TakeDamage( int Damage, Pawn instigatedBy, Vector hitlocation,
- Vector momentum, name damageType)
- {
- if ( !bHidden )
- Super.TakeDamage(Damage, instigatedBy, hitlocation, momentum, damageType);
- }
- function Timer()
- {
- bFrozen = false;
- bShowScores = true;
- bPressedJump = false;
- }
- function BeginState()
- {
- bBehindView = true;
- bFrozen = true;
- bPressedJump = false;
- FindGoodView();
- if ( (Role == ROLE_Authority) && !bHidden )
- Super.Timer();
- SetTimer(1.0, false);
- //log(Self$" entering dying with remote role "$RemoteRole$" and role "$Role$" in state "$state);
- }
- function EndState()
- {
- bBehindView = false;
- bShowScores = false;
- if ( Carcass(ViewTarget) != None )
- ViewTarget = None;
- //Log(self$" exiting dying with remote role "$RemoteRole$" and role "$Role);
- }
- }
- state GameEnded
- {
- ignores SeePlayer, HearNoise, KilledBy, Bump, HitWall, HeadZoneChange, FootZoneChange, ZoneChange, Falling, TakeDamage, PainTimer, Died, Suicide, StartClimbing;
- // 227g: Prevent rotation updates for third person clients.
- function UpdatePawnRotation( rotator Rot );
- exec function ViewClass( class<actor> aClass, optional bool bQuiet )
- {
- }
- exec function ViewPlayer( string S )
- {
- }
- exec function Fire( optional float F )
- {
- if ( Role>=ROLE_Authority && !bFrozen )
- ServerReStartGame();
- }
- exec function AltFire( optional float F )
- {
- Fire(F);
- }
- event PlayerTick( float DeltaTime )
- {
- if ( bUpdatePosition )
- ClientUpdatePosition();
- PlayerMove(DeltaTime);
- }
- function PlayerMove(float DeltaTime)
- {
- local vector X,Y,Z;
- GetAxes(ViewRotation,X,Y,Z);
- // Update view rotation.
- if ( !bFrozen && (bPressedJump || (bFire == 1) || (bAltFire == 1)) )
- ServerReStartGame();
- if ( !bFixedCamera )
- {
- aLookup *= 0.24;
- aTurn *= 0.24;
- ViewRotation.Yaw += 32.0 * DeltaTime * aTurn;
- ViewRotation.Pitch += 32.0 * DeltaTime * aLookUp;
- ViewRotation.Pitch = ViewRotation.Pitch & 65535;
- If ((ViewRotation.Pitch > 18000) && (ViewRotation.Pitch < 49152))
- {
- If (aLookUp > 0)
- ViewRotation.Pitch = 18000;
- else
- ViewRotation.Pitch = 49152;
- }
- }
- ViewShake(DeltaTime);
- ViewFlash(DeltaTime);
- if ( Role < ROLE_Authority ) // then save this move and replicate it
- ReplicateMove(DeltaTime, vect(0,0,0), DODGE_None, rot(0,0,0));
- else
- ProcessMove(DeltaTime, vect(0,0,0), DODGE_None, rot(0,0,0));
- bPressedJump = false;
- }
- function FindGoodView()
- {
- local vector cameraLoc;
- local rotator cameraRot;
- local int tries, besttry;
- local float bestdist, newdist;
- local int startYaw;
- local actor ViewActor;
- ViewRotation.Pitch = 56000;
- tries = 0;
- besttry = 0;
- bestdist = 0.0;
- startYaw = ViewRotation.Yaw;
- for (tries=0; tries<16; tries++)
- {
- if ( ViewTarget != None )
- cameraLoc = ViewTarget.Location;
- else
- cameraLoc = Location;
- PlayerCalcView(ViewActor, cameraLoc, cameraRot);
- newdist = VSize(cameraLoc - Location);
- if (newdist > bestdist)
- {
- bestdist = newdist;
- besttry = tries;
- }
- ViewRotation.Yaw += 4096;
- }
- ViewRotation.Yaw = startYaw + besttry * 4096;
- }
- function Timer()
- {
- bFrozen = false;
- }
- function BeginState()
- {
- EndZoom();
- AnimRate = 0.0;
- bFire = 0;
- bAltFire = 0;
- // Freeze animation for third person clients.
- SimAnim.X = 10000 * AnimFrame;
- SimAnim.Y = 0;
- SimAnim.Z = 0;
- SimAnim.W = 10000 * AnimLast;
- SetCollision(false,false,false);
- bShowScores = true;
- bFrozen = true;
- if ( !bFixedCamera )
- {
- FindGoodView();
- bBehindView = true;
- }
- SetTimer(1.5, false);
- SetPhysics(PHYS_None);
- }
- }
- // New 227g state, Laddering
- function StartClimbing( LadderTrigger Other )
- {
- local int YDiff;
- if( Other.bDirectional )
- {
- YDiff = ((ViewRotation.Yaw - Other.Rotation.Yaw) & 65535);
- if( YDiff>16000 && YDiff<50000 )
- return; // Need to face at ladder to allow start climbing
- }
- if( Abs(Velocity.Z)>Other.MaxGrabVelocity )
- return;
- if( Other.ClimbingNoise!=None )
- PlaySound(Other.ClimbingNoise,SLOT_Misc,1.5);
- ActiveLadder = Other;
- if( Other.bUnarmedClimbing )
- {
- PendingWeapon = Weapon;
- if ( Weapon != None )
- Weapon.PutDown();
- }
- GoToState('PlayerClimbing');
- }
- function PlayClimbing( bool bMovement )
- {
- if( bMovement )
- PlayCrawling();
- else PlayDuck();
- }
- State PlayerClimbing
- {
- function ChangedWeapon()
- {
- if( ActiveLadder.bUnarmedClimbing )
- {
- Inventory.ChangedWeapon();
- Weapon = None;
- }
- else Global.ChangedWeapon();
- }
- function StartClimbing( LadderTrigger Other )
- {
- ActiveLadder = Other; // Begin next ladder.
- if( Other.bUnarmedClimbing && Weapon!=None )
- {
- PendingWeapon = Weapon;
- Weapon.PutDown();
- }
- }
- function EndClimbing( LadderTrigger Other )
- {
- local LadderTrigger L;
- if( ActiveLadder==Other )
- {
- ActiveLadder = None;
- foreach TouchingActors(Class'LadderTrigger',L)
- if( L!=Other )
- L.Touch(Self);
- if( ActiveLadder==None )
- DropFromLadder();
- }
- }
- function DropFromLadder()
- {
- PlayInAir();
- Velocity = vector(ViewRotation)*Default.JumpZ*0.5f;
- if( Acceleration.Z>=0.f )
- Velocity.Z = Default.JumpZ*0.8f;
- else Velocity.Z = 0.f;
- if( Region.Zone.bWaterZone )
- {
- SetPhysics(PHYS_Swimming);
- GoToState('PlayerSwimming');
- }
- else
- {
- SetPhysics(PHYS_Falling);
- GoToState('PlayerWalking');
- }
- if( Weapon==None )
- ChangedWeapon();
- }
- function DoJump( optional float F )
- {
- if ( Role == ROLE_Authority && ActiveLadder!=None )
- PlaySound(ActiveLadder.ClimbingNoise, SLOT_Talk, 1.5, true, 1200, 1.0 );
- if ( (Level.Game != None) && (Level.Game.Difficulty > 0) )
- MakeNoise(0.1 * Level.Game.Difficulty);
- PlayInAir();
- Velocity = vector(ViewRotation)*Default.JumpZ;
- Velocity.Z = Default.JumpZ*0.8f;
- if( ActiveLadder!=None )
- Velocity+=vector(ActiveLadder.Rotation)*Default.JumpZ;
- if( Region.Zone.bWaterZone )
- {
- SetPhysics(PHYS_Swimming);
- GoToState('PlayerSwimming');
- }
- else
- {
- SetPhysics(PHYS_Falling);
- GoToState('PlayerWalking');
- }
- if( Weapon==None )
- ChangedWeapon();
- }
- function AnimEnd()
- {
- PlayClimbing(Acceleration!=vect(0,0,0));
- }
- function ProcessMove(float DeltaTime, vector NewAccel, eDodgeDir DodgeMove, rotator DeltaRot)
- {
- local vector OldAccel;
- if ( bPressedJump )
- {
- DoJump();
- return;
- }
- OldAccel = Acceleration;
- if ( VSize(NewAccel)<0.1 )
- Acceleration = vect(0,0,0);
- else Acceleration = Normal(NewAccel) * FMin(AirSpeed*0.4f,VSize(NewAccel));
- Velocity = Acceleration;
- if( OldAccel==vect(0,0,0) )
- {
- if( Acceleration!=vect(0,0,0) )
- PlayClimbing(true);
- }
- else if( Acceleration==vect(0,0,0) )
- PlayClimbing(false);
- if( Level.NetMode!=NM_Client && ActiveLadder==None )
- DropFromLadder();
- }
- event PlayerTick( float DeltaTime )
- {
- if ( bUpdatePosition )
- ClientUpdatePosition();
- PlayerMove(DeltaTime);
- }
- function PlayerMove(float DeltaTime)
- {
- local vector X,Y,Z;
- GetAxes(ViewRotation,X,Y,Z);
- aForward *= 0.1;
- aStrafe *= 0.1;
- aLookup *= 0.24;
- aTurn *= 0.24;
- aUp *= 0.1;
- Acceleration = aForward*X.Z*vect(0,0,1) + aUp*vect(0,0,1);
- UpdateRotation(DeltaTime, 1);
- if ( Role < ROLE_Authority ) // then save this move and replicate it
- ReplicateMove(DeltaTime, Acceleration, DODGE_None, rot(0,0,0));
- else
- ProcessMove(DeltaTime, Acceleration, DODGE_None, rot(0,0,0));
- bPressedJump = false;
- }
- function BeginState()
- {
- EyeHeight = BaseEyeHeight;
- SetPhysics(PHYS_Flying);
- if( Base!=None )
- SetBase(Level);
- PlayClimbing(false);
- if ( CarriedDecoration != None && Role==ROLE_Authority )
- DropDecoration();
- }
- function EndState()
- {
- WalkBob = vect(0,0,0);
- ActiveLadder = None;
- bIsWalking = false;
- }
- function HandleWalking()
- {
- bIsWalking = false;
- }
- }
- // To be returned for player info on serverlist.
- function GetPlayerModelInfo( out string MeshName, out string SkinName )
- {
- if( Mesh!=None )
- MeshName = string(Mesh.Name);
- else MeshName = MenuName;
- if( Skin!=None )
- SkinName = string(Skin.Name);
- else SkinName = "Default";
- }
Add Comment
Please, Sign In to add comment