Game Development Community

explain code

by John · in Technical Issues · 07/12/2011 (11:11 am) · 2 replies

Is someone can explain thease code detail and step by step to me.
/ Load dts shapes and merge animations
Exec("~/data/models/avatars/beast/player.cs");

// Timeouts for corpse deletion.
$CorpseTimeout = 30000;

//
$PlayerDeathAnim::TorsoFrontFallForward = 1;
$PlayerDeathAnim::TorsoFrontFallBack = 2;
$PlayerDeathAnim::TorsoBackFallForward = 3;
$PlayerDeathAnim::TorsoLeftSpinDeath = 4;
$PlayerDeathAnim::TorsoRightSpinDeath = 5;
$PlayerDeathAnim::LegsLeftGimp = 6;
$PlayerDeathAnim::LegsRightGimp = 7;
$PlayerDeathAnim::TorsoBackFallForward = 8;
$PlayerDeathAnim::HeadFrontDirect = 9;
$PlayerDeathAnim::HeadBackFallForward = 10;
$PlayerDeathAnim::ExplosionBlowBack = 11;

//----------------------------------------------------------------------------
// Splash
//----------------------------------------------------------------------------

datablock ParticleData(PlayerSplashMist)
{
dragCoefficient = 2.0;
gravityCoefficient = -0.05;
inheritedVelFactor = 0.0;
constantAcceleration = 0.0;
lifetimeMS = 400;
lifetimeVarianceMS = 100;
useInvAlpha = false;
spinRandomMin = -90.0;
spinRandomMax = 500.0;
textureName = "~/data/particles/splash";
colors[0] = "0.7 0.8 1.0 1.0";
colors[1] = "0.7 0.8 1.0 0.5";
colors[2] = "0.7 0.8 1.0 0.0";
sizes[0] = 0.5;
sizes[1] = 0.5;
sizes[2] = 0.8;
times[0] = 0.0;
times[1] = 0.5;
times[2] = 1.0;
};

datablock ParticleEmitterData(PlayerSplashMistEmitter)
{
ejectionPeriodMS = 5;
periodVarianceMS = 0;
ejectionVelocity = 3.0;
velocityVariance = 2.0;
ejectionOffset = 0.0;
thetaMin = 85;
thetaMax = 85;
phiReferenceVel = 0;
phiVariance = 360;
overrideAdvances = false;
lifetimeMS = 250;
particles = "PlayerSplashMist";
};


datablock ParticleData(PlayerBubbleParticle)
{
dragCoefficient = 0.0;
gravityCoefficient = -0.50;
inheritedVelFactor = 0.0;
constantAcceleration = 0.0;
lifetimeMS = 400;
lifetimeVarianceMS = 100;
useInvAlpha = false;
textureName = "~/data/particles/splash";
colors[0] = "0.7 0.8 1.0 0.4";
colors[1] = "0.7 0.8 1.0 0.4";
colors[2] = "0.7 0.8 1.0 0.0";
sizes[0] = 0.1;
sizes[1] = 0.3;
sizes[2] = 0.3;
times[0] = 0.0;
times[1] = 0.5;
times[2] = 1.0;
};

datablock ParticleEmitterData(PlayerBubbleEmitter)
{
ejectionPeriodMS = 1;
periodVarianceMS = 0;
ejectionVelocity = 2.0;
ejectionOffset = 0.5;
velocityVariance = 0.5;
thetaMin = 0;
thetaMax = 80;
phiReferenceVel = 0;
phiVariance = 360;
overrideAdvances = false;
particles = "PlayerBubbleParticle";
};

datablock ParticleData(PlayerFoamParticle)
{
dragCoefficient = 2.0;
gravityCoefficient = -0.05;
inheritedVelFactor = 0.0;
constantAcceleration = 0.0;
lifetimeMS = 400;
lifetimeVarianceMS = 100;
useInvAlpha = false;
spinRandomMin = -90.0;
spinRandomMax = 500.0;
textureName = "~/data/particles/splash";
colors[0] = "0.7 0.8 1.0 0.20";
colors[1] = "0.7 0.8 1.0 0.20";
colors[2] = "0.7 0.8 1.0 0.00";
sizes[0] = 0.2;
sizes[1] = 0.4;
sizes[2] = 1.6;
times[0] = 0.0;
times[1] = 0.5;
times[2] = 1.0;
};

