1 |
/* |
/* |
2 |
$Id$ |
$Id$ |
3 |
|
|
4 |
Copyright (C) 2002/2003/2004 Kai Sterker <kaisterker@linuxgames.com> |
Copyright (C) 2002/2003/2004/2005 Kai Sterker <kaisterker@linuxgames.com> |
5 |
Part of the Adonthell Project http://adonthell.linuxgames.com |
Part of the Adonthell Project http://adonthell.linuxgames.com |
6 |
|
|
7 |
Adonthell is free software; you can redistribute it and/or modify |
Adonthell is free software; you can redistribute it and/or modify |
8 |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
9 |
the Free Software Foundation; either version 2 of the License, or |
the Free Software Foundation; either version 2 of the License, or |
10 |
(at your option) any later version. |
(at your option) any later version. |
11 |
|
|
12 |
Adonthell is distributed in the hope that it will be useful, |
Adonthell is distributed in the hope that it will be useful, |
13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
GNU General Public License for more details. |
GNU General Public License for more details. |
16 |
|
|
17 |
You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License |
18 |
along with Adonthell; if not, write to the Free Software |
along with Adonthell; if not, write to the Free Software |
19 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
20 |
*/ |
*/ |
21 |
|
|
22 |
/** |
/** |
23 |
* @file event/time_event.h |
* @file event/time_event.h |
24 |
* |
* |
25 |
* @author Kai Sterker |
* @author Kai Sterker |
26 |
* @brief Declares the time_event class. |
* @brief Declares the time_event class. |
27 |
*/ |
*/ |
28 |
|
|
29 |
#ifndef TIME_EVENT_H |
#ifndef TIME_EVENT_H |
30 |
#define TIME_EVENT_H |
#define TIME_EVENT_H |
31 |
|
|
32 |
#include "event/event.h" |
#include "event/event.h" |
33 |
|
|
34 |
namespace events |
namespace events |
35 |
{ |
{ |
36 |
/** |
/** |
37 |
* The time %event executes the attached script or callback at a certain |
* The time %event executes the attached script or callback at a certain |
38 |
* point in %game-time. This point can either be relative to the current |
* point in %game-time. This point can either be relative to the current |
39 |
* time, or absolute in time. In any case, this point should be in the |
* time, or absolute in time. In any case, this point should be in the |
40 |
* future. Time %event with an alarm time in the past will be triggered |
* future. Time %event with an alarm time in the past will be triggered |
41 |
* at once. |
* at once. |
42 |
*/ |
*/ |
43 |
class time_event : public event |
class time_event : public event |
44 |
{ |
{ |
45 |
public: |
public: |
46 |
/** |
/** |
47 |
* @name Initialization |
* @name Initialization |
48 |
*/ |
*/ |
49 |
//@{ |
//@{ |
50 |
|
|
51 |
/** |
/** |
52 |
* Create a new time %event. |
* Create a new time %event. |
53 |
* |
* |
54 |
* @param time The time when the %event should be raised. The string |
* @param time The time when the %event should be raised. The string |
55 |
* specifies week, day, hour, minute and 1/10 minute in the format |
* specifies week, day, hour, minute and 1/10 minute in the format |
56 |
* "<number>w<number>d<number>h<number>m<number>s". If a number is |
* "<number>w<number>d<number>h<number>m<number>s". If a number is |
57 |
* 0, it can be omitted. |
* 0, it can be omitted. |
58 |
* @param absolute Decides whether the given time is relative from now |
* @param absolute Decides whether the given time is relative from now |
59 |
* on, or an absolute time |
* on, or an absolute time |
60 |
*/ |
*/ |
61 |
time_event (const string & time, bool absolute = false); |
time_event (const string & time, bool absolute = false); |
62 |
|
|
63 |
#ifndef SWIG |
#ifndef SWIG |
64 |
/** |
/** |
65 |
* Standard constructor. |
* Standard constructor. |
66 |
*/ |
*/ |
67 |
time_event () |
time_event () : event () |
68 |
{ |
{ |
69 |
Type = TIME_EVENT; |
Repeat = 1; |
70 |
Repeat = 1; |
} |
71 |
} |
|
72 |
|
/** |
73 |
/** |
* Create a new time %event. This constructor is primarily used for |
74 |
* Create a new time %event. This constructor is primarily used for |
* raising time events. |
75 |
* raising time events. |
* |
76 |
* |
* @param time The "alarm" time in %gametime minutes. |
77 |
* @param time The "alarm" time in %gametime minutes. |
*/ |
78 |
*/ |
time_event (const u_int32 & time) : event () |
79 |
time_event (const u_int32 & time) |
{ |
80 |
{ |
Time = time; |
81 |
Type = TIME_EVENT; |
Repeat = 1; |
82 |
Time = time; |
} |
83 |
Repeat = 1; |
#endif // SWIG |
84 |
} |
|
85 |
#endif // SWIG |
/** |
86 |
|
* Set whether the %event should be raised at fixed intervals. |
87 |
/** |
* |
88 |
* Set whether the %event should be raised at fixed intervals. |
* @param interval The time between two occurences of the %event. |
89 |
* |
* @param count The number of times the %event shall be repeated. |
90 |
* @param interval The time between two occurences of the %event. |
* Specify -1 to repeat it an unlimited number of times. |
91 |
* @param count The number of times the %event shall be repeated. |
*/ |
92 |
* Specify -1 to repeat it an unlimited number of times. |
void set_repeat (const string & interval, s_int32 count = -1); |
93 |
*/ |
//@} |
94 |
void set_repeat (const string & interval, s_int32 count = -1); |
|
95 |
//@} |
/** |
96 |
|
* @name Event Handling |
97 |
/** |
*/ |
98 |
* @name Event Handling |
//@{ |
99 |
*/ |
/** |
100 |
//@{ |
* Compare two time events for equality. |
101 |
/** |
* |
102 |
* Compare two time events for equality. |
* @param e The time event to compare this to. |
103 |
* |
* @return <b>True</b> if the two events equal, <b>false</b> otherwise. |
104 |
* @param evnt The time event to compare this to. |
*/ |
105 |
* @return <b>True</b> if the two events equal, <b>false</b> otherwise. |
bool equals (const event * e) |
106 |
*/ |
{ |
107 |
bool equals (const event * e) |
return Time <= ((time_event *) e)->time (); |
108 |
{ |
} |
109 |
return Time <= ((time_event *) e)->time (); |
|
110 |
} |
#ifndef SWIG |
111 |
|
/** |
112 |
#ifndef SWIG |
* When time events repeat, their alarm time is increased by the |
113 |
/** |
* amount specified with time_event::set_repeat (). |
114 |
* When time events repeat, their alarm time is increased by the |
*/ |
115 |
* amount specified with time_event::set_repeat (). |
void do_repeat (); |
116 |
*/ |
|
117 |
void do_repeat (); |
/** |
118 |
#endif // SWIG |
* Get name of %event. |
119 |
//@} |
* @return the string "time_event"; |
120 |
|
*/ |
121 |
/** |
const char* name () const |
122 |
* @name Loading / Saving |
{ |
123 |
*/ |
return "time_event"; |
124 |
//@{ |
} |
125 |
|
#endif // SWIG |
126 |
/** |
//@} |
127 |
* Saves the basic %event %data (such as the type or script data) |
|
128 |
* to a stream. |
/** |
129 |
* |
* @name Loading / Saving |
130 |
* @param out stream where to save the %event. |
*/ |
131 |
*/ |
//@{ |
132 |
void put_state (base::flat& out) const; |
|
133 |
|
/** |
134 |
/** |
* Saves the basic %event %data (such as the type or script data) |
135 |
* Loads the basic %event %date from a stream. |
* to a stream. |
136 |
* |
* |
137 |
* @param in stream to load the %event from. |
* @param out stream where to save the %event. |
138 |
* @return \e true if the %event could be loaded, \e false otherwise |
*/ |
139 |
*/ |
void put_state (base::flat& out) const; |
140 |
bool get_state (base::flat& in); |
|
141 |
|
/** |
142 |
//@} |
* Loads the basic %event %date from a stream. |
143 |
|
* |
144 |
/** |
* @param in stream to load the %event from. |
145 |
* Get the event's "alarm" time, i.e. the time when it needs to be |
* @return \e true if the %event could be loaded, \e false otherwise |
146 |
* executed. |
*/ |
147 |
* |
bool get_state (base::flat& in); |
148 |
* @return the "alarm" time in %gametime seconds. |
|
149 |
*/ |
//@} |
150 |
u_int32 time () const |
|
151 |
{ |
/** |
152 |
return Time; |
* Get the event's "alarm" time, i.e. the time when it needs to be |
153 |
} |
* executed. |
154 |
|
* |
155 |
#ifndef SWIG |
* @return the "alarm" time in %gametime seconds. |
156 |
/** |
*/ |
157 |
* Allow %event to be passed as python argument |
u_int32 time () const |
158 |
*/ |
{ |
159 |
GET_TYPE_NAME(event::time_event) |
return Time; |
160 |
#endif |
} |
161 |
|
|
162 |
private: |
#ifndef SWIG |
163 |
/// time when the event shall be triggered |
/** |
164 |
u_int32 Time; |
* Allow %event to be passed as python argument |
165 |
|
*/ |
166 |
/// time that lies between two occurances of the event |
GET_TYPE_NAME(events::time_event) |
167 |
u_int32 Interval; |
#endif |
168 |
|
|
169 |
/// whether the alarm time is relative or absolute |
private: |
170 |
bool Absolute; |
/// time when the event shall be triggered |
171 |
}; |
u_int32 Time; |
172 |
} |
|
173 |
|
/// time that lies between two occurances of the event |
174 |
#endif // TIME_EVENT_H |
u_int32 Interval; |
175 |
|
|
176 |
|
/// whether the alarm time is relative or absolute |
177 |
|
bool Absolute; |
178 |
|
}; |
179 |
|
} |
180 |
|
|
181 |
|
#endif // TIME_EVENT_H |