diff --git a/addons/concertina_wire/CfgEventHandlers.hpp b/addons/concertina_wire/CfgEventHandlers.hpp index 6868351825..026afb4e2d 100644 --- a/addons/concertina_wire/CfgEventHandlers.hpp +++ b/addons/concertina_wire/CfgEventHandlers.hpp @@ -31,4 +31,14 @@ class Extended_Init_EventHandlers { init = QUOTE(_this call DEFUNC(dragging,initObject)); }; }; + class ACE_ConcertinaWire { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_init)); + }; + }; + class Land_Razorwire_F { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_init)); + }; + }; }; diff --git a/addons/concertina_wire/XEH_init.sqf b/addons/concertina_wire/XEH_init.sqf new file mode 100644 index 0000000000..dbce4a9b92 --- /dev/null +++ b/addons/concertina_wire/XEH_init.sqf @@ -0,0 +1,4 @@ +#include "script_component.hpp" + +PARAMS_1(_wire); +_wire addEventHandler ["HandleDamage", {_this call FUNC(handleDamage)}]; \ No newline at end of file diff --git a/addons/concertina_wire/XEH_preInit.sqf b/addons/concertina_wire/XEH_preInit.sqf index 3e20236a02..f15feb48bd 100644 --- a/addons/concertina_wire/XEH_preInit.sqf +++ b/addons/concertina_wire/XEH_preInit.sqf @@ -5,6 +5,7 @@ ADDON = false; PREP(deploy); PREP(dismount); PREP(dismountSuccess); +PREP(handleDamage); PREP(handleKilled); ADDON = true; diff --git a/addons/concertina_wire/config.cpp b/addons/concertina_wire/config.cpp index f675283277..06b7bf5d86 100644 --- a/addons/concertina_wire/config.cpp +++ b/addons/concertina_wire/config.cpp @@ -2,7 +2,7 @@ class CfgPatches { class ADDON { - units[] = {}; + units[] = {"ACE_ConcertinaWire", "ACE_ConcertinaWireNoGeo", "ACE_ConcertinaWireCoil"}; weapons[] = {}; requiredVersion = REQUIRED_VERSION; requiredAddons[] = {"ace_apl", "ace_interaction"}; diff --git a/addons/concertina_wire/functions/fnc_handleDamage.sqf b/addons/concertina_wire/functions/fnc_handleDamage.sqf new file mode 100644 index 0000000000..61cd1c4e7c --- /dev/null +++ b/addons/concertina_wire/functions/fnc_handleDamage.sqf @@ -0,0 +1,29 @@ +/* + * Author: Ruthberg + * + * Handles wire damage + * + * Arguments: + * 0: wire + * 1: selectionName + * 2: damage + * 3: source + * 4: projectile + * + * Return Value: + * Nothing + * + * Return value: + * None + */ +#include "script_component.hpp" + +PARAMS_5(_wire,_selectionName,_damage,_source,_projectile); + +if (_damage < 0.5) exitWith { 0 }; + +if (!(isNull _source)) then { + _wire setVariable [QGVAR(lastDamager), _source]; +}; + +_damage diff --git a/addons/concertina_wire/functions/fnc_handleKilled.sqf b/addons/concertina_wire/functions/fnc_handleKilled.sqf index 9625dc1e95..2d2cd7f789 100644 --- a/addons/concertina_wire/functions/fnc_handleKilled.sqf +++ b/addons/concertina_wire/functions/fnc_handleKilled.sqf @@ -17,6 +17,12 @@ PARAMS_2(_wire,_killer); +if (isNull _killer) then { + _killer = _wire getVariable ["ace_concertina_wire_lastDamager", objNull]; + if (isNull _killer) then { + _killer = nearestObject [_wire, "car"]; + }; +}; if (isNull _killer || {_killer == _wire} || {_killer == gunner (vehicle _killer)}) exitWith {}; private ["_type", "_mode", "_distance", "_anim", "_parts", "_selectionPart", "_selection", "_pos_w", "_dir_w", "_vehicle"]; @@ -48,64 +54,65 @@ _dir_w = getDir _wire; _vehicle = vehicle _killer; if (_mode == 0) then { - private ["_x", "_y", "_found", "_wireCheckPosAr", "_no"]; - _x = _pos_w select 0; - _y = _pos_w select 1; - // Check if two Single coils are placed next to each other (i.e playes have built a big wire obstacle) - _wireCheckPosAr = [ - [_x + (sin (_dir_w+90) * 1.5),_y + (cos (_dir_w+90) * 1.5)], - [(_x-(sin _dir_w)) + (sin (_dir_w+90) * 1.5),(_y-(cos _dir_w)) + (cos (_dir_w+90) * 1.5)], - [_x + (sin (_dir_w-90) * 1.5),_y + (cos (_dir_w-90) * 1.5)], - [(_x-(sin _dir_w)) + (sin (_dir_w-90) * 1.5),(_y-(cos _dir_w)) + (cos (_dir_w-90) * 1.5)] - ]; - { - _found = false; - _no = nearestObjects [_x, [typeOf _wire], 3]; //diag_log _no; diag_log "....."; - _no = _no - [_wire]; //diag_log _no; - if (count _no > 0) exitWith { - _found = true; //diag_log "found"; - }; - } foreach _wireCheckPosAr; - // Double coil found! - if (_found) then { - _mode = 1; - } else { - // Randomly make a single coil also catch tanks, if speed is high - if (_vehicle isKindOf "Tank" && {20 > random 100} && {speed _vehicle > 30}) then { - _mode = 1; - } else { - if !(_vehicle isKindOf "Tank") then { - _mode = 1; - }; - }; - }; + private ["_x", "_y", "_found", "_wireCheckPosAr", "_no"]; + _x = _pos_w select 0; + _y = _pos_w select 1; + // Check if two Single coils are placed next to each other (i.e playes have built a big wire obstacle) + _wireCheckPosAr = [ + [_x + (sin (_dir_w+90) * 1.5),_y + (cos (_dir_w+90) * 1.5)], + [(_x-(sin _dir_w)) + (sin (_dir_w+90) * 1.5),(_y-(cos _dir_w)) + (cos (_dir_w+90) * 1.5)], + [_x + (sin (_dir_w-90) * 1.5),_y + (cos (_dir_w-90) * 1.5)], + [(_x-(sin _dir_w)) + (sin (_dir_w-90) * 1.5),(_y-(cos _dir_w)) + (cos (_dir_w-90) * 1.5)] + ]; + { + _found = false; + _no = nearestObjects [_x, [typeOf _wire], 3]; //diag_log _no; diag_log "....."; + _no = _no - [_wire]; //diag_log _no; + if (count _no > 0) exitWith { + _found = true; //diag_log "found"; + }; + } foreach _wireCheckPosAr; + // Double coil found! + if (_found) then { + _mode = 1; + } else { + // Randomly make a single coil also catch tanks, if speed is high + if (_vehicle isKindOf "Tank" && {20 > random 100} && {speed _vehicle > 30}) then { + _mode = 1; + } else { + if !(_vehicle isKindOf "Tank") then { + _mode = 1; + }; + }; + }; }; if (_mode == 1) then { - switch (true) do { - case (_vehicle isKindOf "Tank"): { - _parts = ["ltrack","rtrack"]; - }; - case (_vehicle isKindOf "Wheeled_APC" || {_vehicle isKindOf "Car"}): { - _parts = ["lfwheel","lf2wheel","lmwheel","lbwheel","rfwheel","rf2wheel","rmwheel","rbwheel"]; - }; - }; + switch (true) do { + case (_vehicle isKindOf "Tank"): { + _parts = ["ltrack","rtrack"]; + }; + case (_vehicle isKindOf "Wheeled_APC" || {_vehicle isKindOf "Car"}): { + _parts = ["lfwheel","lf2wheel","lmwheel","lbwheel","rfwheel","rf2wheel","rmwheel","rbwheel"]; + }; + }; } else { - switch (true) do { - case (_vehicle isKindOf "Wheeled_APC" || {_vehicle isKindOf "Car"}): { - _parts = ["lfwheel","lf2wheel","lmwheel","lbwheel","rfwheel","rf2wheel","rmwheel","rbwheel"]; - }; - }; + switch (true) do { + case (_vehicle isKindOf "Wheeled_APC" || {_vehicle isKindOf "Car"}): { + _parts = ["lfwheel","lf2wheel","lmwheel","lbwheel","rfwheel","rf2wheel","rmwheel","rbwheel"]; + }; + }; }; if (canMove _vehicle) then { - { - _selectionPart = "hit" + _x; - if (isText(configFile >> "CfgVehicles" >> typeOf _vehicle >> "hitpoints" >> _selectionPart >> "name")) then { - _selection = getText(configFile >> "CfgVehicles" >> typeOf _vehicle >> "hitpoints" >> _selectionPart >> "name"); - _vehicle setHit [_selection,1]; - }; - } foreach _parts; //TODO: Check sys_vehicle_damage compatibility + { + _selectionPart = "hit" + _x; + if (isText(configFile >> "CfgVehicles" >> typeOf _vehicle >> "hitpoints" >> _selectionPart >> "name")) then { + _selection = getText(configFile >> "CfgVehicles" >> typeOf _vehicle >> "hitpoints" >> _selectionPart >> "name"); + // TODO: Only the tires that have touched the wire should burst. + _vehicle setHit [_selection, 1]; + }; + } forEach _parts; }; if (_mode == 1) then { @@ -116,11 +123,11 @@ if (_mode == 1) then { _vehicle setVelocity ((velocity _vehicle) vectorMultiply 0.75); private ["_vPos", "_vDir"]; - // Set vehicle back in front of wire, since the wire will make the vehicle jump, and a wire with no geometry lod is undestructible and not recognizeable - _vPos = getPosASL _vehicle; - _vDir = getDir _vehicle; - _vehicle setPosASL (_vPos vectorAdd [-0.35 * sin(_vDir), -0.35 * cos(_vDir), 0]); - // TODO: Needs to be placed in safe distance to wire, so we do not constantly re-spawn new wires + // Set vehicle back in front of wire, since the wire will make the vehicle jump, and a wire with no geometry lod is undestructible and not recognizeable + _vPos = getPosASL _vehicle; + _vDir = getDir _vehicle; + _vehicle setPosASL (_vPos vectorAdd [-0.35 * sin(_vDir), -0.35 * cos(_vDir), 0]); + // TODO: Needs to be placed in safe distance to wire, so we do not constantly re-spawn new wires }, [_vehicle, _wire], 0.1, 0] call EFUNC(common,waitAndExecute); };