Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AICoverLock.c
Go to the documentation of this file.
1 
20 {
21  vector m_vCoverPos;
22  vector m_vCoverTallestPos;
23 
24  vector m_vCoverDirXZ; // Cover direction vector in XZ plane
25 
26  int m_iTileX;
27  int m_iTileY;
28  int m_iCoverId;
29 
30  //----------------------------------------------------------------
31  vector GetPosition()
32  {
33  return m_vCoverPos;
34  }
35 
36  //----------------------------------------------------------------
38  bool IsValid()
39  {
40  return m_vCoverPos != vector.Zero;
41  }
42 
43  //----------------------------------------------------------------
45  void Release()
46  {
47  CoverManagerComponent coverMgr = GetCoverManager();
48  if (!coverMgr)
49  return;
50 
51  // Release cover
52  if (m_vCoverPos != vector.Zero)
53  coverMgr.SetOccupiedCover(m_iTileX, m_iTileY, m_iCoverId, false);
54 
55  // This object is invalid from now on
56  m_vCoverPos = vector.Zero;
57  }
58 
59  //----------------------------------------------------------------
60  void SCR_AICoverLock(int tilex, int tiley, int coverId, vector coverPos, vector coverTallestPos)
61  {
62  CoverManagerComponent coverMgr = GetCoverManager();
63  if (!coverMgr)
64  return;
65 
66  m_iTileX = tilex;
67  m_iTileY = tiley;
68  m_iCoverId = coverId;
69  m_vCoverPos = coverPos;
70  m_vCoverTallestPos = coverTallestPos;
71 
72  // Occupy cover on construction
73  if (m_vCoverPos != vector.Zero)
74  coverMgr.SetOccupiedCover(m_iTileX, m_iTileY, m_iCoverId, true);
75 
76  // Calculate derived values
77  vector coverDirXZ = m_vCoverTallestPos - m_vCoverPos;
78  coverDirXZ[1] = 0;
79  coverDirXZ.Normalize();
80  m_vCoverDirXZ = coverDirXZ;
81  }
82 
83  //----------------------------------------------------------------
84  void ~SCR_AICoverLock()
85  {
86  Release();
87  }
88 
89  //----------------------------------------------------------------
91  float CosAngleToThreat(vector threatPos)
92  {
93  vector dirCoverToThreatXZ = threatPos - m_vCoverPos;
94  dirCoverToThreatXZ[1] = 0;
95  dirCoverToThreatXZ.Normalize();
96  float cosAngleCoverDirThreatDir = vector.Dot(m_vCoverDirXZ, dirCoverToThreatXZ);
97  return cosAngleCoverDirThreatDir;
98  }
99 
100  //----------------------------------------------------------------
101  protected static CoverManagerComponent GetCoverManager()
102  {
103  AIWorld aiWorld = GetGame().GetAIWorld();
104  if (!aiWorld)
105  return null;
106  CoverManagerComponent coverMgr = CoverManagerComponent.Cast(aiWorld.FindComponent(CoverManagerComponent));
107  return coverMgr;
108  }
109 }
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_AICoverLock
Definition: SCR_AICoverLock.c:19