UFO: Alien Invasion
Loading...
Searching...
No Matches
g_edict.h
Go to the documentation of this file.
1
5
6/*
7All original material Copyright (C) 2002-2025 UFO: Alien Invasion.
8
9Original file from Quake 2 v3.21: quake2-2.31/game/g_local.h
10Copyright (C) 1997-2001 Id Software, Inc.
11
12This program is free software; you can redistribute it and/or
13modify it under the terms of the GNU General Public License
14as published by the Free Software Foundation; either version 2
15of the License, or (at your option) any later version.
16
17This program is distributed in the hope that it will be useful,
18but WITHOUT ANY WARRANTY; without even the implied warranty of
19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20
21See the GNU General Public License for more details.
22
23You should have received a copy of the GNU General Public License
24along with this program; if not, write to the Free Software
25Foundation, 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"
42class Edict : public SrvEdict {
43public:
44#else
45class Edict {
46public:
47 bool inuse;
50
51 int number;
52
56
59
63
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;
76
78
80 const Edict* link;
83
85
86 byte dir;
87
88 int TU;
89 int HP;
90 int _STUN;
91 int morale;
92
93 int state;
94
95protected:
96 int team;
97 int pnum;
99 unsigned int body;
100 unsigned int head;
101public:
102 int frame;
103
104 char* group;
108protected:
111public:
114
117
119
120 float angle;
122
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;
139 byte dmgtype;
142 bool hiding;
143
146 bool (*_touch)(Edict* self, Edict* activator);
148 void (*reset)(Edict* self, Edict* activator);
150 void (*think)(Edict* self);
154 bool (*use)(Edict* self, Edict* activator);
155 bool (*destroy)(Edict* self);
156
159
161
169 int flags;
170
172
176
177 bool active;
178
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 }
213
216 inline void calcOrigin () {
217 gi.GridPosToVec(fieldSize, pos, origin);
218 }
219
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 }
281
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 }
332
336 inline int getReservedTUs () const {
337 const chrReservations_t* res = &chr.reservedTus;
338 return res->reaction + res->shot + res->crouch;
339 }
340};
341
348class Actor : public Edict {
349public:
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;}
369 inline void setRaged() {setState(STATE_RAGE);}
371 inline void setDazed() {setState(STATE_DAZED);}
373
374 inline void unsetState(int flag) {state &= ~flag;}
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 }
396
400 inline int getUsableTUs () const {
401 return getTus() - getReservedTUs();
402 }
403
407 inline bool isInRescueZone () const {
408 return inRescueZone;
409 }
410
414 inline void setInRescueZone (bool inRescueZone_) {
415 if (inRescueZone_ == isInRescueZone())
416 return;
417
418 inRescueZone = inRescueZone_;
419 }
420};
421
422Actor* makeActor (Edict* ent);
Definition aabb.h:42
An Edict of type Actor.
Definition g_edict.h:348
bool isState(int flag) const
Definition g_edict.h:353
void setStunned()
Definition g_edict.h:366
bool isShaken() const
Definition g_edict.h:354
bool isDead() const
Definition g_edict.h:362
void setBody(unsigned int body_)
Definition g_edict.h:387
void removeStunned()
Definition g_edict.h:376
void unsetState(int flag)
Definition g_edict.h:374
void removeShaken()
Definition g_edict.h:375
void setCrouched()
Definition g_edict.h:372
bool isPanicked() const
Definition g_edict.h:356
int getMorale() const
Definition g_edict.h:350
void removeReaction()
Definition g_edict.h:378
bool isInsane() const
Definition g_edict.h:359
int getUsableTUs() const
Calculates the amount of usable TUs. This is without the reserved TUs.
Definition g_edict.h:400
bool isStunned() const
Definition g_edict.h:355
bool isRaged() const
Definition g_edict.h:358
void setInsane()
Definition g_edict.h:370
unsigned int getHead() const
Definition g_edict.h:390
unsigned int getBody() const
Definition g_edict.h:384
void setInRescueZone(bool inRescueZone_)
Set the rescue zone flag.
Definition g_edict.h:414
bool isReaction() const
Definition g_edict.h:357
void removeCrouched()
Definition g_edict.h:382
bool isCrouched() const
Definition g_edict.h:361
void setReaction()
Definition g_edict.h:368
void setHead(unsigned int head_)
Definition g_edict.h:393
void removeDazed()
Definition g_edict.h:381
void setPanicked()
Definition g_edict.h:367
void removePanicked()
Definition g_edict.h:377
void setDazed()
Definition g_edict.h:371
void removeInsane()
Definition g_edict.h:380
bool isInRescueZone() const
Checks whether the given actor is currently standing in a rescue zone.
Definition g_edict.h:407
bool isDazed() const
Definition g_edict.h:360
void setShaken()
Definition g_edict.h:365
void setState(int flag)
Definition g_edict.h:364
void removeRaged()
Definition g_edict.h:379
void setRaged()
Definition g_edict.h:369
int getPlayerNum() const
Definition g_edict.h:234
teammask_t visflags
Definition g_edict.h:82
int linkcount
Definition g_edict.h:48
Edict * _child
Definition g_edict.h:64
int TU
Definition g_edict.h:88
Edict * particleLink
Definition g_edict.h:79
bool isSameTeamAs(const Edict *other) const
Definition g_edict.h:278
const Edict * link
Definition g_edict.h:80
bool hiding
Definition g_edict.h:142
unsigned int body
Definition g_edict.h:99
character_t chr
Definition g_edict.h:116
Item * getArmour() const
Definition g_edict.h:246
void setPlayerNum(int num)
Definition g_edict.h:186
int flags
Definition g_edict.h:169
camera_edict_data_t camera
Definition g_edict.h:134
int getIdNum() const
Definition g_edict.h:231
bool(* _touch)(Edict *self, Edict *activator)
Definition g_edict.h:146
byte dmgtype
Definition g_edict.h:139
bool isSameAs(const Edict *other) const
Definition g_edict.h:275
void addStun(int stu)
Definition g_edict.h:305
void setMorale(int mor)
Definition g_edict.h:311
void setFloor(const Edict *other)
Definition g_edict.h:207
const char * classname
Definition g_edict.h:67
Item * getRightHandItem() const
Definition g_edict.h:249
bool active
Definition g_edict.h:177
Edict * child()
Definition g_edict.h:237
vec3_t origin
Definition g_edict.h:53
const char * particle
Definition g_edict.h:128
pos3_t pos
Definition g_edict.h:55
moveinfo_t moveinfo
Definition g_edict.h:160
void resetContainer(const containerIndex_t idx)
Definition g_edict.h:204
float angle
Definition g_edict.h:120
Edict * owner()
Definition g_edict.h:240
actorSizeEnum_t fieldSize
Definition g_edict.h:141
int _STUN
Definition g_edict.h:90
int team
Definition g_edict.h:96
void(* think)(Edict *self)
Definition g_edict.h:150
const char * target
Definition g_edict.h:125
int HP
Definition g_edict.h:89
int doorState
Definition g_edict.h:158
const char * noise
Definition g_edict.h:132
byte dir
Definition g_edict.h:86
void init(int idx)
Definition g_edicts.cpp:339
AI_t AI
Definition g_edict.h:171
Edict * groupChain
Definition g_edict.h:167
void setOrigin(const pos3_t newPos)
Set the edict's pos and origin vector to the given grid position.
Definition g_edict.h:223
Item * getLeftHandItem() const
Definition g_edict.h:252
vec3_t angles
Definition g_edict.h:54
vec3_t size
Definition g_edict.h:62
pos3_t * forbiddenListPos
Definition g_edict.h:173
void setActive()
Definition g_edict.h:198
int contentFlags
Definition g_edict.h:84
Edict * clientAction
Definition g_edict.h:113
void resetFloor()
Definition g_edict.h:210
void setTeam(int team_)
Definition g_edict.h:189
bool(* use)(Edict *self, Edict *activator)
Definition g_edict.h:154
void setTouch(bool(*touch_)(Edict *self, Edict *activator))
Definition g_edict.h:321
bool inuse
Definition g_edict.h:47
int getTeam() const
Definition g_edict.h:269
AABB entBox
Definition g_edict.h:60
Edict * _owner
Definition g_edict.h:65
void calcOrigin()
Calculate the edict's origin vector from it's grid position.
Definition g_edict.h:216
int modelindex
Definition g_edict.h:66
float nextthink
Definition g_edict.h:149
bool callTouch(Edict *activator)
Definition g_edict.h:329
void setChild(Edict *child)
Definition g_edict.h:192
Player & getPlayer() const
Definition g_edict.h:265
int mapNum
Definition g_edict.h:73
bool(* destroy)(Edict *self)
Definition g_edict.h:155
bool isOpponent(const Actor *actor) const
Check if given actor is an enemy.
Definition g_edicts.cpp:383
int getReservedTUs() const
Calculates the amount of all currently reserved TUs.
Definition g_edict.h:336
void(* reset)(Edict *self, Edict *activator)
Definition g_edict.h:148
AABB absBox
Definition g_edict.h:61
int dmg
Definition g_edict.h:138
Item * getHandItem(actorHands_t hand) const
Definition g_edict.h:255
int sounds
Definition g_edict.h:137
bool hasTouch() const
Definition g_edict.h:324
int spawnflags
Definition g_edict.h:118
const char * targetname
Definition g_edict.h:126
int time
Definition g_edict.h:136
int count
Definition g_edict.h:135
bool isSamePosAs(const pos3_t cmpPos)
Check whether the edict is on the given position.
Definition g_edict.h:286
linkedList_t * touchedList
Definition g_edict.h:157
solid_t solid
Definition g_edict.h:58
int radius
Definition g_edict.h:123
char * group
Definition g_edict.h:104
entity_type_t type
Definition g_edict.h:81
void toggleActive()
Definition g_edict.h:201
Item * getContainer(const containerIndex_t idx) const
Definition g_edict.h:243
const char * message
Definition g_edict.h:130
void nativeReset()
Definition g_edict.h:195
bool inRescueZone
Definition g_edict.h:109
int number
Definition g_edict.h:51
void setStun(int stu)
Definition g_edict.h:302
void setTus(int tus)
Definition g_edict.h:315
unsigned int head
Definition g_edict.h:100
const char * item
Definition g_edict.h:127
Item * getFloor() const
Definition g_edict.h:262
Edict * groupMaster
Definition g_edict.h:168
int pnum
Definition g_edict.h:97
int speed
Definition g_edict.h:124
int getStun() const
Definition g_edict.h:308
edictMaterial_t material
Definition g_edict.h:133
int forbiddenListSize
Definition g_edict.h:175
int getTus() const
Definition g_edict.h:318
int morale
Definition g_edict.h:91
int frame
Definition g_edict.h:102
int state
Definition g_edict.h:93
const char * description
Definition g_edict.h:131
const char * model
Definition g_edict.h:74
const char * nextmap
Definition g_edict.h:129
item instance data, with linked list capability
Definition inv_shared.h:402
Actor * makeActor(Edict *ent)
Convert an Edict pointer into an Actor pointer.
Definition g_edicts.cpp:327
game_locals_t game
Definition g_main.cpp:37
game_import_t gi
Definition g_main.cpp:39
edictMaterial_t
e.g. used for breakable objects
Definition g_local.h:267
unsigned int teammask_t
Definition g_vis.h:30
solid_t
edict->solid values
Definition game.h:153
int32_t containerIndex_t
Definition inv_shared.h:46
actorHands_t
Definition inv_shared.h:626
@ ACTOR_HAND_LEFT
Definition inv_shared.h:629
@ ACTOR_HAND_RIGHT
Definition inv_shared.h:628
#define STATE_DEAD
Definition q_shared.h:262
#define STATE_STUN
Definition q_shared.h:268
#define STATE_RAGE
Definition q_shared.h:266
entity_type_t
Definition q_shared.h:145
#define STATE_CROUCHED
Definition q_shared.h:263
#define STATE_PANIC
Definition q_shared.h:264
#define STATE_REACTION
Definition q_shared.h:272
#define STATE_SHAKEN
Definition q_shared.h:273
#define STATE_INSANE
Definition q_shared.h:267
#define STATE_DAZED
Definition q_shared.h:269
QGL_EXTERN void(APIENTRY *qglActiveTexture)(GLenum texture)
Interface to game library.
Artificial intelligence of a character.
Definition g_local.h:305
Describes a character with all its attributes.
Definition chr_shared.h:388
How many TUs (and of what type) did a player reserve for a unit?
Definition chr_shared.h:186
actor movement
Definition g_local.h:277
Cross-platform type definitions.
pos_t pos3_t[3]
Definition ufotypes.h:58
vec_t vec3_t[3]
Definition ufotypes.h:39
int32_t actorSizeEnum_t
Definition ufotypes.h:77
#define VectorCopy(src, dest)
Definition vector.h:51
#define VectorCompare(a, b)
Definition vector.h:63