forked from cataclysmbnteam/Cataclysm-BN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
drop_token.cpp
77 lines (61 loc) · 1.58 KB
/
drop_token.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
#include "calendar.h"
#include "drop_token.h"
#include "game.h"
#include "json.h"
void item_drop_token::serialize( JsonOut &jsout ) const
{
jsout.start_object();
jsout.member( "turn", turn );
jsout.member( "drop_number", drop_number );
jsout.member( "parent_number", parent_number );
jsout.end_object();
}
void item_drop_token::deserialize( JsonIn &jsin )
{
JsonObject jo = jsin.get_object();
jo.read( "turn", turn );
jo.read( "drop_number", drop_number );
jo.read( "parent_number", parent_number );
}
item_drop_token drop_token_provider::make_next( time_point turn )
{
if( turn != last_turn ) {
last_turn = turn;
last_drop = 0;
}
last_drop++;
return item_drop_token{ turn, last_drop, last_drop };
}
void drop_token_provider::clear()
{
last_turn = calendar::before_time_starts;
last_drop = 0;
}
void drop_token_provider::serialize( JsonOut &jsout ) const
{
jsout.start_object();
jsout.member( "last_turn", last_turn );
jsout.member( "last_drop", last_drop );
jsout.end_object();
}
void drop_token_provider::deserialize( JsonIn &jsin )
{
JsonObject jo = jsin.get_object();
jo.read( "last_turn", last_turn );
jo.read( "last_drop", last_drop );
}
namespace drop_token
{
drop_token_provider &get_provider()
{
return *g->token_provider_ptr;
}
} // namespace drop_token
std::ostream &operator<<( std::ostream &os, const item_drop_token &dt )
{
os << "{turn:" << to_turn<int>( dt.turn )
<< ", drop:" << dt.drop_number
<< ", parent:" << dt.parent_number
<< '}';
return os;
}