Planeshift

psentity.h

Go to the documentation of this file.
00001 /*
00002  * psentity.h
00003  *
00004  * Copyright (C) 2001-2010 Atomic Blue ([email protected], http://www.planeshift.it)
00005  *
00006  * Credits : Andrea Rizzi <[email protected]>
00007  *           Saul Leite <[email protected]>
00008  *           Mathias 'AgY' Voeroes <[email protected]>
00009  *           and all past and present planeshift coders
00010  *
00011  * This program is free software; you can redistribute it and/or
00012  * modify it under the terms of the GNU General Public License
00013  * as published by the Free Software Foundation (version 2 of the License.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022  *
00023  */
00024 
00025 
00026 #ifndef _PSENTITY_H_
00027 #define _PSENTITY_H_
00028 
00029 
00030 #define DEFAULT_ENTITY_STATE 0
00031 #define UNDEFINED_ENTITY_STATE -1
00032 
00039 class psEntity
00040 {
00041 public:
00048     psEntity(bool isFactoryEntity, const char* entityName);
00049 
00054     ~psEntity();
00055 
00062     psEntity(psEntity* const &entity);
00063 
00068     bool IsFactoryEntity() const
00069     {
00070         return isFactoryEntity;
00071     }
00072 
00078     const csString &GetEntityName() const
00079     {
00080         return entityName;
00081     }
00082 
00087     void SetAsMeshEntity(const char* meshName);
00088 
00093     void SetAsFactoryEntity(const char* factoryName);
00094 
00099     float GetMaxRange() const
00100     {
00101         return maxRange;
00102     }
00103 
00109     void SetRange(float minRange, float maxRange);
00110 
00115     uint GetMeshID() const;
00116 
00121     void SetMeshID(uint id);
00122 
00126     csVector3 GetPosition()
00127     {
00128         return position;
00129     };
00130 
00136     bool DefineState(csRef<iDocumentNode> stateNode);
00137 
00142     bool IsActive() const
00143     {
00144         return isActive;
00145     }
00146 
00151     void SetActive(bool toggle)
00152     {
00153         isActive = toggle;
00154     }
00155 
00161     bool IsTemporary() const;
00162 
00167     bool IsPlaying() const;
00168 
00180     bool CanPlay(int time, float range) const;
00181 
00185     int GetState()
00186     {
00187         return state;
00188     };
00189 
00202     void SetState(int state, bool forceChange, bool setReady);
00203 
00213     bool Play(SoundControl* &ctrl, csVector3 entityPosition);
00214 
00218     void Stop();
00219 
00230     void Update(int time, float distance, int interval, SoundControl* &ctrl,
00231                 csVector3 entityPosition);
00232 
00233 private:
00237     struct EntityState
00238     {
00239         csStringArray resources;    
00240         float volume;               
00241         float probability;          
00242         int delay;                  
00243         int timeOfDayStart;         
00244         int timeOfDayEnd;           
00245 
00246         int fallbackState;          
00247         float fallbackProbability;  
00248 
00249         int references;             
00250     };
00251 
00252     bool isActive;                      
00253 
00254     bool isFactoryEntity;               
00255     csString entityName;                
00256 
00257     int state;                         
00258     int when;                           
00259     uint id;                            
00260     float minRange;                     
00261     float maxRange;                     
00262     csVector3      position;            
00263 
00264     SoundHandle* handle;                
00265     csHash<EntityState*, uint> states;  
00266 
00271     static void StopCallback(void* object);
00272 };
00273 
00274 #endif /*_PSENTITY_H_*/