Code cleanup of Disarming module

This commit is contained in:
jokoho48 2015-08-09 05:18:26 +02:00
parent 2b3c936e99
commit 156609aab2
12 changed files with 71 additions and 66 deletions

View File

@ -1,4 +1,4 @@
#include "script_component.hpp" #include "script_component.hpp"
["DisarmDropItems", {_this call FUNC(eventTargetStart)}] call EFUNC(common,addEventHandler); ["DisarmDropItems", FUNC(eventTargetStart)] call EFUNC(common,addEventHandler);
["DisarmDebugCallback", {_this call FUNC(eventCallerFinish)}] call EFUNC(common,addEventHandler); ["DisarmDebugCallback", FUNC(eventCallerFinish)] call EFUNC(common,addEventHandler);

View File

@ -1,5 +1,6 @@
/* /*
* Author: PabstMirror * Author: PabstMirror
*
* Checks the conditions for being able to disarm a unit * Checks the conditions for being able to disarm a unit
* *
* Arguments: * Arguments:
@ -15,17 +16,17 @@
*/ */
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_1(_target);
private ["_animationStateCfgMoves", "_putDownAnim"]; private ["_animationStateCfgMoves", "_putDownAnim"];
params ["_target"];
//Check animationState for putDown anim //Check animationState for putDown anim
//This ensures the unit doesn't have to actualy do any animation to drop something //This ensures the unit doesn't have to actualy do any animation to drop something
//This should always be true for the 3 possible status effects that allow disarming //This should always be true for the 3 possible status effects that allow disarming
_animationStateCfgMoves = getText (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState _target) >> "actions"); _animationStateCfgMoves = getText (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState _target) >> "actions");
if (_animationStateCfgMoves == "") exitWith {false}; if (_animationStateCfgMoves == "") exitWith { false };
_putDownAnim = getText (configFile >> "CfgMovesBasic" >> "Actions" >> _animationStateCfgMoves >> "PutDown"); _putDownAnim = getText (configFile >> "CfgMovesBasic" >> "Actions" >> _animationStateCfgMoves >> "PutDown");
if (_putDownAnim != "") exitWith {false}; if (_putDownAnim != "") exitWith { false };
(alive _target) && (alive _target) &&

View File

@ -1,5 +1,6 @@
/* /*
* Author: PabstMirror * Author: PabstMirror
*
* Checks the conditions for being able to disarm a unit * Checks the conditions for being able to disarm a unit
* *
* Arguments: * Arguments:
@ -16,7 +17,7 @@
*/ */
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_2(_player,_target); params ["_player", "_target"];
([_target] call FUNC(canBeDisarmed)) && ([_target] call FUNC(canBeDisarmed)) &&
{([_player, _target, []] call EFUNC(common,canInteractWith))} {([_player, _target, []] call EFUNC(common,canInteractWith))}

View File

