Quake II RTX doxygen  1.0 dev
g_utils.c File Reference
#include "g_local.h"

Go to the source code of this file.

Macros

#define MAXCHOICES   8
 

Functions

void G_ProjectSource (const vec3_t point, const vec3_t distance, const vec3_t forward, const vec3_t right, vec3_t result)
 
edict_t * G_Find (edict_t *from, int fieldofs, char *match)
 
edict_t * findradius (edict_t *from, vec3_t org, float rad)
 
edict_t * G_PickTarget (char *targetname)
 
void Think_Delay (edict_t *ent)
 
void G_UseTargets (edict_t *ent, edict_t *activator)
 
float * tv (float x, float y, float z)
 
char * vtos (vec3_t v)
 
void G_SetMovedir (vec3_t angles, vec3_t movedir)
 
float vectoyaw (vec3_t vec)
 
void vectoangles (vec3_t value1, vec3_t angles)
 
char * G_CopyString (char *in)
 
void G_InitEdict (edict_t *e)
 
edict_t * G_Spawn (void)
 
void G_FreeEdict (edict_t *ed)
 
void G_TouchTriggers (edict_t *ent)
 
void G_TouchSolids (edict_t *ent)
 
qboolean KillBox (edict_t *ent)
 

Variables

vec3_t VEC_UP = {0, -1, 0}
 
vec3_t MOVEDIR_UP = {0, 0, 1}
 
vec3_t VEC_DOWN = {0, -2, 0}
 
vec3_t MOVEDIR_DOWN = {0, 0, -1}
 

Macro Definition Documentation

◆ MAXCHOICES

#define MAXCHOICES   8

Definition at line 112 of file g_utils.c.

Function Documentation

◆ findradius()

edict_t* findradius ( edict_t *  from,
vec3_t  org,
float  rad 
)

Definition at line 75 of file g_utils.c.

76 {
77  vec3_t eorg;
78  int j;
79 
80  if (!from)
81  from = g_edicts;
82  else
83  from++;
84  for (; from < &g_edicts[globals.num_edicts]; from++) {
85  if (!from->inuse)
86  continue;
87  if (from->solid == SOLID_NOT)
88  continue;
89  for (j = 0 ; j < 3 ; j++)
90  eorg[j] = org[j] - (from->s.origin[j] + (from->mins[j] + from->maxs[j]) * 0.5);
91  if (VectorLength(eorg) > rad)
92  continue;
93  return from;
94  }
95 
96  return NULL;
97 }

Referenced by bfg_explode(), bfg_think(), medic_FindDeadMonster(), and T_RadiusDamage().

◆ G_CopyString()

char* G_CopyString ( char *  in)

Definition at line 362 of file g_utils.c.

363 {
364  char *out;
365 
366  out = gi.TagMalloc(strlen(in) + 1, TAG_LEVEL);
367  strcpy(out, in);
368  return out;
369 }

◆ G_Find()

edict_t* G_Find ( edict_t *  from,
int  fieldofs,
char *  match 
)

Definition at line 43 of file g_utils.c.

44 {
45  char *s;
46 
47  if (!from)
48  from = g_edicts;
49  else
50  from++;
51 
52  for (; from < &g_edicts[globals.num_edicts] ; from++) {
53  if (!from->inuse)
54  continue;
55  s = *(char **)((byte *)from + fieldofs);
56  if (!s)
57  continue;
58  if (!Q_stricmp(s, match))
59  return from;
60  }
61 
62  return NULL;
63 }

Referenced by BeginIntermission(), door_use_areaportals(), EndDMLevel(), func_clock_think(), G_PickTarget(), G_UseTargets(), misc_viper_bomb_use(), monster_start_go(), SelectCoopSpawnPoint(), SelectFarthestDeathmatchSpawnPoint(), SelectRandomDeathmatchSpawnPoint(), SelectSpawnPoint(), SP_FixCoopSpots(), target_laser_start(), target_lightramp_use(), and teleporter_touch().

◆ G_FreeEdict()

void G_FreeEdict ( edict_t *  ed)

Definition at line 421 of file g_utils.c.

