-
Notifications
You must be signed in to change notification settings - Fork 148
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
Update AI functions #333
Update AI functions #333
Changes from 5 commits
25dcc95
678bb64
752e186
b4f6277
fd36422
9c823f3
f27cdf3
d876997
5f531b5
3d7f518
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* ---------------------------------------------------------------------------- | ||
Function: CBA_fnc_clearWaypoints | ||
|
||
Description: | ||
A function used to correctly clear all waypoints from a group. | ||
|
||
Parameters: | ||
- Group (Group or Object) | ||
|
||
Example: | ||
(begin example) | ||
[group player] call CBA_fnc_clearWaypoints | ||
(end) | ||
|
||
Returns: | ||
None | ||
|
||
Author: | ||
SilentSpike | ||
|
||
---------------------------------------------------------------------------- */ | ||
#include "script_component.hpp" | ||
params [["_group", grpNull, [grpNull,objNull]]]; | ||
_group = _group call CBA_fnc_getGroup; | ||
|
||
private _waypoints = waypoints _group; | ||
{ | ||
// Waypoint index changes with each deletion, so don't delete _x | ||
deleteWaypoint [_group,0]; | ||
} forEach _waypoints; | ||
|
||
// Create a self-deleting waypoint at the leader position to halt all planned movement (based on old waypoints) | ||
private _wp = _group addWaypoint [getPosATL (leader _group), 0]; | ||
_wp setWaypointStatements ["true", "deleteWaypoint [group this,0]"]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,78 +25,84 @@ Returns: | |
Nil | ||
|
||
Author: | ||
Rommel | ||
Rommel, SilentSpike | ||
|
||
---------------------------------------------------------------------------- */ | ||
|
||
params ["_group", ["_position",[]], ["_radius",50], ["_threshold",2]]; | ||
params ["_group", ["_position",[]], ["_radius",50,[0]], ["_threshold",2,[0]], ["_patrol",true,[true]]]; | ||
|
||
_group = _group call CBA_fnc_getGroup; | ||
if !(local _group) exitWith {}; // Don't create waypoints on each machine | ||
|
||
_position = [_position,_group] select (_position isEqualTo []); | ||
_position = _position call CBA_fnc_getPos; | ||
|
||
_group enableattack false; | ||
[_group] call CBA_fnc_clearWaypoints; | ||
_group enableAttack false; | ||
|
||
private ["_count", "_list", "_list2", "_units", "_i"]; | ||
_statics = [_position, vehicles, _radius, {(_x iskindof "StaticWeapon") && {(_x emptypositions "Gunner" > 0)}}] call CBA_fnc_getnearest; | ||
_buildings = _position nearObjects ["building",_radius]; | ||
_units = units _group; | ||
_count = count _units; | ||
private _statics = _position nearObjects ["StaticWeapon", _radius]; | ||
private _buildings = _position nearObjects ["Building", _radius]; | ||
|
||
// Filter out occupied statics | ||
_statics = _statics select { (_x emptyPositions "Gunner") > 0 }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not compatible with the MacOS/Linux ports, currently at v1.54. Needs workaround like commy2 did recently (the "linux.pbo" addon). (Or use |
||
|
||
// Filter out buildings below the size threshold (and store positions for later use) | ||
_buildings = _buildings select { | ||
private _positions = _x buildingPos -1; | ||
|
||
if (isNil {_x getVariable "CBA_taskDefend_positions"}) then { | ||
_x setVariable ["CBA_taskDefend_positions",_positions]; | ||
}; | ||
|
||
count (_positions) > _threshold | ||
}; | ||
|
||
private _units = units _group; | ||
private _assigned = 0; | ||
{ | ||
if (str(_x buildingpos _threshold) == "[0,0,0]") then {_buildings = _buildings - [_x]}; | ||
} foreach _buildings; | ||
_i = 0; | ||
{ | ||
_count = (count _statics) - 1; | ||
if (random 1 < 0.31 && {_count > -1}) then { | ||
_x assignasgunner (_statics select _count); | ||
_statics resize _count; | ||
[_x] ordergetin true; | ||
_i = _i + 1; | ||
// 31% chance to occupy nearest free static weapon | ||
if ((random 1 < 0.31) && { !(_statics isEqualto []) }) then { | ||
_x assignAsGunner (_statics deleteAt 0); | ||
[_x] orderGetIn true; | ||
|
||
_assigned = _assigned + 1; | ||
} else { | ||
if (random 1 < 0.93 && {count _buildings > 0}) then { | ||
private ["_building","_p","_array"]; | ||
_building = _buildings call BIS_fnc_selectRandom; | ||
_array = _building getvariable "CBA_taskDefend_positions"; | ||
if (isnil "_array") then { | ||
private "_k"; _k = 0; | ||
_building setvariable ["CBA_taskDefend_positions",[]]; | ||
while {str(_building buildingpos _k) != "[0,0,0]"} do { | ||
_building setvariable ["CBA_taskDefend_positions",(_building getvariable "CBA_taskDefend_positions") + [_k]]; | ||
_k = _k + 1; | ||
}; | ||
_array = _building getvariable "CBA_taskDefend_positions"; | ||
}; | ||
if (count _array > 0) then { | ||
_p = (_building getvariable "CBA_taskDefend_positions") call BIS_fnc_selectRandom; | ||
_array = _array - [_p]; | ||
if (count _array == 0) then { | ||
// 93% chance to occupy a random nearby building position | ||
if ((random 1 < 0.93) && { !(_buildings isEqualto []) }) then { | ||
private _building = selectRandom _buildings; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ports compatibiltiy issue here aswell - |
||
private _array = _building getVariable ["CBA_taskDefend_positions",[]]; | ||
|
||
if !(_array isEqualTo []) then { | ||
private _pos = _array deleteAt (floor(random(count _array))); | ||
|
||
// If building positions are all taken remove from possible buildings | ||
if (_array isEqualTo []) then { | ||
_buildings = _buildings - [_building]; | ||
_building setvariable ["CBA_taskDefend_positions",nil]; | ||
_building setVariable ["CBA_taskDefend_positions",nil]; | ||
}; | ||
_building setvariable ["CBA_taskDefend_positions",_array]; | ||
[_x,_building buildingpos _p] spawn { | ||
if (surfaceIsWater (_this select 1)) exitwith {}; | ||
(_this select 0) domove (_this select 1); | ||
_building setVariable ["CBA_taskDefend_positions",_array]; | ||
|
||
// AI manipulation trickey to keep them in position until commanded to move | ||
[_x, _pos] spawn { | ||
params ["_unit","_pos"]; | ||
if (surfaceIsWater _pos) exitwith {}; | ||
|
||
_unit doMove _pos; | ||
sleep 5; | ||
waituntil {unitready (_this select 0)}; | ||
(_this select 0) disableai "move"; | ||
dostop _this; | ||
waituntil {not (unitready (_this select 0))}; | ||
(_this select 0) enableai "move"; | ||
waituntil {unitReady _unit}; | ||
_unit disableAI "move"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a note that this function should definitely be updated to use the new feature added in today's dev branch changelog:
However I have no idea if the dev branch stuff will appear in the next verison of arma, or the one after There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably something for a future PR when we do know in which version it will be available? |
||
doStop _unit; | ||
waituntil {!(unitReady _unit)}; | ||
_unit enableAI "move"; | ||
}; | ||
_i = _i + 1; | ||
|
||
_assigned = _assigned + 1; | ||
}; | ||
}; | ||
}; | ||
} foreach _units; | ||
{ | ||
_x setvariable ["CBA_taskDefend_positions",nil]; | ||
} foreach _buildings; | ||
if (count _this > 4 && {!(_this select 4)}) then {_i = _count}; | ||
if (_i < _count * 0.5) then { | ||
} forEach _units; | ||
|
||
// If half of the group's units aren't assigned then patrol | ||
if (_patrol && {_assigned < (count _units) * 0.5}) then { | ||
[_group, _position, _radius, 5, "sad", "safe", "red", "limited"] call CBA_fnc_taskpatrol; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change in behaviour: the old version does not send the first unit (leader?) into the building, but the new one does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, though I'm going to write it such that the leader will only stay outside when the group has more than 2 units as otherwise it actually makes sense for the leader to enter 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I've noticed that the leader will continue on to the group's next waypoint if he isn't searching the building himself.
Should I change it to make him wait outside until the search is done? Otherwise he could run quite far ahead of the group.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's better than him going on without his team.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately I can't find a reliable & safe way to do this.
I could create a waypoint - which introduces the problem of trying to safely remove the waypoint once it has served its purpose (since the creation of other waypoints could change the index - I think using the waypoint statement combined with
currentWaypoint
could do the trick though).While
doStop
permanently stops the unit as far as I can tell - which can be avoided in future once thedisableAI "PATH"
functionality is in the release version of arma.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, got the waypoint solution working cleanly - it's actually preferable to using AI commands because it also takes care of spare group members too and allows me to put the post-search code into the completion statement instead of running a loop 😄