UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cl_localentity.h
Go to the documentation of this file.
1 
5 /*
6 Copyright (C) 2002-2020 UFO: Alien Invasion.
7 
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 
17 See the GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 
23 */
24 
25 #pragma once
26 
27 #include "../renderer/r_entity.h"
28 
30 typedef enum {
38 } actorModes_t;
39 
40 #define IS_MODE_FIRE_RIGHT(x) ((x) == M_FIRE_R || (x) == M_PEND_FIRE_R)
41 #define IS_MODE_FIRE_LEFT(x) ((x) == M_FIRE_L || (x) == M_PEND_FIRE_L)
42 #define IS_MODE_FIRE_HEADGEAR(x) ((x) == M_FIRE_HEADGEAR)
43 #define IS_MODE_FIRE_PENDING(x) ((x) == M_PEND_FIRE_L || (x) == M_PEND_FIRE_R)
44 
45 typedef bool (*localEntitiyAddFunc_t) (struct le_s* le, entity_t* ent);
46 typedef void (*localEntityThinkFunc_t) (struct le_s* le);
47 
48 #define LE_CHECK_LEVELFLAGS 0x0001
49 #define LE_ALWAYS_VISIBLE 0x0002
50 #define LE_LOCKED 0x0004
52 #define LE_REMOVE_NEXT_FRAME 0x0008
53 #define LE_INVISIBLE 0x0010
54 #define LE_SELECTED 0x0020
56 typedef struct leStep_s {
57  int steps;
58  int lastMoveTime;
59  int lastMoveDuration;
60  int stepTimes[MAX_ROUTE];
61  struct leStep_s* next;
63 
65 typedef struct le_s {
66  bool inuse;
68  int entnum;
72  int angle;
75  int dir;
76 
77  int TU, maxTU;
79  int HP, maxHP;
80  int STUN;
81  int state;
83 
84  float angles[3];
85  float alpha;
87  int team;
88  int pnum;
89  int ucn;
91  int flags;
92 
94 
105  struct le_s* clientAction;
107  int contents;
111  char inlineModelName[8];
112  unsigned int modelnum1;
113  unsigned int modelnum2;
114  unsigned int bodySkin;
115  unsigned int headSkin;
123  int thinkDelay;
131  int stepIndex;
133  int startTime, endTime;
138  inline bool isMoving () const
139  {
140  return pathLength > 0;
141  }
142 
144  int sampleIdx;
145  float attenuation;
146  float volume;
149  animState_t as;
150  const char* particleID;
153  const char* ref1, *ref2;
154  const struct le_s* ref3;
162  int gender;
163  const fireDef_t* fd;
168  inline Item* getRightHandItem () const
169  {
170  return inv.getRightHandContainer();
171  }
172  inline Item* getLeftHandItem () const
173  {
174  return inv.getLeftHandContainer();
175  }
176  inline Item* getHandItem (actorHands_t hand) const
177  {
178  if (hand == ACTOR_HAND_RIGHT)
179  return inv.getRightHandContainer();
180  else if (hand == ACTOR_HAND_LEFT)
181  return inv.getLeftHandContainer();
182  return nullptr;
183  }
184  inline Item* getFloorContainer () const
185  {
186  return inv.getFloorContainer();
187  }
188  inline void setFloorContainer (Item* il)
189  {
190  inv.setFloorContainer(il);
191  }
192  inline void setFloor (le_s* other)
193  {
194  inv.setFloorContainer(other->getFloorContainer());
195  }
196  inline void resetFloor ()
197  {
198  inv.setFloorContainer(nullptr);
199  }
200  void init ();
201 } le_t;
202 
203 #define MAX_LOCALMODELS 1024
206 typedef struct localModel_s {
207  char id[MAX_VAR];
209  char name[MAX_QPATH];
211  char tagname[MAX_VAR];
214  struct localModel_s* parent;
215  bool inuse;
217  vec3_t origin;
221  int entnum;
223  int skin;
225  int frame;
231  void (*think) (struct localModel_s* localModel);
233  model_t* model;
235  inline void setScale(const vec3_t scale_) {
236  VectorCopy(scale_, scale);
237  }
238 } localModel_t;
239 
240 static const vec3_t player_mins = { -PLAYER_WIDTH, -PLAYER_WIDTH, PLAYER_MIN };
244 extern cvar_t* cl_le_debug;
245 extern cvar_t* cl_trace_debug;
246 extern cvar_t* cl_leshowinvis;
248 
249 const char* LE_GetAnim(const char* anim, int right, int left, int state);
250 void LE_AddProjectile(const fireDef_t* fd, int flags, const vec3_t muzzle, const vec3_t impact, int normal, le_t* leVictim);
251 void LE_AddGrenade(const fireDef_t* fd, int flags, const vec3_t muzzle, const vec3_t v0, int dt, le_t* leVictim);
252 void LE_AddAmbientSound(const char* sound, const vec3_t origin, int levelflags, float volume, float attenuation);
253 int LE_ActorGetStepTime(const le_t* le, const pos3_t pos, const pos3_t oldPos, const int dir, const int sped);
254 
255 #define LE_IsStunned(le) (((le)->state & STATE_STUN) & ~STATE_DEAD)
257 #define LE_IsDead(le) ((le)->state & STATE_DEAD)
258 #define LE_IsPanicked(le) ((le)->state & STATE_PANIC)
259 #define LE_IsRaged(le) ((le)->state & STATE_RAGE)
260 #define LE_IsInsane(le) ((le)->state & STATE_INSANE)
261 #define LE_IsShaken(le) ((le)->state & STATE_SHAKEN)
262 #define LE_IsCrouched(le) ((le)->state & STATE_CROUCHED)
263 #define LE_IsDazed(le) ((le)->state & STATE_DAZED)
265 #define LE_IsInvisible(le) ((le)->flags & LE_INVISIBLE)
266 #define LE_IsSelected(le) ((le)->flags & LE_SELECTED)
268 #define LE_SetInvisible(le) do { if (cl_leshowinvis->integer) le->flags &= ~LE_INVISIBLE; else le->flags |= LE_INVISIBLE; } while (0)
270 #define LE_IsItem(le) ((le)->type == ET_ITEM)
271 #define LE_IsCamera(le) ((le)->type == ET_CAMERA)
272 #define LE_IsCivilian(le) ((le)->team == TEAM_CIVILIAN)
273 #define LE_IsAlien(le) ((le)->team == TEAM_ALIEN)
274 #define LE_IsPhalanx(le) ((le)->team == TEAM_PHALANX)
275 #define LE_IsRotating(le) ((le)->type == ET_ROTATING)
276 #define LE_IsDoor(le) ((le)->type == ET_DOOR || (le)->type == ET_DOOR_SLIDING)
277 #define LE_IsBreakable(le) ((le)->type == ET_BREAKABLE)
278 #define LE_IsBrushModel(le) (LE_IsBreakable(le) || LE_IsDoor(le) || LE_IsRotating(le))
279 #define LE_IsNotSolid(le) ((le)->type == ET_TRIGGER_RESCUE || (le)->type == ET_TRIGGER_NEXTMAP)
282 #define LE_GetAnimationIndexForDeath(le) ((le)->state & MAX_DEATH)
284 #ifdef DEBUG
285 void LE_List_f(void);
286 void LM_List_f(void);
287 #endif
288 
290 void LE_ExecuteThink(le_t* le);
291 void LE_Think(void);
292 /* think functions */
293 void LET_StartIdle(le_t* le);
294 void LET_Appear(le_t* le);
295 void LET_StartPathMove(le_t* le);
296 void LET_HiddenMove(le_t* le);
297 void LET_BrushModel(le_t* le);
298 void LE_DoEndPathMove(le_t* le);
299 
300 /* local model functions */
301 void LM_Think(void);
302 void LMT_Init(localModel_t* localModel);
303 localModel_t* LM_AddModel(const char* model, const vec3_t origin, const vec3_t angles, int entnum, int levelflags, int flags, const vec3_t scale);
304 void LM_Perish(dbuffer* msg);
305 void LM_AddToScene(void);
306 
307 bool LE_BrushModelAction(le_t* le, entity_t* ent);
308 void CL_RecalcRouting(const le_t* le);
309 void CL_CompleteRecalcRouting(void);
310 
311 void LE_LinkFloorContainer(le_t* le);
312 bool LE_IsLivingAndVisibleActor(const le_t* le);
313 bool LE_IsLivingActor(const le_t* le);
314 bool LE_IsActor(const le_t* le);
315 le_t* LE_Add(int entnum);
316 le_t* LE_Get(int entnum);
317 le_t* LE_GetNextInUse(le_t* lastLE);
318 le_t* LE_GetNext(le_t* lastLE);
319 void LE_Lock(le_t* le);
320 void LE_Unlock(le_t* le);
321 bool LE_IsLocked(int entnum);
322 #define LE_NotFoundError(entnum) _LE_NotFoundError(entnum, -1, __FILE__, __LINE__)
323 #define LE_NotFoundWithTypeError(entnum, type) _LE_NotFoundError(entnum, type, __FILE__, __LINE__)
324 void _LE_NotFoundError(int entnum, int type, const char* file, const int line) __attribute__((noreturn));
325 le_t* LE_Find(entity_type_t type, const pos3_t pos);
326 le_t* LE_FindRadius(le_t* from, const vec3_t org, float rad, entity_type_t type);
327 le_t* LE_GetFromPos(const pos3_t pos);
328 void LE_PlaceItem(le_t* le);
329 void LE_Cleanup(void);
330 void LE_AddToScene(void);
331 void LE_CenterView(const le_t* le);
332 const cBspModel_t* LE_GetClipModel(const le_t* le);
333 model_t* LE_GetDrawModel(unsigned int modelIndex);
334 void LET_SlideDoor(le_t* le, int speed);
335 void LET_RotateDoor(le_t* le, int speed);
336 
337 trace_t CL_Trace(const Line& traceLine, const AABB& box, const le_t* passle, le_t* passle2, int contentmask, int worldLevel);
338 
339 void LM_Register(void);
340 localModel_t* LM_GetByID(const char* id);
void LET_StartPathMove(le_t *le)
Change the actors animation to walking.
cvar_t * cl_trace_debug
float rotationSpeed
animState_t as
#define PLAYER_WIDTH
Definition: q_sizes.h:10
#define VectorCopy(src, dest)
Definition: vector.h:51
pos3_t newPos
void LE_Think(void)
Calls the le think function and updates the animation. The animation updated even if the particular l...
void LMT_Init(localModel_t *localModel)
int ucn
vec3_t size
Item * getLeftHandItem() const
teamDef_t * teamDef
QGL_EXTERN GLint GLenum type
Definition: r_gl.h:94
void _LE_NotFoundError(int entnum, int type, const char *file, const int line) __attribute__((noreturn))
int thinkDelay
this is a fire definition for our weapons/ammo
Definition: inv_shared.h:110
void setFloorContainer(Item *il)
int pnum
int entnum
int dir
int startTime
static const vec3_t scale
float angles[3]
int gender
This is a cvar definition. Cvars can be user modified and used in our menus e.g.
Definition: cvar.h:71
pos3_t pos
bool LE_IsActor(const le_t *le)
Checks whether the given le is a living actor.
cvar_t * cl_le_debug
void LET_Appear(le_t *le)
float alpha
voidpf uLong int origin
Definition: ioapi.h:45
int pathPos
int positionContents
void LM_Think(void)
void LE_AddAmbientSound(const char *sound, const vec3_t origin, int levelflags, float volume, float attenuation)
Adds ambient sounds from misc_sound entities.
int32_t actorSizeEnum_t
Definition: ufotypes.h:77
Definition: aabb.h:42
void init()
void LET_BrushModel(le_t *le)
bool LE_BrushModelAction(le_t *le, entity_t *ent)
Add function for brush models.
Item * getLeftHandContainer() const
Definition: inv_shared.cpp:960
char inlineModelName[8]
bool LE_IsLivingActor(const le_t *le)
Checks whether the given le is a living actor (but might be hidden)
static int oldPos
int angle
struct le_s * clientAction
struct le_s le_t
a local entity
vec3_t origin
pos3_t oldPos
localModel_t * LM_GetByID(const char *id)
struct localModel_s localModel_t
local models
actorModes_t actorMode
int headgear
model_t * model
#define __attribute__(x)
Definition: cxx.h:37
struct localModel_s * parent
void LM_AddToScene(void)
Add the local models to the scene.
int slidingSpeed
int morale
Item * getFloorContainer() const
Definition: inv_shared.cpp:975
lighting structure which contains static and dynamic lighting info for entities
Definition: r_lighting.h:29
le_t * LE_FindRadius(le_t *from, const vec3_t org, float rad, entity_type_t type)
Returns entities that have origins within a spherical area.
void setScale(const vec3_t scale_)
void LET_RotateDoor(le_t *le, int speed)
Rotates a door in the given speed.
void CL_CompleteRecalcRouting(void)
void LET_StartIdle(le_t *le)
Change the animation of an actor to the idle animation (which can be panic, dead or stand) ...
actorModes_t
Actor actions.
int maxMorale
actorSizeEnum_t fieldSize
void resetFloor()
Item * getRightHandItem() const
item instance data, with linked list capability
Definition: inv_shared.h:402
#define PLAYER_DEAD
Definition: q_sizes.h:8
le_t * LE_Find(entity_type_t type, const pos3_t pos)
Searches a local entity on a given grid field.
int flags
inventory definition with all its containers
Definition: inv_shared.h:525
void LET_HiddenMove(le_t *le)
Handle move for invisible actors.
int right
le_t * LE_GetFromPos(const pos3_t pos)
Searches a local entity on a given grid field.
#define PLAYER_MIN
Definition: q_sizes.h:9
void LE_ExecuteThink(le_t *le)
Call think function for the given local entity if its still in use.
lighting_t lighting
#define MAX_VAR
Definition: shared.h:36
Item * getRightHandContainer() const
Definition: inv_shared.cpp:955
void(* localEntityThinkFunc_t)(struct le_s *le)
void LET_SlideDoor(le_t *le, int speed)
Slides a door.
pos3_t mousePendPos
int32_t fireDefIndex_t
Definition: inv_shared.h:78
struct leStep_s * next
int stepIndex
void LE_AddToScene(void)
static const vec3_t player_dead_maxs
#define MAX_ROUTE
Definition: defines.h:84
cvar_t * cl_leshowinvis
Definition: cl_main.cpp:72
actorHands_t
Definition: inv_shared.h:626
model_t * model1
char target[MAX_VAR]
void LE_PlaceItem(le_t *le)
localEntitiyAddFunc_t addFunc
int LE_ActorGetStepTime(const le_t *le, const pos3_t pos, const pos3_t oldPos, const int dir, const int sped)
int endTime
ptl_t * ptl
Definition: line.h:31
Item * getFloorContainer() const
const cBspModel_t * LE_GetClipModel(const le_t *le)
bool(* localEntitiyAddFunc_t)(struct le_s *le, entity_t *ent)
lighting_t lighting
Info on a wound.
Definition: chr_shared.h:350
char name[MAX_QPATH]
static const vec3_t player_mins
pos_t pos3_t[3]
Definition: ufotypes.h:58
model_t * model2
int sampleIdx
bool LE_IsLivingAndVisibleActor(const le_t *le)
Checks whether the given le is a living and visible actor.
float volume
void LE_Cleanup(void)
Cleanup unused LE inventories that the server sent to the client also free some unused LE memory...
const GLuint *typedef void(APIENTRY *GenRenderbuffersEXT_t)(GLsizei
Definition: r_gl.h:189
unsigned int bodySkin
#define PLAYER_STAND
Definition: q_sizes.h:6
const struct le_s * ref3
a local entity
cvar_t * cl_map_draw_rescue_zone
Inventory inv
const fireDef_t * fd
void LE_Lock(le_t *le)
Markes a le_t struct as locked. Should be called at the beginning of an event handler on this le_t...
int speed[MAX_ROUTE]
void LE_Unlock(le_t *le)
Unlocks a previously locked le_t struct.
int pathContents[MAX_ROUTE]
entity_type_t type
int HP
int maxTU
#define MAX_QPATH
Definition: filesys.h:40
const char * ref1
int pathLength
Item * getHandItem(actorHands_t hand) const
struct leStep_s leStep_t
float attenuation
unsigned int modelnum2
localEntityThinkFunc_t think
void LM_Register(void)
Register misc_models.
bool isMoving() const
byte actorMoveLength
The TUs that the current selected actor needs to walk to the current grid position marked by the mous...
void setFloorContainer(Item *cont)
Definition: inv_shared.cpp:950
AABB aabb
void LE_DoEndPathMove(le_t *le)
Ends the move of an actor.
bool inuse
void CL_RecalcRouting(const le_t *le)
dvec_t dvtab[MAX_ROUTE]
void LE_LinkFloorContainer(le_t *le)
link any floor container into the actor temp floor container
vec_t vec3_t[3]
Definition: ufotypes.h:39
entity_type_t
Definition: q_shared.h:145
const char * particleID
void LM_Perish(dbuffer *msg)
void(* think)(struct localModel_s *localModel)
le_t * LE_GetNextInUse(le_t *lastLE)
Iterate through the entities that are in use.
void LE_AddProjectile(const fireDef_t *fd, int flags, const vec3_t muzzle, const vec3_t impact, int normal, le_t *leVictim)
animState_t as
int contents
int TU
int levelflags
short dvec_t
The direction vector tells us where the actor came from (in his previous step). The pathing table hol...
Definition: mathlib.h:236
model_t * LE_GetDrawModel(unsigned int modelIndex)
int team
unsigned int headSkin
le_t * LE_Get(int entnum)
Searches all local entities for the one with the searched entnum.
void LE_AddGrenade(const fireDef_t *fd, int flags, const vec3_t muzzle, const vec3_t v0, int dt, le_t *leVictim)
void LE_CenterView(const le_t *le)
Center the camera on the local entity's origin.
int maxHP
void setFloor(le_s *other)
vec3_t oldOrigin
char tagname[MAX_VAR]
uint8_t byte
Definition: ufotypes.h:34
local models
leStep_t * stepList
int STUN
fireDefIndex_t currentSelectedFiremode
localModel_t * LM_AddModel(const char *model, const vec3_t origin, const vec3_t angles, int entnum, int levelflags, int flags, const vec3_t scale)
Prepares local (not known or handled by the server) models to the map, which will be added later in L...
bool LE_IsLocked(int entnum)
Checks if a given le_t structure is locked, i.e., used by another event at this time.
char animname[MAX_QPATH]
unsigned int modelnum1
int state
le_t * LE_Add(int entnum)
Add a new local entity to the scene.
const char * LE_GetAnim(const char *anim, int right, int left, int state)
Get the correct animation for the given actor state and weapons.
static const vec3_t player_maxs
trace_t CL_Trace(const Line &traceLine, const AABB &box, const le_t *passle, le_t *passle2, int contentmask, int worldLevel)
Moves the given mins/maxs volume through the world from start to end.
int left
woundInfo_t wounds
void LE_SetThink(le_t *le, localEntityThinkFunc_t think)
le_t * LE_GetNext(le_t *lastLE)
Iterate through the list of entities.
const char * ref2