UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
g_edict.h
Go to the documentation of this file.
1 
6 /*
7 All original material Copyright (C) 2002-2020 UFO: Alien Invasion.
8 
9 Original file from Quake 2 v3.21: quake2-2.31/game/g_local.h
10 Copyright (C) 1997-2001 Id Software, Inc.
11 
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License
14 as published by the Free Software Foundation; either version 2
15 of the License, or (at your option) any later version.
16 
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 
21 See the GNU General Public License for more details.
22 
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 
27 */
28 
29 #pragma once
30 
31 #include "../shared/ufotypes.h"
32 
37 #define INH 0
38 /* This is an attempt to inherit Edict from the part known to the server.
39  * This fails because the server knows about parent/child relations between Edicts. */
40 #if INH
41 #include "srvedict.h"
42 class Edict : public SrvEdict {
43 public:
44 #else
45 class Edict {
46 public:
47  bool inuse;
48  int linkcount;
51  int number;
59 
63 
66  int modelindex;
67  const char* classname;
68 #endif
69  /*================================ */
70  /* don't change anything above here - the server expects the fields in that order */
71  /*================================ */
72 
73  int mapNum;
74  const char* model;
80  const Edict* link;
88  int TU;
89  int HP;
90  int _STUN;
91  int morale;
93  int state;
95 protected:
96  int team;
97  int pnum;
99  unsigned int body;
100  unsigned int head;
101 public:
102  int frame;
104  char* group;
108 protected:
111 public:
114 
117 
120  float angle;
123  int radius;
124  int speed;
125  const char* target;
126  const char* targetname;
127  const char* item;
128  const char* particle;
129  const char* nextmap;
130  const char* message;
131  const char* description;
132  const char* noise;
135  int count;
136  int time;
137  int sounds;
138  int dmg;
142  bool hiding;
146  bool (*_touch)(Edict* self, Edict* activator);
148  void (*reset)(Edict* self, Edict* activator);
149  float nextthink;
150  void (*think)(Edict* self);
154  bool (*use)(Edict* self, Edict* activator);
155  bool (*destroy)(Edict* self);
156 
158  int doorState;
161 
169  int flags;
177  bool active;
179  /*==================
180  * ctors
181  *==================*/
182  void init (int idx);
183  /*==================
184  * setters
185  *==================*/
186  inline void setPlayerNum(int num) {
187  pnum = num;
188  }
189  inline void setTeam(int team_) {
190  team = team_;
191  }
192  inline void setChild (Edict* child) {
193  _child = child;
194  }
195  inline void nativeReset () { /* strange name, but there is also a complex function named 'reset' */
196  init(number); /* ... preserve the number */
197  }
198  inline void setActive() {
199  active = true;
200  }
201  inline void toggleActive() {
202  active ^= true;
203  }
204  inline void resetContainer (const containerIndex_t idx) {
205  chr.inv.resetContainer(idx);
206  }
207  inline void setFloor (const Edict* other) {
208  chr.inv.setFloorContainer(other->getFloor());
209  }
210  inline void resetFloor () {
211  chr.inv.setFloorContainer(nullptr);
212  }
216  inline void calcOrigin () {
217  gi.GridPosToVec(fieldSize, pos, origin);
218  }
223  inline void setOrigin (const pos3_t newPos) {
224  VectorCopy(newPos, pos);
225  calcOrigin();
226  }
227 
228  /*==================
229  * getters
230  *==================*/
231  inline int getIdNum() const {
232  return number;
233  }
234  inline int getPlayerNum() const {
235  return pnum;
236  }
237  inline Edict* child () {
238  return _child;
239  }
240  inline Edict* owner () {
241  return _owner;
242  }
243  inline Item* getContainer (const containerIndex_t idx) const {
244  return chr.inv.getContainer2(idx);
245  }
246  inline Item* getArmour () const {
247  return chr.inv.getArmour();
248  }
249  inline Item* getRightHandItem () const {
250  return chr.inv.getRightHandContainer();
251  }
252  inline Item* getLeftHandItem () const {
253  return chr.inv.getLeftHandContainer();
254  }
255  inline Item* getHandItem (actorHands_t hand) const {
256  if (hand == ACTOR_HAND_RIGHT)
257  return chr.inv.getRightHandContainer();
258  else if (hand == ACTOR_HAND_LEFT)
259  return chr.inv.getLeftHandContainer();
260  else return nullptr;
261  }
262  inline Item* getFloor () const {
263  return chr.inv.getFloorContainer();
264  }
265  inline Player& getPlayer () const {
266  return game.players[this->pnum];
267  }
268  /* also used by camera, mission and civilian_target! */
269  inline int getTeam() const {
270  return team;
271  }
272  /*==================
273  * checkers
274  *==================*/
275  inline bool isSameAs (const Edict* other) const {
276  return this->getIdNum() == other->getIdNum();
277  }
278  inline bool isSameTeamAs (const Edict* other) const {
279  return this->getTeam() == other->getTeam();
280  }
286  inline bool isSamePosAs (const pos3_t cmpPos) {
287  return VectorCompare(cmpPos, this->pos);
288  }
289 
290  /*
291  * Check if given actor is an enemy.
292  * Note: Also used by misc_mission to check if an opponent controls the target.
293  */
294  bool isOpponent (const Actor* actor) const;
295  /*==================
296  * manipulators
297  *==================*/
298 
299  /*
300  * A set of unsorted functions that are to be moved to class Actor later
301  */
302  inline void setStun(int stu) {
303  _STUN = stu;
304  }
305  inline void addStun(int stu) {
306  _STUN += stu;
307  }
308  inline int getStun() const {
309  return _STUN;
310  }
311  inline void setMorale(int mor) {
312  morale = mor;
313  }
314  /* only Actors should have TUs */
315  inline void setTus(int tus) {
316  TU = tus;
317  }
318  inline int getTus() const {
319  return TU;
320  }
321  inline void setTouch(bool (*touch_)(Edict* self, Edict* activator)) {
322  _touch = touch_;
323  }
324  inline bool hasTouch() const {
325  return _touch;
326  }
327  /* This is usually called with an Actor* as a param, except for G_TouchEdicts().
328  * The various touch-functions seem to expect an actor, but are not protected against something else. */
329  inline bool callTouch(Edict* activator) {
330  return _touch(this, activator);
331  }
336  inline int getReservedTUs () const {
337  const chrReservations_t* res = &chr.reservedTus;
338  return res->reaction + res->shot + res->crouch;
339  }
340 };
341 
348 class Actor : public Edict {
349 public:
350  inline int getMorale() const {
351  return morale;
352  }
353  inline bool isState(int flag) const {return state & flag;}
354  inline bool isShaken() const {return isState(STATE_SHAKEN);}
355  inline bool isStunned() const {return isState(STATE_STUN & ~STATE_DEAD);}
356  inline bool isPanicked() const {return isState(STATE_PANIC);}
357  inline bool isReaction() const {return isState(STATE_REACTION);}
358  inline bool isRaged() const {return isState(STATE_RAGE);}
359  inline bool isInsane() const {return isState(STATE_INSANE);}
360  inline bool isDazed() const {return isState(STATE_DAZED);}
361  inline bool isCrouched() const {return isState(STATE_CROUCHED);}
362  inline bool isDead() const {return isState(STATE_DEAD);}
363 
364  inline void setState(int flag) {state |= flag;}
365  inline void setShaken() {setState(STATE_SHAKEN);}
366  inline void setStunned() {setState(STATE_STUN);}
367  inline void setPanicked() {setState(STATE_PANIC);}
368  inline void setReaction() {setState(STATE_REACTION);}
369  inline void setRaged() {setState(STATE_RAGE);}
370  inline void setInsane() {setState(STATE_INSANE);}
371  inline void setDazed() {setState(STATE_DAZED);}
372  inline void setCrouched() {setState(STATE_CROUCHED);}
373 
374  inline void unsetState(int flag) {state &= ~flag;}
375  inline void removeShaken() {unsetState(STATE_SHAKEN);}
376  inline void removeStunned() {unsetState(STATE_STUN);}
377  inline void removePanicked() {unsetState(STATE_PANIC);}
378  inline void removeReaction() {unsetState(STATE_REACTION);}
379  inline void removeRaged() {unsetState(STATE_RAGE);}
380  inline void removeInsane() {unsetState(STATE_INSANE);}
381  inline void removeDazed() {unsetState(STATE_DAZED);}
382  inline void removeCrouched() {unsetState(STATE_CROUCHED);}
383 
384  inline unsigned int getBody() const {
385  return body;
386  }
387  inline void setBody(unsigned int body_) {
388  body = body_;
389  }
390  inline unsigned int getHead() const {
391  return head;
392  }
393  inline void setHead(unsigned int head_) {
394  head = head_;
395  }
400  inline int getUsableTUs () const {
401  return getTus() - getReservedTUs();
402  }
407  inline bool isInRescueZone () const {
408  return inRescueZone;
409  }
414  inline void setInRescueZone (bool inRescueZone_) {
415  if (inRescueZone_ == isInRescueZone())
416  return;
417 
418  inRescueZone = inRescueZone_;
419  }
420 };
421 
422 Actor* makeActor (Edict* ent);
int number
Definition: g_edict.h:51
char * group
Definition: g_edict.h:104
bool isInRescueZone() const
Checks whether the given actor is currently standing in a rescue zone.
Definition: g_edict.h:407
int getIdNum() const
Definition: g_edict.h:231
void removeCrouched()
Definition: g_edict.h:382
void toggleActive()
Definition: g_edict.h:201
#define VectorCopy(src, dest)
Definition: vector.h:51
Item * getFloor() const
Definition: g_edict.h:262
void removeReaction()
Definition: g_edict.h:378
void setActive()
Definition: g_edict.h:198
bool isSameTeamAs(const Edict *other) const
Definition: g_edict.h:278
solid_t solid
Definition: g_edict.h:58
const char * targetname
Definition: g_edict.h:126
void nativeReset()
Definition: g_edict.h:195
Edict * child()
Definition: g_edict.h:237
unsigned int body
Definition: g_edict.h:99
bool hiding
Definition: g_edict.h:142
bool hasTouch() const
Definition: g_edict.h:324
float nextthink
Definition: g_edict.h:149
void setRaged()
Definition: g_edict.h:369
void calcOrigin()
Calculate the edict's origin vector from it's grid position.
Definition: g_edict.h:216
void setState(int flag)
Definition: g_edict.h:364
int getStun() const
Definition: g_edict.h:308
void setTeam(int team_)
Definition: g_edict.h:189
bool isRaged() const
Definition: g_edict.h:358
byte dmgtype
Definition: g_edict.h:139
Player * players
Definition: g_local.h:70
void resetContainer(const containerIndex_t idx)
Definition: inv_shared.h:554
linkedList_t * touchedList
Definition: g_edict.h:157
Item * getContainer2(const containerIndex_t idx) const
Definition: inv_shared.h:546
const char * description
Definition: g_edict.h:131
void setPanicked()
Definition: g_edict.h:367
#define STATE_REACTION
Definition: q_shared.h:272
vec3_t angles
Definition: g_edict.h:54
int32_t actorSizeEnum_t
Definition: ufotypes.h:77
bool isPanicked() const
Definition: g_edict.h:356
const char * message
Definition: g_edict.h:130
Definition: aabb.h:42
bool isDead() const
Definition: g_edict.h:362
character_t chr
Definition: g_edict.h:116
int doorState
Definition: g_edict.h:158
Item * getLeftHandContainer() const
Definition: inv_shared.cpp:960
bool(* use)(Edict *self, Edict *activator)
Definition: g_edict.h:154
AABB entBox
Definition: g_edict.h:60
bool inuse
Definition: g_edict.h:47
bool active
Definition: g_edict.h:177
bool isStunned() const
Definition: g_edict.h:355
AABB absBox
Definition: g_edict.h:61
void removePanicked()
Definition: g_edict.h:377
int mapNum
Definition: g_edict.h:73
const char * target
Definition: g_edict.h:125
void removeDazed()
Definition: g_edict.h:381
solid_t
edict->solid values
Definition: game.h:153
void setBody(unsigned int body_)
Definition: g_edict.h:387
int forbiddenListSize
Definition: g_edict.h:175
bool callTouch(Edict *activator)
Definition: g_edict.h:329
moveinfo_t moveinfo
Definition: g_edict.h:160
void removeRaged()
Definition: g_edict.h:379
byte dir
Definition: g_edict.h:86
Item * getArmour() const
Definition: inv_shared.cpp:990
#define STATE_CROUCHED
Definition: q_shared.h:263
Item * getFloorContainer() const
Definition: inv_shared.cpp:975
Item * getArmour() const
Definition: g_edict.h:246
Actor * makeActor(Edict *ent)
Convert an Edict pointer into an Actor pointer.
Definition: g_edicts.cpp:327
Player & getPlayer() const
Definition: g_edict.h:265
camera_edict_data_t camera
Definition: g_edict.h:134
int speed
Definition: g_edict.h:124
const char * noise
Definition: g_edict.h:132
vec3_t size
Definition: g_edict.h:62
Item * getContainer(const containerIndex_t idx) const
Definition: g_edict.h:243
#define STATE_SHAKEN
Definition: q_shared.h:273
int spawnflags
Definition: g_edict.h:118
Item * getRightHandItem() const
Definition: g_edict.h:249
game_locals_t game
Definition: g_main.cpp:37
unsigned int getBody() const
Definition: g_edict.h:384
int getTeam() const
Definition: g_edict.h:269
void setTouch(bool(*touch_)(Edict *self, Edict *activator))
Definition: g_edict.h:321
int getUsableTUs() const
Calculates the amount of usable TUs. This is without the reserved TUs.
Definition: g_edict.h:400
item instance data, with linked list capability
Definition: inv_shared.h:402
unsigned int head
Definition: g_edict.h:100
void removeInsane()
Definition: g_edict.h:380
int modelindex
Definition: g_edict.h:66
unsigned int getHead() const
Definition: g_edict.h:390
game_import_t gi
Definition: g_main.cpp:39
void unsetState(int flag)
Definition: g_edict.h:374
const char * nextmap
Definition: g_edict.h:129
void(* think)(Edict *self)
Definition: g_edict.h:150
Item * getRightHandContainer() const
Definition: inv_shared.cpp:955
int dmg
Definition: g_edict.h:138
void setFloor(const Edict *other)
Definition: g_edict.h:207
int radius
Definition: g_edict.h:123
int TU
Definition: g_edict.h:88
void setInRescueZone(bool inRescueZone_)
Set the rescue zone flag.
Definition: g_edict.h:414
teammask_t visflags
Definition: g_edict.h:82
void removeShaken()
Definition: g_edict.h:375
bool isOpponent(const Actor *actor) const
Check if given actor is an enemy.
Definition: g_edicts.cpp:383
bool isSamePosAs(const pos3_t cmpPos)
Check whether the edict is on the given position.
Definition: g_edict.h:286
int linkcount
Definition: g_edict.h:48
pos3_t pos
Definition: g_edict.h:55
Edict * groupMaster
Definition: g_edict.h:168
int sounds
Definition: g_edict.h:137
float angle
Definition: g_edict.h:120
actorHands_t
Definition: inv_shared.h:626
#define STATE_DEAD
Definition: q_shared.h:262
int _STUN
Definition: g_edict.h:90
edictMaterial_t
e.g. used for breakable objects
Definition: g_local.h:267
An Edict of type Actor.
Definition: g_edict.h:348
bool isInsane() const
Definition: g_edict.h:359
Edict * owner()
Definition: g_edict.h:240
int frame
Definition: g_edict.h:102
void(* reset)(Edict *self, Edict *activator)
Definition: g_edict.h:148
Edict * clientAction
Definition: g_edict.h:113
bool inRescueZone
Definition: g_edict.h:109
Edict * _child
Definition: g_edict.h:64
int time
Definition: g_edict.h:136
#define STATE_RAGE
Definition: q_shared.h:266
pos_t pos3_t[3]
Definition: ufotypes.h:58
actor movement
Definition: g_local.h:277
int state
Definition: g_edict.h:93
#define STATE_STUN
Definition: q_shared.h:268
void removeStunned()
Definition: g_edict.h:376
int flags
Definition: g_edict.h:169
const GLuint *typedef void(APIENTRY *GenRenderbuffersEXT_t)(GLsizei
Definition: r_gl.h:189
actorSizeEnum_t fieldSize
Definition: g_edict.h:141
Interface to game library.
void setOrigin(const pos3_t newPos)
Set the edict's pos and origin vector to the given grid position.
Definition: g_edict.h:223
#define VectorCompare(a, b)
Definition: vector.h:63
void setReaction()
Definition: g_edict.h:368
int count
Definition: g_edict.h:135
int32_t containerIndex_t
Definition: inv_shared.h:46
#define STATE_DAZED
Definition: q_shared.h:269
void setCrouched()
Definition: g_edict.h:372
bool isShaken() const
Definition: g_edict.h:354
Item * getHandItem(actorHands_t hand) const
Definition: g_edict.h:255
bool isDazed() const
Definition: g_edict.h:360
void setMorale(int mor)
Definition: g_edict.h:311
int team
Definition: g_edict.h:96
void setStun(int stu)
Definition: g_edict.h:302
int contentFlags
Definition: g_edict.h:84
int getTus() const
Definition: g_edict.h:318
#define STATE_INSANE
Definition: q_shared.h:267
int getPlayerNum() const
Definition: g_edict.h:234
bool isCrouched() const
Definition: g_edict.h:361
#define STATE_PANIC
Definition: q_shared.h:264
void addStun(int stu)
Definition: g_edict.h:305
entity_type_t type
Definition: g_edict.h:81
void resetFloor()
Definition: g_edict.h:210
void setChild(Edict *child)
Definition: g_edict.h:192
void setFloorContainer(Item *cont)
Definition: inv_shared.cpp:950
void setStunned()
Definition: g_edict.h:366
vec3_t origin
Definition: g_edict.h:53
edictMaterial_t material
Definition: g_edict.h:133
const Edict * link
Definition: g_edict.h:80
bool isSameAs(const Edict *other) const
Definition: g_edict.h:275
bool(* destroy)(Edict *self)
Definition: g_edict.h:155
bool isReaction() const
Definition: g_edict.h:357
vec_t vec3_t[3]
Definition: ufotypes.h:39
entity_type_t
Definition: q_shared.h:145
unsigned int teammask_t
Definition: g_vis.h:30
void setPlayerNum(int num)
Definition: g_edict.h:186
Inventory inv
Definition: chr_shared.h:392
const char * item
Definition: g_edict.h:127
void setTus(int tus)
Definition: g_edict.h:315
int getMorale() const
Definition: g_edict.h:350
Artificial intelligence of a character.
Definition: g_local.h:303
int morale
Definition: g_edict.h:91
const char * classname
Definition: g_edict.h:67
Edict * _owner
Definition: g_edict.h:65
AI_t AI
Definition: g_edict.h:171
void resetContainer(const containerIndex_t idx)
Definition: g_edict.h:204
void setHead(unsigned int head_)
Definition: g_edict.h:393
void setShaken()
Definition: g_edict.h:365
How many TUs (and of what type) did a player reserve for a unit?
Definition: chr_shared.h:179
Definition: g_edict.h:45
int pnum
Definition: g_edict.h:97
Item * getLeftHandItem() const
Definition: g_edict.h:252
uint8_t byte
Definition: ufotypes.h:34
int getReservedTUs() const
Calculates the amount of all currently reserved TUs.
Definition: g_edict.h:336
void setInsane()
Definition: g_edict.h:370
bool isState(int flag) const
Definition: g_edict.h:353
const char * model
Definition: g_edict.h:74
void init(int idx)
Definition: g_edicts.cpp:339
const char * particle
Definition: g_edict.h:128
Edict * groupChain
Definition: g_edict.h:167
void setDazed()
Definition: g_edict.h:371
pos3_t * forbiddenListPos
Definition: g_edict.h:173
Edict * particleLink
Definition: g_edict.h:79
int HP
Definition: g_edict.h:89
chrReservations_t reservedTus
Definition: chr_shared.h:396
bool(* _touch)(Edict *self, Edict *activator)
Definition: g_edict.h:146
Describes a character with all its attributes.
Definition: chr_shared.h:369