422 {
423  gi.unlinkentity(ed); // unlink from world
424 
425  if ((ed - g_edicts) <= (maxclients->value + BODY_QUEUE_SIZE)) {
426 // gi.dprintf("tried to free special edict\n");
427  return;
428  }
429 
430  memset(ed, 0, sizeof(*ed));
431  ed->classname = "freed";
432  ed->freetime = level.time;
433  ed->inuse = qfalse;
434 }

Referenced by ai_run(), BecomeExplosion1(), BecomeExplosion2(), bfg_explode(), bfg_touch(), blaster_touch(), Cmd_Give_f(), debris_die(), Drop_Ammo(), drop_make_touchable(), droptofloor(), fire_bfg(), fire_blaster(), fire_rocket(), flare_think(), func_explosive_explode(), G_UseTargets(), gib_die(), gib_think(), Grenade_Explode(), Grenade_Touch(), MegaHealth_think(), misc_blackhole_use(), monster_start(), multi_trigger(), rocket_touch(), SP_func_clock(), SP_func_explosive(), SP_info_null(), SP_info_player_coop(), SP_info_player_deathmatch(), SP_item_health(), SP_item_health_large(), SP_item_health_mega(), SP_item_health_small(), SP_light(), SP_misc_actor(), SP_misc_deadsoldier(), SP_misc_explobox(), SP_misc_gib_arm(), SP_misc_gib_head(), SP_misc_gib_leg(), SP_misc_insane(), SP_misc_strogg_ship(), SP_misc_teleporter(), SP_misc_viper(), SP_monster_berserk(), SP_monster_boss2(), SP_monster_boss3_stand(), SP_monster_brain(), SP_monster_chick(), SP_monster_flipper(), SP_monster_floater(), SP_monster_flyer(), SP_monster_gladiator(), SP_monster_gunner(), SP_monster_hover(), SP_monster_infantry(), SP_monster_jorg(), SP_monster_makron(), SP_monster_medic(), SP_monster_mutant(), SP_monster_parasite(), SP_monster_soldier(), SP_monster_soldier_light(), SP_monster_soldier_ss(), SP_monster_supertank(), SP_monster_tank(), SP_path_corner(), SP_point_combat(), SP_target_changelevel(), SP_target_goal(), SP_target_help(), SP_target_lightramp(), SP_target_secret(), SP_trigger_gravity(), SP_turret_driver(), SpawnEntities(), SpawnItem(), target_crosslevel_target_think(), target_lightramp_use(), Think_Delay(), ThrowDebris(), ThrowGib(), ThrowHead(), TossClientWeapon(), Touch_Item(), trigger_crosslevel_trigger_use(), trigger_push_touch(), turret_breach_finish_init(), Use_Boss3(), use_target_goal(), and use_target_secret().

◆ G_InitEdict()

void G_InitEdict ( edict_t *  e)

Definition at line 372 of file g_utils.c.

373 {
374  e->inuse = qtrue;
375  e->classname = "noclass";
376  e->gravity = 1.0;
377  e->s.number = e - g_edicts;
378 }

Referenced by ClientBegin(), ClientBeginDeathmatch(), and G_Spawn().

◆ G_PickTarget()

edict_t* G_PickTarget ( char *  targetname)

Definition at line 114 of file g_utils.c.

115 {
116  edict_t *ent = NULL;
117  int num_choices = 0;
118  edict_t *choice[MAXCHOICES];
119 
120  if (!targetname) {
121  gi.dprintf("G_PickTarget called with NULL targetname\n");
122  return NULL;
123  }
124 
125  while (1) {
126  ent = G_Find(ent, FOFS(targetname), targetname);
127  if (!ent)
128  break;
129  choice[num_choices++] = ent;
130  if (num_choices == MAXCHOICES)
131  break;
132  }
133 
134  if (!num_choices) {
135  gi.dprintf("G_PickTarget: target %s not found\n", targetname);
136  return NULL;
137  }
138 
139  return choice[rand() % num_choices];
140 }

