-
Notifications
You must be signed in to change notification settings - Fork 30
/
time.h
124 lines (104 loc) · 2.9 KB
/
time.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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#ifndef _CATA_TIME_H_
#define _CATA_TIME_H_
#include <string>
enum Season
{
SEASON_SPRING,
SEASON_SUMMER,
SEASON_AUTUMN,
SEASON_WINTER
};
Season lookup_season(std::string name);
std::string season_name(Season season);
enum Moon_phase
{
MOON_NEW = 0,
MOON_WAXING,
MOON_FULL,
MOON_WANING,
};
// TODO: Pull this stuff from a config file?
// Light during daytime - also, the max sight distance!
#define DAY_LIGHT 30
// Days in a season - 1/4 of this is a moon cycle!
#define DAYS_IN_SEASON 20
// Seconds per turn; changing this will wildly alter gameplay!
#define SECONDS_IN_TURN 6
// The year the game starts in
#define STARTING_YEAR 2086
// Functions for converting minutes, hours, days into # of turns
#define MINUTES(x) ( ((x) * 60) / SECONDS_IN_TURN )
#define HOURS(x) ( ((x) * 3600) / SECONDS_IN_TURN )
#define DAYS(x) ( ((x) * 86400) / SECONDS_IN_TURN
class Time
{
public:
Time();
~Time();
Time(const Time& copy);
Time(int _second, int _minute, int _hour = 0, int _day = 0,
Season _season = SEASON_SPRING, int _year = 0);
Time(int _turn);
bool operator==(const Time& other) const;
bool operator!=(const Time& other) const;
bool operator< (const Time& other) const;
bool operator< (const int& other) const;
bool operator> (const Time& other) const;
bool operator> (const int& other) const;
bool operator<=(const Time& other) const;
bool operator<=(const int& other) const;
bool operator>=(const Time& other) const;
bool operator>=(const int& other) const;
Time& operator= (const Time& rhs);
Time& operator+=(const Time& rhs);
Time& operator+=(const int& rhs);
Time& operator-=(const Time& rhs);
Time& operator-=(const int& rhs);
operator int() const; // Returns get_turn()
int get_turn() const;
// These four can't be const, since they may call standardize()
int get_second();
int get_minute();
int get_hour();
int get_day();
Season get_season() const;
int get_year() const;
Moon_phase get_moon_phase() const;
int get_sunrise() const; // Depends on season
int get_sunset() const; // Depends on season
std::string get_text(bool twentyfour = false); // "Spring, Day 4, 2:37 PM"
int get_light_level();
void increment(); // turn++, second += SECONDS_IN_TURN
void standardize(); // Ensure seconds < 60, hours < 24, etc
private:
int year;
Season season;
int day;
int hour;
int minute;
int second; // Should always be a multiple of SECONDS_IN_TURN
int turn; // We track turn seperately, so we don't have to calculate it
void set_date_from_turn();
void set_turn_from_date();
};
inline Time operator+(Time lhs, const Time& rhs)
{
lhs += rhs;
return lhs;
}
inline Time operator+(Time lhs, const int& rhs)
{
lhs += rhs;
return lhs;
}
inline Time operator-(Time lhs, const Time& rhs)
{
lhs += rhs;
return lhs;
}
inline Time operator-(Time lhs, const int& rhs)
{
lhs -= rhs;
return lhs;
}
#endif