Conquer Space 0.0.0
A space themed grand strategy game set in the near future, with realistic orbital mechanics, and an emphasis on economics and politics.
stardate.h
Go to the documentation of this file.
1/* Conquer Space
2 * Copyright (C) 2021-2025 Conquer Space
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17#pragma once
18
19#include <cstdint>
20#include <string>
21
22namespace cqsp::core::components {
46class StarDate {
47 public:
48 // How many seconds a tick is
49 // 10 minutes
50 static const int TIME_INCREMENT = 60 * 10;
51
52 static constexpr float MINUTE = 0.1f;
53 static constexpr int HOUR = static_cast<int>(60 * MINUTE);
54 static constexpr int DAY = 24 * HOUR;
55 static constexpr int WEEK = DAY * 7;
56
57 static const int YEAR = DAY * 365;
58
59 void IncrementDate() { date++; }
60
61 uint64_t GetDate() const { return date; }
62
63 double ToSecond() const { return static_cast<double>(date) * TIME_INCREMENT; }
64 double ToDay() const { return date / static_cast<double>(DAY); }
65
66 std::string ToString() const;
67 std::string ToString(double offset) const;
68
69 int GetYear() const;
70 int GetMonth() const;
71 int GetDay() const;
72 int GetHour(double offset = 0.0) const;
73 int GetMinute() const;
74 int ToTicks(double seconds) { return static_cast<int>(seconds / TIME_INCREMENT); }
75
76 void SetDate(unsigned int _date) { date = _date; }
77
78 double operator()() const { return ToSecond(); }
79
80 private:
81 // Time in minutes since the start date
82 // This value is set to -1 since we will need to 0th tick to initialize everything properly
83 uint64_t date = -1;
84
85 static const int start_date = 2000;
86};
87} // namespace cqsp::core::components
Holds and calculates the tick that is on going. Date is the number of hours that has been ongoing sin...
Definition: stardate.h:46
static constexpr int HOUR
Definition: stardate.h:53
int GetDay() const
Definition: stardate.cpp:63
static const int TIME_INCREMENT
Definition: stardate.h:50
uint64_t GetDate() const
Definition: stardate.h:61
int GetYear() const
Definition: stardate.cpp:53
void IncrementDate()
Definition: stardate.h:59
static constexpr int DAY
Definition: stardate.h:54
int GetMonth() const
Definition: stardate.cpp:58
double operator()() const
Definition: stardate.h:78
void SetDate(unsigned int _date)
Definition: stardate.h:76
uint64_t date
Definition: stardate.h:83
int GetMinute() const
Definition: stardate.cpp:76
static constexpr int WEEK
Definition: stardate.h:55
double ToSecond() const
Definition: stardate.h:63
static const int YEAR
Definition: stardate.h:57
static const int start_date
Definition: stardate.h:85
static constexpr float MINUTE
Definition: stardate.h:52
std::string ToString() const
Definition: stardate.cpp:33
int ToTicks(double seconds)
Definition: stardate.h:74
double ToDay() const
Definition: stardate.h:64
int GetHour(double offset=0.0) const
Definition: stardate.cpp:71
Definition: area.h:23