UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
g_actor.h File Reference
#include "g_local.h"

Go to the source code of this file.

Macros

#define G_IsState(ent, s)   ((ent)->state & (s))
 
#define G_IsStunned(ent)   (G_IsState(ent, STATE_STUN) & ~STATE_DEAD)
 
#define G_IsPanicked(ent)   G_IsState(ent, STATE_PANIC)
 
#define G_IsCrouched(ent)   G_IsState(ent, STATE_CROUCHED)
 
#define G_IsDead(ent)   G_IsState(ent, STATE_DEAD)
 
#define G_SetState(ent, s)   (ent)->state |= (s)
 
#define G_SetStunned(ent)   G_SetState((ent), STATE_STUN)
 
#define G_SetDead(ent)   G_SetState((ent), STATE_DEAD)
 
#define G_SetCrouched(ent)   G_SetState((ent), STATE_CROUCHED)
 
#define G_ToggleState(ent, s)   (ent)->state ^= (s)
 
#define G_ToggleCrouched(ent)   G_ToggleState(ent, STATE_CROUCHED)
 

Functions

bool G_IsLivingActor (const Edict *ent) __attribute__((nonnull))
 Checks whether the given edict is a living actor. More...
 
void G_ActorUseDoor (Actor *actor, Edict *door)
 Make the actor use (as in open/close) a door edict. More...
 
void G_ActorSetClientAction (Edict *actor, Edict *ent)
 Handles the client actions (interaction with the world) More...
 
int G_ActorUsableTUs (const Edict *ent)
 Calculates the amount of usable TUs. This is without the reserved TUs. More...
 
int G_ActorGetTUForReactionFire (const Edict *ent)
 Calculates the amount of TUs that are needed for the current selected reaction fire mode. More...
 
void G_ActorReserveTUs (Edict *ent, int resReaction, int resShot, int resCrouch)
 Reserves TUs for different actor actions. More...
 
int G_ActorDoTurn (Edict *ent, byte dir)
 Turns an actor around. More...
 
void G_ActorSetMaxs (Actor *actor)
 Sets correct bounding box for actor (state dependent). More...
 
int G_ActorCalculateMaxTU (const Edict *ent)
 
void G_ActorGiveTimeUnits (Actor *actor)
 Set time units for the given edict. Based on speed skills. More...
 
void G_ActorSetTU (Edict *ent, int tus)
 
void G_ActorUseTU (Edict *ent, int tus)
 
void G_ActorModifyCounters (const Edict *attacker, const Edict *victim, int deltaAlive, int deltaKills, int deltaStuns)
 
void G_ActorGetEyeVector (const Edict *actor, vec3_t eye)
 Fills a vector with the eye position of a given actor. More...
 
void G_ActorCheckRevitalise (Actor *actor)
 
bool G_ActorDieOrStun (Actor *actor, Edict *attacker)
 Reports and handles death or stun of an actor. If the HP of an actor is zero the actor will die, otherwise the actor will get stunned. More...
 
int G_ActorGetContentFlags (const vec3_t origin)
 Get the content flags from where the actor is currently standing. More...
 
bool G_ActorInvMove (Actor *actor, const invDef_t *from, Item *fItem, const invDef_t *to, int tx, int ty, bool checkaction)
 Moves an item inside an inventory. Floors are handled special. More...
 
bool G_ActorReload (Actor *actor, const invDef_t *invDef)
 Reload weapon with actor. More...
 
int G_ActorGetModifiedTimeForFiredef (const Edict *ent, const fireDef_t *const fd, bool reaction)
 

Macro Definition Documentation

#define G_IsCrouched (   ent)    G_IsState(ent, STATE_CROUCHED)
#define G_IsDead (   ent)    G_IsState(ent, STATE_DEAD)
#define G_IsPanicked (   ent)    G_IsState(ent, STATE_PANIC)

Definition at line 31 of file g_actor.h.

Referenced by G_ActorGetEyeVector().

#define G_IsState (   ent,
 
)    ((ent)->state & (s))

Definition at line 29 of file g_actor.h.

Referenced by Edict::isOpponent().

#define G_IsStunned (   ent)    (G_IsState(ent, STATE_STUN) & ~STATE_DEAD)

Definition at line 30 of file g_actor.h.

