forked from Atlantis-PBEM/Atlantis
-
Notifications
You must be signed in to change notification settings - Fork 3
/
events.h
79 lines (62 loc) · 1.89 KB
/
events.h
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#pragma once
#include <string>
class ARegion;
class ARegionList;
class JsonReport;
/// Interface for an event
class IEvent
{
public:
virtual ~IEvent() {}
virtual std::string str(ARegionList ®ions) const = 0;
virtual void writeJson(JsonReport &of, ARegionList ®ions) const = 0;
};
/// Just a string
class StrEvent : public IEvent
{
public:
explicit StrEvent(const std::string &str): str_(str) {}
std::string str(ARegionList &) const override { return str_; }
void writeJson(JsonReport &of, ARegionList ®ions) const override;
protected:
std::string str_; ///< raw string
};
/// Unit collecting taxes in region
class TaxEvent : public IEvent
{
public:
TaxEvent(const std::string &uname, int amt, ARegion *reg);
std::string str(ARegionList ®ions) const override;
void writeJson(JsonReport &of, ARegionList ®ions) const override;
protected:
std::string uname_; ///< unit name
int amt_; ///< amount of taxes
ARegion *reg_; ///< region
};
/// Unit giving items to another unit
class GiveEvent : public IEvent
{
public:
GiveEvent(const std::string &gname, int inum, int amt, const std::string &tname, bool reversed);
std::string str(ARegionList ®ions) const override;
void writeJson(JsonReport &of, ARegionList ®ions) const override;
protected:
std::string gname_; ///< giver
int inum_; ///< item id
int amt_; ///< count
std::string tname_; ///< target
bool reversed_; ///< receive instead of give
};
/// Unit producing items
class ProduceEvent : public IEvent
{
public:
ProduceEvent(const std::string &uname, int inum, int amt, ARegion *reg);
std::string str(ARegionList ®ions) const override;
void writeJson(JsonReport &of, ARegionList ®ions) const override;
protected:
std::string uname_; ///< producing unit
int inum_; ///< item index
int amt_; ///< amount produced
ARegion *reg_; ///< region produced in
};