DMS_Exile/@ExileServer/addons/a3_dms/scripts/fn_FindSafePos.sqf
eraser1 30136c8f37 I know... it's been over a week... gimme a break
#### October 17, 2015 (2:30 PM CST-America):
* **NEW CONFIG VALUES**:

|DMS_TimeToFirstMission|
|DMS_ShowDifficultyColorLegend|
|DMS_TerritoryNearBlacklist|
|DMS_MinSurfaceNormal| (Used to be DMS_MaxSurfaceNormal, simply renamed)
|DMS_ai_launchers_per_group|
* **UPDATING ALL OF YOUR MISSION FILES IS HIGHLY RECOMMENDED UNLESS YOU
KNOW WHAT YOU'RE DOING**
* RENAMED "DMS_MaxSurfaceNormal" to "DMS_MinSurfaceNormal". I must have
been very tired when I named it...
* DMS_MinSurfaceNormal is now 0.9 by default, but will be 0.95 for Altis
and Bornholm (since they're relatively large/flat maps). Esseker is
still 0.85. If you want to convert DMS_MinSurfaceNormal to degrees, you
would take the arc-cosine of the surfaceNormal, and that will give you
the degrees from horizontal. For example, arccos(0.9) is about 25
degrees. Google: "arccos(0.9) in degrees"
* Tweaked and rebalanced "DMS_BanditMissionTypes". Most of the spawn
chances are the same, they're just reduced in order to prevent the
creation of arrays that are far larger than they need to be.
* You can now manually define how long it takes for the first mission to
spawn after a restart.
* DMS will now by default create markers on the bottom left of the map
to show which colors correspond to which difficulty. It isn't very
pretty, but it gets the point across.
* DMS will now manually calculate the center of the map and its radius,
if it isn't preconfigured by DMS.
* You can now specify the vehicles to spawn for missions: "bandits",
"cardealer", "construction", "donthasslethehoff", and "thieves".
* You can now specify the spawning location of any mission (and whether
or not to use an alternative location if the provided location is
invalid). This will allow for easy integration of DMS into admin tools.
* Added support for scripts to be executed on mission completion or
mission failure (this will allow you to have "multi-part" missions,
where you would simply spawn the next part of the mission if the
previous is completed).
* Restructured DMS_DEBUG from the previous patch in favor of a more
"optimized" method.
* DMS_fnc_findSafePos is completely overhauled; DMS no longer uses
"BIS_fnc_findSafePos". It also now throttles minSurfaceNormal on
repeated failure. You can now determine whether or not the mission
should spawn on water (however, I don't suggest you use this function
for water spawns yet).
* You can also now define a minimum distance from other territories for
missions.
* DMS_fnc_IsValidPosition will now check for water depth if the provided
position is meant to be checked as a "water spawn". It will now also
check for nearby missions from A3XAI or VEMF (untested).
* DMS_fnc_IsValidPosition now checks whether or not the position is
outside of the map borders.
* DMS_fnc_SelectOffsetPos will now return the 3rd element of the
provided position as-is.
* You can now have multiple AI within a group with a launcher.
* AI now have a 5-second godmode after spawning.
* You can now spawn a crate using ASL pos. DMS_fnc_SpawnCrate will also
make sure that the provided classname is valid.
* Just like SpawnCrate, "DMS_fnc_SpawnNonPersistentVehicle" and
"DMS_fnc_SpawnPersistentVehicle" will now make sure that the provided
classname is valid.
* "DMS_fnc_SpawnPersistentVehicle" now supports ASL spawning.
* Added support for [Rod Serling's](https://github.com/Rod-Serling) AVS.
* General optimization.
2015-10-17 14:39:07 -05:00

87 lines
4.1 KiB
Plaintext

/*
DMS_fnc_FindSafePos
Created by eraser1
ALL PARAMETERS ARE OPTIONAL (as long as configs are properly defined).
Excluding parameters will create some RPT spam, but it's not too much of an issue.
Usage:
[
_nearestObjectMinDistance, // NUMBER (distance): Minimum distance from the nearest object.
_waterNearLimit, // NUMBER (distance): Minimum distance from water.
_minSurfaceNormal, // NUMBER (between 0-1): Maximum "surfaceNormal"; Basically determines how steep a position is. Check the comment for config value "DMS_MinSurfaceNormal" in config.sqf for more info
_spawnZoneNearLimit, // NUMBER (distance): Minimum distance from a spawn point.
_traderZoneNearLimit, // NUMBER (distance): Minimum distance from a trader zone.
_missionNearLimit, // NUMBER (distance): Minimum distance from another mission.
_playerNearLimit, // NUMBER (distance): Minimum distance from a player.
_throttleParams // BOOLEAN: Whether or not some of the distance values should be throttled on repeated attempts.
_waterSpawn // (OPTIONAL) BOOLEAN: Whether or not the mission is supposed to spawn on water. Default: false
] call DMS_fnc_findSafePos;
*/
private ["_nearestObjectMinDistance", "_waterNearLimit", "_minSurfaceNormal", "_spawnZoneNearLimit", "_traderZoneNearLimit", "_missionNearLimit", "_playerNearLimit", "_territoryNearLimit", "_throttleParams", "_waterSpawn", "_isValidSpot", "_attempts", "_pos"];
params
[
["_nearestObjectMinDistance", 25, [0] ],
["_waterNearLimit", DMS_WaterNearBlacklist, [0] ],
["_minSurfaceNormal", DMS_MinSurfaceNormal, [0] ],
["_spawnZoneNearLimit", DMS_SpawnZoneNearBlacklist, [0] ],
["_traderZoneNearLimit", DMS_TraderZoneNearBlacklist,[0] ],
["_missionNearLimit", DMS_MissionNearBlacklist, [0] ],
["_playerNearLimit", DMS_PlayerNearBlacklist, [0] ],
["_territoryNearLimit", DMS_TerritoryNearBlacklist, [0] ],
["_throttleParams", DMS_ThrottleBlacklists, [true]]
];
_waterSpawn = if ((count _this)>9) then {_this select 9} else {false};
_isValidSpot = false;
_attempts = 0;
_restriction = if (_waterSpawn) then {2} else {0};
while{!_isValidSpot} do
{
_attempts = _attempts+1;
_pos = ([DMS_MapCenterPos,random DMS_MapRadius,random 360] call DMS_fnc_SelectOffsetPos) isFlatEmpty [_nearestObjectMinDistance, 0, 9999, 1, _restriction, _waterSpawn, objNull];
while {_pos isEqualTo []} do
{
_pos = ([DMS_MapCenterPos,random DMS_MapRadius,random 360] call DMS_fnc_SelectOffsetPos) isFlatEmpty [_nearestObjectMinDistance, 0, 9999, 1, _restriction, _waterSpawn, objNull];
};
// It will only throttle the missionNear blacklist and playerNear limits because those are the most likely to throw an exception.
// The throttling works by decreasing the parameters by 10% every 15 attempts, until it reaches 100 meters (by default).
if (_throttleParams && {(_attempts>=DMS_AttemptsUntilThrottle) && {(_attempts%DMS_AttemptsUntilThrottle)==0}}) then
{
_missionNearLimit = (DMS_ThrottleCoefficient * _missionNearLimit) max DMS_MinThrottledDistance;
_playerNearLimit = (DMS_ThrottleCoefficient * _playerNearLimit) max DMS_MinThrottledDistance;
// SurfaceNormal is a bit more tricky than distances, so it's throttled differently. To convert from degrees to surfaceNormal, you take the cosine of the degrees from horizontal. Take the arc-cosine to convert surfaceNormal to degrees: arccos(0.8) in degrees ~= 37
_minSurfaceNormal = (_minSurfaceNormal - 0.005) max 0.8;
if (DMS_DEBUG) then
{
(format ["FindSafePos :: Throttling _missionNearLimit to %1 and _playerNearLimit to %2 and _minSurfaceNormal to %4 after %3 failed attempts to find a safe position!",_missionNearLimit,_playerNearLimit,_attempts,_minSurfaceNormal]) call DMS_fnc_DebugLog;
};
};
_isValidSpot = [_pos, _waterNearLimit, _minSurfaceNormal, _spawnZoneNearLimit, _traderZoneNearLimit, _missionNearLimit, _playerNearLimit, _territoryNearLimit, _waterSpawn] call DMS_fnc_IsValidPosition;
};
_pos set [2,0];
if (DMS_DEBUG) then
{
(format["FindSafePos :: Found mission position %1 in %2 attempts. _this: %3",_pos,_attempts,_this]) call DMS_fnc_DebugLog;
};
_pos;