added everything

This commit is contained in:
Metario
2017-04-17 06:17:10 -06:00
commit 9c6ff74f19
6121 changed files with 1625704 additions and 0 deletions

View File

@ -0,0 +1,113 @@
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// 3D Sounds
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Single shot sounds
datablock AudioDescription(AudioDefault3d)
{
volume = 1.0;
isLooping= false;
is3D = true;
ReferenceDistance= 20.0;
MaxDistance= 100.0;
type = $SimAudioType;
};
datablock AudioDescription(AudioClose3d)
{
volume = 1.0;
isLooping= false;
is3D = true;
ReferenceDistance= 10.0;
MaxDistance= 60.0;
type = $SimAudioType;
};
datablock AudioDescription(AudioClosest3d)
{
volume = 1.0;
isLooping= false;
is3D = true;
ReferenceDistance= 5.0;
MaxDistance= 30.0;
type = $SimAudioType;
};
//-----------------------------------------------------------------------------
// Looping sounds
datablock AudioDescription(AudioDefaultLooping3d)
{
volume = 1.0;
isLooping= true;
is3D = true;
ReferenceDistance= 20.0;
MaxDistance= 100.0;
type = $SimAudioType;
};
datablock AudioDescription(AudioCloseLooping3d)
{
volume = 1.0;
isLooping= true;
is3D = true;
ReferenceDistance= 10.0;
MaxDistance= 50.0;
type = $SimAudioType;
};
datablock AudioDescription(AudioClosestLooping3d)
{
volume = 1.0;
isLooping= true;
is3D = true;
ReferenceDistance= 5.0;
MaxDistance= 30.0;
type = $SimAudioType;
};
//-----------------------------------------------------------------------------
// 2d sounds
//-----------------------------------------------------------------------------
// Used for non-looping environmental sounds (like power on, power off)
datablock AudioDescription(Audio2D)
{
volume = 1.0;
isLooping = false;
is3D = false;
type = $SimAudioType;
};
// Used for Looping Environmental Sounds
datablock AudioDescription(AudioLooping2D)
{
volume = 1.0;
isLooping = true;
is3D = false;
type = $SimAudioType;
};
//-----------------------------------------------------------------------------
datablock AudioProfile(takeme)
{
filename = "~/data/sound/takeme.wav";
description = "AudioDefaultLooping3d";
preload = false;
};

View File

@ -0,0 +1,80 @@
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------
// Global movement speed that affects all cameras. This should be moved
// into the camera datablock.
$Camera::movementSpeed = 40;
//-----------------------------------------------------------------------------
// Define a datablock class to use for our observer camera
//-----------------------------------------------------------------------------
datablock CameraData(Observer)
{
mode = "Observer";
};
//-----------------------------------------------------------------------------
function Observer::onTrigger(%this,%obj,%trigger,%state)
{
// state = 0 means that a trigger key was released
if (%state == 0)
return;
// Default player triggers: 0=fire 1=altFire 2=jump
%client = %obj.getControllingClient();
switch$ (%obj.mode)
{
case "Observer":
// Do something interesting.
case "Corpse":
// Viewing dead corpse, so we probably want to respawn.
%client.spawnPlayer();
// Set the camera back into observer mode, since in
// debug mode we like to switch to it.
%this.setMode(%obj,"Observer");
}
}
function Observer::setMode(%this,%obj,%mode,%arg1,%arg2,%arg3)
{
switch$ (%mode)
{
case "Observer":
// Let the player fly around
%obj.setFlyMode();
case "Corpse":
// Lock the camera down in orbit around the corpse,
// which should be arg1
%transform = %arg1.getTransform();
%obj.setOrbitMode(%arg1, %transform, 0.5, 4.5, 4.5);
}
%obj.mode = %mode;
}
//-----------------------------------------------------------------------------
// Camera methods
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function Camera::onAdd(%this,%obj)
{
// Default start mode
%this.setMode(%this.mode);
}
function Camera::setMode(%this,%mode,%arg1,%arg2,%arg3)
{
// Punt this one over to our datablock
%this.getDatablock().setMode(%this,%mode,%arg1,%arg2,%arg3);
}

