g_utils.c File Reference

Misc utility functions for game module. More...

#include "g_local.h"
#include <time.h>
Include dependency graph for g_utils.c:

Go to the source code of this file.

Defines

#define IS_BMODEL(ent)   ((ent)->model && (ent)->model[0] == '*' && (ent)->solid == SOLID_BSP)

Functions

void G_FreeEdict (edict_t *ent)
 Marks the edict as free.
edict_tG_GetEdictFromPos (const pos3_t pos, const entity_type_t type)
 Searches an edict of the given type at the given grid location.
qboolean G_UseEdict (edict_t *ent, edict_t *activator)
 Call the 'use' function for the given edict and all its group members.
static const objDef_tG_GetObjectForFiredef (const fireDef_t *fd)
 Searches for the obj that has the given firedef.
const char * G_GetWeaponNameForFiredef (const fireDef_t *fd)
 Returns the corresponding weapon name for a given fire definition.
player_tG_GetPlayerForTeam (int team)
 Gets player for given team.
void G_TakeDamage (edict_t *ent, int damage)
 Applies the given damage value to an edict that is either an actor or has the FL_DESTROYABLE flag set.
static void G_TraceDraw (const vec3_t start, const vec3_t end)
 Renders all the traces on the client side if the cvar g_drawtraces is activated.
qboolean G_TestLineWithEnts (const vec3_t start, const vec3_t end)
 fast version of a line trace including entities
qboolean G_TestLine (const vec3_t start, const vec3_t end)
 fast version of a line trace but without including entities
trace_t G_Trace (const vec3_t start, const vec3_t end, const edict_t *passent, int contentmask)
 collision detection - this version is more accurate and includes entity tests
const char * G_GetPlayerName (int pnum)
 Returns the player name for a give player number.
void G_PrintStats (const char *buffer)
 Prints stats to game console and stats log file.
void G_PrintActorStats (const edict_t *victim, const edict_t *attacker, const fireDef_t *fd)
 Prints stats about who killed who with what and how.
edict_tG_Find (edict_t *from, int fieldofs, char *match)
 Searches all active entities for the next one that holds the matching string at fieldofs (use the offsetof() macro) in the structure.
edict_tG_FindTargetEntity (const char *target)
 Searches the edict that has the given target as targetname set.
edict_tG_FindRadius (edict_t *from, const vec3_t org, float rad, entity_type_t type)
 Returns entities that have origins within a spherical area.
void G_GenerateEntList (const char *entList[MAX_EDICTS])
 creates an entity list
void G_RecalcRouting (const edict_t *ent)
void G_CompleteRecalcRouting (void)
static void G_ResetTriggers (edict_t *ent, edict_t **touched, int num)
 Call the reset function for those triggers that are no longer touched (left the trigger zone).
int G_TouchTriggers (edict_t *ent)
 Check the world against triggers for the current entity.
void G_TouchSolids (edict_t *ent)
 Call after linking a new trigger in or destroying a bmodel during gameplay to force all entities it covers to immediately touch it.
void G_TouchEdicts (edict_t *ent, float extend)
 Call after linking a new trigger in or destroying a bmodel during gameplay to force all entities it covers to immediately touch it.

Detailed Description

Misc utility functions for game module.

Definition in file g_utils.c.


Define Documentation

#define IS_BMODEL ( ent   )     ((ent)->model && (ent)->model[0] == '*' && (ent)->solid == SOLID_BSP)

Definition at line 410 of file g_utils.c.

Referenced by G_CompleteRecalcRouting(), and G_GenerateEntList().


Function Documentation

void G_CompleteRecalcRouting ( void   ) 
See also:
G_RecalcRouting

Definition at line 446 of file g_utils.c.

References G_EdictsGetNextInUse(), G_RecalcRouting(), and IS_BMODEL.

Referenced by G_RunFrame().

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

Searches all active entities for the next one that holds the matching string at fieldofs (use the offsetof() macro) in the structure.

Parameters:
[in] from If this is NULL all edicts will be searched, otherwise the given edict will be the start of the search
[in] fieldofs The field offset of the struct member (returned by the offsetof macro) of the field to search the given value for
[in] match The value of the field
Note:
Searches beginning at the edict after from, or the beginning if NULL
 while ((spot = G_Find(spot, FOFS(classname), "misc_whatever")) != NULL) {
   [..]
 }
Returns:
NULL will be returned if the end of the list is reached.

Definition at line 344 of file g_utils.c.

References byte, G_EdictsGetNextInUse(), and Q_strcasecmp.

edict_t* G_FindRadius ( edict_t from,
const vec3_t  org,
float  rad,
entity_type_t  type 
)

Returns entities that have origins within a spherical area.

Parameters:
[in] from The entity to start the search from. NULL will start from the beginning.
[in] org The origin that is the center of the circle.
[in] rad radius to search an edict in.
[in] type Type of entity. ET_NULL to ignore the type.

 edict_t* ent = NULL;
 while ((ent = G_FindRadius(ent, origin, rad, type)) != NULL) {
   [...]
 }

