Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interaction - Add interaction with terrain objects #8103

Merged
merged 13 commits into from
Oct 12, 2021
2 changes: 2 additions & 0 deletions addons/interact_menu/functions/fnc_renderActionPoints.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ private _fnc_renderNearbyActions = {
GVAR(foundActions) = [];
GVAR(lastTimeSearchedActions) = diag_tickTime;

QGVAR(renderNearbyActions) call CBA_fnc_localEvent;

private _numInteractObjects = 0;
private _nearestObjects = nearestObjects [ACE_player, ["All"], 13];
{
Expand Down
2 changes: 2 additions & 0 deletions addons/interaction/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,6 @@ PREP(openDoor);
PREP(canPush);
PREP(push);

// misc
PREP(canFlip);
PREP(replaceTerrainObject);
20 changes: 20 additions & 0 deletions addons/interaction/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,30 @@ ACE_Modifier = 0;
};
}] call CBA_fnc_addEventHandler;

if (isServer) then {
[QGVAR(replaceTerrainObject), FUNC(replaceTerrainObject)] call CBA_fnc_addEventHandler;
};

if (!hasInterface) exitWith {};

GVAR(isOpeningDoor) = false;

[QEGVAR(interact_menu,renderNearbyActions), {
if !GVAR(interactWithTerrainObjects) exitWith {};
Dystopian marked this conversation as resolved.
Show resolved Hide resolved
{
if (
isObjectHidden _x // after hiding on server
|| {_x getVariable [QGVAR(terrainObjectReplaced), false]} // after checking but before hiding
|| {typeOf _x isNotEqualTo ""}
) then {continue};
private _model = getModelInfo _x select 1;
private _class = GVAR(replaceTerrainModels) get _model;
if (isNil "_class") then {continue};
_x setVariable [QGVAR(terrainObjectReplaced), true];
[QGVAR(replaceTerrainObject), [_x, _class]] call CBA_fnc_serverEvent;
} forEach nearestTerrainObjects [ACE_player, [], 5, false];
}] call CBA_fnc_addEventHandler;

