forked from cataclysmbnteam/Cataclysm-BN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
drop_token.h
75 lines (60 loc) · 1.98 KB
/
drop_token.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
#pragma once
#ifndef CATA_SRC_DROP_TOKEN_H
#define CATA_SRC_DROP_TOKEN_H
#include <iostream>
#include "calendar.h"
class JsonOut;
class JsonIn;
class item_drop_token
{
public:
// TODO: private
time_point turn = calendar::turn_zero;
int drop_number = 0;
int parent_number = 0;
item_drop_token() : item_drop_token( time_point(), 0, 0 )
{}
item_drop_token( time_point turn, int drop_number, int parent_number )
: turn( turn )
, drop_number( drop_number )
, parent_number( parent_number )
{}
bool operator==( const item_drop_token &other ) const {
return turn == other.turn
&& drop_number == other.drop_number
&& parent_number == other.parent_number;
}
bool operator!=( const item_drop_token &other ) const {
return !( *this == other );
}
bool is_child_of( const item_drop_token &other ) const {
return turn == other.turn
&& parent_number == other.drop_number
&& drop_number != other.drop_number;
}
bool is_sibling_of( const item_drop_token &other ) const {
return turn == other.turn
&& parent_number == other.parent_number &&
!is_child_of( other );
}
void serialize( JsonOut &jsout ) const;
void deserialize( JsonIn &jsin );
};
class drop_token_provider
{
private:
time_point last_turn = calendar::before_time_starts;
int last_drop = 0;
public:
drop_token_provider() = default;
item_drop_token make_next( time_point turn );
void clear();
void serialize( JsonOut &jsout ) const;
void deserialize( JsonIn &jsin );
};
namespace drop_token
{
drop_token_provider &get_provider();
} // namespace drop_token
std::ostream &operator<<( std::ostream &os, const item_drop_token &dt );
#endif // CATA_SRC_DROP_TOKEN_H