1 #ifndef __WORLD_CLOCK
2 #define __WORLD_CLOCK
3 
4 #include "Types.h"
5 
6 #include <string_theory/string>
7 
8 
9 #define NUM_SEC_IN_DAY		86400
10 #define NUM_SEC_IN_HOUR		3600
11 #define NUM_SEC_IN_MIN		60
12 #define ROUNDTO_MIN		5
13 
14 #define NUM_MIN_IN_DAY		1440
15 #define NUM_MIN_IN_HOUR		60
16 
17 //Kris:
18 //This is the plan for game time...
19 //Game time should be restricted to outside code.  Think of it as encapsulation.  Anyway, using these
20 //simple functions, you will be able to change the amount of time that passes per frame.  The gameloop will
21 //automatically update the clock once per cycle, regardless of the mode you are in.
22 //This does pose potential problems in modes such as the editor, or similar where time shouldn't pass, and
23 //isn't currently handled.  The best thing to do in these cases is call the PauseGame() function when entering
24 //such a mode, and UnPauseGame() when finished.  Everything will be restored just the way you left it.  This
25 //is much simpler to handle in the overall scheme of things.
26 
27 enum LockPauseReason
28 {
29 	LOCK_PAUSE_MSGBOX =  1,
30 	LOCK_PAUSE_CREATURE_ATTACK =  2,
31 	LOCK_PAUSE_DISPLAY_SOLDIER_UPDATE =  4,
32 	LOCK_PAUSE_CREATE_SOLDIER_UPDATE =  5,
33 	LOCK_PAUSE_MEANWHILE =  6,
34 	LOCK_PAUSE_CONTRACT_RENEWAL =  7,
35 	LOCK_PAUSE_CONTRACT_ENDING =  8,
36 	LOCK_PAUSE_PREBATTLE_CURRENT_SQUAD = 11,
37 	LOCK_PAUSE_PREBATTLE = 12,
38 	LOCK_PAUSE_SIMULTANEOUS_ARRIVAL = 13,
39 	LOCK_PAUSE_ENGAGED_IN_CONV = 14,
40 	LOCK_PAUSE_MERC_TALKING = 15,
41 	LOCK_PAUSE_LOCKUI_MODE = 16,
42 	LOCK_PAUSE_LOCKOURTURN_UI_MODE = 17,
43 	LOCK_PAUSE_ITEM_PICKUP = 18,
44 	LOCK_PAUSE_DOOR_OPEN = 19,
45 	LOCK_PAUSE_START_HELI = 20,
46 	LOCK_PAUSE_SECTOR_EXIT = 21
47 };
48 
49 //PAUSE FEATURES
50 //Pauses and unpauses the game.  It sets and clears a flag which preserves the time rate.
51 void PauseGame(void);
52 void UnPauseGame(void);
53 BOOLEAN GamePaused(void);
54 void LockPauseState(LockPauseReason);
55 void UnLockPauseState(void);
56 BOOLEAN PauseStateLocked(void);
57 
58 //USING HIGH RESOLUTION TIME RATE MANIPULATION/ACCESS
59 //Allows external code to change the time rate.
60 void SetGameHoursPerSecond( UINT32 uiGameHoursPerSecond );
61 void SetGameMinutesPerSecond( UINT32 uiGameMinutesPerSecond );
62 //Allows access to the current time rate.
63 UINT32 GetGameSecondsPerFrame(void);
64 void RenderPausedGameBox( void );
65 
66 
67 void StopTimeCompression( void );
68 void StartTimeCompression( void );
69 BOOLEAN IsTimeBeingCompressed( void );	// returns FALSE if time isn't currently being compressed for ANY reason (various pauses, etc.)
70 BOOLEAN IsTimeCompressionOn( void );		// returns TRUE if the player currently wants time to be compressing
71 
72 //USING TIME COMPRESSION
73 //Allows the setting/changing/access of time rate via predefined compression values.
74 //These functions change the index in giTimeCompressSpeeds which aren't in any
75 //particular mathematical pattern.  The higher the index, the faster the time is processed
76 //per frame.  These functions have their limits, so game time will also be between
77 //TIME_COMPRESS_X1 to TIME_COMPRESS_X8 based in the laptop time compression.
78 void SetGameTimeCompressionLevel( UINT32 uiCompressionRate );
79 void DecreaseGameTimeCompressionRate(void);
80 void IncreaseGameTimeCompressionRate(void);
81 
82 //time compression defines
83 enum
84 {
85 	NOT_USING_TIME_COMPRESSION = -1,
86 	TIME_COMPRESS_X0,
87 	TIME_COMPRESS_X1,
88 	TIME_COMPRESS_5MINS,
89 	TIME_COMPRESS_30MINS,
90 	TIME_COMPRESS_60MINS,
91 	TIME_SUPER_COMPRESS,
92 	NUM_TIME_COMPRESS_SPEEDS
93 };
94 
95 
96 //dereferenced with the above enumerations to provide the actual time compression rate.
97 extern INT32 giTimeCompressSpeeds[ NUM_TIME_COMPRESS_SPEEDS ];
98 
99 
100 #define STARTING_TIME		( ( 1 * NUM_SEC_IN_HOUR ) + ( 0 * NUM_SEC_IN_MIN ) + NUM_SEC_IN_DAY ) // 1am
101 #define FIRST_ARRIVAL_DELAY	( ( 6 * NUM_SEC_IN_HOUR ) + ( 0 * NUM_SEC_IN_MIN ) ) // 7am ( 6hours later)
102 
103 #define WORLDTIMESTR		gswzWorldTimeStr
104 
105 
106 // compress mode now in use
107 extern INT32 giTimeCompressMode;
108 
109 
110 enum
111 {
112 	WARPTIME_NO_PROCESSING_OF_EVENTS,
113 	WARPTIME_PROCESS_EVENTS_NORMALLY,
114 	WARPTIME_PROCESS_TARGET_TIME_FIRST,
115 };
116 void WarpGameTime( UINT32 uiAdjustment, UINT8 ubWarpCode );
117 
118 
119 void AdvanceToNextDay(void);
120 
121 //This function is called once per cycle in the game loop.  This determine how often the clock should be
122 //as well as how much to update the clock by.
123 void UpdateClock(void);
124 
125 
126 extern ST::string gswzWorldTimeStr; //Day 99, 23:55
127 
128 extern	UINT32			guiDay;
129 extern	UINT32			guiHour;
130 extern	UINT32			guiMin;
131 
132 //Advanced function used by certain event callbacks.  In the case where time is warped, certain event
133 //need to know how much time was warped since the last query to the event list.
134 //This function returns that value
135 extern UINT32 guiTimeOfLastEventQuery;
136 
137 //This value represents the time that the sector was loaded.  If you are in sector A9, and leave
138 //the game clock at that moment will get saved into the temp file associated with it.  The next time you
139 //enter A9, this value will contain that time.  Used for scheduling purposes.
140 extern UINT32				guiTimeCurrentSectorWasLastLoaded;
141 
142 // is the current pause state due to the player?
143 extern BOOLEAN gfPauseDueToPlayerGamePause;
144 
145 // we've just clued up a pause by the player, the tactical screen will need a full one shot refresh to remove a 2 frame update problem
146 extern BOOLEAN gfJustFinishedAPause;
147 
148 extern BOOLEAN gfResetAllPlayerKnowsEnemiesFlags;
149 
150 extern UINT32 guiLockPauseStateLastReasonId;
151 
152 UINT32 GetWorldTotalMin(void);
153 UINT32 GetWorldTotalSeconds(void);
154 UINT32 GetWorldHour(void);
155 UINT32 GetWorldDay(void);
156 UINT32 GetWorldMinutesInDay(void);
157 UINT32 GetWorldDayInSeconds(void);
158 UINT32 GetWorldDayInMinutes(void);
159 UINT32 GetFutureDayInMinutes( UINT32 uiDay );
160 UINT32 GetMidnightOfFutureDayInMinutes( UINT32 uiDay );
161 
162 BOOLEAN DayTime(void);
163 BOOLEAN NightTime(void);
164 
165 void InitNewGameClock(void);
166 
167 void GotoNextTimeOfDay( UINT32 uiTOD );
168 
169 void RenderClock(void);
170 
171 //IMPORTANT FUNCTION:  Used whenever an event or situation is deemed important enough to cancel the
172 //further processing of time in this current time slice!  This can only be used inside of event callback
173 //functions -- otherwise, it'll be ignored and automatically reset.  An example of this would be when arriving
174 //in a new sector and being prompted to attack or retreat.
175 void InterruptTime(void);
176 void PauseTimeForInterupt(void);
177 
178 extern BOOLEAN gfTimeInterrupt;
179 
180 bool DidGameJustStart();
181 
182 void SaveGameClock(HWFILE, BOOLEAN fGamePaused, BOOLEAN fLockPauseState);
183 void LoadGameClock(HWFILE);
184 
185 // time compress flag stuff
186 BOOLEAN HasTimeCompressOccured( void );
187 void ResetTimeCompressHasOccured( void );
188 void SetFactTimeCompressHasOccured( void );
189 
190 
191 // create mouse region to pause game
192 void CreateMouseRegionForPauseOfClock(void);
193 
194 // remove mouse region for pause game
195 void RemoveMouseRegionForPauseOfClock( void );
196 
197 // handle pausing and unpausing of game
198 void HandlePlayerPauseUnPauseOfGame( void );
199 
200 void ClearTacticalStuffDueToTimeCompression( void );
201 
202 extern BOOLEAN gfGamePaused;
203 extern BOOLEAN gfLockPauseState;
204 
205 #endif
206