Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

Add headless client component #1

Merged
merged 5 commits into from
May 5, 2016
Merged
Show file tree
Hide file tree
Changes from 4 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 addons/headless/$PBOPREFIX$
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
z\acex\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 = "STR_ACE_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 @@
acex_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 ["acex_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 (ace_common_globalEvent);
Copy link
Member

Choose a reason for hiding this comment

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

ace_common_fnc_globalEvent

};
}] call (ace_common_addEventHandler);
Copy link
Member

Choose a reason for hiding this comment

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

ace_common_fnc_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 (ace_common_addEventHandler);
Copy link
Member

Choose a reason for hiding this comment

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

ace_common_fnc_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[] = {"acex_main"};
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 (!(ace_common_settingsInitFinished)) exitWith {
(ace_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 (!(ace_common_settingsInitFinished)) exitWith {
(ace_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 {};

// 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 (ace_common_readSettingFromModule);
Copy link
Member

Choose a reason for hiding this comment

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

ace_common_fnc_readSettingFromModule

[_logic, QGVAR(Delay), "Delay"] call (ace_common_readSettingFromModule);
[_logic, QGVAR(Log), "Log"] call (ace_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 (ace_common_waitAndExecute);
Copy link
Member

Choose a reason for hiding this comment

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

ace_common_fnc_waitAndExecute


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