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 - Cleanup settings #7057

Merged
merged 8 commits into from
Jun 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions addons/common/functions/fnc_cbaSettings.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ LOG("Adding ACE_Settings to CBA_settings");
GVAR(cbaSettings_forcedSettings) = [];
GVAR(cbaSettings_missionSettings) = [];
GVAR(settings) = []; // will stay empty - for BWC?
#ifdef DEBUG_MODE_FULL
GVAR(settingsMovedToSQF) = [];
#endif

// Add Event Handlers:
[QGVAR(setSetting), {
Expand Down Expand Up @@ -66,6 +69,13 @@ GVAR(settings) = []; // will stay empty - for BWC?
false
} count GVAR(runAtSettingsInitialized);
GVAR(runAtSettingsInitialized) = nil; //cleanup

#ifdef DEBUG_MODE_FULL
INFO_1("checking settingsMovedToSQF [%1]",count GVAR(settingsMovedToSQF));
{
if (isNil _x) then { WARNING_1("setting [%1] NOT moved to sqf",_x); };
} forEach GVAR(settingsMovedToSQF);
#endif
}] call CBA_fnc_addEventHandler;

private _start = diag_tickTime;
Expand All @@ -81,6 +91,10 @@ for "_index" from 0 to (_countOptions - 1) do {
} else {
WARNING_1("Setting [%1] - Already defined from somewhere else??",_varName);
};
#ifdef DEBUG_MODE_FULL
} else {
GVAR(settingsMovedToSQF) pushBack configName _optionEntry;
#endif
};
};

Expand Down
48 changes: 22 additions & 26 deletions addons/medical/initSettings.sqf
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
// CBA Settings [ADDON: ace_medical]:

private _categoryArray = [LELSTRING(medical,Category), "?"];

// todo: Check the description is still accurate
[
QGVAR(spontaneousWakeUpChance), "SLIDER",
[LSTRING(MedicalSettings_spontaneousWakeUpChance_DisplayName), LSTRING(MedicalSettings_spontaneousWakeUpChance_Description)],
_categoryArray,
[0,1,0.05,2], // [min, max, default value, trailing decimals (-1 for whole numbers only)]
true, // isGlobal
{[QGVAR(spontaneousWakeUpChance), _this] call EFUNC(common,cbaSettings_settingChanged)},
true // Needs mission restart
QGVAR(limping),
"LIST",
[LSTRING(Limping_DisplayName), LSTRING(Limping_Description)],
LSTRING(Category),
[[0, 1, 2], [ELSTRING(common,Disabled), LSTRING(Limping_LimpOnOpenWounds), LSTRING(Limping_LimpRequiresStitching)], 1],
true,
{[QGVAR(limping), _this] call EFUNC(common,cbaSettings_settingChanged)},
true
] call CBA_settings_fnc_init;

[
QEGVAR(medical,limping), "LIST",
[LSTRING(setting_limping_DisplayName), LSTRING(setting_limping_Description)],
_categoryArray,
[[0,1,2],[LELSTRING(common,disabled), LLSTRING(setting_limping_limpOnOpenWounds), LLSTRING(setting_limping_limpRequiresStitching)], 1], // [values, titles, defaultIndex]
true, // isGlobal
{[QEGVAR(medical,limping), _this] call EFUNC(common,cbaSettings_settingChanged)},
true // Needs mission restart
QGVAR(fractures),
"LIST",
[LSTRING(Fractures_DisplayName), LSTRING(Fractures_Description)],
LSTRING(Category),
[[0, 1, 2], [ELSTRING(common,Disabled), LSTRING(Fractures_SplintHealsFully), LSTRING(Fractures_SplintHasEffects)], 1],
true,
{[QGVAR(fractures), _this] call EFUNC(common,cbaSettings_settingChanged)},
true
] call CBA_settings_fnc_init;

[
QEGVAR(medical,fractures), "LIST",
[LSTRING(setting_fractures_DisplayName), LSTRING(setting_fractures_Description)],
_categoryArray,
[[0,1,2],[LELSTRING(common,disabled), LLSTRING(setting_fractures_splintHealsFully), LLSTRING(setting_fractures_splintHasEffects)], 1], // [values, titles, defaultIndex]
true, // isGlobal
{[QEGVAR(medical,fractures), _this] call EFUNC(common,cbaSettings_settingChanged)},
true // Needs mission restart
QGVAR(spontaneousWakeUpChance),
"SLIDER",
[LSTRING(SpontaneousWakeUpChance_DisplayName), LSTRING(SpontaneousWakeUpChance_Description)],
LSTRING(Category),
[0, 1, 0.05, 2],
true
] call CBA_settings_fnc_init;
216 changes: 37 additions & 179 deletions addons/medical/stringtable.xml

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion addons/medical_blood/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

class Extended_PreStart_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preStart));
Expand Down
4 changes: 2 additions & 2 deletions addons/medical_blood/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ace_medical_blood
===============
=================

Adds blood visual effect on the ground near a bleeding player.
Creates blood drops on the ground near bleeding units.

## Maintainers

Expand Down
6 changes: 3 additions & 3 deletions addons/medical_blood/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

