Advanced Strategic Command
gameeventsystem.h
Go to the documentation of this file.
1 
5 /*
6  This file is part of Advanced Strategic Command; http://www.asc-hq.de
7  Copyright (C) 1994-2010 Martin Bickel and Marc Schellenberger
8 
9  This program is free software; you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 2 of the License, or
12  (at your option) any later version.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; see the file COPYING. If not, write to the
21  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
22  Boston, MA 02111-1307 USA
23 */
24 
25 
26 #ifndef gameeventsystemH
27 #define gameeventsystemH
28 
29 #include <sigc++/sigc++.h>
30 #include "loki/Singleton.h"
31 
32 #include "typen.h"
33 #include "util/factory.h"
34 
35 #include "mapdisplayinterface.h"
36 #include "util/factorywithnames.h"
37 
39 
46 
47 
48 extern bool checkevents( GameMap* gamemap, MapDisplayInterface* md );
49 
50 extern void checktimedevents( GameMap* gamemap, MapDisplayInterface* md );
51 
52 extern void eventReady( GameMap* gamemap );
53 
54 typedef int EventTriggerID;
55 typedef int EventActionID;
56 
57 class Event;
58 
59 class EventTrigger {
60  EventTriggerID triggerID;
61  public:
63  protected:
64  EventTrigger ( EventTriggerID id ) : triggerID ( id ), gamemap(NULL), event(NULL), stateCache(unfulfilled), triggerFinal( false ), invert(false) {};
65  virtual State getState( int player ) = 0;
68 
69  bool isFulfilled();
70  private:
71  State stateCache;
72  bool triggerFinal;
73  public:
74  bool invert;
76  State state( int player );
77 
78  virtual void readData ( tnstream& stream ) = 0;
79  virtual void writeData ( tnstream& stream ) = 0;
80 
81  virtual ASCString getDetailledName() const = 0;
82  virtual ASCString getTypeName() const = 0;
83  virtual void setup() = 0;
84  virtual void arm() {};
85  void setMap( GameMap* gamemap_ ) { gamemap = gamemap_; };
86  void setEvent( Event* ev ) { event = ev; };
87  EventTriggerID getTriggerID() { return triggerID; };
88 
89  virtual ~EventTrigger(){};
90 
91 };
92 
93 class EventAction {
94  EventActionID actionID;
95  protected:
97  EventAction( EventActionID id ) : actionID ( id ), gamemap(NULL) {};
98  public:
99 
100  virtual void readData ( tnstream& stream ) = 0;
101  virtual void writeData ( tnstream& stream ) = 0;
102  virtual ASCString getName() const = 0;
103 
104  virtual ASCString getLocalizationString() const { return ""; };
105  virtual void setLocalizationString( const ASCString& s ) {};
106 
107  virtual void execute( MapDisplayInterface* md ) = 0;
108  virtual void setup() = 0;
109  void setMap( GameMap* gamemap_ ) { gamemap = gamemap_; };
110  EventActionID getActionID() { return actionID; };
111  virtual ~EventAction() {};
112 };
113 
114 class Event {
115  GameMap& gamemap;
116 
117  void clear();
118  public:
119  Event( GameMap& map_ );
120  const GameMap* getMap() const { return &gamemap; };
121 
123 
124  typedef vector<EventTrigger*> Trigger;
126 
127  int id;
133  int turn;
134  int move; // negative values allowed !!
136 
138  int reArmNum;
139 
142 
143  void check( MapDisplayInterface* md );
144  void execute( MapDisplayInterface* md );
145  void spawnAction( EventActionID eai );
147 
148  Event& operator= ( const Event& ev );
149 
150  void read ( tnstream& stream );
151  void write ( tnstream& stream );
152 
153  void arm();
154 
155  sigc::signal<void> executed;
156 
157  virtual ~Event();
158 };
159 
161  bool& var;
162  public:
163  VariableLocker( bool& variable ) : var ( variable ) { var = true; };
164  ~VariableLocker() { var = false; };
165 };
166 
167 
168 typedef Loki::SingletonHolder< FactoryWithNames< EventTrigger, EventTriggerID > > eventTriggerFactory;
169 typedef Loki::SingletonHolder< FactoryWithNames< EventAction , EventActionID > > eventActionFactory;
170 
171 
172 
173 // }; // namespace GameEvents
174 
175 #endif
the time in ASC, measured in turns and moves
Definition: typen.h:178
vector< EventTrigger * > Trigger
void arm()
Loki::SingletonHolder< FactoryWithNames< EventAction, EventActionID > > eventActionFactory
void setMap(GameMap *gamemap_)
void spawnAction(EventActionID eai)
GameMap * gamemap
virtual void writeData(tnstream &stream)=0
void setMap(GameMap *gamemap_)
VariableLocker(bool &variable)
ASCString description
int reArmNum
the number of times this event can be executed; makes only sense in cunjunction with delayedexecution...
virtual ~EventTrigger()
virtual ASCString getName() const =0
EventAction * action
EventAction(EventActionID id)
void checktimedevents(GameMap *gamemap, MapDisplayInterface *md)
The interface for all kinds of IO stream.
void write(tnstream &stream)
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
bool checkevents(GameMap *gamemap, MapDisplayInterface *md)
void setEvent(Event *ev)
void read(tnstream &stream)
Event & operator=(const Event &ev)
virtual State getState(int player)=0
virtual ASCString getDetailledName() const =0
int playerBitmap
Loki::SingletonHolder< FactoryWithNames< EventTrigger, EventTriggerID > > eventTriggerFactory
EventConnections
virtual void arm()
EventTrigger * spawnTrigger(EventTriggerID eti)
EventTriggerID getTriggerID()
struct Event::Delayedexecution delayedexecution
void eventReady(GameMap *gamemap)
virtual ASCString getTypeName() const =0
GameTime triggerTime
virtual void readData(tnstream &stream)=0
const GameMap * getMap() const
virtual void writeData(tnstream &stream)=0
virtual void setLocalizationString(const ASCString &s)
virtual void setup()=0
virtual ASCString getLocalizationString() const
virtual void readData(tnstream &stream)=0
Event(GameMap &map_)
virtual void execute(MapDisplayInterface *md)=0
virtual void setup()=0
enum Event::Status status
int EventActionID
EventActionID getActionID()
void check(MapDisplayInterface *md)
GameMap * gamemap
virtual ~Event()
Trigger trigger
enum Event::TriggerConnection triggerConnection
sigc::signal< void > executed
State state(int player)
takes the inversion into account, which getState(int) does not
void execute(MapDisplayInterface *md)
EventTrigger(EventTriggerID id)
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182
int EventTriggerID
virtual ~EventAction()