more common code cleanup

This commit is contained in:
commy2 2015-09-18 18:28:19 +02:00
parent a8ba96a01b
commit 1b96caedc0
13 changed files with 127 additions and 166 deletions

View File

@ -114,7 +114,6 @@ PREP(interpolateFromArray);
PREP(inTransitionAnim); PREP(inTransitionAnim);
PREP(inWater); PREP(inWater);
PREP(isAlive); PREP(isAlive);
PREP(isArrested);
PREP(isAutoWind); PREP(isAutoWind);
PREP(isAwake); PREP(isAwake);
PREP(isEngineer); PREP(isEngineer);
@ -235,10 +234,6 @@ PREP(getTurretsOther);
PREP(exportConfig); PREP(exportConfig);
PREP(getChildren); PREP(getChildren);
PREP(getDisplayConfigName); PREP(getDisplayConfigName);
PREP(log);
PREP(logControls);
PREP(logDisplays);
PREP(logModEntries);
PREP(monitor); PREP(monitor);
PREP(showUser); PREP(showUser);

View File

@ -1,25 +1,29 @@
/** /*
* fn_inWater_f.sqf * Author: Glowbal
* @Descr: Check if unit is underwater * Check if unit is underwater
* @Author: Glowbal
* *
* @Arguments: [unit OBJECT] * Arguments:
* @Return: BOOL True if unit is in the water * 0: Unit <OBJECT>
* @PublicAPI: true *
* Return Value:
* if unit is in the water (BOOLEAN)
*
* Public: Yes
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_return","_aslPos"]; params ["_unit"];
PARAMS_1(_unit); private "_return";
_return = false; _return = false;
if ((surfaceIsWater getPos _unit)) then { if (surfaceIsWater getPosASL _unit) then {
_aslPos = _unit modelToWorldVisual (_unit selectionPosition "head"); private "_pos";
if ((_aslPos select 2) <= 0) then { _pos = _unit modelToWorldVisual (_unit selectionPosition "head");
if (_pos select 2 < 0) then {
_return = true; _return = true;
}; };
}; };
_return; _return

View File

@ -1,6 +1,5 @@
/* /*
* Author: commy2 * Author: commy2
*
* Check if the object still exists and is alive. This function exists because 'alive objNull' actually returns true. * Check if the object still exists and is alive. This function exists because 'alive objNull' actually returns true.
* *
* Argument: * Argument:
@ -8,6 +7,10 @@
* *
* Return value: * Return value:
* The object exists and is alive (Bool). * The object exists and is alive (Bool).
*
* Public: Yes
*
* Deprecated
*/ */
#include "script_component.hpp" #include "script_component.hpp"

View File

@ -1,13 +0,0 @@
/**
* fn_isArrested.sqf
* @Descr: Check if unit is in arrested state
* @Author: Glowbal
*
* @Arguments: [unit OBJECT]
* @Return: BOOL Returns true if unit or object is in arrest state
* @PublicAPI: true
*/
#include "script_component.hpp"
((_this select 0) getvariable [QGVAR(StateArrested),false])

View File

