~ubuntu-branches/ubuntu/maverick/asc/maverick

« back to all changes in this revision

Viewing changes to source/gameeventsystem.h

  • Committer: Bazaar Package Importer
  • Author(s): Moritz Muehlenhoff, Moritz Muehlenhoff, Barry deFreese, Alexander Reichle-Schmehl
  • Date: 2010-01-01 22:11:14 UTC
  • mfrom: (1.1.6 upstream) (2.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20100101221114-qfg9ogppdfcte4m7
Tags: 2.4.0.0-1
[ Moritz Muehlenhoff ]
* New upstream release. (2.4.0)
  - Drop obsolete patches
  - Initializes map_edit properly. (Closes: #534171).
* Update to standards version 3.8.3
* Switch to source format 3.0 (quilt) (Closes: #538430)
* Adding myself to uploaders

[ Barry deFreese ]
* New upstream release. (2.2.0)

[ Alexander Reichle-Schmehl ]
* Adopt debian/control to my new name.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#define gameeventsystemH
28
28
 
29
29
#include <sigc++/sigc++.h>
 
30
#include "loki/Singleton.h"
30
31
 
31
32
#include "typen.h"
32
 
#include "libs/loki/Singleton.h"
33
 
#include "factory.h"
 
33
#include "util/factory.h"
34
34
 
35
35
#include "mapdisplayinterface.h"
 
36
#include "util/factorywithnames.h"
36
37
 
37
38
class MapDisplayInterface;
38
39
 
44
45
                         cconnection_areaentered_specificunit = 32 };
45
46
 
46
47
 
47
 
extern bool  checkevents( MapDisplayInterface* md );
48
 
 
49
 
extern void  checktimedevents( MapDisplayInterface* md );
50
 
 
51
 
extern void eventReady();
 
48
extern bool  checkevents( GameMap* gamemap, MapDisplayInterface* md );
 
49
 
 
50
extern void  checktimedevents( GameMap* gamemap, MapDisplayInterface* md );
 
51
 
 
52
extern void eventReady( GameMap* gamemap );
52
53
 
53
54
typedef int EventTriggerID;
54
55
typedef int EventActionID;
87
88
 
88
89
      virtual ~EventTrigger(){};
89
90
 
90
 
      // friend Event* readOldEvent( pnstream stream );
91
91
};
92
92
 
93
93
class EventAction {
101
101
      virtual void writeData ( tnstream& stream ) = 0;
102
102
      virtual ASCString getName() const = 0;
103
103
 
 
104
      virtual ASCString getLocalizationString() const { return ""; };
 
105
      virtual void setLocalizationString( const ASCString& s ) {};
 
106
      
104
107
      virtual void execute( MapDisplayInterface* md ) = 0;
105
108
      virtual void setup() = 0;
106
109
      void setMap( GameMap* gamemap_ ) { gamemap = gamemap_; };
162
165
};
163
166
 
164
167
 
165
 
template < class AbstractProduct, typename IdentifierType, typename ObjectCreatorCallBack = AbstractProduct*(*)(), typename NameType = ASCString >
166
 
class FactoryWithNames : protected Factory<AbstractProduct, IdentifierType>
167
 
{
168
 
   private:
169
 
      typedef std::map<NameType, IdentifierType> NameMap;
170
 
      NameMap names;
171
 
   public:
172
 
      vector<NameType> getNames(){
173
 
         vector<NameType> nameList;
174
 
         
175
 
         for ( typename NameMap::iterator i = names.begin(); i != names.end(); ++i )
176
 
            nameList.push_back( i->first );
177
 
         return nameList;
178
 
      }
179
 
 
180
 
      IdentifierType getID( const ASCString& name )
181
 
      {
182
 
         return names[name];
183
 
      }
184
 
 
185
 
      bool registerClass( IdentifierType id, typename FactoryWithNames<AbstractProduct, IdentifierType, typename FactoryWithNames::ObjectCreatorCallBack, NameType>::ObjectCreatorCallBack createFn, Loki::Functor<NameType, TYPELIST_1(const IdentifierType&)> nameProvider )
186
 
      {
187
 
         return registerClass( id, createFn, nameProvider(id) );
188
 
      }
189
 
 
190
 
      bool registerClass( IdentifierType id, typename FactoryWithNames<AbstractProduct, IdentifierType, typename FactoryWithNames::ObjectCreatorCallBack, NameType>::ObjectCreatorCallBack createFn, NameType name )
191
 
      {
192
 
         if ( Factory<AbstractProduct, IdentifierType>::registerClass ( id, createFn )) {
193
 
            names[name] = id;
194
 
            return true;
195
 
         } else
196
 
            return false;
197
 
      }
198
 
 
199
 
      AbstractProduct* createObject( IdentifierType id ) {
200
 
         return Factory<AbstractProduct, IdentifierType>::createObject( id );
201
 
      }
202
 
 
203
 
};
204
 
 
205
 
typedef Loki::SingletonHolder< FactoryWithNames< EventTrigger, EventTriggerID > > triggerFactory;
206
 
typedef Loki::SingletonHolder< FactoryWithNames< EventAction , EventActionID  > > actionFactory;
 
168
typedef Loki::SingletonHolder< FactoryWithNames< EventTrigger, EventTriggerID > > eventTriggerFactory;
 
169
typedef Loki::SingletonHolder< FactoryWithNames< EventAction , EventActionID  > > eventActionFactory;
207
170
 
208
171
 
209
172