Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AIGroupInfoComponent.c
Go to the documentation of this file.
1 [ComponentEditorProps(category: "GameScripted/AI", description: "Component for AI checking state of group")]
3 {
4 }
5 
6 enum EGroupControlMode
7 {
8  NONE = 0,
9  IDLE,
10  AUTONOMOUS,
12  LAST,
13 }
14 
15 class SCR_AIGroupInfoComponent : SCR_AIInfoBaseComponent
16 {
17  private EGroupControlMode m_eGroupControlMode;
18 
19  protected ref ScriptInvoker Event_OnControlModeChanged = new ScriptInvoker();
20 
22  protected AIAgent m_GrenadeThrowAgent;
23 
24  //------------------------------------------------------------------------------------------------
28  bool IsGrenadeThrowAllowed(AIAgent soldierAgent)
29  {
30  if (soldierAgent == m_GrenadeThrowAgent)
31  return true;
32  float time_ms = GetGame().GetWorld().GetWorldTime();
33  return time_ms > m_fTimeGrenadeThrowAllowed_ms;
34  }
35 
36  //------------------------------------------------------------------------------------------------
38  void OnAgentSelectedGrenade(AIAgent soldierAgent)
39  {
40  float time_ms = GetGame().GetWorld().GetWorldTime();
41  m_fTimeGrenadeThrowAllowed_ms = time_ms + 4000;
42  m_GrenadeThrowAgent = soldierAgent;
43  }
44 
45  //------------------------------------------------------------------------------------------------
46  override protected void OnPostInit(IEntity owner)
47  {
48  super.OnPostInit(owner);
49  SetEventMask(owner, EntityEvent.INIT);
50  }
51 
52  //------------------------------------------------------------------------------------------------
54  void SetGroupControlMode(EGroupControlMode currControlMode)
55  {
56  #ifdef AI_DEBUG
57  AddDebugMessage(string.Format("SetGroupControlMode: %1", typename.EnumToString(EGroupControlMode, currControlMode)), msgType:EAIDebugMsgType.INFO);
58  #endif
59 
60  if (currControlMode == m_eGroupControlMode)
61  return;
62 
63  if (!Replication.IsServer())
64  return;
65 
66 
67  RplSetGroupControlMode(currControlMode);
68  Rpc(RplSetGroupControlMode, currControlMode);
69  }
70 
71  //------------------------------------------------------------------------------------------------
72  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
73  protected void RplSetGroupControlMode(EGroupControlMode currControlMode)
74  {
75  m_eGroupControlMode = currControlMode;
76  Event_OnControlModeChanged.Invoke(currControlMode);
77 
78  SCR_AIWorld aiWorld = SCR_AIWorld.Cast(GetGame().GetAIWorld());
79  if (aiWorld)
80  aiWorld.GetOnControlModeChanged().Invoke(AIGroup.Cast(GetOwner()), currControlMode);
81  }
82 
83  //------------------------------------------------------------------------------------------------
85  EGroupControlMode GetGroupControlMode()
86  {
87  return m_eGroupControlMode;
88  }
89 
90  //------------------------------------------------------------------------------------------------
92  ScriptInvoker GetOnControlModeChanged()
93  {
95  }
96 
97  //======================================== RPL ========================================\\
98  override bool RplSave(ScriptBitWriter writer)
99  {
100  writer.WriteIntRange(m_eGroupControlMode, 0, EGroupControlMode.LAST-1);
101 
102  return true;
103  }
104 
105  //------------------------------------------------------------------------------------------------
106  override bool RplLoad(ScriptBitReader reader)
107  {
108  EGroupControlMode groupControlMode;
109 
110  reader.ReadIntRange(groupControlMode, 0, EGroupControlMode.LAST-1);
111 
112  RplSetGroupControlMode(groupControlMode);
113 
114  return true;
115  }
116 }
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
m_eGroupControlMode
SCR_AIGroupInfoComponentClass m_eGroupControlMode
EAIDebugMsgType
EAIDebugMsgType
Definition: SCR_AIDebugMessage.c:1
FOLLOWING_WAYPOINT
SCR_AIGroupInfoComponentClass FOLLOWING_WAYPOINT
Group is following a waypoint.
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SetGroupControlMode
void SetGroupControlMode(EGroupControlMode currControlMode)
Definition: SCR_AIGroupInfoComponent.c:54
SCR_AIGroupInfoComponentClass
Definition: SCR_AIGroupInfoComponent.c:2
RplRpc
SCR_AchievementsHandlerClass ScriptComponentClass RplRpc(RplChannel.Reliable, RplRcver.Owner)] void UnlockOnClient(AchievementId achievement)
Definition: SCR_AchievementsHandler.c:11
RplLoad
override bool RplLoad(ScriptBitReader reader)
Definition: SCR_AIGroupInfoComponent.c:106
m_fTimeGrenadeThrowAllowed_ms
protected float m_fTimeGrenadeThrowAllowed_ms
Definition: SCR_AIGroupInfoComponent.c:21
SCR_AIInfoBaseComponentClass
Definition: SCR_AIInfoBaseComponent.c:2
RplSetGroupControlMode
protected void RplSetGroupControlMode(EGroupControlMode currControlMode)
Definition: SCR_AIGroupInfoComponent.c:73
NONE
SCR_AIGroupInfoComponentClass NONE
SCR_AIWorld
Definition: SCR_AIWorld.c:23
OnAgentSelectedGrenade
void OnAgentSelectedGrenade(AIAgent soldierAgent)
Definition: SCR_AIGroupInfoComponent.c:38
m_GrenadeThrowAgent
protected AIAgent m_GrenadeThrowAgent
Definition: SCR_AIGroupInfoComponent.c:22
OnPostInit
override protected void OnPostInit(IEntity owner)
Called on PostInit when all components are added.
Definition: SCR_AIGroupInfoComponent.c:46
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
IsGrenadeThrowAllowed
bool IsGrenadeThrowAllowed(AIAgent soldierAgent)
Definition: SCR_AIGroupInfoComponent.c:28
GetGroupControlMode
EGroupControlMode GetGroupControlMode()
Definition: SCR_AIGroupInfoComponent.c:85
IDLE
SCR_AIGroupInfoComponentClass IDLE
Group has no waypoints and does not engage an enemy.
Definition: EMovementType.c:14
AUTONOMOUS
SCR_AIGroupInfoComponentClass AUTONOMOUS
Group behaves autonomously, e.g. engaging an enemy.
LAST
SCR_AIGroupInfoComponentClass LAST
GetOnControlModeChanged
ScriptInvoker GetOnControlModeChanged()
Definition: SCR_AIGroupInfoComponent.c:92
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180
Event_OnControlModeChanged
protected ref ScriptInvoker Event_OnControlModeChanged
Definition: SCR_AIGroupInfoComponent.c:19