big refactor, WIP!
This commit is contained in:
50
framework/common/functions/fn_addCBASettings.sqf
Normal file
50
framework/common/functions/fn_addCBASettings.sqf
Normal file
@@ -0,0 +1,50 @@
|
||||
#include "..\script_component.hpp"
|
||||
|
||||
//---------------------
|
||||
// Side Chat
|
||||
//---------------------
|
||||
|
||||
[
|
||||
QGVARMAIN(sideChat),
|
||||
"CHECKBOX",
|
||||
"Side Chat Text Enabled",
|
||||
[QUOTE(SETTINGS_GROUP_NAME), QUOTE(COMPONENT_BEAUTIFIED)],
|
||||
false, // default value
|
||||
true, // requires restart
|
||||
{
|
||||
params ["_value"];
|
||||
[
|
||||
QGVARMAIN(sideChat),
|
||||
_value
|
||||
] call EFUNC(common,logSettingChanged);
|
||||
}
|
||||
] call CBA_fnc_addSetting;
|
||||
|
||||
[QGVARMAIN(sideChat), false] call CBA_settings_fnc_set;
|
||||
|
||||
|
||||
//---------------------
|
||||
// Medical Overlay
|
||||
//---------------------
|
||||
|
||||
[
|
||||
"milsim_client_medState3D_enabled", // variable
|
||||
"CHECKBOX", // type
|
||||
["Enable 3D Triage Card State", "Draws a colored dot over units within 10m indicating current ACE Triage State"], // title
|
||||
["17th Battalion", "Medical"], // category
|
||||
true // default value
|
||||
] call CBA_fnc_addSetting;
|
||||
|
||||
[
|
||||
"milsim_client_medState3D_drawRange", // variable
|
||||
"LIST", // type
|
||||
["Range To Draw Icons", "Determines range at which dots are visible"], // title
|
||||
["17th Battalion", "Medical"], // category
|
||||
[[2, 4, 6, 8, 10], ["2", "4", "6", "8", "10"], 4] // option values, option labels, default index
|
||||
] call CBA_fnc_addSetting;
|
||||
|
||||
|
||||
|
||||
diag_log text "[MILSIM] (settings) Custom CBA settings initialized";
|
||||
|
||||
nil;
|
||||
16
framework/common/functions/fn_addPlayerInfoToArray.sqf
Normal file
16
framework/common/functions/fn_addPlayerInfoToArray.sqf
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "..\script_component.hpp"
|
||||
|
||||
params [["_playerObj", objNull], ["_arrayToModify", [], [[]]]];
|
||||
|
||||
if (isNull _playerObj) exitWith {_arrayToModify};
|
||||
|
||||
{
|
||||
_arrayToModify = [_arrayToModify, _x#0, _x#1] call BIS_fnc_setToPairs;
|
||||
} forEach [
|
||||
["playerName", name _playerObj],
|
||||
["playerUID", getPlayerUID _playerObj],
|
||||
["playerGroup", groupId (group _playerObj)],
|
||||
["playerNetID", [_playerObj] call BIS_fnc_netId]
|
||||
];
|
||||
|
||||
_arrayToModify;
|
||||
15
framework/common/functions/fn_getApprovedAssetsCfg.sqf
Normal file
15
framework/common/functions/fn_getApprovedAssetsCfg.sqf
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "../script_component.hpp"
|
||||
|
||||
private _approvedAssetsCfg = (missionConfigFile >> "ApprovedAssets");
|
||||
|
||||
if (!IS_CONFIG(_approvedAssetsCfg) || {!isClass _approvedAssetsCfg}) exitWith {
|
||||
[
|
||||
LEVEL_ERROR,
|
||||
QUOTE(COMPONENT),
|
||||
"ERROR: Approved assets config not found. Check that the config is present and correctly named in the mission config file. See defines/ApprovedAssets.hpp and framework/util/functions/getApprovedAssetsCfg.sqf.",
|
||||
[]
|
||||
] call EFUNC(common,log);
|
||||
configNull;
|
||||
};
|
||||
|
||||
_approvedAssetsCfg;
|
||||
15
framework/common/functions/fn_getBattalionCfg.sqf
Normal file
15
framework/common/functions/fn_getBattalionCfg.sqf
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "../script_component.hpp"
|
||||
|
||||
private _battalionInfoCfg = (missionConfigFile >> "BattalionInfo");
|
||||
|
||||
if (!IS_CONFIG(_battalionInfoCfg) || {!isClass _battalionInfoCfg}) exitWith {
|
||||
[
|
||||
LEVEL_ERROR,
|
||||
QUOTE(COMPONENT),
|
||||
"ERROR: Battalion config not found. Check that the battalion config is present and correctly named in the mission config file. See defines/BattalionInfo.hpp and framework/util/functions/getBattalionCfg.sqf.",
|
||||
[]
|
||||
] call EFUNC(common,log);
|
||||
configNull;
|
||||
};
|
||||
|
||||
_battalionInfoCfg;
|
||||
19
framework/common/functions/fn_getNameOfBase.sqf
Normal file
19
framework/common/functions/fn_getNameOfBase.sqf
Normal file
@@ -0,0 +1,19 @@
|
||||
#include "..\script_component.hpp"
|
||||
|
||||
params [["_base", objNull, [objNull]]];
|
||||
if (_base == objNull) exitWith {""};
|
||||
|
||||
// get base name
|
||||
private _baseName = _base getVariable ["name", ""];
|
||||
// if (_baseName == "") then {
|
||||
// _baseName = format[
|
||||
// "near %1",
|
||||
// text (nearestLocation [_base, ["NameCity", "NameLocal"]])
|
||||
// ]
|
||||
// };
|
||||
|
||||
if (_baseName == "") then {
|
||||
_baseName = _base call BIS_fnc_locationDescription;
|
||||
};
|
||||
|
||||
_baseName;
|
||||
12
framework/common/functions/fn_getNearestBase.sqf
Normal file
12
framework/common/functions/fn_getNearestBase.sqf
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "..\script_component.hpp"
|
||||
|
||||
params [["_object", objNull, [objNull]]];
|
||||
if (isNull _object) exitWith {objNull};
|
||||
|
||||
private _bases = missionNamespace getVariable ["milsim_baseObjects", []];
|
||||
if (count _bases == 0) exitWith {objNull};
|
||||
|
||||
// get nearest base (Module_Respawn_F)
|
||||
private _closestBase = [_bases, _object] call BIS_fnc_nearestPosition;
|
||||
if (isNull _closestBase) exitWith {objNull};
|
||||
_closestBase;
|
||||
33
framework/common/functions/fn_log.sqf
Normal file
33
framework/common/functions/fn_log.sqf
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
Function: milsim_util_fnc_log
|
||||
|
||||
Description:
|
||||
Used to log messages to the server RPT file.
|
||||
|
||||
Parameters:
|
||||
0: NUMBER - log level.
|
||||
1: STRING - component name.
|
||||
2: STRING - message to log.
|
||||
3: ARRAY - key value pairs of data to log.
|
||||
*/
|
||||
#include "..\script_component.hpp"
|
||||
|
||||
params [
|
||||
["_logLevel", 1, [-1,0,1,2,3]], // script_mod.hpp
|
||||
["_component", "", [""]],
|
||||
["_message", "", [""]],
|
||||
["_data", [], [[]]]
|
||||
];
|
||||
|
||||
if (_logLevel < LOG_LEVEL) exitWith {};
|
||||
|
||||
private _hash = createHashMapFromArray _data;
|
||||
|
||||
// Replace square brackets with round brackets to avoid parsing issues.
|
||||
_message regexReplace ["\[", "("];
|
||||
_message regexReplace ["\]", ")"];
|
||||
|
||||
private _json = [_hash] call CBA_fnc_encodeJSON;
|
||||
_log = format ["[%1] [%2] [%3] [%4] :: %5", QUOTE(PREFIX), _component, _fnc_scriptNameParent, _message, _json];
|
||||
|
||||
diag_log text _log;
|
||||
25
framework/common/functions/fn_logMissionInfo.sqf
Normal file
25
framework/common/functions/fn_logMissionInfo.sqf
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "..\script_component.hpp"
|
||||
|
||||
[
|
||||
QUOTE(COMPONENT),
|
||||
"MISSION INFO",
|
||||
[
|
||||
["serverName", serverName],
|
||||
["worldName", worldName],
|
||||
["missionSeries", getMissionConfigValue ["missionSeries", ""]],
|
||||
["missionName", missionName],
|
||||
["briefingName", briefingName],
|
||||
["overviewText", getMissionConfigValue ["overviewText", ""]],
|
||||
["onLoadName", getMissionConfigValue ["onLoadName", ""]],
|
||||
["onLoadMission", getMissionConfigValue ["onLoadMission", ""]],
|
||||
["missionAuthor", getMissionConfigValue ["author", ""]],
|
||||
["unitSlots", createHashMapFromArray [
|
||||
["EAST", playableSlotsNumber EAST], // 0 is EAST side
|
||||
["WEST", playableSlotsNumber WEST], // 1 is WEST side
|
||||
["RESISTANCE", playableSlotsNumber RESISTANCE], // 2 is RESISTANCE side
|
||||
["CIVILIAN", playableSlotsNumber CIVILIAN], // 3 is CIVILIAN side
|
||||
["SIDEUNKNOWN", 0], // 4 is SIDEUNKNOWN side
|
||||
["LOGIC", playableSlotsNumber sideLogic] // 5 is LOGIC side
|
||||
]]
|
||||
]
|
||||
] call FUNC(log);
|
||||
150
framework/common/functions/fn_logPlayerInventory.sqf
Normal file
150
framework/common/functions/fn_logPlayerInventory.sqf
Normal file
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
Function: milsim_util_fnc_logPlayerInventory
|
||||
|
||||
Description:
|
||||
Checks a player's inventory for non-compliant items and logs results to all machines.
|
||||
|
||||
Author: Hizumi, EagleTrooper, IndigoFox
|
||||
|
||||
Parameters:
|
||||
0: _player - <OBJECT> - Player to check inventory of.
|
||||
|
||||
Returns:
|
||||
<ARRAY> - Array of strings to be logged.
|
||||
|
||||
*/
|
||||
#include "..\script_component.hpp"
|
||||
|
||||
params [
|
||||
["_player", objNull, [objNull]]
|
||||
];
|
||||
|
||||
if (!isPlayer _player) exitWith {
|
||||
[
|
||||
LEVEL_ERROR
|
||||
QUOTE(COMPONENT),
|
||||
"PARAM PLAYER IS NOT A PLAYER",
|
||||
[["player", _player]]
|
||||
] call EFUNC(common,log);
|
||||
};
|
||||
|
||||
// testing
|
||||
// test_old = compile preprocessFileLineNumbers "testold.sqf";
|
||||
// test_new = compile preprocessFileLineNumbers "testnew.sqf";
|
||||
// player addItem "A3_GPNVG18_BLK_TI";
|
||||
// player addWeapon "SMA_HK417_16in";
|
||||
// player addItem "ej_VPS15";
|
||||
// player addItem "ACE_Banana";
|
||||
|
||||
// INSTANTIATE VARS
|
||||
private _foundItemsKeyValue = [];
|
||||
private _allFoundItemsSoFar = [];
|
||||
|
||||
// GET PLAYER ITEMS
|
||||
private _playerItems = [
|
||||
_player, // Unit
|
||||
true, // Include weapons, attachments, loaded magazines
|
||||
true, // Include items in backpack
|
||||
true, // Include items in vest
|
||||
true, // Include items in uniform
|
||||
true, // Include assigned items
|
||||
true // Include not loaded magazines
|
||||
] call CBA_fnc_uniqueUnitItems;
|
||||
|
||||
_playerItems pushBack (headgear _player);
|
||||
_playerItems pushBack (uniform _player);
|
||||
|
||||
|
||||
[
|
||||
LEVEL_INFO,
|
||||
QUOTE(COMPONENT),
|
||||
"CHECKING PLAYER INVENTORY",
|
||||
[_player] call EFUNC(common,addPlayerInfoToArray)
|
||||
] call EFUNC(common,log);
|
||||
|
||||
////////////////////////////////////////
|
||||
// HARDCODED DISALLOWED ITEMS - see functions/definitions/DisallowedEquipment.hpp
|
||||
|
||||
// Get parent class
|
||||
private _disallowedEquipmentCfg = (missionConfigFile >> "DisallowedEquipment");
|
||||
|
||||
// Get all subclasses
|
||||
private _definitionCfgs = (_disallowedEquipmentCfg call BIS_fnc_getCfgSubClasses) apply {
|
||||
(_disallowedEquipmentCfg >> _x)
|
||||
};
|
||||
|
||||
// diag_log text format["DEFINITION CFGS: %1", _definitionCfgs];
|
||||
// Check all items
|
||||
{ // forEach _subclassesCfgs
|
||||
private _definitionCfg = _x;
|
||||
private _definitionLabel = (_definitionCfg >> "label") call BIS_fnc_getCfgData;
|
||||
private _definitionItems = (_definitionCfg >> "items") call BIS_fnc_getCfgDataArray;
|
||||
// diag_log text format["DEF ITEMS: %1", _definitionItems];
|
||||
{ // forEach _playerItems
|
||||
private _playerItem = _x;
|
||||
// diag_log text format["PLAYER ITEM: %1", _playerItem];
|
||||
if (_playerItem in _definitionItems && not (_playerItem in _allFoundItemsSoFar)) then {
|
||||
// add under def label
|
||||
[_foundItemsKeyValue, _definitionLabel, _playerItem] call BIS_fnc_addToPairs;
|
||||
// add to all found items
|
||||
_allFoundItemsSoFar pushBackUnique _playerItem;
|
||||
};
|
||||
} forEach _playerItems;
|
||||
} forEach _definitionCfgs;
|
||||
|
||||
////////////////////////////////////////
|
||||
// UNLISTED THERMAL - Any item with thermal capabilities that is not already in the list
|
||||
|
||||
// Identify thermal items in the player list
|
||||
private _thermalItems = _playerItems select {
|
||||
private _playerItem = _x;
|
||||
private _modes = getArray(configfile >> "CfgWeapons" >> _playerItem >> "visionMode");
|
||||
private _subModes = [configfile >> "CfgWeapons" >> _playerItem >> "ItemInfo" >> "OpticsModes", 1] call BIS_fnc_returnChildren;
|
||||
{
|
||||
_modes append getArray( _x >> "visionMode" );
|
||||
} forEach _subModes;
|
||||
if ((count _modes) isNotEqualTo 0) then {
|
||||
// if the item has thermal capabilities and is not in the list anywhere else, include it
|
||||
"ti" in (_modes apply { toLower _x }) && not (_playerItem in _allFoundItemsSoFar);
|
||||
} else {
|
||||
false;
|
||||
};
|
||||
};
|
||||
|
||||
{
|
||||
[_foundItemsKeyValue, "UNLISTED THERMAL", _x] call BIS_fnc_addToPairs;
|
||||
} forEach _thermalItems;
|
||||
|
||||
|
||||
// Only log compliance message if no non-compliant items were found
|
||||
if (count _allFoundItemsSoFar isEqualTo 0) exitWith {
|
||||
[
|
||||
LEVEL_INFO,
|
||||
QUOTE(COMPONENT),
|
||||
"PLAYER INVENTORY IS COMPLIANT",
|
||||
[_player] call EFUNC(common,addPlayerInfoToArray)
|
||||
] call EFUNC(common,log);
|
||||
};
|
||||
|
||||
// Log all non-compliant items
|
||||
{
|
||||
_x params ["_categoryLabel", "_items"];
|
||||
if (typeName _items isEqualTo "STRING") then {
|
||||
_items = [_items];
|
||||
};
|
||||
{
|
||||
private _itemClassName = _x;
|
||||
private _itemConfig = _itemClassName call CBA_fnc_getItemConfig;
|
||||
// Log to RPT
|
||||
[
|
||||
LEVEL_WARNING,
|
||||
QUOTE(COMPONENT),
|
||||
"NON-COMPLIANT ITEM",
|
||||
[_player, [
|
||||
["category", _categoryLabel],
|
||||
["className", _itemClassName],
|
||||
["displayName", [_itemConfig] call BIS_fnc_displayName]
|
||||
]] call EFUNC(common,addPlayerInfoToArray)
|
||||
] call EFUNC(common,log);
|
||||
} forEach _items;
|
||||
} forEach _foundItemsKeyValue;
|
||||
16
framework/common/functions/fn_logSettingChanged.sqf
Normal file
16
framework/common/functions/fn_logSettingChanged.sqf
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "..\script_component.hpp"
|
||||
|
||||
params [
|
||||
["_settingName", "", [""]],
|
||||
"_newValue"
|
||||
];
|
||||
|
||||
[
|
||||
LEVEL_INFO,
|
||||
QUOTE(COMPONENT),
|
||||
"SETTING CHANGED",
|
||||
[
|
||||
["setting", _settingName],
|
||||
["newValue", _value]
|
||||
]
|
||||
] call EFUNC(common,log);
|
||||
22
framework/common/functions/fn_padString.sqf
Normal file
22
framework/common/functions/fn_padString.sqf
Normal file
@@ -0,0 +1,22 @@
|
||||
#include "..\script_component.hpp"
|
||||
|
||||
params [
|
||||
["_text", "", [""]],
|
||||
["_padSide", "left", ["left", "right"]],
|
||||
["_padChar", " ", [" "]],
|
||||
["_padLength", 4, [4]]
|
||||
];
|
||||
|
||||
// pad a string with a character to a certain length
|
||||
if (_padSide == "left") then {
|
||||
for "_i" from 1 to _padLength - count _text do {
|
||||
_text = _padChar + _text;
|
||||
};
|
||||
};
|
||||
if (_padSide == "right") then {
|
||||
for "_i" from 1 to _padLength - count _text do {
|
||||
_text = _text + _padChar;
|
||||
};
|
||||
};
|
||||
|
||||
_text
|
||||
27
framework/common/functions/fn_recurseSubclasses.sqf
Normal file
27
framework/common/functions/fn_recurseSubclasses.sqf
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "..\script_component.hpp"
|
||||
|
||||
params [
|
||||
["_cfg", configNull, [configNull]],
|
||||
["_code", {}, [{}]]
|
||||
];
|
||||
|
||||
if (isNull _cfg) exitWith {["Provided config is null!"] call BIS_fnc_error};
|
||||
|
||||
|
||||
private _recurseFnc = {
|
||||
params ["_cfg", "_code", ["_recurseCounter", 0]];
|
||||
[_cfg, _recurseCounter] call _code;
|
||||
// get children and recurse
|
||||
private _childCfgs = _cfg call BIS_fnc_returnChildren;
|
||||
if (count _childCfgs isEqualTo 0) exitWith {false};
|
||||
|
||||
{
|
||||
[_x, _code, _recurseCounter + 1] call _recurseFnc;
|
||||
} forEach _childCfgs;
|
||||
false;
|
||||
};
|
||||
|
||||
private _continue = true;
|
||||
while {_continue} do {
|
||||
_continue = [_cfg, _code] call _recurseFnc;
|
||||
};
|
||||
3
framework/common/script_component.hpp
Normal file
3
framework/common/script_component.hpp
Normal file
@@ -0,0 +1,3 @@
|
||||
#define COMPONENT common
|
||||
#define COMPONENT_BEAUTIFIED Common
|
||||
#include "../script_mod.hpp"
|
||||
Reference in New Issue
Block a user