Skip to content

Commit

Permalink
Merge pull request #216 from Sparker95/add-cmdr-roadblock-creation
Browse files Browse the repository at this point in the history
Add cmdr roadblock creation
  • Loading branch information
Sparker95 authored Dec 27, 2019
2 parents aa623a6 + 46f6745 commit 38e1875
Show file tree
Hide file tree
Showing 25 changed files with 1,033 additions and 121 deletions.
5 changes: 3 additions & 2 deletions Project_0.Altis/AI/Commander/AICommander.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,11 @@
#define CMDR_EXT_REINF_INTERVAL_MINUTES 45

// Max amount of simultaneous actions
#define CMDR_MAX_TAKE_OUTPOST_ACTIONS 10
#define CMDR_MAX_REINFORCE_ACTIONS 4
#define CMDR_MAX_TAKE_OUTPOST_ACTIONS 3
#define CMDR_MAX_REINFORCE_ACTIONS 3
//#define CMDR_MAX_ATTACK_ACTIONS 100 QRFs are unlimited
#define CMDR_MAX_PATROL_ACTIONS 6
#define CMDR_MAX_CONSTRUCT_ACTIONS 3

// Max amount of units at airfields
#define CMDR_MAX_INF_AIRFIELD 80
Expand Down
188 changes: 179 additions & 9 deletions Project_0.Altis/AI/Commander/AICommander.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ CLASS("AICommander", "AI")
// External reinforcements
/* save */ VARIABLE_ATTR("datePrevExtReinf", [ATTR_SAVE]);

// Potential positions for new locations
/* save */ VARIABLE_ATTR("newRoadblockPositions", [ATTR_SAVE]);

// Will enable intel interception all the time
VARIABLE("cheatIntelInterception");

#ifdef DEBUG_CLUSTERS
VARIABLE("nextMarkerID");
VARIABLE("clusterMarkers");
Expand Down Expand Up @@ -133,6 +139,12 @@ CLASS("AICommander", "AI")
T_CALLM1("setProcessInterval", PROCESS_INTERVAL);

T_SETV("datePrevExtReinf", DATE_NOW);

// Roadblock positions
T_SETV("newRoadblockPositions", []);

//
T_SETV("cheatIntelInterception", false);
} ENDMETHOD;

METHOD("_initSensors") {
Expand Down Expand Up @@ -640,6 +652,11 @@ CLASS("AICommander", "AI")

OOP_INFO_1("INTERCEPT INTEL AT: %1", _this);

if (T_GETV("cheatIntelInterception")) exitWith {
T_CALLM2("inspectIntel", _intel, INTEL_METHOD_RADIO);
OOP_INFO_0(" cheated intel inter interception");
};

// Check if we have the radio key
pr _ourKnownEnemyKeys = T_GETV("enemyRadioKeys");
pr _weHaveRadioKey = _radioKey in _ourKnownEnemyKeys;
Expand Down Expand Up @@ -1000,12 +1017,13 @@ CLASS("AICommander", "AI")

// Create intel for new target clusters
{
pr _intel = _x select TARGET_CLUSTER_ID_INTEL;
_x params ["_affinity", "_tcNew"];
pr _intel = _tcNew select TARGET_CLUSTER_ID_INTEL;
if (IS_NULL_OBJECT(_intel)) then {
_intel = NEW("IntelCluster", []);
CALLSM2("AICommander", "setIntelClusterProperties", _intel, _x);
CALLSM2("AICommander", "setIntelClusterProperties", _intel, _tcNew);
CALLM1(_inteldb, "addIntel", _intel);
_x set [TARGET_CLUSTER_ID_INTEL, _intel];
_tcNew set [TARGET_CLUSTER_ID_INTEL, _intel];
};
} forEach _tcsNew;
} ENDMETHOD;
Expand All @@ -1014,9 +1032,10 @@ CLASS("AICommander", "AI")
Method: onTargetClusterMerged
Gets called when old clusters get merged into a new one
Parameters: _tc
Parameters: _tcsOld, _tcNew
_tc - the new target cluster
_tcsOld - array with old target clusters
_tcNew - the new target cluster
Returns: nil
*/
Expand Down Expand Up @@ -1668,7 +1687,10 @@ http://patorjk.com/software/taag/#p=display&f=Univers&t=ACTIONS
};