[QGVAR(tapShoulder), {
params ["_unit", "_shoulderNum"];

Expand Down
4 changes: 4 additions & 0 deletions addons/interaction/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ DFUNC(repair_Statement) = { // moved from config because of build problems
} forEach (curatorSelected select 0)
};

if (hasInterface) then {
GVAR(replaceTerrainModels) = createHashMapFromArray call (uiNamespace getVariable QGVAR(cacheReplaceTerrainModels));
};

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

#include "XEH_PREP.hpp"

if (!hasInterface) exitWith {};

private _replaceTerrainClasses = QUOTE( \
getNumber (_x >> 'scope') == 2 \
&& {getNumber (_x >> QQGVAR(replaceTerrainObject)) > 0} \
) configClasses (configFile >> "CfgVehicles");
Dystopian marked this conversation as resolved.
Show resolved Hide resolved
Dystopian marked this conversation as resolved.
Show resolved Hide resolved

private _cacheReplaceTerrainModels = createHashMap;
{
private _model = toLower getText (_x >> "model");
if (_model select [0, 1] == "\") then {
_model = _model select [1];
};
if ((_model select [count _model - 4]) != ".p3d") then {
_model = _model + ".p3d"
};
if (_model in _cacheReplaceTerrainModels) then {continue};
_cacheReplaceTerrainModels set [_model, configName _x];
} forEach _replaceTerrainClasses;

uiNamespace setVariable [QGVAR(cacheReplaceTerrainModels), compileFinal str _cacheReplaceTerrainModels];
59 changes: 59 additions & 0 deletions addons/interaction/dev/initReplaceTerrainCursorObject.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// execVM "z\ace\addons\interaction\dev\initReplaceTerrainCursorObject.sqf";
// use "J" key to replace terrain cursorObject and add dragging actions to it

#include "\z\ace\addons\interaction\script_component.hpp"

DFUNC(replaceTerrainModelsAdd) = {
params ["_model", ["_class", ""]];
if (_model isEqualType objNull) then {
_model = getModelInfo _model select 1;
};
if (_model isEqualTo "") exitWith {systemChat "fail model"; false};

private _savedClass = GVAR(replaceTerrainModels) get _model;
if (!isNil "_savedClass") exitWith {systemChat ("was " + _savedClass); true};

private _parent = "";
if (_class isEqualTo "") then {
private _configClasses = QUOTE(getNumber (_x >> 'scope') == 2 && {!(configName _x isKindOf 'AllVehicles')}) configClasses (configFile >> "CfgVehicles");
{
private _xmodel = toLower getText (_x >> "model");
if (_xmodel select [0, 1] == "\") then {
_xmodel = _xmodel select [1];
};
if ((_xmodel select [count _xmodel - 4]) != ".p3d") then {
_xmodel = _xmodel + ".p3d"
};
if (_model == _xmodel) then {
_class = configName _x;
_parent = configName inheritsFrom _x;
break;
};
} forEach _configClasses;
};
if (_class isEqualTo "") exitWith {systemChat "fail class"; false};
GVAR(replaceTerrainModels) set [_model, _class];
QEGVAR(interact_menu,renderNearbyActions) call CBA_fnc_localEvent;
systemChat ("found " + _class);
diag_log format ["replaceTerrain: class %1: %2", _class, _parent];
true
};

// DIK_J
[0x24, [false, false, false], {
if (
cursorObject call FUNC(replaceTerrainModelsAdd)
&& {["ace_dragging"] call EFUNC(common,isModLoaded)}
) then {
// wait while server replaces object, then init dragging on all clients
[{
if (typeOf cursorObject == "") exitwith {};
[cursorObject, {
if !hasInterface exitWith {};
[_this, true] call EFUNC(dragging,setDraggable);
[_this, true] call EFUNC(dragging,setCarryable);
}] remoteExec ["call", 0];
}, [], 1] call CBA_fnc_waitAndExecute;
};
true
}, nil, nil, false] call CBA_fnc_addKeyHandler;
37 changes: 37 additions & 0 deletions addons/interaction/functions/fnc_replaceTerrainObject.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "script_component.hpp"
/*
* Author: Dystopian
* Replaces terrain object with created one.
* Run on server only.
*
* Arguments:
* 0: Terrain object <OBJECT>
* 1: New object class <STRING>
*
* Return Value:
* None
*
* Example:
* [cursorObject, "Land_Bucket_F"] call ace_interaction_fnc_replaceTerrainObject
*
* Public: No
*/

params ["_terrainObject", "_class"];
TRACE_2("",_terrainObject,_class);

if (isObjectHidden _terrainObject) exitWith {};

private _position = getPosATL _terrainObject;
if (_position select 2 < 0) then {
_position set [2, 0];
};
private _vectorDirAndUp = [vectorDir _terrainObject, vectorUp _terrainObject];

hideObjectGlobal _terrainObject;
// prevent new object clipping with old one
_terrainObject setDamage [1, false];

private _newObject = createVehicle [_class, [0,0,0]];
_newObject setVectorDirAndUp _vectorDirAndUp;
_newObject setPosATL _position;
8 changes: 8 additions & 0 deletions addons/interaction/initSettings.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,11 @@
format ["ACE %1", LLSTRING(DisplayName)],
true
] call CBA_fnc_addSetting;

[
QGVAR(interactWithTerrainObjects), "CHECKBOX",
["str_a3_modules_moduleomquest_defend_f_attributes_useterrainobject0", LSTRING(interactWithTerrainObjects_Description)],
format ["ACE %1", LLSTRING(DisplayName)],
Dystopian marked this conversation as resolved.
Show resolved Hide resolved
false,
true
] call CBA_fnc_addSetting;
4 changes: 4 additions & 0 deletions addons/interaction/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1218,5 +1218,9 @@
<Russian>Включает действия Установить/Снять для приспособлений текущего оружия.</Russian>
<Japanese>インタラクションから使用中の武器に対してのアタッチメント取り外しを可能にします。</Japanese>
</Key>
<Key ID="STR_ACE_Interaction_interactWithTerrainObjects_Description">
<English>Warning: can cause some objects to collide with others.</English>
<Russian>Внимание: может вызвать отталкивание некоторых объектов друг от друга.</Russian>
</Key>
</Package>
</Project>