Jump to content
beno_83au

Find position in the jungle

Recommended Posts

Good afternoon.

 

I've got a script written up to get some positions within the Tanoa jungle that are along the trails. These positions are ideally "deep" within the jungle (by deep, i mean a few hundred metres) with a few less-than-ideal positions that are captured due to the way I've set this up. It works, but I was wondering if there's a better way to go about this, as it seems to be a pretty long winded and imperfect way of going about getting positions:

params ["_mapMiddle","_allRoadPositions","_jungleTrailPositions","_roadPosition"];

_mapMiddle = [10000,10000,0];

_allRoadPositions = _mapMiddle nearRoads 15000;

_jungleTrailPositions = [];
{
	_roadPosition = getPos _x;
	if ((!isOnRoad _roadPosition) && (surfaceType _roadPosition == "#GdtForest")) then {
		if ((({
			(surfaceType _x == "#GdtForest") ||
			(surfaceType _x == "#GdtBeach") ||
			(surfaceType _x == "#GdtSeabed")
		}) count [
			[(_roadPosition select 0) + 200,(_roadPosition select 1) + 200,0],
			[(_roadPosition select 0) + 200,(_roadPosition select 1) - 200,0],
			[(_roadPosition select 0) - 200,(_roadPosition select 1) + 200,0],
			[(_roadPosition select 0) - 200,(_roadPosition select 1) - 200,0],
			[(_roadPosition select 0) + 100,(_roadPosition select 1) + 100,0],
			[(_roadPosition select 0) + 100,(_roadPosition select 1) - 100,0],
			[(_roadPosition select 0) - 100,(_roadPosition select 1) + 100,0],
			[(_roadPosition select 0) - 100,(_roadPosition select 1) - 100,0]
		]) == 8) then {
			_jungleTrailPositions pushBack _roadPosition;
		};
	};
} forEach _allRoadPositions;

{ 
	_mkr = createMarker[str _x,_x];
	_mkr setMarkerShape "ELLIPSE";
	_mkr setMarkerSize [10,10];
	_mkr setMarkerColor "ColorOrange";
	_mkr setMarkerAlpha 1;
} forEach _jungleTrailPositions;

systemChat format["All - %1 --- Jungle - %2",count _allRoadPositions,count _jungleTrailPositions];

Basically, to determine if a position is "deep within the jungle" I check positions around it, being 100m & 200m on each cardinal direction, for their surfaceType. It feels sloppy, but I just couldn't come up with another way (besides checking more distances between 0m-200m) to check the area around the given position for any non-jungle area.

 

Is there a better way of doing this?

Share this post


Link to post
Share on other sites

if you could determine a good average density value for trees in Tanoa's jungle using nearestTerrainObjects, you could then just do nearestTerrainObjects with 100 m search radius on each of the jungle path road segments (should be able to filter those out of your giant road array checking their model string i think...not sure) and count the trees you collected and compare with your density.

 

little more brute force approach i just pulled out of my ass but maybe it leads you somewhere. i'm assuming this happens at mission start. so heaviness of it, would not be that much of a factor?

 

i have made a grid system that analyses all the 100 m grid squares on a map for a mission i'm making and it can pretty reliably detect forests with that method. i assume because BIS make their forest really nice and even. so who knows how it works on mod maps.

  • Like 1

Share this post


Link to post
Share on other sites

That's a very rough method, but should work fine if only ran once at mission start.

Another way would be to use selectBestPlaces, works really fast and you can return a plethora of different places, not just forests, but forests with hills, forests with houses etc..

Check out the related thread made by glorious rübe.

 

Cheers

  • Like 2

Share this post


Link to post
Share on other sites

Thanks guys.

 

On 10/02/2017 at 2:40 AM, Grumpy Old Man said:

Check out the related thread made by glorious rübe.

 

I posted there but didn't get a response (yet anyway, only been < 2 days), but I managed to work things out to a degree that enables me to do what I'm after.

 

params ["_mapMiddle","_allRoadPositions","_jungleTrailPositions","_roadPosition"];
_mapMiddle = [7228,6987,0];
_allRoadPositions = _mapMiddle nearRoads 10000;
_jungleTrailPositions = [];
{
	_roadPosition = getPos _x;
	if (
		(!isOnRoad _roadPosition) &&
		(surfaceType _roadPosition == "#GdtForest")
	) then {
		if ((((selectBestPlaces [_roadPosition,200,"(1 + meadow) * (1 + houses) * (1 + trees) * (1 + sea) * (1 - forest)",5,1]) select 0) select 1) < 2) then {
			_jungleTrailPositions pushBack _roadPosition;
		};
	};
} forEach _allRoadPositions;
missionNamespace setVariable ["jungleTrailPositions",_jungleTrailPositions];

So if returning true for !isOnRoad and surfaceType I run selectBestPlaces on the road position and determine whether it's far enough away from any meadow/houses/trees/sea then add it to the array. In the editor, when run from the console it takes about 58s to add ~588 positions (out of around 22,000 evaulated), but when run from init.sqf it stalls the mission loading for about 15s. I don't know if I can speed it up anymore, but for it's intended use these times don't cause a problem either way.

 

Cheers.

Share this post


Link to post
Share on other sites
23 minutes ago, beno_83au said:

but when run from init.sqf it stalls the mission loading for about 15s

Just hide it behind the loading screen.

[ "myLoadingScreen" ] call BIS_fnc_startLoadingScreen;

//calculate positions

[ "myLoadingScreen" ] call BIS_fnc_endLoadingScreen;

This way the user does not see any noticeable stall/hitching, plus the script runs at full speed as all other simulation and scene rendering is disabled.

  • Like 2

Share this post


Link to post
Share on other sites

Cheers Larrow, I've got a load screen setup going for something else for that exact reason (running startup scripts at full speed) so I'll certainly be taking advantage of that.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×