Skip to content

Commit

Permalink
Add Building Markers (#704)
Browse files Browse the repository at this point in the history
* Add Building Markers
* Setting to automatically create building markers when placing buildings in Zeus
* Marker updates when building is moved
* Marker is deleted if building is deleted
* https://youtu.be/ZjzdFPfDdwQ

---------

Co-authored-by: mharis001 <mhariszakar@gmail.com>
  • Loading branch information
ampersand38 and mharis001 authored Mar 8, 2023
1 parent bd5c438 commit 87b9d3c
Show file tree
Hide file tree
Showing 17 changed files with 269 additions and 1 deletion.
13 changes: 13 additions & 0 deletions addons/attributes/initAttributes.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,19 @@
{alive _entity && {_entity isKindOf "LandVehicle" || {_entity isKindOf "Air"} || {_entity isKindOf "Ship"}}}
] call FUNC(addAttribute);

[
"Object",
[ELSTRING(building_markers,BuildingMarker), ELSTRING(building_markers,BuildingMarker_Tooltip)],
QGVAR(toolbox),
[1, 2, [ELSTRING(common,Disabled), ELSTRING(common,Enabled)]],
{
private _buildings = SELECTED_OBJECTS select {_x isKindOf "Building"};
[_buildings, _value] call EFUNC(building_markers,set);
},
{_entity getVariable [QEGVAR(building_markers,marker), ""] != ""},
{_entity isKindOf "Building"}
] call FUNC(addAttribute);

[
"Object",
LSTRING(PlateNumber),
Expand Down
1 change: 1 addition & 0 deletions addons/building_markers/$PBOPREFIX$
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x\zen\addons\building_markers
17 changes: 17 additions & 0 deletions addons/building_markers/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Extended_PreStart_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_preStart));
};
};

class Extended_PreInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_preInit));
};
};

class Extended_PostInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_postInit));
};
};
3 changes: 3 additions & 0 deletions addons/building_markers/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PREP(handleObjectEdited);
PREP(handleObjectPlaced);
PREP(set);
15 changes: 15 additions & 0 deletions addons/building_markers/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "script_component.hpp"

if (isServer) then {
[QGVAR(set), LINKFUNC(set)] call CBA_fnc_addEventHandler;
};

if (hasInterface) then {
EGVAR(area_markers,blacklist) pushBack QUOTE(ADDON);

[QEGVAR(placement,done), {
params ["_object"];

[nil, _object] call FUNC(handleObjectPlaced);
}] call CBA_fnc_addEventHandler;
};
18 changes: 18 additions & 0 deletions addons/building_markers/XEH_preInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "script_component.hpp"

ADDON = false;

PREP_RECOMPILE_START;
#include "XEH_PREP.hpp"
PREP_RECOMPILE_END;

#include "initSettings.sqf"

["ModuleCurator_F", "Init", {
params ["_logic"];

_logic addEventHandler ["CuratorObjectPlaced", {call FUNC(handleObjectPlaced)}];
_logic addEventHandler ["CuratorObjectEdited", {call FUNC(handleObjectEdited)}];
}, true, [], true] call CBA_fnc_addClassEventHandler;

ADDON = true;
3 changes: 3 additions & 0 deletions addons/building_markers/XEH_preStart.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "script_component.hpp"

#include "XEH_PREP.hpp"
19 changes: 19 additions & 0 deletions addons/building_markers/config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "script_component.hpp"

class CfgPatches {
class ADDON {
name = COMPONENT_NAME;
units[] = {};
weapons[] = {};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {"zen_common"};
author = ECSTRING(main,Author);
authors[] = {"Ampersand"};
url = ECSTRING(main,URL);
VERSION_CONFIG;
};
};

PRELOAD_ADDONS;

#include "CfgEventHandlers.hpp"
25 changes: 25 additions & 0 deletions addons/building_markers/functions/fnc_handleObjectEdited.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "script_component.hpp"
/*
* Author: Ampersand
* Handles editing of an object by Zeus.
*
* Arguments:
* 0: Curator (not used) <OBJECT>
* 1: Edited Object <OBJECT>
*
* Return Value:
* None
*
* Example:
* [_curator, _object] call zen_building_markers_fnc_handleObjectEdited
*
* Public: No
*/

params ["", "_object"];

private _marker = _object getVariable [QGVAR(marker), ""];

if (_marker != "") then {
[QGVAR(set), [_object, true]] call CBA_fnc_serverEvent;
};
23 changes: 23 additions & 0 deletions addons/building_markers/functions/fnc_handleObjectPlaced.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "script_component.hpp"
/*
* Author: Ampersand
* Handles placement of an object by Zeus.
*
* Arguments:
* 0: Curator (not used) <OBJECT>
* 1: Placed Object <OBJECT>
*
* Return Value:
* None
*
* Example:
* [_curator, _object] call zen_building_markers_fnc_handleObjectPlaced
*
* Public: No
*/

params ["", "_object"];

