Handle destruction of tags placed on objects that don't support handledamage.

This commit is contained in:
esteldunedain 2016-01-23 16:24:55 -03:00
parent e31636539a
commit 74b6036f3e
3 changed files with 81 additions and 18 deletions

View File

@ -7,5 +7,6 @@ PREP(createTag);
PREP(tagDirection);
PREP(tagGround);
PREP(tagWall);
PREP(tagTestingThread);
ADDON = true;

View File

@ -34,23 +34,39 @@ _tag setVectorDirAndUp _vectorDirAndUp;
if (isNull _object) exitWith {};
// If the tag is applied to an object, handle its destruction
_object setVariable [QGVAR(testVar), true];
if (_object getVariable [QGVAR(testVar), false]) then {
// The object supports variables and hence HandleDamage too
// Use the cheaper alternative for handling destruction: HandleDamage
// If the object already has tags attached, just add the new one to the list
private _attachedTags = _object getVariable QGVAR(attachedTags);
if !(isNil "_attachedTags ") exitWith {
_attachedTags pushBack _tag;
};
_attachedTags = [_tag];
_object setVariable [QGVAR(attachedTags), _attachedTags];
// If it's the first tag attached to that object, add a handledamage event handler
_object addEventHandler ["HandleDamage", {
params ["_object", "_selection", "_damage"];
if (_selection == "" && _damage >= 1) then {
{
deleteVehicle _x;
} foreach (_object getVariable [QGVAR(attachedTags), []]);
_object setVariable [QGVAR(attachedTags), []];
};
}];
} else {
// The object doesn't supports variables
// Use the more costly alternative: periodic testing
GVAR(tagsToTest) pushBack [_tag, _tagPosASL, _vectorDirAndUp];
// Run the tes
if (!GVAR(testingThread)) then {
call FUNC(tagTestingThread);
};
// If the object already has tags attached, just add the new one to the list
private _attachedTags = _object getVariable QGVAR(attachedTags);
if !(isNil "_attachedTags ") exitWith {
_attachedTags pushBack _tag;
};
_attachedTags = [tags];
_object setVariable [QGVAR(attachedTags), _attachedTags];
// If it's the first tag attached to that object, add a handledamage event handler
_object addEventHandler ["HandleDamage", {
params ["_object", "_selection", "_damage"];
if (_selection == "" && _damage >= 1) then {
{
deleteVehicle _x;
} foreach (_object getVariable [QGVAR(attachedTags), []]);
_object setVariable [QGVAR(attachedTags), []];
};
}];

View File

@ -0,0 +1,46 @@
/*
* Author: esteldunedain
* Checks if tags are still leaning on an object periodically.
*
* Arguments:
* None
*
* Return Value:
* None
*
* Example:
* [] call ace_tagging_fnc_tagTestingThread
*
* Public: No
*/
#include "script_component.hpp"
_fnc_isLeaning = {
params ["_tag", "_tagPosASL", "_vectorDirAndUp"];
_vectorDirAndUp params ["_v1", "_v2"];
private _endPosASL = _tagPosASL vectorAdd (_v1 vectorMultiply 0.08);
// Check for intersections below the unit
private _intersections = lineIntersectsSurfaces [_tagPosASL, _endPosASL, _tag, objNull, true, 1, "GEOM", "FIRE"];
// If there's no intersections
if (_intersections isEqualTo []) exitWith {
TRACE_1("No intersections, deleting:",_tag);
deleteVehicle _tag;
false
};
true
};
GVAR(tagsToTest) = [GVAR(tagsToTest), _fnc_isLeaning] call EFUNC(common,filter);
// If there's no more tag
if (GVAR(tagsToTest) isEqualTo []) exitWith {
GVAR(testingThread) = false;
};
// Schedule for execution again after 5 seconds
[DFUNC(tagTestingThread), [], 5] call EFUNC(common,waitAndExecute);
GVAR(testingThread) = true;