mirror of
https://github.com/EpochModTeam/DayZ-Epoch.git
synced 2025-12-13 19:52:38 +03:00
Update fn_isInsideBuilding.sqf
Optimize code and correct error when no building is sent as a parameter.
This commit is contained in:
@@ -10,18 +10,18 @@
|
||||
// - arg#1 is a boolean: check also whether arg#0 is inside (bounding box of) some non-enterable buildings around. Can be used to check if a player or an installed item is on a building roof.
|
||||
// - arg#0 is posATL, arg#1 should be a building
|
||||
|
||||
private ["_check","_unit","_inside","_building","_size","_type"];
|
||||
private ["_check","_unit","_inside","_building","_type","_option"];
|
||||
|
||||
_check = {
|
||||
private ["_building", "_point", "_inside", "_offset", "_relPos", "_boundingBox", "_min", "_max", "_myX", "_myY", "_myZ"];
|
||||
private ["_building", "_pos", "_inside", "_offset", "_relPos", "_boundingBox", "_min", "_max", "_myX", "_myY", "_myZ"];
|
||||
|
||||
_building = _this select 0;
|
||||
_inside = false;
|
||||
if (isNull _building) exitwith {_inside};
|
||||
_point = _this select 1;
|
||||
if (isNull _building) exitWith {_inside};
|
||||
_pos = _this select 1;
|
||||
_offset = 1; // shrink building boundingbox by this length.
|
||||
|
||||
_relPos = _building worldToModel _point;
|
||||
_relPos = _building worldToModel _pos;
|
||||
_boundingBox = boundingBox _building;
|
||||
|
||||
_min = _boundingBox select 0;
|
||||
@@ -42,38 +42,35 @@ _check = {
|
||||
_inside
|
||||
};
|
||||
|
||||
_size = 0;
|
||||
_unit = _this select 0;
|
||||
if (typeName _unit == "OBJECT") then {
|
||||
_size = sizeOf typeOf _unit;
|
||||
_unit = getPosATL _unit;
|
||||
};
|
||||
|
||||
_inside = false;
|
||||
|
||||
if (count _this > 1 AND {(typeName (_this select 1) == "OBJECT")}) then {
|
||||
// optional argument #1 can be the building used for the check
|
||||
_building = _this select 1;
|
||||
_inside = [_building, _unit] call _check;
|
||||
}
|
||||
else {
|
||||
// else perform check with nearest enterable building (contains a path LOD)
|
||||
if (typeName _unit == "OBJECT") then {
|
||||
_building = nearestBuilding _unit;
|
||||
_inside = [_building,getPosATL _unit] call _check;
|
||||
};
|
||||
if ((!_inside) AND {(count _this > 1)}) then { // if optional argument is a boolean
|
||||
{
|
||||
_building = _x;
|
||||
_type = typeOf _building;
|
||||
if ((((!(_type IN DayZ_SafeObjects)) // not installable objects
|
||||
AND {(!(_type isKindOf "ReammoBox"))}) // not lootpiles (weaponholders and ammoboxes)
|
||||
AND {((_size + (sizeOf _type)) > _unit distance _x)}) // objects might colliding
|
||||
AND {([_x, _unit] call _check)}) exitWith { // perform the check. exitWith works only in non-nested "if"
|
||||
_inside = true;
|
||||
};
|
||||
} forEach(nearestObjects [_unit, ["Building"], 50]);
|
||||
};
|
||||
// [object] call fnc_isInsideBuilding;
|
||||
// This option is called continuously from player_checkStealth.
|
||||
if (count _this == 1) exitWith {
|
||||
//_building = nearestObject [_unit, "Building"];
|
||||
_building = nearestBuilding _unit; // Not sure if this command is faster.
|
||||
_inside = [_building,(getPosATL _unit)] call _check;
|
||||
_inside
|
||||
};
|
||||
|
||||
_option = _this select 1;
|
||||
// [object,building] call fnc_isInsideBuilding;
|
||||
if (typeName _option == "OBJECT") then {
|
||||
// optional argument is a specific building
|
||||
_inside = [_option,(getPosATL _unit)] call _check;
|
||||
} else {
|
||||
// [object,boolean] call fnc_isInsideBuilding; This is used in fn_niceSpot.
|
||||
{
|
||||
_building = _x;
|
||||
_type = typeOf _building;
|
||||
if (!(_type in DayZ_SafeObjects) // not installable objects
|
||||
&& {!(_type isKindOf "ReammoBox")} // not lootpiles (weaponholders and ammoboxes)
|
||||
&& {((sizeOf typeOf _unit) + (sizeOf _type)) > (_unit distance _building)} // objects might colliding
|
||||
&& {[_building, _unit] call _check}) exitWith { // perform the check. exitWith works only in non-nested "if"
|
||||
_inside = true;
|
||||
};
|
||||
} forEach (nearestObjects [_unit, ["Building"], 50]);
|
||||
};
|
||||
//diag_log ("fnc_isInsideBuilding Check: " + str(_inside)+ " last building:"+str(_building));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user