Spinor, could you please post this script?! This is EXACTLY what I have been wanting to be able to do for so long!
I'd love to see this! I can think of so much to do with this!
Checking terrain obstacles with nearestObject?!?! WOW! Such script must be a jewel! Didn't think it was
possible...
Mind you, it is a bad workaround so its far from perfect and as I mentioned it puts
quite some workload on the CPU. As I don't have internet at home at the moment, it's
a little difficult to put the script up. In any case, my script is not originally intended to
determine each single object but to determine the general category of a map grid.
Anyway, here's a snippet (untested) to scan an area of size _dx * _dy around
the position [_x0,_y0]. All objects found are stored in the arrays _objs (containing all
proper objects belonging to an actual object class, e.g. buildings), _roads, _bushes
(probably also containing rocks) , _trees and _forests
;---------------------------
;center of scan area
_x0 = 5000
_y0 = 5000
;scan area size
_dx = 200
_dy = 200
;step size for nearestObject calls
_incr = 5
_objs=[]
_roads=[]
_bushes= []
_trees=[]
_forests[]
_x = _x0 - _dx/2
_y = _y0 - _dy/2
#LoopX
?!(_x < _x0 + _dx/2): goto "EndLoopX"
#LoopY
?!(_y < _y0 + _dy/2): goto "EndLoopY"
_object = nearestObject[_x,_y,0]
;object analysis----------------
;if object is of known class type (== of class "All"), it is not a road/bush/tree/forest
?("All" countType [_object] == 1): _objs = _objs + [_object]; goto "EndAnalysis"
_z = (getPos _object) select 2
?_z < 0.2: _roads = _roads + [_object]; goto "EndAnalysis"
?_z < 3: _bushes = _bushes + [_object]; goto "EndAnalysis"
?_z < 12: _trees = _trees + [_object]; goto "EndAnalysis"
_forests = _forests + [_object]
;---------------------------
#EndAnalysis
_y = _y + _incr
goto "LoopY"
#EndLoopY
_x = _x + _incr
goto "LoopX"
#EndLoopX
;--------------------------------
If the snippet works as expected it should put all the objects, bushes, etc. into their
respective arrays. Armed with these you should be able to do all kinds of stunts,
e.g. determine the closest cover for a given unit, an analysis of good cover areas, etc.
The method is not foolproof and is bound to give some false results sometimes, e.g.
misinterpreting a tree for a bush, etc. The z-values used (0.2,3,12) are not perfect,
a little finetuning maybe required.
With the numbers given, the snippet will have to perform (200/5) * (200/5) = 1600 nearestObject
calls to scan an area of 200m * 200m.
The object analysis can be extended to determine the type of buildings, etc. through the
use of typeOf,countType. Another neat command is buildingPos. If used properly
one can determine whether a building is enterable and if yes, how many building
positions it has.