Author: jtn
Date: Tue Nov 17 09:57:21 2015
New Revision: 30653

URL: http://svn.gna.org/viewcvs/freeciv?rev=30653&view=rev
Log:
Increase unit move_rate fields in network protocol to UINT16, to fix a
regression in range when using an increased move_fragments resolution.

Uses an optional network capability, so both client and server must be
upgraded to benefit. A new server encountering an old client emits
warning messages if a ruleset unit exceeds the capacity of the old
protocol.

Limitation reported by Michal Mazurek (akfaew@gna).

See gna bug #24074.

Modified:
    branches/S2_5/client/gui-gtk-2.0/editprop.c
    branches/S2_5/client/gui-gtk-3.0/editprop.c
    branches/S2_5/client/packhand.c
    branches/S2_5/common/packets.def
    branches/S2_5/fc_version
    branches/S2_5/server/edithand.c
    branches/S2_5/server/ruleset.c
    branches/S2_5/server/unittools.c

Modified: branches/S2_5/client/gui-gtk-2.0/editprop.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-gtk-2.0/editprop.c?rev=30653&r1=30652&r2=30653&view=diff
==============================================================================
--- branches/S2_5/client/gui-gtk-2.0/editprop.c (original)
+++ branches/S2_5/client/gui-gtk-2.0/editprop.c Tue Nov 17 09:57:21 2015
@@ -2200,7 +2200,9 @@
       }
 
       packet->id = punit->id;
-      packet->moves_left = punit->moves_left;
+      /* packet send code will take account of whether network connection
+       * has "extended_move_rate" capability */
+      packet->moves_left_old = packet->moves_left_new = punit->moves_left;
       packet->fuel = punit->fuel;
       packet->moved = punit->moved;
       packet->done_moving = punit->done_moving;
@@ -2368,7 +2370,9 @@
 
       switch (propid) {
       case OPID_UNIT_MOVES_LEFT:
-        packet->moves_left = pv->data.v_int;
+        /* packet send code will take account of whether network connection
+         * has "extended_move_rate" capability */
+        packet->moves_left_old = packet->moves_left_new = pv->data.v_int;
         return;
       case OPID_UNIT_FUEL:
         packet->fuel = pv->data.v_int;

Modified: branches/S2_5/client/gui-gtk-3.0/editprop.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-gtk-3.0/editprop.c?rev=30653&r1=30652&r2=30653&view=diff
==============================================================================
--- branches/S2_5/client/gui-gtk-3.0/editprop.c (original)
+++ branches/S2_5/client/gui-gtk-3.0/editprop.c Tue Nov 17 09:57:21 2015
@@ -2200,7 +2200,9 @@
       }
 
       packet->id = punit->id;
-      packet->moves_left = punit->moves_left;
+      /* packet send code will take account of whether network connection
+       * has "extended_move_rate" capability */
+      packet->moves_left_old = packet->moves_left_new = punit->moves_left;
       packet->fuel = punit->fuel;
       packet->moved = punit->moved;
       packet->done_moving = punit->done_moving;
@@ -2368,7 +2370,9 @@
 
       switch (propid) {
       case OPID_UNIT_MOVES_LEFT:
-        packet->moves_left = pv->data.v_int;
+        /* packet send code will take account of whether network connection
+         * has "extended_move_rate" capability */
+        packet->moves_left_old = packet->moves_left_new = pv->data.v_int;
         return;
       case OPID_UNIT_FUEL:
         packet->fuel = pv->data.v_int;

Modified: branches/S2_5/client/packhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/packhand.c?rev=30653&r1=30652&r2=30653&view=diff
==============================================================================
--- branches/S2_5/client/packhand.c     (original)
+++ branches/S2_5/client/packhand.c     Tue Nov 17 09:57:21 2015
@@ -184,7 +184,11 @@
   output_type_iterate(o) {
     punit->upkeep[o] = packet->upkeep[o];
   } output_type_iterate_end;
-  punit->moves_left = packet->movesleft;
+  if (has_capability("extended_move_rate", client.conn.capability)) {
+    punit->moves_left = packet->movesleft_new;
+  } else {
+    punit->moves_left = packet->movesleft_old;
+  }
   punit->hp = packet->hp;
   punit->activity = packet->activity;
   punit->activity_count = packet->activity_count;
@@ -2977,7 +2981,11 @@
 
   names_set(&c->name, NULL, p->name, p->rule_name);
   c->move_type   = p->move_type;
-  c->min_speed   = p->min_speed;
+  if (has_capability("extended_move_rate", client.conn.capability)) {
+    c->min_speed = p->min_speed_new;
+  } else {
+    c->min_speed = p->min_speed_old;
+  }
   c->hp_loss_pct = p->hp_loss_pct;
   c->hut_behavior = p->hut_behavior;
   c->flags       = p->flags;
@@ -3006,7 +3014,11 @@
   u->pop_cost           = p->pop_cost;
   u->attack_strength    = p->attack_strength;
   u->defense_strength   = p->defense_strength;
-  u->move_rate          = p->move_rate;
+  if (has_capability("extended_move_rate", client.conn.capability)) {
+    u->move_rate        = p->move_rate_new;
+  } else {
+    u->move_rate        = p->move_rate_old;
+  }
   u->require_advance    = advance_by_number(p->tech_requirement);
   u->need_improvement   = improvement_by_number(p->impr_requirement);
   u->need_government    = government_by_number(p->gov_requirement);
@@ -3037,11 +3049,15 @@
   if (p->veteran_levels == 0) {
     u->veteran = NULL;
   } else {
+    const int *move_bonus
+      = has_capability("extended_move_rate", client.conn.capability)
+        ? p->move_bonus_new : p->move_bonus_old;
+
     u->veteran = veteran_system_new(p->veteran_levels);
 
     for (i = 0; i < p->veteran_levels; i++) {
       veteran_system_definition(u->veteran, i, p->veteran_name[i],
-                                p->power_fact[i], p->move_bonus[i], 0, 0);
+                                p->power_fact[i], move_bonus[i], 0, 0);
     }
   }
 
