116 lines
3.3 KiB
C#
116 lines
3.3 KiB
C#
using Godot;
|
|
|
|
namespace Polonium.Agents;
|
|
|
|
/// <summary>
|
|
/// Abstract base class for all agent actions in the system.
|
|
/// Provides the foundation for executable actions that can be performed by agents.
|
|
/// </summary>
|
|
public abstract partial class AgentAction : Node
|
|
{
|
|
/// <summary>
|
|
/// Abstract base class for action parameters.
|
|
/// </summary>
|
|
public abstract class Parameter
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the parameter for this action.
|
|
/// </summary>
|
|
/// <param name="p">The parameter to set.</param>
|
|
public virtual void SetParameter(Parameter p)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Executes the action logic.
|
|
/// </summary>
|
|
public abstract void Execute();
|
|
|
|
/// <summary>
|
|
/// Finishes the action execution and performs cleanup.
|
|
/// </summary>
|
|
public abstract void Finish();
|
|
|
|
/// <summary>
|
|
/// Resets the action to its initial state.
|
|
/// </summary>
|
|
public abstract void Reset();
|
|
|
|
/// <summary>
|
|
/// Abstract base class for agent action templates.
|
|
/// </summary>
|
|
public abstract class Template : PoloniumTemplate<AgentAction>
|
|
{
|
|
/// <summary>
|
|
/// Gets the name of the action.
|
|
/// </summary>
|
|
public abstract string ActionName { get; }
|
|
|
|
/// <summary>
|
|
/// Gets a copy of this template.
|
|
/// </summary>
|
|
public abstract Template Copy { get; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Generic template class for specific agent action types.
|
|
/// </summary>
|
|
/// <typeparam name="TAction">The type of agent action.</typeparam>
|
|
public class Template<TAction> : Template
|
|
where TAction : AgentAction
|
|
{
|
|
/// <summary>
|
|
/// Gets the name of the action from the registry.
|
|
/// </summary>
|
|
public override string ActionName => PoloniumRegistry.Action<TAction>.Name;
|
|
|
|
/// <summary>
|
|
/// Gets an instance of the action from the registry, resets it, and applies modifications.
|
|
/// </summary>
|
|
public override TAction Get
|
|
{
|
|
get
|
|
{
|
|
TAction res = PoloniumRegistry.Asset<TAction>.Get();
|
|
res.Reset();
|
|
Modify(res);
|
|
return res;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Modifies the given agent action object if it's of the correct type.
|
|
/// </summary>
|
|
/// <param name="obj">The agent action object to modify.</param>
|
|
public override void Modify(AgentAction obj)
|
|
{
|
|
if (obj is not TAction act)
|
|
return;
|
|
Modify(act);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the action instance to the registry for reuse.
|
|
/// </summary>
|
|
/// <param name="res">The action instance to return.</param>
|
|
public void Return(TAction res) => PoloniumRegistry.Asset<TAction>.Return(res);
|
|
|
|
/// <summary>
|
|
/// Gets a copy of this template.
|
|
/// </summary>
|
|
public override Template Copy => new Template<TAction> { };
|
|
|
|
/// <summary>
|
|
/// Virtual method to modify the action instance. Override to customize behavior.
|
|
/// </summary>
|
|
/// <param name="action">The action instance to modify.</param>
|
|
public virtual void Modify(TAction action)
|
|
{
|
|
}
|
|
}
|
|
}
|
|
|
|
|