Exemplo n.º 1
0
/*virtual*/ void WBCompEldThinkerPatrol::Tick(float DeltaTime) {
  XTRACE_FUNCTION;

  Unused(DeltaTime);

  WBEntity* const pEntity = GetEntity();
  DEVASSERT(pEntity);

  WBCompEldTransform* const pTransform =
      pEntity->GetTransformComponent<WBCompEldTransform>();
  DEVASSERT(pTransform);

  WBCompRodinKnowledge* const pKnowledge = GET_WBCOMP(pEntity, RodinKnowledge);
  ASSERT(pKnowledge);

  WBCompRodinBlackboard* const pBlackboard =
      GET_WBCOMP(pEntity, RodinBlackboard);
  ASSERT(pBlackboard);

  const Vector CurrentLocation = pTransform->GetLocation();

  // Select the furthest patrol point that we know about.
  WBEntity* pFurthestPatrol = nullptr;
  float FurthestDistSq = -1.0f;

  const WBCompRodinKnowledge::TKnowledgeMap& KnowledgeMap =
      pKnowledge->GetKnowledgeMap();
  FOR_EACH_MAP(KnowledgeIter, KnowledgeMap, WBEntityRef,
               WBCompRodinKnowledge::TKnowledge) {
    WBEntity* pKnowledgeEntity = KnowledgeIter.GetKey().Get();
    const WBCompRodinKnowledge::TKnowledge& Knowledge =
        KnowledgeIter.GetValue();

    if (!pKnowledgeEntity) {
      continue;
    }

    // Filter out knowledge entities that aren't patrol markup.
    STATIC_HASHED_STRING(KnowledgeType);
    STATIC_HASHED_STRING(Patrol);
    if (Knowledge.GetHash(sKnowledgeType) != sPatrol) {
      continue;
    }

    WBCompEldTransform* const pKnowledgeTransform =
        pKnowledgeEntity->GetTransformComponent<WBCompEldTransform>();
    ASSERT(pKnowledgeTransform);

    const float DistSq =
        (pKnowledgeTransform->GetLocation() - CurrentLocation).LengthSquared();
    if (DistSq > FurthestDistSq) {
      FurthestDistSq = DistSq;
      pFurthestPatrol = pKnowledgeEntity;
    }
  }
Exemplo n.º 2
0
/*static*/ EldritchFactions::EFactionCon WBCompEldFaction::GetCon(
    const WBEntity* const pEntityA, const WBEntity* const pEntityB) {
  ASSERT(pEntityA);
  ASSERT(pEntityB);

  WBCompEldFaction* const pFactionA = GET_WBCOMP(pEntityA, EldFaction);
  WBCompEldFaction* const pFactionB = GET_WBCOMP(pEntityB, EldFaction);

  // Null factions are always treated as neutral.
  if (pFactionA == nullptr || pFactionB == nullptr) {
    return EldritchFactions::EFR_Neutral;
  }

  return EldritchFactions::GetCon(pFactionA->m_Faction, pFactionB->m_Faction);
}
Exemplo n.º 3
0
/*static*/ WBEntity* WBCompOwner::GetTopmostOwner( WBEntity* pEntity )
{
	if( !pEntity )
	{
		return NULL;
	}

	for(;;)
	{
		WBCompOwner* pOwner = GET_WBCOMP( pEntity, Owner );
		if( pOwner )
		{
			WBEntity* pOwnerEntity = pOwner->GetOwner();
			if( !pOwnerEntity )
			{
				// This entity has an Owner component, but it's null. Return this.
				return pEntity;
			}
			else
			{
				// Iterate up the chain.
				pEntity = pOwnerEntity;
			}
		}
		else
		{
			// This entity has no Owner component. Return this.
			return pEntity;
		}
	}
}
Exemplo n.º 4
0
/*virtual*/ void WBCompEldSensorMarkup::PollTick(const float DeltaTime) const {
  Unused(DeltaTime);

  const Array<WBCompEldMarkup*>* pMarkupComponents =
      WBComponentArrays::GetComponents<WBCompEldMarkup>();
  if (!pMarkupComponents) {
    return;
  }

  WBEntity* const pEntity = GetEntity();
  DEVASSERT(pEntity);

  WBCompRodinKnowledge* const pKnowledge = GET_WBCOMP(pEntity, RodinKnowledge);
  ASSERT(pKnowledge);

  WBCompEldTransform* const pTransform =
      GetEntity()->GetTransformComponent<WBCompEldTransform>();
  DEVASSERT(pTransform);

  const Vector CurrentLocation = pTransform->GetLocation();
  const float RadiusSq = Square(m_Radius);

  const uint NumMarkups = pMarkupComponents->Size();
  for (uint MarkupIndex = 0; MarkupIndex < NumMarkups; ++MarkupIndex) {
    WBCompEldMarkup* const pMarkup = (*pMarkupComponents)[MarkupIndex];
    ASSERT(pMarkup);

    // Only consider the desired type of markup
    if (pMarkup->GetMarkup() != m_Markup) {
      continue;
    }

    WBEntity* const pMarkupEntity = pMarkup->GetEntity();
    ASSERT(pMarkupEntity);

    WBCompEldTransform* const pMarkupTransform =
        pMarkupEntity->GetTransformComponent<WBCompEldTransform>();

    // Distance check
    const float DistanceSq =
        (pMarkupTransform->GetLocation() - CurrentLocation).LengthSquared();
    if (DistanceSq > RadiusSq) {
      continue;
    }

    // Update knowledge with this patrol
    WBCompRodinKnowledge::TKnowledge& Knowledge =
        pKnowledge->UpdateEntity(pMarkupEntity);

    STATIC_HASHED_STRING(DistanceSq);
    Knowledge.SetFloat(sDistanceSq, DistanceSq);

    STATIC_HASHED_STRING(LastKnownLocation);
    Knowledge.SetVector(sLastKnownLocation, pMarkupTransform->GetLocation());
    ASSERT(!pMarkupTransform->GetLocation().IsZero());

    STATIC_HASHED_STRING(KnowledgeType);
    Knowledge.SetHash(sKnowledgeType, m_Markup);
  }
}
/*virtual*/ void WBActionSetVariable::Execute()
{
	WBAction::Execute();

	WBParamEvaluator::SPEContext PEContext;
	PEContext.m_Entity = GetEntity();

	m_EntityPE.Evaluate( PEContext );
	m_ValuePE.Evaluate( PEContext );

	WBEntity* const pEntity = m_EntityPE.GetEntity();
	if( !pEntity )
	{
		return;
	}

	WBCompVariableMap* const pVariableMap = GET_WBCOMP( pEntity, VariableMap );
	if( !pVariableMap )
	{
		return;
	}

	WBEvent& Variables = pVariableMap->GetVariables();
	Variables.Set( m_VariableName, m_ValuePE );
}
Exemplo n.º 6
0
void WBCompEldSensorTheft::HandleTheft(WBEntity* const pThief) const {
  WBCompEldTransform* const pTransform =
      pThief->GetTransformComponent<WBCompEldTransform>();
  DEVASSERT(pTransform);

  WBCompRodinKnowledge* const pKnowledge =
      GET_WBCOMP(GetEntity(), RodinKnowledge);
  ASSERT(pKnowledge);

  WBCompRodinKnowledge::TKnowledge& Knowledge =
      pKnowledge->UpdateEntity(pThief);

  STATIC_HASHED_STRING(NeverExpire);
  Knowledge.SetBool(sNeverExpire, true);

  STATIC_HASHED_STRING(RegardAsHostile);
  Knowledge.SetBool(sRegardAsHostile, true);

  STATIC_HASHED_STRING(LastKnownLocation);
  Knowledge.SetVector(sLastKnownLocation, pTransform->GetLocation());
  ASSERT(!pTransform->GetLocation().IsZero());

  STATIC_HASHED_STRING(KnowledgeType);
  STATIC_HASHED_STRING(Target);
  Knowledge.SetHash(sKnowledgeType, sTarget);
}
Exemplo n.º 7
0
/*virtual*/ void WBPELookup::Evaluate( const WBParamEvaluator::SPEContext& Context, WBParamEvaluator::SEvaluatedParam& EvaluatedParam ) const
{
	ASSERT( Context.m_Entity );

	WBCompPEMap* const PEMap = GET_WBCOMP( Context.m_Entity, PEMap );
	if( !PEMap )
	{
		WARNDESC( "No PEMap for PE lookup." );
		return;
	}

	WBPE* const PE = PEMap->GetPE( m_Key );
	if( !PE )
	{
#if BUILD_DEV
		if( m_WarnFailure )
		{
			WARNDESC( "PE lookup found nothing in PEMap." );
		}
#endif
		return;
	}

	PE->Evaluate( Context, EvaluatedParam );
}
Exemplo n.º 8
0
void WBCompEldPickup::GiveItemTo(WBEntity* const pEntity) const {
  // Because Pickup is now unfortunately doubling as a Purchaseable.
  // This is such a hack.
  // TODO: Make a separate Purchaseable component.
  if (m_GiveItemDef == "") {
    // OnObtained is fired whether purchased, stolen, or given
    WB_MAKE_EVENT(OnObtained, GetEntity());
    WB_SET_AUTO(OnObtained, Entity, Buyer, pEntity);
    WB_DISPATCH_EVENT(GetEventManager(), OnObtained, GetEntity());

    return;
  }

  DEVASSERT(pEntity);

  WBCompEldInventory* const pInventory = GET_WBCOMP(pEntity, EldInventory);
  ASSERT(pInventory);

  WBEntity* const pGivenEntity =
      WBWorld::GetInstance()->CreateEntity(m_GiveItemDef);
  ASSERT(pGivenEntity);

  pInventory->AddItem(pGivenEntity);

  WB_MAKE_EVENT(OnItemGiven, GetEntity());
  WB_SET_AUTO(OnItemGiven, Entity, GivenTo, pEntity);
  WB_DISPATCH_EVENT(GetEventManager(), OnItemGiven, GetEntity());

  GetEntity()->Destroy();
}
Exemplo n.º 9
0
void WBCompEldHands::ShowWeaponAltHUD() const
{
	WBEntity* const pWeapon = GetWeaponAlt();
	ASSERT( pWeapon );

	WBCompEldWeapon* const pWeaponComponent = GET_WBCOMP( pWeapon, EldWeapon );
	ASSERT( pWeaponComponent );

	STATIC_HASHED_STRING( HUD );
	STATIC_HASHED_STRING( WeaponAltIcon );

	{
		WB_MAKE_EVENT( SetWidgetImage, NULL );
		WB_SET_AUTO( SetWidgetImage, Hash, Screen, sHUD );
		WB_SET_AUTO( SetWidgetImage, Hash, Widget, sWeaponAltIcon );
		WB_SET_AUTO( SetWidgetImage, Hash, Image, pWeaponComponent->GetWeaponIcon() );
		WB_DISPATCH_EVENT( WBWorld::GetInstance()->GetEventManager(), SetWidgetImage, NULL );
	}

	{
		WB_MAKE_EVENT( SetWidgetHidden, NULL );
		WB_SET_AUTO( SetWidgetHidden, Hash, Screen, sHUD );
		WB_SET_AUTO( SetWidgetHidden, Hash, Widget, sWeaponAltIcon );
		WB_SET_AUTO( SetWidgetHidden, Bool, Hidden, false );
		WB_DISPATCH_EVENT( WBWorld::GetInstance()->GetEventManager(), SetWidgetHidden, NULL );
	}
}
Exemplo n.º 10
0
void WBCompEldHands::GiveItem( const SimpleString& ItemDef ) const
{
	WBCompEldInventory* const	pInventory		= GET_WBCOMP( GetEntity(), EldInventory );
	ASSERT( pInventory );

	pInventory->AddItem( ItemDef );
}
Exemplo n.º 11
0
/*virtual*/ void WBPEEldGetItem::Evaluate( const WBParamEvaluator::SPEContext& Context, WBParamEvaluator::SEvaluatedParam& EvaluatedParam ) const
{
	WBParamEvaluator::SEvaluatedParam EntityValue;
	m_EntityPE->Evaluate( Context, EntityValue );

	WBEntity* const pEntity = EntityValue.GetEntity();
	if( !pEntity )
	{
		return;
	}

	WBCompEldInventory* const pInventory = GET_WBCOMP( pEntity, EldInventory );
	if( !pInventory )
	{
		return;
	}

	WBParamEvaluator::SEvaluatedParam SlotValue;
	m_SlotPE->Evaluate( Context, SlotValue );

	ASSERT( SlotValue.m_Type == WBParamEvaluator::EPT_String );

	const HashedString	SlotHash	= SlotValue.m_String;
	WBEntity* const		pItem		= pInventory->GetItem( SlotHash );

	EvaluatedParam.m_Type	= WBParamEvaluator::EPT_Entity;
	EvaluatedParam.m_Entity	= pItem;
}
/*virtual*/ void RodinBTNodeUseStatMod::OnFinish()
{
	RodinBTNodeDecorator::OnFinish();

	WBCompStatMod* const pStatMod = GET_WBCOMP( GetEntity(), StatMod );
	ASSERT( pStatMod );

	pStatMod->UnTriggerEvent( m_StatModEvent );
}
/*virtual*/ void WBActionTriggerStatMod::Execute()
{
	WBAction::Execute();

	WBCompStatMod* const pStatMod = GET_WBCOMP( GetEntity(), StatMod );
	ASSERT( pStatMod );

	pStatMod->SetEventActive( m_StatModEvent, m_Trigger );
}
Exemplo n.º 14
0
void WBCompEldMesh::SetSendUpdatedEvent() {
  // HACK: For optimization, only enable this event on entities that need it.
  WBEntity* const pEntity = GetEntity();
  WBCompEldDropShadow* const pDropShadow = GET_WBCOMP(pEntity, EldDropShadow);
  WBCompEldFrobbable* const pFrobbable = GET_WBCOMP(pEntity, EldFrobbable);

  if (pDropShadow && pDropShadow->GetUseMeshCenter()) {
    m_DependentDropShadow = pDropShadow;
  }

  if (pFrobbable && pFrobbable->GetUseMeshExtents()) {
    m_DependentFrobbable = pFrobbable;
  }

  if (m_DependentDropShadow || m_DependentFrobbable) {
    m_SendUpdatedEvent = true;
  }
}
Exemplo n.º 15
0
EldritchFactions::EFactionCon WBCompEldFaction::GetCon(
    const WBEntity* const pEntityB) {
  ASSERT(pEntityB);

  WBCompEldFaction* const pFactionB = GET_WBCOMP(pEntityB, EldFaction);
  ASSERT(pFactionB);

  return EldritchFactions::GetCon(m_Faction, pFactionB->m_Faction);
}
Exemplo n.º 16
0
void RodinBTNodeEldMoveTo::OnFinish()
{
	WBCompEldAIMotion* pAIMotion = GET_WBCOMP( GetEntity(), EldAIMotion );
	ASSERT( pAIMotion );

	if( m_MoveState == EMTS_StartedMove )
	{
		pAIMotion->StopMove();
	}
}
void RodinBTNodeEldTurnToward::OnFinish()
{
	WBCompEldAIMotion* pAIMotion = GET_WBCOMP( GetEntity(), EldAIMotion );
	ASSERT( pAIMotion );

	if( m_TurnState == ETTS_StartedTurn )
	{
		pAIMotion->StopMove();
	}
}
Exemplo n.º 18
0
void WBCompEldPickup::AcceptPaymentFrom(WBEntity* const pEntity) const {
  DEVASSERT(pEntity);

  WBCompEldWallet* const pWallet = GET_WBCOMP(pEntity, EldWallet);
  ASSERT(pWallet);

  ASSERT(pWallet->GetMoney() >= m_Price);

  pWallet->RemoveMoney(m_Price);
}
Exemplo n.º 19
0
void WBCompEldMesh::CopyAnimationsFrom(WBEntity* const pSourceEntity,
                                       const bool SuppressAnimEvents) const {
  ASSERT(pSourceEntity);
  ASSERT(m_Mesh);

  WBCompEldMesh* const pOtherMesh = GET_WBCOMP(pSourceEntity, EldMesh);
  ASSERT(pOtherMesh);

  m_Mesh->CopyAnimationsFrom(pOtherMesh->GetMesh());
  m_Mesh->SuppressAnimEvents(SuppressAnimEvents);
}
// Copied from WBActionEldSpawnEntity::GetSpawnTransform. For reals, unify this stuff somewhere.
void WBActionEldCheckLine::GetLineTransform( Vector& OutLocation, Angles& OutOrientation ) const
{
	WBEntity* const				pEntity			= GetOwner();
	DEVASSERT( pEntity );
	WBCompEldTransform* const	pTransform		= pEntity->GetTransformComponent<WBCompEldTransform>();
	DEVASSERT( pTransform );
	WBCompEldCamera* const		pCamera			= GET_WBCOMP( pEntity, EldCamera );
	WBCompEldHeadTracker* const	pHeadTracker	= GET_WBCOMP( pEntity, EldHeadTracker );

	// Get location
	{
		if( pHeadTracker )
		{
			OutLocation			= pHeadTracker->GetEyesLocation();
		}
		else
		{
			OutLocation			= pTransform->GetLocation();
			if( pCamera )
			{
				OutLocation		+= pCamera->GetViewTranslationOffset( WBCompEldCamera::EVM_All );
			}
		}
	}

	// Get orientation
	{
		if( pHeadTracker )
		{
			OutOrientation		= pHeadTracker->GetLookDirection().ToAngles();
		}
		else
		{
			OutOrientation		= pTransform->GetOrientation();
			if( pCamera )
			{
				OutOrientation	+= pCamera->GetViewOrientationOffset( WBCompEldCamera::EVM_All );
			}
		}
	}
}
Exemplo n.º 21
0
void WBActionEldGiveItem::GiveItemTo(const SimpleString& ItemDef,
                                     WBEntity* const pEntity) const {
  DEVASSERT(pEntity);

  WBCompEldInventory* const pInventory = GET_WBCOMP(pEntity, EldInventory);
  ASSERT(pInventory);

  WBEntity* const pGivenEntity = WBWorld::GetInstance()->CreateEntity(ItemDef);
  ASSERT(pGivenEntity);

  pInventory->AddItem(pGivenEntity);
}
Exemplo n.º 22
0
/*static*/ bool EldritchGame::IsPlayerDisablingPause()
{
    WBEntity* const pPlayer = GetPlayer();
    if( !pPlayer )
    {
        return false;
    }

    WBCompEldPlayer* const pPlayerComponent = GET_WBCOMP( pPlayer, EldPlayer );
    ASSERT( pPlayerComponent );

    return pPlayerComponent->IsDisablingPause();
}
Exemplo n.º 23
0
/*static*/ bool EldritchGame::IsPlayerVisible()
{
    WBEntity* const pPlayer = GetPlayer();
    if( !pPlayer )
    {
        return false;
    }

    WBCompEldVisible* const pVisible = GET_WBCOMP( pPlayer, EldVisible );
    ASSERT( pVisible );

    return pVisible->IsVisible();
}
Exemplo n.º 24
0
/*static*/ Angles EldritchGame::GetPlayerViewOrientation()
{
    WBEntity* const pPlayer = GetPlayer();
    ASSERT( pPlayer );

    WBCompEldTransform* const pTransform = pPlayer->GetTransformComponent<WBCompEldTransform>();
    DEVASSERT( pTransform );

    WBCompEldCamera* const pCamera = GET_WBCOMP( pPlayer, EldCamera );
    ASSERT( pCamera );

    return pTransform->GetOrientation() + pCamera->GetViewOrientationOffset( WBCompEldCamera::EVM_All );
}
Exemplo n.º 25
0
const SimpleString EldritchGame::GetRIPDamage()
{
    XTRACE_FUNCTION;

    WBEntity* const			pPlayer		= GetPlayer();
    WBCompEldPlayer* const	pPlayerComp	= GET_WBCOMP( pPlayer, EldPlayer );

    const SimpleString DamageDesc = pPlayerComp->GetLastDamageDesc();

    MAKEHASH( DamageDesc );
    const SimpleString RIPDamage = ConfigManager::GetLocalizedString( sDamageDesc, "" );

    return RIPDamage;
}
/*virtual*/ void WBActionRodinBlackboardWrite::Execute() {
  STATIC_HASHED_STRING(EventOwner);
  WBEntity* const pEntity = WBActionStack::Top().GetEntity(sEventOwner);
  DEVASSERT(pEntity);

  WBCompRodinBlackboard* const pBlackboard =
      GET_WBCOMP(pEntity, RodinBlackboard);
  ASSERT(pBlackboard);

  WBParamEvaluator::SPEContext Context;
  Context.m_Entity = pEntity;

  m_ValuePE.Evaluate(Context);
  pBlackboard->Set(m_BlackboardKey, m_ValuePE);
}
Exemplo n.º 27
0
void WBCompEldWatson::TickUnactivated()
{
	WBEntity* const pPlayer = EldritchGame::GetPlayer();
	ASSERT( pPlayer );

	WBCompEldSensorVision* const pVision = GET_WBCOMP( GetEntity(), EldSensorVision );
	ASSERT( pVision );

	if( pVision->IsVisible( pPlayer ) )
	{
		m_Activated = true;

		WB_MAKE_EVENT( OnWatsonActivated, GetEntity() );
		WB_DISPATCH_EVENT( GetEventManager(), OnWatsonActivated, GetEntity() );
	}
}
Exemplo n.º 28
0
/*virtual*/ void WBCompEldWeapon::AddContextToEvent( WBEvent& Event ) const
{
	Super::AddContextToEvent( Event );

	if( m_Ammo != HashedString::NullString )
	{
		WBEntity* const pOwnerEntity = WBCompOwner::GetTopmostOwner( GetEntity() );
		ASSERT( pOwnerEntity );

		WBCompEldAmmoBag* const pAmmoBag = GET_WBCOMP( pOwnerEntity, EldAmmoBag );
		if( pAmmoBag )
		{
			WB_SET_CONTEXT( Event, Bool, HasAmmo, pAmmoBag->HasAmmo( m_Ammo ) );
		}
	}
}
Exemplo n.º 29
0
RodinBTNode::ETickStatus RodinBTNodeBlackboardWrite::Tick(float DeltaTime) {
  Unused(DeltaTime);

  WBEntity* const pEntity = GetEntity();
  WBCompRodinBlackboard* const pBlackboard =
      GET_WBCOMP(pEntity, RodinBlackboard);
  ASSERT(pBlackboard);

  WBParamEvaluator::SPEContext Context;
  Context.m_Entity = pEntity;

  m_ValuePE.Evaluate(Context);
  pBlackboard->Set(m_BlackboardKey, m_ValuePE);

  return ETS_Success;
}
Exemplo n.º 30
0
/*static*/ bool EldritchGame::IsPlayerAlive()
{
    WBEntity* const pPlayer = GetPlayer();
    if( !pPlayer )
    {
        return false;
    }

    WBCompEldHealth* const pHealth = GET_WBCOMP( pPlayer, EldHealth );
    ASSERT( pHealth );
    if( pHealth->IsDead() )
    {
        return false;
    }

    return true;
}