Author: cazfi
Date: Sun Nov 22 14:33:01 2015
New Revision: 30739

URL: http://svn.gna.org/viewcvs/freeciv?rev=30739&view=rev
Log:
Made player AIness first of the new player flags.

See patch #6582

Modified:
    trunk/client/packhand.c
    trunk/common/packets.def
    trunk/common/player.c
    trunk/common/player.h
    trunk/common/scriptcore/api_game_methods.c
    trunk/common/scriptcore/api_game_methods.h
    trunk/common/scriptcore/tolua_game.pkg
    trunk/fc_version
    trunk/server/advisors/autoexplorer.c
    trunk/server/plrhand.c
    trunk/server/savegame.c
    trunk/server/savegame2.c
    trunk/server/savegame3.c
    trunk/utility/bitvector.h

Modified: trunk/client/packhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/packhand.c?rev=30739&r1=30738&r2=30739&view=diff
==============================================================================
--- trunk/client/packhand.c     (original)
+++ trunk/client/packhand.c     Sun Nov 22 14:33:01 2015
@@ -2208,8 +2208,8 @@
   }
 
   /* Set AI.control. */
-  if (pplayer->ai_controlled != pinfo->ai)  {
-    pplayer->ai_controlled = pinfo->ai;
+  if (is_ai(pplayer) != BV_ISSET(pinfo->flags, PLRF_AI)) {
+    BV_SET_VAL(pplayer->flags, PLRF_AI, BV_ISSET(pinfo->flags, PLRF_AI));
     if (pplayer == my_player)  {
       if (is_ai(my_player)) {
         output_window_append(ftc_client, _("AI mode is now ON."));
@@ -2219,10 +2219,13 @@
     }
   }
 
+  pplayer->flags = pinfo->flags;
+
   pplayer->ai_common.science_cost = pinfo->science_cost;
 
   turn_done_changed = (pplayer->phase_done != pinfo->phase_done
-                       || pplayer->ai_controlled != pinfo->ai);
+                       || (BV_ISSET(pplayer->flags, PLRF_AI) !=
+                           BV_ISSET(pinfo->flags, PLRF_AI)));
   pplayer->phase_done = pinfo->phase_done;
 
   pplayer->is_ready = pinfo->is_ready;

Modified: trunk/common/packets.def
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/packets.def?rev=30739&r1=30738&r2=30739&view=diff
==============================================================================
--- trunk/common/packets.def    (original)
+++ trunk/common/packets.def    Sun Nov 22 14:33:01 2015
@@ -265,6 +265,7 @@
 type BV_TECH_FLAGS      = bitvector(bv_tech_flags)
 type BV_TERRAIN_FLAGS   = bitvector(bv_terrain_flags)
 type BV_UCLASS_FLAGS    = bitvector(bv_unit_class_flags)
+type BV_PLR_FLAGS       = bitvector(bv_plr_flags)
 type BV_UNIT_CLASSES    = bitvector(bv_unit_classes)
 type BV_UTYPE_FLAGS     = bitvector(bv_unit_type_flags)
 type BV_UTYPE_ROLES     = bitvector(bv_unit_type_roles)
@@ -809,7 +810,6 @@
 
   BOOL is_connected;
   TURN revolution_finishes;
-  BOOL ai;
   UINT8 ai_skill_level;
   UINT8 barbarian_type;
   BV_PLAYER gives_shared_vision;
@@ -819,6 +819,8 @@
   UINT8 color_red;
   UINT8 color_green;
   UINT8 color_blue;
+
+  BV_PLR_FLAGS flags;
 
   CITYSPE wonders[B_LAST]; diff
   

Modified: trunk/common/player.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/player.c?rev=30739&r1=30738&r2=30739&view=diff
==============================================================================
--- trunk/common/player.c       (original)
+++ trunk/common/player.c       Sun Nov 22 14:33:01 2015
@@ -566,6 +566,8 @@
   pplayer->economic.luxury  = PLAYER_DEFAULT_LUXURY_RATE;
 
   spaceship_init(&pplayer->spaceship);
+
+  BV_CLR_ALL(pplayer->flags);
 
   set_as_human(pplayer);
   pplayer->ai_common.skill_level = ai_level_invalid();
@@ -1769,3 +1771,11 @@
 {
   return pplayer->multipliers_target[multiplier_index(pmul)];
 }
+
+/****************************************************************************
+  Check if player has given flag
+****************************************************************************/
+bool player_has_flag(const struct player *pplayer, enum plr_flag_id flag)
+{
+  return BV_ISSET(pplayer->flags, flag);
+}

Modified: trunk/common/player.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/player.h?rev=30739&r1=30738&r2=30739&view=diff
==============================================================================
--- trunk/common/player.h       (original)
+++ trunk/common/player.h       Sun Nov 22 14:33:01 2015
@@ -52,6 +52,13 @@
   PLRCOL_TEAM_ORDER,
   PLRCOL_NATION_ORDER
 };
