BIS fnc findSafePos: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
mNo edit summary
(updated to accomodate improved function wip)
Line 12: Line 12:
<br>
<br>
The position '''pos''' will be generated inside an area which resides between '''minDist''' and '''maxDist''' from the given '''center'''. If '''objDist''' is also specified, the position will be selected '''objDist''' away from nearest terrain object. If '''maxGrad''' > 0 then the position will be also checked for how flat the area around is within '''objDist''' radius. The function can additionally be instructed to generate position specifically on water or land ('''waterMode''') or on a shoreline ('''shoreMode'''). The '''shoreLine''' param will be ignored if position is not requested specifically on land.<br><br>
The position '''pos''' will be generated inside an area which resides between '''minDist''' and '''maxDist''' from the given '''center'''. If '''objDist''' is also specified, the position will be selected '''objDist''' away from nearest terrain object. If '''maxGrad''' > 0 then the position will be also checked for how flat the area around is within '''objDist''' radius. The function can additionally be instructed to generate position specifically on water or land ('''waterMode''') or on a shoreline ('''shoreMode'''). The '''shoreLine''' param will be ignored if position is not requested specifically on land.<br><br>
Additionally, generated position could be checked against the list of blacklisted positions '''blacklistPos'''. If search for suitable position failed, '''defaultPos''' position will be used. The format for '''defaultPos''' is array with 2 positions: [posOnLand, posOnWater].
Additionally, generated position could be checked against the list of blacklisted positions '''blacklistPos'''. If search for suitable position failed, '''defaultPos''' position will be used. The format for '''defaultPos''' is array with 2 positions: [posOnLand, posOnWater]. |= Description
<br><br>
____________________________________________________________________________________________
<pre>
/*
File: findSafePos.sqf


Description:
| [center, minDist, maxDist, objDist, waterMode, maxGrad, shoreMode, blacklistPos, defaultPos] call [[BIS_fnc_findSafePos]] |= Syntax
Function to retrieve and dynamic position in the world according to several parameters.


Parameter(s):
|p1= center (Optional): - center position. Could be one of:
_this select 0: center position (Array)
* [[Array]] - [[Position2D]] or [[Position3D]] - position
Note: passing [] (empty Array), the world's safePositionAnchor entry will be used.
* [[Object]] - object which position will be used
_this select 1: minimum distance from the center position (Number)
* [[Nothing]] - when passing empty array [] or nothing, the world's "safePositionAnchor" entry will be used.|= Parameter 1
_this select 2: maximum distance from the center position (Number)
|p2= minDist (Optional): [[Number]] - minimum distance from the center position |= Parameter 1
Note: passing -1, the world's safePositionRadius entry will be used.
|p3= manDist (Optional): [[Number]] - maximum distance from the center position. '''Note''': when passing -1, the world's "safePositionRadius" entry will be used|= Parameter 1
_this select 3: minimum distance from the nearest object (Number)
|p4= objDist (Optional): [[Number]] - minimum distance from the nearest object|= Parameter 1
_this select 4: water mode (Number)
|p5= waterMode (Optional): [[Number]] - water mode. Could be one of:
0: cannot be in water
* 0 - cannot be in water
1: can either be in water or not
* 1 - can either be in water or not
2: must be in water
* 2 - must be in water|= Parameter 1
_this select 5: maximum terrain gradient (average altitude difference in meters - Number)
|p6= maxGrad (Optional): [[Number]] - maximum terrain gradient (hill steepness) |= Parameter 1
_this select 6: shore mode (Number):
|p7= waterMode (Optional): [[Number]] - shore mode. Could be one of:
0: does not have to be at a shore
* 0 - does not have to be at a shore
1: must be at a shore
* 1 - must be at a shore|= Parameter 1
_this select 7: (optional) blacklist (Array of Arrays):
|p8= blacklistPos (Optional): blacklisted area. Could be one of:
(_this select 7) select X: Top-left and bottom-right coordinates of blacklisted area (Array)
* [[Array]] - in format [topLeftCorner, bottomRightCorner] - top and bottom coordinates of blacklisted area
_this select 8: (optional) default positions (Array of Arrays):
* [[Object]] - trigger area
(_this select 8) select 0: default position on land (Array)
* [[String]] - marker area
(_this select 8) select 1: default position on water (Array)
* [[Location]] - location |= Parameter 1
|p9= defaultPos (Optional): [[Array]] default positions in format [posOnLand, posOnSea]|= Parameter 1
Returns:
Coordinate array with a position solution.
TODO:
* Maybe allow passing several combinations of position, min and max dist ... so that you can
avoid several things?
* Interpretation of minDist / maxDist is wrong. It's not true distance that is used. Too bad?
*/


</pre><small>''(Placeholder description extracted from the function header by [[BIS_fnc_exportFunctionsToWiki]])''</small> |= Description
| [[Array]] - in format [x,y]. When position cannot be found at all, default center position is returned, which will be in format [x,y,0]|= Return value
____________________________________________________________________________________________
____________________________________________________________________________________________


