2018-09-17 19:19:29 +00:00
|
|
|
#include "script_component.hpp"
|
2015-03-11 08:37:11 +00:00
|
|
|
/*
|
|
|
|
* Author: commy2
|
|
|
|
* Returns the wheel hitpoints and their selections.
|
|
|
|
*
|
|
|
|
* Arguments:
|
2015-08-16 18:14:54 +00:00
|
|
|
* 0: Vehicle <OBJECT>
|
2015-03-11 08:37:11 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
2015-08-16 18:14:54 +00:00
|
|
|
* 0: Wheel hitpoints <ARRAY>
|
|
|
|
* 1: Wheel hitpoint selections in model coordinates <ARRAY>
|
|
|
|
*
|
|
|
|
* Example:
|
2015-09-26 04:36:35 +00:00
|
|
|
* [car1] call ace_repair_fnc_getWheelHitPointsWithSelections
|
2015-08-16 18:14:54 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
2015-03-11 08:37:11 +00:00
|
|
|
*/
|
|
|
|
|
2015-08-09 06:54:44 +00:00
|
|
|
params ["_vehicle"];
|
|
|
|
TRACE_1("params",_vehicle);
|
2015-03-11 08:37:11 +00:00
|
|
|
|
|
|
|
// get the vehicles wheel config
|
2016-09-04 14:44:22 +00:00
|
|
|
private _wheels = configFile >> "CfgVehicles" >> typeOf _vehicle >> "Wheels";
|
2015-03-11 08:37:11 +00:00
|
|
|
|
|
|
|
// exit with nothing if the vehicle has no wheels class
|
2015-09-26 04:36:35 +00:00
|
|
|
if !(isClass _wheels) exitWith {TRACE_1("No Wheels",_wheels); [[],[]]};
|
2015-03-11 08:37:11 +00:00
|
|
|
|
2015-09-26 04:36:35 +00:00
|
|
|
// get all hitpoints and selections
|
|
|
|
(getAllHitPointsDamage _vehicle) params ["_hitPoints", "_hitPointSelections"];
|
2015-03-11 08:37:11 +00:00
|
|
|
|
2015-09-26 04:36:35 +00:00
|
|
|
// get all wheels and read selections from config
|
2015-03-11 08:37:11 +00:00
|
|
|
_wheels = "true" configClasses _wheels;
|
|
|
|
|
2017-10-10 14:39:59 +00:00
|
|
|
private _wheelHitPoints = [];
|
|
|
|
private _wheelHitPointSelections = [];
|
2015-09-26 04:36:35 +00:00
|
|
|
|
2015-03-11 08:37:11 +00:00
|
|
|
{
|
2017-10-10 14:39:59 +00:00
|
|
|
private _wheelName = configName _x;
|
|
|
|
private _wheelCenter = getText (_x >> "center");
|
|
|
|
private _wheelBone = getText (_x >> "boneName");
|
|
|
|
private _wheelBoneNameResized = _wheelBone select [0, 9]; //ount "wheel_X_Y"; // this is a requirement for physx. Should work for all addon vehicles.
|
2015-09-26 04:36:35 +00:00
|
|
|
|
|
|
|
TRACE_4("",_wheelName,_wheelCenter,_wheelBone,_wheelBoneNameResized);
|
2015-03-11 08:37:11 +00:00
|
|
|
|
2017-10-10 14:39:59 +00:00
|
|
|
private _wheelHitPoint = "";
|
|
|
|
private _wheelHitPointSelection = "";
|
2015-03-11 08:37:11 +00:00
|
|
|
|
2015-09-26 04:36:35 +00:00
|
|
|
//Commy's orginal method
|
2015-03-11 08:37:11 +00:00
|
|
|
{
|
2015-09-26 04:36:35 +00:00
|
|
|
if ((_wheelBoneNameResized != "") && {_x find _wheelBoneNameResized == 0}) exitWith { // same as above. Requirement for physx.
|
|
|
|
_wheelHitPoint = _hitPoints select _forEachIndex;
|
|
|
|
_wheelHitPointSelection = _hitPointSelections select _forEachIndex;
|
|
|
|
TRACE_2("wheel found [Orginal]", _wheelName, _wheelHitPoint);
|
2015-03-11 08:37:11 +00:00
|
|
|
};
|
|
|
|
} forEach _hitPointSelections;
|
|
|
|
|
2015-09-26 04:36:35 +00:00
|
|
|
|
|
|
|
if (_vehicle isKindOf "Car") then {
|
|
|
|
//Backup method, search for the closest hitpoint to the wheel's center selection pos.
|
|
|
|
//Ref #2742 - RHS's HMMWV
|
|
|
|
if (_wheelHitPoint == "") then {
|
2017-10-10 14:39:59 +00:00
|
|
|
private _wheelCenterPos = _vehicle selectionPosition _wheelCenter;
|
2015-09-26 04:36:35 +00:00
|
|
|
if (_wheelCenterPos isEqualTo [0,0,0]) exitWith {TRACE_1("no center?",_wheelCenter);};
|
|
|
|
|
|
|
|
|
2017-10-10 14:39:59 +00:00
|
|
|
private _bestDist = 99;
|
|
|
|
private _bestIndex = -1;
|
2015-09-26 04:36:35 +00:00
|
|
|
{
|
|
|
|
if (_x != "") then {
|
2016-05-07 21:04:27 +00:00
|
|
|
//Filter out things that definitly aren't wheeels (#3759)
|
|
|
|
if ((toLower (_hitPoints select _forEachIndex)) in ["hitengine", "hitfuel", "hitbody"]) exitWith {TRACE_1("filter",_x)};
|
2017-10-10 14:39:59 +00:00
|
|
|
private _xPos = _vehicle selectionPosition _x;
|
2015-09-26 04:36:35 +00:00
|
|
|
if (_xPos isEqualTo [0,0,0]) exitWith {};
|
2017-10-10 14:39:59 +00:00
|
|
|
private _xDist = _wheelCenterPos distance _xPos;
|
2015-09-26 04:36:35 +00:00
|
|
|
if (_xDist < _bestDist) then {
|
|
|
|
_bestIndex = _forEachIndex;
|
|
|
|
_bestDist = _xDist;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
} forEach _hitPointSelections;
|
|
|
|
|
|
|
|
TRACE_2("closestPoint",_bestDist,_bestIndex);
|
|
|
|
if (_bestIndex != -1) then {
|
|
|
|
_wheelHitPoint = _hitPoints select _bestIndex;
|
|
|
|
_wheelHitPointSelection = _hitPointSelections select _bestIndex;
|
|
|
|
TRACE_2("wheel found [Backup]", _wheelName, _wheelHitPoint);
|
|
|
|
};
|
|
|
|
};
|
2015-03-11 08:37:11 +00:00
|
|
|
};
|
|
|
|
|
2015-09-26 04:36:35 +00:00
|
|
|
if ((_wheelHitPoint != "") && {_wheelHitPointSelection != ""}) then {
|
|
|
|
_wheelHitPoints pushBack _wheelHitPoint;
|
|
|
|
_wheelHitPointSelections pushBack _wheelHitPointSelection;
|
|
|
|
};
|
|
|
|
} forEach _wheels;
|
2015-03-11 08:37:11 +00:00
|
|
|
|
|
|
|
[_wheelHitPoints, _wheelHitPointSelections]
|