123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430 |
- #include "g_local.h"
- game_locals_t game;
- level_locals_t level;
- game_import_t gi;
- game_export_t globals;
- spawn_temp_t st;
- int sm_meat_index;
- int snd_fry;
- int meansOfDeath;
- edict_t *g_edicts;
- cvar_t *deathmatch;
- cvar_t *coop;
- cvar_t *dmflags;
- cvar_t *skill;
- cvar_t *fraglimit;
- cvar_t *timelimit;
- cvar_t *capturelimit;
- cvar_t *instantweap;
- cvar_t *password;
- cvar_t *maxclients;
- cvar_t *maxentities;
- cvar_t *g_select_empty;
- cvar_t *dedicated;
- cvar_t *filterban;
- cvar_t *sv_maxvelocity;
- cvar_t *sv_gravity;
- cvar_t *sv_rollspeed;
- cvar_t *sv_rollangle;
- cvar_t *gun_x;
- cvar_t *gun_y;
- cvar_t *gun_z;
- cvar_t *run_pitch;
- cvar_t *run_roll;
- cvar_t *bob_up;
- cvar_t *bob_pitch;
- cvar_t *bob_roll;
- cvar_t *sv_cheats;
- cvar_t *flood_msgs;
- cvar_t *flood_persecond;
- cvar_t *flood_waitdelay;
- cvar_t *sv_maplist;
- void SpawnEntities (char *mapname, char *entities, char *spawnpoint);
- void ClientThink (edict_t *ent, usercmd_t *cmd);
- qboolean ClientConnect (edict_t *ent, char *userinfo);
- void ClientUserinfoChanged (edict_t *ent, char *userinfo);
- void ClientDisconnect (edict_t *ent);
- void ClientBegin (edict_t *ent);
- void ClientCommand (edict_t *ent);
- void RunEntity (edict_t *ent);
- void WriteGame (char *filename, qboolean autosave);
- void ReadGame (char *filename);
- void WriteLevel (char *filename);
- void ReadLevel (char *filename);
- void InitGame (void);
- void G_RunFrame (void);
- void ShutdownGame (void)
- {
- gi.dprintf ("==== ShutdownGame ====\n");
- gi.FreeTags (TAG_LEVEL);
- gi.FreeTags (TAG_GAME);
- }
- game_export_t *GetGameAPI (game_import_t *import)
- {
- gi = *import;
- globals.apiversion = GAME_API_VERSION;
- globals.Init = InitGame;
- globals.Shutdown = ShutdownGame;
- globals.SpawnEntities = SpawnEntities;
- globals.WriteGame = WriteGame;
- globals.ReadGame = ReadGame;
- globals.WriteLevel = WriteLevel;
- globals.ReadLevel = ReadLevel;
- globals.ClientThink = ClientThink;
- globals.ClientConnect = ClientConnect;
- globals.ClientUserinfoChanged = ClientUserinfoChanged;
- globals.ClientDisconnect = ClientDisconnect;
- globals.ClientBegin = ClientBegin;
- globals.ClientCommand = ClientCommand;
- globals.RunFrame = G_RunFrame;
- globals.ServerCommand = ServerCommand;
- globals.edict_size = sizeof(edict_t);
- return &globals;
- }
- #ifndef GAME_HARD_LINKED
- void Sys_Error (char *error, ...)
- {
- va_list argptr;
- char text[1024];
- va_start (argptr, error);
- vsprintf (text, error, argptr);
- va_end (argptr);
- gi.error (ERR_FATAL, "%s", text);
- }
- void Com_Printf (char *msg, ...)
- {
- va_list argptr;
- char text[1024];
- va_start (argptr, msg);
- vsprintf (text, msg, argptr);
- va_end (argptr);
- gi.dprintf ("%s", text);
- }
- #endif
- void ClientEndServerFrames (void)
- {
- int i;
- edict_t *ent;
-
-
- for (i=0 ; i<maxclients->value ; i++)
- {
- ent = g_edicts + 1 + i;
- if (!ent->inuse || !ent->client)
- continue;
- ClientEndServerFrame (ent);
- }
- }
- edict_t *CreateTargetChangeLevel(char *map)
- {
- edict_t *ent;
- ent = G_Spawn ();
- ent->classname = "target_changelevel";
- Com_sprintf(level.nextmap, sizeof(level.nextmap), "%s", map);
- ent->map = level.nextmap;
- return ent;
- }
- void EndDMLevel (void)
- {
- edict_t *ent;
- char *s, *t, *f;
- static const char *seps = " ,\n\r";
-
- if ((int)dmflags->value & DF_SAME_LEVEL)
- {
- BeginIntermission (CreateTargetChangeLevel (level.mapname) );
- return;
- }
- if (*level.forcemap) {
- BeginIntermission (CreateTargetChangeLevel (level.forcemap) );
- return;
- }
-
- if (*sv_maplist->string) {
- s = strdup(sv_maplist->string);
- f = NULL;
- t = strtok(s, seps);
- while (t != NULL) {
- if (Q_stricmp(t, level.mapname) == 0) {
-
- t = strtok(NULL, seps);
- if (t == NULL) {
- if (f == NULL)
- BeginIntermission (CreateTargetChangeLevel (level.mapname) );
- else
- BeginIntermission (CreateTargetChangeLevel (f) );
- } else
- BeginIntermission (CreateTargetChangeLevel (t) );
- free(s);
- return;
- }
- if (!f)
- f = t;
- t = strtok(NULL, seps);
- }
- free(s);
- }
- if (level.nextmap[0])
- BeginIntermission (CreateTargetChangeLevel (level.nextmap) );
- else {
- ent = G_Find (NULL, FOFS(classname), "target_changelevel");
- if (!ent)
- {
-
- BeginIntermission (CreateTargetChangeLevel (level.mapname) );
- return;
- }
- BeginIntermission (ent);
- }
- }
- void CheckDMRules (void)
- {
- int i;
- gclient_t *cl;
- if (level.intermissiontime)
- return;
- if (!deathmatch->value)
- return;
- if (ctf->value && CTFCheckRules()) {
- EndDMLevel ();
- return;
- }
- if (CTFInMatch())
- return;
- if (timelimit->value)
- {
- if (level.time >= timelimit->value*60)
- {
- gi.bprintf (PRINT_HIGH, "Timelimit hit.\n");
- EndDMLevel ();
- return;
- }
- }
- if (fraglimit->value)
- for (i=0 ; i<maxclients->value ; i++)
- {
- cl = game.clients + i;
- if (!g_edicts[i+1].inuse)
- continue;
- if (cl->resp.score >= fraglimit->value)
- {
- gi.bprintf (PRINT_HIGH, "Fraglimit hit.\n");
- EndDMLevel ();
- return;
- }
- }
- }
- void ExitLevel (void)
- {
- int i;
- edict_t *ent;
- char command [256];
- level.exitintermission = 0;
- level.intermissiontime = 0;
- if (CTFNextMap())
- return;
- Com_sprintf (command, sizeof(command), "gamemap \"%s\"\n", level.changemap);
- gi.AddCommandString (command);
- ClientEndServerFrames ();
- level.changemap = NULL;
-
- for (i=0 ; i<maxclients->value ; i++)
- {
- ent = g_edicts + 1 + i;
- if (!ent->inuse)
- continue;
- if (ent->health > ent->client->pers.max_health)
- ent->health = ent->client->pers.max_health;
- }
- }
- void G_RunFrame (void)
- {
- int i;
- edict_t *ent;
- level.framenum++;
- level.time = level.framenum*FRAMETIME;
-
- AI_SetSightClient ();
-
- if (level.exitintermission)
- {
- ExitLevel ();
- return;
- }
-
-
-
-
- ent = &g_edicts[0];
- for (i=0 ; i<globals.num_edicts ; i++, ent++)
- {
- if (!ent->inuse)
- continue;
- level.current_entity = ent;
- VectorCopy (ent->s.origin, ent->s.old_origin);
-
- if ((ent->groundentity) && (ent->groundentity->linkcount != ent->groundentity_linkcount))
- {
- ent->groundentity = NULL;
- if ( !(ent->flags & (FL_SWIM|FL_FLY)) && (ent->svflags & SVF_MONSTER) )
- {
- M_CheckGround (ent);
- }
- }
- if (i > 0 && i <= maxclients->value)
- {
- ClientBeginServerFrame (ent);
- continue;
- }
- G_RunEntity (ent);
- }
-
- CheckDMRules ();
-
- ClientEndServerFrames ();
- }
|