38 #define MAX_WALL_THICKNESS_FOR_SHOOTING_THROUGH 8
55 Actor* from =
nullptr;
100 Actor* actor =
nullptr;
118 if (attacker !=
nullptr && actor->
isSameTeamAs(attacker)) {
132 if (attacker !=
nullptr) {
153 else if (newMorale < 0)
177 Actor* check =
nullptr;
181 if (check == shooter)
194 if (dot / (len1 * len2) < 0.7
f)
198 <= minDist * minDist)
259 if (!attacker || !target)
291 }
else if (target->
isDead()) {
306 if (!attacker || !target || !fd)
367 const short armourProtection = armourDef->
protection[dmgWeight];
368 const short totalProtection = armourProtection + naturalProtection;
369 damage = std::min(std::max(0, damage - armourProtection), std::max(1, damage - totalProtection));
371 damage = std::max(1, damage - naturalProtection);
401 if (stunEl || stunGas || shock || mock || smoke)
404 if (damage >= target->
HP) {
434 }
else if (damage < 0) {
458 }
else if (stunGas) {
486 if (!mock && damage > 0 && fd->
splrad)
502 target->
HP = std::min(std::max(target->
HP, 0), target->
chr.
maxHP);
504 if (target->
HP == 0 || target->
HP <= target->
getStun()) {
560 assert(fd->
splrad > 0.0f);
564 Edict* check =
nullptr;
609 const int damage = shock ? 0 : fd->
spldmg[0] * (1.0f - dist / fd->
splrad);
614 if (
G_Damage(check, fd, damage, ent, mock,
nullptr) && isActor
641 if (floor ==
nullptr) {
652 if (actor !=
nullptr)
681 effSpread[
YAW] = fd->
spread[1] * commonfactor;
690 #define GRENADE_DT 0.1f
691 #define GRENADE_STOPSPEED 60.0f
720 target[2] -= z_align;
749 angles[
PITCH] += gauss1 * effSpread[0];
750 angles[
YAW] += gauss2 * effSpread[1];
780 VectorMA(oldPos, GRENADE_DT, curV, newPos);
786 if (tr.
fraction < 1.0f || time + dt > 4.0f) {
811 byte impactFlags = flags;
878 (
int)start[0], (
int)start[1], (
int)start[2],
886 trEnt ?
"yes" :
"no",
888 trEnt ? trEnt->
HP : 0);
894 static void DumpAllEntities (
void)
897 Edict* check =
nullptr;
905 check->
inuse ?
"in use" :
"unused",
942 impact[2] -= z_align;
963 angles[
PITCH] += gauss1 * effSpread[0];
964 angles[
YAW] += gauss2 * effSpread[1];
972 float range = fd->
range;
985 const Edict* passEnt = ent;
1001 VectorMA(cur_loc, range, dir, impact);
1010 DumpTrace(tracefrom, tr);
1026 else if (bounce < fd->bounce)
1038 const bool firstShot = (i == 0);
1039 G_EventShoot(*ent, mask, fd, firstShot, shootType, flags, &tr, tracefrom, impact);
1060 damage /= sqrt(fd->
throughWall - throughWall + 1.0f);
1096 G_Damage(trEnt, fd, damage, ent, mock, impact);
1135 gi.Error(
"G_GetShotFromType: unknown shoot type %i.\n", shootType);
1157 if (fdArray ==
nullptr)
1162 assert(firemode >= 0);
1163 *fd = &fdArray[firemode];
1188 const bool quiet = (mock !=
nullptr) ||
G_IsAIPlayer(&player);
1190 Item* weapon =
nullptr;
1193 if (!
G_PrepareShot(actor, shootType, firemode, &weapon, &container, &fd)) {
1194 if (!weapon && !quiet)
1203 if (allowReaction) {
1214 const Actor* targetEnt =
nullptr;
1274 int shots = fd->
shots;
1284 if (ammo < fd->ammo) {
1298 const int prevDir = mock ? actor->
dir : 0;
1313 target[2] -= z_align;
1324 if (allowReaction) {
1331 if (targetEnt !=
nullptr && (targetEnt->
isDead() && !targetEnt->
isStunned()))
1341 bool itemAlreadyRemoved =
false;
1344 if (ammo > 0 || !weapon->
def()->
thrown) {
1350 itemAlreadyRemoved =
true;
1360 if (itemAlreadyRemoved)
1361 gi.Error(
"Item %s is already removed", weapon->
def()->
id);
1376 for (
int i = 0; i < shots; ++
i) {
1378 G_ShootGrenade(player, actor, fd, shotOrigin, at, mask, weapon, mock, z_align, impact);
1380 G_ShootSingle(actor, fd, shotOrigin, at, mask, weapon, mock, z_align, i, shootType, impact);
1391 if (
gi.isOnMap(impact)) {
1394 const int rounds = std::max(2, fd->
rounds);
1396 }
else if (incendiary) {
1398 const int rounds = std::max(2, fd->
rounds);
1400 }
else if (stunGas) {
1402 const int rounds = std::max(2, fd->
rounds);
1408 if (smoke || incendiary || stunGas) {
1410 Edict* closeActor =
nullptr;
1434 actor->
dir = prevDir;
Edict * G_SpawnFloor(const pos3_t pos)
Spawns a new entity at the floor.
vec_t VectorLength(const vec3_t v)
Calculate the length of a vector.
void G_ClientPrintf(const Player &player, int printLevel, const char *fmt,...)
Edict * G_EdictsGetNextInUse(Edict *lastEnt)
Iterate through the entities that are in use.
int G_TouchTriggers(Edict *ent, const entity_type_t type)
Check the world against triggers for the current entity.
#define VectorCopy(src, dest)
const objDef_t * getWeapon() const
bool tryAddToInventory(Inventory *const inv, const Item *const item, const invDef_t *container)
Tries to add an item to a container (in the inventory inv).
#define MORALE_RANDOM(mod)
bool isSameTeamAs(const Edict *other) const
trace_t G_Trace(const Line &trLine, const Edict *passent, int contentmask)
collision detection - this version is more accurate and includes entity tests
void setAmmoLeft(int value)
Actor * G_EdictsGetNextLivingActor(Actor *lastEnt)
Iterate through the living actor entities.
void G_EventInventoryAmmo(const Edict &ent, const objDef_t *ammo, int amount, shoot_types_t shootType)
Change the amount of available ammo for the given entity.
static void G_ShootSingle(Actor *ent, const fireDef_t *fd, const vec3_t from, const pos3_t at, int mask, const Item *weapon, shot_mock_t *mock, int z_align, int i, shoot_types_t shootType, vec3_t impact)
Fires straight shots.
QGL_EXTERN GLint GLenum type
void getShotOrigin(const vec3_t from, const vec3_t dir, bool crouching, vec3_t shotOrigin) const
void VectorMA(const vec3_t veca, const float scale, const vec3_t vecb, vec3_t outVector)
Sets vector_out (vc) to vevtor1 (va) + scale * vector2 (vb)
this is a fire definition for our weapons/ammo
bool G_SmokeVis(const vec3_t from, const Edict *check)
tests for smoke interference
void G_CheckVis(Edict *check, const vischeckflags_t visFlags)
Check if the edict appears/perishes for the other teams. If they appear for other teams...
void G_EventActorTurn(const Edict &ent)
Send the turn event for the given entity.
const teamDef_t * teamDef
Misc utility functions for game module.
static chrScoreMission_t scoreMission[MAX_EDICTS]
static void G_SpawnItemOnFloor(const pos3_t pos, const Item *item)
Spawn an item on the floor. A new ET_ITEM edict is created if needed.
teammask_t G_PMToVis(playermask_t playerMask)
Converts player mask to vis mask.
static bool G_TeamPointVis(int team, const vec3_t point)
Test if point is "visible" from team.
Actor * G_EdictsGetLivingActorFromPos(const pos3_t pos)
Searches an actor at the given grid location.
static void G_SplashDamage(Actor *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.
int hitsSplash[SKILL_NUM_TYPES][KILLED_NUM_TYPES]
const fireDef_t * getFiredefs() const
Returns the firedefinitions for a given weapon/ammo.
Structure of all stats collected in a mission.
const objDef_t * def(void) const
void G_ActorReserveTUs(Edict *ent, int resReaction, int resShot, int resCrouch)
Reserves TUs for different actor actions.
int stuns[KILLED_NUM_TYPES]
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
Item * getHeadgear() const
#define MAX_WALL_THICKNESS_FOR_SHOOTING_THROUGH
#define G_IsCrouched(ent)
#define G_IsBrushModel(ent)
void VectorNormalizeFast(vec3_t v)
fast vector normalize routine that does not check to make sure that length != 0, nor does it return l...
Defines all attributes of objects used in the inventory.
void G_AppearPerishEvent(playermask_t playerMask, bool appear, Edict &check, const Edict *ent)
Send the appear or perish event to the affected clients.
#define VectorScale(in, scale, out)
void G_ReactionFireSettingsUpdate(Actor *actor, fireDefIndex_t fmIdx, actorHands_t hand, const objDef_t *od)
Updates the reaction fire settings in case something was moved into a hand or from a hand that would ...
chrScoreMission_t * scoreMission
void G_CheckDeathOrKnockout(Actor *target, Actor *attacker, const fireDef_t *fd, int damage)
bool G_IsLivingActor(const Edict *ent)
Checks whether the given edict is a living actor.
int hits[SKILL_NUM_TYPES][KILLED_NUM_TYPES]
float G_ActorVis(const Edict *ent, const Edict *check, bool full)
calculate how much check is "visible" by ent
Actor * makeActor(Edict *ent)
Convert an Edict pointer into an Actor pointer.
static bool G_Damage(Edict *target, const fireDef_t *fd, int damage, Actor *attacker, shot_mock_t *mock, const vec3_t impact)
Deals damage of a give type and amount to a target.
const struct objDef_s * obj
short protection[MAX_DAMAGETYPES]
Item * getRightHandItem() const
int AngleToDir(int angle)
Returns the index of array directionAngles[DIRECTIONS] whose value is the closest to angle...
void G_EventSendState(playermask_t playerMask, const Edict &ent)
#define IS_SHOT_RIGHT(x)
Determine whether the selected shoot type is for the item in the right hand, either shooting or react...
item instance data, with linked list capability
int hitsSplashDamage[SKILL_NUM_TYPES][KILLED_NUM_TYPES]
int kills[KILLED_NUM_TYPES]
void AngleVectors(const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up)
Create the rotation matrix in order to rotate something.
int firedSplash[SKILL_NUM_TYPES]
used in shot probability calculations (pseudo shots)
#define DotProduct(x, y)
Returns the distance between two 3-dimensional vectors.
int32_t shoot_types_t
Available shoot types - also see the ST_ constants.
#define G_IsCivilian(ent)
#define IS_SHOT_HEADGEAR(x)
Determine whether the selected shoot type is for the item in the headgear slot.
void G_SpawnFireField(const vec3_t vec, const char *particle, int rounds, int damage, vec_t radius)
static void G_UpdateShotMock(shot_mock_t *mock, const Edict *shooter, const Edict *struck, int damage)
Function to calculate possible damages for mock pseudoaction.
Edict * G_FindRadius(Edict *from, const vec3_t org, float rad, entity_type_t type)
Returns entities that have origins within a spherical area.
int kills[KILLED_NUM_TYPES]
All parts of the main game logic that are combat related.
void VecToAngles(const vec3_t value1, vec3_t angles)
Converts a vector to an angle vector.
bool isSamePosAs(const pos3_t cmpPos)
Check whether the edict is on the given position.
#define GET_ACC(ab, sk, pn)
int G_ActorGetModifiedTimeForFiredef(const Edict *const ent, const fireDef_t *const fd, const bool reaction)
#define VecToPos(v, p)
Map boundary is +/- MAX_WORLD_WIDTH - to get into the positive area we add the possible max negative ...
#define FIRESH_IsMedikit(firedef)
void G_PrintActorStats(const Edict *victim, const Edict *attacker, const fireDef_t *fd)
Prints stats about who killed who with what and how.
short resistance[MAX_DAMAGETYPES]
void G_EventShootHidden(teammask_t teamMask, const fireDef_t *fd, bool firstShoot, const vec3_t impact, int flags, const Edict *targetEdict)
Start the shooting event for hidden actors.
Edict * G_SpawnParticle(const vec3_t origin, int spawnflags, const char *particle)
byte num_alive[MAX_TEAMS]
bool G_TestLine(const vec3_t start, const vec3_t end)
fast version of a line trace but without including entities
bool CHRSH_IsTeamDefRobot(const teamDef_t *const td)
Check if a team definition is a robot.
Edict * G_GetFloorItemFromPos(const pos3_t pos)
Callback to G_GetEdictFromPos() for given position, used to get items from position.
playermask_t G_VisToPM(teammask_t teamMask)
Converts vis mask to player mask.
void Com_DPrintf(int level, const char *fmt,...)
A Com_Printf that only shows up if the "developer" cvar is set.
static void G_UpdateCharacterBodycount(Edict *attacker, const fireDef_t *fd, const Actor *target)
Update character stats for this mission after successful shoot.
void G_DamageActor(Edict *target, const int damage, const vec3_t impact)
Deals damage and causes wounds.
#define INVDEF(containerID)
static bool G_FireAffectedSurface(const cBspSurface_t *surface, const fireDef_t *fd)
Checks surface vulnerability for firedefinition damagetype.
void getCenter(vec3_t center) const
Calculates the center of the bounding box.
void G_SpawnSmokeField(const vec3_t vec, const char *particle, int rounds, int damage, vec_t radius)
Spawns a smoke field that is available for some rounds.
static void G_ShootGrenade(const Player &player, Actor *shooter, const fireDef_t *fd, const vec3_t from, const pos3_t at, int mask, const Item *weapon, shot_mock_t *mock, int z_align, vec3_t impact)
A parabola-type shoot (grenade, throw).
actorSizeEnum_t fieldSize
void G_TakeDamage(Edict *ent, int damage)
Applies the given damage value to an edict that is either an actor or has the FL_DESTROYABLE flag set...
bool firedHit[KILLED_NUM_TYPES]
#define VectorCompare(a, b)
#define VectorLengthSqr(a)
#define G_TeamToVisMask(team)
void G_EventSpawnSound(playermask_t playerMask, const Edict &ent, const vec3_t origin, const char *sound)
Spawns a sound (that will be spatialized on the client side)
Structure of all stats collected for an actor over time.
bool firedSplashHit[KILLED_NUM_TYPES]
int G_CheckVisTeamAll(const int team, const vischeckflags_t visFlags, const Edict *ent)
Do G_CheckVisTeam for all entities ent is the one that is looking at the others.
void asIntString(char *str, size_t len)
Prints a representation of the box.
static void G_UpdateHitScore(Edict *attacker, const Edict *target, const fireDef_t *fd, const int splashDamage)
Increases the 'hit' score by one for all affected teams/skills by one (except splash damage...
void gaussrand(float *gauss1, float *gauss2)
generate two gaussian distributed random numbers with median at 0 and stdev of 1
#define VectorAdd(a, b, dest)
void G_ReactionFirePreShot(const Actor *target, const int fdTime)
Called when 'target' is about to shoot, this forces a 'draw' to decide who gets the first shot...
int skillKills[SKILL_NUM_TYPES]
#define G_IsSinglePlayer()
static void G_Morale(morale_modifiers type, const Edict *victim, const Edict *attacker, int param)
Applies morale changes to actors around a wounded or killed actor.
bool G_IsActorWounded(const Edict *ent, bool serious)
bool G_ActionCheckForCurrentTeam(const Player &player, Actor *ent, int TU)
Checks whether the requested action is possible for the current active team.
bool G_ClientShoot(const Player &player, Actor *actor, const pos3_t at, shoot_types_t shootType, fireDefIndex_t firemode, shot_mock_t *mock, bool allowReaction, int z_align)
Setup for shooting, either real or mock.
Actor * G_EdictsGetNextLivingActorOfTeam(Actor *lastEnt, const int team)
Iterate through the living actor entities of the given team.
void G_VisFlagsReset(Edict &ent)
void G_EventInventoryDelete(const Edict &ent, playermask_t playerMask, const containerIndex_t containerId, int x, int y)
Tell the client to remove the item from the container.
Brings new objects into the world.
void G_ActorSetTU(Edict *ent, int tus)
void G_EventShoot(const Edict &ent, teammask_t teamMask, const fireDef_t *fd, bool firstShoot, shoot_types_t shootType, int flags, const trace_t *trace, const vec3_t from, const vec3_t impact)
Do the shooting.
bool G_FrustumVis(const Edict *from, const vec3_t point)
Checks whether a point is "visible" from the edicts position.
void G_EventPerish(const Edict &ent)
Send an event to all clients that are seeing the given edict, that it just has disappeared.
functions to handle the storage and lifecycle of all edicts in the game module.
unsigned num_spawned[MAX_TEAMS]
int firedTUs[SKILL_NUM_TYPES]
#define GRENADE_STOPSPEED
bool isSameAs(const Edict *other) const
bool(* destroy)(Edict *self)
float crand(void)
Return random values between -1 and 1.
const objDef_t * ammoDef(void) const
const char * getActorSound(int gender, actorSound_t soundType) const
Returns the actor sounds for a given category.
inventory definition for our menus
bool RayIntersectAABB(const vec3_t start, const vec3_t end, const AABB &aabb)
void G_ActorGetEyeVector(const Edict *actor, vec3_t eye)
Fills a vector with the eye position of a given actor.
void G_SpawnStunSmokeField(const vec3_t vec, const char *particle, int rounds, int damage, vec_t radius)
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...
int firedSplashTUs[SKILL_NUM_TYPES]
void G_MatchEndCheck(void)
Checks whether there are still actors to fight with left. If none are the match end will be triggered...
#define G_IsVisibleForTeam(ent, team)
void G_EventThrow(teammask_t teamMask, const fireDef_t *fd, float dt, byte flags, const vec3_t position, const vec3_t velocity)
Edict * G_GetFloorItems(Edict *ent)
Prepares a list of items on the floor at given entity position.
Edict * G_EdictsGetByNum(const int num)
Get an entity by it's number.
actorHands_t getHand() const
int fired[SKILL_NUM_TYPES]
void G_ReactionFirePostShot(Actor *target)
Called after 'target' has fired, this might trigger more reaction fire or resolve outstanding reactio...
void emptyContainer(Inventory *const inv, const containerIndex_t container)
Clears the linked list of a container - removes all items from this container.
void G_SendStats(Edict &ent)
Send stats to network buffer.
void G_VisFlagsAdd(Edict &ent, teammask_t teamMask)
static void G_ShotMorale(const Actor *shooter, const fireDef_t *fd, const vec3_t from, const Item *weapon, const vec3_t impact)
Applies morale changes to actors who find themselves in the general direction of a shot...
void G_CalcEffectiveSpread(const Actor *shooter, const fireDef_t *fd, vec2_t effSpread)
Calculate the effective spread for the given actor and firemode.
#define ST_NUM_SHOOT_TYPES
Amount of shoottypes available.
void G_EventStartShoot(const Edict &ent, teammask_t teamMask, shoot_types_t shootType, const pos3_t at)
Start the shooting event.
void G_EventEndShoot(const Edict &ent, teammask_t teamMask)
Ends the shooting event.
Item * getLeftHandItem() const
int stuns[KILLED_NUM_TYPES]
#define G_IsAIPlayer(player)
#define VectorDistSqr(a, b)
float G_ActorGetInjuryPenalty(const Edict *const ent, const modifier_types_t type)
Returns the penalty to the given stat caused by the actor wounds.
int skills[SKILL_NUM_TYPES]
void G_FreeEdict(Edict *ent)
Marks the edict as free.
bool G_ActionCheckForReaction(const Player &player, Actor *actor, int TU)
Checks whether the requested action is possible.
#define VectorSubtract(a, b, dest)
void G_TreatActor(Actor *target, const fireDef_t *const fd, const int heal, const int healerTeam)
Heals a target and treats wounds.
Interface for g_client.cpp.
Edict * G_EdictsGetNext(Edict *lastEnt)
Iterate through the list of entities.
playermask_t G_TeamToPM(int team)
Generates the player bit mask for a given team.
#define G_IsBreakable(ent)
int G_ApplyProtection(const Edict *target, const byte dmgWeight, int damage)
Reduces damage by armour and natural protection.
static bool G_PrepareShot(Edict *ent, shoot_types_t shootType, fireDefIndex_t firemode, Item **weapon, containerIndex_t *container, const fireDef_t **fd)
Prepares weapon, firemode and container used for shoot.
chrReservations_t reservedTus