diff options
Diffstat (limited to 'game/activity.h')
-rw-r--r-- | game/activity.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/game/activity.h b/game/activity.h new file mode 100644 index 0000000..33c36fd --- /dev/null +++ b/game/activity.h @@ -0,0 +1,38 @@ +#ifndef ACTIVITY_H +#define ACTIVITY_H + +#include <game/worldobject.h> +#include <memory> +#include <special_members.hpp> + +class Vehicle; + +class Activity { +public: + Activity() = default; + DEFAULT_MOVE_COPY(Activity); + virtual ~Activity() = default; + + virtual void apply(Vehicle *, TickDuration) const = 0; + + template<typename T> class Of; +}; +using ActivityPtr = std::unique_ptr<Activity>; + +template<typename T> concept ActivityConcept = std::is_base_of_v<Activity, T>; +template<ActivityConcept AC> class Can { +public: + virtual void doActivity(const AC *, TickDuration) = 0; +}; + +template<typename T> class Activity::Of : public Activity { + void + apply(Vehicle * v, TickDuration dur) const override + { + if (auto tv = dynamic_cast<Can<T> *>(v)) { + tv->doActivity(static_cast<const T *>(this), dur); + } + } +}; + +#endif |