RTYPE TECHNICAL DOCUMENTATION
  • Introduction
  • Classes
    • utils::InputMap
    • utils::Window
    • utils::constant::ButtonValue
    • network::Client
    • network::LockedQueue
    • network::Server
    • ecs::EnemyFactory
    • ecs::Engine
    • ecs::Entity
    • ecs::Event
    • ecs::Registry
    • ecs::SparseArray
    • ecs::World
    • ecs::WorldManager
    • ecs::component::Activable
    • ecs::component::Animated
    • ecs::component::Animated::AnimFrame
    • ecs::component::AttackAI
    • ecs::component::AttackAI::Action
    • ecs::component::AttackAI::AI
    • ecs::component::AttackAI::AI::Pattern
    • ecs::component::Controllable
    • ecs::component::Direction
    • ecs::component::Drawable
    • ecs::component::EntityType
    • ecs::component::Faction
    • ecs::component::FollowEntity
    • ecs::component::Health
    • ecs::component::Hitbox
    • ecs::component::MovementAI
    • ecs::component::MovementAI::AI
    • ecs::component::NetworkId
    • ecs::component::Parallax
    • ecs::component::Position
    • ecs::component::Projectile
    • ecs::component::Score
    • ecs::component::Shootable
    • ecs::component::Size
    • ecs::component::Text
    • ecs::component::textColor
    • ecs::component::Velocity
    • ecs::component::Weapon
    • audio::AudioManager
    • asset::AssetLoader
    • anim::Animation
  • Namespaces
    • utils
    • utils::constant
    • network
    • ecs
    • ecs::component
    • ecs::systems
    • audio
    • asset
    • anim
  • Modules
    • Input
  • Files
    • src
    • src/client
    • Animation.cpp
    • Animation.hpp
    • AssetLoader.cpp
    • AssetLoader.hpp
    • AudioManager.cpp
    • AudioManager.hpp
    • entrypoint.cpp
    • GetWorld.cpp
    • GetWorld.hpp
    • NetworkClient.cpp
    • NetworkClient.hpp
    • src/ecs
    • src/ecs/components
    • src/ecs/components/client
    • Activable.hpp
    • Animated.hpp
    • Controllable.hpp
    • Drawable.hpp
    • Hitbox.hpp
    • Parallax.hpp
    • Shootable.hpp
    • Text.hpp
    • src/ecs/components/server
    • AttackAI.cpp
    • AttackAI.hpp
    • FollowEntity.hpp
    • Projectile.hpp
    • Direction.hpp
    • EntityType.hpp
    • Faction.hpp
    • Health.hpp
    • MovementAI.cpp
    • MovementAI.hpp
    • NetworkId.hpp
    • Position.hpp
    • Score.hpp
    • Size.hpp
    • Velocity.hpp
    • Weapon.hpp
    • src/ecs/systems
    • src/ecs/systems/client
    • Animate.hpp
    • Draw.hpp
    • ExecuteOnce.hpp
    • HandleIncomingMessages.hpp
    • HandleParallaxBounds.hpp
    • HandleSFMLEvents.hpp
    • HandleSFMLKeys.hpp
    • HealthBar.hpp
    • MenuSelect.hpp
    • ScoreUpdate.hpp
    • SendDirection.hpp
    • src/ecs/systems/server
    • DeathUpdate.hpp
    • FollowEntitySystem.hpp
    • HandleIncomingMessage.hpp
    • PlayerHealthUpdate.hpp
    • PositionUpdate.hpp
    • ProjectileCollision.hpp
    • RunAttackAI.hpp
    • Waves.hpp
    • ManageClientEvents.hpp
    • Movement.hpp
    • PositionLogger.hpp
    • RunMovementAI.hpp
    • EnemyFactory.cpp
    • EnemyFactory.hpp
    • Engine.hpp
    • Entity.hpp
    • Event.hpp
    • LockedQueue.hpp
    • Registry.hpp
    • SparseArray.hpp
    • World.hpp
    • WorldManager.cpp
    • WorldManager.hpp
    • src/server
    • entrypoint.cpp
    • Server.cpp
    • Server.hpp
    • src/utils
    • Constant.hpp
    • InputMap.cpp
    • InputMap.hpp
    • Window.cpp
    • README.md
  • Pages
    • deprecated
  • GitHub
