Skip to content

Commit

Permalink
Merge pull request #3 from jonpas/towingClean
Browse files Browse the repository at this point in the history
Towing Fixes & Additions & Cleanup
  • Loading branch information
GitHawk committed Aug 19, 2015
2 parents 9f3879f + 44e63e8 commit 3933c01
Show file tree
Hide file tree
Showing 18 changed files with 320 additions and 140 deletions.
56 changes: 44 additions & 12 deletions addons/towing/CfgVehicles.hpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
#define MACRO_TOWING_ACTIONS \
class ACE_Actions : ACE_Actions { \
class ACE_MainActions : ACE_MainActions { \
class GVAR(tilting) { \
displayName = CSTRING(TiltingAction); \
distance = TOWING_DISTANCE; \
condition = QUOTE([ARR_2(_player,_target)] call FUNC(canConnect)); \
statement = QUOTE([ARR_2(_player,_target)] call FUNC(connect)); \
class ACE_Actions { \
class ACE_MainActions { \
class GVAR(TiltConnect) { \
displayName = CSTRING(TiltConnect); \
distance = TOWING_ACTION_DISTANCE; \
condition = QUOTE(_this call FUNC(canConnectTiltCable)); \
statement = QUOTE(_this call FUNC(connectTiltCable)); \
exceptions[] = {"isNotInside"}; \
}; \
class GVAR(tiltingFinished) { \
displayName = CSTRING(TiltingFinishedAction); \
distance = TOWING_DISTANCE; \
condition = QUOTE([ARR_2(_player,_target)] call FUNC(canCutTiltRope)); \
statement = QUOTE([ARR_1(_player)] call FUNC(cutTiltRope)); \
class GVAR(TiltDisconnect) { \
displayName = CSTRING(TiltDisconnect); \
distance = TOWING_ACTION_DISTANCE; \
condition = QUOTE(_this call FUNC(canDisconnectTiltCable)); \
statement = QUOTE(_player call FUNC(disconnectTiltCable)); \
exceptions[] = {"isNotInside"}; \
}; \
class GVAR(TowConnect) { \
displayName = CSTRING(TowConnect); \
distance = TOWING_ACTION_DISTANCE; \
condition = QUOTE(_this call FUNC(canConnectTowBar)); \
statement = QUOTE(_this call FUNC(connectTowBar)); \
exceptions[] = {"isNotInside"}; \
}; \
class GVAR(TowDisconnect) { \
displayName = CSTRING(TowDisconnect); \
distance = TOWING_ACTION_DISTANCE; \
condition = QUOTE(_this call FUNC(canDisconnectTowBar)); \
statement = QUOTE(_this call FUNC(disconnectTowBar)); \
exceptions[] = {"isNotInside"}; \
}; \
}; \
Expand All @@ -27,4 +41,22 @@ class CfgVehicles {
class Tank : LandVehicle {
MACRO_TOWING_ACTIONS
};

class StaticWeapon : LandVehicle {
MACRO_TOWING_ACTIONS
};

class Air;
class Helicopter : Air {
MACRO_TOWING_ACTIONS
};

class Plane : Air {
MACRO_TOWING_ACTIONS
};

class Ship;
class Ship_F : Ship {
MACRO_TOWING_ACTIONS
};
};
11 changes: 11 additions & 0 deletions addons/towing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ace_towing
===============

Adds ability to tow vehicles with tow bar and tilt flipped vehicles with ropes.

## Maintainers

The people responsible for merging changes to this component or answering potential questions.

- [GitHawk] (https://github.com/GitHawk)
- [Jonpas] (https://github.com/jonpas)
15 changes: 10 additions & 5 deletions addons/towing/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

ADDON = false;

PREP(canConnect);
PREP(canCutTiltRope);
PREP(connect);
PREP(cutTiltRope);
PREP(tiltConnect);
PREP(attachTiltCable);
PREP(canConnectTiltCable);
PREP(canConnectTowBar);
PREP(canDisconnectTiltCable);
PREP(canDisconnectTowBar);
PREP(connectTiltCable);
PREP(connectTowBar);
PREP(disconnectTiltCable);
PREP(disconnectTowBar);
PREP(towVehicle);

ADDON = true;
4 changes: 2 additions & 2 deletions addons/towing/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class CfgPatches {
weapons[] = {;
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {"ace_interaction"};
author[] = {"GitHawk"};
authorUrl = "";
author[] = {"GitHawk", "Jonpas"};
authorUrl = "https://ace3mod.com";
VERSION_CONFIG;
};
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
/*
* Author: GitHawk
* Calculates a connection for tilting
* Checks if valid attach position and attaches a tilt cable.
*
* Arguments:
* 0: Player <OBJECT>
* 1: Target <OBJECT>
* 2: Visual position <ARRAY>
* 3: Towing stage <NUMBER>
* 0: Unit <OBJECT>
* 1: Attach Target <OBJECT>
* 2: Virtual Position <ARRAY>
*
* Return Value:
* None
*
* Example:
* [player, tank, [0,0,0]] call ace_towing_fnc_tiltConnect
* [player, tank, [0,0,0]] call ace_towing_fnc_attachTiltCable
*
* Public: Yes
* Public: No
*/
#include "script_component.hpp"

params ["_unit", "_attachToVehicle", "_startingPosition", "_stage"];
private ["_startingOffset", "_startDistanceFromCenter", "_closeInUnitVector", "_closeInMax", "_closeInMin", "_closeInDistance", "_endPosTestOffset", "_endPosTest", "_doesIntersect", "_startingPosShifted", "_startASL", "_endPosShifted", "_endASL", "_stage", "_helper", "_rope", "_weaponSelect"];
params ["_unit", "_attachToVehicle", "_startingPosition"];

_startingOffset = _attachToVehicle worldToModel _startingPosition;

_startDistanceFromCenter = vectorMagnitude _startingOffset;
Expand Down Expand Up @@ -59,18 +60,18 @@ while {(_closeInMax - _closeInMin) > 0.01} do {
_closeInDistance = (_closeInMax + _closeInMin) / 2;

//Checks (too close to center or can't attach)
if (((_startDistanceFromCenter - _closeInDistance) < 0.1) || {!([_attachToVehicle, _unit, _itemClassname] call FUNC(canAttach))}) exitWith {
if (((_startDistanceFromCenter - _closeInDistance) < 0.1)) exitWith {
TRACE_2("no valid spot found",_closeInDistance,_startDistanceFromCenter);
[localize LSTRING(Failed)] call EFUNC(common,displayTextStructured);
};

//Move it out slightly, for visibility sake (better to look a little funny than be embedded//sunk in the hull and be useless)
_closeInDistance = (_closeInDistance - 0.0085);
_closeInDistance = _closeInDistance - 0.0085;

_endPosTestOffset = _startingOffset vectorAdd (_closeInUnitVector vectorMultiply _closeInDistance);
_endPosTestOffset set [2, (_startingOffset select 2)];
_endPosTestOffset set [2, _startingOffset select 2];

_stage = ((ace_player getVariable [QGVAR(isTilting), 0])+1);
_stage = (ACE_player getVariable [QGVAR(isTilting), 0]) + 1;

_attachToVehicle setVariable [QGVAR(tiltUp), _unit, true];

Expand Down
28 changes: 0 additions & 28 deletions addons/towing/functions/fnc_canConnect.sqf

This file was deleted.

24 changes: 24 additions & 0 deletions addons/towing/functions/fnc_canConnectTiltCable.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Author: GitHawk
* Check if a unit can connect a tilt cable.
*
* Arguments:
* 0: Target <OBJECT>
* 1: Unit <OBJECT>
*
* Return Value:
* Can Connect <BOOL>
*
* Example:
* [tank, player] call ace_towing_fnc_canConnectTiltCable
*
* Public: No
*/
#include "script_component.hpp"

params ["_target", "_unit"];

!(_target distance _unit > TOWING_ACTION_DISTANCE) &&
{isNil {_target getVariable QGVAR(tiltUp)}} &&
{isNil {_unit getVariable QGVAR(towConnecting)}} &&
{((vectorUp _target) select 2) < 0.7 || _unit getVariable [QGVAR(isTilting), 0] == 1}
24 changes: 24 additions & 0 deletions addons/towing/functions/fnc_canConnectTowBar.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Author: Jonpas
* Check if a unit can connect a tow bar.
*
* Arguments:
* 0: Target <OBJECT>
* 1: Unit <OBJECT>
*
* Return Value:
* Can Connect <BOOL>
*
* Example:
* [tank, player] call ace_towing_fnc_canConnectTowBar
*
* Public: No
*/
#include "script_component.hpp"

params ["_target", "_unit"];

!(_target distance _unit > TOWING_ACTION_DISTANCE) &&
{isNil {_target getVariable QGVAR(isTowing)}} &&
{isNil {_target getVariable QGVAR(isTowed)}} &&
{_unit getVariable [QGVAR(isTilting), 0] == 0}
27 changes: 0 additions & 27 deletions addons/towing/functions/fnc_canCutTiltRope.sqf

This file was deleted.

23 changes: 23 additions & 0 deletions addons/towing/functions/fnc_canDisconnectTiltCable.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Author: GitHawk
* Check if a unit can cut a tilt cable.
*
* Arguments:
* 0: Target <OBJECT>
* 1: Unit <OBJECT>
*
* Return Value:
* Can Disconnect <BOOL>
*
* Example:
* [tank, player] call ace_logistics_fnc_canDisconnectTiltCable
*
* Public: No
*/
#include "script_component.hpp"

params ["_target", "_unit"];

!(_target distance _unit > TOWING_ACTION_DISTANCE) &&
{_target getVariable [QGVAR(tiltUp), _unit] == _unit} &&
{_unit getVariable [QGVAR(isTilting), 0] == 2}
22 changes: 22 additions & 0 deletions addons/towing/functions/fnc_canDisconnectTowBar.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Author: Jonpas
* Check if a unit can disconnect a tow bar.
*
* Arguments:
* 0: Target <OBJECT>
* 1: Unit <OBJECT>
*
* Return Value:
* Can Disconnect <BOOL>
*
* Example:
* [tank, player] call ace_logistics_fnc_canDisconnectTowBar
*
* Public: No
*/
#include "script_component.hpp"

params ["_target", "_unit"];

!(_target distance _unit > TOWING_ACTION_DISTANCE) &&
{!isNil {_target getVariable QGVAR(isTowing)} || !isNil {_target getVariable QGVAR(isTowed)}}
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
/*
* Author: GitHawk
* Connects a tilting rope to a vehicle
* Handles connecting a tilt cable to a vehicle using attach system.
*
* Arguments:
* 0: Player <OBJECT>
* 1: Target <OBJECT>
* 0: Target <OBJECT>
* 1: Unit <OBJECT>
*
* Return Value:
* NIL
* None
*
* Example:
* [tank] call ace_towing_fnc_connect
* [tank, player] call ace_towing_fnc_connectTiltCable
*
* Public: Yes
* Public: No
*/
#include "script_component.hpp"

#define PLACE_WAITING -1
#define PLACE_CANCEL 0
#define PLACE_APPROVE 1

params ["_unit","_target"];
private ["_actionID"];
params ["_target", "_unit"];

GVAR(placeAction) = PLACE_WAITING;

[_unit, QGVAR(vehAttach), true] call EFUNC(common,setForceWalkStatus);

[{[localize LSTRING(TiltingActionShort), ""] call EFUNC(interaction,showMouseHint)}, []] call EFUNC(common,execNextFrame);
_unit setVariable [QGVAR(placeActionEH), [_unit, "DefaultAction", {true}, {GVAR(placeAction) = PLACE_APPROVE;}] call EFUNC(common,AddActionEventHandler)];
[{[localize LSTRING(TiltConnectCable), ""] call EFUNC(interaction,showMouseHint)}, []] call EFUNC(common,execNextFrame);
_unit setVariable [QGVAR(placeActionEH), [_unit, "DefaultAction", {true}, {GVAR(placeAction) = PLACE_APPROVE;}] call EFUNC(common,addActionEventHandler)];

_actionID = _unit addAction [format ["<t color='#FF0000'>%1</t>", localize LSTRING(Cancel)], {GVAR(placeAction) = PLACE_CANCEL; [_unit, QGVAR(vehAttach), false] call EFUNC(common,setForceWalkStatus);}];

[{
private["_virtualPos", "_virtualPosASL", "_lineInterection"];

private ["_virtualPos", "_virtualPosASL", "_lineInterection"];
params ["_args","_pfID"];
EXPLODE_3_PVT(_args,_unit,_attachToVehicle,_actionID);
_args params ["_unit", "_attachToVehicle", "_actionID"];

_virtualPosASL = (eyePos _unit) vectorAdd (positionCameraToWorld [0,0,0.6]) vectorDiff (positionCameraToWorld [0,0,0]);
if (cameraView == "EXTERNAL") then {
Expand All @@ -57,9 +57,7 @@ _actionID = _unit addAction [format ["<t color='#FF0000'>%1</t>", localize LSTRI
_unit removeAction _actionID;

if (GVAR(placeAction) == PLACE_APPROVE) then {
[_unit, _attachToVehicle, _virtualPos] call FUNC(tiltConnect);
[_unit, _attachToVehicle, _virtualPos] call FUNC(attachTiltCable);
};
}; // TODO add model like in attach/functions/fnc_attach
}, 0, [_unit, _target, _actionID] ] call cba_fnc_addPerFrameHandler;

true
}, 0, [_unit, _target, _actionID] ] call CBA_fnc_addPerFrameHandler;
Loading

0 comments on commit 3933c01

Please sign in to comment.