diff --git a/.gitattributes b/.gitattributes index bdb0cab..51d263b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -15,3 +15,9 @@ *.PDF diff=astextplain *.rtf diff=astextplain *.RTF diff=astextplain + +*.sqf eol=crlf +*.sqm eol=crlf +*.ext eol=crlf +*.hpp eol=crlf +*.cpp eol=crlf \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..0826882 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# Advanced Towing + +--- + +The MIT License (MIT) + +Copyright (c) 2016 Seth Duda + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/addons/SA_AdvancedTowing.pbo b/addons/SA_AdvancedTowing.pbo new file mode 100644 index 0000000..b84012a Binary files /dev/null and b/addons/SA_AdvancedTowing.pbo differ diff --git a/addons/SA_AdvancedTowing.pbo.AdvancedTowing.bisign b/addons/SA_AdvancedTowing.pbo.AdvancedTowing.bisign new file mode 100644 index 0000000..298da0c Binary files /dev/null and b/addons/SA_AdvancedTowing.pbo.AdvancedTowing.bisign differ diff --git a/addons/SA_AdvancedTowing/$PBOPREFIX$ b/addons/SA_AdvancedTowing/$PBOPREFIX$ new file mode 100644 index 0000000..40f8a5b --- /dev/null +++ b/addons/SA_AdvancedTowing/$PBOPREFIX$ @@ -0,0 +1 @@ +SA_AdvancedTowing \ No newline at end of file diff --git a/addons/SA_AdvancedTowing/config.cpp b/addons/SA_AdvancedTowing/config.cpp new file mode 100644 index 0000000..3550211 --- /dev/null +++ b/addons/SA_AdvancedTowing/config.cpp @@ -0,0 +1,69 @@ +class CfgPatches +{ + class SA_AdvancedTowing + { + units[] = {"SA_AdvancedTowing"}; + requiredVersion = 1.0; + requiredAddons[] = {"A3_Modules_F"}; + }; +}; + +/* +class CfgVehicles +{ + class Logic; + class Module_F: Logic + { + class ArgumentsBaseUnits + { + class Anything; + }; + class ModuleDescription + { + class Anything; + }; + }; + class SA_AdvancedSlingLoadingModule: Module_F + { + // Standard object definitions + scope = 2; // Editor visibility; 2 will show it in the menu, 1 will hide it. + displayName = "Advanced Sling Loading"; // Name displayed in the menu + category = "NO_CATEGORY"; + + // Name of function triggered once conditions are met + function = "SA_fnc_advancedSlingLoadingInit"; + // Execution priority, modules with lower number are executed first. 0 is used when the attribute is undefined + functionPriority = 1; + // 0 for server only execution, 1 for global execution, 2 for persistent global execution + isGlobal = 0; + // 1 for module waiting until all synced triggers are activated + isTriggerActivated = 0; + // 1 if modules is to be disabled once it's activated (i.e., repeated trigger activation won't work) + isDisposable = 0; + // // 1 to run init function in Eden Editor as well + is3DEN = 0; + + // Menu displayed when the module is placed or double-clicked on by Zeus + //curatorInfoType = "RscDisplayAttributeModuleNuke"; + + // Module description. Must inherit from base class, otherwise pre-defined entities won't be available + class ModuleDescription: ModuleDescription + { + description = "Enables advanced sling loading"; // Short description, will be formatted as structured text + sync[] = {}; // Array of synced entities (can contain base classes) + }; + }; +}; +*/ + +class CfgFunctions +{ + class SA + { + class AdvancedSlingLoading + { + file = "\SA_AdvancedTowing\functions"; + class advancedTowingInit{postInit=1}; + }; + }; +}; \ No newline at end of file diff --git a/addons/SA_AdvancedTowing/functions/fn_advancedTowingInit.sqf b/addons/SA_AdvancedTowing/functions/fn_advancedTowingInit.sqf new file mode 100644 index 0000000..e0f4e12 --- /dev/null +++ b/addons/SA_AdvancedTowing/functions/fn_advancedTowingInit.sqf @@ -0,0 +1,377 @@ +/* +The MIT License (MIT) + +Copyright (c) 2016 Seth Duda + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ +{ + +if(!isNil "SA_TOW_INIT" || !hasInterface) exitWith {}; + +SA_TOW_INIT = true; + + +SA_Simulate_Towing = { + + params ["_vehicle","_vehicleHitchModelPos","_cargo","_cargoHitchModelPos","_ropeLength"]; + + private ["_lastCargoHitchPosition","_lastCargoVectorDir","_bbr","_p1","_p2","_maxCargoWidth","_maxCargoLength","_cargoLength"]; + + _lastCargoHitchPosition = _cargo modelToWorld _cargoHitchModelPos; + _lastCargoVectorDir = vectorDir _cargo; + + _bbr = boundingBoxReal _cargo; + _p1 = _bbr select 0; + _p2 = _bbr select 1; + _maxCargoWidth = abs ((_p2 select 0) - (_p1 select 0)); + _maxCargoLength = abs ((_p2 select 1) - (_p1 select 1)); + _cargoLength = _maxCargoWidth max _maxCargoLength; + + private ["_vehicleHitchPosition","_cargoHitchPosition","_newCargoHitchPosition","_cargoVector","_movedCargoVector","_newCargoDir","_lastCargoVectorDir","_newCargoPosition","_doExit"]; + + _doExit = false; + + while {count (ropeAttachedObjects _vehicle) == 1 && alive _cargo && !_doExit} do { + + _vehicleHitchPosition = _vehicle modelToWorld _vehicleHitchModelPos; + _vehicleHitchPosition set [2,0]; + _cargoHitchPosition = _lastCargoHitchPosition; + _cargoHitchPosition set [2,0]; + + if(_vehicleHitchPosition distance _cargoHitchPosition > _ropeLength) then { + + _newCargoHitchPosition = _vehicleHitchPosition vectorAdd ((_vehicleHitchPosition vectorFromTo _cargoHitchPosition) vectorMultiply _ropeLength); + _cargoVector = _lastCargoVectorDir vectorMultiply _cargoLength; + _movedCargoVector = _newCargoHitchPosition vectorDiff _lastCargoHitchPosition; + _newCargoDir = vectorNormalized (_cargoVector vectorAdd _movedCargoVector); + _lastCargoVectorDir = _newCargoDir; + _newCargoPosition = _newCargoHitchPosition vectorAdd (_newCargoDir vectorMultiply -(vectorMagnitude _cargoHitchModelPos)); + _cargo setVectorDir _newCargoDir; + _cargo setPos _newCargoPosition; + _lastCargoHitchPosition = _newCargoHitchPosition; + + } else { + _lastCargoHitchPosition = _cargo modelToWorld _cargoHitchModelPos; + _lastCargoVectorDir = vectorDir _cargo; + }; + + if(!local _vehicle) then { + _this remoteExec ["SA_Simulate_Towing", _vehicle]; + _doExit = true; + }; + + sleep 0.02; + + }; +}; + + +SA_Get_Hitch_Points = { + params ["_vehicle"]; + private ["_bb","_bbBottom","_bbTop","_centerOfMass","_rearCorner","_rearCorner2","_frontCorner","_frontCorner2","_rearHitchPoint","_frontHitchPoint"]; + _bb = boundingBoxReal _vehicle; + _bbBottom = _bb select 0; + _bbTop = _bb select 1; + _centerOfMass = getCenterOfMass _vehicle; + _rearCorner = [(_bbBottom select 0),(_bbBottom select 1)*0.75, (_centerOfMass select 2) ]; + _rearCorner2 = [(_bbTop select 0),(_bbBottom select 1)*0.75, (_centerOfMass select 2)]; + _frontCorner = [(_bbTop select 0),(_bbTop select 1)*0.75, (_centerOfMass select 2)]; + _frontCorner2 = [(_bbBottom select 0),(_bbTop select 1)*0.75, (_centerOfMass select 2)]; + _rearHitchPoint = [((_rearCorner select 0) + (_rearCorner2 select 0))/2,((_rearCorner select 1) + (_rearCorner2 select 1))/2,((_rearCorner select 2) + (_rearCorner select 2))/2]; + _frontHitchPoint = [((_frontCorner select 0) + (_frontCorner2 select 0))/2,((_frontCorner select 1) + (_frontCorner2 select 1))/2,((_frontCorner select 2) + (_frontCorner2 select 2))/2]; + [_frontHitchPoint,_rearHitchPoint,_frontCorner,_frontCorner2,_rearCorner,_rearCorner2]; +}; + +SA_Attach_Tow_Ropes = { + params ["_cargo","_player"]; + _vehicle = _player getVariable ["SA_Tow_Ropes_Vehicle", objNull]; + if(!isNull _vehicle) then { + if(local _vehicle) then { + private ["_towRopes","_hitchPoints","_cargoHitch"]; + _towRopes = _vehicle getVariable ["SA_Tow_Ropes",[]]; + if(count _towRopes == 1) then { + [_vehicle,_player] call SA_Drop_Tow_Ropes; + _hitchPoints = [_cargo] call SA_Get_Hitch_Points; + _cargoHitch = _hitchPoints select 0; + _helper = "Land_Can_V2_F" createVehicle position _cargo; + _helper attachTo [_cargo, _cargoHitch]; + hideObjectGlobal _helper; + [_helper, [0,0,0], [0,0,-1]] ropeAttachTo (_towRopes select 0); + _ropeLength = (ropeLength (_towRopes select 0)); + _vehicleHitch = ([_vehicle] call SA_Get_Hitch_Points) select 1; + [_vehicle,_vehicleHitch,_cargo,_cargoHitch,_ropeLength] spawn SA_Simulate_Towing; + }; + } else { + _this remoteExecCall ["SA_Attach_Tow_Ropes", _vehicle]; + }; + }; +}; + +SA_Take_Tow_Ropes = { + params ["_vehicle","_player"]; + if(local _vehicle) then { + private ["_existingTowRopes","_hitchPoint","_rope"]; + _existingTowRopes = _vehicle getVariable ["SA_Tow_Ropes",[]]; + if(count _existingTowRopes == 0) then { + _hitchPoint = [_vehicle] call SA_Get_Hitch_Points select 1; + _rope = ropeCreate [_vehicle, _hitchPoint, 10]; + _vehicle setVariable ["SA_Tow_Ropes",[_rope],true]; + _this call SA_Pickup_Tow_Ropes; + }; + } else { + _this remoteExecCall ["SA_Take_Tow_Ropes", _vehicle]; + }; +}; + +SA_Put_Away_Tow_Ropes = { + params ["_vehicle","_player"]; + if(local _vehicle) then { + private ["_existingTowRopes","_hitchPoint","_rope"]; + _existingTowRopes = _vehicle getVariable ["SA_Tow_Ropes",[]]; + if(count _existingTowRopes > 0) then { + _this call SA_Pickup_Tow_Ropes; + _this call SA_Drop_Tow_Ropes; + { + ropeDestroy _x; + } forEach _existingTowRopes; + _vehicle setVariable ["SA_Tow_Ropes",nil,true]; + }; + } else { + _this remoteExecCall ["SA_Put_Away_Tow_Ropes", _vehicle]; + }; +}; + +SA_Pickup_Tow_Ropes = { + params ["_vehicle","_player"]; + if(local _vehicle) then { + private ["_attachedObj","_helper"]; + { + _attachedObj = _x; + { + _attachedObj ropeDetach _x; + } forEach (_vehicle getVariable ["SA_Tow_Ropes",[]]); + } forEach ropeAttachedObjects _vehicle; + _helper = "Land_Can_V2_F" createVehicle position _player; + { + [_helper, [0, 0, 0], [0,0,-1]] ropeAttachTo _x; + _helper attachTo [_player, [-0.1, 0.1, 0.15], "Pelvis"]; + } forEach (_vehicle getVariable ["SA_Tow_Ropes",[]]); + hideObjectGlobal _helper; + _player setVariable ["SA_Tow_Ropes_Vehicle", _vehicle,true]; + _player setVariable ["SA_Tow_Ropes_Pick_Up_Helper", _helper,true]; + } else { + _this remoteExecCall ["SA_Pickup_Tow_Ropes", _vehicle]; + }; +}; + +SA_Drop_Tow_Ropes = { + params ["_vehicle","_player"]; + if(local _vehicle) then { + private ["_helper"]; + _helper = (_player getVariable ["SA_Tow_Ropes_Pick_Up_Helper", objNull]); + if(!isNull _helper) then { + { + _helper ropeDetach _x; + } forEach (_vehicle getVariable ["SA_Tow_Ropes",[]]); + detach _helper; + deleteVehicle _helper; + }; + _player setVariable ["SA_Tow_Ropes_Vehicle", nil,true]; + _player setVariable ["SA_Tow_Ropes_Pick_Up_Helper", nil,true]; + } else { + _this remoteExecCall ["SA_Drop_Tow_Ropes", _vehicle]; + }; +}; + +SA_Attach_Tow_Ropes_Action = { + private ["_vehicle","_towRopes"]; + _vehicle = cursorTarget; + if([_vehicle] call SA_Is_Supported_Vehicle) then { + [_vehicle,player] call SA_Attach_Tow_Ropes; + } else { + false; + }; +}; + +SA_Attach_Tow_Ropes_Action_Check = { + private ["_vehicle","_towVehicle"]; + _vehicle = cursorTarget; + if([_vehicle] call SA_Is_Supported_Vehicle) then { + _towVehicle = player getVariable ["SA_Tow_Ropes_Vehicle", objNull]; + vehicle player == player && player distance _vehicle < 10 && !isNull _towVehicle && _towVehicle != _vehicle; + } else { + false; + }; +}; + +SA_Take_Tow_Ropes_Action_Check = { + private ["_vehicle"]; + _vehicle = cursorTarget; + if([_vehicle] call SA_Is_Supported_Vehicle) then { + _existingTowRopes = _vehicle getVariable ["SA_Tow_Ropes",[]]; + _towVehicle = player getVariable ["SA_Tow_Ropes_Vehicle", objNull]; + vehicle player == player && player distance _vehicle < 10 && (count _existingTowRopes) == 0 && isNull _towVehicle; + } else { + false; + }; +}; + +SA_Put_Away_Tow_Ropes_Action_Check = { + private ["_vehicle"]; + _vehicle = cursorTarget; + if([_vehicle] call SA_Is_Supported_Vehicle) then { + _existingTowRopes = _vehicle getVariable ["SA_Tow_Ropes",[]]; + vehicle player == player && player distance _vehicle < 10 && (count _existingTowRopes) > 0; + } else { + false; + }; +}; + +SA_Drop_Tow_Ropes_Action_Check = { + !isNull (player getVariable ["SA_Tow_Ropes_Vehicle", objNull]) && vehicle player == player; +}; + +SA_Pickup_Tow_Ropes_Action_Check = { + isNull (player getVariable ["SA_Tow_Ropes_Vehicle", objNull]) && count (missionNamespace getVariable ["SA_Nearby_Tow_Vehicles",[]]) > 0 && vehicle player == player; +}; + +SA_Pickup_Tow_Ropes_Action = { + private ["_nearbyTowVehicles"]; + _nearbyTowVehicles = missionNamespace getVariable ["SA_Nearby_Tow_Vehicles",[]]; + if(count _nearbyTowVehicles > 0) then { + [_nearbyTowVehicles select 0, player] call SA_Pickup_Tow_Ropes; + }; +}; + +SA_Drop_Tow_Ropes_Action = { + private ["_vehicle"]; + _vehicle = player getVariable ["SA_Tow_Ropes_Vehicle", objNull]; + if(!isNull _vehicle) then { + [_vehicle, player] call SA_Drop_Tow_Ropes; + }; +}; + +SA_Is_Supported_Vehicle = { + params ["_vehicle"]; + if(not isNull _vehicle) then { + if(_vehicle isKindOf "Tank" || _vehicle isKindOf "Car" || _vehicle isKindOf "Ship" || _vehicle isKindOf "Air") then { + alive _vehicle; + } else { + false; + }; + } else { + false; + }; +}; + +SA_Take_Tow_Ropes_Action = { + private ["_vehicle"]; + _vehicle = cursorTarget; + if([_vehicle] call SA_Is_Supported_Vehicle) then { + [_vehicle,player] call SA_Take_Tow_Ropes; + }; +}; + + +SA_Put_Away_Tow_Ropes_Action = { + private ["_vehicle"]; + _vehicle = cursorTarget; + if([_vehicle] call SA_Is_Supported_Vehicle) then { + [_vehicle,player] call SA_Put_Away_Tow_Ropes; + }; +}; + +if(hasInterface) then { + + player addAction ["Deploy Tow Ropes", { + [] call SA_Take_Tow_Ropes_Action; + }, nil, 0, false, true, "", "call SA_Take_Tow_Ropes_Action_Check"]; + + player addEventHandler ["Respawn", { + player addAction ["Deploy Tow Ropes", { + [] call SA_Take_Tow_Ropes_Action; + }, nil, 0, false, true, "", "call SA_Take_Tow_Ropes_Action_Check"]; + }]; + + player addAction ["Put Away Tow Ropes", { + [] call SA_Put_Away_Tow_Ropes_Action; + }, nil, 0, false, true, "", "call SA_Put_Away_Tow_Ropes_Action_Check"]; + + player addEventHandler ["Respawn", { + player addAction ["Put Away Tow Ropes", { + [] call SA_Put_Away_Tow_Ropes_Action; + }, nil, 0, false, true, "", "call SA_Put_Away_Tow_Ropes_Action_Check"]; + }]; + + player addAction ["Attach To Tow Ropes", { + [] call SA_Attach_Tow_Ropes_Action; + }, nil, 0, false, true, "", "call SA_Attach_Tow_Ropes_Action_Check"]; + + player addEventHandler ["Respawn", { + player addAction ["Attach To Tow Ropes", { + [] call SA_Attach_Tow_Ropes_Action; + }, nil, 0, false, true, "", "call SA_Attach_Tow_Ropes_Action_Check"]; + }]; + + player addAction ["Drop Tow Ropes", { + [] call SA_Drop_Tow_Ropes_Action; + }, nil, 0, false, true, "", "call SA_Drop_Tow_Ropes_Action_Check"]; + + player addEventHandler ["Respawn", { + player addAction ["Drop Tow Ropes", { + [] call SA_Drop_Tow_Ropes_Action; + }, nil, 0, false, true, "", "call SA_Drop_Tow_Ropes_Action_Check"]; + }]; + + player addAction ["Pickup Tow Ropes", { + [] call SA_Pickup_Tow_Ropes_Action; + }, nil, 0, false, true, "", "call SA_Pickup_Tow_Ropes_Action_Check"]; + + player addEventHandler ["Respawn", { + player addAction ["Pickup Tow Ropes", { + [] call SA_Pickup_Tow_Ropes_Action; + }, nil, 0, false, true, "", "call SA_Pickup_Tow_Ropes_Action_Check"]; + }]; + +}; + +SA_Find_Nearby_Tow_Vehicles = { + private ["_nearVehicles","_nearVehiclesWithTowRopes","_vehicle","_ends","_end1","_end2"]; + _nearVehicles = []; + _nearVehicles append (position player nearObjects ["Tank", 30]); + _nearVehicles append (position player nearObjects ["Car", 30]); + _nearVehicles append (position player nearObjects ["Ship", 30]); + _nearVehiclesWithTowRopes = []; + { + _vehicle = _x; + { + _ends = ropeEndPosition _x; + if(count _ends == 2) then { + _end1 = _ends select 0; + _end2 = _ends select 1; + if(((position player) distance _end1) < 5 || ((position player) distance _end2) < 5 ) then { + _nearVehiclesWithTowRopes pushBack _vehicle; + } + }; + } forEach (_vehicle getVariable ["SA_Tow_Ropes",[]]); + } forEach _nearVehicles; + _nearVehiclesWithTowRopes; +}; + + +if(!isDedicated) then { + [] spawn { + while {true} do { + missionNamespace setVariable ["SA_Nearby_Tow_Vehicles", (call SA_Find_Nearby_Tow_Vehicles)]; + sleep 2; + }; + }; +}; + + +} remoteExecCall ["bis_fnc_call", 0,true]; diff --git a/keys/AdvancedTowing.bikey b/keys/AdvancedTowing.bikey new file mode 100644 index 0000000..d02b8dc Binary files /dev/null and b/keys/AdvancedTowing.bikey differ diff --git a/logo.paa b/logo.paa new file mode 100644 index 0000000..8b67a96 Binary files /dev/null and b/logo.paa differ diff --git a/logo.png b/logo.png new file mode 100644 index 0000000..2a30e6d Binary files /dev/null and b/logo.png differ diff --git a/logo.psd b/logo.psd new file mode 100644 index 0000000..94dded0 Binary files /dev/null and b/logo.psd differ diff --git a/mod.cpp b/mod.cpp new file mode 100644 index 0000000..1164872 --- /dev/null +++ b/mod.cpp @@ -0,0 +1,12 @@ +name = "Advanced Towing"; +picture = "logo.paa"; +description = "Advanced Towing"; +logo = "logo.paa"; +logoOver = "logo.paa"; +tooltip = "Advanced Towing"; +tooltipOwned = "Advanced Towing Owned"; +overview = "Advanced Towing"; +author = "[SA] Duda"; +overviewPicture = "logo.paa"; +overviewText = "Advanced Towing"; +overviewFootnote = ""; \ No newline at end of file diff --git a/steamLogo.jpg b/steamLogo.jpg new file mode 100644 index 0000000..009f8de Binary files /dev/null and b/steamLogo.jpg differ diff --git a/steamLogo.psd b/steamLogo.psd new file mode 100644 index 0000000..f0252d4 Binary files /dev/null and b/steamLogo.psd differ