Powered by GitBook
On this page
  • Namespaces
  • Classes
  • Source code
  1. Files

AttackAI.hpp

Namespaces

Name

Classes

Name

struct

struct

struct

struct

Source code

/*
** EPITECH PROJECT, 2022
** RTYPE
** File description:
** AttackAI
*/

#pragma once

#include <algorithm>
#include <functional>
#include <vector>
#include "World.hpp"
#include "components/EntityType.hpp"
#include "components/Faction.hpp"
#include <unordered_map>

namespace ecs::component
{
    struct AttackAI {
      public:
        enum AIType { None, Battlecruiser, Dreadnought, Fighter, Frigate, Scout, Torpedo, NoodleMonster, PlayerBot };

        enum PatternType {
            Wait,
            WaitShort,
            WaitLong,
            ShootBullet,
            ShootEnergySphere,
            ShootEnergySphereFast,
            ShootLaser,
            ShootRocket,
            InvokeAllies,
            InvokeAnyone,
            SpawnAsteroids,
            PlayerBotLaser
        };

        size_t lastAttack;
        size_t lastAttackDelay;

        struct AI {
            struct Pattern {
                Pattern(short reloadTime, std::function<void(const std::size_t)> pattern)
                    : reloadTime(reloadTime), _function(pattern)
                {
                }

                void run(const std::size_t &shooter) const { _function(shooter); }

                short reloadTime;

                std::function<void(const std::size_t)> _function;
            };

            AI(std::vector<PatternType> pattern) : _thisPatterns(pattern), currentAttack(0) {}

            AI(const AI &other) : currentAttack(other.currentAttack), _thisPatterns(other._thisPatterns) {}

            inline const std::vector<PatternType> &getPatterns() const { return _thisPatterns; }

            static const std::unordered_map<PatternType, Pattern> patterns;

          private:
            short currentAttack;
            std::vector<PatternType> _thisPatterns;
        };

        struct Action {
            static void waitAttack(const std::size_t shooter);
            static void shootBulletAttack(const std::size_t shooter);
            static void shootEnerySphereAttack(const std::size_t shooter);
            static void shootLaserAttack(const std::size_t shooter);
            static void shootRocketAttack(const std::size_t shooter);
            static void invokeAlliesAttack(const std::size_t shooter);
            static void spawnAsteroidsAttack(const std::size_t shooter);
            static void invokeAnyoneAttack(const std::size_t shooter);
            static void playerBotLaser(const std::size_t shooter);

          private:
            static void spawnNewBullet(component::EntityType::Types type, int posX, int posY, char dirX, char dirY,
                int sizeX, int sizeY, int velX, int velY, int dmg, ecs::component::Faction::Factions fac,
                int bulletHealth = 1);
        };

        AttackAI(const AIType &type = None) : _thisAI(findAI(type)), lastAttack(0), lastAttackDelay(0) {}

        const AttackAI::AI::Pattern &getRandomAttack() const
        {
            int attack = _thisAI.getPatterns().at(std::rand() % _thisAI.getPatterns().size());
            return AI::patterns.at(static_cast<PatternType>(attack));
        }

      private:
        AI _thisAI;

        inline const AI &findAI(const AIType &type) { return _aiVector.at(type); }

        static const std::unordered_map<AIType, AI> _aiVector;
    };
} // namespace ecs::component

Updated on 2022-11-13 at 17:21:37 +0100

PreviousAttackAI.cppNextFollowEntity.hpp

Last updated 2 years ago

component.

The structure where the pattern of the entity is defined.

The structure contains a std::functions and a reloadTime. Patterns are created in the CPP file.

The structure contains the prototypes of the functions used by patterns.

ecs
ecs::component
ecs::component::AttackAI
AttackAI
ecs::component::AttackAI::AI
AI
ecs::component::AttackAI::AI::Pattern
Pattern
ecs::component::AttackAI::Action
Action