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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
|
// GameTimer.cpp: implementation of the CGameTimer class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "aime_w32.h"
#include "GameTimer.h"
#include "global.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CGameTimer::CGameTimer()
{
input_polls = 0;
initial_time.GetCurrentTime();
last_heal_players = last_heal_mobiles = last_level =
last_magic_players = last_endur_players = 0;
last_second = 0;
}
CGameTimer::~CGameTimer()
{
}
BOOL CGameTimer::handle_timer()
{
// If it is time to cycle the game (each second)
if (the_config.pollspersec <= input_polls)
{
input_polls = 0;
mainstruct->cycle_world();
}
mainstruct->check_players();
mainstruct->check_builders();
handle_events();
mainstruct->handle_quits();
input_polls++;
return TRUE;
}
int CGameTimer::init_times()
{
return 1;
}
/***********************************************************************
** plr_timesincehealed - the seconds since the last player heal
**
**
***********************************************************************/
time_t CGameTimer::plr_TimeSinceHealed()
{
if (!last_heal_players)
return the_config.secs_player_heal;
return (time(0) - last_heal_players);
}
/***********************************************************************
** mob_timesincehealed - the seconds since the last mobile heal
**
**
***********************************************************************/
time_t CGameTimer::mob_TimeSinceHealed()
{
if (!last_heal_mobiles)
return the_config.secs_mobile_heal;
return (time(0) - last_heal_mobiles);
}
/***********************************************************************
** plr_timesinceendur - the seconds since the last player endurance up
**
**
***********************************************************************/
time_t CGameTimer::plr_TimeSinceEndur()
{
if (!last_endur_players)
return the_config.secs_player_endur;
return (time(0) - last_endur_players);
}
/***********************************************************************
** plr_timesincelevel - the seconds since the last level upgrade check
**
**
***********************************************************************/
time_t CGameTimer::plr_TimeSinceLevel()
{
if (!last_level)
return the_config.secs_level_check;
return (time(0) - last_level);
}
/***********************************************************************
** plr_timesincemagic - the seconds since the last player magic up
**
**
***********************************************************************/
time_t CGameTimer::plr_TimeSinceMagic()
{
if (!last_magic_players)
return the_config.secs_player_magic;
return (time(0) - last_magic_players);
}
/***********************************************************************
** handle_events - handles any events that need to be executed right
** now
**
** Parameters: None
**
** Returns: 1 for success, -1 for failure
**
***********************************************************************/
int CGameTimer::handle_events()
{
float time_num[5] = {
( float )1,
( float )0.1,
( float )0.3,
( float )0.55,
( float ).65
};
char *time_change[5] = {
"The sky begins to lighten with the coming of the sun.\n",
"The sun rises above the horizon.\n",
"The sun has peaked in the sky.\n",
"The sun disappears beneath the horizon.\n",
"The last bit of light vanishes, leaving a dark sky.\n"};
if (time(0) == last_second)
return 0;
/* a new second is upon us, handle second events first */
mainstruct->cycle_world();
last_second = time(0);
/* next handle possible time of day progressions */
if ((last_second - start_day) >
(time_num[mainstruct->get_tod()] * the_config.secs_in_day))
{
mainstruct->send_all_outside(time_change[mainstruct->get_tod()]);
mainstruct->increment_tod();
if (mainstruct->get_tod() == Dawn)
start_day = last_second;
}
/* reset these heal times, since we probably already healed */
if ((time(0) - last_heal_players) >= the_config.secs_player_heal)
last_heal_players = time(0);
if ((time(0) - last_heal_mobiles) >= the_config.secs_mobile_heal)
last_heal_mobiles = time(0);
if ((time(0) - last_magic_players) >= the_config.secs_player_magic)
last_magic_players = time(0);
if ((time(0) - last_endur_players) >= the_config.secs_player_endur)
last_endur_players = time(0);
if ((time(0) - last_level) >= the_config.secs_level_check)
last_level = time(0);
return 1;
}
/***********************************************************************
** set_tod_time - sets the appropriate time for tod if we are manually
** changing tod, so it doesn't go back to where it was
**
** Parameters: the_time - the time of day we are setting it to
**
***********************************************************************/
void CGameTimer::set_tod_time(TimeOfDay the_time)
{
float time_num[5] = {
( float )1,
( float )0.1,
( float )0.3,
( float )0.55,
( float ).65
};
long span;
int new_time;
new_time = ((int) the_time) - 1;
if (new_time == -1)
new_time = 4;
span = (long) (time_num[new_time] * the_config.secs_in_day);
start_day = last_second - span;
}
|