Author: sveinung
Date: Sun Jan 10 13:10:44 2016
New Revision: 31431

URL: http://svn.gna.org/viewcvs/freeciv?rev=31431&view=rev
Log:
protocol: remove ruleset_tech's req1 and req2.

Remove the fields req1 and req2 from the ruleset_tech packet. Split their
content depending on what is being communicated.

The meaning of "Never" in a tech's req1 and/or req2 field is that the tech
is removed. Transfer this in the ruleset_tech packet's new removed field.

The meaning of another tech in a tech's req1 and/or req2 field is that it
is needed to research the tech with the field. This is a research
requirement. Start packing them in the research_reqs requirement vector
when transferring a ruleset_tech packet.

The meaning of "None" in req1 and/or req2 is the lack of a tech requirement
to research the tech. Transfer this by not putting a requirement in the
research_reqs requirement vector.

See patch #6807

Modified:
    trunk/client/packhand.c
    trunk/common/packets.def
    trunk/fc_version
    trunk/server/ruleset.c

Modified: trunk/client/packhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/packhand.c?rev=31431&r1=31430&r2=31431&view=diff
==============================================================================
--- trunk/client/packhand.c     (original)
+++ trunk/client/packhand.c     Sun Jan 10 13:10:44 2016
@@ -3248,6 +3248,41 @@
   set_user_unit_type_flag_name(p->id, flagname, helptxt);
 }
 
+/**************************************************************************
+  Unpack a traditional tech req from a standard requirement vector (that
+  still is in the network serialized format rather than a proper
+  requirement vector).
+
+  Returns the position in the requirement vector after unpacking. It will
+  increase if a tech req was extracted.
+**************************************************************************/
+static int unpack_tech_req(const enum tech_req r_num,
+                           const int reqs_size,
+                           const struct requirement *reqs,
+                           struct advance *a,
+                           int i)
+{
+  if (i < reqs_size
+      && reqs[i].source.kind == VUT_ADVANCE) {
+    /* Extract the tech req so the old code can reason about it. */
+
+    /* This IS a traditional tech req... right? */
+    fc_assert(reqs[i].present);
+    fc_assert(reqs[i].range == REQ_RANGE_PLAYER);
+
+    /* Put it in the advance structure. */
+    a->require[r_num] = reqs[i].source.value.advance;
+
+    /* Move on in the requirement vector. */
+    i++;
+  } else {
+    /* No tech req. */
+    a->require[r_num] = advance_by_number(A_NONE);
+  }
+
+  return i;
+}
+
 /****************************************************************************
   Packet ruleset_tech handler.
 ****************************************************************************/
@@ -3262,14 +3297,41 @@
   sz_strlcpy(a->graphic_str, p->graphic_str);
   sz_strlcpy(a->graphic_alt, p->graphic_alt);
 
-  a->require[AR_ONE] = advance_by_number(p->req[AR_ONE]);
-  a->require[AR_TWO] = advance_by_number(p->req[AR_TWO]);
+  i = 0;
+
+  /* The tech requirements req1 and req2 are send inside research_reqs
+   * since they too are required to be fulfilled before the tech can be
+   * researched. */
+
+  if (p->removed) {
+    /* The Freeciv data structures currently records that a tech is removed
+     * by setting req1 and req2 to "Never". */
+    a->require[AR_ONE] = A_NEVER;
+    a->require[AR_TWO] = A_NEVER;
+  } else {
+    /* Unpack req1 and req2 from the research_reqs requirement vector. */
+    i = unpack_tech_req(AR_ONE, p->research_reqs_count, p->research_reqs, a, 
i);
+    i = unpack_tech_req(AR_TWO, p->research_reqs_count, p->research_reqs, a, 
i);
+  }
+
+  /* Any remaining requirements are a part of the research_reqs requirement
+   * vector. */
+  for (; i < p->research_reqs_count; i++) {
+    requirement_vector_append(&a->research_reqs, p->research_reqs[i]);
+  }
+
+  /* The packet's research_reqs should contain req1, req2 and the
+   * requirements of the tech's research_reqs. */
+  fc_assert((a->research_reqs.size
+             + ((a->require[AR_ONE]
+                 && (advance_number(a->require[AR_ONE]) != A_NONE)) ?
+                  1 : 0)
+             + ((a->require[AR_TWO]
+                 && (advance_number(a->require[AR_TWO]) != A_NONE)) ?
+                  1 : 0))
+            == p->research_reqs_count);
+
   a->require[AR_ROOT] = advance_by_number(p->root_req);
