Example #1
0
void setEnemy(int myteam, struct player *me)
{
  int i, other_team;
  
  other_team = 0;
  
  for(i = 0; i < MAXTEAM; i++) {
    if(i == myteam)
      continue;
    else {
      if (realNumShips(i) >= tournplayers)
	other_team = i;
    }
  }
  
  me->p_hist.enemy_team = other_team;
  /* BUG: this should use team_opposing() instead */

}
static int
tournamentMask(int team)
{
    int     i;			/* looping var */
    int     team1, team2;	/* for getting two possible teams */
    int     num1, num2;		/* to hold num players on teams */

    if (!blk_flag)		/* not a paradise client */
	return (0);
    if (status->gameup == 0)	/* if game over, can join no team */
	return (0);
    if (overload)		/* if tester slot then can join */
	return (ALLTEAM);	/* any team */
    if (mustexit)		/* should we force player out */
	return (0);
    if (!time_access())		/* if server closed then can join */
	return (0);		/* no team */

    /* league stuff */
    if (status2->league) {
	if (me->p_homeaway == AWAY)
	    return leaguemask(1, status2->away.index);
	else if (me->p_homeaway == HOME)
	    return leaguemask(0, status2->home.index);
	else {
	    warning("You have connected to a league server but aren't on a side.");
	    me->p_homeaway = (lrand48() & 1) + 1;	/* dangerous int->enum
							   cast */
	    return 0;
	}
	/* NOTREACHED */
    }
    if (me->p_homeaway != NEITHER) {
	warning("You have connected to a non-league server with a league ntserv.");
	me->p_homeaway = NEITHER;
    }

    if (!status->tourn) {
	return status2->nontteamlock;
    }

    if (team != ALLTEAM && deadTeam(team))	/* if former team dead */
	team = ALLTEAM;		/* then check all others */
    for (i = 0; i < NUMTEAM; i++) {	/* go through all teams and eliminate */
	if ((team & (1 << i)) && (deadTeam(1 << i)))	/* from team var all
							   teams */
	    team &= ~(1 << i);	/* that are dead */
    }
    team1 = 0;			/* no team in team 1 */
    num1 = 0;			/* 0 players on team 1 */
    team2 = 0;			/* no team in team 2 */
    num2 = 0;			/* 0 players on team 2 */
    for (i = 0; i < NUMTEAM; i++) {	/* go through all teams */
	if (deadTeam(1 << i))	/* if team is dead then */
	    continue;		/* disregard it */
	if (realNumShips(1 << i) >= configvals->tournplayers) {	/* enough players */
	    if (!team1)		/* if no team in team1 yet */
		team1 = (1 << i);	/* then this will be team 1 */
	    else {		/* otherwise its team2 */
		team2 = (1 << i);
		num1 = realNumShips(team1);	/* get num players on two
						   teams */
		num2 = realNumShips(team2);
		if (num1 == num2) {	/* if teams same size then */
		    if (team & (team1 | team2))	/* if player on one team */
			return (team & (team1 | team2));	/* let him join same
								   team */
		    return (team1 | team2);	/* otherwise, he can join
						   either */
		}
		else if ((num1 > num2) && (team != team1))
		    return (team2);	/* if slight imabalance */
		else if ((num1 < num2) && (team != team2))
		    return (team1);	/* if slight imbalance */
		else {
		    if (ABS(num1 - num2) < 2 || (((num1 > num2) && (team == team2)) ||
					    (num2 > num1 && team == team1)))
			return (team);
		    else
			return (team1 | team2);
		}
	    }
	}
    }				/* end of for loop */
    return (team);		/* just in case */
}