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

Go to the source code of this file.

Macros

#define ACTOR_SPEED_NORMAL   100
 
#define ACTOR_SPEED_CROUCHED   (ACTOR_SPEED_NORMAL / 2)
 

Functions

static void G_BuildForbiddenList (int team, const Edict *movingActor)
 Build the forbidden list for the pathfinding (server side). More...
 
void G_MoveCalc (int team, const Actor *movingActor, const pos3_t from, int distance)
 Precalculates a move table for a given team and a given starting position. This will calculate a routing table for all reachable fields with the given distance from the given spot with the given actorsize. More...
 
void G_MoveCalcLocal (pathing_t *pt, int team, const Edict *movingActor, const pos3_t from, int distance)
 Same as G_MoveCalc, except that it uses the pathing table passed as the first param. More...
 
bool G_FindPath (int team, const Edict *movingActor, const pos3_t from, const pos3_t targetPos, bool crouched, int maxTUs)
 
void G_ActorFall (Edict *ent)
 Let an actor fall down if e.g. the func_breakable the actor was standing on was destroyed. More...
 
static bool G_ActorShouldStopInMidMove (const Edict *ent, int visState, dvec_t *dvtab, int max)
 Checks whether the actor should stop movement. More...
 
static void G_SendFootstepSound (Edict *ent, const int contentFlags)
 
static void G_WriteStep (Actor *ent, const int dvec, const int contentFlags)
 Writes a step of the move event to the net. More...
 
int G_FillDirectionTable (dvec_t *dvtab, size_t dvtabSize, byte crouchingState, pos3_t pos)
 
pos_t G_ActorMoveLength (const Actor *actor, const pathing_t *path, const pos3_t to, bool stored)
 Return the needed TUs to walk to a given position. More...
 
void G_ClientMove (const Player &player, int visTeam, Actor *actor, const pos3_t to)
 Generates the client events that are send over the netchannel to move an actor. More...
 

Variables

static const float FALLING_DAMAGE_FACTOR = 10.0f
 
static forbiddenList_t forbiddenList
 The forbidden list is a list of entity positions that are occupied by an entity. This list is checked everytime an actor wants to walk there. More...
 

Macro Definition Documentation

#define ACTOR_SPEED_CROUCHED   (ACTOR_SPEED_NORMAL / 2)

Definition at line 38 of file g_move.cpp.

Referenced by G_ClientMove().

#define ACTOR_SPEED_NORMAL   100

Definition at line 37 of file g_move.cpp.

Referenced by G_ClientMove().

Function Documentation

void G_ActorFall ( Edict ent)

Let an actor fall down if e.g. the func_breakable the actor was standing on was destroyed.

Parameters
[in,out]entThe actor that should fall down
Todo:
Handle cases where the grid position the actor would fall to is occupied by another actor already.

Definition at line 118 of file g_move.cpp.

References Edict::calcOrigin(), ET_NULL, FALLING_DAMAGE_FACTOR, Edict::fieldSize, G_CheckVis(), G_EventActorFall(), G_EventEnd(), G_GetEdictFromPos(), G_IsBlockingMovementActor, G_IsBreakable, G_TakeDamage(), gi, and Edict::pos.

Referenced by Destroy_Breakable().

pos_t G_ActorMoveLength ( const Actor actor,
const pathing_t path,
const pos3_t  to,
bool  stored 
)

Return the needed TUs to walk to a given position.

Parameters
actorEdict to calculate move length for
pathPointer to pathing table
toPosition to walk to
storedUse the stored mask (the cached move) of the routing data
Returns
ROUTING_NOT_REACHABLE if the move isn't possible, length of move otherwise (TUs)

Definition at line 270 of file g_move.cpp.

References G_ActorGetInjuryPenalty(), G_IsAI, Edict::getPlayer(), gi, Actor::isCrouched(), length, level, MODIFIER_MOVEMENT, level_locals_s::pathingMap, PosSubDV, ROUTING_NOT_REACHABLE, ROUTING_UNREACHABLE, TU_CROUCH, and VectorCopy.