| <!-- [] call [[BIS_fnc_findSafePos]]; --> |= Syntax
|x1= Find position minimum 1m from from player but not further than 150m, not closer than 3m to any other object, not in the water, maximum gradient of 20, not on the shoreline: <code>_pos = <nowiki>[</nowiki>[[player]], 1, 150, 3, 0, 20, 0] [[call]] [[BIS_fnc_findSafePos]];</code> |=  
 
|x2= <code>_pos = <nowiki>[</nowiki>[[getPos]] [[player]], 2000, 5000, 1, 0, 0.7, 0, [], <nowiki>[</nowiki>[[getPos]] [[player]], [[getPos]] [[player]]<nowiki>]</nowiki>] [[call]] [[BIS_fnc_findSafePos]];</code> |=  
|p1= |= Parameter 1
|x3= <code>_pos = <nowiki>[</nowiki>[], 0, 1000] [[call]] [[BIS_fnc_findSafePos]];</code> |=  
 
| |= Return value
____________________________________________________________________________________________


|x1= <code>kRandSpawnPos = [kdestPos, 1, 150, 3, 0, 20, 0] call BIS_fnc_findSafePos;</code> |=
____________________________________________________________________________________________
____________________________________________________________________________________________


| |= See also
|[[BIS_fnc_randomPosTrigger]], [[BIS_fnc_randomPos]]|= See also


}}
}}
Line 70: Line 54:
<h3 style="display:none">Notes</h3>
<h3 style="display:none">Notes</h3>
<dl class="command_description">
<dl class="command_description">
<!-- Note Section BEGIN -->
Example 1 would generate a position as follows: 
Minimal 1 meter from "kdestPos" but not further than 150, not closer than 3 meters to any other object, not in the water, maximum gradient of 20 meters, not on the shoreline. And safe the generated position in "kRandSpawnPos". --[[User:Kamaradski|Kamaradski]] ([[User talk:Kamaradski|talk]]) 13:56, 10 March 2015 (CET)
1 -->
<!-- Note Section END -->
</dl>
</dl>



Revision as of 23:35, 11 January 2017


Hover & click on the images for description

Description

Description:
This function generates position on a map according to several given parameters (see diagram):

bis fnc findsafepos.jpg
The position pos will be generated inside an area which resides between minDist and maxDist from the given center. If objDist is also specified, the position will be selected objDist away from nearest terrain object. If maxGrad > 0 then the position will be also checked for how flat the area around is within objDist radius. The function can additionally be instructed to generate position specifically on water or land (waterMode) or on a shoreline (shoreMode). The shoreLine param will be ignored if position is not requested specifically on land.

Additionally, generated position could be checked against the list of blacklisted positions blacklistPos. If search for suitable position failed, defaultPos position will be used. The format for defaultPos is array with 2 positions: [posOnLand, posOnWater].
Execution:
call
Groups:
Uncategorised

Syntax

Syntax:
[center, minDist, maxDist, objDist, waterMode, maxGrad, shoreMode, blacklistPos, defaultPos] call BIS_fnc_findSafePos
Parameters:
center (Optional): - center position. Could be one of:
  • Array - Position2D or Position3D - position
  • Object - object which position will be used
  • Nothing - when passing empty array [] or nothing, the world's "safePositionAnchor" entry will be used.
minDist (Optional): Number - minimum distance from the center position
manDist (Optional): Number - maximum distance from the center position. Note: when passing -1, the world's "safePositionRadius" entry will be used
objDist (Optional): Number - minimum distance from the nearest object
waterMode (Optional): Number - water mode. Could be one of:
  • 0 - cannot be in water
  • 1 - can either be in water or not
  • 2 - must be in water
maxGrad (Optional): Number - maximum terrain gradient (hill steepness)
waterMode (Optional): Number - shore mode. Could be one of:
  • 0 - does not have to be at a shore
  • 1 - must be at a shore
blacklistPos (Optional): blacklisted area. Could be one of:
  • Array - in format [topLeftCorner, bottomRightCorner] - top and bottom coordinates of blacklisted area
  • Object - trigger area
  • String - marker area
  • Location - location
defaultPos (Optional): Array default positions in format [posOnLand, posOnSea]
Return Value:
Array - in format [x,y]. When position cannot be found at all, default center position is returned, which will be in format [x,y,0]

Examples

Example 1:
Find position minimum 1m from from player but not further than 150m, not closer than 3m to any other object, not in the water, maximum gradient of 20, not on the shoreline: _pos = [player, 1, 150, 3, 0, 20, 0] call BIS_fnc_findSafePos;
Example 2:
_pos = [getPos player, 2000, 5000, 1, 0, 0.7, 0, [], [getPos player, getPos player]] call BIS_fnc_findSafePos;
Example 3:
_pos = [[], 0, 1000] call BIS_fnc_findSafePos;

Additional Information

See also:
BIS_fnc_randomPosTriggerBIS_fnc_randomPos

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note

Notes

Bottom Section