Planeshift

gameevent.h

Go to the documentation of this file.
00001 /*
00002  * gameevent.h
00003  *
00004  * Copyright (C) 2001 Atomic Blue ([email protected], http://www.atomicblue.org)
00005  *
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation (version 2 of the License)
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017  *
00018  */
00019 
00020 #ifndef __GAMEEVENT_H__
00021 #define __GAMEEVENT_H__
00022 
00023 #include <csutil/csstring.h>
00024 
00025 class EventManager;
00026 
00036 class psGameEvent
00037 {
00038     char type[32];          
00039 public:
00040     static EventManager* eventmanager;
00041 
00042     csTicks triggerticks;   
00043     csTicks delayticks;     
00044     int id;                 
00045     static int nextid;      
00046     bool valid;             
00047 
00052     psGameEvent(csTicks ticks,int offsetticks, const char* newType);
00053 
00054     virtual ~psGameEvent();
00055 
00059     void QueueEvent();
00060 
00069     virtual bool CheckTrigger()
00070     {
00071         return valid;
00072     };
00073 
00080     virtual void Trigger()=0;
00081 
00090     virtual void SetValid(bool valid)
00091     {
00092         this->valid = valid;
00093     }
00094 
00100     virtual bool IsValid()
00101     {
00102         return valid;
00103     }
00104 
00109     const char* GetType()
00110     {
00111         return type;
00112     }
00113 
00121     //TODO:    virtual csString ToString() const = 0;
00122     virtual csString ToString() const
00123     {
00124         return "Not implemented";
00125     }
00126 
00127     bool operator==(const psGameEvent &other) const
00128     {
00129         return (triggerticks==other.triggerticks &&
00130                 id==other.id);
00131     };
00132 
00133     bool operator<(const psGameEvent &other) const
00134     {
00135         if(triggerticks<other.triggerticks)
00136             return true;
00137         if(triggerticks>other.triggerticks)
00138             return false;
00139         if(id<other.id)
00140             return true;
00141         return false;
00142     };
00143     bool operator>(const psGameEvent &other) const
00144     {
00145         if(triggerticks>other.triggerticks)
00146             return true;
00147         if(triggerticks<other.triggerticks)
00148             return false;
00149         if(id>other.id)
00150             return true;
00151         return false;
00152     };
00153 };
00154 
00157 #endif
00158