Definition at line 391 of file g_utils.c.

References ET_NULL, G_EdictsGetNextInUse(), edict_s::maxs, edict_s::mins, edict_s::origin, edict_s::type, and VectorLength().

Referenced by G_ActorUseDoor().

edict_t* G_FindTargetEntity ( const char *  target  ) 

Searches the edict that has the given target as targetname set.

Parameters:
target The target name of the edict that you are searching
Returns:
NULL if no edict with the given target name was found, otherwise the edict that has the targetname set you were looking for.

Definition at line 365 of file g_utils.c.

References G_EdictsGetNext(), and edict_s::targetname.

Referenced by G_MissionUse(), and Touch_TouchTrigger().

void G_FreeEdict ( edict_t ent  ) 
void G_GenerateEntList ( const char *  entList[MAX_EDICTS]  ) 

creates an entity list

Parameters:
[out] entList A list of all active inline model entities
See also:
G_RecalcRouting
G_LineVis

Definition at line 418 of file g_utils.c.

References G_EdictsGetNextInUse(), i, IS_BMODEL, and edict_s::model.

Referenced by G_RecalcRouting(), and G_TestLineWithEnts().

edict_t* G_GetEdictFromPos ( const pos3_t  pos,
const entity_type_t  type 
)

Searches an edict of the given type at the given grid location.

Parameters:
pos The grid location to look for an edict.
type The type of the edict to look for or -1 to look for any type in the search.
Returns:
NULL if nothing was found, otherwise the entity located at the given grid position.

Definition at line 54 of file g_utils.c.

References ET_NULL, G_EdictsGetNextInUse(), edict_s::pos, edict_s::type, and VectorCompare.

Referenced by G_ActorFall(), G_ActorShouldStopInMidMove(), G_GetActorFromPos(), G_GetFloorItemsFromPos(), and G_MissionThink().

static const objDef_t* G_GetObjectForFiredef ( const fireDef_t fd  )  [static]

Searches for the obj that has the given firedef.

Parameters:
[in] fd Pointer to fire definition, for which item is wanted.
Returns:
od to which fire definition belongs or NULL when no object found.

Definition at line 106 of file g_utils.c.

References game_import_t::csi, objDef_s::fd, gi, i, objDef_s::numFiredefs, csi_s::numODs, objDef_s::numWeapons, and csi_s::ods.

Referenced by G_GetWeaponNameForFiredef().

player_t* G_GetPlayerForTeam ( int  team  ) 

Gets player for given team.

Parameters:
[in] team The team the player data should be searched for
Returns:
The inuse player for the given team or NULL when no player found.

Definition at line 147 of file g_utils.c.

References game, i, player_s::inuse, player_s::pers, game_locals_t::players, game_locals_t::sv_maxplayersperteam, and client_persistant_t::team.

Referenced by G_ClientEndRound().

const char* G_GetPlayerName ( int  pnum  ) 

Returns the player name for a give player number.

Definition at line 230 of file g_utils.c.

References game, client_persistant_t::netname, player_s::pers, game_locals_t::players, and game_locals_t::sv_maxplayersperteam.

Referenced by G_PrintActorStats(), and GetGameAPI().

const char* G_GetWeaponNameForFiredef ( const fireDef_t fd  ) 

Returns the corresponding weapon name for a given fire definition.

Parameters:
[in] fd Pointer to fire definition, for which item is wanted.
Returns:
id of the item to which fire definition belongs or "unknown" when no object found.
See also:
G_GetObjectForFiredef

Definition at line 133 of file g_utils.c.

References G_GetObjectForFiredef(), and objDef_s::id.

Referenced by G_PrintActorStats().

void G_PrintActorStats ( const edict_t victim,
const edict_t attacker,
const fireDef_t fd 
)

Prints stats about who killed who with what and how.

Parameters:
[in] victim Pointer to edict being a victim.
[in] attacker Pointer to edict being an attacker.
[in] fd Pointer to fire definition used in attack.
See also:
G_Damage
G_PrintStats

Definition at line 268 of file g_utils.c.

References edict_s::chr, Com_sprintf(), G_GetPlayerName(), G_GetWeaponNameForFiredef(), G_PrintStats(), edict_s::HP, fireDef_s::name, character_s::name, edict_s::pnum, edict_s::team, TEAM_ALIEN, and TEAM_CIVILIAN.

Referenced by G_ClientMove(), and G_Damage().

void G_PrintStats ( const char *  buffer  ) 

Prints stats to game console and stats log file.

See also:
G_PrintActorStats

Definition at line 242 of file g_utils.c.

References Com_sprintf(), gi, and logstatsfile.

Referenced by G_GetStartingTeam(), G_MatchDoEnd(), G_PrintActorStats(), and G_UpdateCharacterSkills().

