diff --git a/addons/sitting/CfgEventHandlers.hpp b/addons/sitting/CfgEventHandlers.hpp index 1e804e8cc9..bd13e623f0 100644 --- a/addons/sitting/CfgEventHandlers.hpp +++ b/addons/sitting/CfgEventHandlers.hpp @@ -17,3 +17,11 @@ class Extended_Killed_EventHandlers { }; }; }; + +class Extended_InitPost_EventHandlers { + class All { + class ADDON { + init = QUOTE(_this call DFUNC(addSitActions)) + }; + }; +}; diff --git a/addons/sitting/CfgVehicles.hpp b/addons/sitting/CfgVehicles.hpp index 7b0237d172..0d41ba1ed6 100644 --- a/addons/sitting/CfgVehicles.hpp +++ b/addons/sitting/CfgVehicles.hpp @@ -34,29 +34,10 @@ 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}; @@ -64,7 +45,6 @@ class CfgVehicles { // 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}; @@ -74,7 +54,6 @@ class CfgVehicles { // 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}; @@ -82,7 +61,6 @@ class CfgVehicles { // 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}; @@ -90,7 +68,6 @@ class CfgVehicles { // 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}; @@ -98,7 +75,6 @@ class CfgVehicles { // 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) diff --git a/addons/sitting/XEH_preInit.sqf b/addons/sitting/XEH_preInit.sqf index 86912ada6b..15ffe281c8 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 0000000000..18779d9229 --- /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 fef36b4bbd..1dd0c9676f 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_sit.sqf b/addons/sitting/functions/fnc_sit.sqf index e77e2d2b13..61872dd1a0 100644 --- a/addons/sitting/functions/fnc_sit.sqf +++ b/addons/sitting/functions/fnc_sit.sqf @@ -21,7 +21,7 @@ private ["_actionID", "_configFile", "_sitDirection", "_sitPosition", "_seatPosO params ["_seat", "_player"]; // Set global variable for standing up -GVAR(seat) = _seat; +GVAR(seat) = _seat; //@todo - put into player isSitting variable // Overwrite weird position, because Arma decides to set it differently based on current animation/stance... _player switchMove "amovpknlmstpsraswrfldnon";