UFO: Alien Invasion
Loading...
Searching...
No Matches
e_main.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_localentity.h"
27#include "e_main.h"
72
79static bool CL_CheckDefault (const eventRegister_t* self, const dbuffer* msg)
80{
81 const int number = NET_PeekShort(msg);
82 const bool result = LE_IsLocked(number);
83 if (result)
84 Com_DPrintf(DEBUG_EVENTSYS, "CL_CheckDefault: Delaying event on entnum %i.\n", number);
85 return (!result);
86}
87
93#define E(x) x, STRINGIFY(x)
94 {E(EV_NULL), "", nullptr, nullptr, nullptr},
95 {E(EV_RESET), "bb", CL_Reset, nullptr, nullptr},
96 {E(EV_START), "b", CL_StartGame, nullptr, nullptr},
97 {E(EV_ENDROUND), "b", CL_DoEndRound, nullptr, nullptr},
98 {E(EV_ENDROUNDANNOUNCE), "bb", CL_EndRoundAnnounce, nullptr, nullptr},
99
100 {E(EV_RESULTS), "", CL_ParseResults, CL_ParseResultsTime, nullptr}, /* manually parsed */
101 {E(EV_CENTERVIEW), "g", CL_CenterView, nullptr, nullptr},
102 {E(EV_MOVECAMERA), "g", CL_MoveView, nullptr, nullptr},
103
104 {E(EV_ENT_APPEAR), "sbg", CL_EntAppear, CL_EntAppearTime, nullptr},
105 {E(EV_ENT_PERISH), "sb", CL_EntPerish, nullptr, nullptr},
106 {E(EV_ENT_DESTROY), "s", CL_EntDestroy, nullptr, nullptr},
107 {E(EV_ADD_BRUSH_MODEL), "sbsbppsbb", CL_AddBrushModel, nullptr, nullptr},
108 {E(EV_ADD_EDICT), "sbpp", CL_AddEdict, nullptr, nullptr},
109
110 {E(EV_ACTOR_APPEAR), "!s!sbbbsbgbssssbbsbbbs", CL_ActorAppear, CL_ActorAppearTime, CL_CheckDefault},
111 {E(EV_ACTOR_ADD), "!sbbbbgsb", CL_ActorAdd, nullptr, nullptr},
112 {E(EV_ACTOR_TURN), "sb", CL_ActorDoTurn, nullptr, nullptr},
113 {E(EV_ACTOR_MOVE), "sbsss!lg", CL_ActorDoMove, CL_ActorDoMoveTime, CL_CheckDefault}, /* Don't use this format string - see CL_ActorDoMove for more info */
114 {E(EV_ACTOR_REACTIONFIRECHANGE), "sbbs", CL_ActorReactionFireChange, nullptr, nullptr},
119
121 {E(EV_ACTOR_SHOOT), "ssbsbbbbbppb", CL_ActorDoShoot, CL_ActorDoShootTime, nullptr},
123 {E(EV_ACTOR_THROW), "ssbbbpp", CL_ActorDoThrow, CL_ActorDoThrowTime, nullptr},
125
128 {E(EV_ACTOR_STATS), "!sbsbb", CL_ActorStats, nullptr, nullptr},
130 {E(EV_ACTOR_RESERVATIONCHANGE), "ssss", CL_ActorReservationChange, nullptr, nullptr},
131 {E(EV_ACTOR_WOUND), "sbbb", CL_ActorWound, nullptr, nullptr},
132
135 {E(EV_INV_AMMO), "sbbbbb", CL_InvAmmo, nullptr, nullptr},
136 {E(EV_INV_RELOAD), "sbbbbb", CL_InvReload, CL_InvReloadTime, nullptr},
138 {E(EV_INV_TRANSFER), "sbsbbbbs", nullptr, nullptr, nullptr},
139
140 {E(EV_MODEL_EXPLODE), "s&", CL_Explode, CL_ExplodeTime, nullptr},
141 {E(EV_MODEL_EXPLODE_TRIGGERED), "s&", CL_Explode, nullptr, nullptr},
142
145
146 {E(EV_SOUND), "spb&", CL_SoundEvent, CL_SoundEventTime, nullptr},
147
148 {E(EV_DOOR_OPEN), "s", CL_DoorOpen, nullptr, nullptr},
149 {E(EV_DOOR_CLOSE), "s", CL_DoorClose, nullptr, nullptr},
150 {E(EV_CLIENT_ACTION), "ss", CL_ActorClientAction, nullptr, nullptr},
151 {E(EV_RESET_CLIENT_ACTION), "s", CL_ActorResetClientAction, nullptr, nullptr},
152 {E(EV_CAMERA_APPEAR), "spbbbbb", CL_CameraAppear, nullptr, nullptr},
153#undef E
154};
156
158{
159 for (int i = EV_NULL; i < EV_NUM_EVENTS; i++) {
160 if (events[i].type == eType)
161 return &events[i];
162 }
163
164 Com_Error(ERR_DROP, "Could not get format string for event type %i", eType);
165}
166
177int CL_GetStepTime (const eventTiming_t* eventTiming, const le_t* le, int step)
178{
179 const leStep_t* list = le->stepList;
180 if (list == nullptr)
181 return eventTiming->nextTime;
182 for (int i = 0; i < le->stepIndex; i++) {
183 list = list->next;
184 }
185 if (step < 0) {
186 Com_Printf("invalid step given: %i/%i (entnum: %i with stepindex: %i)\n", step, list->steps, le->entnum, le->stepIndex);
187 return list->lastMoveTime;
188 }
189 if (step > list->steps) {
190 Com_Printf("invalid step given: %i/%i (entnum: %i with stepindex: %i)\n", step, list->steps, le->entnum, le->stepIndex);
191 return list->lastMoveTime + list->lastMoveDuration;
192 }
193 int delay = 0;
194 for (int i = 0; i < list->steps; i++) {
195 if (i > step)
196 break;
197 delay += list->stepTimes[i];
198 }
199 const int eventTime = list->lastMoveTime + delay;
200 return eventTime;
201}
202
203int CL_GetNextTime (const eventRegister_t* event, eventTiming_t* eventTiming, int nextTime)
204{
205 if (nextTime < eventTiming->nextTime) {
206 Com_DPrintf(DEBUG_EVENTSYS, "CL_GetNextTime: nexttime is invalid (%i/%i): %s\n", nextTime, eventTiming->nextTime, event->name);
207 return eventTiming->nextTime;
208 }
209 return nextTime;
210}
211
219const char* CL_ConvertSoundFromEvent (char* sound, size_t size)
220{
221 /* Plain file name? Just return it unchanged */
222 const size_t length = strlen(sound) - 1;
223 if (sound[length] != '+')
224 return sound;
225
226 /* Otherwise we are going to replace the '+' with a random number */
227 sound[length] = '\0';
228
229 /* First we need check how many files we can choose from (if any) */
230 int i;
231 for (i = 0; i < 99; i++)
232 if (FS_CheckFile("sounds/%s%02i", sound, i + 1) == -1)
233 break;
234
235 /* Knowing that we can now choose a random one */
236 if (i > 0) {
237 Q_strcat(sound, size, "%02i", rand() % i + 1);
238 return sound;
239 }
240
241 return "";
242}
bool LE_IsLocked(int entnum)
Checks if a given le_t structure is locked, i.e., used by another event at this time.
Primary header for client.
void Com_DPrintf(int level, const char *fmt,...)
A Com_Printf that only shows up if the "developer" cvar is set.
Definition common.cpp:440
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
#define DEBUG_EVENTSYS
Definition defines.h:64
void CL_ActorAdd(const eventRegister_t *self, dbuffer *msg)
Adds an hidden actor to the list of le's.
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 CL_ActorClientAction(const eventRegister_t *self, dbuffer *msg)
Reads the entity number for client interaction.
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...
int CL_ActorEndShootTime(const eventRegister_t *self, dbuffer *msg, eventTiming_t *eventTiming)
Decides if following events should be delayed.
void CL_ActorEndShoot(const eventRegister_t *self, dbuffer *msg)
Ends shooting with actor.
void CL_ActorDoMove(const eventRegister_t *self, dbuffer *msg)
Moves actor.
int CL_ActorDoMoveTime(const eventRegister_t *self, dbuffer *msg, eventTiming_t *eventTiming)
Decides if following events should be delayed. The delay is the amount of time the actor needs to wal...
void CL_ActorReactionFireAbortShot(const eventRegister_t *self, dbuffer *msg)
Network event function for reaction fire target handling. Responsible for updating the HUD with the i...
int CL_ActorReactionFireAbortShotTime(const eventRegister_t *self, dbuffer *msg, eventTiming_t *eventTiming)
void CL_ActorReactionFireAddTarget(const eventRegister_t *self, dbuffer *msg)
Network event function for reaction fire target handling. Responsible for updating the HUD with the i...
int CL_ActorReactionFireAddTargetTime(const eventRegister_t *self, dbuffer *msg, eventTiming_t *eventTiming)
void CL_ActorReactionFireChange(const eventRegister_t *self, dbuffer *msg)
Network event function for reaction fire mode changes. Responsible for updating the HUD with the info...
int CL_ActorReactionFireRemoveTargetTime(const eventRegister_t *self, dbuffer *msg, eventTiming_t *eventTiming)
void CL_ActorReactionFireRemoveTarget(const eventRegister_t *self, dbuffer *msg)
Network event function for reaction fire target handling. Responsible for updating the HUD with the i...
void CL_ActorReactionFireTargetUpdate(const eventRegister_t *self, dbuffer *msg)
Network event function for reaction fire target handling. Responsible for updating the HUD with the i...
int CL_ActorReactionFireTargetUpdateTime(const eventRegister_t *self, dbuffer *msg, eventTiming_t *eventTiming)
void CL_ActorReservationChange(const eventRegister_t *self, dbuffer *msg)
Network event function for TU reservation. Responsible for updating the HUD with the information that...
void CL_ActorResetClientAction(const eventRegister_t *self, dbuffer *msg)
When no trigger is touched, the client actions are reset.
void CL_ActorRevitalised(const eventRegister_t *self, dbuffer *msg)
Revitalizes a stunned actor (all that is needed is the local entity state set).
int CL_ActorDoShootTime(const eventRegister_t *self, dbuffer *msg, eventTiming_t *eventTiming)
Decides if following events should be delayed. If the projectile has a speed value assigned,...
void CL_ActorDoShoot(const eventRegister_t *self, dbuffer *msg)
Shoot with weapon.
int CL_ActorShootHiddenTime(const eventRegister_t *self, dbuffer *msg, eventTiming_t *eventTiming)
Decides if following events should be delayed.
void CL_ActorShootHidden(const eventRegister_t *self, dbuffer *msg)
Shoot with weapon but don't bother with animations - actor is hidden.
void CL_ActorStartShoot(const eventRegister_t *self, dbuffer *msg)
Starts shooting with actor.
int CL_ActorStartShootTime(const eventRegister_t *self, dbuffer *msg, eventTiming_t *eventTiming)
Decides if following events should be delayed.
void CL_ActorStateChange(const eventRegister_t *self, dbuffer *msg)
void CL_ActorStats(const eventRegister_t *self, dbuffer *msg)
Parses the actor stats that comes from the netchannel.
int CL_ActorDoThrowTime(const eventRegister_t *self, dbuffer *msg, eventTiming_t *eventTiming)
Decides if following events should be delayed.
void CL_ActorDoThrow(const eventRegister_t *self, dbuffer *msg)
Throw item with actor.
void CL_ActorDoTurn(const eventRegister_t *self, dbuffer *msg)
Turns actor.
void CL_ActorWound(const eventRegister_t *self, dbuffer *msg)
Parses the actor wound stats that come from the netchannel.
void CL_AddBrushModel(const eventRegister_t *self, dbuffer *msg)
Register local entities for SOLID_BSP models like func_breakable or func_door.
void CL_AddEdict(const eventRegister_t *self, dbuffer *msg)
Adds server side edicts to the client for displaying them.
void CL_CameraAppear(const eventRegister_t *self, dbuffer *msg)
Adds a camera edicts to the client for displaying them.
void CL_CenterView(const eventRegister_t *self, dbuffer *msg)
void CL_MoveView(const eventRegister_t *self, dbuffer *msg)
void CL_DoEndRound(const eventRegister_t *self, dbuffer *msg)
Performs end-of-turn processing.
void CL_DoorClose(const eventRegister_t *self, dbuffer *msg)
Callback for EV_DOOR_CLOSE event - rotates the inline model and recalc routing.
void CL_DoorOpen(const eventRegister_t *self, dbuffer *msg)
Callback for EV_DOOR_OPEN event - rotates the inline model and recalc routing.
void CL_EndRoundAnnounce(const eventRegister_t *self, dbuffer *msg)
Announces that a player ends his turn.
int CL_EntAppearTime(const struct eventRegister_s *self, dbuffer *msg, eventTiming_t *eventTiming)
void CL_EntAppear(const eventRegister_t *self, dbuffer *msg)
Let an entity appear - like an item on the ground that just got visible.
void CL_EntDestroy(const eventRegister_t *self, dbuffer *msg)
Called whenever an entity is destroyed in the server.
void CL_EntPerish(const eventRegister_t *self, dbuffer *msg)
Called whenever an entity disappears from view.
void CL_Explode(const eventRegister_t *self, dbuffer *msg)
int CL_ExplodeTime(const struct eventRegister_s *self, dbuffer *msg, eventTiming_t *eventTiming)
Decides when the explode event should get executed. This in the impact time.
int CL_InvAddTime(const struct eventRegister_s *self, dbuffer *msg, eventTiming_t *eventTiming)
Decides if following events should be delayed.
void CL_InvAdd(const eventRegister_t *self, dbuffer *msg)
void CL_InvAmmo(const eventRegister_t *self, dbuffer *msg)
int CL_InvDelTime(const struct eventRegister_s *self, dbuffer *msg, eventTiming_t *eventTiming)
Decides if following events should be delayed.
void CL_InvDel(const eventRegister_t *self, dbuffer *msg)
int CL_InvReloadTime(const eventRegister_t *self, dbuffer *msg, eventTiming_t *eventTiming)
void CL_InvReload(const eventRegister_t *self, dbuffer *msg)
int CL_ParticleAppearTime(const struct eventRegister_s *self, dbuffer *msg, eventTiming_t *eventTiming)
void CL_ParticleAppear(const eventRegister_t *self, dbuffer *msg)
Let a particle appear for the client.
int CL_ParticleSpawnEventTime(const struct eventRegister_s *self, dbuffer *msg, eventTiming_t *eventTiming)
void CL_ParticleSpawnEvent(const eventRegister_t *self, dbuffer *msg)
Let a particle spawn for the client.
void CL_Reset(const eventRegister_t *self, dbuffer *msg)
void CL_ParseResults(const eventRegister_t *self, dbuffer *msg)
Reads mission result data from server.
int CL_ParseResultsTime(const struct eventRegister_s *self, dbuffer *msg, eventTiming_t *eventTiming)
void CL_SoundEvent(const eventRegister_t *self, dbuffer *msg)
Play a sound on the client side.
int CL_SoundEventTime(const struct eventRegister_s *self, dbuffer *msg, eventTiming_t *eventTiming)
void CL_StartGame(const eventRegister_t *self, dbuffer *msg)
Activates the map render screen (ca_active).
#define E(x)
const char * CL_ConvertSoundFromEvent(char *sound, size_t size)
Some sound strings may end on a '+' to indicate to use a random sound which can be identified by repl...
Definition e_main.cpp:219
const eventRegister_t * CL_GetEvent(const event_t eType)
Definition e_main.cpp:157
static bool CL_CheckDefault(const eventRegister_t *self, const dbuffer *msg)
A default check function that assumes the entnum is the first short in msg.
Definition e_main.cpp:79
int CL_GetStepTime(const eventTiming_t *eventTiming, const le_t *le, int step)
Calculates the time when the given step was executed in the event chain.
Definition e_main.cpp:177
const eventRegister_t events[]
List of functions to register nodes.
Definition e_main.cpp:92
int CL_GetNextTime(const eventRegister_t *event, eventTiming_t *eventTiming, int nextTime)
Definition e_main.cpp:203
int FS_CheckFile(const char *fmt,...)
Just returns the filelength and -1 if the file wasn't found.
Definition files.cpp:298
voidpf void uLong size
Definition ioapi.h:42
int NET_PeekShort(const dbuffer *buf)
Peeks into a buffer without changing it to get a short int.
Definition netpack.cpp:264
event_t
Possible event values.
Definition q_shared.h:79
@ EV_ACTOR_REACTIONFIRECHANGE
Definition q_shared.h:101
@ EV_ACTOR_SHOOT
Definition q_shared.h:108
@ EV_INV_TRANSFER
Definition q_shared.h:124
@ EV_INV_AMMO
Definition q_shared.h:122
@ EV_DOOR_CLOSE
Definition q_shared.h:136
@ EV_ACTOR_REACTIONFIRETARGETUPDATE
Definition q_shared.h:104
@ EV_NUM_EVENTS
Definition q_shared.h:142
@ EV_ACTOR_REACTIONFIREABORTSHOT
Definition q_shared.h:105
@ EV_ENDROUND
Definition q_shared.h:83
@ EV_ACTOR_WOUND
Definition q_shared.h:118
@ EV_MODEL_EXPLODE_TRIGGERED
Definition q_shared.h:128
@ EV_ACTOR_STATECHANGE
Definition q_shared.h:116
@ EV_ADD_EDICT
Definition q_shared.h:95
@ EV_ACTOR_STATS
Definition q_shared.h:115
@ EV_ENDROUNDANNOUNCE
Definition q_shared.h:84
@ EV_MODEL_EXPLODE
Definition q_shared.h:127
@ EV_CAMERA_APPEAR
Definition q_shared.h:140
@ EV_NULL
Definition q_shared.h:80
@ EV_INV_RELOAD
Definition q_shared.h:123
@ EV_RESULTS
Definition q_shared.h:86
@ EV_ADD_BRUSH_MODEL
Definition q_shared.h:94
@ EV_START
Definition q_shared.h:82
@ EV_ENT_PERISH
Definition q_shared.h:91
@ EV_CENTERVIEW
Definition q_shared.h:87
@ EV_INV_DEL
Definition q_shared.h:121
@ EV_ACTOR_REACTIONFIREADDTARGET
Definition q_shared.h:102
@ EV_PARTICLE_APPEAR
Definition q_shared.h:130
@ EV_ENT_DESTROY
Definition q_shared.h:93
@ EV_ACTOR_END_SHOOT
Definition q_shared.h:111
@ EV_DOOR_OPEN
Definition q_shared.h:135
@ EV_CLIENT_ACTION
Definition q_shared.h:137
@ EV_MOVECAMERA
Definition q_shared.h:88
@ EV_ACTOR_THROW
Definition q_shared.h:110
@ EV_ACTOR_APPEAR
Definition q_shared.h:97
@ EV_ACTOR_MOVE
Definition q_shared.h:100
@ EV_ACTOR_REVITALISED
Definition q_shared.h:114
@ EV_RESET
Definition q_shared.h:81
@ EV_ACTOR_START_SHOOT
Definition q_shared.h:107
@ EV_ACTOR_SHOOT_HIDDEN
Definition q_shared.h:109
@ EV_ACTOR_TURN
Definition q_shared.h:99
@ EV_ACTOR_RESERVATIONCHANGE
Definition q_shared.h:117
@ EV_PARTICLE_SPAWN
Definition q_shared.h:131
@ EV_RESET_CLIENT_ACTION
Definition q_shared.h:138
@ EV_ENT_APPEAR
Definition q_shared.h:90
@ EV_ACTOR_ADD
Definition q_shared.h:98
@ EV_SOUND
Definition q_shared.h:133
@ EV_ACTOR_DIE
Definition q_shared.h:113
@ EV_INV_ADD
Definition q_shared.h:120
@ EV_ACTOR_REACTIONFIREREMOVETARGET
Definition q_shared.h:103
QGL_EXTERN GLuint GLsizei GLsizei * length
Definition r_gl.h:110
QGL_EXTERN GLint i
Definition r_gl.h:113
QGL_EXTERN GLint GLenum type
Definition r_gl.h:94
#define lengthof(x)
Definition shared.h:105
#define CASSERT(x)
Definition shared.h:107
void Q_strcat(char *dest, size_t destsize, const char *format,...)
Safely (without overflowing the destination buffer) concatenates two strings.
Definition shared.cpp:475
Struct that defines one particular event with all its callbacks and data.
Definition e_main.h:42
const char * name
the name of this event (e.g. for logs)
Definition e_main.h:50
CL_ParseEvent timers and vars.
Definition e_main.h:30
int nextTime
Definition e_main.h:31
a local entity
leStep_t * stepList
int stepIndex
int entnum
int stepTimes[MAX_ROUTE]
int lastMoveDuration
struct leStep_s * next