UFO: Alien Invasion
Loading...
Searching...
No Matches
e_event_actorappear.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 "e_event_actorappear.h"
28#include "../../../cl_ugv.h"
29#include "../../../cl_actor.h"
30#include "../../../cl_hud.h"
34
38int CL_ActorAppearTime (const eventRegister_t* self, dbuffer* msg, eventTiming_t* eventTiming)
39{
40 const int eventTime = eventTiming->nextTime;
41
42 /* delay following events */
43 if (!cls.isOurRound())
44 eventTiming->nextTime += 600;
45
46 return eventTime;
47}
48
52static void CL_DrawLineOfSight (const le_t* watcher, const le_t* target)
53{
54 if (!watcher || !target)
55 return;
56
57 /* start is the watchers origin */
58 vec3_t eyes;
59 VectorCopy(watcher->origin, eyes);
60 if (LE_IsCrouched(watcher))
61 eyes[2] += EYE_HT_CROUCH;
62 else
63 eyes[2] += EYE_HT_STAND;
64
65 ptl_t* ptl = CL_ParticleSpawn("fadeTracer", 0, eyes, target->origin);
66 if (ptl == nullptr)
67 return;
68
69 if (LE_IsCivilian(target))
70 VectorSet(ptl->color, 0.2, 0.2, 1);
71}
72
79void CL_ActorAppear (const eventRegister_t* self, dbuffer* msg)
80{
81
82 /* check if the actor is already visible */
83 const int entnum = NET_ReadShort(msg);
84 const int entnumResponsible = NET_ReadShort(msg);
85 le_t* le = LE_Get(entnum);
86 le_t* leResponsible = LE_Get(entnumResponsible);
87
88 if (entnumResponsible != SKIP_LOCAL_ENTITY && !leResponsible)
89 LE_NotFoundError(entnumResponsible);
90
91 /* mission start - no actor is spawned yet - so create it */
92 if (!le)
93 le = LE_Add(entnum);
94
95 /* Locking should be unnecessary if CL_CheckDefault filters this call, since this event starts and
96 * ends in this function only. Adding lock/unlock just to be sure. */
97 LE_Lock(le);
98
99 /* maybe added via CL_ActorAdd before */
100 le->flags &= ~LE_INVISIBLE;
101
102 /* get the info */
103 int teamDefID = -1;
104 int modelnum1, modelnum2;
105 NET_ReadFormat(msg, self->formatString,
106 &le->team, &teamDefID, &le->gender, &le->ucn, &le->pnum, &le->pos,
107 &le->angle, &le->right, &le->left,
108 &modelnum1, &modelnum2, &le->bodySkin, &le->headSkin,
109 &le->state, &le->fieldSize,
110 &le->maxTU, &le->maxMorale, &le->maxHP);
111
112 if (teamDefID < 0 || teamDefID > csi.numTeamDefs)
113 Com_Printf("CL_ActorAppear: Invalid teamDef index\n");
114 else
115 le->teamDef = &csi.teamDef[teamDefID];
116
117 switch (le->fieldSize) {
119 le->addFunc = CL_AddActor;
120 le->type = ET_ACTOR;
121 break;
122 case ACTOR_SIZE_2x2:
123 le->addFunc = CL_AddUGV;
124 le->type = ET_ACTOR2x2;
125 break;
126 default:
127 Com_Error(ERR_DROP, "Unknown fieldSize for le in CL_ActorAppear (EV_ACTOR_APPEAR)");
128 }
129 le->modelnum1 = modelnum1;
130 le->modelnum2 = modelnum2;
131 le->model1 = LE_GetDrawModel(modelnum1);
132 le->model2 = LE_GetDrawModel(modelnum2);
133 Grid_PosToVec(cl.mapData->routing, le->fieldSize, le->pos, le->origin);
134 le->angles[YAW] = directionAngles[le->angle];
135
136 if (LE_IsDead(le) && !LE_IsStunned(le))
138 else
141 if (LE_IsDead(le))
143 else
145
147
148 /* count spotted aliens (also stunned) */
149 cl.numEnemiesSpotted = CL_CountVisibleEnemies();
150 Cvar_SetValue("mn_numaliensspotted", cl.numEnemiesSpotted);
151
152 if (LE_IsLivingActor(le)) {
153 if (!cls.isOurRound()) {
154 /* center view (if wanted) */
155 if (leResponsible) {
156 CL_CheckCameraRoute(leResponsible->pos, le->pos);
157 } else {
158 LE_CenterView(le);
159 }
160 }
161
162 /* draw line of sight */
163 if (le->team != cls.team) {
164 if (leResponsible)
165 CL_DrawLineOfSight(leResponsible, le);
166
167 /* message */
168 if (le->team != TEAM_CIVILIAN) {
169 if (GAME_TeamIsKnown(le->teamDef)) {
170 char tmpbuf[128];
171 Com_sprintf(tmpbuf, sizeof(tmpbuf), _("Enemy spotted: %s!"), _(le->teamDef->name));
172 HUD_DisplayMessage(tmpbuf);
173 } else
174 HUD_DisplayMessage(_("Unknown enemy spotted!"));
175 } else
176 HUD_DisplayMessage(_("Civilian spotted."));
177
178 /* update pathing as new actor could block path */
179 CL_ActorConditionalMoveCalc(leResponsible ? leResponsible : selActor);
180 }
181 }
182
183 /* add team members to the actor list */
185 LE_Unlock(le);
186}
void CL_ActorAddToTeamList(le_t *le)
Adds the actor to the team list.
Definition cl_actor.cpp:362
bool CL_AddActor(le_t *le, entity_t *ent)
Adds an actor to the render entities with all it's models and items.
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
#define EYE_HT_STAND
Definition cl_actor.h:30
bool CL_AddUGV(le_t *le, entity_t *ent)
Adds an UGV to the render entities.
Definition cl_ugv.cpp:35
#define EYE_HT_CROUCH
Definition cl_actor.h:32
clientBattleScape_t cl
int CL_CountVisibleEnemies(void)
Counts visible enemies on the battlescape.
void CL_CheckCameraRoute(const pos3_t from, const pos3_t target)
Only moves the camera to the given target location if its not yet close enough.
bool GAME_TeamIsKnown(const teamDef_t *teamDef)
Definition cl_game.cpp:1439
Shared game type headers.
void HUD_DisplayMessage(const char *text)
Displays a message on the hud.
Definition cl_hud.cpp:138
HUD related routines.
void LE_CenterView(const le_t *le)
Center the camera on the local entity's origin.
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).
model_t * LE_GetDrawModel(unsigned int index)
le_t * LE_Add(int entnum)
Add a new local entity to the scene.
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).
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)
static const vec3_t player_mins
#define LE_INVISIBLE
#define LE_IsCrouched(le)
static const vec3_t player_maxs
#define LE_IsCivilian(le)
static const vec3_t player_dead_maxs
#define LE_NotFoundError(entnum)
#define LE_IsStunned(le)
client_static_t cls
Definition cl_main.cpp:83
ptl_t * CL_ParticleSpawn(const char *name, int levelFlags, const vec3_t s, const vec3_t v, const vec3_t a)
Spawn a new particle to the map.
#define _(String)
Definition cl_shared.h:44
void setMaxs(const vec3_t maxi)
Definition aabb.h:71
void setMins(const vec3_t mini)
Definition aabb.h:68
Primary header for client.
csi_t csi
Definition common.cpp:39
void Com_Error(int code, const char *fmt,...)
Definition common.cpp:459
void Com_Printf(const char *const fmt,...)
Definition common.cpp:428
#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_ACTOR
Definition defines.h:247
#define CONTENTS_DEADACTOR
Definition defines.h:250
#define ACTOR_SIZE_2x2
Definition defines.h:303
#define ACTOR_SIZE_NORMAL
Definition defines.h:302
static void CL_DrawLineOfSight(const le_t *watcher, const le_t *target)
draw a simple 'spotted' line from a spotter to the spotted
void CL_ActorAppear(const eventRegister_t *self, dbuffer *msg)
int CL_ActorAppearTime(const eventRegister_t *self, dbuffer *msg, eventTiming_t *eventTiming)
Decides if following events should be delayed.
void Grid_PosToVec(const Routing &routing, const actorSizeEnum_t actorSize, const pos3_t pos, vec3_t vec)
Converts a grid position to world coordinates.
Definition grid.cpp:832
Battlescape grid functions.
const float directionAngles[CORE_DIRECTIONS]
Definition mathlib.cpp:105
#define YAW
Definition mathlib.h:55
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
int NET_ReadShort(dbuffer *buf)
Definition netpack.cpp:242
#define SKIP_LOCAL_ENTITY
Definition q_shared.h:255
@ ET_ACTOR
Definition q_shared.h:148
@ ET_ACTOR2x2
Definition q_shared.h:160
#define TEAM_CIVILIAN
Definition q_shared.h:61
bool Com_sprintf(char *dest, size_t size, const char *fmt,...)
copies formatted string with buffer-size checking
Definition shared.cpp:494
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
a local entity
int state
int flags
int contents
float angles[3]
vec3_t origin
actorSizeEnum_t fieldSize
int maxMorale
int maxTU
int angle
localEntitiyAddFunc_t addFunc
unsigned int modelnum1
pos3_t pos
model_t * model1
unsigned int headSkin
teamDef_t * teamDef
model_t * model2
AABB aabb
int maxHP
unsigned int modelnum2
unsigned int bodySkin
entity_type_t type
vec4_t color
char name[MAX_VAR]
Definition chr_shared.h:310
vec_t vec3_t[3]
Definition ufotypes.h:39
#define VectorCopy(src, dest)
Definition vector.h:51
#define VectorSet(v, x, y, z)
Definition vector.h:59