+
+#define SPECENUM_NAME plr_flag_id
+#define SPECENUM_VALUE0 PLRF_AI
+#define SPECENUM_VALUE0NAME "ai"
+#define SPECENUM_COUNT  PLRF_COUNT
+#define SPECENUM_BITVECTOR bv_plr_flags
+#include "specenum_gen.h"
 
 struct player_slot;
 
@@ -216,10 +223,12 @@
 struct ai_type;
 struct ai_data;
 
-#define is_human(plr) !(plr)->ai_controlled
-#define is_ai(plr) (plr)->ai_controlled
-#define set_as_human(plr) (plr)->ai_controlled = FALSE
-#define set_as_ai(plr) (plr)->ai_controlled = TRUE
+bool player_has_flag(const struct player *pplayer, enum plr_flag_id flag);
+
+#define is_human(plr) !player_has_flag((plr), PLRF_AI)
+#define is_ai(plr) player_has_flag((plr), PLRF_AI)
+#define set_as_human(plr) BV_CLR((plr)->flags, PLRF_AI)
+#define set_as_ai(plr) BV_SET((plr)->flags, PLRF_AI)
 
 struct player {
   struct player_slot *slot;
@@ -258,9 +267,10 @@
 
   struct player_spaceship spaceship;
 
-  bool ai_controlled; /* FALSE: not automated; TRUE: automated */
   struct player_ai ai_common;
   const struct ai_type *ai;
+
+  bv_plr_flags flags;
 
   bool was_created;                    /* if the player was /created */
   bool random_name;

Modified: trunk/common/scriptcore/api_game_methods.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/scriptcore/api_game_methods.c?rev=30739&r1=30738&r2=30739&view=diff
==============================================================================
--- trunk/common/scriptcore/api_game_methods.c  (original)
+++ trunk/common/scriptcore/api_game_methods.c  Sun Nov 22 14:33:01 2015
@@ -365,6 +365,25 @@
   return player_culture(pplayer);
 }
 
+/**************************************************************************
+  Does player have flag set?
+**************************************************************************/
+bool api_methods_player_has_flag(lua_State *L, Player *pplayer, const char 
*flag)
+{
+  enum plr_flag_id flag_val;
+  
+  LUASCRIPT_CHECK_STATE(L, 0);
+  LUASCRIPT_CHECK_SELF(L, pplayer, 0);
+
+  flag_val = plr_flag_id_by_name(flag, fc_strcasecmp);
+
+  if (plr_flag_id_is_valid(flag_val)) {
+    return player_has_flag(pplayer, flag_val);
+  }
+
+  return FALSE;
+}
+
 /*****************************************************************************
   Return TRUE if players share research.
 *****************************************************************************/

Modified: trunk/common/scriptcore/api_game_methods.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/scriptcore/api_game_methods.h?rev=30739&r1=30738&r2=30739&view=diff
==============================================================================
--- trunk/common/scriptcore/api_game_methods.h  (original)
+++ trunk/common/scriptcore/api_game_methods.h  Sun Nov 22 14:33:01 2015
@@ -83,6 +83,8 @@
                                                           Player *pplayer);
 int api_methods_player_culture_get(lua_State *L, Player *pplayer);
 
+bool api_methods_player_has_flag(lua_State *L, Player *pplayer, const char 
*flag);
+
 /* Tech Type */
 const char *api_methods_tech_type_rule_name(lua_State *L, Tech_Type *ptech);
 const char *api_methods_tech_type_name_translation(lua_State *L, Tech_Type 
*ptech);

Modified: trunk/common/scriptcore/tolua_game.pkg
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/scriptcore/tolua_game.pkg?rev=30739&r1=30738&r2=30739&view=diff
==============================================================================
--- trunk/common/scriptcore/tolua_game.pkg      (original)
+++ trunk/common/scriptcore/tolua_game.pkg      Sun Nov 22 14:33:01 2015
@@ -33,7 +33,6 @@
 struct Player {
   const char *name;
   Nation_Type *nation;
-  bool ai_controlled;
   bool is_alive;
 };
 
@@ -139,6 +138,8 @@
 
   int api_methods_player_culture_get
     @ culture(lua_State *L, Player *self);
