Skip to content

Class cse491::ItemBase

ClassList > cse491 > ItemBase

Inherits the following classes: cse491::Entity

Public Functions

Type Name
virtual void Deserialize_impl (std::istream & is) override
Deserialize item-specific values and call Entity 's Deserialize_impl.
size_t GetOwnerID () const
virtual std::string GetTypeName_impl () override const
Override to allow access the derived name for this type.
virtual bool IsItem () override const
Is Entity an item?
bool IsOnGrid () const
bool IsOnGrid (size_t grid_id) const
bool IsOwned () const
bool IsOwnedBy (size_t entity_id) const
bool IsOwnedByAgent () const
bool IsOwnedByAgent (size_t agent_id) const
bool IsOwnedByItem () const
bool IsOwnedByItem (size_t item_id) const
ItemBase (size_t id, const std::string & name)
virtual void Serialize_impl (std::ostream & os) override const
Serialize item-specific values and call Entity 's Serialize_impl.
ItemBase & SetGrid (size_t grid_id=0)
ItemBase & SetOwner (const Entity & owner)
Identify the entity (item or agent) that now owns this item.
ItemBase & SetUnowned ()
~ItemBase () = default

Public Functions inherited from cse491::Entity

See cse491::Entity

Type Name
Entity & AddItem (size_t id)
Entity & AddItem (Entity & item)
virtual void Deserialize_impl (std::istream & is) override
Serialize entity-specific values.
Entity (size_t id, const std::string & name)
Entity (const Entity &) = delete
Entity (Entity &&) = default
size_t GetGridID () const
size_t GetID () const
std::vector< size_t > GetInventory () const
const std::string & GetName () const
size_t GetNumProperties () const
How many properties does this entity have?
GridPosition GetPosition () const
const T & GetProperty (const std::string & name) const
Return the current value of the specified property.
property_map_t & GetPropertyMap ()
return the property map for the entity
PropertyType GetPropertyType (const std::string & name) const
WorldBase & GetWorld () const
bool HasItem (size_t id) const
Inventory Management.
bool HasProperty (const std::string & name) const
Does this agent have a property with the specified name?
bool HasWorld () const
virtual bool IsAgent () const
Is Entity an autonomous agent?
virtual bool IsInterface () const
Is Entity an interface for a human?
virtual bool IsItem () const
Is Entity an item?
bool IsOnGrid (size_t in_grid_id) const
Entity & RemoveItem (size_t id)
Entity & RemoveItem (Entity & item)
Entity & RemoveProperty (const std::string & name)
Completely remove a property from an Entity .
virtual void Serialize_impl (std::ostream & os) override const
Serialize entity-specific values.
Entity & SetName (const std::string in_name)
Entity & SetPosition (GridPosition in_pos, size_t grid_id=0)
Entity & SetPosition (double x, double y)
Entity & SetProperties ()
Allow for setting multiple properties at once.
Entity & SetProperties (const std::string & name, VALUE_T && value, EXTRA_Ts &&... extras)
Entity & SetProperty (const std::string & name, const T & value)
Change the value of the specified property (will create if needed)
virtual Entity & SetWorld (WorldBase & in_world)
Entity & operator= (const Entity &) = delete
Entity & operator= (Entity &&) = delete
virtual ~Entity () = default

Public Functions inherited from cse491::CoreObject

See cse491::CoreObject

Type Name
void Deserialize (std::istream & is)
Restore the state of this object, extracting it from the provided stream.
bool Deserialize (std::string filename)
A version of Deserialize that accepts a filename to read this object from.
std::string GetTypeName () const
Access the derived name for this type.
void Serialize (std::ostream & os) const
Store the current state of this object for later extraction.
bool Serialize (std::string filename) const
A version of Serialize that accepts a filename for saving just this object.
auto operator<=> (const CoreObject &) const
virtual ~CoreObject ()

Protected Types

Type Name
enum OwnerType

Protected Types inherited from cse491::Entity

See cse491::Entity

Type Name
typedef std::unordered_map< std::string, std::unique_ptr< PropertyBase > > property_map_t
Every entity can have a simple set of properties (with values) associated with it.

Protected Attributes

Type Name
size_t owner_id = = 0
OwnerType owner_type = = OwnerType::NONE

Protected Attributes inherited from cse491::Entity

See cse491::Entity