View File

@ -0,0 +1,187 @@
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Information extacted from the shape.
//
// Wheel Sequences
// spring# Wheel spring motion: time 0 = wheel fully extended,
// the hub must be displaced, but not directly animated
// as it will be rotated in code.
// Other Sequences
// steering Wheel steering: time 0 = full right, 0.5 = center
// breakLight Break light, time 0 = off, 1 = breaking
//
// Wheel Nodes
// hub# Wheel hub, the hub must be in it's upper position
// from which the springs are mounted.
//
// The steering and animation sequences are optional.
// The center of the shape acts as the center of mass for the car.
//-----------------------------------------------------------------------------
datablock AudioProfile(buggyEngineSound)
{
filename = "~/data/sound/vehicles/buggy/engine_idle.wav";
description = AudioClosestLooping3d;
preload = true;
};
datablock ParticleData(TireParticle)
{
textureName = "~/data/shapes/buggy/dustParticle";
dragCoefficient = 2.0;
gravityCoefficient = -0.1;
inheritedVelFactor = 0.1;
constantAcceleration = 0.0;
lifetimeMS = 1000;
lifetimeVarianceMS = 400;
colors[0] = "0.46 0.36 0.26 1.0";
colors[1] = "0.46 0.46 0.36 0.0";
sizes[0] = 1.0;
sizes[1] = 4.0;
};
datablock ParticleEmitterData(TireEmitter)
{
ejectionPeriodMS = 20;
periodVarianceMS = 10;
ejectionVelocity = 1;
velocityVariance = 1.0;
ejectionOffset = 0.0;
thetaMin = 0;
thetaMax = 60;
phiReferenceVel = 0;
phiVariance = 360;
overrideAdvance = false;
particles = "TireParticle";
};
//----------------------------------------------------------------------------
datablock WheeledVehicleTire(DefaultCarTire)
{
// Tires act as springs and generate lateral and longitudinal
// forces to move the vehicle. These distortion/spring forces
// are what convert wheel angular velocity into forces that
// act on the rigid body.
shapeFile = "~/data/shapes/buggy/wheel.dts";
staticFriction = 4.2;
kineticFriction = 3.15;
// Spring that generates lateral tire forces
lateralForce = 18000;
lateralDamping = 6000;
lateralRelaxation = 1;
// Spring that generates longitudinal tire forces
longitudinalForce = 18000;
longitudinalDamping = 4000;
longitudinalRelaxation = 1;
};
datablock WheeledVehicleSpring(DefaultCarSpring)
{
// Wheel suspension properties
length = 0.85; // Suspension travel
force = 2800; // Spring force
damping = 3600; // Spring damping
antiSwayForce = 3; // Lateral anti-sway force
};
datablock WheeledVehicleData(DefaultCar)
{
category = "Vehicles";
shapeFile = "~/data/shapes/buggy/buggy.dts";
emap = true;
maxDamage = 1.0;
destroyedLevel = 0.5;
maxSteeringAngle = 0.385; // Maximum steering angle, should match animation
tireEmitter = TireEmitter; // All the tires use the same dust emitter
// 3rd person camera settings
cameraRoll = true; // Roll the camera with the vehicle
cameraMaxDist = 4.8; // Far distance from vehicle
cameraOffset = 1.5; // Vertical offset from camera mount point
cameraLag = 0.26; // Velocity lag of camera
cameraDecay = 1.25; // Decay per sec. rate of velocity lag
// Rigid Body
mass = 380;
massCenter = "0 -0.2 0"; // Center of mass for rigid body
massBox = "0 0 0"; // Size of box used for moment of inertia,
// if zero it defaults to object bounding box
drag = 0.6; // Drag coefficient
bodyFriction = 0.6;
bodyRestitution = 0.4;
minImpactSpeed = 5; // Impacts over this invoke the script callback
softImpactSpeed = 5; // Play SoftImpact Sound
hardImpactSpeed = 15; // Play HardImpact Sound
integration = 8; // Physics integration: TickSec/Rate
collisionTol = 0.1; // Collision distance tolerance
contactTol = 0.1; // Contact velocity tolerance
// Engine
engineTorque = 3300; // Engine power
engineBrake = 600; // Braking when throttle is 0
brakeTorque = 8000; // When brakes are applied
maxWheelSpeed = 50; // Engine scale by current speed / max speed
// Energy
maxEnergy = 100;
jetForce = 3000;
minJetEnergy = 30;
jetEnergyDrain = 2;
// Sounds
// jetSound = ScoutThrustSound;
// engineSound = BuggyEngineSound;
// squealSound = ScoutSquealSound;
// softImpactSound = SoftImpactSound;
// hardImpactSound = HardImpactSound;
// wheelImpactSound = WheelImpactSound;
// explosion = VehicleExplosion;
};
//-----------------------------------------------------------------------------
function WheeledVehicleData::create(%block)
{
%obj = new WheeledVehicle() {
dataBlock = %block;
};
return(%obj);
}
//-----------------------------------------------------------------------------
function WheeledVehicleData::onAdd(%this,%obj)
{
// Setup the car with some defaults tires & springs
for (%i = %obj.getWheelCount() - 1; %i >= 0; %i--) {
%obj.setWheelTire(%i,DefaultCarTire);
%obj.setWheelSpring(%i,DefaultCarSpring);
%obj.setWheelPowered(%i,false);
}
// Steer front tires
%obj.setWheelSteering(0,1);
%obj.setWheelSteering(1,1);
// Only power the two rear wheels...
%obj.setWheelPowered(2,true);
%obj.setWheelPowered(3,true);
}
function WheeledVehicleData::onCollision(%this,%obj,%col,%vec,%speed)
{
// Collision with other objects, including items
}

