gameeventsystem.h

Go to the documentation of this file.
00001 
00005 /*
00006     This file is part of Advanced Strategic Command; http://www.asc-hq.de
00007     Copyright (C) 1994-2010  Martin Bickel  and  Marc Schellenberger
00008 
00009     This program is free software; you can redistribute it and/or modify
00010     it under the terms of the GNU General Public License as published by
00011     the Free Software Foundation; either version 2 of the License, or
00012     (at your option) any later version.
00013 
00014     This program is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017     GNU General Public License for more details.
00018 
00019     You should have received a copy of the GNU General Public License
00020     along with this program; see the file COPYING. If not, write to the
00021     Free Software Foundation, Inc., 59 Temple Place, Suite 330,
00022     Boston, MA  02111-1307  USA
00023 */
00024 
00025 
00026 #ifndef gameeventsystemH
00027 #define gameeventsystemH
00028 
00029 #include <sigc++/sigc++.h>
00030 #include "loki/Singleton.h"
00031 
00032 #include "typen.h"
00033 #include "util/factory.h"
00034 
00035 #include "mapdisplayinterface.h"
00036 #include "util/factorywithnames.h"
00037 
00038 class MapDisplayInterface;
00039 
00040 enum  EventConnections { cconnection_destroy = 1,
00041                          cconnection_conquer = 2,
00042                          cconnection_lose  = 4,
00043                          cconnection_seen = 8,
00044                          cconnection_areaentered_anyunit = 16,
00045                          cconnection_areaentered_specificunit = 32 };
00046 
00047 
00048 extern bool  checkevents( GameMap* gamemap, MapDisplayInterface* md );
00049 
00050 extern void  checktimedevents( GameMap* gamemap, MapDisplayInterface* md );
00051 
00052 extern void eventReady( GameMap* gamemap );
00053 
00054 typedef int EventTriggerID;
00055 typedef int EventActionID;
00056 
00057 class Event;
00058 
00059 class EventTrigger {
00060       EventTriggerID triggerID;
00061    public:
00062       enum State { unfulfilled, fulfilled, finally_fulfilled, finally_failed };
00063    protected:
00064       EventTrigger ( EventTriggerID id ) : triggerID ( id ), gamemap(NULL), event(NULL), stateCache(unfulfilled), triggerFinal( false ), invert(false) {};
00065       virtual State getState( int player ) = 0;
00066       GameMap* gamemap;
00067       Event* event;
00068 
00069       bool isFulfilled();
00070    private:
00071       State stateCache;
00072       bool triggerFinal;
00073    public:
00074       bool invert;
00076       State state( int player );
00077 
00078       virtual void readData ( tnstream& stream ) = 0;
00079       virtual void writeData ( tnstream& stream ) = 0;
00080       
00081       virtual ASCString getDetailledName() const = 0;
00082       virtual ASCString getTypeName() const = 0;
00083       virtual void setup() = 0;
00084       virtual void arm() {};
00085       void setMap( GameMap* gamemap_ ) { gamemap = gamemap_; };
00086       void setEvent( Event* ev ) { event = ev; };
00087       EventTriggerID getTriggerID() { return triggerID; };
00088 
00089       virtual ~EventTrigger(){};
00090 
00091 };
00092 
00093 class EventAction {
00094       EventActionID actionID;
00095    protected:
00096       GameMap* gamemap;
00097       EventAction( EventActionID id ) : actionID ( id ), gamemap(NULL) {};
00098    public:
00099 
00100       virtual void readData ( tnstream& stream ) = 0;
00101       virtual void writeData ( tnstream& stream ) = 0;
00102       virtual ASCString getName() const = 0;
00103 
00104       virtual ASCString getLocalizationString() const { return ""; };
00105       virtual void setLocalizationString( const ASCString& s ) {};
00106       
00107       virtual void execute( MapDisplayInterface* md ) = 0;
00108       virtual void setup() = 0;
00109       void setMap( GameMap* gamemap_ ) { gamemap = gamemap_; };
00110       EventActionID getActionID() { return actionID; };
00111       virtual ~EventAction() {};
00112 };
00113 
00114 class Event {
00115       GameMap& gamemap;
00116 
00117       void clear();
00118    public:
00119       Event( GameMap& map_ );
00120       const GameMap* getMap() const { return &gamemap; };
00121 
00122       enum Status { Untriggered, Triggered, Timed, Executed } status;
00123 
00124       typedef vector<EventTrigger*> Trigger;
00125       Trigger trigger;
00126 
00127       int id;
00128       int playerBitmap; 
00129       ASCString  description;
00130       GameTime   triggerTime;
00131       struct Delayedexecution {
00132          Delayedexecution():turn(0),move(0){};
00133          int turn;
00134          int move;   // negative values allowed !!
00135       } delayedexecution;
00136 
00138       int reArmNum;
00139 
00140       EventAction* action;
00141       enum TriggerConnection { AND, OR } triggerConnection;
00142 
00143       void check( MapDisplayInterface* md );
00144       void execute( MapDisplayInterface* md );
00145       void spawnAction( EventActionID eai );
00146       EventTrigger* spawnTrigger( EventTriggerID eti );
00147 
00148       Event& operator= ( const Event& ev  );
00149 
00150       void read ( tnstream& stream );
00151       void write ( tnstream& stream );
00152 
00153       void arm();
00154 
00155       SigC::Signal0<void> executed;
00156 
00157       virtual ~Event();
00158 };
00159 
00160 class VariableLocker {
00161    bool& var;
00162    public:
00163       VariableLocker( bool& variable ) : var ( variable ) { var = true; };
00164       ~VariableLocker() { var = false; };
00165 };
00166 
00167 
00168 typedef Loki::SingletonHolder< FactoryWithNames< EventTrigger, EventTriggerID > > eventTriggerFactory;
00169 typedef Loki::SingletonHolder< FactoryWithNames< EventAction , EventActionID  > > eventActionFactory;
00170 
00171 
00172 
00173 // }; // namespace GameEvents
00174 
00175 #endif

Generated on Mon May 21 01:26:33 2012 for Advanced Strategic Command by  doxygen 1.5.1