if (GVAR(enabled) && {_object isKindOf "Building"}) then {
[QGVAR(set), [_object, true]] call CBA_fnc_serverEvent;
};
79 changes: 79 additions & 0 deletions addons/building_markers/functions/fnc_set.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#include "script_component.hpp"
/*
* Author: Ampersand
* Creates or deletes the given object's building marker.
*
* Building markers are grey rectangle area markers for the object's bounding box
* that mimic those of terrain buildings.
*
* When called in create mode for an object that already has a building marker,
* the object's marker is updated to reflect its current position and direction.
*
* The marker is automatically updated if the object is edited by Zeus and
* deleted when the object is deleted. However, the marker will not update if the
* object is edited by some other means (e.g., through script).
*
* Arguments:
* 0: Object(s) <OBJECT|ARRAY>
* 1: Set (create or delete) <BOOL>
*
* Return Value:
* None
*
* Example:
* [_object, true] call zen_building_markers_fnc_set
*
* Public: No
*/

if (!isServer) exitWith {
[QGVAR(set), _this] call CBA_fnc_serverEvent;
};

params [["_object", objNull, [objNull, []]], ["_set", true, [true]]];

if (_object isEqualType []) exitWith {
{
[_x, _set] call FUNC(set);
} forEach _object;
};

if (isNull _object) exitWith {};

private _marker = _object getVariable [QGVAR(marker), ""];

if (_set) then {
// Only update marker if it already exists
if (_marker != "") exitWith {
_marker setMarkerPosLocal getPos _object;
_marker setMarkerDir getDir _object;
};

// Create marker for the given object
0 boundingBoxReal _object params ["_p0", "_p1"];
private _size = _p1 vectorDiff _p0 vectorMultiply 0.5 select [0, 2];

_marker = createMarker [format [QGVAR(%1), _object call BIS_fnc_netId], _object];
_marker setMarkerShapeLocal "RECTANGLE";
_marker setMarkerColorLocal "ColorGrey";
_marker setMarkerBrushLocal "SolidFull";
_marker setMarkerSizeLocal _size;
_marker setMarkerDir getDir _object;
_object setVariable [QGVAR(marker), _marker, true];

// Delete marker when the object is deleted
private _eventID = _object addEventHandler ["Deleted", {
params ["_object"];

deleteMarker (_object getVariable [QGVAR(marker), ""]);
}];

_object setVariable [QGVAR(eventID), _eventID];
} else {
if (_marker == "") exitWith {};

private _eventID = _object getVariable [QGVAR(eventID), -1];
_object removeEventHandler ["Deleted", _eventID];
_object setVariable [QGVAR(marker), nil, true];
deleteMarker _marker;
};
1 change: 1 addition & 0 deletions addons/building_markers/functions/script_component.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "\x\zen\addons\building_markers\script_component.hpp"
8 changes: 8 additions & 0 deletions addons/building_markers/initSettings.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
QGVAR(enabled),
"CHECKBOX",
[LSTRING(Enabled), LSTRING(Enabled_Description)],
[ELSTRING(main,DisplayName), LSTRING(DisplayName)],
false,
false
] call CBA_fnc_addSetting;
17 changes: 17 additions & 0 deletions addons/building_markers/script_component.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#define COMPONENT building_markers
#define COMPONENT_BEAUTIFIED Building Markers
#include "\x\zen\addons\main\script_mod.hpp"

// #define DEBUG_MODE_FULL
// #define DISABLE_COMPILE_CACHE
// #define ENABLE_PERFORMANCE_COUNTERS

#ifdef DEBUG_ENABLED_EDITOR
#define DEBUG_MODE_FULL
#endif

#ifdef DEBUG_SETTINGS_EDITOR
#define DEBUG_SETTINGS DEBUG_SETTINGS_EDITOR
#endif

#include "\x\zen\addons\main\script_macros.hpp"
20 changes: 20 additions & 0 deletions addons/building_markers/stringtable.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<Project name="ZEN">
<Package name="Building_Markers">
<Key ID="STR_ZEN_Building_Markers_DisplayName">
<English>Building Markers</English>
</Key>
<Key ID="STR_ZEN_Building_Markers_Enabled">
<English>Enable Automatic Building Markers</English>
</Key>
<Key ID="STR_ZEN_Building_Markers_Enabled_Description">
<English>Enables automatically creating grey rectangle area markers (similarly to terrain structures) for buildings placed through Zeus.</English>
</Key>
<Key ID="STR_ZEN_Building_Markers_BuildingMarker">
<English>Building Marker</English>
</Key>
<Key ID="STR_ZEN_Building_Markers_BuildingMarker_Tooltip">
<English>Adds a grey rectangle area marker for the building, similarly to terrain structures.</English>
</Key>
</Package>
</Project>
5 changes: 4 additions & 1 deletion addons/placement/functions/fnc_handleObjectPlaced.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ _object allowDamage false;
_object setVectorDirAndUp _dirAndUp;
_object setVelocity [0, 0, 0];

[{_this allowDamage true}, _object] call CBA_fnc_execNextFrame;
[{
_this allowDamage true;
[QGVAR(done), _this] call CBA_fnc_localEvent;
}, _object] call CBA_fnc_execNextFrame;
}, [_object, getPosASL GVAR(helper), [vectorDir GVAR(helper), vectorUp GVAR(helper)]]] call CBA_fnc_execNextFrame;

// Do not cancel the preview if the control key is held
Expand Down
3 changes: 3 additions & 0 deletions docs/user_guide/attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ _* Only for vehicles that are currently occupied._
### Markers
- Text
- Color

### Others
- Building Marker

0 comments on commit 87b9d3c

Please sign in to comment.