Adonthell
0.4
|
00001 /* 00002 $Id: map_event_handler.cc,v 1.5 2003/01/20 00:15:41 ksterker Exp $ 00003 00004 Copyright (C) 2002/2003 Kai Sterker <kaisterker@linuxgames.com> 00005 Part of the Adonthell Project http://adonthell.linuxgames.com 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License. 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY. 00011 00012 See the COPYING file for more details. 00013 */ 00014 00015 /** 00016 * @file map_event_handler.cc 00017 * 00018 * @author Kai Sterker 00019 * @brief Implements the map_event_handler class. 00020 */ 00021 00022 #include <algorithm> 00023 #include "map_event.h" 00024 #include "map_event_handler.h" 00025 00026 00027 // See whether a matching event is registered and execute the 00028 // according script(s) 00029 void map_event_handler::raise_event (const event* e) 00030 { 00031 // we have to iterate back to front as executing an event might 00032 // erase it from the vector. This invalidates any iterators pointing 00033 // _after_ the deleted element. 00034 for (vector<event*>::iterator i = Events.end (); i > Events.begin ();) 00035 { 00036 i--; 00037 00038 // if the events match, execute them. Note that events that use up 00039 // their repeat count are deleted (and automatically unregistered). 00040 if ((*i)->equals (e)) 00041 if (!(*i)->execute (e)) 00042 delete *i; 00043 } 00044 00045 return; 00046 } 00047 00048 // Unregister an event 00049 void map_event_handler::remove_event (event *e) 00050 { 00051 vector<event*>::iterator i; 00052 00053 // Search for the event we want to remove 00054 i = find (Events.begin (), Events.end (), e); 00055 00056 // found? -> get rid of it :) 00057 if (i != Events.end ()) Events.erase (i); 00058 } 00059 00060 // register an event with the handler 00061 void map_event_handler::register_event (event *e) 00062 { 00063 Events.push_back (e); 00064 }