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

Open glass and CUP doors #5226

Merged
merged 12 commits into from
Jun 2, 2017
Merged
1 change: 1 addition & 0 deletions addons/interaction/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ PREP(pardon);

// interaction with doors
PREP(getDoor);
PREP(getGlassDoor);
PREP(getDoorAnimations);
PREP(handleScrollWheel);
PREP(openDoor);
Expand Down
11 changes: 9 additions & 2 deletions addons/interaction/functions/fnc_getDoor.sqf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Author: commy2
* Author: commy2, Phyma
* Find door.
*
* Arguments:
Expand Down Expand Up @@ -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, ""]};

Expand Down
117 changes: 16 additions & 101 deletions addons/interaction/functions/fnc_getDoorAnimations.sqf
Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -20,104 +20,19 @@

params ["_house", "_door"];

private ["_index", "_animations", "_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 _animate = animationNames _house;
private _animations = [];
private _lockedVariable = [];

{
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]
67 changes: 67 additions & 0 deletions addons/interaction/functions/fnc_getGlassDoor.sqf
Original file line number Diff line number Diff line change
@@ -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

Copy link
Contributor

@commy2 commy2 Jun 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

many lines with white space in this file
Sublime Text 3 is the best editor

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well white lines are nice for readability. Segmenting the code, there is not a single white line in a segment. A segment could be a forEach and it wont affect the performance of the code. So I'm hesitating to do this change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commy means spaces (literally) after text. There are a few lines in this file that have that.

I suggest you install EditorConfig plugin for your editor, it will automatically clean that up. Otherwise you can probably also manually set it.

Copy link
Contributor

@PabstMirror PabstMirror Jun 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some text editors let you visualize whitespace,

Notepad++: View -> Show Symbol -> Show White Space and Tab
Sublimb Text: "draw_white_space": "all"
I think Atom is "Show Invisables"

EditorConfig should also clean these up automatically and prevent things like tabs from being saved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okey I fixed sublime with EditorConfig and all that setup so should not be a problem now. It should say something about this in the Developer wiki.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10 changes: 6 additions & 4 deletions addons/interaction/functions/fnc_openDoor.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;