Planeshift
gameevent.h
Go to the documentation of this file.
1 /*
2  * gameevent.h
3  *
4  * Copyright (C) 2001 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5  *
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation (version 2 of the License)
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  */
19 
20 #ifndef __GAMEEVENT_H__
21 #define __GAMEEVENT_H__
22 
23 #include <csutil/csstring.h>
24 
25 class EventManager;
26 
37 {
38  char type[32];
39 public:
41 
42  csTicks triggerticks;
43  csTicks delayticks;
44  int id;
45  static int nextid;
46  bool valid;
47 
52  psGameEvent(csTicks ticks,int offsetticks, const char* newType);
53 
54  virtual ~psGameEvent();
55 
59  void QueueEvent();
60 
69  virtual bool CheckTrigger()
70  {
71  return valid;
72  };
73 
80  virtual void Trigger()=0;
81 
90  virtual void SetValid(bool valid)
91  {
92  this->valid = valid;
93  }
94 
100  virtual bool IsValid()
101  {
102  return valid;
103  }
104 
109  const char* GetType()
110  {
111  return type;
112  }
113 
121  //TODO: virtual csString ToString() const = 0;
122  virtual csString ToString() const
123  {
124  return "Not implemented";
125  }
126 
127  bool operator==(const psGameEvent &other) const
128  {
129  return (triggerticks==other.triggerticks &&
130  id==other.id);
131  };
132 
133  bool operator<(const psGameEvent &other) const
134  {
135  if(triggerticks<other.triggerticks)
136  return true;
137  if(triggerticks>other.triggerticks)
138  return false;
139  if(id<other.id)
140  return true;
141  return false;
142  };
143  bool operator>(const psGameEvent &other) const
144  {
145  if(triggerticks>other.triggerticks)
146  return true;
147  if(triggerticks<other.triggerticks)
148  return false;
149  if(id>other.id)
150  return true;
151  return false;
152  };
153 };
154 
157 #endif
158 
int id
id value combined with ticks ensures uniqueness for tree
Definition: gameevent.h:44
virtual void Trigger()=0
Abstract event processing function.
static EventManager * eventmanager
Definition: gameevent.h:40
bool operator<(const psGameEvent &other) const
Definition: gameevent.h:133
virtual bool IsValid()
Return the valid flag.
Definition: gameevent.h:100
static int nextid
id counter sequence
Definition: gameevent.h:45
virtual void SetValid(bool valid)
Set the valid flag.
Definition: gameevent.h:90
const char * GetType()
Return the type that this event where created with.
Definition: gameevent.h:109
void QueueEvent()
Publish the game event to the local program.
virtual bool CheckTrigger()
Called right before a Trigger is called.
Definition: gameevent.h:69
csTicks delayticks
delay before the event starts
Definition: gameevent.h:43
virtual csString ToString() const
Return a string with information about the event.
Definition: gameevent.h:122
bool valid
Set this to false if the trigger should not be fired.
Definition: gameevent.h:46
csTicks triggerticks
ticks value when event should be triggered.
Definition: gameevent.h:42
psGameEvent(csTicks ticks, int offsetticks, const char *newType)
Construct a new game event.
virtual ~psGameEvent()
All scheduled events must inherit from this class.
Definition: gameevent.h:36
bool operator==(const psGameEvent &other) const
Definition: gameevent.h:127
bool operator>(const psGameEvent &other) const
Definition: gameevent.h:143
This class handles all queueing and invoking of timed events, such as combat, spells, NPC dialog responses, range weapons, or NPC respawning.
Definition: eventmanager.h:40