Skip to content

Commit

Permalink
Merge pull request #1806 from jonpas/sittingFixes
Browse files Browse the repository at this point in the history
Akward Sitting Fixes Part 2
  • Loading branch information
thojkooi committed Jul 25, 2015
2 parents f0a2c7c + 815b798 commit 3514f07
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 8 deletions.
1 change: 0 additions & 1 deletion addons/sitting/XEH_clientInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ if !(hasInterface) exitWith {};
// Handle interruptions
["medical_onUnconscious", {_this call DFUNC(handleInterrupt)}] call EFUNC(common,addEventhandler);
["SetHandcuffed", {_this call DFUNC(handleInterrupt)}] call EFUNC(common,addEventhandler);
["SetSurrendered", {_this call DFUNC(handleInterrupt)}] call EFUNC(common,addEventhandler);
1 change: 1 addition & 0 deletions addons/sitting/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ PREP(canSit);
PREP(canStand);
PREP(getRandomAnimation);
PREP(handleInterrupt);
PREP(hasChairMoved);
PREP(moduleInit);
PREP(sit);
PREP(stand);
Expand Down
8 changes: 6 additions & 2 deletions addons/sitting/functions/fnc_canSit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@
*
* Public: No
*/
//#define DEBUG_MODE_FULL
#include "script_component.hpp"

PARAMS_2(_seat,_player);

// Sitting enabled, is seat object and not occupied
(GVAR(enable) && {getNumber (configFile >> "CfgVehicles" >> typeOf _seat >> QGVAR(canSit)) == 1} && {isNil{_seat getVariable QGVAR(seatOccupied)}})
// 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}}
4 changes: 2 additions & 2 deletions addons/sitting/functions/fnc_handleInterrupt.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* None
*
* Example:
* [player] call ace_sitting_fnc_handleInterrupt;
* player call ace_sitting_fnc_handleInterrupt;
*
* Public: No
*/
Expand All @@ -18,5 +18,5 @@
PARAMS_1(_player);

if (_player getVariable [QGVAR(isSitting), false]) then {
[_player] call FUNC(stand);
_player call FUNC(stand);
};
27 changes: 27 additions & 0 deletions addons/sitting/functions/fnc_hasChairMoved.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Author: Jonpas
* Checks if chair moved from original position.
*
* Arguments:
* 0: Seat <OBJECT>
* 1: Seat Position <ARRAY>
*
* Return Value:
* None
*
* Example:
* [seat, seatPos] call ace_sitting_fnc_hasChairMoved;
*
* Public: No
*/
//#define DEBUG_MODE_FULL
#include "script_component.hpp"

PARAMS_2(_seat,_seatPosOrig);

TRACE_2("Chair position",_seatPosOrig,getPosASL _seat);

// Check each coordinate due to possibility of tiny movements in simulation
(getPosASL _seat) select 0 < (_seatPosOrig select 0) - 0.01 || {(getPosASL _seat) select 0 > (_seatPosOrig select 0) + 0.01} ||
{(getPosASL _seat) select 1 < (_seatPosOrig select 1) - 0.01 || {(getPosASL _seat) select 1 > (_seatPosOrig select 1) + 0.01}} ||
{(getPosASL _seat) select 2 < (_seatPosOrig select 2) - 0.01 || {(getPosASL _seat) select 2 > (_seatPosOrig select 2) + 0.01}}
16 changes: 13 additions & 3 deletions addons/sitting/functions/fnc_sit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*
* Public: No
*/
//#define DEBUG_MODE_FULL
#include "script_component.hpp"

private ["_configFile", "_sitDirection", "_sitPosition", "_sitRotation", "_sitDirectionVisual"];
Expand All @@ -37,20 +38,29 @@ _sitRotation = if (isNumber (_configFile >> QGVAR(sitRotation))) then {getNumber

// Set direction and position
_player setDir _sitDirection;
_player setPosASL (_seat modelToWorld _sitPosition) call EFUNC(common,positionToASL);
// No need for ATL/ASL as modelToWorld returns in format position
_player setPos (_seat modelToWorld _sitPosition);

// Set variables
_player setVariable [QGVAR(isSitting), true];
_seat setVariable [QGVAR(seatOccupied), true, true]; // To prevent multiple people sitting on one seat

// Add rotation control PFH
_sitDirectionVisual = getDirVisual _player; // Needed for precision and issues with using above directly
_seatPosOrig = getPosASL _seat;
[{
EXPLODE_3_PVT(_this select 0,_player,_sitDirectionVisual,_sitRotation);
EXPLODE_5_PVT(_this select 0,_player,_sitDirectionVisual,_sitRotation,_seat,_seatPosOrig);

// Remove PFH if not sitting any more
if !(_player getVariable [QGVAR(isSitting), false]) exitWith {
[_this select 1] call cba_fnc_removePerFrameHandler;
TRACE_1("Remove PFH",_player getVariable [ARR_2(QGVAR(isSitting),false)]);
};

// Stand up if chair moves
if ([_seat, _seatPosOrig] call FUNC(hasChairMoved)) exitWith {
_player call FUNC(stand);
TRACE_2("Chair moved",getPosASL _seat,_seatPosOrig);
};

// Set direction to boundary when passing it
Expand All @@ -60,4 +70,4 @@ _sitDirectionVisual = getDirVisual _player; // Needed for precision and issues w
if (getDir _player < _sitDirectionVisual - _sitRotation) exitWith {
_player setDir (_sitDirectionVisual - _sitRotation);
};
}, 0, [_player, _sitDirectionVisual, _sitRotation]] call cba_fnc_addPerFrameHandler;
}, 0, [_player, _sitDirectionVisual, _sitRotation, _seat, _seatPosOrig]] call cba_fnc_addPerFrameHandler;

0 comments on commit 3514f07

Please sign in to comment.