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

v0.96.8 AA turrets #838

Open
wants to merge 10 commits into
base: v0.96.8
Choose a base branch
from
1 change: 1 addition & 0 deletions Missionframework/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class KPLIB {
class getOpforCap {};
class getOpforFactor {};
class getOpforSpawnPoint {};
class getOpforAASpawnPoint {};
Wyqer marked this conversation as resolved.
Show resolved Hide resolved
class getPlayerCount {};
class getResistanceTier {};
class getSaveableParam {};
Expand Down
7 changes: 7 additions & 0 deletions Missionframework/presets/enemies/apex.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,10 @@ KPLIB_o_planes = [
"O_Plane_CAS_02_dynamicLoadout_F", // To-199 Neophron (CAS)
"O_Plane_Fighter_02_F" // To-201 Shikra
];

// Enemy AA turrets that will be spawned in the backland
KPLIB_o_AA_Turrets = [
Wyqer marked this conversation as resolved.
Show resolved Hide resolved
"B_SAM_System_01_F",
"B_SAM_System_02_F",
["O_SAM_System_04_F", "O_Radar_System_02_F"]
];
7 changes: 7 additions & 0 deletions Missionframework/presets/enemies/custom.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,10 @@ KPLIB_o_planes = [
"O_Plane_CAS_02_dynamicLoadout_F", // To-199 Neophron (CAS)
"O_Plane_Fighter_02_F" // To-201 Shikra
];

// Enemy AA turrets that will be spawned in the backland
KPLIB_o_AA_Turrets = [
"B_SAM_System_01_F",
"B_SAM_System_02_F",
["O_SAM_System_04_F", "O_Radar_System_02_F"]
];
88 changes: 88 additions & 0 deletions Missionframework/scripts/server/ai/AA_turret_manager.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
waitUntil {!isNil "save_is_loaded"};
Wyqer marked this conversation as resolved.
Show resolved Hide resolved
waitUntil {!isNil "GRLIB_vehicle_to_military_base_links"};
Wyqer marked this conversation as resolved.
Show resolved Hide resolved
waitUntil {!isNil "blufor_sectors"};
Wyqer marked this conversation as resolved.
Show resolved Hide resolved
waitUntil {save_is_loaded};
Wyqer marked this conversation as resolved.
Show resolved Hide resolved

if (GRLIB_difficulty_modifier == 0) exitWith {}; // no AA turrets on easiest difficulty level
Wyqer marked this conversation as resolved.
Show resolved Hide resolved
if (isNil "KPLIB_o_AA_Turrets") exitWith {}; // leave, if there are no AA turrets defined in currently played preset
private _AA_Killed_Turrets = 0; // counter of killed AA turrets
Wyqer marked this conversation as resolved.
Show resolved Hide resolved
if (isNil "AA_used_positions") then {AA_used_positions = []}; // define array containing all currently used positions
if (isNil "AA_backland_turrets") then {AA_backland_turrets = []}; // define array containing all turrets corresponding to a used position
Wyqer marked this conversation as resolved.
Show resolved Hide resolved

while {GRLIB_endgame == 0} do {
Wyqer marked this conversation as resolved.
Show resolved Hide resolved
private _sleeptime = (1800 + (random 1800)) / (([] call KPLIB_fnc_getOpforFactor) * GRLIB_csat_aggressivity);
Wyqer marked this conversation as resolved.
Show resolved Hide resolved

if (combat_readiness >= 80) then {_sleeptime = _sleeptime * 0.75};
if (combat_readiness >= 90) then {_sleeptime = _sleeptime * 0.75};
if (combat_readiness >= 95) then {_sleeptime = _sleeptime * 0.75};
Wyqer marked this conversation as resolved.
Show resolved Hide resolved
sleep _sleeptime;

// Check and clear turret array for any destroyed or unmanned units
private _turret = objNull;
{
if (typeName _x == "ARRAY") then {
Wyqer marked this conversation as resolved.
Show resolved Hide resolved
_turret = _x select 0; // in case turret is an array, choose first element of array as turret
Wyqer marked this conversation as resolved.
Show resolved Hide resolved
} else {
_turret = _x;
};
if (!alive _turret || !alive gunner _turret) then {
Wyqer marked this conversation as resolved.
Show resolved Hide resolved
if (typeName _x == "ARRAY") then {
Wyqer marked this conversation as resolved.
Show resolved Hide resolved
{
if (alive _x) then {_x setDamage 1};
} forEach _x;
};
AA_backland_turrets deleteAt _forEachIndex; // delete any destroyed or unmanned AA turret from turret array
AA_used_positions deleteAt _forEachIndex; // delete corresponding position from used positions array
_AA_Killed_Turrets = _AA_Killed_Turrets + 1; // raise kill counter
};
} forEach AA_backland_turrets;

// If AA turrets were destroyed, add a 'punishment' time for the enemy. This extra time is ment to be a dampening of the production of AA turrets
if (_AA_Killed_Turrets > 0) then {
_sleeptime = _sleeptime * _AA_Killed_Turrets;
sleep _sleeptime; // killing AA turrets 'damps' placement of further turrets
Wyqer marked this conversation as resolved.
Show resolved Hide resolved
_AA_Killed_Turrets = 0; // reset kill counter after performing 'damp' sleep
};

// Calculate maximum amount of AA turrets
private _maxAAnumber = round (GRLIB_difficulty_modifier * 2);
Wyqer marked this conversation as resolved.
Show resolved Hide resolved
if (_maxAAnumber > 12) then {_maxAAnumber = 12};
if (combat_readiness > 0 && _maxAAnumber > 0) then {
Wyqer marked this conversation as resolved.
Show resolved Hide resolved
_maxAAnumber = _maxAAnumber * round (combat_readiness / 30);
if (_maxAAnumber > 20) then {_maxAAnumber = 20};
if (_maxAAnumber > (count sectors_allSectors - count blufor_sectors)) then {_maxAAnumber = count sectors_allSectors - count blufor_sectors}; // maximum amount of AA turrets should not exceed number of opfor sectors
Wyqer marked this conversation as resolved.
Show resolved Hide resolved
};

// If maximum amount of AA turrets has not been reached yet, add one to the map
if (count AA_backland_turrets < _maxAAnumber) then {
private _spawn_marker = [] call KPLIB_fnc_getOpforAASpawnPoint; // get a sector for spawning an AA turret
if (_spawn_marker == "") exitWith {diag_log formatText ["%1%2", time, "s (AA_turret_manager) _spawn_marker: Could not find AA position"];};
Wyqer marked this conversation as resolved.
Show resolved Hide resolved
private _rndTurret = selectRandom KPLIB_o_AA_Turrets; // choose an opfor turret to be spawned

// The lower the difficulty level is, the less it is likely to have 'heavy' AA defenses
if (GRLIB_difficulty_modifier < 4 && typeName _rndTurret == "ARRAY") then {
Wyqer marked this conversation as resolved.
Show resolved Hide resolved
private _i = 4 - GRLIB_difficulty_modifier;
while {typeName _rndTurret == "ARRAY" && _i > 0} do {
_rndTurret = selectRandom KPLIB_o_AA_Turrets;
_i = _i - 1;
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(with deprecated variable)

for "_i" from 1 to (4-GRLIB_difficulty_modifier) do {_rndTurret = selectRandom KPLIB_o_AA_Turrests;};

};

private _vehicle = objNull;
AA_used_positions pushBack _spawn_marker;
if (typeName _rndTurret == "ARRAY") exitWith {
private _group = createGroup [GRLIB_side_enemy, true];
Wyqer marked this conversation as resolved.
Show resolved Hide resolved
private _groupVehicles = [];
{
_vehicle = [markerpos _spawn_marker, _x] call KPLIB_fnc_spawnVehicle;
_groupVehicles pushBack _vehicle;
[_vehicle] joinSilent _group;
Wyqer marked this conversation as resolved.
Show resolved Hide resolved
} forEach _rndTurret;
AA_backland_turrets pushBack _groupVehicles;
_group setBehaviour "AWARE";
};
private _vehicle = [markerpos _spawn_marker, _rndTurret] call KPLIB_fnc_spawnVehicle;
AA_backland_turrets pushBack _vehicle;
Wyqer marked this conversation as resolved.
Show resolved Hide resolved
_vehicle setBehaviour "AWARE";
Wyqer marked this conversation as resolved.
Show resolved Hide resolved
};
};
3 changes: 3 additions & 0 deletions Missionframework/scripts/server/init_server.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,6 @@ execVM "scripts\server\offloading\group_diag.sqf";
if (KPLIB_param_restart > 0) then {
execVM "scripts\server\game\server_restart.sqf";
};

// AA turret manager
execVM "scripts\server\ai\AA_turret_manager.sqf";