From 81d962f0d5189617c568eac99f64f366fd706d9e Mon Sep 17 00:00:00 2001 From: commy2 Date: Mon, 19 Sep 2016 09:55:30 +0200 Subject: [PATCH] port litter to treatment --- addons/medical/XEH_postInit.sqf | 1 - addons/medical/functions/fnc_createLitter.sqf | 93 ------------------ addons/medical_treatment/XEH_PREP.hpp | 6 ++ addons/medical_treatment/XEH_postInit.sqf | 2 + .../functions/fnc_litterCleanupLoop.sqf | 13 ++- .../functions/fnc_litterCreate.sqf | 98 +++++++++++++++++++ .../functions/fnc_litterHandleCreate.sqf} | 33 ++++--- .../functions/fnc_treatment_success.sqf | 2 +- 8 files changed, 137 insertions(+), 111 deletions(-) delete mode 100644 addons/medical/functions/fnc_createLitter.sqf rename addons/{medical => medical_treatment}/functions/fnc_litterCleanupLoop.sqf (71%) create mode 100644 addons/medical_treatment/functions/fnc_litterCreate.sqf rename addons/{medical/functions/fnc_handleCreateLitter.sqf => medical_treatment/functions/fnc_litterHandleCreate.sqf} (61%) diff --git a/addons/medical/XEH_postInit.sqf b/addons/medical/XEH_postInit.sqf index efb221066c..5e01a649da 100644 --- a/addons/medical/XEH_postInit.sqf +++ b/addons/medical/XEH_postInit.sqf @@ -11,7 +11,6 @@ call FUNC(stateMachine); if (isServer) then { ["ace_placedInBodyBag", FUNC(serverRemoveBody)] call CBA_fnc_addEventHandler; }; -[QGVAR(createLitterServer), FUNC(handleCreateLitter)] call CBA_fnc_addEventHandler; ["ace_unconscious", { params ["_unit", "_status"]; diff --git a/addons/medical/functions/fnc_createLitter.sqf b/addons/medical/functions/fnc_createLitter.sqf deleted file mode 100644 index 2780642056..0000000000 --- a/addons/medical/functions/fnc_createLitter.sqf +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Author: Glowbal - * Spawns litter for the treatment action on the ground around the target - * - * Arguments: - * 0: The Caller - * 1: The target - * 2: The treatment Selection Name - * 3: The treatment classname - * 4: ? - * 5: Users of Items - * 6: Blood Loss on selection (previously called _previousDamage) - * - * Return Value: - * None - * - * Public: No - */ - -#include "script_component.hpp" - -#define MIN_ENTRIES_LITTER_CONFIG 3 - -params ["_caller", "_target", "_selectionName", "_className", "", "_usersOfItems", "_bloodLossOnSelection"]; -TRACE_6("params",_caller,_target,_selectionName,_className,_usersOfItems,_bloodLossOnSelection); - -//Ensures comptibilty with other possible medical treatment configs -private _previousDamage = _bloodLossOnSelection; - -if !(GVAR(allowLitterCreation)) exitwith {}; -if (vehicle _caller != _caller || {vehicle _target != _target}) exitwith {}; - -private _config = if (GVAR(level) >= 2) then { - (configFile >> "ACE_Medical_Actions" >> "Advanced" >> _className); -} else { - (configFile >> "ACE_Medical_Actions" >> "Basic" >> _className) -}; -if !(isClass _config) exitwith {TRACE_1("No action config", _className);}; - -if !(isArray (_config >> "litter")) exitwith {TRACE_1("No litter config", _className);}; -private _litter = getArray (_config >> "litter"); - -private _createLitter = { - params ["_unit", "_litterClass"]; - // @TODO: handle carriers over water - // For now, don't spawn litter if we are over water to avoid floating litter - if (surfaceIsWater (getPos _unit)) exitWith { false }; - - private _position = getPosATL _unit; - _position params ["_posX", "_posY", "_posZ"]; - _position = [_posX + (random 2) - 1, _posY + (random 2) - 1, _posZ]; - - private _direction = (random 360); - - // Create the litter, and timeout the event based on the cleanup delay - // The cleanup delay for events in MP is handled by the server side - TRACE_3("Creating Litter on server",_litterClass,_position,_direction); - [QGVAR(createLitterServer), [_litterClass, _position, _direction]] call CBA_fnc_serverEvent; - - true -}; - -private _createdLitter = []; -{ - if (_x isEqualType []) then { - if (count _x < MIN_ENTRIES_LITTER_CONFIG) exitwith {}; - - _x params ["_selection", "_litterCondition", "_litterOptions"]; - - if (toLower _selection in [toLower _selectionName, "all"]) then { // in is case sensitve. We can be forgiving here, so lets use toLower. - - if (isnil _litterCondition) then { - _litterCondition = if (_litterCondition != "") then {compile _litterCondition} else {{true}}; - } else { - _litterCondition = missionNamespace getVariable _litterCondition; - if (!(_litterCondition isEqualType {})) then {_litterCondition = {false}}; - }; - if !([_caller, _target, _selectionName, _className, _usersOfItems, _bloodLossOnSelection] call _litterCondition) exitwith {}; - - if (_litterOptions isEqualType []) then { - // Loop through through the litter options and place the litter - { - if (_x isEqualType [] && {(count _x > 0)}) then { - [_target, selectRandom _x] call _createLitter; - }; - if (_x isEqualType "") then { - [_target, _x] call _createLitter; - }; - } foreach _litterOptions; - }; - }; - }; -} foreach _litter; diff --git a/addons/medical_treatment/XEH_PREP.hpp b/addons/medical_treatment/XEH_PREP.hpp index 078c0336ad..44451d2b6d 100644 --- a/addons/medical_treatment/XEH_PREP.hpp +++ b/addons/medical_treatment/XEH_PREP.hpp @@ -1,3 +1,4 @@ + PREP(actionCheckBloodPressure); PREP(actionCheckBloodPressureLocal); PREP(actionCheckPulse); @@ -52,3 +53,8 @@ PREP(useItem); PREP(useItems); PREP(checkItems); + +// litter +PREP(litterCreate); +PREP(litterHandleCreate); +PREP(litterCleanupLoop); diff --git a/addons/medical_treatment/XEH_postInit.sqf b/addons/medical_treatment/XEH_postInit.sqf index 9353b09c0e..bbc091c8a8 100644 --- a/addons/medical_treatment/XEH_postInit.sqf +++ b/addons/medical_treatment/XEH_postInit.sqf @@ -5,3 +5,5 @@ params ["_unit"]; _unit call FUNC(checkItems); }] call CBA_fnc_addEventHandler; + +[QGVAR(createLitterServer), FUNC(litterHandleCreate)] call CBA_fnc_addEventHandler; diff --git a/addons/medical/functions/fnc_litterCleanupLoop.sqf b/addons/medical_treatment/functions/fnc_litterCleanupLoop.sqf similarity index 71% rename from addons/medical/functions/fnc_litterCleanupLoop.sqf rename to addons/medical_treatment/functions/fnc_litterCleanupLoop.sqf index 417144dd64..ee3ff5d811 100644 --- a/addons/medical/functions/fnc_litterCleanupLoop.sqf +++ b/addons/medical_treatment/functions/fnc_litterCleanupLoop.sqf @@ -10,25 +10,28 @@ * * Public: No */ - #include "script_component.hpp" { _x params ["_time", "_objects"]; - //Older elements are always at the begining of the array: - if ((CBA_missionTime - _time) < GVAR(litterCleanUpDelay)) exitWith {}; + + // Older elements are always at the begining of the array + if (CBA_missionTime - _time < GVAR(litterCleanUpDelay)) exitWith {}; + TRACE_2("deleting",_time,_objects); { deleteVehicle _x; } forEach _objects; + GVAR(allCreatedLitter) set [_forEachIndex, objNull]; } forEach GVAR(allCreatedLitter); + GVAR(allCreatedLitter) = GVAR(allCreatedLitter) - [objNull]; -// If no more litter remaining, exit the loop +// If no more litter remain, exit the loop if (GVAR(allCreatedLitter) isEqualTo []) exitWith { GVAR(litterPFHRunning) = false; }; // Schedule the loop to be executed again 30 sec later -[DFUNC(litterCleanupLoop), [], 30] call CBA_fnc_waitAndExecute; +[FUNC(litterCleanupLoop), [], 30] call CBA_fnc_waitAndExecute; diff --git a/addons/medical_treatment/functions/fnc_litterCreate.sqf b/addons/medical_treatment/functions/fnc_litterCreate.sqf new file mode 100644 index 0000000000..115fa10c07 --- /dev/null +++ b/addons/medical_treatment/functions/fnc_litterCreate.sqf @@ -0,0 +1,98 @@ +/* + * Author: Glowbal + * Spawns litter for the treatment action on the ground around the target + * + * Arguments: + * 0: The Caller + * 1: The target + * 2: The treatment Selection Name + * 3: The treatment classname + * 4: ? + * 5: Users of Items + * 6: Blood Loss on selection (previously called _previousDamage) + * + * Return Value: + * None + * + * Public: No + */ +#include "script_component.hpp" + +#define MIN_ENTRIES_LITTER_CONFIG 3 + +params ["_caller", "_target", "_selectionName", "_className", "", "_usersOfItems", "_bloodLossOnSelection"]; +TRACE_6("params",_caller,_target,_selectionName,_className,_usersOfItems,_bloodLossOnSelection); + +// Ensures comptibilty with other possible medical treatment configs +private _previousDamage = _bloodLossOnSelection; + +// Exit if litter is disabled by setting +if !(EGVAR(medical,allowLitterCreation)) exitWith {}; + +// Don't create litter if medic or patient are inside a vehicle +if (vehicle _caller != _caller || {vehicle _target != _target}) exitWith {}; + +private _config = configFile >> "ACE_Medical_Treatment_Actions" >> ["Basic", "Advanced"] select (EGVAR(medical,level) >= 2) >> _className; +if !(isClass _config) exitWith {TRACE_1("No action config",_className);}; + +if !(isArray (_config >> "litter")) exitWith {TRACE_1("No litter config",_className);}; +private _litter = getArray (_config >> "litter"); + +private _createLitter = { + params ["_unit", "_litterClass"]; + + private _position = getPosASL _unit; + + // @TODO: handle carriers over water + // For now, don't spawn litter if we are over water to avoid floating litter + if (surfaceIsWater _position) exitWith {false}; + + _position = _position vectorAdd [ + random 2 - 1, + random 2 - 1, + 0 + ]; + + private _direction = random 360; + + // Create the litter, and timeout the event based on the cleanup delay + // The cleanup delay for events in MP is handled by the server side + TRACE_3("Creating Litter on server",_litterClass,_position,_direction); + [QGVAR(createLitterServer), [_litterClass, _position, _direction]] call CBA_fnc_serverEvent; + + true +}; + +{ + if (count _x < MIN_ENTRIES_LITTER_CONFIG) then { + WARNING_1("Wrong litter array: %1",_x); + } else { + _x params [ + ["_selection", "", [""]], + ["_litterCondition", "", [""]], + ["_litterOptions", [], [[]]] + ]; + + if (toLower _selection in [toLower _selectionName, "all"]) then { + if (_litterCondition isEqualTo "") then { + _litterCondition = {true}; + } else { + _litterCondition = compile _litterCondition; + }; + + // existing configs seem to use carried over magic variables. we pass them as arguments (_this) anyway + if !([_caller, _target, _selectionName, _className, _usersOfItems, _bloodLossOnSelection] call _litterCondition) exitWith {}; + + // Loop through through the litter options and place the litter + { + if (_x isEqualType "") then { + [_target, _x] call _createLitter; + }; + + if (_x isEqualType [] && {count _x > 0}) then { + [_target, selectRandom _x] call _createLitter; + }; + } foreach _litterOptions; + }; + }; +} foreach _litter; diff --git a/addons/medical/functions/fnc_handleCreateLitter.sqf b/addons/medical_treatment/functions/fnc_litterHandleCreate.sqf similarity index 61% rename from addons/medical/functions/fnc_handleCreateLitter.sqf rename to addons/medical_treatment/functions/fnc_litterHandleCreate.sqf index 2c701a2917..8c5fe49dd7 100644 --- a/addons/medical/functions/fnc_handleCreateLitter.sqf +++ b/addons/medical_treatment/functions/fnc_litterHandleCreate.sqf @@ -24,22 +24,33 @@ if (isNil QGVAR(allCreatedLitter)) then { GVAR(litterPFHRunning) = false; }; -private _p3dFile = getText (configFile >> "CfgVehicles" >> _litterClass >> "model"); -if (_p3dFile == "") exitWith {TRACE_2("no model",_litterClass,_p3dFile)}; +private _model = getText (configFile >> "CfgVehicles" >> _litterClass >> "model"); +if (_model == "") exitWith {TRACE_2("no model",_litterClass,_model)}; + // createSimpleObject expects a path without the leading slash -if ((_p3dFile select [0,1]) == "\") then {_p3dFile = _p3dFile select [1];}; +if (_model select [0,1] == "\") then { + _model = _model select [1]; +}; -private _litterObject = createSimpleObject [_p3dFile, [0,0,0]]; +private _litterObject = createSimpleObject [_model, [0,0,0]]; TRACE_2("created",_litterClass,_litterObject); -_litterObject setDir _direction; -_litterObject setPosATL _position; -// Move the litter next frame to get rid of HORRIBLE spacing, fixes #1112 -[{ params ["_object", "_pos"]; _object setPosATL _pos; }, [_litterObject, _position]] call CBA_fnc_execNextFrame; -private _maxLitterCount = getArray (configFile >> "ACE_Settings" >> QGVAR(litterSimulationDetail) >> "_values") select GVAR(litterSimulationDetail); -if ((count GVAR(allCreatedLitter)) > _maxLitterCount) then { +_litterObject setDir _direction; +_litterObject setPosASL _position; + +// Move the litter next frame to get rid of HORRIBLE spacing, fixes #1112 +[{ + params ["_object", "_position"]; + + _object setPosASL _position; +}, [_litterObject, _position]] call CBA_fnc_execNextFrame; + +private _maxLitterCount = getArray (configFile >> "ACE_Settings" >> QEGVAR(medical,litterSimulationDetail) >> "_values") select GVAR(medical,litterSimulationDetail); + +if (count GVAR(allCreatedLitter) > _maxLitterCount) then { // gank the first litter object, and spawn ours. private _oldLitter = GVAR(allCreatedLitter) deleteAt 0; + { deleteVehicle _x; } forEach (_oldLitter select 1); @@ -47,7 +58,7 @@ if ((count GVAR(allCreatedLitter)) > _maxLitterCount) then { GVAR(allCreatedLitter) pushBack [CBA_missionTime, [_litterObject]]; -if(!GVAR(litterPFHRunning) && {GVAR(litterCleanUpDelay) > 0}) then { +if (!GVAR(litterPFHRunning) && {GVAR(litterCleanUpDelay) > 0}) then { // Start the litter cleanup loop GVAR(litterPFHRunning) = true; call FUNC(litterCleanupLoop); diff --git a/addons/medical_treatment/functions/fnc_treatment_success.sqf b/addons/medical_treatment/functions/fnc_treatment_success.sqf index 33de6fb3bf..47ab77433c 100644 --- a/addons/medical_treatment/functions/fnc_treatment_success.sqf +++ b/addons/medical_treatment/functions/fnc_treatment_success.sqf @@ -81,7 +81,7 @@ TRACE_1("advanced",_bloodLossOnSelection); _args call _callback; _args pushBack _bloodLossOnSelection; -_args call FUNC(createLitter); +_args call FUNC(litterCreate); //If we're not already tracking vitals, start: if (!(_target getVariable [QGVAR(addedToUnitLoop),false])) then {