Jump to content
Sign in to follow this  
akvadakar

How to determine if object is in a forest?

Recommended Posts

Hey,

I know that e.g. DAC does not create waypoints for vehicles in a forest.

Does anybody know how to get info that an object is in a forest / near trees ?

Share this post


Link to post
Share on other sites

IIRC in DAC you have to manually place markers or triggers over the forest areas for it to be able to detect them.

If you want a more general solution you can use this function:

comment{/*
IN FOREST
Returns if the location is inside a forest.
Result in forest corners, borders and between forest tiles is unreliable.

Uses measurements of vanilla forests done by Rellikki.

Parameters:
- Required:
* _p: position

- Optional:
* _v: check for vanilla forests only. If false, glades will also be detected. Default is true
* _r: radius. Default is 20
* _s: step. Default is 5

by kenoxite
*/};
private ["_p","_f","_ss","_z","_nO","_r","_x","_y","_i","_d","_v","_s"];

_p=_this select 0;
_v=if(count _this > 1)then{_this select 1}else{true};
_r=if(count _this > 2)then{_this select 2}else{20};
_s=if(count _this > 3)then{_this select 3}else{5};

_x=_p select 0;
_y=_p select 1;
_f=false;
_i=_s;
while {_i<_r && !_f} do {
_d=0;
while {_d<360 && !_f} do {
	_nO=nearestObject [_x+_i *sin(_d),_y+_i *cos(_d)];
	_z=getPos _nO select 2;
	_ss="emptydetector" camcreate [_x,_y,0];
	if((_nO distance _ss)<=40)then{if(_v)then{if((_z >= 18.0418 && _z <= 23.1900) || (_z >= 25.8946 && _z <= 28.5844) || (_z >= 23.4063 && _z <= 24.344) || (_z >= 11.6016 && _z <= 12.7339))then{_f=true}}else{if(_z>12)then{_f=true}}};
	camdestroy _ss;
	_d=_d+30;
};
_i=_i+_s;
};
_f

As stated, it uses Relliki's tree measurements, which should cover the default ones. Also, as it uses nearestObject, it might not return a forest block when the automatic check is done just between two forest blocks. It also has problems with diagonal forest edges. So, it's not 100% reliable, but it might be good enough in most cases.

You can copy the body of the function to a, say, inForest.sqf file, load it into memory as inForestCheck and use it as: [getpos vehicle player] call inForestCheck.

There's also more arguments you can pass. Just check the comments in the function.

  • Sad 1

Share this post


Link to post
Share on other sites

^^ check it. :cool:

Also try a forum search; there should be several solutions floating around (that probably should do better than checking bounding boxes of some nearest objects...).

EDIT: never mind... :o

Edited by ruebe

Share this post


Link to post
Share on other sites

lol ruebe

This is... OFP!

Also, go back to your fancy weather systems with your cheaty engine commands. Here in OFP we have to do it the hard way, or no way at all.

Edited by kenoxite

Share this post


Link to post
Share on other sites
lol ruebe

This is... OFP!

awww, crap. This again... :hammer:

hihi

...so, I see you guys are still having fun with good ol' OFP!

:rolleyes2: :pc:

Share this post


Link to post
Share on other sites

Damn it, I have never used .sqf. Would be cool to have that in .sqs format :o.

Can anyone please explain me this part?

load it into memory as inForestCheck and use it as: [getpos vehicle player] call inForestCheck.

I have no idea what should I do :/

Nice provocation Ruebe :D

Share this post


Link to post
Share on other sites

Can anyone please explain me this part?

I have no idea what should I do :/

That was some weird phrasing on my part. I mean that you can assign the function to a global variable (and hence load it into memory for the rest of the mission).

If you named the sqf file inForest.sqf then you should just write on the init.sqs (or elsewhere, but just once):

inForestCheck = loadFile "inForest.sqf";

Now every time you call the inForestCheck global variable the function will be processed. Such as: [getpos vehicle player] call inForestCheck

Say you want to know if a location set by a player using onMapSingleClick is in a forest, you would use something like:

player onMapSingleClick { if([_pos] call inForestCheck)then{ hint "The position is inside a forest!" } else { hint "The position is not in a forest" } };

Share this post


Link to post
Share on other sites

That is some dark magic but it works - thanks a lot, kenoxite :)

Just the line for onMapSingleClick should be:

onMapSingleClick { if([_pos] call inForestCheck)then{ hint "The position is inside a forest!" } else { hint "The position is not in a forest" } };

Edited by Akvadakar

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
Sign in to follow this  

×