//-----------------------------------------------------------------------------
// AI Turret
//-----------------------------------------------------------------------------
datablock AITurretShapeData(AITurret)
{
category = "Turrets";
shapeFile = "art/shapes/weapons/Turret/Turret_Legs.DAE";
maxDamage = 70;
destroyedLevel = 70;
explosion = GrenadeExplosion;
simpleServerCollision = false;
zRotOnly = false;
// Rotation settings
minPitch = 15;
maxPitch = 80;
maxHeading = 90;
headingRate = 50;
pitchRate = 50;
// Scan settings
maxScanPitch = 10;
maxScanHeading = 30;
maxScanDistance = 20;
trackLostTargetTime = 2;
maxWeaponRange = 30;
weaponLeadVelocity = 0;
// Weapon mounting
numWeaponMountPoints = 1;
weapon[0] = AITurretHead;
weaponAmmo[0] = AITurretAmmo;
weaponAmmoAmount[0] = 10000;
maxInv[AITurretHead] = 1;
maxInv[AITurretAmmo] = 10000;
// Initial start up state
stateName[0] = "Preactivate";
stateTransitionOnAtRest[0] = "Scanning";
stateTransitionOnNotAtRest[0] = "Thrown";
// Scan for targets
stateName[1] = "Scanning";
stateScan[1] = true;
stateTransitionOnTarget[1] = "Target";
stateSequence[1] = "scan";
stateScript[1] = "OnScanning";
// Have a target
stateName[2] = "Target";
stateTransitionOnNoTarget[2] = "NoTarget";
stateTransitionOnTimeout[2] = "Firing";
stateTimeoutValue[2] = 2.0;
stateScript[2] = "OnTarget";
// Fire at target
stateName[3] = "Firing";
stateFire[3] = true;
stateTransitionOnNoTarget[3] = "NoTarget";
stateScript[3] = "OnFiring";
// Lost target
stateName[4] = "NoTarget";
stateTransitionOnTimeout[4] = "Scanning";
stateTimeoutValue[4] = 2.0;
stateScript[4] = "OnNoTarget";
// Player thrown turret
stateName[5] = "Thrown";
stateTransitionOnAtRest[5] = "Deploy";
stateSequence[5] = "throw";
stateScript[5] = "OnThrown";
// Player thrown turret is deploying
stateName[6] = "Deploy";
stateTransitionOnTimeout[6] = "Scanning";
stateTimeoutValue[6] = 2.5;
stateSequence[6] = "deploy";
stateScaleAnimation[6] = true;
stateScript[6] = "OnDeploy";
// Special state that is set when the turret is destroyed.
// This state is set in the onDestroyed() callback.
stateName[7] = "Destroyed";
stateSequence[7] = "destroyed";
};
//-----------------------------------------------------------------------------
// Deployable AI Turret
//-----------------------------------------------------------------------------
datablock AITurretShapeData(DeployableTurret : AITurret)
{
// Mission editor category
category = "Weapon";
className = "DeployableTurretWeapon";
startLoaded = false;
// Basic Item properties
mass = 1.5;
elasticity = 0.1;
friction = 0.6;
simpleServerCollision = false;
// Dynamic properties defined by the scripts
PreviewImage = 'turret.png';
pickUpName = "a deployable turret";
description = "Deployable Turret";
image = DeployableTurretImage;
reticle = "blank";
zoomReticle = 'blank';
};
// ----------------------------------------------------------------------------
// AITurretShapeData
// ----------------------------------------------------------------------------
function AITurretShapeData::onAdd(%this, %obj)
{
Parent::onAdd(%this, %obj);
%obj.mountable = false;
}
// Player has thrown a deployable turret. This copies from ItemData::onThrow()
function AITurretShapeData::onThrow(%this, %user, %amount)
{
// Remove the object from the inventory
if (%amount $= "")
%amount = 1;
if (%this.maxInventory !$= "")
if (%amount > %this.maxInventory)
%amount = %this.maxInventory;
if (!%amount)
return 0;
%user.decInventory(%this,%amount);
// Construct the actual object in the world, and add it to
// the mission group so it's cleaned up when the mission is
// done. The turret's rotation matches the player's.
%rot = %user.getEulerRotation();
%obj = new AITurretShape()
{
datablock = %this;
rotation = "0 0 1 " @ getWord(%rot, 2);
count = 1;
sourceObject = %user;
client = %user.client;
isAiControlled = true;
};
MissionGroup.add(%obj);
// Let the turret know that we're a firend
%obj.addToIgnoreList(%user);
// We need to add this turret to a list on the client so that if we die,
// the turret will still ignore our player.
%client = %user.client;
if (%client)
{
if (!%client.ownedTurrets)
{
%client.ownedTurrets = new SimSet();
}
<span class="comment">// Go through the client's owned turret list. Make sure we're</span>
<span class="comment">// a friend of every turret and every turret is a friend of ours.</span>
<span class="comment">// Commence hugging!</span>
<span class="keywordflow">for</span> (%i=0; %i<%client.ownedTurrets.getCount(); %i++)
{
%turret = %client.ownedTurrets.getObject(%i);
%turret.addToIgnoreList(%obj);
%obj.addToIgnoreList(%turret);
}
<span class="comment">// Add ourselves to the client's owned list.</span>
%client.ownedTurrets.add(%obj);
}
return %obj;
}
function AITurretShapeData::onDestroyed(%this, %turret, %lastState)
{
// This method is invoked by the ShapeBase code whenever the
// object's damage state changes.
%turret.playAudio(0, TurretDestroyed);
%turret.setAllGunsFiring(false);
%turret.resetTarget();
%turret.setTurretState( "Destroyed", true );
// Set the weapons to destoryed
for(%i = 0; %i < %this.numWeaponMountPoints; %i++)
{
%turret.setImageGenericTrigger(%i, 0, true);
}
Parent::onDestroyed(%this, %turret, %lastState);
}
function AITurretShapeData::OnScanning(%this, %turret)
{
//echo("AITurretShapeData::OnScanning: " SPC %this SPC %turret);
%turret.startScanForTargets();
%turret.playAudio(0, TurretScanningSound);
}
function AITurretShapeData::OnTarget(%this, %turret)
{
//echo("AITurretShapeData::OnTarget: " SPC %this SPC %turret);
%turret.startTrackingTarget();
%turret.playAudio(0, TargetAquiredSound);
}
function AITurretShapeData::OnNoTarget(%this, %turret)
{
//echo("AITurretShapeData::OnNoTarget: " SPC %this SPC %turret);
%turret.setAllGunsFiring(false);
%turret.recenterTurret();
%turret.playAudio(0, TargetLostSound);
}
function AITurretShapeData::OnFiring(%this, %turret)
{
//echo("AITurretShapeData::OnFiring: " SPC %this SPC %turret);
%turret.setAllGunsFiring(true);
}
function AITurretShapeData::OnThrown(%this, %turret)
{
//echo("AITurretShapeData::OnThrown: " SPC %this SPC %turret);
%turret.playAudio(0, TurretThrown);
}
function AITurretShapeData::OnDeploy(%this, %turret)
{
//echo("AITurretShapeData::OnDeploy: " SPC %this SPC %turret);
// Set the weapons to loaded
for(%i = 0; %i < %this.numWeaponMountPoints; %i++)
{
%turret.setImageLoaded(%i, true);
}
%turret.playAudio(0, TurretActivatedSound);
}