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

Feature: v3 #120

Merged
merged 326 commits into from
Nov 18, 2024
Merged

Feature: v3 #120

merged 326 commits into from
Nov 18, 2024

Conversation

crashkonijn
Copy link
Owner

@crashkonijn crashkonijn commented Nov 29, 2023

Features:

  • Easy class generation
  • Added Capabilities. These are sub-sets of goals, actions and sensors.
  • Renamed GoapSet to AgentType. This communicates it's purpose much better.
  • AgentType exists of a list of capabilities, which combined form all the goals, actions and sensors for the agent.
  • Added multi-sensor support (a single class that can provide multiple values)
  • Added IGoapEvents and IAgentSetEvents
  • Added the IGoapController interface, this now controls how agents are run.
  • Added the concept of IGoapController, this manages the behaviour of how and when agents are resolved. Question: Possibility of override movement logic? #64
    • Added ReactiveController, this will resolve the next best action once the previous action is completed.
    • Added ProactiveController, this will check if the current action still is the base action every x time as well.
    • Added ManualController, this won't update any agent and will immediately resolve the next action.
  • Added IAgentTimers to the agent.
  • Added IActionRunState in favor of the ActionRunState enum. Feature: More flexible options as the ActionRunState #117
    • Added ContinueActionRunState
    • Added ContinueOrResolveActionRunState
    • Added StopActionRunState
    • Added CompletedActionRunState
    • Added WaitActionRunState
    • Added WaitThenCompleteActionRunState
    • Added WaitThenStopActionRunState
    • Added ActionRunState class, which has static getters and methods that mimic the original situation.
  • Improved handling of Local an Global world data.
  • Sync (generate) classes based on config
  • Added ability to add an IActionProperties class on an Action, similar to IActionData. This enables configuring values for an action through code or the editor! Feature: Add possibility to configure actions better #72
  • Added new graph viewer!
    • Now works on agent, capabilities and agent types. Both during and outside of play!
    • Can be zoomed!
    • Can be collapsed into compact mode, providing more overview!
    • Shows connections per condition
    • Shows distance cost
  • Actions can now be disabled by calling agent.DisableAction<TAction>() or agent.EnableAction<TAction>(). This will prevent the resolver from running this action and it's children.
  • Added an IsValid method to actions. By default this will re-check the conditions to make sure they are still true. Will also check that a ITarget is present when RequireTarget is set to true in action config.
  • Action End, Stop and Complete methods are now optional
  • Resolver has been improved!:
    • Heuristics are changed towards the cost of unmet conditions.
    • Cost now includes distance cost (this was in the heuristic).
    • System should now keep track of it's previous position in the graph, instead of it's current position when resolving when no target is provided.
    • Resolver can now handle multiple input goals
  • Split the agent logic into separate projects
  • All namespaces have been simplified, they now match their respective assemblies! Feature: v3 namespaces and organization #129
    • CrashKonijn.Agent.Core: interfaces and enums
    • CrashKonijn.Agent.Runtime: All implementations
    • CrashKonijn.Goap.Core: interfaces and enums
    • CrashKonijn.Goap.Runtime: All implementations
    • CrashKonijn.Goap.Resolver: All resolver logic, not generally used by a user
  • SetGoal has now been replaced with RequestGoal.
  • RequestGoal can now handle multiple goals at the same time!
  • The current running goal and action will only be overwritten if a performable action is found for the requested goal(s)
  • Sensors now have control over how often they are run, using the ISensorTimer interface.

Fixes:

Chores:

  • Restructured projects, introduced CrashKonijn.Goap.Core project.
  • Moved AgentBehaviour run logic into separate class.
  • Increased test coverage

Breaking changes:

  • All interfaces have moved from CrashKonijn.Goap.Interfaces to CrashKonijn.Goap.Core.Interfaces.
  • All enums have moved from CrashKonijn.Goap.Enums to CrashKonijn.Goap.Core.Enums.
  • Removed Action.End in favor of Action.Stop and Action.Complete Feature: Complete on an action #119
  • ActionRunState is now in the CrashKonijn.Goap.Classes.RunStates interface.
  • AgentEvents: renamed OnTargetOutOfRange to TargetNotInRange for clarity.
  • ActionConfig: renamed InRange to StoppingDistance for clarity.
  • AgentMoveState: renamed OutOfRange to NotInRange for clarity.
  • agent.CurrentAction, agent.CurrentActionData and agent.RunState have been moved to agent.ActionState.X
  • OnTargetLost event is added in favor of calling OnTargetChanged with null

Examples:

Generating classes
image

Capability editor
image

Mulit-sensor

 public class AppleSensor : MultiSensorBase
    {
        private AppleCollection apples;
        private TreeBehaviour[] trees;

        public override void Created()
        {
            this.apples = Object.FindObjectOfType<AppleCollection>();
            this.trees = Object.FindObjectsOfType<TreeBehaviour>();
        }

        public override void Update()
        {
            
        }

        public AppleSensor()
        {
            this.AddLocalTargetSensor<ClosestApple>((agent, references) =>
            {
                var closestApple = this.apples.Get().Closest(agent.transform.position);

                if (closestApple is null)
                    return null;
            
                return new TransformTarget(closestApple.transform);
            });
            
            this.AddLocalTargetSensor<ClosestTree>((agent, references) =>
            {
                return new TransformTarget(this.trees.Closest(agent.transform.position).transform);
            });
            
            this.AddLocalWorldSensor<HasApple>((agent, references) =>
            {
                var inventory = references.GetCachedComponent<InventoryBehaviour>();

                if (inventory == null)
                    return false;
                
                return inventory.Apples.Count > 0;
            });
            
            this.AddGlobalWorldSensor<ThereAreApples>(() =>
            {
                return this.apples.Any();
            });
        }
    }

Graph Viewer

image
image
image

@jzapdot
Copy link

jzapdot commented Dec 7, 2023

Hi @crashkonijn , do you have a roadmap or task tracker for all the items in this release (or any notes showing whats done vs whats to do)? I'm happy to help where able on the work intended for this version and to suggest other PRs along with it.

…s-warning

Fix: multi sensor missing keys warning
@crashkonijn crashkonijn marked this pull request as ready for review November 18, 2024 16:25
@crashkonijn crashkonijn merged commit 7456902 into master Nov 18, 2024
9 checks passed
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.

5 participants