4 static string SCR_AIGetStringFromPort(Node node,
string port)
6 const string UNASSIGNED_VARIABLE =
"Unassigned";
7 if ( node.GetVariableType(
true, port) ==
string )
10 if(!node.GetVariableIn(port, value))
11 value = UNASSIGNED_VARIABLE;
14 else if ( node.GetVariableType(
true, port) ==
int )
17 if(!node.GetVariableIn(port, value))
18 return UNASSIGNED_VARIABLE;
19 return value.ToString();
21 else if ( node.GetVariableType(
true, port) ==
float )
24 if(!node.GetVariableIn(port, value))
25 return UNASSIGNED_VARIABLE;
26 return value.ToString();
28 else if ( node.GetVariableType(
true, port) ==
bool )
31 if(!node.GetVariableIn(port, value))
32 return UNASSIGNED_VARIABLE;
33 return value.ToString();
35 else if ( node.GetVariableType(
true, port) == vector )
38 if(!node.GetVariableIn(port, value))
39 return UNASSIGNED_VARIABLE;
40 return value.ToString();
42 else if ( node.GetVariableType(
true, port).IsInherited(Managed) )
45 if(!node.GetVariableIn(port, value))
46 return UNASSIGNED_VARIABLE;
48 return value.ToString();
57 static ref RandomGenerator s_AIRandomGenerator =
new RandomGenerator;
91 static bool FindAvailableCompartmentInVehicles (array<IEntity> vehicles,
ECompartmentType roleInVehicle, out BaseCompartmentSlot compartmentOut, out IEntity vehicleOut)
93 foreach (IEntity vehicle: vehicles)
97 BaseCompartmentManagerComponent compartmentMan = BaseCompartmentManagerComponent.Cast(vehicle.FindComponent(BaseCompartmentManagerComponent));
98 if (!Vehicle.Cast(vehicle) || !compartmentMan)
100 ref array<BaseCompartmentSlot> compartments = {};
101 compartmentMan.GetCompartments(compartments);
102 foreach (BaseCompartmentSlot compartment: compartments)
106 if (!compartment.GetOccupant() && compartment.IsCompartmentAccessible())
108 compartmentOut = compartment;
109 vehicleOut = vehicle;
119 static bool IsInCompartment(notnull AIAgent agent)
121 IEntity controlledEntity = agent.GetControlledEntity();
122 if (!controlledEntity)
125 ChimeraCharacter character = ChimeraCharacter.Cast(controlledEntity);
129 return character.IsInVehicle();
135 class SCR_AIWeaponHandling
146 array<BaseMuzzleComponent> muzzles = {};
147 weaponComp.GetMuzzlesList(muzzles);
150 if (!currentMuzzle || muzzles.IsEmpty())
153 int currentMuzzleId = muzzles.Find(currentMuzzle);
154 return currentMuzzleId;
158 static BaseMagazineComponent GetCurrentMagazineComponent(BaseWeaponManagerComponent weapMgr)
169 return currentMuzzle.GetMagazine();
173 static bool IsCurrentMuzzleChambered(BaseWeaponManagerComponent weapMgr)
184 return currentMuzzle.IsCurrentBarrelChambered();
191 return weapMgr.GetCurrentWeapon();
195 static void StartMuzzleSwitch(CharacterControllerComponent controller,
int newMuzzleId)
197 controller.SetMuzzle(newMuzzleId);
201 static void StartMagazineSwitchCharacter(CharacterControllerComponent controller, BaseMagazineComponent newMagazineComp)
203 controller.ReloadWeaponWith(newMagazineComp.GetOwner());
209 controller.DoReloadWeaponWith(newMagazineComp.GetOwner());
213 static void StartWeaponSwitchCharacter(CharacterControllerComponent controller,
BaseWeaponComponent newWeaponComp)
215 controller.TryEquipRightHandItem(newWeaponComp.GetOwner(),
EEquipItemType.EEquipTypeWeapon,
false);
222 IEntity newWeaponEntity = newWeaponComp.GetOwner();
223 BaseWeaponManagerComponent weaponMgr = controller.GetWeaponManager();
228 array<WeaponSlotComponent> slots = {};
229 weaponMgr.GetWeaponsSlots(slots);
232 if (slot.GetWeaponEntity() == newWeaponEntity)
233 newWeaponSlot = slot;
242 controller.SelectWeapon(turretOperator, newWeaponSlot);
248 static bool IsAlive(IEntity entity)
254 ChimeraCharacter character = ChimeraCharacter.Cast(entity);
256 damageManager = character.GetDamageManager();
263 return damageManager.GetState() !=
EDamageState.DESTROYED;
267 static bool IsCharacterWounded(IEntity entity)
269 ChimeraCharacter character = ChimeraCharacter.Cast(entity);
277 return damageManager.IsDamagedOverTime(
EDamageType.BLEEDING);