Exemple #1
0
	public void addPlayer( Player p )
	{
		if (fPlayers.contains(p))
			return; // already joined this team
			
		fPlayers.addElement( p );

		// make sure we find out if the team member disconnects
		p.addPlayerStateListener(this);

		// act as a damage filter for this member
		p.addDamageListener(this);

		// assign new skin
		assignSkinTo( p );
		Object[] args = {p.getName(), fTeamIndex};
		Game.localecast("q2java.ctf.CTFMessages", "join_team", args, Engine.PRINT_HIGH);	
		
		//update players stats that he joined this team (the yellow line around team-icon)
		int index1 = ( this == Team.TEAM1 ? STAT_CTF_JOINED_TEAM1_PIC : STAT_CTF_JOINED_TEAM2_PIC );
		int index2 = ( this == Team.TEAM1 ? STAT_CTF_JOINED_TEAM2_PIC : STAT_CTF_JOINED_TEAM1_PIC );
		int picnum = Engine.getImageIndex("i_ctfj");
		p.fEntity.setPlayerStat( index1, (short)picnum );
		p.fEntity.setPlayerStat( index2, (short)0      );
	}
Exemple #2
0
	public boolean removePlayer( Player p )
	{
		if (!fPlayers.contains(p))
			return false;
			
		//update players stats that he leaved this team (the yellow line around team-icon)
		p.fEntity.setPlayerStat( STAT_CTF_JOINED_TEAM1_PIC, (short)0 );
		p.fEntity.setPlayerStat( STAT_CTF_JOINED_TEAM2_PIC, (short)0 );
		
		p.removePlayerStateListener(this);
		p.removeDamageListener(this);
		return fPlayers.removeElement( p );
	}
Exemple #3
0
/**
 * Find a single-player spawnpoint. Kind of simplistic.
 * @return q2jgame.GameEntity, null if nothing available.
 */
public static GenericSpawnpoint getSpawnpointSingle() 
	{
	String target = BaseQ2.getSpawnpoint();

	if (target == null)
		{
		// look for an info_player_start spawnpoint that's not a target
		Vector list = Game.getLevelRegistryList(q2java.baseq2.spawn.info_player_start.REGISTRY_KEY);
		Enumeration enum = list.elements();
		while (enum.hasMoreElements())
			{
			GenericSpawnpoint sp = (GenericSpawnpoint) enum.nextElement();		
			if (sp.getTargetGroup() == null)
				return sp;
			}
			
		// all info_player_starts are targets, so settle for the first one (if available)
		if (list.size() > 0)
			return (GenericSpawnpoint) list.elementAt(0);					
		}
	else
Exemple #4
0
	/**
	 * Check if a player belongs to this team.
	 * @return boolean
	 * @param p The player we're checking on.
	 */
	public boolean isTeamMember(Object obj) 
	{
		return fPlayers.contains(obj);
	}
Exemple #5
0
	public CTFPlayer[] getPlayers()
	{
		CTFPlayer[] players = new CTFPlayer[ fPlayers.size() ];
		fPlayers.copyInto( players );
		return players;
	}
Exemple #6
0
	public int getNumPlayers()
	{
		return fPlayers.size();
	}
Exemple #7
0
/**
 * Select a random spawnpoint, but exclude the two points closest
 * to other players.
 * @return q2jgame.GameEntity
 */
public static GenericSpawnpoint getSpawnpointRandom() 
	{
	GenericSpawnpoint spawnPoint = null;
	GenericSpawnpoint spot1 = null;
	GenericSpawnpoint spot2 = null;
	float range1 = Float.MAX_VALUE;
	float range2 = Float.MAX_VALUE;
	int count = 0;
	
	// find the two deathmatch spawnpoints that are closest to any players
	Vector list = Game.getLevelRegistryList(q2java.baseq2.spawn.info_player_deathmatch.REGISTRY_KEY);

	// if no deathmatch spawnpoint, try single-player ones
	if (list.size() < 1)
		list = Game.getLevelRegistryList(q2java.baseq2.spawn.info_player_start.REGISTRY_KEY);
		
	Enumeration enum = list.elements();
	while (enum.hasMoreElements())
		{
		count++;
		spawnPoint = (GenericSpawnpoint) enum.nextElement();
		float range = MiscUtil.nearestPlayerDistance(spawnPoint);

		if (range < range1)
			{
			range1 = range;
			spot1 = spawnPoint;
			}		
		else
			{
			if (range < range2)
				{
				range2 = range;
				spot2 = spawnPoint;
				}
			}			
			
		}

	if (count == 0)
		return null;
		
	if (count <= 2)
		spot1 = spot2 = null;
	else
		count -= 2;			

	int selection = (GameUtil.randomInt() & 0x0fff) % count;
	spawnPoint = null;

	enum = list.elements();
	while (enum.hasMoreElements())
		{
		spawnPoint = (GenericSpawnpoint) enum.nextElement();
		
		// skip the undesirable spots
		if ((spawnPoint == spot1) || (spawnPoint == spot2))
			continue;
			
		if ((selection--) == 0)					
			break;
		}

	return spawnPoint;
	}