Skip to content

Commit

Permalink
Add spawn destroyer module (#335)
Browse files Browse the repository at this point in the history
* Add spawn destroyer module

* Wait for the preplace mode to end in scheduled env

* Replace dialog with preplace mode and draw lines

* Fix arrow

* Added USS Liberty icon

* Add comments for the drawings

* Set correct bounding box values

* Adds drawArrow3D and drawRectangle3D
  • Loading branch information
Kexanone authored Aug 1, 2018
1 parent f55a07e commit aad72b7
Show file tree
Hide file tree
Showing 14 changed files with 194 additions and 11 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class CfgFunctions
class getVirtualArsenal;
class getWeaponsMuzzlesMagazines;
class forceWeaponFire;
class drawArrow3D;
class drawRectangle3D;
};

class selectUnit
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Author: Kex
Description:
Draws an arrow on the local machine
Intended to be used within the code of an onEachFrame event handler
Parameters:
ARRAY - The base position of the arrow
ARRAY - The direction vector
ARRAY - The up vector
SCALAR - (Default: DEFAULT_BASE_LENGTH) of the base
SCALAR - (Default: DEFAULT_ARROW_LENGTH) Length of the arrow
SCALAR - (Default: DEFAULT_ARROW_WIDTH) Width of the arrow
ARRAY - (Default: DEFAULT_LINE_RGBA) The color of the lines based on RGBA
Returns:
Nothing
*/

#define DEFAULT_BASE_LENGTH 30
#define DEFAULT_ARROW_LENGTH 10
#define DEFAULT_ARROW_WIDTH 20
#define DEFAULT_LINE_RGBA [1,1,0,1]

params
[
"_basePos",
"_vecDir",
"_vecUp",
["_baseLength", DEFAULT_BASE_LENGTH, [0]],
["_arrowLength", DEFAULT_ARROW_LENGTH, [0]],
["_arrowWidth", DEFAULT_ARROW_WIDTH, [0]],
["_rgba", DEFAULT_LINE_RGBA, [[]], 4]
];

private _halfArrowWidth = _arrowWidth/2;
private _baseMinusArrowLength = _baseLength - _arrowLength;
// correct order for a right-handed coordinate system, where _vecDir is x, _vecPerp is y and _vecUp is z
private _vecPerp = _vecUp vectorCrossProduct _vecDir;
// draw projection of the bounding box on the model XY plane
drawLine3D [_basePos, _basePos vectorAdd (_vecDir vectorMultiply _baseLength), _rgba];
drawLine3D [_basePos vectorAdd (_vecDir vectorMultiply _baseLength), _basePos vectorAdd (_vecDir vectorMultiply _baseMinusArrowLength) vectorAdd (_vecPerp vectorMultiply _halfArrowWidth), _rgba];
drawLine3D [_basePos vectorAdd (_vecDir vectorMultiply _baseLength), _basePos vectorAdd (_vecDir vectorMultiply _baseMinusArrowLength) vectorAdd (_vecPerp vectorMultiply -_halfArrowWidth), _rgba];
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Author: Kex
Description:
Draws a rectangle on the local machine
Intended to be used within the code of an onEachFrame event handler
Parameters:
ARRAY - The center position of the rectangle
ARRAY - The direction vector
ARRAY - The up vector
SCALAR - The length of the rectangle in vector dir direction
SCALAR - The length of the rectangle in the perpendicular direction
ARRAY - (Default: DEFAULT_LINE_RGBA) The color of the lines based on RGBA
Returns:
Nothing
*/

#define DEFAULT_LINE_RGBA [1,1,0,1]

params
[
"_centerPos",
"_vecDir",
"_vecUp",
"_len_x",
"_len_y",
["_rgba", DEFAULT_LINE_RGBA, [[]], 4]
];

