mirror of
https://github.com/EpochModTeam/DayZ-Epoch.git
synced 2025-12-14 04:02:37 +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#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
|
// - 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 = {
|
_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;
|
_building = _this select 0;
|
||||||
_inside = false;
|
_inside = false;
|
||||||
if (isNull _building) exitwith {_inside};
|
if (isNull _building) exitWith {_inside};
|
||||||
_point = _this select 1;
|
_pos = _this select 1;
|
||||||
_offset = 1; // shrink building boundingbox by this length.
|
_offset = 1; // shrink building boundingbox by this length.
|
||||||
|
|
||||||
_relPos = _building worldToModel _point;
|
_relPos = _building worldToModel _pos;
|
||||||
_boundingBox = boundingBox _building;
|
_boundingBox = boundingBox _building;
|
||||||
|
|
||||||
_min = _boundingBox select 0;
|
_min = _boundingBox select 0;
|
||||||
@@ -42,39 +42,36 @@ _check = {
|
|||||||
_inside
|
_inside
|
||||||
};
|
};
|
||||||
|
|
||||||
_size = 0;
|
|
||||||
_unit = _this select 0;
|
_unit = _this select 0;
|
||||||
if (typeName _unit == "OBJECT") then {
|
|
||||||
_size = sizeOf typeOf _unit;
|
|
||||||
_unit = getPosATL _unit;
|
|
||||||
};
|
|
||||||
|
|
||||||
_inside = false;
|
_inside = false;
|
||||||
|
|
||||||
if (count _this > 1 AND {(typeName (_this select 1) == "OBJECT")}) then {
|
// [object] call fnc_isInsideBuilding;
|
||||||
// optional argument #1 can be the building used for the check
|
// This option is called continuously from player_checkStealth.
|
||||||
_building = _this select 1;
|
if (count _this == 1) exitWith {
|
||||||
_inside = [_building, _unit] call _check;
|
//_building = nearestObject [_unit, "Building"];
|
||||||
}
|
_building = nearestBuilding _unit; // Not sure if this command is faster.
|
||||||
else {
|
_inside = [_building,(getPosATL _unit)] call _check;
|
||||||
// else perform check with nearest enterable building (contains a path LOD)
|
_inside
|
||||||
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
|
|
||||||
|
_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;
|
_building = _x;
|
||||||
_type = typeOf _building;
|
_type = typeOf _building;
|
||||||
if ((((!(_type IN DayZ_SafeObjects)) // not installable objects
|
if (!(_type in DayZ_SafeObjects) // not installable objects
|
||||||
AND {(!(_type isKindOf "ReammoBox"))}) // not lootpiles (weaponholders and ammoboxes)
|
&& {!(_type isKindOf "ReammoBox")} // not lootpiles (weaponholders and ammoboxes)
|
||||||
AND {((_size + (sizeOf _type)) > _unit distance _x)}) // objects might colliding
|
&& {((sizeOf typeOf _unit) + (sizeOf _type)) > (_unit distance _building)} // objects might colliding
|
||||||
AND {([_x, _unit] call _check)}) exitWith { // perform the check. exitWith works only in non-nested "if"
|
&& {[_building, _unit] call _check}) exitWith { // perform the check. exitWith works only in non-nested "if"
|
||||||
_inside = true;
|
_inside = true;
|
||||||
};
|
};
|
||||||
} forEach (nearestObjects [_unit, ["Building"], 50]);
|
} forEach (nearestObjects [_unit, ["Building"], 50]);
|
||||||
};
|
};
|
||||||
};
|
|
||||||
//diag_log ("fnc_isInsideBuilding Check: " + str(_inside)+ " last building:"+str(_building));
|
//diag_log ("fnc_isInsideBuilding Check: " + str(_inside)+ " last building:"+str(_building));
|
||||||
|
|
||||||
_inside
|
_inside
|
||||||
|
|||||||
Reference in New Issue
Block a user