Files
EscapistsReintroduced/docs/evidence/hq-speech-2026-10-05/native-radio-probe.c
T
jakub 6a667d8deb Capture current mission, AI, map and administration development
Include the current addon, terrain integrations, tools, regression tests and recorded development evidence.
2026-10-13 22:52:53 +02:00

65 lines
3.0 KiB
C

class ERR_TestRadioDelivery : ScriptedRadioMessage
{
BaseTransceiver Expected;
int Count;
float Quality;
override void OnDelivery(BaseTransceiver receiver, int freq, float quality)
{
if (receiver != Expected) return;
Count++; Quality = quality;
}
}
modded class ArmaReforgerScripted
{
protected float m_RadioProbeTime;
protected int m_RadioProbePhase;
protected BaseRadioComponent m_RadioProbeTX;
protected BaseRadioComponent m_RadioProbeRX;
protected ref ERR_TestRadioDelivery m_RadioProbeMessage;
protected bool m_RadioProbeFailed;
protected IEntity ProbeRadio(vector position)
{
EntitySpawnParams spawn = new EntitySpawnParams(); spawn.TransformMode = ETransformMode.WORLD;
spawn.Transform[3] = position;
return SpawnEntityPrefab(Resource.Load(ERR_EnemyRadio.BASIC), GetWorld(), spawn);
}
override void OnUpdate(BaseWorld world, float timeslice)
{
super.OnUpdate(world, timeslice);
if (m_RadioProbePhase > 11) return;
m_RadioProbeTime += timeslice;
if (m_RadioProbeTime < 2) return;
m_RadioProbeTime = 0;
if (m_RadioProbePhase == 0)
{
IEntity first = ProbeRadio("4000 50 4000"), second = ProbeRadio("4005 50 4000");
if (!first || !second) { Print("ERR RADIO PROBE FAILED: prefab"); m_RadioProbePhase = 99; return; }
m_RadioProbeTX = BaseRadioComponent.Cast(first.FindComponent(BaseRadioComponent));
m_RadioProbeRX = BaseRadioComponent.Cast(second.FindComponent(BaseRadioComponent));
m_RadioProbeTX.SetPower(true); m_RadioProbeRX.SetPower(true);
m_RadioProbeTX.SetEncryptionKey("probe"); m_RadioProbeRX.SetEncryptionKey("probe");
m_RadioProbeTX.GetTransceiver(0).SetFrequency(38000); m_RadioProbeRX.GetTransceiver(0).SetFrequency(38000);
m_RadioProbeTX.GetTransceiver(0).SetRange(1000); m_RadioProbeRX.GetTransceiver(0).SetMuteState(false);
}
else if (m_RadioProbePhase % 2 == 1)
{
m_RadioProbeMessage = new ERR_TestRadioDelivery(); m_RadioProbeMessage.Expected = m_RadioProbeRX.GetTransceiver(0);
m_RadioProbeMessage.SetEncryptionKey("probe");
m_RadioProbeTX.GetTransceiver(0).BeginTransmission(m_RadioProbeMessage);
}
else
{
bool shouldReceive = m_RadioProbePhase == 2;
bool received = m_RadioProbeMessage.Count > 0 && m_RadioProbeMessage.Quality > 0;
if (received != shouldReceive) m_RadioProbeFailed = true;
PrintFormat("ERR RADIO PROBE: phase=%1 count=%2 quality=%3 expected=%4", m_RadioProbePhase, m_RadioProbeMessage.Count, m_RadioProbeMessage.Quality, shouldReceive);
if (m_RadioProbePhase == 2) m_RadioProbeRX.GetTransceiver(0).SetFrequency(38200);
if (m_RadioProbePhase == 4) { m_RadioProbeRX.GetTransceiver(0).SetFrequency(38000); m_RadioProbeRX.SetEncryptionKey("wrong"); }
if (m_RadioProbePhase == 6) { m_RadioProbeRX.SetEncryptionKey("probe"); m_RadioProbeRX.SetPower(false); }
if (m_RadioProbePhase == 8) { m_RadioProbeRX.SetPower(true); m_RadioProbeTX.GetTransceiver(0).SetRange(1); }
if (m_RadioProbePhase == 10) PrintFormat("ERR TERRAIN LOOKUP COMPLETE: radio_probe_pass=%1", !m_RadioProbeFailed);
}
m_RadioProbePhase++;
}
}