← Home SEEBIE90 DOCS
Download PDF
The SOFLAM Integration Core mod is published under the Arma Public License (APL)Example code is free to useSuggestions: Discord to the author

SOFLAM Integration Core

The remote tablet Changed

A tablet in the hand that shows the live picture of a SOFLAM on a tripod and controls it from a distance. These are the parts that took work: who owns which state, how a screen gets a camera, and how to stop a character that the engine keeps releasing.

In plain wordsA tablet item that controls a tripod-mounted SOFLAM: link it to one device, see its camera, take over to aim. Every command goes through the relay, and the character is held still by an event the engine asks for every frame.

What it is

The tablet is a gadget, like the vanilla ballistic table: the hold pose and the inspect view come from the prefab (animation graph “Gadget”), and the screen is a render target, a layout whose root widget is a RTTexture0, which is set on the item as soon as it is in the hand. It is an item in the US arsenal; five lights on the bezel show power, link, laser, tracking and vision mode. Two attributes set the distances: m_fLinkSearchRange (5 m: how close a device must be to be linked by the tablet itself) and m_fLinkKeepRange (150 m: beyond it the link breaks; the connection bars divide it into five steps).

Link to a device→Camera on the screen→Keys and menu→Take over to aim

Linking to exactly one deviceChanged

If several SOFLAM stand side by side, “the nearest one in range” is not good enough: you do not know which one you are connected to. So the device itself carries a user action, GTG_SOFLAM_TabletLinkAction: “Link Tablet” on the device in front of you, “Unlink Tablet” while it is yours. The action takes the tablet that the player holds and the designator of the entity it sits on, and ties them together.

Example code – free to useGTG_SOFLAM_TabletLinkAction.c (excerpt)
override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
{
	GTG_SOFLAM_TabletComponent tablet = GetHeldTablet(pUserEntity);
	GTG_SOFLAM_LaserDesignatorComponent device = GetDesignator();
	if (!tablet || !device)
		return;

	if (tablet.IsLinkedToDevice(device))
		tablet.UnlinkDevice();
	else
		tablet.LinkToDevice(device);
}

override bool HasLocalEffectOnlyScript()
{
	return true;		// the link is state of this tablet on this machine, nothing to send
}

override bool CanBeShownScript(IEntity user)
{
	return GetHeldTablet(user) != null && GetDesignator() != null;		// only while you hold a tablet
}

The link is a reference to the device in the tablet on the owner’s machine. It is not replicated: nobody else needs to know which device your tablet looks at.

The Link key of the tablet (the one that picks the nearest device in range, TryLink) used to take whatever device was nearest, and the nearest one can be the SOFLAM in your own pocket: the search finds items in a character’s inventory too. Since 3.1.0 it asks IsStowedOnCharacter(deviceOwner) first, which walks up the parents of the device. A device that hangs below a character is stowed, unless it is the gadget that character holds in his hand. Stowed devices are skipped, and a device that is already linked and then gets stowed is unlinked (“SOFLAM stowed”).

Example code – free to useGTG_SOFLAM_TabletComponent.c (excerpt)
protected bool IsStowedOnCharacter(IEntity deviceOwner)
{
	IEntity parent = deviceOwner.GetParent();
	while (parent)
	{
		ChimeraCharacter character = ChimeraCharacter.Cast(parent);
		if (character)
		{
			SCR_GadgetManagerComponent gadgets = SCR_GadgetManagerComponent.GetGadgetManager(character);
			if (gadgets && gadgets.GetHeldGadget() == deviceOwner)
				return false;		// in the hand, not in a pocket

			return true;
		}

		parent = parent.GetParent();
	}

	return false;		// on a tripod or on the ground: no character above it
}

Since 3.1.1 only a SOFLAM that stands on a tripod can be linked. A designator that lies on the ground or is held in the hand is skipped, by the Link key and by the link action alike; the action is not even offered. The test walks up the parents of the device and looks for the tripod component, so a device on the tripod itself and one on the mount of a vehicle both count. A device that was linked and is taken off the tripod is unlinked, with the message SOFLAM not on a tripod; the Link key says No SOFLAM on a tripod in range when there is none.

