/[adonthell]/adonthell/src/event/time_event.h
ViewVC logotype

Diff of /adonthell/src/event/time_event.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by ksterker, Tue Mar 8 09:41:47 2005 UTC revision 1.6 by ksterker, Fri Jun 3 17:29:13 2005 UTC
# Line 1  Line 1 
1  /*  /*
2     $Id$     $Id$
3    
4     Copyright (C) 2002/2003/2004/2005 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 () : event ()          time_event () : event ()
68          {          {
69              Repeat = 1;              Repeat = 1;
70          }          }
71                    
72          /**          /**
73           * Create a new time %event. This constructor is primarily used for           * Create a new time %event. This constructor is primarily used for
74           * raising time events.           * raising time events.
75           *           *
76           * @param time The "alarm" time in %gametime minutes.           * @param time The "alarm" time in %gametime minutes.
77           */           */
78          time_event (const u_int32 & time) : event ()          time_event (const u_int32 & time) : event ()
79          {          {
80              Time = time;              Time = time;
81              Repeat = 1;              Repeat = 1;
82          }          }
83  #endif // SWIG  #endif // SWIG
84                    
85          /**          /**
86           * Set whether the %event should be raised at fixed intervals.           * Set whether the %event should be raised at fixed intervals.
87           *           *
88           * @param interval The time between two occurences of the %event.           * @param interval The time between two occurences of the %event.
89           * @param count The number of times the %event shall be repeated.           * @param count The number of times the %event shall be repeated.
90           *      Specify -1 to repeat it an unlimited number of times.           *      Specify -1 to repeat it an unlimited number of times.
91           */           */
92          void set_repeat (const string & interval, s_int32 count = -1);          void set_repeat (const string & interval, s_int32 count = -1);
93          //@}          //@}
94                    
95          /**          /**
96           * @name Event Handling           * @name Event Handling
97           */           */
98          //@{          //@{
99          /**          /**
100           * Compare two time events for equality.           * Compare two time events for equality.
101           *           *
102           * @param e The time event to compare this to.           * @param e The time event to compare this to.
103           * @return <b>True</b> if the two events equal, <b>false</b> otherwise.           * @return <b>True</b> if the two events equal, <b>false</b> otherwise.
104           */           */
105          bool equals (const event * e)          bool equals (const event * e)
106          {          {
107              return Time <= ((time_event *) e)->time ();              return Time <= ((time_event *) e)->time ();
108          }          }
109    
110  #ifndef SWIG          #ifndef SWIG        
111          /**          /**
112           * When time events repeat, their alarm time is increased by the           * When time events repeat, their alarm time is increased by the
113           * amount specified with time_event::set_repeat ().           * amount specified with time_event::set_repeat ().
114           */           */
115          void do_repeat ();          void do_repeat ();
116    
117          /**          /**
118           * Get name of %event.           * Get name of %event.
119           * @return the string "time_event";           * @return the string "time_event";
120           */           */
121          const char* name () const          const char* name () const
122          {          {
123              return "time_event";              return "time_event";
124          }          }
125  #endif // SWIG  #endif // SWIG
126          //@}          //@}
127                    
128          /**          /**
129           * @name Loading / Saving           * @name Loading / Saving
130           */           */
131          //@{          //@{
132                    
133          /**          /**
134           * Saves the basic %event %data (such as the type or script data)           * Saves the basic %event %data (such as the type or script data)
135           * to a stream.           * to a stream.
136           *           *
137           * @param out stream where to save the %event.           * @param out stream where to save the %event.
138           */           */
139          void put_state (base::flat& out) const;          void put_state (base::flat& out) const;
140                    
141          /**          /**
142           * Loads the basic %event %date from a stream.           * Loads the basic %event %date from a stream.
143           *           *
144           * @param in stream to load the %event from.           * @param in stream to load the %event from.
145           * @return \e true if the %event could be loaded, \e false otherwise           * @return \e true if the %event could be loaded, \e false otherwise
146           */           */
147          bool get_state (base::flat& in);          bool get_state (base::flat& in);
148            
149          //@}          //@}
150            
151          /**          /**
152           * Get the event's "alarm" time, i.e. the time when it needs to be           * Get the event's "alarm" time, i.e. the time when it needs to be
153           * executed.           * executed.
154           *           *
155           * @return the "alarm" time in %gametime seconds.           * @return the "alarm" time in %gametime seconds.
156           */           */
157          u_int32 time () const          u_int32 time () const
158          {          {
159              return Time;              return Time;
160          }          }
161    
162  #ifndef SWIG  #ifndef SWIG
163          /**          /**
164           * Allow %event to be passed as python argument           * Allow %event to be passed as python argument
165           */           */
166          GET_TYPE_NAME(events::time_event)          GET_TYPE_NAME(events::time_event)
167  #endif  #endif
168    
169      private:      private:
170          /// time when the event shall be triggered          /// time when the event shall be triggered
171          u_int32 Time;          u_int32 Time;
172            
173          /// time that lies between two occurances of the event          /// time that lies between two occurances of the event
174          u_int32 Interval;          u_int32 Interval;
175                    
176          /// whether the alarm time is relative or absolute          /// whether the alarm time is relative or absolute
177          bool Absolute;          bool Absolute;
178      };      };
179  }  }
180    
181  #endif // TIME_EVENT_H  #endif // TIME_EVENT_H

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26