Skip to content
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

Extend Advanced CAS #367

Merged
merged 17 commits into from
Sep 26, 2018
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ class CfgFunctions
class forceWeaponFire;
class drawArrow3D;
class drawRectangle3D;
class vectAngleXY;
class getDirPitchBank;
class vectDirUpFromDirPitchBank;
class arrayStdDev;
class transferOwnership;
};
CreepPork marked this conversation as resolved.
Show resolved Hide resolved
class interpolation
{
file = "\achilles\functions_f_achilles\functions\interpolation";
class interpolation_cubicBezier1D;
class interpolation_cubicBezier1D_slope;
};

class selectUnit
Expand Down Expand Up @@ -110,6 +121,9 @@ class CfgFunctions
class effectFire;
class instantBuildingGarrison;
class changeAccessoires;
class advancedPlaneCAS;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the spacing broken on github or not?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, apparently changeAccessories had indentation based on spaces.

class advancedHeliCAS;
class advancedBlackfishCAS;
};
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Function:
Achilles_arrayStdDev
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fnc


Authors:
Kex

Description:
Returns the population standard deviation of the array for _ddof = 0
CreepPork marked this conversation as resolved.
Show resolved Hide resolved
Returns the sample standard deviation of the array for _ddof = 1

Parameters:
_array - <ARRAY> The array from which the standard deviation is computed from
_ddof - <INTEGER> [0] The delta degrees of freedom (see description above)

Returns:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scalar here, int there

_stdDev - <SCALAR> The standard deviation

Exampes:
(begin example)
CreepPork marked this conversation as resolved.
Show resolved Hide resolved
(end)
*/
params ["_array", ["_ddof", 0, [0]]];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spacing everywhere please stop pushing it into a oneliner

private _N = (count _array) - _ddof;
if (_N <= 0) exitWith {0};
private _mean = _array call BIS_fnc_arithmeticMean;
private _array = _array apply {(_x - _mean)^2};
private _sum = _array call Achilles_fnc_sum;
sqrt (_sum / _N)
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Function:
Achilles_fnc_getDirPitchBank

Authors:
Kex

Description:
Returns dir, pitch and bank angle of the object
Unlike for getDir, the dir angle is 0 for vector dir [1,0,0]
and is positive in counterclockwise direction (i.e. mathematical angle instead of azimuth)

Parameters:
_object - <OBJECT> first 3D vector

Returns:
_dirPitchBank - <ARRAY> List with dir, pitch and bank angle.

Exampes:
(begin example)
[_object] call Achilles_fnc_getDirPitchBank;
(end)
*/

params ["_object"];
private _vectDir = vectorDirVisual _object;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spacing again

private _vectUp = vectorUpVisual _object;
private _pitch = 90 - acos(_vectDir vectorCos [0,0,1]);
// Get bank
private _vectPerpY = _vectDir vectorCrossProduct [0,0,1];
private _vectPerpZ = _vectPerpY vectorCrossProduct _vectDir;
private _world_to_model = [_vectPerpZ, _vectPerpY, _vectDir];
private _bank = [[1,0,0], [_world_to_model, _vectUp] call CBA_fnc_vectMap3D] call Achilles_fnc_vectAngleXY;
// Get dir
private _dir = [[1,0,0], _vectDir] call Achilles_fnc_vectAngleXY;
// Return
[_dir, _pitch, _bank]
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
Function:
Achilles_fnc_transferOwnership

Authors:
Kex

Description:
Changest the ownership of the past objects and groups
Provides a workaround for the loss of loadout bug after the transfer
This function has to be executed in scheduled environment and is completed as soon as it can confirm that the transfer was completed.

Parameters:
_object_list - <ARRAY> of <OBJECT> Objects to transfer
_group_list - <ARRAY> of <GROUP> Groups to transfer
_ownerID - <INTEGER> [clientOwner] The owner ID of the machine the objects and groups should be transfered to
By default they are transfered to this machine

Returns:
nothing

Exampes:
(begin example)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fantastic example

(end)
*/
params ["_object_list", "_group_list", ["_ownerID", clientOwner, [0]]];

