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

PATCOM Garrisons minor fixes and adjustments #2876

Merged
73 changes: 53 additions & 20 deletions A3A/addons/patcom/functions/Patcom/fn_patrolGroupGarrison.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -29,53 +29,86 @@ params ["_group", "_position", "_radius"];
private _units = units _group;
private _buildings = [];
private _newGroups = [];
private _minimumUnits = 2; // Minimum units per building.

if (count _units == 0) exitwith {};
if (count _units == 0) exitwith {
Debug_1("PATCOM | No units found in group (%1). Exiting", _group);
};

_group lockWP true;
_buildings = nearestObjects [_position, keys PATCOM_Garrison_Positions, _radius];
_buildings = [_position, _radius] call A3A_fnc_patrolEnterableBuildings;

if (count _buildings == 0) then {
_buildings = [_position, _radius] call A3A_fnc_patrolEnterableBuildings;
if (count _buildings == 0) exitWith {
Debug_1("PATCOM | No Valid Garrison buildings found near group: %1 | Defaulting to Defend.", _group);
[_group, "Patrol_Defend", 0, 100, -1, true, _position, false] call A3A_fnc_patrolLoop;
_group
};

// don't place units on destroyed buildings
// Don't place units in destroyed buildings
_buildings = _buildings select { damage _x < 1 && !isObjectHidden _x };
_buildings = _buildings call BIS_fnc_arrayShuffle;

// Figure out how many units should be put in each building.
private _unitsPerBuilding = ceil(count _units / count _buildings);
if (_unitsPerBuilding < _minimumUnits) then {_unitsPerBuilding = _minimumUnits};

{
if (count _units == 0) exitWith {};
private _building = _x;
private _class = typeOf _building;
private _buildingPositions = [];
private _unitsPlaced = 0;

if (_class in PATCOM_Garrison_Positions) then {
// Check to see if building is in whitelist first for better unit positions.
if (_class in PATCOM_Garrison_Positions_Whitelist) then {
{
private _buildingPos = _building buildingPos _x;
if !(_buildingPos isEqualTo [0,0,0]) then {
_buildingPositions pushBack _buildingPos;
};
} forEach (PATCOM_Garrison_Positions get _class);
_buildingPositions pushBack (_building buildingPos _x);
} forEach (PATCOM_Garrison_Positions_Whitelist get _class);
} else {
// If no pre-defined building positions are found. We default to a random one.
_buildingPositions = _building buildingPos -1;
};

// Mix up the building positions for better randomization.
_buildingPositions = _buildingPositions call BIS_fnc_arrayShuffle;

{
if (count _units == 0) exitWith {};
private _unit = _units select 0;
private _position = _x;
_unit setposATL _position;
// Exit if no more units are available to be placed.
if (count _units == 0) exitWith {
Trace("PATCOM | No more garrison units available to place. Exiting");
};

// Exit if we have already placed max amount of units in building.
if (_unitsPlaced >= _unitsPerBuilding) exitWith {
Trace("PATCOM | Max garrison units placed in building. Moving to next building");
};

// Move to next position if current one is invalid.
if (_x isEqualTo [0,0,0]) then {
Debug_1("PATCOM | Position invalid in (%1), moving to next position", _class);
continue;
};

// Continue to next building position if current position is too close to a static weapon.
if ((count (_x nearEntities ["StaticWeapon", 3])) > 0) then {
Debug_1("PATCOM | Position (%1) too close to StaticWeapon, moving to next position.", _x);
continue;
};

// Move the unit and set them up in position.
private _unit = _units deleteAt 0;
_unit setPosATL _x;
_unit setdir ((_unit getRelDir _building)-180);
_unit disableAI "PATH";
_unit setUnitPos "UP";

dostop _unit;

// Add 1 to unit placed counter for max units per building limit. (_minimumUnits)
_unitsPlaced = _unitsPlaced + 1;

_units deleteAt 0;
} foreach _buildingPositions;
} forEach _buildingPositions;
} forEach _buildings;

// Splits Garrison AI into an additional defense group if not enough buildings/positions were found.
// Splits Garrison AI into additional defense groups if not enough buildings/positions were found.
if (count _units > 0) then {
private _groupSplit = createGroup (side _group);
_newGroups pushBack _groupSplit;
Expand Down
2 changes: 1 addition & 1 deletion A3A/addons/patcom/functions/Patcom/fn_patrolInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ PATCOM_Building_Blacklist = createHashMap;
} forEach A3A_buildingBlacklist;

// This HashMap contains a list of valid garrison positions.
PATCOM_Garrison_Positions = createHashMapFromArray [
PATCOM_Garrison_Positions_Whitelist = createHashMapFromArray [
["Land_Cargo_HQ_V1_F", [6,7,8]],
["Land_Cargo_HQ_V2_F", [6,7,8]],
["Land_Cargo_HQ_V3_F", [6,7,8]],
Expand Down