Adonthell  0.4
event_handler.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2000/2001/2002 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 /**
21  * @file event_handler.cc
22  * @author Kai Sterker <kai.sterker@gmail.com>
23  *
24  * @brief Implements the event_handler class.
25  *
26  */
27 
28 #include "event_handler.h"
29 #include "map_event.h"
30 #include "map_event_handler.h"
31 #include "time_event.h"
32 #include "time_event_handler.h"
33 
34 // Array with registered event handlers
35 event_handler_base* event_handler::Handler[MAX_EVENTS];
36 
37 // functions that return newly instanciated events
38 // of a certain type
43 
44 // Initialize the game event system
45 void event_handler::init ()
46 {
47  // register event handlers
48  Handler[ENTER_EVENT] = new map_event_handler;
49  Handler[LEAVE_EVENT] = new map_event_handler;
50  Handler[ACTION_EVENT] = new map_event_handler;
51  Handler[TIME_EVENT] = new time_event_handler;
52 
53  // register events
54  REGISTER_EVENT (TIME_EVENT, time_event)
55  REGISTER_EVENT (ENTER_EVENT, enter_event)
56  REGISTER_EVENT (LEAVE_EVENT, leave_event)
57  REGISTER_EVENT (ACTION_EVENT, action_event)
58 }
59 
60 // Clear the registered handlers
62 {
63  for (int i = 0; i < MAX_EVENTS; i++)
64  if (Handler[i] != NULL)
65  delete Handler[i];
66 }
This is the base class for actual event handlers.
Declares the event_handler class.
To notify when a mapcharacter left a mapsquare.
Definition: map_event.h:126
Declares the map_event_handler class.
To notify when a mapcharacter "act" on a square.
Definition: map_event.h:139
#define NEW_EVENT(evt)
A function that returns a new instance of an event.
Definition: event_list.h:203
To notify when a character entered a mapsquare.
Definition: map_event.h:113
This class keeps track of map events, i.e.
The time event executes the attached script or callback at a certain point in game-time.
Definition: time_event.h:38
static void cleanup()
Delete the event handlers.
Declares the time_event_handler class.
Declares the time_event class.
#define REGISTER_EVENT(type, evt)
Registers an event with the event_list, allowing it to load this event without knowing about it at co...
Definition: event_list.h:197
Declares the different map events.
It ensures global access to the individual event handlers.
Definition: event_handler.h:37
This class keeps track of time events, i.e.