From 715da4d1bd03a058c95f7ef52e1a5f2686fdbde2 Mon Sep 17 00:00:00 2001 From: jonpas Date: Mon, 8 Nov 2021 00:21:36 +0100 Subject: [PATCH] Fortify - Add map area markers for Fortify objects (#8525) Co-authored-by: Seb <65898127+Seb105@users.noreply.github.com> Co-authored-by: PabstMirror --- AUTHORS.txt | 1 + addons/fortify/XEH_PREP.hpp | 1 + addons/fortify/XEH_postInit.sqf | 9 ++++ .../functions/fnc_createObjectMarker.sqf | 48 +++++++++++++++++++ .../fortify/functions/fnc_deployConfirm.sqf | 2 +- addons/fortify/initSettings.sqf | 15 ++++++ addons/fortify/stringtable.xml | 41 ++++++++++++++++ 7 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 addons/fortify/functions/fnc_createObjectMarker.sqf diff --git a/AUTHORS.txt b/AUTHORS.txt index 11f7094d44..e9391fb8cb 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -153,6 +153,7 @@ ruPaladin Rutger "RedBery" Meijering sancron Schwaggot +Seb shukari simon84 Skengman2 diff --git a/addons/fortify/XEH_PREP.hpp b/addons/fortify/XEH_PREP.hpp index b2feda35fa..785ba0a49f 100644 --- a/addons/fortify/XEH_PREP.hpp +++ b/addons/fortify/XEH_PREP.hpp @@ -15,3 +15,4 @@ ACEX_PREP(getPlaceableSet); ACEX_PREP(modifyAction); ACEX_PREP(setupModule); ACEX_PREP(buildLocationModule); +ACEX_PREP(createObjectMarker); diff --git a/addons/fortify/XEH_postInit.sqf b/addons/fortify/XEH_postInit.sqf index f14c4cb8f7..e46942d779 100644 --- a/addons/fortify/XEH_postInit.sqf +++ b/addons/fortify/XEH_postInit.sqf @@ -7,6 +7,15 @@ if (isServer) then { 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 + [ + FUNC(createObjectMarker), + [_unit, _object], + 1 + ] call CBA_fnc_waitAndExecute; + }; }] call CBA_fnc_addEventHandler; }; diff --git a/addons/fortify/functions/fnc_createObjectMarker.sqf b/addons/fortify/functions/fnc_createObjectMarker.sqf new file mode 100644 index 0000000000..45c79e7dca --- /dev/null +++ b/addons/fortify/functions/fnc_createObjectMarker.sqf @@ -0,0 +1,48 @@ +#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: Unit placing + * 1: Created fortify object + * + * Return Value: + * None + * + * Example: + * [player, cursorObject] call ace_fortify_fnc_createObjectMarker + * + * Public: No + */ + +params ["_unit", "_object"]; +TRACE_2("createObjectMarker",_unit,_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 +private _markerNameStr = format [QGVAR(marker_%1), hashValue _object]; +private _channel = if (GVAR(markObjectsOnMap) == 2) then { 0 } else { 1 }; + +private _marker = createMarkerLocal [_markerNameStr, _object, _channel, _unit]; +TRACE_2("created",_marker,_channel); +_marker setMarkerShapeLocal "RECTANGLE"; +_marker setMarkerBrushLocal "SolidFull"; +_marker setMarkerSizeLocal [(_maxWidth / 2),(_maxLength / 2)]; +_marker setMarkerDirLocal _direction; +_marker setMarkerColor "ColorGrey"; +_object setVariable [QGVAR(mapMarker), _marker, false]; + +_object addEventHandler ["Deleted", { + params ["_object"]; + private _marker = _object getVariable QGVAR(mapMarker); + TRACE_2("cleaning up marker",_object,_marker); + deleteMarker _marker +}]; diff --git a/addons/fortify/functions/fnc_deployConfirm.sqf b/addons/fortify/functions/fnc_deployConfirm.sqf index d04124fd93..e8d027f1fa 100644 --- a/addons/fortify/functions/fnc_deployConfirm.sqf +++ b/addons/fortify/functions/fnc_deployConfirm.sqf @@ -34,7 +34,7 @@ private _newObject = _typeOf createVehicle _posASL; _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. [QXGVAR(objectPlaced), [_unit, _side, _newObject]] call CBA_fnc_globalEvent; if (cba_events_control) then { diff --git a/addons/fortify/initSettings.sqf b/addons/fortify/initSettings.sqf index 6ecb47444a..0772bf9bdc 100644 --- a/addons/fortify/initSettings.sqf +++ b/addons/fortify/initSettings.sqf @@ -9,3 +9,18 @@ 2 ] ] call CBA_fnc_addSetting; + +[ + 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; diff --git a/addons/fortify/stringtable.xml b/addons/fortify/stringtable.xml index 3461791084..f0dd063d7b 100644 --- a/addons/fortify/stringtable.xml +++ b/addons/fortify/stringtable.xml @@ -157,6 +157,47 @@ Показывать всегда Her Zaman Göster + + Create map markers + + + Create map markers that look like terrain buildings when static fortifications are placed + + + Never + Nikdy + Nie + Никогда + Nigdy + Mai + Nunca + Jamais + 永不 + なし + 항상 안 함 + Nunca + 永不 + Asla + + + For units friendly to the placer + + + For everyone + 所有人 + Pour tous + Para todos + Per tutti + Dla wszystkich + Для всех + Für alle + Pro všechny + Para todos + 모든 사람 + 针对每一个人 + 全員に + Herkes için + Small Małe