Konstantinn Bonnetmake ctf workb8f176f11 years agoHistory
864 lines · 18.7 KB · C
RawDownload
#include <u.h>#include <libc.h>#include <stdio.h>#include "../dat.h"#include "../fns.h" typedef struct{	char	*name;	void	(*spawn)(edict_t *ent);} spawn_t;  spawn_t	spawns[] = {	{"item_health", SP_item_health},	{"item_health_small", SP_item_health_small},	{"item_health_large", SP_item_health_large},	{"item_health_mega", SP_item_health_mega}, 	{"info_player_start", SP_info_player_start},	{"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},	{"func_door", SP_func_door},	{"func_door_secret", SP_func_door_secret},	{"func_door_rotating", SP_func_door_rotating},	{"func_rotating", SP_func_rotating},	{"func_train", SP_func_train},	{"func_water", SP_func_water},	{"func_conveyor", SP_func_conveyor},	{"func_areaportal", SP_func_areaportal},	{"func_clock", SP_func_clock},	{"func_wall", SP_func_wall},	{"func_object", SP_func_object},	{"func_timer", SP_func_timer},	{"func_explosive", SP_func_explosive},	{"func_killbox", SP_func_killbox}, 	{"trigger_always", SP_trigger_always},	{"trigger_once", SP_trigger_once},	{"trigger_multiple", SP_trigger_multiple},	{"trigger_relay", SP_trigger_relay},	{"trigger_push", SP_trigger_push},	{"trigger_hurt", SP_trigger_hurt},	{"trigger_key", SP_trigger_key},	{"trigger_counter", SP_trigger_counter},	{"trigger_elevator", SP_trigger_elevator},	{"trigger_gravity", SP_trigger_gravity},	{"trigger_monsterjump", SP_trigger_monsterjump}, 	{"target_temp_entity", SP_target_temp_entity},	{"target_speaker", SP_target_speaker},	{"target_explosion", SP_target_explosion},	{"target_changelevel", SP_target_changelevel},	{"target_secret", SP_target_secret},	{"target_goal", SP_target_goal},	{"target_splash", SP_target_splash},	{"target_spawner", SP_target_spawner},	{"target_blaster", SP_target_blaster},	{"target_crosslevel_trigger", SP_target_crosslevel_trigger},	{"target_crosslevel_target", SP_target_crosslevel_target},	{"target_laser", SP_target_laser},	{"target_help", SP_target_help},/* remove monster code	{"target_actor", SP_target_actor},*/	{"target_lightramp", SP_target_lightramp},	{"target_earthquake", SP_target_earthquake},	{"target_character", SP_target_character},	{"target_string", SP_target_string}, 	{"worldspawn", SP_worldspawn},	{"viewthing", SP_viewthing}, 	{"light", SP_light},	{"light_mine1", SP_light_mine1},	{"light_mine2", SP_light_mine2},	{"info_null", SP_info_null},	{"func_group", SP_info_null},	{"info_notnull", SP_info_notnull},	{"path_corner", SP_path_corner},	{"point_combat", SP_point_combat}, 	{"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},/* remove monster code	{"misc_actor", SP_misc_actor},*/	{"misc_gib_arm", SP_misc_gib_arm},	{"misc_gib_leg", SP_misc_gib_leg},	{"misc_gib_head", SP_misc_gib_head},/* remove monster code	{"misc_insane", SP_misc_insane},*/	{"misc_deadsoldier", SP_misc_deadsoldier},	{"misc_viper", SP_misc_viper},	{"misc_viper_bomb", SP_misc_viper_bomb},	{"misc_bigviper", SP_misc_bigviper},	{"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},	{"misc_easterchick2", SP_misc_easterchick2}, /* remove monster code	{"monster_berserk", SP_monster_berserk},	{"monster_gladiator", SP_monster_gladiator},	{"monster_gunner", SP_monster_gunner},	{"monster_infantry", SP_monster_infantry},	{"monster_soldier_light", SP_monster_soldier_light},	{"monster_soldier", SP_monster_soldier},	{"monster_soldier_ss", SP_monster_soldier_ss},	{"monster_tank", SP_monster_tank},	{"monster_tank_commander", SP_monster_tank},	{"monster_medic", SP_monster_medic},	{"monster_flipper", SP_monster_flipper},	{"monster_chick", SP_monster_chick},	{"monster_parasite", SP_monster_parasite},	{"monster_flyer", SP_monster_flyer},	{"monster_brain", SP_monster_brain},	{"monster_floater", SP_monster_floater},	{"monster_hover", SP_monster_hover},	{"monster_mutant", SP_monster_mutant},	{"monster_supertank", SP_monster_supertank},	{"monster_boss2", SP_monster_boss2},	{"monster_boss3_stand", SP_monster_boss3_stand},	{"monster_jorg", SP_monster_jorg}, 	{"monster_commander_body", SP_monster_commander_body}, 	{"turret_breach", SP_turret_breach},	{"turret_base", SP_turret_base},	{"turret_driver", SP_turret_driver},*/ 	{NULL, NULL}}; /*===============ED_CallSpawn Finds the spawn function for the entity and calls it===============*/void ED_CallSpawn (edict_t *ent){	spawn_t	*s;	gitem_t	*item;	int		i; 	if (!ent->classname)	{		gi.dprintf ("ED_CallSpawn: NULL classname\n");		return;	} 	// 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			SpawnItem (ent, item);			return;		}	} 	// check normal spawn functions	for (s=spawns ; s->name ; s++)	{		if (!strcmp(s->name, ent->classname))		{	// 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	*newb, *new_p;	int		i,l;		l = strlen(string) + 1; 	newb = gi.TagMalloc (l, TAG_LEVEL); 	new_p = newb; 	for (i=0 ; i< l ; i++)	{		if (string[i] == '\\' && i < l-1)		{			i++;			if (string[i] == 'n')				*new_p++ = '\n';			else				*new_p++ = '\\';		}		else			*new_p++ = string[i];	}		return newb;}    /*===============ED_ParseField Takes a key/value pair and sets the binary valuesin an edict===============*/void ED_ParseField (char *key, char *value, edict_t *ent){	field_t	*f;	byte	*b;	float	v;	vec3_t	vec; 	for (f=fields ; f->name ; f++)	{		if (!cistrcmp(f->name, key))		{	// found it			if (f->flags & FFL_SPAWNTEMP)				b = (byte *)&st;			else				b = (byte *)ent; 			switch (f->type)			{			case F_LSTRING:				*(char **)(b+f->ofs) = ED_NewString (value);				break;			case F_VECTOR:				sscanf (value, "%f %f %f", &vec[0], &vec[1], &vec[2]);				((float *)(b+f->ofs))[0] = vec[0];				((float *)(b+f->ofs))[1] = vec[1];				((float *)(b+f->ofs))[2] = vec[2];				break;			case F_INT:				*(int *)(b+f->ofs) = atoi(value);				break;			case F_FLOAT:				*(float *)(b+f->ofs) = atof(value);				break;			case F_ANGLEHACK:				v = atof(value);				((float *)(b+f->ofs))[0] = 0;				((float *)(b+f->ofs))[1] = v;				((float *)(b+f->ofs))[2] = 0;				break;			case F_IGNORE:				break;			}			return;		}	}	gi.dprintf ("%s is not a field\n", key);} /*====================ED_ParseEdict Parses an edict out of the given string, returning the new positioned should be a properly initialized empty edict.====================*/char *ED_ParseEdict (char *data, edict_t *ent){	qboolean	init;	char		keyname[256];	char		*com_token; 	init = false;	memset (&st, 0, sizeof(st)); // go through all the dictionary pairs	while (1)	{		// 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			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		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================*/void G_FindTeams (void){	edict_t	*e, *e2, *chain;	int		i, j;	int		c, c2; 	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++;				chain->teamchain = e2;				e2->teammaster = e;				chain = e2;				e2->flags |= FL_TEAMSLAVE;			}		}	} 	gi.dprintf ("%i teams with %i entities\n", c, c2);} /*==============SpawnEntities Creates a server's entity / program execution context byparsing textual entity definitions out of an ent file.==============*/void SpawnEntities (char *mapname, char *entities, char *spawnpoint){	edict_t		*ent;	int			inhibit;	char		*com_token;	int			i;	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 (); 	gi.FreeTags (TAG_LEVEL); 	memset (&level, 0, sizeof(level));	memset (g_edicts, 0, game.maxentities * sizeof (g_edicts[0])); 	strncpy (level.mapname, mapname, sizeof(level.mapname)-1);	strncpy (game.spawnpoint, spawnpoint, sizeof(game.spawnpoint)-1); 	// 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	while (1)	{		// 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(!cistrcmp(level.mapname, "command") && !cistrcmp(ent->classname, "trigger_once") && !cistrcmp(ent->model, "*27"))			ent->spawnflags &= ~SPAWNFLAG_NOT_HARD; 		// remove things (except the world) from different skill levels or deathmatch		if (ent != g_edicts)		{			if (deathmatch->value)			{				if ( ent->spawnflags & SPAWNFLAG_NOT_DEATHMATCH )				{					G_FreeEdict (ent);						inhibit++;					continue;				}			}			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))					)					{						G_FreeEdict (ent);							inhibit++;						continue;					}			} 			ent->spawnflags &= ~(SPAWNFLAG_NOT_EASY|SPAWNFLAG_NOT_MEDIUM|SPAWNFLAG_NOT_HARD|SPAWNFLAG_NOT_COOP|SPAWNFLAG_NOT_DEATHMATCH);		} 		ED_CallSpawn (ent);	}	 	gi.dprintf ("%i entities inhibited\n", inhibit); 	G_FindTeams (); 	PlayerTrail_Init (); //ZOID	CTFSpawn();//ZOID}

Lines 1–500 of 864.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t