Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_VotingFactionCommanderRelieve.c
Go to the documentation of this file.
3{
4 //------------------------------------------------------------------------------------------------
5 override bool IsAvailable(int value, bool isOngoing)
6 {
8 if (!campaignGameMode || !campaignGameMode.GetCommanderRoleEnabled())
9 return false;
10
11 SCR_FactionManager fManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
12 if (!fManager)
13 return false;
14
15 Faction playerFaction = fManager.GetPlayerFaction(value);
16 if (!playerFaction)
17 return false;
18
19 SCR_Faction playerFactionLocal = SCR_Faction.Cast(fManager.GetLocalPlayerFaction());
20 if (!playerFactionLocal || playerFactionLocal != playerFaction)
21 return false;
22
23 return value == playerFactionLocal.GetCommanderId();
24 }
25
26 //------------------------------------------------------------------------------------------------
27 override int GetPlayerCount()
28 {
29 int playerCount;
30 SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
31
32 Faction targetFaction;
33
34 if (factionManager)
35 targetFaction = factionManager.GetPlayerFaction(m_iValue);
36
37 //--- Count only players on the same faction as target of the vote
38 //--- e.g., with 50% vote limit, only half of BLUFOR players will have to vote, not half of all players
39
40 Faction playerFaction;
41 array<int> players = {};
42
43 for (int i = 0, count = GetGame().GetPlayerManager().GetPlayers(players); i < count; i++)
44 {
45 playerFaction = factionManager.GetPlayerFaction(players[i]);
46
47 if (targetFaction == playerFaction)
48 playerCount++;
49 }
50
51 //--- Limit to prevent instant completion in a session with less than limited participants
52 return Math.Max(playerCount, m_iMinVotes);
53 }
54
55 //------------------------------------------------------------------------------------------------
56 override bool CanSendNotification(int value)
57 {
58 SCR_FactionManager fManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
59 if (!fManager)
60 return false;
61
62 return fManager.GetPlayerFaction(value) == fManager.GetLocalPlayerFaction();
63 }
64
65 //------------------------------------------------------------------------------------------------
66 override void OnVotingEnd(int value = DEFAULT_VALUE, int winner = DEFAULT_VALUE)
67 {
68 if (winner == DEFAULT_VALUE)
69 return;
70
71 if (Replication.IsClient())
72 return;
73
74 SCR_Faction faction = SCR_Faction.Cast(SCR_FactionManager.SGetPlayerFaction(winner));
75 if (!faction || faction.GetCommanderId() != winner)
76 return;
77
78 SCR_FactionCommanderHandlerComponent component = SCR_FactionCommanderHandlerComponent.GetInstance();
79 if (!component)
80 return;
81
82 component.SetFactionCommander(SCR_Faction.Cast(SCR_FactionManager.SGetPlayerFaction(winner)), SCR_Faction.AI_COMMANDER_ID);
83 }
84}
EVotingType
Definition EVotingType.c:2
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
SCR_BaseGameMode GetGameMode()
class SCR_CampaignHintStorage SCR_BaseContainerCustomTitleEnum(EHint, "m_eHintId")
int GetPlayers(out notnull array< int > outPlayers)
void SCR_FactionManager(IEntitySource src, IEntity parent)
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
Definition Math.c:13
Main replication API.
Definition Replication.c:14
static const int AI_COMMANDER_ID
int GetCommanderId()
static const int DEFAULT_VALUE