diff --git a/addons/dragging/CfgEventHandlers.hpp b/addons/dragging/CfgEventHandlers.hpp index 2ff7d07c0da..532038c2c59 100644 --- a/addons/dragging/CfgEventHandlers.hpp +++ b/addons/dragging/CfgEventHandlers.hpp @@ -23,12 +23,7 @@ class Extended_Init_EventHandlers { init = QUOTE(_this call DFUNC(initObject)); }; }; - class ReammoBox_F { - class ADDON { - init = QUOTE(_this call DFUNC(initObject)); - }; - }; - class ACE_RepairItem_Base { + class ThingX { class ADDON { init = QUOTE(_this call DFUNC(initObject)); }; diff --git a/addons/sitting/CfgEventHandlers.hpp b/addons/sitting/CfgEventHandlers.hpp index 1e804e8cc9a..da7efe16013 100644 --- a/addons/sitting/CfgEventHandlers.hpp +++ b/addons/sitting/CfgEventHandlers.hpp @@ -17,3 +17,12 @@ class Extended_Killed_EventHandlers { }; }; }; + +// Need initPost or there are problems with setVariable +class Extended_InitPost_EventHandlers { + class ThingX { + class ADDON { + init = QUOTE(_this call DFUNC(addSitActions)) + }; + }; +}; diff --git a/addons/sitting/CfgVehicles.hpp b/addons/sitting/CfgVehicles.hpp index a156d5e87e1..4ac0d0edb79 100644 --- a/addons/sitting/CfgVehicles.hpp +++ b/addons/sitting/CfgVehicles.hpp @@ -34,79 +34,67 @@ class CfgVehicles { }; }; - #define MACRO_SEAT_ACTION \ - class ACE_Actions { \ - class ACE_MainActions { \ - displayName = ECSTRING(interaction,MainAction); \ - selection = ""; \ - distance = 1.5; \ - condition = "true"; \ - class GVAR(Sit) { \ - displayName = CSTRING(Sit); \ - condition = QUOTE(_this call FUNC(canSit)); \ - statement = QUOTE(_this call FUNC(sit)); \ - showDisabled = 0; \ - priority = 0; \ - icon = PATHTOF(UI\sit_ca.paa); \ - }; \ - }; \ - }; - class ThingX; // Folding Chair class Land_CampingChair_V1_F: ThingX { XEH_ENABLED; - MACRO_SEAT_ACTION GVAR(canSit) = 1; GVAR(sitDirection) = 180; GVAR(sitPosition[]) = {0, -0.1, -0.45}; - GVAR(sitRotation) = 10; + EGVAR(dragging,canCarry) = 1; + EGVAR(dragging,carryPosition[]) = {0, 0.75, 0.5}; + EGVAR(dragging,carryDirection) = 180; }; // Camping Chair class Land_CampingChair_V2_F: ThingX { XEH_ENABLED; - MACRO_SEAT_ACTION GVAR(canSit) = 1; GVAR(sitDirection) = 180; GVAR(sitPosition[]) = {0, -0.1, -0.45}; - GVAR(sitRotation) = 45; + EGVAR(dragging,canCarry) = 1; + EGVAR(dragging,carryPosition[]) = {0, 0.75, 0.5}; + EGVAR(dragging,carryDirection) = 180; }; class Furniture_base_F; // Chair (Plastic) class Land_ChairPlastic_F: Furniture_base_F { XEH_ENABLED; - MACRO_SEAT_ACTION GVAR(canSit) = 1; GVAR(sitDirection) = 90; GVAR(sitPosition[]) = {0, 0, -0.5}; - GVAR(sitRotation) = 5; + EGVAR(dragging,canCarry) = 1; + EGVAR(dragging,carryPosition[]) = {0, 0.75, 0.5}; + EGVAR(dragging,carryDirection) = 270; }; // Chair (Wooden) class Land_ChairWood_F: Furniture_base_F { XEH_ENABLED; - MACRO_SEAT_ACTION GVAR(canSit) = 1; GVAR(sitDirection) = 180; GVAR(sitPosition[]) = {0, -0.05, 0}; - GVAR(sitRotation) = 75; + EGVAR(dragging,canCarry) = 1; + EGVAR(dragging,carryPosition[]) = {0, 0.75, 0.5}; + EGVAR(dragging,carryDirection) = 180; }; // Office Chair class Land_OfficeChair_01_F: Furniture_base_F { XEH_ENABLED; - MACRO_SEAT_ACTION GVAR(canSit) = 1; GVAR(sitDirection) = 180; GVAR(sitPosition[]) = {0, 0, -0.6}; - GVAR(sitRotation) = 15; + EGVAR(dragging,canCarry) = 1; + EGVAR(dragging,carryPosition[]) = {0, 0.75, 0.5}; + EGVAR(dragging,carryDirection) = 180; }; // Rattan Chair class Land_RattanChair_01_F: Furniture_base_F { XEH_ENABLED; - MACRO_SEAT_ACTION GVAR(canSit) = 1; GVAR(sitDirection) = 180; GVAR(sitPosition[]) = {0, -0.1, -1}; // Z must be -1 due to chair's geometry (magic floating seat point) - GVAR(sitRotation) = 2; + EGVAR(dragging,canCarry) = 1; + EGVAR(dragging,carryPosition[]) = {0, 0.75, 0.5}; + EGVAR(dragging,carryDirection) = 180; }; }; diff --git a/addons/sitting/XEH_clientInit.sqf b/addons/sitting/XEH_clientInit.sqf index 9cf8278877f..23816bd8d77 100644 --- a/addons/sitting/XEH_clientInit.sqf +++ b/addons/sitting/XEH_clientInit.sqf @@ -4,7 +4,7 @@ if (!hasInterface) exitWith {}; // Add interaction menu exception -["isNotSitting", {!((_this select 0) getVariable [QGVAR(isSitting), false])}] call EFUNC(common,addCanInteractWithCondition); +["isNotSitting", {isNil {(_this select 0) getVariable QGVAR(isSitting)}}] call EFUNC(common,addCanInteractWithCondition); // Handle interruptions ["medical_onUnconscious", {_this call DFUNC(handleInterrupt)}] call EFUNC(common,addEventhandler); diff --git a/addons/sitting/XEH_preInit.sqf b/addons/sitting/XEH_preInit.sqf index 86912ada6b2..15ffe281c8d 100644 --- a/addons/sitting/XEH_preInit.sqf +++ b/addons/sitting/XEH_preInit.sqf @@ -2,6 +2,7 @@ ADDON = false; +PREP(addSitActions); PREP(canSit); PREP(canStand); PREP(getRandomAnimation); @@ -10,4 +11,6 @@ PREP(moduleInit); PREP(sit); PREP(stand); +GVAR(initializedClasses) = []; + ADDON = true; diff --git a/addons/sitting/functions/fnc_addSitActions.sqf b/addons/sitting/functions/fnc_addSitActions.sqf new file mode 100644 index 00000000000..18779d9229d --- /dev/null +++ b/addons/sitting/functions/fnc_addSitActions.sqf @@ -0,0 +1,42 @@ +/* + * Author: Jonpas + * Adds sit actions. + * + * Arguments: + * 0: Seat + * + * Return Value: + * None + * + * Example: + * [seat] call ace_sitting_fnc_addSitActions + * + * Public: No + */ +#include "script_component.hpp" + +params ["_seat"]; +private ["_type", "_sitAction"]; + +_type = typeOf _seat; + +// Exit if the object is not specified as a seat +if (getNumber (configFile >> "CfgVehicles" >> _type >> QGVAR(canSit)) != 1) exitWith {}; + +// Exit if class already initialized +if (_type in GVAR(initializedClasses)) exitWith {}; + +GVAR(initializedClasses) pushBack _type; + +_sitAction = [ + QGVAR(Sit), + localize LSTRING(Sit), + QUOTE(PATHTOF(UI\sit_ca.paa)), + {_this call FUNC(sit)}, + {_this call FUNC(canSit)}, + {}, + [], + [0, 0, 0], + 1.5 +] call EFUNC(interact_menu,createAction); +[_type, 0, ["ACE_MainActions"], _sitAction] call EFUNC(interact_menu,addActionToClass); diff --git a/addons/sitting/functions/fnc_canSit.sqf b/addons/sitting/functions/fnc_canSit.sqf index fef36b4bbd2..1dd0c9676f5 100644 --- a/addons/sitting/functions/fnc_canSit.sqf +++ b/addons/sitting/functions/fnc_canSit.sqf @@ -4,22 +4,20 @@ * * Arguments: * 0: Seat - * 1: Player * * Return Value: * Can Sit Down * * Example: - * [seat, player] call ace_sitting_fnc_canSit + * [seat] call ace_sitting_fnc_canSit * * Public: No */ #include "script_component.hpp" -params ["_seat", "_player"]; +params ["_seat"]; // Sitting enabled, is seat object, not occupied and standing up (or not on a big slope) GVAR(enable) && -{getNumber (configFile >> "CfgVehicles" >> typeOf _seat >> QGVAR(canSit)) == 1} && {isNil {_seat getVariable QGVAR(seatOccupied)}} && {round (vectorUp _seat select 0) == 0 && {round (vectorUp _seat select 1) == 0} && {round (vectorUp _seat select 2) == 1}} diff --git a/addons/sitting/functions/fnc_canStand.sqf b/addons/sitting/functions/fnc_canStand.sqf index c516485a824..a051e1784e3 100644 --- a/addons/sitting/functions/fnc_canStand.sqf +++ b/addons/sitting/functions/fnc_canStand.sqf @@ -18,4 +18,4 @@ params ["_player"]; // Sitting -(_player getVariable [QGVAR(isSitting), false]) +!isNil {_player getVariable QGVAR(isSitting)} diff --git a/addons/sitting/functions/fnc_handleInterrupt.sqf b/addons/sitting/functions/fnc_handleInterrupt.sqf index 328675c1720..c7e0a545ffb 100644 --- a/addons/sitting/functions/fnc_handleInterrupt.sqf +++ b/addons/sitting/functions/fnc_handleInterrupt.sqf @@ -17,6 +17,6 @@ params ["_player"]; -if (_player getVariable [QGVAR(isSitting), false]) then { +if (!isNil {_player getVariable QGVAR(isSitting)}) then { _player call FUNC(stand); }; diff --git a/addons/sitting/functions/fnc_sit.sqf b/addons/sitting/functions/fnc_sit.sqf index 5e9c36947eb..821bb230d15 100644 --- a/addons/sitting/functions/fnc_sit.sqf +++ b/addons/sitting/functions/fnc_sit.sqf @@ -16,23 +16,14 @@ */ #include "script_component.hpp" -private ["_actionID", "_configFile", "_sitDirection", "_sitPosition", "_sitRotation", "_seatPosOrig"]; +private ["_actionID", "_configFile", "_sitDirection", "_sitPosition", "_seatPosOrig"]; params ["_seat", "_player"]; -// Set global variable for standing up -GVAR(seat) = _seat; - // Overwrite weird position, because Arma decides to set it differently based on current animation/stance... _player switchMove "amovpknlmstpsraswrfldnon"; // Add scroll-wheel action to release object -_actionID = _player getVariable [QGVAR(StandUpActionID), -1]; - -if (_actionID != -1) then { - _player removeAction _actionID; -}; - _actionID = _player addAction [ format ["%1", localize LSTRING(Stand)], QUOTE((_this select 0) call FUNC(stand)), @@ -44,13 +35,10 @@ _actionID = _player addAction [ QUOTE(_this call FUNC(canStand)) ]; -_player setVariable [QGVAR(StandUpActionID), _actionID]; - // Read config _configFile = configFile >> "CfgVehicles" >> typeOf _seat; _sitDirection = (getDir _seat) + getNumber (_configFile >> QGVAR(sitDirection)); _sitPosition = getArray (_configFile >> QGVAR(sitPosition)); -_sitRotation = if (isNumber (_configFile >> QGVAR(sitRotation))) then {getNumber (_configFile >> QGVAR(sitRotation))} else {45}; // Apply default if config entry not present // Get random animation and perform it (before moving player to ensure correct placement) [_player, call FUNC(getRandomAnimation), 2] call EFUNC(common,doAnimation); // Correctly places when using non-transitional animations @@ -61,8 +49,8 @@ _player setDir _sitDirection; // No need for ATL/ASL as modelToWorld returns in format position _player setPos (_seat modelToWorld _sitPosition); -// Set variables -_player setVariable [QGVAR(isSitting), true]; +// Set variables, save seat object on player +_player setVariable [QGVAR(isSitting), [_seat, _actionID]]; _seat setVariable [QGVAR(seatOccupied), true, true]; // To prevent multiple people sitting on one seat @@ -73,7 +61,7 @@ _seatPosOrig = getPosASL _seat; _args params ["_player", "_seat", "_seatPosOrig"]; // Remove PFH if not sitting any more - if !(_player getVariable [QGVAR(isSitting), false]) exitWith { + if (isNil {_player getVariable QGVAR(isSitting)}) exitWith { [_pfhId] call CBA_fnc_removePerFrameHandler; TRACE_1("Remove PFH",_player getVariable [ARR_2(QGVAR(isSitting), false)]); }; diff --git a/addons/sitting/functions/fnc_stand.sqf b/addons/sitting/functions/fnc_stand.sqf index ef19d5f5867..4c08461746e 100644 --- a/addons/sitting/functions/fnc_stand.sqf +++ b/addons/sitting/functions/fnc_stand.sqf @@ -16,12 +16,14 @@ #include "script_component.hpp" params ["_player"]; +private ["_animation"]; -// remove scroll wheel action -_player removeAction (_player getVariable [QGVAR(StandUpActionID), -1]); +(_player getVariable QGVAR(isSitting)) params ["_seat", "_actionID"]; + +// Remove scroll-wheel action +_player removeAction _actionID; // Restore animation -private "_animation"; _animation = switch (currentWeapon _player) do { case "": {"amovpercmstpsnonwnondnon"}; case (primaryWeapon _player): {"amovpercmstpslowwrfldnon"}; @@ -33,5 +35,5 @@ _animation = switch (currentWeapon _player) do { // Set variables to nil _player setVariable [QGVAR(isSitting), nil]; -GVAR(seat) setVariable [QGVAR(seatOccupied), nil, true]; -GVAR(seat) = nil; +if (isNull _seat) exitWith {}; +_seat setVariable [QGVAR(seatOccupied), nil, true];