g_combat.c File Reference

All parts of the main game logic that are combat related. More...

#include "g_local.h"
Include dependency graph for g_combat.c:

Go to the source code of this file.

Defines

#define MAX_WALL_THICKNESS_FOR_SHOOTING_THROUGH   8
#define GRENADE_DT   0.1
#define GRENADE_STOPSPEED   60.0

Enumerations

enum  morale_modifiers { ML_WOUND, ML_DEATH }

Functions

static qboolean G_TeamPointVis (int team, const vec3_t point)
 Test if point is "visible" from team.
static void G_Morale (int type, const edict_t *victim, const edict_t *attacker, int param)
 Applies morale changes to actors around a wounded or killed actor.
static void G_UpdateShotMock (shot_mock_t *mock, const edict_t *shooter, const edict_t *struck, int damage)
 Function to calculate possible damages for mock pseudoaction.
static void G_UpdateCharacterBodycount (edict_t *attacker, const fireDef_t *fd, const edict_t *target)
 Update character stats for this mission after successful shoot.
static void G_UpdateHitScore (edict_t *attacker, const edict_t *target, const fireDef_t *fd, const int splashDamage)
 Increases the 'hit' score by one for all affected teams/skills by one (except splash damage, read below).
static void G_Damage (edict_t *target, const fireDef_t *fd, int damage, edict_t *attacker, shot_mock_t *mock)
 Deals damage of a give type and amount to a target.
static qboolean G_FireAffectedSurface (const cBspSurface_t *surface, const fireDef_t *fd)
 Checks surface vulnerability for firedefinition damagetype.
static void G_SplashDamage (edict_t *ent, const fireDef_t *fd, vec3_t impact, shot_mock_t *mock, const trace_t *tr)
 Deals splash damage to a target and its surroundings.
static void G_SpawnItemOnFloor (const pos3_t pos, const item_t *item)
 Spawn an item on the floor. A new ET_ITEM edict is created if needed.
static void G_ShootGrenade (const player_t *player, edict_t *ent, const fireDef_t *fd, const vec3_t from, const pos3_t at, int mask, const item_t *weapon, shot_mock_t *mock, int z_align)
 A parabola-type shoot (grenade, throw).
static void G_ShootSingle (edict_t *ent, const fireDef_t *fd, const vec3_t from, const pos3_t at, int mask, const item_t *weapon, shot_mock_t *mock, int z_align, int i, shoot_types_t shootType)
 Fires straight shots.
static void G_GetShotOrigin (const edict_t *shooter, const fireDef_t *fd, const vec3_t dir, vec3_t shotOrigin)
static qboolean G_PrepareShot (edict_t *ent, shoot_types_t shootType, fireDefIndex_t firemode, item_t **weapon, containerIndex_t *container, const fireDef_t **fd)
 Prepares weapon, firemode and container used for shoot.
qboolean G_ClientShoot (const player_t *player, edict_t *ent, const pos3_t at, shoot_types_t shootType, fireDefIndex_t firemode, shot_mock_t *mock, qboolean allowReaction, int z_align)
 Setup for shooting, either real or mock.

Detailed Description

All parts of the main game logic that are combat related.

Definition in file g_combat.c.


Define Documentation

#define GRENADE_DT   0.1

Definition at line 568 of file g_combat.c.

Referenced by G_ShootGrenade().

#define GRENADE_STOPSPEED   60.0

Definition at line 569 of file g_combat.c.

Referenced by G_ShootGrenade().

#define MAX_WALL_THICKNESS_FOR_SHOOTING_THROUGH   8

Definition at line 28 of file g_combat.c.

Referenced by G_ShootSingle().


Enumeration Type Documentation

Enumerator:
ML_WOUND 
ML_DEATH 

Definition at line 30 of file g_combat.c.


Function Documentation

qboolean G_ClientShoot ( const player_t player,
edict_t ent,
const pos3_t  at,
shoot_types_t  shootType,
fireDefIndex_t  firemode,
shot_mock_t mock,
qboolean  allowReaction,
int  z_align 
)

Setup for shooting, either real or mock.

