|
UFO: Alien Invasion
|
Misc utility functions for game module. More...
#include "g_utils.h"#include <time.h>#include "g_client.h"#include "g_actor.h"#include "g_edicts.h"#include "g_trigger.h"
Go to the source code of this file.
Macros | |
| #define | IS_BMODEL(ent) |
Functions | |
| void | G_FreeEdict (Edict *ent) |
| Marks the edict as free. | |
| Edict * | G_GetEdictFromPos (const pos3_t pos, const entity_type_t type) |
| Searches an edict of the given type at the given grid location. | |
| 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. | |
| bool | G_UseEdict (Edict *ent, Edict *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 * | 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. | |
| static void | G_TraceDraw (const Line &traceLine) |
Renders all the traces on the client side if the cvar g_drawtraces is activated. | |
| 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. | |
| 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_PrintStats (const char *format,...) |
| Prints stats to game console and stats log file. | |
| void | G_PrintActorStats (const Edict *victim, const Edict *attacker, const fireDef_t *fd) |
| Prints stats about who killed who with what and how. | |
| Edict * | G_FindRadius (Edict *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 char *model, const GridBox &box) |
| void | G_CompleteRecalcRouting (void) |
| static void | G_ResetTriggers (Edict *ent, Edict **touched, int num) |
| Call the reset function for those triggers that are no longer touched (left the trigger zone). | |
| static int | G_GetTouchingEdicts (const AABB &aabb, Edict **list, int maxCount, Edict *skip) |
| Fills a list with edicts that are in use and are touching the given bounding box. | |
| int | G_TouchTriggers (Edict *ent, const entity_type_t type) |
| 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 *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. | |
| uint32_t | G_GetLevelFlagsFromPos (const pos3_t pos) |
| Calculates the level flags for a given grid position. | |
Misc utility functions for game module.
Definition in file g_utils.cpp.
| #define IS_BMODEL | ( | ent | ) |
Definition at line 428 of file g_utils.cpp.
Referenced by G_CompleteRecalcRouting(), and G_GenerateEntList().
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_PrintStats(), 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.
| [in] | from | The entity to start the search from. nullptr 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* ent = nullptr;
[...]
}
Definition g_edict.h:45 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 |
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().
Marks the edict as free.
| ent | The edict to free. |
Definition at line 41 of file g_utils.cpp.
References Edict::classname, G_EventDestroyEdict(), gi, Edict::inuse, and Edict::nativeReset().
Referenced by Destroy_Breakable(), Destroy_Camera(), G_ActorInvMove(), G_InitCamera(), 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_camera(), SP_misc_item(), SP_misc_message(), SP_misc_mission(), SP_misc_model(), SP_player_start(), SP_trigger_nextmap(), SP_trigger_rescue(), SP_trigger_touch(), Think_SmokeAndFire(), 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 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().
| 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.
| [in] | origin | The center of the area to search for close actors |
| [in] | radius | The 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().
| Edict * 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. |
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().
Searches an edict that is not of the given types at the given grid location.
| pos | The grid location to look for an edict. |
| n | The amount of given entity_type_t values that are given via variadic arguments to this function. |
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_PrintStats(), and G_SpawnFieldPart().
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 nullptr when no object found. Definition at line 148 of file g_utils.cpp.
References objDef_t::fd, gi, i, objDef_t::numFiredefs, and objDef_t::numWeapons.
Referenced by G_GetWeaponNameForFiredef().
| Player * G_GetPlayerForTeam | ( | int | team | ) |
Gets player for given team.
| [in] | team | The team the player data should be searched for |
nullptr when no player found. 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.
Referenced by G_PrintActorStats(), and GetGameAPI().
Fills a list with edicts that are in use and are touching the given bounding box.
| [in] | aabb | The bounding box |
| [out] | list | The edict list that this trace is hitting |
| [in] | maxCount | The size of the given list |
| [in] | skip | An edict to skip (e.g. pointer to the calling edict) |
Definition at line 519 of file g_utils.cpp.
References Edict::absBox, AABB::doesIntersect(), G_EdictsGetFirst(), G_EdictsGetNextInUse(), Edict::solid, and SOLID_NOT.
Referenced by G_TouchEdicts(), G_TouchSolids(), and G_TouchTriggers().
| 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 173 of file g_utils.cpp.
References G_GetObjectForFiredef(), and objDef_t::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 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().
| void G_PrintStats | ( | const char * | format, |
| ... ) |
Prints stats to game console and stats log file.
Definition at line 304 of file g_utils.cpp.
References Com_sprintf(), format(), gi, logstatsfile, and Q_vsnprintf().
Referenced by G_ActorRevitalise(), G_BleedWounds(), G_GetStartingTeam(), G_MatchDoEnd(), G_MoraleBehaviour(), G_MoralePanic(), G_MoraleRage(), G_MoraleStopPanic(), G_MoraleStopRage(), and G_PrintActorStats().
Definition at line 452 of file g_utils.cpp.
References G_GenerateEntList(), gi, and MAX_EDICTS.
Referenced by Destroy_Breakable(), Door_Use(), G_CompleteRecalcRouting(), and G_PrintStats().
Call the reset function for those triggers that are no longer touched (left the trigger zone).
| ent | The edict that is leaving the trigger area |
| touched | The edicts that the activating ent currently touches |
| num | The amount of edicts in the touched list |
Definition at line 485 of file g_utils.cpp.
References G_EdictsGetNextInUse(), G_TriggerIsInList(), G_TriggerRemoveFromList(), i, Edict::reset, Edict::solid, and SOLID_TRIGGER.
Referenced by G_TouchTriggers().
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 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().
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 253 of file g_utils.cpp.
References G_TraceDraw(), gi, and TL_FLAG_NONE.
Referenced by G_SplashDamage(), and 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 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().
Call after linking a new trigger in or destroying a bmodel during gameplay to force all entities it covers to immediately touch it.
| [in] | trigger | The edict to check. |
| [in] | extend | Extend 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().
Call after making a step to a new grid tile to immediately touch edicts whose bbox intersects with the edicts' bbox.
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().
| int G_TouchTriggers | ( | Edict * | ent, |
| const entity_type_t | type ) |
Check the world against triggers for the current entity.
| [in,out] | ent | The entity that maybe touches others |
| [in] | type | Type of the entity |
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().
collision detection - this version is more accurate and includes entity tests
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().
Renders all the traces on the client side if the cvar g_drawtraces is activated.
| traceLine | The start and end vectors of the line to trace |
Definition at line 225 of file g_utils.cpp.
References g_drawtraces, G_EventParticleSpawn(), PM_ALL, Line::start, Line::stop, TRACE_ALL_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 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().