private _half_len_x = _len_x/2;
private _half_len_y = _len_y/2;
// correct order for a right-handed coordinate system, where _vecDir is x, _vecPerp is y and _vecUp is z
private _vecPerp = _vecUp vectorCrossProduct _vecDir;
// draw projection of the bounding box on the model XY plane
drawLine3D [_centerPos vectorAdd (_vecDir vectorMultiply _half_len_x) vectorAdd (_vecPerp vectorMultiply _half_len_y), _centerPos vectorAdd (_vecDir vectorMultiply _half_len_x) vectorAdd (_vecPerp vectorMultiply -_half_len_y), _rgba];
drawLine3D [_centerPos vectorAdd (_vecDir vectorMultiply -_half_len_x) vectorAdd (_vecPerp vectorMultiply _half_len_y), _centerPos vectorAdd (_vecDir vectorMultiply -_half_len_x) vectorAdd (_vecPerp vectorMultiply -_half_len_y), _rgba];
drawLine3D [_centerPos vectorAdd (_vecDir vectorMultiply _half_len_x) vectorAdd (_vecPerp vectorMultiply _half_len_y), _centerPos vectorAdd (_vecDir vectorMultiply -_half_len_x) vectorAdd (_vecPerp vectorMultiply _half_len_y), _rgba];
drawLine3D [_centerPos vectorAdd (_vecDir vectorMultiply _half_len_x) vectorAdd (_vecPerp vectorMultiply -_half_len_y), _centerPos vectorAdd (_vecDir vectorMultiply -_half_len_x) vectorAdd (_vecPerp vectorMultiply -_half_len_y), _rgba];
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// AUTHOR: Kex
// DATE: 6/11/17
// VERSION: 3.0
// DESCRIPTION: Define position for object in advance; MUST BE EXECUTED IN UNSCHEDULED ENVIRONMENT!
// DESCRIPTION: Define position for object in advance. If suspension is allowed, this script will wait till completion
//
// ARGUMENTS:
// _this select 0: OBJECT / GROUP - Object or group to be placed
Expand All @@ -26,7 +26,7 @@ if (count (missionNamespace getVariable ["Achilles_var_preplaceModeObjects",[]])
_objects_list = [[_entity], units _entity] select (_entity isEqualType grpNull);
missionNamespace setVariable ["Achilles_var_preplaceModeObjects", _objects_list];

[_objects_list] spawn
private _scriptHandle = [_objects_list] spawn
{
params ["_objects_list"];
{
Expand Down Expand Up @@ -102,3 +102,9 @@ missionNamespace setVariable ["Achilles_var_preplaceModeObjects", _objects_list]
} forEach _objects_list;
missionNamespace setVariable ["Achilles_var_preplaceModeObjects", []];
};

// if we can suspend wait till completion
if (canSuspend) then
{
waitUntil {sleep 0.1; scriptDone _scriptHandle};
};
3 changes: 3 additions & 0 deletions @AresModAchillesExpansion/addons/language_f/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1606,6 +1606,9 @@
<Chinese>美國海軍自由號</Chinese>
<Chinesesimp>美国海军自由号</Chinesesimp>
</Key>
<Key ID="STR_AMAE_USS_LIBERTY">
<Original>USS Liberty</Original>
</Key>
<Key ID="STR_AMAE_SUBMARINE">
<English>Submarine</English>
<Original>Submarine</Original>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Achilles_Spawn_Function_Base
class SpawnEffect;
class SpawnAdvancedCompositions;
class SpawnCarrier;
class SpawnDestroyer;
class SpawnExplosives;
class SpawnEmptyObject;
};
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ class Achilles_Module_Spawn_Carrier : Achilles_Spawn_Module_Base
portrait = "\achilles\data_f_achilles\icons\icon_freedom.paa";
};

class Achilles_Module_Spawn_Destroyer : Achilles_Spawn_Module_Base
{
scopeCurator = 2;
displayName = "$STR_AMAE_USS_LIBERTY";
function = "Achilles_fnc_SpawnDestroyer";
icon = "\achilles\data_f_achilles\icons\icon_liberty.paa";
portrait = "\achilles\data_f_achilles\icons\icon_liberty.paa";
};

class Achilles_Module_Spawn_Explosives : Achilles_Spawn_Module_Base
{
scopeCurator = 2;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@
#include "\achilles\modules_f_ares\module_header.hpp"

private _dialogResult =
#define BOUNDING_BOX_LENGTH 387.71
#define BOUNDING_BOX_WIDTH 100.8262

// draw the location for the preplace mode
[
localize "STR_AMAE_USS_FREEDOM",
[
[localize "STR_AMAE_DIRECTION", ["N","NE","E","SE","S","SW","W","NW"]]
]
] call Ares_fnc_ShowChooseDialog;
"Achilles_id_drawBoatLocation",
"onEachFrame",
{
params ["_logic"];
// model position shifted by +5 m in Z direction in order to prevent intersections with the water surface
private _pos = ASLToAGL getPosASL _logic vectorAdd [0,0,5];
// get basis vectors for the model XY plane
private _vecDir = vectorDir _logic;
_vecDir set [2, 0];
_vecDir = vectorNormalized _vecDir;
// draw projection of the bounding box on the model XY plane
[_pos, _vecDir, [0,0,1], BOUNDING_BOX_LENGTH, BOUNDING_BOX_WIDTH] call Achilles_fnc_drawRectangle3D;
// draw an arrow for the heading on the model XY plane
[_pos, _vecDir vectorMultiply -1, [0,0,1]] call Achilles_fnc_drawArrow3D;
},
[_logic]
] call BIS_fnc_addStackedEventHandler;

