Complete.Org: Mailing Lists: Archives: freeciv-dev: July 1999:
Re: [Freeciv-Dev] New game.ruleset to support custom calendars, etc. (PR
Home

Re: [Freeciv-Dev] New game.ruleset to support custom calendars, etc. (PR

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx, bugs@xxxxxxxxxxxxxxxxxxx
Subject: Re: [Freeciv-Dev] New game.ruleset to support custom calendars, etc. (PR#45)
From: "Bobby D. Bryant" <bdbryant@xxxxxxxxxxxxxxx>
Date: Mon, 05 Jul 1999 10:07:17 -0500

bdbryant@xxxxxxxxxxxxxxx wrote:

> This is a new file, game.ruleset.  ...

Jitterbug does not seem to allow me to append anything to the above (id = 45), 
so
the actual patch files are attached below.  Here's hoping someone can/will 
attach
them properly...

Bobby Bryant
Austin, Texas

--- common/game.c-orig  Mon Jul  5 04:57:47 1999
+++ common/game.c       Mon Jul  5 08:06:45 1999
@@ -250,8 +250,6 @@
   game.tech        = GAME_DEFAULT_TECHLEVEL;
   game.skill_level = GAME_DEFAULT_SKILL_LEVEL;
   game.timeout     = GAME_DEFAULT_TIMEOUT;
-  game.end_year    = GAME_DEFAULT_END_YEAR;
-  game.year        = GAME_START_YEAR;
   game.min_players = GAME_DEFAULT_MIN_PLAYERS;
   game.max_players = GAME_DEFAULT_MAX_PLAYERS;
   game.aifill      = GAME_DEFAULT_AIFILL;
@@ -282,6 +280,7 @@
   game.save_nturns=10;
   game.randseed=GAME_DEFAULT_RANDSEED;
 
+  strcpy(game.ruleset.game, GAME_DEFAULT_RULESET);
   strcpy(game.ruleset.techs, GAME_DEFAULT_RULESET);
   strcpy(game.ruleset.units, GAME_DEFAULT_RULESET);
   strcpy(game.ruleset.buildings, GAME_DEFAULT_RULESET);
@@ -316,11 +315,11 @@
 }
 
 /***************************************************************
-...
+Update the calendar for the new turn.
 ***************************************************************/
 void game_next_year(void)
 {
-  int spaceshipparts, i;
+  int spaceshipparts, i, increment;
   int parts[] = { B_SCOMP, B_SMODULE, B_SSTRUCTURAL, B_LAST };
 
   if (game.year == 1) /* hacked it to get rid of year 0 */
@@ -348,20 +347,19 @@
     }
   }
 
-  if( game.year >= 1900 || ( spaceshipparts>=3 && game.year>0 ) )
+  if( spaceshipparts>=3 && game.year>0 )
     game.year += 1;
-  else if( game.year >= 1750 || spaceshipparts>=2 )
+  else if( spaceshipparts>=2 )
     game.year += 2;
-  else if( game.year >= 1500 || spaceshipparts>=1 )
+  else if( spaceshipparts>=1 )
     game.year += 5;
-  else if( game.year >= 1000 )
-    game.year += 10;
-  else if( game.year >= 0 )
-    game.year += 20;
-  else if( game.year >= -1000 ) /* used this line for tuning (was -1250) */
-    game.year += 25;
-  else
-    game.year += 50; 
+  else {
+   /* Use the epoch table loaded from game.rulesets. */
+    for(i=0; i<MAX_EPOCHS; i++)
+      if (game.year >= game.epoch[i].start_year)
+        increment=game.epoch[i].turn_increment;
+   game.year += increment;
+  };
 
   if (game.year == 0) 
     game.year = 1;
--- common/game.h-orig  Mon Jul  5 05:05:56 1999
+++ common/game.h       Mon Jul  5 09:19:43 1999
@@ -33,6 +33,10 @@
 
 struct unit;
 struct city;
+struct epoch {
+  int start_year;
+  int turn_increment;
+};
 
 struct civ_game {
   int version;
@@ -42,6 +46,7 @@
   int tech;
   int skill_level;
   int timeout;
+  int start_year;
   int end_year;
   int year;
   int techlevel;
@@ -78,6 +83,7 @@
   int sewer_size;
   int spacerace;
   struct {
+    char game[MAX_LENGTH_NAME];
     char techs[MAX_LENGTH_NAME];
     char units[MAX_LENGTH_NAME];
     char buildings[MAX_LENGTH_NAME];
@@ -92,6 +98,7 @@
     int nav;                   /* AI convenience: tech_req for first
                                   non-trireme ferryboat */
   } rtech;
+ struct epoch epoch[MAX_EPOCHS];
 };
 
 struct lvldat {
@@ -144,10 +151,6 @@
 #define GAME_MIN_UNHAPPYSIZE 1
 #define GAME_MAX_UNHAPPYSIZE 6
 
-#define GAME_DEFAULT_END_YEAR    2000
-#define GAME_MIN_END_YEAR        GAME_START_YEAR
-#define GAME_MAX_END_YEAR        5000
-
 #define GAME_DEFAULT_MIN_PLAYERS     1
 #define GAME_MIN_MIN_PLAYERS         1
 #define GAME_MAX_MIN_PLAYERS         MAX_PLAYERS
@@ -236,7 +239,5 @@
 
 #define GAME_DEFAULT_SKILL_LEVEL 3      /* easy */
 #define GAME_OLD_DEFAULT_SKILL_LEVEL 5  /* normal; for old save games */
-
-#define GAME_START_YEAR -4000
 
 #endif  /* FC__GAME_H */
--- server/gamehand.c-orig      Mon Jul  5 05:42:23 1999
+++ server/gamehand.c   Mon Jul  5 08:33:59 1999
@@ -42,7 +42,7 @@
 extern int iRandJ, iRandK, iRandX; 
 extern int rand_init;
 
-#define SAVEFILE_OPTIONS "1.7 startoptions unirandom spacerace2 rulesets"
+#define SAVEFILE_OPTIONS "1.8.2 startoptions unirandom spacerace2 rulesets"
 
 /**************************************************************************
 ...
@@ -256,9 +256,15 @@
   if (game.skill_level==0)
     game.skill_level = GAME_OLD_DEFAULT_SKILL_LEVEL;
   game.timeout       = secfile_lookup_int(file, "game.timeout");
+  for( i=0; i<MAX_EPOCHS; i++) {
+   game.epoch[i].start_year = secfile_lookup_int(file,
+                                                "game.epoch%d.start_year", i);
+   game.epoch[i].turn_increment = secfile_lookup_int(file,
+                                                    
"game.epoch%d.turn_increment", i);
+  };
   game.end_year      = secfile_lookup_int(file, "game.end_year");
-  game.techlevel     = secfile_lookup_int(file, "game.techlevel");
   game.year          = secfile_lookup_int(file, "game.year");
+  game.techlevel     = secfile_lookup_int(file, "game.techlevel");
   game.min_players   = secfile_lookup_int(file, "game.min_players");
   game.max_players   = secfile_lookup_int(file, "game.max_players");
   game.nplayers      = secfile_lookup_int(file, "game.nplayers");
@@ -321,6 +327,8 @@
   }
 
   if (has_capability("rulesets",savefile_options)) {
+    strcpy(game.ruleset.game,
+          secfile_lookup_str(file, "game.ruleset.game"));
     strcpy(game.ruleset.techs,
           secfile_lookup_str(file, "game.ruleset.techs"));
     strcpy(game.ruleset.units,
@@ -463,6 +471,12 @@
   secfile_insert_int(file, game.tech, "game.tech");
   secfile_insert_int(file, game.skill_level, "game.skill_level");
   secfile_insert_int(file, game.timeout, "game.timeout");
+  for( i=0; i<MAX_EPOCHS; i++) {
+   secfile_insert_int(file, game.epoch[i].start_year,
+                     "game.epoch%d.start_year", i);
+   secfile_insert_int(file, game.epoch[i].turn_increment,
+                     "game.epoch%d.turn_increment", i);
+  };
   secfile_insert_int(file, game.end_year, "game.end_year");
   secfile_insert_int(file, game.year, "game.year");
   secfile_insert_int(file, game.techlevel, "game.techlevel");
@@ -491,6 +505,7 @@
   secfile_insert_int(file, game.diplchance, "game.diplchance");
   secfile_insert_int(file, game.aqueductloss, "game.aqueductloss");
   secfile_insert_int(file, game.randseed, "game.randseed");
+  secfile_insert_str(file, game.ruleset.game, "game.ruleset.game");
   secfile_insert_str(file, game.ruleset.techs, "game.ruleset.techs");
   secfile_insert_str(file, game.ruleset.units, "game.ruleset.units");
   secfile_insert_str(file, game.ruleset.buildings, "game.ruleset.buildings");
--- server/plrhand.c-orig       Mon Jul  5 06:12:07 1999
+++ server/plrhand.c    Mon Jul  5 07:29:43 1999
@@ -347,7 +347,7 @@
 
   if (fp == NULL)
     {
-      if (game.year > GAME_START_YEAR)
+      if (game.year > game.start_year)
        fp = fopen("civscore.log","a");
       else
        {
--- server/ruleset.c-orig       Mon Jul  5 04:58:37 1999
+++ server/ruleset.c    Mon Jul  5 07:45:22 1999
@@ -14,6 +14,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
+#include <values.h>
 
 #include "capability.h"
 #include "city.h"
@@ -38,6 +39,7 @@
                       char *description);
 static int match_name_from_list(char *name, char **list, int n_list);
 
+static void load_ruleset_game(char *ruleset_subdir);
 static void load_ruleset_techs(char *ruleset_subdir);
 static void load_ruleset_units(char *ruleset_subdir);
 static void load_ruleset_buildings(char *ruleset_subdir);
@@ -178,9 +180,47 @@
 }
 
 /**************************************************************************
-  ...  
-  This must be done before the other load_ruleset_ functions,
-  since other rulesets want to match tech names.
+ Load the basic game rules from game.ruleset in the specified subdirectory.
+**************************************************************************/
+static void load_ruleset_game(char *ruleset_subdir)
+{
+  struct section_file file;
+  char *filename, *datafile_options;
+  char prefix[64];
+  int i;
+
+  filename = openload_ruleset_file(&file, ruleset_subdir, "game");
+  section_file_lookup(&file,"datafile.description"); /* unused */
+  datafile_options = check_ruleset_capabilities(&file, "1.8.2", filename);
+
+  /* Load the epoch info. */
+  for( i=0; i<MAX_EPOCHS; i++ ) {
+    sprintf(prefix, "calendar.epoch%d", i);
+    /* Used MAXINT as the default, so you can have fewer than the maximum
+     * allowed number of epochs, and if so the start_date will default to
+     * a value that will never be exceeded. */
+    game.epoch[i].start_year=secfile_lookup_int_default(&file, MAXINT,
+                                                       "%s.start_date",
+                                                       prefix);
+    game.epoch[i].turn_increment=secfile_lookup_int_default(&file, MAXINT,
+                                                           "%s.turn_increment",
+                                                           prefix);;
+  }
+
+  /* Start the game on the first year of the first epoch. */
+  game.start_year=game.epoch[0].start_year;
+  game.year=game.start_year;
+
+  /* Load the end year. */
+  game.end_year=secfile_lookup_int(&file, "calendar.end_date");
+
+  section_file_check_unused(&file, filename);
+  section_file_free(&file);
+}
+
+/**************************************************************************
+  This must be done before the load_ruleset_units and load_ruleset_buildings
+  functions, since other rulesets want to match tech names.
 **************************************************************************/
 static void load_ruleset_techs(char *ruleset_subdir)
 {
@@ -638,6 +678,7 @@
 void load_rulesets(void)
 {
   freelog(LOG_NORMAL, "Loading rulesets");
+  load_ruleset_game(game.ruleset.game);
   load_ruleset_techs(game.ruleset.techs);
   load_ruleset_units(game.ruleset.units);
   load_ruleset_buildings(game.ruleset.buildings);
@@ -655,7 +696,8 @@
       connection_do_buffer(get_player(to)->conn);
     }
   }
-  
+
+  /* So far, nothing to send for send_ruleset_game() */
   send_ruleset_techs(dest);
   send_ruleset_units(dest);
   send_ruleset_buildings(dest);
--- common/shared.h-orig        Mon Jul  5 06:50:11 1999
+++ common/shared.h     Mon Jul  5 06:51:05 1999
@@ -25,6 +25,7 @@
 #define MAX_PLAYERS 14
 #define MAX_LENGTH_NAME 32
 #define MAX_LENGTH_ADDRESS 32
+#define MAX_EPOCHS 10
 
 #ifndef MAX
 #define MAX(x,y) (((x)>(y))?(x):(y))
--- server/stdinhand.c-orig     Mon Jul  5 05:24:33 1999
+++ server/stdinhand.c  Mon Jul  5 07:38:08 1999
@@ -263,6 +263,15 @@
     "Number of initial advances per player", "" },
 
 /* Various rules: these cannot be changed once the game has started. */
+  { "game", NULL,
+    SSET_RULES, SSET_TO_CLIENT,
+    0, 0, 0,
+    "Data subdir containing game.ruleset",
+    "  This should specify a subdirectory of the data directory, containing 
a\n"
+    "  file called \"game.ruleset\".  Various rules controlling the game 
will\n"
+    "  be initialized from this file.  See also README.rulesets.",
+    game.ruleset.game, GAME_DEFAULT_RULESET },
+
   { "techs", NULL,
     SSET_RULES, SSET_TO_CLIENT,
     0, 0, 0,
@@ -428,15 +437,7 @@
 /* Meta options: these don't affect the internal rules of the game, but
  * do affect players.  Also options which only produce extra server
  * "output" and don't affect the actual game.
- * ("endyear" is here, and not RULES_FLEXIBLE, because it doesn't
- * affect what happens in the game, it just determines when the
- * players stop playing and look at the score.)
  */
-  { "endyear", &game.end_year,
-    SSET_META, SSET_TO_CLIENT,
-    GAME_MIN_END_YEAR, GAME_MAX_END_YEAR, GAME_DEFAULT_END_YEAR,
-    "Year the game ends", "" },
-
   { "timeout", &game.timeout,
     SSET_META, SSET_TO_CLIENT,
     GAME_MIN_TIMEOUT, GAME_MAX_TIMEOUT, GAME_DEFAULT_TIMEOUT,

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