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

Battle Group Spawning + AI #942

Merged
merged 9 commits into from
Mar 15, 2024
1 change: 1 addition & 0 deletions Missionframework/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class KPLIB {
class isCapitalActive {};
class isClassUAV {};
class isRadio {};
class lambs_enableReinforcements{};
class log {};
class potatoScan {};
class protectObject {};
Expand Down
27 changes: 27 additions & 0 deletions Missionframework/functions/fn_LAMBS_enableReinforcements.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
File: fn_LAMBS_enableReinforcements.sqf
Author: Jenna
Date: 2023-10-21
Last Update: 2023-10-21
License: MIT License - http://www.opensource.org/licenses/MIT

Description:
Enables LAMBS reinforcements + radio on a given group

Parameter(s):
_grp - Group to enable features on [Group, defaults to grpNull]

Returns:
Nothing
*/

params [
["_grp", grpNull, [grpNull]]
];

if (isNull _grp) exitwith {
["Attempted to set LAMBS Reinforcements on null group.", "ERROR"] remoteExecCall ["KPLIB_fnc_log", 2];
};

(leader _grp) setVariable ["lambs_danger_dangerRadio", true, true];
_grp setVariable ["lambs_danger_enableGroupReinforce", true, true];
5 changes: 2 additions & 3 deletions Missionframework/functions/fn_spawnVehicle.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ params [

if (_pos isEqualTo [0, 0, 0]) exitWith {["No or zero pos given"] call BIS_fnc_error; objNull};
if (_classname isEqualTo "") exitWith {["Empty string given"] call BIS_fnc_error; objNull};
if (!canSuspend) exitWith {_this spawn KPLIB_fnc_spawnVehicle};


private _newvehicle = objNull;
private _spawnpos = [];
Expand All @@ -41,7 +41,7 @@ if (_precise) then {
while {_spawnPos isEqualTo []} do {
_i = _i + 1;
_spawnpos = (_pos getPos [random 150, random 360]) findEmptyPosition [10, 100, _classname];
if (_i isEqualTo 10) exitWith {};
if (_i isEqualTo 10) exitWith {_spawnPos = zeroPos};
};
};

Expand Down Expand Up @@ -83,7 +83,6 @@ if (_classname in KPLIB_o_militiaVehicles) then {
private _grp = createGroup [KPLIB_side_enemy, true];
private _crew = units (createVehicleCrew _newvehicle);
_crew joinSilent _grp;
sleep 0.1;
{
_x addMPEventHandler ["MPKilled", {
params ["_unit", "_killer"];
Expand Down
59 changes: 19 additions & 40 deletions Missionframework/scripts/server/ai/battlegroup_ai.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,30 @@ params [
];

if (isNull _grp) exitWith {};
if (isNil "reset_battlegroups_ai") then {reset_battlegroups_ai = false};

sleep (5 + (random 5));

private _objPos = [getPos (leader _grp)] call KPLIB_fnc_getNearestBluforObjective;

[_objPos] remoteExec ["remote_call_incoming"];

private _startpos = getPos (leader _grp);


private _waypoint = [];
while {((getPos (leader _grp)) distance _startpos) < 100} do {

while {!((waypoints _grp) isEqualTo [])} do {deleteWaypoint ((waypoints _grp) select 0);};
{_x doFollow leader _grp} forEach units _grp;

_startpos = getPos (leader _grp);

_waypoint = _grp addWaypoint [_objPos, 100];
_waypoint setWaypointType "MOVE";
_waypoint setWaypointSpeed "NORMAL";
_waypoint setWaypointBehaviour "AWARE";
_waypoint setWaypointCombatMode "YELLOW";
_waypoint setWaypointCompletionRadius 30;

_waypoint = _grp addWaypoint [_objPos, 100];
_waypoint setWaypointType "SAD";
_waypoint = _grp addWaypoint [_objPos, 100];
_waypoint setWaypointType "SAD";
_waypoint = _grp addWaypoint [_objPos, 100];
_waypoint setWaypointType "SAD";
_waypoint = _grp addWaypoint [_objPos, 100];
_waypoint setWaypointType "CYCLE";

sleep 90;
};

waitUntil {
sleep 5;
(((units _grp) select {alive _x}) isEqualTo []) || reset_battlegroups_ai
};

sleep (5 + (random 5));
reset_battlegroups_ai = false;

if (!((units _grp) isEqualTo []) && (KPLIB_endgame == 0)) then {
[_grp] spawn battlegroup_ai;
};
{ deleteWaypoint _x } forEachReversed waypoints _grp;
{_x doFollow leader _grp} forEach units _grp;

_waypoint = _grp addWaypoint [_objPos, 100];
_waypoint setWaypointType "MOVE";
_waypoint setWaypointSpeed "NORMAL";
_waypoint setWaypointBehaviour "AWARE";
_waypoint setWaypointCombatMode "YELLOW";
_waypoint setWaypointCompletionRadius 30;

_waypoint = _grp addWaypoint [_objPos, 100];
_waypoint setWaypointType "SAD";
_waypoint = _grp addWaypoint [_objPos, 100];
_waypoint setWaypointType "SAD";
_waypoint = _grp addWaypoint [_objPos, 100];
_waypoint setWaypointType "SAD";
_waypoint = _grp addWaypoint [_objPos, 100];
_waypoint setWaypointType "CYCLE";
21 changes: 11 additions & 10 deletions Missionframework/scripts/server/battlegroup/spawn_battlegroup.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ if !(_spawn_marker isEqualTo "") then {

// Adjust target size for infantry
_target_size = 12 max (_target_size * 4);
private _squadNumber = round (_target_size/8);

// Create infantry groups with up to 8 units per squad
private _grp = createGroup [KPLIB_side_enemy, true];
for "_i" from 0 to (_target_size - 1) do {
if (_i > 0 && {(_i % 8) isEqualTo 0}) then {
_bg_groups pushBack _grp;
_grp = createGroup [KPLIB_side_enemy, true];
for "_i" from 1 to _squadNumber do {
// Create infantry groups with up to 8 units per squad
private _grp = createGroup [KPLIB_side_enemy, true];
for "_i" from 0 to 7 do {
[selectRandom _infClasses, markerPos _spawn_marker, _grp] call KPLIB_fnc_createManagedUnit;
};
[selectRandom _infClasses, markerPos _spawn_marker, _grp] call KPLIB_fnc_createManagedUnit;
[_grp] call KPLIB_fnc_LAMBS_enableReinforcements;
[_grp] call battlegroup_ai;
_grp setVariable ["KPLIB_isBattleGroup",true];
};
[_grp] spawn battlegroup_ai;
_bg_groups pushBack _grp;
} else {
private _vehicle_pool = [KPLIB_o_battleGrpVehicles, KPLIB_o_battleGrpVehiclesLight] select (KPLIB_enemyReadiness < 50);

Expand All @@ -55,7 +55,8 @@ if !(_spawn_marker isEqualTo "") then {
sleep 0.5;

(crew _vehicle) joinSilent _nextgrp;
[_nextgrp] spawn battlegroup_ai;
[_nextgrp] call battlegroup_ai;
_nextgrp setVariable ["KPLIB_isBattleGroup", true];
_bg_groups pushback _nextgrp;

some-evil-kitty marked this conversation as resolved.
Show resolved Hide resolved
if ((_x in KPLIB_o_troopTransports) && ([] call KPLIB_fnc_getOpforCap < KPLIB_cap_battlegroup)) then {
Expand Down
8 changes: 8 additions & 0 deletions Missionframework/scripts/server/init_server.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,11 @@ execVM "scripts\server\offloading\group_diag.sqf";
if (KPLIB_param_restart > 0) then {
execVM "scripts\server\game\server_restart.sqf";
};

["KPLIB_ResetBattleGroups", {
{
if (_x getVariable ["KPLIB_isBattleGroup", false]) then {
[_x] call battlegroup_ai;
}
} foreach allGroups;
}] call CBA_fnc_addEventHandler;
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ stats_readiness_earned = stats_readiness_earned + _KPLIB_enemyReadiness_increase
KPLIB_sectors_player pushback _liberated_sector; publicVariable "KPLIB_sectors_player";
stats_sectors_liberated = stats_sectors_liberated + 1;

reset_battlegroups_ai = true; publicVariable "reset_battlegroups_ai";
["KPLIB_ResetBattleGroups"] call CBA_fnc_serverEvent;

if (_liberated_sector in KPLIB_sectors_factory) then {
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ if ( KPLIB_endgame == 0 ) then {
sleep 3;
KPLIB_sectors_fob = KPLIB_sectors_fob - [_thispos];
publicVariable "KPLIB_sectors_fob";
reset_battlegroups_ai = true;
["KPLIB_ResetBattleGroups"] call CBA_fnc_serverEvent;
[_thispos] call KPLIB_fnc_destroyFob;
[] spawn KPLIB_fnc_doSave;
stats_fobs_lost = stats_fobs_lost + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ if ( KPLIB_endgame == 0 ) then {
KPLIB_sectors_player = KPLIB_sectors_player - [ _sector ];
publicVariable "KPLIB_sectors_player";
[_sector, 2] remoteExec ["remote_call_sector"];
reset_battlegroups_ai = true;
["KPLIB_ResetBattleGroups"] call CBA_fnc_serverEvent;
[] spawn KPLIB_fnc_doSave;
stats_sectors_lost = stats_sectors_lost + 1;
{
Expand Down