From 83c325cfe1ecbcdeb84d96c7b55b39562af7238f Mon Sep 17 00:00:00 2001 From: McDiod Date: Fri, 8 Sep 2017 20:40:01 +0200 Subject: [PATCH] update grad-civs --- functions/missionSetup/cfgFunctions.hpp | 1 + functions/missionSetup/fn_initCivs.sqf | 43 ---------- functions/missionSetup/fn_initCivsEquip.sqf | 51 ++++++++++++ node_modules/grad-civs/README.md | 10 +++ node_modules/grad-civs/cfgFunctions.hpp | 6 +- node_modules/grad-civs/component.hpp | 17 ++++ .../grad-civs/functions/behaviour/fn_flee.sqf | 3 +- .../functions/behaviour/fn_stopCiv.sqf | 2 +- .../functions/behaviour/fn_taskPatrol.sqf | 21 +++-- .../functions/common/fn_findBuildings.sqf | 34 ++++++++ .../common/fn_findPositionOfInterest.sqf | 10 ++- .../functions/common/fn_findRandomPos.sqf | 6 +- .../functions/common/fn_findRandomPosArea.sqf | 18 ++++ .../functions/common/fn_populateArea.sqf | 39 +++++++++ .../grad-civs/functions/spawn/fn_cleanup.sqf | 8 +- .../spawn/fn_createSideRoadVehicles.sqf | 83 +++++++++++++++++++ .../functions/spawn/fn_deleteIfDamaged.sqf | 10 +++ .../functions/spawn/fn_findSpawnPosition.sqf | 20 ++--- .../functions/spawn/fn_getPlayerPositions.sqf | 9 -- .../functions/spawn/fn_serverLoop.sqf | 30 +++++-- node_modules/grad-civs/package.json | 32 +++---- package.json | 2 +- 22 files changed, 347 insertions(+), 108 deletions(-) create mode 100644 functions/missionSetup/fn_initCivsEquip.sqf create mode 100644 node_modules/grad-civs/functions/common/fn_findBuildings.sqf create mode 100644 node_modules/grad-civs/functions/common/fn_findRandomPosArea.sqf create mode 100644 node_modules/grad-civs/functions/common/fn_populateArea.sqf create mode 100644 node_modules/grad-civs/functions/spawn/fn_createSideRoadVehicles.sqf create mode 100644 node_modules/grad-civs/functions/spawn/fn_deleteIfDamaged.sqf delete mode 100644 node_modules/grad-civs/functions/spawn/fn_getPlayerPositions.sqf diff --git a/functions/missionSetup/cfgFunctions.hpp b/functions/missionSetup/cfgFunctions.hpp index da0eaf0..4acae77 100644 --- a/functions/missionSetup/cfgFunctions.hpp +++ b/functions/missionSetup/cfgFunctions.hpp @@ -2,6 +2,7 @@ class grad_missionSetup { class missionSetup { class createDiaryRecords {}; class initCivs {}; + class initCivsEquip {preInit = 1;}; class initMission {postInit = 1;}; class initVars {preInit = 1;}; class intro {}; diff --git a/functions/missionSetup/fn_initCivs.sqf b/functions/missionSetup/fn_initCivs.sqf index 45051c9..8ae808d 100644 --- a/functions/missionSetup/fn_initCivs.sqf +++ b/functions/missionSetup/fn_initCivs.sqf @@ -1,49 +1,6 @@ #include "component.hpp" -#define REPNIF0(var1,var2) if(count var2 > 0) then {var1 = var2} -#define APPENDUNIQUE(var1,var2) var1 = var1 + var2;var1 = var1 arrayIntersect var1 - private _enable = ([missionConfigFile >> "CfgGradCivs","enableCivs",0] call BIS_fnc_returnConfigEntry) == 1; if !(_enable) exitWith {}; -private _islandType = [missionConfigFile >> "CfgIslands" >> worldName,"type",""] call BIS_fnc_returnConfigEntry; -if (_islandType == "") exitWith {ERROR("World is not defined in cfgIslands.")}; - -private _civCfg = missionConfigFile >> "CfgCivilians" >> _islandType; - -private _clothes = [_civCfg,"clothes",[]] call BIS_fnc_returnConfigEntry; -private _headgear = [_civCfg,"headgear",[]] call BIS_fnc_returnConfigEntry; -private _faces = [_civCfg,"faces",[]] call BIS_fnc_returnConfigEntry; -private _goggles = [_civCfg,"goggles",[]] call BIS_fnc_returnConfigEntry; -private _backpacks = [_civCfg,"backpacks",[]] call BIS_fnc_returnConfigEntry; - -private _userEquipmentCfg = missionConfigFile >> "CfgGradCivs" >> "userEquipment"; -private _userClothes = [_userEquipmentCfg,"clothes",[]] call BIS_fnc_returnConfigEntry; -private _userHeadgear = [_userEquipmentCfg,"headgear",[]] call BIS_fnc_returnConfigEntry; -private _userFaces = [_userEquipmentCfg,"faces",[]] call BIS_fnc_returnConfigEntry; -private _userGoggles = [_userEquipmentCfg,"goggles",[]] call BIS_fnc_returnConfigEntry; -private _userBackpacks = [_userEquipmentCfg,"backpacks",[]] call BIS_fnc_returnConfigEntry; - - -private _replace = ([_userEquipmentCfg,"replace",0] call BIS_fnc_returnConfigEntry) == 1; -if (_replace) then { - REPNIF0(_clothes,_userClothes); - REPNIF0(_headgear,_userHeadgear); - REPNIF0(_faces,_userFaces); - REPNIF0(_goggles,_userGoggles); - REPNIF0(_backpacks,_userBackpacks); -} else { - APPENDUNIQUE(_clothes,_userClothes); - APPENDUNIQUE(_headgear,_userHeadgear); - APPENDUNIQUE(_faces,_userFaces); - APPENDUNIQUE(_goggles,_userGoggles); - APPENDUNIQUE(_backpacks,_userBackpacks); -}; - -[_clothes] call grad_civs_fnc_setClothes; -[_headgear] call grad_civs_fnc_setHeadgear; -[_faces] call grad_civs_fnc_setFaces; -[_goggles] call grad_civs_fnc_setGoggles; -[_backpacks] call grad_civs_fnc_setBackpacks; - [] call grad_civs_fnc_initModule; diff --git a/functions/missionSetup/fn_initCivsEquip.sqf b/functions/missionSetup/fn_initCivsEquip.sqf new file mode 100644 index 0000000..4415f0b --- /dev/null +++ b/functions/missionSetup/fn_initCivsEquip.sqf @@ -0,0 +1,51 @@ +#include "component.hpp" +#define REPNIF0(var1,var2) if(count var2 > 0) then {var1 = var2} +#define APPENDUNIQUE(var1,var2) var1 = var1 + var2;var1 = var1 arrayIntersect var1 + +private _enable = ([missionConfigFile >> "CfgGradCivs","enableCivs",0] call BIS_fnc_returnConfigEntry) == 1; +if !(_enable) exitWith {}; + +private _islandType = [missionConfigFile >> "CfgIslands" >> worldName,"type",""] call BIS_fnc_returnConfigEntry; +if (_islandType == "") exitWith {ERROR("World is not defined in cfgIslands.")}; + +private _civCfg = missionConfigFile >> "CfgCivilians" >> _islandType; + +private _clothes = [_civCfg,"clothes",[]] call BIS_fnc_returnConfigEntry; +private _headgear = [_civCfg,"headgear",[]] call BIS_fnc_returnConfigEntry; +private _faces = [_civCfg,"faces",[]] call BIS_fnc_returnConfigEntry; +private _goggles = [_civCfg,"goggles",[]] call BIS_fnc_returnConfigEntry; +private _backpacks = [_civCfg,"backpacks",[]] call BIS_fnc_returnConfigEntry; +private _vehicles = [_civCfg,"vehicles",[]] call BIS_fnc_returnConfigEntry; + +private _userEquipmentCfg = missionConfigFile >> "CfgGradCivs" >> "userEquipment"; +private _userClothes = [_userEquipmentCfg,"clothes",[]] call BIS_fnc_returnConfigEntry; +private _userHeadgear = [_userEquipmentCfg,"headgear",[]] call BIS_fnc_returnConfigEntry; +private _userFaces = [_userEquipmentCfg,"faces",[]] call BIS_fnc_returnConfigEntry; +private _userGoggles = [_userEquipmentCfg,"goggles",[]] call BIS_fnc_returnConfigEntry; +private _userBackpacks = [_userEquipmentCfg,"backpacks",[]] call BIS_fnc_returnConfigEntry; +private _userVehicles = [_userEquipmentCfg,"vehicles",[]] call BIS_fnc_returnConfigEntry; + + +private _replace = ([_userEquipmentCfg,"replace",0] call BIS_fnc_returnConfigEntry) == 1; +if (_replace) then { + REPNIF0(_clothes,_userClothes); + REPNIF0(_headgear,_userHeadgear); + REPNIF0(_faces,_userFaces); + REPNIF0(_goggles,_userGoggles); + REPNIF0(_backpacks,_userBackpacks); + REPNIF0(_vehicles,_userVehicles); +} else { + APPENDUNIQUE(_clothes,_userClothes); + APPENDUNIQUE(_headgear,_userHeadgear); + APPENDUNIQUE(_faces,_userFaces); + APPENDUNIQUE(_goggles,_userGoggles); + APPENDUNIQUE(_backpacks,_userBackpacks); + APPENDUNIQUE(_vehicles,_userVehicles); +}; + +[_clothes] call grad_civs_fnc_setClothes; +[_headgear] call grad_civs_fnc_setHeadgear; +[_faces] call grad_civs_fnc_setFaces; +[_goggles] call grad_civs_fnc_setGoggles; +[_backpacks] call grad_civs_fnc_setBackpacks; +[_vehicles] call grad_civs_fnc_setVehicles; diff --git a/node_modules/grad-civs/README.md b/node_modules/grad-civs/README.md index afe8931..c53ae38 100644 --- a/node_modules/grad-civs/README.md +++ b/node_modules/grad-civs/README.md @@ -179,3 +179,13 @@ Used to manually initialize module. Has to be executed on clients and server. Ef Parameter | Explanation ----------|----------------------------------------------------------- headgear | Array - All classnames of clothes that civilians may wear. + +## grad_civs_fnc_populateArea +Manually populates an area with civilians. These civilians count towards the maximum amount, but will get cleaned up when no players are near enough. + +### Syntax +`[area] 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. diff --git a/node_modules/grad-civs/cfgFunctions.hpp b/node_modules/grad-civs/cfgFunctions.hpp index bcce730..88dce7f 100644 --- a/node_modules/grad-civs/cfgFunctions.hpp +++ b/node_modules/grad-civs/cfgFunctions.hpp @@ -15,8 +15,11 @@ class grad_civs { class common { file = MODULES_DIRECTORY\grad-civs\functions\common; + class findBuildings {}; class findPositionOfInterest {}; class findRandomPos {}; + class findRandomPosArea {}; + class populateArea {}; class setBackpacks {}; class setClothes {}; class setDebugMode {}; @@ -54,9 +57,10 @@ class grad_civs { class spawnCivilian {}; class cleanup {}; + class createSideRoadVehicles {}; + class deleteIfDamaged {}; class dressAndBehave {}; class findSpawnPosition {}; - class getPlayerPositions {}; class addToVehicle {}; class serverLoop {}; class spawnVehicle {}; diff --git a/node_modules/grad-civs/component.hpp b/node_modules/grad-civs/component.hpp index b2f53a2..0535170 100644 --- a/node_modules/grad-civs/component.hpp +++ b/node_modules/grad-civs/component.hpp @@ -1,3 +1,20 @@ #define PREFIX GRAD #define COMPONENT civs + +/*#define DEBUG_MODE_FULL*/ #include "\x\cba\addons\main\script_macros_mission.hpp" + + + +#ifdef DEBUG_MODE_FULL + +#define LOGTIME_START(var1) missionNamespace setVariable [var1,diag_tickTime] +#define LOGTIME_DELTAT(var1) diag_tickTime - (missionNamespace getVariable [var1,diag_tickTime]) +#define LOGTIME_END(var1) LOG_SYS('PERFORMANCE',format [ARR_3('%1 took %2s',var1,LOGTIME_DELTAT(var1))]); missionNamespace setVariable [var1,nil] + +#else + +#define LOGTIME_START(var1) +#define LOGTIME_END(var1) + +#endif diff --git a/node_modules/grad-civs/functions/behaviour/fn_flee.sqf b/node_modules/grad-civs/functions/behaviour/fn_flee.sqf index d953309..7a7e88e 100644 --- a/node_modules/grad-civs/functions/behaviour/fn_flee.sqf +++ b/node_modules/grad-civs/functions/behaviour/fn_flee.sqf @@ -27,6 +27,7 @@ private _onVehicleExit = { //run away if (50 > random 100) then { _pos = [leader _grp,[150,300],[0,360]] call grad_civs_fnc_findRandomPos; + if (count _pos == 0) exitWith {}; { _x setVariable ["grad_civs_currentlyThinking", "who the fuck is shooting, have to run far away"]; false @@ -74,7 +75,7 @@ private _resumePatrol = { params ["_grp"]; units _grp doFollow leader _grp; - [_grp, leader _grp, 400 - (random 300), [3,6], [0,2,10]] call grad_civs_fnc_taskPatrol; + [_grp, leader _grp, 400 - (random 300), [3,6], [0,2,10]] spawn grad_civs_fnc_taskPatrol; { _x setSpeedMode "LIMITED"; diff --git a/node_modules/grad-civs/functions/behaviour/fn_stopCiv.sqf b/node_modules/grad-civs/functions/behaviour/fn_stopCiv.sqf index 649a2b5..8e26308 100644 --- a/node_modules/grad-civs/functions/behaviour/fn_stopCiv.sqf +++ b/node_modules/grad-civs/functions/behaviour/fn_stopCiv.sqf @@ -57,7 +57,7 @@ private _onUntargeted = { units _grp orderGetIn true; } else { (leader _grp) setVariable ["grad_civs_currentlyThinking", "lets patrol around"]; - [_grp, position (leader _grp), 400 - (random 300), [3,6], [0,2,10]] call grad_civs_fnc_taskPatrol; + [_grp, position (leader _grp), 400 - (random 300), [3,6], [0,2,10]] spawn grad_civs_fnc_taskPatrol; _grp setVariable ["grad_civs_stopScriptRunning", false]; }; }; diff --git a/node_modules/grad-civs/functions/behaviour/fn_taskPatrol.sqf b/node_modules/grad-civs/functions/behaviour/fn_taskPatrol.sqf index 915ca1f..4142be9 100644 --- a/node_modules/grad-civs/functions/behaviour/fn_taskPatrol.sqf +++ b/node_modules/grad-civs/functions/behaviour/fn_taskPatrol.sqf @@ -27,15 +27,18 @@ if !(local _group) exitWith {}; //create waypoints for [{_i=0}, {_i<_count}, {_i=_i+1}] do { _searchPosition = [_centerPosition,[0,_radius],[0,360],nil,_findWaterPos,_findRoadPos] call grad_civs_fnc_findRandomPos; - _position = if (_findPosOfInterest && {80 > random 100}) then {[_searchPosition] call grad_civs_fnc_findPositionOfInterest} else {_searchPosition}; - _waypoint = _group addWaypoint [_position, 0]; - - _waypoint setWaypointType "MOVE"; - _waypoint setWaypointBehaviour "SAFE"; - _waypoint setWaypointSpeed (if (4 > random 100) then {"NORMAL"} else {"LIMITED"}); - _waypoint setWaypointFormation "STAG COLUMN"; - _waypoint setWaypointTimeout _timeout; - _waypoint setWaypointCompletionRadius 1; + + if (count _searchPosition > 0) then { + _position = if (_findPosOfInterest && {80 > random 100}) then {[_searchPosition] call grad_civs_fnc_findPositionOfInterest} else {_searchPosition}; + _waypoint = _group addWaypoint [_position, 0]; + + _waypoint setWaypointType "MOVE"; + _waypoint setWaypointBehaviour "SAFE"; + _waypoint setWaypointSpeed (if (4 > random 100) then {"NORMAL"} else {"LIMITED"}); + _waypoint setWaypointFormation "STAG COLUMN"; + _waypoint setWaypointTimeout _timeout; + _waypoint setWaypointCompletionRadius 1; + }; }; diff --git a/node_modules/grad-civs/functions/common/fn_findBuildings.sqf b/node_modules/grad-civs/functions/common/fn_findBuildings.sqf new file mode 100644 index 0000000..a62bc6e --- /dev/null +++ b/node_modules/grad-civs/functions/common/fn_findBuildings.sqf @@ -0,0 +1,34 @@ +#include "..\..\component.hpp" + +params ["_searchPos","_radius"]; + +//exclusion list for houses +_exclusionList = [ + "Land_Pier_F", + "Land_Pier_small_F", + "Land_NavigLight", + "Land_LampHarbour_F", + "Land_runway_edgelight" +]; + +if (count _searchPos == 0) exitWith {[]}; + +//HOUSE LIST =================================================================== +_houseList = nearestObjects [_searchPos,["House"],_radius]; + +//Clean up house list (remove buildings that have no positions) +_cleanUpCounter = 0; +{ + _buildingPos = _x buildingPos 0; + if ((str _buildingPos) == "[0,0,0]") then { + _houseList = _houseList - [_x]; + _cleanUpCounter = _cleanUpCounter + 1; + } else { + if (typeOf _x in _exclusionList) then { + _houseList = _houseList - [_x]; + _cleanUpCounter = _cleanUpCounter + 1; + }; + }; +}forEach _houseList; + +_houseList diff --git a/node_modules/grad-civs/functions/common/fn_findPositionOfInterest.sqf b/node_modules/grad-civs/functions/common/fn_findPositionOfInterest.sqf index 9690b21..88cc323 100644 --- a/node_modules/grad-civs/functions/common/fn_findPositionOfInterest.sqf +++ b/node_modules/grad-civs/functions/common/fn_findPositionOfInterest.sqf @@ -1,16 +1,20 @@ -/* rip from diod */ - #include "..\..\component.hpp" params ["_searchPosition"]; if (_searchPosition isEqualType objNull) then {_searchPosition = getPos _searchPosition}; -private _buildings = nearestObjects [_searchPosition, ["House", "Building"], 100]; +private _buildings = _searchPosition nearObjects ["House", 100]; +_buildings append (_searchPosition nearObjects ["Building",100]); + private _nearestBuilding = if (count _buildings > 0) then {_buildings select 0} else {objNull}; private _buildingPositions = [_nearestBuilding] call BIS_fnc_buildingPositions; private _position = if (count _buildingPositions > 0) then {selectRandom _buildingPositions} else { [_searchPosition,[50,100],[0,360]] call grad_civs_fnc_findRandomPos; }; +if (count _position == 0) then { + _position = _searchPosition; +}; + _position diff --git a/node_modules/grad-civs/functions/common/fn_findRandomPos.sqf b/node_modules/grad-civs/functions/common/fn_findRandomPos.sqf index c95af6b..3dc51d0 100644 --- a/node_modules/grad-civs/functions/common/fn_findRandomPos.sqf +++ b/node_modules/grad-civs/functions/common/fn_findRandomPos.sqf @@ -8,7 +8,7 @@ _angles params ["_minAngle", "_maxAngle"]; if (_center isEqualType objNull) then {_center = getPos _center}; -for [{private _i=0}, {_i<50}, {_i=_i+1}] do { +for [{private _i=0}, {_i<25}, {_i=_i+1}] do { _searchDist = (random (_maxRad - _minRad)) + _minRad; _searchAngle = (random (_maxAngle - _minAngle)) + _minAngle; _searchPos = _center getPos [_searchDist, _searchAngle]; @@ -22,8 +22,4 @@ for [{private _i=0}, {_i<50}, {_i=_i+1}] do { if (count _pos > 0 && {(surfaceIsWater _pos) isEqualTo _findWaterPos}) exitWith {}; }; -if (str _pos == "[]") then { - _pos = [0,0,0]; -}; - _pos diff --git a/node_modules/grad-civs/functions/common/fn_findRandomPosArea.sqf b/node_modules/grad-civs/functions/common/fn_findRandomPosArea.sqf new file mode 100644 index 0000000..bcfc3c2 --- /dev/null +++ b/node_modules/grad-civs/functions/common/fn_findRandomPosArea.sqf @@ -0,0 +1,18 @@ +#include "..\..\component.hpp" + +params ["_area",["_vehicleType","B_Soldier_F"],["_findWaterPos",false],["_findRoadPos",false]]; + +_pos = []; +for [{private _i=0}, {_i<25}, {_i=_i+1}] do { + _searchPos = _area call BIS_fnc_randomPosTrigger; + + if (_findRoadPos) then { + _nearRoads = _searchPos nearRoads 50; + _searchPos = if (count _nearRoads > 0) then {getPos (_nearRoads select 0)} else {[]}; + }; + + _pos = if (_vehicleType != "" && {count _searchPos > 0}) then {_searchPos findEmptyPosition [0,10,_vehicleType]} else {_searchPos}; + if (count _pos > 0 && {(surfaceIsWater _pos) isEqualTo _findWaterPos}) exitWith {}; +}; + +_pos diff --git a/node_modules/grad-civs/functions/common/fn_populateArea.sqf b/node_modules/grad-civs/functions/common/fn_populateArea.sqf new file mode 100644 index 0000000..515b913 --- /dev/null +++ b/node_modules/grad-civs/functions/common/fn_populateArea.sqf @@ -0,0 +1,39 @@ +#include "..\..\component.hpp" + +if (!isServer) exitWith {}; +if (!canSuspend) exitWith {_this spawn grad_civs_fnc_populateArea}; + +params ["_area",["_amount",20]]; + +private _areas = if (_area isEqualType objNull) then {synchronizedObjects _area} else {[_area]}; +private _maxLoops = _amount * 5; +{ + _amountSpawned = 0; + for [{_i=0},{_i<1000},{_i=_i+1}] do { + + _spawnPos = [_x] call grad_civs_fnc_findRandomPosArea; + if (count _spawnPos > 0) then { + _civ = [_spawnPos] call grad_civs_fnc_spawnCivilian; + _civ setVariable ["grad_civs_excludeFromCleanup",true]; + GRAD_CIVS_ONFOOTUNITS pushBack _civ; + GRAD_CIVS_ONFOOTCOUNT = GRAD_CIVS_ONFOOTCOUNT + 1; + [_civ,_spawnPos,300 - (random 250),[3,6],[0,2,10],true] spawn grad_civs_fnc_taskPatrol; + _amountSpawned = _amountSpawned + 1; + }; + + if (_amountSpawned >= _amount) exitWith {}; + 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 + }; + + INFO_2("Populated area with %1 civilians and %2 static cars.",_amountSpawned,_vehAmount); + + false +} count _areas; diff --git a/node_modules/grad-civs/functions/spawn/fn_cleanup.sqf b/node_modules/grad-civs/functions/spawn/fn_cleanup.sqf index c6282a6..c562b7c 100644 --- a/node_modules/grad-civs/functions/spawn/fn_cleanup.sqf +++ b/node_modules/grad-civs/functions/spawn/fn_cleanup.sqf @@ -1,6 +1,6 @@ #include "..\..\component.hpp" -params ["_playerPositions","_mode"]; +params ["_allPlayers","_mode"]; private ["_cleanupDistance","_civsArray","_civsArrayVar","_counterVar","_idVar"]; switch (_mode) do { @@ -24,10 +24,14 @@ if (count _civsArray == 0) exitWith {}; private _id = missionNamespace getVariable [_idVar,0]; _id = if (_id >= (count _civsArray)-1) then {0} else {_id+1}; +for [{_i=0},{_i= (count _civsArray)-1) then {0} else {_id+1}; +}; missionNamespace setVariable [_idVar,_id]; private _civ = _civsArray select _id; -private _delete = ({_civ distance _x < _cleanupDistance} count _playerPositions) == 0; +private _delete = ({_civ distance _x < _cleanupDistance} count _allPlayers) == 0; if (_delete) then { _civsArray deleteAt _id; diff --git a/node_modules/grad-civs/functions/spawn/fn_createSideRoadVehicles.sqf b/node_modules/grad-civs/functions/spawn/fn_createSideRoadVehicles.sqf new file mode 100644 index 0000000..e0560b7 --- /dev/null +++ b/node_modules/grad-civs/functions/spawn/fn_createSideRoadVehicles.sqf @@ -0,0 +1,83 @@ +#include "..\..\component.hpp" + +params ["_locationPosition","_locationRadius","_amountFactor","_houseFactor","_minDistance"]; + +if (count GRAD_CIVS_VEHICLES == 0) exitWith {}; +private _vehiclePositions = []; + +//LOCAL FUNCTIONS ============================================================== +private _fnc_nearbyVehiclePositions = { + params ["_pos"]; + + _nearbyVehiclePositions = []; + {if (_pos distance2D _x < _minDistance) then {_nearbyVehiclePositions pushBack _x}} forEach _vehiclePositions; + _nearbyVehiclePositions +}; + +private _fnc_isSafe = { + params ["_pos"]; + !(([_pos,0,1,0,0,0.6,0,[],[[0,0,0],[0,0,0]]] call BIS_fnc_findSafePos) isEqualTo [0,0,0]) +}; + + +//MAIN ========================================================================= +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))); + +while {count _roads > 0 && count _thesePositions < _vehiclesToCreate} do { + private ["_vehPos","_canCreate","_chosenDirection","_offRoadFound"]; + + _randomRoadID = round (random ((count _roads)-1)); + _road = _roads deleteAt _randomRoadID; + + if (!isNull _road) then { + if (count (roadsConnectedTo _road) == 0) exitWith {}; + _roadDir = _road getDir ((roadsConnectedTo _road) select 0); + _boundingBox = boundingBox _road; + _width = ((_boundingBox select 1) select 0) - ((_boundingBox select 0) select 0); + + _startDirection = selectRandom [1,-1]; + { + _chosenDirection = _x; + _offRoadFound = false; + for [{_i=1}, {_i<50}, {_i=_i+1}] do { + _testPos = _road getRelPos [1.5 + _i*0.2,_roadDir+90*_chosenDirection]; + _vehPos = _testPos; + if (!isOnRoad _testPos) exitWith {_offRoadFound = true}; + }; + + _enoughHouses = if (_houseFactor < 0) then {true} else {(count ([_vehPos,20] call grad_civs_fnc_findBuildings)) * _houseFactor > random 100}; + + _canCreate = switch (true) do { + case (!_offRoadFound): {"ONROAD"}; + case (count (getPos _road nearRoads 10) > 2): {"ONINTERSECTION"}; + case (!_enoughHouses): {"NOHOUSES"}; + case (count ([_vehPos] call _fnc_nearbyVehiclePositions) > 0): {"TOOCLOSE"}; + case (!([_vehPos] call _fnc_isSafe)): {"UNSAFE"}; + default {"CANCREATE"}; + }; + + if (_forEachIndex == 1) then {_roadDir = _roadDir + 180}; + if (_canCreate == "CANCREATE") exitWith {}; + } forEach [_startDirection,-_startDirection]; + + if (_canCreate == "CANCREATE") then { + _type = selectRandom GRAD_CIVS_VEHICLES; + _thesePositions pushBack _vehPos; + _vehiclePositions pushBack _vehPos; + _veh = createVehicle [_type,[0,0,0],[],0,"CAN_COLLIDE"]; + [{!isNull (_this select 0)}, { + params ["_veh","_roadDir","_chosenDirection","_vehPos"]; + _veh setDir _roadDir + (90 + 90*_chosenDirection); + _veh setPos _vehPos; + _veh setVelocity [0,0,1]; + _veh lock 2; + [_veh] call grad_civs_fnc_deleteIfDamaged; + }, [_veh,_roadDir,_chosenDirection,_vehPos]] call CBA_fnc_waitUntilAndExecute; + }; + }; +}; + +count _vehiclePositions diff --git a/node_modules/grad-civs/functions/spawn/fn_deleteIfDamaged.sqf b/node_modules/grad-civs/functions/spawn/fn_deleteIfDamaged.sqf new file mode 100644 index 0000000..4cdc74c --- /dev/null +++ b/node_modules/grad-civs/functions/spawn/fn_deleteIfDamaged.sqf @@ -0,0 +1,10 @@ +#include "..\..\component.hpp" + +[{!isNull (_this select 0)}, { + [{ + params ["_object"]; + if (damage _object > 0) then { + deleteVehicle _object; + }; + }, _this, 5] call CBA_fnc_waitAndExecute; +}, _this] call CBA_fnc_waitUntilAndExecute; diff --git a/node_modules/grad-civs/functions/spawn/fn_findSpawnPosition.sqf b/node_modules/grad-civs/functions/spawn/fn_findSpawnPosition.sqf index 4ccdb10..a3b6456 100644 --- a/node_modules/grad-civs/functions/spawn/fn_findSpawnPosition.sqf +++ b/node_modules/grad-civs/functions/spawn/fn_findSpawnPosition.sqf @@ -1,15 +1,16 @@ #include "..\..\component.hpp" -params ["_allPlayerPositions", "_minSpawnDistance", "_maxSpawnDistance", "_civilianGroups"]; +params ["_allPlayers", "_minSpawnDistance", "_maxSpawnDistance", "_civilianGroups"]; -if (count _allPlayerPositions == 0) exitWith {INFO("_allPlayerPositions is empty"); [0,0,0]}; +if (count _allPlayers == 0) exitWith {INFO("_allPlayers is empty"); [0,0,0]}; private _spawnDistanceDiff = _maxSpawnDistance - _minSpawnDistance; private _roadSegment = objNull; -private _refPlayerPos = selectRandom _allPlayerPositions; +private _roadPos = [0,0,0]; +private _refPlayerPos = getPos (selectRandom _allPlayers); - -for [{_i=0}, {_i<20}, {_i=_i+1}] do { +//only 1 repetition for performance reasons >> kept for loop in case we want to bump it up again +for [{_i=0}, {_i<1}, {_i=_i+1}] do { _dir = random 360; _refPosX = (_refPlayerPos select 0) + (_minSpawnDistance + _spawnDistanceDiff / 2) * sin _dir; @@ -17,20 +18,20 @@ for [{_i=0}, {_i<20}, {_i=_i+1}] do { _roadSegments = [_refPosX, _refPosY] nearRoads (_spawnDistanceDiff / 2); _roadSegment = if (count _roadSegments > 0) then {selectRandom _roadSegments} else {objNull}; + _roadPos = getPos _roadSegment; _inSpawnZone = { { - _roadPos = getPos _roadSegment; if (_x distance _roadPos < _minSpawnDistance) exitWith {false}; if (_x distance _roadPos > _maxSpawnDistance) exitWith {false}; true - } forEach _allPlayerPositions; + } forEach _allPlayers; }; _awayFromOtherCivs = { { _unit = (units _x) param [0,objNull]; - if ((getPos _roadSegment) distance _unit < 100) exitWith {false}; + if (_roadPos distance _unit < 100) exitWith {false}; true } forEach _civilianGroups; }; @@ -38,5 +39,4 @@ for [{_i=0}, {_i<20}, {_i=_i+1}] do { if (!isNull _roadSegment && _inSpawnZone && _awayFromOtherCivs) exitWith {}; }; - -getPos _roadSegment +_roadPos diff --git a/node_modules/grad-civs/functions/spawn/fn_getPlayerPositions.sqf b/node_modules/grad-civs/functions/spawn/fn_getPlayerPositions.sqf deleted file mode 100644 index a7ffe46..0000000 --- a/node_modules/grad-civs/functions/spawn/fn_getPlayerPositions.sqf +++ /dev/null @@ -1,9 +0,0 @@ -/* blatantly ripped from engima traffic */ - -#include "..\..\component.hpp" - -if (isMultiplayer) then { - (call CBA_fnc_players) apply {getPos _x} -} else { - [getPos player] -} diff --git a/node_modules/grad-civs/functions/spawn/fn_serverLoop.sqf b/node_modules/grad-civs/functions/spawn/fn_serverLoop.sqf index 97d69b6..6f42191 100644 --- a/node_modules/grad-civs/functions/spawn/fn_serverLoop.sqf +++ b/node_modules/grad-civs/functions/spawn/fn_serverLoop.sqf @@ -7,53 +7,69 @@ private _mainLoop = { if (call GRAD_CIVS_EXITON) exitWith {[_handle] call CBA_fnc_removePerFrameHandler}; - _playerPositions = [] call grad_civs_fnc_getPlayerPositions; + _allPlayers = (call CBA_fnc_players); if (GRAD_CIVS_ENABLEDONFOOT) then { if (GRAD_CIVS_ONFOOTCOUNT < GRAD_CIVS_MAXCIVSONFOOT) then { + + LOGTIME_START("findSpawnPos_onFoot"); _pos = [ - _playerPositions, + _allPlayers, GRAD_CIVS_SPAWNDISTANCEONFOOTMIN, GRAD_CIVS_SPAWNDISTANCEONFOOTMAX, GRAD_CIVS_ONFOOTUNITS ] call grad_civs_fnc_findSpawnPosition; + LOGTIME_END("findSpawnPos_onFoot"); if (_pos isEqualTo [0,0,0]) exitWith {}; + LOGTIME_START("spawnCiv_onFoot"); _unit = [_pos] call grad_civs_fnc_spawnCivilian; + LOGTIME_END("spawnCiv_onFoot"); GRAD_CIVS_ONFOOTCOUNT = GRAD_CIVS_ONFOOTCOUNT + 1; GRAD_CIVS_ONFOOTUNITS pushBack _unit; if (GRAD_CIVS_DEBUGMODE) then {publicVariable "GRAD_CIVS_ONFOOTUNITS"; publicVariable "GRAD_CIVS_ONFOOTCOUNT"}; - [_unit,_pos,400 - (random 300),[3,6],[0,2,10],true] call grad_civs_fnc_taskPatrol; + [_unit,_pos,400 - (random 300),[3,6],[0,2,10],true] spawn grad_civs_fnc_taskPatrol; }; - [_playerPositions,"onfoot"] call grad_civs_fnc_cleanup; + + LOGTIME_START("cleanup_onFoot"); + [_allPlayers,"onfoot"] call grad_civs_fnc_cleanup; + LOGTIME_END("cleanup_onFoot"); }; if (GRAD_CIVS_ENABLEDINVEHICLES) then { if (GRAD_CIVS_INVEHICLESCOUNT < GRAD_CIVS_MAXCIVSINVEHICLES) then { + + LOGTIME_START("findSpawnPos_vehicle"); _pos = [ - _playerPositions, + _allPlayers, GRAD_CIVS_SPAWNDISTANCEINVEHICLESMIN, GRAD_CIVS_SPAWNDISTANCEINVEHICLESMAX, GRAD_CIVS_INVEHICLESUNITS ] call grad_civs_fnc_findSpawnPosition; + LOGTIME_END("findSpawnPos_vehicle"); if (_pos isEqualTo [0,0,0]) exitWith {}; + LOGTIME_START("spawnCiv_vehicle"); _veh = [_pos,selectRandom GRAD_CIVS_VEHICLES] call grad_civs_fnc_spawnVehicle; _unit = [_pos] call grad_civs_fnc_spawnCivilian; _unit assignAsDriver _veh; _unit moveinAny _veh; (group _unit) setSpeedMode "NORMAL"; - [_unit,_pos,2500,3,[0,0,0],false,true] call grad_civs_fnc_taskPatrol; + LOGTIME_END("spawnCiv_vehicle"); + + [_unit,_pos,2500,3,[0,0,0],false,true] spawn grad_civs_fnc_taskPatrol; GRAD_CIVS_INVEHICLESCOUNT = GRAD_CIVS_INVEHICLESCOUNT + 1; GRAD_CIVS_INVEHICLESUNITS pushBack _unit; if (GRAD_CIVS_DEBUGMODE) then {publicVariable "GRAD_CIVS_INVEHICLESUNITS"; publicVariable "GRAD_CIVS_INVEHICLESCOUNT"}; }; - [_playerPositions,"invehicles"] call grad_civs_fnc_cleanup; + LOGTIME_START("cleanup_vehicle"); + [_allPlayers,"invehicles"] call grad_civs_fnc_cleanup; + LOGTIME_END("cleanup_vehicle"); }; }; diff --git a/node_modules/grad-civs/package.json b/node_modules/grad-civs/package.json index 07d056d..1d771b4 100644 --- a/node_modules/grad-civs/package.json +++ b/node_modules/grad-civs/package.json @@ -2,26 +2,26 @@ "_args": [ [ { - "raw": "grad-civs@0.2.3", + "raw": "grad-civs@0.3.0", "scope": null, "escapedName": "grad-civs", "name": "grad-civs", - "rawSpec": "0.2.3", - "spec": "0.2.3", + "rawSpec": "0.3.0", + "spec": "0.3.0", "type": "version" }, "E:\\Dokumente\\Arma 3 - Other Profiles\\McDiod\\mpmissions\\TvT_Template.VR" ] ], - "_from": "grad-civs@0.2.3", - "_id": "grad-civs@0.2.3", + "_from": "grad-civs@0.3.0", + "_id": "grad-civs@0.3.0", "_inCache": true, "_installable": true, "_location": "/grad-civs", "_nodeVersion": "4.4.7", "_npmOperationalInternal": { "host": "s3://npm-registry-packages", - "tmp": "tmp/grad-civs-0.2.3.tgz_1502820118641_0.5477944375015795" + "tmp": "tmp/grad-civs-0.3.0.tgz_1504895581190_0.5886009691748768" }, "_npmUser": { "name": "gruppe-adler", @@ -30,22 +30,22 @@ "_npmVersion": "3.10.5", "_phantomChildren": {}, "_requested": { - "raw": "grad-civs@0.2.3", + "raw": "grad-civs@0.3.0", "scope": null, "escapedName": "grad-civs", "name": "grad-civs", - "rawSpec": "0.2.3", - "spec": "0.2.3", + "rawSpec": "0.3.0", + "spec": "0.3.0", "type": "version" }, "_requiredBy": [ "#USER", "/" ], - "_resolved": "https://registry.npmjs.org/grad-civs/-/grad-civs-0.2.3.tgz", - "_shasum": "7921cb326c7c64c8b22f2ef58031f4054c34ecdf", + "_resolved": "https://registry.npmjs.org/grad-civs/-/grad-civs-0.3.0.tgz", + "_shasum": "829aa50c7cec2f3efe9ca687640dd691e14f4f4a", "_shrinkwrap": null, - "_spec": "grad-civs@0.2.3", + "_spec": "grad-civs@0.3.0", "_where": "E:\\Dokumente\\Arma 3 - Other Profiles\\McDiod\\mpmissions\\TvT_Template.VR", "contributors": [ { @@ -60,10 +60,10 @@ "devDependencies": {}, "directories": {}, "dist": { - "shasum": "7921cb326c7c64c8b22f2ef58031f4054c34ecdf", - "tarball": "https://registry.npmjs.org/grad-civs/-/grad-civs-0.2.3.tgz" + "shasum": "829aa50c7cec2f3efe9ca687640dd691e14f4f4a", + "tarball": "https://registry.npmjs.org/grad-civs/-/grad-civs-0.3.0.tgz" }, - "gitHead": "c7526b09c7e94a4086cd03d0dbdb4d6a8790b543", + "gitHead": "e9caafde1c67ddf940a898380ddf907cb265e590", "maintainers": [ { "name": "gruppe-adler", @@ -74,5 +74,5 @@ "optionalDependencies": {}, "readme": "ERROR: No README data found!", "scripts": {}, - "version": "0.2.3" + "version": "0.3.0" } diff --git a/package.json b/package.json index 8239f20..bea204c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "tvt-template", "description": "Gruppe Adler TvT Template", - "version": "1.0.5", + "version": "1.0.6", "contributors": [ { "name": "McDiod"