UFO: Alien Invasion
Loading...
Searching...
No Matches
e_event_actorstatechange.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"
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}
@ RES_CROUCH
Definition chr_shared.h:210
@ SND_DEATH
Definition chr_shared.h:219
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_ActorRemoveFromTeamList(le_t *le)
Removes an actor (from your team) from the team list.
Definition cl_actor.cpp:400
int CL_ActorUsableTUs(const le_t *le)
Returns the amount of usable (overall-reserved) TUs for an actor.
Definition cl_actor.cpp:259
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
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
character_t * CL_ActorGetChr(const le_t *le)
Returns the character information for an actor in the teamlist.
Definition cl_actor.cpp:155
void HUD_DisplayMessage(const char *text)
Displays a message on the hud.
Definition cl_hud.cpp:138
HUD related routines.
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 LET_StartIdle(le_t *le)
Change the animation of an actor to the idle animation (which can be panic, dead or stand).
le_t * LE_Get(int entnum)
Searches all local entities for the one with the searched entnum.
bool LE_IsActor(const le_t *le)
Checks whether the given le is a living actor.
#define LE_IsDazed(le)
#define LE_IsPanicked(le)
#define LE_IsCrouched(le)
#define LE_IsShaken(le)
#define LE_IsRaged(le)
static const vec3_t player_dead_maxs
#define LE_NotFoundError(entnum)
client_static_t cls
Definition cl_main.cpp:83
#define _(String)
Definition cl_shared.h:44
void setMaxs(const vec3_t maxi)
Definition aabb.h:71
Primary header for client.
void Com_Printf(const char *const fmt,...)
Definition common.cpp:428
#define TU_CROUCH
Definition defines.h:72
void CL_ActorStateChange(const eventRegister_t *self, dbuffer *msg)
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 STATE_DEAD
Definition q_shared.h:262
#define STATE_STUN
Definition q_shared.h:268
#define STATE_RAGE
Definition q_shared.h:266
#define STATE_CROUCHED
Definition q_shared.h:263
#define STATE_PANIC
Definition q_shared.h:264
#define STATE_REACTION
Definition q_shared.h:272
#define STATE_SHAKEN
Definition q_shared.h:273
#define STATE_INSANE
Definition q_shared.h:267
#define STATE_DAZED
Definition q_shared.h:269
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
a local entity
int state
void resetFloor()
AABB aabb
entity_type_t type