00001 #ifndef __UNIT_H__
00002 #define __UNIT_H__
00003
00004 #pragma once
00005
00006 #include "Level.h"
00007 #include "AStarSearchManager.h"
00008
00009
00010 #include "OgreSceneManager.h"
00011 #include "OgreSceneNode.h"
00012 #include "OgreVector3.h"
00013 #include "OgreString.h"
00014 #include "OgreEntity.h"
00015 #include "OgreMath.h"
00016 #include "OgreUserDefinedObject.h"
00017 #include "OgreIteratorWrappers.h"
00018 #include "OgreAnimationState.h"
00019
00020 #include <list>
00021 #include <vector>
00022
00023 using Ogre::AnimationState;
00024 using Ogre::VectorIterator;
00025 using Ogre::UserDefinedObject;
00026 using Ogre::SceneManager;
00027 using Ogre::SceneNode;
00028 using Ogre::Node;
00029 using Ogre::Vector3;
00030 using Ogre::String;
00031 using Ogre::Entity;
00032 using Ogre::Real;
00033
00034 using std::list;
00035 using std::vector;
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 namespace ASR
00049 {
00050 class Projectile;
00051
00052
00053 class Unit : public UserDefinedObject
00054 {
00055
00056 public:
00057 static String TYPE_NAME;
00058
00059 typedef VectorIterator<list<Vector3>> WaypointIterator;
00060
00061 enum UnitStatus
00062 {
00063 US_IDLE,
00064 US_MOVING,
00065 US_DYING,
00066 US_DEAD,
00067 US_ATTACKING,
00068 US_CHASING
00069 };
00070
00071
00072
00073 private:
00074 int mCurHitPoints;
00075 int mMaxHitPoints;
00076
00077 float mRange;
00078 float mSightRadius;
00079
00080
00081
00082
00083 private:
00084
00085 Unit* mTarget;
00086
00087
00088 float mAttackTime;
00089
00091 float mFireRate;
00092
00093 typedef vector<Projectile*> BulletList;
00094 BulletList mProjectiles;
00095
00096
00097
00098
00099 private:
00100 AnimationState* mAnimationState;
00101
00102
00103
00104
00105 private:
00106
00107 bool mNavDirty;
00108
00109 Entity* mEntity;
00110
00111
00112 public:
00113 Entity* mShoulder;
00114 Entity* mShield;
00115 Entity* mWeapon;
00116
00117 private:
00118
00119 String mMeshName;
00120 String mUnitName;
00121
00122 SceneNode* mUnitNode;
00123
00124 static int mNumUnits;
00125
00126 AStarSearch<Level::LevelNode>* mSearch;
00127 list<Vector3> mWaypoints;
00128
00130 const static float mSearchUpdateTime;
00131
00133 float mSearchElapsedTime;
00134
00135 UnitStatus mStatus;
00136
00137
00138
00139 public:
00140 Unit( SceneNode* parentNode, String meshName );
00141 ~Unit(void);
00142
00143
00144
00145
00146
00147 public:
00148
00149
00150 String getUnitName () const;
00151 Entity* getEntity ();
00152 const String& getTypeName () const;
00153
00154 float getSightRadius () const;
00155 float getRange () const;
00156
00157
00158
00159
00160 public:
00161 void hide ();
00162 void show ();
00163
00164
00165 void scale ( Real x, Real y, Real z );
00166
00172 void setStatus ( UnitStatus status );
00173
00177 void updateAnimation ( float deltaTime );
00178
00179
00180
00181 public:
00182 void translate ( const Vector3& vec, Node::TransformSpace space = Node::TS_PARENT );
00183 Vector3 getPosition () const;
00184 void setPosition ( const Vector3& pos );
00185
00186 void setDirection ( const Vector3& dir );
00187 void setDirection ( float x, float y, float z );
00188
00189 void clearWaypoints ();
00190 void addWaypoint ( const Vector3& position );
00191
00192
00197 Vector3 getDestination ();
00198
00202 void removeDestination ();
00203
00208 bool hasDestination ();
00209
00210 WaypointIterator getWaypointIterator ();
00211
00216 void stopMovement ();
00217
00224 bool setDestination ( const Vector3& destination );
00225
00226 private:
00231 void _assignWaypoints ();
00232
00236 void _destroySearch ();
00237
00238
00239
00240
00241 public:
00246 void assignTarget ( Unit* target );
00247
00248
00255 bool isEngaged () const;
00256
00257
00263 Unit* getTarget () const;
00264
00269 void doAttack ();
00270
00274 void assignDamage ( int damage );
00275
00279 bool isDead () const;
00280
00281 private:
00286 float _getTimeBetweenAttacks ();
00287
00292 void _spawnAttack ();
00293
00297 void _updateProjectiles ();
00298
00303 float _getDistanceToTarget ();
00304
00308 void _destroyAttacks ();
00309
00313 float _calcDamage ( const Unit* unit ) const;
00314
00320 void _chaseTarget ();
00321
00322
00323
00324
00325 private:
00326 void _alignToWaypoint ();
00327 void _alignToTarget ();
00328 };
00329 }
00330
00331 #endif