28 #include <sys/types.h> 54 "The Season of New Year",
55 "The Season of Growth",
56 "The Season of Harvest",
57 "The Season of Decay",
58 "The Season of the Blizzard",
64 "the Day of the Moon",
65 "the Day of the Bull",
66 "the Day of the Deception",
69 "the Day of the Great Gods",
76 "Month of the Ice Dragon",
77 "Month of the Frost Giant",
80 "Month of the Harvest",
83 "Month of the Dragon",
85 "Month of the Great Infernus",
87 "Month of the Dark Shades",
88 "Month of the Devourers",
90 "Month of the Ancient Darkness",
145 clock_gettime(CLOCK_MONOTONIC, &
game_time);
167 double sec = difftime(end->tv_sec, start->tv_sec);
168 long nsec = end->tv_nsec - start->tv_nsec;
169 return (
long)(sec * 1e6 + nsec / 1e3);
176 long nsec_sum = time->tv_nsec + usec * 1e3;
177 time->tv_sec += nsec_sum / 1e9;
178 time->tv_nsec = nsec_sum % (long)1e9;
191 clock_gettime(CLOCK_MONOTONIC, &now);
193 if (time_since_last_sleep >= 0)
200 clock_gettime(CLOCK_MONOTONIC, &
game_time);
231 else if (tod->
month < 6)
233 else if (tod->
month < 9)
235 else if (tod->
month < 12)
242 else if (tod->
hour < 8)
244 else if (tod->
hour < 13)
246 else if (tod->
hour < 15)
248 else if (tod->
hour < 20)
250 else if (tod->
hour < 23)
274 if (day == 1 || ((day%10) == 1 && day > 20))
276 else if (day == 2 || ((day%10) == 2 && day > 20))
278 else if (day == 3 || ((day%10) == 3 && day > 20))
284 "The %d%s Day of the %s, Year %d",
299 int tot = 0, long_count = 0;
300 uint32_t maxt = 0, mint = 99999999, i;
309 "Statistics for last %d ticks:\n\tmin/avg/max = %d/%d/%d ms per tick",
315 "\tticks longer than %d ms = %d (%d%%)",
tick_duration / 1000,
319 "Time last %d ticks:",
335 "avg time=%dms max time=%dms min time=%dms",
340 "ticks longer than max time (%dms) = %d (%d%%)",
350 clock_gettime(CLOCK_REALTIME, &now);
371 snprintf(buf, bufsize,
"%d minute%s past %d o'clock %s",
373 tod->
minute+1 < 2 ?
"" :
"s",
374 tod->
hour%14 == 0 ? 14 : tod->
hour%14,
375 tod->
hour >= 14 ?
"pm" :
"am");
const char * get_periodofday(const int index)
give access to weekday names
const char * get_month_name(const int index)
give access to month names
unsigned long todtick
Game world time, in in-game hours.
Defines for the ingame clock, ticks management and weather system.
void draw_ext_info_format(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format,...) PRINTF_ARGS(6
static uint32_t process_tot_mtime
?
long get_sleep_remaining()
Represents the ingame time.
void time_info(object *op)
Players wants to know the time.
Global type definitions and header inclusions.
long timespec_diff(struct timespec *end, struct timespec *start)
Return the difference between two timespec's in microseconds.
#define MSG_TYPE_COMMAND
Responses to commands, eg, who.
static uint32_t psaveind
Index in process_utime_save.
static const char *const season_name[SEASONS_PER_YEAR+1]
Ingame seasons.
void set_tick_duration(long t)
Sets the tick duration.
#define QUERY_FLAG(xyz, p)
#define PBUFLEN
Size of history buffer.
#define MAX_TIME
If you feel the game is too fast or too slow, change MAX_TIME.
static void log_time(uint32_t process_utime)
Adds time to our history list.
static uint32_t process_utime_long_count
Number of times server couldn't keep up with game time (tried to sleep for a negative time) ...
static const char *const periodsofday[PERIODS_PER_DAY]
uint32_t pticks
Number of ticks since time reset.
#define FLAG_WIZ
Object has special privilegies.
long seconds(void)
Return wall clock time in seconds.
#define MSG_TYPE_COMMAND_DEBUG
Various debug type commands.
static uint32_t process_min_utime
Shortest cycle time.
uint32_t tick_duration
Gloabal variables:
static struct timespec game_time
const char * time_format_time(const timeofday_t *tod, char *buf, size_t bufsize)
Formats a timestamp in Crossfire time.
void get_tod(timeofday_t *tod)
Computes the ingame time of the day.
static uint32_t process_max_utime
Longest cycle time.
static const char *const weekdays[DAYS_PER_WEEK]
Days of the week.
void reset_sleep(void)
Initialise all variables used in the timing routines.
static void print_tod(object *op)
Prints the time.
#define MSG_TYPE_COMMAND_INFO
Generic info: resistances, etc.
#define NDI_UNIQUE
Print immediately, don't buffer.
const char * get_season_name(const int index)
give access to season names
static void timespec_add(struct timespec *time, long usec)
Add 'usec' microseconds to the given timespec.
float ticks_to_seconds(int ticks)
static uint32_t process_utime_save[PBUFLEN]
Historic data.
#define PTICKS_PER_CLOCK
Number of ticks per in-game hour.
static const char *const month_name[MONTHS_PER_YEAR]
Months.
unsigned int tick_length(float seconds)
Calculate the number of ticks that correspond to real time.
const char * get_weekday(const int index)
give access to weekday names