Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[medical] Code cleanup using SQFLint #6485

Merged
merged 10 commits into from
Aug 2, 2018
Merged
1 change: 1 addition & 0 deletions addons/common/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ PREP(fixLoweredRifleAnimation);
PREP(fixPosition);
PREP(getAllDefinedSetVariables);
PREP(getAwakeAnim);
PREP(getCountOfItem);
PREP(getDeathAnim);
PREP(getDefaultAnim);
PREP(getDefinedVariable);
Expand Down
31 changes: 31 additions & 0 deletions addons/common/functions/fnc_getCountOfItem.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "script_component.hpp"
/*
* Author: Dedmen
* Return how many items of type _itemType the player has in his containers (Uniform, Vest, Backpack)
* Doesn't count assignedItems, weapons, weapon attachments, magazines in weapons
*
* Arguments:
* 0: unit <OBJECT>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought the same actually. But I just copied it from another function :D

* 1: Classname of item (Case-Sensitive) <STRING>
*
* Return Value:
* itemCount <NUMBER>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Item Count

*
* Example:
* [bob, "FirstAidKit"] call ace_common_fnc_getCountOfItem
*
* Public: Yes
*/

params ["_unit", "_itemType"];

private _countItemsInContainer = {
(getItemCargo _this) params ["_itemTypes", "_itemCounts"];

private _index = _itemTypes find _itemType;
_itemCounts param [_index, 0]
};

((uniformContainer _unit) call _countItemsInContainer) +
((vestContainer _unit) call _countItemsInContainer) +
((backpackContainer _unit) call _countItemsInContainer)
3 changes: 2 additions & 1 deletion addons/medical/functions/fnc_addDamageToUnit.sqf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "script_component.hpp"
/*
* Author: PabstMirror
* Manually Apply Damage to a unit (can cause lethal damage)
Expand All @@ -19,9 +20,9 @@
*
* Public: Yes
*/

// #define DEBUG_MODE_FULL
// #define DEBUG_TESTRESULTS
#include "script_component.hpp"

params [["_unit", objNull, [objNull]], ["_damageToAdd", -1, [0]], ["_bodyPart", "", [""]], ["_typeOfDamage", "", [""]], ["_instigator", objNull, [objNull]]];
TRACE_5("params",_unit,_damageToAdd,_bodyPart,_typeOfDamage,_instigator);
Expand Down
3 changes: 2 additions & 1 deletion addons/medical/functions/fnc_setUnconscious.sqf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "script_component.hpp"
/*
* Author: Glowbal
* Sets a unit in the unconscious state.
Expand All @@ -18,8 +19,8 @@
*
* Public: yes
*/

// #define DEBUG_MODE_FULL
#include "script_component.hpp"

