From 3e6fc52733d4bd9c27d7671b4274c7169a8856df Mon Sep 17 00:00:00 2001 From: VKing Date: Wed, 16 Dec 2015 20:22:18 +0100 Subject: [PATCH] First working iteration. Todo: Implement in module (Choose new or old/don't break old missions) Magazine UI+model Add preparing delay Fix function readmes Cleanup in functions? Credits MP Testing --- addons/mk6mortar/CfgEventHandlers.hpp | 2 +- addons/mk6mortar/CfgVehicles.hpp | 76 +++++++++++++------ addons/mk6mortar/CfgWeapons.hpp | 1 + addons/mk6mortar/XEH_clientInit.sqf | 21 +++++ addons/mk6mortar/XEH_preInit.sqf | 4 + addons/mk6mortar/cfgMagazines.hpp | 43 +++++++++-- addons/mk6mortar/config.cpp | 3 +- .../functions/fnc_canLoadMagazine.sqf | 55 ++++++++++++++ .../functions/fnc_canUnloadMagazine.sqf | 29 +++++++ .../mk6mortar/functions/fnc_loadMagazine.sqf | 66 ++++++++++++++++ .../functions/fnc_unloadMagazine.sqf | 38 ++++++++++ addons/mk6mortar/stringtable.xml | 28 +++++-- 12 files changed, 329 insertions(+), 37 deletions(-) create mode 100644 addons/mk6mortar/functions/fnc_canLoadMagazine.sqf create mode 100644 addons/mk6mortar/functions/fnc_canUnloadMagazine.sqf create mode 100644 addons/mk6mortar/functions/fnc_loadMagazine.sqf create mode 100644 addons/mk6mortar/functions/fnc_unloadMagazine.sqf diff --git a/addons/mk6mortar/CfgEventHandlers.hpp b/addons/mk6mortar/CfgEventHandlers.hpp index 34c6ecc22c..a4aee88a22 100644 --- a/addons/mk6mortar/CfgEventHandlers.hpp +++ b/addons/mk6mortar/CfgEventHandlers.hpp @@ -5,7 +5,7 @@ class Extended_PreInit_EventHandlers { }; class Extended_PostInit_EventHandlers { class ADDON { - clientInit = QUOTE( call COMPILE_FILE(XEH_clientInit) ); + clientInit = QUOTE(call COMPILE_FILE(XEH_clientInit)); }; }; class Extended_FiredBIS_EventHandlers { diff --git a/addons/mk6mortar/CfgVehicles.hpp b/addons/mk6mortar/CfgVehicles.hpp index 97d3d1ec01..d09c54c1b4 100644 --- a/addons/mk6mortar/CfgVehicles.hpp +++ b/addons/mk6mortar/CfgVehicles.hpp @@ -20,11 +20,15 @@ class CfgVehicles { class Turrets { class MainTurret; }; + class ACE_Actions; }; class StaticMortar: StaticWeapon { class Turrets: Turrets { class MainTurret: MainTurret {}; }; + class ACE_Actions: ACE_Actions { + class ACE_MainActions; + }; }; class Mortar_01_base_F: StaticMortar { class Turrets: Turrets { @@ -34,36 +38,58 @@ class CfgVehicles { discreteDistanceInitIndex = 0; }; }; - class ACE_Actions { - class ACE_MainACtions { + class ACE_Actions: ACE_Actions { + class GVAR(unloadMagazine) { + displayName = CSTRING(unloadMagazine); + distance = 4; + condition = QUOTE([ARR_2(_player,_target)] call FUNC(canUnloadMagazine)); + statement = QUOTE([ARR_2(_player,_target)] call FUNC(unloadMagazine)); + icon = ""; + selection = "usti hlavne"; + }; + class GVAR(LoadActions) { + displayName = CSTRING(loadMortar); + distance = 4; + condition = QUOTE([ARR_2(_player,_target)] call FUNC(canLoadMagazine)); + statement = ""; + icon = ""; + selection = "usti hlavne"; + class GVAR(loadMagazine_HE_Guided) { + displayName = CSTRING(loadMagazine_HE_Guided); + distance = 4; + condition = QUOTE([ARR_3(_player,_target,'ACE_1Rnd_82mm_Mo_HE_Guided')] call FUNC(canLoadMagazine)); + statement = QUOTE([ARR_3(_player,_target,'ACE_1Rnd_82mm_Mo_HE_Guided')] call FUNC(loadMagazine)); + icon = ""; + }; + class GVAR(loadMagazine_HE_LaserGuided) { + displayName = CSTRING(loadMagazine_HE_LaserGuided); + distance = 4; + condition = QUOTE([ARR_3(_player,_target,'ACE_1Rnd_82mm_Mo_HE_LaserGuided')] call FUNC(canLoadMagazine)); + statement = QUOTE([ARR_3(_player,_target,'ACE_1Rnd_82mm_Mo_HE_LaserGuided')] call FUNC(loadMagazine)); + icon = ""; + }; + class GVAR(loadMagazine_Illum) { + displayName = CSTRING(loadMagazine_Illum); + distance = 4; + condition = QUOTE([ARR_3(_player,_target,'ACE_1Rnd_82mm_Mo_Illum')] call FUNC(canLoadMagazine)); + statement = QUOTE([ARR_3(_player,_target,'ACE_1Rnd_82mm_Mo_Illum')] call FUNC(loadMagazine)); + icon = ""; + }; + class GVAR(loadMagazine_Smoke) { + displayName = CSTRING(loadMagazine_Smoke); + distance = 4; + condition = QUOTE([ARR_3(_player,_target,'ACE_1Rnd_82mm_Mo_Smoke')] call FUNC(canLoadMagazine)); + statement = QUOTE([ARR_3(_player,_target,'ACE_1Rnd_82mm_Mo_Smoke')] call FUNC(loadMagazine)); + icon = ""; + }; class GVAR(loadMagazine_HE) { displayName = CSTRING(loadMagazine_HE); distance = 4; - condition = QUOTE([ARR_2(_player,_target)] call FUNC(canLoadMagazine)); - statement = QUOTE([ARR_3(_player,_target,'HE')] call FUNC(loadMagazine)); - icon = ""; - class GVAR(loadMagazine_Smoke) { - displayName = CSTRING(loadMagazine_Smoke); - distance = 4; - condition = QUOTE([ARR_3(_player,_target,'Smoke')] call FUNC(canLoadMagazine)); - statement = QUOTE([ARR_3(_player,_target,'Smoke')] call FUNC(loadMagazine)); - icon = ""; - }; - class GVAR(loadMagazine_Illum) { - displayName = CSTRING(loadMagazine_Illum); - distance = 4; - condition = QUOTE([ARR_3(_player,_target,'Illum')] call FUNC(canLoadMagazine)); - statement = QUOTE([ARR_3(_player,_target,'Illum')] call FUNC(loadMagazine)); - icon = ""; - }; - }; - class GVAR(unloadMagazine) { - displayName = CSTRING(unloadMagazine); - distance = 4; - condition = QUOTE([ARR_2(_player,_target)] call FUNC(canUnloadMagazine)); - statement = QUOTE([ARR_2(_player,_target)] call FUNC(unloadMagazine)); + condition = QUOTE([ARR_3(_player,_target,'ACE_1Rnd_82mm_Mo_HE')] call FUNC(canLoadMagazine)); + statement = QUOTE([ARR_3(_player,_target,'ACE_1Rnd_82mm_Mo_HE')] call FUNC(loadMagazine)); icon = ""; }; + }; }; class ACE_SelfActions { class GVAR(toggleMils) { diff --git a/addons/mk6mortar/CfgWeapons.hpp b/addons/mk6mortar/CfgWeapons.hpp index b3d6bcd440..f535840e99 100644 --- a/addons/mk6mortar/CfgWeapons.hpp +++ b/addons/mk6mortar/CfgWeapons.hpp @@ -18,6 +18,7 @@ class CfgWeapons { class Single1; }; class ACE_mortar_82mm: mortar_82mm { + author = ECSTRING(common,ACETeam); magazines[] = {"ACE_1Rnd_82mm_Mo_HE","ACE_1Rnd_82mm_Mo_Smoke","ACE_1Rnd_82mm_Mo_Illum", "ACE_1Rnd_82mm_Mo_HE_Guided","ACE_1Rnd_82mm_Mo_HE_LaserGuided"}; modes[] = {"Single1","Single2","Single3"}; diff --git a/addons/mk6mortar/XEH_clientInit.sqf b/addons/mk6mortar/XEH_clientInit.sqf index cde5277260..3937e11f0e 100644 --- a/addons/mk6mortar/XEH_clientInit.sqf +++ b/addons/mk6mortar/XEH_clientInit.sqf @@ -4,3 +4,24 @@ if (!hasInterface) exitWith {}; ["playerVehicleChanged", {_this call FUNC(handlePlayerVehicleChanged);}] call EFUNC(common,addEventHandler); ["infoDisplayChanged", {_this call FUNC(turretDisplayLoaded);}] call EFUNC(common,addEventHandler); + +[QGVAR(addMagazine), { + params ["_static", "_magazine"]; + + _static addMagazineTurret [_magazine,[0]]; + +}] call EFUNC(common,addEventHandler); + +[QGVAR(removeMagazine), { + params ["_static", "_magazine"]; + + _static removeMagazineTurret [_magazine,[0]]; + +}] call EFUNC(common,addEventHandler); + +[QGVAR(setAmmo), { + params ["_static", "_magazine","_ammoCount"]; + + _static setMagazineTurretAmmo [_magazine, _ammoCount, [0]]; + +}] call EFUNC(common,addEventHandler); diff --git a/addons/mk6mortar/XEH_preInit.sqf b/addons/mk6mortar/XEH_preInit.sqf index 9af89ccb35..b892760673 100644 --- a/addons/mk6mortar/XEH_preInit.sqf +++ b/addons/mk6mortar/XEH_preInit.sqf @@ -8,8 +8,11 @@ PREP(dev_simulateCalcRangeTableLine); PREP(dev_simulateFindSolution); PREP(dev_simulateShot); +PREP(canLoadMagazine); +PREP(canUnloadMagazine); PREP(handleFired); PREP(handlePlayerVehicleChanged); +PREP(loadMagazine); PREP(moduleInit); PREP(rangeTableCanUse); PREP(rangeTableOpen); @@ -17,5 +20,6 @@ PREP(rangeTablePageChange); PREP(rangeTablePreCalculatedValues); PREP(toggleMils); PREP(turretDisplayLoaded); +PREP(unloadMagazine); ADDON = true; diff --git a/addons/mk6mortar/cfgMagazines.hpp b/addons/mk6mortar/cfgMagazines.hpp index 7075d2310e..939f21c3a2 100644 --- a/addons/mk6mortar/cfgMagazines.hpp +++ b/addons/mk6mortar/cfgMagazines.hpp @@ -1,32 +1,65 @@ + // Artificially low for testing +#DEFINE __MASS = 10 + class cfgMagazines { class 8Rnd_82mm_Mo_shells; class ACE_1Rnd_82mm_Mo_HE: 8Rnd_82mm_Mo_shells { count = 1; + scope = 2; + scopeCurator = 2; + author = ECSTRING(common,ACETeam); displayName = CSTRING(magazine_HE_displayName); - // Infantry-carry stuff here + descriptionShort = CSTRING(magazine_HE_descriptionShort); + model = ""; + picture = ""; + mass = __MASS; }; class 8Rnd_82mm_Mo_Smoke_white; class ACE_1Rnd_82mm_Mo_Smoke: 8Rnd_82mm_Mo_Smoke_white { count = 1; + scope = 2; + scopeCurator = 2; + author = ECSTRING(common,ACETeam); displayName = CSTRING(magazine_Smoke_displayName); - + descriptionShort = CSTRING(magazine_Smoke_descriptionShort); + model = ""; + picture = ""; + mass = __MASS; }; class 8Rnd_82mm_Mo_Flare_white; class ACE_1Rnd_82mm_Mo_Illum: 8Rnd_82mm_Mo_Flare_white { count = 1; + scope = 2; + scopeCurator = 2; + author = ECSTRING(common,ACETeam); displayName = CSTRING(magazine_Illum_displayName); - + descriptionShort = CSTRING(magazine_Illum_descriptionShort); + model = ""; + picture = ""; + mass = __MASS; }; class 8Rnd_82mm_Mo_guided; class ACE_1Rnd_82mm_Mo_HE_Guided: 8Rnd_82mm_Mo_guided { count = 1; + scope = 2; + scopeCurator = 2; + author = ECSTRING(common,ACETeam); displayName = CSTRING(magazine_HE_Guided_displayName); - + descriptionShort = CSTRING(magazine_HE_Guided_descriptionShort); + model = ""; + picture = ""; + mass = __MASS; }; class 8Rnd_82mm_Mo_LG; class ACE_1Rnd_82mm_Mo_HE_LaserGuided: 8Rnd_82mm_Mo_LG { count = 1; + scope = 2; + scopeCurator = 2; + author = ECSTRING(common,ACETeam); displayName = CSTRING(magazine_HE_LaserGuided_displayName); - + descriptionShort = CSTRING(magazine_HE_LaserGuided_descriptionShort); + model = ""; + picture = ""; + mass = __MASS; }; }; diff --git a/addons/mk6mortar/config.cpp b/addons/mk6mortar/config.cpp index 8a54d15a5b..52a9ac2347 100644 --- a/addons/mk6mortar/config.cpp +++ b/addons/mk6mortar/config.cpp @@ -3,7 +3,7 @@ class CfgPatches { class ADDON { units[] = {}; - weapons[] = {"ACE_RangeTable_82mm"}; + weapons[] = {"ACE_RangeTable_82mm","ace_mortar_82mm"}; requiredVersion = REQUIRED_VERSION; requiredAddons[] = {"ace_interaction"}; author[] = {"PabstMirror"}; @@ -16,6 +16,7 @@ class CfgPatches { #include "CfgEventHandlers.hpp" #include "CfgVehicles.hpp" #include "CfgWeapons.hpp" +#include "CfgMagazines.hpp" //UI Stuff: diff --git a/addons/mk6mortar/functions/fnc_canLoadMagazine.sqf b/addons/mk6mortar/functions/fnc_canLoadMagazine.sqf new file mode 100644 index 0000000000..67aa2cdf2b --- /dev/null +++ b/addons/mk6mortar/functions/fnc_canLoadMagazine.sqf @@ -0,0 +1,55 @@ +/* + * Author: Grey + * Checks whether magazine can be loaded into static weapon + * + * Arguments: + * 0: static + * 1: unit + * 2: magazineClassOptional + * + * Return Value: + * canLoadMagazine + * + * Example: + * [_target,_player,'16aa_static_magazine_1Rnd_105mm_HE'] call lsr_staticweapons_canLoadMagazine + * + * Public: Yes + */ + +#include "script_component.hpp" + +params ["_unit","_static",["_magazineClassOptional","",[""]]]; +private ["_canLoadMagazine","_currentMagazine","_weapon","_magazines","_listOfMagNames", + "_hasCompatibleMagazine","_count"]; + +if !(alive _static) exitWith {false}; + +_canLoadMagazine = false; + +_currentMagazine = (magazinesAllTurrets _static) select 1; +_weapon = (_static weaponsTurret [0]) select 0; + +_magazines = magazines _unit; +_listOfMagNames = getArray(configFile >> "cfgWeapons" >> _weapon >> "magazines"); +_hasCompatibleMagazine = false; +_count = 0; + +//If function is called with an optional string then check if player has that magzine otherwise check all magazines of the player to see if they are compatible with the static weapon +if (_magazineClassOptional != "") then { + if ([_unit,_magazineClassOptional] call EFUNC(common,hasMagazine)) then { + _hasCompatibleMagazine = true; + }; +}else{ + { + if ([_unit,_x] call EFUNC(common,hasMagazine)) exitWith {_hasCompatibleMagazine = true;}; + } forEach _listOfMagNames; +}; +//If static weapon has a magazine then find the ammo count +if ((count (_static magazinesTurret [0])) > 0)then{ + _count = _currentMagazine select 2; +}; +//If the static weapon doesn't have a magzine or a magazine with no bullets, the player has a compatible magazine and the static weapon has a barrel then you can load a magazine +if ( ( ((count (_static magazinesTurret [0])) == 0) || (_count == 0) ) && _hasCompatibleMagazine) then { + _canLoadMagazine = true; +}; +_canLoadMagazine diff --git a/addons/mk6mortar/functions/fnc_canUnloadMagazine.sqf b/addons/mk6mortar/functions/fnc_canUnloadMagazine.sqf new file mode 100644 index 0000000000..9a2afac32a --- /dev/null +++ b/addons/mk6mortar/functions/fnc_canUnloadMagazine.sqf @@ -0,0 +1,29 @@ +/* + * Author: Grey + * Checks whether magazine can be unloaded from static weapon + * + * Arguments: + * 0: static + * 1: unit + * + * Return Value: + * canUnloadMagazine + * + * Example: + * [_target,_player] call lsr_staticweapons_canUnloadMagazine + * + * Public: Yes + */ +#include "script_component.hpp" + +params ["_unit","_static"]; +private ["_canUnloadMagazine","_ammoCount"]; + +if !(alive _static) exitWith {false}; +_canUnloadMagazine = false; + +_ammoCount = ((magazinesAllTurrets _static) select 1) select 2; +if (_ammoCount > 0) then { + _canUnloadMagazine = true; +}; +_canUnloadMagazine diff --git a/addons/mk6mortar/functions/fnc_loadMagazine.sqf b/addons/mk6mortar/functions/fnc_loadMagazine.sqf new file mode 100644 index 0000000000..d5a0436cf4 --- /dev/null +++ b/addons/mk6mortar/functions/fnc_loadMagazine.sqf @@ -0,0 +1,66 @@ +/* + * Author: Grey + * Loads Magazine into static weapon + * + * Arguments: + * 0: static + * 1: unit + * 2: magazineClassOptional + * + * Return Value: + * None + * + * Example: + * [_target,_player,'16aa_static_magazine_l16_illum'] call lsr_staticweapons_loadMagazine + * + * Public: Yes + */ +#include "script_component.hpp" + +params ["_unit","_static",["_magazineClassOptional","",[""]]]; +private ["_weapon","_currentMagazine","_count","_magazines","_magazineDetails","_listOfMagNames", + "_magazineClass","_magazineClassDetails","_parsed","_roundsLeft","_configMortar"]; + +//Get weapon & magazine information of static weapon +_weapon = (_static weaponsTurret [0]) select 0; +_currentMagazine = (magazinesAllTurrets _static) select 1; +_currentMagazineClass = _currentMagazine select 0; +_count = _currentMagazine select 2; + +//Check all of the players magazines to see if they are compatible with the static weapon. First magazine that is compatible is chosen +_magazines = magazines _unit; +_magazineDetails = magazinesDetail _unit; +_listOfMagNames = getArray(configFile >> "cfgWeapons" >> _weapon >> "magazines"); +_magazineClass = ""; +_magazineClassDetails = ""; +_parsed =""; +_roundsLeft = 0; +{ + if (_x in _listOfMagNames) exitWith { + _magazineClass = _magazines select _forEachIndex; + _magazineClassDetails = _magazineDetails select _forEachIndex; + }; +} forEach _magazines; +//If the static weapon already has an empty magazine then remove it +if (_count == 0) then { + [QGVAR(removeMagazine), [_static, _currentMagazineClass]] call EFUNC(common,globalEvent); +}; +//Find out the ammo count of the compatible magazine found +if (_magazineClassDetails != "") then{ + _parsed = _magazineClassDetails splitString "([]/: )"; + _parsed params ["_type", "", "", "_roundsLeftText", "_maxRoundsText"]; + _roundsLeft = parseNumber _roundsLeftText; + _roundsMax = parseNumber _maxRoundsText; + _magType = _type; +}; + +//_configMortar = getNumber (configFile >> "CfgMagazines" >> _magazineClass >> QGVAR(isMortarRound)); +//If function has been called with an optional classname hten add that magazine to the static weapon. Otherwise add the compatible magazine +if(_magazineClassOptional !="") then{ + _unit removeMagazine _magazineClassOptional; + [QGVAR(addMagazine), [_static, _magazineClassOptional]] call EFUNC(common,globalEvent); + }else{ + _unit removeMagazine _magazineClass; + [QGVAR(addMagazine), [_static, _magazineClass]] call EFUNC(common,globalEvent); + [QGVAR(setAmmo), _static, [_static, _magazineClass,_roundsLeft]] call EFUNC(common,targetEvent); + }; diff --git a/addons/mk6mortar/functions/fnc_unloadMagazine.sqf b/addons/mk6mortar/functions/fnc_unloadMagazine.sqf new file mode 100644 index 0000000000..fba5e56c58 --- /dev/null +++ b/addons/mk6mortar/functions/fnc_unloadMagazine.sqf @@ -0,0 +1,38 @@ +/* + * Author: Grey + * + * Unload current magazine from static weapon + * + * Arguments: + * 0: static + * 1: unit + * + * Return Value: + * None + * + * Example: + * [_target, _player] call lsr_staticweapons_unloadMagazine + * + * Public: Yes + */ +#include "script_component.hpp" + +params ["_unit","_static"]; +private ["_weapon","_currentMagazine","_currentMagazineClass","_ammoCount"]; + +//Get weapon & magazine information about static weapon +_weapon = (_static weaponsTurret [0]) select 0; +_currentMagazine = (magazinesAllTurrets _static) select 1; +_currentMagazineClass = _currentMagazine select 0; +_ammoCount = _currentMagazine select 2; + +//If current magazine is empty then remove it otherwise remove it and add it to the players inventory +if (_ammoCount == 0) then { + [QGVAR(removeMagazine), [_static, _currentMagazineClass]] call EFUNC(common,globalEvent); +}else { + _pos = _unit modelToWorldVisual [0,1,0]; + _unit = createVehicle ["WeaponHolder_Single_F",_pos,[],0,"NONE"]; + _unit addMagazineAmmoCargo [_currentMagazineClass, 1, _ammoCount]; + _unit setPosATL _pos; + [QGVAR(removeMagazine), [_static, _currentMagazineClass]] call EFUNC(common,globalEvent); +}; diff --git a/addons/mk6mortar/stringtable.xml b/addons/mk6mortar/stringtable.xml index e36cf14e0c..49ad0016a1 100644 --- a/addons/mk6mortar/stringtable.xml +++ b/addons/mk6mortar/stringtable.xml @@ -135,20 +135,23 @@ Модуль настройки миномета MK6. Ce module permet de régler les options du mortier MK6 + + Load Mortar + - Load HE Round + Load HE - Load Smoke Round + Load Smoke - Load Illumination Round + Load Illumination - Load Guided HE Round + Load Guided HE - Load Laser Guided HE Round + Load Laser Guided HE Unload Round @@ -168,5 +171,20 @@ 82mm Laser Guided HE Round + + Used in Mk6 mortar + + + Used in Mk6 mortar + + + Used in Mk6 mortar + + + Used in Mk6 mortar + + + Used in Mk6 mortar +