/
gametime.h
82 lines (59 loc) · 2.05 KB
/
gametime.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
#pragma once
#include "library/strings.h"
#include <cstdint>
namespace OpenApoc
{
static constexpr unsigned VANILLA_TICKS_PER_SECOND = 36;
static constexpr unsigned TICKS_MULTIPLIER = 4;
static constexpr unsigned TICKS_PER_SECOND = VANILLA_TICKS_PER_SECOND * TICKS_MULTIPLIER;
static constexpr unsigned TICKS_PER_MINUTE = TICKS_PER_SECOND * 60;
static constexpr unsigned TICKS_PER_HOUR = TICKS_PER_MINUTE * 60;
static constexpr unsigned TICKS_PER_DAY = TICKS_PER_HOUR * 24;
static constexpr unsigned TURBO_TICKS = 5 * 60 * TICKS_PER_SECOND;
class GameTime
{
private:
bool secondPassedFlag = false;
bool fiveMinutesPassedFlag = false;
bool hourPassedFlag = false;
bool dayPassedFlag = false;
bool weekPassedFlag = false;
public:
uint64_t ticks = 0;
GameTime() = default;
GameTime(uint64_t ticks);
void addTicks(uint64_t ticks);
unsigned int getHours() const;
unsigned int getMinutes() const;
unsigned int getDay() const;
unsigned int getWeek() const;
uint64_t getTicks() const;
// returns week with prefix
UString getWeekString() const;
// returns formatted time in format hh:mm
UString getShortTimeString() const;
// returns formatted time in format hh:mm:ss
UString getLongTimeString() const;
// returns formatted date in format a, d m, y
UString getLongDateString() const;
// returns formatted date in format d m, y
UString getShortDateString() const;
// set at end of each second
bool secondPassed() const;
void setSecondPassed(bool newValue) { secondPassedFlag = newValue; }
// set at end of each 5 minutes
bool fiveMinutesPassed() const;
void setFiveMinutesPassed(bool newValue) { fiveMinutesPassedFlag = newValue; }
// set at end of each hour
bool hourPassed() const;
void setHourPassed(bool newValue) { hourPassedFlag = newValue; }
// set at midnight
bool dayPassed() const;
void setDayPassed(bool newValue) { dayPassedFlag = newValue; }
// set at sunday midnight
bool weekPassed() const;
void setWeekPassed(bool newValue) { weekPassedFlag = newValue; }
void clearFlags();
static GameTime midday();
};
} // namespace OpenApoc