@@ -3408,7 +3424,11 @@
   sz_strlcpy(proad->activity_gfx, p->activity_gfx);
   sz_strlcpy(proad->act_gfx_alt, p->act_gfx_alt);
 
-  proad->move_cost = p->move_cost;
+  if (has_capability("extended_move_rate", client.conn.capability)) {
+    proad->move_cost = p->move_cost_new;
+  } else {
+    proad->move_cost = p->move_cost_old;
+  }
   proad->move_mode = p->move_mode;
   proad->build_time = p->build_time;
   proad->defense_bonus = p->defense_bonus;
@@ -3671,10 +3691,16 @@
     game.rgame.global_init_buildings[i] = packet->global_init_buildings[i];
   }
 
-  for (i = 0; i < packet->veteran_levels; i++) {
-    veteran_system_definition(game.veteran, i, packet->veteran_name[i],
-                              packet->power_fact[i], packet->move_bonus[i],
-                              0, 0);
+  {
+    const int *move_bonus
+      = has_capability("extended_move_rate", client.conn.capability)
+        ? packet->move_bonus_new : packet->move_bonus_old;
+
+    for (i = 0; i < packet->veteran_levels; i++) {
+      veteran_system_definition(game.veteran, i, packet->veteran_name[i],
+                                packet->power_fact[i], move_bonus[i],
+                                0, 0);
+    }
   }
 
   fc_assert(game.plr_bg_color == NULL);

Modified: branches/S2_5/common/packets.def
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/common/packets.def?rev=30653&r1=30652&r2=30653&view=diff
==============================================================================
--- branches/S2_5/common/packets.def    (original)
+++ branches/S2_5/common/packets.def    Tue Nov 17 09:57:21 2015
@@ -822,7 +822,9 @@
 
   UNIT_TYPE type;
   UNIT transported_by; /* Only valid if transported is set. */
-  UINT8 movesleft, hp, fuel;
+  UINT8 movesleft_old;  remove-cap(extended_move_rate)
+  UINT16 movesleft_new; add-cap(extended_move_rate)
+  UINT8 hp, fuel;
   /* UINT16 size for activity_count assumed in checks in ruleset.c */
   UINT16 activity_count, changed_from_count;
   TILE goto_tile;
@@ -1216,7 +1218,8 @@
   UINT8 pop_cost;
   UINT8 attack_strength;
   UINT8 defense_strength;
-  UINT8 move_rate;
+  UINT8 move_rate_old;  remove-cap(extended_move_rate)
+  UINT16 move_rate_new; add-cap(extended_move_rate)
   TECH tech_requirement;
   UINT8 impr_requirement;
   GOVERNMENT gov_requirement;
@@ -1233,13 +1236,14 @@
   UINT8 upkeep[O_LAST]; # normal upkeep cost (food, gold, shields)
 
   UINT8 paratroopers_range;  # max range of paratroopers, F_PARATROOPERS
-  UINT8 paratroopers_mr_req;
-  UINT8 paratroopers_mr_sub;
+  UINT8 paratroopers_mr_req; # whole move points, not move_fragments
+  UINT8 paratroopers_mr_sub; # whole move points, not move_fragments
 
   UINT8 veteran_levels;
   STRING veteran_name[MAX_VET_LEVELS:veteran_levels][MAX_LEN_NAME];
   UINT16 power_fact[MAX_VET_LEVELS:veteran_levels];
-  UINT8 move_bonus[MAX_VET_LEVELS:veteran_levels];
+  UINT8 move_bonus_old[MAX_VET_LEVELS:veteran_levels];  
remove-cap(extended_move_rate)
+  UINT16 move_bonus_new[MAX_VET_LEVELS:veteran_levels]; 
add-cap(extended_move_rate)
 
   UINT8 bombard_rate;
   UINT8 city_size;
@@ -1277,7 +1281,8 @@
   UINT8 veteran_levels;
   STRING veteran_name[MAX_VET_LEVELS:veteran_levels][MAX_LEN_NAME];
   UINT16 power_fact[MAX_VET_LEVELS:veteran_levels];
-  UINT8 move_bonus[MAX_VET_LEVELS:veteran_levels];
+  UINT8 move_bonus_old[MAX_VET_LEVELS:veteran_levels];  
remove-cap(extended_move_rate)
+  UINT16 move_bonus_new[MAX_VET_LEVELS:veteran_levels]; 
add-cap(extended_move_rate)
 
   UINT8 background_red;
   UINT8 background_green;
@@ -1496,7 +1501,8 @@
   STRING name[MAX_LEN_NAME];
   STRING rule_name[MAX_LEN_NAME];
   UINT8 move_type;
-  UINT8 min_speed;
+  UINT8 min_speed_old;  remove-cap(extended_move_rate)
+  UINT16 min_speed_new; add-cap(extended_move_rate)
   UINT8 hp_loss_pct;
   UINT8 hut_behavior;
   BV_UCLASS_FLAGS flags;
@@ -1534,7 +1540,8 @@
   STRING graphic_alt[MAX_LEN_NAME];
   STRING activity_gfx[MAX_LEN_NAME];
   STRING act_gfx_alt[MAX_LEN_NAME];
-  UINT8 move_cost;
+  UINT8 move_cost_old;  remove-cap(extended_move_rate)
+  UINT16 move_cost_new; add-cap(extended_move_rate)
   MOVE_MODE move_mode;
   UINT8 build_time;
   UINT8 defense_bonus;
@@ -1870,7 +1877,8 @@
   UNIT_TYPE utype;
   PLAYER owner;
   CITY homecity;
-  UINT8 moves_left;
+  UINT8 moves_left_old;  remove-cap(extended_move_rate)
+  UINT16 moves_left_new; add-cap(extended_move_rate)
   UINT8 hp;
   UINT8 veteran;
   UINT8 fuel;

Modified: branches/S2_5/fc_version
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/fc_version?rev=30653&r1=30652&r2=30653&view=diff
==============================================================================
--- branches/S2_5/fc_version    (original)
+++ branches/S2_5/fc_version    Tue Nov 17 09:57:21 2015
@@ -55,7 +55,7 @@
 #     as long as possible.  We want to maintain network compatibility with
 #     the stable branch for as long as possible.
 NETWORK_CAPSTRING_MANDATORY="+Freeciv-2.5-network"
-NETWORK_CAPSTRING_OPTIONAL="nationset_change tech_cost split_reports"
+NETWORK_CAPSTRING_OPTIONAL="nationset_change tech_cost split_reports 
extended_move_rate"
 
 FREECIV_DISTRIBUTOR=""
 

Modified: branches/S2_5/server/edithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/edithand.c?rev=30653&r1=30652&r2=30653&view=diff
==============================================================================
--- branches/S2_5/server/edithand.c     (original)
+++ branches/S2_5/server/edithand.c     Tue Nov 17 09:57:21 2015
@@ -19,6 +19,7 @@
 
 /* utility */
 #include "bitvector.h"
+#include "capability.h"
 #include "fcintl.h"
 #include "log.h"
 #include "shared.h"
@@ -826,7 +827,11 @@
 
   putype = unit_type(punit);
 
-  moves_left = CLIP(0, packet->moves_left, putype->move_rate);
+  if (has_capability("extended_move_rate", pc->capability)) {
+    moves_left = CLIP(0, packet->moves_left_new, putype->move_rate);
+  } else {
+    moves_left = CLIP(0, packet->moves_left_old, putype->move_rate);
+  }
   if (moves_left != punit->moves_left) {
     punit->moves_left = moves_left;
     changed = TRUE;

Modified: branches/S2_5/server/ruleset.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/ruleset.c?rev=30653&r1=30652&r2=30653&view=diff
==============================================================================
--- branches/S2_5/server/ruleset.c      (original)
+++ branches/S2_5/server/ruleset.c      Tue Nov 17 09:57:21 2015
@@ -5232,7 +5232,9 @@
     sz_strlcpy(packet.name, untranslated_name(&c->name));
     sz_strlcpy(packet.rule_name, rule_name(&c->name));
     packet.move_type = c->move_type;
-    packet.min_speed = c->min_speed;
+    /* packet send code will take account of whether each connection
+     * has "extended_move_rate" capability */
+    packet.min_speed_old = packet.min_speed_new = c->min_speed;
     packet.hp_loss_pct = c->hp_loss_pct;
     packet.hut_behavior = c->hut_behavior;
     packet.flags = c->flags;
@@ -5289,7 +5291,9 @@
     packet.pop_cost = u->pop_cost;
     packet.attack_strength = u->attack_strength;
     packet.defense_strength = u->defense_strength;
-    packet.move_rate = u->move_rate;
+    /* packet send code will take account of whether each connection
+     * has "extended_move_rate" capability */
+    packet.move_rate_old = packet.move_rate_new = u->move_rate;
     packet.tech_requirement = u->require_advance
                               ? advance_number(u->require_advance)
                               : advance_count();
@@ -5339,10 +5343,35 @@
 
         sz_strlcpy(packet.veteran_name[i], untranslated_name(&vlevel->name));
         packet.power_fact[i] = vlevel->power_fact;
-        packet.move_bonus[i] = vlevel->move_bonus;
+        /* packet send code will take account of whether each connection
+         * has "extended_move_rate" capability */
+        packet.move_bonus_old[i] = packet.move_bonus_new[i]
+          = vlevel->move_bonus;
       }
     }
     PACKET_STRVEC_COMPUTE(packet.helptext, u->helptext);
