Skip to content
Draft
Show file tree
Hide file tree
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
17 changes: 12 additions & 5 deletions addons/common/functions/fnc_getRandomPos.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* 2: Position can be on road <BOOL>
* 3: Position must be near house <BOOL>
* 4: Search radius for empty position <NUMBER>
* 5: Blacklisted areas <ARRAY<OBJECT/STRING/AREA/LOCATION>>
*
* Return Value:
* 0: Random position on the map <POSITION>
Expand All @@ -19,14 +20,20 @@
* Public: No
*/

params [["_objectType", ""], ["_nearRoad", false], ["_allowOnRoad", true], ["_nearHouse", false], ["_emptyPosSearchRadius", 25]];
params [
["_objectType", ""],
["_nearRoad", false],
["_allowOnRoad", true],
["_nearHouse", false],
["_emptyPosSearchRadius", 25],
["_blacklistedAreas", []]];

// Function returns random position
private _fnc_randomPos = {
params ["_nearRoad", "_allowOnRoad", "_nearHouse"];
params ["_nearRoad", "_allowOnRoad", "_nearHouse", "_blacklistedAreas"];
private _randomPos = [];
while {_randomPos isEqualTo []} do {
_randomPos = [] call BIS_fnc_randomPos;
_randomPos = [nil, _blacklistedAreas] call BIS_fnc_randomPos;
if (!(_randomPos isEqualTo []) && {_nearHouse && {!([_randomPos] call FUNC(isHouseNearby))}}) then {
_randomPos = [];
};
Expand All @@ -50,13 +57,13 @@ if (!(_objectType isEqualType "")) then {
};

// If no object is given, just random position is enough
if (_objectType isEqualTo "") exitWith {[_nearRoad, _allowOnRoad, _nearHouse] call _fnc_randomPos};
if (_objectType isEqualTo "") exitWith {[_nearRoad, _allowOnRoad, _nearHouse, _blacklistedAreas] call _fnc_randomPos};

private _randomPos = [];
private _loopLimit = 250;
// Loop until acquired random empty pos is within location area (or loop limit reached)
while {(_loopLimit >= 0) && {(_randomPos isEqualTo [])}} do {
_randomPos = [_nearRoad, _allowOnRoad, _nearHouse] call _fnc_randomPos;
_randomPos = [_nearRoad, _allowOnRoad, _nearHouse, _blacklistedAreas] call _fnc_randomPos;
_randomPos = _randomPos findEmptyPosition [0, _emptyPosSearchRadius, _objectType];
_loopLimit = _loopLimit - 1;
};
Expand Down
3 changes: 2 additions & 1 deletion addons/police/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class CfgPatches {
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {
"afsk_equipment",
"afsk_modules"
"afsk_modules",
"afsk_vehicles"
};
author = "ArmaForces";
VERSION_CONFIG;
Expand Down
3 changes: 3 additions & 0 deletions addons/police/functions/fnc_initPoliceStation.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ _logic setVariable ["Marker", _marker];
// Create teleporter
_logic setVariable ["Teleporter", _flag, true];
[QGVAR(createTeleport), [_flag]] call CBA_fnc_globalEventJIP;

private _stationArea = _logic getVariable ["objectArea", []];
[QGVAR(policeStationInitialized), [_logic]] call CBA_fnc_localEvent;
7 changes: 7 additions & 0 deletions addons/vehicles/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#include "script_component.hpp"

if (isServer) then {
[FUNC(initVehicles)] call CBA_fnc_execNextFrame;

[QEGVAR(police,policeStationInitialized), {
params ["_policeStationArea"];
// Register as blacklisted area for civilian vehicle spawn
GVAR(vehicleBlacklistedAreas) pushBackUnique _policeStationArea;
}] call CBA_fnc_addEventHandler;

[QGVAR(carAlarm), FUNC(carAlarm)] call CBA_fnc_addEventHandler;
[QGVAR(disableCarAlarm), FUNC(disableCarAlarm)] call CBA_fnc_addEventHandler;
Expand Down
4 changes: 2 additions & 2 deletions addons/vehicles/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
ADDON = false;
#include "XEH_PREP.hpp"

#include "initSettings.sqf"
#include "initSettings.inc.sqf"

// We need some improvements in determining civilian vehicles limit
GVAR(emptyVehiclesLimit) = 500;

if (isServer) then {
call FUNC(initVehicles);
GVAR(vehicleBlacklistedAreas) = [];
};

ADDON = true;
2 changes: 1 addition & 1 deletion addons/vehicles/functions/fnc_initVehicles.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private _civilianCarTypes = "( (getNumber (_x >> 'scope') >= 2)

while {_i > 0} do {
private _carType = selectRandom _civilianCarTypes;
private _pos = [_carType, true, false, true] call EFUNC(common,getRandomPos);
private _pos = [_carType, true, false, true, nil, GVAR(vehicleBlacklistedAreas)] call EFUNC(common,getRandomPos);
if (!(_pos isEqualTo [])) then {
// Check if there are other vehicles nearby to prevent creating too much vehicles in one area
private _distance = 100 * (4 - GVAR(emptyVehiclesLimitMultiplier));
Expand Down