UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
e_main.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_localentity.h"
27 #include "e_main.h"
72 
79 static 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 };
155 CASSERT(lengthof(events) == EV_NUM_EVENTS);
156 
157 const eventRegister_t* CL_GetEvent (const event_t eType)
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 
177 int 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 
203 int 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 
219 const 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 }
void CL_EndRoundAnnounce(const eventRegister_t *self, dbuffer *msg)
Announces that a player ends his turn.
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...
void CL_ActorRevitalised(const eventRegister_t *self, dbuffer *msg)
Revitalizes a stunned actor (all that is needed is the local entity state set).
void CL_AddEdict(const eventRegister_t *self, dbuffer *msg)
Adds server side edicts to the client for displaying them.
int FS_CheckFile(const char *fmt,...)
Just returns the filelength and -1 if the file wasn't found.
Definition: files.cpp:298
void CL_ActorDoMove(const eventRegister_t *self, dbuffer *msg)
Moves actor.
#define DEBUG_EVENTSYS
Definition: defines.h:64
void CL_Reset(const eventRegister_t *self, dbuffer *msg)
QGL_EXTERN GLint GLenum type
Definition: r_gl.h:94
void CL_ActorDoThrow(const eventRegister_t *self, dbuffer *msg)
Throw item with actor.
int CL_ParticleAppearTime(const struct eventRegister_s *self, dbuffer *msg, eventTiming_t *eventTiming)
#define E(x)
int CL_InvAddTime(const struct eventRegister_s *self, dbuffer *msg, eventTiming_t *eventTiming)
Decides if following events should be delayed.
void CL_ParseResults(const eventRegister_t *self, dbuffer *msg)
Reads mission result data from server.
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 entnum
void CL_ParticleAppear(const eventRegister_t *self, dbuffer *msg)
Let a particle appear for the client.
void CL_ActorDoTurn(const eventRegister_t *self, dbuffer *msg)
Turns actor.
void CL_InvDel(const eventRegister_t *self, dbuffer *msg)
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_ActorWound(const eventRegister_t *self, dbuffer *msg)
Parses the actor wound stats that come from the netchannel.
int CL_ActorShootHiddenTime(const eventRegister_t *self, dbuffer *msg, eventTiming_t *eventTiming)
Decides if following events should be delayed.
int CL_GetNextTime(const eventRegister_t *event, eventTiming_t *eventTiming, int nextTime)
Definition: e_main.cpp:203
void CL_ActorStats(const eventRegister_t *self, dbuffer *msg)
Parses the actor stats that comes from the netchannel.
bool LE_IsLocked(int entnum)
Checks if a given le_t structure is locked, i.e., used by another event at this time.
void CL_InvReload(const eventRegister_t *self, dbuffer *msg)
void CL_DoorOpen(const eventRegister_t *self, dbuffer *msg)
Callback for EV_DOOR_OPEN event - rotates the inline model and recalc routing.
int CL_ActorReactionFireRemoveTargetTime(const eventRegister_t *self, dbuffer *msg, eventTiming_t *eventTiming)
int NET_PeekShort(const dbuffer *buf)
Peeks into a buffer without changing it to get a short int.
Definition: netpack.cpp:264
void CL_ActorAppear(const eventRegister_t *self, dbuffer *msg)
void CL_ActorShootHidden(const eventRegister_t *self, dbuffer *msg)
Shoot with weapon but don't bother with animations - actor is hidden.
void CL_ActorDoShoot(const eventRegister_t *self, dbuffer *msg)
Shoot with weapon.
void Com_Printf(const char *const fmt,...)
Definition: common.cpp:386
int CL_EntAppearTime(const struct eventRegister_s *self, dbuffer *msg, eventTiming_t *eventTiming)
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_ExplodeTime(const struct eventRegister_s *self, dbuffer *msg, eventTiming_t *eventTiming)
Decides when the explode event should get executed. This in the impact time.
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_InvAdd(const eventRegister_t *self, dbuffer *msg)
int CL_ParseResultsTime(const struct eventRegister_s *self, dbuffer *msg, eventTiming_t *eventTiming)
int stepTimes[MAX_ROUTE]
CL_ParseEvent timers and vars.
Definition: e_main.h:30
void CL_ActorAdd(const eventRegister_t *self, dbuffer *msg)
Adds an hidden actor to the list of le's.
void Com_Error(int code, const char *fmt,...)
Definition: common.cpp:417
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...
int lastMoveTime
#define ERR_DROP
Definition: common.h:211
int CL_ActorStartShootTime(const eventRegister_t *self, dbuffer *msg, eventTiming_t *eventTiming)
Decides if following events should be delayed.
GLsizei size
Definition: r_gl.h:152
void CL_ParticleSpawnEvent(const eventRegister_t *self, dbuffer *msg)
Let a particle spawn for the client.
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
QGL_EXTERN GLuint GLsizei GLsizei * length
Definition: r_gl.h:110
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_ParticleSpawnEventTime(const struct eventRegister_s *self, dbuffer *msg, eventTiming_t *eventTiming)
void CL_InvAmmo(const eventRegister_t *self, dbuffer *msg)
const eventRegister_t * CL_GetEvent(const event_t eType)
Definition: e_main.cpp:157
event_t
Possible event values.
Definition: q_shared.h:79
int lastMoveDuration
void CL_AddBrushModel(const eventRegister_t *self, dbuffer *msg)
Register local entities for SOLID_BSP models like func_breakable or func_door.
struct leStep_s * next
int stepIndex
void CL_ActorStateChange(const eventRegister_t *self, dbuffer *msg)
int CL_ActorReactionFireAbortShotTime(const eventRegister_t *self, dbuffer *msg, eventTiming_t *eventTiming)
int CL_ActorAppearTime(const eventRegister_t *self, dbuffer *msg, eventTiming_t *eventTiming)
Decides if following events should be delayed.
void Com_DPrintf(int level, const char *fmt,...)
A Com_Printf that only shows up if the "developer" cvar is set.
Definition: common.cpp:398
void CL_CenterView(const eventRegister_t *self, dbuffer *msg)
Struct that defines one particular event with all its callbacks and data.
Definition: e_main.h:42
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
void CL_DoorClose(const eventRegister_t *self, dbuffer *msg)
Callback for EV_DOOR_CLOSE event - rotates the inline model and recalc routing.
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...
CASSERT(lengthof(events)==EV_NUM_EVENTS)
a local entity
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_CameraAppear(const eventRegister_t *self, dbuffer *msg)
Adds a camera edicts to the client for displaying them.
int CL_ActorEndShootTime(const eventRegister_t *self, dbuffer *msg, eventTiming_t *eventTiming)
Decides if following events should be delayed.
int CL_ActorReactionFireAddTargetTime(const eventRegister_t *self, dbuffer *msg, eventTiming_t *eventTiming)
void CL_ActorStartShoot(const eventRegister_t *self, dbuffer *msg)
Starts shooting with actor.
void CL_Explode(const eventRegister_t *self, dbuffer *msg)
const eventRegister_t events[]
List of functions to register nodes.
Definition: e_main.cpp:92
int CL_ActorDoThrowTime(const eventRegister_t *self, dbuffer *msg, eventTiming_t *eventTiming)
Decides if following events should be delayed.
void CL_ActorResetClientAction(const eventRegister_t *self, dbuffer *msg)
When no trigger is touched, the client actions are reset.
const char * name
the name of this event (e.g. for logs)
Definition: e_main.h:50
QGL_EXTERN GLint i
Definition: r_gl.h:113
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_EntAppear(const eventRegister_t *self, dbuffer *msg)
Let an entity appear - like an item on the ground that just got visible.
void CL_ActorClientAction(const eventRegister_t *self, dbuffer *msg)
Reads the entity number for client interaction.
void Q_strcat(char *dest, size_t destsize, const char *format,...)
Safely (without overflowing the destination buffer) concatenates two strings.
Definition: shared.cpp:475
int CL_InvDelTime(const struct eventRegister_s *self, dbuffer *msg, eventTiming_t *eventTiming)
Decides if following events should be delayed.
void CL_EntPerish(const eventRegister_t *self, dbuffer *msg)
Called whenever an entity disappears from view.
void CL_EntDestroy(const eventRegister_t *self, dbuffer *msg)
Called whenever an entity is destroyed in the server.
#define lengthof(x)
Definition: shared.h:105
int CL_ActorReactionFireTargetUpdateTime(const eventRegister_t *self, dbuffer *msg, eventTiming_t *eventTiming)
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_SoundEventTime(const struct eventRegister_s *self, dbuffer *msg, eventTiming_t *eventTiming)
int nextTime
Definition: e_main.h:31
leStep_t * stepList
void CL_DoEndRound(const eventRegister_t *self, dbuffer *msg)
Performs end-of-turn processing.
void CL_MoveView(const eventRegister_t *self, dbuffer *msg)
void CL_SoundEvent(const eventRegister_t *self, dbuffer *msg)
Play a sound on the client side.
void CL_ActorEndShoot(const eventRegister_t *self, dbuffer *msg)
Ends shooting with actor.
int CL_InvReloadTime(const eventRegister_t *self, dbuffer *msg, eventTiming_t *eventTiming)
void CL_StartGame(const eventRegister_t *self, dbuffer *msg)
Activates the map render screen (ca_active)