if (_ownerID > 0 && (_ownerID != clientOwner)) then
{
// transfer ownership to server
// save the unit loadout
{
{
if (alive _x) then
{
_x setVariable ["Achilles_var_tmpLoadout", getUnitLoadout _x, true];
};
} forEach units _x;
} forEach _group_list;
[
[_ownerID,_object_list,_group_list],
{
params ["_ownerID","_object_list", "_group_list"];
// change ownership
{_x setOwner _ownerID} forEach _object_list;
{_x setGroupOwner _ownerID} forEach _group_list;
// reset the unit loadout as soon as they have become local
waitUntil {sleep 1; ({not local _x} count _group_list == 0) or {({not isNull _x} count _group_list == 0) or {{{alive _x} count units _x > 0} count _group_list == 0}}};
{
{
private _loadout = _x getVariable ["Achilles_var_tmpLoadout", []];
if !(_loadout isEqualTo []) then
{
_x setUnitLoadout _loadout;
};
_x setVariable ["Achilles_var_tmpLoadout", nil, true];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i’d prefer temp

} forEach units _x;
} forEach _group_list;
}, 2
] call Achilles_fnc_spawn;
}
else
{
// transfer ownership to Zeus
[
[clientOwner,_object_list,_group_list],
{
params ["_ownerID", "_object_list", "_group_list"];
// save the unit loadout
{
{
if (alive _x) then
{
_x setVariable ["Achilles_var_tmpLoadout", getUnitLoadout _x, true];
};
} forEach units _x;
} forEach _group_list;
// change ownership
{_x setOwner _ownerID} forEach _object_list;
{_x setGroupOwner _ownerID} forEach _group_list;
}, 2
] call Achilles_fnc_spawn;
// reset the unit loadout as soon as they have become local
waitUntil {sleep 1; ({not local _x} count _group_list == 0) or {({not isNull _x} count _group_list == 0) or {{{alive _x} count units _x > 0} count _group_list == 0}}};
{
{
private _loadout = _x getVariable ["Achilles_var_tmpLoadout", []];
if !(_loadout isEqualTo []) then
{
_x setUnitLoadout _loadout;
};
_x setVariable ["Achilles_var_tmpLoadout", nil, true];
} forEach units _x;
} forEach _group_list;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Function:
Achilles_fnc_vectAngleXY

Authors:
Kex

Description:
Calculates the signed angle from the first to the second vector in xy-plane
Positive sign means counterclockwise
Returns an angle from (-180,180]

Parameters:
_vecA - <ARRAY> First 3D vector
_vecB - <ARRAY> Second 3D vector

Returns:
_angle - <SCALAR> The measured angle

Exampes:
(begin example)
// returns 90
[[1,0,0],[0,1,0]] call Achilles_fnc_vectAngleXY;
(end)
*/

params
[
["_vecA", [0,0,0], [[]], 3],
["_vecB", [0,0,0], [[]], 3]
];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spacing

_vecA set [2, 0];
_vecB set [2, 0];
private _angle = acos (_vecA vectorCos _vecB);
// The sign of det(_vecA_XY _vecB_XY) tells us the orientation of the basis
private _determinat = (_vecA#0) * (_vecB#1) - (_vecB#0) * (_vecA#1);
if (_determinat < 0) then
{
_angle = -_angle;
};
// return
_angle
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

;

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
Function:
Achilles_fnc_vectDirUpFromDirPitchBank

Authors:
Kex

Description:
Returns vector dir and up from dir, pitch and bank angles
The output is suitable for setVectorDirAndUp
Rotation order: first dir, then pitch, then bank
Unlike for setDir, the dir angle is 0 for vector dir [1,0,0]
and is positive in counterclockwise direction (i.e. mathematical angle instead of azimuth)

Parameters:
_object - <OBJECT> first 3D vector

Returns:
_dirPitchBank - <ARRAY> List with dir, pitch and bank angle.

Exampes:
(begin example)
// returns [[0,sqrt(0.5),sqrt(0.5)],[sqrt(0.5),-0.5,0.5]]
[90,45,45] call Achilles_fnc_vectDirUpFromDirPitchBank;
(end)
*/

params ["_dir", "_pitch", "_bank"];
// Generate leveled vector dir and up
private _vectDir = [cos(_dir), sin(_dir), 0];
private _vectUp = [0,0,1];
// Get the pitch rotation matrix
private _world_to_model = [_vectDir, _vectUp, _vectDir vectorCrossProduct _vectUp];
private _model_to_world = [_world_to_model] call CBA_fnc_matrixTranspose;
private _rotMatrix_pitch = [_model_to_world, [[[cos(_pitch),-sin(_pitch),0],[sin(_pitch),cos(_pitch),0],[0,0,1]], _world_to_model] call CBA_fnc_matrixProduct3D] call CBA_fnc_matrixProduct3D;
// Get the bank rotation matrix
private _model_to_world = [_rotMatrix_pitch, _model_to_world] call CBA_fnc_matrixProduct3D;
private _world_to_model = [_model_to_world] call CBA_fnc_matrixTranspose;
private _rotMatrix_bank = [_model_to_world, [[[1,0,0],[0,cos(_bank),-sin(_bank)],[0,sin(_bank),cos(_bank)]], _world_to_model] call CBA_fnc_matrixProduct3D] call CBA_fnc_matrixProduct3D;
// Rotate vector dir and up
_vectDir = [_rotMatrix_pitch, _vectDir] call CBA_fnc_vectMap3D;
_vectUp = [_rotMatrix_pitch, _vectUp] call CBA_fnc_vectMap3D;
_vectUp = [_rotMatrix_bank, _vectUp] call CBA_fnc_vectMap3D;
// return
[_vectDir, _vectUp]
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// AUTHOR: Kex, CreepPork_LV
// DATE: 22/12/17
// VERSION: 1.1
// DESCRIPTION: Forces the group of the given unit to suppress the given target
// DESCRIPTION: Forces the group of the given unit to suppress the given target
// This function has to be executed in the scheduled environment on the machine the unit is local.
// It seems that the function doesn't work on machines without an interface (e.g. sever or HC)
//
// ARGUMENTS:
// _this select 0: OBJECT - Unit that is injured
Expand Down
Loading