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

[Freeciv-Dev] [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] [RFC PATCH] init_techs
From: Arien Malec <arien_malec@xxxxxxxxx>
Date: Wed, 19 Sep 2001 08:34:08 -0700 (PDT)

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();
 }
 

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