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

Sitting Framework #2620

Merged
merged 7 commits into from
Oct 18, 2015
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
7 changes: 1 addition & 6 deletions addons/dragging/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
};
Expand Down
9 changes: 9 additions & 0 deletions addons/sitting/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
};
};
};
48 changes: 18 additions & 30 deletions addons/sitting/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};
2 changes: 1 addition & 1 deletion addons/sitting/XEH_clientInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions addons/sitting/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

ADDON = false;

PREP(addSitActions);
PREP(canSit);
PREP(canStand);
PREP(getRandomAnimation);
Expand All @@ -10,4 +11,6 @@ PREP(moduleInit);
PREP(sit);
PREP(stand);

GVAR(initializedClasses) = [];

ADDON = true;
42 changes: 42 additions & 0 deletions addons/sitting/functions/fnc_addSitActions.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Author: Jonpas
* Adds sit actions.
*
* Arguments:
* 0: Seat <OBJECT>
*
* 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);
6 changes: 2 additions & 4 deletions addons/sitting/functions/fnc_canSit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,20 @@
*
* Arguments:
* 0: Seat <OBJECT>
* 1: Player <OBJECT>
*
* Return Value:
* Can Sit Down <BOOL>
*
* 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}}
2 changes: 1 addition & 1 deletion addons/sitting/functions/fnc_canStand.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
params ["_player"];

// Sitting
(_player getVariable [QGVAR(isSitting), false])
!isNil {_player getVariable QGVAR(isSitting)}
2 changes: 1 addition & 1 deletion addons/sitting/functions/fnc_handleInterrupt.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@

params ["_player"];

if (_player getVariable [QGVAR(isSitting), false]) then {
if (!isNil {_player getVariable QGVAR(isSitting)}) then {
_player call FUNC(stand);
};
20 changes: 4 additions & 16 deletions addons/sitting/functions/fnc_sit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 ["<t color='#FFFF00'>%1</t>", localize LSTRING(Stand)],
QUOTE((_this select 0) call FUNC(stand)),
Expand All @@ -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
Expand All @@ -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


Expand All @@ -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)]);
};
Expand Down
12 changes: 7 additions & 5 deletions addons/sitting/functions/fnc_stand.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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"};
Expand All @@ -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];