Help with Defense Platform

As some of you know, I am working on a defense platform for TWM called the guardia. Previously, it used a function that spawned projectile objects. Well, I got bored of that, so I decided to spawn a turret on it instead. However, it doesn't seem to want to work for me. The Platform spawns alright, and I can see the turret. When it gets near a target it activates as if it were to fire. I'm not sure if this is working. I need to know how to flip the turret upside down so it is on the bottom of the platform making it easier to fire at targets:

here is my code:
datablock FlyingVehicleData(GuardiaVehicle) : ShrikeDamageProfile
{
   spawnOffset = "0 0 2";
   canControl = false;
   catagory = "Vehicles";
   shapeFile = "turret_mortar_large.dts";
   multipassenger = false;
   computeCRC = true;

   debrisShapeName = "turret_mortar_large.dts";
   debris = ShapeDebris;
   renderWhenDestroyed = false;

   drag    = 0.15;
   density = 1.0;

   numMountPoints = 0; //cant mount this...
   cameraMaxDist = 15;
   cameraOffset = 2.5;
   cameraLag = 0.9;
   explosion = VehicleExplosion;
	explosionDamage = 0.5;
	explosionRadius = 5.0;

   maxDamage = 1.40;
   destroyedLevel = 1.40;

   isShielded = true;
   energyPerDamagePoint = 160;
   maxEnergy = 280;      // Afterburner and any energy weapon pool
   rechargeRate = 0.8;

   minDrag = 30;           // Linear Drag (eventually slows you down when not thrusting...constant drag)
   rotationalDrag = 900;        // Anguler Drag (dampens the drift after you stop moving the mouse...also tumble drag)

   maxAutoSpeed = 5;       // Autostabilizer kicks in when less than this speed. (meters/second)
   autoAngularForce = 50;       // Angular stabilizer force (this force levels you out when autostabilizer kicks in)
   autoLinearForce = 300;        // Linear stabilzer force (this slows you down when autostabilizer kicks in)
   autoInputDamping = 0.95;      // Dampen control input so you don't` whack out at very slow speeds

   // Maneuvering
   maxSteeringAngle = 5;    // Max radiens you can rotate the wheel. Smaller number is more maneuverable.
   horizontalSurfaceForce = 6;   // Horizontal center "wing" (provides "bite" into the wind for climbing/diving and turning)
   verticalSurfaceForce = 8;     // Vertical center "wing" (controls side slip. lower numbers make MORE slide.)
   maneuveringForce = 3000;      // Horizontal jets (W,S,D,A key thrust)
   steeringForce = 1200;         // Steering jets (force applied when you move the mouse)
   steeringRollForce = 1600;      // Steering jets (how much you heel over when you turn)
   rollForce = 18;                // Auto-roll (self-correction to right you after you roll/invert)
   hoverHeight = 2;        // Height off the ground at rest
   createHoverHeight = 3;  // Height off the ground when created
   maxForwardSpeed = 400;  // speed in which forward thrust force is no longer applied (meters/second)

   // Turbo Jet
   jetForce = 3000;      // Afterburner thrust (this is in addition to normal thrust)
   minJetEnergy = 1;     // Afterburner can't be used if below this threshhold.
   jetEnergyDrain = 0;       // Energy use of the afterburners (low number is less drain...can be fractional)                                                                                                                                                                                                                                                                                          // Auto stabilize speed
   vertThrustMultiple = 3.0;

   // Rigid body
   mass = 150;        // Mass of the vehicle
   bodyFriction = 0;     // Don't mess with this.
   bodyRestitution = 0.5;   // When you hit the ground, how much you rebound. (between 0 and 1)
   minRollSpeed = 0;     // Don't mess with this.
   softImpactSpeed = 14;       // Sound hooks. This is the soft hit.
   hardImpactSpeed = 25;    // Sound hooks. This is the hard hit.

   // Ground Impact Damage (uses DamageType::Ground)
   minImpactSpeed = 10;      // If hit ground at speed above this then it's an impact. Meters/second
   speedDamageScale = 0.06;

   // Object Impact Damage (uses DamageType::Impact)
   collDamageThresholdVel = 23.0;
   collDamageMultiplier   = 0.02;

   //
   minTrailSpeed = 15;      // The speed your contrail shows up at.
   trailEmitter = ContrailEmitter;
   forwardJetEmitter = FlyerJetEmitter;
   downJetEmitter = FlyerJetEmitter;

   //
   jetSound = ScoutFlyerThrustSound;
   engineSound = ScoutFlyerEngineSound;
   softImpactSound = SoftImpactSound;
   hardImpactSound = HardImpactSound;
   //wheelImpactSound = WheelImpactSound;

   //
   softSplashSoundVelocity = 10.0;
   mediumSplashSoundVelocity = 15.0;
   hardSplashSoundVelocity = 20.0;
   exitSplashSoundVelocity = 10.0;

   exitingWater      = VehicleExitWaterMediumSound;
   impactWaterEasy   = VehicleImpactWaterSoftSound;
   impactWaterMedium = VehicleImpactWaterMediumSound;
   impactWaterHard   = VehicleImpactWaterMediumSound;
   waterWakeSound    = VehicleWakeMediumSplashSound;

   dustEmitter = VehicleLiftoffDustEmitter;
   triggerDustHeight = 4.0;
   dustHeight = 1.0;

   damageEmitter[0] = LightDamageSmoke;
   damageEmitter[1] = HeavyDamageSmoke;
   damageEmitter[2] = DamageBubbles;
   damageEmitterOffset[0] = "0.0 -3.0 0.0 ";
   damageLevelTolerance[0] = 0.3;
   damageLevelTolerance[1] = 0.7;
   numDmgEmitterAreas = 1;

   //minMountDist = 4;

   splashEmitter[0] = VehicleFoamDropletsEmitter;
   splashEmitter[1] = VehicleFoamEmitter;

   shieldImpact = VehicleShieldImpact;

   cmdCategory = "Tactical";
   cmdIcon = CMDFlyingScoutIcon;
   cmdMiniIconName = "commander/MiniIcons/com_scout_grey";
   targetNameTag = 'Guardia Defence';
   targetTypeTag = 'Vehicle';
   sensorData = AWACPulseSensor;
   sensorRadius = AWACPulseSensor.detectRadius;
   sensorColor = "255 194 9";

   checkRadius = 5.5;
   observeParameters = "1 10 10";

   runningLight[0] = ShrikeLight1;
//   runningLight[1] = ShrikeLight2;

   shieldEffectScale = "0.937 1.125 0.60";

};

datablock TurretData(GuardiaTurret) : TurretDamageProfile
{
   className = DeployedTurret;
   shapeFile = "turret_base_large.dts";
   spawnOffset = "0 0 0";
   scale = "0.1 0.1 0.1";

   rechargeRate = 0.31;

   selfPower = true;

   needsPower = true;
   mass = 5.0;
   maxDamage = 2.25;
   destroyedLevel = 2.25;
   disabledLevel = 1.35;
   repairRate = 0;
   explosion = TurretExplosion;
   expDmgRadius = 15.0;
   expDamage = 0.7;
   expImpulse = 2000.0;

   deployedObject = true;

   thetaMin = 15;
   thetaMax = 140;
   //thetaNull = 90;

   isShielded = true;
   energyPerDamagePoint = 50;
   maxEnergy = 150;

   humSound = SensorHumSound;
   heatSignature = 1;
   pausePowerThread = true;

   canControl = false; //auto fires
   cmdCategory = "DTactical";
   cmdIcon = CMDTurretIcon;
   cmdMiniIconName = "commander/MiniIcons/com_turret_grey";
   targetNameTag = 'Guardia';
   targetTypeTag = 'Cannon';
   sensorData = TurretBaseSensorObj;
   sensorRadius = TurretBaseSensorObj.detectRadius;
   sensorColor = "0 212 45";

   firstPersonOnly = true;

   debrisShapeName = "debris_generic.dts";
   debris = TurretDebris;
};

function SetRandomTag(%G) {
%l = getrandom(1,26);
switch (%l) {
case 1:
%nl = "A";
case 2:
%nl = "B";
case 3:
%nl = "C";
case 4:
%nl = "D";
case 5:
%nl = "E";
case 6:
%nl = "F";
case 7:
%nl = "G";
case 8:
%nl = "H";
case 9:
%nl = "I";
case 10:
%nl = "J";
case 11:
%nl = "K";
case 12:
%nl = "L";
case 13:
%nl = "M";
case 14:
%nl = "N";
case 15:
%nl = "O";
case 16:
%nl = "P";
case 17:
%nl = "Q";
case 18:
%nl = "R";
case 19:
%nl = "S";
case 20:
%nl = "T";
case 21:
%nl = "U";
case 22:
%nl = "V";
case 23:
%nl = "W";
case 24:
%nl = "X";
case 25:
%nl = "Y";
case 26:
%nl = "Z";
}
%n1 = getrandom(0,9);
%n2 = getrandom(0,9);
%name = "Guardia Defense Platform ["@%nl@""@%n1@""@%n2@"]";
setTargetName(%G.target, addtaggedstring(%name));
}

function GuardiaVehicle::onAdd(%this, %obj) {
   Parent::onAdd(%this, %obj);
   setTargetSensorGroup(%obj.getTarget(),%obj.team);
   %turret = TurretData::create(GuardiaTurret);
   %turret.selectedWeapon = 1;
   MissionCleanup.add(%turret);
   %turret.team = %obj.team;
   %turret.setSelfPowered();
   %obj.mountObject(%turret, 10);
   %turret.setCapacitorRechargeRate( %turret.getDataBlock().capacitorRechargeRate );
   %turret.mountobj = %obj;
   %obj.turretObject = %turret;
   %turret.team = %obj.team;
   %turret.base = %obj;
   setTargetSensorGroup(%turret.getTarget(),%turret.team);
   MountGuardiaBarrel(%turret); //mount the barrel
   SetRandomTag(%obj);
   
   checktargeting(%obj);
}

function GuardiaVehicle::deleteAllMounted(%data, %obj)
{
   %turret = %obj.getMountNodeObject(10);
   if (!%turret)
      return;

   %turret.schedule(1000, delete);
}

function MountGuardiaBarrel(%turret) {
%turret.mountImage("ELFBarrelLarge", 0);
}

//function GuardiaFire(%g ,%tobj) {            //not really needed?
//%g.turretobject.aquireTime = getSimTime();
//%g.turretobject.setImageTrigger(10,true);
//%g.turretobject.setImageTrigger(10,false);
//}

function checktargeting(%obj) {
   if(!isObject(%obj))
	return;
   %pos = %obj.getposition();
   %count = MissionCleanup.getCount();
   %closestObject = -1;
   %closestDistance = 32767;
   for(%i = 0; %i < %count; %i++)
   {
	%Z = MissionCleanup.getObject(%i);
	if(%Z.iszombie && %Z.getState() !$= "Dead"){
	   %testPos = %Z.getPosition();
	   %distance = vectorDist(%pos, %testPos);
	   if (%distance > 0 && %distance < %closestDistance)
	   {
	   	%closestObject = %Z;
	   	%closestDistance = %distance;
	   }
	}
   }
   if(%closestObject){
   objmovetotarget(%obj,%closestObject,%closestDistance);
   }
   %obj.Targeting = schedule(400, %obj, "checktargeting", %obj);
 }

function objmovetotarget(%obj,%closestObject,%closestDistance){
   %pos = %obj.getposition();
   if(%closestDistance <= 9999){
	if(%obj.hastarget != 1 && %closestdistance >= 10 && %closestdistance <= 9999){
//       if(%closestObject.getstate() !$= "dead") {
//	   GuardiaFire(%obj,%closestObject);
//       }
//       else {
	   %obj.objRmove = schedule(100, %obj, "GuardSetRandomMove", %obj);
//       }
    }
	if(%obj.hastarget != 1){
	   %obj.hastarget = 1;
	}

	%clpos = %closestObject.getPosition();
      %vector = vectorNormalize(vectorSub(%clpos, %pos));
	%v1 = getword(%vector, 0);
	%v2 = getword(%vector, 1);
	%v3 = getword(%vector, 1);
	%nv1 = %v2;
	%nv2 = (%v1 * -1);
	%none = 0;
	%vector2 = %nv1@" "@%nv2@" "@%none;
	%obj.setRotation(fullrot("0 0 0",%vector2));
 
	if (%closestdistance >= 10 && %closestdistance <= 9999){
//       if(%closestObject.getstate() !$= "dead") {
//	   GuardiaFire(%obj,%closestObject);
//       }
//       else {
	   %obj.objRmove = schedule(100, %obj, "GuardSetRandomMove", %obj);
//       }
    }

	%fmultiplier = 1000;
	%vector = vectorscale(%vector, %Fmultiplier);
	%upvec = "100";
	%x = Getword(%vector,0);
	%y = Getword(%vector,1);
	%z = Getword(%vector,2);
	if(%z >= 200)
	   %upvec = (%upvec * -5);
	%vector = %x@" "@%y@" "@%upvec;
	%obj.applyImpulse(%pos, %vector);
   }
   else if(%obj.hastarget == 1){
	%obj.hastarget = 0;
	%obj.objRmove = schedule(100, %obj, "GuardSetRandomMove", %obj);
   }
}

function GuardSetRandomMove(%obj){
   if (!isobject(%obj))
	return;
   %RX = getrandom(-10, 10);
   %RY = getrandom(-10, 10);
   %RZ = getrandom(-10, 10);
   %vector = %RX@" "@%RY@" "@%RZ;
   %obj.direction = vectornormalize(%vector);
   %obj.Mnum = getrandom(1, 20);
   %obj.objRmove = schedule(500, %obj, "GuardRandomLoop", %obj);
}

function GuardRandomLoop(%obj){
   %speed = 150;
   if (!isobject(%obj))
	return;
   if (%obj.hastarget == 1){
	%obj.direction = "";
	return;
   }
   if (%obj.Mnum >= 1){
	%X = getword(%obj.direction, 1);
	%Y = (getword(%obj.direction, 0) * -1);
	%none = 0;
	%vector = %X@" "@%Y@" "@%none;
	%obj.setRotation(fullrot("0 0 0",%vector));
	%vector = vectorscale(%obj.direction, %speed);
	%obj.applyimpulse(%obj.getposition(), %vector);
	%obj.Mnum = (%obj.Mnum - 1);
	%obj.objRmove = schedule(500, %obj, "GuardRandomLoop", %obj);
   }
   else if(%obj.Mnum == 0)
	%obj.objRmove = schedule(100, %obj, "GuardSetRandomMove", %obj);
}

Comments

  • Does the Gurdia move? If not, just simply set the rotation...the default upright rotation is 0 0 0 100. I think.
  • Sounds alot like my Sentinels... I wouldn't be surprised if it is... And that vehicle code looks similar to the Sentinel vehicle.
  • Sounds alot like my Sentinels... I wouldn't be surprised if it is...

    Yea, now that you mention it, the code seems like the Sentinel code. I saw some of it in older posts in ACCM. :D
  • Lets hope so. If that's what it does, it'll be alot like Homeworld 2, and I'll support the idea. If they are just platforms like he says.
  • Ah... So he is copying my idea... I'm not surprised... "function objmovetotarget" suggests he is trying to duplicate my Sentinels.

    Phantom, platforms normally don't move... Just to let you know.
  • Note that a turret is just a shape with a function that spawns projectiles, a target list builder, and a moving nozzle.
    the default upright rotation is 0 0 0 100
    Technically it would set that to the defualt rotation, but only because you didn't set the X Y Z modifiers that the 100 would transform.

    Yes, rotation is the way to go if it's a stationary object. However, since it's a vehicle and you've got the turret attached to a mount node, you can resize it, but you can't mess with the position/rotation.

    You could flip the vehicle itself upside down, mount it on something else, or use your own targetting system.
  • Ah... So he is copying my idea... I'm not surprised... "function objmovetotarget" suggests he is trying to duplicate my Sentinels.

    Phantom, platforms normally don't move... Just to let you know.

    I told you before I was working on a sentinel like vehicle. The whole idea is neat.
    Yea, now that you mention it, the code seems like the Sentinel code. I saw some of it in older posts in ACCM. :D

    Sorry DX. I wrote this thing without any other sources.
    You could flip the vehicle itself upside down, mount it on something else, or use your own targetting system.

    Apparently I cant flip the turret on the vehicle. How do I flip the vehicle?
  • Bln, sentinels were my idea in the first place, so you can't complain if he uses the idea too...

    And yeah, I know my sentinels sucked, but they were funny :)
  • how do I flip the vehicle though?
  • Try adding a rotation (along the x-axis) to it? Con has this nifty function called rotAdd.
  • that simply adds two rotations. It does not apply it.
  • Meh... Anyways... Phantom, let me do the vehicle for you. I am uber at datablocks and stuff. I can get the turret mounted correctly for you.
  • BAh! Blnukem uses same emoticon source as me
    sterb034.gif me vs BL, i won
  • Not really... I am not Pikachu. That would be Eolk.
  • Not really... I am not Pikachu. That would be Eolk.

    Rofl..

    Are you just going to PM / Email me it to me when you are done?
  • that simply adds two rotations. It does not apply it.
    Wow, you really are a coding genius! Here's a hint, the functionLibrary.cs file has some insights on how to apply it...
  • Wow, you really are a coding genius!

    I try...
Sign In or Register to comment.