@ -1,45 +1,55 @@
/** /*
* fn_loadPerson_f.sqf * Author: Glowbal
* @Descr: Loads a specified unit into any nearby vehicle * Loads a specified unit into any nearby vehicle
* @Author: Glowbal
* *
* @Arguments: [caller OBJECT, unitToBeLoaded OBJECT] * Arguments:
* @Return: OBJECT Returns the vehicle that the unitToBeloaded has been loaded in. Returns ObjNull if function failed * 0: Unit that will load <OBJECT>
* @PublicAPI: true * 1: Unit to be loaded <OBJECT>
*
* Return Value:
* the vehicle that the unitToBeloaded has been loaded in. Returns ObjNull if function failed <OBJECT>
*
* Public: Yes
*/ */
#include "script_component.hpp" #include "script_component.hpp"
#define GROUP_SWITCH_ID QUOTE(FUNC(loadPerson)) #define GROUP_SWITCH_ID QUOTE(FUNC(loadPerson))
private ["_caller", "_unit","_vehicle", "_loadcar", "_loadhelicopter", "_loadtank","_loadboat"]; params ["_caller", "_unit"];
_caller = [_this, 0, ObjNull,[ObjNull]] call BIS_fnc_Param;
_unit = [_this, 1, ObjNull,[ObjNull]] call BIS_fnc_Param; private ["_vehicle", "_loadcar", "_loadair", "_loadtank", "_loadboat"];
_vehicle = ObjNull;
_vehicle = objNull;
if (!([_caller] call FUNC(canInteract)) || {_caller == _unit}) exitwith {_vehicle}; if (!([_caller] call FUNC(canInteract)) || {_caller == _unit}) exitwith {_vehicle};
_loadcar = nearestObject [_unit, "car"]; _loadcar = nearestObject [_unit, "Car"];
if (_unit distance _loadcar <= 10) then { if (_unit distance _loadcar <= 10) then {
_vehicle = _loadcar; _vehicle = _loadcar;
} else { } else {
_loadhelicopter = nearestObject [_unit, "air"]; _loadair = nearestObject [_unit, "Air"];
if (_unit distance _loadhelicopter <= 10) then {
_vehicle = _loadhelicopter; if (_unit distance _loadair <= 10) then {
_vehicle = _loadair;
} else { } else {
_loadtank = nearestObject [_unit, "tank"]; _loadtank = nearestObject [_unit, "Tank"];
if (_unit distance _loadtank <= 10) then { if (_unit distance _loadtank <= 10) then {
_vehicle = _loadtank; _vehicle = _loadtank;
} else { } else {
_loadboat = nearestObject [_unit, "ship"]; _loadboat = nearestObject [_unit, "Ship_F"];
if (_unit distance _loadboat <= 10) then { if (_unit distance _loadboat <= 10) then {
_vehicle = _loadboat; _vehicle = _loadboat;
}; };
}; };
}; };
}; };
if (!isNull _vehicle) then { if (!isNull _vehicle) then {
[_unit, true, GROUP_SWITCH_ID, side group _caller] call FUNC(switchToGroupSide); [_unit, true, GROUP_SWITCH_ID, side group _caller] call FUNC(switchToGroupSide);
[[_unit, _vehicle,_caller], QUOTE(FUNC(loadPersonLocal)), _unit, false] call EFUNC(common,execRemoteFnc); [[_unit, _vehicle, _caller], QFUNC(loadPersonLocal), _unit, false] call FUNC(execRemoteFnc);
}; };
_vehicle _vehicle

View File