Referenced by actor_use(), FoundTarget(), func_train_find(), monster_start_go(), path_corner_touch(), point_combat_touch(), target_actor_touch(), train_next(), trigger_elevator_init(), trigger_elevator_use(), turret_breach_finish_init(), and turret_driver_link().

◆ G_ProjectSource()

void G_ProjectSource ( const vec3_t  point,
const vec3_t  distance,
const vec3_t  forward,
const vec3_t  right,
vec3_t  result 
)

◆ G_SetMovedir()

void G_SetMovedir ( vec3_t  angles,
vec3_t  movedir 
)

Definition at line 296 of file g_utils.c.

297 {
298  if (VectorCompare(angles, VEC_UP)) {
299  VectorCopy(MOVEDIR_UP, movedir);
300  } else if (VectorCompare(angles, VEC_DOWN)) {
301  VectorCopy(MOVEDIR_DOWN, movedir);
302  } else {
303  AngleVectors(angles, movedir, NULL, NULL);
304  }
305 
306  VectorClear(angles);
307 }

Referenced by InitTrigger(), SP_func_button(), SP_func_door(), SP_func_water(), SP_target_actor(), SP_target_blaster(), SP_target_spawner(), SP_target_splash(), SP_trigger_multiple(), and target_laser_start().

◆ G_Spawn()

edict_t* G_Spawn ( void  )

Definition at line 391 of file g_utils.c.

392 {
393  int i;
394  edict_t *e;
395 
396  e = &g_edicts[game.maxclients + 1];
397  for (i = game.maxclients + 1 ; i < globals.num_edicts ; i++, e++) {
398  // the first couple seconds of server time can involve a lot of
399  // freeing and allocating, so relax the replacement policy
400  if (!e->inuse && (e->freetime < 2 || level.time - e->freetime > 0.5)) {
401  G_InitEdict(e);
402  return e;
403  }
404  }
405 
406  if (i == game.maxentities)
407  gi.error("ED_Alloc: no free edicts");
408 
409  globals.num_edicts++;
410  G_InitEdict(e);
411  return e;
412 }

Referenced by ai_run(), Cmd_Give_f(), CreateTargetChangeLevel(), Drop_Item(), fire_bfg(), fire_blaster(), fire_flaregun(), fire_grenade(), fire_grenade2(), fire_rocket(), G_UseTargets(), InitBodyQue(), jorg_dead(), makron_die(), MakronToss(), plat_spawn_inside_trigger(), PlayerNoise(), PlayerTrail_Init(), SP_CreateCoopSpots(), SP_misc_teleporter(), SpawnEntities(), Think_SpawnDoorTrigger(), ThrowDebris(), ThrowGib(), and use_target_spawner().

◆ G_TouchSolids()

void G_TouchSolids ( edict_t *  ent)

Definition at line 475 of file g_utils.c.

476 {
477  int i, num;
478  edict_t *touch[MAX_EDICTS], *hit;
479 
480  num = gi.BoxEdicts(ent->absmin, ent->absmax, touch
481  , MAX_EDICTS, AREA_SOLID);
482 
483  // be careful, it is possible to have an entity in this
484  // list removed before we get to it (killtriggered)
485  for (i = 0 ; i < num ; i++) {
486  hit = touch[i];
487  if (!hit->inuse)
488  continue;
489  if (ent->touch)
490  ent->touch(hit, ent, NULL, NULL);
491  if (!ent->inuse)
492  break;
493  }
494 }

◆ G_TouchTriggers()

void G_TouchTriggers ( edict_t *  ent)

Definition at line 443 of file g_utils.c.

444 {
445  int i, num;
446  edict_t *touch[MAX_EDICTS], *hit;
447 
448  // dead things don't activate triggers!
449  if ((ent->client || (ent->svflags & SVF_MONSTER)) && (ent->health <= 0))
450  return;
451 
452  num = gi.BoxEdicts(ent->absmin, ent->absmax, touch
453  , MAX_EDICTS, AREA_TRIGGERS);
454 
455  // be careful, it is possible to have an entity in this
456  // list removed before we get to it (killtriggered)
457  for (i = 0 ; i < num ; i++) {
458  hit = touch[i];
459  if (!hit->inuse)
460  continue;
461  if (!hit->touch)
462  continue;
463  hit->touch(hit, ent, NULL, NULL);
464  }
465 }

