home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2007 September / maximum-cd-2007-09.iso / Assets / data / AssaultCube_v0.93.exe / source / src / entity.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-05-28  |  7.4 KB  |  264 lines

  1. enum                            // static entity types
  2. {
  3.     NOTUSED = 0,                // entity slot not in use in map
  4.     LIGHT,                      // lightsource, attr1 = radius, attr2 = intensity
  5.     PLAYERSTART,                // attr1 = angle
  6.     I_CLIPS, I_AMMO,I_GRENADE,
  7.     I_HEALTH, I_ARMOUR, I_AKIMBO,
  8.     MAPMODEL,                   // attr1 = angle, attr2 = idx
  9.     CARROT,                     // attr1 = tag, attr2 = type
  10.     LADDER,
  11.     CTF_FLAG,                   // attr1 = angle, attr2 = red/blue
  12.     MAXENTTYPES
  13. };
  14.  
  15. #define isitem(i) (i >= I_CLIPS && i <= I_AKIMBO)
  16.  
  17. struct persistent_entity        // map entity
  18. {
  19.     short x, y, z;              // cube aligned position
  20.     short attr1;
  21.     uchar type;                 // type is one of the above
  22.     uchar attr2, attr3, attr4;
  23. };
  24.  
  25. struct entity : public persistent_entity
  26. {
  27.     bool spawned;               // the only dynamic state of a map entity
  28. };
  29.  
  30. enum { GUN_KNIFE = 0, GUN_PISTOL, GUN_SHOTGUN, GUN_SUBGUN, GUN_SNIPER, GUN_ASSAULT, GUN_GRENADE, NUMGUNS };
  31. #define reloadable_gun(g) (g != GUN_KNIFE && g != GUN_GRENADE)
  32.  
  33. #define isteam(a,b)   (m_teammode && strcmp(a, b)==0)
  34.  
  35. #define TEAM_CLA 0
  36. #define TEAM_RVSF 1
  37. #define team_valid(t) (!strcmp(t, "RVSF") || !strcmp(t, "CLA"))
  38. #define team_string(t) ((t) ? "RVSF" : "CLA")
  39. #define team_int(t) (strcmp((t), "CLA") == 0 ? TEAM_CLA : TEAM_RVSF)
  40. #define team_opposite(o) ((o) == TEAM_CLA ? TEAM_RVSF : TEAM_CLA)
  41.  
  42. struct itemstat { int add, start, max, sound; };
  43. // End add
  44.  
  45. enum { ENT_PLAYER = 0, ENT_BOT, ENT_CAMERA, ENT_BOUNCE };
  46. enum { CS_ALIVE = 0, CS_DEAD, CS_LAGGED, CS_EDITING };
  47. enum { CR_DEFAULT, CR_MASTER, CR_ADMIN };
  48.  
  49. struct physent
  50. {
  51.     vec o, vel;                         // origin, velocity
  52.     float yaw, pitch, roll;             // used as vec in one place
  53.     float maxspeed;                     // cubes per second, 24 for player
  54.     int timeinair;                      // used for fake gravity
  55.     float radius, eyeheight, aboveeye;  // bounding box size
  56.     bool inwater;
  57.     bool onfloor, onladder, jumpnext;
  58.     char move, strafe;
  59.     uchar state, type;
  60.  
  61.     physent() : o(0, 0, 0), yaw(270), pitch(0), roll(0), maxspeed(16),
  62.                 radius(1.1f), eyeheight(4.5f), aboveeye(0.7f),
  63.                 state(CS_ALIVE), type(ENT_PLAYER)
  64.     {
  65.         reset();
  66.     }
  67.  
  68.     void reset()
  69.     {
  70.         vel.x = vel.y = vel.z = 0;
  71.         move = strafe = 0;
  72.         timeinair = 0;
  73.         onfloor = onladder = inwater = jumpnext = false;
  74.     }
  75. };
  76.  
  77. struct dynent : physent                 // animated ent
  78. {
  79.     bool k_left, k_right, k_up, k_down; // see input code  
  80.  
  81.     animstate prev[2], current[2];              // md2's need only [0], md3's need both for the lower&upper model
  82.     int lastanimswitchtime[2];
  83.     void *lastmodel[2];
  84.  
  85.     void stopmoving()
  86.     {
  87.         k_left = k_right = k_up = k_down = jumpnext = false;
  88.         move = strafe = 0;
  89.     }
  90.  
  91.     void reset()
  92.     {
  93.         physent::reset();
  94.         stopmoving();
  95.     }
  96.  
  97.     dynent() { reset(); loopi(2) { lastanimswitchtime[i] = -1; lastmodel[i] = NULL; } }
  98. };
  99.  
  100. #define MAXNAMELEN 15
  101. #define MAXTEAMLEN 4
  102.  
  103. struct bounceent;
  104.  
  105. #define POSHIST_SIZE 7
  106.  
  107. struct poshist
  108. {
  109.     int nextupdate, curpos, numpos;
  110.     vec pos[POSHIST_SIZE];
  111.  
  112.     poshist() : nextupdate(0) { reset(); }
  113.  
  114.     const int size() const { return numpos; }
  115.     
  116.     void reset()
  117.     {
  118.         curpos = 0;
  119.         numpos = 0;
  120.     }
  121.  
  122.     void addpos(const vec &o)
  123.     {
  124.         pos[curpos] = o;
  125.         curpos++;
  126.         if(curpos>=POSHIST_SIZE) curpos = 0;
  127.         if(numpos<POSHIST_SIZE) numpos++;
  128.     }
  129.  
  130.     const vec &getpos(int i) const
  131.     {
  132.         i = curpos-1-i;
  133.         if(i < 0) i += POSHIST_SIZE;
  134.         return pos[i];
  135.     }
  136.  
  137.     void update(const vec &o, int lastmillis)
  138.     {
  139.         if(lastmillis<nextupdate) return;
  140.         if(o.dist(pos[0]) >= 4.0f) addpos(o);
  141.         nextupdate = lastmillis + 100;
  142.     }
  143. };
  144.  
  145. struct playerent : dynent
  146. {
  147.     int clientnum, lastupdate, plag, ping;
  148.     int lifesequence;                   // sequence id for each respawn, used in damage test
  149.     int frags, flagscore;
  150.     int health, armour;
  151.     int gunselect, gunwait;
  152.     int lastaction, lastattackgun, lastmove, lastpain, lastteamkill;
  153.     int clientrole;
  154.     bool attacking;
  155.     int ammo[NUMGUNS];
  156.     int mag[NUMGUNS];
  157.     string name, team;
  158.     int shots;                          //keeps track of shots from auto weapons
  159.     bool reloading, hasarmour, weaponchanging;
  160.     int nextweapon; // weapon we switch to
  161.     int primary;                        //primary gun
  162.     int nextprimary; // primary after respawning
  163.     int skin, nextskin; // skin after respawning
  164.  
  165.     int thrownademillis;
  166.     struct bounceent *inhandnade;
  167.     int akimbo;
  168.     int akimbolastaction[2];
  169.     int akimbomillis;
  170.  
  171.     poshist history; // Previous stored locations of this player
  172.  
  173.     playerent() : clientnum(-1), plag(0), ping(0), lifesequence(0), frags(0), flagscore(0), lastpain(0), lastteamkill(0), clientrole(CR_DEFAULT),
  174.                   shots(0), reloading(false), primary(GUN_ASSAULT), nextprimary(GUN_ASSAULT),
  175.                   skin(0), nextskin(0), inhandnade(NULL)
  176.     {
  177.         name[0] = team[0] = 0;
  178.         respawn();
  179.     }
  180.  
  181.     void respawn()
  182.     {
  183.         reset();
  184.         history.reset();
  185.         health = 100;
  186.         armour = 0;
  187.         hasarmour = false;
  188.         lastaction = akimbolastaction[0] = akimbolastaction[1] = 0;
  189.         akimbomillis = 0;
  190.         gunselect = GUN_PISTOL;
  191.         gunwait = 0;
  192.         attacking = false;
  193.         weaponchanging = false;
  194.         akimbo = 0;
  195.         loopi(NUMGUNS) ammo[i] = mag[i] = 0;
  196.     }
  197. };
  198.  
  199. class CBot;
  200.  
  201. struct botent : playerent
  202. {
  203.     // Added by Rick
  204.     CBot *pBot; // Only used if this is a bot, points to the bot class if we are the host,
  205.                 // for other clients its NULL
  206.     // End add by Rick      
  207.  
  208.     playerent *enemy;                      // monster wants to kill this entity
  209.     // Added by Rick: targetpitch
  210.     float targetpitch;                    // monster wants to look in this direction
  211.     // End add   
  212.     float targetyaw;                    // monster wants to look in this direction
  213.  
  214.     botent() : pBot(NULL), enemy(NULL) { type = ENT_BOT; }
  215. };
  216.  
  217. // Moved from server.cpp by Rick
  218. struct server_entity            // server side version of "entity" type
  219. {
  220.     bool spawned;
  221.     int spawnsecs;
  222. };
  223. // End move
  224.  
  225. enum { CTFF_INBASE = 0, CTFF_STOLEN, CTFF_DROPPED };
  226.  
  227. struct flaginfo
  228. {
  229.     int team;
  230.     entity *flag;
  231.     int actor_cn;
  232.     playerent *actor;
  233.     vec originalpos;
  234.     int state; // one of CTFF_*
  235.     bool ack;
  236.     flaginfo() : flag(0), actor(0), state(CTFF_INBASE), ack(false) {}
  237. };
  238.  
  239. enum { NADE_ACTIVATED = 1, NADE_THROWED, GIB};
  240.  
  241. struct bounceent : physent // nades, gibs
  242. {
  243.     int millis, timetolife, bouncestate; // see enum above
  244.     float rotspeed;
  245.     playerent *owner;
  246.  
  247.     bounceent() : bouncestate(0), rotspeed(1.0f), owner(NULL)
  248.     {
  249.         type = ENT_BOUNCE;
  250.         maxspeed = 40;
  251.         radius = 0.2f;
  252.         eyeheight = 0.3f;
  253.         aboveeye = 0.0f;
  254.     }
  255. };
  256.  
  257. #define NADE_IN_HAND (player1->gunselect==GUN_GRENADE && player1->inhandnade)
  258. #define NADE_THROWING (player1->gunselect==GUN_GRENADE && player1->thrownademillis && !player1->inhandnade)
  259.  
  260. #define has_akimbo(d) ((d)->gunselect==GUN_PISTOL && (d)->akimbo)
  261.  
  262. #define WEAPONCHANGE_TIME 400
  263.  
  264.