Skip to content

Commit

Permalink
(#642): WIP implementing refactor for wave spawns
Browse files Browse the repository at this point in the history
  • Loading branch information
Ansible2 committed Jul 9, 2023
1 parent 10bb815 commit 9a7b17e
Show file tree
Hide file tree
Showing 8 changed files with 232 additions and 137 deletions.
2 changes: 1 addition & 1 deletion Functions/Queue/fn_spawnQueue_add.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Function: BLWK_fnc_queue_add
Description:
Adds the given args to the enemy spawn queue
Adds the given args to the enemy spawn queue.
Parameters:
0: _class : <STRING> - The classname of the unit you want to add to the queue
Expand Down
37 changes: 37 additions & 0 deletions Functions/Queue/fn_spawnQueue_create.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* ----------------------------------------------------------------------------
Function: BLWK_fnc_spawnQueue_create
Description:
Creates a unit for the wave based upon the args provided.
Parameters:
0: _class : <STRING> - The classname of the unit you want to add to the queue
1: _position : <PositionATL[] OR OBJECT> - The position to spawn the unit at
2: _onManCreatedFunctionName : <STRING> - The global var name for the function
to run once the unit is created on the AI handler owner machine.
Returns:
NOTHING
Examples:
(begin example)
[
missionConfigFile >> "BLWK_waveTypes" >> "normalWaves" >> "standardWave"
] call BLWK_fnc_spawnQueue_create;
(end)
Author(s):
Ansible2
---------------------------------------------------------------------------- */
scriptName "BLWK_fnc_spawnQueue_create";

params [
["_class","",[""]],
["_position",[],[objNull,[]]]
["_onManCreatedFunctionName","BLWK_fnc_standardWave_onManCreated",[""]],
];


// TODO: create man and add him to the mustkill array on the server

nil
6 changes: 5 additions & 1 deletion Functions/Queue/fn_spawnQueue_popAndCreate.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ Author(s):
---------------------------------------------------------------------------- */
scriptName "BLWK_fnc_spawnQueue_popAndCreate";

if (!isServer) exitWith {};

// check if queue is empty
private _queue = localNamespace getVariable ["BLWK_spawnQueue",[]];
if (_queue isEqualTo []) exitWith {};

(_queue deleteAt 0) params ["_type","_position","_onManCreatedFunctionName"];
private _spawnArgs = _queue deleteAt 0;
_spawnArgs remoteExecCall ["BLWK_fnc_spawnQueue_create",BLWK_theAIHandlerOwnerID];
// params ["_type","_position","_onManCreatedFunctionName"]
142 changes: 46 additions & 96 deletions Functions/Wave Type Libraries/Common Wave Library/fn_wave_create.sqf
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
/* ----------------------------------------------------------------------------
Function: BLWK_fnc_wave_create
Description:
Takes the first entry in the enemy man spawn queue, removes the item and then
spawns the unit from the arguments.
Parameters:
0: _waveConfig <CONFIG> - The config path of the wave to create
1: _totalNumEnemiesToSpawnDuringWave <NUMBER> - The total number of enemies to spawn during the wave.
If less than `1`, the number will be automatically calculated.
Returns:
NOTHING
Examples:
(begin example)
[
missionConfigFile >> "BLWK_waveTypes" >> "normalWaves" >> "standardWave"
] call BLWK_fnc_wave_create;
(end)
Author(s):
Ansible2
---------------------------------------------------------------------------- */
scriptName "BLWK_fnc_wave_create";

// if (clientOwner isNotEqualTo BLWK_theAIHandlerOwnerID) exitWith {
Expand All @@ -16,77 +40,19 @@ scriptName "BLWK_fnc_wave_create";
// };

// #define DEFAULT_ON_WAVE_SELECTED_NAME "BLWK_fnc_standardWave_onWaveSelected"
#define DEFAULT_WAVE_CONFIG_PATH missionConfigFile >> "BLWK_waveTypes" >> "normalWaves" >> "standardWave"
#define SPECIAL_WAVE_CONFIG missionConfigFile >> "BLWK_waveTypes" >> "specialWaves"
#define BASE_ENEMY_NUMBER 2

params [
["_waveConfig",configNull,[configNull]],
["_totalNumEnemiesToSpawnDuringWave",-1,[123]]
];

// private _onWaveSelectedFunction = missionNamespace getVariable [_onWaveSelectedFunctionName,{}];
// if (_waveConfig isEqualTo configNull) exitWith {
// private _message = [
// "Could not find onWaveSelected function with the name: ",
// _onWaveSelectedFunction,
// " on the server! Using standard Wave..."
// ] joinString "";

// [_message,10] remoteExecCall ["KISKA_fnc_errorNotification",0];
// [_message,true] remoteExecCall ["KISKA_fnc_log",2];

// [DEFAULT_ON_WAVE_SELECTED_NAME] call BLWK_fnc_wave_create;
// };

private _notifyOfError = {
params ["_message"];

[_message] remoteExec ["BLWK_fnc_notifyAdminsOrHostOfError",0];
[_message,true] call KISKA_fnc_log;
};

private _fn_getFunctionFromWaveConfig = {
params [
"_configProperty",
["_justName",false]
];

private _requestedFunctionName = getText(_waveConfig >> _configProperty);
private _default_functionName = getText(DEFAULT_WAVE_CONFIG_PATH >> _configProperty);
if (_requestedFunctionName isEqualTo "") then {
_requestedFunctionName = _default_functionName
};

private _requestedFunction = missionNamespace getVariable [
_requestedFunctionName,
{}
];
if (_requestedFunction isEqualTo {}) then {
private _message = [
"Could not find function for property: ",
_configProperty,
" with the name: ",
_requestedFunctionName,
" on the server in config: ",
_waveConfig
] joinString "";
[_message] call _notifyOfError;

_requestedFunction = missionNamespace getVariable _default_functionName;
};


if (_justName) exitWith { _requestedFunctionName };
_requestedFunction
};


/* ----------------------------------------------------------------------------
Create Queue
---------------------------------------------------------------------------- */
private _generatManClassesFunction = ["generateMenClassnames"] call _fn_getFunctionFromWaveConfig;
private _generateSpawnPositionFunction = ["generateManSpawnPosition"] call _fn_getFunctionFromWaveConfig;
private _generatManClassesFunction = ["generateMenClassnames"] call BLWK_fnc_waves_getFunctionFromConfig;
private _generateSpawnPositionFunction = ["generateManSpawnPosition"] call BLWK_fnc_waves_getFunctionFromConfig;

if (_totalNumEnemiesToSpawnDuringWave < BASE_ENEMY_NUMBER) then {
_totalNumEnemiesToSpawnDuringWave = BASE_ENEMY_NUMBER * ((BLWK_enemiesPerWaveMultiplier * BLWK_currentWaveNumber) + 1);
Expand All @@ -100,7 +66,7 @@ if (!BLWK_multipleEnemyPositions) then {
_spawnPosition_temp = selectRandom BLWK_infantrySpawnPositions;
};

private _onManCreatedFunctionName = ["generateManSpawnPosition",true] call _fn_getFunctionFromWaveConfig;
private _onManCreatedFunctionName = ["generateManSpawnPosition",true] call BLWK_fnc_waves_getFunctionFromConfig;
for "_i" from 1 to _totalNumEnemiesToSpawnDuringWave do {
if (BLWK_multipleEnemyPositions) then {
_spawnPosition_temp = call _generateSpawnPositionFunction;
Expand All @@ -111,51 +77,35 @@ for "_i" from 1 to _totalNumEnemiesToSpawnDuringWave do {
_class,
_spawnPosition_temp,
_onManCreatedFunctionName
] call BLWK_fnc_addToQueue;
] call BLWK_fnc_spawnQueue_add;
};


/* ----------------------------------------------------------------------------
Send wave start notification
---------------------------------------------------------------------------- */
private _notification = [];
_notification pushBack (getText(_waveConfigPath >> "creationNotificationTemplate"));

private _notificationText = getText(_waveConfigPath >> "notificationText");
if ([_waveConfigPath >> "compileNotificationText"] call BIS_fnc_getCfgDataBool) then {
_notificationText = call compileFinal _notificationText;

} else {
_notificationText = [_notificationText];
// TODO: spawn enemies

// spawn the enemies for wave start
private _numStartingEnemies = BLWK_maxEnemyInfantryAtOnce;
private _spawnQueueCount = count (missionNamespace getVariable [STANDARD_ENEMY_INFANTRY_QUEUE,[]]);
if (_spawnQueueCount < BLWK_maxEnemyInfantryAtOnce) then {
_numStartingEnemies = _spawnQueueCount;
};
_notification pushBack _notificationText;


private _players = call CBAP_fnc_players;
_notification remoteExec ["BIS_fnc_showNotification", _players];
// play a sound for special waves
private _isSpecialWave = [_waveConfigPath,SPECIAL_WAVE_CONFIG] call CBAP_fnc_inheritsFrom;
if (_isSpecialWave) then {
["Alarm"] remoteExec ["playSound", _players];
private _unit = objNull;
private _units = [];
for "_i" from 1 to _numStartingEnemies do {
_unit = [STANDARD_ENEMY_INFANTRY_QUEUE,"_this call BLWK_fnc_stdEnemyManCreateCode"] call BLWK_fnc_createFromQueue;
_units pushBack _unit;
};

// TODO:
// need to create base enemy units
// server needs to know when all units are dead to end the wave
// server needs to know that wave has started (e.g. initial enemies have spawned)


// Wave types determine how to create enemies to a point
// Things the ai owner cares about:
// 1. where is the guy spawning
// 2. what type is he
// 3. what code should I run on his creation?

// [] remoteExecCall ["BLWK_fnc_onWaveEnemiesSpawned",2];

/* ----------------------------------------------------------------------------
Activate Initialization
---------------------------------------------------------------------------- */
localNamespace setVariable ["BLWK_currentWaveConfig",_waveConfig];
[_waveConfig] spawn {
// TODO: wait for enemies spawned from ai handler owner
};

localNamespace setVariable ["BLWK_currentWaveConfig",_waveConfigPath];

nil

Expand Down
40 changes: 1 addition & 39 deletions Functions/Waves/fn_startWave.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ if (_clearDroppedItems) then {
---------------------------------------------------------------------------- */
private _previousWaveNum = missionNamespace getVariable ["BLWK_currentWaveNumber",0];
missionNamespace setVariable ["BLWK_currentWaveNumber", _previousWaveNum + 1,true];

missionNamespace setVariable ["BLWK_inBetweenWaves",false,true];
missionNamespace setVariable ["BLWK_initialWaveSpawnComplete",false];


/* ----------------------------------------------------------------------------
Expand All @@ -75,43 +73,7 @@ if (missionNamespace getVariable ["BLWK_extractionQueued",false]) then {
};


/* ----------------------------------------------------------------------------
Clean Dead
---------------------------------------------------------------------------- */
call BLWK_fnc_cleanUpTheDead;


/* ----------------------------------------------------------------------------
Make sure enemies have spawned
---------------------------------------------------------------------------- */
// check to make sure there are actually units inside the wave array before looping
// or that all initial units are spawned
waitUntil {
if (
missionNamespace getVariable ["BLWK_initialWaveSpawnComplete",false] OR
{(call BLWK_fnc_getMusKillList) isNotEqualTo []}
) exitWith {true};
sleep 1;
false
};


// log wave
[["Start Wave: ",BLWK_currentWaveNumber],false] call KISKA_fnc_log;

// invoke wave start event
[missionNamespace,"BLWK_onWaveStart"] remoteExecCall ["BIS_fnc_callScriptedEventHandler",0];


/* ----------------------------------------------------------------------------
Check for wave end
---------------------------------------------------------------------------- */
waitUntil {
if (call BLWK_fnc_isWaveCleared) exitWith {
[] spawn BLWK_fnc_endWave;
true
};

sleep 3;
false
};
nil
74 changes: 74 additions & 0 deletions Functions/Waves/fn_waves_getFunctionFromConfig.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/* ----------------------------------------------------------------------------
Function: BLWK_fnc_waves_getFunctionFromConfig
Description:
Intellegently finds the code for a given config property in a wave config.
Will fill in with the standard wave defaults and notify users of certain errors.
Parameters:
0: _waveConfig <CONFIG> - The config path of the wave to get the property from
1: _configProperty <STRING> - The name of the code property to find in the config
2: _justName <BOOL> - If true, only the string name of the function will be returned
Returns:
<STRING | CODE> - either returns the name of a function or the code associated with that name
Examples:
(begin example)
private _code = [
missionConfigFile >> "BLWK_waveTypes" >> "normalWaves" >> "standardWave",
"generateMenClassnames"
] call BLWK_fnc_waves_getFunctionFromConfig;
(end)
(begin example)
private _functionName = [
missionConfigFile >> "BLWK_waveTypes" >> "normalWaves" >> "standardWave",
"generateMenClassnames",
true
] call BLWK_fnc_waves_getFunctionFromConfig;
(end)
Author(s):
Ansible2
---------------------------------------------------------------------------- */
scriptName "BLWK_fnc_waves_getFunctionFromConfig";

#define DEFAULT_WAVE_CONFIG_PATH missionConfigFile >> "BLWK_waveTypes" >> "normalWaves" >> "standardWave"

params [
["_waveConfig",configNull,[configNull]],
["_configProperty","",""],
["_justName",false,[true]]
];

private _requestedFunctionName = getText(_waveConfig >> _configProperty);
private _default_functionName = getText(DEFAULT_WAVE_CONFIG_PATH >> _configProperty);
if (_requestedFunctionName isEqualTo "") then {
_requestedFunctionName = _default_functionName
};

private _requestedFunction = missionNamespace getVariable [
_requestedFunctionName,
{}
];
if (_requestedFunction isEqualTo {}) then {
private _message = [
"Could not find function for property: ",
_configProperty,
" with the name: ",
_requestedFunctionName,
" on the server in config: ",
_waveConfig
] joinString "";

[_message] remoteExec ["BLWK_fnc_notifyAdminsOrHostOfError",0];
[_message,true] call KISKA_fnc_log;

_requestedFunction = missionNamespace getVariable _default_functionName;
};


if (_justName) exitWith { _requestedFunctionName };
_requestedFunction
Loading

0 comments on commit 9a7b17e

Please sign in to comment.