Reformat g_spawn.c

This commit is contained in:
Yamagi Burmeister 2011-10-15 07:48:24 +00:00
parent f13b82939e
commit dcc29861ae

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.
*
* =======================================================================
*
* Item spawning.
*
* =======================================================================
*/
#include "header/local.h"
@ -26,7 +32,6 @@ typedef struct
void (*spawn)(edict_t *ent);
} spawn_t;
void SP_item_health(edict_t *self);
void SP_item_health_small(edict_t *self);
void SP_item_health_large(edict_t *self);
@ -144,7 +149,6 @@ void SP_turret_breach (edict_t *self);
void SP_turret_base(edict_t *self);
void SP_turret_driver(edict_t *self);
spawn_t spawns[] = {
{"item_health", SP_item_health},
{"item_health_small", SP_item_health_small},
@ -155,10 +159,8 @@ spawn_t spawns[] = {
{"info_player_deathmatch", SP_info_player_deathmatch},
{"info_player_coop", SP_info_player_coop},
{"info_player_intermission", SP_info_player_intermission},
//ZOID
{"info_player_team1", SP_info_player_team1},
{"info_player_team2", SP_info_player_team2},
//ZOID
{"func_plat", SP_func_plat},
{"func_button", SP_func_button},
@ -221,10 +223,8 @@ spawn_t spawns[] = {
{"misc_explobox", SP_misc_explobox},
{"misc_banner", SP_misc_banner},
//ZOID
{"misc_ctf_banner", SP_misc_ctf_banner},
{"misc_ctf_small_banner", SP_misc_ctf_small_banner},
//ZOID
{"misc_satellite_dish", SP_misc_satellite_dish},
{"misc_gib_arm", SP_misc_gib_arm},
{"misc_gib_leg", SP_misc_gib_leg},
@ -235,10 +235,8 @@ spawn_t spawns[] = {
{"misc_strogg_ship", SP_misc_strogg_ship},
{"misc_teleporter", SP_misc_teleporter},
{"misc_teleporter_dest", SP_misc_teleporter_dest},
//ZOID
{"trigger_teleport", SP_trigger_teleport},
{"info_teleport_destination", SP_info_teleport_destination},
//ZOID
{"misc_blackhole", SP_misc_blackhole},
{"misc_eastertank", SP_misc_eastertank},
{"misc_easterchick", SP_misc_easterchick},
@ -248,13 +246,10 @@ spawn_t spawns[] = {
};
/*
===============
ED_CallSpawn
Finds the spawn function for the entity and calls it
===============
* Finds the spawn function for the entity and calls it
*/
void ED_CallSpawn (edict_t *ent)
void
ED_CallSpawn(edict_t *ent)
{
spawn_t *s;
gitem_t *item;
@ -266,36 +261,38 @@ void ED_CallSpawn (edict_t *ent)
return;
}
// check item spawn functions
/* check item spawn functions */
for (i = 0, item = itemlist; i < game.num_items; i++, item++)
{
if (!item->classname)
{
continue;
}
if (!strcmp(item->classname, ent->classname))
{ // found it
{
/* found it */
SpawnItem(ent, item);
return;
}
}
// check normal spawn functions
/* check normal spawn functions */
for (s = spawns; s->name; s++)
{
if (!strcmp(s->name, ent->classname))
{ // found it
{
/* found it */
s->spawn(ent);
return;
}
}
gi.dprintf("%s doesn't have a spawn function\n", ent->classname);
}
/*
=============
ED_NewString
=============
*/
char *ED_NewString (char *string)
char *
ED_NewString(char *string)
{
char *newb, *new_p;
int i, l;
@ -308,33 +305,34 @@ char *ED_NewString (char *string)
for (i = 0; i < l; i++)
{
if (string[i] == '\\' && i < l-1)
if ((string[i] == '\\') && (i < l - 1))
{
i++;
if (string[i] == 'n')
{
*new_p++ = '\n';
else
*new_p++ = '\\';
}
else
{
*new_p++ = '\\';
}
}
else
{
*new_p++ = string[i];
}
}
return newb;
}
/*
===============
ED_ParseField
Takes a key/value pair and sets the binary values
in an edict
===============
* Takes a key/value pair and sets
* the binary values in an edict
*/
void ED_ParseField (char *key, char *value, edict_t *ent)
void
ED_ParseField(char *key, char *value, edict_t *ent)
{
field_t *f;
byte *b;
@ -344,11 +342,16 @@ void ED_ParseField (char *key, char *value, edict_t *ent)
for (f = fields; f->name; f++)
{
if (!Q_stricmp(f->name, key))
{ // found it
{
/* found it */
if (f->flags & FFL_SPAWNTEMP)
{
b = (byte *)&st;
}
else
{
b = (byte *)ent;
}
switch (f->type)
{
@ -378,21 +381,21 @@ void ED_ParseField (char *key, char *value, edict_t *ent)
default:
break;
}
return;
}
}
gi.dprintf("%s is not a field\n", key);
}
/*
====================
ED_ParseEdict
Parses an edict out of the given string, returning the new position
ed should be a properly initialized empty edict.
====================
* Parses an edict out of the given string,
* returning the new position ed should be
* a properly initialized empty edict.
*/
char *ED_ParseEdict (char *data, edict_t *ent)
char *
ED_ParseEdict(char *data, edict_t *ent)
{
qboolean init;
char keyname[256];
@ -401,54 +404,66 @@ char *ED_ParseEdict (char *data, edict_t *ent)
init = false;
memset(&st, 0, sizeof(st));
// go through all the dictionary pairs
/* go through all the dictionary pairs */
while (1)
{
// parse key
/* parse key */
com_token = COM_Parse(&data);
if (com_token[0] == '}')
{
break;
}
if (!data)
{
gi.error("ED_ParseEntity: EOF without closing brace");
}
strncpy(keyname, com_token, sizeof(keyname) - 1);
// parse value
/* parse value */
com_token = COM_Parse(&data);
if (!data)
{
gi.error("ED_ParseEntity: EOF without closing brace");
}
if (com_token[0] == '}')
{
gi.error("ED_ParseEntity: closing brace without data");
}
init = true;
// keynames with a leading underscore are used for utility comments,
// and are immediately discarded by quake
/* keynames with a leading underscore are used
for utility comments, and are immediately
discarded by quake */
if (keyname[0] == '_')
{
continue;
}
ED_ParseField(keyname, com_token, ent);
}
if (!init)
{
memset(ent, 0, sizeof(*ent));
}
return data;
}
/*
================
G_FindTeams
Chain together all entities with a matching team field.
All but the first will have the FL_TEAMSLAVE flag set.
All but the last will have the teamchain field set to the next one
================
* Chain together all entities with a matching team field.
*
* All but the first will have the FL_TEAMSLAVE flag set.
* All but the last will have the teamchain field set to the next one
*/
void G_FindTeams (void)
void
G_FindTeams(void)
{
edict_t *e, *e2, *chain;
int i, j;
@ -456,26 +471,46 @@ void G_FindTeams (void)
c = 0;
c2 = 0;
for (i = 1, e = g_edicts + i; i < globals.num_edicts; i++, e++)
{
if (!e->inuse)
{
continue;
}
if (!e->team)
{
continue;
}
if (e->flags & FL_TEAMSLAVE)
{
continue;
}
chain = e;
e->teammaster = e;
c++;
c2++;
for (j = i + 1, e2 = e + 1; j < globals.num_edicts; j++, e2++)
{
if (!e2->inuse)
{
continue;
}
if (!e2->team)
{
continue;
}
if (e2->flags & FL_TEAMSLAVE)
{
continue;
}
if (!strcmp(e->team, e2->team))
{
c2++;
@ -491,14 +526,11 @@ void G_FindTeams (void)
}
/*
==============
SpawnEntities
Creates a server's entity / program execution context by
parsing textual entity definitions out of an ent file.
==============
* Creates a server's entity / program execution context by
* parsing textual entity definitions out of an ent file.
*/
void SpawnEntities (char *mapname, char *entities, char *spawnpoint)
void
SpawnEntities(char *mapname, char *entities, char *spawnpoint)
{
edict_t *ent;
int inhibit;
@ -507,12 +539,21 @@ void SpawnEntities (char *mapname, char *entities, char *spawnpoint)
float skill_level;
skill_level = floor(skill->value);
if (skill_level < 0)
{
skill_level = 0;
}
if (skill_level > 3)
{
skill_level = 3;
}
if (skill->value != skill_level)
{
gi.cvar_forceset("skill", va("%f", skill_level));
}
SaveClientData();
@ -524,34 +565,52 @@ void SpawnEntities (char *mapname, char *entities, char *spawnpoint)
strncpy(level.mapname, mapname, sizeof(level.mapname) - 1);
strncpy(game.spawnpoint, spawnpoint, sizeof(game.spawnpoint) - 1);
// set client fields on player ents
/* set client fields on player ents */
for (i = 0; i < game.maxclients; i++)
{
g_edicts[i + 1].client = game.clients + i;
}
ent = NULL;
inhibit = 0;
// parse ents
/* parse ents */
while (1)
{
// parse the opening brace
/* parse the opening brace */
com_token = COM_Parse(&entities);
if (!entities)
{
break;
}
if (com_token[0] != '{')
{
gi.error("ED_LoadFromFile: found %s when expecting {", com_token);
}
if (!ent)
{
ent = g_edicts;
}
else
{
ent = G_Spawn();
}
entities = ED_ParseEdict(entities, ent);
// yet another map hack
if (!Q_stricmp(level.mapname, "command") && !Q_stricmp(ent->classname, "trigger_once") && !Q_stricmp(ent->model, "*27"))
/* yet another map hack */
if (!Q_stricmp(level.mapname, "command") &&
!Q_stricmp(ent->classname,
"trigger_once") && !Q_stricmp(ent->model, "*27"))
{
ent->spawnflags &= ~SPAWNFLAG_NOT_HARD;
}
// remove things (except the world) from different skill levels or deathmatch
/* remove things (except the world) from
different skill levels or deathmatch */
if (ent != g_edicts)
{
if (deathmatch->value)
@ -565,10 +624,13 @@ void SpawnEntities (char *mapname, char *entities, char *spawnpoint)
}
else
{
if ( /* ((coop->value) && (ent->spawnflags & SPAWNFLAG_NOT_COOP)) || */
((skill->value == 0) && (ent->spawnflags & SPAWNFLAG_NOT_EASY)) ||
((skill->value == 1) && (ent->spawnflags & SPAWNFLAG_NOT_MEDIUM)) ||
(((skill->value == 2) || (skill->value == 3)) && (ent->spawnflags & SPAWNFLAG_NOT_HARD))
if (((skill->value == 0) &&
(ent->spawnflags & SPAWNFLAG_NOT_EASY)) ||
((skill->value == 1) &&
(ent->spawnflags & SPAWNFLAG_NOT_MEDIUM)) ||
(((skill->value == 2) ||
(skill->value == 3)) &&
(ent->spawnflags & SPAWNFLAG_NOT_HARD))
)
{
G_FreeEdict(ent);
@ -577,7 +639,8 @@ void SpawnEntities (char *mapname, char *entities, char *spawnpoint)
}
}
ent->spawnflags &= ~(SPAWNFLAG_NOT_EASY|SPAWNFLAG_NOT_MEDIUM|SPAWNFLAG_NOT_HARD|SPAWNFLAG_NOT_COOP|SPAWNFLAG_NOT_DEATHMATCH);
ent->spawnflags &= ~(SPAWNFLAG_NOT_EASY | SPAWNFLAG_NOT_MEDIUM |
SPAWNFLAG_NOT_HARD | SPAWNFLAG_NOT_COOP | SPAWNFLAG_NOT_DEATHMATCH);
}
ED_CallSpawn(ent);
@ -589,24 +652,21 @@ void SpawnEntities (char *mapname, char *entities, char *spawnpoint)
PlayerTrail_Init();
//ZOID
CTFSpawn();
//ZOID
}
//===================================================================
/* =================================================================== */
char *single_statusbar =
"yb -24 "
// health
/* health */
"xv 0 "
"hnum "
"xv 50 "
"pic 0 "
// ammo
/* ammo */
"if 2 "
" xv 100 "
" anum "
@ -614,7 +674,7 @@ char *single_statusbar =
" pic 2 "
"endif "
// armor
/* armor */
"if 4 "
" xv 200 "
" rnum "
@ -622,7 +682,7 @@ char *single_statusbar =
" pic 4 "
"endif "
// selected item
/* selected item */
"if 6 "
" xv 296 "
" pic 6 "
@ -630,7 +690,7 @@ char *single_statusbar =
"yb -50 "
// picked up item
/* picked up item */
"if 7 "
" xv 0 "
" pic 7 "
@ -640,7 +700,7 @@ char *single_statusbar =
" yb -50 "
"endif "
// timer
/* timer */
"if 9 "
" xv 262 "
" num 2 10 "
@ -648,7 +708,7 @@ char *single_statusbar =
" pic 9 "
"endif "
// help / weapon icon
/* help / weapon icon */
"if 11 "
" xv 148 "
" pic 11 "
@ -658,13 +718,13 @@ char *single_statusbar =
char *dm_statusbar =
"yb -24 "
// health
/* health */
"xv 0 "
"hnum "
"xv 50 "
"pic 0 "
// ammo
/* ammo */
"if 2 "
" xv 100 "
" anum "
@ -672,7 +732,7 @@ char *dm_statusbar =
" pic 2 "
"endif "
// armor
/* armor */
"if 4 "
" xv 200 "
" rnum "
@ -680,7 +740,7 @@ char *dm_statusbar =
" pic 4 "
"endif "
// selected item
/* selected item */
"if 6 "
" xv 296 "
" pic 6 "
@ -688,7 +748,7 @@ char *dm_statusbar =
"yb -50 "
// picked up item
/* picked up item */
"if 7 "
" xv 0 "
" pic 7 "
@ -698,7 +758,7 @@ char *dm_statusbar =
" yb -50 "
"endif "
// timer
/* timer */
"if 9 "
" xv 246 "
" num 2 10 "
@ -706,98 +766,113 @@ char *dm_statusbar =
" pic 9 "
"endif "
// help / weapon icon
/* help / weapon icon */
"if 11 "
" xv 148 "
" pic 11 "
"endif "
// frags
/* frags */
"xr -50 "
"yt 2 "
"num 3 14"
;
/*QUAKED worldspawn (0 0 0) ?
Only used for the world.
"sky" environment map name
"skyaxis" vector axis for rotating sky
"skyrotate" speed of rotation in degrees/second
"sounds" music cd track number
"gravity" 800 is default gravity
"message" text to print at user logon
*
* Only used for the world.
* "sky" environment map name
* "skyaxis" vector axis for rotating sky
* "skyrotate" speed of rotation in degrees/second
* "sounds" music cd track number
* "gravity" 800 is default gravity
* "message" text to print at user logon
*/
void SP_worldspawn (edict_t *ent)
void
SP_worldspawn(edict_t *ent)
{
ent->movetype = MOVETYPE_PUSH;
ent->solid = SOLID_BSP;
ent->inuse = true; // since the world doesn't use G_Spawn()
ent->s.modelindex = 1; // world model is always index 1
ent->inuse = true; /* since the world doesn't use G_Spawn() */
ent->s.modelindex = 1; /* world model is always index 1 */
//---------------
/* --------------- */
// reserve some spots for dead player bodies for coop / deathmatch
/* reserve some spots for dead player bodies for coop / deathmatch */
InitBodyQue();
// set configstrings for items
/* set configstrings for items */
SetItemNames();
if (st.nextmap)
{
strcpy(level.nextmap, st.nextmap);
}
// make some data visible to the server
/* make some data visible to the server */
if (ent->message && ent->message[0])
{
gi.configstring(CS_NAME, ent->message);
strncpy(level.level_name, ent->message, sizeof(level.level_name));
}
else
{
strncpy(level.level_name, level.mapname, sizeof(level.level_name));
}
if (st.sky && st.sky[0])
{
gi.configstring(CS_SKY, st.sky);
}
else
{
gi.configstring(CS_SKY, "unit1_");
}
gi.configstring(CS_SKYROTATE, va("%f", st.skyrotate));
gi.configstring (CS_SKYAXIS, va("%f %f %f",
st.skyaxis[0], st.skyaxis[1], st.skyaxis[2]) );
gi.configstring(CS_SKYAXIS, va("%f %f %f", st.skyaxis[0], st.skyaxis[1], st.skyaxis[2]));
gi.configstring(CS_CDTRACK, va("%i", ent->sounds));
gi.configstring(CS_MAXCLIENTS, va("%i", (int)(maxclients->value)));
// status bar program
/* status bar program */
if (deathmatch->value)
//ZOID
if (ctf->value) {
{
if (ctf->value)
{
gi.configstring(CS_STATUSBAR, ctf_statusbar);
CTFPrecache();
} else
//ZOID
gi.configstring (CS_STATUSBAR, dm_statusbar);
}
else
{
gi.configstring(CS_STATUSBAR, dm_statusbar);
}
}
else
{
gi.configstring(CS_STATUSBAR, single_statusbar);
}
//---------------
/* --------------- */
// help icon for statusbar
/* help icon for statusbar */
gi.imageindex("i_help");
level.pic_health = gi.imageindex("i_health");
gi.imageindex("help");
gi.imageindex("field_3");
if (!st.gravity)
{
gi.cvar_set("sv_gravity", "800");
}
else
{
gi.cvar_set("sv_gravity", st.gravity);
}
snd_fry = gi.soundindex ("player/fry.wav"); // standing in lava / slime
snd_fry = gi.soundindex("player/fry.wav"); /* standing in lava / slime */
PrecacheItem(FindItem("Blaster"));
@ -809,19 +884,19 @@ void SP_worldspawn (edict_t *ent)
gi.soundindex("misc/udeath.wav");
// gibs
/* gibs */
gi.soundindex("items/respawn1.wav");
// sexed sounds
/* sexed sounds */
gi.soundindex("*death1.wav");
gi.soundindex("*death2.wav");
gi.soundindex("*death3.wav");
gi.soundindex("*death4.wav");
gi.soundindex("*fall1.wav");
gi.soundindex("*fall2.wav");
gi.soundindex ("*gurp1.wav"); // drowning damage
gi.soundindex("*gurp1.wav"); /* drowning damage */
gi.soundindex("*gurp2.wav");
gi.soundindex ("*jump1.wav"); // player jump
gi.soundindex("*jump1.wav"); /* player jump */
gi.soundindex("*pain25_1.wav");
gi.soundindex("*pain25_2.wav");
gi.soundindex("*pain50_1.wav");
@ -831,9 +906,7 @@ void SP_worldspawn (edict_t *ent)
gi.soundindex("*pain100_1.wav");
gi.soundindex("*pain100_2.wav");
// sexed models
// THIS ORDER MUST MATCH THE DEFINES IN g_local.h
// you can add more, max 15
/* sexed models */
gi.modelindex("#w_blaster.md2");
gi.modelindex("#w_shotgun.md2");
gi.modelindex("#w_sshotgun.md2");
@ -847,22 +920,22 @@ void SP_worldspawn (edict_t *ent)
gi.modelindex("#w_bfg.md2");
gi.modelindex("#w_grapple.md2");
//-------------------
/* ------------------- */
gi.soundindex ("player/gasp1.wav"); // gasping for air
gi.soundindex ("player/gasp2.wav"); // head breaking surface, not gasping
gi.soundindex("player/gasp1.wav"); /* gasping for air */
gi.soundindex("player/gasp2.wav"); /* head breaking surface, not gasping */
gi.soundindex ("player/watr_in.wav"); // feet hitting water
gi.soundindex ("player/watr_out.wav"); // feet leaving water
gi.soundindex("player/watr_in.wav"); /* feet hitting water */
gi.soundindex("player/watr_out.wav"); /* feet leaving water */
gi.soundindex ("player/watr_un.wav"); // head going underwater
gi.soundindex("player/watr_un.wav"); /* head going underwater */
gi.soundindex("player/u_breath1.wav");
gi.soundindex("player/u_breath2.wav");
gi.soundindex ("items/pkup.wav"); // bonus item pickup
gi.soundindex ("world/land.wav"); // landing thud
gi.soundindex ("misc/h2ohit1.wav"); // landing splash
gi.soundindex("items/pkup.wav"); /* bonus item pickup */
gi.soundindex("world/land.wav"); /* landing thud */
gi.soundindex("misc/h2ohit1.wav"); /* landing splash */
gi.soundindex("items/damage.wav");
gi.soundindex("items/protect.wav");
@ -879,49 +952,47 @@ void SP_worldspawn (edict_t *ent)
gi.modelindex("models/objects/gibs/skull/tris.md2");
gi.modelindex("models/objects/gibs/head2/tris.md2");
//
// Setup light animation tables. 'a' is total darkness, 'z' is doublebright.
//
/* Setup light animation tables. 'a' is total darkness, 'z' is doublebright. */
// 0 normal
/* 0 normal */
gi.configstring(CS_LIGHTS + 0, "m");
// 1 FLICKER (first variety)
/* 1 FLICKER (first variety) */
gi.configstring(CS_LIGHTS + 1, "mmnmmommommnonmmonqnmmo");
// 2 SLOW STRONG PULSE
/* 2 SLOW STRONG PULSE */
gi.configstring(CS_LIGHTS + 2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
// 3 CANDLE (first variety)
/* 3 CANDLE (first variety) */
gi.configstring(CS_LIGHTS + 3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
// 4 FAST STROBE
/* 4 FAST STROBE */
gi.configstring(CS_LIGHTS + 4, "mamamamamama");
// 5 GENTLE PULSE 1
/* 5 GENTLE PULSE 1 */
gi.configstring(CS_LIGHTS + 5, "jklmnopqrstuvwxyzyxwvutsrqponmlkj");
// 6 FLICKER (second variety)
/* 6 FLICKER (second variety) */
gi.configstring(CS_LIGHTS + 6, "nmonqnmomnmomomno");
// 7 CANDLE (second variety)
/* 7 CANDLE (second variety) */
gi.configstring(CS_LIGHTS + 7, "mmmaaaabcdefgmmmmaaaammmaamm");
// 8 CANDLE (third variety)
/* 8 CANDLE (third variety) */
gi.configstring(CS_LIGHTS + 8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
// 9 SLOW STROBE (fourth variety)
/* 9 SLOW STROBE (fourth variety) */
gi.configstring(CS_LIGHTS + 9, "aaaaaaaazzzzzzzz");
// 10 FLUORESCENT FLICKER
/* 10 FLUORESCENT FLICKER */
gi.configstring(CS_LIGHTS + 10, "mmamammmmammamamaaamammma");
// 11 SLOW PULSE NOT FADE TO BLACK
/* 11 SLOW PULSE NOT FADE TO BLACK */
gi.configstring(CS_LIGHTS + 11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
// styles 32-62 are assigned by the light program for switchable lights
/* styles 32-62 are assigned by the light program for switchable lights */
// 63 testing
/* 63 testing */
gi.configstring(CS_LIGHTS + 63, "a");
}