// Create a little composition at this place
[_posWorld] call misc_fnc_createCampComposition;
// We don't want to create this composition for roadblocks though
if (_locType in [LOCATION_TYPE_OUTPOST, LOCATION_TYPE_CAMP]) then {
[_posWorld] call misc_fnc_createCampComposition;
};

// Create the location
pr _loc = NEW_PUBLIC("Location", [_pos]);
Expand Down Expand Up @@ -2035,7 +2057,7 @@ http://patorjk.com/software/taag/#p=display&f=Univers&t=CMDR%20AI
private _tgtPos = GETV(_x, "pos");
private _tgtType = GETV(_x, "type");
private _dist = _srcPos distance _tgtPos;
if((_tgtType == LOCATION_TYPE_ROADBLOCK and _dist < 3000) or (_tgtType != LOCATION_TYPE_ROADBLOCK and _dist < 10000)) then {
if(_dist < 10000) then {
private _params = [_srcId, _tgtId];
_actions pushBack (NEW("TakeLocationCmdrAction", _params));
};
Expand Down Expand Up @@ -2139,6 +2161,78 @@ http://patorjk.com/software/taag/#p=display&f=Univers&t=CMDR%20AI
_actions
} ENDMETHOD;

METHOD("generateConstructRoadblockActions") {
params [P_THISOBJECT, P_OOP_OBJECT("_worldNow"), P_OOP_OBJECT("_worldFuture")];

// Limit amount of concurrent actions
T_PRVAR(activeActions);
pr _count = {GET_OBJECT_CLASS(_x) == "ConstructLocationCmdrAction"} count _activeActions;
//OOP_INFO_1(" Existing patrol actions: %1", _count);
if (_count > CMDR_MAX_CONSTRUCT_ACTIONS) exitWith {[]};

// Take src garrisons from now, we don't want to consider future resource availability, only current.
private _srcGarrisons = CALLM(_worldNow, "getAliveGarrisons", [["military"]]) select {
private _potentialSrcGarr = _x;
// Must be not already busy
!CALLM(_potentialSrcGarr, "isBusy", []) and
// Must be at a location
{ !IS_NULL_OBJECT(CALLM(_potentialSrcGarr, "getLocation", [])) } and
// Must not be source of another mission
{
T_PRVAR(activeActions);
_activeActions findIf {
GET_OBJECT_CLASS(_x) == "ConstructLocationCmdrAction" and
{ GETV(_x, "srcGarrId") == GETV(_potentialSrcGarr, "id") }
} == NOT_FOUND
} and
// Must have minimum efficiency available
{
private _overDesiredEff = CALLM(_worldNow, "getOverDesiredEff", [_potentialSrcGarr]);
// Must have at least a minimum available eff
EFF_GTE(_overDesiredEff, EFF_MIN_EFF)
}
};

// Take potential location positions from the future
// In the future there must be no location around these places
pr _potentialPositions = T_GETV("newRoadblockPositions");
_potentialPositions = _potentialPositions select {
pr _locs = CALLM4(_worldFuture, "getNearestLocations", _x, 200, [], []);
count _locs == 0 // There are no locations nearby in the future
};

private _strategy = T_GETV("cmdrStrategy");
private _actions = [];
private _side = T_GETV("side");
{
private _srcId = GETV(_x, "id");
private _srcPos = GETV(_x, "pos");
{
private _locPos = _x;
private _locType = LOCATION_TYPE_ROADBLOCK;
// Check strategy
// We only want to create those where it makes sense to create them
// We check desireability first to limit the amount of potential actions early in our evaluations
if (CALLM4(_strategy, "getConstructLocationDesirability", _worldNow, _locPos, _locType, _side) > 0) then {
private _dist = _srcPos distance _locPos;
if(_dist < 2200) then { // Only consider deploying roadblocks within some distance
private _params = [_srcId, _locPos, _locType];
_actions pushBack (NEW("ConstructLocationCmdrAction", _params));
};
};
} forEach _potentialPositions;
} forEach _srcGarrisons;

OOP_INFO_MSG("Considering %1 ConstructLocation roadblock actions from %2 garrisons to %3 positions", [count _actions ARG count _srcGarrisons ARG count _potentialPositions]);

#ifdef OOP_INFO
private _str = format ["{""cmdrai"": {""side"": ""%1"", ""action_name"": ""ConstructLocation"", ""potential_action_count"": %2, ""src_garrisons"": %3, ""tgt_positions"": %4}}", _side, count _actions, count _srcGarrisons, count _potentialPositions];
OOP_INFO_MSG(_str, []);
#endif

_actions
} ENDMETHOD;

