Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make civilians start more compacted in cities/villages #71

Merged
merged 3 commits into from
Mar 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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