// only run this after the settings are initialized
if !(EGVAR(common,settingsInitFinished)) exitWith {
Expand Down
1 change: 1 addition & 0 deletions addons/medical_ai/functions/fnc_playTreatmentAnim.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*
* Public: No
*/

params ["_unit", "_isBandage", "_isSelfTreatment"];

if (vehicle _unit != _unit) exitWith {};
Expand Down
1 change: 1 addition & 0 deletions addons/medical_feedback/functions/fnc_effectBleeding.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Return Value:
* None
*/

params ["_enable", "_bloodloss"];
if (isNull findDisplay 46) exitWith {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Return Value:
* None
*/

params ["_enable", "_intensity"];

if ((!_enable) || {_intensity == 0}) exitWith {
Expand Down
1 change: 1 addition & 0 deletions addons/medical_feedback/functions/fnc_effectHeartBeat.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Return Value:
* None
*/

params ["_heartRate"];

if (_heartRate == 0) exitWith {
Expand Down
1 change: 1 addition & 0 deletions addons/medical_feedback/functions/fnc_effectPain.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Return Value:
* None
*/

params ["_enable", "_intensity"];

if (!_enable || {_intensity == 0}) exitWith {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Return Value:
* None
*/

params ["_enable", "_mode"];

switch (_mode) do {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*
* Public: No
*/

#define MAX_DISTANCE 10

params ["_target", ["_show", 0], ["_selectionN", 0]];
Expand Down
6 changes: 3 additions & 3 deletions addons/medical_gui/functions/fnc_handleUI_DisplayOptions.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private _display = uiNamespace getVariable QGVAR(medicalMenu);
if (isNil "_display") exitWith {}; // no valid dialog present

if (_name isEqualTo "toggle") exitWith {
_newTarget = ACE_player;
private _newTarget = ACE_player;
//If we are on the player, and only if our old target is still valid, switch to it:
if ((GVAR(INTERACTION_TARGET) == ACE_player) &&
{[ACE_player, GVAR(INTERACTION_TARGET_PREVIOUS), ["isNotInside", "isNotSwimming"]] call EFUNC(common,canInteractWith)} &&
Expand Down Expand Up @@ -89,12 +89,12 @@ if (_name isEqualTo "triage") exitWith {

ctrlEnable [212, false];

_entries = [ACE_player, GVAR(INTERACTION_TARGET), _name] call FUNC(getTreatmentOptions);
private _entries = [ACE_player, GVAR(INTERACTION_TARGET), _name] call FUNC(getTreatmentOptions);

{
//player sidechat format["TRIGGERED: %1",_x];
if (_forEachIndex > END_IDC) exitWith {};
_ctrl = (_display displayCtrl (START_IDC + _forEachIndex));
private _ctrl = (_display displayCtrl (START_IDC + _forEachIndex));
if (!(_forEachIndex > AMOUNT_OF_ENTRIES)) then {
_ctrl ctrlSetText (_x select 0);
private _code = format ["ace_medical_menu_pendingReopen = true; call %1;", (_x select 3)];
Expand Down
1 change: 1 addition & 0 deletions addons/medical_gui/functions/fnc_onMenuOpen.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*
* Public: No
*/

#define MAX_DISTANCE 10

params ["_display"];
Expand Down
2 changes: 1 addition & 1 deletion addons/medical_gui/functions/fnc_updateUIInfo.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private _selectionN = GVAR(selectedBodyPart);
if (_selectionN < 0 || {_selectionN > 5}) exitWith {};

private _genericMessages = [];
private _partText = [ELSTRING(medical_treatment,Head), ELSTRING(medical_treatment,Torso), ELSTRING(medical_treatment,LeftArm) ,ELSTRING(medical_treatment,RightArm) ,ELSTRING(medical_treatment,LeftLeg), ELSTRING(medical_treatment,RightLeg)] select _selectionN;
private _partText = [ELSTRING(medical_treatment,Head), ELSTRING(medical_treatment,Torso), ELSTRING(medical_treatment,LeftArm), ELSTRING(medical_treatment,RightArm), ELSTRING(medical_treatment,LeftLeg), ELSTRING(medical_treatment,RightLeg)] select _selectionN;
_genericMessages pushBack [localize _partText, [1, 1, 1, 1]];

if IS_BLEEDING(_target) then {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*
* Public: No
*/

params ["_unit"];

private _startTime = _unit getVariable [QGVAR(cardiacArrestStart), CBA_missionTime];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*
* Public: No
*/

params ["_unit"];

(GVAR(fatalInjuryCondition) < 2) && {!(_unit getVariable [QGVAR(deathBlocked), false])}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*
* Public: No
*/

params ["_unit"];

[QEGVAR(medical,FatalInjuryInstantTransition), _unit] call CBA_fnc_localEvent;
15 changes: 13 additions & 2 deletions addons/medical_statemachine/functions/fnc_handleStateDefault.sqf
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@

#include "script_component.hpp"
/*
* Author: BaerMitUmlaut
*
*
* Arguments:
* 0: The Unit <OBJECT>
*
* Return Value:
* None
*
* Public: No
*/

params ["_unit", "_stateName"];
params ["_unit"];

// If the unit died the loop is finished
if (!alive _unit) exitWith {};
Expand Down
16 changes: 13 additions & 3 deletions addons/medical_statemachine/functions/fnc_handleStateInjured.sqf
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@

#include "script_component.hpp"
/*
* Author: BaerMitUmlaut
*
*
* Arguments:
* 0: The Unit <OBJECT>
*
* Return Value:
* None
*
* Public: No
*/

params ["_unit", "_stateName"];
params ["_unit"];

// If the unit died the loop is finished
if (!alive _unit) exitWith {};
Expand All @@ -19,4 +30,3 @@ private _painLevel = GET_PAIN_PERCEIVED(_unit);
if (_painLevel > 0) then {
[QEGVAR(medical,moan), [_unit, _painLevel]] call CBA_fnc_localEvent;
};

Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@

#include "script_component.hpp"
/*
* Author: BaerMitUmlaut
*
*
* Arguments:
* 0: The Unit <OBJECT>
*
* Return Value:
* None
*
* Public: No
*/

params ["_unit", "_stateName"];
params ["_unit"];

// If the unit died the loop is finished
if (!alive _unit) exitWith {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*
* Public: No
*/

params ["_unit"];

_unit setVariable [QEGVAR(medical,deathBlocked), true];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* Return Value:
* None
*/

params ["_unit", "_change", "_timeToMaxEffect", "_maxTimeInSystem"];

private _adjustments = _unit getVariable [VAR_HEART_RATE_ADJ,[]];
Expand Down
2 changes: 1 addition & 1 deletion addons/medical_treatment/functions/fnc_bodyCleanupLoop.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* None
*
* Example:
* call ACE_medical_fnc_bodyCleanupLoop
* call ACE_medical_treatment_fnc_bodyCleanupLoop
*
* Public: No
*/
Expand Down
4 changes: 2 additions & 2 deletions addons/medical_treatment/functions/fnc_checkItems.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

params ["_unit"];

private _countFirstAidKit = {_x == "FirstAidKit"} count items _unit;
private _countFirstAidKit = [_unit, "FirstAidKit"] call EFUNC(common,getCountOfItem);
_unit removeItems "FirstAidKit";

private _countMedikit = {_x == "Medikit"} count items _unit;
private _countMedikit = [_unit, "Medikit"] call EFUNC(common,getCountOfItem);
_unit removeItems "Medikit";

for "_i" from 1 to _countFirstAidKit do {
Expand Down
6 changes: 3 additions & 3 deletions addons/medical_treatment/functions/fnc_getTriageStatus.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* Public: Yes
*/

private ["_unit","_return","_status"];
params ["_unit"];
_status = _unit getVariable [QEGVAR(medical,triageLevel), -1];
_return = switch (_status) do {

private _status = _unit getVariable [QEGVAR(medical,triageLevel), -1];
private _return = switch (_status) do {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of a return variable is pointless in this function since the switch is at the end anyway 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about replacing the switch by an ARRAY param [_status, default] ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah. Would then call localize for all entries everytime

case 1: {[localize ELSTRING(medical_treatment,Triage_Status_Minor), 1, [0, 0.5, 0, 0.9]]};
case 2: {[localize ELSTRING(medical_treatment,Triage_Status_Delayed), 2, [0.7, 0.5, 0, 0.9]]};
case 3: {[localize ELSTRING(medical_treatment,Triage_Status_Immediate), 3, [0.4, 0.07, 0.07, 0.9]]};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

params ["_unit"];

private _vehicle = vehicle _unit;

if (_unit == _vehicle) exitWith {false};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* None
*
* Example:
* call ACE_medical_fnc_litterCleanupLoop
* call ACE_medical_treatment_fnc_litterCleanupLoop
*
* Public: No
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* None
*
* Example:
* [cursorTarget] call ace_medical_fnc_serverRemoveBody
* [cursorTarget] call ace_medical_treatment_fnc_serverRemoveBody
*
* Public: No
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ params ["_target"];

if (!alive _target) exitWith {};

_unit setVariable [VAR_PAIN, 0, true];
_unit setVariable [VAR_BLOOD_VOL, DEFAULT_BLOOD_VOLUME, true];
_target setVariable [VAR_PAIN, 0, true];
_target setVariable [VAR_BLOOD_VOL, DEFAULT_BLOOD_VOLUME, true];

// tourniquets
_target setVariable [VAR_TOURNIQUET, DEFAULT_TOURNIQUET_VALUES, true];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*
* Public: Yes
*/

#define MORPHINE_PAIN_SUPPRESSION 0.6

params ["_target", "_className", "_partIndex"];
Expand Down
3 changes: 2 additions & 1 deletion addons/medical_vitals/functions/fnc_handleUnitVitals.sqf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "script_component.hpp"
/*
* Author: Glowbal
* Updates the vitals. Called from the statemachine's onState functions.
Expand All @@ -13,8 +14,8 @@
*
* Public: No
*/

// #define DEBUG_MODE_FULL
#include "script_component.hpp"

params ["_unit"];

Expand Down