Open glass and CUP doors (#5226)

* Fixed glassdoor

Fixed so glassdoor now works with ace slow open.

* Made it more pretty with new file

Made it more pretty with new file

* Tidy up a bit

* Removed white space

* Replace tabs with spaces

Replace tabs with spaces

* Simplified and added comments

* Changes + was stupid was commit

Changes to go with code guidlines and extra check if door is empty

* Tabs to spaces

* Small fixes + Fixed so CUP houses now works

Fixed so CUP houses now works

* Remove todo

* Fixed requested changes

* Removed whitespaces
This commit is contained in:
Phyma 2017-06-02 23:50:53 +02:00 committed by PabstMirror
parent ae69118fba
commit 288f956316
5 changed files with 98 additions and 106 deletions

View File

@ -30,6 +30,7 @@ PREP(pardon);
// interaction with doors
PREP(getDoor);
PREP(getGlassDoor);
PREP(getDoorAnimations);
PREP(handleScrollWheel);
PREP(openDoor);

View File

@ -1,5 +1,5 @@
/*
* Author: commy2
* Author: commy2, Phyma
* Find door.
*
* Arguments:
@ -35,7 +35,14 @@ if (typeOf _house == "") exitWith {[objNull, ""]};
_intersections = [_house, "GEOM"] intersect [_position0, _position1];
_door = _intersections select 0 select 0;
_door = toLower (_intersections select 0 select 0);
if (isNil "_door") exitWith {[_house, ""]};
//Check if door is glass because then we need to find the proper location of the door so we can use it
if ((_door find "glass") != -1) then {
_door = [_distance, _house, _door] call FUNC(getGlassDoor);
};
if (isNil "_door") exitWith {[_house, ""]};

View File

@ -1,6 +1,6 @@
/*
* Author: commy2
* Get door animations. @todo rewrite for better custom building support
* Author: commy2, Phyma
* Get door animations.
*
* Arguments:
* 0: House <OBJECT>
@ -20,104 +20,19 @@
params ["_house", "_door"];
private ["_index", "_animations", "_lockedVariable"];
private _animate = animationNames _house;
private _animations = [];
private _lockedVariable = [];
_index = [
"door_1",
"door_2",
"door_3",
"door_4",
"door_5",
"door_6",
"door_7",
"door_8",
"door_9",
"door_10",
"door_11",
"door_12",
"door_13",
"door_14",
"door_15",
"door_16",
"door_17",
"door_18",
"door_19",
"door_20",
"door_21",
"door_22",
"hatch_1",
"hatch_2",
"hatch_3",
"hatch_4",
"hatch_5",
"hatch_6"
] find toLower _door;
if (_index == -1) exitWith {[[],""]};
_animations = [
["Door_1_rot", "Door_Handle_1_rot_1", "Door_Handle_1_rot_2"],
["Door_2_rot", "Door_Handle_2_rot_1", "Door_Handle_2_rot_2"],
["Door_3_rot", "Door_Handle_3_rot_1", "Door_Handle_3_rot_2"],
["Door_4_rot", "Door_Handle_4_rot_1", "Door_Handle_4_rot_2"],
["Door_5_rot", "Door_Handle_5_rot_1", "Door_Handle_5_rot_2"],
["Door_6_rot", "Door_Handle_6_rot_1", "Door_Handle_6_rot_2"],
["Door_7_rot", "Door_Handle_7_rot_1", "Door_Handle_7_rot_2"],
["Door_8_rot", "Door_Handle_8_rot_1", "Door_Handle_8_rot_2"],
["Door_9_rot", "Door_Handle_9_rot_1", "Door_Handle_9_rot_2"],
["Door_10_rot", "Door_Handle_10_rot_1", "Door_Handle_10_rot_2"],
["Door_11_rot", "Door_Handle_11_rot_1", "Door_Handle_11_rot_2"],
["Door_12_rot", "Door_Handle_12_rot_1", "Door_Handle_12_rot_2"],
["Door_13_rot", "Door_Handle_13_rot_1", "Door_Handle_13_rot_2"],
["Door_14_rot", "Door_Handle_14_rot_1", "Door_Handle_14_rot_2"],
["Door_15_rot", "Door_Handle_15_rot_1", "Door_Handle_15_rot_2"],
["Door_16_rot", "Door_Handle_16_rot_1", "Door_Handle_16_rot_2"],
["Door_17_rot", "Door_Handle_17_rot_1", "Door_Handle_17_rot_2"],
["Door_18_rot", "Door_Handle_18_rot_1", "Door_Handle_18_rot_2"],
["Door_19_rot", "Door_Handle_19_rot_1", "Door_Handle_19_rot_2"],
["Door_20_rot", "Door_Handle_20_rot_1", "Door_Handle_20_rot_2"],
["Door_21_rot", "Door_Handle_21_rot_1", "Door_Handle_21_rot_2"],
["Door_22_rot", "Door_Handle_22_rot_1", "Door_Handle_22_rot_2"],
["Hatch_1_rot"],
["Hatch_2_rot"],
["Hatch_3_rot"],
["Hatch_4_rot"],
["Hatch_5_rot"],
["Hatch_6_rot"]
] select _index;
_lockedVariable = [
["BIS_Disabled_Door_1", "Door_Handle_1_rot_1", "Door_Locked_1_rot"],
["BIS_Disabled_Door_2", "Door_Handle_2_rot_1", "Door_Locked_2_rot"],
["BIS_Disabled_Door_3", "Door_Handle_3_rot_1", "Door_Locked_3_rot"],
["BIS_Disabled_Door_4", "Door_Handle_4_rot_1", "Door_Locked_4_rot"],
["BIS_Disabled_Door_5", "Door_Handle_5_rot_1", "Door_Locked_5_rot"],
["BIS_Disabled_Door_6", "Door_Handle_6_rot_1", "Door_Locked_6_rot"],
["BIS_Disabled_Door_7", "Door_Handle_7_rot_1", "Door_Locked_7_rot"],
["BIS_Disabled_Door_8", "Door_Handle_8_rot_1", "Door_Locked_8_rot"],
["BIS_Disabled_Door_9", "Door_Handle_9_rot_1", "Door_Locked_9_rot"],
["BIS_Disabled_Door_10", "Door_Handle_10_rot_1", "Door_Locked_10_rot"],
["BIS_Disabled_Door_11", "Door_Handle_11_rot_1", "Door_Locked_11_rot"],
["BIS_Disabled_Door_12", "Door_Handle_12_rot_1", "Door_Locked_12_rot"],
["BIS_Disabled_Door_13", "Door_Handle_13_rot_1", "Door_Locked_13_rot"],
["BIS_Disabled_Door_14", "Door_Handle_14_rot_1", "Door_Locked_14_rot"],
["BIS_Disabled_Door_15", "Door_Handle_15_rot_1", "Door_Locked_15_rot"],
["BIS_Disabled_Door_16", "Door_Handle_16_rot_1", "Door_Locked_16_rot"],
["BIS_Disabled_Door_17", "Door_Handle_17_rot_1", "Door_Locked_17_rot"],
["BIS_Disabled_Door_18", "Door_Handle_18_rot_1", "Door_Locked_18_rot"],
["BIS_Disabled_Door_19", "Door_Handle_19_rot_1", "Door_Locked_19_rot"],
["BIS_Disabled_Door_20", "Door_Handle_20_rot_1", "Door_Locked_20_rot"],
["BIS_Disabled_Door_21", "Door_Handle_21_rot_1", "Door_Locked_21_rot"],
["BIS_Disabled_Door_22", "Door_Handle_22_rot_1", "Door_Locked_22_rot"],
["", ""],
["", ""],
["", ""],
["", ""],
["", ""],
["", ""]
] select _index;
{
private _animName = toLower _x;
if ((_animName find (toLower _door)) != -1) then {
if (((_animName find "disabled") != -1) || ((_animName find "locked") != -1)) then {
_lockedVariable pushBack _animName;
} else {
_animations pushBack _animName;
};
};
} forEach _animate;
[_animations, _lockedVariable]

View File

@ -0,0 +1,67 @@
/*
* Author: Phyma
* Find glass door.
*
* Arguments:
* 0: Distance <NUMBER>
* 1: House <OBJECT>
* 2: Door name <STRING>
*
* Return Value:
* 0: Door Name <STRING>
*
* Example:
* [player, target] call ace_interaction_fnc_getGlassDoor
*
* Public: No
*/
#include "script_component.hpp"
params ["_distance", "_house", "_door"];
private _doorParts = [];
private _doorPos = [];
private _animate = animationNames _house;
private _glassDoor = _door splitString "_";
private _glassPos = (_house selectionPosition [(_glassDoor select 0) + "_" + (_glassDoor select 1) + "_effects", "Memory"]);
// Calculate all animation names so we know what is there
{
private _animName = toLower _x;
if (((_animName find "door") != -1) && ((_animName find "locked") == -1) && ((_animName find "disabled") == -1) && ((_animName find "handle") == -1)) then {
private _splitStr = _animName splitString "_";
_doorParts pushBack ((_splitStr select 0) + "_" + (_splitStr select 1) + "_trigger");
};
} forEach _animate;
// Get the pos of all the door components and save the parts
{
_doorPos pushBack (_house selectionPosition [_x, "Memory"]);
} forEach _doorParts;
// Calculate what door that is closest to the glass door
private _lowestDistance = 0;
{
private _objDist = _glassPos distance _x;
//Make sure we dont take another door by mistake
if (_objDist <= _distance) then {
//Need to set the value in the beginning
if (_lowestDistance == 0) then {
_lowestDistance = _objDist;
private _splitStr = (_doorParts select _forEachIndex) splitString "_";
_door = (_splitStr select 0) + "_" + (_splitStr select 1);
} else {
if (_objDist < _lowestDistance) then {
_lowestDistance = _objDist;
private _splitStr = (_doorParts select _forEachIndex) splitString "_";
_door = (_splitStr select 0) + "_" + (_splitStr select 1);
};
};
};
} forEach _doorPos;
// Check if we have a door or if it is the glass part
if ((isNil "_door") || ((_door find "glass") != -1)) exitWith {};
_door

View File

@ -28,9 +28,12 @@ _getDoorAnimations params ["_animations", "_lockedVariable"];
if (_animations isEqualTo []) exitWith {};
if (_house animationPhase (_animations select 0) <= 0 && {_house getVariable [_lockedVariable select 0, 0] == 1}) exitWith {
_lockedVariable set [0, _house];
_lockedVariable call BIS_fnc_LockedDoorOpen;
//Check if the door can be locked aka have locked variable, otherwhise cant lock it
if (!(isNil (_lockedVariable select 0))) then {
if ((_house animationPhase (_animations select 0) <= 0) && {_house getVariable [_lockedVariable select 0, 0] == 1}) exitWith {
_lockedVariable set [0, _house];
_lockedVariable call BIS_fnc_LockedDoorOpen;
};
};
playSound "ACE_Sound_Click"; // @todo replace with smth. more fitting
@ -62,7 +65,6 @@ GVAR(usedScrollWheel) = false;
if (CBA_missionTime > _time && {diag_frameno > _frame}) then {
GVAR(usedScrollWheel) = true;
};
// do incremental door opening
{_house animate [_x, GVAR(doorTargetPhase)]; false} count _animations;
}, 0.1, [_house, _animations, getPosASL ACE_player, CBA_missionTime + 0.2, diag_frameno + 2]] call CBA_fnc_addPerFrameHandler;