-
Notifications
You must be signed in to change notification settings - Fork 762
CSW - Improve CSW tripod placement #11433
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
johnb432
wants to merge
2
commits into
master
Choose a base branch
from
csw-add-deploy
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| #include "script_component.hpp" | ||
|
|
||
| params ["_display"]; | ||
|
|
||
| _display displayAddEventHandler ["MouseZChanged", {(_this select 1) call FUNC(handleScrollWheel)}]; | ||
| _display displayAddEventHandler ["MouseButtonDown", { | ||
| // Right clicking cancels deployment | ||
| if ((_this select 1) == 1 && {ACE_player getVariable [QGVAR(isDeploying), false]}) then { | ||
| GVAR(placeAction) = PLACE_CANCEL; | ||
| }; | ||
| }]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,100 +1,96 @@ | ||
| #include "..\script_component.hpp" | ||
| /* | ||
| * Author: tcvm | ||
| * Author: tcvm, johnb43 | ||
| * Deploys the tripod. | ||
| * | ||
| * Arguments: | ||
| * 0: Unit <OBJECT> | ||
| * 1: Position ASL <ARRAY> | ||
| * 2: Vector direction & up <NUMBER> | ||
| * | ||
| * Return Value: | ||
| * None | ||
| * | ||
| * Example: | ||
| * player call ace_csw_fnc_assemble_deployTripod | ||
| * [player, (getPosASL player) vectorAdd [0, 2, 0], [[1, 0, 0], [0, 0, 1]]] call ace_csw_fnc_assemble_deployTripod | ||
| * | ||
| * Public: No | ||
| */ | ||
|
|
||
| [{ | ||
| params ["_player"]; | ||
| TRACE_1("assemble_deployTripod",_player); | ||
| params ["_player", "_posASL", "_vectorDirAndUp"]; | ||
| TRACE_1("assemble_deployTripod",_player); | ||
|
|
||
| // Save magazines and attachments (handle loaded launchers which can become csw like CUP Metis) | ||
| private _secondaryWeaponInfo = (getUnitLoadout _player) select 1; | ||
| private _secondaryWeaponClassname = _secondaryWeaponInfo deleteAt 0; | ||
| // Save magazines and attachments (handle loaded launchers which can become csw like CUP Metis) | ||
| private _secondaryWeaponInfo = (getUnitLoadout _player) select 1; | ||
| private _secondaryWeaponClassname = _secondaryWeaponInfo deleteAt 0; | ||
|
|
||
| // Remove empty entries | ||
| _secondaryWeaponInfo = _secondaryWeaponInfo select {_x isNotEqualTo "" && {_x isNotEqualTo []}}; | ||
| // Remove empty entries | ||
| _secondaryWeaponInfo = _secondaryWeaponInfo select {_x isNotEqualTo "" && {_x isNotEqualTo []}}; | ||
|
|
||
| // Remove the tripod from the launcher slot | ||
| _player removeWeaponGlobal _secondaryWeaponClassname; | ||
| // Remove the tripod from the launcher slot | ||
| _player removeWeaponGlobal _secondaryWeaponClassname; | ||
|
|
||
| private _onFinish = { | ||
| params ["_args"]; | ||
| _args params ["_player", "_secondaryWeaponClassname", "_secondaryWeaponInfo"]; | ||
| TRACE_3("deployTripod finish",_player,_secondaryWeaponClassname,_secondaryWeaponInfo); | ||
| private _onFinish = { | ||
| params ["_args"]; | ||
| _args params ["_player", "_secondaryWeaponClassname", "_secondaryWeaponInfo", "_posASL", "_vectorDirAndUp"]; | ||
| TRACE_5("deployTripod finish",_player,_secondaryWeaponClassname,_secondaryWeaponInfo,_posASL,_vectorDirAndUp); | ||
|
|
||
| private _tripodClassname = getText (configFile >> "CfgWeapons" >> _secondaryWeaponClassname >> QUOTE(ADDON) >> "deploy"); | ||
| private _tripodClassname = getText (configFile >> "CfgWeapons" >> _secondaryWeaponClassname >> QUOTE(ADDON) >> "deploy"); | ||
|
|
||
| // Create a tripod | ||
| private _cswTripod = createVehicle [_tripodClassname, [0, 0, 0], [], 0, "NONE"]; | ||
| // Because the tripod can be a "full weapon" we disable any data that will allow it to be loaded | ||
| _cswTripod setVariable [QGVAR(assemblyMode), 2, true]; // Explicitly set enabled&unload assembly mode and broadcast | ||
| // Create a tripod | ||
| private _cswTripod = createVehicle [_tripodClassname, [0, 0, 0], [], 0, "CAN_COLLIDE"]; | ||
| // Because the tripod can be a "full weapon" we disable any data that will allow it to be loaded | ||
| _cswTripod setVariable [QGVAR(assemblyMode), 2, true]; // Explicitly set enabled&unload assembly mode and broadcast | ||
|
|
||
| private _secondaryWeaponMagazines = []; | ||
| private _secondaryWeaponMagazines = []; | ||
|
|
||
| { | ||
| // Magazines | ||
| if (_x isEqualType []) then { | ||
| _secondaryWeaponMagazines pushBack _x; | ||
| } else { | ||
| // Items | ||
| [_player, _x, true] call CBA_fnc_addItem; | ||
| }; | ||
| } forEach _secondaryWeaponInfo; | ||
|
|
||
| // Only add magazines once the weapon is fully ready | ||
| if (_secondaryWeaponMagazines isNotEqualTo []) then { | ||
| _cswTripod setVariable [QGVAR(secondaryWeaponMagazines), _secondaryWeaponMagazines, true]; | ||
| { | ||
| // Magazines | ||
| if (_x isEqualType []) then { | ||
| _secondaryWeaponMagazines pushBack _x; | ||
| } else { | ||
| // Items | ||
| [_player, _x, true] call CBA_fnc_addItem; | ||
| }; | ||
| } forEach _secondaryWeaponInfo; | ||
|
|
||
| // Disable vanilla assembly until FUNC(initVehicle) runs and sets the definite value | ||
| [_cswTripod, "disableWeaponAssembly", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set); | ||
| // Only add magazines once the weapon is fully ready | ||
| if (_secondaryWeaponMagazines isNotEqualTo []) then { | ||
| _cswTripod setVariable [QGVAR(secondaryWeaponMagazines), _secondaryWeaponMagazines, true]; | ||
| }; | ||
|
|
||
| private _posATL = _player getRelPos [2, 0]; | ||
| _posATL set [2, ((getPosATL _player) select 2) + 0.5]; | ||
| // Disable vanilla assembly until FUNC(initVehicle) runs and sets the definite value | ||
| [_cswTripod, "disableWeaponAssembly", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set); | ||
|
|
||
| _cswTripod setDir (direction _player); | ||
| _cswTripod setPosATL _posATL; | ||
| _cswTripod setVectorUp (surfaceNormal _posATL); | ||
| _cswTripod setPosASL _posASL; | ||
| _cswTripod setVectorDirAndUp _vectorDirAndUp; | ||
|
|
||
| [_player, "PutDown"] call EFUNC(common,doGesture); | ||
| [_player, "PutDown"] call EFUNC(common,doGesture); | ||
|
|
||
| // drag after deploying | ||
| if ((missionNamespace getVariable [QGVAR(dragAfterDeploy), false]) && {["ace_dragging"] call EFUNC(common,isModLoaded)}) then { | ||
| if ([_player, _cswTripod] call EFUNC(dragging,canCarry)) then { | ||
| TRACE_1("starting carry",_cswTripod); | ||
| [_player, _cswTripod] call EFUNC(dragging,startCarry); | ||
| } else { | ||
| TRACE_1("cannot carry",_cswTripod); | ||
| }; | ||
| // drag after deploying | ||
| if ((missionNamespace getVariable [QGVAR(dragAfterDeploy), false]) && {["ace_dragging"] call EFUNC(common,isModLoaded)}) then { | ||
| if ([_player, _cswTripod] call EFUNC(dragging,canCarry)) then { | ||
| TRACE_1("starting carry",_cswTripod); | ||
| [_player, _cswTripod] call EFUNC(dragging,startCarry); | ||
| } else { | ||
| TRACE_1("cannot carry",_cswTripod); | ||
| }; | ||
| }; | ||
| }; | ||
|
|
||
| private _onFailure = { | ||
| params ["_args"]; | ||
| _args params ["_player", "_secondaryWeaponClassname", "_secondaryWeaponInfo"]; | ||
| TRACE_3("deployTripod failure",_player,_secondaryWeaponClassname,_secondaryWeaponInfo); | ||
| private _onFailure = { | ||
| params ["_args"]; | ||
| _args params ["_player", "_secondaryWeaponClassname", "_secondaryWeaponInfo"]; | ||
| TRACE_3("deployTripod failure",_player,_secondaryWeaponClassname,_secondaryWeaponInfo); | ||
|
|
||
| // Add tripod back | ||
| [_player, _secondaryWeaponClassname] call CBA_fnc_addWeaponWithoutItems; | ||
| // Add tripod back | ||
| [_player, _secondaryWeaponClassname] call CBA_fnc_addWeaponWithoutItems; | ||
|
|
||
| // Add all attachments back | ||
| { | ||
| _player addWeaponItem [_secondaryWeaponClassname, _x, true]; | ||
| } forEach _secondaryWeaponInfo; | ||
| }; | ||
| // Add all attachments back | ||
| { | ||
| _player addWeaponItem [_secondaryWeaponClassname, _x, true]; | ||
| } forEach _secondaryWeaponInfo; | ||
| }; | ||
|
|
||
| private _deployTime = getNumber (configFile >> "CfgWeapons" >> _secondaryWeaponClassname >> QUOTE(ADDON) >> "deployTime"); | ||
| [TIME_PROGRESSBAR(_deployTime), [_player, _secondaryWeaponClassname, _secondaryWeaponInfo], _onFinish, _onFailure, LLSTRING(PlaceTripod_progressBar)] call EFUNC(common,progressBar); | ||
| }, _this] call CBA_fnc_execNextFrame; | ||
| private _deployTime = getNumber (configFile >> "CfgWeapons" >> _secondaryWeaponClassname >> QUOTE(ADDON) >> "deployTime"); | ||
| [TIME_PROGRESSBAR(_deployTime), [_player, _secondaryWeaponClassname, _secondaryWeaponInfo, _posASL, _vectorDirAndUp], _onFinish, _onFailure, LLSTRING(PlaceTripod_progressBar)] call EFUNC(common,progressBar); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| #include "..\script_component.hpp" | ||
| /* | ||
| * Author: Garth 'L-H' de Wet, Ruthberg, commy2, Smith, johnb43 | ||
| * Starts the deploy process for unloading an object. | ||
| * | ||
| * Arguments: | ||
| * 0: Unit deploying <OBJECT> | ||
| * | ||
| * Return Value: | ||
| * None | ||
| * | ||
| * Example: | ||
| * player call ace_csw_fnc_assemble_startDeployTripod | ||
| * | ||
| * Public: No | ||
| */ | ||
|
|
||
| params ["_player"]; | ||
|
|
||
| // Don't allow deploying if already deploying | ||
| if (_player getVariable [QGVAR(isDeploying), false]) exitWith {}; | ||
|
|
||
| private _secondaryWeaponClassname = secondaryWeapon _player; | ||
| private _classname = getText (configFile >> "CfgWeapons" >> _secondaryWeaponClassname >> QUOTE(ADDON) >> "deploy"); | ||
|
|
||
| // Prevent the placing unit from running | ||
| [_player, "forceWalk", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set); | ||
| [_player, "blockThrow", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set); | ||
|
|
||
| // Create a local preview object | ||
| private _tripodPreviewObject = createVehicleLocal [_classname, [0, 0, 0], [], 0, "CAN_COLLIDE"]; | ||
|
|
||
| GVAR(tripodPreviewObject) = _tripodPreviewObject; | ||
|
|
||
| // Prevent collisions with object | ||
| _tripodPreviewObject disableCollisionWith _player; | ||
| _tripodPreviewObject enableSimulation false; | ||
| _tripodPreviewObject setMass 1e-12; | ||
|
|
||
| // Detect radius of zone where collision can damage the player | ||
| private _tripodPreviewObjectRadius = 1 max ((boundingBoxReal [_tripodPreviewObject, "FireGeometry"]) select 2); | ||
|
|
||
| // Add height offset of model | ||
| private _offset = ((_tripodPreviewObject modelToWorldVisual [0, 0, 0]) select 2) - ((_player modelToWorldVisual [0, 0, 0]) select 2) + 1; | ||
|
|
||
| // Attach object | ||
| _tripodPreviewObject attachTo [_player, [0, 1.5 * _tripodPreviewObjectRadius, _offset]]; | ||
|
|
||
| GVAR(placeAction) = PLACE_WAITING; | ||
|
|
||
| // PFH that runs while the deployment is in progress | ||
| GVAR(deployPFH) = [{ | ||
| (_this select 0) params ["_player", "_secondaryWeaponClassname", "_tripodPreviewObject"]; | ||
|
|
||
| // Cancel deployment if criteria not met | ||
| if ( | ||
| isNull _tripodPreviewObject || | ||
| {secondaryWeapon _player != _secondaryWeaponClassname} || | ||
| {!(_player call FUNC(canDeployTripod))} || | ||
| {GVAR(placeAction) == PLACE_CANCEL} | ||
| ) exitWith { | ||
| _player call FUNC(deployCancel); | ||
| }; | ||
|
|
||
| // Check if the center of the object is not inside another (don't check for other intersections though) | ||
| private _validPosition = (lineIntersectsSurfaces [eyePos _player, getPosASL _tripodPreviewObject, _player]) isEqualTo []; | ||
|
|
||
| // Update mouse hint | ||
| ((uiNamespace getVariable [QEGVAR(interaction,mouseHint), displayNull]) displayCtrl 2420) ctrlSetText (localize ([LSTRING(BlockedAction), LSTRING(PlaceAction)] select _validPosition)); | ||
|
|
||
| if (GVAR(placeAction) != PLACE_APPROVE) exitWith {}; | ||
|
|
||
| // Deploy the CSW | ||
| if (_validPosition) exitWith { | ||
| _player call FUNC(deployConfirm); | ||
| }; | ||
|
|
||
| // Don't allow placing in an invalid position | ||
| GVAR(placeAction) = PLACE_WAITING; | ||
| }, 0, [_player, _secondaryWeaponClassname, _tripodPreviewObject]] call CBA_fnc_addPerFrameHandler; | ||
|
|
||
| // Add mouse button action and hint | ||
| [LLSTRING(PlaceAction), LELSTRING(common,Cancel), LLSTRING(RaiseLowerRotate)] call EFUNC(interaction,showMouseHint); | ||
|
|
||
| _player setVariable [QGVAR(deploy), [_player, "DefaultAction", {GVAR(deployPFH) != -1}, {GVAR(placeAction) = PLACE_APPROVE}] call EFUNC(common,addActionEventHandler)]; | ||
|
|
||
| _player setVariable [QGVAR(isDeploying), true, true]; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #include "..\script_component.hpp" | ||
| /* | ||
| * Author: Garth 'L-H' de Wet, johnb43 | ||
| * Cancels CSW tripod placement. | ||
| * | ||
| * Arguments: | ||
| * 0: Key <NUMBER> | ||
| * | ||
| * Return Value: | ||
| * None | ||
| * | ||
| * Example: | ||
| * 1 call ace_csw_fnc_cancelDeployTripod | ||
| * | ||
| * Public: No | ||
| */ | ||
|
|
||
| params ["_key"]; | ||
|
|
||
| if (_key != 1 || {GVAR(deployPFH) == -1}) exitWith {}; | ||
|
|
||
| GVAR(placeAction) = PLACE_CANCEL; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
offset is -141.348?
placement is blocked, until I scroll mouse, then it works fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, although the solution isn't as elegant as I'd like it to be. Constant offset is easier to handle though.
I'll have to update cargo's deploy too, as it has the same problem.