UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
e_event_actordie.cpp
Go to the documentation of this file.
1 
5 /*
6 Copyright (C) 2002-2020 UFO: Alien Invasion.
7 
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 
17 See the GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, 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"
29 #include "../../../cl_particle.h"
30 #include "../../../../renderer/r_mesh_anim.h"
31 #include "e_event_actordie.h"
32 
37 int 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 
51 void 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 */
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 
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 }
#define LE_IsStunned(le)
animState_t as
#define TEAM_PHALANX
Definition: q_shared.h:62
#define TEAM_ALIEN
Definition: q_shared.h:63
int pnum
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
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).
void CL_ActorRemoveFromTeamList(le_t *le)
Removes an actor (from your team) from the team list.
Definition: cl_actor.cpp:400
#define _(String)
Definition: cl_shared.h:43
bool Com_sprintf(char *dest, size_t size, const char *fmt,...)
copies formatted string with buffer-size checking
Definition: shared.cpp:494
void LE_Unlock(le_t *le)
Unlocks a previously locked le_t struct.
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
character_t * CL_ActorGetChr(const le_t *le)
Returns the character information for an actor in the teamlist.
Definition: cl_actor.cpp:155
#define TEAM_CIVILIAN
Definition: q_shared.h:61
bool parsedShot
Definition: e_main.h:36
void R_AnimChange(animState_t *as, const model_t *mod, const char *name)
Changes the animation for md2 models.
CL_ParseEvent timers and vars.
Definition: e_main.h:30
void Com_Error(int code, const char *fmt,...)
Definition: common.cpp:417
void resetFloor()
client_static_t cls
Definition: cl_main.cpp:83
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
void CL_ActorPlaySound(const le_t *le, actorSound_t soundType)
Plays various sounds on actor action.
Definition: cl_actor.cpp:2134
#define LE_GetAnimationIndexForDeath(le)
Valid indices from 1 - MAX_DEATH.
#define ERR_DROP
Definition: common.h:211
le_t * LE_Get(int entnum)
Searches all local entities for the one with the searched entnum.
static const vec3_t player_dead_maxs
model_t * model1
clientBattleScape_t cl
int CL_CountVisibleEnemies(void)
Counts visible enemies on the battlescape.
ptl_t * ptl
const char * CL_PlayerGetName(unsigned int player)
Get the player name.
Definition: cl_parse.cpp:113
Struct that defines one particular event with all its callbacks and data.
Definition: e_main.h:42
a local entity
#define CONTENTS_DEADACTOR
Definition: defines.h:250
entity_type_t type
le_t * selActor
Definition: cl_actor.cpp:49
#define LE_IsDead(le)
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 CL_ParticleFree(ptl_t *p)
Free a particle and all it's children.
AABB aabb
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...
bool parsedDeath
Definition: e_main.h:35
int impactTime
Definition: e_main.h:33
char name[MAX_VAR]
Definition: chr_shared.h:371
int contents
#define lengthof(x)
Definition: shared.h:105
int team
bool LE_IsLivingActor(const le_t *le)
Checks whether the given le is a living actor (but might be hidden)
void setMaxs(const vec3_t maxi)
Definition: aabb.h:71
void Cvar_SetValue(const char *varName, float value)
Expands value to a string and calls Cvar_Set.
Definition: cvar.cpp:671
int nextTime
Definition: e_main.h:31
void R_AnimAppend(animState_t *as, const model_t *mod, const char *name)
Appends a new animation to the current running one.
Definition: r_mesh_anim.cpp:84
void LE_SetThink(le_t *le, localEntityThinkFunc_t think)
int state
void HUD_DisplayMessage(const char *text)
Displays a message on the hud.
Definition: cl_hud.cpp:138
#define LE_NotFoundError(entnum)
Describes a character with all its attributes.
Definition: chr_shared.h:369