Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_RecruitAIGroupCommand.c
Go to the documentation of this file.
1//------------------------------------------------------------------------------------------------
4{
5 //------------------------------------------------------------------------------------------------
6 override bool Execute(IEntity cursorTarget, IEntity target, vector targetPosition, int playerID, bool isClient)
7 {
8 if (isClient)
9 {
10 //place to place a logic that would be executed for other players
11 return true;
12 }
13
14 SCR_PlayerController playerController = SCR_PlayerController.Cast(GetGame().GetPlayerManager().GetPlayerController(playerID));
15 if (!playerController)
16 return false;
17
18 SCR_PlayerControllerGroupComponent groupController = SCR_PlayerControllerGroupComponent.Cast(playerController.FindComponent(SCR_PlayerControllerGroupComponent));
19 if (!groupController)
20 return false;
21
22 SCR_ChimeraCharacter character = SCR_ChimeraCharacter.Cast(cursorTarget);
23 if (!character)
24 return false;
25
26 if (GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(character) == 0)
27 groupController.RequestAddAIAgent(character, playerID);
28
29 return true;
30 }
31
32 //------------------------------------------------------------------------------------------------
33 override bool CanBeExecuted(IEntity target)
34 {
35 if (!target || !super.CanBeExecuted(target))
36 return false;
37
38 SCR_ChimeraCharacter character = SCR_ChimeraCharacter.Cast(target);
39 if (!character)
40 return false;
41
42 if (!character.IsRecruitable())
43 {
45 return false;
46 }
47
48 SCR_PlayerControllerGroupComponent groupController = SCR_PlayerControllerGroupComponent.GetLocalPlayerControllerGroupComponent();
49 if (!groupController)
50 return false;
51
52 SCR_AIGroup group = groupController.GetPlayersGroup();
53 if (!group)
54 return false;
55
56 // Check if target's faction is friendly to controller's Faction.
57 // Currently target faction may be different from player controller's faction.
58 Faction targetFaction = character.GetFaction();
59 Faction controllerFaction = group.GetFaction();
60 if (targetFaction && controllerFaction && (targetFaction.GetFactionKey() != controllerFaction.GetFactionKey()))
61 return false;
62
63 SCR_AIGroup slaveGroup = group.GetSlave();
64 if (!slaveGroup)
65 return false;
66
67 SCR_CommandingManagerComponent commandingManager = SCR_CommandingManagerComponent.GetInstance();
68 if (!commandingManager)
69 return false;
70
71 int maxAI = commandingManager.GetMaxAIPerGroup();
72 //in case there is a limit on how many AIs can be in single group.
73 if (maxAI != -1 && slaveGroup.GetServerAgentsCount() >= maxAI)
74 {
76 return false;
77 }
78
79 return true;
80 }
81
82 //------------------------------------------------------------------------------------------------
83 override bool CanBeShown()
84 {
86 return false;
87
88 PlayerCamera camera = GetGame().GetPlayerController().GetPlayerCamera();
89 if (!camera)
90 return false;
91
92 IEntity cursorTarget = camera.GetCursorTarget();
93 SCR_ChimeraCharacter character = SCR_ChimeraCharacter.Cast(cursorTarget);
94 if (!character)
95 return false;
96
97 if (character.IsRecruited())
98 return false;
99
101 if (!playerController)
102 return false;
103
104 SCR_RespawnSystemComponent respawnComponent = SCR_RespawnSystemComponent.GetInstance();
105 if (!respawnComponent)
106 return false;
107
108 SCR_PlayerControllerGroupComponent groupController = SCR_PlayerControllerGroupComponent.GetLocalPlayerControllerGroupComponent();
109 if (!groupController)
110 return false;
111
112 SCR_AIGroup group = groupController.GetPlayersGroup();
113 if (!group)
114 return false;
115
116 if (!CanRoleShow())
117 return false;
118
119 if (character.GetFaction() != playerController.GetLocalControlledEntityFaction())
120 return false;
121
122 int playerID = GetGame().GetPlayerController().GetPlayerId();
123
124 SCR_Faction playerFaction;
125 SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
126 if (factionManager)
127 {
128 playerFaction = SCR_Faction.Cast(factionManager.GetPlayerFaction(playerID));
129 }
130
131 return !groupController.IsAICharacterInAnyGroup(character, playerFaction);
132 }
133}
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
void SCR_CommandingManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
void SCR_FactionManager(IEntitySource src, IEntity parent)
SCR_AIGroup GetSlave()
Faction GetFaction()
override bool CanBeShownInCurrentLifeState()
void SetCannotExecuteReason(LocalizedString newReason)
static const LocalizedString CANNOT_EXECUTE_SOLDIER_NA
static Faction GetLocalControlledEntityFaction()
proto external PlayerController GetPlayerController()