Skip to content

Commit

Permalink
optimize spawn position search
Browse files Browse the repository at this point in the history
  • Loading branch information
McDiod committed Sep 6, 2017
1 parent a93afe1 commit 5f7b6e0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
12 changes: 7 additions & 5 deletions functions/spawn/fn_findSpawnPosition.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,24 @@ if (count _allPlayers == 0) exitWith {INFO("_allPlayers is empty"); [0,0,0]};

private _spawnDistanceDiff = _maxSpawnDistance - _minSpawnDistance;
private _roadSegment = objNull;
private _roadPos = [0,0,0];
private _refPlayerPos = getPos (selectRandom _allPlayers);


for [{_i=0}, {_i<20}, {_i=_i+1}] do {
for [{_i=0}, {_i<10}, {_i=_i+1}] do {
_dir = random 360;

_refPosX = (_refPlayerPos select 0) + (_minSpawnDistance + _spawnDistanceDiff / 2) * sin _dir;
_refPosY = (_refPlayerPos select 1) + (_minSpawnDistance + _spawnDistanceDiff / 2) * cos _dir;

_roadSegments = [_refPosX, _refPosY] nearRoads (_spawnDistanceDiff / 2);
_roadSegment = if (count _roadSegments > 0) then {selectRandom _roadSegments} else {objNull};
_roadPos = getPos _roadSegment;

diag_log [_roadSegment,_roadPos];

_inSpawnZone = {
{
_roadPos = getPos _roadSegment;
if (_x distance _roadPos < _minSpawnDistance) exitWith {false};
if (_x distance _roadPos > _maxSpawnDistance) exitWith {false};
true
Expand All @@ -30,13 +33,12 @@ for [{_i=0}, {_i<20}, {_i=_i+1}] do {
_awayFromOtherCivs = {
{
_unit = (units _x) param [0,objNull];
if ((getPos _roadSegment) distance _unit < 100) exitWith {false};
if (_roadPos distance _unit < 100) exitWith {false};
true
} forEach _civilianGroups;
};

if (!isNull _roadSegment && _inSpawnZone && _awayFromOtherCivs) exitWith {};
};


getPos _roadSegment
_roadPos
4 changes: 0 additions & 4 deletions functions/spawn/fn_serverLoop.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ private _mainLoop = {
GRAD_CIVS_ONFOOTUNITS pushBack _unit;
if (GRAD_CIVS_DEBUGMODE) then {publicVariable "GRAD_CIVS_ONFOOTUNITS"; publicVariable "GRAD_CIVS_ONFOOTCOUNT"};

LOGTIME_START("taskPatrol_onFoot");
[_unit,_pos,400 - (random 300),[3,6],[0,2,10],true] spawn grad_civs_fnc_taskPatrol;
LOGTIME_END("taskPatrol_onFoot");
};

LOGTIME_START("cleanup_onFoot");
Expand Down Expand Up @@ -63,9 +61,7 @@ private _mainLoop = {
(group _unit) setSpeedMode "NORMAL";
LOGTIME_END("spawnCiv_vehicle");

LOGTIME_START("taskPatrol_vehicle");
[_unit,_pos,2500,3,[0,0,0],false,true] spawn grad_civs_fnc_taskPatrol;
LOGTIME_END("taskPatrol_vehicle");

GRAD_CIVS_INVEHICLESCOUNT = GRAD_CIVS_INVEHICLESCOUNT + 1;
GRAD_CIVS_INVEHICLESUNITS pushBack _unit;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "grad-civs",
"description": "ambient civilians",
"version": "0.2.3",
"version": "0.2.4",
"contributors": [
{
"name": "nomisum"
Expand Down

0 comments on commit 5f7b6e0

Please sign in to comment.