Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2005:
[Freeciv-Dev] (PR#13042) give specialists their own packet
Home

[Freeciv-Dev] (PR#13042) give specialists their own packet

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#13042) give specialists their own packet
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 11 May 2005 12:54:32 -0700
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=13042 >

This patch makes the specialist into a separate network packet.  This
avoids some ugliness.

-jason
? vgcore.pid24244
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.514
diff -u -r1.514 packhand.c
--- client/packhand.c   11 May 2005 16:40:02 -0000      1.514
+++ client/packhand.c   11 May 2005 19:04:17 -0000
@@ -2425,25 +2425,7 @@
   int i;
 
   /* Must set num_specialist_types before iterating over them. */
-  SP_COUNT = packet->num_specialist_types;
   DEFAULT_SPECIALIST = packet->default_specialist;
-  i = 0;
-  specialist_type_iterate(sp) {
-    struct specialist *s = get_specialist(sp);
-    int j;
-
-    sz_strlcpy(s->name, packet->specialist_name[sp]);
-    sz_strlcpy(s->short_name, packet->specialist_short_name[sp]);
-
-    for (j = 0; j < packet->specialist_reqs_count[sp]; j++) {
-      requirement_vector_append(&s->reqs, &packet->specialist_reqs[i + j]);
-    }
-    assert(s->reqs.size == packet->specialist_reqs_count[sp]);
-    i += j;
-  } specialist_type_iterate_end;
-  tileset_setup_specialist_types(tileset);
-
-  assert(packet->specialist_reqs_size == i);
 
   for (i = 0; i < MAX_VET_LEVELS; i++) {
     game.trireme_loss_chance[i] = packet->trireme_loss_chance[i];
@@ -2453,6 +2435,33 @@
 }
 
 /**************************************************************************
+   Handle info about a single specialist.
+**************************************************************************/
+void handle_ruleset_specialist(struct packet_ruleset_specialist *p)
+{
+  int j;
+  struct specialist *s;
+
+  if (p->id < 0 || p->id >= game.control.num_specialist_types) {
+    freelog(LOG_ERROR,
+           "Received bad specialistd id %d in handle_ruleset_specialist",
+           p->id);
+  }
+
+  s = get_specialist(p->id);
+
+  sz_strlcpy(s->name, p->name);
+  sz_strlcpy(s->short_name, p->short_name);
+
+  for (j = 0; j < p->reqs_count; j++) {
+    requirement_vector_append(&s->reqs, &p->reqs[j]);
+  }
+  assert(s->reqs.size == p->reqs_count);
+
+  tileset_setup_specialist_type(tileset, p->id);
+}
+
+/**************************************************************************
   ...
 **************************************************************************/
 void handle_unit_bribe_info(int unit_id, int cost)
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.303
diff -u -r1.303 tilespec.c
--- client/tilespec.c   10 May 2005 17:01:23 -0000      1.303
+++ client/tilespec.c   11 May 2005 19:04:18 -0000
@@ -883,7 +883,9 @@
       tileset_setup_tech_type(tileset, tech_id);
     }
   } tech_type_iterate_end;
-  tileset_setup_specialist_types(tileset);
+  specialist_type_iterate(sp) {
+    tileset_setup_specialist_type(tileset, sp);
+  } specialist_type_iterate_end;
 
   /* tilespec_load_tiles reverts the city tile pointers to 0.  This
      is a workaround. */
@@ -1703,28 +1705,26 @@
 /****************************************************************************
   Setup the graphics for specialist types.
 ****************************************************************************/
