Code cleanup of sitting module

This commit is contained in:
Michael Braun 2015-08-07 15:12:24 +02:00
parent d636b4b5c7
commit 60e4c2e601
8 changed files with 33 additions and 27 deletions

View File

@ -10,17 +10,16 @@
* Can Sit Down <BOOL>
*
* Example:
* [seat, player] call ace_sitting_fnc_canSit;
* [seat, player] call ace_sitting_fnc_canSit
*
* Public: No
*/
//#define DEBUG_MODE_FULL
#include "script_component.hpp"
PARAMS_2(_seat,_player);
params ["_seat", "_player"];
// 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)}} &&
{isNil {_seat getVariable QGVAR(seatOccupied)}} &&
{round (vectorUp _seat select 0) == 0 && {round (vectorUp _seat select 1) == 0} && {round (vectorUp _seat select 2) == 1}}

View File

@ -15,7 +15,7 @@
*/
#include "script_component.hpp"
PARAMS_1(_player);
params ["_player"];
// Sitting
(_player getVariable [QGVAR(isSitting),false])
(_player getVariable [QGVAR(isSitting), false])

View File

@ -9,13 +9,13 @@
* Random Animation <STRING>
*
* Example:
* _animation = call ace_sitting_fnc_getRandomAnimation;
* _animation = call ace_sitting_fnc_getRandomAnimation
*
* Public: No
*/
#include "script_component.hpp"
private ["_animations"];
private "_animations";
// Animations Pool
_animations = [
@ -46,4 +46,4 @@ _animations = [
];
// Select random animation
(_animations select (floor (random (count _animations))))
(_animations select floor random count _animations)

View File

@ -9,13 +9,13 @@
* None
*
* Example:
* player call ace_sitting_fnc_handleInterrupt;
* player call ace_sitting_fnc_handleInterrupt
*
* Public: No
*/
#include "script_component.hpp"
PARAMS_1(_player);
params ["_player"];
if (_player getVariable [QGVAR(isSitting), false]) then {
_player call FUNC(stand);

View File

@ -10,18 +10,21 @@
* None
*
* Example:
* [seat, seatPos] call ace_sitting_fnc_hasChairMoved;
* [seat, seatPos] call ace_sitting_fnc_hasChairMoved
*
* Public: No
*/
//#define DEBUG_MODE_FULL
#include "script_component.hpp"
PARAMS_2(_seat,_seatPosOrig);
params ["_seat", "_seatPosOrig"];
TRACE_2("Chair position",_seatPosOrig,getPosASL _seat);
(getPosASL _seat) params ["_seatX", "_seatY", "_seatZ"];
_seatPosOrig params ["_seatOrigX", "_seatOrigY", "_seatOrigZ"];
// 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}}
if (abs (_seatX - _seatOrigX) > 0.01) exitWith {true};
if (abs (_seatY - _seatOrigY) > 0.01) exitWith {true};
if (abs (_seatZ - _seatOrigZ) > 0.01) exitWith {true};
false

View File

@ -3,18 +3,22 @@
* Initializes the Sitting module.
*
* Arguments:
* Whatever the module provides.
* 0: The module logic <LOGIC>
* 1: Units <ARRAY>
* 2: Activated <BOOL>
*
* Return Value:
* None
*
* Public: No
*/
#include "script_component.hpp"
if !(isServer) exitWith {};
PARAMS_3(_logic,_units,_activated);
params ["_logic", "_units", "_activated"];
if !(_activated) exitWith {};
if (!_activated) exitWith {};
[_logic, QGVAR(enable), "enable"] call EFUNC(common,readSettingFromModule);

View File

@ -14,12 +14,11 @@
*
* Public: No
*/
//#define DEBUG_MODE_FULL
#include "script_component.hpp"
private ["_configFile", "_sitDirection", "_sitPosition", "_sitRotation", "_sitDirectionVisual"];
PARAMS_2(_seat,_player);
params ["_seat", "_player"];
// Set global variable for standing up
GVAR(seat) = _seat;
@ -49,12 +48,13 @@ _seat setVariable [QGVAR(seatOccupied), true, true]; // To prevent multiple peop
_sitDirectionVisual = getDirVisual _player; // Needed for precision and issues with using above directly
_seatPosOrig = getPosASL _seat;
[{
EXPLODE_5_PVT(_this select 0,_player,_sitDirectionVisual,_sitRotation,_seat,_seatPosOrig);
params ["_args", "_pfhId"];
_args params ["_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)]);
[_pfhId] call cba_fnc_removePerFrameHandler;
TRACE_1("Remove PFH",_player getVariable [ARR_2(QGVAR(isSitting), false)]);
};
// Stand up if chair moves

View File

@ -15,7 +15,7 @@
*/
#include "script_component.hpp"
PARAMS_1(_player);
params ["_player"];
// Restore animation
[_player, "", 2] call EFUNC(common,doAnimation);