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

Add Dynamic AI Group Tranferring to Headless Clients #3107

Merged
merged 4 commits into from
Feb 4, 2016
Merged
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
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ Robert Boklahánics <bokirobi@gmail.com>
ruPaladin <happyworm24@rambler.ru>
simon84 <badguy360th@gmail.com>
Sniperwolf572 <tenga6@gmail.com>
System98
SzwedzikPL <szwedzikpl@gmail.com>
Tachi <zaveruha007@gmail.com>
Toaster <jonathan.pereira@gmail.com>
Expand Down
1 change: 1 addition & 0 deletions addons/headless/$PBOPREFIX$
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
z\ace\addons\headless
20 changes: 20 additions & 0 deletions addons/headless/ACE_Settings.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class ACE_Settings {
class GVAR(Enabled) {
value = 0;
typeName = "BOOL";
displayName = ECSTRING(common,Enabled);
description = CSTRING(EnabledDesc);
};
class GVAR(Delay) {
value = DELAY_DEFAULT;
typeName = "SCALAR";
displayName = CSTRING(Delay);
description = CSTRING(DelayDesc);
};
class GVAR(Log) {
value = 0;
typeName = "BOOL";
displayName = CSTRING(Log);
description = CSTRING(LogDesc);
};
};
19 changes: 19 additions & 0 deletions addons/headless/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Extended_PreInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preInit));
};
};

class Extended_PostInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_postInit));
};
};

class Extended_InitPost_EventHandlers {
class AllVehicles {
class ADDON {
serverInit = QUOTE(_this call FUNC(handleInitPost));
};
};
};
37 changes: 37 additions & 0 deletions addons/headless/CfgVehicles.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class CfgVehicles {
class ACE_Module;
class GVAR(module): ACE_Module {
author = ECSTRING(common,ACETeam);
category = "ACE_missionModules";
displayName = CSTRING(Module);
function = QFUNC(moduleInit);
scope = 2;
isGlobal = 1; // Global
isTriggerActivated = 0;
isDisposable = 0;
icon = QUOTE(PATHTOF(UI\Icon_Module_Headless_ca.paa));
class Arguments {
class Enabled {
displayName = ECSTRING(common,Enabled);
description = CSTRING(EnabledDesc);
typeName = "BOOL";
defaultValue = 0;
};
class Delay {
displayName = CSTRING(Delay);
description = CSTRING(DelayDesc);
typeName = "NUMBER";
defaultValue = DELAY_DEFAULT;
};
class Log {
displayName = CSTRING(Log);
description = CSTRING(LogDesc);
typeName = "BOOL";
defaultValue = 0;
};
};
class ModuleDescription {
description = CSTRING(ModuleDesc);
};
};
};
16 changes: 16 additions & 0 deletions addons/headless/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ace_headless
============

Adds automatic passing of AI groups to (up to 3) Headless Clients.
- Automatic Headless Client recognition
- Event-based transferring (on unit spawn, Headless Client connect and disconnect)
- Round-robin transferring when more than 1 Headless Client is present
- Mission makers can use the following to prevent a group from transferring to a Headless Client:
`this setVariable ["ace_headless_blacklist", true, true];`


## Maintainers

The people responsible for merging changes to this component or answering potential questions.

