summaryrefslogtreecommitdiff
path: root/game/activity.h
blob: 33c36fd772374e872b4483ec50806276728ff07f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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