View File

@ -0,0 +1,87 @@
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------
function centerPrintAll( %message, %time, %lines )
{
if( %lines $= "" || ((%lines > 3) || (%lines < 1)) )
%lines = 1;
%count = ClientGroup.getCount();
for (%i = 0; %i < %count; %i++)
{
%cl = ClientGroup.getObject(%i);
if( !%cl.isAIControlled() )
commandToClient( %cl, 'centerPrint', %message, %time, %lines );
}
}
function bottomPrintAll( %message, %time, %lines )
{
if( %lines $= "" || ((%lines > 3) || (%lines < 1)) )
%lines = 1;
%count = ClientGroup.getCount();
for (%i = 0; %i < %count; %i++)
{
%cl = ClientGroup.getObject(%i);
if( !%cl.isAIControlled() )
commandToClient( %cl, 'bottomPrint', %message, %time, %lines );
}
}
//-------------------------------------------------------------------------------------------------------
function centerPrint( %client, %message, %time, %lines )
{
if( %lines $= "" || ((%lines > 3) || (%lines < 1)) )
%lines = 1;
commandToClient( %client, 'CenterPrint', %message, %time, %lines );
}
function bottomPrint( %client, %message, %time, %lines )
{
if( %lines $= "" || ((%lines > 3) || (%lines < 1)) )
%lines = 1;
commandToClient( %client, 'BottomPrint', %message, %time, %lines );
}
//-------------------------------------------------------------------------------------------------------
function clearCenterPrint( %client )
{
commandToClient( %client, 'ClearCenterPrint');
}
function clearBottomPrint( %client )
{
commandToClient( %client, 'ClearBottomPrint');
}
//-------------------------------------------------------------------------------------------------------
function clearCenterPrintAll()
{
%count = ClientGroup.getCount();
for (%i = 0; %i < %count; %i++)
{
%cl = ClientGroup.getObject(%i);
if( !%cl.isAIControlled() )
commandToClient( %cl, 'ClearCenterPrint');
}
}
function clearBottomPrintAll()
{
%count = ClientGroup.getCount();
for (%i = 0; %i < %count; %i++)
{
%cl = ClientGroup.getObject(%i);
if( !%cl.isAIControlled() )
commandToClient( %cl, 'ClearBottomPrint');
}
}

View File