Referenced by G_ActionCheck(), and G_IsLivingActor().

#define G_SetCrouched (   ent)    G_SetState((ent), STATE_CROUCHED)

Definition at line 39 of file g_actor.h.

#define G_SetDead (   ent)    G_SetState((ent), STATE_DEAD)

Definition at line 38 of file g_actor.h.

#define G_SetState (   ent,
 
)    (ent)->state |= (s)

Definition at line 36 of file g_actor.h.

Referenced by G_ActorDie(), and G_ClientStateChange().

#define G_SetStunned (   ent)    G_SetState((ent), STATE_STUN)

Definition at line 37 of file g_actor.h.

#define G_ToggleCrouched (   ent)    G_ToggleState(ent, STATE_CROUCHED)

Definition at line 42 of file g_actor.h.

Referenced by G_ClientStateChange().

#define G_ToggleState (   ent,
 
)    (ent)->state ^= (s)

Definition at line 41 of file g_actor.h.

Function Documentation

bool G_ActorDieOrStun ( Actor actor,
Edict attacker 
)

Reports and handles death or stun of an actor. If the HP of an actor is zero the actor will die, otherwise the actor will get stunned.

Parameters
[in]actorPointer to an entity being killed or stunned actor.
[in]attackerPointer to attacker - it must be notified about state of victim.
Todo:
Discuss whether stunned actor should really drop everything to floor. Maybe it should drop only what he has in hands? Stunned actor can wake later during mission.

Definition at line 435 of file g_actor.cpp.

References G_ActorDie(), G_ActorStun(), G_CheckVis(), G_CheckVisTeamAll(), G_ClientStateChange(), G_EventActorDie(), G_EventActorStateChange(), G_InventoryToFloor(), G_ReactionFireOnDead(), G_ReactionFireTargetsDestroy(), G_VisToPM(), Edict::getPlayer(), Edict::getTeam(), gi, Edict::HP, Actor::isStunned(), Edict::resetFloor(), Edict::solid, SOLID_NOT, STATE_REACTION, and Edict::visflags.

Referenced by G_CheckDeathOrKnockout(), G_MatchSendResults(), G_ThinkActorDieAfterSpawn(), and TEST_F().

int G_ActorDoTurn ( Edict ent,
byte  dir 
)

Turns an actor around.

Parameters
[in]entthe actor (edict) we are talking about
[in]dirthe direction to turn the edict into, might be an action
Returns
Bitmask of visible (VIS_*) values
See also
G_CheckVisTeamAll
Todo:
If performing an action, ensure the actor is facing the direction needed to perform the action if needed (climbing ladders).

Definition at line 154 of file g_actor.cpp.

References CORE_DIRECTIONS, Edict::dir, directionAngles, dvleft, dvright, FLYING_DIRECTIONS, G_CheckVisTeamAll(), G_EventActorTurn(), Edict::getTeam(), i, PATHFINDING_DIRECTIONS, and VIS_STOP.

Referenced by AI_TurnIntoDirection(), G_ClientMove(), and G_ClientTurn().

int G_ActorGetContentFlags ( const vec3_t  origin)

Get the content flags from where the actor is currently standing.

Definition at line 484 of file g_actor.cpp.

References gi, PLAYER_MIN, and VectorCopy.

Referenced by G_ClientMove(), and G_ClientTeamInfo().

void G_ActorGetEyeVector ( const Edict actor,
vec3_t  eye 
)

Fills a vector with the eye position of a given actor.

Parameters
[in]actorThe actor edict to get the eye position in the world from
[out]eyeThe eye vector world position

Definition at line 357 of file g_actor.cpp.

References EYE_CROUCH, EYE_STAND, G_IsCrouched, G_IsPanicked, Edict::origin, and VectorCopy.

Referenced by G_ActorVis(), G_SplashDamage(), G_TeamPointVis(), and G_Vis().

int G_ActorGetModifiedTimeForFiredef ( const Edict ent,
const fireDef_t *const  fd,
bool  reaction 
)
int G_ActorGetTUForReactionFire ( const Edict ent)

Calculates the amount of TUs that are needed for the current selected reaction fire mode.

Note
It's assumed that there is a sane fire mode selected for reaction fire
Parameters
[in]entThe actors edict
Returns
The amount of TUs that are needed for the current selected reaction fire mode.