-void tileset_setup_specialist_types(struct tileset *t)
+void tileset_setup_specialist_type(struct tileset *t, Specialist_type_id id)
 {
   /* Load the specialist sprite graphics. */
-  specialist_type_iterate(i) {
-    struct citizen_type c = {.type = CITIZEN_SPECIALIST, .spec_type = i};
-    const char *name = get_citizen_name(c);
-    char buffer[512];
-    int j;
+  struct citizen_type c = {.type = CITIZEN_SPECIALIST, .spec_type = id};
+  const char *name = get_citizen_name(c);
+  char buffer[512];
+  int j;
 
-    for (j = 0; j < NUM_TILES_CITIZEN; j++) {
-      my_snprintf(buffer, sizeof(buffer), "specialist.%s_%d", name, j);
-      t->sprites.specialist[i].sprite[j] = load_sprite(t, buffer);
-      if (!t->sprites.specialist[i].sprite[j]) {
-       break;
-      }
-    }
-    t->sprites.specialist[i].count = j;
-    if (j == 0) {
-      freelog(LOG_NORMAL, _("No graphics for specialist %s."), name);
-      exit(EXIT_FAILURE);
+  for (j = 0; j < NUM_TILES_CITIZEN; j++) {
+    my_snprintf(buffer, sizeof(buffer), "specialist.%s_%d", name, j);
+    t->sprites.specialist[id].sprite[j] = load_sprite(t, buffer);
+    if (!t->sprites.specialist[id].sprite[j]) {
+      break;
     }
-  } specialist_type_iterate_end;
+  }
+  t->sprites.specialist[id].count = j;
+  if (j == 0) {
+    freelog(LOG_NORMAL, _("No graphics for specialist %s."), name);
+    exit(EXIT_FAILURE);
+  }
 }
 
 /****************************************************************************
Index: client/tilespec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.h,v
retrieving revision 1.151
diff -u -r1.151 tilespec.h
--- client/tilespec.h   30 Apr 2005 17:09:25 -0000      1.151
+++ client/tilespec.h   11 May 2005 19:04:18 -0000
@@ -112,7 +112,7 @@
 void tilespec_reread(const char *tileset_name);
 void tilespec_reread_callback(struct client_option *option);
 
-void tileset_setup_specialist_types(struct tileset *t);
+void tileset_setup_specialist_type(struct tileset *t, int id);
 void tileset_setup_unit_type(struct tileset *t, int id);
 void tileset_setup_impr_type(struct tileset *t, int id);
 void tileset_setup_tech_type(struct tileset *t, int id);
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.124
diff -u -r1.124 packets.def
--- common/packets.def  11 May 2005 14:11:21 -0000      1.124
+++ common/packets.def  11 May 2005 19:04:22 -0000
@@ -228,7 +228,7 @@
   Spaceship
   Ruleset
 
-The last used packet number is 115.
+The last used packet number is 116.
 ****************************************************/
 
 
@@ -1045,21 +1045,23 @@
   bitvector(bv_roles) roles;
 end
 
-/* stuff that does not fit yet in game_info */
 PACKET_RULESET_GAME=97;sc,lsend
-  UINT8 default_specialist, num_specialist_types;
-  UINT8 bonus_array_size; # Hack to get around limitations of packgen
-  STRING specialist_name[SP_MAX:num_specialist_types][MAX_LEN_NAME];
-  STRING specialist_short_name[SP_MAX:num_specialist_types][MAX_LEN_NAME];
-  UINT16 specialist_reqs_size;
-  UINT8 specialist_reqs_count[SP_MAX:num_specialist_types];
-  REQUIREMENT specialist_reqs[SP_MAX * MAX_NUM_REQS:specialist_reqs_size];
+  UINT8 default_specialist;
+
   TECH_LIST global_init_techs[MAX_NUM_TECH_LIST];
   UINT8 trireme_loss_chance[MAX_VET_LEVELS];
   UINT8 work_veteran_chance[MAX_VET_LEVELS];
   UINT8 veteran_chance[MAX_VET_LEVELS];
 end
 
+PACKET_RULESET_SPECIALIST=116;sc,lsend
+  SPECIALIST id;
+  STRING name[MAX_LEN_NAME];
+  STRING short_name[MAX_LEN_NAME];
+  UINT8 reqs_count;
+  REQUIREMENT reqs[MAX_NUM_REQS:reqs_count];
+end
+
 PACKET_RULESET_GOVERNMENT_RULER_TITLE=98;sc,lsend
   GOVERNMENT gov;
   UINT8 id;
@@ -1249,6 +1251,7 @@
   UINT8 playable_nation_count;
   UINT8 styles_count;
   UINT8 terrain_count;
+  UINT8 num_specialist_types;
 
   STRING team_name[MAX_NUM_TEAMS][MAX_LEN_NAME];
 end
Index: common/specialist.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/specialist.c,v
retrieving revision 1.3
diff -u -r1.3 specialist.c
--- common/specialist.c 11 May 2005 14:11:21 -0000      1.3
+++ common/specialist.c 11 May 2005 19:04:22 -0000
@@ -17,10 +17,10 @@
 
 #include "city.h"
 #include "effects.h"
+#include "game.h"
 #include "specialist.h"
 
 struct specialist specialists[SP_MAX];
-int num_specialist_types;
 int default_specialist;
 
 /****************************************************************************
Index: common/specialist.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/specialist.h,v
retrieving revision 1.3
diff -u -r1.3 specialist.h
--- common/specialist.h 11 May 2005 14:11:21 -0000      1.3
+++ common/specialist.h 11 May 2005 19:04:22 -0000
@@ -26,11 +26,10 @@
   struct requirement_vector reqs;
 };
 
-#define SP_COUNT num_specialist_types
+#define SP_COUNT game.control.num_specialist_types
 #define DEFAULT_SPECIALIST default_specialist
 
 extern struct specialist specialists[SP_MAX];
-extern int num_specialist_types;
 extern int default_specialist;
 
 void specialists_init(void);
Index: server/ruleset.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v
retrieving revision 1.262
diff -u -r1.262 ruleset.c
--- server/ruleset.c    11 May 2005 16:44:34 -0000      1.262
+++ server/ruleset.c    11 May 2005 19:04:23 -0000
@@ -2621,6 +2621,31 @@
 }
 
 /**************************************************************************
+  Send the specialists ruleset information (all individual specialist
+  types) to the specified connections.
+**************************************************************************/
+static void send_ruleset_specialists(struct conn_list *dest)
+{
+  struct packet_ruleset_specialist packet;
+
+  specialist_type_iterate(spec_id) {
+    struct specialist *s = get_specialist(spec_id);
+    int j;
+
+    packet.id = spec_id;
+    sz_strlcpy(packet.name, s->name);
+    sz_strlcpy(packet.short_name, s->short_name);
+    j = 0;
+    requirement_vector_iterate(&s->reqs, preq) {
+      packet.reqs[j++] = *preq;
+    } requirement_vector_iterate_end;
+    packet.reqs_count = j;
+
+    lsend_packet_ruleset_specialist(dest, &packet);
+  } specialist_type_iterate_end;
+}
+
+/**************************************************************************
   Send the techs ruleset information (all individual advances) to the
   specified connections.
 **************************************************************************/
@@ -2910,28 +2935,6 @@
 static void send_ruleset_game(struct conn_list *dest)
 {
   struct packet_ruleset_game misc_p;
-  int i;
-
-  misc_p.num_specialist_types = SP_COUNT;
-  misc_p.bonus_array_size = SP_COUNT * O_COUNT;
-  misc_p.default_specialist = DEFAULT_SPECIALIST;
-  i = 0;
-  specialist_type_iterate(sp) {
-    struct specialist *s = get_specialist(sp);
-    int j;
-
-    sz_strlcpy(misc_p.specialist_name[sp], s->name);
-    sz_strlcpy(misc_p.specialist_short_name[sp], s->short_name);
-
-    j = 0;
-    requirement_vector_iterate(&s->reqs, preq) {
-      misc_p.specialist_reqs[i + j] = *preq;
-      j++;
-    } requirement_vector_iterate_end;
-    i += j;
-    misc_p.specialist_reqs_count[sp] = j;
-  } specialist_type_iterate_end;
-  misc_p.specialist_reqs_size = i;
 
   memcpy(misc_p.trireme_loss_chance, game.trireme_loss_chance, 
          sizeof(game.trireme_loss_chance));
@@ -3036,6 +3039,7 @@
   send_ruleset_techs(dest);
   send_ruleset_governments(dest);
   send_ruleset_units(dest);
+  send_ruleset_specialists(dest);
   send_ruleset_terrain(dest);
   send_ruleset_buildings(dest);
   send_ruleset_nations(dest);

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#13042) give specialists their own packet, Jason Short <=