예제 #1
0
void CPhysicsObject::ApplyForceOffset(const Vector &forceVector, const Vector &worldPosition) {
	if (!IsMoveable() || !IsMotionEnabled()) {
		return;
	}
	Wake();

	Vector local;
	WorldToLocal(&local, worldPosition);

	btVector3 force, offset;
	ConvertForceImpulseToBull(forceVector, force);
	ConvertPosToBull(local, offset);
	m_pObject->applyImpulse(force, offset);
	Wake();
}
예제 #2
0
//---------------------------------------------------------
//---------------------------------------------------------
void CBounceBomb::OnPhysGunDrop( CBasePlayer *pPhysGunUser, PhysGunDrop_t Reason )
{
	m_hPhysicsAttacker = pPhysGunUser;
	m_flLastPhysicsInfluenceTime = gpGlobals->curtime;

	m_flTimeGrabbed = FLT_MAX;

	m_bHeldByPhysgun = false;

	if( m_iMineState == MINE_STATE_ARMED )
	{
		// Put the mine back to searching.
		Wake( false );
		return;
	}

	if( Reason == DROPPED_BY_CANNON )
	{
		// Set to lock down to ground again.
		m_bPlacedByPlayer = true;
		OpenHooks( true );
		SetMineState( MINE_STATE_DEPLOY );
	}
	else if ( Reason == LAUNCHED_BY_CANNON )
	{
		SetMineState( MINE_STATE_LAUNCHED );
	}
}
예제 #3
0
파일: Schedulable.cpp 프로젝트: dakyri/qua
void
Schedulable::Update(Time t)
{
	short	nWake=0;
	
	if (instances.CountItems() == 0)
		return;

	instances.Lock();
	for (short i=0; i<instances.CountItems(); i++) {
		Instance	*inst = (Instance *)instances.ItemAt(i);
		if (	t>= inst->startTime
				&& t <= inst->startTime + inst->duration
				&& inst->status != STATUS_RUNNING) {
			Wake(inst);
		} else if (	(t< inst->startTime
				|| t >= inst->startTime + inst->duration)
				&& inst->status == STATUS_RUNNING) {
			Sleep(inst);
		}
		if (inst->status == STATUS_RUNNING) {
			nWake++;
			Run(inst);
		}
	}
	
	if (nWake == 0) {
		;
	}
	instances.Unlock();
}
예제 #4
0
void PowerdScheduler::ScheduledWakeup()
{
	LOG_AM_TRACE("Entering function %s", __FUNCTION__);
	LOG_AM_DEBUG("Powerd wakeup callback received");

	Wake();
}
예제 #5
0
/*virtual*/ void WBCompEldSleeper::HandleEvent(const WBEvent& Event) {
  XTRACE_FUNCTION;

  Super::HandleEvent(Event);

  STATIC_HASHED_STRING(OnDamaged);
  STATIC_HASHED_STRING(OnAINoise);

  const HashedString EventName = Event.GetEventName();
  if (EventName == sOnDamaged) {
    Wake();
  } else if (EventName == sOnAINoise) {
    STATIC_HASHED_STRING(EventOwner);
    WBEntity* const pEventOwner = Event.GetEntity(sEventOwner);
    ASSERT(pEventOwner);

    if (pEventOwner == GetEntity()) {
      // Ignore AI noises from self (see SensorHearing for more details).
    } else {
      STATIC_HASHED_STRING(NoiseLocation);
      const Vector NoiseLocation = Event.GetVector(sNoiseLocation);

      STATIC_HASHED_STRING(NoiseRadius);
      const float NoiseRadius = Event.GetFloat(sNoiseRadius);

      HandleNoise(NoiseLocation, NoiseRadius);
    }
  }
}
예제 #6
0
void State::Update(double deltaTime) {

    if(IsActive() == false) {
        ClearImpulses();
        ClearForces();
        SetVelocity(0.0, 0.0);
        SetAcceleration(0.0, 0.0);
        return;
    }

    a2de::Vector2D total_forces;
    std::for_each(_forces.begin(), _forces.end(), [&total_forces] (ForceContainer::value_type& current_force) mutable -> a2de::Vector2D 
    {
        if(current_force.second < 0.0) return Vector2D();
        total_forces += current_force.first;
        return total_forces;
    });

    Vector2D total_impulses = std::accumulate(_impulses.begin(), _impulses.end(), Vector2D());
    Vector2D F(total_forces + total_impulses);
    ClearImpulses();
    double mass = GetMass();

    //If static body, do nothing.
    if(Math::IsEqual(mass, 0.0)) {
        ClearImpulses();
        ClearForces();
        SetVelocity(0.0, 0.0);
        SetAcceleration(0.0, 0.0);
        Sleep();
        return;
    }

    //Integrate from constant acceleration.
    //a = F / m
    //v = at + v;
    //p = (1/2)at^2 + vt + p

    SetAcceleration(F / mass);
    SetVelocity(GetAcceleration() * deltaTime + GetVelocity());
    SetPosition(((0.5 * GetAcceleration()) * deltaTime * deltaTime) + (GetVelocity() * deltaTime) + GetPosition());

    _forces.remove_if([=](ForceContainer::value_type& current_force)->bool {
        current_force.second -= deltaTime;
        return (current_force.second < 0.0);
    });

    if(_impulses.empty() && _forces.empty() &&
      ((a2de::Math::IsEqual(_acceleration.GetX(), 0.0) && a2de::Math::IsEqual(_acceleration.GetY(), 0.0)) &&
      (a2de::Math::IsEqual(_velocity.GetX(), 0.0) && a2de::Math::IsEqual(_velocity.GetY(), 0.0))))
    {
        SetVelocity(0.0, 0.0);
        SetAcceleration(0.0, 0.0);
        Sleep();
    } else {
        Wake();
    }      

}
예제 #7
0
void GlibScheduler::TimeoutCallback()
{
	LOG_TRACE("Scheduler timeout callback");

	m_timeout.reset();

	Wake();
}
예제 #8
0
void CPhysicsObject::ApplyTorqueCenter(const AngularImpulse &torque) {
	if (!IsMoveable() || !IsMotionEnabled()) {
		return;
	}
	Wake();

	btVector3 bullTorque;
	ConvertAngularImpulseToBull(torque, bullTorque);
	m_pObject->applyTorqueImpulse(bullTorque);
}
예제 #9
0
파일: Thread.cpp 프로젝트: FFalcon/jbushOS
void Thread::EnqueueAPC(APC *apc)
{
	cpu_flags fl = DisableInterrupts();
	fApcQueue.Enqueue(apc);
#if 0
	if (GetState() == kThreadWaiting)
		Wake(E_INTERRUPTED);
#endif

	RestoreInterrupts(fl);
}
예제 #10
0
void CPhysicsObject::ApplyForceCenter(const Vector &forceVector) {
	if (!IsMoveable() || !IsMotionEnabled()) {
		return;
	}
	Wake();

	// forceVector is in kg*in/s*time
	// bullet takes forces in newtons, aka kg*m/s*time

	btVector3 force;
	ConvertForceImpulseToBull(forceVector, force);
	m_pObject->applyCentralImpulse(force);
}
void CPhysicsObject::ApplyTorqueCenter( const AngularImpulse &torqueImpulse )
{
	//Assert(IsMoveable());
	if ( !IsMoveable() )
		return;
	IVP_U_Float_Point ivpTorque;
	ConvertAngularImpulseToIVP( torqueImpulse, ivpTorque );
	IVP_Core *core = m_pObject->get_core();
	core->async_rot_push_core_multiple_ws( &ivpTorque, 1.0 );
	core->rot_speed_change.k[0] = clamp( core->rot_speed_change.k[0], -MAX_ROT_SPEED, MAX_ROT_SPEED );
	core->rot_speed_change.k[1] = clamp( core->rot_speed_change.k[1], -MAX_ROT_SPEED, MAX_ROT_SPEED );
	core->rot_speed_change.k[2] = clamp( core->rot_speed_change.k[2], -MAX_ROT_SPEED, MAX_ROT_SPEED );
	Wake();
}
예제 #12
0
//---------------------------------------------------------
//---------------------------------------------------------
void CBounceBomb::Spawn()
{
	Precache();

	Wake( false );

	SetModel("models/props_combine/combine_mine01.mdl");

	SetSolid( SOLID_VPHYSICS );

	m_hSprite.Set( NULL );
	m_takedamage = DAMAGE_EVENTS_ONLY;

	// Find my feet!
	m_iHookN = LookupPoseParameter( "blendnorth" );
	m_iHookE = LookupPoseParameter( "blendeast" );
	m_iHookS = LookupPoseParameter( "blendsouth" );
	m_iAllHooks = LookupPoseParameter( "blendstates" );
	m_flHookPositions = 0;

	SetHealth( 100 );

	m_bBounce = true;

	SetSequence( SelectWeightedSequence( ACT_IDLE ) );

	OpenHooks( true );

	m_bHeldByPhysgun = false;	

	m_iFlipAttempts = 0;

	if( !GetParent() )
	{
		// Create vphysics now if I'm not being carried.
		CreateVPhysics();
	}

	m_flTimeGrabbed = FLT_MAX;

	if( m_bDisarmed )
	{
		SetMineState( MINE_STATE_DORMANT );
	}
	else
	{
		SetMineState( MINE_STATE_DEPLOY );
	}
}
예제 #13
0
void WBCompEldSleeper::HandleNoise(const Vector& NoiseLocation,
                                   const float NoiseRadius) {
  if (m_IsAwake) {
    return;
  }

  WBCompEldSensorHearing* const pHearingSensor =
      GET_WBCOMP(GetEntity(), EldSensorHearing);
  ASSERT(pHearingSensor);

  float Certainty = 0.0f;
  if (!pHearingSensor->GetNoiseCertainty(NoiseLocation, NoiseRadius,
                                         Certainty)) {
    return;
  }

  if (Certainty >= m_NoiseThreshold) {
    Wake();
  }
}
void CPhysicsObject::SetVelocity( const Vector *velocity, const AngularImpulse *angularVelocity )
{
	Assert(IsMoveable());
	if ( !IsMoveable() )
		return;
	IVP_Core *core = m_pObject->get_core();

	Wake();

	if ( velocity )
	{
		ConvertPositionToIVP( *velocity, core->speed_change );
		core->speed.set_to_zero();
	}

	if ( angularVelocity )
	{
		ConvertAngularImpulseToIVP( *angularVelocity, core->rot_speed_change );
		core->rot_speed.set_to_zero();
	}
}
예제 #15
0
void CPhysicsObject::AddVelocity(const Vector *velocity, const AngularImpulse *angularVelocity) {
	if (!velocity && !angularVelocity) return;

	if (!IsMoveable() || !IsMotionEnabled()) {
		return;
	}
	Wake();

	btVector3 bullvelocity, bullangular;
	if (velocity) {
		ConvertPosToBull(*velocity, bullvelocity);
		m_pObject->setLinearVelocity(m_pObject->getLinearVelocity() + bullvelocity);
	}

	// Angular velocity is supplied in local space.
	if (angularVelocity) {
		ConvertAngularImpulseToBull(*angularVelocity, bullangular);
		bullangular = m_pObject->getWorldTransform().getBasis() * bullangular;

		m_pObject->setAngularVelocity(m_pObject->getAngularVelocity() + bullangular);
	}
}
void CPhysicsObject::ApplyForceOffset( const Vector &forceVector, const Vector &worldPosition )
{
//	Assert(IsMoveable());
	if ( !IsMoveable() )
		return;

	IVP_U_Point pos;
	IVP_U_Float_Point force;

	ConvertForceImpulseToIVP( forceVector, force );
	ConvertPositionToIVP( worldPosition, pos );

	IVP_Core *core = m_pObject->get_core();
	core->async_push_core_ws( &pos, &force );
	core->speed_change.k[0] = clamp( core->speed_change.k[0], -MAX_SPEED, MAX_SPEED );
	core->speed_change.k[1] = clamp( core->speed_change.k[1], -MAX_SPEED, MAX_SPEED );
	core->speed_change.k[2] = clamp( core->speed_change.k[2], -MAX_SPEED, MAX_SPEED );

	core->rot_speed_change.k[0] = clamp( core->rot_speed_change.k[0], -MAX_ROT_SPEED, MAX_ROT_SPEED );
	core->rot_speed_change.k[1] = clamp( core->rot_speed_change.k[1], -MAX_ROT_SPEED, MAX_ROT_SPEED );
	core->rot_speed_change.k[2] = clamp( core->rot_speed_change.k[2], -MAX_ROT_SPEED, MAX_ROT_SPEED );
	Wake();
}
예제 #17
0
파일: lamp.cpp 프로젝트: BenoitGour/RGBLamp
void Lamp::readSerial(char data[],unsigned char buffLen)
{
  _idleTime=0;
  char rxData [buffLen];  
  for (int i=0; i<= buffLen -1; i++) rxData[i] = data[i];

  if (_sleeping)
  {
    if (strcmp(rxData,"t") ==0) LampStatus(!isLampOn());
    else  Wake();
  }
  else
  {
    if (strcmp(rxData,"idx") ==0);// Serial.println(menuPosition(),HEX);
    else if (strcmp(rxData,"c") ==0) updateMenuIndex('c');
    else if (strcmp(rxData,"lmp") ==0) LampStatus(!isLampOn());
    else if (strcmp(rxData,"h") ==0) updateMenuIndex('h');
    else if (strcmp(rxData,"l") ==0) updateMenuIndex('l');
    else if (strcmp(rxData,"r") ==0) updateMenuIndex('r');
    else if (strcmp(rxData,"t") ==0) updateMenuIndex('t');

  }
}
// UNDONE: Limit these?
void CPhysicsObject::AddVelocity( const Vector *velocity, const AngularImpulse *angularVelocity )
{
	Assert(IsMoveable());
	if ( !IsMoveable() )
		return;
	IVP_Core *core = m_pObject->get_core();

	Wake();

	if ( velocity )
	{
		IVP_U_Float_Point ivpVelocity;
		ConvertPositionToIVP( *velocity, ivpVelocity );
		core->speed_change.add( &ivpVelocity );
	}

	if ( angularVelocity )
	{
		IVP_U_Float_Point ivpAngularVelocity;
		ConvertAngularImpulseToIVP( *angularVelocity, ivpAngularVelocity );

		core->rot_speed_change.add(&ivpAngularVelocity);
	}
}
void LongPollThread::fireTermination()
{
    Terminated = true;
    Wake();
}
예제 #20
0
//---------------------------------------------------------
//---------------------------------------------------------
void CBounceBomb::SearchThink()
{
	if( !UTIL_FindClientInPVS(edict()) )
	{
		// Sleep!
		SetNextThink( gpGlobals->curtime + 0.5 );
		return;
	}

	if(	(CAI_BaseNPC::m_nDebugBits & bits_debugDisableAI) )
	{
		if( IsAwake() )
		{
			Wake(false);
		}

		SetNextThink( gpGlobals->curtime + 0.5 );
		return;
	}

	SetNextThink( gpGlobals->curtime + 0.1 );
	StudioFrameAdvance();

	if( m_pConstraint && gpGlobals->curtime - m_flTimeGrabbed >= 1.0f )
	{
		m_OnPulledUp.FireOutput( this, this );
		SetMineState( MINE_STATE_CAPTIVE );
		return;
	}

	float flNearestNPCDist = FindNearestNPC();

	if( flNearestNPCDist <= BOUNCEBOMB_WARN_RADIUS )
	{
		if( !IsAwake() )
		{
			Wake( true );
		}
	}
	else
	{
 		if( IsAwake() )
		{
			Wake( false );
		}

		return;
	}

	if( flNearestNPCDist <= BOUNCEBOMB_DETONATE_RADIUS && !IsFriend( m_hNearestNPC ) )
	{
		if( m_bBounce )
		{
			SetMineState( MINE_STATE_TRIGGERED );
		}
		else
		{
			// Don't pop up in the air, just explode if the NPC gets closer than explode radius.
			SetThink( &CBounceBomb::ExplodeThink );
			SetNextThink( gpGlobals->curtime + m_flExplosionDelay );
		}
	}
}
예제 #21
0
//---------------------------------------------------------
//---------------------------------------------------------
void CBounceBomb::Spawn()
{
	Precache();

	Wake( false );

	SetModel("models/props_combine/combine_mine01.mdl");

	SetSolid( SOLID_VPHYSICS );

	m_hSprite.Set( NULL );
	m_takedamage = DAMAGE_EVENTS_ONLY;

	// Find my feet!
	m_iHookN = LookupPoseParameter( "blendnorth" );
	m_iHookE = LookupPoseParameter( "blendeast" );
	m_iHookS = LookupPoseParameter( "blendsouth" );
	m_iAllHooks = LookupPoseParameter( "blendstates" );
	m_flHookPositions = 0;

	SetHealth( 100 );

	m_bBounce = true;

	SetSequence( SelectWeightedSequence( ACT_IDLE ) );

	OpenHooks( true );

	m_bHeldByPhysgun = false;	

	m_iFlipAttempts = 0;

	if( !GetParent() )
	{
		// Create vphysics now if I'm not being carried.
		CreateVPhysics();
	}

	m_flTimeGrabbed = FLT_MAX;

	if( m_bDisarmed )
	{
		SetMineState( MINE_STATE_DORMANT );
	}
	else
	{
		SetMineState( MINE_STATE_DEPLOY );
	}

	// default to a different skin for cavern turrets (unless explicitly overridden)
	if ( m_iModification == MINE_MODIFICATION_CAVERN )
	{
		// look for this value in the first datamap
		// loop through the data description list, restoring each data desc block
		datamap_t *dmap = GetDataDescMap();

		bool bFoundSkin = false;
		// search through all the readable fields in the data description, looking for a match
		for ( int i = 0; i < dmap->dataNumFields; ++i )
		{
			if ( dmap->dataDesc[i].flags & (FTYPEDESC_OUTPUT | FTYPEDESC_KEY) )
			{
				if ( !Q_stricmp(dmap->dataDesc[i].externalName, "Skin") )
				{
					bFoundSkin = true; 
					break;
				}
			}
		}

		if (!bFoundSkin)
		{
			// select a random skin for the mine. Actually, we'll cycle through the available skins 
			// using a static variable to provide better distribution. The static isn't saved but
			// really it's only cosmetic.
			static unsigned int nextSkin = MINE_CITIZEN_SKIN_MIN;
			m_nSkin = nextSkin;
			// increment the skin for next time
			nextSkin = (nextSkin >= MINE_CITIZEN_SKIN_MAX) ? MINE_CITIZEN_SKIN_MIN : nextSkin + 1;
		}	

		// pretend like the player set me down.
		m_bPlacedByPlayer = true;
	}
}
void CPhysicsObject::InitFromTemplate( CPhysicsEnvironment *pEnvironment, void *pGameData, const vphysics_save_cphysicsobject_t &objectTemplate )
{
	m_collideType = objectTemplate.collideType;

	IVP_Template_Real_Object ivpObjectTemplate;
	IVP_U_Quat rotation;
	IVP_U_Point pos;

	ConvertRotationToIVP( objectTemplate.angles, rotation );
	ConvertPositionToIVP( objectTemplate.origin, pos );

	ivpObjectTemplate.mass = objectTemplate.mass;
	
	if ( objectTemplate.materialIndex >= 0 )
	{
		ivpObjectTemplate.material = physprops->GetIVPMaterial( objectTemplate.materialIndex );
	}
	else
	{
		ivpObjectTemplate.material = physprops->GetIVPMaterial( physprops->GetSurfaceIndex( "default" ) );
	}

	Assert( ivpObjectTemplate.material );
	// HACKHACK: Pass this name in for debug
	ivpObjectTemplate.set_name(objectTemplate.pName);
	ivpObjectTemplate.set_nocoll_group_ident( NULL );

	ivpObjectTemplate.physical_unmoveable = objectTemplate.isStatic ? IVP_TRUE : IVP_FALSE;
	ivpObjectTemplate.rot_inertia_is_factor = IVP_TRUE;

	ivpObjectTemplate.rot_inertia.set( 1,1,1 );
	ivpObjectTemplate.rot_speed_damp_factor.set( objectTemplate.rotSpeedDamping, objectTemplate.rotSpeedDamping, objectTemplate.rotSpeedDamping );
	ivpObjectTemplate.speed_damp_factor = objectTemplate.speedDamping;

    IVP_U_Matrix massCenterMatrix;
    massCenterMatrix.init();
	const Vector *massOverride = 0;
	if ( objectTemplate.massCenterOverride != vec3_origin )
	{
		IVP_U_Point center;
		ConvertPositionToIVP( objectTemplate.massCenterOverride, center );
		massCenterMatrix.shift_os( &center );
		ivpObjectTemplate.mass_center_override = &massCenterMatrix;
		massOverride = &objectTemplate.massCenterOverride;
	}

	IVP_Real_Object *realObject = NULL;
	if ( m_collideType == COLLIDE_BALL )
	{
		IVP_Template_Ball ballTemplate;
		ballTemplate.radius = ConvertDistanceToIVP( objectTemplate.sphereRadius );

		realObject = pEnvironment->GetIVPEnvironment()->create_ball( &ballTemplate, &ivpObjectTemplate, &rotation, &pos );
	}
	else
	{
		const IVP_Compact_Surface *pSurface = (const IVP_Compact_Surface *)objectTemplate.pCollide;
		IVP_SurfaceManager_Polygon *surman = new IVP_SurfaceManager_Polygon( pSurface );
		realObject = pEnvironment->GetIVPEnvironment()->create_polygon(surman, &ivpObjectTemplate, &rotation, &pos);
	}


	Init( realObject, objectTemplate.materialIndex, objectTemplate.volume, objectTemplate.dragCoefficient, objectTemplate.dragCoefficient, massOverride );

	SetInertia( objectTemplate.rotInertia );
	
	// will wake up the object
	if ( objectTemplate.velocity.LengthSqr() != 0 || objectTemplate.angVelocity.LengthSqr() != 0 )
	{
		Assert( !objectTemplate.isAsleep );
		SetVelocity( &objectTemplate.velocity, &objectTemplate.angVelocity );
	}

	SetCallbackFlags( (unsigned short) objectTemplate.callbacks );
	SetGameFlags( (unsigned short) objectTemplate.gameFlags );

	SetGameData( pGameData );
	SetContents( objectTemplate.contentsMask );

	if ( objectTemplate.dragEnabled )
	{
		Assert( !objectTemplate.isStatic );
		EnableDrag( true );
	}

	if ( !objectTemplate.motionEnabled )
	{
		Assert( !objectTemplate.isStatic );
		EnableMotion( false );
	}

	if ( objectTemplate.isTrigger )
	{
		BecomeTrigger();
	}

	if ( !objectTemplate.gravityEnabled )
	{
		EnableGravity( false );
	}

	if ( objectTemplate.collisionEnabled )
	{
		EnableCollisions( true );
	}

	if ( !objectTemplate.isAsleep )
	{
		Assert( !objectTemplate.isStatic );
		Wake();
	}
	m_pShadow = NULL;
}
예제 #23
0
void
XmppClient::OnAuthDone() {
  Wake();
}
예제 #24
0
void NSBContext::OnClick()
{
    if (WaitInterrupt || (pText && !pText->Advance()))
        Wake();
}
예제 #25
0
void NSBContext::TryWake()
{
    if (pObject && pObject->Action())
        Wake();
}
예제 #26
0
ScreenSaverWaker::ScreenSaverWaker(QObject* parent) : QObject(parent)
{
    QObject::connect(&timer,SIGNAL(timeout()),this,SLOT(Wake()));
}
예제 #27
0
void State::ApplyForce(const Vector2D& force, double duration) {
    if(duration < 0.0) return;
    Wake();
    _forces.push_back(std::make_pair(force, duration));
}
예제 #28
0
int CE_Cycler_Fix::OnTakeDamage_Alive(const CTakeDamageInfo& info)
{
#if 0
	return BaseClass::OnTakeDamage_Alive(info);
#endif

	Forget( bits_MEMORY_INCOVER );

	if ( !CCombatCharacter::FAKE_OnTakeDamage_Alive( info ) )
		return 0;

	if ( GetSleepState() == AISS_WAITING_FOR_THREAT )
		Wake();

	CEntity *attacker = CEntity::Instance(info.GetAttacker());

	// NOTE: This must happen after the base class is called; we need to reduce
	// health before the pain sound, since some NPCs use the final health
	// level as a modifier to determine which pain sound to use.

	// REVISIT: Combine soldiers shoot each other a lot and then talk about it
	// this improves that case a bunch, but it seems kind of harsh.
	if ( !GetSquad() || !GetSquad()->SquadIsMember( attacker ) )
	{
		PainSound( info );// "Ouch!"
	}

	// See if we're running a dynamic interaction that should break when I am damaged.
	if ( IsActiveDynamicInteraction() )
	{
		ScriptedNPCInteraction_t *pInteraction = GetRunningDynamicInteraction();
		if ( pInteraction->iLoopBreakTriggerMethod & SNPCINT_LOOPBREAK_ON_DAMAGE )
		{
			CEAI_ScriptedSequence *_m_hCine = Get_m_hCine();
			// Can only break when we're in the action anim
			if ( _m_hCine->IsPlayingAction() )
			{
				_m_hCine->StopActionLoop( true );
			}
		}
	}

	// If we're not allowed to die, refuse to die
	// Allow my interaction partner to kill me though

	if ( m_iHealth <= 0 && HasInteractionCantDie() && attacker != m_hInteractionPartner )
	{
		m_iHealth = 1;
	}

	// -----------------------------------
	//  Fire outputs
 	// -----------------------------------
	if ( m_flLastDamageTime != gpGlobals->curtime )
	{
		// only fire once per frame
		m_OnDamaged->FireOutput( attacker, this);

		if( attacker && attacker->IsPlayer() )
		{
			m_OnDamagedByPlayer->FireOutput( attacker, this );
			
			// This also counts as being harmed by player's squad.
			m_OnDamagedByPlayerSquad->FireOutput( attacker, this );
		} else {
			// See if the person that injured me is an NPC.
			CAI_NPC *pAttacker = dynamic_cast<CAI_NPC *>( attacker );

			if( pAttacker && pAttacker->IsAlive() )
			{
				if( pAttacker->GetSquad() != NULL && pAttacker->IsInPlayerSquad() )
				{
					m_OnDamagedByPlayerSquad->FireOutput( attacker, this );
				}
			}
		}
	}

	if( (info.GetDamageType() & DMG_CRUSH) && !(info.GetDamageType() & DMG_PHYSGUN) && info.GetDamage() >= MIN_PHYSICS_FLINCH_DAMAGE )
	{
		SetCondition( COND_PHYSICS_DAMAGE );
	}

	if ( m_iHealth <= ( m_iMaxHealth / 2 ) )
	{
		m_OnHalfHealth->FireOutput( attacker, this );
	}

	// react to the damage (get mad)
	if ( ( (GetFlags() & FL_NPC) == 0 ) || !attacker )
		return 1;

	// If the attacker was an NPC or client update my position memory
	if ( attacker->GetFlags() & (FL_NPC | FL_CLIENT) )
	{
		// ------------------------------------------------------------------
		//				DO NOT CHANGE THIS CODE W/O CONSULTING
		// Only update information about my attacker I don't see my attacker
		// ------------------------------------------------------------------
		if ( !FInViewCone_Entity( info.GetAttacker() ) || !FVisible_Entity( info.GetAttacker() ) )
		{
			// -------------------------------------------------------------
			//  If I have an inflictor (enemy / grenade) update memory with
			//  position of inflictor, otherwise update with an position
			//  estimate for where the attack came from
			// ------------------------------------------------------
			Vector vAttackPos;
			CEntity *inflictor = CEntity::Instance(info.GetInflictor());
			if (inflictor)
			{
				vAttackPos = inflictor->GetAbsOrigin();
			}
			else
			{
				vAttackPos = (GetAbsOrigin() + ( *g_vecAttackDir * 64 ));
			}


			// ----------------------------------------------------------------
			//  If I already have an enemy, assume that the attack
			//  came from the enemy and update my enemy's position
			//  unless I already know about the attacker or I can see my enemy
			// ----------------------------------------------------------------
			if ( GetEnemy() != NULL							&&
				!GetEnemies()->HasMemory( info.GetAttacker() )			&&
				!HasCondition(COND_SEE_ENEMY)	)
			{
				UpdateEnemyMemory(GetEnemy_CBase(), vAttackPos, GetEnemy_CBase());
			}
			// ----------------------------------------------------------------
			//  If I already know about this enemy, update his position
			// ----------------------------------------------------------------
			else if (GetEnemies()->HasMemory( info.GetAttacker() ))
			{
				UpdateEnemyMemory(info.GetAttacker(), vAttackPos);
			}
			// -----------------------------------------------------------------
			//  Otherwise just note the position, but don't add enemy to my list
			// -----------------------------------------------------------------
			else
			{
				UpdateEnemyMemory(NULL, vAttackPos);
			}
		}

		// add pain to the conditions
		if ( IsLightDamage( info ) )
		{
			SetCondition( COND_LIGHT_DAMAGE );
		}
		if ( IsHeavyDamage( info ) )
		{
			SetCondition( COND_HEAVY_DAMAGE );
		}

		ForceGatherConditions();

		// Keep track of how much consecutive damage I have recieved
		if ((gpGlobals->curtime - m_flLastDamageTime) < 1.0)
		{
			m_flSumDamage += info.GetDamage();
		}
		else
		{
			m_flSumDamage = info.GetDamage();
		}
		m_flLastDamageTime = gpGlobals->curtime;
		if ( attacker && attacker->IsPlayer() )
			m_flLastPlayerDamageTime = gpGlobals->curtime;
		GetEnemies()->OnTookDamageFrom( info.GetAttacker() );

		if (m_flSumDamage > m_iMaxHealth*0.3)
		{
			SetCondition(COND_REPEATED_DAMAGE);
		}
	
		NotifyFriendsOfDamage( info.GetAttacker() );
	}

	// ---------------------------------------------------------------
	//  Insert a combat sound so that nearby NPCs know I've been hit
	// ---------------------------------------------------------------
	g_helpfunc.CSoundEnt_InsertSound(SOUND_COMBAT, GetAbsOrigin(), 1024, 0.5, BaseEntity(), SOUNDENT_CHANNEL_INJURY );
	
	return 1;
}
예제 #29
0
void GeneralTask::OnHttpResponse(int status_code, const char * buf, int len) {
    GotResponse(status_code, buf, len); // here?
    Wake();
}
예제 #30
0
void State::ApplyImpulse(const Vector2D& impulse) {
    Wake();
    _impulses.push_back(impulse);
}