Definition at line 116 of file g_actor.cpp.

References Edict::chr, Item::def(), G_ActorGetModifiedTimeForFiredef(), Item::getFiredefs(), FiremodeSettings::getFmIdx(), FiremodeSettings::getHand(), Edict::getHandItem(), and character_s::RFmode.

Referenced by G_ActorHasEnoughTUsReactionFire(), and G_ReactionFireSettingsReserveTUs().

void G_ActorGiveTimeUnits ( Actor actor)

Set time units for the given edict. Based on speed skills.

Parameters
actorThe actor edict

Definition at line 260 of file g_actor.cpp.

References G_ActorCalculateMaxTU(), G_ActorSetTU(), Actor::isDazed(), and Actor::removeDazed().

Referenced by AI_SetStats(), G_ClientTeamInfo(), and G_GiveTimeUnits().

bool G_ActorInvMove ( Actor actor,
const invDef_t fromContType,
Item fItem,
const invDef_t toContType,
int  tx,
int  ty,
bool  checkaction 
)

Moves an item inside an inventory. Floors are handled special.

Parameters
[in]actorThe pointer to the selected/used edict/soldier.
[in]fromContTypeThe container (-id) the item should be moved from.
[in]fItemThe item you want to move.
[in]toContTypeThe container (-def) the item should be moved to.
[in]txx position where you want the item to go in the destination container
[in]tyy position where you want the item to go in the destination container
[in]checkactionSet this to true if you want to check for TUs, otherwise false.
See also
event PA_INVMOVE
AI_ActorThink
Todo:
what if we don't have enough TUs after subtracting the reserved ones?

Definition at line 506 of file g_actor.cpp.

References _, ABILITY_POWER, Item::ammoDef(), Inventory::canHoldItemWeight(), Edict::chr, Item::def(), Inventory::findInContainer(), Inventory::findSpace(), G_ActionCheckForCurrentTeam(), G_ActorSetTU(), G_ActorUseTU(), G_CheckVis(), G_ClientPrintf(), G_EventEnd(), G_EventInventoryAdd(), G_EventInventoryDelete(), G_EventInventoryReload(), G_EventPerish(), G_FreeEdict(), G_GetFloorItems(), G_ReactionFireSettingsUpdate(), G_SendStats(), G_SpawnFloor(), G_TeamToPM(), G_VisToPM(), G_WriteItem(), game, Item::getAmount(), Item::getFirstShapePosition(), Edict::getFloor(), FiremodeSettings::getFmIdx(), FiremodeSettings::getHand(), Inventory::getItemAtPos(), Edict::getPlayer(), Edict::getReservedTUs(), Edict::getTeam(), Edict::getTus(), FiremodeSettings::getWeapon(), Item::getX(), Item::getY(), gi, IA_NONE, IA_NORELOAD, IA_NOTIME, IA_RELOAD, IA_RELOAD_SWAP, invDef_s::id, character_s::inv, game_locals_s::invi, invDef_s::isFloorDef(), invDef_s::isLeftDef(), invDef_s::isRightDef(), InventoryInterface::moveInInventory(), NONE, NONE_AMMO, Edict::pos, PRINT_HUD, character_s::RFmode, character_s::score, Edict::setFloor(), chrScoreGlobal_s::skills, Edict::TU, and Edict::visflags.

Referenced by actorL_throwgrenade(), AI_PrepBestAction(), AI_TryToReloadWeapon(), G_ActorReload(), G_ClientAction(), G_ClientGetWeaponFromInventory(), G_MissionTouch(), G_MoralePanic(), and TEST_F().

void G_ActorModifyCounters ( const Edict attacker,
const Edict victim,
int  deltaAlive,
int  deltaKills,
int  deltaStuns 
)
bool G_ActorReload ( Actor actor,
const invDef_t invDef 
)

Reload weapon with actor.

Parameters
[in]actorPointer to an actor reloading weapon.
[in]invDefReloading weapon in right or left hand.
See also
AI_ActorThink

Definition at line 714 of file g_actor.cpp.

References Edict::chr, CID_RIGHT, Item::def(), Container::def(), G_ActorInvMove(), Edict::getContainer(), Inventory::getNextCont(), Container::getNextItem(), Edict::getRightHandItem(), invDef_s::id, Container::id, character_s::inv, INVDEF, Item::isHeldTwoHanded(), invDef_s::isLeftDef(), objDef_s::isLoadableInWeapon(), and invDef_s::out.

