-
Notifications
You must be signed in to change notification settings - Fork 740
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
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
z\ace\addons\headless |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {}; | ||
|
||
// Rebalance | ||
[false] call FUNC(rebalance); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?