From c17b3b28efe98f5c15830d76e90c23323536dce4 Mon Sep 17 00:00:00 2001 From: 3Mydlo3 Date: Thu, 7 Mar 2024 20:46:25 +0100 Subject: [PATCH] Make civilians start more compacted in cities/villages (#71) * Attempt to spawn civilians more compacted in cities * Decrease chance of too many civilians in one area * Add distinction for villages and cities in terms of spawn radius --- .../civilian/functions/fnc_initCivilians.sqf | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/addons/civilian/functions/fnc_initCivilians.sqf b/addons/civilian/functions/fnc_initCivilians.sqf index 9bf6b6d7..e75057ce 100644 --- a/addons/civilian/functions/fnc_initCivilians.sqf +++ b/addons/civilian/functions/fnc_initCivilians.sqf @@ -15,13 +15,29 @@ * Public: No */ +#define NEAR_ROAD true +#define ALLOW_ON_ROAD true +#define NEAR_BUILDINGS true +#define MAX_DISTANCE_TO_VILLAGE 500 +#define MAX_DISTANCE_TO_NEAREST_CITY 1000 + private _i = GVAR(initialCiviliansCount); while {_i > 0} do { - private _pos = [nil, false, true, true] call EFUNC(common,getRandomPos); + private _pos = [nil, NEAR_ROAD, ALLOW_ON_ROAD, NEAR_BUILDINGS] call EFUNC(common,getRandomPos); if (!(_pos isEqualTo [])) then { - private _nearestCity = [_pos, 1500] call FUNC(getNearestCity); + private _nearestCity = [_pos, MAX_DISTANCE_TO_NEAREST_CITY] call FUNC(getNearestCity); if (_nearestCity isEqualTo objNull) exitWith {}; + + private _nearestCityType = _nearestCity getVariable [QGVAR(cityType), "NameVillage"]; + private _cityPosition = _nearestCity getVariable [QGVAR(position), [0, 0, 0]]; + private _maxAllowedDistance = if (_nearestCityType isEqualTo "NameVillage") then { MAX_DISTANCE_TO_VILLAGE } else { MAX_DISTANCE_TO_NEAREST_CITY }; + if (_pos distance _cityPosition > _maxAllowedDistance) exitWith {}; + + private _nearbyCivilians = _pos nearEntities ["Man", 100]; + private _nearbyCiviliansCount = count _nearbyCivilians; + if (_nearbyCiviliansCount >= 2 && {(random 1) - _nearbyCiviliansCount * 0.05 > 0.1}) exitWith {}; + [_pos] call FUNC(createCivilian); _i = _i - 1; };