Complete.Org: Mailing Lists: Archives: freeciv-dev: December 1999:
[Freeciv-Dev] patch: remove/replace game.scenario field (PR#209)
Home

[Freeciv-Dev] patch: remove/replace game.scenario field (PR#209)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Cc: bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] patch: remove/replace game.scenario field (PR#209)
From: David Pfitzner <dwp@xxxxxxxxxxxxxx>
Date: Sun, 26 Dec 1999 20:32:12 -0800 (PST)

I've never much liked the game.scenario field, mainly because I 
find it hard to remember for long what its values mean, and how 
they interact with other things.

This patch fixes this by removing the game.scenario field, and
using instead several "more obvious" fields:
  game.is_new_game  (replaces is_new_game var in civserver.c)
  map.fixed_start_positions (with existing map.num_start_positions)
  map.have_specials

I'm not 100% sure I've converted everything correctly, but I don't
think the existing code is 100% correct anyway.  (Eg, currently, with
or without this patch, if you load a save game and then re-save before
starting, you don't get the same savegame, but rather a scenario-like
savegame which doesn't work...)  I think this patch gives a better
framework for fixing such problems.

-- David
diff -u -r --exclude-from exclude freeciv-cvs/common/game.c fc-adv/common/game.c
--- freeciv-cvs/common/game.c   Thu Dec 23 16:50:16 1999
+++ fc-adv/common/game.c        Sun Dec 26 17:07:49 1999
@@ -707,6 +707,7 @@
 void game_init(void)
 {
   int i;
+  game.is_new_game = 1;
   game.globalwarming=0;
   game.warminglevel=8;
   game.gold        = GAME_DEFAULT_GOLD;
@@ -738,7 +739,6 @@
   game.spacerace   = GAME_DEFAULT_SPACERACE;
   game.barbarians  = GAME_DEFAULT_BARBARIAN;
   game.heating     = 0;
-  game.scenario    = 0;
   strcpy(game.save_name, "civgame");
   game.save_nturns=10;
   game.randseed=GAME_DEFAULT_RANDSEED;
diff -u -r --exclude-from exclude freeciv-cvs/common/game.h fc-adv/common/game.h
--- freeciv-cvs/common/game.h   Thu Dec 23 16:50:16 1999
+++ fc-adv/common/game.h        Sun Dec 26 17:07:39 1999
@@ -38,6 +38,7 @@
 struct city;
 
 struct civ_game {
+  int is_new_game;             /* 1 for games never started */
   int version;
   int civstyle;
   int gold;
@@ -70,7 +71,6 @@
   int warminglevel;
   char save_name[MAX_LEN_NAME];
   int save_nturns;
-  int scenario;
   int foodbox;
   int aqueductloss;
   int techpenalty;
diff -u -r --exclude-from exclude freeciv-cvs/common/map.c fc-adv/common/map.c
--- freeciv-cvs/common/map.c    Sat Oct 30 15:37:11 1999
+++ fc-adv/common/map.c Sun Dec 26 17:20:29 1999
@@ -96,6 +96,8 @@
   map.generator=MAP_DEFAULT_GENERATOR;
   map.tiles=0;
   map.num_start_positions=0;
+  map.fixed_start_positions=0;
+  map.have_specials = 0;
 
   tile_init(&void_tile);
 }
diff -u -r --exclude-from exclude freeciv-cvs/common/map.h fc-adv/common/map.h
--- freeciv-cvs/common/map.h    Sat Oct 30 15:37:11 1999
+++ fc-adv/common/map.h Sun Dec 26 17:20:18 1999
@@ -162,6 +162,8 @@
   int forestsize;
   int generator;
   int num_start_positions;
+  int fixed_start_positions;
+  int have_specials;
   struct tile *tiles;
   struct map_position start_positions[MAX_NUM_NATIONS];
 };
diff -u -r --exclude-from exclude freeciv-cvs/server/civserver.c 
fc-adv/server/civserver.c
--- freeciv-cvs/server/civserver.c      Thu Dec 23 16:51:28 1999
+++ fc-adv/server/civserver.c   Sun Dec 26 18:13:20 1999
@@ -137,8 +137,6 @@
 unsigned char used_ids[8192]={0};
 int is_server = 1;
 
-int is_new_game=1;
-
 /* The following is unused, AFAICT.  --dwp */
 char usage[] = 
 "Usage: %s [-fhlpgv] [--file] [--help] [--log] [--port]\n\t[--gamelog] 
[--version]\n";
@@ -297,18 +295,12 @@
       freelog(LOG_FATAL, _("Couldn't load savefile: %s"), load_filename);
       exit(1);
     }
-    game.scenario=game_load(&file);
+    game_load(&file);
     section_file_check_unused(&file, load_filename);
     section_file_free(&file);
 
-   /* game.scenario: 0=normal savegame, 1=everything but players,
-       2=just tile map and startpositions, 3=just tile map
-   */
-    if (game.scenario) { /* we may have a scenario here */
-      if(game.nplayers) { /* no, it's just a normal savegame */
-       is_new_game=0;
-       game.scenario=0;
-      }
+    if (!game.is_new_game) {
+      /* Is this right/necessary/the_right_place_for_this/etc? --dwp */
       while(is_id_allocated(global_id_counter++));
     }
     freelog(LOG_VERBOSE, "Load time: %g seconds (%g apparent)",
@@ -339,7 +331,7 @@
 
   send_server_info_to_metaserver(1,0);
 
-  if(is_new_game) {
+  if(game.is_new_game) {
     load_rulesets();
     /* otherwise rulesets were loaded when savegame was loaded */
   }
@@ -400,12 +392,12 @@
   if(!rand_init)
     mysrand(game.randseed);
 
-  if(is_new_game)
+  if(game.is_new_game)
     generate_ai_players();
    
   /* if we have a tile map, and map.generator==0, call map_fractal_generate
      anyway, to make the specials and huts */
-  if(map_is_empty() || (map.generator == 0 && is_new_game))
+  if(map_is_empty() || (map.generator == 0 && game.is_new_game))
     map_fractal_generate();
   else 
     flood_it(1);
@@ -415,7 +407,7 @@
   server_state=RUN_GAME_STATE;
   send_server_info_to_metaserver(1,0);
 
-  if(is_new_game) {
+  if(game.is_new_game) {
     int i;
     for(i=0; i<game.nplayers; i++) {
       init_tech(&game.players[i], game.tech); 
@@ -425,9 +417,9 @@
 
     /* we don't want random start positions in a scenario which already
        provides them.  -- Gudy */
-    if(game.scenario==1 || game.scenario==2)
+    if(map.num_start_positions>0) {
       flood_it(1);
-    else {
+    } else {
       flood_it(0);
       create_start_positions();
     }
@@ -436,7 +428,7 @@
   initialize_move_costs(); /* this may be the wrong place to do this */
   generate_minimap(); /* for city_desire; saves a lot of calculations */
 
-  if (!is_new_game) {
+  if (!game.is_new_game) {
     for (i=0;i<game.nplayers;i++) {
       civ_score(&game.players[i]);  /* if we don't, the AI gets really 
confused */
       if (game.players[i].ai.control) {
@@ -450,15 +442,13 @@
   
   send_all_info(0);
 
-  if(is_new_game) 
+  if(game.is_new_game) 
     init_new_game();
-    
+
+  game.is_new_game = 0;
+
   send_game_state(0, CLIENT_GAME_RUNNING_STATE);
   
-  /* from here on, treat scenarios as normal games, as this is what
-     they have become (nothing special about them anymore)*/
-  game.scenario=0;
-  
   while(server_state==RUN_GAME_STATE) {
     force_end_of_sniff=0;
     freelog(LOG_DEBUG, "Shuffleplayers");
@@ -1510,7 +1500,7 @@
       send_player_info(&game.players[i], 0);
       notify_player(0, _("Game: Lost connection to %s."), 
game.players[i].name);
 
-      if(is_new_game && (server_state==PRE_GAME_STATE ||
+      if(game.is_new_game && (server_state==PRE_GAME_STATE ||
                         server_state==SELECT_RACES_STATE))
         server_remove_player(&game.players[i]);
       check_for_full_turn_done();
diff -u -r --exclude-from exclude freeciv-cvs/server/gamehand.c 
fc-adv/server/gamehand.c
--- freeciv-cvs/server/gamehand.c       Thu Dec 23 16:51:28 1999
+++ fc-adv/server/gamehand.c    Sun Dec 26 17:31:26 1999
@@ -54,7 +54,7 @@
   int i, j, x, y;
   int start_pos[MAX_NUM_PLAYERS]; /* indices into map.start_positions[] */
   
-  if (game.scenario!=1 && game.scenario!=2) {
+  if (!map.fixed_start_positions) {
     /* except in a scenario which provides them,
        shuffle the start positions around... */
     assert(game.nplayers==map.num_start_positions);
@@ -74,7 +74,7 @@
      to random from remainder.  (Would be better to label start
      positions by nation etc, but this will do for now. --dwp)
   */
-  if(game.scenario!=1 && game.scenario!=2) {
+  if(!map.fixed_start_positions) {
     for(i=0; i<game.nplayers; i++) {
       start_pos[i] = i;
     } 
@@ -268,7 +268,7 @@
 /***************************************************************
 ...
 ***************************************************************/
-int game_load(struct section_file *file)
+void game_load(struct section_file *file)
 {
   int i;
   enum server_states tmp_server_state;
@@ -417,12 +417,15 @@
       }
 
       if (tmp_server_state==PRE_GAME_STATE &&
-         map.generator == 0) { /* generator 0 = map done with map editor */
+         map.generator == 0) {
+       /* generator 0 = map done with map editor */
+       /* aka a "scenario" */
         if (has_capability("specials",savefile_options)) {
           map_load(file);
+         map.fixed_start_positions = 1;
           section_file_check_unused(file, NULL);
           section_file_free(file);
-          return 1; /* make this a type 1 scenario */
+          return;
         }
         map_tiles_load(file);
         if (has_capability("riversoverlay",savefile_options)) {
@@ -430,16 +433,19 @@
        }
         if (has_capability("startpos",savefile_options)) {
           map_startpos_load(file);
-          return 2; /* make this a type 2 scenario */
+         map.fixed_start_positions = 1;
+          return;
         }
-       return 3; /* make this a type 3 scenario */
+       return;
       }
     }
     if(tmp_server_state==PRE_GAME_STATE) {
-      return 0;
+      return;
     }
   }
 
+  game.is_new_game = 0;
+  
   load_rulesets();
 
   map_load(file);
@@ -469,7 +475,7 @@
   game.player_idx=0;
   game.player_ptr=&game.players[0];  
 
-  return 1;
+  return;
 }
 
 
@@ -502,12 +508,10 @@
       }
       temp2=strtok(NULL," ");
     }
-    if(game.scenario==2) {
-      /* we have start positions in type 2 scenarios */
+    if(map.num_start_positions>0) {
       strcat(temp1," startpos");
-    } else
-    if(game.scenario==1) {
-      /* we have start positions and specials in type 1 scenarios */
+    }
+    if(map.have_specials) {
       strcat(temp1," specials");
     }
     secfile_insert_str(file, temp1+1, "savefile.options");
@@ -574,7 +578,7 @@
     secfile_insert_int(file, map.huts, "map.huts");
     secfile_insert_int(file, map.generator, "map.generator");
   } 
-  if ((server_state==PRE_GAME_STATE) && (game.scenario==0)) {
+  if ((server_state==PRE_GAME_STATE) && game.is_new_game) {
     return; /* want to save scenarios as well */
   }
   if (server_state!=PRE_GAME_STATE) {
diff -u -r --exclude-from exclude freeciv-cvs/server/gamehand.h 
fc-adv/server/gamehand.h
--- freeciv-cvs/server/gamehand.h       Sun Jul 11 22:57:05 1999
+++ fc-adv/server/gamehand.h    Sun Dec 26 17:30:38 1999
@@ -21,7 +21,7 @@
 void send_game_info(struct player *dest);
 void send_game_state(struct player *dest, int state);
 
-int game_load(struct section_file *file);
+void game_load(struct section_file *file);
 void game_save(struct section_file *file);
 
 #endif  /* FC__GAMEHAND_H */
diff -u -r --exclude-from exclude freeciv-cvs/server/mapgen.c 
fc-adv/server/mapgen.c
--- freeciv-cvs/server/mapgen.c Thu Dec 23 16:51:28 1999
+++ fc-adv/server/mapgen.c      Sun Dec 26 13:17:31 1999
@@ -730,7 +730,7 @@
     remove_tiny_islands();
   }
 
-  if(game.scenario!=1) /* type 1 scenarios already provide specials */
+  if(!map.have_specials) /* some scenarios already provide specials */
     add_specials(map.riches); /* hvor mange promiller specials oensker vi*/
   
   /* print_map(); */
@@ -967,7 +967,7 @@
 {
   int x,y;
   enum tile_terrain_type ttype;
-  for (y=1;y<map.ysize-1;y++)
+  for (y=1;y<map.ysize-1;y++) {
     for (x=0;x<map.xsize; x++) {
       ttype = map_get_terrain(x, y);
       if ((ttype==T_OCEAN && is_coastline(x,y)) || (ttype!=T_OCEAN)) {
@@ -984,6 +984,8 @@
        }
       }
     }
+  }
+  map.have_specials = 1;
 }
 
 /**************************************************************************
diff -u -r --exclude-from exclude freeciv-cvs/server/maphand.c 
fc-adv/server/maphand.c
--- freeciv-cvs/server/maphand.c        Tue Oct  5 00:03:08 1999
+++ fc-adv/server/maphand.c     Sun Dec 26 17:45:04 1999
@@ -332,8 +332,7 @@
    */
   secfile_insert_int(file, map.is_earth, "map.is_earth");
 
-  /* don't save start positions in a type 3 scenario */
-  if(game.scenario!=3) {
+  if(map.num_start_positions>0) {
     for(i=0; i<game.nation_count; i++) {
       secfile_insert_int(file, map.start_positions[i].x, "map.r%dsx", i);
       secfile_insert_int(file, map.start_positions[i].y, "map.r%dsy", i);
@@ -349,8 +348,7 @@
     secfile_insert_str(file, pbuf, "map.t%03d", y);
   }
 
-  /* don't save specials in scenarios of types 2 and 3 */
-  if((game.scenario==3) || (game.scenario==2)) {
+  if(!map.have_specials) {
     free(pbuf);
     return;
   }
@@ -606,6 +604,7 @@
       }
     }
   }
+  map.have_specials = 1;
 }
 
 /***************************************************************
diff -u -r --exclude-from exclude freeciv-cvs/server/stdinhand.c 
fc-adv/server/stdinhand.c
--- freeciv-cvs/server/stdinhand.c      Thu Dec 23 16:51:32 1999
+++ fc-adv/server/stdinhand.c   Sun Dec 26 17:25:08 1999
@@ -556,10 +556,10 @@
   case SSET_GAME_INIT:
   case SSET_RULES:
     /* Only change start params and most rules if we don't yet have a map,
-     * or if we do have a map but its a scenario one.  Once a scenario is
-     * actually started, game.scenario will be set to 0.
+     * or if we do have a map but its a scenario one (ie, the game has
+     * never actually been started).
      */
-    return (map_is_empty() || (game.scenario!=0));
+    return (map_is_empty() || game.is_new_game);
   case SSET_RULES_FLEXIBLE:
   case SSET_META:
     /* These can always be changed: */

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] patch: remove/replace game.scenario field (PR#209), David Pfitzner <=