Class walle::PathAgent
#include <PathAgent.hpp>
Inherits the following classes: AgentBase
Public Functions
Type | Name |
---|---|
cse491::GridPosition | CalcNextPos () const |
void | DecrementIndex () |
int | GetIndex () const Get the index. |
cse491::GridPosition | GetNextPosition () override |
std::vector< cse491::GridPosition > const & | GetPath () const Get the Path. |
void | IncrementIndex () |
bool | Initialize () override |
PathAgent () = delete |
|
PathAgent (size_t id, std::string const & name) |
|
PathAgent (size_t id, std::string const & name, std::vector< cse491::GridPosition > offsets) |
|
PathAgent (size_t id, std::string const & name, std::string_view commands) |
|
PathAgent & | ResetIndex () Reset the index to 0. |
size_t | SelectAction (cse491::WorldGrid const &, cse491::type_options_t const &, cse491::item_map_t const &, cse491::agent_map_t const &) override |
PathAgent & | SetPath (std::vector< cse491::GridPosition > offsets, size_t start_index=0) |
PathAgent & | SetPath (std::string_view commands, size_t start_index=0) |
virtual cse491::GridPosition | UpdateAndGetNextPos (bool increment) |
~PathAgent () override |
Protected Attributes
Type | Name |
---|---|
int | index_ = = 0 Current index into offsets_. |
std::vector< cse491::GridPosition > | offsets_ |
Detailed Description
Agent that has a user-defined custom movement pattern Passed a sequence of to be sequentially applied as the agent is updated
Public Functions Documentation
function CalcNextPos
cse491::GridPosition walle::PathAgent::CalcNextPos () const
Retrieves the position of the agent after applying the current offset
Returns:
next position of the agent
function DecrementIndex
void walle::PathAgent::DecrementIndex ()
Decrements the index into the offsets sequence
function GetIndex
Get the index.
int walle::PathAgent::GetIndex () const
Returns:
int index
Retrieves which step the agent is on
Returns:
the current index into the offsets
function GetNextPosition
cse491::GridPosition walle::PathAgent::GetNextPosition () override
Overrides AgentBase GetNextPosition to retrieve the calculated next position
Returns:
next position to move the path agent in
function GetPath
Get the Path.
std::vector< cse491::GridPosition > const & walle::PathAgent::GetPath () const
Returns:
vector of GridPositions
Returns an immutable reference to this agent's current path
Returns:
sequence of offsets
function IncrementIndex
void walle::PathAgent::IncrementIndex ()
Increments the index into the offsets sequence
function Initialize
bool walle::PathAgent::Initialize () override
Checks that the agent is able to move arbitrarily Verifies that it can currently index into a valid offset
Returns:
true if so; false otherwise
function PathAgent [1/4]
walle::PathAgent::PathAgent () = delete
function PathAgent [2/4]
walle::PathAgent::PathAgent (
size_t id,
std::string const & name
)
Constructor (agent default)
Parameters:
id
unique agent idname
name of path agent
Note:
When this constructor is called, the agent must still be assigned a path before a call to Initialize
function PathAgent [3/4]
walle::PathAgent::PathAgent (
size_t id,
std::string const & name,
std::vector< cse491::GridPosition > offsets
)
Constructor (vector)
Parameters:
id
unique agent idname
name of path agentoffsets
collection of offsets to move the agent
Attention:
The sequence of offsets must not be empty
function PathAgent [4/4]
walle::PathAgent::PathAgent (
size_t id,
std::string const & name,
std::string_view commands
)
Constructor (string)
Parameters:
id
unique agent idname
name of path agentcommands
sequence of commands to be interpreted as offsets
Attention:
The sequence of offsets must not be empty
function ResetIndex
Reset the index to 0.
inline PathAgent & walle::PathAgent::ResetIndex ()
Returns:
self
function SelectAction
size_t walle::PathAgent::SelectAction (
cse491::WorldGrid const &,
cse491::type_options_t const &,
cse491::item_map_t const &,
cse491::agent_map_t const &
) override
Tells world to
Returns:
whether the update succeeded
function SetPath [1/2]
PathAgent & walle::PathAgent::SetPath (
std::vector< cse491::GridPosition > offsets,
size_t start_index=0
)
Assigns the offsets_member to a new series of offsets
Parameters:
offsets
collection of grid positions used as the new offsetsstart_index
which offset to start indexing into (beginning by default)
Returns:
self
Attention:
throws an std::invalid_argument
when an invalid start index is provided
function SetPath [2/2]
PathAgent & walle::PathAgent::SetPath (
std::string_view commands,
size_t start_index=0
)
Assigns the offsets_ member to a new series of offsets, taking a command string
Parameters:
commands
formatted string of commands used as offsetsstart_index
which command to begin indexing into (first command by default)
Returns:
self
Attention:
throws an std::invalid_argument
when mis-formatted commands an invalid index is provided
function UpdateAndGetNextPos
virtual cse491::GridPosition walle::PathAgent::UpdateAndGetNextPos (
bool increment
)
Convenience method Applies the current offset to calculate the next position and then adjusts the index
Parameters:
increment
decides whether to move in the forward or backward direction to allow for complex pathing
Returns:
function ~PathAgent
walle::PathAgent::~PathAgent () override
Protected Attributes Documentation
variable index_
int index_;
variable offsets_
std::vector<cse491::GridPosition> offsets_;
Collection of ways to offset the Agent's position
Attention:
This is a not a sequence of direct coordinates on the WorldGrid, but a series of offsets
The documentation for this class was generated from the following file source/Agents/PathAgent.hpp