datablock ParticleEmitterData(PlayerFoamEmitter)
{
ejectionPeriodMS = 10;
periodVarianceMS = 0;
ejectionVelocity = 3.0;
velocityVariance = 1.0;
ejectionOffset = 0.0;
thetaMin = 85;
thetaMax = 85;
phiReferenceVel = 0;
phiVariance = 360;
overrideAdvances = false;
particles = "PlayerFoamParticle";
};


datablock ParticleData( PlayerFoamDropletsParticle )
{
dragCoefficient = 1;
gravityCoefficient = 0.2;
inheritedVelFactor = 0.2;
constantAcceleration = -0.0;
lifetimeMS = 600;
lifetimeVarianceMS = 0;
textureName = "~/data/particles/splash";
colors[0] = "0.7 0.8 1.0 1.0";
colors[1] = "0.7 0.8 1.0 0.5";
colors[2] = "0.7 0.8 1.0 0.0";
sizes[0] = 0.8;
sizes[1] = 0.3;
sizes[2] = 0.0;
times[0] = 0.0;
times[1] = 0.5;
times[2] = 1.0;
};

datablock ParticleEmitterData( PlayerFoamDropletsEmitter )
{
ejectionPeriodMS = 7;
periodVarianceMS = 0;
ejectionVelocity = 2;
velocityVariance = 1.0;
ejectionOffset = 0.0;
thetaMin = 60;
thetaMax = 80;
phiReferenceVel = 0;
phiVariance = 360;
overrideAdvances = false;
orientParticles = true;
particles = "PlayerFoamDropletsParticle";
};


datablock ParticleData( PlayerSplashParticle )
{
dragCoefficient = 1;
gravityCoefficient = 0.2;
inheritedVelFactor = 0.2;
constantAcceleration = -0.0;
lifetimeMS = 600;
lifetimeVarianceMS = 0;
colors[0] = "0.7 0.8 1.0 1.0";
colors[1] = "0.7 0.8 1.0 0.5";
colors[2] = "0.7 0.8 1.0 0.0";
sizes[0] = 0.5;
sizes[1] = 0.5;
sizes[2] = 0.5;
times[0] = 0.0;
times[1] = 0.5;
times[2] = 1.0;
};

datablock ParticleEmitterData( PlayerSplashEmitter )
{
ejectionPeriodMS = 1;
periodVarianceMS = 0;
ejectionVelocity = 3;
velocityVariance = 1.0;
ejectionOffset = 0.0;
thetaMin = 60;
thetaMax = 80;
phiReferenceVel = 0;
phiVariance = 360;
overrideAdvances = false;
orientParticles = true;
lifetimeMS = 100;
particles = "PlayerSplashParticle";
};

datablock SplashData(PlayerSplash)
{
numSegments = 15;
ejectionFreq = 15;
ejectionAngle = 40;
ringLifetime = 0.5;
lifetimeMS = 300;
velocity = 4.0;
startRadius = 0.0;
acceleration = -3.0;
texWrap = 5.0;

texture = "~/data/particles/splash";

emitter[0] = PlayerSplashEmitter;
emitter[1] = PlayerSplashMistEmitter;

colors[0] = "0.7 0.8 1.0 0.0";
colors[1] = "0.7 0.8 1.0 0.3";
colors[2] = "0.7 0.8 1.0 0.7";
colors[3] = "0.7 0.8 1.0 0.0";
times[0] = 0.0;
times[1] = 0.4;
times[2] = 0.8;
times[3] = 1.0;
};


//----------------------------------------------------------------------------
// Foot puffs
//----------------------------------------------------------------------------

datablock ParticleData(LightPuff)
{
dragCoefficient = 2.0;
gravityCoefficient = -0.01;
inheritedVelFactor = 0.6;
constantAcceleration = 0.0;
lifetimeMS = 800;
lifetimeVarianceMS = 100;
useInvAlpha = true;
spinRandomMin = -35.0;
spinRandomMax = 35.0;
colors[0] = "1.0 1.0 1.0 1.0";
colors[1] = "1.0 1.0 1.0 0.0";
sizes[0] = 0.1;
sizes[1] = 0.8;
times[0] = 0.3;
times[1] = 1.0;
};