Type Name
size_t grid_id = = 0
Which grid is this entity on?
size_t id = = 0
Unique ID for this entity (0 is used for "no ID")
std::vector< size_t > inventory
What entity ids are held by this entity?
std::string name = = ""
Name for this entity (E.g., "Player 1" or "+2 Sword")
GridPosition position
Where on the grid is this entity?
property_map_t property_map

Protected Functions inherited from cse491::Entity

See cse491::Entity

Type Name
Property< T > & AsProperty (const std::string & name) const

Protected Functions inherited from cse491::CoreObject

See cse491::CoreObject

Type Name
virtual void Deserialize_impl (std::istream &) = 0
Override to restore the state of this object from the provided stream.
bool EndDeserialize (std::istream & is)
Set up end of the deserialization for this class (does type checking)
void EndSerialize (std::ostream & os) const
Set up end of the serialization for this class (allows checking later)
virtual std::string GetTypeName_impl () const = 0
Override to allow access the derived name for this type.
virtual void Serialize_impl (std::ostream &) const = 0
Override to store the current state of this object for later extraction.
bool StartDeserialize (std::istream & is)
Set up beginning of the deserialization for this class (does type checking)
void StartSerialize (std::ostream & os) const
Set up beginning of the serialization for this class (allows checking later)

Public Functions Documentation

function Deserialize_impl

Deserialize item-specific values and call Entity 's Deserialize_impl.

inline virtual void cse491::ItemBase::Deserialize_impl (
    std::istream & is
) override

Parameters:

  • is istream to read contents from.

Implements cse491::Entity::Deserialize_impl

function GetOwnerID

inline size_t cse491::ItemBase::GetOwnerID () const

function GetTypeName_impl

Override to allow access the derived name for this type.

inline virtual std::string cse491::ItemBase::GetTypeName_impl () override const

Returns:

A unique typename, ideally the exact name for this class (with scope) This member function will be helpful for serialization and debugging. It should return a fully scoped typename, such as "cse491::WorldGrid".

Implements cse491::CoreObject::GetTypeName_impl

function IsItem

inline virtual bool cse491::ItemBase::IsItem () override const

Implements cse491::Entity::IsItem

function IsOnGrid [1/2]

inline bool cse491::ItemBase::IsOnGrid () const

function IsOnGrid [2/2]

inline bool cse491::ItemBase::IsOnGrid (
    size_t grid_id
) const

function IsOwned

inline bool cse491::ItemBase::IsOwned () const

function IsOwnedBy

inline bool cse491::ItemBase::IsOwnedBy (
    size_t entity_id
) const

function IsOwnedByAgent [1/2]

inline bool cse491::ItemBase::IsOwnedByAgent () const

function IsOwnedByAgent [2/2]

inline bool cse491::ItemBase::IsOwnedByAgent (
    size_t agent_id
) const

function IsOwnedByItem [1/2]

inline bool cse491::ItemBase::IsOwnedByItem () const

function IsOwnedByItem [2/2]

inline bool cse491::ItemBase::IsOwnedByItem (
    size_t item_id
) const

function ItemBase

inline cse491::ItemBase::ItemBase (
    size_t id,
    const std::string & name
) 

function Serialize_impl

Serialize item-specific values and call Entity 's Serialize_impl.

inline virtual void cse491::ItemBase::Serialize_impl (
    std::ostream & os
) override const

Parameters:

  • os ostream to write contents to.

Implements cse491::Entity::Serialize_impl

function SetGrid

inline ItemBase & cse491::ItemBase::SetGrid (
    size_t grid_id=0
) 

function SetOwner

Identify the entity (item or agent) that now owns this item.

inline ItemBase & cse491::ItemBase::SetOwner (
    const Entity & owner
) 

Parameters:

  • owner The new owning entity.

Returns:

A reference to this item.

function SetUnowned

inline ItemBase & cse491::ItemBase::SetUnowned () 

function ~ItemBase

cse491::ItemBase::~ItemBase () = default

Protected Types Documentation

enum OwnerType

enum cse491::ItemBase::OwnerType {
    NONE = 0,
    GRID,
    ITEM,
    AGENT
};

Protected Attributes Documentation

variable owner_id

size_t owner_id;

variable owner_type

OwnerType owner_type;

The documentation for this class was generated from the following file source/core/ItemBase.hpp