Skip to content

Commit

Permalink
add staticVehicles param to fn_populateArea
Browse files Browse the repository at this point in the history
  • Loading branch information
McDiod committed Feb 24, 2019
1 parent 3cf0b16 commit 35f5628
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,14 @@ headgear | Array - All classnames of clothes that civilians may wear.
Manually populates an area with civilians. These civilians count towards the maximum amount.

### Syntax
`[area,amount,excludeFromCleanup] call grad_civs_fnc_populateArea`

Parameter | Explanation
----------|-------------------------------------------------------------------------------------------------------------------------------------------------
area | Array / Object - Area array in format `[a, b, angle, isRectangle]` or array of area arrays or gamelogic synchronzed to one or multiple triggers.
amount | Number - Amount of civilians to spawn.
excludeFromCleanup (optional) | Bool - Sets if these civilians will be excluded from cleanup when no players are near. (default: true)
`[area,amount,excludeFromCleanup,staticVehicles,staticVehiclesMax] call grad_civs_fnc_populateArea`

Parameter | Explanation
------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------
area | Array / Object - Area array in format `[a, b, angle, isRectangle]` or array of area arrays or gamelogic synchronzed to one or multiple triggers.
amount | Number - Amount of civilians to spawn.
excludeFromCleanup (optional) | Bool - Sets if these civilians will be excluded from cleanup when no players are near. (default: true)
staticVehicles (optional) | Bool - Sets if static vehicles will be created in the area. (default: false)
staticVehiclesMax (optional) | Number - Maximum amount of static vehicles to create. Actual amount is based on number of roads and houses in area.

![](http://i.imgur.com/Cimaz4c.jpg)
20 changes: 12 additions & 8 deletions functions/common/fn_populateArea.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ if (!isServer) exitWith {};
if (!canSuspend) exitWith {_this spawn grad_civs_fnc_populateArea};
if (isNil "GRAD_CIVS_ONFOOTUNITS") exitWith {ERROR("grad-civs has not been initialized.")};

params ["_area",["_amount",20],["_excludeFromCleanup",true]];
params ["_area",["_amount",20],["_excludeFromCleanup",true],["_staticCars",false],["_staticCarsMax",20]];

private _areas = if (_area isEqualType objNull) then {synchronizedObjects _area} else {[_area]};
private _maxLoops = _amount * 5;
Expand All @@ -16,7 +16,7 @@ private _maxLoops = _amount * 5;
if (count _spawnPos > 0) then {
_civ = [_spawnPos] call grad_civs_fnc_spawnCivilian;
if (_excludeFromCleanup) then {
_civ setVariable ["grad_civs_excludeFromCleanup",true];
_civ setVariable ["grad_civs_excludeFromCleanup",true];
};
GRAD_CIVS_ONFOOTUNITS pushBack _civ;
GRAD_CIVS_ONFOOTCOUNT = GRAD_CIVS_ONFOOTCOUNT + 1;
Expand All @@ -28,14 +28,18 @@ private _maxLoops = _amount * 5;
if (_i > _maxLoops) exitWith {};
};

_vehAmount = if (_x isEqualType objNull) then {
(triggerArea _x) params [["_a",0],["_b",0]];
[getPos _x,_a max _b,1,30,15] call grad_civs_fnc_createSideRoadVehicles
} else {
_x params ["_center",["_a",0],["_b",0]];
[_center,_a max _b,1,1,15] call grad_civs_fnc_createSideRoadVehicles
private _vehAmount = 0;
if (_staticCars) then {
_vehAmount = if (_x isEqualType objNull) then {
(triggerArea _x) params [["_a",0],["_b",0]];
[getPos _x,_a max _b,5,5,15,_staticCarsMax] call grad_civs_fnc_createSideRoadVehicles
} else {
_x params ["_center",["_a",0],["_b",0]];
[_center,_a max _b,5,5,15,_staticCarsMax] call grad_civs_fnc_createSideRoadVehicles
};
};


INFO_2("Populated area with %1 civilians and %2 static cars.",_amountSpawned,_vehAmount);

false
Expand Down
4 changes: 2 additions & 2 deletions functions/spawn/fn_createSideRoadVehicles.sqf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "..\..\component.hpp"

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

if (count GRAD_CIVS_VEHICLES == 0) exitWith {};
private _vehiclePositions = [];
Expand All @@ -24,7 +24,7 @@ private _fnc_isSafe = {
private _thesePositions = [];
private _roads = _locationPosition nearRoads _locationRadius;
private _vehiclesToCreate = (round ((count _roads) * 0.07 * _amountFactor));
_vehiclesToCreate = round (2 max (_vehiclesToCreate + ((random (_vehiclesToCreate * 0.4)) - _vehiclesToCreate * 0.2)));
_vehiclesToCreate = round ((2 max (_vehiclesToCreate + ((random (_vehiclesToCreate * 0.4)) - _vehiclesToCreate * 0.2))) min _maxAmount);

while {count _roads > 0 && count _thesePositions < _vehiclesToCreate} do {
private ["_vehPos","_canCreate","_chosenDirection","_offRoadFound"];
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.4.1",
"version": "0.4.2",
"contributors": [
{
"name": "nomisum"
Expand Down

0 comments on commit 35f5628

Please sign in to comment.