datablock ParticleEmitterData(LightPuffEmitter)
{
ejectionPeriodMS = 35;
periodVarianceMS = 10;
ejectionVelocity = 0.2;
velocityVariance = 0.1;
ejectionOffset = 0.0;
thetaMin = 20;
thetaMax = 60;
phiReferenceVel = 0;
phiVariance = 360;
overrideAdvances = false;
useEmitterColors = true;
particles = "LightPuff";
};

//----------------------------------------------------------------------------
// Liftoff dust
//----------------------------------------------------------------------------

datablock ParticleData(LiftoffDust)
{
dragCoefficient = 1.0;
gravityCoefficient = -0.01;
inheritedVelFactor = 0.0;
constantAcceleration = 0.0;
lifetimeMS = 1000;
lifetimeVarianceMS = 100;
useInvAlpha = true;
spinRandomMin = -90.0;
spinRandomMax = 500.0;
colors[0] = "1.0 1.0 1.0 1.0";
sizes[0] = 1.0;
times[0] = 1.0;
};

datablock ParticleEmitterData(LiftoffDustEmitter)
{
ejectionPeriodMS = 5;
periodVarianceMS = 0;
ejectionVelocity = 2.0;
velocityVariance = 0.0;
ejectionOffset = 0.0;
thetaMin = 90;
thetaMax = 90;
phiReferenceVel = 0;
phiVariance = 360;
overrideAdvances = false;
useEmitterColors = true;
particles = "LiftoffDust";
};


//----------------------------------------------------------------------------

datablock DecalData(PlayerFootprint)
{
sizeX = 0.25;
sizeY = 0.25;
textureName = "~/data/models/avatars/beast/footprint";
};

datablock DebrisData( PlayerDebris )
{
explodeOnMaxBounce = false;

elasticity = 0.15;
friction = 0.5;

lifetime = 4.0;
lifetimeVariance = 0.0;

minSpinSpeed = 40;
maxSpinSpeed = 600;

numBounces = 5;
bounceVariance = 0;

staticOnMaxBounce = true;
gravModifier = 1.0;

useRadiusMass = true;
baseRadius = 1;

velocity = 20.0;
velocityVariance = 12.0;
};

