BVB Source Codes

CRYENGINE Show VehicleDamageBehaviorAISignal.cpp Source code

Return Download CRYENGINE: download VehicleDamageBehaviorAISignal.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #include "StdAfx.h"
  4. #include "VehicleDamageBehaviorAISignal.h"
  5.  
  6. #include <CryAISystem/IAgent.h>
  7. #include "IVehicleSystem.h"
  8.  
  9. CVehicleDamageBehaviorAISignal::CVehicleDamageBehaviorAISignal()
  10.         : m_pVehicle(nullptr)
  11.         , m_freeSignalRepeat(false)
  12.         , m_isActive(false)
  13.         , m_signalId(0)
  14.         , m_freeSignalRadius(15.0f)
  15.         , m_timeCounter(0.0f)
  16. {}
  17.  
  18. //------------------------------------------------------------------------
  19. bool CVehicleDamageBehaviorAISignal::Init(IVehicle* pVehicle, const CVehicleParams& table)
  20. {
  21.         m_pVehicle = pVehicle;
  22.  
  23.         CVehicleParams signalTable = table.findChild("AISignal");
  24.         if (!signalTable)
  25.                 return false;
  26.  
  27.         if (!signalTable.getAttr("signalId", m_signalId))
  28.                 return false;
  29.  
  30.         m_signalText = signalTable.getAttr("signalText");
  31.         m_freeSignalText = signalTable.getAttr("freeSignalText");
  32.         signalTable.getAttr("freeSignalRadius", m_freeSignalRadius);
  33.         signalTable.getAttr("freeSignalRepeat", m_freeSignalRepeat);
  34.  
  35.         return true;
  36. }
  37.  
  38. void CVehicleDamageBehaviorAISignal::Reset()
  39. {
  40.         if (m_isActive)
  41.                 ActivateUpdate(false);
  42. }
  43.  
  44. //------------------------------------------------------------------------
  45. void CVehicleDamageBehaviorAISignal::ActivateUpdate(bool activate)
  46. {
  47.         if (activate && !m_isActive)
  48.         {
  49.                 m_timeCounter = 1.0f;
  50.                 m_pVehicle->SetObjectUpdate(this, IVehicle::eVOU_AlwaysUpdate);
  51.         }
  52.         else if (!activate && m_isActive)
  53.                 m_pVehicle->SetObjectUpdate(this, IVehicle::eVOU_NoUpdate);
  54.  
  55.         m_isActive = activate;
  56. }
  57.  
  58. //------------------------------------------------------------------------
  59. void CVehicleDamageBehaviorAISignal::OnDamageEvent(EVehicleDamageBehaviorEvent event, const SVehicleDamageBehaviorEventParams& behaviorParams)
  60. {
  61.         if (event == eVDBE_VehicleDestroyed || event == eVDBE_MaxRatioExceeded)
  62.         {
  63.                 ActivateUpdate(false);
  64.                 return;
  65.         }
  66.  
  67.         if (event != eVDBE_Hit)
  68.                 return;
  69.  
  70.         IEntity* pEntity = m_pVehicle->GetEntity();
  71.         if (!pEntity || !pEntity->HasAI())
  72.                 return;
  73.  
  74.         IAISystem* pAISystem = gEnv->pAISystem;
  75.         if (!pAISystem)
  76.                 return;
  77.  
  78.         if (!m_freeSignalText.empty())
  79.         {
  80.                 Vec3 entityPosition = pEntity->GetPos();
  81.  
  82.                 IAISignalExtraData* pData = gEnv->pAISystem->CreateSignalExtraData();
  83.                 pData->point = entityPosition;
  84.  
  85.                 pAISystem->SendAnonymousSignal(m_signalId, m_freeSignalText.c_str(), entityPosition, m_freeSignalRadius, NULL, pData);
  86.  
  87.                 if (m_freeSignalRepeat)
  88.                         ActivateUpdate(true);
  89.         }
  90.  
  91.         IAISignalExtraData* pExtraData = pAISystem->CreateSignalExtraData();
  92.         CRY_ASSERT(pExtraData);
  93.         pExtraData->iValue = behaviorParams.shooterId;
  94.  
  95.         pAISystem->SendSignal(SIGNALFILTER_SENDER, m_signalId, m_signalText.c_str(), pEntity->GetAI(), pExtraData);
  96. }
  97.  
  98. void CVehicleDamageBehaviorAISignal::Update(const float deltaTime)
  99. {
  100.         if (m_pVehicle->IsDestroyed())
  101.         {
  102.                 ActivateUpdate(false);
  103.                 return;
  104.         }
  105.  
  106.         m_timeCounter -= deltaTime;
  107.         if (m_timeCounter < 0.0f)
  108.         {
  109.                 IEntity* pEntity = m_pVehicle->GetEntity();
  110.                 CRY_ASSERT(pEntity);
  111.                 IAISystem* pAISystem = gEnv->pAISystem;
  112.                 CRY_ASSERT(pAISystem);
  113.  
  114.                 Vec3 entityPosition = pEntity->GetPos();
  115.  
  116.                 IAISignalExtraData* pData = gEnv->pAISystem->CreateSignalExtraData();
  117.                 pData->point = entityPosition;
  118.  
  119.                 pAISystem->SendAnonymousSignal(m_signalId, m_freeSignalText.c_str(), entityPosition, m_freeSignalRadius, NULL, pData);
  120.  
  121.                 m_timeCounter = 1.0f;
  122.         }
  123. }
  124.  
  125. void CVehicleDamageBehaviorAISignal::GetMemoryUsage(ICrySizer* s) const
  126. {
  127.         s->AddObject(this, sizeof(*this));
  128.         s->AddObject(m_signalText);
  129.         s->AddObject(m_freeSignalText);
  130. }
  131.  
  132. DEFINE_VEHICLEOBJECT(CVehicleDamageBehaviorAISignal);
  133.  
downloadVehicleDamageBehaviorAISignal.cpp Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top