/*
Method: updateExternalReinforcement
Should be called on each process. Updates external reinforcements.
Expand Down Expand Up @@ -2443,6 +2537,12 @@ http://patorjk.com/software/taag/#p=display&f=Univers&t=CMDR%20AI

_scoresAndActions sort DESCENDING;

OOP_DEBUG_MSG("Scores of all actions:", []);
for "_i" from 0 to ((count _scoresAndActions) - 1) do {
private _scoreAndAction = _scoresAndActions select _i;
OOP_DEBUG_MSG(" %1", [_scoreAndAction]);
};

// _newActions = [_newActions, [], { CALLM(_x, "getFinalScore", []) }, "DECEND"] call BIS_fnc_sortBy;

// Get the best scoring action
Expand Down Expand Up @@ -2533,12 +2633,16 @@ http://patorjk.com/software/taag/#p=display&f=Univers&t=CMDR%20AI
["generateReinforceActions", "generatePatrolActions"]
};
case CMDR_PLANNING_PRIORITY_LOW: {
["generateTakeOutpostActions"]
["generateTakeOutpostActions", "generateConstructRoadblockActions"]
};
};
#else
// We will plan the shit ouf of this world model
private _generators = ["generateAttackActions", "generateReinforceActions", "generatePatrolActions", "generateTakeOutpostActions"];
private _generators = [ "generateAttackActions",
"generateReinforceActions",
"generatePatrolActions",
"generateTakeOutpostActions",
"generateConstructRoadblockActions"];
#endif

T_CALLM("selectActions", [_generators ARG _maxNewActions ARG _world ARG _simWorldNow ARG _simWorldFuture]);
Expand Down Expand Up @@ -2584,6 +2688,27 @@ http://patorjk.com/software/taag/#p=display&f=Univers&t=CMDR%20AI
























// = = = = = = = = = = = Radio = = = = = = = = = = = = =

// Initializes the radio key grid
Expand Down Expand Up @@ -2740,7 +2865,49 @@ http://patorjk.com/software/taag/#p=display&f=Univers&t=CMDR%20AI
REMOTE_EXEC_CALL_STATIC_METHOD("RadioKeyTab", "staticServerShowKeys", _args, _clientOwner, false);
} ENDMETHOD;
















// = = = = = = = = = = = = = = Roadblocks and dynamic locations = = = = = = = = = = = = = =

// Adds a position for commander to consider create a roadblock at
METHOD("addRoadblockPosition") {
params [P_THISOBJECT, P_POSITION("_pos")];

T_GETV("newRoadblockPositions") pushBack (+_pos);
} ENDMETHOD;


















// - - - - - - - STORAGE - - - - - - -

/* override */ METHOD("preSerialize") {
params [P_THISOBJECT, P_OOP_OBJECT("_storage")];

Expand Down Expand Up @@ -2857,6 +3024,9 @@ http://patorjk.com/software/taag/#p=display&f=Univers&t=CMDR%20AI
pr _radioKeyGrid = T_GETV("radioKeyGrid");
CALLM1(_storage, "load", _radioKeyGrid);

//
T_SETV("cheatIntelInterception", false);

true
} ENDMETHOD;

Expand Down
Loading

0 comments on commit 38e1875

Please sign in to comment.