+
+    /* Warn old clients about problems with large move_rates
+     * (there will also be a "Trying to put NNN into 8 bits" message
+     * at log_error level for each) */
+    if (u->move_rate >= 256) {
+      struct conn_list *oldconns = conn_list_new();
+
+      conn_list_iterate(dest, pconn) {
+        if (!has_capability("extended_move_rate", pconn->capability)) {
+          conn_list_append(oldconns, pconn);
+          log_error("%s has client too old to receive correct move_rate (%d) "
+                    "for %s", conn_description(pconn),
+                    u->move_rate / SINGLE_MOVE, utype_name_translation(u));
+        }
+      } conn_list_iterate_end;
+      notify_conn(oldconns, NULL, E_CONNECTION, ftc_warning, 
+                  "Warning: your client is too old to cope with the large "
+                  "move rate (%d) of %s in this ruleset; expect trouble "
+                  "with this unit.",
+                  u->move_rate / SINGLE_MOVE, utype_name_translation(u));
+      conn_list_destroy(oldconns);
+    }
 
     lsend_packet_ruleset_unit(dest, &packet);
 
@@ -5671,7 +5700,9 @@
     sz_strlcpy(packet.activity_gfx, r->activity_gfx);
     sz_strlcpy(packet.act_gfx_alt, r->act_gfx_alt);
 