Referenced by ClientThink(), SV_movestep(), SV_Physics_Step(), SV_Push(), SV_PushEntity(), and SV_StepDirection().

◆ G_UseTargets()

void G_UseTargets ( edict_t *  ent,
edict_t *  activator 
)

Definition at line 166 of file g_utils.c.

167 {
168  edict_t *t;
169 
170 //
171 // check for a delay
172 //
173  if (ent->delay) {
174  // create a temp object to fire at a later time
175  t = G_Spawn();
176  t->classname = "DelayedUse";
177  t->nextthink = level.time + ent->delay;
178  t->think = Think_Delay;
179  t->activator = activator;
180  if (!activator)
181  gi.dprintf("Think_Delay with no activator\n");
182  t->message = ent->message;
183  t->target = ent->target;
184  t->killtarget = ent->killtarget;
185  return;
186  }
187 
188 
189 //
190 // print the message
191 //
192  if ((ent->message) && !(activator->svflags & SVF_MONSTER)) {
193  gi.centerprintf(activator, "%s", ent->message);
194  if (ent->noise_index)
195  gi.sound(activator, CHAN_AUTO, ent->noise_index, 1, ATTN_NORM, 0);
196  else
197  gi.sound(activator, CHAN_AUTO, gi.soundindex("misc/talk1.wav"), 1, ATTN_NORM, 0);
198  }
199 
200 //
201 // kill killtargets
202 //
203  if (ent->killtarget) {
204  t = NULL;
205  while ((t = G_Find(t, FOFS(targetname), ent->killtarget))) {
206  G_FreeEdict(t);
207  if (!ent->inuse) {
208  gi.dprintf("entity was removed while using killtargets\n");
209  return;
210  }
211  }
212  }
213 
214 //
215 // fire targets
216 //
217  if (ent->target) {
218  t = NULL;
219  while ((t = G_Find(t, FOFS(targetname), ent->target))) {
220  // doors fire area portals in a specific way
221  if (!Q_stricmp(t->classname, "func_areaportal") &&
222  (!Q_stricmp(ent->classname, "func_door") || !Q_stricmp(ent->classname, "func_door_rotating")))
223  continue;
224 
225  if (t == ent) {
226  gi.dprintf("WARNING: Entity used itself.\n");
227  } else {
228  if (t->use)
229  t->use(t, ent, activator);
230  }
231  if (!ent->inuse) {
232  gi.dprintf("entity was removed while using targets\n");
233  return;
234  }
235  }
236  }
237 }

Referenced by button_wait(), door_go_up(), func_clock_think(), func_explosive_explode(), func_timer_think(), misc_viper_bomb_touch(), monster_death_use(), multi_trigger(), path_corner_touch(), point_combat_touch(), SP_trigger_always(), target_actor_touch(), target_crosslevel_target_think(), target_explosion_explode(), Think_Delay(), Touch_Item(), train_wait(), trigger_key_use(), trigger_relay_use(), use_target_goal(), and use_target_secret().

◆ KillBox()

qboolean KillBox ( edict_t *  ent)

Definition at line 515 of file g_utils.c.

516 {
517  trace_t tr;
518 
519  while (1) {
520  tr = gi.trace(ent->s.origin, ent->mins, ent->maxs, ent->s.origin, NULL, MASK_PLAYERSOLID);
521  if (!tr.ent)
522  break;
523 
524  // nail it
525  T_Damage(tr.ent, ent, ent, vec3_origin, ent->s.origin, vec3_origin, 100000, 0, DAMAGE_NO_PROTECTION, MOD_TELEFRAG);
526 
527  // if we didn't kill it, fail
528  if (tr.ent->solid)
529  return qfalse;
530  }
531 
532  return qtrue; // all clear
533 }

Referenced by func_explosive_spawn(), func_object_use(), func_wall_use(), monster_triggered_spawn(), PutClientInServer(), teleporter_touch(), use_killbox(), and use_target_spawner().

