mob.h

00001 /*--License:
00002         Lilith 3D Engine
00003         Copyright Lee Thomason (Grinning Lizard Software) 2002-2007
00004         www.grinninglizard.com/lilith
00005 
00006         This program is free software; you can redistribute it and/or
00007         modify it under the terms of the GNU General Public License
00008         as published by the Free Software Foundation; either version 2
00009         of the License, or (at your option) any later version.
00010 
00011         This program is distributed in the hope that it will be useful,
00012         but WITHOUT ANY WARRANTY; without even the implied warranty of
00013         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014         GNU General Public License for more details.
00015 
00016         You should have received a copy of the GNU General Public License
00017         along with this program; if not, write to the Free Software
00018         Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 
00020         The full text of the license can be found in license.txt
00021 */
00022 
00023 #ifndef LILITH_MOB_INCLUDED
00024 #define LILITH_MOB_INCLUDED
00025 
00026 #ifdef _MSC_VER
00027 #pragma warning( disable : 4786 )       // Debugger truncating names.
00028 #pragma warning( disable : 4530 )       // Exception handler isn't used
00029 #endif
00030 
00031 #include <set>
00032 #include <vector>
00033 
00034 #include "../grinliz/gldebug.h"
00035 #include "../grinliz/glrandom.h"
00036 #include "../grinliz/glvector.h"
00037 #include "genericobject.h"
00038 
00039 namespace lilith3d
00040 {
00041 
00042 class TimeClock;
00043 class TerrainMesh;
00044 class AnimatedMesh;
00045 class Lilith3D;
00046 class DecalMesh;
00047 class MeshResource;
00048 class AnimatedResource;
00049 class LilithObject;
00050 class MD2Resource;
00051 class MD2Mesh;
00052 class BuildingMesh;
00053 
00054 
00072 class Mob
00073 {
00074   public:
00075         Mob();
00076         virtual ~Mob();
00077 
00078         virtual void Update( TimeClock* tc ) = 0;
00079 
00080         bool Alive()    { return alive; }       
00081         void Kill();                                            
00082 
00083         virtual void KillAnimation() = 0;
00084 
00085   protected:
00086 
00087   private:
00088         bool alive;
00089 };
00090 
00091 const float MOB_STAND = -360.0f;
00092 
00097 class WalkingMob : public Mob
00098 {
00099   public:
00100 
00103         WalkingMob( const MD2Resource* res, float x, float y );
00104         virtual ~WalkingMob();
00105 
00106         // internal
00107         virtual void Update( TimeClock* tc );
00108 
00112         void PathTo( float x, float y, float z=0.0f );
00113 
00117         void PathTo( const LilithObject& object );
00118 
00119         bool IsPathing()        { return path != 0; }
00120 
00123         void Move( float rotationBias );
00124 
00128         void Rotate( int dir );
00130         int Rotating() {
00131                 if ( !path ) return rotate;
00132                 return 0;
00133         }
00134 
00138         void SetPos( const grinliz::Vector3F& location, float rotation );
00139 
00143         void SetPos( float x, float y, float rotation )
00144         {
00145                 grinliz::Vector3F at = { x, y, 0.0f };
00146                 SetPos( at, rotation );
00147         }
00148         
00149         const grinliz::Vector3F& Pos(); 
00150         const float    ZRot();                  
00151 
00153         bool Attack();
00155         bool Emote( int id );
00157         bool Stun();
00159         bool Stand();
00160 
00163         int GetAction();
00164 
00166         void SetPathIllumination( bool _illuminate )    { this->illuminate = _illuminate; }
00167 
00168         virtual void KillAnimation();
00169 
00170         const MD2Mesh* GetMD2Mesh() const                               { return mobileMesh; }
00171         //const AnimatedMesh* GetAnimatedMesh() const           { return mobileMesh; }
00172 
00173         const MD2Resource* GetMD2Resource() const;
00174         void UpdateZFromPSI( PathSurfaceInstance* psi );
00175 
00176   private:
00177         // States:
00178         // Pathing, then 'path' is a valid pointer
00179         // else:
00180         //              Moving, then the current action is checked, and rotationBias applied of running
00181     //          Rotation, the value of 'rotate' 
00182 
00183         float CalcRotation( float subDestX, float subDestY, float x, float y );
00184         void FindSpace();
00185 
00186         MD2Mesh                                                         *mobileMesh;
00187         std::vector< grinliz::Vector2F >        *path;                  // allocated to follow a path
00188         int                                                                     pathIndex;              // Where the mob is in the path vector.
00189         float                                                           rotationBias;   // for RELATIVE, motion relative to face (set up strafing)
00190         int                                                                     rotate;                 // +/- 1 or 0 for RELATIVE
00191         bool                                                            illuminate;             // light up the path for debugging or showing off
00192         bool                                                            repath;                 // repath if the path changes
00193 
00194         PathSurfaceInstance*                            standingOnPSI;
00195         PSIMobRing                                                      psiMobRing;
00196 
00197         static grinliz::Random random;
00198 };
00199 
00200 /*
00201 class MobGroup
00202 {
00203   public:
00204         MobGroup()                                      {       magic1= 0x01234567; magic2 = 0x89abcdef; }
00205         ~MobGroup()                                     {}
00206 
00207         void Add( Mob* mob )            {       GLASSERT( allMobs.find( mob ) == allMobs.end() ); 
00208                                                                         allMobs.insert( mob ); 
00209                                                                 }
00210         void Remove( Mob* mob )         {       GLASSERT( allMobs.find( mob ) != allMobs.end() );
00211                                                                         allMobs.erase( mob ); 
00212                                                                         GLASSERT( allMobs.find( mob ) == allMobs.end() );
00213                                                                 }
00214 
00215         void UpdateAll( TimeClock* tc )
00216         {
00217                 std::set< Mob* >::iterator it = allMobs.begin();
00218                 while ( it != allMobs.end() )
00219                 {
00220                         (*it)->Update( tc );
00221                         ++it;
00222                 }
00223         }
00224 
00225   private:
00226         U32 magic1;
00227         std::set< Mob* > allMobs;
00228         U32 magic2;
00229 };
00230 */
00231 
00232 class MobGroup
00233 {
00234   public:
00235         MobGroup()                                      {       magic1= 0x01234567; magic2 = 0x89abcdef; }
00236         ~MobGroup()                                     {}
00237 
00238         void Add( Mob* mob )            {       GLASSERT( Find( mob ) == allMobs.size() ); 
00239                                                                         allMobs.push_back( mob ); 
00240                                                                 }
00241         void Remove( Mob* mob )         {       unsigned i = Find( mob );
00242                                                                         GLASSERT( i != allMobs.size() );
00243                                                                         allMobs.erase( allMobs.begin()+i ); 
00244                                                                         GLASSERT( Find( mob ) == allMobs.size() );
00245                                                                 }
00246 
00247         void UpdateAll( TimeClock* tc )
00248         {
00249                 std::vector< Mob* >::iterator it = allMobs.begin();
00250                 while ( it != allMobs.end() )
00251                 {
00252                         (*it)->Update( tc );
00253                         ++it;
00254                 }
00255         }
00256 
00257         unsigned Find( Mob* mob ) 
00258         {
00259                 for( unsigned i=0; i<allMobs.size(); ++i ) {
00260                         if ( allMobs[i] == mob ) 
00261                                 return i;
00262                 }
00263                 return allMobs.size();
00264         }
00265 
00266   private:
00267         U32 magic1;
00268         std::vector< Mob* > allMobs;
00269         U32 magic2;
00270 };
00271 
00272 };
00273 
00274 #endif
00275 

Generated on Fri Mar 23 19:36:22 2007 for Lilith3D by  doxygen 1.5.1-p1