BVB Source Codes

CRYENGINE Show ShootOp.cpp Source code

Return Download CRYENGINE: download ShootOp.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 "ShootOp.h"
  5.  
  6. #include <CrySystem/XML/XMLAttrReader.h>
  7. #include "PipeUser.h"
  8.  
  9. #include <CryAISystem/IMovementSystem.h>
  10. #include <CryAISystem/MovementRequest.h>
  11.  
  12. namespace
  13. {
  14. struct ShootOpDictionary
  15. {
  16.         ShootOpDictionary();
  17.         CXMLAttrReader<ShootOp::ShootAt> shootAt;
  18.         CXMLAttrReader<EFireMode>        fireMode;
  19. };
  20.  
  21. ShootOpDictionary::ShootOpDictionary()
  22. {
  23.         shootAt.Reserve(3);
  24.         shootAt.Add("Target", ShootOp::AttentionTarget);
  25.         shootAt.Add("RefPoint", ShootOp::ReferencePoint);
  26.         shootAt.Add("LocalSpacePosition", ShootOp::LocalSpacePosition);
  27.  
  28.         fireMode.Add("Off", FIREMODE_OFF);
  29.         fireMode.Add("Burst", FIREMODE_BURST);
  30.         fireMode.Add("Continuous", FIREMODE_CONTINUOUS);
  31.         fireMode.Add("Forced", FIREMODE_FORCED);
  32.         fireMode.Add("Aim", FIREMODE_AIM);
  33.         fireMode.Add("Secondary", FIREMODE_SECONDARY);
  34.         fireMode.Add("SecondarySmoke", FIREMODE_SECONDARY_SMOKE);
  35.         fireMode.Add("Melee", FIREMODE_MELEE);
  36.         fireMode.Add("Kill", FIREMODE_KILL);
  37.         fireMode.Add("BurstWhileMoving", FIREMODE_BURST_WHILE_MOVING);
  38.         fireMode.Add("PanicSpread", FIREMODE_PANIC_SPREAD);
  39.         fireMode.Add("BurstDrawFire", FIREMODE_BURST_DRAWFIRE);
  40.         fireMode.Add("MeleeForced", FIREMODE_MELEE_FORCED);
  41.         fireMode.Add("BurstSnipe", FIREMODE_BURST_SNIPE);
  42.         fireMode.Add("AimSweep", FIREMODE_AIM_SWEEP);
  43.         fireMode.Add("BurstOnce", FIREMODE_BURST_ONCE);
  44. }
  45.  
  46. ShootOpDictionary g_shootOpDictionary;
  47. }
  48.  
  49. ShootOp::ShootOp()
  50.         : m_position(ZERO)
  51.         , m_duration(0.0f)
  52.         , m_shootAt(LocalSpacePosition)
  53.         , m_fireMode(FIREMODE_OFF)
  54.         , m_stance(STANCE_NULL)
  55. {
  56. }
  57.  
  58. ShootOp::ShootOp(const XmlNodeRef& node)
  59.         : m_position(ZERO)
  60.         , m_duration(0.0f)
  61.         , m_shootAt(LocalSpacePosition)
  62.         , m_fireMode(FIREMODE_OFF)
  63.         , m_stance(STANCE_NULL)
  64. {
  65.         g_shootOpDictionary.shootAt.Get(node, "at", m_shootAt, true);
  66.         g_shootOpDictionary.fireMode.Get(node, "fireMode", m_fireMode, true);
  67.         node->getAttr("position", m_position);
  68.         node->getAttr("duration", m_duration);
  69.         s_xml.GetStance(node, "stance", m_stance);
  70. }
  71.  
  72. ShootOp::ShootOp(const ShootOp& rhs)
  73.         : m_position(rhs.m_position)
  74.         , m_duration(rhs.m_duration)
  75.         , m_shootAt(rhs.m_shootAt)
  76.         , m_fireMode(rhs.m_fireMode)
  77.         , m_stance(rhs.m_stance)
  78. {
  79. }
  80.  
  81. void ShootOp::Enter(CPipeUser& pipeUser)
  82. {
  83.         if (m_shootAt == LocalSpacePosition)
  84.                 SetupFireTargetForLocalPosition(pipeUser);
  85.         else if (m_shootAt == ReferencePoint)
  86.                 SetupFireTargetForReferencePoint(pipeUser);
  87.  
  88.         pipeUser.SetFireMode(m_fireMode);
  89.  
  90.         if (m_stance != STANCE_NULL)
  91.                 pipeUser.m_State.bodystate = m_stance;
  92.  
  93.         MovementRequest movementRequest;
  94.         movementRequest.entityID = pipeUser.GetEntityID();
  95.         movementRequest.type = MovementRequest::Stop;
  96.         gEnv->pAISystem->GetMovementSystem()->QueueRequest(movementRequest);
  97.  
  98.         m_timeWhenShootingShouldEnd = gEnv->pTimer->GetFrameStartTime() + CTimeValue(m_duration);
  99. }
  100.  
  101. void ShootOp::Leave(CPipeUser& pipeUser)
  102. {
  103.         if (m_dummyTarget)
  104.         {
  105.                 pipeUser.SetFireTarget(NILREF);
  106.                 m_dummyTarget.Release();
  107.         }
  108.  
  109.         pipeUser.SetFireMode(FIREMODE_OFF);
  110. }
  111.  
  112. void ShootOp::Update(CPipeUser& pipeUser)
  113. {
  114.         FUNCTION_PROFILER(gEnv->pSystem, PROFILE_AI);
  115.  
  116.         const CTimeValue& now = gEnv->pTimer->GetFrameStartTime();
  117.  
  118.         if (now >= m_timeWhenShootingShouldEnd)
  119.                 GoalOpSucceeded();
  120. }
  121.  
  122. void ShootOp::Serialize(TSerialize serializer)
  123. {
  124.         serializer.BeginGroup("ShootOp");
  125.  
  126.         serializer.Value("position", m_position);
  127.         serializer.Value("timeWhenShootingShouldEnd", m_timeWhenShootingShouldEnd);
  128.         serializer.Value("duration", m_duration);
  129.         serializer.EnumValue("shootAt", m_shootAt, ShootAtSerializationHelperFirst, ShootAtSerializationHelperLast);
  130.         serializer.EnumValue("fireMode", m_fireMode, FIREMODE_SERIALIZATION_HELPER_FIRST, FIREMODE_SERIALIZATION_HELPER_LAST);
  131.         m_dummyTarget.Serialize(serializer, "shootTarget");
  132.  
  133.         serializer.EndGroup();
  134. }
  135.  
  136. void ShootOp::SetupFireTargetForLocalPosition(CPipeUser& pipeUser)
  137. {
  138.         // The user of this op has specified that the character
  139.         // should fire at a predefined position in local-space.
  140.         // Transform that position into world-space and store it
  141.         // in an AI object. The pipe user will shoot at this.
  142.  
  143.         gAIEnv.pAIObjectManager->CreateDummyObject(m_dummyTarget);
  144.  
  145.         const Vec3 fireTarget = pipeUser.GetEntity()->GetWorldTM().TransformPoint(m_position);
  146.  
  147.         m_dummyTarget->SetPos(fireTarget);
  148.  
  149.         pipeUser.SetFireTarget(m_dummyTarget);
  150. }
  151.  
  152. void ShootOp::SetupFireTargetForReferencePoint(CPipeUser& pipeUser)
  153. {
  154.         gAIEnv.pAIObjectManager->CreateDummyObject(m_dummyTarget);
  155.  
  156.         if (IAIObject* referencePoint = pipeUser.GetRefPoint())
  157.         {
  158.                 m_dummyTarget->SetPos(referencePoint->GetPos());
  159.         }
  160.         else
  161.         {
  162.                 gEnv->pLog->LogWarning("Agent '%s' is trying to shoot at the reference point but it hasn't been set.", pipeUser.GetName());
  163.                 m_dummyTarget->SetPos(ZERO);
  164.         }
  165.  
  166.         pipeUser.SetFireTarget(m_dummyTarget);
  167. }
  168.  
downloadShootOp.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