@ -1,5 +1,6 @@
/* /*
* Author: PabstMirror * Author: PabstMirror
*
* Makes a unit drop items * Makes a unit drop items
* *
* Arguments: * Arguments:
@ -22,13 +23,11 @@
private ["_fncSumArray", "_return", "_holder", "_dropPos", "_targetMagazinesStart", "_holderMagazinesStart", "_xClassname", "_xAmmo", "_targetMagazinesEnd", "_holderMagazinesEnd", "_holderItemsStart", "_targetItemsStart", "_addToCrateClassnames", "_addToCrateCount", "_index", "_holderItemsEnd", "_targetItemsEnd", "_holderIsEmpty"]; private ["_fncSumArray", "_return", "_holder", "_dropPos", "_targetMagazinesStart", "_holderMagazinesStart", "_xClassname", "_xAmmo", "_targetMagazinesEnd", "_holderMagazinesEnd", "_holderItemsStart", "_targetItemsStart", "_addToCrateClassnames", "_addToCrateCount", "_index", "_holderItemsEnd", "_targetItemsEnd", "_holderIsEmpty"];
params ["_caller", "_target", "_listOfItemsToRemove", ["_doNotDropAmmo", false, [false]]]; //By default units drop all weapon mags when dropping a weapon
PARAMS_3(_caller,_target,_listOfItemsToRemove);
DEFAULT_PARAM(3,_doNotDropAmmo,false); //By default units drop all weapon mags when dropping a weapon
_fncSumArray = { _fncSumArray = {
_return = 0; _return = 0;
{_return = _return + _x;} forEach (_this select 0); {_return = _return + _x;} count (_this select 0);
_return _return
}; };
@ -48,7 +47,7 @@ if (!_doNotDropAmmo) then {
if ((_x getVariable [QGVAR(disarmUnit), objNull]) == _target) exitWith { if ((_x getVariable [QGVAR(disarmUnit), objNull]) == _target) exitWith {
_holder = _x; _holder = _x;
}; };
} forEach ((getpos _target) nearObjects [DISARM_CONTAINER, 3]); } count ((getpos _target) nearObjects [DISARM_CONTAINER, 3]);
}; };
//Create a new weapon holder //Create a new weapon holder
@ -124,7 +123,7 @@ _addToCrateCount = [];
_addToCrateCount pushBack 1; _addToCrateCount pushBack 1;
}; };
}; };
} forEach _targetItemsStart; } count _targetItemsStart;
//Add the items to the holder (combined to reduce addItemCargoGlobal calls) //Add the items to the holder (combined to reduce addItemCargoGlobal calls)
{ {

View File

@ -1,5 +1,6 @@
/* /*
* Author: PabstMirror * Author: PabstMirror
*
* Recieves a possible error code from FUNC(eventTargetFinish) * Recieves a possible error code from FUNC(eventTargetFinish)
* *
* Arguments: * Arguments:
@ -17,7 +18,7 @@
*/ */
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_3(_caller,_target,_errorMsg); params ["_caller", "_target", "_errorMsg"];
if (_caller != ACE_player) exitWith {}; if (_caller != ACE_player) exitWith {};

View File

@ -1,5 +1,6 @@
/* /*
* Author: PabstMirror * Author: PabstMirror
*
* After FUNC(disarmDropItems) has completed, passing a possible error code. * After FUNC(disarmDropItems) has completed, passing a possible error code.
* Passes that error back to orginal caller. * Passes that error back to orginal caller.
* *
@ -18,7 +19,7 @@
*/ */
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_3(_caller,_target,_errorMsg); params ["_caller", "_target", "_errorMsg"];
if (_errorMsg != "") then { if (_errorMsg != "") then {
diag_log text format ["[ACE_Disarming] %1 - eventTargetFinish: %2", ACE_time, _this]; diag_log text format ["[ACE_Disarming] %1 - eventTargetFinish: %2", ACE_time, _this];

View File

@ -1,5 +1,6 @@
/* /*
* Author: PabstMirror * Author: PabstMirror
*
* Disarm Event Handler, Starting func, called on the target. * Disarm Event Handler, Starting func, called on the target.
* If target has to remove uniform/vest, this will add all uniform/vest items to the drop list. * If target has to remove uniform/vest, this will add all uniform/vest items to the drop list.
* *
@ -18,7 +19,7 @@
*/ */
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_3(_caller,_target,_listOfObjectsToRemove); params ["_caller", "_target", "_listOfObjectsToRemove"];
private "_itemsToAdd"; private "_itemsToAdd";
@ -30,12 +31,12 @@ _itemsToAdd = [];
if (_x == (vest _target)) then { if (_x == (vest _target)) then {
_itemsToAdd = _itemsToAdd + (vestItems _target); _itemsToAdd = _itemsToAdd + (vestItems _target);
}; };
} forEach _listOfObjectsToRemove; } count _listOfObjectsToRemove;
{ {
if (!(_x in _listOfObjectsToRemove)) then { if (!(_x in _listOfObjectsToRemove)) then {
_listOfObjectsToRemove pushBack _x; _listOfObjectsToRemove pushBack _x;
}; };
} forEach _itemsToAdd; } count _itemsToAdd;
[_caller, _target, _listOfObjectsToRemove] call FUNC(disarmDropItems); [_caller, _target, _listOfObjectsToRemove] call FUNC(disarmDropItems);

