30 class SCR_AISoundHandling
33 static const int SIGNAL_VALUE_SOLDIER_ALL = 1000;
34 static const int DISTANCE_TYPE_MID = 50;
35 static const int DISTANCE_TYPE_LONG = 2500;
38 static bool SetSignalsAndTransmit(
SCR_AITalkRequest request, IEntity speakerEntity, VoNComponent von, SignalsManagerComponent signalsMgr)
40 ref array<float> signals = {};
41 SCR_CallsignCharacterComponent callsignComponent;
42 int SN_Seed = signalsMgr.FindSignal(
"Seed");
44 SetSignal(SN_Seed, Math.RandomFloat(0, 1), signals);
47 callsignComponent = SCR_CallsignCharacterComponent.Cast(request.m_Entity.FindComponent(SCR_CallsignCharacterComponent));
54 if (!request.m_Entity)
56 ErrorMissingEntity(commType);
59 SetSignal_TargetValues(request.m_Entity, signalsMgr, signals);
60 SetSignal_SoldierCalledValues(signalsMgr, SIGNAL_VALUE_SOLDIER_ALL, signals);
66 if (request.m_vPosition == vector.Zero)
68 ErrorMissingPosition(commType);
71 SetSignal_SoldierCalledValues(signalsMgr, SIGNAL_VALUE_SOLDIER_ALL, signals);
73 float distanceType = SetSignal_PositionValues(request.m_Entity, signalsMgr, request.m_vPosition, speakerEntity.GetOrigin(), signals);
74 if (distanceType < DISTANCE_TYPE_MID)
76 else if (distanceType < DISTANCE_TYPE_LONG)
85 if (!request.m_Entity || request.m_vPosition == vector.Zero)
87 ErrorMissingEntityOrPosition(commType);
90 SetSignal_TargetFactionValues(request.m_Entity, signalsMgr, signals);
91 float distanceType = SetSignal_PositionValues(request.m_Entity, signalsMgr, request.m_vPosition, speakerEntity.GetOrigin(), signals);
92 SetSignal_FactionValues(signalsMgr, 1, signals);
93 if (distanceType < DISTANCE_TYPE_MID)
95 else if (distanceType < DISTANCE_TYPE_LONG)
103 SetSignal_SoldierCalledValues(signalsMgr, SIGNAL_VALUE_SOLDIER_ALL, signals);
109 if (!request.m_Entity)
111 ErrorMissingEntity(commType);
114 SetSignal_TargetValues(request.m_Entity, signalsMgr, signals);
115 SetSignal_SoldierCalledValues(signalsMgr, SIGNAL_VALUE_SOLDIER_ALL, signals);
121 if (!callsignComponent)
123 ErrorMissingCallsign(commType);
126 SetSignal_MountAsValues(signalsMgr, callsignComponent.GetCharacterCallsignIndex(), RoleInVehicleToSoundRoleEnum(request.m_EnumSignal), signals);
132 SetSignal_SoldierCalledValues(signalsMgr, SIGNAL_VALUE_SOLDIER_ALL, signals);
138 SetSignal_SoldierCalledValues(signalsMgr, SIGNAL_VALUE_SOLDIER_ALL, signals);
144 if (callsignComponent)
145 SetSignal_SoldierCalledValues(signalsMgr, callsignComponent.GetCharacterCallsignIndex(), signals);
151 if (!callsignComponent)
153 ErrorMissingCallsign(commType);
156 SetSignal_SoldierCalledValues(signalsMgr, callsignComponent.GetCharacterCallsignIndex(), signals);
157 SetSignal_FlankValues(signalsMgr, request.m_EnumSignal, signals);
163 SetSignal_SoldierCalledValues(signalsMgr, SIGNAL_VALUE_SOLDIER_ALL, signals);
204 SetSignal_SoldierCalledValues(signalsMgr, SIGNAL_VALUE_SOLDIER_ALL, signals);
220 if (callsignComponent)
221 SetSignal_SoldierCalledValues(signalsMgr, callsignComponent.GetCharacterCallsignIndex(), signals);
227 if (callsignComponent)
228 SetSignal_SoldierCalledValues(signalsMgr, callsignComponent.GetCharacterCallsignIndex(), signals);
239 Print(
string.Format(
"SCR_AISoundHandling: SetSignalsAndTransmit: Missing callsign for: %1",
typename.EnumToString(
ECommunicationType, commType)), LogLevel.ERROR);
245 Print(
string.Format(
"SCR_AISoundHandling: SetSignalsAndTransmit: Missing entity for: %1",
typename.EnumToString(
ECommunicationType, commType)), LogLevel.ERROR);
251 Print(
string.Format(
"SCR_AISoundHandling: SetSignalsAndTransmit: Missing position for: %1",
typename.EnumToString(
ECommunicationType, commType)), LogLevel.ERROR);
257 Print(
string.Format(
"SCR_AISoundHandling: SetSignalsAndTransmit: Missing entity or position for: %1",
typename.EnumToString(
ECommunicationType, commType)), LogLevel.ERROR);
261 static SCR_AIInfoComponent GetInfoComponent(IEntity entity)
266 if (entity && !agent)
268 AIControlComponent cc = AIControlComponent.Cast(entity.FindComponent(AIControlComponent));
275 return agent.m_InfoComponent;
279 static int InfoUnitRoleToSoundCharacterEnum(SCR_AIInfoComponent info)
282 return ECP_Characters.MAN;
283 else if (info.HasRole(EUnitRole.MACHINEGUNNER))
284 return ECP_Characters.MACHINE_GUNNER;
285 else if (info.HasRole(EUnitRole.AT_SPECIALIST))
286 return ECP_Characters.AT_SOLDIER;
287 else if (info.HasRole(EUnitRole.SNIPER))
288 return ECP_Characters.SNIPER;
289 else if (info.HasRole(EUnitRole.RIFLEMAN))
290 return ECP_Characters.SOLDIER;
291 return ECP_Characters.MAN;
295 static int RoleInVehicleToSoundRoleEnum(
int role)
301 return ECP_VehicleRoles.DRIVER;
305 return ECP_VehicleRoles.GUNNER;
309 return ECP_VehicleRoles.PASSANGER;
316 static int VehicleTypeToSoundVehicleFactionEnum(
int role)
320 case EVehicleType.VEHICLE:
322 return ECP_VehicleTypes.VEHICLE;
324 case EVehicleType.CAR:
326 return ECP_VehicleTypes.CAR;
328 case EVehicleType.TRUCK:
330 return ECP_VehicleTypes.TRUCK;
332 case EVehicleType.APC:
334 return ECP_VehicleTypes.APC;
336 case EVehicleType.COMM_TRUCK:
338 return ECP_VehicleTypes.COMM_TRUCK;
340 case EVehicleType.FUEL_TRUCK:
342 return ECP_VehicleTypes.FUEL_TRUCK;
344 case EVehicleType.SUPPLY_TRUCK:
346 return ECP_VehicleTypes.SUPPLY_TRUCK;
348 case EVehicleType.MORTAR:
350 return ECP_VehicleTypes.MORTAR;
354 return ECP_VehicleTypes.HELICOPTER;
361 static void SetSignal_TargetValues(IEntity target, SignalsManagerComponent signalsManagerComponent, array<float> signals)
363 if (target.IsInherited(Vehicle))
365 int SN_Vehicle = signalsManagerComponent.FindSignal(
"Vehicle");
367 SetSignal(SN_Vehicle, Vehicle.Cast(target).m_eVehicleType, signals);
370 else if (target.IsInherited(ChimeraCharacter))
372 int SN_Character = signalsManagerComponent.FindSignal(
"Character");
373 SCR_AIInfoComponent targetInfoComponent = GetInfoComponent(target);
374 int unitRole = InfoUnitRoleToSoundCharacterEnum(targetInfoComponent);
376 SetSignal(SN_Character, unitRole, signals);
382 static void SetSignal_TargetFactionValues(IEntity target, SignalsManagerComponent signalsManagerComponent, array<float> signals)
384 if (target.IsInherited(Vehicle))
386 int SN_VehicleFaction = signalsManagerComponent.FindSignal(
"VehicleFaction");
388 SetSignal(SN_VehicleFaction, 100 + VehicleTypeToSoundVehicleFactionEnum(Vehicle.Cast(target).m_eVehicleType), signals);
391 else if (target.IsInherited(ChimeraCharacter))
393 int SN_CharacterFaction = signalsManagerComponent.FindSignal(
"CharacterFaction");
394 SCR_AIInfoComponent targetInfoComponent = GetInfoComponent(target);
395 int unitRole = InfoUnitRoleToSoundCharacterEnum(targetInfoComponent) + 100;
397 SetSignal(SN_CharacterFaction, unitRole, signals);
403 static float SetSignal_PositionValues(IEntity target, SignalsManagerComponent signalsManagerComponent, vector locationTarget, vector locationSelf, array<float> signals)
406 locationTarget = target.GetOrigin();
408 float distance = vector.Distance(locationTarget,locationSelf);
411 vector dirVec = locationTarget - locationSelf;
412 float directionAngle = dirVec.ToYaw();
413 int SN_DirectionClose = signalsManagerComponent.FindSignal(
"DirectionClose");
414 SetSignal(SN_DirectionClose, directionAngle, signals);
416 else if (
distance < DISTANCE_TYPE_LONG)
418 vector dirVec = locationTarget - locationSelf;
419 float directionAngle = dirVec.ToYaw();
421 int SN_TargetDistance = signalsManagerComponent.FindSignal(
"TargetDistance");
422 int SN_DirectionAngle = signalsManagerComponent.FindSignal(
"DirectionAngle");
424 SetSignal(SN_TargetDistance,
distance, signals);
425 SetSignal(SN_DirectionAngle, directionAngle, signals);
427 else if (
distance >= DISTANCE_TYPE_LONG)
429 SetSignal_GridValues(locationTarget, signalsManagerComponent, signals);
435 static void SetSignal_GridValues(vector locationTarget, SignalsManagerComponent signalsManagerComponent, array<float> signals)
437 array<int> gridXcoords = {};
438 array<int> gridZcoords = {};
440 SCR_MapEntity.GetGridPos(locationTarget, gridX: gridX, gridZ: gridZ);
442 int SN_Grid = signalsManagerComponent.FindSignal(
"Grid");
443 for (
int i = 2; i >= 0; i--)
445 int mod = Math.Pow(10, i);
446 gridXcoords.Insert(gridX / mod);
447 gridZcoords.Insert(gridZ / mod);
451 for (
int i = 0; i < 3; i++)
452 SetSignal(SN_Grid, gridXcoords[i], signals);
453 for (
int i = 0; i < 3; i++)
454 SetSignal(SN_Grid, gridZcoords[i], signals);
458 static void SetSignal_SoldierCalledValues(SignalsManagerComponent signalsManagerComponent,
int soldierCalled, array<float> signals)
460 int SN_SoldierCalled = signalsManagerComponent.FindSignal(
"SoldierCalled");
462 SetSignal(SN_SoldierCalled, soldierCalled, signals);
466 static void SetSignal_MountAsValues(SignalsManagerComponent signalsManagerComponent,
int soldierCalledId,
int soldierRole, array<float> signals)
468 int SN_SoldierCalled = signalsManagerComponent.FindSignal(
"SoldierCalled");
469 int SN_Role = signalsManagerComponent.FindSignal(
"Role");
471 SetSignal(SN_SoldierCalled, soldierCalledId, signals);
472 SetSignal(SN_Role, soldierRole, signals);
476 static void SetSignal_FlankValues(SignalsManagerComponent signalsManagerComponent,
int flank, array<float> signals)
478 int SN_Flank = signalsManagerComponent.FindSignal(
"Flank");
480 SetSignal(SN_Flank, flank, signals);
484 static void SetSignal_FactionValues(SignalsManagerComponent signalsManagerComponent,
int faction, array<float> signals)
486 int SN_Faction = signalsManagerComponent.FindSignal(
"Faction");
488 SetSignal(SN_Faction, faction, signals);
492 static void SetSignal(
int index,
float value, notnull array<float> signals)
494 signals.Insert(
index);
495 signals.Insert(value);
504 return chimeraAgent.m_UtilityComponent.m_CommsHandler;