-  for (i = 0; i < p->research_reqs_count; i++) {
-    requirement_vector_append(&a->research_reqs, p->research_reqs[i]);
-  }
-
-  fc_assert(a->research_reqs.size == p->research_reqs_count);
 
   a->flags = p->flags;
   a->cost = p->cost;

Modified: trunk/common/packets.def
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/packets.def?rev=31431&r1=31430&r2=31431&view=diff
==============================================================================
--- trunk/common/packets.def    (original)
+++ trunk/common/packets.def    Sun Jan 10 13:10:44 2016
@@ -1380,10 +1380,10 @@
 
 PACKET_RULESET_TECH = 144; sc, lsend
   TECH id;
-  TECH req[2];
   TECH root_req;
   UINT8 research_reqs_count;
   REQUIREMENT research_reqs[MAX_NUM_REQS:research_reqs_count];
+  BOOL removed;
   BV_TECH_FLAGS flags;
   UFLOAT10x3 cost;
   UINT32 num_reqs;

Modified: trunk/fc_version
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/fc_version?rev=31431&r1=31430&r2=31431&view=diff
==============================================================================
--- trunk/fc_version    (original)
+++ trunk/fc_version    Sun Jan 10 13:10:44 2016
@@ -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-2016.Jan.08"
+NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-3.0-2016.Jan.10"
 NETWORK_CAPSTRING_OPTIONAL=""
 
 FREECIV_DISTRIBUTOR=""

Modified: trunk/server/ruleset.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/ruleset.c?rev=31431&r1=31430&r2=31431&view=diff
==============================================================================
--- trunk/server/ruleset.c      (original)
+++ trunk/server/ruleset.c      Sun Jan 10 13:10:44 2016
@@ -6407,26 +6407,48 @@
 
   advance_iterate(A_FIRST, a) {
     packet.id = advance_number(a);
+    packet.removed = !valid_advance(a);
     sz_strlcpy(packet.name, untranslated_name(&a->name));
     sz_strlcpy(packet.rule_name, rule_name(&a->name));
     sz_strlcpy(packet.graphic_str, a->graphic_str);
     sz_strlcpy(packet.graphic_alt, a->graphic_alt);
 
-    packet.req[AR_ONE] = a->require[AR_ONE]
-                         ? advance_number(a->require[AR_ONE])
-                         : advance_count();
-    packet.req[AR_TWO] = a->require[AR_TWO]
-                         ? advance_number(a->require[AR_TWO])
-                         : advance_count();
+    /* Current size of the packet's research_reqs requirement vector. */
+    i = 0;
+
+    /* The requirements req1 and req2 are needed to research a tech. Send
+     * them in the research_reqs requirement vector. Range is set to player
+     * since pooled research is configurable. */
+
+    if ((a->require[AR_ONE] != A_NEVER)
+        && advance_number(a->require[AR_ONE]) > A_NONE) {
+      packet.research_reqs[i++]
+          = req_from_values(VUT_ADVANCE, REQ_RANGE_PLAYER,
+                            FALSE, TRUE, FALSE,
+                            advance_number(a->require[AR_ONE]));
+    }
+
+    if ((a->require[AR_TWO] != A_NEVER)
+        && advance_number(a->require[AR_TWO]) > A_NONE) {
+      packet.research_reqs[i++]
+          = req_from_values(VUT_ADVANCE, REQ_RANGE_PLAYER,
+                            FALSE, TRUE, FALSE,
+                            advance_number(a->require[AR_TWO]));;
+    }
+
+    /* The requirements of the tech's research_reqs also goes in the
+     * packet's research_reqs requirement vector. */
+    requirement_vector_iterate(&a->research_reqs, req) {
+      packet.research_reqs[i++] = *req;
+    } requirement_vector_iterate_end;
+
+    /* The packet's research_reqs should contain req1, req2 and the
+     * requirements of the tech's research_reqs. */
+    packet.research_reqs_count = i;
+
     packet.root_req = a->require[AR_ROOT]
                       ? advance_number(a->require[AR_ROOT])
                       : advance_count();
-
-    i = 0;
-    requirement_vector_iterate(&a->research_reqs, req) {
-      packet.research_reqs[i++] = *req;
-    } requirement_vector_iterate_end;
-    packet.research_reqs_count = i;
 
     packet.flags = a->flags;
     packet.cost = a->cost;


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

Reply via email to