Code cleanup 1.54

This commit is contained in:
commy2
2016-01-06 22:42:02 +01:00
parent 0bc540305d
commit e56e18bff3
37 changed files with 276 additions and 327 deletions

View File

@ -11,26 +11,24 @@
*/
#include "script_component.hpp"
EXPLODE_2_PVT(_this,_player,_target);
params ["_player", "_target"];
if (vehicle _target != _target) exitWith {false};
private ["_magazineCfg","_magazineType"];
_magazineType = currentMagazine _target;
_magazineCfg = configFile >> "CfgMagazines" >> _magazineType;
private _magazineType = currentMagazine _target;
private _magazineCfg = configFile >> "CfgMagazines" >> _magazineType;
if (getNumber (_magazineCfg >> "ACE_isBelt") == 0) exitWith {false};
// Check if the ammo is not empty or full
private "_ammoCount";
_ammoCount = _target ammo currentWeapon _target;
private _ammoCount = _target ammo currentWeapon _target;
// Exit if the belt is full or empty
if ((_ammoCount == 0) || (getNumber (_magazineCfg >> "count") - _ammoCount) == 0) exitWith {false};
if (_ammoCount == 0 || getNumber (_magazineCfg >> "count") - _ammoCount == 0) exitWith {false};
// Check if the player has any of the same magazines
// Calculate max ammo
private "_maxAmmo";
_maxAmmo = 0;
private _maxAmmo = 0;
{
_maxAmmo = _maxAmmo max (_x select 1);

View File

@ -13,10 +13,9 @@
#define COUNT_BARS 12
EXPLODE_1_PVT(_this,_unit);
params ["_unit"];
private ["_target"];
_target = vehicle _unit;
private _target = vehicle _unit;
if (count _this > 1) then {
_target = _this select 1;

View File

@ -14,11 +14,9 @@
EXPLODE_1_PVT(_this,_target);
private ["_weapon","_muzzle","_magazine","_showNumber","_ammo","_maxRounds","_count","_text","_color","_picture","_ammoBarsStructuredText", "_a", "_loadedName", "_string"];
_weapon = currentWeapon _target;
_muzzle = currentMuzzle _target;
_magazine = currentMagazine _target;
private _weapon = currentWeapon _target;
private _muzzle = currentMuzzle _target;
private _magazine = currentMagazine _target;
// currentWeapon returns "" for static weapons before they are shot once
if (_target isKindOf "StaticWeapon") then {
@ -31,8 +29,8 @@ if (_target isKindOf "StaticWeapon") then {
if (_magazine == "") then {
// Try to get magazine using magazinesAmmoFull
private ["_magazines"];
_magazines = magazinesAmmoFull _target;
private _magazines = magazinesAmmoFull _target;
{
if (_x select 2) exitWith {
_magazine = _x select 0;
@ -45,10 +43,10 @@ if (_magazine == "") exitWith {};
if (_weapon == "") exitWith {};
if (!( _muzzle isEqualType "")) then {_muzzle = _weapon};
_showNumber = false;
_ammo = 0;
_maxRounds = 1;
_count = 0;
private _showNumber = false;
private _ammo = 0;
private _maxRounds = 1;
private _count = 0;
// not grenade launcher
if (_muzzle == _weapon) then {
@ -75,16 +73,16 @@ if (_muzzle == _weapon) then {
};
};
_ammoBarsStructuredText = if (_showNumber) then {
private _ammoBarsStructuredText = if (_showNumber) then {
parseText format ["<t align='center' >%1x</t>", _count]
} else {
_color = [((2 * (1 - _ammo / _maxRounds)) min 1), ((2 * _ammo / _maxRounds) min 1), 0];
private _color = [((2 * (1 - _ammo / _maxRounds)) min 1), ((2 * _ammo / _maxRounds) min 1), 0];
_string = "";
private _string = "";
for "_a" from 1 to _count do {
_string = _string + "|";
};
_text = [_string, _color] call EFUNC(common,stringToColoredText);
private _text = [_string, _color] call EFUNC(common,stringToColoredText);
_string = "";
for "_a" from (_count + 1) to (_maxRounds min COUNT_BARS) do {
@ -97,11 +95,11 @@ _ammoBarsStructuredText = if (_showNumber) then {
if (_target isKindOf "StaticWeapon") then {
//Vehicle mags (usualy) don't have pictures, so just show the text above ammo count
_loadedName = getText (configFile >> "CfgMagazines" >> _magazine >> "displaynameshort");
private _loadedName = getText (configFile >> "CfgMagazines" >> _magazine >> "displaynameshort");
_loadedName = parseText format ["<t align='center' >%1</t>", _loadedName];
_text = composeText [_loadedName, linebreak, _ammoBarsStructuredText];
private _text = composeText [_loadedName, linebreak, _ammoBarsStructuredText];
[_text] call EFUNC(common,displayTextStructured);
} else {
_picture = getText (configFile >> "CfgMagazines" >> _magazine >> "picture");
private _picture = getText (configFile >> "CfgMagazines" >> _magazine >> "picture");
[_ammoBarsStructuredText, _picture] call EFUNC(common,displayTextPicture);
};

View File

@ -11,26 +11,24 @@
*/
#include "script_component.hpp"
EXPLODE_2_PVT(_this,_player,_target);
params ["_player", "_target"];
if (vehicle _target != _target) exitWith {false};
private ["_magazineCfg","_magazineType", "_condition", "_onFailure", "_onFinish"];
_magazineType = currentMagazine _target;
_magazineCfg = configFile >> "CfgMagazines" >> _magazineType;
private _magazineType = currentMagazine _target;
private _magazineCfg = configFile >> "CfgMagazines" >> _magazineType;
if (getNumber (_magazineCfg >> "ACE_isBelt") == 0) exitWith {false};
// Check if the ammo is not empty or full
private "_ammoCount";
_ammoCount = _target ammo currentWeapon _target;
private _ammoCount = _target ammo currentWeapon _target;
// Exit if the belt is full or empty
if ((_ammoCount == 0) || (getNumber (_magazineCfg >> "count") - _ammoCount) == 0) exitWith {false};
// Check if the player has any of the same same magazines
// Calculate max ammo it can link
private "_maxAmmo";
_maxAmmo = 0;
private _maxAmmo = 0;
{
_maxAmmo = _maxAmmo max (_x select 1);
@ -38,21 +36,20 @@ _maxAmmo = 0;
if (_maxAmmo == 0) exitWith {};
// Condition to call each frame
_condition = {
EXPLODE_2_PVT((_this select 0),_player,_target);
private _condition = {
(_this select 0) params ["_player", "_target"];
([_player, _target, []] call EFUNC(common,canInteractWith)) && ((_player distance _target) < 3) && ((speed _target) < 1)
};
_onFinish = {
EXPLODE_3_PVT((_this select 0),_player,_target,_magazine);
private _onFinish = {
(_this select 0) params ["_player", "_target", "_magazine"];
// Raise event on remote unit
["linkedAmmo", [_target], [_target, _player, _magazine]] call EFUNC(common,targetEvent);
};
_onFailure = {
private _onFailure = {
EXPLODE_3_PVT((_this select 0),_player,_target,_magazine);
[_player, "AmovPknlMstpSrasWrflDnon", 1] call EFUNC(common,doAnimation);