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

#include <list>
#include <vector>
#include "BasicEntity.h"
#include "WallType.h"

/**
 * Struct to represent data for a room
 */
struct Room {
    std::vector<WallType> walls;
    std::vector<BasicEntity*> obstacles;
    glm::vec2 centre{0};
    glm::vec2 min{0};
    glm::vec2 max{0};
};

// Forward declaration
class GameWorld;

/**
 * @class Sound
 * @brief An interface between the game state and AI.
 *
 * @author Chase Percy
 * @author Michael John
 */
class ArcanistLevel {
   public:
    ArcanistLevel() = default;
    ~ArcanistLevel();

    /**
     * Add a room to the m_rooms data structure.
     * @param room the room to add.
     */
    void addRoom(Room& room) { m_rooms.push_back(room); }

    /**
     * Get the room at index i if i is a valid index.
     * @param i the index to get the room from
     * @return the room at index i
     */
    const Room& getRoom(std::size_t i) const;

    /**
     * get all rooms from m_rooms
     * @return all rooms
     */
    const std::vector<Room>& getRooms() const;

    /**
     * Set the number of rooms. Used to differentiate between rooms and
     * corridors in the m_rooms vector. Element 0 - m_numOfRooms are rooms, the
     * rest are corridors.
     * @param i the number of rooms.
     */
    void setNumOfRooms(std::size_t i) { m_numOfRooms = i; }

    /**
     * gets the number of rooms, not including corridors.
     * @return number of rooms.
     */
    std::size_t getNumOfRooms() { return m_numOfRooms; }

    /**
     * Returns the nearest room relative to a position.
     * @param position the position to compare rooms to.
     * @return the closest room.
     */
    const Room& getNearestRoom(const glm::vec2& position) const;

    /**
     * Get all walls from all rooms and corridors.
     * @return all walls
     */
    const std::vector<WallType>& getAllWalls() const;

    /**
     * Returns all obstacles from all rooms
     * @return all obstacles
     */
    const std::vector<BasicEntity*>& getAllObstacles() const;

    /**
     * Check if a position is in bounds (within the walls of the map). This
     * function is for checking enemies as it has more tolerance for wall
     * penetration.
     * @param position the position to check
     * @return true if in bounds, else false.
     */
    bool isInBounds(const glm::vec2& position) const;

    /**
     * Checks if a position is in bounds (within the walls of the map). This
     * function is for checking objects like projectiles are in bounds and a low
     * tolerance for wall penetration.
     * @param position the position to check
     * @return True if in bound, else false.
     */
    bool isInBoundsTight(const glm::vec2& position) const;

    /**
     * clears m_allObstacles and repopulates it with current room data.
     */
    void updateAllEntities();

    /**
     * clears m_allWalls and repopulates it with current room data.
     */
    void updateAllWalls();

    /**
     * Returns a random spawn point within a valid location on the map.
     * @return spawn point
     */
    glm::vec2 getRandomSpawn();

    /**
     * Get a random spawn relative to a seed.
     * @param seed the seed to generate the randomness
     * @return spawn point
     */
    glm::vec2 getRandomSpawn(int seed);

    /**
     * Get a random spawn point within a room
     * @param room the room to spawn in
     * @return a spawn point
     */
    glm::vec2 getRandomSpawn(const Room& room);

    /**
     * Get a random room to spawn in relative to a seed.
     * @param room the room to spawn in
     * @param seed the seed to generate the randomness
     * @return spawn point
     */
    glm::vec2 getRandomSpawn(const Room& room, int seed);

    std::list<glm::vec2>
        debugIntersections;  /// Used for debugging intersections

   private:
    std::vector<Room> m_rooms;  /// the rooms for the current level
    std::size_t m_numOfRooms{
        0};  /// the number of rooms not including corridors
    std::vector<BasicEntity*> m_allObstacles;  /// All obstacles for the level
    std::vector<WallType> m_allWalls;          /// All walls for the level
};