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

Update AI functions #333

Merged
merged 10 commits into from
May 21, 2016
Merged

Update AI functions #333

merged 10 commits into from
May 21, 2016

Conversation

kymckay
Copy link
Contributor

@kymckay kymckay commented May 19, 2016

In creating some zeus AI modules for ACE I noticed that the CBA AI functions didn't behave exactly as expected and made this PR to change that.

The changes can be found in the commit descriptions, but to summarise:

  • Task functions will now clear all previous waypoints before assigning the task's waypoints (a new function fnc_clearWaypoints was introduced to correctly clear all existing waypoints without issue).
  • The fnc_searchNearby function can now be called and doesn't have to be spawned.
  • The fnc_taskPatrol function now completes the patrol by placing the cycle waypoint back at the start instead of randomly.
  • Functions fnc_taskDefend and fnc_searchNearby were rewritten to be both more readable and optimized.
  • Function fnc_taskDefend now handles building positions slightly differently such that if multiple groups are tasked to defend overlapping areas the positions are shared between all of the units, not just the units within each group. Meaning that multiple units will not not occupy the same position unless all positions are occupied already.
  • Function fnc_searchNearby now handles cases where units are killed while searching the building better. The group will collectively try to search every position in the building, whereas previously some positions could be overlooked because they were assigned to a dead unit (since the units array wasn't updating correctly). Similarly the function will handle cases where the leader is killed better, returning units to their new leader after the search is complete.

Unfortunately clearing all waypoints from AI is not as simple as deleting them all with `deleteWaypoint`.

You have to kill their pre-planned movement (based on old waypoints) by having them complete at least one waypoint.

One solution is to move all of their old waypoints to their position before deleting them, however if waypoint statements are being used this could have adverse effects.

So this function creates a fresh waypoint for the purpose of killing their movement. It is also self-deleting (through its completion statement) to avoid any possible issues with timing.
- Retain open building positions to make groups defending overlapping areas respect one another.
- Use new A3 scripting commands to optimise and enhance the function.
- Makes the function a lot more readable with comments and more spacing.
- Capitalize commands and function names appropriately.
- Any existing waypoints are cleared before defending begins.
- The `cycle` waypoint is placed back at the start of the loop instead of randomly within the radius.
- Any existing waypoints are cleared before the patrol loop is created.
- `_this` is now correctly private.
@kymckay kymckay mentioned this pull request May 19, 2016
7 tasks
- Any existing waypoints are now cleared before the searching begins.
- The recursive argument check is now more explicit.
- Now callable (by including the spawn within the function).
- Accounts for units being killed while searching and dispatches all available units to search simultaneously.
- Doesn't permanently change behaviour of the group if the function aborts due to building distance.
- Optimized with new A3 commands and made more readable with comments and spacing.
waituntil {not (unitready (_this select 0))};
(_this select 0) enableai "move";
waituntil {unitReady _unit};
_unit disableAI "move";
Copy link
Contributor Author

@kymckay kymckay May 20, 2016

Choose a reason for hiding this comment

The 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:

Ability to enableAI / disableAI "PATH", which stops the AI’s movement but not the target alignment

However I have no idea if the dev branch stuff will appear in the next verison of arma, or the one after

Copy link
Contributor

Choose a reason for hiding this comment

The 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?

@kymckay
Copy link
Contributor Author

kymckay commented May 21, 2016

I hadn't realize CBA is now supporting two versions of arma, well that sucks 😆

Will amend all of the above!

Commented out the part that isn't easily regex replaced so that it can be uncommented in future.
In actuality this is something of a compromise.

Having the leader enter the building was not an intentional change I made. However it makes sense to do things that way when the group is small and so for any group with 2 or less units (includes the leader) the leader will now search the building too.
Accounts for cases where the leader enters the building.
- The group leader (and any spare units) will now wait at his current position for the search to be complete before moving on.
- Waiting between orders instead of between rounds of orders should prevent congestion and decrease time gaps in the search.
- Embedding the post-search code into the waypoint condition and completion removes the need to `waitUntil` while also providing built in group unit list `thisList`.
If a waypoint was created at index 0 before the group complete the waypoint used to reset their path, then the wrong waypoint would be deleted upon its completion.
@Killswitch00 Killswitch00 merged commit 3d8ed8b into CBATeam:master May 21, 2016
@commy2 commy2 added this to the 2.4.0 milestone May 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants