ICT290 / src / scene / AIController / EntityBrain / AttackSystem.h
AttackSystem.h
Raw
//
// Created by Micha on 27/09/2021.
//

#pragma once

#include <list>
#include <map>

#include <SDL.h>
#include <algorithm>
#include <glm/glm.hpp>
#include <glm/gtx/euler_angles.hpp>

class AttackType;
class Vehicle;

class AttackSystem {
   public:
    AttackSystem(Vehicle* owner,
                 float ReactionTime,
                 float AimAccuracy,
                 float AimPersistance);

    ~AttackSystem();

    // sets up the weapon map with just one weapon: the blaster
    void initialize();

    // this method aims the bot's current weapon at the target (if there is a
    // target) and, if aimed correctly, fires a round. (Called each update-step
    // from Vehicle::Update)
    // void          TakeAimAndShoot()const;
    void takeAimAndShoot() const;

    // this method determines the most appropriate weapon to use given the
    // current game state. (Called every n update-steps from Vehicle::Update)
    // void          SelectWeapon();
    void selectAttack();

    // this will add a weapon of the specified type to the bot's inventory.
    // If the bot already has a weapon of this type only the ammo is added.
    //(called by the weapon giver-triggers to give a bot a weapon)
    // void          AddWeapon(unsigned int weapon_type);
    void addAttack(unsigned int attackType);

    // changes the current weapon to one of the specified type (provided that
    // type is in the bot's possession) void          ChangeWeapon(unsigned int
    // type);
    void changeAttack(unsigned int type);

    // shoots the current weapon at the given position
    // void          ShootAt(glm::vec2 pos)const;
    void shootAt(glm::vec2 pos) const;

    // returns a pointer to the current weapon
    // Raven_Weapon* GetCurrentWeapon()const{return m_pCurrentWeapon;}
    AttackType* getCurrentWeapon() const { return m_CurrentAttack; }

    // returns a pointer to the specified weapon type (if in inventory, null if
    // not)
    // Raven_Weapon* GetWeaponFromInventory(int weapon_type);
    AttackType* getAttackFromInventory(int weapon_type);

    // returns the amount of ammo remaining for the specified weapon
    int getAmmoRemainingForWeapon(unsigned int weapon_type);

    // float         ReactionTime()const{return m_dReactionTime;}
    float reactionTime() const { return m_ReactionTime; }

    // void          RenderCurrentWeapon()const;
    // void          RenderDesirabilities()const;
   private:
    // a map of weapon instances indexed into by type
    // typedef std::map<int, Raven_Weapon*>  WeaponMap;
    typedef std::map<int, AttackType*> AttackMap;

   private:
    Vehicle* m_Owner;

    // pointers to the weapons the bot is carrying (a bot may only carry one
    // instance of each weapon)
    AttackMap m_AttackMap;

    // a pointer to the weapon the bot is currently holding
    AttackType* m_CurrentAttack;

    // this is the minimum amount of time a bot needs to see an opponent before
    // it can react to it. This variable is used to prevent a bot shooting at
    // an opponent the instant it becomes visible.
    float m_ReactionTime;

    // each time the current weapon is fired a certain amount of random noise is
    // added to the the angle of the shot. This prevents the bots from hitting
    // their opponents 100% of the time. The lower this value the more accurate
    // a bot's aim will be. Recommended values are between 0 and 0.2 (the value
    // represents the max deviation in radians that can be added to each shot).
    float m_AimAccuracy;

    // the amount of time a bot will continue aiming at the position of the
    // target even if the target disappears from view.
    float m_AimPersistance;

    // predicts where the target will be by the time it takes the current
    // weapon's projectile type to reach it. Used by TakeAimAndShoot Vector2D
    // PredictFuturePositionOfTarget()const;
    glm::vec2 predictFuturePositionOfTarget() const;

    // adds a random deviation to the firing angle not greater than
    // m_dAimAccuracy rads
    void addNoiseToAim(glm::vec2& AimingPos) const;
};

// ICT290_ATTACKSYSTEM_H