more common code cleanup

This commit is contained in:
commy2 2015-09-20 23:18:51 +02:00
parent 62ec00a251
commit a98a45e5d1
13 changed files with 159 additions and 115 deletions

View File

@ -1,28 +1,38 @@
/*
* Author: bux578, commy2
*
* Returns an array containing all items of a given unit
*
* Argument:
* 0: Unit (Object)
* Arguments:
* 0: Unit <OBJECT>
*
* Return value:
* Array with all the gear, format:
* 0: headgear (String)
* 1: goggles (String)
* 2,3: uniform (String, Array)
* 4,5: vest (String, Array)
* 6,7: backpack (String, Array)
* 8-10: rifle (String, Array, Array)
* 11-13: launcher (String, Array, Array)
* 14-16: pistol (String, Array, Array)
* 17: map, compass, watch, etc. (Array)
* 18: binocluar (String)
* Return Value:
* 0: Headgear <STRING>
* 1: Goggles <STRING>
* 2: Uniform <STRING>
* 3: Uniform Items <ARRAY>
* 4: Vest <String>
* 5: Vest Items <ARRAY>
* 6: Backback <STRING>
* 7: Backpack Items <ARRAY>
* 8: Rifle <STRING>
* 9: Rifle Items <ARRAY>
* 10: Rifle Magazines <ARRAY>
* 11: Launcher <STRING>
* 12: Launcher Items <ARRAY>
* 13: Launcher Magazines <ARRAY>
* 14: Handgun <STRING>
* 15: Handgun Items <ARRAY>
* 16: Handgun Magazines <ARRAY>
* 17: Assigned Items (map, compass, watch, etc.) <ARRAY>
* 18: Binoculars <STRING>
*
* Public: Yes
*
* Note: Element 17 includes the Head Mounted Display (HMD)
*/
#include "script_component.hpp"
PARAMS_1(_unit);
params ["_unit"];
if (isNull _unit) exitWith {[
"",

View File

@ -1,25 +1,27 @@
/*
* Author: commy2
*
* Return the captivity status of an unit.
*
* Argument:
* 0: Unit (Object)
* Arguments:
* 0: Unit <OBJECT>
*
* Return value:
* Reasons, why the unit is a captive. An empty array is returned if the unit is not a captive (Array of Strings)
* Return Value:
* Captivity Reasons, empty if not captive <ARRAY>
*
* Public: Yes
*/
#include "script_component.hpp"
private ["_captivityReasons", "_unitCaptivityStatus", "_unitCaptivityReasons"];
params ["_unit"];
PARAMS_1(_unit);
private ["_captivityReasons", "_unitCaptivityStatus", "_unitCaptivityReasons"];
_captivityReasons = missionNamespace getVariable ["ACE_captivityReasons", []];
_unitCaptivityStatus = [captiveNum _unit, count _captivityReasons] call FUNC(binarizeNumber);
_unitCaptivityReasons = [];
{
if (_unitCaptivityStatus select _forEachIndex) then {
_unitCaptivityReasons pushBack _x;

View File

@ -1,10 +1,20 @@
// by commy2
/*
* Author: commy2
* Obtain children of a config entry
*
* Arguments:
* 0: Unit <OBJECT>
*
* Return Value:
* Parent Entry Class Children <ARRAY>
*
* Public: Yes
*/
#include "script_component.hpp"
private ["_classes"];
PARAMS_2(_name,_cfgClass);
params ["_name", "_cfgClass"];
private "_classes";
_classes = format ["configName inheritsFrom _x == '%1'", _name] configClasses (configFile >> _cfgClass);
_classes = [_classes, {configName _this}] call FUNC(map);
_classes
[_classes, {configName _this}] call FUNC(map) // return

View File

@ -1,21 +1,22 @@
/*
* Author: commy2
*
* Get the commander config of a vehicles turret.
*
* Argument:
* 0: vehicle (Object)
* Arguments:
* 0: vehicle <OBJECT>
*
* Return value:
* Commander config (Config)
* Return Value:
* Commander config <CONFIG>
*
* Public: Yes
*/
#include "script_component.hpp"
private ["_config", "_turret"];
params ["_vehicle"];
PARAMS_1(_vehicle);
private ["_config", "_turret"];
_config = configFile >> "CfgVehicles" >> typeOf _vehicle;
_turret = [_vehicle] call FUNC(getTurretCommander);
[_config, _turret] call FUNC(getTurretConfigPath)
[_config, _turret] call FUNC(getTurretConfigPath) // return

View File

@ -1,21 +1,22 @@
/*
* Author: commy2
*
* Get the gunner config of a vehicles turret.
*
* Argument:
* 0: vehicle (Object)
* Arguments:
* 0: vehicle <OBJECT>
*
* Return value:
* Gunner config (Config)
* Return Value:
* Gunner config <CONFIG>
*
* Public: Yes
*/
#include "script_component.hpp"
private ["_config", "_turret"];
params ["_vehicle"];
PARAMS_1(_vehicle);
private ["_config", "_turret"];
_config = configFile >> "CfgVehicles" >> typeOf _vehicle;
_turret = [_vehicle] call FUNC(getTurretGunner);
[_config, _turret] call FUNC(getTurretConfigPath)
[_config, _turret] call FUNC(getTurretConfigPath) // return

View File

@ -1,17 +1,18 @@
/*
* Author: commy2
* Determins type of item. Can be CfgMagaines, CfgWeapons or CfgGlasses.
*
* What kind of Cfg is the item. Works for CfgMagaines, CfgWeapons and CfgGlasses
* Arguments:
* 0: Item Classname <STRING>
*
* Argument:
* 0: A item's classname. (String)
* Return Value:
* Config category ("CfgWeapons", "CfgMagazines", "CfgGlasses", "") <STRING>
*
* Return value:
* CfgWhatever (String)
* Public: Yes
*/
#include "script_component.hpp"
PARAMS_1(_item);
params ["_item"];
if (isClass (configFile >> "CfgWeapons" >> _item)) exitWith {"CfgWeapons"};

View File

@ -1,17 +1,18 @@
/*
* Author: commy2
* Determins type of object. Can be CfgVehicles or CfgAmmo.
*
* What kind of Cfg is the object. Works for CfgVehicles and CfgAmmo
* Arguments:
* 0: Object classname <STRING>
*
* Argument:
* 0: An object's classname. (String)
* Return Value:
* Config category ("CfgWeapons", "Cfgmagazines", "CfgGlasses", "") <STRING>
*
* Return value:
* CfgWhatever (String)
* Public: Yes
*/
#include "script_component.hpp"
PARAMS_1(_object);
params ["_object"];
if (isClass (configFile >> "CfgVehicles" >> _object)) exitWith {"CfgVehicles"};

View File

@ -1,20 +1,19 @@
/*
* Author: commy2
* Returns gunner using specified weapon type in vehicle. Only works if all turrets have different weapons.
*
* Get the gunner of a vehicle who uses the given weapon type. Requires every turret to have a different weapon.
* Arguments:
* 0: Vehicle <OBJECT>
* 1: Weapon <STRING>
*
* Argument:
* 0: The vehicle (Object)
* 1: weapon of the vehicle (String)
* Return Value:
* Gunner <OBJECT>
*
* Return value:
* The turret gunner with this weapon (Object)
* Public: Yes
*/
#include "script_component.hpp"
private ["_vehicle", "_weapon"];
_vehicle = _this select 0;
_weapon = _this select 1;
params ["_vehicle", "_weapon"];
// on foot
if (gunner _vehicle == _vehicle && {_weapon in weapons _vehicle || {toLower _weapon in ["throw", "put"]}}) exitWith {gunner _vehicle};
@ -27,11 +26,12 @@ _gunner = objNull;
if (_weapon in (_vehicle weaponsTurret _x)) exitWith {
_gunner = _vehicle turretUnit _x;
};
} forEach allTurrets [_vehicle, true];
false
} count allTurrets [_vehicle, true];
// ensure that at least the pilot is returned if there is no gunner
if (isManualFire _vehicle && {isNull _gunner}) then {
_gunner = driver _vehicle;
_gunner = driver _vehicle;
};
_gunner

View File

@ -1,30 +1,34 @@
/*
* Author: commy2
*
* Get the turret index of a vehicles commander.
*
* Argument:
* 0: Vehicle (Object)
* Arguments:
* 0: Vehicle <OBJECT>
*
* Return value:
* Turret index of the vehicles commander. Empty array means no observer position. (Array)
* Return Value:
* Vehicle commander turrent indecies <ARRAY>
*
* Public: Yes
*/
#include "script_component.hpp"
private ["_turrets", "_turret", "_config"];
params ["_vehicle"];
PARAMS_1(_vehicle);
private ["_turrets", "_turret", "_config"];
_turrets = allTurrets [_vehicle, true];
_turret = [];
{
_config = configFile >> "CfgVehicles" >> typeOf _vehicle;
_config = configFile >> "CfgVehicles" >> typeOf _vehicle;
_config = [_config, _x] call FUNC(getTurretConfigPath);
_config = [_config, _x] call FUNC(getTurretConfigPath);
if (getNumber (_config >> "primaryObserver") == 1) exitWith {
_turret = _x;
};
false
} count _turrets;
if (getNumber (_config >> "primaryObserver") == 1) exitWith {
_turret = _x;
};
} forEach _turrets;
_turret

View File

@ -1,23 +1,25 @@
/*
* Author: commy2
*
* Get the turret index of a vehicles copilot.
*
* Argument:
* 0: Vehicle (Object)
* Arguments:
* 0: Vehicle <OBJECT>
*
* Return value:
* Turret index of the vehicles gunner. Empty array means no copilot position. (Array)
* Return Value:
* Vehicle Copilot Turret indecies <ARRAY>
*
* Public: Yes
*/
#include "script_component.hpp"
private ["_turrets", "_turret", "_config"];
params ["_vehicle"];
PARAMS_1(_vehicle);
private ["_turrets", "_turret", "_config"];
_turrets = allTurrets [_vehicle, true];
_turret = [];
{
_config = configFile >> "CfgVehicles" >> typeOf _vehicle;
@ -26,6 +28,7 @@ _turret = [];
if (getNumber (_config >> "isCopilot") == 1 && {getNumber (_config >> "primaryGunner") != 1} && {getNumber (_config >> "primaryObserver") != 1}) exitWith {
_turret = _x;
};
} forEach _turrets;
false
} count _turrets;
_turret

