Skip to content

Commit

Permalink
Make civilians start more compacted in cities/villages (#71)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
3Mydlo3 authored Mar 7, 2024
1 parent 94969a6 commit c17b3b2
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions addons/civilian/functions/fnc_initCivilians.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit c17b3b2

Please sign in to comment.