datablock PlayerData(BeastAvatar)
{
renderFirstPerson = false;
emap = true;

className = AIBeast;
shapeFile = "~/data/models/avatars/beast/player.dts";
cameraMaxDist = 3;
computeCRC = true;

canObserve = true;
cmdCategory = "Clients";

cameraDefaultFov = 90.0;
cameraMinFov = 5.0;
cameraMaxFov = 120.0;

debrisShapeName = "~/data/models/avatars/beast/debris_player.dts";
debris = playerDebris;

aiAvoidThis = true;

minLookAngle = -1.4;
maxLookAngle = 1.4;
maxFreelookAngle = 3.0;

mass = 90;
drag = 0.3;
maxdrag = 0.4;
density = 10;
maxDamage = 100;
maxEnergy = 60;
repairRate = 0.33;
energyPerDamagePoint = 75.0;

rechargeRate = 0.256;

runForce = 48 * 90;
runEnergyDrain = 0;
minRunEnergy = 0;
maxForwardSpeed = 14;
maxBackwardSpeed = 13;
maxSideSpeed = 13;

maxUnderwaterForwardSpeed = 8.4;
maxUnderwaterBackwardSpeed = 7.8;
maxUnderwaterSideSpeed = 7.8;

jumpForce = 8.3 * 90;
jumpEnergyDrain = 0;
minJumpEnergy = 0;
jumpDelay = 15;

recoverDelay = 9;
recoverRunForceScale = 1.2;

minImpactSpeed = 45;
speedDamageScale = 0.4;

boundingBox = "1.2 1.2 2.3";
pickupRadius = 0.75;

// Damage location details
boxNormalHeadPercentage = 0.83;
boxNormalTorsoPercentage = 0.49;
boxHeadLeftPercentage = 0;
boxHeadRightPercentage = 1;
boxHeadBackPercentage = 0;
boxHeadFrontPercentage = 1;

// Foot Prints
decalData = PlayerFootprint;
decalOffset = 0.25;

footPuffEmitter = LightPuffEmitter;
footPuffNumParts = 10;
footPuffRadius = 0.25;

dustEmitter = LiftoffDustEmitter;

splash = PlayerSplash;
splashVelocity = 4.0;
splashAngle = 67.0;
splashFreqMod = 300.0;
splashVelEpsilon = 0.60;
bubbleEmitTime = 0.4;
splashEmitter[0] = PlayerFoamDropletsEmitter;
splashEmitter[1] = PlayerFoamEmitter;
splashEmitter[2] = PlayerBubbleEmitter;
mediumSplashSoundVelocity = 10.0;
hardSplashSoundVelocity = 20.0;
exitSplashSoundVelocity = 5.0;

// Controls over slope of runnable/jumpable surfaces
runSurfaceAngle = 70;
jumpSurfaceAngle = 80;

minJumpSpeed = 20;
maxJumpSpeed = 30;

horizMaxSpeed = 68;
horizResistSpeed = 33;
horizResistFactor = 0.35;

upMaxSpeed = 80;
upResistSpeed = 25;
upResistFactor = 0.3;

footstepSplashHeight = 0.35;

//NOTE: some sounds commented out until wav's are available

// Footstep Sounds
// FootSoftSound = FootLightSoftSound;
// FootHardSound = FootLightHardSound;
// FootMetalSound = FootLightMetalSound;
// FootSnowSound = FootLightSnowSound;
// FootShallowSound = FootLightShallowSplashSound;
// FootWadingSound = FootLightWadingSound;
// FootUnderwaterSound = FootLightUnderwaterSound;

//FootBubblesSound = FootLightBubblesSound;
//movingBubblesSound = ArmorMoveBubblesSound;
//waterBreathSound = WaterBreathMaleSound;

//impactSoftSound = ImpactLightSoftSound;
//impactHardSound = ImpactLightHardSound;
//impactMetalSound = ImpactLightMetalSound;
//impactSnowSound = ImpactLightSnowSound;

//impactWaterEasy = ImpactLightWaterEasySound;
//impactWaterMedium = ImpactLightWaterMediumSound;
//impactWaterHard = ImpactLightWaterHardSound;

groundImpactMinSpeed = 10.0;
groundImpactShakeFreq = "4.0 4.0 4.0";
groundImpactShakeAmp = "1.0 1.0 1.0";
groundImpactShakeDuration = 0.8;
groundImpactShakeFalloff = 10.0;

//exitingWater = ExitingWaterLightSound;

observeParameters = "0.5 4.5 4.5";

// Allowable Inventory Items
maxInv[BulletAmmo] = 20;
maxInv[RifleAmmo] = 100;
maxInv[CrossbowAmmo] = 50;
maxInv[Crossbow] = 1;
maxInv[Rifle] = 1;

// ai properties

index = 0;
look = 0;
range = 0;
alertness = 10;
attention = 1;
threatAttention = 1;
aggression = 1.5;
};


//----------------------------------------------------------------------------
// Armor Datablock methods
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------

function AIBeast::onAdd(%this,%obj)
{
// Vehicle timeout
%obj.mountVehicle = true;

// Default dynamic armor stats
%obj.setRechargeRate(%this.rechargeRate);
%obj.setRepairRate(0);
}

function AIBeast::onRemove(%this, %obj)
{
if (%obj.client.player == %obj)
%obj.client.player = 0;
}

function AIBeast::onNewDataBlock(%this,%obj)
{
}


//----------------------------------------------------------------------------

function AIBeast::onMount(%this,%obj,%vehicle,%node)
{
if (%node == 0) {
%obj.setTransform("0 0 0 0 0 1 0");
%obj.setActionThread(%vehicle.getDatablock().mountPose[%node],true,true);
%obj.lastWeapon = %obj.getMountedImage($WeaponSlot);

%obj.unmountImage($WeaponSlot);
%obj.setControlObject(%vehicle);
%obj.client.setObjectActiveImage(%vehicle, 2);
}
}

