Reformat g_main.c

This commit is contained in:
Yamagi Burmeister 2011-10-14 07:17:08 +00:00
parent 46ee52025b
commit 542604630b

View file

@ -1,21 +1,27 @@
/*
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* Copyright (C) 1997-2001 Id Software, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* =======================================================================
*
* Jump in into the game.so and support functions.
*
* =======================================================================
*/
#include "header/local.h"
@ -38,10 +44,8 @@ cvar_t *dmflags;
cvar_t *skill;
cvar_t *fraglimit;
cvar_t *timelimit;
//ZOID
cvar_t *capturelimit;
cvar_t *instantweap;
//ZOID
cvar_t *password;
cvar_t *maxclients;
cvar_t *maxentities;
@ -88,11 +92,10 @@ void ReadLevel (char *filename);
void InitGame(void);
void G_RunFrame(void);
/* =================================================================== */
//===================================================================
void ShutdownGame (void)
void
ShutdownGame(void)
{
gi.dprintf("==== ShutdownGame ====\n");
@ -100,16 +103,12 @@ void ShutdownGame (void)
gi.FreeTags(TAG_GAME);
}
/*
=================
GetGameAPI
Returns a pointer to the structure with all entry points
and global variables
=================
* Returns a pointer to the structure with
* all entry points and global variables
*/
game_export_t *GetGameAPI (game_import_t *import)
game_export_t *
GetGameAPI(game_import_t *import)
{
gi = *import;
@ -139,9 +138,8 @@ game_export_t *GetGameAPI (game_import_t *import)
return &globals;
}
#ifndef GAME_HARD_LINKED
// this is only here so the functions in q_shared.c and q_shwin.c can link
void Sys_Error (char *error, ...)
void
Sys_Error(char *error, ...)
{
va_list argptr;
char text[1024];
@ -153,7 +151,8 @@ void Sys_Error (char *error, ...)
gi.error(ERR_FATAL, "%s", text);
}
void Com_Printf (char *msg, ...)
void
Com_Printf(char *msg, ...)
{
va_list argptr;
char text[1024];
@ -165,41 +164,34 @@ void Com_Printf (char *msg, ...)
gi.dprintf("%s", text);
}
#endif
/* ====================================================================== */
//======================================================================
/*
=================
ClientEndServerFrames
=================
*/
void ClientEndServerFrames (void)
void
ClientEndServerFrames(void)
{
int i;
edict_t *ent;
// calc the player views now that all pushing
// and damage has been added
/* calc the player views now that all
pushing and damage has been added */
for (i = 0; i < maxclients->value; i++)
{
ent = g_edicts + 1 + i;
if (!ent->inuse || !ent->client)
{
continue;
ClientEndServerFrame (ent);
}
ClientEndServerFrame(ent);
}
}
/*
=================
CreateTargetChangeLevel
Returns the created target changelevel
=================
* Returns the created target changelevel
*/
edict_t *CreateTargetChangeLevel(char *map)
edict_t *
CreateTargetChangeLevel(char *map)
{
edict_t *ent;
@ -211,94 +203,119 @@ edict_t *CreateTargetChangeLevel(char *map)
}
/*
=================
EndDMLevel
The timelimit or fraglimit has been exceeded
=================
* The timelimit or fraglimit has been exceeded
*/
void EndDMLevel (void)
void
EndDMLevel(void)
{
edict_t *ent;
char *s, *t, *f;
static const char *seps = " ,\n\r";
// stay on same level flag
/* stay on same level flag */
if ((int)dmflags->value & DF_SAME_LEVEL)
{
BeginIntermission(CreateTargetChangeLevel(level.mapname));
return;
}
if (*level.forcemap) {
if (*level.forcemap)
{
BeginIntermission(CreateTargetChangeLevel(level.forcemap));
return;
}
// see if it's in the map list
if (*sv_maplist->string) {
/* see if it's in the map list */
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) {
// it's in the list, go to the next one
while (t != NULL)
{
if (Q_stricmp(t, level.mapname) == 0)
{
/* it's in the list, go to the next one */
t = strtok(NULL, seps);
if (t == NULL) { // end of list, go to first one
if (f == NULL) // there isn't a first one, same level
if (t == NULL) /* end of list, go to first one */
{
if (f == NULL) /* there isn't a first one, same level */
{
BeginIntermission(CreateTargetChangeLevel(level.mapname));
}
else
{
BeginIntermission(CreateTargetChangeLevel(f));
} else
}
}
else
{
BeginIntermission(CreateTargetChangeLevel(t));
}
free(s);
return;
}
if (!f)
{
f = t;
}
t = strtok(NULL, seps);
}
free(s);
}
if (level.nextmap[0]) // go to a specific map
if (level.nextmap[0]) /* go to a specific map */
{
BeginIntermission(CreateTargetChangeLevel(level.nextmap));
else { // search for a changelevel
}
else /* search for a changelevel */
{
ent = G_Find(NULL, FOFS(classname), "target_changelevel");
if (!ent)
{ // the map designer didn't include a changelevel,
// so create a fake ent that goes back to the same level
{
/* the map designer didn't include a changelevel,
so create a fake ent that goes back to the same level */
BeginIntermission(CreateTargetChangeLevel(level.mapname));
return;
}
BeginIntermission(ent);
}
}
/*
=================
CheckDMRules
=================
*/
void CheckDMRules (void)
void
CheckDMRules(void)
{
int i;
gclient_t *cl;
if (level.intermissiontime)
{
return;
}
if (!deathmatch->value)
{
return;
}
//ZOID
if (ctf->value && CTFCheckRules()) {
if (ctf->value && CTFCheckRules())
{
EndDMLevel();
return;
}
if (CTFInMatch())
return; // no checking in match mode
//ZOID
{
return; /* no checking in match mode */
}
if (timelimit->value)
{
@ -311,11 +328,15 @@ void CheckDMRules (void)
}
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)
{
@ -325,14 +346,10 @@ void CheckDMRules (void)
}
}
}
}
/*
=============
ExitLevel
=============
*/
void ExitLevel (void)
void
ExitLevel(void)
{
int i;
edict_t *ent;
@ -342,7 +359,9 @@ void ExitLevel (void)
level.intermissiontime = 0;
if (CTFNextMap())
{
return;
}
Com_sprintf(command, sizeof(command), "gamemap \"%s\"\n", level.changemap);
gi.AddCommandString(command);
@ -350,25 +369,28 @@ void ExitLevel (void)
level.changemap = NULL;
// clear some things before going to next level
/* clear some things before going to next level */
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;
}
}
}
/*
================
G_RunFrame
Advances the world by 0.1 seconds
================
* Advances the world by 0.1 seconds
*/
void G_RunFrame (void)
void
G_RunFrame(void)
{
int i;
edict_t *ent;
@ -376,10 +398,10 @@ void G_RunFrame (void)
level.framenum++;
level.time = level.framenum * FRAMETIME;
// choose a client for monsters to target this frame
/* choose a client for monsters to target this frame */
AI_SetSightClient();
// exit intermissions
/* exit intermissions */
if (level.exitintermission)
{
@ -387,31 +409,35 @@ void G_RunFrame (void)
return;
}
//
// treat each object in turn
// even the world gets a chance to think
//
/* treat each object in turn even
the world gets a chance to think */
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 the ground entity moved, make sure we are still on it
if ((ent->groundentity) && (ent->groundentity->linkcount != ent->groundentity_linkcount))
/* if the ground entity moved, make sure we are still on it */
if ((ent->groundentity) &&
(ent->groundentity->linkcount != ent->groundentity_linkcount))
{
ent->groundentity = NULL;
if ( !(ent->flags & (FL_SWIM|FL_FLY)) && (ent->svflags & SVF_MONSTER) )
if (!(ent->flags & (FL_SWIM | FL_FLY)) &&
(ent->svflags & SVF_MONSTER))
{
M_CheckGround(ent);
}
}
if (i > 0 && i <= maxclients->value)
if ((i > 0) && (i <= maxclients->value))
{
ClientBeginServerFrame(ent);
continue;
@ -420,10 +446,10 @@ void G_RunFrame (void)
G_RunEntity(ent);
}
// see if it is time to end a deathmatch
/* see if it is time to end a deathmatch */
CheckDMRules();
// build the playerstate_t structures for all players
/* build the playerstate_t structures for all players */
ClientEndServerFrames();
}