Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_MortarShootAction.c
Go to the documentation of this file.
2{
3 [Attribute("0", desc: "If action should be performed from the left side of the mortar")]
5
6 [Attribute("0", desc: "Check if turret is empty to ensure that loader will not clip into the gunner of the mortar")]
7 protected bool m_bCheckIfTurretIsEmpty;
8
10 protected SCR_MortarMuzzleComponent m_MortarMuzzleComponent;
11 protected SCR_MortarShellGadgetComponent m_ShellComp;
13 protected float m_fFuzeTime = -1;
14
15 protected const LocalizedString WRONG_SHELL_TYPE = "#AR-UserAction_WrongShellType";
16 protected const LocalizedString ALREADY_LOADED = "#AR-UserAction_AlreadyLoaded";
17 protected const LocalizedString FIRE_WITH_MANUAL_FUZE = "#AR-UserAction_MortarFire_ManualFuze";
18 protected const LocalizedString FIRE_WITH_AUTOMATIC_FUZE = "#AR-UserAction_MortarFire_AutomaticFuze";
19 protected const LocalizedString AREA_OBSTRUCTED = "#AR-UserAction_SeatObstructed";
20
21 //------------------------------------------------------------------------------------------------
22 override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
23 {
24 m_MortarMuzzleComponent = SCR_MortarMuzzleComponent.Cast(pOwnerEntity.FindComponent(SCR_MortarMuzzleComponent));
26 m_MortarMagWell = m_MortarMuzzleComponent.GetMagazineWell();
27 }
28
29 //------------------------------------------------------------------------------------------------
30 override bool CanBeShownScript(IEntity user)
31 {
33 return false;
34
36 if (!character)
37 return false;
38
39 CharacterControllerComponent controllerComponent = character.GetCharacterController();
40 if (!controllerComponent || !controllerComponent.CanPlayItemGesture())
41 return false;
42
44 if (!m_ShellComp || m_ShellComp.IsLoaded())
45 return false;
46
47 return super.CanBeShownScript(user);
48 }
49
50 //------------------------------------------------------------------------------------------------
51 override bool CanBePerformedScript(IEntity user)
52 {
54 if (!character)
55 return false;
56
57 CharacterControllerComponent controllerComponent = character.GetCharacterController();
58 if (!controllerComponent || !controllerComponent.CanPlayItemGesture())
59 return false;
60
61 IEntity shell = controllerComponent.GetAttachedGadgetAtLeftHandSlot();
62 if (!shell)
63 return false;
64
66 if (!shellMagazine || !shellMagazine.GetMagazineWell() || shellMagazine.GetMagazineWell().Type() != m_MortarMagWell.Type())
67 {
69 return false;
70 }
71
72 if (m_MortarMuzzleComponent.GetAmmoCount() >= 1 || m_MortarMuzzleComponent.IsBeingLoaded())
73 {
75 return false;
76 }
77
79 {
80 SCR_BaseCompartmentManagerComponent compartmentManager = SCR_BaseCompartmentManagerComponent.Cast(GetOwner().FindComponent(SCR_BaseCompartmentManagerComponent));
81 if (compartmentManager && compartmentManager.AnyCompartmentsOccupiedOrLocked())
82 {
84 return false;
85 }
86 }
87
88 SetCannotPerformReason(string.Empty);
89 return true;
90 }
91
92 //------------------------------------------------------------------------------------------------
93 override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
94 {
95 if (m_MortarMuzzleComponent.GetAmmoCount() >= m_MortarMuzzleComponent.GetMaxAmmoCount())
96 return;
97
98 if (SCR_PlayerController.GetLocalControlledEntity() == pUserEntity || SCR_CharacterHelper.IsAPlayer(pUserEntity))
99 return;//filter out all players as this method is intended only for AI
100
101 ChimeraCharacter character = ChimeraCharacter.Cast(pUserEntity);
102 if (!character)
103 return;
104
105 if (!m_ShellComp)
106 {
107 CharacterControllerComponent controllerComponent = character.GetCharacterController();
108 if (!controllerComponent || !controllerComponent.IsGadgetInHands())
109 return;
110
111 IEntity shell = controllerComponent.GetAttachedGadgetAtLeftHandSlot();
112 m_ShellComp = SCR_MortarShellGadgetComponent.Cast(shell.FindComponent(SCR_MortarShellGadgetComponent));
113 if (!m_ShellComp)
114 return;
115 }
116
118 }
119
120 //------------------------------------------------------------------------------------------------
121 protected SCR_MortarShellGadgetComponent GetHeldShellGadgetComp(notnull ChimeraCharacter character)
122 {
123 CharacterControllerComponent controllerComponent = character.GetCharacterController();
124 if (!controllerComponent || !controllerComponent.IsGadgetInHands())
125 return null;
126
127 IEntity shell = controllerComponent.GetAttachedGadgetAtLeftHandSlot();
128 if (!shell)
129 return null;
130
131 return SCR_MortarShellGadgetComponent.Cast(shell.FindComponent(SCR_MortarShellGadgetComponent));
132 }
133
134 //------------------------------------------------------------------------------------------------
135 override bool GetActionNameScript(out string outName)
136 {
137 if (!m_ShellComp || !m_ShellComp.IsUsingTimeFuze() || !GetCannotPerformReason().IsEmpty())
138 return false;
139
140 UIInfo actionInfo = GetUIInfo();
141 if (!actionInfo)
142 return false;
143
145 if (!character)
146 return false;
147
148 SCR_ShellConfig timeFuzeConfig = m_ShellComp.GetSavedConfig(character);
149 if (!timeFuzeConfig || !timeFuzeConfig.IsUsingManualTime())
150 {
151 float elevation = m_MortarMuzzleComponent.GetMuzzleElevation();
152 float timeToDetonation = m_ShellComp.GetTimeToDetonation(elevation, false);
153 string fuzeTime = WidgetManager.Translate(UIConstants.VALUE_UNIT_SECONDS, timeToDetonation.ToString(-1, 1));
154 outName = WidgetManager.Translate(FIRE_WITH_AUTOMATIC_FUZE, fuzeTime);
155 }
156 else
157 {
158 string fuzeTime = WidgetManager.Translate(UIConstants.VALUE_UNIT_SECONDS, timeFuzeConfig.GetSavedTime().ToString(-1, 1));
159 outName = WidgetManager.Translate(FIRE_WITH_MANUAL_FUZE, fuzeTime);
160 }
161
162 return true;
163 }
164
165 //------------------------------------------------------------------------------------------------
166 override void OnActionStart(IEntity pUserEntity)
167 {
168 m_Loader = ChimeraCharacter.Cast(pUserEntity);
169 }
170
171 //------------------------------------------------------------------------------------------------
172 override protected bool OnSaveActionData(ScriptBitWriter writer)
173 {
174 if (!m_ShellComp)
175 return false;
176
178 if (!character)
179 return false;
180
181 float fuzeTime = -1;
182 SCR_ShellConfig timeFuzeConfig = m_ShellComp.GetSavedConfig(character);
183 if (timeFuzeConfig && timeFuzeConfig.IsUsingManualTime())
184 fuzeTime = timeFuzeConfig.GetSavedTime();
185
186 writer.WriteFloat(fuzeTime);
187
188 return super.OnSaveActionData(writer);
189 }
190
191 //------------------------------------------------------------------------------------------------
192 override protected bool OnLoadActionData(ScriptBitReader reader)
193 {
194 float fuzeTime;
195 reader.ReadFloat(fuzeTime);
196 bool loaded = super.OnLoadActionData(reader);
197
198 if (!m_Loader)
199 return false;
200
201 if (m_MortarMuzzleComponent.GetAmmoCount() >= m_MortarMuzzleComponent.GetMaxAmmoCount())
202 return false;
203
205 if (!m_ShellComp)
206 return false;
207
209
210 return loaded;
211 }
212}
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
void SetCannotPerformReason(string reason)
proto external IEntity GetOwner()
Returns the parent entity of this action.
string GetCannotPerformReason()
proto external UIInfo GetUIInfo()
Returns the UIInfo set for this user action or null if none.
proto external Managed FindComponent(typename typeName)
override void OnActionStart(IEntity pUserEntity)
const LocalizedString AREA_OBSTRUCTED
const LocalizedString FIRE_WITH_MANUAL_FUZE
SCR_MortarShellGadgetComponent m_ShellComp
override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
override bool CanBePerformedScript(IEntity user)
const LocalizedString WRONG_SHELL_TYPE
SCR_MortarShellGadgetComponent GetHeldShellGadgetComp(notnull ChimeraCharacter character)
const LocalizedString FIRE_WITH_AUTOMATIC_FUZE
SCR_MortarMuzzleComponent m_MortarMuzzleComponent
const LocalizedString ALREADY_LOADED
override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
override bool GetActionNameScript(out string outName)
bool OnSaveActionData(ScriptBitWriter writer)
bool OnLoadActionData(ScriptBitReader reader)
override bool CanBeShownScript(IEntity user)
BaseMagazineWell m_MortarMagWell
static IEntity GetLocalControlledEntity()
A scripted action class having optional logic to check if vehicle is valid.
UIInfo - allows to define UI elements.
Definition UIInfo.c:14
SCR_FieldOfViewSettings Attribute
proto native bool IsEmpty()