1 | /* |
1 | /* |
2 | * CrossFire, A Multiplayer game for X-windows |
2 | * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
3 | * |
3 | * |
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
5 | * Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * This program is free software; you can redistribute it and/or modify |
8 | * Crossfire TRT is free software: you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
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 |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * (at your option) any later version. |
11 | * (at your option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
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 |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
|
21 | * |
20 | * |
22 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
21 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
23 | */ |
22 | */ |
24 | |
23 | |
25 | #include <global.h> |
24 | #include <global.h> |
26 | #include <funcpoint.h> |
25 | #include <funcpoint.h> |
27 | #include <tod.h> |
26 | #include <tod.h> |
… | |
… | |
32 | #include <sys/time.h> |
31 | #include <sys/time.h> |
33 | |
32 | |
34 | /* |
33 | /* |
35 | * Gloabal variables: |
34 | * Gloabal variables: |
36 | */ |
35 | */ |
37 | long pticks; |
36 | tick_t pticks; |
38 | |
37 | |
39 | static const char *season_name[5] = { |
38 | static const char *season_name[5] = { |
40 | "New Year", |
39 | "New Year", |
41 | "Growth", |
40 | "Growth", |
42 | "Harvest", |
41 | "Harvest", |
… | |
… | |
75 | }; |
74 | }; |
76 | |
75 | |
77 | void |
76 | void |
78 | get_tod (timeofday_t * tod) |
77 | get_tod (timeofday_t * tod) |
79 | { |
78 | { |
80 | unsigned int todtick = runtime * (1. / RUNTIME_PER_HOUR); |
79 | unsigned int todtick = (unsigned int)(runtime * (1. / RUNTIME_PER_HOUR)); |
81 | |
80 | |
82 | tod->year = todtick / HOURS_PER_YEAR; |
81 | tod->year = todtick / HOURS_PER_YEAR; |
83 | tod->month = todtick / HOURS_PER_MONTH % MONTHS_PER_YEAR; |
82 | tod->month = todtick / HOURS_PER_MONTH % MONTHS_PER_YEAR; |
84 | tod->day = todtick % HOURS_PER_MONTH / DAYS_PER_MONTH; |
83 | tod->day = todtick % HOURS_PER_MONTH / DAYS_PER_MONTH; |
85 | tod->hour = todtick % HOURS_PER_DAY; |
84 | tod->hour = todtick % HOURS_PER_DAY; |
86 | tod->minute = (runtime - todtick * RUNTIME_PER_HOUR) * (60. / RUNTIME_PER_HOUR); |
85 | tod->minute = (int)((runtime - todtick * RUNTIME_PER_HOUR) * (60. / RUNTIME_PER_HOUR)); |
87 | |
86 | |
88 | tod->dayofweek = tod->day % DAYS_PER_WEEK; |
87 | tod->dayofweek = tod->day % DAYS_PER_WEEK; |
89 | tod->weekofmonth = tod->day / WEEKS_PER_MONTH; |
88 | tod->weekofmonth = tod->day / WEEKS_PER_MONTH; |
90 | tod->season = min (4, tod->month / 3); |
89 | tod->season = min (4, tod->month / 3); |
91 | } |
90 | } |
92 | |
91 | |
93 | void |
92 | void |
94 | print_tod (object *op) |
93 | print_tod (object *op) |
95 | { |
94 | { |
96 | timeofday_t tod; |
95 | timeofday_t tod; |
97 | |
|
|
98 | get_tod (&tod); |
96 | get_tod (&tod); |
99 | |
97 | |
100 | char todmsg [1024]; |
98 | char todmsg [1024]; |
101 | |
99 | |
102 | int day = tod.day + 1; |
100 | int day = tod.day + 1; |