Parameters:
[in] player The player this action belongs to (i.e. either the ai or the player)
[in] ent the edict that is doing the shot
[in] at Position to fire on.
[in] shootType What type of shot this is (left, right reaction-left etc...).
[in] firemode The firemode index of the ammo for the used weapon.
[in] mock pseudo shooting - only for calculating mock values - NULL for real shots
[in] allowReaction Set to qtrue to check whether this has forced any reaction fire, otherwise qfalse.
Returns:
qtrue if everything went ok (i.e. the shot(s) where fired ok), otherwise qfalse.
Parameters:
[in] z_align This value may change the target z height - often GROUND_DELTA is used to calculate the alignment. This can be used for splash damage weapons. It's often useful to target the ground close to the victim. That way you don't need a 100 percent chance to hit your target. Even if you don't hit it, the splash damage might reduce the health of your target.

Todo:
check for direct shot / splash damage shot?

Reset status.

See also:
G_UpdateHitScore for the check.

Reset status.

See also:
G_UpdateHitScore for the check.

If loaded ammo is less than needed ammo from firedef then reduce shot-number relative to the difference.

Todo:
This really needs an overhaul.And it might get dumped completely when Feature Request "[1814158] Extended shot-definitions in firedef" https://sourceforge.net/tracker/?func=detail&atid=805245&aid=1814158&group_id=157793 gets implemented.

< State info so we can check if an item was already removed.

Definition at line 1064 of file g_combat.c.

References _, item_s::a, fireDef_s::ammo, AngleToDir(), edict_s::chr, CORE_DIRECTIONS, objDef_s::deplete, edict_s::dir, inventoryInterface_s::EmptyContainer, edict_s::fieldSize, chrScoreMission_s::fired, chrScoreMission_s::firedHit, chrScoreMission_s::firedSplash, chrScoreMission_s::firedSplashHit, chrScoreMission_s::firedSplashTUs, chrScoreMission_s::firedTUs, objDef_s::fireTwoHanded, G_ActionCheckForCurrentTeam(), G_ActionCheckWithoutTeam(), G_ActorSetTU(), G_CheckVisTeamAll(), G_ClientPrintf(), G_EdictPosIsSameAs(), G_EventActorTurn(), G_EventInventoryAmmo(), G_EventInventoryDelete(), G_EventShootHidden(), G_EventStartShoot(), G_GetShotOrigin(), G_IsAIPlayer, G_IsDead, G_IsVisibleForTeam, G_MatchEndCheck(), G_PrepareShot(), G_ReactionFirePostShot(), G_ReactionFirePreShot(), G_SendStats(), G_ShootGrenade(), G_ShootSingle(), G_TeamPointVis(), G_TeamToVisMask, G_VisToPM(), game, gi, fireDef_s::gravity, character_s::i, game_locals_t::i, edict_s::inuse, INVDEF, fireDef_s::irgoggles, IS_SHOT_REACTION, KILLED_NUM_TYPES, LEFT, item_s::m, MAX_TEAMS, objDef_s::oneshot, edict_s::origin, edict_s::pos, PRINT_HUD, qfalse, qtrue, fireDef_s::range, player_s::reactionLeftover, game_import_t::routingMap, character_s::scoreMission, fireDef_s::shots, invDef_s::single, fireDef_s::splrad, item_s::t, edict_s::team, objDef_s::thrown, fireDef_s::time, todeg, edict_s::TU, VectorDist, VectorMA(), VectorSubtract, edict_s::visflags, and fireDef_s::weaponSkill.

Referenced by actorL_shoot(), AI_ActorThink(), G_ClientAction(), and G_ReactionFireShoot().

static void G_Damage ( edict_t target,
const fireDef_t fd,
int  damage,
edict_t attacker,
shot_mock_t mock 
) [static]

Deals damage of a give type and amount to a target.

Parameters:
[in,out] target What we want to damage.
[in] fd The fire definition that defines what type of damage is dealt.
[in] damage The value of the damage.
[in] attacker The attacker.
[in] mock pseudo shooting - only for calculating mock values - NULL for real shots
See also:
G_SplashDamage
G_TakeDamage
G_PrintActorStats

Todo:
there should be a possible protection, too
Todo:
Also increase the morale a little bit when soldier gets healing and morale is lower than max possible?

< Check for >0 and splrad to not count this as direct hit.

Definition at line 291 of file g_combat.c.