+  bool api_methods_player_has_flag
+    @ has_flag (lua_State *L, Player *self, const char *flag);
 }
 
 module methods_private {
@@ -154,7 +155,7 @@
 
 -- Player methods
 function Player:is_human()
-  return not self.ai_controlled
+  return not self.has_flag(self, "AI");
 end
 
 function Player:exists()

Modified: trunk/fc_version
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/fc_version?rev=30739&r1=30738&r2=30739&view=diff
==============================================================================
--- trunk/fc_version    (original)
+++ trunk/fc_version    Sun Nov 22 14:33:01 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-3.0-2015.Nov.19b"
+NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-3.0-2015.Nov.22"
 NETWORK_CAPSTRING_OPTIONAL=""
 
 FREECIV_DISTRIBUTOR=""

Modified: trunk/server/advisors/autoexplorer.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/advisors/autoexplorer.c?rev=30739&r1=30738&r2=30739&view=diff
==============================================================================
--- trunk/server/advisors/autoexplorer.c        (original)
+++ trunk/server/advisors/autoexplorer.c        Sun Nov 22 14:33:01 2015
@@ -375,7 +375,7 @@
      * which goes beside the unknown, with a good EC callback... */
     enum override_bool allow = NO_OVERRIDE;
 
-    if (pplayer->ai_controlled) {
+    if (is_ai(pplayer)) {
       CALL_PLR_AI_FUNC(want_to_explore, pplayer, punit, best_tile, &allow);
     }
     if (allow == OVERRIDE_FALSE) {

Modified: trunk/server/plrhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/plrhand.c?rev=30739&r1=30738&r2=30739&view=diff
==============================================================================
--- trunk/server/plrhand.c      (original)
+++ trunk/server/plrhand.c      Sun Nov 22 14:33:01 2015
@@ -1016,10 +1016,10 @@
     packet->music_style = -1; /* No music style available */
   }
 
-  packet->is_alive=plr->is_alive;
-  packet->turns_alive=plr->turns_alive;
-  packet->is_connected=plr->is_connected;
-  packet->ai = plr->ai_controlled;
+  packet->is_alive = plr->is_alive;
+  packet->turns_alive = plr->turns_alive;
+  packet->is_connected = plr->is_connected;
+  packet->flags = plr->flags;
   packet->ai_skill_level = is_ai(plr)
                            ? plr->ai_common.skill_level : 0;
   for (i = 0; i < player_slot_count(); i++) {

Modified: trunk/server/savegame.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame.c?rev=30739&r1=30738&r2=30739&view=diff
==============================================================================
--- trunk/server/savegame.c     (original)
+++ trunk/server/savegame.c     Sun Nov 22 14:33:01 2015
@@ -1686,6 +1686,7 @@
   struct nation_type *pnation;
   struct nation_style *style;
   int old_barb_type;
+  bool ai_controlled;
 
   research = research_get(plr);
 
@@ -1788,6 +1789,7 @@
   p = secfile_lookup_str(file, "player%d.city_style_by_name", plrno);
   if (!p) {
     char* old_order[4] = {"European", "Classical", "Tropical", "Asian"};
+
     c_s = secfile_lookup_int_default(file, 0, "player%d.city_style", plrno);
     if (c_s < 0 || c_s > 3) {
       log_error("Player%d: unsupported city_style %d. Changed to \"%s\".",
@@ -1804,16 +1806,21 @@
   }
   plr->style = style;
 
-  plr->nturns_idle=0;
-  plr->is_male=secfile_lookup_bool_default(file, TRUE, "player%d.is_male", 
plrno);
+  plr->nturns_idle = 0;
+  plr->is_male = secfile_lookup_bool_default(file, TRUE, "player%d.is_male", 
plrno);
   fc_assert_exit_msg(secfile_lookup_bool(file, &plr->is_alive,
                                          "player%d.is_alive", plrno),
                      "%s", secfile_error());
   plr->turns_alive = secfile_lookup_int_default(file, game.info.turn,
                                                 "player%d.turns_alive", plrno);
-  fc_assert_exit_msg(secfile_lookup_bool(file, &plr->ai_controlled,
+  fc_assert_exit_msg(secfile_lookup_bool(file, &ai_controlled,
                                          "player%d.ai.control", plrno),
                      "%s", secfile_error());
+  if (ai_controlled) {
+    set_as_ai(player_by_number(plrno));
+  } else {
+    set_as_human(player_by_number(plrno));
+  }
   plr->phase_done = FALSE;
 
   /* Backwards-compatibility: the tech goal value is still stored in the
@@ -4224,7 +4231,7 @@
   /* Recalculate the potential buildings for each city.  
    * Has caused some problems with game random state. */
   players_iterate(pplayer) {
-    bool saved_ai_control = pplayer->ai_controlled;
+    bool saved_ai_control = is_ai(pplayer);
 
     /* Recalculate for all players. */
     set_as_human(pplayer);
@@ -4235,7 +4242,9 @@
     /* Close data phase again so it can be opened again when game starts. */
     adv_data_phase_done(pplayer);
 
-    pplayer->ai_controlled = saved_ai_control;
+    if (saved_ai_control) {
+      set_as_ai(pplayer);
+    }
   } players_iterate_end;
 
   /* Player colors are always needed once game has started. Pre-2.4 savegames

Modified: trunk/server/savegame2.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame2.c?rev=30739&r1=30738&r2=30739&view=diff
==============================================================================
--- trunk/server/savegame2.c    (original)
+++ trunk/server/savegame2.c    Sun Nov 22 14:33:01 2015
@@ -2714,6 +2714,7 @@
   struct government *gov;
   const char *level;
   const char *barb_str;
+  bool ai_controlled;
 
   /* Check status and return if not OK (sg_success != TRUE). */
   sg_check_ret();
@@ -2775,9 +2776,14 @@
                                      "player%d.got_first_city", plrno),
                  "%s", secfile_error());
 
-  sg_failure_ret(secfile_lookup_bool(loading->file, &plr->ai_controlled,
+  sg_failure_ret(secfile_lookup_bool(loading->file, &ai_controlled,
                                      "player%d.ai.control", plrno),
                  "%s", secfile_error());
+  if (ai_controlled) {
+    set_as_ai(player_by_number(plrno));
+  } else {
+    set_as_human(player_by_number(plrno));
+  }
 
   /* Load diplomatic data (diplstate + embassy + vision).
    * Shared vision is loaded in sg_load_players(). */
@@ -5019,7 +5025,7 @@
    * This also changes the game state if you save the game directly after
    * loading it and compare the results. */
   players_iterate(pplayer) {
-    bool saved_ai_control = pplayer->ai_controlled;
+    bool saved_ai_control = is_ai(pplayer);
 
     /* Recalculate for all players. */
     set_as_human(pplayer);
@@ -5030,7 +5036,9 @@
     /* Close data phase again so it can be opened again when game starts. */
     adv_data_phase_done(pplayer);
 
-    pplayer->ai_controlled = saved_ai_control;
+    if (saved_ai_control) {
+      set_as_ai(pplayer);
+    }
   } players_iterate_end;
 
   /* Check worked tiles map */

Modified: trunk/server/savegame3.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame3.c?rev=30739&r1=30738&r2=30739&view=diff
==============================================================================
--- trunk/server/savegame3.c    (original)
+++ trunk/server/savegame3.c    Sun Nov 22 14:33:01 2015
@@ -3553,6 +3553,7 @@
   struct government *gov;
   const char *level;
   const char *barb_str;
+  bool ai_controlled;
 
   /* Check status and return if not OK (sg_success != TRUE). */
   sg_check_ret();
@@ -3614,9 +3615,14 @@
                                      "player%d.got_first_city", plrno),
                  "%s", secfile_error());
 
-  sg_failure_ret(secfile_lookup_bool(loading->file, &plr->ai_controlled,
+  sg_failure_ret(secfile_lookup_bool(loading->file, &ai_controlled,
                                      "player%d.ai.control", plrno),
                  "%s", secfile_error());
+  if (ai_controlled) {
+    set_as_ai(player_by_number(plrno));
+  } else {
+    set_as_human(player_by_number(plrno));
+  }
 
   /* Load diplomatic data (diplstate + embassy + vision).
    * Shared vision is loaded in sg_load_players(). */
@@ -6790,7 +6796,7 @@
    * This also changes the game state if you save the game directly after
    * loading it and compare the results. */
   players_iterate(pplayer) {
-    bool saved_ai_control = pplayer->ai_controlled;
+    bool saved_ai_control = is_ai(pplayer);
 
     /* Recalculate for all players. */
     set_as_human(pplayer);
@@ -6801,7 +6807,9 @@
     /* Close data phase again so it can be opened again when game starts. */
     adv_data_phase_done(pplayer);
 
-    pplayer->ai_controlled = saved_ai_control;
+    if (saved_ai_control) {
+      set_as_ai(pplayer);
+    }
   } players_iterate_end;
 
   /* Check worked tiles map */

Modified: trunk/utility/bitvector.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/utility/bitvector.h?rev=30739&r1=30738&r2=30739&view=diff
==============================================================================
--- trunk/utility/bitvector.h   (original)
+++ trunk/utility/bitvector.h   Sun Nov 22 14:33:01 2015
@@ -80,6 +80,10 @@
     _BV_ASSERT(bv, bit);                                                    \
     (bv).vec[_BV_BYTE_INDEX(bit)] &= ~_BV_BITMASK(bit);                     \
   } while(FALSE)
+#define BV_SET_VAL(bv, bit, val)                                            \
+  do {                                                                      \
+    if (val) { BV_SET(bv, bit); } else { BV_CLR(bv, bit); }                 \
+  } while (FALSE);
 #define BV_CLR_ALL(bv)                                                      \
   do {                                                                      \
      memset((bv).vec, 0, sizeof((bv).vec));                                 \


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to