예제 #1
0
VTorque::SoundSourceType *VTorque::playSound( SoundEffectType *pSoundProfile, SceneObjectType *pObject, const U32 &pPosition, const F32 &pPitch )
{
    if ( !pSoundProfile )
    {
        // Sanity!
        return NULL;
    }

#ifdef VT_EDITOR

    // Fetch Reference Transform.
    const MatrixF &transform = pObject->getTransform();

    // Play Sound.
    SFXSound *source = ( SFXSound* )SFX->playOnce( pSoundProfile, &transform );

    if ( source )
    {
        // Set Position.
        source->setPosition( pPosition );

        // Set Pitch.
        source->setPitch( pPitch );
    }

    // Return Source.
    return source;

#else

    // Fetch Client Group.
    SimGroup* clientGroup = Sim::getClientGroup();

    for ( SimGroup::iterator itr = clientGroup->begin(); itr != clientGroup->end(); itr++ )
    {
        NetConnection *connection = static_cast<NetConnection*>( *itr );
        if ( connection )
        {
            // Create Event.
            VSoundEffectNetEvent *event = new VSoundEffectNetEvent();

            // Setup Event.
            event->mProfile   = pSoundProfile;
            event->mPosition  = pPosition;
            event->mPitch     = pPitch;
            event->mIs3D      = true;
            event->mTransform = pObject->getTransform();

            // Post Event.
            connection->postNetEvent( event );
        }
    }

    return NULL;

#endif
}
예제 #2
0
void VTorque::setPostEffectOn( PostEffectType *pPostEffect, const bool &pStatus )
{
    if ( !pPostEffect )
    {
        // Sanity!
        return;
    }

#ifdef VT_EDITOR

    if ( pStatus )
    {
        // Enable Effect.
        pPostEffect->enable();
    }
    else
    {
        // Disable Effect.
        pPostEffect->disable();
    }

#else

    // Fetch Name.
    StringTableEntry name = pPostEffect->getName();
    if ( !name || name == StringTable->insert( "" ) )
    {
        Con::warnf( "VTorque::setPostEffectOn() - Invalid Object Name." );
        return;
    }

    // Fetch Client Group.
    SimGroup* clientGroup = Sim::getClientGroup();

    for ( SimGroup::iterator itr = clientGroup->begin(); itr != clientGroup->end(); itr++ )
    {
        NetConnection *connection = static_cast<NetConnection*>( *itr );
        if ( connection )
        {
            // Create Event.
            VPostEffectNetEvent *event = new VPostEffectNetEvent();

            // Setup Event.
            event->mPostEffect = name;
            event->mEnabled    = pStatus;

            // Post Event.
            connection->postNetEvent( event );
        }
    }

#endif
}
예제 #3
0
void Lightning::warningFlashes()
{
   AssertFatal(isServerObject(), "Error, client objects may not initiate lightning!");


   SimGroup* pClientGroup = Sim::getClientGroup();
   for (SimGroup::iterator itr = pClientGroup->begin(); itr != pClientGroup->end(); itr++) {
      NetConnection* nc = static_cast<NetConnection*>(*itr);
      if (nc != NULL)
      {
         LightningStrikeEvent* pEvent = new LightningStrikeEvent;
         pEvent->mLightning = this;

         nc->postNetEvent(pEvent);
      }
   }
}
예제 #4
0
void Lightning::strikeRandomPoint()
{
   AssertFatal(isServerObject(), "Error, client objects may not initiate lightning!");


   Point3F strikePoint( gRandGen.randF( 0.0f, 1.0f ), gRandGen.randF( 0.0f, 1.0f ), 0.0f );

   // check if an object is within target range

   strikePoint *= mObjScale;
   strikePoint += getPosition();
   strikePoint += Point3F( -mObjScale.x * 0.5f, -mObjScale.y * 0.5f, 0.0f );

   Box3F queryBox;
   F32 boxWidth = strikeRadius * 2.0f;

   queryBox.minExtents.set( -boxWidth * 0.5f, -boxWidth * 0.5f, -mObjScale.z * 0.5f );
   queryBox.maxExtents.set(  boxWidth * 0.5f,  boxWidth * 0.5f,  mObjScale.z * 0.5f );
   queryBox.minExtents += strikePoint;
   queryBox.maxExtents += strikePoint;

   SimpleQueryList sql;
   getContainer()->findObjects(queryBox, DAMAGEABLE_TYPEMASK,
                               SimpleQueryList::insertionCallback, &sql);

   SceneObject *highestObj = NULL;
   F32 highestPnt = 0.0f;

   for( U32 i = 0; i < sql.mList.size(); i++ )
   {
      Point3F objectCenter;
      sql.mList[i]->getObjBox().getCenter(&objectCenter);
      objectCenter.convolve(sql.mList[i]->getScale());
      sql.mList[i]->getTransform().mulP(objectCenter);

      // check if object can be struck

      RayInfo rayInfo;
      Point3F start = objectCenter;
      start.z = mObjScale.z * 0.5f + getPosition().z;
      Point3F end = objectCenter;
      end.z = -mObjScale.z * 0.5f + getPosition().z;
      bool rayHit = gServerContainer.castRay( start, end,
                                   (0xFFFFFFFF),
                                   &rayInfo);

      if( rayHit && rayInfo.object == sql.mList[i] )
      {
         if( !highestObj )
         {
            highestObj = sql.mList[i];
            highestPnt = objectCenter.z;
            continue;
         }

         if( objectCenter.z > highestPnt )
         {
            highestObj = sql.mList[i];
            highestPnt = objectCenter.z;
         }
      }


   }

   // hah haaaaa, we have a target!
   SceneObject *targetObj = NULL;
   if( highestObj )
   {
      F32 chance = gRandGen.randF();
      if( chance <= chanceToHitTarget )
      {
         Point3F objectCenter;
         highestObj->getObjBox().getCenter(&objectCenter);
         objectCenter.convolve(highestObj->getScale());
         highestObj->getTransform().mulP(objectCenter);

         bool playerInWarmup = false;
         Player *playerObj = dynamic_cast< Player * >(highestObj);
         if( playerObj )
         {
            if( !playerObj->getControllingClient() )
            {
               playerInWarmup = true;
            }
         }

         if( !playerInWarmup )
         {
            applyDamage_callback( objectCenter, VectorF( 0.0f, 0.0f, 1.0f ), highestObj );
            targetObj = highestObj;
         }
      }
   }

   SimGroup* pClientGroup = Sim::getClientGroup();
   for (SimGroup::iterator itr = pClientGroup->begin(); itr != pClientGroup->end(); itr++)
   {
      NetConnection* nc = static_cast<NetConnection*>(*itr);

      LightningStrikeEvent* pEvent = new LightningStrikeEvent;
      pEvent->mLightning = this;

      pEvent->mStart.x = strikePoint.x;
      pEvent->mStart.y = strikePoint.y;
      pEvent->mTarget = targetObj;

      nc->postNetEvent(pEvent);
   }


}