Skip to content

Commit

Permalink
Moving Ace Init (#2842)
Browse files Browse the repository at this point in the history
* initial commit

* review changes

* ace_throwable fix

* Fixes & cleanup for ACE init refactor:
- Removed surplus initACEUnconsciousHandler call.
- Removed leftover debug systemChat from treatment logging.
- Fixed bug in throwableThrown EH.
- Moved claim calls before the early-out.
- Moved initServer event handlers to correct place (pre-serverInitDone)

---------

Co-authored-by: John Jordan <[email protected]>
  • Loading branch information
killerswin2 and jaj22 authored Aug 19, 2023
1 parent e9b1123 commit ebd76dc
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 67 deletions.
1 change: 1 addition & 0 deletions A3A/addons/core/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ class CfgFunctions
class cityinfo {};
class clientIdleChecker {};
class credits {};
class initACE {};
class initACEUnconsciousHandler {};
class initBases {};
class initUtilityItems {};
Expand Down
58 changes: 58 additions & 0 deletions A3A/addons/core/functions/init/fn_initACE.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* File: fn_initACE.sqf
* Function: A3A_fnc_initACE
* Function description
* Initialization code for ACE3 stuff
* Arguments:
* 0: Objects <ARRAY>
* 1: All <BOOL>
*
* Return Value:
* None
*
* Example:
* call A3A_fnc_initACE;
*
* Public: No
*/

#include "..\..\script_component.hpp"

if (A3A_hasACEMedical) then {
// log atropine, epinephrine, and morphine use
// Appears to be local to the medic
["ace_treatmentStarted", {
params ["_caller", "_target", "_selectionName", "_className", "_itemUser", "_usedItem"];
if (_usedItem in ["ACE_atropine", "ACE_epinephrine", "ACE_morphine"]) then {
ServerInfo_3("Player: %1 used %2 on %3",name _caller,_usedItem,name _target);
};
}] call CBA_fnc_addEventHandler;
};

["ace_explosives_place", {
params ["_explosive","_dir","_pitch","_unit"];
if (captive player && _unit == player) then { player setCaptive false };
}] call CBA_fnc_addEventHandler;

["ace_throwableThrown", {
params ["_unit", "_throwable"];
if (captive player && _unit == player) then { player setCaptive false };
}] call CBA_fnc_addEventHandler;

[boxX, boxX] call ace_common_fnc_claim; //Disables ALL Ace Interactions
[vehicleBox, VehicleBox] call ace_common_fnc_claim; //Disables ALL Ace Interactions

if (isNil "ace_interact_menu_fnc_compileMenu" || isNil "ace_interact_menu_fnc_compileMenuSelfAction") exitWith {
Error("ACE non-public functions have changed, rebel group join/leave actions will not be removed.");
};
// Remove group join action from all rebel unit types
// Need to compile the menus first, because ACE delays creating menus until a unit of that class is created
private _unitTypes = ["I_G_soldier_F", "I_G_Soldier_TL_F", "I_G_Soldier_AR_F", "I_G_medic_F", "I_G_engineer_F", "I_G_Soldier_GL_F", "I_G_officer_F"];
{
[_x] call ace_interact_menu_fnc_compileMenu;
[_x] call ace_interact_menu_fnc_compileMenuSelfAction;
[_x, 0, ["ACE_ApplyHandcuffs"]] call ace_interact_menu_fnc_removeActionFromClass;
[_x, 1, ["ACE_SelfActions", "ACE_TeamManagement", "ACE_LeaveGroup"]] call ace_interact_menu_fnc_removeActionFromClass;
[_x, 0, ["ACE_MainActions", "ACE_JoinGroup"]] call ace_interact_menu_fnc_removeActionFromClass;
} forEach _unitTypes; // TODO: add raw unit types from new templates

28 changes: 2 additions & 26 deletions A3A/addons/core/functions/init/fn_initClient.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,6 @@ player addEventHandler ["GetInMan", {
};
}];

if (A3A_hasACE) then {
["ace_explosives_place", {
params ["_explosive","_dir","_pitch","_unit"];
if (_unit == player) then { player setCaptive false };
}] call CBA_fnc_addEventHandler;
};

// Prevent players getting shot by their own AIs. EH is respawn-persistent
player addEventHandler ["HandleRating", {0}];

Expand Down Expand Up @@ -355,27 +348,9 @@ waituntil {!isnull (finddisplay 46)};
GVAR(keys_battleMenu) = false; //initilize key flags to false


if (A3A_hasACE) then
{
if (isNil "ace_interact_menu_fnc_compileMenu" || isNil "ace_interact_menu_fnc_compileMenuSelfAction") exitWith {
Error("ACE non-public functions have changed, rebel group join/leave actions will not be removed.");
};
// Remove group join action from all rebel unit types
// Need to compile the menus first, because ACE delays creating menus until a unit of that class is created
private _unitTypes = ["I_G_soldier_F", "I_G_Soldier_TL_F", "I_G_Soldier_AR_F", "I_G_medic_F", "I_G_engineer_F", "I_G_Soldier_GL_F", "I_G_officer_F"];
{
[_x] call ace_interact_menu_fnc_compileMenu;
[_x] call ace_interact_menu_fnc_compileMenuSelfAction;
[_x, 0, ["ACE_ApplyHandcuffs"]] call ace_interact_menu_fnc_removeActionFromClass;
[_x, 1, ["ACE_SelfActions", "ACE_TeamManagement", "ACE_LeaveGroup"]] call ace_interact_menu_fnc_removeActionFromClass;
[_x, 0, ["ACE_MainActions", "ACE_JoinGroup"]] call ace_interact_menu_fnc_removeActionFromClass;
} forEach _unitTypes; // TODO: add raw unit types from new templates
};

