UFO: Alien Invasion
Loading...
Searching...
No Matches
g_utils.h File Reference

Misc utility functions for game module. More...

#include "g_local.h"
Include dependency graph for g_utils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void G_FreeEdict (Edict *e)
 Marks the edict as free.
EdictG_GetEdictFromPos (const pos3_t pos, const entity_type_t type)
 Searches an edict of the given type at the given grid location.
EdictG_GetEdictFromPosExcluding (const pos3_t pos, const int n,...)
 Searches an edict that is not of the given types at the given grid location.
bool G_UseEdict (Edict *ent, Edict *activator)
 Call the 'use' function for the given edict and all its group members.
const char * G_GetWeaponNameForFiredef (const fireDef_t *fd)
 Returns the corresponding weapon name for a given fire definition.
Player * G_GetPlayerForTeam (int team)
 Gets player for given team.
void G_TakeDamage (Edict *ent, int damage)
 Applies the given damage value to an edict that is either an actor or has the FL_DESTROYABLE flag set.
bool G_TestLineWithEnts (const vec3_t start, const vec3_t end)
 fast version of a line trace including entities
bool 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 Line &trLine, const Edict *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 *format,...) __attribute__((format(__printf__
void void G_PrintActorStats (const Edict *victim, const Edict *attacker, const fireDef_t *fd)
 Prints stats about who killed who with what and how.
EdictG_FindRadius (Edict *from, const vec3_t org, float rad, entity_type_t type=ET_NULL)
 Returns entities that have origins within a spherical area.
playermask_t G_GetClosePlayerMask (const vec3_t origin, float radius)
 Assembles a player mask for those players that have a living team member close to the given location.
void G_GenerateEntList (const char *entList[MAX_EDICTS])
 creates an entity list
void G_RecalcRouting (const char *model, const GridBox &box)
void G_CompleteRecalcRouting (void)
int G_TouchTriggers (Edict *ent, const entity_type_t type=ET_NULL)
 Check the world against triggers for the current entity.
int G_TouchSolids (Edict *ent, float extend)
 Call after making a step to a new grid tile to immediately touch edicts whose bbox intersects with the edicts' bbox.
void G_TouchEdicts (Edict *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.
uint32_t G_GetLevelFlagsFromPos (const pos3_t pos)
 Calculates the level flags for a given grid position.

Detailed Description

Misc utility functions for game module.

Definition in file g_utils.h.

Function Documentation

◆ G_CompleteRecalcRouting()

void G_CompleteRecalcRouting ( void )

◆ G_FindRadius()

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

Returns entities that have origins within a spherical area.

Parameters
[in]fromThe entity to start the search from. nullptr will start from the beginning.
[in]orgThe origin that is the center of the circle.
[in]radradius to search an edict in.
[in]typeType of entity. ET_NULL to ignore the type.
Edict* ent = nullptr;
while ((ent = G_FindRadius(ent, origin, rad, type)) != nullptr) {
[...]
}
Edict * G_FindRadius(Edict *from, const vec3_t org, float rad, entity_type_t type)
Returns entities that have origins within a spherical area.
Definition g_utils.cpp:408
voidpf uLong int origin
Definition ioapi.h:45
QGL_EXTERN GLint GLenum type
Definition r_gl.h:94

Definition at line 408 of file g_utils.cpp.

References Edict::entBox, ET_NULL, G_EdictsGetNextInUse(), AABB::getCenter(), Edict::origin, Edict::type, type, and VectorLength().

Referenced by G_ActorUseDoor(), G_ClientShoot(), G_GetClosePlayerMask(), and G_PrintStats().

◆ G_FreeEdict()

◆ G_GenerateEntList()

void G_GenerateEntList ( const char * entList[MAX_EDICTS])

creates an entity list

Parameters
[out]entListA list of all active inline model entities
See also
G_RecalcRouting
G_LineVis

Definition at line 436 of file g_utils.cpp.

References G_EdictsGetNextInUse(), i, IS_BMODEL, MAX_EDICTS, and Edict::model.

Referenced by G_PrintStats(), G_RecalcRouting(), and G_TestLineWithEnts().

◆ G_GetClosePlayerMask()

playermask_t G_GetClosePlayerMask ( const vec3_t origin,
float radius )

Assembles a player mask for those players that have a living team member close to the given location.

Parameters
[in]originThe center of the area to search for close actors
[in]radiusThe radius to look in

Definition at line 288 of file g_utils.cpp.

References G_FindRadius(), G_IsLivingActor(), G_TeamToPM(), and Edict::getTeam().

Referenced by Door_Use(), and G_PrintStats().

◆ G_GetEdictFromPos()

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

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

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

Definition at line 59 of file g_utils.cpp.

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

Referenced by AIL_positionmission(), AIL_setwaypoint(), G_ActorFall(), G_GetFloorItemFromPos(), G_MissionThink(), and G_SpawnFieldPart().

◆ G_GetEdictFromPosExcluding()

Edict * G_GetEdictFromPosExcluding ( const pos3_t pos,
const int n,
... )

Searches an edict that is not of the given types at the given grid location.

Parameters
posThe grid location to look for an edict.
nThe amount of given entity_type_t values that are given via variadic arguments to this function.
Returns
nullptr if nothing was found, otherwise the entity located at the given grid position.

Definition at line 81 of file g_utils.cpp.

References ET_MAX, G_EdictsGetNextInUse(), i, Edict::pos, Edict::type, and VectorCompare.

◆ G_GetLevelFlagsFromPos()

uint32_t G_GetLevelFlagsFromPos ( const pos3_t pos)

Calculates the level flags for a given grid position.

Definition at line 650 of file g_utils.cpp.

References i, and PATHFINDING_HEIGHT.

Referenced by G_PrintStats(), and G_SpawnFieldPart().

◆ G_GetPlayerForTeam()

Player * G_GetPlayerForTeam ( int team)

Gets player for given team.

Parameters
[in]teamThe team the player data should be searched for
Returns
The inuse player for the given team or nullptr when no player found.
Todo
What if there are multiple players for a team (multiplayer coop match)

Definition at line 188 of file g_utils.cpp.

References G_PlayerGetNextActiveAI(), and G_PlayerGetNextActiveHuman().

Referenced by AI_CheckRespawn(), and G_ClientEndRound().

◆ G_GetPlayerName()

const char * G_GetPlayerName ( int pnum)

Returns the player name for a give player number.

Definition at line 275 of file g_utils.cpp.

References game.

Referenced by G_PrintActorStats(), and GetGameAPI().

◆ G_GetWeaponNameForFiredef()

const char * G_GetWeaponNameForFiredef ( const fireDef_t * fd)

Returns the corresponding weapon name for a given fire definition.

Parameters
[in]fdPointer 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 173 of file g_utils.cpp.

References G_GetObjectForFiredef(), and objDef_t::id.

Referenced by G_PrintActorStats().

◆ G_PrintActorStats()

void void G_PrintActorStats ( const Edict * victim,
const Edict * attacker,
const fireDef_t * fd )

Prints stats about who killed who with what and how.

Parameters
[in]victimPointer to edict being a victim.
[in]attackerPointer to edict being an attacker.
[in]fdPointer to fire definition used in attack.
See also
G_Damage
G_PrintStats

Definition at line 336 of file g_utils.cpp.

References Edict::chr, Com_sprintf(), G_GetPlayerName(), G_GetWeaponNameForFiredef(), G_PrintStats(), Edict::getIdNum(), Edict::getPlayerNum(), Edict::getTeam(), Edict::HP, Edict::isSameTeamAs(), character_t::name, fireDef_t::name, TEAM_ALIEN, and TEAM_CIVILIAN.

Referenced by G_CheckDeathOrKnockout(), and G_PrintStats().

◆ G_PrintStats()

◆ G_RecalcRouting()

void G_RecalcRouting ( const char * model,
const GridBox & box )

◆ G_TakeDamage()

void G_TakeDamage ( Edict * ent,
int damage )

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

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

Definition at line 215 of file g_utils.cpp.

References G_IsActor, G_IsBreakable, and Edict::HP.

Referenced by G_ActorFall(), G_BleedWounds(), G_Damage(), G_DamageActor(), and G_TreatActor().

◆ G_TestLine()

bool G_TestLine ( const vec3_t start,
const vec3_t end )

fast version of a line trace but without including entities

Parameters
startThe start vector of the trace
endThe end vector of the trace
Returns
false if not blocked

Definition at line 253 of file g_utils.cpp.

References G_TraceDraw(), gi, and TL_FLAG_NONE.

Referenced by G_SplashDamage(), and G_TeamPointVis().

◆ G_TestLineWithEnts()

bool G_TestLineWithEnts ( const vec3_t start,
const vec3_t end )

fast version of a line trace including entities

Parameters
startThe start vector of the trace
endThe end vector of the trace
Returns
false if not blocked

Definition at line 237 of file g_utils.cpp.

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

Referenced by AIL_missiontargets(), and G_LineVis().

◆ G_TouchEdicts()

void G_TouchEdicts ( Edict * trigger,
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]triggerThe edict to check.
[in]extendExtend value for the bounding box

Definition at line 625 of file g_utils.cpp.

References Edict::absBox, Edict::callTouch(), Edict::chr, Com_DPrintf(), DEBUG_GAME, AABB::expand(), G_GetTouchingEdicts(), Edict::hasTouch(), i, Edict::inuse, lengthof, MAX_EDICTS, Edict::model, and character_t::name.

Referenced by Destroy_Breakable(), and G_PrintStats().

◆ G_TouchSolids()

int G_TouchSolids ( Edict * ent,
float extend )

Call after making a step to a new grid tile to immediately touch edicts whose bbox intersects with the edicts' bbox.

Returns
the amount of touched edicts

Definition at line 590 of file g_utils.cpp.

References Edict::absBox, Edict::callTouch(), AABB::expand(), G_GetTouchingEdicts(), G_IsLivingActor(), Edict::hasTouch(), i, Edict::inuse, lengthof, makeActor(), MAX_EDICTS, Edict::solid, and SOLID_TRIGGER.

Referenced by G_ClientMove(), and G_PrintStats().

◆ G_TouchTriggers()

int G_TouchTriggers ( Edict * ent,
const entity_type_t type )

Check the world against triggers for the current entity.

Parameters
[in,out]entThe entity that maybe touches others
[in]typeType of the entity
Returns
Returns the number of associated client actions

Definition at line 547 of file g_utils.cpp.

References Edict::absBox, Edict::callTouch(), Edict::dmg, ET_NULL, G_GetTouchingEdicts(), G_IsLivingActor(), G_ResetTriggers(), G_TriggerAddToList(), Edict::hasTouch(), i, Actor::isStunned(), lengthof, makeActor(), MAX_EDICTS, Edict::solid, SOLID_TRIGGER, Edict::type, and type.

Referenced by G_ActorUseDoor(), G_ClientMove(), G_ClientShoot(), G_ClientTeamInfo(), G_PrintStats(), G_RoundTouchTriggers(), and G_SpawnAIPlayer().

◆ G_Trace()

trace_t G_Trace ( const Line & trLine,
const Edict * 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 265 of file g_utils.cpp.

References G_TraceDraw(), and gi.

Referenced by AI_CheckLineOfFire(), G_SendFootstepSound(), G_ShootGrenade(), G_ShootSingle(), and G_SpawnFieldGroup().

◆ G_UseEdict()

bool G_UseEdict ( Edict * ent,
Edict * activator )

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

Parameters
[in]entThe edict to call the use function for
[in]activatorThe edict that uses ent
Returns
true when triggering the use function was successful.
See also
G_ClientUseEdict

Definition at line 117 of file g_utils.cpp.

References Edict::groupChain, Edict::groupMaster, and Edict::use.

Referenced by G_ClientUseEdict(), G_MissionThink(), Reset_TouchTrigger(), SP_func_door(), and Touch_TouchTrigger().