View File

@ -1,5 +1,6 @@
/* /*
* Author: PabstMirror * Author: PabstMirror
*
* Helper function to get all gear of a container * Helper function to get all gear of a container
* *
* Arguments: * Arguments:
@ -15,15 +16,17 @@
*/ */
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_1(_target); params ["_target"];
private ["_allGear"]; private ["_allGear"];
_allGear = [[],[]];
_items = [];
_counts = [];
{ {
(_allGear select 0) append (_x select 0); _x params ["_item", "_count"];
(_allGear select 1) append (_x select 1); _item append _item;
} forEach [(getWeaponCargo _target), (getItemCargo _target), (getMagazineCargo _target), (getBackpackCargo _target)]; _count append _count;
} count [(getWeaponCargo _target), (getItemCargo _target), (getMagazineCargo _target), (getBackpackCargo _target)];
_allGear [_items,_counts] // Return

View File

@ -1,5 +1,6 @@
/* /*
* Author: PabstMirror * Author: PabstMirror
*
* Helper function to get all gear of a unit. * Helper function to get all gear of a unit.
* *
* Arguments: * Arguments:
@ -15,7 +16,7 @@
*/ */
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_1(_target); params ["_target"];
private ["_allItems", "_classnamesCount", "_index", "_uniqueClassnames"]; private ["_allItems", "_classnamesCount", "_index", "_uniqueClassnames"];
@ -49,6 +50,6 @@ _classnamesCount = [];
_uniqueClassnames pushBack _x; _uniqueClassnames pushBack _x;
_classnamesCount pushBack 1; _classnamesCount pushBack 1;
}; };
} forEach _allItems; } count _allItems;
[_uniqueClassnames, _classnamesCount] [_uniqueClassnames, _classnamesCount]

View File

