ent.h

Go to the documentation of this file.
00001 /*
00002  * ent.h
00003  *
00004  *  Created on: Nov 20, 2011
00005  *      Author: sushil
00006  */
00007 
00008 #ifndef ENT_H_
00009 #define ENT_H_
00010 
00011 
00012 #include <iostream>
00013 #include <cstring>
00014 #include <assert.h>
00015 
00016 #include <boost/lexical_cast.hpp>
00017 
00018 
00019 #include <OgreVector3.h>
00020 #include <OgreQuaternion.h>
00021 
00022 #include <const.h>
00023 #include <utils.h>
00024 
00025 #include <command.h>
00026 #include <unitWeapons.h>
00027 #include <unitAI.h>
00028 #include <physics.h>
00029 
00030 #include <enums.h>
00031 #include <identity.h>
00032 #include "unitBuilder.h"
00033 
00034 //#include <aspect.h>
00035 #include <netAspect.h>
00036 
00037 
00038 namespace FastEcslent {
00039 
00040         class Engine ;
00041         class UnitAspect ;
00042 //      class GameMgr;
00043 
00044         class Entity {
00045 
00046         public:
00047                 static int count;
00048                 //physics and AI
00049 
00050                 Ogre::Vector3 pos;
00051                 Ogre::Vector3 vel;
00052                 Ogre::Vector3 acc;
00053 
00054                 Ogre::Vector3 potentialVec;
00055                 double attractivePotential;
00056 
00057                 Ogre::Quaternion rot;
00058                 float yaw;
00059                 float desiredSpeed;
00060                 float desiredHeading;
00061                 float speed;
00062                 float maxSpeed;
00063                 float minSpeed;
00064                 float speedRange;
00065                 float heading;
00066                 float maxAcceleration;
00067                 float maxRotationalSpeed;
00068 
00069 
00070                 float turningRadius;
00071 
00072                 float length, width, height, depth;
00073                 float mass;
00074 
00075                 std::string uiname;
00076                 std::string meshName;
00077 
00078                 Engine   *engine;
00079                 Identity entityId;
00080                 //int      idNumber;
00081                 EntityType entityType;   // cigarette, ddg, ...
00082                 EntityClass entityClass;//surface, air, building
00083 
00084                 //Game stuff
00085                 //bool     alive;
00086                 EntityState entityState;
00087                 double      gestationPeriod;
00088                 double      timeLeftToBirth;
00089                 double      timeLeftToDie;
00090 
00091                 double      hitpoints;
00092 
00093                 boost::mutex entLock;
00094 
00095                 std::deque<UnitAspect*> aspects;
00096                 //UnitAspect   *aspects[NASPECTTYPES];
00097                 Weapon*      weapon;
00098                 UnitAI*      ai;
00099                 Physics*     physics;
00100                 Builder*     builder;
00101                 NetAspect*   netAspect;
00102 
00103                 // selection
00104                 bool isSelected;
00105                 bool selectable;
00106                 bool didSelectSoundPlayed;
00107                 bool isNewBorn;
00108 
00109                 //Distance
00110 
00111                 /*Command *commands[MaxCommands];
00112                 int     nCommands;
00113 */
00114 
00115         private:
00116                 void reset();
00117 
00118         protected:
00119                 virtual void init();
00120 
00121         public:
00122                 Entity(Engine *eng, EntityType entType) ;
00123 
00124                 UnitAspect *getAspect(UnitAspectType i);
00125                 void        removeAspect(UnitAspectType i);
00126                 void         addAspect(UnitAspect* asp);
00127                 void            switchState(EntityState newState);
00128 
00129                 virtual void print();
00130                 virtual void tick(double dt);
00131                 //****************************************************************************************************************
00132                 //void(Entity::*tick)(double); // The tick function called depends on entity's state. One of the next four possibilities
00133 //              /TickType tick;
00134                 //****************************************************************************************************************
00135                 virtual void gestatingTick(double dt);
00136                 virtual void aliveTick(double dt);
00137                 virtual void dyingTick(double dt);
00138                 virtual void deadTick(double dt);
00139                 //****************************************************************************************************************
00140                 virtual bool raising(double dt);
00141                 virtual bool sinking(double dt);
00142 
00143         };
00144 
00145 
00146         class Marine : public Entity { //marine
00147 
00148         public:
00149 
00150                 Marine(Engine *eng) : Entity(eng, MARINE) {
00151                         meshName = "cigarette.mesh";
00152                         uiname = "Cigarette.";
00153                         uiname.append(boost::lexical_cast<std::string>(count++));
00154 
00155 
00156                         // properties
00157                         length = meters(20.0f);
00158                         width  = meters(4.0f);
00159                         height = meters(6.0f);
00160 
00161                         maxSpeed = knots(45.0f);
00162                         minSpeed = knots(0.0f);
00163                         speedRange = maxSpeed - minSpeed + EPSILON;
00164                         maxAcceleration = feetPerSecondSquared(15.0f);
00165                         maxRotationalSpeed = degreesPerSecond(6.5f);
00166                         turningRadius = 10;
00167                         mass = pounds(1100);
00168 
00169                         selectable = true;
00170 
00171                         entityId.side = RED;
00172 
00173                         hitpoints = 50;
00174 
00175                 }
00176         };
00177 
00178         class Reaper : public Entity { // flamer
00179 
00180         public:
00181 
00182                 Reaper(Engine *eng) : Entity(eng, REAPER) {
00183                         meshName = "boat.mesh";
00184                         uiname = "SpeedBoat.";
00185                         uiname.append(boost::lexical_cast<std::string>(count++));
00186 
00187 
00188                         // properties
00189                         length = 10.0f;
00190                         width  = 4.0f;
00191                         height = 6.0f;
00192                         maxSpeed = knots(40.0f);
00193                         minSpeed = knots(0.0f);
00194                         speedRange = maxSpeed - minSpeed + EPSILON;
00195                         maxAcceleration = 20.0f;
00196                         maxRotationalSpeed = 2.5f;
00197                         turningRadius = 10;
00198                         mass = pounds(1100);
00199 
00200                         selectable = true;
00201 
00202                         entityId.side = RED;
00203 
00204                         hitpoints = 60;
00205                 }
00206         };
00207 
00208         class Tank : public Entity { //tank
00209 
00210         public:
00211 
00212                 Tank(Engine *eng) : Entity(eng, TANK) {
00213                         meshName = "ddg51.mesh";
00214                         uiname = "DDG51.";
00215                         uiname.append(boost::lexical_cast<std::string>(count++));
00216 
00217                         // properties
00218                         length = feet(466.0f);
00219                         width  = feet(59.0f);
00220                         height = feet(100.0f);
00221                         maxSpeed = knots(30.0f);
00222                         minSpeed = knots(0.0f);
00223                         speedRange = maxSpeed - minSpeed + EPSILON;
00224                         maxAcceleration = feetPerSecondSquared(10.0f);
00225                         maxRotationalSpeed = degreesPerSecond(1.0f);
00226                         turningRadius = 750;
00227                         mass = tons(842);
00228 
00229                         selectable = true;
00230 
00231                         entityId.side = BLUE;
00232 
00233                         hitpoints = 160;
00234                 }
00235         };
00236 
00237 
00238         class Thor : public Entity {
00239 
00240         public:
00241 
00242                 Thor(Engine *eng) : Entity(eng, THOR) {
00243                         meshName = "cvn68.mesh";
00244                         uiname = "CVN68.";
00245                         uiname.append(boost::lexical_cast<std::string>(count++));
00246 
00247                         // properties
00248                         length = meters(332.0f);
00249                         width  = meters(200.0f);
00250                         height = meters(100.0f);
00251 
00252                         maxSpeed = knots(30.0f);
00253                         minSpeed = knots(0.0f);
00254                         speedRange = maxSpeed - minSpeed + EPSILON;
00255 
00256                         maxAcceleration = feetPerSecondSquared(9.0f);
00257                         maxRotationalSpeed = degreesPerSecond(0.5f);
00258                         turningRadius = 100;
00259                         mass = tons(1100);
00260 
00261                         selectable = true;
00262 
00263                         entityId.side = BLUE;
00264 
00265                         hitpoints = 400;
00266                 }
00267         };
00268 
00269         class Marauder : public Entity {
00270 
00271         public:
00272 
00273                 Marauder(Engine *eng) : Entity(eng, MARAUDER) {
00274                         meshName = "sleek.mesh";
00275                         uiname = "Sleek.";
00276                         uiname.append(boost::lexical_cast<std::string>(count++));
00277 
00278                         // properties
00279                         length = meters(30.0f);
00280                         width  = meters(20.0f);
00281                         height = meters(10.0f);
00282                         maxSpeed = knots(40.0f);
00283                         minSpeed = knots(0.0f);
00284                         speedRange = maxSpeed - minSpeed + EPSILON;
00285 
00286                         maxAcceleration = feetPerSecondSquared(20.0f);
00287                         maxRotationalSpeed = degreesPerSecond(1.5f);
00288                         turningRadius = 10;
00289                         mass = tons(75);
00290 
00291                         selectable = true;
00292 
00293                         entityId.side = BLUE;
00294 
00295                         hitpoints = 125;
00296 
00297                 }
00298         };
00299 
00300         class Helion : public Entity {
00301 
00302         public:
00303 
00304                 Helion(Engine *eng) : Entity(eng, HELLION) {
00305                         meshName = "alienship.mesh";
00306                         uiname = "AlienShip.";
00307                         uiname.append(boost::lexical_cast<std::string>(count++));
00308 
00309                         // properties
00310                         length = meters(5.0f);
00311                         width  = meters(2.0f);
00312                         height = meters(5.0f);
00313                         maxSpeed = knots(60.0f);
00314                         minSpeed = knots(0.0f);
00315                         speedRange = maxSpeed - minSpeed + EPSILON;
00316 
00317                         maxAcceleration = feetPerSecondSquared(20.0f);
00318                         maxRotationalSpeed = degreesPerSecond(2.5f);
00319                         turningRadius = 8;
00320                         mass = tons(0.6);
00321 
00322                         selectable = true;
00323 
00324                         entityId.side = YELLOW;
00325 
00326                         hitpoints = 70;
00327 
00328                 }
00329         };
00330         
00331 
00332         class SCVehicle : public Entity {
00333 
00334         public:
00335 
00336                 float mineralCount;
00337                 float mineralOccupyTime;
00338                 float maxMineralCount;
00339                 float mineralGatherRate;
00340 
00341                 float gasCount;
00342                 float gasOccupyTime;
00343                 float maxGasCount;
00344                 float gasGatherRate;
00345 
00346                 SCVehicle(Engine *eng) : Entity(eng, SCV) {
00347                         meshName = "scv.mesh";
00348                         uiname = "SpaceConstructionVehicle";
00349                         uiname.append(boost::lexical_cast<std::string>(count++));
00350 
00351                         // properties
00352                         length = meters(30.0f);
00353                         width  = meters(2.0f);
00354                         height = meters(5.0f);
00355                         maxSpeed = knots(20.0f);
00356                         minSpeed = knots(0.0f);
00357                         speedRange = maxSpeed - minSpeed + EPSILON;
00358                         speed = 0.0f;
00359                         desiredSpeed = 0.0f;
00360 
00361                         maxAcceleration = feetPerSecondSquared(20.0f);
00362                         maxRotationalSpeed = degreesPerSecond(5.5f);
00363                         turningRadius = 100;
00364                         mass = tons(0.5);
00365 
00366                         selectable = true;
00367 
00368                         entityId.side = YELLOW;
00369 
00370                         // http://wiki.teamliquid.net/starcraft2/Resources
00371                         mineralCount = 0;
00372                         maxMineralCount = 5; //per trip
00373                         mineralOccupyTime = 2.786;
00374                         mineralGatherRate = maxMineralCount/mineralOccupyTime;
00375 
00376                         gasCount = 0;
00377                         maxGasCount = 4; // per trip
00378                         gasOccupyTime = 5.981;//1.981;
00379                         gasGatherRate = maxGasCount/gasOccupyTime;
00380                         
00381                         hitpoints = 50;
00382 
00383             this->init();
00384                         
00385                 }
00386         virtual void init();
00387         };
00388 
00389 
00390 }
00391 
00392 #endif /* ENT_H_ */

Generated on Fri Dec 13 14:54:15 2013 for FastECSLent by  doxygen 1.5.4