Misc utility functions for game module. More...
#include "g_local.h"
#include <time.h>
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_t * | G_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_t * | G_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_t * | G_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_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. | |
edict_t * | G_FindTargetEntity (const char *target) |
Searches the edict that has the given target as targetname set. | |
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. | |
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. |
Misc utility functions for game module.
Definition in file g_utils.c.
#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().
void G_CompleteRecalcRouting | ( | void | ) |
Definition at line 446 of file g_utils.c.
References G_EdictsGetNextInUse(), G_RecalcRouting(), and IS_BMODEL.
Referenced by G_RunFrame().
Searches all active entities for the next one that holds the matching string at fieldofs (use the offsetof() macro) in the structure.
[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 |
while ((spot = G_Find(spot, FOFS(classname), "misc_whatever")) != NULL) { [..] }
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.
[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.
target | The target name of the edict that you are searching |
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 | ) |
Marks the edict as free.
Definition at line 36 of file g_utils.c.
References edict_s::classname, G_EventDestroyEdict(), gi, edict_s::inuse, and qfalse.
Referenced by Destroy_Breakable(), G_ActorInvMove(), G_MissionThink(), G_MissionUse(), G_SpawnItemOnFloor(), Message_Use(), SP_2x2_start(), SP_alien_start(), SP_civilian_start(), SP_dummy(), SP_human_start(), SP_light(), SP_misc_item(), SP_misc_message(), SP_misc_mission(), SP_misc_model(), SP_player_start(), SP_trigger_touch(), and Touch_TouchTrigger().
void G_GenerateEntList | ( | const char * | entList[MAX_EDICTS] | ) |
creates an entity list
[out] | entList | A list of all active inline model entities |
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.
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. |
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().
Searches for the obj that has the given firedef.
[in] | fd | Pointer to fire definition, for which item is wanted. |
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.
[in] | team | The team the player data should be searched for |
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.
[in] | fd | Pointer to fire definition, for which item is wanted. |
Definition at line 133 of file g_utils.c.
References G_GetObjectForFiredef(), and objDef_s::id.
Referenced by G_PrintActorStats().
Prints stats about who killed who with what and how.
[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. |
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.
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 | ) |
Definition at line 434 of file g_utils.c.
References G_GenerateEntList(), gi, MAX_EDICTS, edict_s::model, and game_import_t::routingMap.
Referenced by Destroy_Breakable(), Door_Use(), and G_CompleteRecalcRouting().
Call the reset function for those triggers that are no longer touched (left the trigger zone).
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.
ent | The edict to apply the damage to. | |
damage | The damage value. |
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().
fast version of a line trace but without including entities
start | The start vector of the trace | |
end | The end vector of the trace |
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().
fast version of a line trace including entities
start | The start vector of the trace | |
end | The end vector of the trace |
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.
[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.
[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().
collision detection - this version is more accurate and includes entity tests
Definition at line 221 of file g_utils.c.
References G_TraceDraw(), and gi.
Referenced by G_PhysicsStep(), G_ShootGrenade(), and G_ShootSingle().
Renders all the traces on the client side if the cvar g_drawtraces
is activated.
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().
Call the 'use' function for the given edict and all its group members.
[in] | ent | The edict to call the use function for |
[in] | activator | The edict that uses ent |
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().