@ -1,25 +1,28 @@
/** /*
* fn_loadPersonLocal_f.sqf * Author: Glowbal
* @Descr: Load a person, local * Load a person, local
* @Author: Glowbal
* *
* @Arguments: [unit OBJECT, vehicle OBJECT, caller OBJECT] * Arguments:
* @Return: void * 0: unit to be loaded <OBJECT>
* @PublicAPI: false * 1: vehicle that will beloaded <OBJECT>
* 2: caller that will load <OBJECT>
*
* Return Value:
* None
*
* Public: Yes
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_unit","_vehicle","_caller","_handle","_loaded","_slotsOpen"]; params ["_unit", "_vehicle", "_caller"];
_unit = [_this, 0, ObjNull,[ObjNull]] call BIS_fnc_Param;
_vehicle = [_this, 1, ObjNull,[ObjNull]] call BIS_fnc_Param;
_caller = [_this, 2, ObjNull,[ObjNull]] call BIS_fnc_Param;
_slotsOpen = false;
if (!alive _unit) then { if (!alive _unit) then {
_unit = [_unit,_caller] call FUNC(makeCopyOfBody); _unit = [_unit, _caller] call FUNC(makeCopyOfBody);
}; };
private "_slotsOpen";
_slotsOpen = false;
if (_vehicle emptyPositions "cargo" > 0) then { if (_vehicle emptyPositions "cargo" > 0) then {
_unit moveInCargo _vehicle; _unit moveInCargo _vehicle;
@ -32,26 +35,29 @@ if (_vehicle emptyPositions "cargo" > 0) then {
}; };
if (_slotsOpen) then { if (_slotsOpen) then {
_loaded = _vehicle getvariable [QGVAR(loaded_persons),[]]; private "_loaded";
_loaded pushback _unit; _loaded = _vehicle getVariable [QGVAR(loaded_persons),[]];
_vehicle setvariable [QGVAR(loaded_persons),_loaded,true]; _loaded pushBack _unit;
if (!([_unit] call FUNC(isAwake))) then {
_handle = [_unit,_vehicle] spawn {
private ["_unit","_vehicle"];
_unit = _this select 0;
_vehicle = _this select 1;
waituntil {vehicle _unit == _vehicle};
sleep 0.5;
//Save the "awake" animation before applying the death animation _vehicle setVariable [QGVAR(loaded_persons), _loaded, true];
if (vehicle _unit == _vehicle) then {
_unit setVariable [QEGVAR(medical,vehicleAwakeAnim), [_vehicle, (animationState _unit)]]; if !([_unit] call FUNC(isAwake)) then {
[{
(_this select 0) params ["_unit", "_vehicle"];
// wait until the unit is in the vehicle
if (vehicle _unit != _vehicle) exitWith {
// kill this pfh if either one is deleted
if (isNull _unit || isNull _vehicle) then {
[_this select 1] call CBA_fnc_removePerFrameHandler;
};
}; };
[_unit,([_unit] call FUNC(getDeathAnim)), 1, true] call FUNC(doAnimation);
};
} else {
if ([_unit] call FUNC(isArrested)) then {
}; _unit setVariable [QEGVAR(medical,vehicleAwakeAnim), [_vehicle, animationState _unit]];
[_unit, [_unit] call FUNC(getDeathAnim), 1, true] call FUNC(doAnimation);
[_this select 1] call CBA_fnc_removePerFrameHandler;
}, 0.5, [_unit, _vehicle]] call CBA_fnc_addPerFrameHandler;
}; };
}; };

View File

@ -13,28 +13,26 @@
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_name", "_isClientSetable", "_isForced", "_profileValue"];
// Iterate through settings // Iterate through settings
{ {
_name = _x select 0; _x params ["_name", "", "_isClientSetable", "", "", "", "_isForced"];
_isClientSetable = _x select 2;
_isForced = _x select 6;
// If setting is user setable // If setting is user setable
if (_isClientSetable) then { if (_isClientSetable) then {
// If setting is not forced // If setting is not forced
if !(_isForced) then { if !(_isForced) then {
_profileValue = profileNamespace getvariable _name; private "_profileValue";
_profileValue = profileNamespace getVariable _name;
// If the setting is stored on the profile // If the setting is stored on the profile
if !(isNil "_profileValue") then { if !(isNil "_profileValue") then {
// If the profile variable has the correct type // If the profile variable has the correct type
if (typeName _profileValue == typeName (missionNamespace getvariable _name)) then { if (typeName _profileValue == typeName (missionNamespace getVariable _name)) then {
// Load the setting from the profile // Load the setting from the profile
missionNamespace setvariable [_name, _profileValue]; missionNamespace setVariable [_name, _profileValue];
}; };
}; };
}; };
}; };
false
} forEach GVAR(settings); } count GVAR(settings);

View File

@ -13,24 +13,26 @@
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_parseConfigForSettings"];
GVAR(settings) = []; GVAR(settings) = [];
_parseConfigForSettings = { private "_fnc_parseConfigForSettings";
private ["_config", "_countOptions", "_optionEntry", "_index"]; _fnc_parseConfigForSettings = {
private ["_config", "_countOptions", "_optionEntry"];
_config = _this select 0; _config = _this select 0;
_countOptions = count _config; _countOptions = count _config;
for "_index" from 0 to (_countOptions - 1) do { for "_index" from 0 to (_countOptions - 1) do {
_optionEntry = _config select _index; _optionEntry = _config select _index;
[_optionEntry] call FUNC(setSettingFromConfig); [_optionEntry] call FUNC(setSettingFromConfig);
}; };
// Check if all settings should be forced // Check if all settings should be forced
if (GVAR(forceAllSettings)) then { if (GVAR(forceAllSettings)) then {
{ {
_x set [6, true]; _x set [6, true];
} forEach GVAR(settings); false
} count GVAR(settings);
}; };
}; };
@ -41,17 +43,18 @@ _parseConfigForSettings = {
// This ensures that all settings are of their correct type, in case an outdated or corrupt server config is used , as well as have their correct localized display name and description // This ensures that all settings are of their correct type, in case an outdated or corrupt server config is used , as well as have their correct localized display name and description
// Regular config // Regular config
[configFile >> "ACE_Settings"] call _parseConfigForSettings; [configFile >> "ACE_Settings"] call _fnc_parseConfigForSettings;
// Server config // Server config
[configFile >> "ACE_ServerSettings"] call _parseConfigForSettings; [configFile >> "ACE_ServerSettings"] call _fnc_parseConfigForSettings;
// mission side settings // mission side settings
[missionConfigFile >> "ACE_Settings"] call _parseConfigForSettings; [missionConfigFile >> "ACE_Settings"] call _fnc_parseConfigForSettings;
// Publish all settings data // Publish all settings data
publicVariable QGVAR(settings); publicVariable QGVAR(settings);
// Publish all setting values // Publish all setting values
{ {
publicVariable (_x select 0); publicVariable (_x select 0);
} forEach GVAR(settings); false
} count GVAR(settings);

View File

@ -3,31 +3,37 @@
* *
* Execute a local event on this client only. * Execute a local event on this client only.
* *
* Argument: * Arguments:
* 0: Event name (string) * 0: Event name (string)
* 1: Event args (any) * 1: Event args (any)
* *
* Return value: * Return Value:
* Nothing * None
*
* Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_2(_eventName,_eventArgs); params ["_eventName", "_eventArgs"];
private["_eventIndex", "_eventNames", "_events"]; GVAR(events) params ["_eventNames", "_eventArray"];
_eventNames = GVAR(events) select 0; private "_eventIndex";
_eventIndex = _eventNames find _eventName; _eventIndex = _eventNames find _eventName;
if(_eventIndex != -1) then {
_events = (GVAR(events) select 1) select _eventIndex; if (_eventIndex != -1) then {
private "_events";
_events = _eventArray select _eventIndex;
#ifdef DEBUG_EVENTS #ifdef DEBUG_EVENTS
ACE_LOGINFO_1("* Local Event: %1",_eventName); ACE_LOGINFO_1("* Local Event: %1",_eventName);
ACE_LOGINFO_1(" args=%1",_eventArgs); ACE_LOGINFO_1(" args=%1",_eventArgs);
#endif #endif
{ {
if(!isNil "_x") then { if (!isNil "_x") then {
_eventArgs call CALLSTACK_NAMED(_x, FORMAT_2("Local Event %1 ID: %2",_eventName,_forEachIndex)); _eventArgs call CALLSTACK_NAMED(_x,FORMAT_2("Local Event %1 ID: %2",_eventName,_forEachIndex));
#ifdef DEBUG_EVENTS_CALLSTACK #ifdef DEBUG_EVENTS_CALLSTACK
ACE_LOGINFO_1(" ID: %1",_forEachIndex); ACE_LOGINFO_1(" ID: %1",_forEachIndex);
#endif #endif

View File

@ -1,25 +0,0 @@
// by commy2
#include "script_component.hpp"
if ((_this select 0) in (missionNamespace getVariable ["ACE_Debug", []])) then {
_this resize 4;
PARAMS_4(_type,_argument,_function,_showInGame);
if (isNil "_function") then {
_function = {_this};
};
if (isNil "_showInGame") then {
_showInGame = true;
};
private "_result";
_result = _argument call _function;
if (_showInGame) then {
systemChat format ["%1", _result];
};
diag_log text format ["[ACE] Debug: %1 : %2 - %3 : %4", _type, diag_frameno, _fnc_scriptNameParent, _result];
};

View File

@ -1,4 +0,0 @@
// by commy2
#include "script_component.hpp"
[allControls findDisplay _this, {ctrlIDC _this}] call FUNC(map)

View File

@ -1,4 +0,0 @@
// by commy2
#include "script_component.hpp"
[allDisplays, {ctrlIDD _this}] call FUNC(map)

View File

@ -1,18 +0,0 @@
// by commy2
#include "script_component.hpp"
private ["_configs", "_entries", "_name"];
_configs = "true" configClasses (configFile >> _this);
_entries = [];
{
{
_name = toLower configName _x;
if !(_name in _entries) then {
diag_log text _name;
_entries pushBack _name;
};
} forEach configProperties [_x, "toLower configName _x find 'ace' == 0", false];
} forEach _configs;