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