|
发表于 2013-3-24 22:38:14
|
显示全部楼层
本帖最后由 FFUR2007SLX2_5 于 2013-3-24 22:57 编辑
- c_fnc_getBuildingPositions = {
- private ["_fnc_checkLOS", "_b", "_offset", "_aslPos", "_bBox", "_bBoxWidth", "_bBoxDepth", "_bBoxHeight", "_searchW", "_searchH", "_notVisable", "_visFromSide", "_visFromAbove", "_i", "_bP", "_xPos", "_visIndex", "_p"];
- _fnc_checkLOS = {
- private ["_b", "_pos", "_width", "_height", "_facing", "_return", "_aPos", "_blockingObjects", "_nrVis", "_numChecks", "_dirDif", "_i", "_c", "_xDir", "_sidePos"];
- _b = _this select 0;
- _pos = ATLtoASL (_this select 1);
- _width = _this select 2;
- _height = _this select 3;
-
- _facing = getDir _b;
-
- _return = 0;
-
- _aPos = [_pos select 0, _pos select 1, (_pos select 2) + _height];
- _blockingObjects = lineIntersectsWith [_pos, _aPos];
-
- if( !(_b in _blockingObjects) ) then {
- _return = 2;
- } else {
- _nrVis = 4;
- _numChecks = 12;
- _dirDif = 360/_numChecks;
- _i = 0;
- _c = 0;
- while {_i < _numChecks && _c < _nrVis} do {
- _xDir = _facing + _dirDif*_i;
- _sidePos = [(_pos select 0)+(_width*sin _xDir), (_pos select 1)+(_width*cos _xDir), _pos select 2];
-
- _blockingObjects = lineIntersectsWith [_pos, _sidePos];
- if (!(_b in _blockingObjects)) then {
- _c = _c + 1;
- } else {
- _c = 0;
- };
-
- _i = _i + 1;
- };
-
- if(_c == _nrVis) then {
- _return = 1;
- };
- };
- _return
- };
-
- if(typeName _this == typeName []) then {
- _b = _this select 0;
- _offset = if(count _this > 1) then { _this select 1 } else { 1.5 };
- _aslPos = getPosASL _b;
- _bBox = boundingBox _b;
-
- _bBoxWidth = ((_bBox select 1) select 0) - ((_bBox select 0) select 0);
- _bBoxDepth = ((_bBox select 1) select 1) - ((_bBox select 0) select 1);
- _bBoxHeight = ((_bBox select 1) select 2) - ((_bBox select 0) select 2);
-
- _searchW = if(_bBoxWidth > _bBoxDepth) then {_bBoxWidth} else {_bBoxDepth};
- _searchH = _bBoxHeight;
-
- _notVisable = [];
- _visFromSide = [];
- _visFromAbove = [];
-
- _i = 0;
- _bP = _b buildingPos _i;
- while {{_x != 0} count _bP > 0} do {
- _xPos = [_bP select 0, _bP select 1, (_bP select 2) + _offset];
- _visIndex = [_b, _xPos, _searchW, 50] call _fnc_checkLOS;
- switch (_visIndex) do {
- case 0: {
- _notVisable set [count _notVisable, _bP];
- };
- case 1: {
- _visFromSide set [count _visFromSide, _bP];
- };
- case 2: {
- _visFromAbove set [count _visFromAbove, _bP];
- };
- default {
- diag_log text format ["c_fnc_getBuildingPositions - Invalid _visIndex: %1", _visIndex];
- };
- };
- _i = _i + 1;
- _bP = _b buildingPos _i;
- };
- //Return
- [_notVisable, _visFromSide, _visFromAbove]
-
- } else {
- _b = _this;
- _p = [];
- _i = 0;
- _bP = _b buildingPos _i;
- while {{_x != 0} count _bP > 0} do {
- _p set [count _p, _bP];
- _i = _i + 1;
- _bP = _b buildingPos _i;
- };
- _p
- }
- };
复制代码 这里返还房屋最高的屋顶坐标,使用以下调用:- hint format ["%1",((nearestBuilding this) call c_fnc_getBuildingPositions) select 2];
复制代码 注:受模型限制,某些房屋不具备屋顶坐标,所以只能搜索到最高的阳台坐标或最高的窗口坐标。对于模型非定义坐标获取屋顶高度则自己加码调节:- player setpos [(((thislist select 0) call c_fnc_getBuildingPositions) select 2) select 0,(((thislist select 0) call c_fnc_getBuildingPositions) select 2) select 1,((((thislist select 0) call c_fnc_getBuildingPositions) select 2) select 2) + 2]
复制代码 PS以上是单个位置,若count (((nearestBuilding this) call c_fnc_getBuildingPositions) select 2) > 1那就可以selectRandom. |
|