ICT290 / src / scene / AIController / BasicEntity.h
BasicEntity.h
Raw
#pragma once

#include <glm/glm.hpp>
#include <iostream>

#include "Messaging/EntityManager.h"
#include "Messaging/Telegram.h"

/**
 * @class BasicEntity
 * @brief  This is the base entity class that all entities derive from.
 *          All entities are assigned a unique int ID on creation
 *          Code is based on the textbook:
 *          "Programming game AI by Example"
 *          by Matt Buckland
 *
 *
 * @author Michael John
 * @version 1.00
 * @date 21/08/2021
 *
 * @todo
 *
 * @bug
 */

struct Telegram;

enum { basicType = -1 };

/**
 * Basic entity that all physical entities in the world derive from
 */
class BasicEntity {
   public:
    /**
     * Constructor
     * @param type Type of entity
     * @param position 2Dposition in the world -fixed at 0.0 on the Y axis
     * @param scale 2D scalar of entities size
     * @param boundRadius radius of entity used for avoidance
     */
    BasicEntity(int type,
                glm::vec2 position,
                glm::vec2 scale,
                float boundRadius);

    virtual ~BasicEntity() = default;

    virtual bool HandleMessage(const Telegram&) { return false; }

    /**
     * Getter for unique id of entity, created at instatiation of entity
     * @return int ID number
     */
    int getID() const;

    /**
     * Gets entity type
     * @return int type of entity
     */
    int getType() const;

    /**
     * Sets entities type
     * @param type entities type
     */
    void setType(int type);

    /**
     * Get 2D position vector of entity
     * @return glm::vec2 position of entity
     */
    glm::vec2 getPosition() const;

    /**
     * Sets entities position
     * @param position 2D glm::vec2 position of entity
     */
    void setPosition(glm::vec2 position);

    /**
     * Gets scale of entity
     * @return glm::vec2 x and z size of entity
     */
    glm::vec2 getScale() const;

    /**
     * Sets scale of entity
     * @param scale glm::vec2 x and z scale of entity
     */
    void setScale(glm::vec2 scale);

    /**
     * Get entities bound radius
     * @return float radius of entity
     */
    float getBoundingRadius() const;

    /**
     * Sets the entities bounding radius
     * @param radius float radius of entity
     */
    void setBoundingRadius(float radius);

    /**
     * Check if flag is set on entity- used for setting entities to check
     * @return bool flag state
     */
    bool getFlag() const;

    /**
     * Sets the entities flag to on
     */
    void setFlag();

    /**
     * Sets the entities flag to off
     */
    void unsetFlag();

   protected:
    glm::vec2 m_Position;    /// Entities position
    glm::vec2 m_Scale;       /// Entities scale
    float m_BoundingRadius;  /// Entites radius

   private:
    void nextValidID();  /// gets and increments unique int ID for entity
    static int nextID;   /// contains next unique ID
    int m_ID;            /// ID of this entity
    int m_Type;          /// type of this entity
    bool m_Flag;         /// holds flag setting
};