- [Jonpas](http://github.com/jonpas)
Binary file added addons/headless/UI/Icon_Module_Headless_ca.paa
Binary file not shown.
16 changes: 16 additions & 0 deletions addons/headless/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "script_component.hpp"

// Exit on player clients that are not hosts
if (hasInterface && !isServer) exitWith {};

["SettingsInitialized", {
if (isServer) then {
// Add disconnect EH if HC transferring enabled
if (GVAR(Enabled)) then {
addMissionEventHandler ["HandleDisconnect", {_this call FUNC(handleDisconnect)}];
};
} else {
// Register HC (this part happens on HC only)
["ACE_HeadlessClientJoined", [player]] call EFUNC(common,globalEvent);
};
}] call EFUNC(common,addEventHandler);
18 changes: 18 additions & 0 deletions addons/headless/XEH_preInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "script_component.hpp"

ADDON = false;

PREP(handleConnectHC);
PREP(handleDisconnect);
PREP(handleInitPost);
PREP(moduleInit);
PREP(rebalance);
PREP(transferGroups);

if (isServer) then {
GVAR(headlessClients) = [];
GVAR(inRebalance) = false;
["ACE_HeadlessClientJoined", FUNC(handleConnectHC)] call EFUNC(common,addEventHandler);
};

ADDON = true;
17 changes: 17 additions & 0 deletions addons/headless/config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "script_component.hpp"

class CfgPatches {
class ADDON {
units[] = {};
weapons[] = {};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {"ace_common"};
author[]= {"Jonpas"};
authorUrl = "https://github.com/jonpas";
VERSION_CONFIG;
};
};

#include "ACE_Settings.hpp"
#include "CfgEventHandlers.hpp"
#include "CfgVehicles.hpp"
36 changes: 36 additions & 0 deletions addons/headless/functions/fnc_handleConnectHC.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Author: Jonpas
* Registers connected Headless Client for use.
*
* Arguments:
* 0: Headless Client <OBJECT>
*
* Return Value:
* None
*
* Example:
* [headlessClient] call ace_headless_handleConnectHC;
*
* Public: No
*/
#include "script_component.hpp"

params ["_headlessClient"];

// Delay until settings are initialized (for checking if HC trasnferring is enabled)
if (!EGVAR(common,settingsInitFinished)) exitWith {
EGVAR(common,runAtSettingsInitialized) pushBack [FUNC(handleConnectHC), _this];
};

// Exit if HC transferring disabled or HC already registered
if (!GVAR(Enabled) || {_headlessClient in GVAR(headlessClients)}) exitWith {};

// Register for use
GVAR(headlessClients) pushBack _headlessClient;

if (GVAR(Log)) then {
ACE_LOGINFO_1("Registered HC: %1",_headlessClient);
};

// Rebalance
[true] call FUNC(rebalance);
34 changes: 34 additions & 0 deletions addons/headless/functions/fnc_handleDisconnect.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Author: Jonpas
* Removes Headless Client from use.
*
* Arguments:
* 0: Object <OBJECT>
*
* Return Value:
* Transfer To Server <BOOL>
*
* Example:
* [unit] call ace_headless_handleDisconnect;
*
* Public: No
*/
#include "script_component.hpp"

params ["_object"];

// Exit if not HC
if !(_object in GVAR(headlessClients)) exitWith {};

// Remove HC
GVAR(headlessClients) deleteAt (GVAR(headlessClients) find _object);

if (GVAR(Log)) then {
ACE_LOGINFO_1("Removed HC: %1",_object);
};

// Rebalance
[true] call FUNC(rebalance);

// Prevent transferring of HC to server
false
31 changes: 31 additions & 0 deletions addons/headless/functions/fnc_handleInitPost.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Author: Jonpas
* Request a rebalance.
*
* Arguments:
* 0: Object <OBJECT>
*
* Return Value:
* None
*
* Example:
* [object] call ace_headless_handleInitPost;
*
* Public: No
*/
#include "script_component.hpp"

params ["_object"];

TRACE_1("InitPost",_object);

// Delay until settings are initialized (for checking if HC trasnferring is enabled)
if (!EGVAR(common,settingsInitFinished)) exitWith {
EGVAR(common,runAtSettingsInitialized) pushBack [FUNC(handleInitPost), _this];
};

// Exit if HC transferring disabled or object not a unit (including unit inside vehicle) or is player
if (!GVAR(Enabled) || {!(_object in allUnits)} || {isPlayer _object}) exitWith {};
Copy link
Member Author

Choose a reason for hiding this comment

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

Apparently isPlayer check always returns false at this stage on dedicated server, making it rebalance on player connect as well, not sure if there is a better way to handle that?


// Rebalance
[false] call FUNC(rebalance);
27 changes: 27 additions & 0 deletions addons/headless/functions/fnc_moduleInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Author: Jonpas
* Initializes the Headless module.
*
* Arguments:
* 0: The module logic <LOGIC>
* 1: Units <ARRAY> (Unused)
* 2: Activated <BOOL>
*
* Return Value:
* None
*
* Public: No
*/
#include "script_component.hpp"

if (!isServer) exitWith {};

params ["_logic", "", "_activated"];

if (!_activated) exitWith {};

[_logic, QGVAR(Enabled), "Enabled"] call EFUNC(common,readSettingFromModule);
[_logic, QGVAR(Delay), "Delay"] call EFUNC(common,readSettingFromModule);
[_logic, QGVAR(Log), "Log"] call EFUNC(common,readSettingFromModule);

ACE_LOGINFO("Headless Module Initialized.");
29 changes: 29 additions & 0 deletions addons/headless/functions/fnc_rebalance.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Author: Jonpas
* Rebalance AI groups accross HCs.
*
* Arguments:
* 0: Force <BOOL>
*
* Return Value:
* None
*
* Example:
* [false] call ace_headless_rebalance;
*
* Public: No
*/
#include "script_component.hpp"

params ["_force"];

TRACE_3("Rebalance",GVAR(inRebalance),GVAR(headlessClients),_force);

// Exit if waiting for rebalance or no HCs present
if (GVAR(inRebalance) || {GVAR(headlessClients) isEqualTo []}) exitWith {};

// Transfer after rebalance delay
[FUNC(transferGroups), [_force], GVAR(Delay)] call EFUNC(common,waitAndExecute);

// Currently in rebalance flag
GVAR(inRebalance) = true;
Loading