Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2000:
[Freeciv-Dev] Freeciv Patch: national ruleset can now grant specified in
Home

[Freeciv-Dev] Freeciv Patch: national ruleset can now grant specified in

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Cc: freeciv-data <freeciv-data@xxxxxxxxxxx>, Moses Lei <mlei@xxxxxxxxxxxxxxxx>, Mark Polo <mark@xxxxxxxxx>, Paul Zastoupil <paulz@xxxxxxxxxxxx>, Robert Brady <rwb197@xxxxxxxxxxxxxxx>
Subject: [Freeciv-Dev] Freeciv Patch: national ruleset can now grant specified initial techs.
From: "Bobby D. Bryant" <bdbryant@xxxxxxxxxxxxxxx>
Date: Sun, 24 Dec 2000 04:38:41 -0600

The attached .diff allows a national ruleset to specify some techs to be
granted to a nation at the start of the game.  (This feature is needed
for various modpacks now under development.)

Note: The patch is a    "cvs diff -u"   based on the CVS version as of
24-December-2000.  It may not work with Freeciv 11.4.


To grant the techs, add a line similar to the following to a nation's
record in nations.ruleset (or the nation-specific inclusion file) -

    initial_techs = "Elf_Lore", "Woodcraft", "Archery"

For consistency between rulesets, I am recommending that it be added
immediately before the tech_goals line, thus -

    ...
    advisors=100,100,100,100,100,100,100

    initial_techs = "Elf_Lore", "Woodcraft", "Archery"

    tech_goals="Monarchy", "Sorcery", "Diplomacy"
    ...

There will not be an error if you use a nation without an initial_techs
field, so you do not need to go back and add an empty initial_techs list
to nations that do not actually need it.

Verbose logging on the server will list the techs granted by this
mechanism, and will also identify attempts to grant invalid techs, or
nations that do not receive any such techs at all (similar to what is
already being done for national tech_goals).


Thanks for supporting Freeciv,

Bobby Bryant
Austin, Texas

Index: common/nation.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/nation.h,v
retrieving revision 1.5
diff -u -r1.5 nation.h
--- nation.h    2000/03/04 03:55:27     1.5
+++ nation.h    2000/12/24 09:50:31
@@ -15,6 +15,8 @@
 
 #include "shared.h"            /* MAX_LEN_NAME */
 
+#define MAX_NUM_INITIAL_TECHS 5
+
 #define MAX_NUM_TECH_GOALS 10
 #define MAX_NUM_NATIONS  63
 #define MAX_NUM_LEADERS  16
@@ -52,6 +54,8 @@
   int civilized;            /* c 0 = don't use nukes,  2 = use nukes, lots of 
pollution */
   /* civilized was never implemented, but will be eventually. -- Syela */
   int advisors[ADV_LAST];   /* never implemented either. -- Syela */
+
+  int initial_techs[MAX_NUM_INITIAL_TECHS]; /* granted by nation's ruleset */
 
   /* Following basically disabled -- Syela */
   /* Note the client doesn't use/have these. */
Index: server/plrhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.c,v
retrieving revision 1.176
diff -u -r1.176 plrhand.c
--- plrhand.c   2000/12/22 00:36:48     1.176
+++ plrhand.c   2000/12/24 09:50:39
@@ -426,14 +426,39 @@
 }
 
 /**************************************************************************
-...
+Is this tech one of those initially assigned to this player by nations.ruleset?
 **************************************************************************/
+int is_initial_tech(struct player *plr, int tech)
+{
+  int i;
+  struct nation_type *nation;
+
+  nation = get_nation_by_idx(plr->nation);
+  for (i=0; i < MAX_NUM_INITIAL_TECHS; i++) {
+   if (tech == nation->initial_techs[i]) {
+    return 1; /* found it */
+   }
+  }
+  return 0; /* never found it */
+}
+
+/**************************************************************************
+Assign appropriate initial techs to a player
+**************************************************************************/
 void init_tech(struct player *plr, int tech)
 {
   int i;
-  for (i=0;i<game.num_tech_types;i++) 
-    set_invention(plr, i, 0);
+
   set_invention(plr, A_NONE, TECH_KNOWN);
+  for (i=A_FIRST; i<game.num_tech_types; i++) {
+    if (is_initial_tech(plr, i)) {
+      freelog(LOG_VERBOSE, "granting initial tech %s to %s",
+             advances[i].name, plr->name);
+      set_invention(plr, i, TECH_KNOWN);
+    } else {
+      set_invention(plr, i, TECH_UNKNOWN);
+    }
+  }
 
   plr->research.researchpoints=1;
   for (i=0;i<tech;i++) {
Index: server/plrhand.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.h,v
retrieving revision 1.35
diff -u -r1.35 plrhand.h
--- plrhand.h   2000/12/20 15:16:22     1.35
+++ plrhand.h   2000/12/24 09:50:40
@@ -70,6 +70,7 @@
                    char saving_bulbs);
 void tech_researched(struct player* plr);
 int update_tech(struct player *plr, int bulbs);
+int is_initial_tech(struct player *plr, int tech);
 void init_tech(struct player *plr, int tech);
 void choose_random_tech(struct player *plr);
 void choose_tech(struct player *plr, int tech);
Index: server/ruleset.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v
retrieving revision 1.68
diff -u -r1.68 ruleset.c
--- ruleset.c   2000/11/10 19:47:26     1.68
+++ ruleset.c   2000/12/24 09:50:51
@@ -1884,6 +1884,41 @@
       pl->city_style = 0;
     }
 
+    /* Techs to be granted at start of game */
+
+    techs = secfile_lookup_str_vec(file, &dim, "%s.initial_techs", sec[i]);
+    if( dim > MAX_NUM_INITIAL_TECHS ) {
+      freelog(LOG_VERBOSE,
+             "Only %d techs can be granted from %d specified for nation %s",
+             MAX_NUM_INITIAL_TECHS, dim, pl->name_plural);
+      dim = MAX_NUM_INITIAL_TECHS;
+    }
+    /* Below LOG_VERBOSE rather than LOG_ERROR so that can use single
+       nation ruleset file with variety of tech ruleset files: */
+    for( j=0; j<dim; j++) {
+      val = find_tech_by_name(techs[j]);
+      if(val == A_LAST) {
+       freelog(LOG_VERBOSE, "Could not match initial tech \"%s\" for the %s",
+               techs[j], pl->name_plural);
+      } else if (!tech_exists(val)) {
+       freelog(LOG_VERBOSE, "Initial tech \"%s\" for the %s doesn't exist",
+               techs[j], pl->name_plural);
+       val = A_LAST;
+      }
+      if(val != A_LAST && val != A_NONE) {
+       freelog(LOG_DEBUG, "%s initial tech (%d) %3d %s",
+               pl->name, j, val, techs[j]);
+       pl->initial_techs[j] = val;
+      }
+    }
+    freelog(LOG_DEBUG, "%s %d initial tech ", pl->name, j);
+    if(j==0) {
+      freelog(LOG_VERBOSE, "No valid initial techs for %s", pl->name);
+    }
+    while( j < MAX_NUM_INITIAL_TECHS )
+      pl->initial_techs[j++] = A_NONE;
+    if (techs) free(techs);
+
     /* AI stuff */
 
     pl->attack = secfile_lookup_int_default(file, 2, "%s.attack", sec[i]);

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] Freeciv Patch: national ruleset can now grant specified initial techs., Bobby D. Bryant <=