function AIBeast::onUnmount( %this, %obj, %vehicle, %node )
{
if (%node == 0)
%obj.mountImage(%obj.lastWeapon, $WeaponSlot);
}

function AIBeast::doDismount(%this, %obj, %forced)
{
// This function is called by player.cc when the jump trigger
// is true while mounted
if (!%obj.isMounted())
return;

// Position above dismount point
%pos = getWords(%obj.getTransform(), 0, 2);
%oldPos = %pos;
%vec[0] = " 0 0 1";
%vec[1] = " 0 0 1";
%vec[2] = " 0 0 -1";
%vec[3] = " 1 0 0";
%vec[4] = "-1 0 0";
%impulseVec = "0 0 0";
%vec[0] = MatrixMulVector( %obj.getTransform(), %vec[0]);

// Make sure the point is valid
%pos = "0 0 0";
%numAttempts = 5;
%success = -1;
for (%i = 0; %i < %numAttempts; %i++) {
%pos = VectorAdd(%oldPos, VectorScale(%vec[%i], 3));
if (%obj.checkDismountPoint(%oldPos, %pos)) {
%success = %i;
%impulseVec = %vec[%i];
break;
}
}
if (%forced && %success == -1)
%pos = %oldPos;

%obj.mountVehicle = false;
%obj.schedule(4000, "setMountVehicle", true);

// Position above dismount point
%obj.setTransform(%pos);
%obj.applyImpulse(%pos, VectorScale(%impulseVec, %obj.getDataBlock().mass));
%obj.setPilot(false);
%obj.vehicleTurret = "";
}


//----------------------------------------------------------------------------

function AIBeast::onCollision(%this,%obj,%col)
{
if (%obj.getState() $= "Dead")
return;

// Try and pickup all items
if (%col.getClassName() $= "Item")
%obj.pickup(%col);

// Mount vehicles
%this = %col.getDataBlock();
if ((%this.className $= WheeledVehicleData) && %obj.mountVehicle &&
%obj.getState() $= "Move" && %col.mountable) {

// Only mount drivers for now.
%node = 0;
%col.mountObject(%obj,%node);
%obj.mVehicle = %col;
}
}

function AIBeast::onImpact(%this, %obj, %collidedObject, %vec, %vecLen)
{
%obj.damage(0, VectorAdd(%obj.getPosition(),%vec),
%vecLen * %this.speedDamageScale, "Impact");
}


//----------------------------------------------------------------------------

function AIBeast::damage(%this, %obj, %sourceObject, %position, %damage, %damageType)
{
if (%obj.getState() $= "Dead")
return;
%obj.applyDamage(%damage);
%location = "Body";

// Deal with client callbacks here because we don't have this
// information in the onDamage or onDisable methods
%client = %obj.client;
%sourceClient = %sourceObject ? %sourceObject.client : 0;

if (%obj.getState() $= "Dead")
%client.onDeath(%sourceObject, %sourceClient, %damageType, %location);
}

function AIBeast::onDamage(%this, %obj, %delta)
{
// This method is invoked by the ShapeBase code whenever the
// object's damage level changes.
if (%delta > 0 && %obj.getState() !$= "Dead") {

// Increment the flash based on the amount.
%flash = %obj.getDamageFlash() + ((%delta / %this.maxDamage) * 2);
if (%flash > 0.75)
%flash = 0.75;
%obj.setDamageFlash(%flash);

// If the pain is excessive, let's hear about it.
if (%delta > 10)
%obj.playPain();
}
}

function AIBeast::onDisabled(%this,%obj,%state)
{
// The player object sets the "disabled" state when damage exceeds
// it's maxDamage value. This is method is invoked by ShapeBase
// state mangement code.

// If we want to deal with the damage information that actually
// caused this death, then we would have to move this code into
// the script "damage" method.
%obj.playDeathCry();
%obj.playDeathAnimation();
%obj.setDamageFlash(0.75);

// Release the main weapon trigger
%obj.setImageTrigger(0,false);

// Schedule corpse removal. Just keeping the place clean.
%obj.schedule($CorpseTimeout - 1500, "startFade", 1500, 0, true);
%obj.schedule($CorpseTimeout, "delete");
}