void G_RecalcRouting ( const edict_t ent  ) 
static void G_ResetTriggers ( edict_t ent,
edict_t **  touched,
int  num 
) [static]

Call the reset function for those triggers that are no longer touched (left the trigger zone).

Parameters:
ent 
touched 
num 

Definition at line 461 of file g_utils.c.

References G_EdictsGetNextInUse(), i, edict_s::reset, edict_s::solid, and SOLID_TRIGGER.

Referenced by G_TouchTriggers().

void G_TakeDamage ( edict_t ent,
int  damage 
)

Applies the given damage value to an edict that is either an actor or has the FL_DESTROYABLE flag set.

Parameters:
ent The edict to apply the damage to.
damage The damage value.
Note:
This function assures, that the health points of the edict are never getting negative.
See also:
G_Damage

Definition at line 170 of file g_utils.c.

References G_IsActor, G_IsBreakable, and edict_s::HP.

Referenced by G_ActorFall(), G_Damage(), and Touch_HurtTrigger().

qboolean G_TestLine ( const vec3_t  start,
const vec3_t  end 
)

fast version of a line trace but without including entities

Parameters:
start The start vector of the trace
end The end vector of the trace
Returns:
false if not blocked

Definition at line 209 of file g_utils.c.

References G_TraceDraw(), gi, and TL_FLAG_NONE.

Referenced by G_TeamPointVis().

qboolean G_TestLineWithEnts ( const vec3_t  start,
const vec3_t  end 
)

fast version of a line trace including entities

Parameters:
start The start vector of the trace
end The end vector of the trace
Returns:
false if not blocked

Definition at line 193 of file g_utils.c.

References G_GenerateEntList(), G_TraceDraw(), gi, MAX_EDICTS, and TL_FLAG_NONE.

Referenced by G_LineVis().

void G_TouchEdicts ( edict_t ent,
float  extend 
)

Call after linking a new trigger in or destroying a bmodel during gameplay to force all entities it covers to immediately touch it.

Parameters:
[in] ent The edict to check.
[in] extend Extend value for the bounding box

Definition at line 541 of file g_utils.c.

References edict_s::absmax, edict_s::absmin, edict_s::chr, Com_DPrintf(), DEBUG_GAME, gi, i, edict_s::inuse, MAX_EDICTS, edict_s::model, character_s::name, and edict_s::touch.

Referenced by Destroy_Breakable().

void G_TouchSolids ( edict_t ent  ) 

Call after linking a new trigger in or destroying a bmodel during gameplay to force all entities it covers to immediately touch it.

Definition at line 513 of file g_utils.c.

References edict_s::absmax, edict_s::absmin, gi, i, edict_s::inuse, MAX_EDICTS, edict_s::solid, SOLID_TRIGGER, and edict_s::touch.

int G_TouchTriggers ( edict_t ent  ) 

Check the world against triggers for the current entity.

Parameters:
[in,out] ent The entity that maybe touches others

Definition at line 483 of file g_utils.c.

References edict_s::absmax, edict_s::absmin, G_IsLivingActor(), G_ResetTriggers(), gi, i, MAX_EDICTS, edict_s::solid, SOLID_TRIGGER, and edict_s::touch.

Referenced by G_ActorUseDoor(), G_ClientGetFreeSpawnPointForActorSize(), and G_ClientMove().

trace_t G_Trace ( const vec3_t  start,
const vec3_t  end,
const edict_t passent,
int  contentmask 
)

collision detection - this version is more accurate and includes entity tests

Note:
traces a box from start to end, ignoring entities passent, stopping if it hits an object of type specified via contentmask (MASK_*).
Returns:
The trace result

Definition at line 221 of file g_utils.c.

References G_TraceDraw(), and gi.

Referenced by G_PhysicsStep(), G_ShootGrenade(), and G_ShootSingle().

static void G_TraceDraw ( const vec3_t  start,
const vec3_t  end 
) [static]

Renders all the traces on the client side if the cvar g_drawtraces is activated.

Parameters:
start The start vector of the trace
end The end vector of the trace

Definition at line 181 of file g_utils.c.

References g_drawtraces, G_EventParticleSpawn(), cvar_s::integer, PM_ALL, TRACING_ALL_VISIBLE_LEVELS, and vec3_origin.

Referenced by G_TestLine(), G_TestLineWithEnts(), and G_Trace().

qboolean G_UseEdict ( edict_t ent,
edict_t activator 
)

Call the 'use' function for the given edict and all its group members.

Parameters:
[in] ent The edict to call the use function for
[in] activator The edict that uses ent
Returns:
qtrue when there is possibility to use edict being parameter.
See also:
G_ClientUseEdict

Definition at line 77 of file g_utils.c.

References FL_GROUPSLAVE, edict_s::flags, G_UseEdict(), edict_s::groupChain, qfalse, qtrue, and edict_s::use.

Referenced by G_ClientUseEdict(), G_UseEdict(), and SP_func_door().


Generated by  doxygen 1.6.2