View File

@ -1,23 +1,25 @@
/*
* Author: commy2
*
* Get the turret index of a vehicles gunner.
*
* Argument:
* 0: Vehicle (Object)
* Arguments:
* 0: Vehicle <OBJECT>
*
* Return value:
* Turret index of the vehicles gunner. Empty array means no gunner position. (Array)
* Return Value:
* Vehicle Gunner Turret indecies <ARRAY>
*
* Public: Yes
*/
#include "script_component.hpp"
private ["_turrets", "_turret", "_config"];
params ["_vehicle"];
PARAMS_1(_vehicle);
private ["_turrets", "_turret", "_config"];
_turrets = allTurrets [_vehicle, true];
_turret = [];
{
_config = configFile >> "CfgVehicles" >> typeOf _vehicle;
@ -26,6 +28,7 @@ _turret = [];
if (getNumber (_config >> "primaryGunner") == 1) exitWith {
_turret = _x;
};
} forEach _turrets;
false
} count _turrets;
_turret

View File

@ -1,23 +1,25 @@
/*
* Author: commy2
*
* Get the turret indices of ffv turrets.
*
* Argument:
* 0: Vehicle (Object)
* Arguments:
* 0: Vehicle <OBJECT>
*
* Return value:
* Turret index of the vehicles gunner. Empty array means no ffv turrets. (Array)
* Return Value:
* Vehicle FFV Turret indecies <ARRAY>
*
* Public: Yes
*/
#include "script_component.hpp"
private ["_turrets", "_turret", "_config"];
params ["_vehicle"];
PARAMS_1(_vehicle);
private ["_turrets", "_turret", "_config"];
_turrets = allTurrets [_vehicle, true];
_turret = [];
{
_config = configFile >> "CfgVehicles" >> typeOf _vehicle;
@ -26,5 +28,7 @@ _turret = [];
if (getNumber (_config >> "isPersonTurret") == 1) then {
_turret pushBack _x;
};
} forEach _turrets;
false
} count _turrets;
_turret

View File

@ -1,23 +1,25 @@
/*
* Author: commy2
*
* Get the turret indices of other turrets (not gunner, commander, copilot or ffv).
*
* Argument:
* 0: Vehicle (Object)
* Arguments:
* 0: Vehicle <OBJECT>
*
* Return value:
* Turret index of the vehicles gunner. Empty array means no other turrets. (Array)
* Return Value:
* Vehicle Other Turret indecies <ARRAY>
*
* Public: Yes
*/
#include "script_component.hpp"
private ["_turrets", "_turret", "_config"];
params ["_vehicle"];
PARAMS_1(_vehicle);
private ["_turrets", "_turret", "_config"];
_turrets = allTurrets [_vehicle, true];
_turret = [];
{
_config = configFile >> "CfgVehicles" >> typeOf _vehicle;
@ -30,5 +32,7 @@ _turret = [];
) then {
_turret pushBack _x;
};
} forEach _turrets;
false
} count _turrets;
_turret