ACE3/addons/interaction/functions/fnc_openDoor.sqf

72 lines
2.0 KiB
Plaintext
Raw Normal View History

/*
* Author: commy2
* Open door.
*
* Arguments:
* 0: House <OBJECT>
* 1: Door <STRING>
*
2015-09-28 16:06:25 +00:00
* Return Value:
* None
*
* Example:
* [house, "door"] call ace_interaction_fnc_openDoor
*
* Public: No
*/
2015-01-11 23:13:47 +00:00
#include "script_component.hpp"
2015-01-11 19:32:51 +00:00
private "_info";
_info = [MACRO_DOOR_REACH_DISTANCE] call FUNC(getDoor);
2015-01-11 19:32:51 +00:00
_info params ["_house", "_door"];
2015-01-11 19:32:51 +00:00
if (isNull _house) exitWith {};
private "_getDoorAnimations";
2015-05-16 03:52:54 +00:00
_getDoorAnimations = [_house, _door] call FUNC(getDoorAnimations);
2015-01-11 19:32:51 +00:00
_getDoorAnimations params ["_animations", "_lockedVariable"];
2015-01-11 19:32:51 +00:00
if (_animations isEqualTo []) exitWith {};
2015-01-11 19:32:51 +00:00
if (_house animationPhase (_animations select 0) <= 0 && {_house getVariable [_lockedVariable select 0, 0] == 1}) exitWith {
_lockedVariable set [0, _house];
_lockedVariable call BIS_fnc_LockedDoorOpen;
2015-01-11 19:32:51 +00:00
};
playSound "ACE_Sound_Click"; // @todo replace with smth. more fitting
GVAR(doorTargetPhase) = _house animationPhase (_animations select 0);
GVAR(isOpeningDoor) = true;
GVAR(usedScrollWheel) = false;
[{
(_this select 0) params ["_house", "_animations", "_position", "_time", "_frame"];
2015-01-11 19:32:51 +00:00
if !(GVAR(isOpeningDoor)) exitWith {
[_this select 1] call CBA_fnc_removePerFrameHandler;
2015-01-11 19:32:51 +00:00
// didn't use incremental opening. Just do animation normally.
if !(GVAR(usedScrollWheel)) then {
private "_phase";
_phase = [0, 1] select (_house animationPhase (_animations select 0) < 0.5);
{_house animate [_x, _phase]; false} count _animations;
};
};
2015-01-11 19:32:51 +00:00
// check if player moved too far away
if (getPosASL ACE_player distance _position > 1) exitWith {
GVAR(isOpeningDoor) = false;
};
2015-01-11 19:32:51 +00:00
// this allows for holding the door in it's current state.
if (ACE_time > _time && {diag_frameno > _frame}) then {
GVAR(usedScrollWheel) = true;
};
2015-01-11 19:32:51 +00:00
// do incremental door opening
{_house animate [_x, GVAR(doorTargetPhase)]; false} count _animations;
}, 0.1, [_house, _animations, getPosASL ACE_player, ACE_time + 0.2, diag_frameno + 2]] call CBA_fnc_addPerFrameHandler;