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

[WIP] AI Profiles #164

Draft
wants to merge 19 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions addons/danger/CfgAIProfile.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class LAMBS_CfgAIProfiles {
class Default {
requestArtillery = 1;

};
};
1 change: 0 additions & 1 deletion addons/danger/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ PREP(tacticsCQB);
PREP(tacticsFlank);
PREP(tacticsGarrison);
PREP(tacticsHide);
PREP(tacticsProfiles);
PREP(tacticsSuppress);
PREP(vehicle);
PREP(vehicleAssault);
Expand Down
1 change: 1 addition & 0 deletions addons/danger/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ class CfgPatches {
#include "CfgFSMs.hpp"
#include "Cfg3DEN.hpp"
#include "ZEN_CfgContext.hpp"
#include "CfgAIProfile.hpp"
7 changes: 4 additions & 3 deletions addons/danger/functions/fnc_tactics.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ params [["_unit", objNull, [objNull]]];
// _unit call FUNC(tacticsCQB);
//};

private _group = group _unit;
// check if group AI disabled
if ((group _unit) getVariable [QGVAR(disableGroupAI), false]) exitWith {false};
if (_group getVariable [QGVAR(disableGroupAI), false]) exitWith {false};

// Initated contact?
private _contactState = group _unit getVariable [QGVAR(contact), 0];
private _contactState = _group getVariable [QGVAR(contact), 0];
if (_contactState < time) exitWith {_unit call FUNC(tacticsContact)};

// ai profiles ~ here is where AI profiles will be extrapolated - nkenny
if (_unit call FUNC(tacticsProfiles)) exitWith {true};
// if ([_unit, "something"] call EFUNC(main,doesProfileAllow)) exitWith {true};

// Leader assessment
if (!isPlayer (leader _unit)) then {_unit call FUNC(tacticsAssess);};
Expand Down
25 changes: 0 additions & 25 deletions addons/danger/functions/fnc_tacticsProfiles.sqf

This file was deleted.

5 changes: 5 additions & 0 deletions addons/eventhandlers/CfgAIProfile.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class LAMBS_CfgAIProfiles {
class Default {
reactToExplosions = 1;
};
};
1 change: 1 addition & 0 deletions addons/eventhandlers/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ class CfgPatches {
};

#include "CfgEventHandlers.hpp"
#include "CfgAIProfile.hpp"
1 change: 1 addition & 0 deletions addons/eventhandlers/functions/fnc_explosionEH.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ if (
|| {!isNull objectParent _unit}
|| {(stance _unit) isEqualTo "PRONE"}
|| {_unit getVariable [QGVAR(explosionReactionTime), 0] > time}
|| {[_unit, "reactToExplosions"] call EFUNC(main,doesProfileAllow)}
) exitWith {false};

// settings
Expand Down
12 changes: 12 additions & 0 deletions addons/main/CfgAIProfile.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class LAMBS_CfgAIProfiles {
class Default {
#ifdef ISDEV
allowDemoNumberAsBool = 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

All of the profile stuff is in the main component, wouldn't it be better to have the dev values in danger and the actual prod default values in main?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I would split it into the modules where it is used

Copy link
Collaborator

Choose a reason for hiding this comment

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

We do need then at least in the wiki some entry with all config entries. It is confusing to look at the code and only see a fraction of possible entries. (Or we have to tell people to use the config viewer)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

originally I planned to build a tool that shows and allows you to create and modify profiles in the editor in the release after the profiles where introduced. but writing a small export for the wiki is also fairly easy

allowDemoRandom = 0.5;
allowDemoBool = "true";
allowDemoBool2 = "False";
allowDemoCodeBool = "selectRandom [true, true, false, true, false, false]";
allowDemoCodeNumber = "random 1";
#endif
};
};
5 changes: 5 additions & 0 deletions addons/main/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ SUBPREP(debug,debugMarkerColor);
SUBPREP(debug,debugObjectColor);
SUBPREP(debug,dotMarker);
SUBPREP(debug,zoneMarker);

SUBPREP(Profiles,parseAIProfiles);
SUBPREP(Profiles,setProfileAllow);
SUBPREP(Profiles,setupProfile);
SUBPREP(Profiles,doesProfileAllow);
6 changes: 6 additions & 0 deletions addons/main/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ GVAR(drawRectInUseEGSpectator) = [];
GVAR(drawRectCacheCurator) = [];
GVAR(drawRectInUseCurator) = [];
addMissionEventHandler ["Draw3D", { call FUNC(debugDraw); }];

if (isServer) then {
GVAR(ProfilesNamespace) = true call CBA_fnc_createNamespace;
publicVariable QGVAR(ProfilesNamespace);
call FUNC(parseAIProfiles);
};
1 change: 1 addition & 0 deletions addons/main/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class CfgPatches {
};
#include "CfgFactionClasses.hpp"
#include "CfgEventHandlers.hpp"
#include "CfgAIProfile.hpp"

class GVAR(Display) {
idd = -1;
Expand Down
41 changes: 41 additions & 0 deletions addons/main/functions/Profiles/fnc_doesProfileAllow.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "script_component.hpp"
/*
* Author: joko // Jonas
* Group profiles handler -- Checks and runs AI profiles -- group actions with the fnc_profileXxx prefix.
*
* Arguments:
* 0: Group/Unit <OBJECT, GROUP>
* 1: Profile Tactic <STRING>
*
* Return Value:
* Tactic is allowed to Execute
*
* Example:
* [bob] call lambs_danger_fnc_doesProfileAllow;
*
* Public: No
*/
params [["_target", objNull, [objNull, grpNull]], ["_tactic", "unkown", [""]]];

private _profile = _target getVariable [QGVAR(AIProfile), "default"];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Kind of a QoL thing. Have a cba setting which profile should be used as default

the CBA setting is a list of available profiles

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

a dropdown would be impossible because they can be saved in the description and created via scripted modules. and parsing that while in the editor is from my knowledge not possible. the only thing for CBA setting we could do is a normal text box.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The way I see it, is, a drop down is doable, but only account for config and missionconfig profiles. If someone adds them in editor OR via script it is in their authority to set the default correctly.


private _profileData = GVAR(ProfilesNamespace) getVariable toLower(_profile);
if (isNil "_profileData") then {
_profileData = GVAR(ProfilesNamespace) getVariable "Default";
};
_tactic = toLower(_tactic);
private _value = [_profileData, _tactic] call CBA_fnc_hashGet;
if (_value isEqualType {}) then {
diwako marked this conversation as resolved.
Show resolved Hide resolved
_value = [_target, _tactic] call _value;
};
if (_value isEqualType 0) then {
if (_value in [1,0]) then {
_value = _value isEqualTo 1;
} else {
_value = RND(_value);
};
};
if !(_value isEqualType true) then {
_value = true;
};
_value;
51 changes: 51 additions & 0 deletions addons/main/functions/Profiles/fnc_parseAIProfiles.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include "script_component.hpp"
/*
* Author: joko // Jonas
*
*
* Arguments:
*
*
* Return Value:
*
*
* Example:
*
*
* Public: No
*/

{
{
private _profileName = toLower(configName _x);
private _profile = GVAR(ProfilesNamespace) getVariable _profileName;
if (isNil "_profile") then {
_profile = [[], true] call CBA_fnc_hashCreate;
};
{
private _value = false;
private _tactic = toLower(configName _x);
if (isText _x) then {
_value = getText _x;
if (toLower(_value) in ["true", "false"]) then {
switch (toLower _value) do {
case ("true"): {
_value = true;
};
default {
_value = false;
};
};
} else {
_value = compile _value;
};
} else {
if (isNumber _x) then {
_value = getNumber _x;
};
};
_profile = [_profile, _tactic, _value] call CBA_fnc_hashSet;
} forEach configProperties [_x, "!isClass _x", true];
GVAR(ProfilesNamespace) setVariable [_profileName, _profile, true];
} forEach configProperties [_x >> "LAMBS_CfgAIProfiles", "isClass _x", true];
} forEach [configFile, missionConfigFile];
28 changes: 28 additions & 0 deletions addons/main/functions/Profiles/fnc_setProfileAllow.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "script_component.hpp"
/*
* Author: joko // Jonas
* Group profiles handler -- Checks and runs AI profiles -- group actions with the fnc_profileXxx prefix.
*
* Arguments:
* 0: Profile <STRING>
* 1: Profile Tactic <STRING>
* 2: Profile Enabled <BOOL>
*
* Return Value:
* Tactic is allowed to Execute
*
* Example:
* ["default", "tacticHidding", true] call lambs_danger_fnc_setProfileAllow;
*
* Public: No
*/
params [["_profileName", "", [""]], ["_tacticName", "", [""]], ["_enabled", true, [true, 0, {}]]];
_profileName = toLower(_profileName);
private _profile = GVAR(ProfilesNamespace) getVariable _profileName;
if (isNil "_profile") then {
_profile = [[], true] call CBA_fnc_hashCreate;
};

_profile = [_profile, toLower(_tacticName), _enabled] call CBA_fnc_hashSet;

GVAR(ProfilesNamespace) setVariable [_profileName, _profile, true];
26 changes: 26 additions & 0 deletions addons/main/functions/Profiles/fnc_setupProfile.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "script_component.hpp"
/*
* Author: joko // Jonas
* Group profiles handler -- Checks and runs AI profiles -- group actions with the fnc_profileXxx prefix.
*
* Arguments:
* 0: Group/Unit <OBJECT, GROUP>
* 1: Profile Tactic <STRING>
*
* Return Value:
* Tactic is allowed to Execute
*
* Example:
* [bob] call lambs_danger_fnc_setupProfile;
*
* Public: No
*/
params ["_tacticName", "_tactics"];

private _profile = +GVAR(ProfilesNamespace) getVariable "default"; // Create a Copy of the default Profile

{
_profile = [_profile, toLower(_x select 0), _x select 1] call CBA_fnc_hashSet;
} forEach _tactics;

GVAR(ProfilesNamespace) setVariable [toLower(_tacticName), _profile, true];
1 change: 1 addition & 0 deletions addons/main/functions/Profiles/script_component.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "\z\lambs\addons\danger\script_component.hpp"