Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2001:
[Freeciv-Dev] Re: [RFC PATCH] init_techs
Home

[Freeciv-Dev] Re: [RFC PATCH] init_techs

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: [RFC PATCH] init_techs
From: Arien Malec <arien_malec@xxxxxxxxx>
Date: Thu, 20 Sep 2001 17:19:38 -0700 (PDT)

OK, here's an updated patch that frees the memory returned by
secfile_lookup_str_vec & implements sending the new information over the game
ruleset packet.

The variable doesn't need to be saved to the savefile, since it only applies at
game start...

So from my perspective, the patch is complete. If there are any suggested
correction, I'd be happy to hear about them.

Arien

--- Arien Malec <arien_malec@xxxxxxxxx> wrote:
> Attached is a preliminary version of the init_techs patch
> 
> Things it does not do:
> 
> 1) Save ruleset options
> 2) Send information to client (is this needed?)
> 
> Questions I have:
> 
> 1) I've chosen games.ruleset.options.init_techs as the place to put the init
> techs list. Format for setting init techs is
> init_techs = "Explosives, Automobile, [etc]"
> 
> My earlier patch put this in techs.ruleset.options, but init_techs is not an
> option on how techs work, but an option setting initial game parameters. I'm
> open to suggestions on where to put this.
> 
> 2) Putting this in games.ruleset makes it necessary to move loading the
> game.ruleset after the loading of techs.
> 
> 3) I'm dynamically allocating the advances list in game.rgame. It never gets
> explicitly free'd which makes me somewhat nervous. It should, however, get
> discarded at server exit.
> 
> Comments?
> 
> Arien
> 
> __________________________________________________
> Terrorist Attacks on U.S. - How can you help?
> Donate cash, emergency relief information
> http://dailynews.yahoo.com/fc/US/Emergency_Information/> Index: common/game.h
> ===================================================================
> RCS file: /home/freeciv/CVS/freeciv/common/game.h,v
> retrieving revision 1.87
> diff -u -r1.87 game.h
> --- common/game.h 2001/09/16 12:43:25 1.87
> +++ common/game.h 2001/09/19 15:19:50
> @@ -141,7 +141,7 @@
>  
>    int watchtower_extra_vision;
>    int watchtower_vision;
> -
> +  
>    struct {
>      char techs[MAX_LEN_NAME];
>      char units[MAX_LEN_NAME];
> @@ -182,6 +182,8 @@
>      int nuke_contamination;
>      int granary_food_ini;
>      int granary_food_inc;
> +    int *init_techs; /* Advances to assign to all players at game
> +   start. A_LAST terminated.*/
>    } rgame;
>  
>    char demography[MAX_LEN_DEMOGRAPHY];
> Index: data/default/game.ruleset
> ===================================================================
> RCS file: /home/freeciv/CVS/freeciv/data/default/game.ruleset,v
> retrieving revision 1.3
> diff -u -r1.3 game.ruleset
> --- data/default/game.ruleset 2001/01/22 04:57:17 1.3
> +++ data/default/game.ruleset 2001/09/19 15:19:50
> @@ -14,6 +14,9 @@
>  description="Default game rules for Freeciv"
>  options="1.11.1"
>  
> +[options]
> +init_techs = ""
> +
>  [civstyle]
>  min_city_center_food = 1
>  min_city_center_shield = 1
> Index: server/plrhand.c
> ===================================================================
> RCS file: /home/freeciv/CVS/freeciv/server/plrhand.c,v
> retrieving revision 1.198
> diff -u -r1.198 plrhand.c
> --- server/plrhand.c 2001/09/12 09:12:14 1.198
> +++ server/plrhand.c 2001/09/19 15:19:52
> @@ -473,6 +473,9 @@
>    set_invention(plr, A_NONE, TECH_KNOWN);
>  
>    plr->research.researchpoints=1;
> +  for (i=0; game.rgame.init_techs[i] != A_LAST; i++) {
> +    set_invention(plr, game.rgame.init_techs[i], TECH_KNOWN);
> +  }
>    for (i=0;i<tech;i++) {
>      choose_random_tech(plr); /* could be choose_goal_tech -- Syela */
>      set_invention(plr, plr->research.researching, TECH_KNOWN);
> Index: server/ruleset.c
> ===================================================================
> RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v
> retrieving revision 1.80
> diff -u -r1.80 ruleset.c
> --- server/ruleset.c 2001/09/15 15:31:27 1.80
> +++ server/ruleset.c 2001/09/19 15:19:53
> @@ -2109,6 +2109,44 @@
>  }
>  
>  /**************************************************************************
> +Lookup init techs from section file
> +**************************************************************************/
> +static int *secfile_lookup_init_techs (struct section_file *file)
> +{
> +  int num_init_techs;
> +  char **init_tech_names;
> +  int *init_techs;
> +  int i, j;
> +  
> +  init_tech_names = secfile_lookup_str_vec(file, &num_init_techs,
> +        "options.init_techs");
> +
> +  if (num_init_techs > MAX_NUM_TECH_LIST) {
> +    freelog (LOG_ERROR, "num_init_techs: %d > total number of techs",
> +      num_init_techs);
> +  }
> +
> +  init_techs = fc_malloc (sizeof(int) * num_init_techs);
> +
> +  for (i = j = 0; i < num_init_techs; i++) {
> +    if (strcmp(init_tech_names[i],"") != 0) {
> +      
> +      int t = find_tech_by_name (init_tech_names[i]);
> +      
> +      if (t != A_LAST) {
> + init_techs[j++] = t;
> +      } else {
> + freelog(LOG_ERROR, "Bad initial tech in game.ruleset: %s",
> +  init_tech_names[i]);
> +      }
> +    }
> +  }
> +  init_techs[j] = A_LAST;
> +
> +  return init_techs;
> +}
> +
> +/**************************************************************************
>  Load game.ruleset file
>  **************************************************************************/
>  static void load_ruleset_game(char *ruleset_subdir)
> @@ -2184,6 +2222,8 @@
>      game.rgame.granary_food_inc = 100;
>    }
>  
> +  game.rgame.init_techs = secfile_lookup_init_techs (&file);
> +  
>    section_file_check_unused(&file, filename);
>    section_file_free(&file);
>  }
> @@ -2514,7 +2554,6 @@
>    struct section_file cityfile, nationfile;
>  
>    freelog(LOG_NORMAL, _("Loading rulesets"));
> -  load_ruleset_game(game.ruleset.game);
>  
>    openload_ruleset_file(&techfile, game.ruleset.techs, "techs");
>    load_tech_names(&techfile);
> @@ -2544,6 +2583,7 @@
>    load_ruleset_terrain(&terrfile);
>    load_ruleset_buildings(&buildfile);
>    load_ruleset_nations(&nationfile);
> +  load_ruleset_game(game.ruleset.game);
>    translate_data_names();
>  }
>  
> 

__________________________________________________
Terrorist Attacks on U.S. - How can you help?
Donate cash, emergency relief information
http://dailynews.yahoo.com/fc/US/Emergency_Information/
Index: common/capstr.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/capstr.c,v
retrieving revision 1.86
diff -u -r1.86 capstr.c
--- common/capstr.c     2001/09/12 08:39:36     1.86
+++ common/capstr.c     2001/09/21 00:11:57
@@ -71,7 +71,7 @@
  */
 
 #define CAPABILITY "+1.11.6 conn_info pop_cost turn attributes new_bonus_tech"\
-" fund_added processing_packets"
+" fund_added processing_packets init_techs"
   
 /* "+1.11.6" is protocol for 1.11.6 beta release.
   
@@ -93,6 +93,9 @@
 
    "processing_packets" sends PACKET_PROCESSING_STARTED and
    PACKET_PROCESSING_FINISHED packets.
+
+   "init_techs" is the ability to specify a game default set of
+   initial advances to give to all players.
 */
 
 void init_our_capability(void)
Index: common/game.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.h,v
retrieving revision 1.87
diff -u -r1.87 game.h
--- common/game.h       2001/09/16 12:43:25     1.87
+++ common/game.h       2001/09/21 00:11:57
@@ -141,7 +141,7 @@
 
   int watchtower_extra_vision;
   int watchtower_vision;
-
+  
   struct {
     char techs[MAX_LEN_NAME];
     char units[MAX_LEN_NAME];
@@ -182,6 +182,8 @@
     int nuke_contamination;
     int granary_food_ini;
     int granary_food_inc;
+    int *init_techs; /* Advances to assign to all players at game
+                       start. A_LAST terminated.*/
   } rgame;
 
   char demography[MAX_LEN_DEMOGRAPHY];
Index: common/packets.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.c,v
retrieving revision 1.163
diff -u -r1.163 packets.c
--- common/packets.c    2001/09/19 20:59:24     1.163
+++ common/packets.c    2001/09/21 00:11:59
@@ -3739,7 +3739,10 @@
   cptr=put_uint8(cptr, packet->nuke_contamination);
   cptr=put_uint8(cptr, packet->granary_food_ini);
   cptr=put_uint8(cptr, packet->granary_food_inc);
-
+  if (has_capability("init_techs", pc->capability)) {
+    cptr=put_tech_list(cptr, packet->init_techs);
+  }
+  
   put_uint16(buffer, cptr-buffer);
   return send_packet_data(pc, buffer, cptr-buffer);
 }
@@ -3766,6 +3769,9 @@
   iget_uint8(&iter, &packet->nuke_contamination);
   iget_uint8(&iter, &packet->granary_food_ini);
   iget_uint8(&iter, &packet->granary_food_inc);
+  if (has_capability("init_techs", pc->capability)) {
+    iget_tech_list(&iter, packet->init_techs);
+  }
 
   pack_iter_end(&iter, pc);
   remove_packet_from_buffer(pc->buffer);
