コード例 #1
0
ファイル: Door.cpp プロジェクト: AltimorTASDK/TribesRebirth
void Door::onLast()
{
   if (const char *lpcszScript = scriptName("onOpen"))
   {
      Console->executef(3, lpcszScript, scriptThis(), getId());
   }
}
コード例 #2
0
void PxSingleActor::onCollision( GameBase *hitObject, const VectorF &impactForce )
{
   if ( isGhost() )  
      return;

   PROFILE_SCOPE( PxSingleActor_OnCollision );

   // TODO: Why do we not get a hit position?
   Point3F hitPos = getPosition();

   String strHitPos = String::ToString( "%g %g %g", hitPos.x, hitPos.y, hitPos.z );
   String strImpactVec = String::ToString( "%g %g %g", impactForce.x, impactForce.y, impactForce.z );
   String strImpactForce = String::ToString( "%g", impactForce.len() );
      
   Con::executef( mDataBlock, "onCollision", scriptThis(), 
      hitObject ? hitObject->scriptThis() : NULL, 
      strHitPos.c_str(), strImpactVec.c_str(), strImpactForce.c_str() );
}
コード例 #3
0
ファイル: player.cpp プロジェクト: AltimorTASDK/TribesRebirth
void Player::applyDamage(int type,float value,const Point3F pos,
	const Point3F& vec,const Point3F& mom,int objectId)
{
   const char* script;
	if (!isGhost())
		if ((script = scriptName("onDamage")) != NULL) {
         const char* pVert;
         const char* pQuad;
         getDamageLocation(pos, pVert, pQuad);

			Console->evaluatef("%s(%s,%d,%g,\"%g %g %g\",\"%g %g %g\",\"%g %g %g\",%s,%s,%d);",
				script,scriptThis(),type,value,
				pos.x,pos.y,pos.z,
				vec.x,vec.y,vec.z,
				mom.x,mom.y,mom.z,
            pVert, pQuad,
				objectId);
      }
}
コード例 #4
0
ファイル: player.cpp プロジェクト: AltimorTASDK/TribesRebirth
void Player::kill ()
{
   if (isGhost() || dead)
      return;

	dead = true;
	damageLevel = data->maxDamage;
	setMaskBits (DamageMask);

	disableSupressionField();
	dieTime = manager->getCurrentTime();
	  
	if (const char* script = scriptName("onKilled"))
		Console->executef(2,script,scriptThis());

	type = CorpseObjectType;
	collisionMask = ServerCorpseCollisionMask;
	collisionImage.trigger = true;
	SimMessageEvent::post(this, manager->getCurrentTime() + CorpseTriggerTimeout, CorpseTriggerMsg);
	jetting = false;
}
コード例 #5
0
ファイル: projectile.cpp プロジェクト: adhistac/ee-client-2-0
//--------------------------------------------------------------------------
void Projectile::onCollision(const Point3F& hitPosition, const Point3F& hitNormal, SceneObject* hitObject)
{
   // No client specific code should be placed or branched from this function
   if(isClientObject())
      return;

   if (hitObject != NULL && isServerObject())
   {
      char *posArg = Con::getArgBuffer(64);
      char *normalArg = Con::getArgBuffer(64);

      dSprintf(posArg, 64, "%g %g %g", hitPosition.x, hitPosition.y, hitPosition.z);
      dSprintf(normalArg, 64, "%g %g %g", hitNormal.x, hitNormal.y, hitNormal.z);

      Con::executef(mDataBlock, "onCollision",
         scriptThis(),
         Con::getIntArg(hitObject->getId()),
         Con::getFloatArg(mFadeValue),
         posArg,
         normalArg);
   }
}
コード例 #6
0
ファイル: projectile.cpp プロジェクト: adhistac/ee-client-2-0
void Projectile::explode(const Point3F& p, const Point3F& n, const U32 collideType)
{
   // Make sure we don't explode twice...
   if (mHidden == true)
      return;

   mHidden = true;
   if (isServerObject()) {
      // Do what the server needs to do, damage the surrounding objects, etc.
      mExplosionPosition = p;
      mExplosionNormal = n;
      mCollideHitType  = collideType;

      char buffer[128];
      dSprintf(buffer, sizeof(buffer),  "%g %g %g", mExplosionPosition.x,
                                                    mExplosionPosition.y,
                                                    mExplosionPosition.z);
      Con::executef(mDataBlock, "onExplode", scriptThis(), buffer, Con::getFloatArg(mFadeValue));

      setMaskBits(ExplosionMask);
      safeDeleteObject();
   } 
   else 
   {
      // Client just plays the explosion at the right place...
      //       
      Explosion* pExplosion = NULL;

      if (mDataBlock->waterExplosion && pointInWater(p))
      {
         pExplosion = new Explosion;
         pExplosion->onNewDataBlock(mDataBlock->waterExplosion);
      }
      else
      if (mDataBlock->explosion)
      {
         pExplosion = new Explosion;
         pExplosion->onNewDataBlock(mDataBlock->explosion);
      }

      if( pExplosion )
      {
         MatrixF xform(true);
         xform.setPosition(p);
         pExplosion->setTransform(xform);
         pExplosion->setInitialState(p, n);
         pExplosion->setCollideType( collideType );
         if (pExplosion->registerObject() == false)
         {
            Con::errorf(ConsoleLogEntry::General, "Projectile(%s)::explode: couldn't register explosion",
                        mDataBlock->getName() );
            delete pExplosion;
            pExplosion = NULL;
         }
      }

      // Client (impact) decal.
      if ( mDataBlock->decal )     
         gDecalManager->addDecal( p, n, 0.0f, mDataBlock->decal );

      // Client object
      updateSound();
   }

   /*
   // Client and Server both should apply forces to PhysicsWorld objects
   // within the explosion. 
   if ( false && mPhysicsWorld )
   {
      F32 force = 200.0f;
      mPhysicsWorld->explosion( p, 15.0f, force );
   }
   */
}
コード例 #7
0
ファイル: turret.cpp プロジェクト: AltimorTASDK/TribesRebirth
void Turret::shoot (bool playerControlled, Player* targetPlayer)
{
   if (data && data->isSustained == false) {
	   if (data && data->projectile.type == -1)
	   	{
	   		if (!isGhost())
	   			if (const char* script = scriptName("onFire"))
	   				Console->executef(2, script, scriptThis());
	   	}
	   else
	   	{
	   		float energy = getEnergy();
	   		if (waitTime <= manager->getCurrentTime() && data && energy >= data->minGunEnergy && data->projectile.type != -1)
	   			{
                  TMat3F muzzleTransform;
	   				getMuzzleTransform(0, &muzzleTransform);
	   				Projectile* bullet = createProjectile(data->projectile);

	   				if (!playerControlled && data->deflection)
	   					{
	   						static Random random;
	   						EulerF angles;
	   					   muzzleTransform.angles (&angles);
	   						angles.x += (random.getFloat() - 0.5) * M_2PI * data->deflection;
	   						angles.z += (random.getFloat() - 0.5) * M_2PI * data->deflection;
	   						muzzleTransform.set (angles, muzzleTransform.p);
	   					}
	   				else
	   					if (playerControlled)
	   						{
	   							Point3F start = muzzleTransform.p;
	   							muzzleTransform = getEyeTransform ();
	   							aimedTransform (&muzzleTransform, start);
	   							muzzleTransform.p = start;
	   						}

	   				bullet->initProjectile (muzzleTransform, Point3F (0, 0, 0), getId());

	   	         if (bullet->isTargetable() == true) {
	   	            if (targetPlayer != NULL) {
	   						if (GameBase* mo = targetPlayer->getMountObject())
	   		               bullet->setTarget(static_cast<ShapeBase*>(mo));
	   						else
	   		               bullet->setTarget(targetPlayer);
                     } else if (playerControlled) {
                        ShapeBase* pClosest   = NULL;
                        Point3F    closeHisPos;
                        float      closestVal = -2.0f;
                        SimSet::iterator itr;
                     
                        Point3F lookDir;
                        getEyeTransform().getRow(1, &lookDir);
                        lookDir.normalize();

                        SimContainerQuery collisionQuery;
                        SimCollisionInfo  info;
                        collisionQuery.id     = getId();
                        collisionQuery.type   = -1;
                        collisionQuery.mask   = Projectile::csm_collisionMask;
                        collisionQuery.detail = SimContainerQuery::DefaultDetail;
                        collisionQuery.box.fMin = getEyeTransform().p;
                        SimContainer* pRoot = (SimContainer*)manager->findObject(SimRootContainerId);

                        SimSet* pSet = dynamic_cast<SimSet*>(manager->findObject(PlayerSetId));
                        AssertFatal(pSet != NULL, "No player set?");
                        for (itr = pSet->begin(); itr != pSet->end(); itr++) {
                           Player* pPlayer = dynamic_cast<Player*>(*itr);

                           if (!pPlayer || pPlayer->getVisibleToTeam(getTeam()) == false)
                              continue;

                           collisionQuery.box.fMax = pPlayer->getBoxCenter();
                           if (pRoot->findLOS(collisionQuery, &info, SimCollisionImageQuery::High) == true) {
                              if (info.object != (SimObject*)pPlayer)
                                 continue;
                           }

                           Point3F hisPos = pPlayer->getBoxCenter();
                           hisPos -= getLinearPosition();
                           hisPos.normalize();

                           float prod = m_dot(hisPos, lookDir);
                           if (prod > 0.0f && prod > closestVal) {
                              closestVal = prod;
                              pClosest   = pPlayer;
                              closeHisPos = hisPos;
                           }
                        }

                        pSet = dynamic_cast<SimSet*>(manager->findObject(MoveableSetId));
                        AssertFatal(pSet != NULL, "No moveable set?");
                        for (itr = pSet->begin(); itr != pSet->end(); itr++) {
                           if (((*itr)->getType() & VehicleObjectType) == 0)
                              continue;

                           ShapeBase* pObject = dynamic_cast<ShapeBase*>(*itr);
                           
                           if (pObject->getVisibleToTeam(getTeam()) == false)
                              continue;

                           collisionQuery.box.fMax = pObject->getBoxCenter();
                           if (pRoot->findLOS(collisionQuery, &info, SimCollisionImageQuery::High) == true) {
                              if (info.object != (SimObject*)pObject)
                                 continue;
                           }

                           Point3F hisPos = pObject->getBoxCenter();
                           hisPos -= getLinearPosition();
                           hisPos.normalize();

                           float prod = m_dot(hisPos, lookDir);
                           if (prod > 0.0f && prod > closestVal) {
                              closestVal = prod;
                              closeHisPos = hisPos;
                              pClosest   = pObject;
                           }
                        }

                        // We need to find the current FOV, and take the percentage of
                        //  it specified in the .dat file for this turret.  Only if the
                        //  do product is greater than this, do we allow the target to
                        //  be set...
                        //
                        float myFov   = (fov / 2.0) * data->targetableFovRatio;
                        float compCos = cos(myFov);
                        if (compCos > 0.996f)   // hack for single precision math.  It's very
                           compCos = 0.996;     // hard to get more precise answers from the dot prod.

                        if (pClosest != NULL && closestVal > compCos)
                           bullet->setTarget(pClosest);
                     }
                  }

	   				if (data->maxGunEnergy)
	   					{
	   						float e;
	   						e = energy > data->maxGunEnergy ? data->maxGunEnergy : energy;

                        float pofm = e / float(data->maxGunEnergy);

	   						bullet->setEnergy (e, pofm);

	   						energy -= e;
	   						setEnergy (energy);
	   					}

                  SimGroup *grp = NULL;
                  if(SimObject *obj = manager->findObject("MissionCleanup"))
                     grp = dynamic_cast<SimGroup*>(obj);
                  if(!manager->registerObject(bullet))
                     delete bullet;
                  else
                  {
                     if(grp)
                        grp->addObject(bullet);
                     else
                        manager->addObject(bullet);
                  }

	   				waitTime = manager->getCurrentTime() + data->reloadDelay;

	   				if (animThread)
	   					{
	   						setFireThread ();
	   						animThread->SetPosition (0.0);
	   					}
	   				
	   				fireCount++;
	   				setMaskBits (ShootingMask);
	   			}
	   	}
   } else {
      if (data && data->projectile.type == -1) {
         if (!isGhost())
            if (const char* script = scriptName("onFire"))
               Console->executef(2, script, scriptThis());
      }
      else {
         float energy = getEnergy();
         if (waitTime <= manager->getCurrentTime() && data && energy >= data->minGunEnergy && data->projectile.type != -1) {
            TMat3F muzzleTransform;
            getMuzzleTransform(0, &muzzleTransform);
            Projectile* bullet = createProjectile(data->projectile);

            if (!playerControlled && data->deflection) {
               static Random random;
               EulerF angles;
               muzzleTransform.angles (&angles);
               angles.x += (random.getFloat() - 0.5) * M_2PI * data->deflection;
               angles.z += (random.getFloat() - 0.5) * M_2PI * data->deflection;
               muzzleTransform.set (angles, muzzleTransform.p);
            } else if (playerControlled) {
               Point3F start = muzzleTransform.p;
               muzzleTransform = getEyeTransform ();
               aimedTransform (&muzzleTransform, start);
               muzzleTransform.p = start;
            }

            bullet->initProjectile (muzzleTransform, Point3F (0, 0, 0), getId());
            AssertFatal(bullet->isSustained() == true, "Error, must be sustained bullet");
            SimGroup *grp = NULL;
            if(SimObject *obj = manager->findObject("MissionCleanup"))
               grp = dynamic_cast<SimGroup*>(obj);
            if(!manager->registerObject(bullet))
               delete bullet;
            else
            {
               if(grp)
                  grp->addObject(bullet);
               else
                  manager->addObject(bullet);
            }

            if (animThread) {
               setFireThread ();
               animThread->SetPosition (0.0);
            }
            
            fireCount++;
            setMaskBits (ShootingMask);

            m_fireState  = Firing;
            m_beganState = wg->currentTime;

            m_pProjectile = bullet;
            m_pTarget     = targetPlayer;
            
            if (m_pTarget)
               deleteNotify(m_pTarget);
         }
      }
   }
}
コード例 #8
0
ファイル: turret.cpp プロジェクト: AltimorTASDK/TribesRebirth
void Turret::updateMove (PlayerMove *move, float interval)
{
   if (data->isSustained == false) {
	   if (getControlClient() && state != EXTENDED)
	   	{
	   		if (!isGhost())
	   			extend (interval);
	   	}

		if (state != EXTENDED)
			move = NULL;

	   float oTR = turretRotation;
	   float oTE = turretElevation;

	   if (move && (!animThread || animThread->getPriority() != -1 ||
	   		animThread->getPosition() >= 1.0))
	   	{
#if 0
	   		float maxSpeed = data->speed * data->speedModifier * interval;
	   		float moveFrac = interval * 32;
#else
	   		float maxSpeed = data->speed * data->speedModifier;
	   		float moveFrac = interval * 16;
#endif
	   		float pitch = m_clamp(move->pitch,-maxSpeed,maxSpeed);
	   		float turn = m_clamp(move->turnRot,-maxSpeed,maxSpeed);
	   		turretElevation += pitch * moveFrac;
	   		turretRotation += turn * moveFrac;

	   		wrapElevation ();
	   		if (maxElevation != minElevation)
	   			{
	   				if (turretElevation > maxElevation)
	   					turretElevation = maxElevation;
	   			
	   				if (turretElevation < minElevation)
	   					turretElevation = minElevation;
	   			}
	
	   		wrapRotation ();
	   		if (maxRotation != minRotation)
	   			{
	   				if (turretRotation > maxRotation)
	   					turretRotation = maxRotation;
	   			
	   				if (turretRotation < minRotation)
	   					turretRotation = minRotation;
	   			}
	   	
	   		if (move->trigger)
	   			{
	   				if (!isGhost ())
	   					shoot (true);
	   			}
	   	
	   		if (move->jumpAction && !isGhost())
            {
               const char *fn = scriptName("jump");
               if(fn)
                  Console->executef(2, fn, scriptThis());
            }
	   	}

	   if (elevationThread && maxElevation != minElevation)
	   	elevationThread->SetPosition ((turretElevation - minElevation) / (maxElevation - minElevation));
	   	
	   if (rotationThread)
	   	{
	   		if (!isEqual (maxRotation, minRotation))
	   			rotationThread->SetPosition ((turretRotation - minRotation) / (maxRotation - minRotation));
	   		else
	   			rotationThread->SetPosition (turretRotation / M_2PI);
	   	}

	   // this is for the firing anim...
	   if (animThread && state == EXTENDED)
	   	animThread->AdvanceTime (interval);

	   // this is for the power anim...
	   if (animThread && isGhost())
	   	{
	   		if (state == EXTENDING)
	   			extend (interval);
	   		else
	   			if (state == RETRACTING)
	   				retract (interval);
	   	}

	   if (!isGhost ())
	   	{
	   		// Need to animate on the server to get the
	   		// node transforms.
	   		image.shape->animate ();

	   		if (oTE != turretElevation)
	   			setMaskBits (ElevationMask);
	   		if (oTR != turretRotation)
	   			setMaskBits (TRotationMask);
	   	}

	} else {
	   if (getControlClient() && state != EXTENDED) {
	      if (!isGhost())
	         extend (interval);
	   }

		if (state != EXTENDED)
			move = NULL;

	   float oTR = turretRotation;
	   float oTE = turretElevation;

	   if (move && (!animThread || animThread->getPriority() != -1 ||
	   		animThread->getPosition() >= 1.0))
	   {
	   	float maxSpeed = data->speed * interval;
	   	float pitch = m_clamp(move->pitch,-maxSpeed,maxSpeed);
	   	float turn = m_clamp(move->turnRot,-maxSpeed,maxSpeed);
	   	float moveFrac = interval * 32;
	   	turretElevation += pitch * moveFrac;
	   	turretRotation += turn * moveFrac;

	   	wrapElevation ();
	   	if (maxElevation != minElevation) {
	   		if (turretElevation > maxElevation)
	   			turretElevation = maxElevation;
	   	
	   		if (turretElevation < minElevation)
	   			turretElevation = minElevation;
	   	}
	
	   	wrapRotation ();
	   	if (maxRotation != minRotation) {
	   		if (turretRotation > maxRotation)
	   			turretRotation = maxRotation;
	   	
	   		if (turretRotation < minRotation)
	   			turretRotation = minRotation;
	   	}
	
	   	if (move->trigger && m_fireState == Waiting) {
	   		if (!isGhost ())
	   			shoot(true, NULL);
	   	} else if (!move->trigger && m_fireState == Firing) {
	   		if (!isGhost())
	   			unshoot();
         }
	
	   	if (move->jumpAction && !isGhost()) {
            if (m_fireState == Firing)
               unshoot();

            const char *fn = scriptName("jump");
            if(fn)
               Console->executef(2, fn, scriptThis());
         }
	   }

	   if (elevationThread && maxElevation != minElevation)
	   	elevationThread->SetPosition ((turretElevation - minElevation) / (maxElevation - minElevation));
	   	
	   if (rotationThread) {
	   	if (!isEqual (maxRotation, minRotation))
	   		rotationThread->SetPosition ((turretRotation - minRotation) / (maxRotation - minRotation));
	   	else
	   		rotationThread->SetPosition (turretRotation / M_2PI);
	   }

	   // this is for the firing anim...
	   if (animThread && state == EXTENDED)
	   	animThread->AdvanceTime (interval);

	   // this is for the power anim...
	   if (animThread && isGhost()) {
	   	if (state == EXTENDING)
	   		extend (interval);
	   	else if (state == RETRACTING)
	   	   retract (interval);
	   }

	   if (!isGhost ()) {
	   	// Need to animate on the server to get the
	   	// node transforms.
	   	image.shape->animate ();

	   	if (oTE != turretElevation)
	   		setMaskBits (ElevationMask);
	   	if (oTR != turretRotation)
	   		setMaskBits (TRotationMask);
	   }
   }
}