UFO: Alien Invasion
Loading...
Searching...
No Matches
sv_game.cpp
Go to the documentation of this file.
1
5
6/*
7All original material Copyright (C) 2002-2025 UFO: Alien Invasion.
8
9Original file from Quake 2 v3.21: quake2-2.31/server/sv_game.c
10Copyright (C) 1997-2001 Id Software, Inc.
11
12This program is free software; you can redistribute it and/or
13modify it under the terms of the GNU General Public License
14as published by the Free Software Foundation; either version 2
15of the License, or (at your option) any later version.
16
17This program is distributed in the hope that it will be useful,
18but WITHOUT ANY WARRANTY; without even the implied warranty of
19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20
21See the GNU General Public License for more details.
22
23You should have received a copy of the GNU General Public License
24along with this program; if not, write to the Free Software
25Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26*/
27
28#include "server.h"
29#include "sv_log.h"
30#include "../common/grid.h"
31#include "../common/routing.h"
32#include "../ports/system.h"
33#include "../shared/thread.h"
35
39static void SV_dprintf (const char* fmt, ...)
40{
41 va_list ap;
42
43 va_start(ap, fmt);
44 SV_LogAdd(fmt, ap);
45 va_end(ap);
46}
47
52static void SV_PlayerPrintf (const SrvPlayer* player, int level, const char* fmt, va_list ap)
53{
54 if (level == PRINT_NONE)
55 return;
56
57 if (player) {
58 char msg[1024];
59 Q_vsnprintf(msg, sizeof(msg), fmt, ap);
60 client_t* cl = SV_GetClient(player->getNum());
61 SV_ClientPrintf(cl, level, "%s", msg);
62 } else
63 SV_LogAdd(fmt, ap);
64}
65
69static float SV_GetVisibility (const pos3_t position)
70{
71 return CM_GetVisibility(&sv->mapTiles, position);
72}
73
74static void SV_error (const char* fmt, ...) __attribute__((noreturn));
79static void SV_error (const char* fmt, ...)
80{
81 char msg[1024];
82 va_list argptr;
83
84 va_start(argptr, fmt);
85 Q_vsnprintf(msg, sizeof(msg), fmt, argptr);
86 va_end(argptr);
87
88 Com_Error(ERR_DROP, "Game Error: %s", msg);
89}
90
99static unsigned int SV_FindIndex (const char* name, int start, int max, bool create)
100{
101 int i;
102
103 if (!name || !name[0])
104 return 0;
105
106 for (i = 1; i < max && SV_GetConfigString(start + i)[0] != '\0'; i++) {
107 const char* configString = SV_GetConfigString(start + i);
108 if (Q_streq(configString, name))
109 return i;
110 }
111
112 if (!create)
113 return 0;
114
115 if (i == max)
116 SV_error("*Index: overflow '%s' start: %i, max: %i", name, start, max);
117
118 SV_SetConfigString(start + i, name);
119
120 if (Com_ServerState() != ss_loading) { /* send the update to everyone */
121 dbuffer msg(4 + strlen(name));
123 NET_WriteShort(&msg, start + i);
124 NET_WriteString(&msg, name);
125 SV_Multicast(~0, msg);
126 }
127
128 return i;
129}
130
131static unsigned int SV_ModelIndex (const char* name)
132{
133 return SV_FindIndex(name, CS_MODELS, MAX_MODELS, true);
134}
135
140static void SV_SetModel (edict_t* ent, const char* name)
141{
142 if (!name)
143 SV_error("SV_SetModel: nullptr");
144
146
147 /* if it is an inline model, get the size information for it */
148 if (name[0] == '*') {
149 const cBspModel_t* mod = CM_InlineModel(&sv->mapTiles, name);
150 /* Copy model mins and maxs to entity */
151 ent->entBox.set(mod->cbmBox);
152 /* This is to help the entity collision code out */
153 /* Copy entity origin and angles to model*/
154 CM_SetInlineModelOrientation(&sv->mapTiles, name, ent->origin, ent->angles);
155 }
156}
157
161static void SV_Configstring (int index, const char* fmt, ...)
162{
164 va_list argptr;
165
167 SV_error("configstring: bad index %i", index);
168
169 va_start(argptr, fmt);
170 Q_vsnprintf(val, sizeof(val), fmt, argptr);
171 va_end(argptr);
172
174
175 if (Com_ServerState() != ss_loading) { /* send the update to everyone */
176 dbuffer msg(4 + strlen(val));
178 NET_WriteShort(&msg, index);
179 NET_WriteString(&msg, val);
180
181 /* send to all clients */
182 SV_Multicast(~0, msg);
183 }
184}
185
186static void SV_WriteChar (char c)
187{
188 NET_WriteChar(sv->pendingEvent.buf, c);
189}
190
191static void SV_WriteByte (byte c)
192{
193 NET_WriteByte(sv->pendingEvent.buf, c);
194}
195
196static void SV_WriteShort (int c)
197{
198 NET_WriteShort(sv->pendingEvent.buf, c);
199}
200
201static void SV_WriteLong (int c)
202{
203 NET_WriteLong(sv->pendingEvent.buf, c);
204}
205
206static void SV_WriteString (const char* s)
207{
208 NET_WriteString(sv->pendingEvent.buf, s);
209}
210
211static void SV_WritePos (const vec3_t pos)
212{
213 NET_WritePos(sv->pendingEvent.buf, pos);
214}
215
216static void SV_WriteGPos (const pos3_t pos)
217{
218 NET_WriteGPos(sv->pendingEvent.buf, pos);
219}
220
221static void SV_WriteDir (const vec3_t dir)
222{
223 NET_WriteDir(sv->pendingEvent.buf, dir);
224}
225
226static void SV_WriteAngle (float f)
227{
228 NET_WriteAngle(sv->pendingEvent.buf, f);
229}
230
231static void SV_WriteFormat (const char* format, ...)
232{
233 va_list ap;
234 va_start(ap, format);
235 NET_vWriteFormat(sv->pendingEvent.buf, format, ap);
236 va_end(ap);
237}
238
239static int SV_ReadChar (void)
240{
241 return NET_ReadChar(sv->messageBuffer);
242}
243
244static int SV_ReadByte (void)
245{
246 return NET_ReadByte(sv->messageBuffer);
247}
248
249static int SV_ReadShort (void)
250{
251 return NET_ReadShort(sv->messageBuffer);
252}
253
254static int SV_ReadLong (void)
255{
256 return NET_ReadLong(sv->messageBuffer);
257}
258
259static int SV_ReadString (char* str, size_t length)
260{
261 return NET_ReadString(sv->messageBuffer, str, length);
262}
263
264static void SV_ReadPos (vec3_t pos)
265{
266 NET_ReadPos(sv->messageBuffer, pos);
267}
268
269static void SV_ReadGPos (pos3_t pos)
270{
271 NET_ReadGPos(sv->messageBuffer, pos);
272}
273
274static void SV_ReadDir (vec3_t vector)
275{
276 NET_ReadDir(sv->messageBuffer, vector);
277}
278
279static float SV_ReadAngle (void)
280{
281 return NET_ReadAngle(sv->messageBuffer);
282}
283
284static void SV_ReadData (void* buffer, int size)
285{
286 NET_ReadData(sv->messageBuffer, buffer, size);
287}
288
292static void SV_ReadFormat (const char* format, ...)
293{
294 va_list ap;
295
296 assert(format);
297 if (!*format) /* PA_NULL */
298 return;
299
300 va_start(ap, format);
301 NET_vReadFormat(sv->messageBuffer, format, ap);
302 va_end(ap);
303}
304
308static void SV_AbortEvents (void)
309{
310 pending_event_t* p = &sv->pendingEvent;
311
312 if (!p->pending)
313 return;
314
315 p->pending = false;
316 delete p->buf;
317 p->buf = nullptr;
318}
319
320static void SV_SendQueuedEvents (void)
321{
322 for (int i = 0; i < sv->eventQueuePos; i++) {
323 pending_event_t& entry = sv->eventQueue[i];
324 NET_WriteByte(entry.buf, EV_NULL);
325 SV_Multicast(entry.playerMask, *entry.buf);
326 delete entry.buf;
327 }
328 sv->eventQueuePos = 0;
329}
330
334static void SV_EndEvents (void)
335{
336 pending_event_t* p = &sv->pendingEvent;
337
338 if (!p->pending) {
340 return;
341 }
342
344 SV_Multicast(p->playerMask, *p->buf);
345 p->pending = false;
346 delete p->buf;
347 p->buf = nullptr;
348
350}
351
352typedef struct {
353 const char* name;
355
356#define M(x) { #x }
418#undef M
420
427static void SV_AddEvent (unsigned int mask, int eType, int entnum)
428{
429 pending_event_t* p = &sv->pendingEvent;
430 const int rawType = eType &~ EVENT_INSTANTLY;
431
432 if (rawType >= EV_NUM_EVENTS || rawType < 0)
433 Com_Error(ERR_DROP, "SV_AddEvent: invalid event %i", rawType);
434
435 const char* eventName = eventNames[rawType].name;
436 Com_DPrintf(DEBUG_EVENTSYS, "Event type: %s (%i - %i) (mask %s) (entnum: %i)\n", eventName,
437 rawType, eType, Com_UnsignedIntToBinary(mask), entnum);
438
439 /* finish the last event */
440 if (p->pending)
441 SV_EndEvents();
442 else
444
445 /* start the new event */
446 p->pending = true;
447 p->playerMask = mask;
448 p->type = eType;
449 p->entnum = entnum;
450 p->buf = new dbuffer();
451
452 /* write header */
454 NET_WriteByte(p->buf, eType);
455 if (entnum != -1)
456 NET_WriteShort(p->buf, entnum);
457}
458
465static void SV_QueueEvent (unsigned int mask, int eType, int entnum)
466{
467 if (sv->eventQueuePos > lengthof(sv->eventQueue))
468 Com_Error(ERR_DROP, "overflow in SV_QueueEvent");
469
470 const int rawType = eType &~ EVENT_INSTANTLY;
471
472 if (rawType >= EV_NUM_EVENTS || rawType < 0)
473 Com_Error(ERR_DROP, "SV_QueueEvent: invalid event %i", rawType);
474
475 const char* eventName = eventNames[rawType].name;
476 Com_DPrintf(DEBUG_EVENTSYS, "Queued event type: %s (%i - %i) (mask %s) (entnum: %i)\n", eventName,
477 rawType, eType, Com_UnsignedIntToBinary(mask), entnum);
478
479 pending_event_t& p = sv->eventQueue[sv->eventQueuePos++];
480
481 /* start the new event */
482 p.pending = false;
483 p.playerMask = mask;
484 p.type = eType;
485 p.entnum = entnum;
486 p.buf = new dbuffer();
487 /* write header */
489 NET_WriteByte(p.buf, eType);
490 if (p.entnum != -1)
492}
493
494static void SV_QueueWriteByte (byte c)
495{
496 NET_WriteByte(sv->eventQueue[sv->eventQueuePos - 1].buf, c);
497}
498
499static void SV_QueueWriteString (const char* s)
500{
501 NET_WriteString(sv->eventQueue[sv->eventQueuePos - 1].buf, s);
502}
503
504static void SV_QueueWritePos (const vec3_t pos)
505{
506 NET_WritePos(sv->eventQueue[sv->eventQueuePos - 1].buf, pos);
507}
508
509static void SV_QueueWriteShort (int c)
510{
511 NET_WriteShort(sv->eventQueue[sv->eventQueuePos - 1].buf, c);
512}
513
517static int SV_GetEvent (void)
518{
519 const pending_event_t* p = &sv->pendingEvent;
520 if (!p->pending)
521 return -1;
522
523 return p->type;
524}
525
527{
528 const pending_event_t* p = &sv->pendingEvent;
529 if (!p->pending)
530 return nullptr;
531
532 if (p->entnum == -1)
533 return nullptr;
534
535 const sv_edict_t& e = sv->edicts[p->entnum];
536 return e.ent;
537}
538
542static void* SV_TagAlloc (int size, int tagNum, const char* file, int line)
543{
544 if (tagNum < 0)
545 tagNum *= -1;
546
547 return _Mem_Alloc(size, true, sv->gameSysPool, tagNum, file, line);
548}
549
550static void SV_MemFree (void* ptr, const char* file, int line)
551{
552 _Mem_Free(ptr, file, line);
553}
554
558static void SV_FreeTags (int tagNum, const char* file, int line)
559{
560 if (tagNum < 0)
561 tagNum *= -1;
562
563 _Mem_FreeTag(sv->gameSysPool, tagNum, file, line);
564}
565
566static bool SV_TestLine (const vec3_t start, const vec3_t stop, const int levelmask)
567{
568 return TR_TestLine(&sv->mapTiles, start, stop, levelmask);
569}
570
571static bool SV_TestLineWithEnt (const vec3_t start, const vec3_t stop, const int levelmask, const char** entlist)
572{
573 /* do the line test */
574 const bool hit = CM_EntTestLine(&sv->mapTiles, Line(start, stop), levelmask, entlist);
575 return hit;
576}
577
578static pos_t SV_GridFall (const int actorSize, const pos3_t pos)
579{
580 return Grid_Fall(sv->mapData.routing, actorSize, pos);
581}
582
583static void SV_RecalcRouting (const char* name, const GridBox& box, const char** list)
584{
585 Grid_RecalcRouting(&sv->mapTiles, sv->mapData.routing, name, box, list);
586}
587
588static void SV_GridPosToVec (const int actorSize, const pos3_t pos, vec3_t vec)
589{
590 Grid_PosToVec(sv->mapData.routing, actorSize, pos, vec);
591}
592
593static bool SV_GridIsOnMap (const vec3_t vec)
594{
595 return sv->mapData.mapBox.contains(vec);
596}
597
598static void SV_GridCalcPathing (actorSizeEnum_t actorSize, pathing_t* path, const pos3_t from, int distance, forbiddenList_t* forbiddenList)
599{
600 Grid_CalcPathing(sv->mapData.routing, actorSize, path, from, distance, forbiddenList);
601}
602
603static bool SV_GridFindPath (actorSizeEnum_t actorSize, pathing_t* path, const pos3_t from, const pos3_t targetPos, byte crouchingState, int maxTUs, forbiddenList_t* forbiddenList)
604{
605 return Grid_FindPath(sv->mapData.routing, actorSize, path, from, targetPos, crouchingState, maxTUs, forbiddenList);
606}
607
608static bool SV_CanActorStandHere (const int actorSize, const pos3_t pos)
609{
610 return RT_CanActorStandHere(sv->mapData.routing, actorSize, pos);
611}
612
613static void SV_SetInlineModelOrientation (const char* name, const vec3_t origin, const vec3_t angles)
614{
615 CM_SetInlineModelOrientation(&sv->mapTiles, name, origin, angles);
616}
617
618static void SV_GetInlineModelAABB (const char* name, AABB& aabb)
619{
620 CM_GetInlineModelAABB(&sv->mapTiles, name, aabb);
621}
622
623static void SV_UnloadGame (void)
624{
625#ifndef HARD_LINKED_GAME
626 if (svs.gameLibrary) {
627 Com_Printf("Unload the game library\n");
628 SDL_UnloadObject(svs.gameLibrary);
629 }
630#endif
631}
632
637{
638#ifndef HARD_LINKED_GAME
639 typedef game_export_t* (*game_api_t) (game_import_t*);
640 game_api_t GetGameAPI;
641 const char* path;
642
643 if (svs.gameLibrary)
644 Com_Error(ERR_FATAL, "SV_GetGameAPI without SV_UnloadGame");
645
646 Com_Printf("------- Loading game.%s -------\n", SO_EXT);
647
648#ifdef PKGLIBDIR
649 svs.gameLibrary = Com_LoadLibrary(PKGLIBDIR, "game");
650#endif
651
652 /* now run through the search paths */
653 path = nullptr;
654 while (!svs.gameLibrary) {
655 path = FS_NextPath(path);
656 if (!path)
657 /* couldn't find one anywhere */
658 return nullptr;
659 svs.gameLibrary = Com_LoadLibrary(path, "game");
660 if (svs.gameLibrary != nullptr)
661 break;
662 }
663
664 GetGameAPI = (game_api_t)(uintptr_t)SDL_LoadFunction(svs.gameLibrary, "GetGameAPI");
665 if (!GetGameAPI) {
667 return nullptr;
668 }
669#endif
670
671 return GetGameAPI(parms);
672}
673
674static char const* const gameSysPoolName = "Server: Game system";
675
682{
683 uint32_t size;
684
685 if (!svs.ge)
686 return;
687
689
690 if (svs.gameThread) {
691 SDL_CondSignal(svs.gameFrameCond);
692 SDL_WaitThread(svs.gameThread, nullptr);
693 SDL_DestroyCond(svs.gameFrameCond);
694 svs.gameFrameCond = nullptr;
695 svs.gameThread = nullptr;
696 }
697
698 svs.ge->Shutdown();
699
700 size = Mem_PoolSize(sv->gameSysPool);
701 if (size > 0) {
702 Com_Printf("WARNING: Game memory leak (%u bytes)\n", size);
703 Cmd_ExecuteString("mem_stats %s", gameSysPoolName);
704 }
705
706 Mem_DeletePool(sv->gameSysPool);
707 sv->gameSysPool = nullptr;
708
710
711 svs.ge = nullptr;
712}
713
720{
721 do {
722 const ScopedMutex scopedMutex(svs.serverMutex);
723 SDL_CondWait(svs.gameFrameCond, svs.serverMutex);
725 } while (!sv->endgame);
726
727 return 0;
728}
729
737{
738 sv->endgame = svs.ge->RunFrame();
739 if (sv->state == ss_game_shutdown)
740 sv->endgame = true;
741}
742
748{
749 game_import_t import;
750
751 /* unload anything we have now */
752 /*SV_ShutdownGameProgs();*/
753
754 /* load a new game dll */
755 import.BroadcastPrintf = SV_BroadcastPrintf;
756 import.DPrintf = SV_dprintf;
757 import.PlayerPrintf = SV_PlayerPrintf;
758 import.Error = SV_error;
759
760 import.Trace = SV_Trace;
761 import.LinkEdict = SV_LinkEdict;
762 import.UnlinkEdict = SV_UnlinkEdict;
763
764 import.TestLine = SV_TestLine;
765 import.TestLineWithEnt = SV_TestLineWithEnt;
766 import.GrenadeTarget = Com_GrenadeTarget;
767
768 import.GridCalcPathing = SV_GridCalcPathing;
769 import.GridFindPath = SV_GridFindPath;
770 import.MoveStore = Grid_MoveStore;
771 import.MoveLength = Grid_MoveLength;
772 import.MoveNext = Grid_MoveNext;
773 import.GetTUsForDirection = Grid_GetTUsForDirection;
774 import.GridFall = SV_GridFall;
775 import.GridPosToVec = SV_GridPosToVec;
776 import.isOnMap = SV_GridIsOnMap;
777 import.GridRecalcRouting = SV_RecalcRouting;
778 import.CanActorStandHere = SV_CanActorStandHere;
779 import.GridShouldUseAutostand = Grid_ShouldUseAutostand;
780
781 import.GetVisibility = SV_GetVisibility;
782
783 import.ModelIndex = SV_ModelIndex;
784
785 import.SetInlineModelOrientation = SV_SetInlineModelOrientation;
786 import.GetInlineModelAABB = SV_GetInlineModelAABB;
787
788 import.SetModel = SV_SetModel;
789
790 import.ConfigString = SV_Configstring;
791
792 import.PointContents = SV_PointContents;
793 import.GetFootstepSound = SV_GetFootstepSound;
794 import.GetBounceFraction = SV_GetBounceFraction;
795 import.LoadModelAABB = SV_LoadModelAABB;
796
797 import.FS_Gamedir = FS_Gamedir;
798 import.FS_LoadFile = FS_LoadFile;
799 import.FS_FreeFile = FS_FreeFile;
800 import.Sys_Fopen = Sys_Fopen;
801
802 import.WriteChar = SV_WriteChar;
803 import.WriteByte = SV_WriteByte;
804 import.WriteShort = SV_WriteShort;
805 import.WriteLong = SV_WriteLong;
806 import.WriteString = SV_WriteString;
807 import.WritePos = SV_WritePos;
808 import.WriteGPos = SV_WriteGPos;
809 import.WriteDir = SV_WriteDir;
810 import.WriteAngle = SV_WriteAngle;
811 import.WriteFormat = SV_WriteFormat;
812
813 import.AbortEvents = SV_AbortEvents;
814 import.EndEvents = SV_EndEvents;
815 import.AddEvent = SV_AddEvent;
816 import.GetEvent = SV_GetEvent;
817 import.GetEventEdict = SV_GetEventEdict;
818
819 import.QueueEvent = SV_QueueEvent;
820 import.QueueWriteByte = SV_QueueWriteByte;
821 import.QueueWritePos = SV_QueueWritePos;
822 import.QueueWriteString = SV_QueueWriteString;
823 import.QueueWriteShort = SV_QueueWriteShort;
824
825 import.ReadChar = SV_ReadChar;
826 import.ReadByte = SV_ReadByte;
827 import.ReadShort = SV_ReadShort;
828 import.ReadLong = SV_ReadLong;
829 import.ReadString = SV_ReadString;
830 import.ReadPos = SV_ReadPos;
831 import.ReadGPos = SV_ReadGPos;
832 import.ReadDir = SV_ReadDir;
833 import.ReadAngle = SV_ReadAngle;
834 import.ReadData = SV_ReadData;
835 import.ReadFormat = SV_ReadFormat;
836
837 import.GetConstInt = Com_GetConstInt;
838 import.GetConstIntFromNamespace = Com_GetConstIntFromNamespace;
839 import.GetConstVariable = Com_GetConstVariable;
840 import.RegisterConstInt = Com_RegisterConstInt;
841 import.UnregisterConstVariable = Com_UnregisterConstVariable;
842
843 import.GetCharacterValues = Com_GetCharacterValues;
844
845 import.TagMalloc = SV_TagAlloc;
846 import.TagFree = SV_MemFree;
847 import.FreeTags = SV_FreeTags;
848
849 import.Cvar_Get = Cvar_Get;
850 import.Cvar_Set = Cvar_Set;
851 import.Cvar_String = Cvar_GetString;
852
853 import.Cmd_Argc = Cmd_Argc;
854 import.Cmd_Argv = Cmd_Argv;
855 import.Cmd_Args = Cmd_Args;
856 import.AddCommandString = Cbuf_AddText;
857
858 import.seed = Sys_Milliseconds();
859 import.csi = &csi;
860
861 Com_Printf("setting game random seed to %i\n", import.seed);
862
863 svs.ge = SV_GetGameAPI(&import);
864
865 if (!svs.ge)
866 Com_Error(ERR_DROP, "failed to load game library");
867 if (svs.ge->apiversion != GAME_API_VERSION)
868 Com_Error(ERR_DROP, "game is version %i, not %i", svs.ge->apiversion, GAME_API_VERSION);
869
870 sv->gameSysPool = Mem_CreatePool(gameSysPoolName);
871
872 svs.ge->Init();
873
874 if (sv_threads->integer) {
875 svs.gameFrameCond = SDL_CreateCond();
876 svs.gameThread = Com_CreateThread(SV_RunGameFrameThread, "GameThread");
877 }
878}
static forbiddenList_t forbiddenList
A list of locations that cannot be moved to.
Definition cl_actor.cpp:602
clientBattleScape_t cl
void * _Mem_Alloc(size_t size, bool zeroFill, memPool_t *pool, const int tagNum, const char *fileName, const int fileLine)
Definition aabb.h:42
void set(const AABB &other)
Copies the values from the given aabb.
Definition aabb.h:60
Definition line.h:31
int modelindex
Definition srvedict.h:54
vec3_t angles
Definition srvedict.h:43
AABB entBox
Definition srvedict.h:48
vec3_t origin
Definition srvedict.h:42
int getNum(void) const
Definition game.h:58
void Cmd_ExecuteString(const char *text,...)
A complete command line has been parsed, so try to execute it.
Definition cmd.cpp:1007
const char * Cmd_Argv(int arg)
Returns a given argument.
Definition cmd.cpp:516
const char * Cmd_Args(void)
Returns a single string containing argv(1) to argv(argc()-1).
Definition cmd.cpp:526
int Cmd_Argc(void)
Return the number of arguments of the current command. "command parameter" will result in a argc of 2...
Definition cmd.cpp:505
void Cbuf_AddText(const char *format,...)
Adds command text at the end of the buffer.
Definition cmd.cpp:126
bool CM_EntTestLine(mapTiles_t *mapTiles, const Line &traceLine, const int levelmask, const char **entlist)
Checks traces against the world and all inline models.
Definition cmodel.cpp:184
void CM_GetInlineModelAABB(mapTiles_t *mapTiles, const char *name, AABB &aabb)
This function calculates a model's aabb in world coordinates.
Definition bsp.cpp:979
cBspModel_t * CM_SetInlineModelOrientation(mapTiles_t *mapTiles, const char *name, const vec3_t origin, const vec3_t angles)
This function updates a model's orientation.
Definition bsp.cpp:963
float CM_GetVisibility(const mapTiles_t *mapTiles, const pos3_t position)
Checks how well a position is visible.
Definition bsp.cpp:991
cBspModel_t * CM_InlineModel(const mapTiles_t *mapTiles, const char *name)
Searches all inline models and return the cBspModel_t pointer for the given modelnumber or -name.
Definition bsp.cpp:929
bool RT_CanActorStandHere(const Routing &routing, const int actorSize, const pos3_t pos)
Check if an actor can stand(up) in the cell given by pos.
Definition routing.cpp:237
csi_t csi
Definition common.cpp:39
void Com_SetServerState(int state)
Definition common.cpp:587
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
int Com_ServerState(void)
Check whether we are the server or have a singleplayer tactical mission.
Definition common.cpp:578
float Com_GrenadeTarget(const vec3_t from, const vec3_t at, float speed, bool launched, bool rolled, vec3_t v0)
Calculates parabola-type shot.
Definition common.cpp:273
void * Com_LoadLibrary(const char *path, const char *prefix)
Attempts to load a library using a filename suffix list.
Definition common.cpp:126
void Com_Error(int code, const char *fmt,...)
Definition common.cpp:459
const char * Com_UnsignedIntToBinary(uint32_t x)
Definition common.cpp:1038
void Com_Printf(const char *const fmt,...)
Definition common.cpp:428
bool Com_CheckConfigStringIndex(int index)
Definition common.cpp:877
@ svc_event
Definition common.h:155
@ svc_configstring
Definition common.h:154
#define ERR_DROP
Definition common.h:211
#define ERR_FATAL
Definition common.h:210
#define PKGLIBDIR
cvar_t * Cvar_Set(const char *varName, const char *value,...)
Sets a cvar value.
Definition cvar.cpp:615
cvar_t * Cvar_Get(const char *var_name, const char *var_value, int flags, const char *desc)
Init or return a cvar.
Definition cvar.cpp:342
const char * Cvar_GetString(const char *varName)
Returns the value of cvar as string.
Definition cvar.cpp:210
#define __attribute__(x)
Definition cxx.h:37
#define DEBUG_EVENTSYS
Definition defines.h:64
#define MAX_TOKEN_CHARS
Definition defines.h:372
#define PRINT_NONE
Definition defines.h:105
#define MAX_MODELS
Definition defines.h:100
const char * FS_NextPath(const char *prevpath)
Allows enumerating all of the directories in the search path.
Definition files.cpp:614
int FS_LoadFile(const char *path, byte **buffer)
Filenames are relative to the quake search path.
Definition files.cpp:384
void FS_FreeFile(void *buffer)
Definition files.cpp:411
const char * FS_Gamedir(void)
Called to find where to write a file (savegames, etc).
Definition files.cpp:68
level_locals_t level
Definition g_main.cpp:38
game_export_t * GetGameAPI(game_import_t *import)
Returns a pointer to the structure with all entry points and global variables.
Definition g_main.cpp:384
SrvEdict edict_t
Definition game.h:164
#define GAME_API_VERSION
Definition game.h:35
void Grid_CalcPathing(const Routing &routing, const actorSizeEnum_t actorSize, pathing_t *path, const pos3_t from, int maxTUs, forbiddenList_t *fb_list)
Recalculate the pathing table for the given actor(-position).
Definition grid.cpp:497
pos_t Grid_MoveLength(const pathing_t *path, const pos3_t to, byte crouchingState, bool stored)
Return the needed TUs to walk to a given position.
Definition grid.cpp:698
int Grid_GetTUsForDirection(const int dir, bool crouched)
Returns the amounts of TUs that are needed to perform one step into the given direction.
Definition grid.cpp:766
pos_t Grid_Fall(const Routing &routing, const actorSizeEnum_t actorSize, const pos3_t pos)
Calculated the new height level when something falls down from a certain position.
Definition grid.cpp:783
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
bool Grid_ShouldUseAutostand(const pathing_t *path, const pos3_t toPos)
Checks if a crouched actor could save TUs by standing up, walking and crouching again.
Definition grid.cpp:818
void Grid_MoveStore(pathing_t *path)
Caches the calculated move.
Definition grid.cpp:683
int Grid_MoveNext(const pathing_t *path, const pos3_t toPos, byte crouchingState)
Get the direction to use to move to a position (used to reconstruct the path).
Definition grid.cpp:719
bool Grid_FindPath(const Routing &routing, const actorSizeEnum_t actorSize, pathing_t *path, const pos3_t from, const pos3_t targetPos, byte crouchingState, int maxTUs, forbiddenList_t *forbiddenList)
Tries to find a path from the given actor(-position) to a given target position.
Definition grid.cpp:590
void Grid_RecalcRouting(mapTiles_t *mapTiles, Routing &routing, const char *name, const GridBox &box, const char **list)
This function recalculates the routing surrounding the entity name.
Definition grid.cpp:922
Battlescape grid functions.
voidpf void uLong size
Definition ioapi.h:42
voidpf uLong int origin
Definition ioapi.h:45
void _Mem_FreeTag(memPool_t *pool, const int tagNum, const char *fileName, const int fileLine)
Free memory blocks assigned to a specified tag within a pool.
Definition mem.cpp:243
void _Mem_Free(void *ptr, const char *fileName, const int fileLine)
Definition mem.cpp:204
#define Mem_DeletePool(pool)
Definition mem.h:33
#define Mem_PoolSize(pool)
Definition mem.h:51
#define Mem_CreatePool(name)
Definition mem.h:32
int NET_ReadString(dbuffer *buf, char *string, size_t length)
Definition netpack.cpp:302
float NET_ReadAngle(dbuffer *buf)
Definition netpack.cpp:383
void NET_ReadData(dbuffer *buf, void *data, int len)
Definition netpack.cpp:394
void NET_WriteShort(dbuffer *buf, int c)
Definition netpack.cpp:45
void NET_WriteDir(dbuffer *buf, const vec3_t dir)
Definition netpack.cpp:124
void NET_vReadFormat(dbuffer *buf, const char *format, va_list ap)
Reads from a buffer according to format; version without syntactic sugar for variable arguments,...
Definition netpack.cpp:415
void NET_ReadDir(dbuffer *buf, vec3_t dir)
Definition netpack.cpp:400
void NET_vWriteFormat(dbuffer *buf, const char *format, va_list ap)
Writes to buffer according to format; version without syntactic sugar for variable arguments,...
Definition netpack.cpp:149
void NET_WriteGPos(dbuffer *buf, const pos3_t pos)
Definition netpack.cpp:103
void NET_ReadPos(dbuffer *buf, vec3_t pos)
Definition netpack.cpp:364
int NET_ReadLong(dbuffer *buf)
Definition netpack.cpp:282
int NET_ReadChar(dbuffer *buf)
Definition netpack.cpp:221
int NET_ReadByte(dbuffer *buf)
Reads a byte from the netchannel.
Definition netpack.cpp:234
int NET_ReadShort(dbuffer *buf)
Definition netpack.cpp:242
void NET_WriteAngle(dbuffer *buf, float f)
Definition netpack.cpp:110
void NET_WriteByte(dbuffer *buf, byte c)
Definition netpack.cpp:39
void NET_WriteLong(dbuffer *buf, int c)
Definition netpack.cpp:52
void NET_WriteChar(dbuffer *buf, char c)
Definition netpack.cpp:33
void NET_WritePos(dbuffer *buf, const vec3_t pos)
Definition netpack.cpp:96
void NET_WriteString(dbuffer *buf, const char *str)
Definition netpack.cpp:59
void NET_ReadGPos(dbuffer *buf, pos3_t pos)
Definition netpack.cpp:376
@ 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
#define MAX_TILESTRINGS
Definition q_shared.h:298
void format(__printf__, 1, 2)))
#define CS_MODELS
Definition q_shared.h:327
QGL_EXTERN GLsizei const GLvoid * data
Definition r_gl.h:89
QGL_EXTERN GLuint GLsizei GLsizei * length
Definition r_gl.h:110
QGL_EXTERN GLuint index
Definition r_gl.h:110
QGL_EXTERN GLfloat f
Definition r_gl.h:114
QGL_EXTERN GLint i
Definition r_gl.h:113
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition r_gl.h:110
grid pathfinding and routing
void Com_RegisterConstInt(const char *name, int value)
Register mappings between script strings and enum values for values of the type V_INT.
Definition scripts.cpp:198
bool Com_UnregisterConstVariable(const char *name)
Removes a registered constant from the script mapping hash table.
Definition scripts.cpp:147
bool Com_GetConstIntFromNamespace(const char *space, const char *variable, int *value)
Searches whether a given value was registered as a string to int mapping.
Definition scripts.cpp:103
void Com_GetCharacterValues(const char *teamDefition, character_t *chr)
Assign character values, 3D models and names to a character.
Definition scripts.cpp:2408
bool Com_GetConstInt(const char *name, int *value)
Searches whether a given value was registered as a string to int mapping.
Definition scripts.cpp:74
const char * Com_GetConstVariable(const char *space, int value)
Searches the mapping variable for a given integer value and a namespace.
Definition scripts.cpp:122
Main server include file.
char * SV_GetConfigString(int index)
Definition sv_main.cpp:77
const char * SV_GetFootstepSound(const char *texture)
Query the footstep sound for the given surface texture.
Definition sv_world.cpp:451
trace_t SV_Trace(const Line &traceLine, const AABB &box, const edict_t *passedict, int contentmask)
Moves the given mins/maxs volume through the world from start to end.
Definition sv_world.cpp:417
client_t * SV_GetClient(int index)
Definition sv_main.cpp:174
void SV_LinkEdict(edict_t *ent)
Needs to be called any time an entity changes origin, mins, maxs, or solid. Automatically unlinks if ...
Definition sv_world.cpp:131
void SV_Multicast(int mask, const dbuffer &msg)
Sends the contents of msg to a subset of the clients, then frees msg.
Definition sv_send.cpp:126
void void SV_ClientPrintf(client_t *cl, int level, const char *fmt,...) __attribute__((format(__printf__
cvar_t * sv_threads
Definition sv_main.cpp:48
float SV_GetBounceFraction(const char *texture)
Different terrain types might have different bounce fraction.
Definition sv_world.cpp:462
@ ss_game_shutdown
Definition server.h:100
@ ss_loading
Definition server.h:98
bool SV_LoadModelAABB(const char *model, int frame, AABB &aabb)
Load the bounding box for the model on the serverside for pathfinding and clipping.
Definition sv_world.cpp:543
serverInstanceGame_t * sv
Definition sv_init.cpp:36
void void void SV_BroadcastPrintf(int level, const char *fmt,...) __attribute__((format(__printf__
#define SV_SetConfigString(index, value)
Definition server.h:188
void SV_UnlinkEdict(edict_t *ent)
call before removing an entity, and before trying to move one, so it doesn't clip against itself
Definition sv_world.cpp:97
serverInstanceStatic_t svs
Definition sv_init.cpp:35
int SV_RunGameFrameThread(void *data)
Thread for the game frame function.
Definition sv_game.cpp:719
int SV_PointContents(const vec3_t p)
Returns the content flags for a given point.
Definition sv_world.cpp:395
#define Q_streq(a, b)
Definition shared.h:136
#define lengthof(x)
Definition shared.h:105
#define CASSERT(x)
Definition shared.h:107
int Q_vsnprintf(char *str, size_t size, const char *format, va_list ap)
Safe (null terminating) vsnprintf implementation.
Definition shared.cpp:535
AABB cbmBox
Definition typedefs.h:27
const char * name
Definition sv_game.cpp:353
A list of locations that cannot be moved to.
Definition grid.h:35
functions exported by the game subsystem
Definition game.h:317
functions provided by the main engine
Definition game.h:173
dbuffer * buf
Definition server.h:73
edict_t * ent
Definition server.h:43
static game_export_t * SV_GetGameAPI(game_import_t *parms)
Loads the game shared library and calls the api init function.
Definition sv_game.cpp:636
static void SV_WriteLong(int c)
Definition sv_game.cpp:201
static int SV_ReadByte(void)
Definition sv_game.cpp:244
static void SV_ReadGPos(pos3_t pos)
Definition sv_game.cpp:269
static void SV_QueueWriteShort(int c)
Definition sv_game.cpp:509
static void SV_WriteGPos(const pos3_t pos)
Definition sv_game.cpp:216
static void SV_SetModel(edict_t *ent, const char *name)
Definition sv_game.cpp:140
static float SV_GetVisibility(const pos3_t position)
Glue function to get the visibility from a given position.
Definition sv_game.cpp:69
static void SV_QueueEvent(unsigned int mask, int eType, int entnum)
Definition sv_game.cpp:465
static void SV_GetInlineModelAABB(const char *name, AABB &aabb)
Definition sv_game.cpp:618
static int SV_ReadChar(void)
Definition sv_game.cpp:239
static void SV_WritePos(const vec3_t pos)
Definition sv_game.cpp:211
static void SV_EndEvents(void)
Definition sv_game.cpp:334
void SV_ShutdownGameProgs(void)
Called when either the entire server is being killed, or it is changing to a different game directory...
Definition sv_game.cpp:681
static float SV_ReadAngle(void)
Definition sv_game.cpp:279
static void SV_WriteFormat(const char *format,...)
Definition sv_game.cpp:231
static void SV_SetInlineModelOrientation(const char *name, const vec3_t origin, const vec3_t angles)
Definition sv_game.cpp:613
static void SV_ReadPos(vec3_t pos)
Definition sv_game.cpp:264
static void SV_dprintf(const char *fmt,...)
Debug print to server console.
Definition sv_game.cpp:39
static void SV_WriteDir(const vec3_t dir)
Definition sv_game.cpp:221
static bool SV_TestLineWithEnt(const vec3_t start, const vec3_t stop, const int levelmask, const char **entlist)
Definition sv_game.cpp:571
static void SV_error(const char *fmt,...) __attribute__((noreturn))
Abort the server with a game error.
Definition sv_game.cpp:79
static bool SV_TestLine(const vec3_t start, const vec3_t stop, const int levelmask)
Definition sv_game.cpp:566
static bool SV_CanActorStandHere(const int actorSize, const pos3_t pos)
Definition sv_game.cpp:608
static void SV_RecalcRouting(const char *name, const GridBox &box, const char **list)
Definition sv_game.cpp:583
static int SV_ReadLong(void)
Definition sv_game.cpp:254
static edict_t * SV_GetEventEdict(void)
Definition sv_game.cpp:526
static void SV_ReadDir(vec3_t vector)
Definition sv_game.cpp:274
void SV_InitGameProgs(void)
Init the game subsystem for a new map.
Definition sv_game.cpp:747
static unsigned int SV_ModelIndex(const char *name)
Definition sv_game.cpp:131
static void SV_WriteChar(char c)
Definition sv_game.cpp:186
static unsigned int SV_FindIndex(const char *name, int start, int max, bool create)
Search the index in the config strings relative to a given start.
Definition sv_game.cpp:99
static void SV_UnloadGame(void)
Definition sv_game.cpp:623
static void SV_ReadFormat(const char *format,...)
Definition sv_game.cpp:292
static void SV_QueueWriteString(const char *s)
Definition sv_game.cpp:499
static void SV_QueueWritePos(const vec3_t pos)
Definition sv_game.cpp:504
static void SV_MemFree(void *ptr, const char *file, int line)
Definition sv_game.cpp:550
static void SV_PlayerPrintf(const SrvPlayer *player, int level, const char *fmt, va_list ap)
Print to a single client.
Definition sv_game.cpp:52
static void SV_AbortEvents(void)
Definition sv_game.cpp:308
static void * SV_TagAlloc(int size, int tagNum, const char *file, int line)
Makes sure the game DLL does not use client, or signed tags.
Definition sv_game.cpp:542
void SV_RunGameFrame(void)
Calls the G_RunFrame function from game api let everything in the world think and move.
Definition sv_game.cpp:736
static int SV_ReadString(char *str, size_t length)
Definition sv_game.cpp:259
static int SV_ReadShort(void)
Definition sv_game.cpp:249
static void SV_AddEvent(unsigned int mask, int eType, int entnum)
Definition sv_game.cpp:427
static void SV_Configstring(int index, const char *fmt,...)
Definition sv_game.cpp:161
static bool SV_GridFindPath(actorSizeEnum_t actorSize, pathing_t *path, const pos3_t from, const pos3_t targetPos, byte crouchingState, int maxTUs, forbiddenList_t *forbiddenList)
Definition sv_game.cpp:603
static void SV_ReadData(void *buffer, int size)
Definition sv_game.cpp:284
static void SV_SendQueuedEvents(void)
Definition sv_game.cpp:320
static bool SV_GridIsOnMap(const vec3_t vec)
Definition sv_game.cpp:593
static void SV_FreeTags(int tagNum, const char *file, int line)
Makes sure the game DLL does not use client, or signed tags.
Definition sv_game.cpp:558
static void SV_WriteByte(byte c)
Definition sv_game.cpp:191
static void SV_WriteString(const char *s)
Definition sv_game.cpp:206
static void SV_QueueWriteByte(byte c)
Definition sv_game.cpp:494
static void SV_WriteAngle(float f)
Definition sv_game.cpp:226
int SV_RunGameFrameThread(void *data)
Thread for the game frame function.
Definition sv_game.cpp:719
static int SV_GetEvent(void)
Definition sv_game.cpp:517
static const eventNames_t eventNames[]
Definition sv_game.cpp:357
#define M(x)
Definition sv_game.cpp:356
static char const *const gameSysPoolName
Definition sv_game.cpp:674
static pos_t SV_GridFall(const int actorSize, const pos3_t pos)
Definition sv_game.cpp:578
static void SV_GridCalcPathing(actorSizeEnum_t actorSize, pathing_t *path, const pos3_t from, int distance, forbiddenList_t *forbiddenList)
Definition sv_game.cpp:598
static void SV_GridPosToVec(const int actorSize, const pos3_t pos, vec3_t vec)
Definition sv_game.cpp:588
static void SV_WriteShort(int c)
Definition sv_game.cpp:196
void SV_LogAdd(const char *format, va_list ap)
Async version to add a log entry for the game lib.
Definition sv_log.cpp:60
game lib logging handling
System specific stuff.
FILE * Sys_Fopen(const char *filename, const char *mode)
int Sys_Milliseconds(void)
SDL_Thread * Com_CreateThread(int(*fn)(void *), const char *name, void *data=nullptr)
Definition thread.h:5
bool TR_TestLine(mapTiles_t *mapTiles, const vec3_t start, const vec3_t end, const int levelmask)
Checks traces against the world.
Definition tracing.cpp:310
pos_t pos3_t[3]
Definition ufotypes.h:58
byte pos_t
Definition ufotypes.h:57
vec_t vec3_t[3]
Definition ufotypes.h:39
int32_t actorSizeEnum_t
Definition ufotypes.h:77