// start preplace mode
[_logic] call Achilles_fnc_PreplaceMode;

// delete the drawings
["Achilles_id_drawBoatLocation", "onEachFrame"] call BIS_fnc_removeStackedEventHandler;

if (_dialogResult isEqualTo []) exitWith {};
private _dir = 180 + (_dialogResult select 0) * 45;
if (isNull _logic) exitWith {};

[[getPosATL _logic, _dir],
// spawn the acual boat
[[getPosATL _logic, getDir _logic],
{
params ["_posATL", "_dir"];
private _carrier = createVehicle ["Land_Carrier_01_base_F",[-300,-300,0],[],0,"CAN_COLLIDE"];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "\achilles\modules_f_ares\module_header.hpp"

#define BOUNDING_BOX_LENGTH 222.22
#define BOUNDING_BOX_WIDTH 44.4438

// draw the location for the preplace mode
[
"Achilles_id_drawBoatLocation",
"onEachFrame",
{
params ["_logic"];
// model position shifted by +5 m in Z direction in order to prevent intersections with the water surface
private _pos = ASLToAGL getPosASL _logic vectorAdd [0,0,5];
// get basis vectors for the model XY plane
private _vecDir = vectorDir _logic;
_vecDir set [2, 0];
_vecDir = vectorNormalized _vecDir;
// draw projection of the bounding box on the model XY plane
[_pos, _vecDir, [0,0,1], BOUNDING_BOX_LENGTH, BOUNDING_BOX_WIDTH] call Achilles_fnc_drawRectangle3D;
// draw an arrow for the heading on the model XY plane
[_pos, _vecDir vectorMultiply -1, [0,0,1]] call Achilles_fnc_drawArrow3D;
},
[_logic]
] call BIS_fnc_addStackedEventHandler;

// start preplace mode
[_logic] call Achilles_fnc_PreplaceMode;

// delete the drawings
["Achilles_id_drawBoatLocation", "onEachFrame"] call BIS_fnc_removeStackedEventHandler;

if (isNull _logic) exitWith {};

// spawn the acual boat
[[getPosATL _logic, getDir _logic],
{
params ["_posATL", "_dir"];
private _destroyer = createVehicle ["Land_Destroyer_01_base_F",[-300,-300,0],[],0,"CAN_COLLIDE"];
_destroyer setPosATL _posATL;
_destroyer setVectorDirAndUp [[sin _dir, cos _dir, 0], [0,0,1]];
[_destroyer] remoteExecCall ["BIS_fnc_Destroyer01Init", 0, _destroyer];
{_x addCuratorEditableObjects [[_destroyer], false]} forEach allCurators;
// delete old carrier parts
{deleteVehicle _x} forEach (nearestObjects [[-300,-300,0], ["Land_Destroyer_01_Boat_Rack_01_Base_F","Land_Destroyer_01_hull_base_F","ShipFlag_US_F"], 300, true]);
}, 2] call Achilles_fnc_spawn;

#include "\achilles\modules_f_ares\module_footer.hpp"
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class CfgPatches
"Achilles_Module_Change_Side_Relations",
"Achilles_Module_Spawn_Explosives",
"Achilles_Module_Spawn_Carrier",
"Achilles_Module_Spawn_Destroyer",
"Achilles_Module_Spawn_Advanced_Composition",
"Achilles_Module_Zeus_SwitchUnit",
"Achilles_Module_Zeus_AssignZeus",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,11 @@ switch (true) do
deleteVehicle (_x param [0,objNull]);
} foreach _carrierPartsArray;
};
case (_handled_object isKindOf "Land_Destroyer_01_base_F"):
{
private _destroyerPartsArray = _handled_object getVariable ["bis_carrierParts", []];
{
deleteVehicle (_x param [0,objNull]);
} foreach _destroyerPartsArray;
};
};
2 changes: 2 additions & 0 deletions @AresModAchillesExpansion/credits.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ All of these icons are licensed under Creative Commons Attribution license.
- https://thenounproject.com/icon/1061230/
* USS Freedom module icon (by Salaidinovich)
- https://thenounproject.com/icon/1201287/
* USS Liberty module icon (by Robert A. Di Ieso)
- https://thenounproject.com/term/ship/659581

## Translations
* French
Expand Down
Binary file added Pictures/Icons/icon_liberty.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit aad72b7

Please sign in to comment.