From 74648440f111593cff22825117c8d0da6776fc21 Mon Sep 17 00:00:00 2001 From: Dystopian Date: Mon, 4 May 2020 22:08:55 +0400 Subject: [PATCH 1/2] Add civilian driver randomizing --- Code/functions/DRN/fn_MilitaryTraffic.sqf | 37 ++++++++++++++--------- Code/functions/Server/fn_initServer.sqf | 10 +++++- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/Code/functions/DRN/fn_MilitaryTraffic.sqf b/Code/functions/DRN/fn_MilitaryTraffic.sqf index 5f9b1bd0..515c9aca 100644 --- a/Code/functions/DRN/fn_MilitaryTraffic.sqf +++ b/Code/functions/DRN/fn_MilitaryTraffic.sqf @@ -1,4 +1,4 @@ -private ["_activeVehiclesAndGroup", "_vehiclesGroup", "_spawnSegment", "_vehicle", "_group", "_result", "_possibleVehicles", "_vehicleType", "_vehiclesCrew", "_skill", "_minDistance", "_tries", "_trafficLocation"]; +private ["_activeVehiclesAndGroup", "_spawnSegment", "_group", "_possibleVehicles", "_vehicleType", "_skill", "_minDistance", "_tries", "_trafficLocation"]; private ["_currentEntityNo", "_vehicleVarName", "_tempVehiclesAndGroup", "_deletedVehiclesCount", "_firstIteration", "_roadSegments", "_destinationSegment", "_destinationPos", "_direction"]; private ["_roadSegmentDirection", "_testDirection", "_facingAway", "_posX", "_posY", "_pos"]; private ["_fnc_OnSpawnVehicle", "_fnc_FindSpawnSegment"]; @@ -307,12 +307,27 @@ while {true} do { _possibleVehicles = a3e_arr_Escape_MilitaryTraffic_CivilianVehicleClasses; }; _vehicleType = _possibleVehicles select floor (random count _possibleVehicles); - _result = [_pos, _direction + 90, _vehicleType, _side] call BIS_fnc_spawnVehicle; - _vehicle = _result select 0; - [_vehicle] call a3e_fnc_onVehicleSpawn; - _vehiclesCrew = _result select 1; - _vehiclesGroup = _result select 2; + private _result = [_pos, _direction + 90, _vehicleType, _side] call BIS_fnc_spawnVehicle; + _result params ["_vehicle", "_vehiclesCrew", "_vehiclesGroup"]; + [_vehicle] call a3e_fnc_onVehicleSpawn; + if (_side == civilian) then { + private _class = selectRandom a3e_arr_Escape_MilitaryTraffic_CivilianCrewClasses; + private _newDriver = _vehiclesGroup createUnit [_class, _pos, [] , 0, "NONE"]; + private _driver = driver _vehicle; + moveOut _driver; + deleteVehicle _driver; + _newDriver moveInDriver _vehicle; + if (random 10 < 2 && {0 < _vehicle emptyPositions "Cargo"}) then { + _class = selectRandom a3e_arr_Escape_MilitaryTraffic_CivilianCrewClasses; + _vehiclesGroup createUnit [_class, _pos, [] , 0, "CARGO"]; + }; + _vehiclesCrew = crew _vehicle; + _vehiclesGroup addVehicle _vehicle; + _vehiclesGroup selectLeader commander _vehicle; + _result = [_vehicle, _vehiclesCrew, _vehiclesGroup]; + }; + // Name vehicle sleep random 0.05; if (isNil "drn_MilitaryTraffic_CurrentEntityNo") then { @@ -361,9 +376,7 @@ while {true} do { { private ["_debugMarkerColor"]; - _vehicle = _x select 0; - _group = _x select 1; - _debugMarkerName = _x select 3; + _x params ["_vehicle", "_group", "", "_debugMarkerName"]; _side = side _group; _debugMarkerColor = "Default"; @@ -392,11 +405,7 @@ while {true} do { private ["_closestUnitDistance", "_distance", "_crewUnits"]; private ["_scriptHandle"]; - _vehicle = _x select 0; - _group = _x select 1; - _crewUnits = _x select 2; - _debugMarkerName = _x select 3; - _scriptHandle = _x select 4; + _x params ["_vehicle", "_group", "_crewUnits", "_debugMarkerName", "_scriptHandle"]; _closestUnitDistance = 1000000; diff --git a/Code/functions/Server/fn_initServer.sqf b/Code/functions/Server/fn_initServer.sqf index 7c664a5a..e97fb4cf 100644 --- a/Code/functions/Server/fn_initServer.sqf +++ b/Code/functions/Server/fn_initServer.sqf @@ -416,7 +416,15 @@ private _UseMotorPools = Param_MotorPools; _vehicle addMagazineCargoglobal ["Chemlight_green", 5]; }; }; - + + a3e_arr_Escape_MilitaryTraffic_CivilianCrewClasses = ' + configName _x isKindOf "CAManBase" + && {getNumber (_x >> "scope") == 2} + && {getText (_x >> "vehicleClass") != "MenVR"} + && {getNumber (_x >> "side") == 3} + && {-1 == toLower (getArray (_x >> "hiddenSelectionsTextures") param [0, ""]) find "c_poloshirt_3_co.paa"} + ' configClasses (configFile >> "CfgVehicles") apply {configName _x}; + [civilian, [], _vehiclesCount, _enemySpawnDistance, _radius, 0.5, 0.5, _fnc_onSpawnCivilian, A3E_Debug] spawn drn_fnc_MilitaryTraffic; From 28e43f857742418f8c1b249c17bc3936d96502ac Mon Sep 17 00:00:00 2001 From: Dystopian Date: Fri, 9 Jan 2026 01:22:38 +0300 Subject: [PATCH 2/2] Revert trim trailing space --- Code/functions/Server/fn_initServer.sqf | 156 +++++++++--------- .../Spawning/fn_SpawnCivilianVehicle.sqf | 19 ++- 2 files changed, 89 insertions(+), 86 deletions(-) diff --git a/Code/functions/Server/fn_initServer.sqf b/Code/functions/Server/fn_initServer.sqf index b46e56d0..3e2bd0ca 100644 --- a/Code/functions/Server/fn_initServer.sqf +++ b/Code/functions/Server/fn_initServer.sqf @@ -25,7 +25,7 @@ if(!isNil("A3E_Param_Debug")) then { }; if(is3DENPreview) then { A3E_Debug = true; - + //Delete AI in Preview: { if(!isPlayer _x) then { @@ -64,7 +64,7 @@ _enemySpawnDistance = (A3E_Param_EnemySpawnDistance); [_enemyFrequency] call compile preprocessFileLineNumbers "Units\UnitClasses.sqf"; -//Load base templates +//Load base templates [] call a3e_fnc_loadTemplates; @@ -87,7 +87,7 @@ A3E_VAR_Side_Ind setFriend [A3E_VAR_Side_Blufor, 0]; A3E_VAR_Side_Blufor setFriend [A3E_VAR_Side_Opfor, 0]; A3E_VAR_Side_Opfor setFriend [A3E_VAR_Side_Blufor, 0]; - + if(A3E_Param_War_Torn == 0) then { A3E_VAR_Side_Opfor Setfriend [A3E_VAR_Side_Ind, 1]; A3E_VAR_Side_Ind setFriend [A3E_VAR_Side_Opfor, 1]; @@ -103,13 +103,13 @@ if(A3E_Param_War_Torn == 0) then { private ["_hour","_date"]; _hour = A3E_Param_TimeOfDay; switch (A3E_Param_TimeOfDay) do { - case 24: { + case 24: { _hour = round(random(24)); }; case 25: { _hour = 6+round(random(10)); //Between 0600 and 1600 }; - case 26: { + case 26: { _hour = 17 + round(random(11)); //Between 1700 and 0400 _hour = _hour % 24; }; @@ -121,7 +121,7 @@ _date set [4,0]; a3e_var_Escape_hoursSkipped = _hour - (date select 3); publicVariable "a3e_var_Escape_hoursSkipped"; - + [_date] call bis_fnc_setDate; @@ -147,18 +147,18 @@ _enemyMaxSkill = 0.60; //Kudos to Semiconductor -switch (A3E_Param_EnemySkill) do { - // Convert value from params.hpp into acceptable range - case 0: { _enemyMinSkill = 0.10; _enemyMaxSkill = 0.30; }; - case 1: { _enemyMinSkill = 0.30; _enemyMaxSkill = 0.50; }; - case 2: { _enemyMinSkill = 0.40; _enemyMaxSkill = 0.60; }; - case 3: { _enemyMinSkill = 0.60; _enemyMaxSkill = 0.80; }; - case 4: { _enemyMinSkill = 0.80; _enemyMaxSkill = 0.95; }; - default { _enemyMinSkill = 0.40; _enemyMaxSkill = 0.60; }; -}; - -a3e_var_Escape_enemyMinSkill = _enemyMinSkill; -a3e_var_Escape_enemyMaxSkill = _enemyMaxSkill; +switch (A3E_Param_EnemySkill) do { + // Convert value from params.hpp into acceptable range + case 0: { _enemyMinSkill = 0.10; _enemyMaxSkill = 0.30; }; + case 1: { _enemyMinSkill = 0.30; _enemyMaxSkill = 0.50; }; + case 2: { _enemyMinSkill = 0.40; _enemyMaxSkill = 0.60; }; + case 3: { _enemyMinSkill = 0.60; _enemyMaxSkill = 0.80; }; + case 4: { _enemyMinSkill = 0.80; _enemyMaxSkill = 0.95; }; + default { _enemyMinSkill = 0.40; _enemyMaxSkill = 0.60; }; +}; + +a3e_var_Escape_enemyMinSkill = _enemyMinSkill; +a3e_var_Escape_enemyMaxSkill = _enemyMaxSkill; a3e_var_Escape_enemyMinSkill = _enemyMinSkill; a3e_var_Escape_enemyMaxSkill = _enemyMaxSkill; @@ -201,8 +201,8 @@ private _backpack = [] call A3E_fnc_createStartpos; //### The following is a mission function now -[true] call A3E_fnc_InitVillageMarkers; -//[true] call drn_fnc_InitAquaticPatrolMarkers; +[true] call A3E_fnc_InitVillageMarkers; +//[true] call drn_fnc_InitAquaticPatrolMarkers; //Wait for players to actually arrive ingame. This may be a long time if server is set to persistent waituntil{uisleep 1; count([] call A3E_FNC_GetPlayers)>0}; @@ -253,7 +253,7 @@ if(false) then { private ["_fnc_OnSpawnAmbientInfantryGroup", "_fnc_OnSpawnAmbientInfantryUnit", "_scriptHandle"]; private ["_playerGroup", "_minEnemiesPerGroup", "_maxEnemiesPerGroup", "_fnc_OnSpawnGroup"]; - + _playerGroup = [] call A3E_fnc_GetPlayerGroup; switch (_enemyFrequency) do @@ -274,48 +274,48 @@ if(false) then { _maxEnemiesPerGroup = 8; }; }; - + _fnc_OnSpawnGroup = { { _x call drn_fnc_Escape_OnSpawnGeneralSoldierUnit; } foreach units _this; }; - + [(units _playerGroup) select 0, A3E_VAR_Side_Opfor, a3e_arr_Escape_InfantryTypes, _minEnemiesPerGroup, _maxEnemiesPerGroup, 500000, _enemyMinSkill, _enemyMaxSkill, _enemySpawnDistance + 250, _fnc_OnSpawnGroup, A3E_Debug] call drn_fnc_InitAquaticPatrols; - - + + // Initialize ambient infantry groups _fnc_OnSpawnAmbientInfantryUnit = { _this call drn_fnc_Escape_OnSpawnGeneralSoldierUnit; }; - + _fnc_OnSpawnAmbientInfantryGroup = { private ["_unit", "_enemyUnit"]; private ["_scriptHandle"]; - + _unit = units _this select 0; - + while {!(isNull _unit)} do { _enemyUnit = _unit findNearestEnemy (getPos _unit); if (!(isNull _enemyUnit)) exitWith { - + private _i = 0; for [{_i = (count waypoints _this) - 1}, {_i >= 0}, {_i = _i - 1}] do { deleteWaypoint [_this, _i]; }; - + _scriptHandle = [_this, drn_searchAreaMarkerName, (getPos _enemyUnit), A3E_Debug] spawn drn_fnc_searchGroup; _this setVariable ["drn_scriptHandle", _scriptHandle]; }; - + sleep 5; }; }; - + private ["_infantryGroupsCount", "_radius", "_groupsPerSqkm"]; switch (_enemyFrequency) do @@ -342,15 +342,15 @@ if(false) then { _radius = (_enemySpawnDistance + 500) / 1000; _infantryGroupsCount = round (_groupsPerSqkm * _radius * _radius * 3.141592); - + [_playerGroup, A3E_VAR_Side_Opfor, a3e_arr_Escape_InfantryTypes, _infantryGroupsCount, _enemySpawnDistance + 200, _enemySpawnDistance + 500, _minEnemiesPerGroup, _maxEnemiesPerGroup, _enemyMinSkill, _enemyMaxSkill, 750, _fnc_OnSpawnAmbientInfantryUnit, _fnc_OnSpawnAmbientInfantryGroup, A3E_Debug] spawn drn_fnc_AmbientInfantry; - + // Initialize the Escape military and civilian traffic private ["_vehiclesPerSqkm", "_radius", "_vehiclesCount", "_fnc_onSpawnCivilian"]; - + // Civilian traffic - + switch (_enemyFrequency) do { case 1: // 1-3 players @@ -366,14 +366,14 @@ if(false) then { _vehiclesPerSqkm = 1.2; }; }; - + _radius = _enemySpawnDistance + 500; _vehiclesCount = round (_vehiclesPerSqkm * (_radius / 1000) * (_radius / 1000) * 3.141592); + - - + // Enemy military traffic - + switch (_enemyFrequency) do { case 1: // 1-3 players @@ -389,22 +389,22 @@ if(false) then { _vehiclesPerSqkm = 1; }; }; - + _radius = _enemySpawnDistance + 500; _vehiclesCount = round (_vehiclesPerSqkm * (_radius / 1000) * (_radius / 1000) * 3.141592); [_vehiclesCount,_enemySpawnDistance,_radius,_enemyMinSkill, _enemyMaxSkill] spawn { params["_vehiclesCount","_enemySpawnDistance","_radius","_enemyMinSkill", "_enemyMaxSkill"]; - sleep 60*15; //Wait 15 Minutes before heavy vehicles may arrive + sleep 60*15; //Wait 15 Minutes before heavy vehicles may arrive [A3E_VAR_Side_Opfor, [], _vehiclesCount/2, _enemySpawnDistance, _radius, _enemyMinSkill, _enemyMaxSkill, drn_fnc_Escape_TrafficSearch, A3E_Debug] spawn drn_fnc_MilitaryTraffic; [A3E_VAR_Side_Ind, [], _vehiclesCount/2, _enemySpawnDistance, _radius, _enemyMinSkill, _enemyMaxSkill, drn_fnc_Escape_TrafficSearch, A3E_Debug] spawn drn_fnc_MilitaryTraffic; }; private ["_areaPerRoadBlock", "_maxEnemySpawnDistanceKm", "_roadBlockCount"]; private ["_fnc_OnSpawnInfantryGroup", "_fnc_OnSpawnMannedVehicle"]; - + _fnc_OnSpawnInfantryGroup = {{_x call drn_fnc_Escape_OnSpawnGeneralSoldierUnit;} foreach units _this;}; _fnc_OnSpawnMannedVehicle = {{_x call drn_fnc_Escape_OnSpawnGeneralSoldierUnit;} foreach (_this select 1);}; - + switch (_enemyFrequency) do { case 1: { _areaPerRoadBlock = 4.19; @@ -416,10 +416,10 @@ if(false) then { _areaPerRoadBlock = 2.5; }; }; - + _maxEnemySpawnDistanceKm = (_enemySpawnDistance + 500) / 1000; _roadBlockCount = round ((_maxEnemySpawnDistanceKm * _maxEnemySpawnDistanceKm * 3.141592) / _areaPerRoadBlock); - + if (_roadBlockCount < 1) then { _roadBlockCount = 1; }; @@ -459,17 +459,17 @@ call A3E_fnc_InitTraps; [A3E_StartPos, _backPack, _enemyFrequency] spawn { params ["_startPos", "_backPack", "_enemyFrequency"]; private ["_guardGroup", "_marker", "_guardCount", "_guardGroups", "_unit", "_createNewGroup"]; - - + + // Spawn guard _guardCount = [-1,-1,3,8] call a3e_fnc_getDynamicSquadSize; - private _i = 0; + private _i = 0; for [{_i = 0}, {_i < (_guardCount)}, {_i = _i + 1}] do { private _weapon = a3e_arr_PrisonBackpackWeapons select floor(random(count(a3e_arr_PrisonBackpackWeapons))); _backpack addWeaponCargoGlobal[(_weapon select 0),1]; _backpack addMagazineCargoGlobal[(_weapon select 1),3]; }; - + // Spawn more guards _marker = createMarker ["drn_guardAreaMarker", _startPos]; _marker setMarkerShape "ELLIPSE"; @@ -478,62 +478,62 @@ call A3E_fnc_InitTraps; if(missionNamespace getvariable["A3E_Debug",false]) then { _marker setMarkerAlpha 0.5; }; - + //_guardCount = (2 + (_enemyFrequency)) + floor (random 2); _guardGroups = []; _createNewGroup = true; - + for [{_i = 0}, {_i < _guardCount}, {_i = _i + 1}] do { private ["_pos"]; - + _pos = [_marker] call drn_fnc_CL_GetRandomMarkerPos; while {_pos distance _startPos < 10} do { _pos = [_marker] call drn_fnc_CL_GetRandomMarkerPos; }; - + if (_createNewGroup) then { _guardGroup = createGroup A3E_VAR_Side_Ind; _guardGroups set [count _guardGroups, _guardGroup]; _createNewGroup = false; }; - + //(a3e_arr_Escape_StartPositionGuardTypes select floor (random count a3e_arr_Escape_StartPositionGuardTypes)) createUnit [_pos, _guardGroup, "", (0.5), "CAPTAIN"]; _guardGroup createUnit [(a3e_arr_Escape_StartPositionGuardTypes select floor (random count a3e_arr_Escape_StartPositionGuardTypes)), _pos, [], 0, "FORM"]; - + if (count units _guardGroup >= 2) then { _createNewGroup = true; }; }; - + { _guardGroup = _x; - + _guardGroup setFormDir floor (random 360); - + { _unit = _x; //(units _guardGroup) select 0; _unit setUnitRank "CAPTAIN"; _unit unlinkItem "ItemCompass"; _unit unlinkItem "ItemGPS"; - - + + private _mapItems = missionNamespace getVariable ["A3E_MapItemsUsedInMission",["ItemMap"]]; {_unit unlinkItem _x;} foreach _mapItems; - + private _itemsToRemove = missionNamespace getVariable ["A3E_ItemsToBeRemoved",[]]; { _unit unlinkItem _x; } foreach _itemsToRemove; - - + + if (ACE_MedicalServer) then {_unit addItem "ACE_epinephrine"};//Add Epinephrine for each unit removeBackpackGlobal _unit; - + if(random 100 < 80) then { removeAllPrimaryWeaponItems _unit; - + }; private _hmd = hmd _unit; @@ -554,7 +554,7 @@ call A3E_fnc_InitTraps; _unit unlinkItem _hmd; _unit removeItem _hmd; }; - + //Track kills _unit addEventHandler ["Killed", { params ["_unit", "_killer"]; @@ -563,21 +563,21 @@ call A3E_fnc_InitTraps; missionNamespace setvariable ["A3E_Kill_Count",_killStats+1,false]; }; }]; - + //_unit setSkill a3e_var_Escape_enemyMinSkill; //[_unit, a3e_var_Escape_enemyMinSkill] call EGG_EVO_skill; - + //This should remove all types of handgrenades (for example RHS) _unit removeMagazines "Handgrenade"; - + _unit setVehicleAmmo 0.3 + random 0.7; } foreach units _guardGroup; - + [_guardGroup, _marker] spawn A3E_fnc_Patrol; - + } foreach _guardGroups; - + //Add an alert trigger to the prison A3E_fnc_revealPlayers = { private _guardGroup = _this; @@ -601,9 +601,9 @@ call A3E_fnc_InitTraps; // Start thread that waits for escape to start [_guardGroups] spawn { params ["_guardGroups"]; - + sleep 5; - + while {isNil("A3E_EscapeHasStarted")} do { sleep 1; // If any member of the group is to far away from fence, then escape has started @@ -621,7 +621,7 @@ call A3E_fnc_InitTraps; }; } foreach call A3E_FNC_GetPlayers; }; - + // ESCAPE HAS STARTED //{ // [[[_x], {(_this select 0) setCaptive false;}], "BIS_fnc_spawn", _x, false] call BIS_fnc_MP; @@ -634,7 +634,7 @@ call A3E_fnc_InitTraps; while{isNil("A3E_SoundPrisonAlarm")} do { if(!isNil("A3E_EscapeHasStarted")) then { { - private ["_guardGroup"]; + private ["_guardGroup"]; _guardGroup = _x; { if((_guardGroup knowsAbout _x)>2.5) exitwith { @@ -656,7 +656,7 @@ call A3E_fnc_InitTraps; sleep 0.5; }; }; - + //Watch for captive state [] spawn { while{isNil("A3E_EscapeHasStarted")} do { diff --git a/Code/functions/Spawning/fn_SpawnCivilianVehicle.sqf b/Code/functions/Spawning/fn_SpawnCivilianVehicle.sqf index 02afe93d..7dacb193 100644 --- a/Code/functions/Spawning/fn_SpawnCivilianVehicle.sqf +++ b/Code/functions/Spawning/fn_SpawnCivilianVehicle.sqf @@ -18,10 +18,13 @@ if(!isNull _road) then { ["Spawning vehicle.",["Spawning","CivilianCommuters"],[_pos, _direction, _vehicleType, civilian]] call a3e_fnc_log; private _result = [_pos, _direction, _vehicleType, civilian] call BIS_fnc_spawnVehicle; -_result params ["_vehicle", "_vehiclesCrew", "_group"]; +private _vehicle = _result select 0; [_vehicle] call a3e_fnc_onVehicleSpawn; +private _vehiclesCrew = _result select 1; +private _group = _result select 2; + // replace unit with random class private _class = selectRandom a3e_arr_Escape_MilitaryTraffic_CivilianCrewClasses; private _newDriver = _group createUnit [_class, _pos, [] , 0, "NONE"]; @@ -44,24 +47,24 @@ _group selectLeader commander _vehicle; clearitemcargoglobal _vehicle; clearWeaponCargoGlobal _vehicle; -clearMagazineCargoGlobal _vehicle; +clearMagazineCargoGlobal _vehicle; if (random 100 < 20) then { private ["_weaponItem"]; - + _weaponItem = selectRandom a3e_arr_CivilianCarWeapons; - + _vehicle addWeaponCargoGlobal [_weaponItem select 0, 1]; _vehicle addMagazineCargoGlobal [_weaponItem select 1, _weaponItem select 2]; -}; +}; if (random 100 < 80) then { - _vehicle addItemCargoglobal ["firstaidkit", 3]; + _vehicle addItemCargoglobal ["firstaidkit", 3]; }; if (random 100 < 80) then { - _vehicle addMagazineCargoglobal ["smokeshellRed", 2]; + _vehicle addMagazineCargoglobal ["smokeshellRed", 2]; }; if (random 100 < 80) then { - _vehicle addMagazineCargoglobal ["Chemlight_green", 5]; + _vehicle addMagazineCargoglobal ["Chemlight_green", 5]; }; ["Creating group.",["Spawning","CivilianCommuters"]] call a3e_fnc_log;