Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

Fortify: Add map area markers for ACEX Fortify Objects #258

Closed
wants to merge 15 commits into from
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,4 @@ VyMajoris(W-Cephei)<vycanismajoriscsa@gmail.com>
Winter <simon@agius-muscat.net>
wizpig64
zGuba
Seb <sebsmith90@gmail.com>
1 change: 1 addition & 0 deletions addons/fortify/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ PREP(getPlaceableSet);
PREP(modifyAction);
PREP(setupModule);
PREP(buildLocationModule);
PREP(createObjectMarker);
37 changes: 37 additions & 0 deletions addons/fortify/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
#include "script_component.hpp"

if (isServer) then {
GVAR(markerObjectHashmap) = createHashMap;
publicVariable QGVAR(markerObjectHashmap);
[QGVAR(registerObjects), LINKFUNC(registerObjects)] call CBA_fnc_addEventHandler;
[QGVAR(objectPlaced), {
params ["_unit", "_side", "_object"];
TRACE_3("objectPlaced",_unit,_side,_object);
private _jipID = [QGVAR(addActionToObject), [_side, _object]] call CBA_fnc_globalEventJIP;
[_jipID, _object] call CBA_fnc_removeGlobalEventJIP; // idealy this function should be called on the server
if (GVAR(markObjectsOnMap) isNotEqualTo 0 && {_object isKindOf "Static"}) then {
// Wait ensures correct marker pos/rot as object is moved into position after creation
[
{_this call FUNC(createObjectMarker)},
_object,
1
] call CBA_fnc_waitAndExecute;
};
}] call CBA_fnc_addEventHandler;
};

Expand Down Expand Up @@ -63,3 +73,30 @@ GVAR(objectRotationZ) = 0;
[_object, 0, ["ACE_MainActions"], _removeAction] call ACEFUNC(interact_menu,addActionToObject);
};
}] call CBA_fnc_addEventHandler;

[QGVAR(setMarkerVisible), {
params ["_object"];
[
{!isNull player},
{
params ["_object"];
private _currentUnit = call CBA_fnc_currentUnit;
private _objectSide = _object getVariable QGVAR(objectSide);
private _playerSide = side group _currentUnit;
private _marker = _object getVariable QGVAR(mapMarker);
// If enemy placed object, hide marker, else set visible
private _alpha = if (GVAR(markObjectsOnMap) isEqualTo 1 && {_objectSide getFriend _playerSide < 0.6}) then {0} else {1};
_marker setMarkerAlphaLocal _alpha;
},
_object
] call CBA_fnc_waitUntilAndExecute;
Seb105 marked this conversation as resolved.
Show resolved Hide resolved
}] call CBA_fnc_addEventHandler;


// Reset map marker alphas when the side of the controlled unit changes.
["group", {
{
private _object = _y;
[QGVAR(setMarkerVisible), _object] call CBA_fnc_localEvent;
} forEach GVAR(markerObjectHashmap);
}] call CBA_fnc_addPlayerEventHandler;
54 changes: 54 additions & 0 deletions addons/fortify/functions/fnc_createObjectMarker.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include "script_component.hpp"

/*
* Author: Seb
* Creates a map marker for a created static object but only for sides friendly to the creator side.
*
* Arguments:
* 0: Created fortify object <OBJECT>
*
* Return Value:
* None
*
* Example:
* _object call acex_fortify_fnc_createObjectMarker
*
* Public: No
*/

params ["_object"];

// Get Object size and direction
private _bbr = 0 boundingBoxReal _object;
private _p1 = _bbr select 0;
private _p2 = _bbr select 1;
private _maxWidth = abs ((_p2 select 0) - (_p1 select 0));
private _maxLength = abs ((_p2 select 1) - (_p1 select 1));
private _direction = getDir _object;

// Marker name unique to this object, add it to a hashmap that matches map markers to objects.
private _markerNameStr = format [QGVAR(marker_%1), _object];

// Create marker, set alpha using global event
private _marker = createMarkerLocal [_markerNameStr, _object];
_marker setMarkerShapeLocal "RECTANGLE";
_marker setMarkerBrushLocal "SolidFull";
_marker setMarkerSizeLocal [(_maxWidth / 2),(_maxLength / 2)];
_marker setMarkerDirLocal _direction;
_marker setMarkerColor "ColorGrey";
_object setVariable [QGVAR(mapMarker), _marker, true];

// Marker Alpha set in EH:
private _jipID = [QGVAR(setMarkerVisible), _object] call CBA_fnc_globalEventJIP;
[_jipID, _object] call CBA_fnc_removeGlobalEventJIP;

GVAR(markerObjectHashmap) set [_marker, _object];
publicVariable QGVAR(markerObjectHashmap);

_object addEventHandler ["Deleted", {
params ["_object"];
private _marker = _object getVariable QGVAR(mapMarker);
GVAR(markerObjectHashmap) deleteAt _marker;
deleteMarker _marker;
publicVariable QGVAR(markerObjectHashmap);
}];
3 changes: 2 additions & 1 deletion addons/fortify/functions/fnc_deployConfirm.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ private _vectorDir = vectorDir _object;
deleteVehicle _object;

private _newObject = _typeOf createVehicle _posASL;
_newObject setVariable [QGVAR(objectSide), _side, true];
_newObject setPosASL _posASL;
_newObject setVectorDirAndUp [_vectorDir, _vectorUp];

// Server will use this event to run the jip compatible QGVAR(addActionToObject) event
// Server will use this event to run the jip compatible QGVAR(addActionToObject) event and create the related map marker.
[QGVAR(objectPlaced), [_unit, _side, _newObject]] call CBA_fnc_globalEvent;

if (cba_events_control) then {
Expand Down
17 changes: 16 additions & 1 deletion addons/fortify/initSettings.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,19 @@
[LLSTRING(settingHintNone), LLSTRING(settingHintHasTool), LLSTRING(settingHintEveryone)],
2
]
] call CBA_settings_fnc_init;
] call CBA_fnc_addSetting;

[
Seb105 marked this conversation as resolved.
Show resolved Hide resolved
QGVAR(markObjectsOnMap),
"LIST",
[LLSTRING(markObjectsOnMap), LLSTRING(markObjectsOnMapDesc)],
LLSTRING(settingsCategory),
[
[0, 1, 2],
[LLSTRING(markObjectsOnMapNone), LLSTRING(markObjectsOnMapFriendly), LLSTRING(markObjectsOnMapEveryone)],
1
],
true,
{},
true
] call CBA_fnc_addSetting;
15 changes: 15 additions & 0 deletions addons/fortify/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,21 @@
<Russian>Показывать всегда</Russian>
<Turkish>Her Zaman Göster</Turkish>
</Key>
<Key ID="STR_ACEX_Fortify_markObjectsOnMap">
<English>Create map markers</English>
</Key>
<Key ID="STR_ACEX_Fortify_markObjectsOnMapDesc">
<English>Create map markers that look like terrain buildings when static fortifications are placed</English>
</Key>
<Key ID="STR_ACEX_Fortify_markObjectsOnMapNone">
<English>Never</English>
</Key>
<Key ID="STR_ACEX_Fortify_markObjectsOnMapFriendly">
<English>For units friendly to the placer</English>
</Key>
<Key ID="STR_ACEX_Fortify_markObjectsOnMapEveryone">
<English>For everyone</English>
</Key>
<Key ID="STR_ACEX_Fortify_small">
<English>Small</English>
<Polish>Małe</Polish>
Expand Down