Referenced by AI_TryToReloadWeapon().

void G_ActorReserveTUs ( Edict ent,
int  resReaction,
int  resShot,
int  resCrouch 
)

Reserves TUs for different actor actions.

Parameters
[in,out]entThe actor to reserve TUs for. Might not be nullptr.
[in]resReactionTUs for reaction fire
[in]resShotTUs for shooting
[in]resCrouchTUs for going into crouch mode

Definition at line 136 of file g_actor.cpp.

References Edict::chr, chrReservations_s::crouch, G_EventActorSendReservations(), Edict::getTus(), chrReservations_s::reaction, character_s::reservedTus, and chrReservations_s::shot.

Referenced by G_ClientAction(), G_ClientStateChange(), G_Damage(), and G_ReactionFireSettingsReserveTUs().

void G_ActorSetClientAction ( Edict actor,
Edict ent 
)

Handles the client actions (interaction with the world)

Parameters
actorThe actors' edict
entThe edict that can be used by the actor

Definition at line 82 of file g_actor.cpp.

References Edict::clientAction, FL_CLIENTACTION, Edict::flags, G_EventResetClientAction(), and G_EventSetClientAction().

Referenced by Reset_DoorTrigger(), Reset_TouchTrigger(), Touch_DoorTrigger(), and Touch_TouchTrigger().

void G_ActorSetMaxs ( Actor actor)

Sets correct bounding box for actor (state dependent).

Parameters
[in]actorPointer to entity for which bounding box is being set.
Note
Also re-links the actor edict - because the server must know about the changed bounding box for tracing to work.

Definition at line 226 of file g_actor.cpp.

References Edict::chr, CHRSH_IsTeamDefRobot(), Edict::entBox, ET_ACTOR, ET_ACTOR2x2, Edict::getIdNum(), gi, Actor::isCrouched(), Actor::isDead(), PLAYER2x2_WIDTH, PLAYER_CROUCH, PLAYER_DEAD, PLAYER_STAND, PLAYER_WIDTH, AABB::setMaxs(), AABB::setMaxZ(), character_s::teamDef, and Edict::type.

Referenced by G_ActorDie(), G_ActorRevitalise(), G_ActorStun(), G_ClientStateChange(), G_MoraleBehaviour(), and G_MoralePanic().

int G_ActorUsableTUs ( const Edict ent)

Calculates the amount of usable TUs. This is without the reserved TUs.

Parameters
[in]entThe actor to calculate the amount of usable TUs for. If ent is nullptr, we return zero here
Returns
The amount of usable TUs for the given actor edict

Definition at line 102 of file g_actor.cpp.

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

Referenced by G_ActionCheckForCurrentTeam().

void G_ActorUseDoor ( Actor actor,
Edict door 
)

Make the actor use (as in open/close) a door edict.

Note
Will also check whether the door is still reachable (this might have changed due to the rotation) after the usage
Parameters
actorThe actor that is using the door
doorThe door that should be opened/closed

Definition at line 55 of file g_actor.cpp.

References FL_GROUPSLAVE, Edict::flags, G_ClientUseEdict(), G_FindRadius(), G_IsAI, G_TouchTriggers(), Edict::getPlayer(), Edict::groupMaster, Edict::origin, and UNIT_SIZE.

Referenced by G_ClientAction(), and Touch_DoorTrigger().

void G_ActorUseTU ( Edict ent,
int  tus 
)

Definition at line 278 of file g_actor.cpp.

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

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

bool G_IsLivingActor ( const Edict ent)

Checks whether the given edict is a living actor.

Parameters
[in]entThe edict to perform the check for
See also
LE_IsLivingActor

Definition at line 43 of file g_actor.cpp.

References G_IsActor, G_IsDead, and G_IsStunned.

Referenced by Door_Use(), G_Damage(), G_EdictsGetNextLivingActor(), G_GetClosePlayerMask(), G_IsActorWounded(), G_MissionTouch(), G_ReactionFireCanBeEnabled(), G_SplashDamage(), G_TouchSolids(), G_TouchTriggers(), G_Vis(), G_VisShouldStop(), and Touch_HurtTrigger().