Creepy-simulation
 
Loading...
Searching...
No Matches
Unit.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <optional>
5
6#include "FieldParams.hpp"
7#include "utils.hpp"
13 std::shared_ptr<FieldParams> fieldParams_;
14 double moveRadius_;
15 std::uint32_t unitsCount_;
16
17 public:
24 UnitsParams(double moveRadius, const std::shared_ptr<FieldParams> &fieldParams, uint32_t unitsCount);
29 [[nodiscard]] auto getMoveRadius() const { return moveRadius_; }
34 [[nodiscard]] auto getFieldParams() const { return fieldParams_; }
39 [[nodiscard]] auto getUnitsCount() const { return unitsCount_; }
45 virtual Point generatePos(std::optional<Point> initialPoint);
49 virtual ~UnitsParams() = default;
50
51 UnitsParams(const UnitsParams &) = delete;
52
53 void operator=(const UnitsParams &) = delete;
54
56
57 void operator=(UnitsParams &&) = delete;
58};
63class Unit : public std::enable_shared_from_this<Unit> {
64 Point coord_{};
65 size_t id_;
66
67 protected:
72 void setID(const size_t id) { id_ = id; }
77 void setCoord(const Point coord) { coord_ = coord; }
78
79 public:
84 explicit Unit(size_t id, const std::shared_ptr<UnitsParams> &params);
89 [[nodiscard]] auto getCoord() const { return coord_; }
94 [[nodiscard]] auto getID() const { return id_; }
99 virtual void updateState(const std::shared_ptr<Unit> &another) = 0;
103 virtual void walk() = 0;
107 virtual void die() = 0;
111 virtual ~Unit() = default;
112
113 Unit(const Unit &other) = default;
114
115 Unit &operator=(const Unit &other) = default;
116
117 Unit(Unit &&other) = default;
118
119 Unit &operator=(Unit &&other) = default;
120};
Represents a generic unit in the simulation.
Definition Unit.hpp:63
virtual void updateState(const std::shared_ptr< Unit > &another)=0
Updates the state of the unit based on interaction with another unit.
virtual void walk()=0
Executes the walking behavior of the unit.
virtual ~Unit()=default
Virtual destructor for Unit.
auto getCoord() const
Retrieves the current coordinates of the unit.
Definition Unit.hpp:89
Unit & operator=(const Unit &other)=default
void setID(const size_t id)
Sets the ID of the unit.
Definition Unit.hpp:72
Unit & operator=(Unit &&other)=default
Unit(const Unit &other)=default
auto getID() const
Retrieves the ID of the unit.
Definition Unit.hpp:94
virtual void die()=0
Executes the death behavior of the unit.
void setCoord(const Point coord)
Sets the coordinates of the unit.
Definition Unit.hpp:77
Unit(Unit &&other)=default
Configuration parameters shared among multiple units.
Definition Unit.hpp:12
void operator=(const UnitsParams &)=delete
virtual ~UnitsParams()=default
Virtual destructor for UnitsParams.
virtual Point generatePos(std::optional< Point > initialPoint)
Generates a position for a unit, optionally starting from an initial point.
Definition Unit.cpp:8
void operator=(UnitsParams &&)=delete
auto getFieldParams() const
Retrieves the shared field parameters.
Definition Unit.hpp:34
auto getUnitsCount() const
Retrieves the total number of units.
Definition Unit.hpp:39
UnitsParams(UnitsParams &&)=delete
UnitsParams(const UnitsParams &)=delete
auto getMoveRadius() const
Retrieves the movement radius of the units.
Definition Unit.hpp:29
Represents a 2D point with x and y coordinates.
Definition utils.hpp:10