UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
g_utils.h File Reference

Misc utility functions for game module. More...

#include "g_local.h"

Go to the source code of this file.

Functions

void G_FreeEdict (Edict *e)
 Marks the edict as free. More...
 
EdictG_GetEdictFromPos (const pos3_t pos, const entity_type_t type)
 Searches an edict of the given type at the given grid location. More...
 
EdictG_GetEdictFromPosExcluding (const pos3_t pos, const int n,...)
 Searches an edict that is not of the given types at the given grid location. More...
 
bool G_UseEdict (Edict *ent, Edict *activator)
 Call the 'use' function for the given edict and all its group members. More...
 
const char * G_GetWeaponNameForFiredef (const fireDef_t *fd)
 Returns the corresponding weapon name for a given fire definition. More...
 
Player * G_GetPlayerForTeam (int team)
 Gets player for given team. More...
 
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. More...
 
bool G_TestLineWithEnts (const vec3_t start, const vec3_t end)
 fast version of a line trace including entities More...
 
bool G_TestLine (const vec3_t start, const vec3_t end)
 fast version of a line trace but without including entities More...
 
trace_t G_Trace (const Line &trLine, const Edict *passent, int contentmask)
 collision detection - this version is more accurate and includes entity tests More...
 
const char * G_GetPlayerName (int pnum)
 Returns the player name for a give player number. More...
 
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. More...
 
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. More...
 
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. More...
 
void G_GenerateEntList (const char *entList[MAX_EDICTS])
 creates an entity list More...
 
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. More...
 
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. More...
 
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. More...
 
uint32_t G_GetLevelFlagsFromPos (const pos3_t pos)
 Calculates the level flags for a given grid position. More...
 

Detailed Description

Misc utility functions for game module.

Definition in file g_utils.h.

Function Documentation

void G_CompleteRecalcRouting ( void  )
See also
G_RecalcRouting

Definition at line 464 of file g_utils.cpp.

References Com_Printf(), GridBox::EMPTY, G_EdictsGetNextInUse(), G_RecalcRouting(), i, IS_BMODEL, and Edict::model.

Referenced by G_RunFrame(), and TEST_F().

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.
1 Edict* ent = nullptr;
2 while ((ent = G_FindRadius(ent, origin, rad, type)) != nullptr) {
3  [...]
4 }

Definition at line 408 of file g_utils.cpp.

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

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

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, and Edict::model.

Referenced by G_RecalcRouting(), and G_TestLineWithEnts().

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().

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, and VectorCompare.

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

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.

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_SpawnFieldPart().

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().

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, game_locals_s::players, and game_locals_s::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]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_s::id.

Referenced by 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(), fireDef_s::name, character_s::name, TEAM_ALIEN, and TEAM_CIVILIAN.

Referenced by G_CheckDeathOrKnockout().

void G_PrintStats ( const char *  format,
  ... 
)
void G_RecalcRouting ( const char *  model,
const GridBox box 
)
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().

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().

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().

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_s::name.

Referenced by Destroy_Breakable().

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().

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, and Edict::type.

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

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().

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().