UFO: Alien Invasion
Loading...
Searching...
No Matches
e_event_actordie.cpp
Go to the documentation of this file.
1
4
5/*
6Copyright (C) 2002-2025 UFO: Alien Invasion.
7
8This program is free software; you can redistribute it and/or
9modify it under the terms of the GNU General Public License
10as published by the Free Software Foundation; either version 2
11of the License, or (at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
17See the GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
23*/
24
25#include "../../../../client.h"
26#include "../../../cl_actor.h"
27#include "../../../cl_hud.h"
28#include "../../../cl_parse.h"
31#include "e_event_actordie.h"
32
37int CL_ActorDieTime (const struct eventRegister_s* self, dbuffer* msg, eventTiming_t* eventTiming)
38{
39 eventTiming->parsedDeath = true;
40 if (eventTiming->parsedShot && eventTiming->impactTime > cl.time)
41 return eventTiming->impactTime;
42 return eventTiming->nextTime;
43}
44
51void CL_ActorDie (const eventRegister_t* self, dbuffer* msg)
52{
53 int entnum, state, playerNum, attacker;
54
55 NET_ReadFormat(msg, self->formatString, &entnum, &state, &playerNum, &attacker);
56
57 /* get les */
58 le_t* le = LE_Get(entnum);
59
60 if (!le)
61 LE_NotFoundError(entnum);
62
63 if (!LE_IsLivingActor(le))
64 Com_Error(ERR_DROP, "CL_ActorDie: Can't kill, LE is not an actor (type: %i)", le->type);
65
66 if (!LE_IsStunned(le) && LE_IsDead(le))
67 Com_Error(ERR_DROP, "CL_ActorDie: Can't kill, actor already dead");
68
69 LE_Lock(le);
70
71 /* set relevant vars */
72 le->resetFloor();
73 le->state = state;
74
75 /* count spotted aliens */
76 cl.numEnemiesSpotted = CL_CountVisibleEnemies();
77 Cvar_SetValue("mn_numaliensspotted", cl.numEnemiesSpotted);
78
79 /* play animation */
80 LE_SetThink(le, nullptr);
81 R_AnimChange(&le->as, le->model1, va("death%i", LE_GetAnimationIndexForDeath(le)));
82 R_AnimAppend(&le->as, le->model1, va("dead%i", LE_GetAnimationIndexForDeath(le)));
83
84 /* Print some info about the death or stun. */
85 if (le->team == cls.team) {
86 if (playerNum != le->pnum) {
87 const char* playerName = CL_PlayerGetName(playerNum);
88 char tmpbuf[128];
89 Com_sprintf(tmpbuf, lengthof(tmpbuf), _("%s lost a soldier\n"), playerName);
90 HUD_DisplayMessage(tmpbuf);
91 } else {
92 const character_t* chr = CL_ActorGetChr(le);
93 if (chr) {
94 char tmpbuf[128];
95 if (LE_IsStunned(le)) {
96 Com_sprintf(tmpbuf, lengthof(tmpbuf), _("%s was stunned\n"), chr->name);
97 } else if (!attacker) {
98 Com_sprintf(tmpbuf, lengthof(tmpbuf), _("%s has died\n"), chr->name);
99 } else {
100 Com_sprintf(tmpbuf, lengthof(tmpbuf), _("%s was killed\n"), chr->name);
101 }
102 HUD_DisplayMessage(tmpbuf);
103 }
104 }
105 } else {
106 switch (le->team) {
107 case (TEAM_CIVILIAN):
108 if (LE_IsStunned(le))
109 HUD_DisplayMessage(_("A civilian was stunned."));
110 else if (!attacker)
111 HUD_DisplayMessage(_("A civilian has died."));
112 else
113 HUD_DisplayMessage(_("A civilian was killed."));
114 break;
115 case (TEAM_ALIEN):
116 if (LE_IsStunned(le))
117 HUD_DisplayMessage(_("An alien was stunned."));
118 else if (!attacker)
119 HUD_DisplayMessage(_("An alien has died."));
120 else
121 HUD_DisplayMessage(_("An alien was killed."));
122 break;
123 case (TEAM_PHALANX):
124 if (LE_IsStunned(le))
125 HUD_DisplayMessage(_("A soldier was stunned."));
126 else if (!attacker)
127 HUD_DisplayMessage(_("A soldier has died."));
128 else
129 HUD_DisplayMessage(_("A soldier was killed."));
130 break;
131 default:
132 if (LE_IsStunned(le))
133 HUD_DisplayMessage(va(_("A member of team %i was stunned."), le->team));
134 else if (!attacker)
135 HUD_DisplayMessage(va(_("A member of team %i has died."), le->team));
136 else
137 HUD_DisplayMessage(va(_("A member of team %i was killed."), le->team));
138 break;
139 }
140 }
141
145
147
149 if (!LE_IsStunned(le))
151 if (le->ptl) {
152 CL_ParticleFree(le->ptl);
153 le->ptl = nullptr;
154 }
156
157 /* update pathing as we maybe can walk onto the dead actor now */
159 LE_Unlock(le);
160}
@ SND_DEATH
Definition chr_shared.h:219
void CL_ActorRemoveFromTeamList(le_t *le)
Removes an actor (from your team) from the team list.
Definition cl_actor.cpp:400
void CL_ActorPlaySound(const le_t *le, actorSound_t soundType)
Plays various sounds on actor action.
void CL_ActorConditionalMoveCalc(le_t *le)
Recalculate forbidden list, available moves and actor's move length for the current selected actor.
Definition cl_actor.cpp:682
le_t * selActor
Definition cl_actor.cpp:49
character_t * CL_ActorGetChr(const le_t *le)
Returns the character information for an actor in the teamlist.
Definition cl_actor.cpp:155
clientBattleScape_t cl
int CL_CountVisibleEnemies(void)
Counts visible enemies on the battlescape.
void HUD_DisplayMessage(const char *text)
Displays a message on the hud.
Definition cl_hud.cpp:138
HUD related routines.
void LE_Unlock(le_t *le)
Unlocks a previously locked le_t struct.
bool LE_IsLivingActor(const le_t *le)
Checks whether the given le is a living actor (but might be hidden).
void LE_SetThink(le_t *le, localEntityThinkFunc_t think)
void LE_Lock(le_t *le)
Markes a le_t struct as locked. Should be called at the beginning of an event handler on this le_t,...
le_t * LE_Get(int entnum)
Searches all local entities for the one with the searched entnum.
#define LE_IsDead(le)
#define LE_GetAnimationIndexForDeath(le)
Valid indices from 1 - MAX_DEATH.
static const vec3_t player_dead_maxs
#define LE_NotFoundError(entnum)
#define LE_IsStunned(le)
client_static_t cls
Definition cl_main.cpp:83
const char * CL_PlayerGetName(unsigned int player)
Get the player name.
Definition cl_parse.cpp:113
void CL_ParticleFree(ptl_t *p)
Free a particle and all it's children.
#define _(String)
Definition cl_shared.h:44
void setMaxs(const vec3_t maxi)
Definition aabb.h:71
Primary header for client.
void Com_Error(int code, const char *fmt,...)
Definition common.cpp:459
#define ERR_DROP
Definition common.h:211
void Cvar_SetValue(const char *varName, float value)
Expands value to a string and calls Cvar_Set.
Definition cvar.cpp:671
#define CONTENTS_DEADACTOR
Definition defines.h:250
void CL_ActorDie(const eventRegister_t *self, dbuffer *msg)
Kills an actor (all that is needed is the local entity state set to STATE_DEAD).
int CL_ActorDieTime(const struct eventRegister_s *self, dbuffer *msg, eventTiming_t *eventTiming)
Some events will be delayed if they are executed in the context of a dying actor. That's why we set t...
void NET_ReadFormat(dbuffer *buf, const char *format,...)
The user-friendly version of NET_ReadFormat that reads variable arguments from a buffer according to ...
Definition netpack.cpp:533
#define TEAM_PHALANX
Definition q_shared.h:62
#define TEAM_ALIEN
Definition q_shared.h:63
#define TEAM_CIVILIAN
Definition q_shared.h:61
void R_AnimChange(animState_t *as, const model_t *mod, const char *name)
Changes the animation for md2 models.
void R_AnimAppend(animState_t *as, const model_t *mod, const char *name)
Appends a new animation to the current running one.
#define lengthof(x)
Definition shared.h:105
bool Com_sprintf(char *dest, size_t size, const char *fmt,...)
copies formatted string with buffer-size checking
Definition shared.cpp:494
const char * va(const char *format,...)
does a varargs printf into a temp buffer, so I don't need to have varargs versions of all text functi...
Definition shared.cpp:410
Describes a character with all its attributes.
Definition chr_shared.h:388
char name[MAX_VAR]
Definition chr_shared.h:390
Struct that defines one particular event with all its callbacks and data.
Definition e_main.h:42
const char * formatString
The format string that is used to write and parse this event.
Definition e_main.h:54
CL_ParseEvent timers and vars.
Definition e_main.h:30
int nextTime
Definition e_main.h:31
int impactTime
Definition e_main.h:33
bool parsedDeath
Definition e_main.h:35
bool parsedShot
Definition e_main.h:36
a local entity
int state
int contents
void resetFloor()
ptl_t * ptl
animState_t as
model_t * model1
AABB aabb
entity_type_t type