UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
e_event_actorstatechange.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 "../../../../ui/ui_main.h"
27 #include "../../../cl_localentity.h"
28 #include "../../../cl_actor.h"
29 #include "../../../cl_hud.h"
31 
33 {
34  int entnum, state;
35  NET_ReadFormat(msg, self->formatString, &entnum, &state);
36 
37  le_t* le = LE_Get(entnum);
38  if (!le)
39  LE_NotFoundError(entnum);
40 
41  if (!LE_IsActor(le)) {
42  Com_Printf("StateChange message ignored... LE is no actor (number: %i, state: %i, type: %i)\n",
43  entnum, state, le->type);
44  return;
45  }
46 
47  /* If standing up or crouching down remove the reserved-state for crouching. */
48  if (((state & STATE_CROUCHED) && !LE_IsCrouched(le)) ||
49  (!(state & STATE_CROUCHED) && LE_IsCrouched(le))) {
51  /* We have not enough non-reserved TUs,
52  * but some reserved for crouching/standing up.
53  * i.e. we only reset the reservation for crouching if it's the very last attempt. */
54  CL_ActorReserveTUs(le, RES_CROUCH, 0); /* Reset reserved TUs (0 TUs) */
55  }
56  }
57 
58  /* killed by the server: no animation is played, etc. */
59  if ((state & STATE_DEAD) && LE_IsLivingActor(le)) {
60  if ((state & STATE_STUN) != (le->state & STATE_STUN))
62  le->state = state;
63  le->resetFloor();
64  LE_SetThink(le, nullptr);
67  return;
68  }
69 
70  character_t* chr = CL_ActorGetChr(le);
71  if (chr) { /* Print some informative messages */
72  if (le->team == cls.team) {
73  if ((state & STATE_DAZED) && !LE_IsDazed(le))
74  HUD_DisplayMessage(va(_("%s is dazed!\nEnemy used flashbang!"), chr->name));
75 
76  if ((state & STATE_PANIC) && !LE_IsPanicked(le))
77  HUD_DisplayMessage(va(_("%s panics!"), chr->name));
78 
79  if ((state & STATE_RAGE) && !LE_IsRaged(le)) {
80  if ((state & STATE_INSANE)) {
81  HUD_DisplayMessage(va(_("%s is consumed by mad rage!"), chr->name));
82  } else {
83  HUD_DisplayMessage(va(_("%s is on a rampage!"), chr->name));
84  }
85  }
86 
87  if ((state & STATE_SHAKEN) && !LE_IsShaken(le))
88  HUD_DisplayMessage(va(_("%s is currently shaken."), chr->name));
89  }
90  }
91 
92  le->state = state;
94 
95  /* save those states that the actor should also carry over to other missions */
96  if (chr)
97  chr->state = (le->state & STATE_REACTION);
98 
99  /* state change may have affected move length */
101 }
#define LE_IsCrouched(le)
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_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
#define STATE_REACTION
Definition: q_shared.h:272
#define TU_CROUCH
Definition: defines.h:72
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
void Com_Printf(const char *const fmt,...)
Definition: common.cpp:386
#define STATE_CROUCHED
Definition: q_shared.h:263
bool LE_IsActor(const le_t *le)
Checks whether the given le is a living actor.
#define STATE_SHAKEN
Definition: q_shared.h:273
void resetFloor()
client_static_t cls
Definition: cl_main.cpp:83
void CL_ActorReserveTUs(const le_t *le, const reservation_types_t type, const int tus)
Replace the reserved TUs for a certain type.
Definition: cl_actor.cpp:273
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
le_t * LE_Get(int entnum)
Searches all local entities for the one with the searched entnum.
int CL_ActorReservedTUs(const le_t *le, const reservation_types_t type)
Returns the amount of reserved TUs for a certain type.
Definition: cl_actor.cpp:214
static const vec3_t player_dead_maxs
#define LE_IsDazed(le)
#define STATE_DEAD
Definition: q_shared.h:262
void CL_ActorStateChange(const eventRegister_t *self, dbuffer *msg)
#define STATE_RAGE
Definition: q_shared.h:266
int CL_ActorUsableTUs(const le_t *le)
Returns the amount of usable (overall-reserved) TUs for an actor.
Definition: cl_actor.cpp:259
Struct that defines one particular event with all its callbacks and data.
Definition: e_main.h:42
#define STATE_STUN
Definition: q_shared.h:268
a local entity
#define STATE_DAZED
Definition: q_shared.h:269
entity_type_t type
#define STATE_INSANE
Definition: q_shared.h:267
#define STATE_PANIC
Definition: q_shared.h:264
AABB aabb
char name[MAX_VAR]
Definition: chr_shared.h:371
#define LE_IsRaged(le)
#define LE_IsPanicked(le)
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 LE_SetThink(le_t *le, localEntityThinkFunc_t think)
void LET_StartIdle(le_t *le)
Change the animation of an actor to the idle animation (which can be panic, dead or stand) ...
#define LE_IsShaken(le)
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