Index: common/packets.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.h,v
retrieving revision 1.95
diff -u -r1.95 packets.h
--- common/packets.h    2001/09/16 12:43:27     1.95
+++ common/packets.h    2001/09/21 00:12:00
@@ -785,6 +785,7 @@
   int nuke_contamination;
   int granary_food_ini;
   int granary_food_inc;
+  int init_techs[MAX_NUM_TECH_LIST];
 };
 
 /*********************************************************
Index: data/default/game.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/default/game.ruleset,v
retrieving revision 1.3
diff -u -r1.3 game.ruleset
--- data/default/game.ruleset   2001/01/22 04:57:17     1.3
+++ data/default/game.ruleset   2001/09/21 00:12:00
@@ -14,6 +14,9 @@
 description="Default game rules for Freeciv"
 options="1.11.1"
 
+[options]
+init_techs = ""
+
 [civstyle]
 min_city_center_food   = 1
 min_city_center_shield = 1
Index: server/plrhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.c,v
retrieving revision 1.198
diff -u -r1.198 plrhand.c
--- server/plrhand.c    2001/09/12 09:12:14     1.198
+++ server/plrhand.c    2001/09/21 00:12:01
@@ -473,6 +473,9 @@
   set_invention(plr, A_NONE, TECH_KNOWN);
 
   plr->research.researchpoints=1;
+  for (i=0; game.rgame.init_techs[i] != A_LAST; i++) {
+    set_invention(plr, game.rgame.init_techs[i], TECH_KNOWN);
+  }
   for (i=0;i<tech;i++) {
     choose_random_tech(plr); /* could be choose_goal_tech -- Syela */
     set_invention(plr, plr->research.researching, TECH_KNOWN);
Index: server/ruleset.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v
retrieving revision 1.80
diff -u -r1.80 ruleset.c
--- server/ruleset.c    2001/09/15 15:31:27     1.80
+++ server/ruleset.c    2001/09/21 00:12:03
@@ -2109,6 +2109,46 @@
 }
 
 /**************************************************************************
+Lookup init techs from section file
+**************************************************************************/
+static int *secfile_lookup_init_techs (struct section_file *file)
+{
+  int num_init_techs;
+  char **init_tech_names;
+  int *init_techs;
+  int i, j;
+  
+  init_tech_names = secfile_lookup_str_vec(file, &num_init_techs,
+                                          "options.init_techs");
+
+  if (num_init_techs > MAX_NUM_TECH_LIST) {
+    freelog (LOG_ERROR, "num_init_techs: %d > total number of techs",
+            num_init_techs);
+  }
+
+  init_techs = fc_malloc (sizeof(int) * num_init_techs);
+
+  for (i = j = 0; i < num_init_techs; i++) {
+    if (strcmp(init_tech_names[i],"") != 0) {
+      
+      int t = find_tech_by_name (init_tech_names[i]);
+      
+      if (t != A_LAST) {
+       init_techs[j++] = t;
+      } else {
+       freelog(LOG_ERROR, "Bad initial tech in game.ruleset: %s",
+               init_tech_names[i]);
+      }
+    }
+  }
+  init_techs[j] = A_LAST;
+
+  if (init_tech_names)
+    free (init_tech_names);
+  return init_techs;
+}
+
+/**************************************************************************
 Load game.ruleset file
 **************************************************************************/
 static void load_ruleset_game(char *ruleset_subdir)
@@ -2184,6 +2224,8 @@
     game.rgame.granary_food_inc = 100;
   }
 
+  game.rgame.init_techs = secfile_lookup_init_techs (&file);
+  
   section_file_check_unused(&file, filename);
   section_file_free(&file);
 }
@@ -2490,6 +2532,7 @@
 static void send_ruleset_game(struct conn_list *dest)
 {
   struct packet_ruleset_game misc_p;
+  int i;
 
   misc_p.min_city_center_food = game.rgame.min_city_center_food;
   misc_p.min_city_center_shield = game.rgame.min_city_center_shield;
@@ -2501,6 +2544,9 @@
   misc_p.nuke_contamination = game.rgame.nuke_contamination;
   misc_p.granary_food_ini = game.rgame.granary_food_ini;
   misc_p.granary_food_inc = game.rgame.granary_food_inc;
+  for (i = 0; game.rgame.init_techs[i] != A_LAST; i++) {
+    misc_p.init_techs[i] = game.rgame.init_techs[i];
+  }
 
   lsend_packet_ruleset_game(dest, &misc_p);
 }
@@ -2514,7 +2560,6 @@
   struct section_file cityfile, nationfile;
 
   freelog(LOG_NORMAL, _("Loading rulesets"));
-  load_ruleset_game(game.ruleset.game);
 
   openload_ruleset_file(&techfile, game.ruleset.techs, "techs");
   load_tech_names(&techfile);
@@ -2544,6 +2589,7 @@
   load_ruleset_terrain(&terrfile);
   load_ruleset_buildings(&buildfile);
   load_ruleset_nations(&nationfile);
+  load_ruleset_game(game.ruleset.game);
   translate_data_names();
 }
 

[Prev in Thread] Current Thread [Next in Thread]