Game Development Community

MissionArea for vehicles

by Martin Schultz · in Torque Game Engine Advanced · 08/02/2006 (6:50 am) · 0 replies

For my current game I needed the MissionArea object working for vehicles in TSE and added a method to the vehicle class to get it working. I took it directly out of the player class and it worked right out of the box.

I thought I'd quickly share my effort here if someone else needs this too. This was tested with MS 3.

In vehicle.h add around line 176 this line (marked bold):
Rigid mRigid;
   ShapeBaseConvex mConvex;
   int restCount;
   [b]bool mInMissionArea;          ///< Are we in the mission area?[/b]

   ParticleEmitter *mDustEmitterList[VehicleData::VC_NUM_DUST_EMITTERS];

Add also the method header (around line 201):
virtual void updateForces(F32 dt);
   ///See if the player is still in the mission area
   [b]void checkMissionArea();[/b]

   void writePacketData(GameConnection * conn, BitStream *stream);

In vehicle.cc in the method void Vehicle::updatePos(F32 dt) add this line here around line 990 (marked bold):
// Water script callbacks
      if (!inLiquid && mWaterCoverage != 0.0f) {
         Con::executef(mDataBlock,4,"onEnterLiquid",scriptThis(), Con::getFloatArg(mWaterCoverage), Con::getIntArg(mLiquidType));
         inLiquid = true;
      }
      else if (inLiquid && mWaterCoverage == 0.0f) {
         Con::executef(mDataBlock,3,"onLeaveLiquid",scriptThis(), Con::getIntArg(mLiquidType));
         inLiquid = false;
      }
	  // Check for the mission area
	  [b]checkMissionArea();[/b]
   }
   else {

      // Play impact sounds on the client.
      if (collided) {
         F32 collSpeed = (

Add here also the method checkMissionArea() directly behind UpdatePos:
void Vehicle::checkMissionArea()
{
   // Checks to see if the player is in the Mission Area...
   Point3F pos;
   MissionArea * obj = dynamic_cast<MissionArea*>(Sim::findObject("MissionArea"));

   if(!obj)
      return;

   const RectI &area = obj->getArea();
   getTransform().getColumn(3, &pos);

   if ((pos.x < area.point.x || pos.x > area.point.x + area.extent.x ||
       pos.y < area.point.y || pos.y > area.point.y + area.extent.y)) {
      if(mInMissionArea) {
         mInMissionArea = false;
         Con::executef(mDataBlock,3,"onLeaveMissionArea",scriptThis());
      }
   }
   else if(!mInMissionArea)
   {
      mInMissionArea = true;
      Con::executef(mDataBlock,3,"onEnterMissionArea",scriptThis());
   }
}

Recompile and you're done. Make sure you have the corresponding script callbacks set up for your namespace. The 2 callbacks are:
function ShapeBase::onEnterMissionArea(%this, %obj)
{
	error("ShapeBase::onEnterMissionArea. %obj: "@%obj);
}

function ShapeBase::onLeaveMissionArea(%this, %obj)
{
	error("ShapeBase::onLeaveMissionArea. %obj: "@%obj);
}

Hope it works for you and I didn't oversee that it is already implemented for vehicles somewhere... :-)

Martin