@ -1,5 +1,6 @@
/* /*
* Author: PabstMirror * Author: PabstMirror
*
* Opens the disarm dialog (allowing a person to remove items) * Opens the disarm dialog (allowing a person to remove items)
* *
* Arguments: * Arguments:
@ -15,21 +16,9 @@
* Public: No * Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
params ["_caller", "_target"];
#define TEXTURES_RANKS [ \
"", \
"\A3\Ui_f\data\GUI\Cfg\Ranks\private_gs.paa", \
"\A3\Ui_f\data\GUI\Cfg\Ranks\corporal_gs.paa", \
"\A3\Ui_f\data\GUI\Cfg\Ranks\sergeant_gs.paa", \
"\A3\Ui_f\data\GUI\Cfg\Ranks\lieutenant_gs.paa", \
"\A3\Ui_f\data\GUI\Cfg\Ranks\captain_gs.paa", \
"\A3\Ui_f\data\GUI\Cfg\Ranks\major_gs.paa", \
"\A3\Ui_f\data\GUI\Cfg\Ranks\colonel_gs.paa" \
]
PARAMS_2(_caller,_target);
private "_display"; private "_display";
#define DEFUALTPATH "\A3\Ui_f\data\GUI\Cfg\Ranks\%1_gs.paa"
//Sanity Checks //Sanity Checks
if (_caller != ACE_player) exitwith {ERROR("Player isn't caller?");}; if (_caller != ACE_player) exitwith {ERROR("Player isn't caller?");};
if (!([_player, _target] call FUNC(canPlayerDisarmUnit))) exitWith {ERROR("Can't Disarm Unit");}; if (!([_player, _target] call FUNC(canPlayerDisarmUnit))) exitWith {ERROR("Can't Disarm Unit");};
@ -47,8 +36,8 @@ GVAR(disarmTarget) = _target;
//Setup Drop Event (on right pannel) //Setup Drop Event (on right pannel)
(_display displayCtrl 632) ctrlAddEventHandler ["LBDrop", { (_display displayCtrl 632) ctrlAddEventHandler ["LBDrop", {
if (isNull GVAR(disarmTarget)) exitWith {}; if (isNull GVAR(disarmTarget)) exitWith {};
PARAMS_5(_ctrl,_xPos,_yPos,_idc,_itemInfo); params ["_ctrl", "_xPos", "_yPos", "_idc", "_itemInfo"];
EXPLODE_3_PVT((_itemInfo select 0),_displayText,_value,_data); (_itemInfo select 0) params ["_displayText", "_value", "_data"];
if (isNull GVAR(disarmTarget)) exitWith {ERROR("disarmTarget is null");}; if (isNull GVAR(disarmTarget)) exitWith {ERROR("disarmTarget is null");};
@ -60,18 +49,18 @@ GVAR(disarmTarget) = _target;
//Setup PFEH //Setup PFEH
[{ [{
private ["_groundContainer", "_targetContainer", "_playerName", "_rankPicture", "_rankIndex", "_targetUniqueItems", "_holderUniqueItems", "_holder"]; private ["_groundContainer", "_targetContainer", "_playerName", "_icon", "_rankPicture", "_targetUniqueItems", "_holderUniqueItems", "_holder"];
disableSerialization; disableSerialization;
EXPLODE_2_PVT(_this,_args,_pfID); params ["_args", "_idPFH"];
EXPLODE_3_PVT(_args,_player,_target,_display); _args params ["_player", "_target", "_display"];
if ((!([_player, _target] call FUNC(canPlayerDisarmUnit))) || if ((!([_player, _target] call FUNC(canPlayerDisarmUnit))) ||
{isNull _display} || {isNull _display} ||
{_player != ACE_player}) then { {_player != ACE_player}) then {
[_pfID] call CBA_fnc_removePerFrameHandler; [_idPFH] call CBA_fnc_removePerFrameHandler;
GVAR(disarmTarget) = objNull; GVAR(disarmTarget) = objNull;
if (!isNull _display) then {closeDialog 0;}; //close dialog if still open if (!isNull _display) then { closeDialog 0; }; //close dialog if still open
} else { } else {
_groundContainer = _display displayCtrl 632; _groundContainer = _display displayCtrl 632;
@ -80,8 +69,9 @@ GVAR(disarmTarget) = _target;
_rankPicture = _display displayCtrl 1203; _rankPicture = _display displayCtrl 1203;
//Show rank and name (just like BIS's inventory) //Show rank and name (just like BIS's inventory)
_rankIndex = ((["PRIVATE", "CORPORAL", "SERGEANT", "LIEUTENANT", "CAPTAIN", "MAJOR", "COLONEL"] find (rank _target)) + 1); _icon = format [DEFUALTPATH, toLower (rank _target)];
_rankPicture ctrlSetText (TEXTURES_RANKS select _rankIndex); if (_icon isEqualTo DEFUALTPATH) then {_icon = ""};
_rankPicture ctrlSetText _icon;
_playerName ctrlSetText ([GVAR(disarmTarget)] call EFUNC(common,getName)); _playerName ctrlSetText ([GVAR(disarmTarget)] call EFUNC(common,getName));
//Clear both inventory lists: //Clear both inventory lists:
@ -98,7 +88,7 @@ GVAR(disarmTarget) = _target;
if ((_x getVariable [QGVAR(disarmUnit), objNull]) == _target) exitWith { if ((_x getVariable [QGVAR(disarmUnit), objNull]) == _target) exitWith {
_holder = _x; _holder = _x;
}; };
} forEach ((getpos _target) nearObjects [DISARM_CONTAINER, 3]); } count ((getpos _target) nearObjects [DISARM_CONTAINER, 3]);
//If a holder exists, show it's inventory //If a holder exists, show it's inventory
if (!isNull _holder) then { if (!isNull _holder) then {

View File

@ -1,5 +1,6 @@
/* /*
* Author: PabstMirror * Author: PabstMirror
*
* Shows a list of inventory items in a listBox control. * Shows a list of inventory items in a listBox control.
* *
* Arguments: * Arguments:
@ -17,11 +18,12 @@
#include "script_component.hpp" #include "script_component.hpp"
disableSerialization; disableSerialization;
PARAMS_2(_listBoxCtrl,_itemsCountArray);
private ["_classname", "_count", "_displayName", "_picture"]; private ["_classname", "_count", "_displayName", "_picture"];
params ["_listBoxCtrl", "_itemsCountArray"];
{ {
private "_configPath";
_displayName = ""; _displayName = "";
_picture = ""; _picture = "";
@ -31,21 +33,25 @@ private ["_classname", "_count", "_displayName", "_picture"];
if ((_classname != DUMMY_ITEM) && {_classname != "ACE_FakePrimaryWeapon"}) then { //Don't show the dummy potato or fake weapon if ((_classname != DUMMY_ITEM) && {_classname != "ACE_FakePrimaryWeapon"}) then { //Don't show the dummy potato or fake weapon
switch (true) do { switch (true) do {
case (isClass (configFile >> "CfgWeapons" >> _classname)): { case (isClass (configFile >> "CfgWeapons" >> _classname)): {
_displayName = getText (configFile >> "CfgWeapons" >> _classname >> "displayName"); _configPath = (configFile >> "CfgWeapons");
_picture = getText (configFile >> "CfgWeapons" >> _classname >> "picture"); _displayName = getText (_configPath >> _classname >> "displayName");
_picture = getText (_configPath >> _classname >> "picture");
}; };
case (isClass (configFile >> "CfgMagazines" >> _classname)): { case (isClass (configFile >> "CfgMagazines" >> _classname)): {
_displayName = getText (configFile >> "CfgMagazines" >> _classname >> "displayName"); _configPath = (configFile >> "CfgMagazines");
_picture = getText (configFile >> "CfgMagazines" >> _classname >> "picture"); _displayName = getText (_configPath >> _classname >> "displayName");
_picture = getText (_configPath >> _classname >> "picture");
}; };
case (isClass (configFile >> "CfgVehicles" >> _classname)): { case (isClass (configFile >> "CfgVehicles" >> _classname)): {
_displayName = getText (configFile >> "CfgVehicles" >> _classname >> "displayName"); _configPath = (configFile >> "CfgVehicles");
_picture = getText (configFile >> "CfgVehicles" >> _classname >> "picture"); _displayName = getText (_configPath >> _classname >> "displayName");
_picture = getText (_configPath >> _classname >> "picture");
}; };
case (isClass (configFile >> "CfgGlasses" >> _classname)): { case (isClass (configFile >> "CfgGlasses" >> _classname)): {
_displayName = getText (configFile >> "CfgGlasses" >> _classname >> "displayName"); _configPath = (configFile >> "CfgGlasses");
_picture = getText (configFile >> "CfgGlasses" >> _classname >> "picture"); _displayName = getText (_configPath >> _classname >> "displayName");
_picture = getText (_configPath >> _classname >> "picture");
}; };
default { default {
ERROR(format ["[%1] - bad classname", _classname]); ERROR(format ["[%1] - bad classname", _classname]);

View File

@ -1,5 +1,6 @@
/* /*
* Author: PabstMirror * Author: PabstMirror
*
* Verifies magazines moved with exact ammo counts preserved. * Verifies magazines moved with exact ammo counts preserved.
* Arrays will be in format from magazinesAmmo/magazinesAmmoCargo * Arrays will be in format from magazinesAmmo/magazinesAmmoCargo
* e.g.: [["30Rnd_65x39_caseless_mag",15], ["30Rnd_65x39_caseless_mag",30]] * e.g.: [["30Rnd_65x39_caseless_mag",15], ["30Rnd_65x39_caseless_mag",30]]
@ -36,6 +37,6 @@ _problem = false;
_index = _beginingArray find _x; _index = _beginingArray find _x;
if (_index == -1) exitWith {_problem = true;}; if (_index == -1) exitWith {_problem = true;};
_beginingArray deleteAt _index; _beginingArray deleteAt _index;
} forEach (_endA + _endB); } count (_endA + _endB);
(!_problem) && {_beginingArray isEqualTo []} (!_problem) && {_beginingArray isEqualTo []}