Example code – free to useGTG_SOFLAM_TabletComponent.c (excerpt)
static bool IsMountedOnTripod(IEntity deviceOwner)
{
	IEntity entity = deviceOwner;
	while (entity)
	{
		if (entity.FindComponent(GTG_SOFLAM_TripodComponent))
			return true;

		entity = entity.GetParent();
	}

	return false;
}

Every command goes through the relay

The tablet never changes the device itself. Changing the laser code, for example, goes to the server as a request, and the server sets it and distributes it – the same path as a turn of the code wheel on the device. That is the lesson of Who may send applied once more: a client that does not own the device talks to nobody, so the GTG_SOFLAM_Relay on the player’s character carries the message. The aim command is the one that is sent often, so it is unreliable: a lost point heals itself with the next one, and an old one is never worth waiting for.

Example code – free to useGTG_SOFLAM_Relay.c (excerpt)
[RplRpc(RplChannel.Unreliable, RplRcver.Server)]
void GTG_SOFLAM_RelaisRichten(RplId geraet, vector welt)
{
	GTG_SOFLAM_LaserDesignatorComponent designator = GTG_SOFLAM_Relay.FindeGeraet(geraet);
	if (designator)
		designator.GTG_ServerRichten(welt);		// the server points head and turret at the world point
}

void GTG_SOFLAM_SendeRichten(RplId geraet, vector welt)
{
	Rpc(GTG_SOFLAM_RelaisRichten, geraet, welt);
}

A camera for the screen

The picture on the tablet is a ScriptCamera on the linked device, shown by a RenderTargetWidget in the layout. The hand uses half the resolution. The setup is the pattern on Several displays, one state: pick a camera index that others do not use, set field of view, near and far plane and the brightness, bind the widget to the index, and tell the vision component which camera to put its effects on. The five zoom levels are the same ones as on the sight, converted to a field of view with the same formula the vanilla optic uses:

Example code – free to useGTG_SOFLAM_TabletComponent.c (excerpt)
protected float GTG_ZoomFov(int level)
{
	float zoom = GTG_SOFLAM_ZoomFOVInfo.GTG_ZoomAt(level);
	float referenceTan = Math.Tan(FEED_FOV * 0.5 * Math.DEG2RAD) * 5.0;		// level 1 (5x) is exactly FEED_FOV
	return 2.0 * Math.RAD2DEG * Math.Atan2(referenceTan, zoom);
}

Taking over: the mouse aims, the character stands still

In the full-screen view the mouse swings the device, and W A S D or the stick swing it faster. The player’s own character must not walk or look around meanwhile. The obvious call is SetDisableMovementControls(true) – and it does not hold: the engine set it back to false in every frame, and the character kept walking with W A S D. The tablet still sets both locks in every frame (it checks and sets again), but the effect comes from somewhere else: an event the engine asks every frame.

Example code – free to useGTG_SOFLAM_Relay.c (excerpt)
class GTG_SOFLAM_MovementLock
{
	static bool s_bBlocked;		// the tablet sets it while full screen or take-over is active
}

modded class SCR_CharacterControllerComponent
{
	override bool SCR_GetDisableMovementControls()
	{
		if (GTG_SOFLAM_MovementLock.s_bBlocked)
		{
			// only the character of THIS player on THIS machine
			PlayerController controller = GetGame().GetPlayerController();
			if (controller && controller.GetControlledEntity() == GetOwner())
				return true;
		}

		return super.SCR_GetDisableMovementControls();
	}
}
Ask, do not tellA flag that you write is overwritten by whoever owns the state. An event the engine asks cannot be overwritten: it is asked again every frame, and the answer is yours. Whenever a setting is reset behind your back, look for the matching question the engine puts instead of fighting the answer.

Keys on the tablet