Referenced by AI_CheckForMissionTargets(), AI_CivilianCalcActionScore(), AI_FighterCalcActionScore(), AI_FindHerdLocation(), AI_FindHidingLocation(), AI_FindMissionLocation(), AI_PanicCalcActionScore(), AI_PrepBestAction(), AIL_findweapons(), AIL_positionapproach(), AIL_positionflee(), AIL_positionshoot(), AIL_positionwander(), G_ClientMove(), pos3L_distance(), and pos3L_goto().

static bool G_ActorShouldStopInMidMove ( const Edict ent,
int  visState,
dvec_t dvtab,
int  max 
)
static

Checks whether the actor should stop movement.

Parameters
entThe actors edict
visStateThe visibility check state VIS_PERISH, VIS_APPEAR
dvtabThe direction vectors
maxThe index of the next step in dvtab
Returns
true if the actor should stop movement, false otherwise

Definition at line 151 of file g_move.cpp.

References G_EdictsGetLivingActorFromPos(), G_IsBlockingMovementActor, G_IsVisibleForTeam, Edict::getTeam(), Edict::pos, PosAddDV, VectorCopy, VIS_APPEAR, and VIS_STOP.

Referenced by G_ClientMove().

static void G_BuildForbiddenList ( int  team,
const Edict movingActor 
)
static

Build the forbidden list for the pathfinding (server side).

Parameters
[in]teamThe team number if the list should be calculated from the eyes of that team. Use 0 to ignore team.
[in]movingActorThe moving actor to build the forbidden list for. If this is an AI actor, everything other actor will be included in the forbidden list - even the invisible ones. This is needed to ensure that they are not walking into each other (civilians <=> aliens, aliens <=> civilians)
See also
G_MoveCalc
Grid_CheckForbidden
CL_BuildForbiddenList <- shares quite some code
Note
This is used for pathfinding. It is a list of where the selected unit can not move to because others are standing there already.

Definition at line 59 of file g_move.cpp.

References forbiddenList_s::add(), ET_SOLID, Edict::fieldSize, Edict::forbiddenListPos, Edict::forbiddenListSize, G_EdictsGetNextInUse(), G_IsAI, G_IsBlockingMovementActor, G_TeamToVisMask, Edict::pos, forbiddenList_s::reset(), TEAM_ALL, Edict::type, and Edict::visflags.

Referenced by G_FindPath(), and G_MoveCalcLocal().

void G_ClientMove ( const Player &  player,
int  visTeam,
Actor actor,
const pos3_t  to 
)

Generates the client events that are send over the netchannel to move an actor.

Parameters
[in]playerPlayer who is moving an actor
[in]visTeamThe team to check the visibility for - if this is 0 we build the forbidden list above all edicts - for the human controlled actors this would mean that clicking to a grid position that is not reachable because an invisible actor is standing there would not result in a single step - as the movement is aborted before. For AI movement this is in general 0 - but not if they e.g. hide.
[in]actorEdict to move
[in]toThe grid position to walk to
See also
CL_ActorStartMove
PA_MOVE
Todo:
Handle dazed via trigger_hurt

Definition at line 307 of file g_move.cpp.

References ACTOR_SPEED_CROUCHED, ACTOR_SPEED_NORMAL, Edict::calcOrigin(), Edict::chr, Edict::clientAction, Edict::dir, f, Edict::fieldSize, G_ActionCheckForCurrentTeam(), G_ActorDoTurn(), G_ActorGetContentFlags(), G_ActorGetInjuryPenalty(), G_ActorMoveLength(), G_ActorSetTU(), G_ActorShouldStopInMidMove(), g_actorspeed, G_CheckDeathOrKnockout(), G_CheckVis(), G_CheckVisTeamAll(), G_ClientStateChange(), G_EventActorTurn(), G_EventEnd(), G_EventMoveCameraTo(), G_FillDirectionTable(), G_GetFloorItems(), G_IsAI, G_IsCivilian, G_MatchEndCheck(), G_MoveCalc(), G_ReactionFireNotifyClientEndMove(), G_ReactionFireNotifyClientStartMove(), G_ReactionFireOnMovement(), G_SendStats(), G_TeamToVisMask, G_TouchSolids(), G_TouchTriggers(), G_VisToPM(), G_WriteStep(), getDVdir, Edict::getStun(), Edict::getTeam(), gi, Edict::HP, Actor::isCrouched(), Actor::isDead(), length, lengthof, level, MAX_ROUTE, MODIFIER_MOVEMENT, chrScoreMission_s::movedCrouched, chrScoreMission_s::movedNormal, Edict::moveinfo, Edict::origin, level_locals_s::pathingMap, Edict::pos, PosAddDV, Edict::resetFloor(), ROUTING_NOT_REACHABLE, character_s::scoreMission, Edict::speed, Edict::state, STATE_CROUCHED, moveinfo_s::steps, Edict::TU, TU_CROUCH, TU_MOVE_STRAIGHT, TU_TURN, cvar_s::value, VectorCompare, VectorCopy, VIS_STOP, and Edict::visflags.