@ -0,0 +1,46 @@
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------
datablock TriggerData(CheckPointTrigger)
{
// The period is value is used to control how often the console
// onTriggerTick callback is called while there are any objects
// in the trigger. The default value is 100 MS.
tickPeriodMS = 100;
};
//-----------------------------------------------------------------------------
function CheckPointTrigger::onEnterTrigger(%this,%trigger,%obj)
{
Parent::onEnterTrigger(%this,%trigger,%obj);
if(%obj.client.nextCheck == %trigger.checkpoint)
{
if(%trigger.isLast)
{
// Player has completed a lap.
%obj.client.lap++;
if(%obj.client.lap >= $Game::Laps)
{
// Increase his score by 1.
%obj.client.incScore(1);
// End the game
cycleGame();
}
else {
%obj.client.nextCheck = 1;
commandToClient(%obj.client, 'IncreaseLapCounter');
}
}
else {
// Continue to the next one.
%obj.client.nextCheck++;
}
}
else
centerPrint(%obj.client, "Wrong Checkpoint!", 1, 1);
}

View File

@ -0,0 +1,57 @@
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Misc. server commands avialable to clients
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function serverCmdToggleCamera(%client)
{
%control = %client.getControlObject();
if (%control == %client.car)
{
%control = %client.camera;
%control.mode = toggleCameraFly;
}
else
{
%control = %client.car;
%control.mode = observerFly;
}
%client.setControlObject(%control);
}
function serverCmdDropPlayerAtCamera(%client)
{
if ($Server::TestCheats || isObject(EditorGui))
{
%client.player.setTransform(%client.camera.getTransform());
%client.player.setVelocity("0 0 0");
%client.setControlObject(%client.player);
}
}
function serverCmdDropCameraAtPlayer(%client)
{
%client.camera.setTransform(%client.player.getEyeTransform());
%client.camera.setVelocity("0 0 0");
%client.setControlObject(%client.camera);
}
//-----------------------------------------------------------------------------
function serverCmdReset(%client)
{
if (isObject(%client.car))
{
%client.car.delete();
%client.spawnCar();
%client.setControlObject(%client.car);
%client.nextCheck = 1;
}
}

View File