boxX allowDamage false; // hmm...
boxX addAction ["Transfer Vehicle cargo to Ammobox", {[] spawn A3A_fnc_empty;}, 4];
boxX addAction ["Move this asset", A3A_fnc_moveHQObject,nil,0,false,true,"","(_this == theBoss)", 4];
if (A3A_hasACE) then { [boxX, boxX] call ace_common_fnc_claim;}; //Disables ALL Ace Interactions
flagX allowDamage false;
flagX addAction ["Unit Recruitment", {if ([getPosATL player] call A3A_fnc_enemyNearCheck) then {["Recruit Unit", "You cannot recruit units while there are enemies near you."] call A3A_fnc_customHint;} else { [] spawn A3A_fnc_unit_recruit; }},nil,0,false,true,"","(isPlayer _this) and (_this == _this getVariable ['owner',objNull]) and (side (group _this) == teamPlayer)"];
flagX addAction ["Move this asset", A3A_fnc_moveHQObject,nil,0,false,true,"","(_this == theBoss)", 4];
Expand All @@ -393,7 +368,6 @@ vehicleBox allowDamage false;
vehicleBox addAction [localize "STR_A3A_actions_restore_units", A3A_fnc_vehicleBoxRestore,nil,0,false,true,"","(isPlayer _this) and (_this == _this getVariable ['owner',objNull]) and (side (group _this) == teamPlayer)", 4];
vehicleBox addAction ["Vehicle Arsenal", JN_fnc_arsenal_handleAction, [], 0, true, false, "", "alive _target && vehicle _this != _this", 10];
[vehicleBox] call HR_GRG_fnc_initGarage;
if (A3A_hasACE) then { [vehicleBox, VehicleBox] call ace_common_fnc_claim;}; //Disables ALL Ace Interactions

vehicleBox addAction ["Buy Vehicle", {
if ([getPosATL player] call A3A_fnc_enemyNearCheck) then {
Expand Down Expand Up @@ -449,6 +423,8 @@ _layer = ["statisticsX"] call bis_fnc_rscLayer;
//Load the player's personal save.
[] spawn A3A_fnc_createDialog_shouldLoadPersonalSave;

if (A3A_hasACE) then {call A3A_fnc_initACE};

[allCurators] remoteExecCall ["A3A_fnc_initZeusLogging",0];

initClientDone = true;
Expand Down
80 changes: 39 additions & 41 deletions A3A/addons/core/functions/init/fn_initServer.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,45 @@ addMissionEventHandler ["EntityKilled", {
};
}];

if ((isClass (configfile >> "CBA_Extended_EventHandlers")) && (
isClass (configfile >> "CfgPatches" >> "lambs_danger"))) then {
// disable lambs danger fsm entrypoint
["CAManBase", "InitPost", {
params ["_unit"];
(group _unit) setVariable ["lambs_danger_disableGroupAI", true];
_unit setVariable ["lambs_danger_disableAI", true];
}] call CBA_fnc_addClassEventHandler;
};

// Could replace these with entityCreated handler instead...
if(A3A_hasZen) then {
["zen_common_createZeus", {
_this spawn {
params ["_unit"];

// wait in case our event was called first
waitUntil {sleep 1; !isNull getAssignedCuratorLogic _unit};

//now add the logging to the module
[[getAssignedCuratorLogic _unit]] remoteExecCall ["A3A_fnc_initZeusLogging",0];
};
}] call CBA_fnc_addEventHandler;
};

if (A3A_hasACE) then {
["ace_zeus_createZeus", {
_this spawn {
params ["_unit"];

// wait in case our event was called first
waitUntil {sleep 1; !isNull getAssignedCuratorLogic _unit};

//now add the logging to the module
[[getAssignedCuratorLogic _unit]] remoteExecCall ["A3A_fnc_initZeusLogging",0];
};
}] call CBA_fnc_addEventHandler;
};


serverInitDone = true; publicVariable "serverInitDone";
Info("Setting serverInitDone as true");
Expand Down Expand Up @@ -289,46 +328,5 @@ savingServer = false; // enable saving
};
};

if ((isClass (configfile >> "CBA_Extended_EventHandlers")) && (
isClass (configfile >> "CfgPatches" >> "lambs_danger"))) then {
// disable lambs danger fsm entrypoint
["CAManBase", "InitPost", {
params ["_unit"];
(group _unit) setVariable ["lambs_danger_disableGroupAI", true];
_unit setVariable ["lambs_danger_disableAI", true];
}] call CBA_fnc_addClassEventHandler;
};



if(A3A_hasZen) then
{
["zen_common_createZeus", {
[_this] spawn {
params ["_unit"];

// wait in case our event was called first
waitUntil {sleep 1; !isNull getAssignedCuratorLogic _unit};

//now add the logging to the module
[[getAssignedCuratorLogic _unit]] remoteExecCall ["A3A_fnc_initZeusLogging",0];
};
}] call CBA_fnc_addEventHandler;
};

if(A3A_hasACE) then
{
["ace_zeus_createZeus", {
[_this] spawn {
params ["_unit"];

// wait in case our event was called first
waitUntil {sleep 1; !isNull getAssignedCuratorLogic _unit};

//now add the logging to the module
[[getAssignedCuratorLogic _unit]] remoteExecCall ["A3A_fnc_initZeusLogging",0];
};
}] call CBA_fnc_addEventHandler;
};

Info("initServer completed");

0 comments on commit ebd76dc

Please sign in to comment.