UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
g_vis.cpp File Reference
#include "g_local.h"
#include "g_actor.h"
#include "g_client.h"
#include "g_edicts.h"
#include "g_health.h"
#include "g_inventory.h"
#include "g_utils.h"
#include "g_vis.h"

Go to the source code of this file.

Functions

bool G_FrustumVis (const Edict *from, const vec3_t point)
 Checks whether a point is "visible" from the edicts position. More...
 
static bool G_LineVis (const vec3_t from, const vec3_t to)
 tests the visibility between two points More...
 
bool G_SmokeVis (const vec3_t from, const Edict *check)
 tests for smoke interference More...
 
float G_ActorVis (const Edict *ent, const Edict *check, bool full)
 calculate how much check is "visible" by ent More...
 
int G_VisCheckDist (const Edict *const ent)
 
bool G_Vis (const int team, const Edict *from, const Edict *check, const vischeckflags_t flags)
 test if check is visible by from More...
 
int G_TestVis (const int team, Edict *check, const vischeckflags_t flags)
 test if check is visible by team (or if visibility changed?) More...
 
static bool G_VisShouldStop (const Edict *ent)
 
static int G_DoTestVis (const int team, Edict *check, const vischeckflags_t visFlags, playermask_t playerMask, const Edict *ent)
 
void G_CheckVisPlayer (Player &player, const vischeckflags_t visFlags)
 Sets visible edict on player spawn. More...
 
static int G_CheckVisTeam (const int team, Edict *check, const vischeckflags_t visFlags, const Edict *ent)
 Checks whether an edict appear/perishes for a specific team - also updates the visflags each edict carries. More...
 
int G_CheckVisTeamAll (const int team, const vischeckflags_t visFlags, const Edict *ent)
 Do G_CheckVisTeam for all entities ent is the one that is looking at the others. More...
 
void G_VisMakeEverythingVisible (void)
 Make everything visible to anyone who can't already see it. More...
 
void G_CheckVis (Edict *check, const vischeckflags_t visFlags)
 Check if the edict appears/perishes for the other teams. If they appear for other teams, the needed information for those clients are also send in G_CheckVisTeam resp. G_AppearPerishEvent. More...
 
void G_VisFlagsClear (int team)
 Reset the visflags for all edicts in the global list for the given team - and only for the given team. More...
 
void G_VisFlagsAdd (Edict &ent, teammask_t teamMask)
 
void G_VisFlagsReset (Edict &ent)
 
void G_VisFlagsSwap (Edict &ent, teammask_t teamMask)
 

Function Documentation

float G_ActorVis ( const Edict ent,
const Edict check,
bool  full 
)

calculate how much check is "visible" by ent

Parameters
[in]entThe source edict of the check
[in]checkThe edict to check how good (or if at all) it is visible
[in]fullPerform a full check in different directions. If this is false the actor is fully visible if one vis check returned true. With true this function can also return a value != 0.0 and != 1.0. Try to only use true if you really need the full check. Full checks are of course more expensive.
Returns
a value between 0.0 and 1.0 (one of the ACTOR_VIS_* constants) which reflects the visibility from 0 to 100 percent
Note
This call isn't cheap - try to do this only if you really need the visibility check or the statement whether one particular actor see another particular actor.
See also
CL_ActorVis

Definition at line 100 of file g_vis.cpp.

References ACTOR_VIS_0, ACTOR_VIS_10, ACTOR_VIS_100, ACTOR_VIS_50, G_ActorGetEyeVector(), G_IsCrouched, G_IsDead, G_LineVis(), G_SmokeVis(), i, Edict::origin, PLAYER_CROUCH, PLAYER_DEAD, PLAYER_MIN, PLAYER_STAND, VectorCopy, VectorMA(), and VectorNormalizeFast().

Referenced by AI_CheckCrouch(), AI_CheckUsingDoor(), AI_CivilianCalcActionScore(), AI_FighterCalcActionScore(), AI_FindBestFiredef(), AI_PanicCalcActionScore(), AI_SearchDestroyableObject(), AIL_positionshoot(), ReactionFire::canSee(), G_Morale(), and G_Vis().

void G_CheckVis ( Edict check,
const vischeckflags_t  visFlags 
)

Check if the edict appears/perishes for the other teams. If they appear for other teams, the needed information for those clients are also send in G_CheckVisTeam resp. G_AppearPerishEvent.

Parameters
[in]checkThe edict that is maybe seen by others. If nullptr, all edicts are checked
visFlagsModifiers for the checks
See also
G_CheckVisTeam

