All parts of the main game logic that are combat related. More...
#include "g_local.h"
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. |
All parts of the main game logic that are combat related.
Definition in file g_combat.c.
#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().
enum morale_modifiers |
Definition at line 30 of file g_combat.c.
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.
[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. |
[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. |
Reset status.
Reset status.
If loaded ammo is less than needed ammo from firedef then reduce shot-number relative to the difference.
< 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.
[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 |
< 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.
[in] | surface | The collision surface to check the surface flag for |
[in] | fd | The firedef to check the dmgtype for |
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.
[in] | type | Type of morale modifier ( |
[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. |
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.
[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. |
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).
[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 |
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.
[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) |
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().
Spawn an item on the floor. A new ET_ITEM edict is created if needed.
[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.
[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) |
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().
Test if point is "visible" from team.
[in] | team | A team to test. |
[in] | point | A point to check. |
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.
[in,out] | attacker | Pointer to attacker. |
[in] | fd | Pointer to fireDef_t used in shoot. |
[in] | target | Pointer to target. |
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).
[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.
[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. |
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().