~nordfriese/freerct/debian-building

« back to all changes in this revision

Viewing changes to src/dates.h

  • Committer: Benedikt Straub
  • Date: 2021-07-01 16:54:22 UTC
  • Revision ID: benedikt_straub-20210701165422-kwxa3y9ga23kirrr
Initial commit (da71e14)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of FreeRCT.
 
3
 * FreeRCT is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
 
4
 * FreeRCT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
5
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with FreeRCT. If not, see <http://www.gnu.org/licenses/>.
 
6
 */
 
7
 
 
8
/** @file dates.h Declarations for dates in the game. */
 
9
 
 
10
#ifndef DATES_H
 
11
#define DATES_H
 
12
 
 
13
static const int TICK_COUNT_PER_DAY = 300; ///< Number of ticks in a day (stored in #Date::frac).
 
14
 
 
15
typedef uint32 CompressedDate; ///< Compressed date for easy transfer/storage.
 
16
 
 
17
/** Bits and sizes of the compressed date format. */
 
18
enum CompressedDateBits {
 
19
        CDB_DAY_LENGTH   =  5, ///< Length of the 'day'      field in the compressed date.
 
20
        CDB_MONTH_LENGTH =  4, ///< Length of the 'month'    field in the compressed date.
 
21
        CDB_YEAR_LENGTH  =  7, ///< Length of the 'year'     field in the compressed date.
 
22
        CDB_FRAC_LENGTH  = 10, ///< Length of the 'fraction' field in the compressed date.
 
23
 
 
24
        CDB_DAY_START = 0,                                   ///< Start bit of the 'day' field.
 
25
        CDB_MONTH_START = CDB_DAY_START + CDB_DAY_LENGTH,    ///< Start bit of the 'month' field.
 
26
        CDB_YEAR_START = CDB_MONTH_START + CDB_MONTH_LENGTH, ///< Start bit of the 'year' field.
 
27
        CDB_FRAC_START = CDB_YEAR_START + CDB_YEAR_LENGTH,   ///< Start bit of the 'fraction' field.
 
28
};
 
29
 
 
30
/** %Date in the game. */
 
31
class Date {
 
32
public:
 
33
        Date();
 
34
        Date(int pday, int pmonth, int pyear, int pfrac = 0);
 
35
        Date(CompressedDate cd);
 
36
        Date(const Date &d);
 
37
        Date &operator=(const Date &d);
 
38
        ~Date()
 
39
        {
 
40
        }
 
41
 
 
42
        void Initialize();
 
43
 
 
44
        CompressedDate Compress() const;
 
45
 
 
46
        int GetNextMonth() const;
 
47
        int GetPreviousMonth() const;
 
48
 
 
49
        int day;   ///< Day of the month, 1-based.
 
50
        int month; ///< Month of the year, 1-based.
 
51
        int year;  ///< The current year, 1-based.
 
52
        int frac;  ///< Day fraction, 0-based.
 
53
};
 
54
 
 
55
void DateOnTick();
 
56
void LoadDate(Loader &ldr);
 
57
void SaveDate(Saver &svr);
 
58
 
 
59
extern Date _date;
 
60
extern const int _days_per_month[13];
 
61
 
 
62
#endif