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 |
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 event |
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 |
|
|
46 |
/** |
/** |
47 |
* Available %event types. |
* Available %event types. |
48 |
*/ |
*/ |
49 |
enum |
enum |
50 |
{ |
{ |
51 |
ENTER_EVENT = 0, // Characters reach a new tile |
ENTER_EVENT = 0, // Characters reach a new tile |
52 |
LEAVE_EVENT = 1, // Characters leave a tile |
LEAVE_EVENT = 1, // Characters leave a tile |
53 |
TIME_EVENT = 2, // Certain point in gametime reached |
TIME_EVENT = 2, // Certain point in gametime reached |
54 |
ACTION_EVENT = 3, // Character "acts" on a square |
ACTION_EVENT = 3, // Character "acts" on a square |
55 |
MAX_EVENTS = 4 |
MAX_EVENTS = 4 |
56 |
}; |
}; |
57 |
|
|
58 |
#endif // SWIG |
#endif // SWIG |
59 |
|
|
60 |
/** |
/** |
65 |
* Events are used to notify when certain things happen during the game. |
* Events are used to notify when certain things happen during the game. |
66 |
* They may either execute the "run" method of an exclusive %python script |
* They may either execute the "run" method of an exclusive %python script |
67 |
* or a simple %python callback defined elsewhere. |
* or a simple %python callback defined elsewhere. |
68 |
*/ |
*/ |
69 |
class event |
class event |
70 |
{ |
{ |
71 |
public: |
public: |
75 |
*/ |
*/ |
76 |
event (); |
event (); |
77 |
#endif |
#endif |
78 |
/** |
/** |
79 |
* Destructor. |
* Destructor. |
80 |
*/ |
*/ |
81 |
virtual ~event () { } |
virtual ~event () { } |
82 |
|
|
83 |
/** |
/** |
90 |
* @return type of the %event |
* @return type of the %event |
91 |
*/ |
*/ |
92 |
u_int8 type () const |
u_int8 type () const |
93 |
{ |
{ |
94 |
return Type; |
return Type; |
95 |
} |
} |
96 |
|
|
97 |
/** |
/** |
98 |
* Return whether this event should be repeated. |
* Return whether this event should be repeated. |
99 |
* |
* |
104 |
{ |
{ |
105 |
return Repeat; |
return Repeat; |
106 |
} |
} |
107 |
|
|
108 |
/** |
/** |
109 |
* Set whether this event should be repeated. A number greater than 0 |
* Set whether this event should be repeated. A number greater than 0 |
110 |
* 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 |
116 |
{ |
{ |
117 |
Repeat = count; |
Repeat = count; |
118 |
} |
} |
119 |
|
|
120 |
#ifndef SWIG |
#ifndef SWIG |
121 |
/** |
/** |
122 |
* This is called by the %event %listener when the %event has been |
* This is called by the %event %listener when the %event has been |
123 |
* triggered to decrease the event's repeat count. If the repeat-count |
* triggered to decrease the event's repeat count. If the repeat-count |
124 |
* reaches 0, the %event needs to be destroyed. |
* reaches 0, the %event needs to be destroyed. |
125 |
*/ |
*/ |
126 |
virtual void do_repeat () |
virtual void do_repeat () |
129 |
} |
} |
130 |
#endif // SWIG |
#endif // SWIG |
131 |
|
|
132 |
/** |
/** |
133 |
* Compare two events for equality. |
* Compare two events for equality. |
134 |
* |
* |
135 |
* @param evnt pointer to the %event to compare with. |
* @param evnt pointer to the %event to compare with. |
136 |
* @return \e true if the events are equal, \e false otherwise. |
* @return \e true if the events are equal, \e false otherwise. |
137 |
*/ |
*/ |
138 |
virtual bool equals (const event* evnt) = 0; |
virtual bool equals (const event* evnt) = 0; |
139 |
|
|
140 |
/** |
/** |
141 |
* @name Loading / Saving |
* @name Loading / Saving |
142 |
*/ |
*/ |
143 |
//@{ |
//@{ |
144 |
|
|
145 |
/** |
/** |
146 |
* Saves the basic %event %data (such as the type or repeat data) |
* Saves the basic %event %data (such as the type or repeat data) |
147 |
* to a file. Call this method from the derived class. |
* to a file. Call this method from the derived class. |
148 |
* |
* |
149 |
* @param out stream where to save the %event. |
* @param out stream where to save the %event. |
150 |
*/ |
*/ |
151 |
virtual void put_state (base::flat& out) const; |
virtual void put_state (base::flat& out) const; |
152 |
|
|
153 |
/** |
/** |
154 |
* Loads the basic %event %data from stream. Call this method from |
* Loads the basic %event %data from stream. Call this method from |
155 |
* the derived class. |
* the derived class. |
156 |
* |
* |
157 |
* @param in flattener to load the %event from. |
* @param in flattener to load the %event from. |
158 |
* @return \e true if the %event could be loaded, \e false otherwise |
* @return \e true if the %event could be loaded, \e false otherwise |
159 |
*/ |
*/ |
174 |
//@{ |
//@{ |
175 |
/** |
/** |
176 |
* Event type - see enum above. |
* Event type - see enum above. |
177 |
*/ |
*/ |
178 |
u_int8 Type; |
u_int8 Type; |
179 |
|
|
180 |
/** |
/** |
181 |
* Defines how often the %event should be repeated. <b>0</b> means |
* Defines how often the %event should be repeated. <b>0</b> means |
182 |
* 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 |
183 |
* exactly n times. |
* exactly n times. |
184 |
*/ |
*/ |
185 |
s_int32 Repeat; |
s_int32 Repeat; |