Skip to content

Commit

Permalink
population zones (i.e. whitelisting areas) + bugfix (#55)
Browse files Browse the repository at this point in the history
* fix for no position found
* wait a few secs until server loop starts
	* `[thisTrigger] call grad_civs_fnc_addExclusionZone` <-give that a  chance to run before spawning the first civs
* add POPULATION_ZONES : whitelist populations zones, and restrict them with exclusion ones. default population zone is the whole map.
* be explicit about empty arrays (thx @diwako)
  • Loading branch information
Fusselwurm authored Mar 19, 2020
1 parent 365ebb3 commit 41695dd
Show file tree
Hide file tree
Showing 18 changed files with 69 additions and 12 deletions.
4 changes: 4 additions & 0 deletions cfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class grad_civs {
class addExclusionZone {};
class clearExclusionZones {};
class getExclusionZones {};
class addPopulationZone {};
class clearPopulationZones {};
class getPopulationZones {};
class populateArea {};
class setBackpacks {};
class setClothes {};
Expand Down Expand Up @@ -56,6 +59,7 @@ class grad_civs {
class getGlobalCivs {};
class isInHouse {};
class nowPlusSeconds {};
class isInPopulatedZone {};
class removeFromStateMachine {};
};

Expand Down
Binary file added docs/exclusion_zone_trigger.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion functions/api/fn_addExclusionZone.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ if (isNull _trigger) exitWith {
ERROR("got NULL instead of a trigger as parameter");
};

GRAD_CIVS_EXCLUSION_ZONES pushBack _trigger;
GVAR(EXCLUSION_ZONES) pushBack _trigger;

INFO_2("added exclusion zone %1 at %2", triggerArea _trigger, getPos _trigger);
13 changes: 13 additions & 0 deletions functions/api/fn_addPopulationZone.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "..\..\component.hpp"

_this params [
["_trigger", objNull]
];

if (isNull _trigger) exitWith {
ERROR("got NULL instead of a trigger as parameter");
};

GVAR(POPULATION_ZONES) pushBack _trigger;

INFO_2("added population zone %1 at %2", triggerArea _trigger, getPos _trigger);
2 changes: 1 addition & 1 deletion functions/api/fn_clearExclusionZones.sqf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "..\..\component.hpp"

GRAD_CIVS_EXCLUSION_ZONES = [];
GVAR(EXCLUSION_ZONES) = [];

INFO("all exclusion zones removed");
5 changes: 5 additions & 0 deletions functions/api/fn_clearPopulationZones.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "..\..\component.hpp"

GVAR(POPULATION_ZONES) = [];

INFO("all population zones removed");
4 changes: 3 additions & 1 deletion functions/api/fn_getExclusionZones.sqf
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
GRAD_CIVS_EXCLUSION_ZONES
#include "..\..\component.hpp"

GVAR(EXCLUSION_ZONES)
3 changes: 3 additions & 0 deletions functions/api/fn_getPopulationZones.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "..\..\component.hpp"

GVAR(POPULATION_ZONES)
5 changes: 4 additions & 1 deletion functions/behaviour/fn_taskPatrolFindWaypoint.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ for "_i" from 1 to _maxTries do {
_findWaterPos,
_findRoadPos
] call FUNC(findRandomPos);
if (_searchPosition isEqualTo []) then {
_searchPosition = _position;
};

_searchPosition = if (_findPosOfInterest && {80 > random 100}) then {
[_searchPosition, false] call FUNC(findPositionOfInterest);
} else {
_searchPosition
};

private _inAnyExclusionZone = [GRAD_CIVS_EXCLUSION_ZONES, {_searchPosition inArea (_this#0)}] call FUNC(arrayContains);
private _inAnyExclusionZone = [_searchPosition] call FUNC(isInPopulatedZone);
if (!_inAnyExclusionZone) exitWith {
LOG_1("position %1 is not in exclusionzone, return it", _searchPosition);
_waypointPosition = _searchPosition;
Expand Down
2 changes: 1 addition & 1 deletion functions/behaviour/fn_taskPatrolFindWaypoints.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ for [{_i=0}, {_i<_count}, {_i=_i+1}] do {
_findWaterPos
] call FUNC(taskPatrolFindWaypoint);

if (count _nextWaypoint == 0) exitWith {
if (_nextWaypoint isEqualTo []) exitWith {
WARNING_3("could not find more than %1 waypoints within %2m around %3", _i, _radius, _position)
};
LOG_1("waypoint #%1 found", _i);
Expand Down
2 changes: 1 addition & 1 deletion functions/common/fn_findPositionOfInterest.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private _position = if (count _buildingPositions > 0) then {selectRandom _buildi
[_searchPosition,[50,100],[0,360]] call FUNC(findRandomPos);
};

if (count _position == 0) then {
if (_position isEqualTo []) then {
_position = _searchPosition;
};

Expand Down
16 changes: 16 additions & 0 deletions functions/common/fn_isInPopulatedZone.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "..\..\component.hpp"

params [
["_position", [0, 0, 0]]
];

private _inAnyPopulationZone = if (count GVAR(POPULATION_ZONES) == 0) then {
true
} else {
[GVAR(POPULATION_ZONES), {_position inArea (_this#0)}] call FUNC(arrayContains)
};
if (!_inAnyPopulationZone) exitWith {false};

private _inAnyExclusionZone = [GVAR(EXCLUSION_ZONES), {_position inArea (_this#0)}] call FUNC(arrayContains);

!_inAnyExclusionZone
3 changes: 2 additions & 1 deletion functions/init/fn_initConfig.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,5 @@ missionNamespace setVariable ["GRAD_CIVS_SPAWNDISTANCEINVEHICLESMAX",_distances

GRAD_CIVS_BUS_MEETNEIGHBOR_COOLDOWN = 150;
GRAD_CIVS_CHAT_TIME = 20;
GRAD_CIVS_EXCLUSION_ZONES = [];
GVAR(EXCLUSION_ZONES) = [];
GVAR(POPULATION_ZONES) = [];
2 changes: 1 addition & 1 deletion functions/spawn/fn_createSideRoadVehicles.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

params ["_locationPosition","_locationRadius","_amountFactor","_houseFactor","_minDistance","_maxAmount"];

if (count GRAD_CIVS_VEHICLES == 0) exitWith {};
if (GRAD_CIVS_VEHICLES isEqualTo []) exitWith {};
private _vehiclePositions = [];

//LOCAL FUNCTIONS ==============================================================
Expand Down
2 changes: 1 addition & 1 deletion functions/spawn/fn_findSpawnPosition.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private _result = {
[_allPlayers, _candidate, _minDistance] call grad_civs_fnc_isInDistanceFromOtherPlayers
}
&& {
({ _candidate inArea _x; } count GRAD_CIVS_EXCLUSION_ZONES) == 0
[_candidate] call FUNC(isInPopulatedZone)
}
) exitWith {
LOG_1("found spawn position %1", _candidate);
Expand Down
2 changes: 1 addition & 1 deletion functions/spawn/fn_findSpawnRoadSegment.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

params ["_allPlayers", "_minSpawnDistance", "_maxSpawnDistance", "_civilians"];

if (count _allPlayers == 0) exitWith {LOG("_allPlayers is empty"); objNull};
if (_allPlayers isEqualTo []) exitWith {LOG("_allPlayers is empty"); objNull};

private _refPlayerPos = getPos (selectRandom _allPlayers);

Expand Down
12 changes: 11 additions & 1 deletion functions/spawn/fn_serverLoop.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@ private _mainLoop = {

[] call grad_civs_fnc_spawnPass;
};
grad_civs_mainLoop = [_mainLoop, 2, []] call CBA_fnc_addPerFrameHandler;

// wait a bit until the main loop starts. that way, exclusion zone trigger inits have a chance to run
[
{
private _mainLoop = _this#0;
grad_civs_mainLoop = [_mainLoop, 2, []] call CBA_fnc_addPerFrameHandler;
},
[_mainLoop],
10
] call CBA_fnc_waitAndExecute;


grad_civs_debugLoop = [{
params ["_args", "_handle"];
Expand Down
2 changes: 1 addition & 1 deletion functions/spawn/fn_spawnPass.sqf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "..\..\component.hpp"

_allPlayers = allPlayers - (entities "HeadlessClient_F");
if (count _allPlayers == 0) exitWith {};
if (_allPlayers isEqualTo []) exitWith {};

private _fps = diag_fps;
if (_fps < GRAD_CIVS_MINFPS) exitWith {INFO_2("not spawning additional civs: less FPS than required (%1/%2)", _fps, GRAD_CIVS_MINFPS)};
Expand Down

0 comments on commit 41695dd

Please sign in to comment.