References _, ABILITY_POWER, edict_s::chr, CHRSH_IsTeamDefRobot(), Com_DPrintf(), CONTAINER, chrReservations_s::crouch, game_import_t::csi, csi_s::damShock, csi_s::damStunElectro, csi_s::damStunGas, DEBUG_GAME, edict_s::destroy, difficulty, objDef_s::dmgtype, fireDef_s::dmgweight, G_ActorCheckRevitalise(), G_ActorDieOrStun(), G_ActorReserveTUs(), G_ActorSetTU(), G_CheckVis(), G_CheckVisTeamAll(), G_ClientPrintf(), G_IsAlien, G_IsBrushModel, G_IsLivingActor(), G_IsStunned, G_Morale(), g_nodamage, G_PLAYER_FROM_ENT, G_PrintActorStats(), G_RemoveReaction, G_SendStats(), G_SetDazed, G_TakeDamage(), G_UpdateCharacterBodycount(), G_UpdateHitScore(), G_UpdateShotMock(), GET_HP, gi, chrScoreMission_s::heal, edict_s::HP, csi_s::idArmour, cvar_s::integer, MAX_TEAMS, character_s::maxHP, character_s::minHP, ML_DEATH, ML_WOUND, mor_panic, fireDef_s::obj, PRINT_HUD, objDef_s::protection, qfalse, qtrue, character_s::reservedTus, teamDef_s::resistance, character_s::score, character_s::scoreMission, chrReservations_s::shot, chrScoreGlobal_s::skills, fireDef_s::splrad, edict_s::STUN, sv_maxclients, edict_s::team, and character_s::teamDef.

Referenced by G_ShootSingle(), and G_SplashDamage().

static qboolean G_FireAffectedSurface ( const cBspSurface_t surface,
const fireDef_t fd 
) [inline, static]

Checks surface vulnerability for firedefinition damagetype.

Returns:
True if the surface has the fireaffected flag set and the firedef might produce fire (e.g. flamer)
Parameters:
[in] surface The collision surface to check the surface flag for
[in] fd The firedef to check the dmgtype for
Todo:
Such function should check notonly fire - it should be generic function to check surface vulnerability for given damagetype.

Definition at line 446 of file g_combat.c.

References game_import_t::csi, csi_s::damBlast, csi_s::damFire, objDef_s::dmgtype, gi, fireDef_s::obj, qfalse, qtrue, SURF_BURN, and cBspSurface_s::surfaceFlags.

Referenced by G_ShootSingle(), and G_SplashDamage().

static void G_GetShotOrigin ( const edict_t shooter,
const fireDef_t fd,
const vec3_t  dir,
vec3_t  shotOrigin 
) [static]

Definition at line 976 of file g_combat.c.

References edict_s::fieldSize, gi, edict_s::pos, game_import_t::routingMap, and fireDef_s::shotOrg.

Referenced by G_ClientShoot().

static void G_Morale ( int  type,
const edict_t victim,
const edict_t attacker,
int  param 
) [static]

Applies morale changes to actors around a wounded or killed actor.

Note:
only called when mor_panic is not zero
Parameters:
[in] type Type of morale modifier (
See also:
morale_modifiers)
Parameters:
[in] victim An actor being a victim of the attack.
[in] attacker An actor being attacker in this attack.
[in] param Used to modify morale changes, for G_Damage() it is value of damage.
See also:
G_Damage

Definition at line 75 of file g_combat.c.

References ABILITY_MIND, edict_s::chr, ET_ACTOR, G_ActorVis(), G_EdictsGetNextInUse(), G_FrustumVis(), G_IsCivilian, G_IsDead, G_SendStats(), GET_MORALE, gi, int(), cvar_s::integer, level, ML_DEATH, ML_WOUND, mob_death, mob_wound, mof_civilian, mof_enemy, mof_teamkill, mof_watching, mon_teamfactor, mor_attacker, mor_default, mor_distance, mor_pain, mor_victim, edict_s::morale, MORALE_RANDOM, level_locals_t::num_alive, level_locals_t::num_spawned, edict_s::origin, qfalse, character_s::score, chrScoreGlobal_s::skills, sv_maxclients, edict_s::team, TEAM_ALIEN, TEAM_CIVILIAN, edict_s::type, cvar_s::value, and VectorDist.

