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 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
11 changes: 11 additions & 0 deletions addons/danger/CfgAIProfile.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class LAMBS_CfgAIProfiles {
class Default {
requestArtillery = 1;
};
};
class LAMBS_CfgAIProfilesValueDescriptions {
class requestArtillery {
name = "Request Artillery";
description = "The AI is allowed to Request Artillery.";
};
};
1 change: 0 additions & 1 deletion addons/danger/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ PREP(tacticsFlank);
PREP(tacticsGarrison);
PREP(tacticsHide);
PREP(tacticsHold);
PREP(tacticsProfiles);
PREP(tacticsReinforce);
PREP(tacticsSuppress);

Expand Down
1 change: 1 addition & 0 deletions addons/danger/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ class CfgPatches {
#include "CfgVehicles.hpp"
#include "Cfg3DEN.hpp"
#include "ZEN_CfgContext.hpp"
#include "CfgAIProfile.hpp"
7 changes: 5 additions & 2 deletions addons/danger/functions/fnc_brainAdjust.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
*
* Public: No
*/
params ["", ["_priorties", GVAR(fsmPriorities)]];

// this function may have use in the future - nkenny
params ["_unit", ["_priorties", GVAR(fsmPriorities)]];

private _modifiedPriorties = _unit getVariable QGVAR(Priorities);
if (!isNil "_modifiedPriorties" && { _modifiedPriorties isEqualType [] } && { count GVAR(fsmPriorities) == count _modifiedPriorties}) then {
_priorties = _modifiedPriorties;
};
// end
_priorties
3 changes: 1 addition & 2 deletions addons/danger/functions/fnc_tactics.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ params [["_unit", objNull, [objNull]], ["_target", objNull, [objNull]]];
//};

private _group = group _unit;

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

Expand All @@ -32,7 +31,7 @@ private _contactState = _group getVariable [QGVAR(contact), 0];
if (_contactState < time) exitWith {[_unit, _target] 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.

12 changes: 12 additions & 0 deletions addons/eventhandlers/CfgAIProfile.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class LAMBS_CfgAIProfiles {
class Default {
reactToExplosions = 1;
};
};

class LAMBS_CfgAIProfilesValueDescriptions {
class reactToExplosions {
name = "React to Explosion";
description = "The AI Reacts with Animations to Explosion nearby.";
};
};
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,getProfileValue)}
) exitWith {false};

// settings
Expand Down
20 changes: 20 additions & 0 deletions addons/main/Cfg3DEN.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Cfg3DEN {
class Mission {
class Scenario {
class AttributeCategories {
class GVAR(category) {
class GVAR(AIProfiles) {
property = QGVAR(AIProfiles);
value = 0;
control = "CBA_Settings_CategoryHider";
displayName = "";
tooltip = "";
defaultValue = QUOTE(HASH_NULL);
expression = "";
wikiType = "[[Array]]";
};
};
};
};
};
};
41 changes: 41 additions & 0 deletions addons/main/CfgAIProfile.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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
};
};

class LAMBS_CfgAIProfilesValueDescriptions {
#ifdef ISDEV
class allowDemoNumberAsBool {
name = "Demo allowDemoNumberAsBool";
description = "Description of allowDemoNumberAsBool";
};
class allowDemoRandom {
name = "Demo Setting allowDemoRandom";
description = "Description of allowDemoRandom";
};
class allowDemoBool {
name = "Demo allowDemoBool";
description = "Description of allowDemoBool";
};
class allowDemoBool2 {
name = "Demo allowDemoBool2";
description = "Description of allowDemoBool2";
};
class allowDemoCodeBool {
name = "Demo allowDemoCodeBool";
description = "Description of allowDemoCodeBool";
};
class allowDemoCodeNumber {
name = "Demo allowDemoCodeNumber";
description = "Description of allowDemoCodeNumber";
};
#endif
};
21 changes: 21 additions & 0 deletions addons/main/CfgDisplay3DEN.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class ctrlMenuStrip;
class Display3DEN {
class Controls {
class MenuStrip: ctrlMenuStrip {
class Items {
class Tools {
items[] += {
QGVAR(AIProfileEditor)
};
};
class GVAR(AIProfileEditor) {
text = CSTRING(OpenAIProfileEditor);
picture = "\A3\ui_f\data\igui\cfg\simpleTasks\types\meet_ca.paa";
action = QUOTE(call FUNC(profileEditor));
shortcuts[] = {};
opensNewWindow = 1;
};
};
};
};
};
6 changes: 6 additions & 0 deletions addons/main/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,9 @@ SUBPREP(debug,debugMarkerColor);
SUBPREP(debug,debugObjectColor);
SUBPREP(debug,dotMarker);
SUBPREP(debug,zoneMarker);