-    packet.move_cost = r->move_cost;
+    /* packet send code will take account of whether each connection
+     * has "extended_move_rate" capability */
+    packet.move_cost_old = packet.move_cost_new = r->move_cost;
     packet.move_mode = r->move_mode;
     packet.build_time = r->build_time;
     packet.defense_bonus = r->defense_bonus;
@@ -5938,7 +5969,9 @@
 
     sz_strlcpy(misc_p.veteran_name[i], untranslated_name(&vlevel->name));
     misc_p.power_fact[i] = vlevel->power_fact;
-    misc_p.move_bonus[i] = vlevel->move_bonus;
+    /* packet send code will take account of whether each connection
+     * has "extended_move_rate" capability */
+    misc_p.move_bonus_old[i] = misc_p.move_bonus_new[i] = vlevel->move_bonus;
   }
 
   fc_assert(sizeof(misc_p.global_init_techs)

Modified: branches/S2_5/server/unittools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/unittools.c?rev=30653&r1=30652&r2=30653&view=diff
==============================================================================
--- branches/S2_5/server/unittools.c    (original)
+++ branches/S2_5/server/unittools.c    Tue Nov 17 09:57:21 2015
@@ -2286,7 +2286,9 @@
   } output_type_iterate_end;
   packet->veteran = punit->veteran;
   packet->type = utype_number(unit_type(punit));
-  packet->movesleft = punit->moves_left;
+  /* packet send code will take account of whether each connection
+   * has "extended_move_rate" capability */
+  packet->movesleft_old = packet->movesleft_new = punit->moves_left;
   packet->hp = punit->hp;
   packet->activity = punit->activity;
   packet->activity_count = punit->activity_count;


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

Reply via email to