2018-09-17 19:19:29 +00:00
#include "script_component.hpp"
2015-07-17 20:43:00 +00:00
/*
* Author: Rocko
* Handles vehicle damage from hitting wire
*
* Arguments:
* 0: wire <OBJECT>
* 1: vehicle <OBJECT>
*
* Return Value:
* None
2015-08-09 00:19:34 +00:00
*
2017-06-08 13:31:51 +00:00
* Example:
* [wire, car] call ace_concertina_wire_fnc_vehicleDamage
*
2015-08-09 00:19:34 +00:00
* Public: No
2015-07-17 20:43:00 +00:00
*/
2015-08-09 00:19:34 +00:00
params ["_wire", "_vehicle"];
2015-07-17 20:43:00 +00:00
2017-10-10 14:39:59 +00:00
private _type = typeOf _wire;
private _mode = switch (_type) do {
2015-07-17 20:43:00 +00:00
case "ACE_ConcertinaWire": { 0 };
case "Land_Razorwire_F": { 1 };
default { -1 };
};
if (_mode == -1) exitWith {};
// _mode = 0 = Single Coil
// _mode = 1 = Triple Coil
// --------------------------------
// L M R
// 4.54929 (4)
// 6.13564 (6)
//9.78744 (10)
_type = typeOf _wire;
2017-10-10 14:39:59 +00:00
private _anim = _wire animationPhase "wire_2";
private _pos_w = getPos _wire;
private _dir_w = getDir _wire;
2015-07-17 20:43:00 +00:00
if (_mode == 0) then {
2017-10-10 14:39:59 +00:00
private _found = false;
2015-08-09 00:19:34 +00:00
_pos_w params ["_x","_y"];
2015-07-17 20:43:00 +00:00
// Check if two Single coils are placed next to each other (i.e playes have built a big wire obstacle)
2017-10-10 14:39:59 +00:00
private _wireCheckPosAr = [
2016-09-04 14:44:22 +00:00
[_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)]
2015-07-17 20:43:00 +00:00
];
{
_found = false;
2017-10-10 14:39:59 +00:00
private _no = nearestObjects [_x, [typeOf _wire], 3]; //diag_log _no; diag_log ".....";
2015-12-21 16:05:48 +00:00
_no = _no - [_wire]; //diag_log _no;
2015-07-17 20:43:00 +00:00
if (count _no > 0) exitWith {
2015-12-21 16:05:48 +00:00
_found = true; //diag_log "found";
2015-07-17 20:43:00 +00:00
};
2015-11-30 16:23:48 +00:00
} forEach _wireCheckPosAr;
2015-07-17 20:43:00 +00:00
// 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;
};
};
};
};
2017-10-10 14:39:59 +00:00
private _parts = [];
2015-07-17 20:43:00 +00:00
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"];
};
};
} else {
switch (true) do {
case (_vehicle isKindOf "Wheeled_APC" || {_vehicle isKindOf "Car"}): {
_parts = ["lfwheel","lf2wheel","lmwheel","lbwheel","rfwheel","rf2wheel","rmwheel","rbwheel"];
};
};
};
if (canMove _vehicle) then {
{
2017-10-10 14:39:59 +00:00
private _selectionPart = "hit" + _x;
2021-02-18 18:58:08 +00:00
if (isText(configOf _vehicle >> "hitpoints" >> _selectionPart >> "name")) then {
private _selection = getText(configOf _vehicle >> "hitpoints" >> _selectionPart >> "name");
2015-07-17 20:43:00 +00:00
// TODO: Only the tires that have touched the wire should burst.
_vehicle setHit [_selection, 1];
};
} forEach _parts;
};
if (_mode == 1) then {
if (_vehicle isKindOf "StaticWeapon") exitWith {};
[{
2017-10-10 14:39:59 +00:00
params ["_vehicle", "_wire"];
2015-07-17 20:43:00 +00:00
_vehicle setVelocity ((velocity _vehicle) vectorMultiply 0.75);
// 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
2017-10-10 14:39:59 +00:00
private _vPos = getPosASL _vehicle;
private _vDir = getDir _vehicle;
2015-07-17 20:43:00 +00:00
_vehicle setPosASL (_vPos vectorAdd [-0.35 * sin(_vDir), -0.35 * cos(_vDir), 0]);
2016-09-04 14:44:22 +00:00
// TODO: Needs to be placed in safe distance to wire, so we do not constantly re - spawn new wires
2016-05-22 13:27:24 +00:00
}, [_vehicle, _wire], 0.1] call CBA_fnc_waitAndExecute;
2015-07-17 20:43:00 +00:00
};
//TODO: Create broken geoless wire (two version)
//TODO: Make wire remains stop vehicles