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

Interface for g_client.cpp. More...

#include "g_local.h"

Go to the source code of this file.

Functions

Player * G_PlayerGetNextHuman (Player *lastPlayer)
 Iterate through the list of players. More...
 
Player * G_PlayerGetNextAI (Player *lastPlayer)
 Iterate through the list of players. More...
 
Player * G_PlayerGetNextActiveHuman (Player *lastPlayer)
 Iterate through the list of players. More...
 
Player * G_PlayerGetNextActiveAI (Player *lastPlayer)
 Iterate through the list of players. More...
 
playermask_t G_TeamToPM (int team)
 Generates the player bit mask for a given team. More...
 
teammask_t G_PMToVis (playermask_t playerMask)
 Converts player mask to vis mask. More...
 
playermask_t G_VisToPM (teammask_t teamMask)
 Converts vis mask to player mask. More...
 
void G_ClientPrintf (const Player &player, int printlevel, const char *fmt,...) __attribute__((format(__printf__
 
void void G_GiveTimeUnits (int team)
 Network function to update the time units (TUs) for each team-member. More...
 
void G_AppearPerishEvent (playermask_t player_mask, bool appear, Edict &check, const Edict *ent)
 Send the appear or perish event to the affected clients. More...
 
void G_SendInvisible (const Player &player)
 This function sends all the actors to the client that are not visible initially - this is needed because an actor can e.g. produce sounds that are send over the net. And the client can only handle them if he knows the le_t (local entity) already. More...
 
int G_GetActiveTeam (void)
 Returns the current active team to the server. More...
 
bool G_ActionCheckForCurrentTeam (const Player &player, Actor *ent, int TU)
 Checks whether the requested action is possible for the current active team. More...
 
bool G_ActionCheckForCurrentTeam2 (const Player &player, Edict *ent, int TU)
 
bool G_ActionCheckForReaction (const Player &player, Actor *actor, int TU)
 Checks whether the requested action is possible. More...
 
void G_ClientStateChange (const Player &player, Actor *actor, int reqState, bool checkaction)
 Changes the state of a player/soldier. More...
 
bool G_ClientCanReload (Actor *actor, containerIndex_t containerID)
 Returns true if actor can reload weapon. More...
 
bool G_ClientGetWeaponFromInventory (Actor *actor)
 Retrieve or collect a loaded weapon from any linked container for the actor's right hand. More...
 
bool G_ClientUseEdict (const Player &player, Actor *actor, Edict *door)
 This function 'uses' the edict. E.g. it opens the door when the player wants it to open. More...
 
int G_ClientAction (Player &player)
 The client sent us a message that he did something. We now execute the related function(s) and notify him if necessary. More...
 
bool G_SetTeamForPlayer (Player &player, const int team)
 Set the used team for the given player. More...
 
int G_ClientGetTeamNum (const Player &player)
 Returns the assigned team number of the player. More...
 
int G_ClientGetTeamNumPref (const Player &player)
 Returns the preferred team number for the player. More...
 
bool G_ClientIsReady (const Player *player)
 
ActorG_ClientGetFreeSpawnPointForActorSize (const Player &player, const actorSizeEnum_t actorSize)
 Searches a free spawning point for a given actor size and turns it into an actor. More...
 
void G_ClientInitActorStates (const Player &player)
 This is called after the actors are spawned and will set actor states without consuming TUs. More...
 
void G_ClientTeamInfo (const Player &player)
 The client lets the server spawn the actors for a given player by sending their information (models, inventory, etc..) over the network. More...
 
bool G_ClientBegin (Player &player)
 This functions starts the client. More...
 
void G_ClientStartMatch (Player &player)
 Sets the team, init the TU and sends the player stats. More...
 
void G_ClientUserinfoChanged (Player &player, const char *userinfo)
 called whenever the player updates a userinfo variable. More...
 
bool G_ClientConnect (Player *player, char *userinfo, size_t userinfoSize)
 Checks whether the connection is valid or invalid and set some user info keys. More...
 
void G_ClientDisconnect (Player &player)
 
void G_ResetClientData (void)
 Called after every player has joined. More...
 

Detailed Description

Interface for g_client.cpp.

Definition in file g_client.h.

Function Documentation

bool G_ActionCheckForCurrentTeam ( const Player &  player,
Actor ent,
int  TU 
)

Checks whether the requested action is possible for the current active team.

Parameters
[in]playerWhich player (human player) is trying to do the action
[in]entWhich of his units is trying to do the action.
[in]TUThe time units to check against the ones ent has. the action with

Definition at line 380 of file g_client.cpp.

References _, level_locals_s::activeTeam, G_ActionCheck(), G_ActorUsableTUs(), G_ClientPrintf(), level, and PRINT_HUD.

Referenced by G_ActorInvMove(), G_ClientMove(), G_ClientShoot(), G_ClientStateChange(), G_ClientTurn(), and G_ClientUseEdict().

bool G_ActionCheckForCurrentTeam2 ( const Player &  player,
Edict ent,
int  TU 
)
bool G_ActionCheckForReaction ( const Player &  player,
Actor actor,
int  TU 
)

Checks whether the requested action is possible.

Parameters
[in]playerWhich player (human player) is trying to do the action
[in]actorWhich of his units is trying to do the action.
[in]TUThe time units to check against the ones actor has. the action with
See also
G_ActionCheck

Definition at line 403 of file g_client.cpp.

References G_ActionCheck(), and Edict::getTus().

Referenced by G_ClientShoot().

void G_AppearPerishEvent ( playermask_t  playerMask,
bool  appear,
Edict check,
const Edict ent 
)

Send the appear or perish event to the affected clients.

Parameters
[in]playerMaskThese are the affected players or clients In case of e.g. teamplay there can be more than one client affected - thus this is a player mask
[in]appearIs this event about an appearing actor (or a perishing one)
[in]checkThe edict we are talking about (that appears or perishes)
[in]entThe edict that was responsible for letting the check edict appear or perish. Might be nullptr.
See also
CL_ActorAppear

Definition at line 245 of file g_client.cpp.

References ET_ACTOR, ET_ACTOR2x2, ET_CAMERA, ET_ITEM, ET_PARTICLE, ET_TRIGGER_RESCUE, G_EventActorAppear(), G_EventAddBrushModel(), G_EventCameraAppear(), G_EventEdictAppear(), G_EventEdictPerish(), G_EventSendParticle(), G_IsVisibleOnBattlefield, G_PMToVis(), G_SendInventory(), G_VisFlagsSwap(), gi, makeActor(), and Edict::type.

Referenced by AI_CheckRespawn(), G_DoTestVis(), G_MissionThink(), G_SplashDamage(), and G_VisMakeEverythingVisible().

int G_ClientAction ( Player &  player)

The client sent us a message that he did something. We now execute the related function(s) and notify him if necessary.

Parameters
[in]playerThe player to execute the action for (the actor belongs to this player)
Note
a client action will also send the server side edict number to determine the actor

Definition at line 638 of file g_client.cpp.

References Edict::chr, Edict::clientAction, format(), G_ActorInvMove(), G_ActorReserveTUs(), G_ActorUseDoor(), G_ClientMove(), G_ClientShoot(), G_ClientStateChange(), G_ClientTurn(), G_EdictsGetByNum(), G_IsDoor, G_ReactionFireSettingsUpdate(), Inventory::getItemAtPos(), gi, i, character_s::inv, INVDEF, INVSH_GetItemByIDX(), isValidContId(), makeActor(), pa_format, PA_INVMOVE, PA_MOVE, PA_NULL, PA_REACT_SELECT, PA_RESERVE_STATE, PA_SHOOT, PA_STATE, PA_TURN, PA_USE, chrReservations_s::reaction, and character_s::reservedTus.

Referenced by GetGameAPI().

bool G_ClientBegin ( Player &  player)
bool G_ClientCanReload ( Actor actor,
containerIndex_t  containerID 
)
bool G_ClientConnect ( Player *  player,
char *  userinfo,
size_t  userinfoSize 
)

Checks whether the connection is valid or invalid and set some user info keys.

Parameters
[in,out]playerThe player that is trying to connect to the game
[in,out]userinfoThe userinfo data that is checked and changed
[in]userinfoSizeThe size of the userinfo buffer
See also
G_ClientDisconnect
CL_ConnectionlessPacket
Todo:
Check if the teamnum preference has already reached maxsoldiers and reject connection if so
Returns
false if the connection is refused, true otherwise

Definition at line 1436 of file g_client.cpp.

References Com_Printf(), G_ClientDisconnect(), G_ClientUserinfoChanged(), G_PlayerToPM, gi, Info_SetValueForKey(), Info_ValueForKey(), OBJZERO, password, PRINT_CONSOLE, Q_streq, REJ_BANNED, REJ_PASSWORD_REQUIRED_OR_INCORRECT, REJ_SERVER_FULL, cvar_s::string, and SV_FilterPacket().

Referenced by GetGameAPI().

Actor* G_ClientGetFreeSpawnPointForActorSize ( const Player &  player,
const actorSizeEnum_t  actorSize 
)

Searches a free spawning point for a given actor size and turns it into an actor.

Parameters
[in]playerThe player to get the free spawn points for
[in]actorSizeThe actor size to get a spawning point for
Returns
An actor edict or nullptr if no free spawning point was found

Definition at line 1039 of file g_client.cpp.

References ACTOR_SIZE_2x2, ACTOR_SIZE_NORMAL, Edict::chr, ET_ACTOR, ET_ACTOR2x2, ET_ACTOR2x2SPAWN, ET_ACTORSPAWN, Edict::fieldSize, character_s::fieldSize, FL_DESTROYABLE, Edict::flags, G_ActorModifyCounters(), G_ClientGetFreeSpawnPoint(), G_EdictDuplicate(), G_ReactionFireTargetsCreate(), G_ThinkActorDieAfterSpawn(), G_ThinkActorGoCrouch(), G_VisFlagsReset(), Edict::getTeam(), gi, Edict::HP, level, makeActor(), Edict::nextthink, level_locals_s::num_spawned, Edict::setMorale(), Edict::setPlayerNum(), Edict::spawnflags, STATE_CROUCHED, STATE_DEAD, STATE_STUN, Edict::think, and Edict::type.

Referenced by G_ClientTeamInfo(), and G_SpawnAIPlayer().

int G_ClientGetTeamNum ( const Player &  player)

Returns the assigned team number of the player.

Definition at line 889 of file g_client.cpp.

Referenced by G_GetTeam(), and GetGameAPI().

int G_ClientGetTeamNumPref ( const Player &  player)

Returns the preferred team number for the player.

Definition at line 897 of file g_client.cpp.

References Info_IntegerForKey().

Referenced by G_GetTeam().

bool G_ClientGetWeaponFromInventory ( Actor actor)

Retrieve or collect a loaded weapon from any linked container for the actor's right hand.

Note
This function will also collect items from floor containers when the actor is standing on a given point.
See also
AI_ActorThink

Definition at line 568 of file g_client.cpp.

References Edict::chr, CID_RIGHT, Item::def(), Container::def(), G_ActorInvMove(), Inventory::getNextCont(), Container::getNextItem(), character_s::inv, INVDEF, Item::isWeapon(), Item::mustReload(), invDef_s::out, character_s::teamDef, and teamDef_s::weapons.

Referenced by AI_ActorThink(), and AIL_grabweapon().

void G_ClientInitActorStates ( const Player &  player)

This is called after the actors are spawned and will set actor states without consuming TUs.

Parameters
playerThe player to perform the action for

Definition at line 1215 of file g_client.cpp.

References G_ActorSetTU(), G_ClientStateChange(), G_ClientStateChangeUpdate(), G_EdictsGetActorByUCN(), G_ReactionFireSettingsReserveTUs(), G_ReactionFireSettingsUpdate(), Edict::getTus(), gi, i, INVSH_GetItemByIDX(), length, and NONE.

Referenced by GetGameAPI().

bool G_ClientIsReady ( const Player *  player)
Returns
true if the player is for starting the multiplayer match

Definition at line 905 of file g_client.cpp.

Referenced by GetGameAPI().

void G_ClientPrintf ( const Player &  player,
int  printlevel,
const char *  fmt,
  ... 
)
void G_ClientStateChange ( const Player &  player,
Actor actor,
int  reqState,
bool  checkaction 
)

Changes the state of a player/soldier.

Parameters
[in,out]playerThe player who controls the actor
[in]actorthe edict to perform the state change for
[in]reqStateThe bit-map of the requested state change
[in]checkactionif false only activate the events - network stuff is handled in the calling function don't even use the G_ActionCheckForCurrentTeam function
Note
Use checkaction false only for e.g. spawning values

Definition at line 473 of file g_client.cpp.

References _, Edict::chr, chrReservations_s::crouch, Edict::fieldSize, G_ActionCheckForCurrentTeam(), G_ActorReserveTUs(), G_ActorSetMaxs(), G_ActorUseTU(), G_ClientPrintf(), G_ClientStateChangeUpdate(), G_EventReactionFireChange(), G_IsAI, G_ReactionFireSettingsReserveTUs(), G_SetState, G_ToggleCrouched, gi, Actor::isCrouched(), Actor::isReaction(), Actor::isShaken(), Edict::pos, PRINT_HUD, Actor::removeReaction(), character_s::reservedTus, chrReservations_s::shot, STATE_CROUCHED, STATE_REACTION, and TU_CROUCH.

Referenced by AI_ActorThink(), AI_InitPlayer(), AIL_crouch(), AIL_reactionfire(), G_ActorDieOrStun(), G_ClientAction(), G_ClientInitActorStates(), G_ClientMove(), G_MoraleBehaviour(), G_MoralePanic(), G_MoraleRage(), G_ReactionFireSettingsUpdate(), and G_ThinkActorGoCrouch().

void G_ClientTeamInfo ( const Player &  player)
bool G_ClientUseEdict ( const Player &  player,
Actor actor,
Edict edict 
)

This function 'uses' the edict. E.g. it opens the door when the player wants it to open.

See also
PA_USE_DOOR
Parameters
[in]playerThe player is trying to activate the door
[in,out]actorThe actor the player is using to activate the entity
[in,out]edictThe entity that is to be used
Todo:
Do we have to change the trigger position here, too? I don't think this is really needed.
See also
CL_ActorUse
G_UseEdict

Definition at line 614 of file g_client.cpp.

References G_ActionCheckForCurrentTeam(), G_ActorUseTU(), G_EventEnd(), G_SendStats(), G_UseEdict(), and Edict::TU.

Referenced by G_ActorUseDoor().

void G_ClientUserinfoChanged ( Player &  player,
const char *  userinfo 
)

called whenever the player updates a userinfo variable.

Note
The game can override any of the settings in place (forcing skins or names, etc) before copying it off.

Definition at line 1393 of file g_client.cpp.

References Com_DPrintf(), CS_PLAYERNAMES, DEBUG_GAME, G_GetTeam(), G_MatchIsRunning(), gi, Info_IntegerForKey(), Info_Validate(), Info_ValueForKey(), Q_strncpyz(), and TEAM_NO_ACTIVE.

Referenced by G_ClientConnect(), and GetGameAPI().

int G_GetActiveTeam ( void  )

Returns the current active team to the server.

If this has the value TEAM_NO_ACTIVE there is either no
living actor for any player left, or the turn wasn't started yet.

Definition at line 327 of file g_client.cpp.

References level_locals_s::activeTeam, and level.

Referenced by G_ClientEndRound(), G_GetNextActiveTeam(), and GetGameAPI().

void void G_GiveTimeUnits ( int  team)

Network function to update the time units (TUs) for each team-member.

Parameters
[in]teamThe index of the team to update the values for.
See also
G_SendStats

Definition at line 224 of file g_client.cpp.

References G_ActorGiveTimeUnits(), G_EdictsGetNextLivingActorOfTeam(), and G_SendStats().

Referenced by G_ClientEndRound().

Player* G_PlayerGetNextActiveAI ( Player *  lastPlayer)

Iterate through the list of players.

Parameters
lastPlayerThe player found in the previous iteration; if nullptr, we start at the beginning

Definition at line 126 of file g_client.cpp.

References G_PlayerGetNextAI().

Referenced by AI_Run(), G_ClientEndRound(), G_GetPlayerForTeam(), and G_GetTeam().

Player* G_PlayerGetNextActiveHuman ( Player *  lastPlayer)

Iterate through the list of players.

Parameters
lastPlayerThe player found in the previous iteration; if nullptr, we start at the beginning

Definition at line 110 of file g_client.cpp.

References G_PlayerGetNextHuman().

Referenced by AI_Run(), G_CheckForceEndRound(), G_ClientEndRound(), G_GetPlayerForTeam(), G_GetStartingTeam(), G_GetTeam(), G_Players_f(), G_PMToVis(), G_Say_f(), and G_VisToPM().

Player* G_PlayerGetNextAI ( Player *  lastPlayer)

Iterate through the list of players.

Parameters
lastPlayerThe player found in the previous iteration; if nullptr, we start at the beginning

Definition at line 84 of file g_client.cpp.

References game, game_locals_s::players, and game_locals_s::sv_maxplayersperteam.

Referenced by AI_CreatePlayer(), and G_PlayerGetNextActiveAI().

Player* G_PlayerGetNextHuman ( Player *  lastPlayer)

Iterate through the list of players.

Parameters
lastPlayerThe player found in the previous iteration; if nullptr, we start at the beginning

Definition at line 58 of file g_client.cpp.

References game, game_locals_s::players, and game_locals_s::sv_maxplayersperteam.

Referenced by G_PlayerGetNextActiveHuman(), G_SetTeamForPlayer(), G_TeamToPM(), and TEST_F().

teammask_t G_PMToVis ( playermask_t  playerMask)

Converts player mask to vis mask.

Parameters
[in]playerMaskThe player bit mask (contains the player numbers) that is converted to a vis mask
Returns
Returns a vis mask for all the teams of the connected players that are marked in the given playerMask.

Definition at line 165 of file g_client.cpp.

References G_PlayerGetNextActiveHuman(), G_PlayerToPM, and G_TeamToVisMask.

Referenced by G_AppearPerishEvent(), and G_SplashDamage().

void G_ResetClientData ( void  )

Called after every player has joined.

Definition at line 1510 of file g_client.cpp.

References OBJZERO, and scoreMissionNum.

Referenced by G_SpawnEntities().

void G_SendInvisible ( const Player &  player)

This function sends all the actors to the client that are not visible initially - this is needed because an actor can e.g. produce sounds that are send over the net. And the client can only handle them if he knows the le_t (local entity) already.

Note
Call this for the first G_CheckVis call for every new actor or player
See also
G_CheckVis
CL_ActorAdd

Definition at line 302 of file g_client.cpp.

References G_EdictsGetNextActor(), G_EventActorAdd(), G_IsVisibleForTeam, G_PlayerToPM, Edict::getTeam(), level, level_locals_s::num_alive, and TEAM_NO_ACTIVE.

Referenced by G_ClientStartMatch().

bool G_SetTeamForPlayer ( Player &  player,
const int  team 
)

Set the used team for the given player.

Parameters
[out]playerThe player the team should be set for
[in]teamThe team to set for the given player
Returns
true if the team was set successfully, false otherwise.

Definition at line 852 of file g_client.cpp.

References G_IsAIPlayer, g_nospawn, G_PlayerGetNextHuman(), gi, Info_SetValueForKeyAsInteger(), cvar_s::integer, level, MAX_TEAMS, level_locals_s::num_spawnpoints, sv_teamplay, TEAM_ALIEN, TEAM_CIVILIAN, and TEAM_NO_ACTIVE.

Referenced by AI_CreatePlayer(), and G_GetTeam().

playermask_t G_TeamToPM ( int  team)

Generates the player bit mask for a given team.

Parameters
[in]teamThe team to create the player bit mask for
Note
E.g. multiplayer team play can have more than one human player on the same team.

Definition at line 144 of file g_client.cpp.

References G_PlayerGetNextHuman(), and G_PlayerToPM.

Referenced by G_ActorInvMove(), G_CheckVisTeam(), G_EventActorAppear(), G_EventSendState(), G_EventSetClientAction(), G_GetClosePlayerMask(), G_SendStats(), G_SplashDamage(), and G_VisMakeEverythingVisible().