1 /* gameHook.h
2    gameHook's lives on a map and provides means to take special actions every timeframe.
3    They can be used to implement elevators (modifying the map characteristics),
4    targetZones (level finished when player enters them), etc...
5 
6    Copyright (C) 2000  Mathias Broxvall
7 
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12 
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17 
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 */
22 
23 #ifndef GAMEHOOK_H
24 #define GAMEHOOK_H
25 
26 #include <libguile.h>
27 #include "general.h"
28 
29 typedef enum {
30   GameHookEvent_Death = 0,
31   GameHookEvent_Spawn,
32   GameHookEvent_Tick,
33   GameHookEvent_MaxHooks
34 } GameHookEvent;
35 
36 enum {
37   Role_Dead = 0,          /* collects entities for cleanup */
38   Role_GameHook = 1,      /* pure GameHooks (will not be rendered) */
39   Role_OtherAnimated = 2, /* animated: misc types */
40   Role_Ball = 3,          /* animated: all types inheriting from Ball, except */
41   Role_Player = 4,        /* animated: ... player balls */
42   Role_Pipe = 5,          /* animated: pipes */
43   Role_PipeConnector = 6, /* animated: pipe connectors */
44   Role_Forcefield = 7,    /* animated: forcefields */
45   Role_MaxTypes = 8
46 };
47 
48 class Game;
49 
50 class GameHook {
51  public:
52   explicit GameHook(Game& game, int role);
53   virtual ~GameHook();
54   virtual void tick(Real);
55   virtual void doExpensiveComputations();
56 
57   /** Trigger any guile hooks which have been registered for this
58       event */
59   void triggerHook(GameHookEvent event, SCM arg);
60 
61   /** Register a hook which can be triggered on various events */
62   void registerHook(GameHookEvent event, SCM hook);
63 
64   /** Returns the hook currently registered to event, or NULL */
65   SCM getHook(GameHookEvent event);
66 
67   /** Marks the object for removal from the world. */
68   void remove();
69 
70   /** Unregisters all hooks */
71   virtual void releaseCallbacks();
72 
73   Game& game; /* A pointer to the game to which the hook is attached */
74   int entity_role;
75   bool is_on;   /* for switches, forcefields, objects with toggle state */
76   bool invalid; /* if true, object is slated for cleanup */
77 
78  private:
79   SCM hooks[GameHookEvent_MaxHooks];
80 };
81 
82 #endif
83