ACE3/addons/common/functions/fnc_isInBuilding.sqf

46 lines
1.0 KiB
Plaintext
Raw Normal View History

/*
* Author: commy2
* Check if the unit is in a building. Will return true if the unit is sitting in a bush.
*
2015-09-18 19:12:40 +00:00
* Arguments:
* 0: Unit <OBJECT>
*
* Return value:
2015-09-18 19:12:40 +00:00
* Is the unit in a building? <BOOL>
*
* Public: Yes
*/
2015-01-13 19:56:02 +00:00
#include "script_component.hpp"
2015-09-18 19:12:40 +00:00
#define CHECK_DISTANCE 10
2015-09-18 19:12:40 +00:00
params ["_unit"];
2015-09-18 19:12:40 +00:00
private ["_position", "_intersections"];
_position = eyePos _unit;
2015-09-18 19:12:40 +00:00
_intersections = 0;
2015-09-18 19:12:40 +00:00
if (lineIntersects [_position, _position vectorAdd [0, 0, +CHECK_DISTANCE]]) then {
_intersections = _intersections + 1;
};
2015-09-18 19:12:40 +00:00
if (lineIntersects [_position, _position vectorAdd [+CHECK_DISTANCE, 0, 0]]) then {
_intersections = _intersections + 1;
};
2015-09-18 19:12:40 +00:00
if (lineIntersects [_position, _position vectorAdd [-CHECK_DISTANCE, 0, 0]]) then {
_intersections = _intersections + 1;
};
2015-09-18 19:12:40 +00:00
if (lineIntersects [_position, _position vectorAdd [0, +CHECK_DISTANCE, 0]]) then {
_intersections = _intersections + 1;
};
2015-09-18 19:12:40 +00:00
if (lineIntersects [_position, _position vectorAdd [0, -CHECK_DISTANCE, 0]]) then {
_intersections = _intersections + 1;
};
_intersections > 3