//-----------------------------------------------------------------------------

function AIBeast::onLeaveMissionArea(%this, %obj)
{
// Inform the client
// %obj.client.onLeaveMissionArea();
}

function AIBeast::onEnterMissionArea(%this, %obj)
{
// Inform the client
%obj.client.onEnterMissionArea();
}

//-----------------------------------------------------------------------------

function AIBeast::onTrigger(%this, %obj, %triggerNum, %val)
{
// This method is invoked when the player receives a trigger
// move event. The player automatically triggers slot 0 and
// slot one off of triggers # 0 & 1. Trigger # 2 is also used
// as the jump key.
}


//-----------------------------------------------------------------------------
// Player methods
//-----------------------------------------------------------------------------

//----------------------------------------------------------------------------

function Player::kill(%this, %damageType)
{
%this.damage(0, %this.getPosition(), 10000, %damageType);
}


//----------------------------------------------------------------------------

function Player::mountVehicles(%this,%bool)
{
// If set to false, this variable disables vehicle mounting.
%this.mountVehicle = %bool;
}

function Player::isPilot(%this)
{
%vehicle = %this.getObjectMount();
// There are two "if" statements to avoid a script Warning.
if (%vehicle)
if (%vehicle.getMountNodeObject(0) == %this)
return true;
return false;
}


//----------------------------------------------------------------------------

function Player::playDeathAnimation(%this)
{
if (%this.deathIdx++ > 11)
%this.deathIdx = 1;
%this.setActionThread("Death" @ %this.deathIdx);
}

function Player::playCelAnimation(%this,%anim)
{
if (%this.getState() !$= "Dead")
%this.setActionThread("cel"@%anim);
}

#1
07/12/2011 (12:08 pm)
// Load dts shapes and merge animations
Exec("~/data/models/avatars/beast/player.cs");
This loads up another script file that contains the animation definition that the TSShapeConstructor needs to merge the dsq animations that are used for this specific player shape.

// Timeouts for corpse deletion.
$CorpseTimeout = 30000;
A global variable that sets the time at which a corpse is deleted from the scene.

$PlayerDeathAnim::TorsoFrontFallForward = 1;
$PlayerDeathAnim::TorsoFrontFallBack = 2;
$PlayerDeathAnim::TorsoBackFallForward = 3;
$PlayerDeathAnim::TorsoLeftSpinDeath = 4;
$PlayerDeathAnim::TorsoRightSpinDeath = 5;
$PlayerDeathAnim::LegsLeftGimp = 6;
$PlayerDeathAnim::LegsRightGimp = 7;
$PlayerDeathAnim::TorsoBackFallForward = 8;
$PlayerDeathAnim::HeadFrontDirect = 9;
$PlayerDeathAnim::HeadBackFallForward = 10;
$PlayerDeathAnim::ExplosionBlowBack = 11;
In stock code these globals do absolutely nothing. Ignore/remove them. If you are interested in how to make use of them, I show how in my Improved PlayDeathAnimation Resource.

Datablocks: the properties for certain particle effects, debris, player body, etc.

The various script methods are callbacks and game logic relevant to the AiBeast/Player class. Read the comments, try to follow the logic within the functions to understand what each is doing - it's mostly self-explanatory.
#2
07/12/2011 (8:38 pm)
datablock ParticleData(PlayerSplashMist)
{
dragCoefficient = 2.0;
gravityCoefficient = -0.05;
inheritedVelFactor = 0.0;
constantAcceleration = 0.0;
lifetimeMS = 400;
lifetimeVarianceMS = 100;
useInvAlpha = false;
spinRandomMin = -90.0;
spinRandomMax = 500.0;
textureName = "~/data/particles/splash";
colors[0] = "0.7 0.8 1.0 1.0";
colors[1] = "0.7 0.8 1.0 0.5";
colors[2] = "0.7 0.8 1.0 0.0";
sizes[0] = 0.5;
sizes[1] = 0.5;
sizes[2] = 0.8;
times[0] = 0.0;
times[1] = 0.5;
times[2] = 1.0;
};
what's things these codes description?