-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add keybinds for controlling AI near players - Watch Cursor: Makes all selected units watch the cursor location. Pressing this command with the cursor over a selected unit will cancel the watch target - Watch Curator Camera: Makes all selected units watch the curator camera position, useful when camera is near players or making AI look up - Move To Cursor: Makes all selected units move to the cursor location. Units will return to formation and waypoint afterward - Toggle AI PATH: Makes all selected units start or stop moving. Does not affect aiming or shooting - Force Fire: Makes selected units fire their current or their vehicle turret's weapon Keybinds are UNBOUND by default Co-authored-by: mharis001 <34453221+mharis001@users.noreply.github.com> Co-authored-by: Neil Evers <neil.evers.1995@gmail.com> Co-authored-by: mharis001 <mhariszakar@gmail.com>
- Loading branch information
1 parent
4dc8323
commit 1679273
Showing
13 changed files
with
674 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include "script_component.hpp" | ||
/* | ||
* Author: mharis001, Ampersand | ||
* Checks if the given unit or vehicle can fire its current weapon. | ||
* | ||
* Arguments: | ||
* 0: Unit or Vehicle <OBJECT> | ||
* 1: Ignore Ammo <BOOL> (default: false) | ||
* 2: Ignore Reload <BOOL> (default: false) | ||
* | ||
* Return Value: | ||
* Can Fire <BOOL> | ||
* | ||
* Example: | ||
* [_unit] call zen_common_fnc_canFire | ||
* | ||
* Public: No | ||
*/ | ||
|
||
params [["_unit", objNull, [objNull]], ["_ignoreAmmo", false, [false]], ["_ignoreReload", false, [false]]]; | ||
|
||
private _unit = _unit call FUNC(getEffectiveGunner); | ||
|
||
alive _unit | ||
&& {!isPlayer _unit} | ||
&& {lifeState _unit in ["HEALTHY", "INJURED"]} | ||
&& { | ||
private _vehicle = vehicle _unit; | ||
|
||
if (_vehicle == _unit || {_unit call FUNC(isUnitFFV)}) then { | ||
currentWeapon _unit != "" | ||
&& {_ignoreAmmo || {_unit ammo currentMuzzle _unit > 0}} | ||
&& {_ignoreReload || {!(_unit call FUNC(isReloading))}} | ||
} else { | ||
private _turretPath = _vehicle unitTurret _unit; | ||
weaponState [_vehicle, _turretPath] params ["_weapon", "", "", "", "_ammoCount"]; | ||
|
||
_weapon != "" | ||
&& {!("fake" in toLower _weapon)} | ||
&& {_ignoreAmmo || {_ammoCount > 0} || {_weapon isKindOf ["CarHorn", configFile >> "CfgWeapons"]}} | ||
&& {_ignoreReload || {!([_vehicle, _turretPath] call FUNC(isReloading))}} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
#include "script_component.hpp" | ||
/* | ||
* Author: Ampersand, mharis001 | ||
* Draws a hint that contains icon and line elements in 2D (Zeus display map) | ||
* and 3D (in world) for the given duration. | ||
* | ||
* Will overwrite an existing hint when called using the same ID. Position | ||
* arguments can be given as OBJECTs, in which case the hint elements will | ||
* follow objects as they move and will be hidden if the object is deleted. | ||
* | ||
* The visual properties for "ICON" elements are: | ||
* 0: Position <ARRAY|OBJECT> | ||
* 1: Icon Texture <STRING> | ||
* 2: Color (RGBA) <ARRAY> (default: [1, 1, 1, 1]) | ||
* 3: Scale <NUMBER> (default: 1) | ||
* 4: Angle <NUMBER> (default: 0) | ||
* 5: Text <STRING> (default: "") | ||
* 6: Shadow <NUMBER|BOOL> (default: 0) | ||
* 7: Text Size <NUMBER> (default: 0.05) | ||
* 8: Font <STRING> (default: "RobotoCondensed") | ||
* 9: Align <STRING> (default: "center") | ||
* | ||
* The visual properties for "LINE" elements are: | ||
* 0: Start Position <ARRAY|OBJECT> | ||
* 1: End Position <ARRAY|OBJECT> | ||
* 2: Color (RGBA) <ARRAY> (default: [1, 1, 1, 1]) | ||
* | ||
* Arguments: | ||
* 0: Elements <ARRAY> | ||
* 0: Type <STRING> | ||
* - either "ICON" or "LINE". | ||
* 1: Visual Properties <ARRAY> | ||
* - depends on element type (see above for details). | ||
* 1: Duration (in seconds) <NUMBER> | ||
* 2: ID <STRING|OBJECT> (default: "") | ||
* - an ID is generated when an empty string is given. | ||
* - in the case of an OBJECT, the hash value is used. | ||
* | ||
* Return Value: | ||
* ID <STRING> | ||
* | ||
* Example: | ||
* [["ICON", [_unit, _texture]], 3] call zen_common_fnc_drawHint | ||
* | ||
* Public: No | ||
*/ | ||
|
||
#define MAP_ICON_SIZE 24 | ||
|
||
params [ | ||
["_elements", [], [[]]], | ||
["_duration", 0, [0]], | ||
["_id", "", ["", objNull]] | ||
]; | ||
|
||
private _ctrlMap = findDisplay IDD_RSCDISPLAYCURATOR displayCtrl IDC_RSCDISPLAYCURATOR_MAINMAP; | ||
|
||
// Map of hint IDs and their corresponding draw (2D and 3D) event handler IDs | ||
if (isNil QGVAR(drawHintMap)) then { | ||
GVAR(drawHintMap) = createHashMap; | ||
}; | ||
|
||
// Use an object's hash value as its hint ID | ||
if (_id isEqualType objNull) then { | ||
_id = hashValue _id; | ||
}; | ||
|
||
// Generate a hint ID if one is not given | ||
if (_id isEqualTo "") then { | ||
if (isNil QGVAR(drawHintCounter)) then { | ||
GVAR(drawHintCounter) = -1; | ||
}; | ||
|
||
GVAR(drawHintCounter) = GVAR(drawHintCounter) + 1; | ||
|
||
_id = [CBA_clientID, GVAR(drawHintCounter)] joinString ":"; | ||
}; | ||
|
||
// Remove an existing hint with the same ID | ||
if (_id in GVAR(drawHintMap)) then { | ||
GVAR(drawHintMap) deleteAt _id params ["_id2D", "_id3D"]; | ||
|
||
_ctrlMap ctrlRemoveEventHandler ["Draw", _id2D]; | ||
removeMissionEventHandler ["Draw3D", _id3D]; | ||
}; | ||
|
||
// Validate the given hint elements and separate them by type | ||
private _icons = []; | ||
private _lines = []; | ||
|
||
{ | ||
_x params [["_type", "", [""]], ["_args", [], [[]]]]; | ||
|
||
switch (_type) do { | ||
case "ICON": { | ||
_args params [ | ||
["_position", [0, 0, 0], [[], objNull], 3], | ||
["_icon", "", [""]], | ||
["_color", [1, 1, 1, 1], [[]], 4], | ||
["_scale", 1, [0]], | ||
["_angle", 0, [0]], | ||
["_text", "", [""]], | ||
["_shadow", 0, [0, false]], | ||
["_textSize", 0.05, [0]], | ||
["_font", "RobotoCondensed", [""]], | ||
["_align", "center", [""]] | ||
]; | ||
|
||
_icons pushBack [_position, _icon, _color, _scale, _angle, _text, _shadow, _textSize, _font, _align]; | ||
}; | ||
case "LINE": { | ||
_args params [ | ||
["_begPos", [0, 0, 0], [[], objNull], 3], | ||
["_endPos", [0, 0, 0], [[], objNull], 3], | ||
["_color", [1, 1, 1, 1], [[]], 4] | ||
]; | ||
|
||
_lines pushBack [_begPos, _endPos, _color]; | ||
}; | ||
default { | ||
ERROR_1("Invalid hint element type - %1.",_type); | ||
}; | ||
}; | ||
} forEach _elements; | ||
|
||
// Add event handlers to draw the hint elements | ||
private _fnc_draw2D = { | ||
params ["_ctrlMap"]; | ||
_thisArgs params ["_icons", "_lines"]; | ||
|
||
{ | ||
_x params ["_position", "_icon", "_color", "_scale", "_angle", "_text", "_shadow", "_textSize", "_font", "_align"]; | ||
|
||
if (_position isEqualTo objNull) then {continue}; | ||
|
||
_ctrlMap drawIcon [_icon, _color, _position, _scale * MAP_ICON_SIZE, _scale * MAP_ICON_SIZE, _angle, _text, _shadow, _textSize, _font, _align]; | ||
} forEach _icons; | ||
|
||
{ | ||
_x params ["_begPos", "_endPos", "_color"]; | ||
|
||
if (objNull in [_begPos, _endPos]) then {continue}; | ||
|
||
_ctrlMap drawLine [_begPos, _endPos, _color]; | ||
} forEach _lines; | ||
}; | ||
|
||
private _fnc_draw3D = { | ||
_thisArgs params ["_icons", "_lines", "_endTime", "_id"]; | ||
|
||
// Exit if the Zeus display is closed or hint duration is complete | ||
if (isNull curatorCamera || {CBA_missionTime >= _endTime}) exitWith { | ||
GVAR(drawHintMap) deleteAt _id params ["_id2D", "_id3D"]; | ||
|
||
private _ctrlMap = findDisplay IDD_RSCDISPLAYCURATOR displayCtrl IDC_RSCDISPLAYCURATOR_MAINMAP; | ||
_ctrlMap ctrlRemoveEventHandler ["Draw", _id2D]; | ||
removeMissionEventHandler ["Draw3D", _id3D]; | ||
}; | ||
|
||
// No 3D drawing needed if the map is visible | ||
if (visibleMap) exitWith {}; | ||
|
||
{ | ||
_x params ["_position", "_icon", "_color", "_scale", "_angle", "_text", "_shadow", "_textSize", "_font", "_align"]; | ||
|
||
if (_position isEqualTo objNull) then {continue}; | ||
|
||
if (_position isEqualType objNull) then { | ||
_position = unitAimPositionVisual _position; | ||
}; | ||
|
||
drawIcon3D [_icon, _color, _position, _scale, _scale, _angle, _text, _shadow, _textSize, _font, _align]; | ||
} forEach _icons; | ||
|
||
{ | ||
_x params ["_begPos", "_endPos", "_color"]; | ||
|
||
if (objNull in [_begPos, _endPos]) then {continue}; | ||
|
||
if (_begPos isEqualType objNull) then { | ||
_begPos = unitAimPositionVisual _begPos; | ||
}; | ||
|
||
if (_endPos isEqualType objNull) then { | ||
_endPos = unitAimPositionVisual _endPos; | ||
}; | ||
|
||
drawLine3D [_begPos, _endPos, _color]; | ||
} forEach _lines; | ||
}; | ||
|
||
private _args = [_icons, _lines, CBA_missionTime + _duration, _id]; | ||
private _id2D = [_ctrlMap, "Draw", _fnc_draw2D, _args] call CBA_fnc_addBISEventHandler; | ||
private _id3D = [missionNamespace, "Draw3D", _fnc_draw3D, _args] call CBA_fnc_addBISEventHandler; | ||
GVAR(drawHintMap) set [_id, [_id2D, _id3D]]; | ||
|
||
// Return the hint ID (in case a generated one was used) | ||
_id |
Oops, something went wrong.