forked from Atlantis-PBEM/Atlantis
-
Notifications
You must be signed in to change notification settings - Fork 3
/
events.cpp
107 lines (90 loc) · 2.59 KB
/
events.cpp
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "events.h"
#include "aregion.h"
#include "astring.h"
#include "fileio.h"
#include "items.h"
#include <sstream>
//----------------------------------------------------------------------------
void StrEvent::writeJson(JsonReport &of, ARegionList &) const
{
of.putStr(str_.c_str());
}
//----------------------------------------------------------------------------
TaxEvent::TaxEvent(const std::string &uname, int amt, ARegion *reg)
: uname_(uname)
, amt_(amt)
, reg_(reg)
{
}
std::string TaxEvent::str(ARegionList ®ions) const
{
std::ostringstream os;
os << uname_ << ": Collects $" << amt_ << " in taxes in ";
os << reg_->ShortPrint(®ions) << '.';
return os.str();
}
void TaxEvent::writeJson(JsonReport &of, ARegionList ®ions) const
{
of.startDict(NULL);
of.putPairStr("type", "Tax");
of.putPairStr("name", uname_.c_str());
of.putPairInt("amount", amt_);
of.startDict("region");
reg_->CPrint(&of, ®ions, false);
of.endDict();
of.endDict();
}
//----------------------------------------------------------------------------
GiveEvent::GiveEvent(const std::string &gname, int inum, int amt, const std::string &tname, bool reversed)
: gname_(gname)
, inum_(inum)
, amt_(amt)
, tname_(tname)
, reversed_(reversed)
{
}
std::string GiveEvent::str(ARegionList &) const
{
std::ostringstream os;
if (reversed_)
os << tname_ << ": Receives " << ItemString(inum_, amt_) << " from " << gname_ << '.';
else
os << gname_ << ": Gives " << ItemString(inum_, amt_) << " to " << tname_ << '.';
return os.str();
}
void GiveEvent::writeJson(JsonReport &of, ARegionList ®ions) const
{
of.startDict(NULL);
of.putPairStr("type", reversed_ ? "Receive" : "Give");
of.putPairStr("giver", gname_.c_str());
of.putPairStr("receiver", tname_.c_str());
of.putPairStr("abbr", ItemDefs[inum_].abr);
of.putPairInt("amount", amt_);
of.endDict();
}
//----------------------------------------------------------------------------
ProduceEvent::ProduceEvent(const std::string &uname, int inum, int amt, ARegion *reg)
: uname_(uname)
, inum_(inum)
, amt_(amt)
, reg_(reg)
{
}
std::string ProduceEvent::str(ARegionList ®ions) const
{
std::ostringstream os;
os << uname_ << ": Produces " << ItemString(inum_, amt_) << " in " << reg_->ShortPrint(®ions) << '.';
return os.str();
}
void ProduceEvent::writeJson(JsonReport &of, ARegionList ®ions) const
{
of.startDict(NULL);
of.putPairStr("type", "Produce");
of.putPairStr("name", uname_.c_str());
of.putPairStr("abbr", ItemDefs[inum_].abr);
of.putPairInt("amount", amt_);
of.startDict("region");
reg_->CPrint(&of, ®ions, false);
of.endDict();
of.endDict();
}