@ -0,0 +1,338 @@
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------
// Pause while looking over the end game screen (in secs)
$Game::EndGamePause = 10;
// Pause until race starts.
$Game::WaitTime = 5000;
// The amount of laps to race through.
$Game::Laps = 2;
//-----------------------------------------------------------------------------
// Functions that implement game-play
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function onServerCreated()
{
// Server::GameType is sent to the master server.
// This variable should uniquely identify your game and/or mod.
$Server::GameType = "Racing Starter Kit";
// Server::MissionType sent to the master server. Clients can
// filter servers based on mission type.
$Server::MissionType = "Racing";
// GameStartTime is the sim time the game started. Used to calculated
// game elapsed time.
$Game::StartTime = 0;
// Load up all datablocks, objects etc. This function is called when
// a server is constructed.
exec("./audioProfiles.cs");
exec("./camera.cs");
exec("./markers.cs");
exec("./triggers.cs");
exec("./shapeBase.cs");
exec("./staticShape.cs");
exec("./radiusDamage.cs");
exec("./car.cs");
exec("./checkpoint.cs");
// Keep track of when the game started
$Game::StartTime = $Sim::Time;
}
function onServerDestroyed()
{
// This function is called as part of a server shutdown.
}
//-----------------------------------------------------------------------------
function onMissionLoaded()
{
// Called by loadMission() once the mission is finished loading.
// Nothing special for now, just start up the game play.
startGame();
}
function onMissionEnded()
{
// Called by endMission(), right before the mission is destroyed
// Normally the game should be ended first before the next
// mission is loaded, this is here in case loadMission has been
// called directly. The mission will be ended if the server
// is destroyed, so we only need to cleanup here.
cancel($Game::Schedule);
$Game::Running = false;
$Game::Cycling = false;
}
//-----------------------------------------------------------------------------
function startGame()
{
if ($Game::Running) {
error("startGame: End the game first!");
return;
}
schedule($Game::WaitTime, 0, "countThree");
}
function countThree()
{
// Tell the client to count.
for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) {
%cl = ClientGroup.getObject( %clientIndex );
commandToClient(%cl, 'SetCounter', 3);
}
schedule(1000, 0, "countTwo");
}
function countTwo()
{
// Tell the client to count.
for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) {
%cl = ClientGroup.getObject( %clientIndex );
commandToClient(%cl, 'SetCounter', 2);
}
schedule(1000, 0, "countOne");
}
function countOne()
{
// Tell the client to count.
for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) {
%cl = ClientGroup.getObject( %clientIndex );
commandToClient(%cl, 'SetCounter', 1);
}
schedule(1000, 0, "startRace");
}
function startRace()
{
// Inform the client we're starting up
for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) {
%cl = ClientGroup.getObject( %clientIndex );
commandToClient(%cl, 'GameStart');
// Other client specific setup..
%cl.lap = 0;
%cl.nextCheck = 1;
%cl.setControlObject(%cl.car);
%cl.camera.setFlyMode();
}
// Start the game timer
// if ($Game::Duration)
// $Game::Schedule = schedule($Game::Duration * 1000, 0, "onGameDurationEnd" );
$Game::Running = true;
$Game::Running = true;
}
function endGame()
{
if (!$Game::Running) {
error("endGame: No game running!");
return;
}
// Stop any game timers
cancel($Game::Schedule);
// Inform the client the game is over
for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) {
%cl = ClientGroup.getObject( %clientIndex );
commandToClient(%cl, 'GameEnd');
}
// Delete all the temporary mission objects
resetMission();
$Game::Running = false;
}
function onGameDurationEnd()
{
// This "redirect" is here so that we can abort the game cycle if
// the $Game::Duration variable has been cleared, without having
// to have a function to cancel the schedule.
if ($Game::Duration && !isObject(EditorGui))
cycleGame();
}
//-----------------------------------------------------------------------------
function cycleGame()
{
// This is setup as a schedule so that this function can be called
// directly from object callbacks. Object callbacks have to be
// carefull about invoking server functions that could cause
// their object to be deleted.
if (!$Game::Cycling) {
$Game::Cycling = true;
$Game::Schedule = schedule(0, 0, "onCycleExec");
}
}
function onCycleExec()
{
// End the current game and start another one, we'll pause for a little
// so the end game victory screen can be examined by the clients.
endGame();
$Game::Schedule = schedule($Game::EndGamePause * 1000, 0, "onCyclePauseEnd");
}
function onCyclePauseEnd()
{
$Game::Cycling = false;
// Just cycle through the missions for now.
%search = $Server::MissionFileSpec;
for (%file = findFirstFile(%search); %file !$= ""; %file = findNextFile(%search)) {
if (%file $= $Server::MissionFile) {
// Get the next one, back to the first if there
// is no next.
%file = findNextFile(%search);
if (%file $= "")
%file = findFirstFile(%search);
break;
}
}
loadMission(%file);
}
//-----------------------------------------------------------------------------
// GameConnection Methods
// These methods are extensions to the GameConnection class. Extending
// GameConnection make is easier to deal with some of this functionality,
// but these could also be implemented as stand-alone functions.
//-----------------------------------------------------------------------------
function GameConnection::onClientEnterGame(%this)
{
commandToClient(%this, 'SyncClock', $Sim::Time - $Game::StartTime);
commandToClient(%this, 'SetMaxLaps', $Game::Laps);
// Create a new camera object.
%this.camera = new Camera() {
dataBlock = Observer;
};
MissionCleanup.add( %this.camera );
%this.camera.scopeToClient(%this);
// Client controls the camera by default.
%this.setControlObject(%this.camera);
if(!$Game::Running)
{
// Create a car object.
%this.spawnCar();
// Orbit the camera around the car
%this.camera.setOrbitMode(%this.car, %this.car.getTransform(), 0.5, 4.5, 4.5);
}
}
function GameConnection::onClientLeaveGame(%this)
{
if (isObject(%this.camera))
%this.camera.delete();
if (isObject(%this.car))
%this.car.delete();
}
//-----------------------------------------------------------------------------
function GameConnection::onLeaveMissionArea(%this)
{
// The control objects invoked this method when they
// move out of the mission area.
}
function GameConnection::onEnterMissionArea(%this)
{
// The control objects invoked this method when they
// move back into the mission area.
}
//-----------------------------------------------------------------------------
function GameConnection::spawnCar(%this)
{
// Combination create player and drop him somewhere
%spawnPoint = pickSpawnPoint();
%this.createCar(%spawnPoint);
}
//-----------------------------------------------------------------------------
function GameConnection::createCar(%this, %spawnPoint)
{
if (%this.car > 0) {
// The client should not have a player currently
// assigned. Assigning a new one could result in
// a player ghost.
error( "Attempting to create an angus ghost!" );
}
// Create the player object
%car = new WheeledVehicle() {
dataBlock = DefaultCar;
client = %this;
};
MissionCleanup.add(%car);
// Player setup...
%car.setTransform(%spawnPoint);
%car.setShapeName(%this.name);
// Update the camera to start with the player
%this.camera.setTransform(%car.getEyeTransform());
// Give the client control of the player
%this.car = %car;
}
//-----------------------------------------------------------------------------
// Support functions
//-----------------------------------------------------------------------------
function pickSpawnPoint()
{
%groupName = "MissionGroup/PlayerDropPoints";
%group = nameToID(%groupName);
if (%group != -1) {
%count = %group.getCount();
if (%count != 0) {
%index = getRandom(%count-1);
%spawn = %group.getObject(%index);
return %spawn.getTransform();
}
else
error("No spawn points found in " @ %groupName);
}
else
error("Missing spawn points group " @ %groupName);
// Could be no spawn points, in which case we'll stick the
// player at the center of the world.
return "0 0 300 1 0 0 0";
}

