Adonthell  0.4
map_event_handler.cc
Go to the documentation of this file.
1 /*
2  $Id: map_event_handler.cc,v 1.5 2003/01/20 00:15:41 ksterker Exp $
3 
4  Copyright (C) 2002/2003 Kai Sterker <kaisterker@linuxgames.com>
5  Part of the Adonthell Project http://adonthell.linuxgames.com
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 /**
16  * @file map_event_handler.cc
17  *
18  * @author Kai Sterker
19  * @brief Implements the map_event_handler class.
20  */
21 
22 #include <algorithm>
23 #include "map_event.h"
24 #include "map_event_handler.h"
25 
26 
27 // See whether a matching event is registered and execute the
28 // according script(s)
30 {
31  // we have to iterate back to front as executing an event might
32  // erase it from the vector. This invalidates any iterators pointing
33  // _after_ the deleted element.
34  for (vector<event*>::iterator i = Events.end (); i > Events.begin ();)
35  {
36  i--;
37 
38  // if the events match, execute them. Note that events that use up
39  // their repeat count are deleted (and automatically unregistered).
40  if ((*i)->equals (e))
41  if (!(*i)->execute (e))
42  delete *i;
43  }
44 
45  return;
46 }
47 
48 // Unregister an event
50 {
51  vector<event*>::iterator i;
52 
53  // Search for the event we want to remove
54  i = find (Events.begin (), Events.end (), e);
55 
56  // found? -> get rid of it :)
57  if (i != Events.end ()) Events.erase (i);
58 }
59 
60 // register an event with the handler
62 {
63  Events.push_back (e);
64 }