Referenced by AI_ActorThink(), AI_PrepBestAction(), G_ClientAction(), pos3L_goto(), and TEST_F().

int G_FillDirectionTable ( dvec_t dvtab,
size_t  dvtabSize,
byte  crouchingState,
pos3_t  pos 
)

Definition at line 244 of file g_move.cpp.

References gi, level, level_locals_s::pathingMap, PosSubDV, ROUTING_UNREACHABLE, and setDVz.

Referenced by G_ClientMove().

bool G_FindPath ( int  team,
const Edict movingActor,
const pos3_t  from,
const pos3_t  targetPos,
bool  crouched,
int  maxTUs 
)
void G_MoveCalc ( int  team,
const Actor movingActor,
const pos3_t  from,
int  distance 
)

Precalculates a move table for a given team and a given starting position. This will calculate a routing table for all reachable fields with the given distance from the given spot with the given actorsize.

Parameters
[in]teamThe current team (see G_BuildForbiddenList)
[in]fromPosition in the map to start the move-calculation from.
[in]distanceThe distance in TUs to calculate the move for.
[in]movingActorThe actor to calculate the move for

Definition at line 88 of file g_move.cpp.

References G_MoveCalcLocal(), level, and level_locals_s::pathingMap.

Referenced by AI_PrepBestAction(), AI_TurnIntoDirection(), AIL_positionflee(), AIL_positionmission(), AIL_positionshoot(), AIL_positionwander(), G_ClientMove(), and pos3L_goto().

void G_MoveCalcLocal ( pathing_t pt,
int  team,
const Edict movingActor,
const pos3_t  from,
int  distance 
)

Same as G_MoveCalc, except that it uses the pathing table passed as the first param.

Parameters
[in]ptthe pathfinding table
[in]teamThe current team (see G_BuildForbiddenList)
[in]fromPosition in the map to start the move-calculation from.
[in]distanceThe distance in TUs to calculate the move for.
[in]movingActorThe actor to calculate the move for

Definition at line 101 of file g_move.cpp.

References Edict::fieldSize, G_BuildForbiddenList(), and gi.

Referenced by AI_FindHerdLocation(), AI_FindHidingLocation(), and G_MoveCalc().

static void G_WriteStep ( Actor ent,
const int  dvec,
const int  contentFlags 
)
static

Writes a step of the move event to the net.

Parameters
[in]entActor (entity) to move
[in]dvecThe direction vector for the step to be added
[in]contentFlagsThe material we are walking over

Definition at line 216 of file g_move.cpp.

References Edict::contentFlags, EV_ACTOR_MOVE, G_EventAdd(), G_SendFootstepSound(), Edict::getIdNum(), gi, Actor::isCrouched(), MAX_ROUTE, Edict::moveinfo, PM_ALL, Edict::speed, and moveinfo_s::steps.

Referenced by G_ClientMove().

Variable Documentation

const float FALLING_DAMAGE_FACTOR = 10.0f
static

Definition at line 39 of file g_move.cpp.

Referenced by G_ActorFall().

forbiddenList_t forbiddenList
static

The forbidden list is a list of entity positions that are occupied by an entity. This list is checked everytime an actor wants to walk there.

Definition at line 45 of file g_move.cpp.