diff --git a/Functions/Queue/fn_spawnQueue_add.sqf b/Functions/Queue/fn_spawnQueue_add.sqf index fccd4b9d..608ba289 100644 --- a/Functions/Queue/fn_spawnQueue_add.sqf +++ b/Functions/Queue/fn_spawnQueue_add.sqf @@ -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 : - The classname of the unit you want to add to the queue diff --git a/Functions/Queue/fn_spawnQueue_create.sqf b/Functions/Queue/fn_spawnQueue_create.sqf new file mode 100644 index 00000000..c4bc05eb --- /dev/null +++ b/Functions/Queue/fn_spawnQueue_create.sqf @@ -0,0 +1,37 @@ +/* ---------------------------------------------------------------------------- +Function: BLWK_fnc_spawnQueue_create + +Description: + Creates a unit for the wave based upon the args provided. + +Parameters: + 0: _class : - The classname of the unit you want to add to the queue + 1: _position : - The position to spawn the unit at + 2: _onManCreatedFunctionName : - 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 diff --git a/Functions/Queue/fn_spawnQueue_popAndCreate.sqf b/Functions/Queue/fn_spawnQueue_popAndCreate.sqf index c3fa25c8..476e6662 100644 --- a/Functions/Queue/fn_spawnQueue_popAndCreate.sqf +++ b/Functions/Queue/fn_spawnQueue_popAndCreate.sqf @@ -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"] \ No newline at end of file diff --git a/Functions/Wave Type Libraries/Common Wave Library/fn_wave_create.sqf b/Functions/Wave Type Libraries/Common Wave Library/fn_wave_create.sqf index 011f0c5e..ad13580f 100644 --- a/Functions/Wave Type Libraries/Common Wave Library/fn_wave_create.sqf +++ b/Functions/Wave Type Libraries/Common Wave Library/fn_wave_create.sqf @@ -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 - The config path of the wave to create + 1: _totalNumEnemiesToSpawnDuringWave - 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 { @@ -16,8 +40,6 @@ 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 [ @@ -25,68 +47,12 @@ params [ ["_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); @@ -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; @@ -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 diff --git a/Functions/Waves/fn_startWave.sqf b/Functions/Waves/fn_startWave.sqf index dd75e7d0..6d038509 100644 --- a/Functions/Waves/fn_startWave.sqf +++ b/Functions/Waves/fn_startWave.sqf @@ -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]; /* ---------------------------------------------------------------------------- @@ -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 diff --git a/Functions/Waves/fn_waves_getFunctionFromConfig.sqf b/Functions/Waves/fn_waves_getFunctionFromConfig.sqf new file mode 100644 index 00000000..2375eae2 --- /dev/null +++ b/Functions/Waves/fn_waves_getFunctionFromConfig.sqf @@ -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 - The config path of the wave to get the property from + 1: _configProperty - The name of the code property to find in the config + 2: _justName - If true, only the string name of the function will be returned + +Returns: + - 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 diff --git a/Functions/Waves/fn_waves_onInitialized.sqf b/Functions/Waves/fn_waves_onInitialized.sqf new file mode 100644 index 00000000..f93db56f --- /dev/null +++ b/Functions/Waves/fn_waves_onInitialized.sqf @@ -0,0 +1,63 @@ +/* ---------------------------------------------------------------------------- +Function: BLWK_fnc_waves_onInitialized + +Description: + Activates some basic events after a wave has been fully initialized. + + Meaning that the initial group of units has been spawned. + +Parameters: + 0: _waveConfig - The config path of the wave that was created + +Returns: + NOTHING + +Examples: + (begin example) + [ + missionConfigFile >> "BLWK_waveTypes" >> "normalWaves" >> "standardWave" + ] call BLWK_fnc_waves_onInitialized; + (end) + +Author(s): + Ansible2 +---------------------------------------------------------------------------- */ +scriptName "BLWK_fnc_waves_onInitialized"; + +#define SPECIAL_WAVE_CONFIG missionConfigFile >> "BLWK_waveTypes" >> "specialWaves" + +if (!isServer) exitWith {}; + +params [ + ["_waveConfigPath",configNull,[configNull]] +]; + +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]; +}; +_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]; +}; + + + +[["Start Wave: ",BLWK_currentWaveNumber],false] call KISKA_fnc_log; + +[missionNamespace,"BLWK_onWaveStart"] remoteExecCall ["BIS_fnc_callScriptedEventHandler",0]; + + +nil diff --git a/Headers/descriptionEXT/functions.hpp b/Headers/descriptionEXT/functions.hpp index aa01c863..d1894021 100644 --- a/Headers/descriptionEXT/functions.hpp +++ b/Headers/descriptionEXT/functions.hpp @@ -530,6 +530,11 @@ class BLWK class Waves { file = "Functions\Waves"; + class waves_getFunctionFromConfig + {}; + class waves_onInitialized + {}; + class addToMustKillList {}; class cacheEnemyMenSpawnPositions