Skip to content

Commit

Permalink
Disable planning for player side commander
Browse files Browse the repository at this point in the history
  • Loading branch information
Sparker95 committed Dec 4, 2019
1 parent aea9079 commit 9d1cfb4
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 19 deletions.
21 changes: 19 additions & 2 deletions Project_0.Altis/AI/Commander/AICommander.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ CLASS("AICommander", "AI")
// Ported from CmdrAI
/* save */ VARIABLE_ATTR("activeActions", [ATTR_SAVE]);
VARIABLE("planningCycle");
VARIABLE("planningEnabled"); // Bool, if true, when active commander will perform AI planning

METHOD("new") {
params [P_THISOBJECT, ["_agent", "", [""]], ["_side", WEST, [WEST]], ["_msgLoop", "", [""]]];
Expand All @@ -64,7 +65,7 @@ CLASS("AICommander", "AI")
ASSERT_OBJECT_CLASS(_msgLoop, "MessageLoop");
T_SETV("side", _side);
T_SETV("msgLoop", _msgLoop);

T_SETV("planningEnabled", false);
T_SETV("garrisons", []);

T_SETV("targets", []);
Expand Down Expand Up @@ -190,14 +191,18 @@ CLASS("AICommander", "AI")
T_SETV("state", "action update");
T_SETV("stateStart", TIME_NOW);
#endif

T_CALLM("update", [_worldModel]);

#ifdef DEBUG_COMMANDER
T_SETV("state", "model planning");
T_SETV("stateStart", TIME_NOW);
#endif

#ifndef CMDR_AI_NO_PLAN
T_CALLM("plan", [_worldModel]);
if(T_GETV("planningEnabled")) then {
T_CALLM("plan", [_worldModel]);
};
#endif

// C L E A N U P
Expand Down Expand Up @@ -1682,6 +1687,15 @@ http://patorjk.com/software/taag/#p=display&f=Univers&t=CMDR%20AI
T_CALLM("_plan", [_world ARG _priority]);
};
} ENDMETHOD;

/*
Method: enablePlanning
nalbes planning on a commander AI which is started.
*/
METHOD("enablePlanning") {
params [P_THISOBJECT, P_BOOL("_enable")];
T_SETV("planningEnabled", _enable);
} ENDMETHOD;

/*
Method: update
Expand Down Expand Up @@ -2413,6 +2427,9 @@ http://patorjk.com/software/taag/#p=display&f=Univers&t=CMDR%20AI
// Call method of all base classes
CALL_CLASS_METHOD("AI", _thisObject, "postDeserialize", [_storage]);

// GameMode must re-enable it
T_SETV("planningEnabled", false);

// Initialize variables
#ifdef DEBUG_CLUSTERS
T_SETV("nextMarkerID", 0);
Expand Down
17 changes: 16 additions & 1 deletion Project_0.Altis/GameMode/CivilWar/CivilWarGameMode.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ CLASS("CivilWarGameMode", "GameModeBase")

} ENDMETHOD;

/* virtual */ METHOD("startCommanders") {
_this spawn {
params [P_THISOBJECT];
// Add some delay so that we don't start processing instantly, because we might want to synchronize intel with players
sleep 10;
CALLM1(T_GETV("AICommanderInd"), "enablePlanning", true);
CALLM1(T_GETV("AICommanderWest"), "enablePlanning", false);
CALLM1(T_GETV("AICommanderEast"), "enablePlanning", false);
{
// We postMethodAsync them, because we don't want to start processing right after mission start
CALLM2(T_GETV(_x), "postMethodAsync", "start", []);
} forEach ["AICommanderInd", "AICommanderWest", "AICommanderEast"];
};
} ENDMETHOD;

// Creates gameModeData of a location
/* protected override */ METHOD("initLocationGameModeData") {
params [P_THISOBJECT, P_OOP_OBJECT("_loc")];
Expand Down Expand Up @@ -94,7 +109,7 @@ CLASS("CivilWarGameMode", "GameModeBase")
} else {
if (_type == LOCATION_TYPE_OUTPOST) then {
if (random 100 < 50) then {
ENEMY_SIDE
selectRandom [ENEMY_SIDE, WEST]
} else {
CIVILIAN
};
Expand Down
28 changes: 16 additions & 12 deletions Project_0.Altis/GameMode/GameModeBase.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,22 @@ CLASS("GameModeBase", "MessageReceiverEx")
0
} ENDMETHOD;

// Not all game modes need all commanders
// By default all commanders are started and perform planning
// This can be overriden in this method
/* virtual */ METHOD("startCommanders") {
_this spawn {
params [P_THISOBJECT];
// Add some delay so that we don't start processing instantly, because we might want to synchronize intel with players
sleep 10;
{
CALLM1(T_GETV(_x), "enablePlanning", true);
// We postMethodAsync them, because we don't want to start processing right after mission start
CALLM2(T_GETV(_x), "postMethodAsync", "start", []);
} forEach ["AICommanderInd", "AICommanderWest", "AICommanderEast"];
};
} ENDMETHOD;

// -------------------------------------------------------------------------
// | S E R V E R O N L Y |
// -------------------------------------------------------------------------
Expand Down Expand Up @@ -575,18 +591,6 @@ CLASS("GameModeBase", "MessageReceiverEx")
} forEach gSpecialGarrisons;
} ENDMETHOD;

METHOD("startCommanders") {
_this spawn {
params [P_THISOBJECT];
// Add some delay so that we don't start processing instantly, because we might want to synchronize intel with players
sleep 10;
{
// We postMethodAsync them, because we don't want to start processing right after mission start
CALLM2(T_GETV(_x), "postMethodAsync", "start", []);
} forEach ["AICommanderInd", "AICommanderWest", "AICommanderEast"];
};
} ENDMETHOD;

fnc_getLocName = {
params["_name"];
private _names = "getText( _x >> 'name') == _name" configClasses ( configFile >> "CfgWorlds" >> worldName >> "Names" );
Expand Down
2 changes: 1 addition & 1 deletion Project_0.Altis/MessageLoop/fn_threadFunc.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ It checks for messages in the loop and calls handleMessages of objects.
#define PROCESS_CATEGORIES_DEBUG

// Will log every message
//#define PROFILE_MESSAGE_JSON
#define PROFILE_MESSAGE_JSON

// Performs monitoring of thread func prformance
#define THREAD_FUNC_DEBUG
Expand Down
4 changes: 2 additions & 2 deletions Project_0.Altis/config/oop_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
//#define CMDR_AI_TESTING

// Disables planning for cmdr ai, in case we want to test something
#define CMDR_AI_NO_PLAN
//#define CMDR_AI_NO_PLAN

// Profiling
//#define OOP_PROFILE
// Don't set it above 0.002 or so! Or even above 0.004! diag_tickTime precision is only 0.001 and degrades as the game runs
#define OOP_PROFILE_MIN_T 0.002

// Various runtime OOP assertions (class existence, member variable existence, etc)
#define OOP_ASSERT
//#define OOP_ASSERT


// ========= Release config ============
Expand Down
2 changes: 1 addition & 1 deletion Project_0.Altis/config/saveVersion.hpp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2
3

0 comments on commit 9d1cfb4

Please sign in to comment.