mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-01-28 00:24:44 +00:00
533 lines
11 KiB
C#
533 lines
11 KiB
C#
|
|
//-----------------------------------------------------------------------------
|
||
|
|
// Copyright (c) 2012 GarageGames, LLC
|
||
|
|
//
|
||
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||
|
|
// of this software and associated documentation files (the "Software"), to
|
||
|
|
// deal in the Software without restriction, including without limitation the
|
||
|
|
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||
|
|
// sell copies of the Software, and to permit persons to whom the Software is
|
||
|
|
// furnished to do so, subject to the following conditions:
|
||
|
|
//
|
||
|
|
// The above copyright notice and this permission notice shall be included in
|
||
|
|
// all copies or substantial portions of the Software.
|
||
|
|
//
|
||
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||
|
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||
|
|
// IN THE SOFTWARE.
|
||
|
|
//-----------------------------------------------------------------------------
|
||
|
|
function escapeFromGame()
|
||
|
|
{
|
||
|
|
disconnect();
|
||
|
|
}
|
||
|
|
|
||
|
|
function showPlayerList(%val)
|
||
|
|
{
|
||
|
|
if (%val)
|
||
|
|
PlayerListGui.toggle();
|
||
|
|
}
|
||
|
|
|
||
|
|
function hideHUDs(%val)
|
||
|
|
{
|
||
|
|
if (%val)
|
||
|
|
HudlessPlayGui.toggle();
|
||
|
|
}
|
||
|
|
|
||
|
|
function doScreenShotHudless(%val)
|
||
|
|
{
|
||
|
|
if(%val)
|
||
|
|
{
|
||
|
|
canvas.setContent(HudlessPlayGui);
|
||
|
|
//doScreenshot(%val);
|
||
|
|
schedule(10, 0, "doScreenShot", %val);
|
||
|
|
}
|
||
|
|
else
|
||
|
|
canvas.setContent(PlayGui);
|
||
|
|
}
|
||
|
|
|
||
|
|
$movementSpeed = 1; // m/s
|
||
|
|
|
||
|
|
function setSpeed(%speed)
|
||
|
|
{
|
||
|
|
if(%speed)
|
||
|
|
$movementSpeed = %speed;
|
||
|
|
}
|
||
|
|
|
||
|
|
function moveleft(%val)
|
||
|
|
{
|
||
|
|
$mvLeftAction = %val * $movementSpeed;
|
||
|
|
}
|
||
|
|
|
||
|
|
function moveright(%val)
|
||
|
|
{
|
||
|
|
$mvRightAction = %val * $movementSpeed;
|
||
|
|
}
|
||
|
|
|
||
|
|
function moveforward(%val)
|
||
|
|
{
|
||
|
|
$mvForwardAction = %val * $movementSpeed;
|
||
|
|
}
|
||
|
|
|
||
|
|
function movebackward(%val)
|
||
|
|
{
|
||
|
|
$mvBackwardAction = %val * $movementSpeed;
|
||
|
|
}
|
||
|
|
|
||
|
|
function moveup(%val)
|
||
|
|
{
|
||
|
|
%object = ServerConnection.getControlObject();
|
||
|
|
|
||
|
|
if(%object.isInNamespaceHierarchy("Camera"))
|
||
|
|
$mvUpAction = %val * $movementSpeed;
|
||
|
|
}
|
||
|
|
|
||
|
|
function movedown(%val)
|
||
|
|
{
|
||
|
|
%object = ServerConnection.getControlObject();
|
||
|
|
|
||
|
|
if(%object.isInNamespaceHierarchy("Camera"))
|
||
|
|
$mvDownAction = %val * $movementSpeed;
|
||
|
|
}
|
||
|
|
|
||
|
|
function turnLeft( %val )
|
||
|
|
{
|
||
|
|
$mvYawRightSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
function turnRight( %val )
|
||
|
|
{
|
||
|
|
$mvYawLeftSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
function panUp( %val )
|
||
|
|
{
|
||
|
|
$mvPitchDownSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
function panDown( %val )
|
||
|
|
{
|
||
|
|
$mvPitchUpSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
function getMouseAdjustAmount(%val)
|
||
|
|
{
|
||
|
|
// based on a default camera FOV of 90'
|
||
|
|
return(%val * ($cameraFov / 90) * 0.01) * $pref::Input::LinkMouseSensitivity;
|
||
|
|
}
|
||
|
|
|
||
|
|
function getGamepadAdjustAmount(%val)
|
||
|
|
{
|
||
|
|
// based on a default camera FOV of 90'
|
||
|
|
return(%val * ($cameraFov / 90) * 0.01) * 10.0;
|
||
|
|
}
|
||
|
|
|
||
|
|
function yaw(%val)
|
||
|
|
{
|
||
|
|
%yawAdj = getMouseAdjustAmount(%val);
|
||
|
|
if(ServerConnection.isControlObjectRotDampedCamera())
|
||
|
|
{
|
||
|
|
// Clamp and scale
|
||
|
|
%yawAdj = mClamp(%yawAdj, -m2Pi()+0.01, m2Pi()-0.01);
|
||
|
|
%yawAdj *= 0.5;
|
||
|
|
}
|
||
|
|
|
||
|
|
$mvYaw += %yawAdj;
|
||
|
|
}
|
||
|
|
|
||
|
|
function pitch(%val)
|
||
|
|
{
|
||
|
|
%pitchAdj = getMouseAdjustAmount(%val);
|
||
|
|
if(ServerConnection.isControlObjectRotDampedCamera())
|
||
|
|
{
|
||
|
|
// Clamp and scale
|
||
|
|
%pitchAdj = mClamp(%pitchAdj, -m2Pi()+0.01, m2Pi()-0.01);
|
||
|
|
%pitchAdj *= 0.5;
|
||
|
|
}
|
||
|
|
|
||
|
|
$mvPitch += %pitchAdj;
|
||
|
|
}
|
||
|
|
|
||
|
|
function jump(%val)
|
||
|
|
{
|
||
|
|
$mvTriggerCount2++;
|
||
|
|
}
|
||
|
|
|
||
|
|
function gamePadMoveX( %val )
|
||
|
|
{
|
||
|
|
if(%val > 0)
|
||
|
|
{
|
||
|
|
$mvRightAction = %val * $movementSpeed;
|
||
|
|
$mvLeftAction = 0;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
$mvRightAction = 0;
|
||
|
|
$mvLeftAction = -%val * $movementSpeed;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function gamePadMoveY( %val )
|
||
|
|
{
|
||
|
|
if(%val > 0)
|
||
|
|
{
|
||
|
|
$mvForwardAction = %val * $movementSpeed;
|
||
|
|
$mvBackwardAction = 0;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
$mvForwardAction = 0;
|
||
|
|
$mvBackwardAction = -%val * $movementSpeed;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function gamepadYaw(%val)
|
||
|
|
{
|
||
|
|
%yawAdj = getGamepadAdjustAmount(%val);
|
||
|
|
if(ServerConnection.isControlObjectRotDampedCamera())
|
||
|
|
{
|
||
|
|
// Clamp and scale
|
||
|
|
%yawAdj = mClamp(%yawAdj, -m2Pi()+0.01, m2Pi()-0.01);
|
||
|
|
%yawAdj *= 0.5;
|
||
|
|
}
|
||
|
|
|
||
|
|
if(%yawAdj > 0)
|
||
|
|
{
|
||
|
|
$mvYawLeftSpeed = %yawAdj;
|
||
|
|
$mvYawRightSpeed = 0;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
$mvYawLeftSpeed = 0;
|
||
|
|
$mvYawRightSpeed = -%yawAdj;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function gamepadPitch(%val)
|
||
|
|
{
|
||
|
|
%pitchAdj = getGamepadAdjustAmount(%val);
|
||
|
|
if(ServerConnection.isControlObjectRotDampedCamera())
|
||
|
|
{
|
||
|
|
// Clamp and scale
|
||
|
|
%pitchAdj = mClamp(%pitchAdj, -m2Pi()+0.01, m2Pi()-0.01);
|
||
|
|
%pitchAdj *= 0.5;
|
||
|
|
}
|
||
|
|
|
||
|
|
if(%pitchAdj > 0)
|
||
|
|
{
|
||
|
|
$mvPitchDownSpeed = %pitchAdj;
|
||
|
|
$mvPitchUpSpeed = 0;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
$mvPitchDownSpeed = 0;
|
||
|
|
$mvPitchUpSpeed = -%pitchAdj;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function doCrouch(%val)
|
||
|
|
{
|
||
|
|
$mvTriggerCount3++;
|
||
|
|
}
|
||
|
|
|
||
|
|
function doSprint(%val)
|
||
|
|
{
|
||
|
|
$mvTriggerCount5++;
|
||
|
|
}
|
||
|
|
|
||
|
|
function mouseFire(%val)
|
||
|
|
{
|
||
|
|
$mvTriggerCount0++;
|
||
|
|
}
|
||
|
|
|
||
|
|
function gamepadFire(%val)
|
||
|
|
{
|
||
|
|
if(%val > 0.1 && !$gamepadFireTriggered)
|
||
|
|
{
|
||
|
|
$gamepadFireTriggered = true;
|
||
|
|
$mvTriggerCount0++;
|
||
|
|
}
|
||
|
|
else if(%val <= 0.1 && $gamepadFireTriggered)
|
||
|
|
{
|
||
|
|
$gamepadFireTriggered = false;
|
||
|
|
$mvTriggerCount0++;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function gamepadAltTrigger(%val)
|
||
|
|
{
|
||
|
|
if(%val > 0.1 && !$gamepadAltTriggerTriggered)
|
||
|
|
{
|
||
|
|
$gamepadAltTriggerTriggered = true;
|
||
|
|
$mvTriggerCount1++;
|
||
|
|
}
|
||
|
|
else if(%val <= 0.1 && $gamepadAltTriggerTriggered)
|
||
|
|
{
|
||
|
|
$gamepadAltTriggerTriggered = false;
|
||
|
|
$mvTriggerCount1++;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function toggleZoomFOV()
|
||
|
|
{
|
||
|
|
$Player::CurrentFOV = $Player::CurrentFOV / 2;
|
||
|
|
|
||
|
|
if($Player::CurrentFOV < 5)
|
||
|
|
resetCurrentFOV();
|
||
|
|
|
||
|
|
if(ServerConnection.zoomed)
|
||
|
|
setFOV($Player::CurrentFOV);
|
||
|
|
else
|
||
|
|
{
|
||
|
|
setFov(ServerConnection.getControlCameraDefaultFov());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function resetCurrentFOV()
|
||
|
|
{
|
||
|
|
$Player::CurrentFOV = ServerConnection.getControlCameraDefaultFov() / 2;
|
||
|
|
}
|
||
|
|
|
||
|
|
function turnOffZoom()
|
||
|
|
{
|
||
|
|
ServerConnection.zoomed = false;
|
||
|
|
setFov(ServerConnection.getControlCameraDefaultFov());
|
||
|
|
Reticle.setVisible(true);
|
||
|
|
zoomReticle.setVisible(false);
|
||
|
|
|
||
|
|
// Rather than just disable the DOF effect, we want to set it to the level's
|
||
|
|
// preset values.
|
||
|
|
//DOFPostEffect.disable();
|
||
|
|
ppOptionsUpdateDOFSettings();
|
||
|
|
}
|
||
|
|
|
||
|
|
function setZoomFOV(%val)
|
||
|
|
{
|
||
|
|
if(%val)
|
||
|
|
toggleZoomFOV();
|
||
|
|
}
|
||
|
|
|
||
|
|
function toggleZoom(%val)
|
||
|
|
{
|
||
|
|
if (%val)
|
||
|
|
{
|
||
|
|
ServerConnection.zoomed = true;
|
||
|
|
setFov($Player::CurrentFOV);
|
||
|
|
Reticle.setVisible(false);
|
||
|
|
zoomReticle.setVisible(true);
|
||
|
|
|
||
|
|
DOFPostEffect.setAutoFocus( true );
|
||
|
|
DOFPostEffect.setFocusParams( 0.5, 0.5, 50, 500, -5, 5 );
|
||
|
|
DOFPostEffect.enable();
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
turnOffZoom();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function mouseButtonZoom(%val)
|
||
|
|
{
|
||
|
|
toggleZoom(%val);
|
||
|
|
}
|
||
|
|
|
||
|
|
function toggleFreeLook( %val )
|
||
|
|
{
|
||
|
|
if ( %val )
|
||
|
|
$mvFreeLook = true;
|
||
|
|
else
|
||
|
|
$mvFreeLook = false;
|
||
|
|
}
|
||
|
|
|
||
|
|
function toggleFirstPerson(%val)
|
||
|
|
{
|
||
|
|
if (%val)
|
||
|
|
{
|
||
|
|
ServerConnection.setFirstPerson(!ServerConnection.isFirstPerson());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function toggleCamera(%val)
|
||
|
|
{
|
||
|
|
if (%val)
|
||
|
|
commandToServer('ToggleCamera');
|
||
|
|
}
|
||
|
|
|
||
|
|
function unmountWeapon(%val)
|
||
|
|
{
|
||
|
|
if (%val)
|
||
|
|
commandToServer('unmountWeapon');
|
||
|
|
}
|
||
|
|
|
||
|
|
function throwWeapon(%val)
|
||
|
|
{
|
||
|
|
if (%val)
|
||
|
|
commandToServer('Throw', "Weapon");
|
||
|
|
}
|
||
|
|
function tossAmmo(%val)
|
||
|
|
{
|
||
|
|
if (%val)
|
||
|
|
commandToServer('Throw', "Ammo");
|
||
|
|
}
|
||
|
|
|
||
|
|
function nextWeapon(%val)
|
||
|
|
{
|
||
|
|
if (%val)
|
||
|
|
commandToServer('cycleWeapon', "next");
|
||
|
|
}
|
||
|
|
|
||
|
|
function prevWeapon(%val)
|
||
|
|
{
|
||
|
|
if (%val)
|
||
|
|
commandToServer('cycleWeapon', "prev");
|
||
|
|
}
|
||
|
|
|
||
|
|
function mouseWheelWeaponCycle(%val)
|
||
|
|
{
|
||
|
|
if (%val < 0)
|
||
|
|
commandToServer('cycleWeapon', "next");
|
||
|
|
else if (%val > 0)
|
||
|
|
commandToServer('cycleWeapon', "prev");
|
||
|
|
}
|
||
|
|
|
||
|
|
function pageMessageHudUp( %val )
|
||
|
|
{
|
||
|
|
if ( %val )
|
||
|
|
pageUpMessageHud();
|
||
|
|
}
|
||
|
|
|
||
|
|
function pageMessageHudDown( %val )
|
||
|
|
{
|
||
|
|
if ( %val )
|
||
|
|
pageDownMessageHud();
|
||
|
|
}
|
||
|
|
|
||
|
|
function resizeMessageHud( %val )
|
||
|
|
{
|
||
|
|
if ( %val )
|
||
|
|
cycleMessageHudSize();
|
||
|
|
}
|
||
|
|
|
||
|
|
function startRecordingDemo( %val )
|
||
|
|
{
|
||
|
|
if ( %val )
|
||
|
|
startDemoRecord();
|
||
|
|
}
|
||
|
|
|
||
|
|
function stopRecordingDemo( %val )
|
||
|
|
{
|
||
|
|
if ( %val )
|
||
|
|
stopDemoRecord();
|
||
|
|
}
|
||
|
|
|
||
|
|
function dropCameraAtPlayer(%val)
|
||
|
|
{
|
||
|
|
if (%val)
|
||
|
|
commandToServer('dropCameraAtPlayer');
|
||
|
|
}
|
||
|
|
|
||
|
|
function dropPlayerAtCamera(%val)
|
||
|
|
{
|
||
|
|
if (%val)
|
||
|
|
commandToServer('DropPlayerAtCamera');
|
||
|
|
}
|
||
|
|
|
||
|
|
function bringUpOptions(%val)
|
||
|
|
{
|
||
|
|
if (%val)
|
||
|
|
Canvas.pushDialog(OptionsDlg);
|
||
|
|
}
|
||
|
|
|
||
|
|
GlobalActionMap.bind(keyboard, "ctrl o", bringUpOptions);
|
||
|
|
|
||
|
|
|
||
|
|
//------------------------------------------------------------------------------
|
||
|
|
// Debugging Functions
|
||
|
|
//------------------------------------------------------------------------------
|
||
|
|
function showMetrics(%val)
|
||
|
|
{
|
||
|
|
if(%val)
|
||
|
|
{
|
||
|
|
if(!Canvas.isMember(FrameOverlayGui))
|
||
|
|
metrics("fps gfx shadow sfx terrain groundcover forest net");
|
||
|
|
else
|
||
|
|
metrics("");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
GlobalActionMap.bind(keyboard, "ctrl F2", showMetrics);
|
||
|
|
|
||
|
|
//------------------------------------------------------------------------------
|
||
|
|
//
|
||
|
|
// Start profiler by pressing ctrl f3
|
||
|
|
// ctrl f3 - starts profile that will dump to console and file
|
||
|
|
//
|
||
|
|
function doProfile(%val)
|
||
|
|
{
|
||
|
|
if (%val)
|
||
|
|
{
|
||
|
|
// key down -- start profile
|
||
|
|
echo("Starting profile session...");
|
||
|
|
profilerReset();
|
||
|
|
profilerEnable(true);
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
// key up -- finish off profile
|
||
|
|
echo("Ending profile session...");
|
||
|
|
|
||
|
|
profilerDumpToFile("profilerDumpToFile" @ getSimTime() @ ".txt");
|
||
|
|
profilerEnable(false);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Trace a line along the direction the crosshair is pointing
|
||
|
|
// If you find a car with a player in it...eject them
|
||
|
|
function carjack()
|
||
|
|
{
|
||
|
|
%player = LocalClientConnection.getControlObject();
|
||
|
|
|
||
|
|
if (%player.getClassName() $= "Player")
|
||
|
|
{
|
||
|
|
%eyeVec = %player.getEyeVector();
|
||
|
|
|
||
|
|
%startPos = %player.getEyePoint();
|
||
|
|
%endPos = VectorAdd(%startPos, VectorScale(%eyeVec, 1000));
|
||
|
|
|
||
|
|
%target = ContainerRayCast(%startPos, %endPos, $TypeMasks::VehicleObjectType);
|
||
|
|
|
||
|
|
if (%target)
|
||
|
|
{
|
||
|
|
// See if anyone is mounted in the car's driver seat
|
||
|
|
%mount = %target.getMountNodeObject(0);
|
||
|
|
|
||
|
|
// Can only carjack bots
|
||
|
|
// remove '&& %mount.getClassName() $= "AIPlayer"' to allow you
|
||
|
|
// to carjack anyone/anything
|
||
|
|
if (%mount && %mount.getClassName() $= "AIPlayer")
|
||
|
|
{
|
||
|
|
commandToServer('carUnmountObj', %mount);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function getOut()
|
||
|
|
{
|
||
|
|
vehicleMap.pop();
|
||
|
|
moveMap.push();
|
||
|
|
commandToServer('dismountVehicle');
|
||
|
|
}
|
||
|
|
|
||
|
|
function brakeLights()
|
||
|
|
{
|
||
|
|
// Turn on/off the Cheetah's head lights.
|
||
|
|
commandToServer('toggleBrakeLights');
|
||
|
|
}
|
||
|
|
|
||
|
|
function brake(%val)
|
||
|
|
{
|
||
|
|
commandToServer('toggleBrakeLights');
|
||
|
|
$mvTriggerCount2++;
|
||
|
|
}
|