Referenced by G_Damage().

static qboolean G_PrepareShot ( edict_t ent,
shoot_types_t  shootType,
fireDefIndex_t  firemode,
item_t **  weapon,
containerIndex_t container,
const fireDef_t **  fd 
) [static]

Prepares weapon, firemode and container used for shoot.

Parameters:
[in] ent Pointer to attacker.
[in] shootType Type of shot.
[in] firemode An index of used firemode.
[in,out] weapon Weapon being used. It is NULL when calling this function.
[in,out] container Container with weapon being used. It is 0 when calling this function.
[in,out] fd Firemode being used. It is NULL when calling this function.
Returns:
qtrue if function is able to check and set everything correctly.
See also:
G_ClientShoot

Definition at line 1005 of file g_combat.c.

References game_import_t::csi, FIRESH_FiredefForWeapon(), gi, HEADGEAR, csi_s::idHeadgear, csi_s::idLeft, csi_s::idRight, IS_SHOT_HEADGEAR, IS_SHOT_RIGHT, LEFT, item_s::m, qfalse, qtrue, RIGHT, ST_NUM_SHOOT_TYPES, and item_s::t.

Referenced by G_ClientShoot().

static void G_ShootGrenade ( const player_t player,
edict_t ent,
const fireDef_t fd,
const vec3_t  from,
const pos3_t  at,
int  mask,
const item_t weapon,
shot_mock_t mock,
int  z_align 
) [static]

A parabola-type shoot (grenade, throw).

