コード例 #1
0
ファイル: g_spawn.c プロジェクト: darkshade9/aq2-tng-alpha
/*
==============
SpawnEntities

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)
{
	edict_t *ent = NULL;
	int inhibit = 0;
	char *com_token;
	int i;
	float skill_level;
	//AQ2:TNG New Location Code
	char locfile[MAX_QPATH], line[256];
	FILE *f;
	int readmore, x, y, z, rx, ry, rz, count;
	char *locationstr, *param;
	cvar_t *game_cvar;
	int u;
	//    placedata_t temp;


	// Reset teamplay stuff
	for(i = TEAM1; i < TEAM_TOP; i++)
	{
		teams[i].score = teams[i].total = 0;
		teams[i].ready = teams[i].locked = 0;
		teams[i].pauses_used = teams[i].wantReset = 0;
		gi.cvar_forceset(teams[i].teamscore->name, "0");
	}

	matchtime = 0;
	day_cycle_at = 0;
	team_round_going = team_game_going = team_round_countdown = 0;
	lights_camera_action = holding_on_tie_check = 0;
	timewarning = fragwarning = 0;

	teamCount = 2;

	if (ctf->value)
	{
		// Make sure teamplay is enabled
		if (!teamplay->value)
		{
			gi.dprintf ("CTF Enabled - Forcing teamplay on\n");
			gi.cvar_forceset(teamplay->name, "1");
		}
		if (use_3teams->value)
		{
			gi.dprintf ("CTF Enabled - Forcing 3Teams off\n");
			gi.cvar_forceset(use_3teams->name, "0");
		}
		if(teamdm->value)
		{
			gi.dprintf ("CTF Enabled - Forcing Team DM off\n");
			gi.cvar_forceset(teamdm->name, "0");
		}
		if (use_tourney->value)
		{
			gi.dprintf ("CTF Enabled - Forcing Tourney off\n");
			gi.cvar_forceset(use_tourney->name, "0");
		}
		if (!((int) (dmflags->value) & DF_NO_FRIENDLY_FIRE))
		{
			gi.dprintf ("CTF Enabled - Forcing Friendly Fire off\n");
			gi.cvar_forceset(dmflags->name, va("%i", (int)dmflags->value | DF_NO_FRIENDLY_FIRE));
		}
		strcpy(teams[TEAM1].name, "RED");
		strcpy(teams[TEAM2].name, "BLUE");
		strcpy(teams[TEAM1].skin, "male/ctf_r");
		strcpy(teams[TEAM2].skin, "male/ctf_b");
		strcpy(teams[TEAM1].skin_index, "../players/male/ctf_r_i");
		strcpy(teams[TEAM2].skin_index, "../players/male/ctf_b_i");
		if(ctf->value == 2)
			gi.cvar_forceset(ctf->name, "1"); //for now
	}
	else if(teamdm->value)
	{
		if (!teamplay->value)
		{
			gi.dprintf ("Team Deathmatch Enabled - Forcing teamplay on\n");
			gi.cvar_forceset(teamplay->name, "1");
		}
		if (use_3teams->value)
		{
			gi.dprintf ("Team Deathmatch Enabled - Forcing 3Teams off\n");
			gi.cvar_forceset(use_3teams->name, "0");
		}
		if (use_tourney->value)
		{
			gi.dprintf ("Team Deathmatch Enabled - Forcing Tourney off\n");
			gi.cvar_forceset(use_tourney->name, "0");
		}
	}
	else if (use_3teams->value)
	{
		teamCount = 3;
		if (!teamplay->value)
		{
			gi.dprintf ("3 Teams Enabled - Forcing teamplay on\n");
			gi.cvar_forceset(teamplay->name, "1");
		}
		if (use_tourney->value)
		{
			gi.dprintf ("3 Teams Enabled - Forcing Tourney off\n");
			gi.cvar_forceset(use_tourney->name, "0");
		}
		if (!use_oldspawns->value)
		{
			gi.dprintf ("3 Teams Enabled - Forcing use_oldspawns on\n");
			gi.cvar_forceset(use_oldspawns->name, "1");
		}
	}
	else if (matchmode->value)
	{
		if (!teamplay->value)
		{
			gi.dprintf ("Matchmode Enabled - Forcing teamplay on\n");
			gi.cvar_forceset(teamplay->name, "1");
		}
		if (use_tourney->value)
		{
			gi.dprintf ("Matchmode Enabled - Forcing Tourney off\n");
			gi.cvar_forceset(use_tourney->name, "0");
		}
	}
	else if (use_tourney->value)
	{
		if (!teamplay->value)
		{
			gi.dprintf ("Tourney Enabled - Forcing teamplay on\n");
			gi.cvar_forceset(teamplay->name, "1");
		}
	}

	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]));

	Q_strncpyz(level.mapname, mapname, sizeof(level.mapname));
	Q_strncpyz(game.spawnpoint, spawnpoint, sizeof(game.spawnpoint));

	// set client fields on player ents
	for (i = 0; i < game.maxclients; i++)
		g_edicts[i + 1].client = game.clients + i;

	// 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 (!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
		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);

	// AQ2:TNG Igor adding .flg files

	// CTF configuration
	if(ctf->value)
	{
		if(!CTFLoadConfig(level.mapname))
		{
			if ((!G_Find(NULL, FOFS (classname), "item_flag_team1") ||
				 !G_Find(NULL, FOFS (classname), "item_flag_team2")))
			{
				gi.dprintf ("No native CTF map, loading flag positions from file\n");
				if (LoadFlagsFromFile (level.mapname))
					ChangePlayerSpawns ();
			}
		}
	}
	
	// AQ2:TNG End adding .flg files

	G_FindTeams ();

	PlayerTrail_Init ();

	// TNG:Freud - Ghosts
	num_ghost_players = 0;

	//FIREBLADE
	if (!teamplay->value || teamdm->value || ctf->value == 2)
	{
		//FIREBLADE
		//zucc for special items
		SetupSpecSpawn ();
	}
	else if (teamplay->value)
	{
		GetSpawnPoints ();
		//TNG:Freud - New spawning system
		if(!use_oldspawns->value)
			NS_GetSpawnPoints();
	}

	//AQ2:TNG Slicer - New location  code
	memset (ml_build, 0, sizeof (ml_build));
	memset (ml_creator, 0, sizeof (ml_creator));


	game_cvar = gi.cvar ("game", "", 0);

	if (!*game_cvar->string)
		Com_sprintf(locfile, sizeof(locfile), "%s/tng/%s.aqg", GAMEVERSION, level.mapname);
	else
		Com_sprintf(locfile, sizeof(locfile), "%s/tng/%s.aqg", game_cvar->string, level.mapname);

	f = fopen (locfile, "rt");
	if (!f)
	{
		ml_count = 0;
		gi.dprintf ("No location file for %s\n", level.mapname);
		return;
	}

	gi.dprintf ("Location file: %s\n", level.mapname);

	readmore = 1;
	count = 0;

	while (readmore)
	{
		readmore = (fgets (line, 256, f) != NULL);
		param = strtok (line, " :\r\n\0");
		if (line[0] == '#' && line[2] == 'C')
		{
			u = 0;
			for (i = 10; line[i] != '\n'; i++)
			{
				if (line[i] == '\r') continue;
					ml_creator[u] = line[i];
				u++;
			}
		}
		if (line[0] == '#' && line[2] == 'B')
		{
			u = 0;
			for (i = 8; line[i] != '\n'; i++)
			{
				if (line[i] != ' ' && line[i] != '\r')
				{
					ml_build[u] = line[i];
					u++;
				}
			}
		}
		ml_build[5] = 0;
		ml_creator[100] = 0;

		// TODO: better support for file comments
		if (!param || param[0] == '#')
			continue;

		x = atoi (param);

		param = strtok (NULL, " :\r\n\0");
		if (!param)
			continue;
		y = atoi (param);

		param = strtok (NULL, " :\r\n\0");
		if (!param)
			continue;
		z = atoi (param);

		param = strtok (NULL, " :\r\n\0");
		if (!param)
			continue;
		rx = atoi (param);

		param = strtok (NULL, " :\r\n\0");
		if (!param)
			continue;
		ry = atoi (param);

		param = strtok (NULL, " :\r\n\0");
		if (!param)
			continue;
		rz = atoi (param);

		param = strtok (NULL, "\r\n\0");
		if (!param)
			continue;
		locationstr = param;

		locationbase[count].x = x;
		locationbase[count].y = y;
		locationbase[count].z = z;
		locationbase[count].rx = rx;
		locationbase[count].ry = ry;
		locationbase[count].rz = rz;
		Q_strncpyz (locationbase[count].desc, locationstr, sizeof(locationbase[count].desc));

		count++;

		if (count >= MAX_LOCATIONS_IN_BASE)
		{
			gi.dprintf ("Cannot read more than %d locations.\n", MAX_LOCATIONS_IN_BASE);
			break;
		}
	}

	ml_count = count;
	fclose (f);
	gi.dprintf ("Found %d locations.\n", count);

}
コード例 #2
0
ファイル: g_spawn.c プロジェクト: MaddTheSane/Quake2-Action
/*
==============
SpawnEntities

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)
{
        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 (!Q_stricmp(level.mapname, "command") && !stricmp(ent->classname, "trigger_once") && !stricmp(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 ();

//FIREBLADE
        if (!teamplay->value)
        {
//FIREBLADE
                //zucc for special items
                SetupSpecSpawn();
        }


}