Definition at line 409 of file g_vis.cpp.

References G_CheckVisTeam(), G_CheckVisTeamAll(), level, MAX_TEAMS, and level_locals_s::num_alive.

Referenced by Door_Use(), G_ActorDieOrStun(), G_ActorFall(), G_ActorInvMove(), G_ActorRevitalise(), G_ClientMove(), G_ClientStateChangeUpdate(), G_Damage(), G_InventoryToFloor(), G_SpawnAIPlayer(), G_SpawnAIPlayers(), G_SpawnItemOnFloor(), G_SpawnParticle(), SP_misc_smoke(), and Think_SmokeAndFire().

void G_CheckVisPlayer ( Player &  player,
const vischeckflags_t  visFlags 
)

Sets visible edict on player spawn.

See also
G_ClientStartMatch
G_CheckVisTeam
G_AppearPerishEvent

Definition at line 327 of file g_vis.cpp.

References G_DoTestVis(), G_EdictsGetNextInUse(), and G_PlayerToPM.

Referenced by G_ClientStartMatch().

static int G_CheckVisTeam ( const int  team,
Edict check,
const vischeckflags_t  visFlags,
const Edict ent 
)
static

Checks whether an edict appear/perishes for a specific team - also updates the visflags each edict carries.

See also
G_TestVis
Parameters
[in]teamTeam to check the vis for
[in]checkThe edict that you want to check (and which maybe will appear or perish for the given team). If this is nullptr every edict will be checked.
visFlagsModifiers for the checks
[in]entThe edict that is (maybe) seeing other edicts
Returns
If an actor get visible who's no civilian VIS_STOP is added to the bit mask, VIS_APPEAR means, that the actor is becoming visible for the queried team, VIS_PERISH means that the actor (the edict) is getting invisible
Note
the edict may not only be actors, but also items of course
See also
G_TeamToPM
G_TestVis
G_AppearPerishEvent
G_CheckVisPlayer
G_CheckVisTeamAll
Note
If something appears, the needed information for those clients that are affected are also send in G_AppearPerishEvent

Definition at line 359 of file g_vis.cpp.

References G_DoTestVis(), G_TeamToPM(), and Edict::inuse.

Referenced by G_CheckVis(), and G_CheckVisTeamAll().

int G_CheckVisTeamAll ( const int  team,
const vischeckflags_t  visFlags,
const Edict ent 
)

Do G_CheckVisTeam for all entities ent is the one that is looking at the others.

Definition at line 376 of file g_vis.cpp.

References G_CheckVisTeam(), and G_EdictsGetNextInUse().

Referenced by AIL_see(), Door_Use(), G_ActorDieOrStun(), G_ActorDoTurn(), G_ActorRevitalise(), G_CheckVis(), G_ClientEndRound(), G_ClientMove(), G_ClientShoot(), G_ClientStateChangeUpdate(), G_Damage(), and G_SpawnAIPlayer().

static int G_DoTestVis ( const int  team,
Edict check,
const vischeckflags_t  visFlags,
playermask_t  playerMask,
const Edict ent 
)
static
Parameters
[in]teamThe team looking at the edict (or not)
[in]checkThe edict to check the visibility for
[in]visFlagsThe flags for the vis check
[in]playerMaskThe mask for the players to send the appear/perish events to. If this is 0 the events are not sent - we only update the visflags of the edict
[in]entThe edict that was responsible for letting the check edict appear and is looking

Definition at line 290 of file g_vis.cpp.

References G_AppearPerishEvent(), G_EventActorAdd(), G_IsActor, G_TeamToVisMask, G_TestVis(), G_VisFlagsSwap(), G_VisShouldStop(), VIS_APPEAR, VIS_PERISH, VIS_STOP, VS_CHANGE, VS_YES, and VT_NEW.

Referenced by G_CheckVisPlayer(), and G_CheckVisTeam().

bool G_FrustumVis ( const Edict from,
const vec3_t  point 
)

Checks whether a point is "visible" from the edicts position.

See also
FrustumVis

Definition at line 38 of file g_vis.cpp.

References Edict::camera, Edict::dir, FrustumVis(), G_IsActiveCamera, Edict::origin, and camera_edict_data_s::rotate.

Referenced by AI_CheckCrouch(), AI_CheckUsingDoor(), ReactionFire::canSee(), G_Morale(), G_SplashDamage(), G_TeamPointVis(), and G_Vis().

static bool G_LineVis ( const vec3_t  from,
const vec3_t  to 
)
static

tests the visibility between two points

