1 |
/* |
/* |
2 |
$Id$ |
$Id$ |
3 |
|
|
4 |
Copyright (C) 2000/2001/2002/2003/2004/2005 Kai Sterker |
Copyright (C) 2000/2001/2002/2003/2004/2005 Kai Sterker |
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/event.h |
* @file event/event.h |
24 |
* @author Kai Sterker <kaisterker@linuxgames.com> |
* @author Kai Sterker <kaisterker@linuxgames.com> |
25 |
* |
* |
26 |
* @brief Declares the %event class. |
* @brief Declares the %event class. |
27 |
* |
* |
28 |
*/ |
*/ |
29 |
|
|
30 |
#ifndef EVENT_EVENT_H |
#ifndef EVENT_EVENT_H |
31 |
#define EVENT_EVENT_H |
#define EVENT_EVENT_H |
32 |
|
|
33 |
#include "base/flat.h" |
#include "base/flat.h" |
34 |
|
|
35 |
/** |
/** |
36 |
* Support for various events used to drive the game world and the plot. |
* Support for various events used to drive the game world and the plot. |
37 |
*/ |
*/ |
38 |
namespace events |
namespace events |
39 |
{ |
{ |
40 |
#ifndef SWIG |
#ifndef SWIG |
41 |
/** |
/** |
42 |
* Directory where %event scripts reside. |
* Directory where %event scripts reside. |
43 |
*/ |
*/ |
44 |
#define EVENTS_DIR "game_events." |
#define EVENTS_DIR "game_events." |
45 |
#endif // SWIG |
#endif // SWIG |
46 |
|
|
47 |
/** |
/** |
48 |
* Base class for events. You can create your own %event types that can |
* Base class for events. You can create your own %event types that can |
49 |
* be handled by the event_list and event_handler by inheriting from |
* be handled by the event_list and event_handler by inheriting from |
50 |
* this class. |
* this class. |
51 |
* |
* |
52 |
* Events are used to notify when certain things happen during the game. |
* Events are used to notify when certain things happen during the game. |
53 |
* They may either execute the "run" method of an exclusive %python script |
* They may either execute the "run" method of an exclusive %python script |
54 |
* or a simple %python callback defined elsewhere. |
* or a simple %python callback defined elsewhere. |
55 |
*/ |
*/ |
56 |
class event |
class event |
57 |
{ |
{ |
58 |
public: |
public: |
59 |
#ifndef SWIG |
#ifndef SWIG |
60 |
/** |
/** |
61 |
* Constructor. Needs to be called by any derived class! |
* Constructor. Needs to be called by any derived class! |
62 |
*/ |
*/ |
63 |
event (); |
event (); |
64 |
#endif |
#endif |
65 |
/** |
/** |
66 |
* Destructor. |
* Destructor. |
67 |
*/ |
*/ |
68 |
virtual ~event () { } |
virtual ~event () { } |
69 |
|
|
70 |
/** |
/** |
71 |
* @name Member access |
* @name Member access |
72 |
*/ |
*/ |
73 |
//@{ |
//@{ |
74 |
/** |
/** |
75 |
* Get the event's type. |
* Get the event's type. |
76 |
* |
* |
77 |
* @return type of the %event |
* @return type of the %event |
78 |
*/ |
*/ |
79 |
u_int8 type (); |
u_int8 type (); |
80 |
|
|
81 |
#ifndef SWIG |
#ifndef SWIG |
82 |
/** |
/** |
83 |
* Get name of %event. |
* Get name of %event. |
84 |
* @return name of %event. |
* @return name of %event. |
85 |
*/ |
*/ |
86 |
virtual const char* name () const = 0; |
virtual const char* name () const = 0; |
87 |
#endif // SWIG |
#endif // SWIG |
88 |
|
|
89 |
/** |
/** |
90 |
* Return whether this event should be repeated. |
* Return whether this event should be repeated. |
91 |
* |
* |
92 |
* @return the number of times this event should be repeated or |
* @return the number of times this event should be repeated or |
93 |
* -1 in case it should be repeated unlimited times. |
* -1 in case it should be repeated unlimited times. |
94 |
*/ |
*/ |
95 |
s_int32 repeat () const |
s_int32 repeat () const |
96 |
{ |
{ |
97 |
return Repeat; |
return Repeat; |
98 |
} |
} |
99 |
|
|
100 |
/** |
/** |
101 |
* Set whether this event should be repeated. A number greater than 0 |
* Set whether this event should be repeated. A number greater than 0 |
102 |
* will execute the event that many times, a number less than 0 will |
* will execute the event that many times, a number less than 0 will |
103 |
* repeat the event forever. A number equal to 0 won't repeat the event. |
* repeat the event forever. A number equal to 0 won't repeat the event. |
104 |
* |
* |
105 |
* @param count How often the event should be repeated. |
* @param count How often the event should be repeated. |
106 |
*/ |
*/ |
107 |
void set_repeat (s_int32 count) |
void set_repeat (s_int32 count) |
108 |
{ |
{ |
109 |
Repeat = count; |
Repeat = count; |
110 |
} |
} |
111 |
|
|
112 |
#ifndef SWIG |
#ifndef SWIG |
113 |
/** |
/** |
114 |
* This is called by the %event %listener when the %event has been |
* This is called by the %event %listener when the %event has been |
115 |
* triggered to decrease the event's repeat count. If the repeat-count |
* triggered to decrease the event's repeat count. If the repeat-count |
116 |
* reaches 0, the %event needs to be destroyed. |
* reaches 0, the %event needs to be destroyed. |
117 |
*/ |
*/ |
118 |
virtual void do_repeat () |
virtual void do_repeat () |
119 |
{ |
{ |
120 |
if (Repeat > 0) Repeat--; |
if (Repeat > 0) Repeat--; |
121 |
} |
} |
122 |
#endif // SWIG |
#endif // SWIG |
123 |
|
|
124 |
/** |
/** |
125 |
* Compare two events for equality. |
* Compare two events for equality. |
126 |
* |
* |
127 |
* @param evnt pointer to the %event to compare with. |
* @param evnt pointer to the %event to compare with. |
128 |
* @return \e true if the events are equal, \e false otherwise. |
* @return \e true if the events are equal, \e false otherwise. |
129 |
*/ |
*/ |
130 |
virtual bool equals (const event* evnt) = 0; |
virtual bool equals (const event* evnt) = 0; |
131 |
|
|
132 |
/** |
/** |
133 |
* @name Loading / Saving |
* @name Loading / Saving |
134 |
*/ |
*/ |
135 |
//@{ |
//@{ |
136 |
|
|
137 |
/** |
/** |
138 |
* Saves the basic %event %data (such as the type or repeat data) |
* Saves the basic %event %data (such as the type or repeat data) |
139 |
* to a file. Call this method from the derived class. |
* to a file. Call this method from the derived class. |
140 |
* |
* |
141 |
* @param out stream where to save the %event. |
* @param out stream where to save the %event. |
142 |
*/ |
*/ |
143 |
virtual void put_state (base::flat& out) const; |
virtual void put_state (base::flat& out) const; |
144 |
|
|
145 |
/** |
/** |
146 |
* Loads the basic %event %data from stream. Call this method from |
* Loads the basic %event %data from stream. Call this method from |
147 |
* the derived class. |
* the derived class. |
148 |
* |
* |
149 |
* @param in flattener to load the %event from. |
* @param in flattener to load the %event from. |
150 |
* @return \e true if the %event could be loaded, \e false otherwise |
* @return \e true if the %event could be loaded, \e false otherwise |
151 |
*/ |
*/ |
152 |
virtual bool get_state (base::flat& in); |
virtual bool get_state (base::flat& in); |
153 |
//@} |
//@} |
154 |
|
|
155 |
#ifndef SWIG |
#ifndef SWIG |
156 |
/** |
/** |
157 |
* Allow %event to be passed as python argument |
* Allow %event to be passed as python argument |
158 |
*/ |
*/ |
159 |
GET_TYPE_NAME_VIRTUAL (events::event) |
GET_TYPE_NAME_VIRTUAL (events::event) |
160 |
#endif |
#endif |
161 |
|
|
162 |
protected: |
protected: |
163 |
/** |
/** |
164 |
* @name Basic Event Data |
* @name Basic Event Data |
165 |
*/ |
*/ |
166 |
//@{ |
//@{ |
167 |
/** |
/** |
168 |
* Event type - see enum above. |
* Event type - see enum above. |
169 |
*/ |
*/ |
170 |
u_int8 Type; |
u_int8 Type; |
171 |
|
|
172 |
/** |
/** |
173 |
* Defines how often the %event should be repeated. <b>0</b> means |
* Defines how often the %event should be repeated. <b>0</b> means |
174 |
* never, <b>-1</b> means infinitely and <b>n</b> (n > 0) means |
* never, <b>-1</b> means infinitely and <b>n</b> (n > 0) means |
175 |
* exactly n times. |
* exactly n times. |
176 |
*/ |
*/ |
177 |
s_int32 Repeat; |
s_int32 Repeat; |
178 |
//@} |
//@} |
179 |
}; |
}; |
180 |
} |
} |
181 |
|
|
182 |
#endif // EVENT_EVENT_H |
#endif // EVENT_EVENT_H |