◆ Think_Delay()

void Think_Delay ( edict_t *  ent)

Definition at line 144 of file g_utils.c.

145 {
146  G_UseTargets(ent, ent->activator);
147  G_FreeEdict(ent);
148 }

Referenced by G_UseTargets().

◆ tv()

float* tv ( float  x,
float  y,
float  z 
)

Definition at line 248 of file g_utils.c.

249 {
250  static int index;
251  static vec3_t vecs[8];
252  float *v;
253 
254  // use an array so that multiple tempvectors won't collide
255  // for a while
256  v = vecs[index];
257  index = (index + 1) & 7;
258 
259  v[0] = x;
260  v[1] = y;
261  v[2] = z;
262 
263  return v;
264 }

Referenced by droptofloor(), NET_Sleep(), and os_select().

◆ vectoangles()

void vectoangles ( vec3_t  value1,
vec3_t  angles 
)

Definition at line 330 of file g_utils.c.

331 {
332  float forward;
333  float yaw, pitch;
334 
335  if (value1[1] == 0 && value1[0] == 0) {
336  yaw = 0;
337  if (value1[2] > 0)
338  pitch = 90;
339  else
340  pitch = 270;
341  } else {
342  if (value1[0])
343  yaw = (int)(atan2(value1[1], value1[0]) * 180 / M_PI);
344  else if (value1[1] > 0)
345  yaw = 90;
346  else
347  yaw = -90;
348  if (yaw < 0)
349  yaw += 360;
350 
351  forward = sqrt(value1[0] * value1[0] + value1[1] * value1[1]);
352  pitch = (int)(atan2(value1[2], forward) * 180 / M_PI);
353  if (pitch < 0)
354  pitch += 360;
355  }
356 
357  angles[PITCH] = -pitch;
358  angles[YAW] = yaw;
359  angles[ROLL] = 0;
360 }

Referenced by fire_bfg(), fire_blaster(), fire_flaregun(), fire_grenade(), fire_grenade2(), fire_lead(), fire_rocket(), flare_sparks(), gib_touch(), MakronHyperblaster(), medic_cable_attack(), misc_viper_bomb_prethink(), parasite_drain_attack_ok(), soldier_fire(), TankMachineGun(), turret_driver_link(), and turret_driver_think().

◆ vectoyaw()

float vectoyaw ( vec3_t  vec)

Definition at line 310 of file g_utils.c.

311 {
312  float yaw;
313 
314  if (/*vec[YAW] == 0 &&*/ vec[PITCH] == 0) {
315  yaw = 0;
316  if (vec[YAW] > 0)
317  yaw = 90;
318  else if (vec[YAW] < 0)
319  yaw = -90;
320  } else {
321  yaw = (int)(atan2(vec[YAW], vec[PITCH]) * 180 / M_PI);
322  if (yaw < 0)
323  yaw += 360;
324  }
325 
326  return yaw;
327 }

Referenced by actor_pain(), actor_use(), ai_charge(), ai_checkattack(), ai_run(), ai_stand(), barrel_touch(), Boss2_CheckAttack(), FindTarget(), HuntTarget(), Jorg_CheckAttack(), Makron_CheckAttack(), MakronSpawn(), monster_start_go(), path_corner_touch(), PlayerTrail_Add(), and target_actor_touch().

◆ vtos()

char* vtos ( vec3_t  v)

Definition at line 275 of file g_utils.c.

276 {
277  static int index;
278  static char str[8][32];
279  char *s;
280 
281  // use an array so that multiple vtos won't collide
282  s = str[index];
283  index = (index + 1) & 7;
284 
285  Q_snprintf(s, 32, "(%i %i %i)", (int)v[0], (int)v[1], (int)v[2]);
286 
287  return s;
288 }

