Planeshift
psentity.h
Go to the documentation of this file.
1 /*
2  * psentity.h
3  *
4  * Copyright (C) 2001-2010 Atomic Blue (info@planeshift.it, http://www.planeshift.it)
5  *
6  * Credits : Andrea Rizzi <88whacko@gmail.com>
7  * Saul Leite <leite@engineer.com>
8  * Mathias 'AgY' Voeroes <agy@operswithoutlife.net>
9  * and all past and present planeshift coders
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation (version 2 of the License.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22  *
23  */
24 
25 
26 #ifndef _PSENTITY_H_
27 #define _PSENTITY_H_
28 
29 
30 #define DEFAULT_ENTITY_STATE 0
31 #define UNDEFINED_ENTITY_STATE -1
32 
39 class psEntity
40 {
41 public:
48  psEntity(bool isFactoryEntity, const char* entityName);
49 
54  ~psEntity();
55 
62  psEntity(psEntity* const &entity);
63 
68  bool IsFactoryEntity() const
69  {
70  return isFactoryEntity;
71  }
72 
78  const csString &GetEntityName() const
79  {
80  return entityName;
81  }
82 
87  void SetAsMeshEntity(const char* meshName);
88 
93  void SetAsFactoryEntity(const char* factoryName);
94 
99  float GetMaxRange() const
100  {
101  return maxRange;
102  }
103 
109  void SetRange(float minRange, float maxRange);
110 
115  uint GetMeshID() const;
116 
121  void SetMeshID(uint id);
122 
126  csVector3 GetPosition()
127  {
128  return position;
129  };
130 
136  bool DefineState(csRef<iDocumentNode> stateNode);
137 
142  bool IsActive() const
143  {
144  return isActive;
145  }
146 
151  void SetActive(bool toggle)
152  {
153  isActive = toggle;
154  }
155 
161  bool IsTemporary() const;
162 
167  bool IsPlaying() const;
168 
180  bool CanPlay(int time, float range) const;
181 
185  int GetState()
186  {
187  return state;
188  };
189 
202  void SetState(int state, bool forceChange, bool setReady);
203 
213  bool Play(SoundControl* &ctrl, csVector3 entityPosition);
214 
218  void Stop();
219 
230  void Update(int time, float distance, int interval, SoundControl* &ctrl,
231  csVector3 entityPosition);
232 
233 private:
237  struct EntityState
238  {
239  csStringArray resources;
240  float volume;
241  float probability;
242  int delay;
243  int timeOfDayStart;
244  int timeOfDayEnd;
245 
246  int fallbackState;
247  float fallbackProbability;
248 
249  int references;
250  };
251 
252  bool isActive;
253 
254  bool isFactoryEntity;
255  csString entityName;
256 
257  int state;
258  int when;
259  uint id;
260  float minRange;
261  float maxRange;
262  csVector3 position;
263 
264  SoundHandle* handle;
265  csHash<EntityState*, uint> states;
266 
271  static void StopCallback(void* object);
272 };
273 
274 #endif /*_PSENTITY_H_*/
const csString & GetEntityName() const
Gets the entity name associated to this object.
Definition: psentity.h:78
bool IsPlaying() const
Check if the sound associated to this entity is still working.
int GetState()
Gets the state of the entity.
Definition: psentity.h:185
bool CanPlay(int time, float range) const
Checks if all condition for the sound to play are satisfied in the current state. ...
bool IsActive() const
Check if this entity is active.
Definition: psentity.h:142
void SetRange(float minRange, float maxRange)
Sets the range for this entity.
void Stop()
If this entity is playing, this method forces this to stop the sound.
void SetMeshID(uint id)
Set the ID of the mesh associated to this entity.
void SetAsMeshEntity(const char *meshName)
Sets this object as a mesh entity.
bool IsTemporary() const
Used to determine if this is a temporary entity associated to a specific mesh object or if it is a fa...
bool Play(SoundControl *&ctrl, csVector3 entityPosition)
Force this entity to play the sound associated to its current state.
psEntity(bool isFactoryEntity, const char *entityName)
Create a new psEntity.
A Volume and Sound control class.
Definition: control.h:40
float GetMaxRange() const
Gets the maximum distance at which this entity can be heard.
Definition: psentity.h:99
bool DefineState(csRef< iDocumentNode > stateNode)
Create a new state from an XML <state> node.
void SetAsFactoryEntity(const char *factoryName)
Sets this object as a factory entity.
uint GetMeshID() const
Get the ID of the mesh associated to this entity.
void SetActive(bool toggle)
Activate or deactivate this entity.
Definition: psentity.h:151
bool IsFactoryEntity() const
Return true if this is a factory entity.
Definition: psentity.h:68
void SetState(int state, bool forceChange, bool setReady)
Set the new state for the entity.
csVector3 GetPosition()
Returns the 3d position of this entity.
Definition: psentity.h:126
void Update(int time, float distance, int interval, SoundControl *&ctrl, csVector3 entityPosition)
Update the entity&#39;s activation status, play the sound associated with the current state if all condit...
~psEntity()
Destructor.
This object represents a planeshift entity sound.
Definition: psentity.h:39