Initial sauer
[SauerbratenRemote.git] / src / shared / ents.h
blob9429b125081e4dc5e166f8466c2f5dffd0527232
1 // this file defines static map entities ("entity") and dynamic entities (players/monsters, "dynent")
2 // the gamecode extends these types to add game specific functionality
4 // ET_*: the only static entity types dictated by the engine... rest are gamecode dependent
6 enum { ET_EMPTY=0, ET_LIGHT, ET_MAPMODEL, ET_PLAYERSTART, ET_ENVMAP, ET_PARTICLES, ET_SOUND, ET_SPOTLIGHT, ET_GAMESPECIFIC };
8 struct entity // persistent map entity
10 vec o; // position
11 short attr1, attr2, attr3, attr4, attr5;
12 uchar type; // type is one of the above
13 uchar reserved;
16 enum
18 TRIGGER_RESET = 0,
19 TRIGGERING,
20 TRIGGERED,
21 TRIGGER_RESETTING,
22 TRIGGER_DISAPPEARED
25 struct extentity : entity // part of the entity that doesn't get saved to disk
27 uchar spawned, inoctanode, visible, triggerstate; // the only dynamic state of a map entity
28 vec color, dir;
29 int lasttrigger;
30 extentity *attached;
32 extentity() : visible(false), triggerstate(TRIGGER_RESET), lasttrigger(0), attached(NULL) {}
35 //extern vector<extentity *> ents; // map entities
37 enum
39 ANIM_DEAD = 0, ANIM_DYING, ANIM_IDLE,
40 ANIM_FORWARD, ANIM_BACKWARD, ANIM_LEFT, ANIM_RIGHT,
41 ANIM_PUNCH, ANIM_SHOOT, ANIM_PAIN,
42 ANIM_JUMP, ANIM_SINK, ANIM_SWIM,
43 ANIM_EDIT, ANIM_LAG, ANIM_TAUNT, ANIM_WIN, ANIM_LOSE,
44 ANIM_GUNSHOOT, ANIM_GUNIDLE,
45 ANIM_VWEP, ANIM_SHIELD, ANIM_POWERUP,
46 ANIM_MAPMODEL, ANIM_TRIGGER,
47 NUMANIMS
50 #define ANIM_INDEX 0xFF
51 #define ANIM_LOOP (1<<8)
52 #define ANIM_START (1<<9)
53 #define ANIM_END (1<<10)
54 #define ANIM_REVERSE (1<<11)
55 #define ANIM_DIR 0xF00
56 #define ANIM_SECONDARY 12
57 #define ANIM_NOSKIN (1<<24)
58 #define ANIM_ENVMAP (1<<25)
59 #define ANIM_TRANSLUCENT (1<<26)
60 #define ANIM_SHADOW (1<<27)
61 #define ANIM_SETTIME (1<<28)
62 #define ANIM_FLAGS (0x7F<<24)
64 struct animstate // used for animation blending of animated characters
66 int anim, frame, range, basetime;
67 float speed;
68 animstate() : anim(0), frame(0), range(0), basetime(0), speed(100.0f) { }
70 bool operator==(const animstate &o) const { return frame==o.frame && range==o.range && (anim&(ANIM_SETTIME|ANIM_DIR))==(o.anim&(ANIM_SETTIME|ANIM_DIR)) && (anim&ANIM_SETTIME || basetime==o.basetime) && speed==o.speed; }
71 bool operator!=(const animstate &o) const { return frame!=o.frame || range!=o.range || (anim&(ANIM_SETTIME|ANIM_DIR))!=(o.anim&(ANIM_SETTIME|ANIM_DIR)) || (!(anim&ANIM_SETTIME) && basetime!=o.basetime) || speed!=o.speed; }
74 #define ANIM_INDEX 0xFF
75 #define ANIM_LOOP (1<<8)
76 #define ANIM_START (1<<9)
77 #define ANIM_END (1<<10)
78 #define ANIM_REVERSE (1<<11)
79 #define ANIM_SECONDARY 12
80 #define ANIM_NOSKIN (1<<24)
81 #define ANIM_ENVMAP (1<<25)
82 #define ANIM_TRANSLUCENT (1<<26)
83 #define ANIM_SHADOW (1<<27)
84 #define ANIM_FLAGS (0x7F<<24)
86 enum { CS_ALIVE = 0, CS_DEAD, CS_SPAWNING, CS_LAGGED, CS_EDITING, CS_SPECTATOR };
88 enum { PHYS_FLOAT = 0, PHYS_FALL, PHYS_SLIDE, PHYS_SLOPE, PHYS_FLOOR, PHYS_STEP_UP, PHYS_STEP_DOWN, PHYS_BOUNCE };
90 enum { ENT_PLAYER = 0, ENT_AI, ENT_INANIMATE, ENT_CAMERA, ENT_BOUNCE };
92 enum { COLLIDE_AABB = 0, COLLIDE_ELLIPSE };
94 struct physent // base entity type, can be affected by physics
96 vec o, vel, gravity; // origin, velocity, accumulated gravity
97 float yaw, pitch, roll;
98 float maxspeed; // cubes per second, 100 for player
99 int timeinair;
100 float radius, eyeheight, aboveeye; // bounding box size
101 float xradius, yradius;
102 vec floor; // the normal of floor the dynent is on
104 bool inwater;
105 bool jumpnext;
106 bool blocked, moving; // used by physics to signal ai
107 physent *onplayer;
108 int lastmove, lastmoveattempt, collisions, stacks;
110 char move, strafe;
112 uchar physstate; // one of PHYS_* above
113 uchar state; // one of CS_* above
114 uchar type; // one of ENT_* above
115 uchar collidetype; // one of COLLIDE_* above
117 physent() : o(0, 0, 0), yaw(270), pitch(0), roll(0), maxspeed(100),
118 radius(4.1f), eyeheight(14), aboveeye(1), xradius(4.1f), yradius(4.1f),
119 blocked(false), moving(true),
120 onplayer(NULL), lastmove(0), lastmoveattempt(0), collisions(0), stacks(0),
121 state(CS_ALIVE), type(ENT_PLAYER),
122 collidetype(COLLIDE_ELLIPSE)
123 { reset(); }
125 void reset()
127 inwater = false;
128 timeinair = strafe = move = 0;
129 physstate = PHYS_FALL;
130 vel = gravity = vec(0, 0, 0);
134 struct occludequery;
136 struct dynent : physent // animated characters, or characters that can receive input
138 bool k_left, k_right, k_up, k_down; // see input code
139 float targetyaw, rotspeed; // AI rotation
140 float lastyaw, lastpitch; // last yaw/pitch to interpolate from, MP only
141 int orientmillis; // time last yaw/pitch was recorded
143 animstate prev[2], current[2]; // md2's need only [0], md3's need both for the lower&upper model
144 int lastanimswitchtime[2];
145 void *lastmodel[2];
146 occludequery *query;
147 int occluded, lastrendered;
149 dynent() : lastyaw(0), lastpitch(0), orientmillis(0), query(NULL), occluded(0), lastrendered(0)
151 reset();
152 loopi(2) { lastanimswitchtime[i] = -1; lastmodel[i] = NULL; }
155 void stopmoving()
157 k_left = k_right = k_up = k_down = jumpnext = false;
158 move = strafe = 0;
159 targetyaw = rotspeed = 0;
162 void reset()
164 physent::reset();
165 stopmoving();
168 vec abovehead() { return vec(o).add(vec(0, 0, aboveeye+4)); }
170 void normalize_yaw(float angle)
172 while(yaw<angle-180.0f) yaw += 360.0f;
173 while(yaw>angle+180.0f) yaw -= 360.0f;