SUBPREP(Profiles,getProfileValue);
SUBPREP(Profiles,parseAIProfiles);
SUBPREP(Profiles,profileEditor);
SUBPREP(Profiles,setProfileAllow);
SUBPREP(Profiles,setupProfile);
7 changes: 7 additions & 0 deletions addons/main/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,11 @@ GVAR(shareHandlers) = [];

GVAR(blockSuppressionModelCache) = false call CBA_fnc_createNamespace;

GVAR(minObstacleProximity) = 5;

if (isServer && !is3DEN) then {
GVAR(ProfilesNamespace) = true call CBA_fnc_createNamespace;
publicVariable QGVAR(ProfilesNamespace);
call FUNC(parseAIProfiles);
};
ADDON = true;
2 changes: 2 additions & 0 deletions addons/main/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ class CfgPatches {
VERSION_CONFIG;
};
};
#include "CfgDisplay3DEN.hpp"
#include "CfgFactionClasses.hpp"
#include "CfgEventHandlers.hpp"
#include "CfgAIProfile.hpp"

class GVAR(Display) {
idd = -1;
Expand Down
50 changes: 50 additions & 0 deletions addons/main/functions/Profiles/fnc_getProfileValue.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#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>
* 2: Profile Default Value <ANYTHING>
*
* Return Value:
* Value Stored in the Profile Tactic
*
* Example:
* [bob] call lambs_danger_fnc_getProfileValue;
*
* Remarks:
* Based on the 3rd parameter the type of return is getting defined.
* If the value type of the profile tactic is a different to the _default type it the default gets returned.
*
*
* Public: No
*/
params [["_target", objNull, [objNull, grpNull]], ["_tactic", "unkown", [""]], ["_default", true, [true, 0]]];

private _profile = _target getVariable [QGVAR(AIProfile), GVAR(defaultAIProfile)];

private _profileData = GVAR(ProfilesNamespace) getVariable _profile;
if (isNil "_profileData") then {
_profileData = GVAR(ProfilesNamespace) getVariable "default";
};

// Simple Unit/Group Based Overwrite
private _overwrite = _target getVariable QGVAR(OverwriteProfile);
if (!isNil "_overwrite" && { _overwrite isEqualType [] } && { _tactic in _overwrite }) then {
_profileData = _overwrite;
};

_tactic = toLower _tactic;
private _value = _profileData get _tactic;

if (_value isEqualType {}) then {
_value = [_target, _tactic] call _value;
};
if (_value isEqualType 0) then {
if (_default isEqualType true) then {
_value = _value isEqualTo 1;
};
};
_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 = createHashMap;
};
{
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 set [_tactic, _value];
} forEach configProperties [_x, "!isClass _x", true];
GVAR(ProfilesNamespace) setVariable [_profileName, _profile, true];
} forEach configProperties [_x >> "LAMBS_CfgAIProfiles", "isClass _x", true];
} forEach [configFile, missionConfigFile];
51 changes: 51 additions & 0 deletions addons/main/functions/Profiles/fnc_profileEditor.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
*/
// [{ call Lambs_main_fnc_profileEditor; }, 2] call CBA_fnc_waitAndExecute;
#ifdef ISDEV
private _display = ([findDisplay 46, findDisplay 313] select is3DEN) createDisplay QGVAR(display);
#else
private _display = findDisplay 313 createDisplay QGVAR(display);
#endif

private _defaultProfile = configProperties [configFile >> "LAMBS_CfgAIProfiles" >> "default", "!isClass _x", true];
private _height = ((count _defaultProfile) + 1) * (PY(CONST_HEIGHT + CONST_SPACE_HEIGHT) * 2);

private _basePositionX = 0.5 - (PX(CONST_WIDTH) / 2);
private _basePositionY = 0.5 - (_height / 2);

private _globalGroup = _display ctrlCreate ["RscText", -1];
_globalGroup ctrlSetBackgroundColor BACKGROUND_RGB(0.8);
_globalGroup ctrlSetPosition [_basePositionX, 0.5 - (_height / 2), PX(CONST_WIDTH), _height];
_globalGroup ctrlCommit 0;

private _header = _display ctrlCreate ["RscText", -1, _globalGroup];
_header ctrlSetText "Profile: Default"; // TODO(joko): Add Profile Selector
_header ctrlSetFontHeight PY(CONST_HEIGHT);
_header ctrlSetPosition [0.5 - (PX(CONST_WIDTH / 2)), _basePositionY, PX(CONST_WIDTH), PY(5)];
_header ctrlSetBackgroundColor COLOR_RGBA;
_header ctrlCommit 0;

_display setVariable ["header", _header];

// TODO(joko): Code
// TODO(joko): Checkbox
// TODO(joko): Number
// TODO(joko): Clear
// TOOD(joko): New Profile
// TODO(joko): Duplicate Profile
// TODO(joko): Parsing
// TODO(joko): Saving
Loading