View File

@ -0,0 +1,37 @@
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------
datablock MissionMarkerData(WayPointMarker)
{
category = "Misc";
shapeFile = "~/data/shapes/markers/octahedron.dts";
};
datablock MissionMarkerData(SpawnSphereMarker)
{
category = "Misc";
shapeFile = "~/data/shapes/markers/octahedron.dts";
};
//------------------------------------------------------------------------------
// - serveral marker types may share MissionMarker datablock type
function MissionMarkerData::create(%block)
{
switch$(%block)
{
case "WayPointMarker":
%obj = new WayPoint() {
dataBlock = %block;
};
return(%obj);
case "SpawnSphereMarker":
%obj = new SpawnSphere() {
datablock = %block;
};
return(%obj);
}
return(-1);
}

View File

@ -0,0 +1,53 @@
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------
// Support function which applies damage to objects within the radius of
// some effect, usually an explosion. This function will also optionally
// apply an impulse to each object.
function radiusDamage(%sourceObject, %position, %radius, %damage, %damageType, %impulse)
{
// Use the container system to iterate through all the objects
// within our explosion radius. We'll apply damage to all ShapeBase
// objects.
InitContainerRadiusSearch(%position, %radius, $TypeMasks::ShapeBaseObjectType);
%halfRadius = %radius / 2;
while ((%targetObject = containerSearchNext()) != 0) {
// Calculate how much exposure the current object has to
// the explosive force. The object types listed are objects
// that will block an explosion. If the object is totally blocked,
// then no damage is applied.
%coverage = calcExplosionCoverage(%position, %targetObject,
$TypeMasks::InteriorObjectType | $TypeMasks::TerrainObjectType |
$TypeMasks::ForceFieldObjectType | $TypeMasks::VehicleObjectType);
if (%coverage == 0)
continue;
// Radius distance subtracts out the length of smallest bounding
// box axis to return an appriximate distance to the edge of the
// object's bounds, as opposed to the distance to it's center.
%dist = containerSearchCurrRadiusDist();
// Calculate a distance scale for the damage and the impulse.
// Full damage is applied to anything less than half the radius away,
// linear scale from there.
%distScale = (%dist < %halfRadius)? 1.0:
1.0 - ((%dist - %halfRadius) / %halfRadius);
// Apply the damage
%targetObject.damage(%sourceObject, %position,
%damage * %coverage * %distScale, %damageType);
// Apply the impulse
if (%impulse) {
%impulseVec = VectorSub(%targetObject.getWorldBoxCenter(), %position);
%impulseVec = VectorNormalize(%impulseVec);
%impulseVec = VectorScale(%impulseVec, %impulse * %distScale);
%targetObject.applyImpulse(%position, %impulseVec);
}
}
}

