00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
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
00172
00173 const MD2Resource* GetMD2Resource() const;
00174 void UpdateZFromPSI( PathSurfaceInstance* psi );
00175
00176 private:
00177
00178
00179
00180
00181
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;
00188 int pathIndex;
00189 float rotationBias;
00190 int rotate;
00191 bool illuminate;
00192 bool repath;
00193
00194 PathSurfaceInstance* standingOnPSI;
00195 PSIMobRing psiMobRing;
00196
00197 static grinliz::Random random;
00198 };
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
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