With the full-screen view or the take-over open, the character is held, and the normal character contexts do not deliver the keys of the device. The tablet therefore activates a context of its own, in every frame while a dialog or overlay is open, and the keys of the device (designate, range, track, vision modes, palette, zoom) are in it:

Example code – free to useGTG_SOFLAM_TabletComponent.c (excerpt)
// in the tablet's per-frame update:
if (m_bFull || m_bControl)
	GetGame().GetInputManager().ActivateContext("GTG_SOFLAM_TabletContext");
Example code – free to useConfigs/System/chimeraInputCommon.conf (excerpt)
ActionContext GTG_SOFLAM_TabletContext {
 Priority 100
 Flags 0x2 0
 ActionRefs {
  "WeaponOpticsZoomIn"
  "WeaponOpticsZoomOut"
  "GTG_SOFLAM_DesignatorAction"
  "GTG_SOFLAM_RangefindAction"
  "GTG_SOFLAM_TrackingAction"
  "GTG_SOFLAM_ThermalPaletteAction"
  "GTG_SOFLAM_VisionModeAction"
  // ...
 }
}

On the device in the hand, without a dialog, the context stays off: there the keys arrive through the normal character context.

Other picture sources

Since 3.1.0 the screen is not tied to the SOFLAM. The menu has three tiles in the source row: the SOFLAM, and two for pictures that other mods provide, UAV and UGV. A mod registers a GTG_SOFLAM_TabletFeedSource and the tablet gives it the same screen, the same zoom, the same thermal and night vision, a HUD of its own and a settings page. For a source the full-screen control does the same as for the SOFLAM: the mouse, W A S D or the right stick slew the camera, aiming leaves. All of it is on the page Picture sources for the tablet.

The tablet keeps one GTG_SOFLAM_VisionModeComponent of its own for these pictures (the SOFLAM picture keeps using the component of the device). It is the same component as in the GTG Thermal Framework, so the keys, the palettes and the controller layout are those of the SOFLAM. The component sits on the tablet prefab and works only while a source shows its picture.

The settings menu

The tablet has a menu of its own (TAB). Its Settings page holds the laser code, the default sight mode, the strength of the IR laser, the brightness of the display and, new in 3.1.0, Auto map marking: a switch, off by default, that decides whether the enemies a picture source sees are put on the map of the player. The state is kept by GTG_SOFLAM_TabletSettings as one static value on the viewer’s machine. The markers on the map are local: only that player sees them, and they disappear again when he switches the setting off. When a source has a settings page, the same switch is its last row, so a player does not have to leave the picture.

What it took

SymptomCauseFix
The Link key ties the tablet to a SOFLAM that lies on the groundEverything in range counted, whatever its stateLook for the tripod component up the parents (IsMountedOnTripod), in the Link key, in the action and when a link is checked
The Link key ties the tablet to the SOFLAM in the own pocketThe search runs over everything around the tablet, and a stowed item hangs below its characterSkip devices that hang below a character, unless the character holds them in his hand
The character walks while the tablet is full screenThe engine resets SetDisableMovementControls every frameAnswer the question the engine asks: override SCR_GetDisableMovementControls
The tablet’s keys do nothing in full screenThe character contexts are not delivering them with a held characterA context of your own, activated in every frame while the dialog is open
The picture on the screen is white after a mode changeThe feed camera pinned its own exposure, and the vision component wrote -1 to itRelease the brightness only on the player camera; the tablet pins its own
The infrared beam is visible to the naked eyeNight vision on the feed camera set the global infrared flagSet the flag for the feed only while it covers the whole screen
The readout on the screen does not updateThe screen is redrawn only when its content signature changes, and the signature missed palette, window and zoomPut every displayed value into the signature
Example code on this page is free to use in your own projects (credit appreciated). The SOFLAM Integration Core mod is published under the Arma Public License (APL). Suggestions: Discord. Arma Reforger / Enfusion are trademarks of Bohemia Interactive.
Impressum · Privacy Policy