Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AISendMessageDebugUI.c
Go to the documentation of this file.
1 class SCR_AISendMessageDebugUIClass : GenericEntityClass
2 {
3 
4 };
5 
11 {
12  static SCR_AISendMessageDebugUI s_Instance;
13 
14  //-------------------------------------------------------------------------------------------
15  static void Init()
16  {
17  if (!s_Instance)
19  }
20 
21 
22  //-------------------------------------------------------------------------------------------
23  void SCR_AISendMessageDebugUI(IEntitySource src, IEntity parent)
24  {
25  SetFlags(EntityFlags.ACTIVE, true);
26  SetEventMask(EntityEvent.FRAME);
27  }
28 
29 
30  //-------------------------------------------------------------------------------------------
31  protected override void EOnFrame(IEntity owner, float timeSlice)
32  {
33  if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_AI_SEND_MESSAGE))
34  s_Instance.Draw();
35  }
36 
37 
38  //-------------------------------------------------------------------------------------------
39  protected void Draw()
40  {
41  SCR_AIWorld aiWorld = SCR_AIWorld.Cast(GetGame().GetAIWorld());
42  if (!aiWorld)
43  return;
44 
45  // Init list with string names of info messages
46  /*
47  TStringArray InfoMsgNames = {};
48  TIntArray infoMsgEnumValues = {};
49  typename msgTypeInfoTypename = EMessageType_Info;
50  for (int i = 0; i < msgTypeInfoTypename.GetVariableCount(); i++)
51  {
52  int _enumValue;
53  msgTypeInfoTypename.GetVariableValue(null, i, _enumValue);
54 
55  // Check if this message is supposed to be used in this Debug UI
56  SCR_AIMessageBase msg = aiWorld.GetInfoMessageOfType(_enumValue);
57 
58  if (!msg)
59  continue;
60 
61  if (!msg.DebugUi_IsVisible())
62  continue;
63 
64  infoMsgEnumValues.Insert(_enumValue);
65 
66  string _s = typename.EnumToString(EMessageType_Info, _enumValue);
67  InfoMsgNames.Insert(_s);
68  }
69  */
70 
71  DbgUI.Begin("Send Info Message");
72 
73 
74  // Text: Selected AI
75  IEntity ent = GetSelectedAiEntity();
76  DbgUI.Text(string.Format("Selected Entity: %1", ent.ToString()));
77 
78  if (ent)
79  {
80  AIControlComponent controlComp = AIControlComponent.Cast(ent.FindComponent(AIControlComponent));
81  AIAgent senderAgent = controlComp.GetAIAgent();
82 
83  const int buttonWidth = 500;
84  if (DbgUI.Button("INFO: NO AMMO -> GROUP", buttonWidth))
85  SendNoAmmoToGroup(ent, senderAgent);
86  }
87  else
88  {
89  DbgUI.Text("You must select an AI Entity with Game Master first!");
90  }
91 
92  DbgUI.End();
93  }
94 
95 
96  //-------------------------------------------------------------------------------------------
97  protected SCR_AIMessageBase CreateInfoMessage(EMessageType_Info msgType, IEntity senderEnt)
98  {
99  SCR_AIWorld aiWorld = SCR_AIWorld.Cast(GetGame().GetAIWorld());
100  AIControlComponent controlComp = AIControlComponent.Cast(senderEnt.FindComponent(AIControlComponent));
101  AIAgent senderAgent = controlComp.GetAIAgent();
102  AICommunicationComponent mailbox = senderAgent.GetCommunicationComponent();
103 
104  SCR_AIMessageBase msg; // Disabled for now, it's not useful
105 
106  return msg;
107  }
108 
109 
110  //-------------------------------------------------------------------------------------------
111  protected void BroadcastMessage(AIAgent senderAgent, SCR_AIMessageBase msg, AIAgent receiver)
112  {
113  AICommunicationComponent mailbox = senderAgent.GetCommunicationComponent();
114 
115  mailbox.RequestBroadcast(msg, receiver);
116  }
117 
118 
119  //-------------------------------------------------------------------------------------------
120  protected IEntity GetSelectedAiEntity()
121  {
122  // Get first AI entity selected in Game Master
124  set<SCR_EditableEntityComponent> selectedEntities = new set<SCR_EditableEntityComponent>();
125  filter.GetEntities(selectedEntities);
126 
127  if (selectedEntities.Count() != 1)
128  return null;
129 
130  SCR_EditableCharacterComponent editCharacterComp = SCR_EditableCharacterComponent.Cast(selectedEntities[0]);
131 
132  if (!editCharacterComp)
133  return null;
134 
135  return editCharacterComp.GetAgent().GetControlledEntity();
136  }
137 
138 
139 
140 
141  //-------------------------------------------------------------------------------------------
142  protected void SendNoAmmoToGroup(IEntity senderEnt, AIAgent senderAgent)
143  {
144  SCR_AIMessage_NoAmmo msg = SCR_AIMessage_NoAmmo.Cast(CreateInfoMessage(EMessageType_Info.NO_AMMO, senderEnt));
145 
146  msg.m_entityToSupply = senderEnt;
147 
148  // Get current mag well
149  auto weaponManager = BaseWeaponManagerComponent.Cast(senderEnt.FindComponent(BaseWeaponManagerComponent));
150  BaseWeaponComponent weapon = weaponManager.GetCurrent();
151  msg.m_MagazineWell = SCR_AIGetMagazineWell.GetWeaponMainMagazineWell(weapon);
152  Print(string.Format("SendNoAmmoToGroup: %1, %2", senderEnt.ToString(), msg.m_MagazineWell.ToString()), LogLevel.DEBUG);
153 
154  AIAgent receiver = senderAgent.GetParentGroup();
155  BroadcastMessage(senderAgent, msg, receiver);
156  }
157 };
EEditableEntityState
EEditableEntityState
Definition: EEditableEntityState.c:37
SpawnEntity
protected IEntity SpawnEntity(ResourceName entityResourceName, notnull IEntity slotOwner)
Definition: SCR_CatalogEntitySpawnerComponent.c:1008
SCR_AISendMessageDebugUI
Definition: SCR_AISendMessageDebugUI.c:10
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
EMessageType_Info
EMessageType_Info
Definition: SCR_AIMessage.c:1
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
SCR_AIWorld
Definition: SCR_AIWorld.c:23
s_Instance
SCR_SpawnerSlotManagerClass s_Instance
Class used for managing changes and removals of slots present in world.
BaseWeaponComponent
Definition: BaseWeaponComponent.c:12
SCR_BaseEditableEntityFilter
Definition: SCR_BaseEditableEntityFilter.c:13
SCR_AISendMessageDebugUIClass
Definition: SCR_AISendMessageDebugUI.c:1
SCR_AIGetMagazineWell
Definition: SCR_AIGetMagazineWell.c:1
SCR_AIMessage_NoAmmo
Definition: SCR_AIMessage.c:131
SCR_DebugMenuID
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition: DebugMenuID.c:3
SCR_AIMessageBase
Definition: SCR_AIMessage.c:44