Parameters
[in]fromThe point to check visibility from
[in]toThe point to check visibility to
Returns
true if the points are invisible from each other (trace hit something), false otherwise.

Definition at line 54 of file g_vis.cpp.

References G_TestLineWithEnts().

Referenced by G_ActorVis(), and G_Vis().

bool G_SmokeVis ( const vec3_t  from,
const Edict check 
)

tests for smoke interference

Parameters
[in]fromThe point to check visibility from
[in]checkThe edict to check visibility to
Returns
true if check is invisible from from (smoke is in the way), false otherwise.

Definition at line 65 of file g_vis.cpp.

References Edict::absBox, f, G_EdictsGetNextInUse(), G_IsSmoke, AABB::maxs, AABB::mins, Edict::origin, RayIntersectAABB(), UNIT_SIZE, and VectorDist.

Referenced by G_ActorVis(), and G_SplashDamage().

int G_TestVis ( const int  team,
Edict check,
const vischeckflags_t  flags 
)

test if check is visible by team (or if visibility changed?)

See also
G_CheckVisTeam
Parameters
[in]teamthe team the edict may become visible for or perish from their view
[in]checkthe edict we are talking about - which may become visible or perish
[in]flagsif you want to check whether the edict may also perish from other players view, you should use the VT_PERISHCHK bits
Note
If the edict is already visible and flags doesn't contain the bits of VT_PERISHCHK, no further checks are performed - only the VS_YES bits are returned
Returns
VS_CHANGE is added to the bit mask if the edict flipped its visibility (invisible to visible or vice versa) VS_YES means the edict is visible for the given team

Definition at line 255 of file g_vis.cpp.

References g_aidebug, G_EdictsGetNextInUse(), G_IsVisibleForTeam, G_Vis(), cvar_s::integer, VS_CHANGE, VS_YES, and VT_PERISHCHK.

Referenced by AI_IsExposed(), AIL_positionapproach(), AIL_positionflee(), and G_DoTestVis().

bool G_Vis ( const int  team,
const Edict from,
const Edict check,
const vischeckflags_t  flags 
)

test if check is visible by from

Parameters
[in]teamLiving team members are always visible. If this is a negative number we inverse the team rules (see comments included). In combination with VT_NOFRUSTUM we can check whether there is any edict (that is no in our team) that can see check
[in]fromis from team team and must be a living actor
[in]checkThe edict we want to get the visibility for
[in]flagsVT_NOFRUSTUM, ...

Definition at line 183 of file g_vis.cpp.

References ACTOR_VIS_0, ET_ACTOR, ET_ACTOR2x2, ET_CAMERA, ET_ITEM, ET_PARTICLE, G_ActorGetEyeVector(), G_ActorVis(), G_FrustumVis(), G_IsActiveCamera, G_IsDead, G_IsLivingActor(), G_IsVisibleOnBattlefield, G_LineVis(), G_VisCheckDist(), Edict::getTeam(), Edict::inuse, Edict::origin, Edict::pos, Edict::type, VectorCompare, VectorDistSqr, and VT_NOFRUSTUM.

Referenced by AI_HideNeeded(), AIL_see(), and G_TestVis().

void G_VisFlagsAdd ( Edict ent,
teammask_t  teamMask 
)

Definition at line 433 of file g_vis.cpp.

References Edict::visflags.

Referenced by G_ClientSendEdictsAndBrushModels(), and G_SplashDamage().

void G_VisFlagsClear ( int  team)

Reset the visflags for all edicts in the global list for the given team - and only for the given team.

Definition at line 424 of file g_vis.cpp.

References G_EdictsGetNextInUse(), G_TeamToVisMask, and Edict::visflags.

Referenced by G_ClientStartMatch(), and G_SpawnAIPlayers().

void G_VisFlagsReset ( Edict ent)
void G_VisFlagsSwap ( Edict ent,
teammask_t  teamMask 
)

Definition at line 443 of file g_vis.cpp.

References Edict::visflags.

Referenced by G_AppearPerishEvent(), and G_DoTestVis().

void G_VisMakeEverythingVisible ( void  )

Make everything visible to anyone who can't already see it.

Definition at line 390 of file g_vis.cpp.

References G_AppearPerishEvent(), G_EdictsGetNextInUse(), G_IsActor, G_SendInventory(), G_TeamToPM(), G_VisToPM(), Edict::getTeam(), and Edict::visflags.

Referenced by G_MatchSendResults().

static bool G_VisShouldStop ( const Edict ent)
static

Definition at line 277 of file g_vis.cpp.

References G_IsCivilian, and G_IsLivingActor().

Referenced by G_DoTestVis().