Complete.Org: Mailing Lists: Archives: freeciv-dev: October 2002:
[Freeciv-Dev] Re: teamslite11
Home

[Freeciv-Dev] Re: teamslite11

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: "Per I. Mathisen" <per@xxxxxxxxxxx>
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: teamslite11
From: Raimar Falke <rf13@xxxxxxxxxxxxxxxxx>
Date: Tue, 29 Oct 2002 21:07:39 +0100

On Tue, Oct 29, 2002 at 06:15:36PM +0000, Per I. Mathisen wrote:
> Hopefully last one. Changes:
>  - removed some patch "noise"
>  - ensure sane team names
>  - removed need for team_register function
>  - teamchat -> send to allies
>  - send to allies key is '.'
> 
> That's all. Hopefully this can now be committed.

> +/***************************************************************
> +  Returns name of a team given its id
> +***************************************************************/
> +const char *team_get_name(Team_Type_id team)
> +{
> +  assert(team < MAX_NUM_TEAMS && team != TEAM_NONE);
> +  if (game.team_count < team) {
> +    return NULL;
> +  }
> +
> +  return teams[team].name;
> +}
> +
> +/***************************************************************
> +  Returns pointer to a team given its id
> +***************************************************************/
> +struct team *team_get_by_id(Team_Type_id id)
> +{
> +  assert(id < game.team_count || id == TEAM_NONE);
> +  if (id == TEAM_NONE) {
> +    return NULL;
> +  }
> +  return &teams[id];
> +}

team_get_name(x) == team_get_by_id(x)->name

So I'm for removing team_get_name.

> +/***************************************************************
> +  Set a player to a team. Removes previous team affiliation,
> +  creates a new team if it does not exist.
> +***************************************************************/
> +void team_add_player(struct player *pplayer, const char *team_name)
> +{
> +  Team_Type_id team_id, i;
> +
> +  assert(pplayer != NULL && team_name != NULL);
> +
> +  /* find or create team */
> +  team_id = team_find_by_name(team_name);
> +  if (team_id == TEAM_NONE) {
> +    /* see if we have another team available */
> +    for (i = 0; i < MAX_NUM_TEAMS; i++) {
> +      if (teams[i].id == TEAM_NONE) {
> +        team_id = i;
> +        break;
> +      }
> +    }
> +    /* check if too many teams */
> +    if (team_id == TEAM_NONE) {
> +      freelog(LOG_ERROR, "Impossible: Too many teams!");
> +      assert(FALSE);
> +      exit(EXIT_FAILURE);
> +    }

> +    /* add another team */
> +    teams[team_id].id = team_id;
> +    sz_strlcpy(teams[team_id].name, team_name);
> +    pplayer->team = team_id;
> +    game.team_count++;
> +  } else {
> +    pplayer->team = team_id;
> +  }

Can be changed to:

> +    /* add another team */
> +    teams[team_id].id = team_id;
> +    sz_strlcpy(teams[team_id].name, team_name);
> +    game.team_count++;
> +  }
+    pplayer->team = team_id;

> +/***************************************************************
> +  Removes a player from a team, and removes the team if empty of
> +  players
> +***************************************************************/
> +void team_remove_player(struct player *pplayer)
> +{
> +  Team_Type_id i;
> +  int count = 0;
> +
> +  assert(pplayer != NULL && pplayer->team < MAX_NUM_TEAMS);
> +
> +  if (pplayer->team == TEAM_NONE) {
> +    return;
> +  }
> +

1)

> +  /* anyone else using my team? */
> +  for (i = 0; i < MAX_NUM_TEAMS; i++) {
> +    if ((teams[i].id == pplayer->team)
> +        && (pplayer->team != i)) {

> +      count++;
> +      break;

A bool is enough.

> +    }
> +  }
> +
> +  /* no other team members left? remove team */
> +  if (count == 0) {
> +    teams[pplayer->team].id = TEAM_NONE;
> +    game.team_count--;
> +  }

> +  pplayer->team = TEAM_NONE;

If this is placed at 1 we can remove the test "pplayer->team != i".

> Index: common/packets.c
> ===================================================================
> RCS file: /home/freeciv/CVS/freeciv/common/packets.c,v
> retrieving revision 1.220
> diff -u -r1.220 packets.c
> --- common/packets.c  2002/10/27 22:42:18     1.220
> +++ common/packets.c  2002/10/29 18:06:26
> @@ -818,6 +818,10 @@
>    dio_put_string(&dout, pinfo->name);
>  
>    dio_put_bool8(&dout, pinfo->is_male);

> +  if (has_capability("team", pc->capability)) {
> +    dio_put_uint8(&dout, pinfo->team);

> +    dio_put_string(&dout, pinfo->team_name);
> +  }

Waste of bandwidth since the team doesn't change.

> +
> +  /* average game scores for teams */
> +  team_iterate(pteam) {
> +    int team_members = 0;
> +    int count = 0;

> +    int teamscore = 0;
> +    int teamsize = 0;

team_members is separated by "_".

> -void handle_chat_msg(struct connection *pconn,
> +void handle_chat_msg(struct player *pplayer, struct connection *pconn,

Unneeded. Use pconn->player

> +  {"team",   ALLOW_CTRL,
> +   N_("team <player> [team]"),
> +   N_("Change, add or remove a player's team affiliation."),
> +   N_("Sets a player as member of a team. If no team specified, the "
> +      "player is set teamless. Use \"\" if names contain whitespace. "
> +      "A team is a group of players that start out allied, with shared "
> +      "vision and embassies, and fight together to achieve team victory "
> +      "with averaged individual scores.")
> +  },

"AI members of a team share their techs".

> @@ -1730,7 +1740,7 @@
>  {
>    struct player *pplayer;
>    PlayerNameStatus PNameStatus;
> -   
> +
>    if (server_state!=PRE_GAME_STATE)
>    {
>      cmd_reply(CMD_CREATE, caller, C_SYNTAX,

Noise.

Last but not least there was the valid concern that the techs that the
AI gives away are harmful.

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
  "Heuer's Law: Any feature is a bug unless it can be turned off."


[Prev in Thread] Current Thread [Next in Thread]