Skip to content

Commit

Permalink
add loadbalancer for spawning units
Browse files Browse the repository at this point in the history
  • Loading branch information
theace0296 committed Apr 3, 2022
1 parent ddce139 commit c57e952
Show file tree
Hide file tree
Showing 41 changed files with 177 additions and 85 deletions.
24 changes: 12 additions & 12 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"matthewthorning.align-vertically",
"me-dutour-mathieu.vscode-github-actions",
"github.vscode-pull-request-github",
"eamodio.gitlens",
"billw2011.sqf-debugger",
// See https://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"matthewthorning.align-vertically",
"me-dutour-mathieu.vscode-github-actions",
"github.vscode-pull-request-github",
"eamodio.gitlens",
"billw2011.sqf-debugger",
"smith.sqf-formatter",
"armitxes.sqf",
"armitxes.sqf",
"eelislynne.sqf-wiki",
"senfo.sqflint",
"redhat.vscode-yaml"
]
"senfo.sqflint",
"redhat.vscode-yaml"
]
}
4 changes: 3 additions & 1 deletion RandFramework/Global/common/fn_createConvoy.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ params [
if (isNil "_side" || isNil "_vehicles" || isNil "_startPos" || isNil "_endPos") exitWith {};

private _finalGroup = [];
private _group = creategroup _side;
private _group = (createGroup [_side, true]);
_group setFormation "FILE";
_group setSpeedMode "LIMITED";

Expand Down Expand Up @@ -193,6 +193,8 @@ if (_disableAIMods) then {
_x allowDamage true;
} forEach _finalGroup;

[_group] call TRGM_GLOBAL_fnc_loadbalancer_setGroupOwner;

if (!_noWaypoints) then {
[_group, _convoySpeed, _convoySeparation, _pushThrough] spawn TRGM_GLOBAL_fnc_convoy;
};
Expand Down
2 changes: 1 addition & 1 deletion RandFramework/Global/common/fn_createUnit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ if !(_unitType isEqualTo "") then {
private _unit = _group createUnit [_tempUnitType, _position, _markers, _placement, _special];
if !(_type isEqualTo _tempUnitType) then {
[_unit, _type] call TRGM_GLOBAL_fnc_setLoadout;
private _tempUnit = (createGroup CIVILIAN) createUnit [_type, [0,0,0], [], 0, 'NONE'];
private _tempUnit = ((createGroup [CIVILIAN, true])) createUnit [_type, [0,0,0], [], 0, 'NONE'];
private _speaker = speaker _tempUnit;
private _face = face _tempUnit;
private _pitch = pitch _tempUnit;
Expand Down
4 changes: 3 additions & 1 deletion RandFramework/Global/common/fn_createVehicleCrew.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ private ["_group", "_side"];

if (_sideOrGroup isEqualType WEST) then {
_side = _sideOrGroup;
_group = createGroup _side;
_group = (createGroup [_side, true]);
} else {
_side = side _sideOrGroup;
_group = _sideOrGroup;
Expand Down Expand Up @@ -92,4 +92,6 @@ if (_sideOrGroup isEqualType WEST && {!((driver _vehicle) isEqualTo (leader _gro
[_group, driver _vehicle] remoteExec ["selectLeader", groupOwner _group];
};

[_group] call TRGM_GLOBAL_fnc_loadbalancer_setGroupOwner;

_crew;
2 changes: 1 addition & 1 deletion RandFramework/Global/common/fn_enemyAirSupport.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if !(isServer) exitWith {};
TRGM_VAR_CalledAirsupportIndex = TRGM_VAR_CalledAirsupportIndex + 1;
publicVariable "TRGM_VAR_CalledAirsupportIndex";

private _groupp1 = createGroup TRGM_VAR_EnemySide;
private _groupp1 = (createGroup [TRGM_VAR_EnemySide, true]);

private _AirVehicle = nil;
if (_IsAirType isEqualTo 1) then {
Expand Down
10 changes: 6 additions & 4 deletions RandFramework/Global/common/fn_reinforcements.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ if !(_noDelay) then {
};
};

private _heloCrew = createGroup _side;
private _heloCrew = (createGroup [_side, true]);

//set the scope of local variables that are defined in other scope(s), so they can be used over the entire script
private ["_helo","_infgrp"];
Expand All @@ -92,7 +92,7 @@ if (_debugMode) then {
//Side Check to spawn appropriate helicopter & cargo
switch (_side) do {
case WEST : {
_infgrp = createGroup WEST;
_infgrp = (createGroup [WEST, true]);

[_infgrp, (call fTeamleader), [0,0], [], 5, "NONE"] call TRGM_GLOBAL_fnc_createUnit; sleep(_AdditionalUnitCreationDelay);
[_infgrp, (call fGrenadier), [0,0], [], 5, "NONE"] call TRGM_GLOBAL_fnc_createUnit; sleep(_AdditionalUnitCreationDelay);
Expand All @@ -102,7 +102,7 @@ switch (_side) do {
_helo = createVehicle [(call ReinforceVehicleFriendly), _spawnMrk, [], 0, "FLY"];
};
case EAST : {
_infgrp = createGroup EAST;
_infgrp = (createGroup [EAST, true]);

[_infgrp, (call sTeamleader), [0,0], [], 5, "NONE"] call TRGM_GLOBAL_fnc_createUnit; sleep(_AdditionalUnitCreationDelay);
[_infgrp, (call sGrenadier), [0,0], [], 5, "NONE"] call TRGM_GLOBAL_fnc_createUnit; sleep(_AdditionalUnitCreationDelay);
Expand All @@ -112,7 +112,7 @@ switch (_side) do {
_helo = createVehicle [(call ReinforceVehicle), _spawnMrk, [], 0, "FLY"];
};
case INDEPENDENT : {
_infgrp = createGroup INDEPENDENT;
_infgrp = (createGroup [INDEPENDENT, true]);

[_infgrp, (call sTeamleaderMilitia), [0,0], [], 5, "NONE"] call TRGM_GLOBAL_fnc_createUnit; sleep(_AdditionalUnitCreationDelay);
[_infgrp, (call sGrenadierMilitia), [0,0], [], 5, "NONE"] call TRGM_GLOBAL_fnc_createUnit; sleep(_AdditionalUnitCreationDelay);
Expand All @@ -129,6 +129,8 @@ if (_debugMode) then {
player globalChat format ["Cargo Group: %1", _infGrp];
};

[_infGrp] call TRGM_GLOBAL_fnc_loadbalancer_setGroupOwner;

//Set the infantry groups skill levels (_skill is a 1 based index, so use _skill - 1 for selecting on a zero based index)
if (_skill > 4) then {_skill = 4;};
if (_skill < 1) then {_skill = 1;};
Expand Down
2 changes: 1 addition & 1 deletion RandFramework/Global/common/fn_supplyHelicopter.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ try {
case INDEPENDENT: { _airToUse = (call ReinforceVehicleMilitia); };
default {};
};
private _heloGroup = createGroup _side;
private _heloGroup = (createGroup [_side, true]);
private _airDropHelo = createVehicle [_airToUse, [(_spawnPos select 0), (_spawnPos select 1)], [], 0, "FLY"];

[_heloGroup, _airDropHelo, true] call TRGM_GLOBAL_fnc_createVehicleCrew;
Expand Down
10 changes: 10 additions & 0 deletions RandFramework/Global/loadbalancer/fn_loadbalancer_aggregate.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// private _fnc_scriptName = "TRGM_GLOBAL_fnc_loadbalancer_aggregate";
private _allHeadlessClients = entities "HeadlessClient_F";
private _allPlayers = allPlayers - _allHeadlessClients;

private _allHeadlessClientsWeighted = flatten (_allHeadlessClients apply {[owner _x, linearConversion [25, 60, _x getVariable ["TRGM_VAR_ClientFps", 0], 0, 1, true]]});
private _allPlayersWeighted = flatten (_allPlayers apply {[owner _x, linearConversion [25, 60, _x getVariable ["TRGM_VAR_ClientFps", 0], 0, 1, true]]});

// update arrays
missionNamespace setVariable ["TRGM_VAR_HC_FpsWeighted", _allHeadlessClientsWeighted];
missionNamespace setVariable ["TRGM_VAR_Players_FpsWeighted", _allPlayersWeighted];
7 changes: 7 additions & 0 deletions RandFramework/Global/loadbalancer/fn_loadbalancer_fpsLoop.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// private _fnc_scriptName = "TRGM_GLOBAL_fnc_loadbalancer_fpsLoop";
[] spawn {
if (player != player) exitWith {};
while {sleep 10; true} do {
[player, diag_fps] call TRGM_GLOBAL_fnc_loadbalancer_setFps;
};
};
8 changes: 8 additions & 0 deletions RandFramework/Global/loadbalancer/fn_loadbalancer_getHost.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// private _fnc_scriptName = "TRGM_GLOBAL_fnc_loadbalancer_getHost";
private _target = selectRandomWeighted (missionNamespace getVariable ["TRGM_VAR_HC_FpsWeighted", []]);
if (!isNil "_target") exitWith { _target };

_target = selectRandomWeighted (missionNamespace getVariable ["TRGM_VAR_Players_FpsWeighted", []]);
if (!isNil "_target") exitWith { _target };

2
6 changes: 6 additions & 0 deletions RandFramework/Global/loadbalancer/fn_loadbalancer_init.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// private _fnc_scriptName = "TRGM_GLOBAL_fnc_loadbalancer_init";
[] spawn {
while {sleep 10; true} do {
call TRGM_GLOBAL_fnc_loadbalancer_aggregate;
};
};
4 changes: 4 additions & 0 deletions RandFramework/Global/loadbalancer/fn_loadbalancer_setFps.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// private _fnc_scriptName = "TRGM_GLOBAL_fnc_loadbalancer_setFps";
params [["_player", objNull, [objNull]], ["_fps",0,[0]]];
if (isNull _player) exitWith {};
_player setVariable ["TRGM_VAR_ClientFps", _fps];
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// private _fnc_scriptName = "TRGM_GLOBAL_fnc_loadbalancer_setGroupOwner";
params [["_group", grpNull, [grpNull]]];
if (isNull _group) exitWith {};
if (({isPlayer _x} count units _group) > 0) exitWith {};
private _selectedClient = call TRGM_GLOBAL_fnc_loadbalancer_getHost;
_group setGroupOwner _selectedClient;
_group setVariable ["TRGM_VAR_groupClientOwner", _selectedClient];
{
_x addEventHandler ["Local", {
params ["_unit", "_isLocal"];
if (_isLocal) then {
group _unit setVariable ["TRGM_VAR_groupClientOwner", clientOwner, true];
};
}];
} forEach units _group;
4 changes: 2 additions & 2 deletions RandFramework/Missions/bombDisposalMission.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ MISSION_fnc_CustomMission = { //This function is the main script for your missio
},[_bombSerialNumber]]]; remoteExec ["addAction", 0, true];


_objInformant = [createGroup Civilian, selectRandom InformantClasses,[-200,-200,0],[],0,"NONE", true] call TRGM_GLOBAL_fnc_createUnit;
_objInformant = [(createGroup [Civilian, true]), selectRandom InformantClasses,[-200,-200,0],[],0,"NONE", true] call TRGM_GLOBAL_fnc_createUnit;
if (isNil "_objInformant" || {isNull _objInformant}) then {
private _iterations = 0;
while {(isNil "_objInformant" || {isNull _objInformant}) && {_iterations < 20}} do {
_objInformant = [createGroup Civilian, selectRandom InformantClasses,[-200,-200,0],[],0,"NONE", true] call TRGM_GLOBAL_fnc_createUnit;
_objInformant = [(createGroup [Civilian, true]), selectRandom InformantClasses,[-200,-200,0],[],0,"NONE", true] call TRGM_GLOBAL_fnc_createUnit;
_iterations = _iterations + 1;
};
};
Expand Down
6 changes: 3 additions & 3 deletions RandFramework/Missions/hvtMission.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ MISSION_fnc_CustomMission = { //This function is the main script for your missio

_sInformant1Name = format["objInformant%1",_iTaskIndex];

_objInformant = [createGroup _sideToUse, _infClassToUse, [0,0,500], [], 0, "NONE", true] call TRGM_GLOBAL_fnc_createUnit;
_objInformant = [(createGroup [_sideToUse, true]), _infClassToUse, [0,0,500], [], 0, "NONE", true] call TRGM_GLOBAL_fnc_createUnit;

if (isNil "_objInformant" || {isNull _objInformant}) then {
private _iterations = 0;
while {(isNil "_objInformant" || {isNull _objInformant}) && {_iterations < 20}} do {
_objInformant = [createGroup _sideToUse, _infClassToUse, [0,0,500], [], 0, "NONE", true] call TRGM_GLOBAL_fnc_createUnit;
_objInformant = [(createGroup [_sideToUse, true]), _infClassToUse, [0,0,500], [], 0, "NONE", true] call TRGM_GLOBAL_fnc_createUnit;
_iterations = _iterations + 1;
};
};
Expand Down Expand Up @@ -151,7 +151,7 @@ MISSION_fnc_CustomMission = { //This function is the main script for your missio

if (_hvtType isEqualTo "INTERROGATE" || _hvtType isEqualTo "KILL") then { //if interrogate or kill task
if (_sideToUse isEqualTo TRGM_VAR_EnemySide) then { //only give weapon if enemy side unit
_grpName = createGroup TRGM_VAR_EnemySide;
_grpName = (createGroup [TRGM_VAR_EnemySide, true]);
[_objInformant] joinSilent _grpName;
_objInformant addMagazine "30Rnd_9x21_Mag_SMG_02";
_objInformant addMagazine "30Rnd_9x21_Mag_SMG_02";
Expand Down
10 changes: 5 additions & 5 deletions RandFramework/Missions/meetingAssassinationMission.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,23 @@ MISSION_fnc_CustomMission = { //This function is the main script for your missio
if (!isNil "_direction") then {
_objVehicle setDir (_direction);
};
_guardUnit1 = [(createGroup TRGM_VAR_EnemySide), selectRandom _HVTGuys,_poshVehPos,[],0,"NONE", true] call TRGM_GLOBAL_fnc_createUnit;
_guardUnit1 = [((createGroup [TRGM_VAR_EnemySide, true])), selectRandom _HVTGuys,_poshVehPos,[],0,"NONE", true] call TRGM_GLOBAL_fnc_createUnit;
}
else {
_flatPos = nil;
_flatPos = [getPos _objectiveMainBuilding, 10, 50, 5, 0, 0.5, 0,[],[getPos _objectiveMainBuilding,getPos _objectiveMainBuilding]] call TRGM_GLOBAL_fnc_findSafePos;
if ((_flatPos select 0) > 0) then {
_guardUnit1 = [(createGroup TRGM_VAR_EnemySide), selectRandom _HVTGuys,_flatPos,[],0,"NONE", true] call TRGM_GLOBAL_fnc_createUnit;
_guardUnit1 = [((createGroup [TRGM_VAR_EnemySide, true])), selectRandom _HVTGuys,_flatPos,[],0,"NONE", true] call TRGM_GLOBAL_fnc_createUnit;
}
else {
_guardUnit1 = [(createGroup TRGM_VAR_EnemySide), selectRandom _HVTGuys,getPos _objectiveMainBuilding,[],20,"NONE", true] call TRGM_GLOBAL_fnc_createUnit;
_guardUnit1 = [((createGroup [TRGM_VAR_EnemySide, true])), selectRandom _HVTGuys,getPos _objectiveMainBuilding,[],20,"NONE", true] call TRGM_GLOBAL_fnc_createUnit;
};
};
(group _guardUnit1) setBehaviour 'CARELESS';
_guardUnit1 setCaptive true;

_hvtGroup = createGroup TRGM_VAR_EnemySide;
_hvtGuardGroup = createGroup TRGM_VAR_EnemySide;
_hvtGroup = (createGroup [TRGM_VAR_EnemySide, true]);
_hvtGuardGroup = (createGroup [TRGM_VAR_EnemySide, true]);

_mainHVT = [_hvtGroup, _mainHVTClass,[-500,-500,0],[],20,"NONE", true] call TRGM_GLOBAL_fnc_createUnit;
sleep 0.1;
Expand Down
Loading

0 comments on commit c57e952

Please sign in to comment.