Referenced by actor_use(), droptofloor(), flymonster_start_go(), FoundTarget(), monster_start(), monster_start_go(), point_combat_touch(), SP_func_clock(), SP_func_door_rotating(), SP_func_timer(), SP_func_train(), SP_misc_actor(), SP_misc_strogg_ship(), SP_misc_viper(), SP_path_corner(), SP_target_actor(), SP_target_changelevel(), SP_target_earthquake(), SP_target_help(), SP_target_lightramp(), SP_target_speaker(), SP_trigger_gravity(), SP_trigger_key(), SP_trigger_once(), SP_turret_driver(), SpawnItem(), target_laser_start(), target_lightramp_use(), train_next(), turret_breach_finish_init(), and walkmonster_start_go().

Variable Documentation

◆ MOVEDIR_DOWN

vec3_t MOVEDIR_DOWN = {0, 0, -1}

Definition at line 294 of file g_utils.c.

Referenced by G_SetMovedir().

◆ MOVEDIR_UP

vec3_t MOVEDIR_UP = {0, 0, 1}

Definition at line 292 of file g_utils.c.

Referenced by G_SetMovedir().

◆ VEC_DOWN

vec3_t VEC_DOWN = {0, -2, 0}

Definition at line 293 of file g_utils.c.

Referenced by G_SetMovedir().

◆ VEC_UP

vec3_t VEC_UP = {0, -1, 0}

Definition at line 291 of file g_utils.c.

Referenced by G_SetMovedir().

gi
game_import_t gi
Definition: g_main.c:23
G_Find
edict_t * G_Find(edict_t *from, int fieldofs, char *match)
Definition: g_utils.c:43
Think_Delay
void Think_Delay(edict_t *ent)
Definition: g_utils.c:144
maxclients
cvar_t * maxclients
Definition: g_main.c:42
Q_snprintf
size_t Q_snprintf(char *dest, size_t size, const char *fmt,...)
Definition: shared.c:846
BODY_QUEUE_SIZE
#define BODY_QUEUE_SIZE
Definition: g_local.h:84
MOVEDIR_UP
vec3_t MOVEDIR_UP
Definition: g_utils.c:292
MOD_TELEFRAG
#define MOD_TELEFRAG
Definition: g_local.h:478
FOFS
#define FOFS(x)
Definition: g_local.h:498
TAG_LEVEL
#define TAG_LEVEL
Definition: g_local.h:79
g_edicts
edict_t * g_edicts
Definition: g_main.c:31
T_Damage
void T_Damage(edict_t *targ, edict_t *inflictor, edict_t *attacker, vec3_t dir, vec3_t point, vec3_t normal, int damage, int knockback, int dflags, int mod)
Definition: g_combat.c:358
G_UseTargets
void G_UseTargets(edict_t *ent, edict_t *activator)
Definition: g_utils.c:166
vec3_origin
vec3_t vec3_origin
Definition: shared.c:21
DAMAGE_NO_PROTECTION
#define DAMAGE_NO_PROTECTION
Definition: g_local.h:652
VEC_DOWN
vec3_t VEC_DOWN
Definition: g_utils.c:293
forward
static vec3_t forward
Definition: p_view.c:27
MOVEDIR_DOWN
vec3_t MOVEDIR_DOWN
Definition: g_utils.c:294
game
game_locals_t game
Definition: g_main.c:21
AngleVectors
void AngleVectors(vec3_t angles, vec3_t forward, vec3_t right, vec3_t up)
Definition: shared.c:23
G_InitEdict
void G_InitEdict(edict_t *e)
Definition: g_utils.c:372
globals
game_export_t globals
Definition: g_main.c:24
G_FreeEdict
void G_FreeEdict(edict_t *ed)
Definition: g_utils.c:421
level_locals_t::time
float time
Definition: g_local.h:299
VEC_UP
vec3_t VEC_UP
Definition: g_utils.c:291
G_Spawn
edict_t * G_Spawn(void)
Definition: g_utils.c:391
right
static vec3_t right
Definition: p_view.c:27
level
level_locals_t level
Definition: g_main.c:22
MAXCHOICES
#define MAXCHOICES
Definition: g_utils.c:112
int
CONST PIXELFORMATDESCRIPTOR int
Definition: wgl.c:26
game_locals_t::maxentities
int maxentities
Definition: g_local.h:281
game_locals_t::maxclients
int maxclients
Definition: g_local.h:280