PREP(cleanupLoop);
PREP(createBlood);
PREP(handleWoundReceived);
PREP(init);
PREP(isBleeding);
PREP(onBleeding);
PREP(createBlood);
PREP(serverCleanupBlood);
PREP(spurt);
29 changes: 7 additions & 22 deletions addons/medical_blood/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,18 @@ if (isServer) then {

[QGVAR(bloodDropCreated), {
params ["_bloodDrop"];
// Add to created queue with format [expireTime, object]
private _index = GVAR(bloodDrops) pushBack [(CBA_missionTime + BLOOD_OBJECT_LIFETIME), _bloodDrop];

if (count GVAR(bloodDrops) >= MAX_BLOOD_OBJECTS) then {
// Add to created queue with format: [expire time, blood object]
private _index = GVAR(bloodDrops) pushBack [CBA_missionTime + GVAR(bloodLifetime), _bloodDrop];

if (count GVAR(bloodDrops) >= GVAR(maxBloodObjects)) then {
(GVAR(bloodDrops) deleteAt 0) params ["", "_deletedBloodDrop"];
deleteVehicle _deletedBloodDrop;
};

if (_index == 1) then { // Start the waitAndExecute loop
[FUNC(serverCleanupBlood), [], BLOOD_OBJECT_LIFETIME] call CBA_fnc_waitAndExecute;
// Start the cleanup loop
if (_index == 0) then {
[FUNC(cleanupLoop), [], GVAR(bloodLifetime)] call CBA_fnc_waitAndExecute;
};
}] call CBA_fnc_addEventHandler;
};

["ace_settingsInitialized", {
TRACE_1("settingsInitialized", GVAR(enabledFor));
if (GVAR(enabledFor) == 0) exitWith {}; // 0: disabled
if ((GVAR(enabledFor) == 1) && {!hasInterface}) exitWith {}; // 1: enabledFor_OnlyPlayers

private _listcode = if (GVAR(enabledFor) == 1) then {
{if (alive ACE_player) then {[ACE_player]} else {[]}} // ace_player is only possible local player
} else {
EFUNC(common,getLocalUnits) // filter all local units
};

private _stateMachine = [_listcode, true] call CBA_statemachine_fnc_create;
[_stateMachine, LINKFUNC(onBleeding), {}, {}, "Bleeding"] call CBA_statemachine_fnc_addState;

[QEGVAR(medical,woundReceived), FUNC(handleWoundReceived)] call CBA_fnc_addEventHandler;
}] call CBA_fnc_addEventHandler;
2 changes: 1 addition & 1 deletion addons/medical_blood/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ class CfgPatches {
};
};

#include "ACE_Settings.hpp"
#include "CfgEventHandlers.hpp"
#include "ACE_Settings.hpp"
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
#include "script_component.hpp"
/*
* Author: PabstMirror
* Loop that cleans up blood
* Handles cleaning up blood objects that have reached the end of their lifetime.
*
* Arguments:
* None
*
* ReturnValue:
* Return Value:
* None
*
* Example:
* [] call ace_medical_blood_fnc_cleanupLoop
*
* Public: No
*/

(GVAR(bloodDrops) deleteAt 0) params ["", "_deletedBloodDrop"];
deleteVehicle _deletedBloodDrop;

// If we cleaned out the array, exit loop
// Exit the loop if we have cleaned out the array
if (GVAR(bloodDrops) isEqualTo []) exitWith {};

// Wait until the next blood drop in the queue will expire
(GVAR(bloodDrops) select 0) params ["_expireTime"];
[FUNC(serverCleanupBlood), [], (_expireTime - CBA_missionTime)] call CBA_fnc_waitAndExecute;
[FUNC(cleanupLoop), [], _expireTime - CBA_missionTime] call CBA_fnc_waitAndExecute;
20 changes: 10 additions & 10 deletions addons/medical_blood/functions/fnc_createBlood.sqf
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
#include "script_component.hpp"
/*
* Author: Glowbal
* Spawn a blood drop.
* Creates a blood object and handles its cleanup.
* Available blood drop classes are blooddrop_1 through blooddrop_4.
*
* Arguments:
* 0: classname of blood drop <OBJECT>
* 0: Blood Drop Type <STRING>
* 1: Position <ARRAY>
*
* Return Value:
* Created blood drop <OBJECT>
* Blood Drop <OBJECT>
*
* Example:
* ["blooddrop_2", getPos player] call ace_medical_blood_fnc_createBlood
*
* Public: No
*/

params ["_type", "_pos"];
TRACE_2("creating blood",_type,_pos);
params ["_type", "_position"];
TRACE_2("Creating blood",_type,_position);

private _model = GVAR(models) getVariable _type;

private _object = createSimpleObject [_model, [0,0,0]];
_object setDir random 360;
_object setPos _pos;
private _bloodDrop = createSimpleObject [_model, [0, 0, 0]];
_bloodDrop setDir random 360;
_bloodDrop setPos _position;

[QGVAR(bloodDropCreated), [_object]] call CBA_fnc_serverEvent;
[QGVAR(bloodDropCreated), _bloodDrop] call CBA_fnc_serverEvent;

_object
_bloodDrop
28 changes: 14 additions & 14 deletions addons/medical_blood/functions/fnc_handleWoundReceived.sqf
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "script_component.hpp"
/*
* Author: Glowbal, commy2
* Handle wounds received event.
* Handles the wounds received event by triggering any needed blood creation.
*
* Arguments:
* 0: unit <OBJECT>
* 1: bodyPart <String>
* 2: damage <NUMBER>
* 3: shooter <OBJECT>
* 0: Unit <OBJECT>
* 1: Body Part (not used) <STRING>
* 2: Damage <NUMBER>
* 3: Shooter <OBJECT>
*
* Return Value:
* None
Expand All @@ -20,16 +20,16 @@

params ["_unit", "", "_damage", "_shooter"];

if (GVAR(enabledFor) == 1 && {!isPlayer _unit && {_unit != ACE_player}}) exitWith {};
if (vehicle _unit != _unit && {!((vehicle _unit) isKindOf "StaticWeapon")}) exitWith {}; // Don't bleed on ground if mounted
// Don't bleed when players only and a non-player unit is wounded
if (GVAR(enabledFor) == BLOOD_ONLY_PLAYERS && {!isPlayer _unit && {_unit != ACE_player}}) exitWith {};

_damage = _damage min 1;
// Don't bleed on the ground if in a vehicle
if (vehicle _unit != _unit && {!(vehicle _unit isKindOf "StaticWeapon")}) exitWith {};

if (isNull _shooter) exitWith { // won't be able to calculate the direction properly, so instead we pick something at random
[QGVAR(spurt), [_unit, random 360, _damage]] call CBA_fnc_serverEvent;
private _bulletDir = if (isNull _shooter) then {
random 360 // Cannot calculate the direction properly, pick a random direction
} else {
_shooter getDir _unit // Calculate the bullet direction
};

// Calculate bulletDirection
private _bulletDir = _shooter getDir _unit;

[QGVAR(spurt), [_unit, _bulletDir, _damage]] call CBA_fnc_serverEvent;
[QGVAR(spurt), [_unit, _bulletDir, _damage min 1]] call CBA_fnc_serverEvent;
65 changes: 65 additions & 0 deletions addons/medical_blood/functions/fnc_init.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include "script_component.hpp"
/*
* Author: mharis001
* Initializes the medical blood system based on the given mode.
* Should only be called from the CBA setting changed script.
*
* Arguments:
* 0: Mode <NUMBER>
*
* Return Value:
* None
*
* Example:
* [2] call ace_medical_blood_fnc_init
*
* Public: No
*/

params ["_mode"];

// Exit if setting is refreshed to the same value
if (!isNil QGVAR(currentSetup) && {_mode == GVAR(currentSetup)}) exitWith {
TRACE_2("Setting refreshed to current setup",GVAR(currentSetup),_mode);
};

// Track this new configuration that will be set up
GVAR(currentSetup) = _mode;

// Delete current state machine if it exists
if (!isNil QGVAR(stateMachine)) then {
GVAR(stateMachine) call CBA_statemachine_fnc_delete;
GVAR(stateMachine) = nil;
};

// Remove wound received if it was previously added
if (!isNil QGVAR(woundReceivedEH)) then {
[QEGVAR(medical,woundReceived), GVAR(woundReceivedEH)] call CBA_fnc_removeEventHandler;
GVAR(woundReceivedEH) = nil;
};

// Don't need to set up anything if blood is disabled or players only on a non-player machine
if (_mode == BLOOD_DISABLED || {_mode == BLOOD_ONLY_PLAYERS && {!hasInterface}}) exitWith {
TRACE_1("Mode does not require any setup",_mode);
};

private _listCode = if (_mode == BLOOD_ONLY_PLAYERS) then {
// ACE_player is the only possible local player
{
if (alive ACE_player) then {
[ACE_player]
} else {
[]
};
}
} else {
// Filter all local units
EFUNC(common,getLocalUnits)
};

GVAR(stateMachine) = [_listCode, true] call CBA_statemachine_fnc_create;
[GVAR(stateMachine), LINKFUNC(onBleeding), {}, {}, "Bleeding"] call CBA_statemachine_fnc_addState;

GVAR(woundReceivedEH) = [QEGVAR(medical,woundReceived), FUNC(handleWoundReceived)] call CBA_fnc_addEventHandler;

TRACE_3("Set up state machine and wounds event",_mode,GVAR(stateMachine),GVAR(woundReceivedEH));
6 changes: 3 additions & 3 deletions addons/medical_blood/functions/fnc_isBleeding.sqf
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "script_component.hpp"
/*
* Author: Glowbal
* Check if is bleeding
* Checks if the given unit is bleeding. Handles both ACE Medical and Vanilla.
*
* Arguments:
* 0: unit <TYPE>
* 0: Unit <OBJECT>
*
* Return Value:
* is Bleeding <BOOL>
* Is Bleeding <BOOL>
*
* Example:
* [player] call ace_medical_blood_fnc_isBleeding
Expand Down
Loading