1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  *
22  * Based on the original sources
23  *   Faery Tale II -- The Halls of the Dead
24  *   (c) 1993-1996 The Wyrmkeep Entertainment Co.
25  */
26 
27 #ifndef SAGA2_CALENDER_H
28 #define SAGA2_CALENDER_H
29 
30 namespace Saga2 {
31 
32 /* ===================================================================== *
33    CalenderTime class
34  * ===================================================================== */
35 
36 class CalenderTime {
37 public:
38 	enum {
39 		//  Basic constants
40 		kDaysPerWeek     = 7,
41 		kDaysPerYear     = 365,
42 		kHoursPerDay     = 24,
43 		kRealMinutesPerDay = 30,
44 
45 		//  Number of animation frames per day
46 		kFramesPerDay    = 10 * 60 * kRealMinutesPerDay,
47 
48 		//  Derived variables
49 		kFramesPerHour   = (kFramesPerDay / kHoursPerDay),
50 		kFramesAtNoon    = (kFramesPerDay / 2),
51 
52 		kDayBias = kFramesAtNoon / 6,
53 
54 		kGameStartHour = 5
55 	};
56 
57 	uint16      _years,
58 	            _weeks,
59 	            _days,
60 	            _dayInYear,
61 	            _dayInWeek,
62 	            _hour,
63 	            _frameInHour;
64 
65 	bool _calenderPaused;
66 
CalenderTime()67 	CalenderTime() {
68 		_years = _weeks = _days = _dayInYear = _dayInWeek = _hour = _frameInHour = 0;
69 		_calenderPaused = false;
70 	}
71 
72 	void read(Common::InSaveFile *in);
73 	void write(Common::MemoryWriteStreamDynamic *out);
74 
75 	void update(void);
76 	int lightLevel(int maxLevel);
77 
frameInDay(void)78 	uint16 frameInDay(void) {
79 		return _hour * kFramesPerHour + _frameInHour;
80 	}
81 };
82 
83 /* ===================================================================== *
84    FrameAlarm class
85  * ===================================================================== */
86 
87 class FrameAlarm {
88 	uint16      _baseFrame,
89 	            _duration;
90 public:
91 	void set(uint16 dur);
92 	bool check(void);
93 	uint16 elapsed(void);
94 
95 	void write(Common::MemoryWriteStreamDynamic *out);
96 	void read(Common::InSaveFile *in);
97 };
98 
99 /* ===================================================================== *
100    Calender management functions
101  * ===================================================================== */
102 
103 void updateCalender(void);
104 void pauseCalender(void);
105 void resumeCalender(void);
106 
107 uint32 operator - (const CalenderTime &time1, const CalenderTime &time2);
108 
109 void initCalender(void);
110 
111 void saveCalender(Common::OutSaveFile *outS);
112 void loadCalender(Common::InSaveFile *in);
113 
114 bool isDayTime(void);
115 
116 const int MAX_LIGHT = 12;       // maximum light level
117 
118 }
119 
120 #endif
121