| 1 |
elmex |
1.1 |
/* |
| 2 |
|
|
CrossFire, A Multiplayer game for X-windows |
| 3 |
|
|
|
| 4 |
pippijn |
1.8 |
Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
| 5 |
elmex |
1.1 |
Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
| 6 |
|
|
Copyright (C) 1992 Frank Tore Johansen |
| 7 |
|
|
|
| 8 |
|
|
This program is free software; you can redistribute it and/or modify |
| 9 |
|
|
it under the terms of the GNU General Public License as published by |
| 10 |
|
|
the Free Software Foundation; either version 2 of the License, or |
| 11 |
|
|
(at your option) any later version. |
| 12 |
|
|
|
| 13 |
|
|
This program is distributed in the hope that it will be useful, |
| 14 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
|
|
GNU General Public License for more details. |
| 17 |
|
|
|
| 18 |
|
|
You should have received a copy of the GNU General Public License |
| 19 |
|
|
along with this program; if not, write to the Free Software |
| 20 |
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 21 |
|
|
|
| 22 |
root |
1.5 |
The authors can be reached via e-mail at <crossfire@schmorp.de> |
| 23 |
elmex |
1.1 |
*/ |
| 24 |
|
|
|
| 25 |
|
|
#include <global.h> |
| 26 |
|
|
#include <funcpoint.h> |
| 27 |
|
|
#include <tod.h> |
| 28 |
|
|
|
| 29 |
pippijn |
1.6 |
#include <stdio.h> |
| 30 |
|
|
#include <sys/types.h> |
| 31 |
|
|
#include <sys/time.h> |
| 32 |
elmex |
1.1 |
|
| 33 |
|
|
/* |
| 34 |
|
|
* Gloabal variables: |
| 35 |
|
|
*/ |
| 36 |
|
|
|
| 37 |
|
|
long psaveind; |
| 38 |
|
|
long pticks; |
| 39 |
|
|
|
| 40 |
root |
1.4 |
const char *season_name[] = { |
| 41 |
|
|
"The Season of New Year", |
| 42 |
|
|
"The Season of Growth", |
| 43 |
|
|
"The Season of Harvest", |
| 44 |
|
|
"The Season of Decay", |
| 45 |
|
|
"The Season of the Blizzard", |
| 46 |
|
|
"\n" |
| 47 |
elmex |
1.1 |
}; |
| 48 |
|
|
|
| 49 |
|
|
const char *weekdays[DAYS_PER_WEEK] = { |
| 50 |
root |
1.4 |
"the Day of the Moon", |
| 51 |
|
|
"the Day of the Bull", |
| 52 |
|
|
"the Day of the Deception", |
| 53 |
|
|
"the Day of Thunder", |
| 54 |
|
|
"the Day of Freedom", |
| 55 |
|
|
"the Day of the Great Gods", |
| 56 |
|
|
"the Day of the Sun" |
| 57 |
elmex |
1.1 |
}; |
| 58 |
|
|
|
| 59 |
|
|
const char *month_name[MONTHS_PER_YEAR] = { |
| 60 |
root |
1.4 |
"Month of Winter", /* 0 */ |
| 61 |
|
|
"Month of the Ice Dragon", |
| 62 |
|
|
"Month of the Frost Giant", |
| 63 |
|
|
"Month of Valriel", |
| 64 |
|
|
"Month of Lythander", |
| 65 |
|
|
"Month of the Harvest", |
| 66 |
|
|
"Month of Gaea", |
| 67 |
|
|
"Month of Futility", |
| 68 |
|
|
"Month of the Dragon", |
| 69 |
|
|
"Month of the Sun", |
| 70 |
|
|
"Month of the Great Infernus", |
| 71 |
|
|
"Month of Ruggilli", |
| 72 |
|
|
"Month of the Dark Shades", |
| 73 |
|
|
"Month of the Devourers", |
| 74 |
|
|
"Month of Sorig", |
| 75 |
|
|
"Month of the Ancient Darkness", |
| 76 |
|
|
"Month of Gorokh" |
| 77 |
elmex |
1.1 |
}; |
| 78 |
|
|
|
| 79 |
|
|
extern unsigned long todtick; |
| 80 |
|
|
|
| 81 |
|
|
void |
| 82 |
root |
1.4 |
get_tod (timeofday_t * tod) |
| 83 |
elmex |
1.1 |
{ |
| 84 |
root |
1.4 |
tod->year = todtick / HOURS_PER_YEAR; |
| 85 |
|
|
tod->month = (todtick / HOURS_PER_MONTH) % MONTHS_PER_YEAR; |
| 86 |
|
|
tod->day = (todtick % HOURS_PER_MONTH) / DAYS_PER_MONTH; |
| 87 |
|
|
tod->dayofweek = tod->day % DAYS_PER_WEEK; |
| 88 |
|
|
tod->hour = todtick % HOURS_PER_DAY; |
| 89 |
|
|
tod->minute = (pticks % PTICKS_PER_CLOCK) / (PTICKS_PER_CLOCK / 58); |
| 90 |
elmex |
1.1 |
if (tod->minute > 58) |
| 91 |
root |
1.4 |
tod->minute = 58; /* it's imprecise at best anyhow */ |
| 92 |
|
|
tod->weekofmonth = tod->day / WEEKS_PER_MONTH; |
| 93 |
elmex |
1.1 |
if (tod->month < 3) |
| 94 |
|
|
tod->season = 0; |
| 95 |
|
|
else if (tod->month < 6) |
| 96 |
|
|
tod->season = 1; |
| 97 |
|
|
else if (tod->month < 9) |
| 98 |
|
|
tod->season = 2; |
| 99 |
|
|
else if (tod->month < 12) |
| 100 |
|
|
tod->season = 3; |
| 101 |
|
|
else |
| 102 |
|
|
tod->season = 4; |
| 103 |
|
|
} |
| 104 |
|
|
|
| 105 |
|
|
void |
| 106 |
root |
1.4 |
print_tod (object *op) |
| 107 |
elmex |
1.1 |
{ |
| 108 |
|
|
timeofday_t tod; |
| 109 |
|
|
const char *suf; |
| 110 |
|
|
int day; |
| 111 |
|
|
|
| 112 |
root |
1.4 |
get_tod (&tod); |
| 113 |
|
|
sprintf (errmsg, "It is %d minute%s past %d o'clock %s, on %s", |
| 114 |
|
|
tod.minute + 1, ((tod.minute + 1 < 2) ? "" : "s"), |
| 115 |
|
|
((tod.hour % 14 == 0) ? 14 : ((tod.hour) % 14)), ((tod.hour >= 14) ? "pm" : "am"), weekdays[tod.dayofweek]); |
| 116 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, errmsg); |
| 117 |
elmex |
1.1 |
|
| 118 |
|
|
day = tod.day + 1; |
| 119 |
|
|
if (day == 1 || ((day % 10) == 1 && day > 20)) |
| 120 |
|
|
suf = "st"; |
| 121 |
|
|
else if (day == 2 || ((day % 10) == 2 && day > 20)) |
| 122 |
|
|
suf = "nd"; |
| 123 |
|
|
else if (day == 3 || ((day % 10) == 3 && day > 20)) |
| 124 |
|
|
suf = "rd"; |
| 125 |
|
|
else |
| 126 |
|
|
suf = "th"; |
| 127 |
root |
1.4 |
sprintf (errmsg, "The %d%s Day of the %s, Year %d", day, suf, month_name[tod.month], tod.year + 1); |
| 128 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, errmsg); |
| 129 |
elmex |
1.1 |
|
| 130 |
root |
1.4 |
sprintf (errmsg, "Time of Year: %s", season_name[tod.season]); |
| 131 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, errmsg); |
| 132 |
elmex |
1.1 |
} |
| 133 |
|
|
|