Author: jtn Date: Tue Dec 22 11:02:51 2015 New Revision: 31150 URL: http://svn.gna.org/viewcvs/freeciv?rev=31150&view=rev Log: Tell client whether player color is set and whether it can be chosen in pregame, to allow UI for color choosing in future.
See gna patch #6703. Modified: branches/S2_6/client/colors_common.c branches/S2_6/client/colors_common.h branches/S2_6/client/packhand.c branches/S2_6/client/tilespec.c branches/S2_6/common/packets.def branches/S2_6/common/player.c branches/S2_6/common/player.h branches/S2_6/fc_version branches/S2_6/server/plrhand.c branches/S2_6/server/plrhand.h branches/S2_6/server/stdinhand.c Modified: branches/S2_6/client/colors_common.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/colors_common.c?rev=31150&r1=31149&r2=31150&view=diff ============================================================================== --- branches/S2_6/client/colors_common.c (original) +++ branches/S2_6/client/colors_common.c Tue Dec 22 11:02:51 2015 @@ -106,7 +106,21 @@ } /********************************************************************** + Return whether the player has a color assigned yet. + Should only be FALSE in pregame. +***********************************************************************/ +bool player_has_color(const struct tileset *t, + const struct player *pplayer) +{ + fc_assert_ret_val(pplayer != NULL, NULL); + + return pplayer->rgb != NULL; +} + +/********************************************************************** Return the color of the player. + In pregame, callers should check player_has_color() before calling + this. ***********************************************************************/ struct color *get_player_color(const struct tileset *t, const struct player *pplayer) Modified: branches/S2_6/client/colors_common.h URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/colors_common.h?rev=31150&r1=31149&r2=31150&view=diff ============================================================================== --- branches/S2_6/client/colors_common.h (original) +++ branches/S2_6/client/colors_common.h Tue Dec 22 11:02:51 2015 @@ -117,6 +117,8 @@ #include "specenum_gen.h" struct color *get_color(const struct tileset *t, enum color_std stdcolor); +bool player_has_color(const struct tileset *t, + const struct player *pplayer); struct color *get_player_color(const struct tileset *t, const struct player *pplayer); struct color *get_terrain_color(const struct tileset *t, Modified: branches/S2_6/client/packhand.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/packhand.c?rev=31150&r1=31149&r2=31150&view=diff ============================================================================== --- branches/S2_6/client/packhand.c (original) +++ branches/S2_6/client/packhand.c Tue Dec 22 11:02:51 2015 @@ -2079,13 +2079,21 @@ new_player = !player_slot_is_used(pslot); pplayer = player_new(pslot); - if (pplayer->rgb == NULL || (pplayer->rgb->r != pinfo->color_red - || pplayer->rgb->g != pinfo->color_green - || pplayer->rgb->b != pinfo->color_blue)) { - struct rgbcolor *prgbcolor = rgbcolor_new(pinfo->color_red, - pinfo->color_green, - pinfo->color_blue); - fc_assert_ret(prgbcolor != NULL); + if ((pplayer->rgb == NULL) != !pinfo->color_valid + || (pinfo->color_valid && + (pplayer->rgb->r != pinfo->color_red + || pplayer->rgb->g != pinfo->color_green + || pplayer->rgb->b != pinfo->color_blue))) { + struct rgbcolor *prgbcolor; + + if (pinfo->color_valid) { + prgbcolor = rgbcolor_new(pinfo->color_red, + pinfo->color_green, + pinfo->color_blue); + fc_assert_ret(prgbcolor != NULL); + } else { + prgbcolor = NULL; + } player_set_color(pplayer, prgbcolor); tileset_player_init(tileset, pplayer); @@ -2095,6 +2103,7 @@ /* Queue a map update -- may need to redraw borders, etc. */ update_map_canvas_visible(); } + pplayer->client.color_changeable = pinfo->color_changeable; if (new_player) { /* Initialise client side player data (tile vision). At the moment Modified: branches/S2_6/client/tilespec.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/tilespec.c?rev=31150&r1=31149&r2=31150&view=diff ============================================================================== --- branches/S2_6/client/tilespec.c (original) +++ branches/S2_6/client/tilespec.c Tue Dec 22 11:02:51 2015 @@ -6416,9 +6416,9 @@ void tileset_player_init(struct tileset *t, struct player *pplayer) { int plrid, i, j; + struct sprite *color; fc_assert_ret(pplayer != NULL); - fc_assert_ret(pplayer->rgb != NULL); plrid = player_index(pplayer); fc_assert_ret(plrid >= 0); @@ -6427,10 +6427,18 @@ /* Free all data before recreating it. */ tileset_player_free(t, plrid); - t->sprites.player[plrid].color - = create_plr_sprite(ensure_color(pplayer->rgb)); + if (player_has_color(t, pplayer)) { + t->sprites.player[plrid].color = color + = create_plr_sprite(get_player_color(t, pplayer)); + } else { + /* XXX: if player hasn't been assigned a color, perhaps there's no + * point proceeding with an arbitrary color; this should only happen + * in pregame. Probably blank sprites would be better. */ + color = t->sprites.background.color; + } + t->sprites.player[plrid].background - = crop_sprite(t->sprites.player[plrid].color, 0, 0, + = crop_sprite(color, 0, 0, t->normal_tile_width, t->normal_tile_height, t->sprites.mask.tile, 0, 0); @@ -6438,9 +6446,8 @@ for (j = 0; j < 2; j++) { struct sprite *s; - if (t->sprites.player[plrid].color - && t->sprites.grid.borders[i][j]) { - s = crop_sprite(t->sprites.player[plrid].color, 0, 0, + if (color && t->sprites.grid.borders[i][j]) { + s = crop_sprite(color, 0, 0, t->normal_tile_width, t->normal_tile_height, t->sprites.grid.borders[i][j], 0, 0); } else { Modified: branches/S2_6/common/packets.def URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/packets.def?rev=31150&r1=31149&r2=31150&view=diff ============================================================================== --- branches/S2_6/common/packets.def (original) +++ branches/S2_6/common/packets.def Tue Dec 22 11:02:51 2015 @@ -804,6 +804,8 @@ UINT16 culture; SINT16 love[MAX_NUM_PLAYER_SLOTS]; + BOOL color_valid; + BOOL color_changeable; UINT8 color_red; UINT8 color_green; UINT8 color_blue; Modified: branches/S2_6/common/player.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/player.c?rev=31150&r1=31149&r2=31150&view=diff ============================================================================== --- branches/S2_6/common/player.c (original) +++ branches/S2_6/common/player.c Tue Dec 22 11:02:51 2015 @@ -606,17 +606,19 @@ /**************************************************************************** Set the player's color. + May be NULL in pregame. ****************************************************************************/ void player_set_color(struct player *pplayer, const struct rgbcolor *prgbcolor) { - fc_assert_ret(prgbcolor != NULL); - if (pplayer->rgb != NULL) { rgbcolor_destroy(pplayer->rgb); - } - - pplayer->rgb = rgbcolor_copy(prgbcolor); + pplayer->rgb = NULL; + } + + if (prgbcolor) { + pplayer->rgb = rgbcolor_copy(prgbcolor); + } } /**************************************************************************** Modified: branches/S2_6/common/player.h URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/player.h?rev=31150&r1=31149&r2=31150&view=diff ============================================================================== --- branches/S2_6/common/player.h (original) +++ branches/S2_6/common/player.h Tue Dec 22 11:02:51 2015 @@ -328,6 +328,8 @@ enum mood_type mood; int tech_upkeep; + + bool color_changeable; } client; }; }; Modified: branches/S2_6/fc_version URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/fc_version?rev=31150&r1=31149&r2=31150&view=diff ============================================================================== --- branches/S2_6/fc_version (original) +++ branches/S2_6/fc_version Tue Dec 22 11:02:51 2015 @@ -54,7 +54,7 @@ # - Avoid adding a new mandatory capability to the development branch for # as long as possible. We want to maintain network compatibility with # the stable branch for as long as possible. -NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-2.6-2015.Dec.16" +NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-2.6-2015.Dec.20" NETWORK_CAPSTRING_OPTIONAL="" FREECIV_DISTRIBUTOR="" Modified: branches/S2_6/server/plrhand.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/plrhand.c?rev=31150&r1=31149&r2=31150&view=diff ============================================================================== --- branches/S2_6/server/plrhand.c (original) +++ branches/S2_6/server/plrhand.c Tue Dec 22 11:02:51 2015 @@ -1088,6 +1088,7 @@ } players_iterate_end; if (plr->rgb != NULL) { + packet->color_valid = TRUE; packet->color_red = plr->rgb->r; packet->color_green = plr->rgb->g; packet->color_blue = plr->rgb->b; @@ -1096,17 +1097,20 @@ * '/list colors' etc. */ const struct rgbcolor *preferred = player_preferred_color(plr); if (preferred != NULL) { + packet->color_valid = TRUE; packet->color_red = preferred->r; packet->color_green = preferred->g; packet->color_blue = preferred->b; } else { fc_assert(!game_was_started()); - /* Can't tell the client 'no color', so use dummy values (black). */ + packet->color_valid = FALSE; + /* Client shouldn't use these dummy values */ packet->color_red = 0; packet->color_green = 0; packet->color_blue = 0; } } + packet->color_changeable = player_color_changeable(plr, NULL); /* Only send score if we have contact */ if (info_level >= INFO_MEETING) { @@ -1376,6 +1380,23 @@ } /**************************************************************************** + Return whether a player's color can currently be set with the + '/playercolor' command. If not, give a reason why not, if 'reason' is + not NULL (need not be freed). +****************************************************************************/ +bool player_color_changeable(const struct player *pplayer, const char **reason) +{ + if (!game_was_started() && game.server.plrcolormode != PLRCOL_PLR_SET) { + if (reason) { + *reason = _("Can only set player color prior to game start if " + "'plrcolormode' is PLR_SET."); + } + return FALSE; + } + return TRUE; +} + +/**************************************************************************** Permanently assign colors to any players that don't already have them. First assign preferred colors, then assign the rest randomly, trying to avoid clashes. @@ -1475,7 +1496,7 @@ if (prgbcolor != NULL) { player_set_color(pplayer, prgbcolor); } else { - /* Server only: this can be NULL in pregame. */ + /* This can legitimately be NULL in pregame. */ fc_assert_ret(!game_was_started()); rgbcolor_destroy(pplayer->rgb); pplayer->rgb = NULL; Modified: branches/S2_6/server/plrhand.h URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/plrhand.h?rev=31150&r1=31149&r2=31150&view=diff ============================================================================== --- branches/S2_6/server/plrhand.h (original) +++ branches/S2_6/server/plrhand.h Tue Dec 22 11:02:51 2015 @@ -27,6 +27,7 @@ struct rgbcolor *prgbcolor, bool allow_ai_type_fallbacking); const struct rgbcolor *player_preferred_color(struct player *pplayer); +bool player_color_changeable(const struct player *pplayer, const char **reason); void assign_player_colors(void); void server_player_set_color(struct player *pplayer, const struct rgbcolor *prgbcolor); Modified: branches/S2_6/server/stdinhand.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/stdinhand.c?rev=31150&r1=31149&r2=31150&view=diff ============================================================================== --- branches/S2_6/server/stdinhand.c (original) +++ branches/S2_6/server/stdinhand.c Tue Dec 22 11:02:51 2015 @@ -3971,12 +3971,13 @@ goto cleanup; } - if (!game_was_started() && game.server.plrcolormode != PLRCOL_PLR_SET) { - cmd_reply(CMD_PLAYERCOLOR, caller, C_FAIL, - _("Can only set player color prior to game start if " - "'plrcolormode' is PLR_SET.")); - ret = FALSE; - goto cleanup; + { + const char *reason; + if (!player_color_changeable(pplayer, &reason)) { + cmd_reply(CMD_PLAYERCOLOR, caller, C_FAIL, "%s", reason); + ret = FALSE; + goto cleanup; + } } if (0 == fc_strcasecmp(token[1], "reset")) { _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits