Adonthell  0.4
map_event_handler.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002/2003 Kai Sterker <kai.sterker@gmail.com>
3  Part of the Adonthell Project <http://adonthell.nongnu.org>
4 
5  Adonthell is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  Adonthell is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with Adonthell. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 /**
20  * @file map_event_handler.cc
21  *
22  * @author Kai Sterker
23  * @brief Implements the map_event_handler class.
24  */
25 
26 #include <algorithm>
27 #include "map_event.h"
28 #include "map_event_handler.h"
29 
30 
31 // See whether a matching event is registered and execute the
32 // according script(s)
34 {
35  // we have to iterate back to front as executing an event might
36  // erase it from the vector. This invalidates any iterators pointing
37  // _after_ the deleted element.
38  for (vector<event*>::iterator i = Events.end (); i > Events.begin ();)
39  {
40  i--;
41 
42  // if the events match, execute them. Note that events that use up
43  // their repeat count are deleted (and automatically unregistered).
44  if ((*i)->equals (e))
45  if (!(*i)->execute (e))
46  delete *i;
47  }
48 
49  return;
50 }
51 
52 // Unregister an event
54 {
55  vector<event*>::iterator i;
56 
57  // Search for the event we want to remove
58  i = find (Events.begin (), Events.end (), e);
59 
60  // found? -> get rid of it :)
61  if (i != Events.end ()) Events.erase (i);
62 }
63 
64 // register an event with the handler
66 {
67  Events.push_back (e);
68 }
Declares the map_event_handler class.
Base class for events.
Definition: event.h:75
void register_event(event *evnt)
Register a map event with the event handler.
void raise_event(const event *evnt)
Raise one or more events in case the given &#39;trigger&#39; matches.
Declares the different map events.
void remove_event(event *evnt)
Removes the given event from the event handler.