View File

@ -0,0 +1,60 @@
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------
// This file contains ShapeBase methods used by all the derived classes
//-----------------------------------------------------------------------------
// ShapeBase object
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function ShapeBase::damage(%this, %sourceObject, %position, %damage, %damageType)
{
// All damage applied by one object to another should go through this
// method. This function is provided to allow objects some chance of
// overriding or processing damage values and types. As opposed to
// having weapons call ShapeBase::applyDamage directly.
// Damage is redirected to the datablock, this is standard proceedure
// for many built in callbacks.
%this.getDataBlock().damage(%this, %sourceObject, %position, %damage, %damageType);
}
//-----------------------------------------------------------------------------
function ShapeBase::setDamageDt(%this, %damageAmount, %damageType)
{
// This function is used to apply damage over time. The damage
// is applied at a fixed rate (50 ms). Damage could be applied
// over time using the built in ShapBase C++ repair functions
// (using a neg. repair), but this has the advantage of going
// through the normal script channels.
if (%obj.getState() !$= "Dead") {
%this.damage(0, "0 0 0", %damageAmount, %damageType);
%obj.damageSchedule = %obj.schedule(50, "setDamageDt", %damageAmount, %damageType);
}
else
%obj.damageSchedule = "";
}
function ShapeBase::clearDamageDt(%this)
{
if (%obj.damageSchedule !$= "") {
cancel(%obj.damageSchedule);
%obj.damageSchedule = "";
}
}
//-----------------------------------------------------------------------------
// ShapeBase datablock
//-----------------------------------------------------------------------------
function ShapeBaseData::damage(%this, %obj, %position, %source, %amount, %damageType)
{
// Ignore damage by default. This empty method is here to
// avoid console warnings.
}

View File

@ -0,0 +1,19 @@
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Hook into the mission editor.
function StaticShapeData::create(%data)
{
// The mission editor invokes this method when it wants to create
// an object of the given datablock type.
%obj = new StaticShape() {
dataBlock = %data;
};
return %obj;
}

View File

@ -0,0 +1,52 @@
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// DefaultTrigger is used by the mission editor. This is also an example
// of trigger methods and callbacks.
datablock TriggerData(DefaultTrigger)
{
// The period is value is used to control how often the console
// onTriggerTick callback is called while there are any objects
// in the trigger. The default value is 100 MS.
tickPeriodMS = 100;
};
//-----------------------------------------------------------------------------
function DefaultTrigger::onEnterTrigger(%this,%trigger,%obj)
{
// This method is called whenever an object enters the %trigger
// area, the object is passed as %obj. The default onEnterTrigger
// method (in the C++ code) invokes the ::onTrigger(%trigger,1) method on
// every object (whatever it's type) in the same group as the trigger.
Parent::onEnterTrigger(%this,%trigger,%obj);
}
function DefaultTrigger::onLeaveTrigger(%this,%trigger,%obj)
{
// This method is called whenever an object leaves the %trigger
// area, the object is passed as %obj. The default onLeaveTrigger
// method (in the C++ code) invokes the ::onTrigger(%trigger,0) method on
// every object (whatever it's type) in the same group as the trigger.
Parent::onLeaveTrigger(%this,%trigger,%obj);
}
function DefaultTrigger::onTickTrigger(%this,%trigger)
{
// This method is called every tickPerioMS, as long as any
// objects intersect the trigger. The default onTriggerTick
// method (in the C++ code) invokes the ::onTriggerTick(%trigger) method on
// every object (whatever it's type) in the same group as the trigger.
// You can iterate through the objects in the list by using these
// methods:
// %this.getNumObjects();
// %this.getObject(n);
Parent::onTickTrigger(%this,%trigger);
}