See also:
G_ShootSingle
Com_GrenadeTarget
Parameters:
[in] player The shooting player
[in] ent The shooting actor
[in] fd The firedefinition the actor is shooting with
[in] from The position the actor is shooting from
[in] at The grid position the actor is shooting to (or trying to shoot to)
[in] mask The team visibility mask (who's seeing the event)
[in] weapon The weapon to shoot with
[in] mock pseudo shooting - only for calculating mock values - NULL for real shots
[in] z_align This value may change the target z height

Todo:
Remove the 2.0f and use gaussian random number instead of crand()

Definition at line 584 of file g_combat.c.

References _, ABILITY_ACCURACY, level_locals_t::activeTeam, fireDef_s::ammo, AngleVectors(), fireDef_s::bounce, fireDef_s::bounceFac, byte, edict_s::chr, crand(), fireDef_s::delay, DotProduct, trace_s::endpos, trace_s::ent, edict_s::fieldSize, trace_s::fraction, G_ClientPrintf(), G_EventThrow(), G_IsActor, G_IsDead, G_SpawnItemOnFloor(), G_SplashDamage(), G_TeamPointVis(), G_Trace(), GET_ACC, gi, GRAVITY, GRENADE_DT, GRENADE_STOPSPEED, GROUND_DELTA, i, fireDef_s::launched, level, MASK_SHOT, MAX_TEAMS, cBspSurface_s::name, oldPos, player_s::pers, PITCH, trace_s::plane, PRINT_HUD, fireDef_s::range, fireDef_s::rolled, game_import_t::routingMap, character_s::score, SF_BODY, SF_BOUNCED, SF_BOUNCING, SF_IMPACT, SKILL_BALANCE, chrScoreGlobal_s::skills, fireDef_s::splrad, fireDef_s::spread, trace_s::surface, item_s::t, client_persistant_t::team, objDef_s::thrown, VecToAngles(), VecToPos, VectorAdd, VectorCopy, VectorLength(), VectorMA(), VectorScale, WEAPON_BALANCE, fireDef_s::weaponSkill, and YAW.

Referenced by G_ClientShoot().

static void G_ShootSingle ( edict_t ent,
const fireDef_t fd,
const vec3_t  from,
const pos3_t  at,
int  mask,
const item_t weapon,
shot_mock_t mock,
int  z_align,
int  i,
shoot_types_t  shootType 
) [static]

Fires straight shots.

Parameters:
[in] ent The attacker.
[in] fd The fire definition that is used for the shot.
[in] from Location of the gun muzzle.
[in] at Grid coordinate of the target.
[in] mask Visibility bit-mask (who's seeing the event)
[in] weapon The weapon the actor is shooting with
[in] mock pseudo shooting - only for calculating mock values - NULL for real shots
[in] z_align This value may change the target z height
[in] i The ith shot
[in] shootType The firemode (ST_NUM_SHOOT_TYPES)
See also:
CL_TargetingStraight

Todo:
The random dir-modifier?
Todo:
need some change to reflect 2x2 units. Also might need a check if the distance is bigger than the one to the impact location.
Todo:
can't we use the fd->shotOrg here and get rid of the sv_shot_origin cvar?
Todo:
reduce even more if the wall was hit far away and not close by the shooting actor

Definition at line 776 of file g_combat.c.

References ABILITY_ACCURACY, ABILITY_MIND, fireDef_s::ammo, AngleVectors(), fireDef_s::bounce, byte, edict_s::chr, Com_DPrintf(), trace_s::contentFlags, CONTENTS_SOLID, crand(), fireDef_s::crouch, fireDef_s::damage, DEBUG_GAME, fireDef_s::delay, objDef_s::deplete, DotProduct, trace_s::endpos, trace_s::ent, edict_s::fieldSize, FIRESH_IsMedikit, trace_s::fraction, G_Damage(), G_EdictPosIsSameAs(), G_EventShoot(), G_EventShootHidden(), G_FireAffectedSurface(), G_IsActor, G_IsBreakable, G_IsCivilian, G_IsCrouched, G_IsDead, G_SpawnItemOnFloor(), G_SpawnParticle(), G_SplashDamage(), G_TeamToVisMask, G_Trace(), G_UpdateHitScore(), gaussrand(), GET_ACC, GET_INJURY_MULT, gi, edict_s::HP, MASK_SHOT, MAX_WALL_THICKNESS_FOR_SHOOTING_THROUGH, character_s::maxHP, PITCH, trace_s::plane, qfalse, fireDef_s::range, game_import_t::routingMap, character_s::score, SF_BODY, SF_BOUNCED, SF_BOUNCING, SF_IMPACT, SKILL_BALANCE, chrScoreGlobal_s::skills, fireDef_s::splrad, fireDef_s::spread, trace_s::startsolid, trace_s::surface, sv_shot_origin, item_s::t, edict_s::team, fireDef_s::throughWall, objDef_s::thrown, UNIT_SIZE, cvar_s::value, VecToAngles(), VecToPos, VectorAdd, VectorCopy, VectorMA(), VectorNormalize(), VectorScale, VectorSubtract, WEAPON_BALANCE, fireDef_s::weaponSkill, and YAW.

Referenced by G_ClientShoot().

static void G_SpawnItemOnFloor ( const pos3_t  pos,
const item_t item 
) [static]

Spawn an item on the floor. A new ET_ITEM edict is created if needed.

Parameters:
[in] pos The grid position to spawn the item at
[in] item The item to spawn

Definition at line 539 of file g_combat.c.

References edict_s::chr, game_import_t::csi, G_CheckVis(), G_EventPerish(), G_FreeEdict(), G_GetActorFromPos(), G_GetFloorItems(), G_GetFloorItemsFromPos(), G_SpawnFloor(), game, gi, character_s::i, game_locals_t::i, csi_s::idFloor, INVDEF, qtrue, inventoryInterface_s::TryAddToInventory, and edict_s::visflags.

Referenced by G_ShootGrenade(), and G_ShootSingle().

static void G_SplashDamage ( edict_t ent,
const fireDef_t fd,
vec3_t  impact,
shot_mock_t mock,
const trace_t tr 
) [static]

Deals splash damage to a target and its surroundings.

Parameters:
[in] ent The shooting actor
[in] fd The fire definition that defines what type of damage is dealt and how big the splash radius is.
[in] impact The impact vector where the grenade is exploding
[in,out] mock pseudo shooting - only for calculating mock values - NULL for real shots
[in] tr The trace where the grenade hits something (or not)

Todo:
splash might also hit other surfaces and the trace doesn't handle that

Definition at line 468 of file g_combat.c.

References edict_s::absmax, edict_s::absmin, shot_mock_t::allow_self, check, trace_s::contentFlags, game_import_t::csi, csi_s::damShock, objDef_s::dmgtype, G_ActorVis(), G_AppearPerishEvent(), G_Damage(), G_EdictsGetNextInUse(), G_FireAffectedSurface(), G_FrustumVis(), G_IsActor, G_IsBreakable, G_IsBrushModel, G_IsLivingActor(), G_SpawnParticle(), G_VisToPM(), gi, fireDef_s::irgoggles, fireDef_s::obj, edict_s::origin, trace_s::plane, qfalse, qtrue, fireDef_s::spldmg, fireDef_s::splrad, trace_s::surface, UNIT_SIZE, VectorCenterFromMinsMaxs(), VectorCopy, VectorDist, VectorMA(), and edict_s::visflags.

Referenced by G_ShootGrenade(), and G_ShootSingle().

static qboolean G_TeamPointVis ( int  team,
const vec3_t  point 
) [static]

Test if point is "visible" from team.

Parameters:
[in] team A team to test.
[in] point A point to check.
Returns:
qtrue if point is "visible"

Definition at line 41 of file g_combat.c.

References EYE_CROUCH, EYE_STAND, G_EdictsGetNextLivingActorOfTeam(), G_FrustumVis(), G_IsCrouched, G_TestLine(), edict_s::origin, qfalse, qtrue, and VectorCopy.

Referenced by G_ClientShoot(), and G_ShootGrenade().

static void G_UpdateCharacterBodycount ( edict_t attacker,
const fireDef_t fd,
const edict_t target 
) [static]

Update character stats for this mission after successful shoot.

Note:
Mind you that this code is always from the view of PHALANX soldiers right now, not anybody else!
Parameters:
[in,out] attacker Pointer to attacker.
[in] fd Pointer to fireDef_t used in shoot.
[in] target Pointer to target.
See also:
G_UpdateCharacterSkills

Definition at line 180 of file g_combat.c.

References edict_s::chr, edict_s::HP, KILLED_CIVILIANS, KILLED_ENEMIES, KILLED_TEAM, chrScoreGlobal_s::kills, chrScoreMission_s::kills, lengthof, character_s::score, character_s::scoreMission, scoreMission, chrScoreMission_s::skillKills, chrScoreGlobal_s::stuns, chrScoreMission_s::stuns, edict_s::team, TEAM_ALIEN, TEAM_CIVILIAN, TEAM_PHALANX, type, and fireDef_s::weaponSkill.

Referenced by G_Damage().

static void G_UpdateHitScore ( edict_t attacker,
const edict_t target,
const fireDef_t fd,
const int  splashDamage 
) [static]

Increases the 'hit' score by one for all affected teams/skills by one (except splash damage, read below).

Parameters:
[in,out] attacker The soldier to update (he/she dealt the damage)
[in] target The hit target.
[in] fd the used fire definition.
[in] splashDamage Do we count it as splashdamage? If this value is not zero the stats well be counted as splashdamage and the value will be added to the overall splash-damage count.

Definition at line 227 of file g_combat.c.

References edict_s::chr, chrScoreMission_s::firedHit, chrScoreMission_s::firedSplashHit, chrScoreMission_s::hits, chrScoreMission_s::hitsSplash, chrScoreMission_s::hitsSplashDamage, KILLED_CIVILIANS, KILLED_ENEMIES, KILLED_TEAM, qtrue, character_s::scoreMission, edict_s::team, TEAM_ALIEN, TEAM_CIVILIAN, type, and fireDef_s::weaponSkill.

Referenced by G_Damage(), and G_ShootSingle().

static void G_UpdateShotMock ( shot_mock_t mock,
const edict_t shooter,
const edict_t struck,
int  damage 
) [static]

Function to calculate possible damages for mock pseudoaction.

Parameters:
[in,out] mock Pseudo action - only for calculating mock values - NULL for real action.
[in] shooter Pointer to attacker for this mock pseudoaction.
[in] struck Pointer to victim of this mock pseudoaction.
[in] damage Updates mock value of damage.
Note:
Called only from G_Damage().
See also:
G_Damage

Definition at line 150 of file g_combat.c.

References shot_mock_t::allow_self, shot_mock_t::civilian, shot_mock_t::damage, shot_mock_t::enemyCount, shot_mock_t::friendCount, G_IsActor, G_IsCivilian, G_IsDead, G_IsVisibleForTeam, edict_s::inuse, edict_s::number, and edict_s::team.

Referenced by G_Damage().


Generated by  doxygen 1.6.2