mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Common - Add wheel hitpoint function (#10075)
* Add wheel hitpoint function * Moved cache to missionNamespace
This commit is contained in:
parent
c28a3d6cdf
commit
421071027e
@ -103,6 +103,7 @@ PREP(getWeaponAzimuthAndInclination);
|
|||||||
PREP(getWeaponIndex);
|
PREP(getWeaponIndex);
|
||||||
PREP(getWeaponState);
|
PREP(getWeaponState);
|
||||||
PREP(getWeight);
|
PREP(getWeight);
|
||||||
|
PREP(getWheelHitPointsWithSelections);
|
||||||
PREP(getWindDirection);
|
PREP(getWindDirection);
|
||||||
PREP(getZoom);
|
PREP(getZoom);
|
||||||
PREP(goKneeling);
|
PREP(goKneeling);
|
||||||
|
@ -10,6 +10,7 @@ PREP_RECOMPILE_END;
|
|||||||
GVAR(syncedEvents) = createHashMap;
|
GVAR(syncedEvents) = createHashMap;
|
||||||
GVAR(showHudHash) = createHashMap;
|
GVAR(showHudHash) = createHashMap;
|
||||||
GVAR(vehicleIconCache) = createHashMap; // for getVehicleIcon
|
GVAR(vehicleIconCache) = createHashMap; // for getVehicleIcon
|
||||||
|
GVAR(wheelSelections) = createHashMap;
|
||||||
|
|
||||||
GVAR(blockItemReplacement) = false;
|
GVAR(blockItemReplacement) = false;
|
||||||
|
|
||||||
|
104
addons/common/functions/fnc_getWheelHitPointsWithSelections.sqf
Normal file
104
addons/common/functions/fnc_getWheelHitPointsWithSelections.sqf
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
#include "..\script_component.hpp"
|
||||||
|
/*
|
||||||
|
* Author: commy2, johnb43
|
||||||
|
* Returns the wheel hitpoints and their selections.
|
||||||
|
*
|
||||||
|
* Arguments:
|
||||||
|
* 0: Vehicle <OBJECT>
|
||||||
|
*
|
||||||
|
* Return Value:
|
||||||
|
* 0: Wheel hitpoints <ARRAY>
|
||||||
|
* 1: Wheel hitpoint selections <ARRAY>
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* cursorObject call ace_common_fnc_getWheelHitPointsWithSelections
|
||||||
|
*
|
||||||
|
* Public: No
|
||||||
|
*/
|
||||||
|
|
||||||
|
params ["_vehicle"];
|
||||||
|
TRACE_1("params",_vehicle);
|
||||||
|
|
||||||
|
// TODO: Fix for GM vehicles
|
||||||
|
GVAR(wheelSelections) getOrDefaultCall [typeOf _vehicle, {
|
||||||
|
// Get the vehicles wheel config
|
||||||
|
private _wheels = configOf _vehicle >> "Wheels";
|
||||||
|
|
||||||
|
if (isClass _wheels) then {
|
||||||
|
// Get all hitpoints and selections
|
||||||
|
(getAllHitPointsDamage _vehicle) params ["_hitPoints", "_hitPointSelections"];
|
||||||
|
|
||||||
|
// Get all wheels and read selections from config
|
||||||
|
_wheels = "true" configClasses _wheels;
|
||||||
|
|
||||||
|
private _wheelHitPoints = [];
|
||||||
|
private _wheelHitPointSelections = [];
|
||||||
|
|
||||||
|
{
|
||||||
|
private _wheelName = configName _x;
|
||||||
|
private _wheelCenter = getText (_x >> "center");
|
||||||
|
private _wheelBone = getText (_x >> "boneName");
|
||||||
|
private _wheelBoneNameResized = _wheelBone select [0, 9]; // Count "wheel_X_Y"; // this is a requirement for physx. Should work for all addon vehicles.
|
||||||
|
|
||||||
|
TRACE_4("",_wheelName,_wheelCenter,_wheelBone,_wheelBoneNameResized);
|
||||||
|
|
||||||
|
private _wheelHitPoint = "";
|
||||||
|
private _wheelHitPointSelection = "";
|
||||||
|
|
||||||
|
// Commy's orginal method
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
};
|
||||||
|
} forEach _hitPointSelections;
|
||||||
|
|
||||||
|
|
||||||
|
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 {
|
||||||
|
private _wheelCenterPos = _vehicle selectionPosition _wheelCenter;
|
||||||
|
if (_wheelCenterPos isEqualTo [0, 0, 0]) exitWith {TRACE_1("no center?",_wheelCenter);};
|
||||||
|
|
||||||
|
|
||||||
|
private _bestDist = 99;
|
||||||
|
private _bestIndex = -1;
|
||||||
|
{
|
||||||
|
if (_x != "") then {
|
||||||
|
// Filter out things that definitly aren't wheeels (#3759)
|
||||||
|
if ((toLowerANSI (_hitPoints select _forEachIndex)) in ["hitengine", "hitfuel", "hitbody"]) exitWith {TRACE_1("filter",_x)};
|
||||||
|
private _xPos = _vehicle selectionPosition _x;
|
||||||
|
if (_xPos isEqualTo [0, 0, 0]) exitWith {};
|
||||||
|
private _xDist = _wheelCenterPos distance _xPos;
|
||||||
|
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);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
if ((_wheelHitPoint != "") && {_wheelHitPointSelection != ""}) then {
|
||||||
|
_wheelHitPoints pushBack _wheelHitPoint;
|
||||||
|
_wheelHitPointSelections pushBack _wheelHitPointSelection;
|
||||||
|
};
|
||||||
|
} forEach _wheels;
|
||||||
|
|
||||||
|
[_wheelHitPoints, _wheelHitPointSelections]
|
||||||
|
} else {
|
||||||
|
// Exit with nothing if the vehicle has no wheels class
|
||||||
|
TRACE_1("No Wheels",_wheels);
|
||||||
|
|
||||||
|
[[], []]
|
||||||
|
}
|
||||||
|
}, true] // return
|
@ -17,38 +17,22 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
params ["_vehicle", "_position"];
|
params ["_vehicle", "_position"];
|
||||||
TRACE_1("damageWheelsAndEngine",_vehicle);
|
TRACE_2("damageWheelsAndEngine",_vehicle,_position);
|
||||||
|
|
||||||
// Vehicle needs to be local and vulnerable
|
// Vehicle needs to be local and vulnerable
|
||||||
if !(local _vehicle && {isDamageAllowed _vehicle}) exitWith {};
|
if !(local _vehicle && {isDamageAllowed _vehicle}) exitWith {};
|
||||||
|
|
||||||
// Burn tires
|
|
||||||
private _fnc_isWheelHitPoint = {
|
|
||||||
params ["_selectionName"];
|
|
||||||
// Wheels must use a selection named "wheel_X_Y_steering" for PhysX to work
|
|
||||||
_selectionName select [0, 6] == "wheel_" && {
|
|
||||||
_selectionName select [count _selectionName - 9] == "_steering"
|
|
||||||
} // return
|
|
||||||
};
|
|
||||||
|
|
||||||
private _config = configOf _vehicle >> "HitPoints";
|
|
||||||
|
|
||||||
{
|
{
|
||||||
private _wheelSelection = getText (_config >> _x >> "name");
|
// If wheel is close enough to incendiary, burn it
|
||||||
|
if (_position distance (_vehicle modelToWorld (_vehicle selectionPosition _x)) < EFFECT_SIZE * 2) then {
|
||||||
if (_wheelSelection call _fnc_isWheelHitPoint) then {
|
_vehicle setHit [_x, 1];
|
||||||
private _wheelPosition = _vehicle modelToWorld (_vehicle selectionPosition _wheelSelection);
|
|
||||||
|
|
||||||
if (_position distance _wheelPosition < EFFECT_SIZE * 2) then {
|
|
||||||
_vehicle setHit [_wheelSelection, 1];
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
} forEach (getAllHitPointsDamage _vehicle param [0, []]);
|
} forEach ((_vehicle call EFUNC(common,getWheelHitPointsWithSelections)) select 1);
|
||||||
|
|
||||||
// Burn car engines only
|
// Burn car engines only
|
||||||
if (_vehicle isKindOf "Wheeled_APC_F") exitWith {};
|
if (_vehicle isKindOf "Wheeled_APC_F") exitWith {};
|
||||||
|
|
||||||
private _engineSelection = getText (_config >> "HitEngine" >> "name");
|
private _engineSelection = getText (configOf _vehicle >> "HitPoints" >> "HitEngine" >> "name");
|
||||||
private _enginePosition = _vehicle modelToWorld (_vehicle selectionPosition _engineSelection);
|
private _enginePosition = _vehicle modelToWorld (_vehicle selectionPosition _engineSelection);
|
||||||
|
|
||||||
if (_position distance _enginePosition < EFFECT_SIZE * 2) then {
|
if (_position distance _enginePosition < EFFECT_SIZE * 2) then {
|
||||||
|
@ -25,7 +25,6 @@ PREP(getSelectionsToIgnore);
|
|||||||
PREP(getPatchWheelTime);
|
PREP(getPatchWheelTime);
|
||||||
PREP(getPostRepairDamage);
|
PREP(getPostRepairDamage);
|
||||||
PREP(getRepairItems);
|
PREP(getRepairItems);
|
||||||
PREP(getWheelHitPointsWithSelections);
|
|
||||||
PREP(hasItems);
|
PREP(hasItems);
|
||||||
PREP(isEngineer);
|
PREP(isEngineer);
|
||||||
PREP(isInRepairFacility);
|
PREP(isInRepairFacility);
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "..\script_component.hpp"
|
#include "..\script_component.hpp"
|
||||||
|
|
||||||
addMissionEventHandler ["Draw3D", {
|
addMissionEventHandler ["Draw3D", {
|
||||||
|
if (isGamePaused) exitWith {};
|
||||||
if !((cursorObject isKindOf "Car") || (cursorObject isKindOf "Tank") || (cursorObject isKindOf "Air")) exitWith {};
|
if !((cursorObject isKindOf "Car") || (cursorObject isKindOf "Tank") || (cursorObject isKindOf "Air")) exitWith {};
|
||||||
private _config = configOf cursorObject;
|
private _config = configOf cursorObject;
|
||||||
|
|
||||||
@ -11,7 +12,7 @@ addMissionEventHandler ["Draw3D", {
|
|||||||
private _hitpointGroups = getArray (_config >> QGVAR(hitpointGroups));
|
private _hitpointGroups = getArray (_config >> QGVAR(hitpointGroups));
|
||||||
|
|
||||||
(getAllHitPointsDamage cursorObject) params [["_hitPoints", []], ["_hitSelections", []]];
|
(getAllHitPointsDamage cursorObject) params [["_hitPoints", []], ["_hitSelections", []]];
|
||||||
([cursorObject] call FUNC(getWheelHitPointsWithSelections)) params ["_wheelHitPoints", "_wheelHitSelections"];
|
([cursorObject] call EFUNC(common,getWheelHitPointsWithSelections)) params ["_wheelHitPoints", "_wheelHitSelections"];
|
||||||
|
|
||||||
private _output = [];
|
private _output = [];
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ private _selectionsToIgnore = _vehicle call FUNC(getSelectionsToIgnore);
|
|||||||
(getAllHitPointsDamage _vehicle) params [["_hitPoints", []], ["_hitSelections", []]]; // Since 1.82 these are all lower case
|
(getAllHitPointsDamage _vehicle) params [["_hitPoints", []], ["_hitSelections", []]]; // Since 1.82 these are all lower case
|
||||||
|
|
||||||
// get hitpoints of wheels with their selections
|
// get hitpoints of wheels with their selections
|
||||||
([_vehicle] call FUNC(getWheelHitPointsWithSelections)) params ["_wheelHitPoints", "_wheelHitSelections"];
|
([_vehicle] call EFUNC(common,getWheelHitPointsWithSelections)) params ["_wheelHitPoints", "_wheelHitSelections"];
|
||||||
|
|
||||||
private _hitPointsAddedNames = [];
|
private _hitPointsAddedNames = [];
|
||||||
private _hitPointsAddedStrings = [];
|
private _hitPointsAddedStrings = [];
|
||||||
|
@ -28,7 +28,7 @@ private _turretPaths = ((fullCrew [_vehicle, "gunner", true]) + (fullCrew [_vehi
|
|||||||
|
|
||||||
(getAllHitPointsDamage _vehicle) params [["_hitPoints", []], ["_hitSelections", []]];
|
(getAllHitPointsDamage _vehicle) params [["_hitPoints", []], ["_hitSelections", []]];
|
||||||
// get hitpoints of wheels with their selections
|
// get hitpoints of wheels with their selections
|
||||||
([_vehicle] call FUNC(getWheelHitPointsWithSelections)) params ["_wheelHitPoints", "_wheelHitSelections"];
|
([_vehicle] call EFUNC(common,getWheelHitPointsWithSelections)) params ["_wheelHitPoints", "_wheelHitSelections"];
|
||||||
|
|
||||||
private _indexesToIgnore = [];
|
private _indexesToIgnore = [];
|
||||||
private _processedSelections = [];
|
private _processedSelections = [];
|
||||||
|
@ -1,97 +0,0 @@
|
|||||||
#include "..\script_component.hpp"
|
|
||||||
/*
|
|
||||||
* Author: commy2
|
|
||||||
* Returns the wheel hitpoints and their selections.
|
|
||||||
*
|
|
||||||
* Arguments:
|
|
||||||
* 0: Vehicle <OBJECT>
|
|
||||||
*
|
|
||||||
* Return Value:
|
|
||||||
* 0: Wheel hitpoints <ARRAY>
|
|
||||||
* 1: Wheel hitpoint selections in model coordinates <ARRAY>
|
|
||||||
*
|
|
||||||
* Example:
|
|
||||||
* [car1] call ace_repair_fnc_getWheelHitPointsWithSelections
|
|
||||||
*
|
|
||||||
* Public: No
|
|
||||||
*/
|
|
||||||
|
|
||||||
params ["_vehicle"];
|
|
||||||
TRACE_1("params",_vehicle);
|
|
||||||
|
|
||||||
// get the vehicles wheel config
|
|
||||||
private _wheels = configOf _vehicle >> "Wheels";
|
|
||||||
|
|
||||||
// exit with nothing if the vehicle has no wheels class
|
|
||||||
if !(isClass _wheels) exitWith {TRACE_1("No Wheels",_wheels); [[],[]]};
|
|
||||||
|
|
||||||
// get all hitpoints and selections
|
|
||||||
(getAllHitPointsDamage _vehicle) params ["_hitPoints", "_hitPointSelections"];
|
|
||||||
|
|
||||||
// get all wheels and read selections from config
|
|
||||||
_wheels = "true" configClasses _wheels;
|
|
||||||
|
|
||||||
private _wheelHitPoints = [];
|
|
||||||
private _wheelHitPointSelections = [];
|
|
||||||
|
|
||||||
{
|
|
||||||
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.
|
|
||||||
|
|
||||||
TRACE_4("",_wheelName,_wheelCenter,_wheelBone,_wheelBoneNameResized);
|
|
||||||
|
|
||||||
private _wheelHitPoint = "";
|
|
||||||
private _wheelHitPointSelection = "";
|
|
||||||
|
|
||||||
//Commy's orginal method
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
};
|
|
||||||
} forEach _hitPointSelections;
|
|
||||||
|
|
||||||
|
|
||||||
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 {
|
|
||||||
private _wheelCenterPos = _vehicle selectionPosition _wheelCenter;
|
|
||||||
if (_wheelCenterPos isEqualTo [0,0,0]) exitWith {TRACE_1("no center?",_wheelCenter);};
|
|
||||||
|
|
||||||
|
|
||||||
private _bestDist = 99;
|
|
||||||
private _bestIndex = -1;
|
|
||||||
{
|
|
||||||
if (_x != "") then {
|
|
||||||
//Filter out things that definitly aren't wheeels (#3759)
|
|
||||||
if ((toLowerANSI (_hitPoints select _forEachIndex)) in ["hitengine", "hitfuel", "hitbody"]) exitWith {TRACE_1("filter",_x)};
|
|
||||||
private _xPos = _vehicle selectionPosition _x;
|
|
||||||
if (_xPos isEqualTo [0,0,0]) exitWith {};
|
|
||||||
private _xDist = _wheelCenterPos distance _xPos;
|
|
||||||
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);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
if ((_wheelHitPoint != "") && {_wheelHitPointSelection != ""}) then {
|
|
||||||
_wheelHitPoints pushBack _wheelHitPoint;
|
|
||||||
_wheelHitPointSelections pushBack _wheelHitPointSelection;
|
|
||||||
};
|
|
||||||
} forEach _wheels;
|
|
||||||
|
|
||||||
[_wheelHitPoints, _wheelHitPointSelections]
|
|
Loading…
Reference in New Issue
Block a user