Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2004:
[Freeciv-Dev] (PR#8803) num_start_positions limited by max_players
Home

[Freeciv-Dev] (PR#8803) num_start_positions limited by max_players

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#8803) num_start_positions limited by max_players
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 21 May 2004 23:06:33 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=8803 >

If a scenario specifies 14 start positions but max_players is only 7, 
only the first 7 start positions will be loaded or used.  See the 80x50 
earth-v2 scenario.

No doubt this is my bug.  This patch fixes it.

jason

Index: server/gamehand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/gamehand.c,v
retrieving revision 1.134
diff -u -r1.134 gamehand.c
--- server/gamehand.c   21 May 2004 18:34:59 -0000      1.134
+++ server/gamehand.c   22 May 2004 06:05:48 -0000
@@ -106,18 +106,27 @@
    * desired players. */
 
   /* First set up some data fields. */
+  freelog(LOG_VERBOSE, "Placing players at start positions.");
   for (i = 0; i < map.num_start_positions; i++) {
+    Nation_Type_id n = map.start_positions[i].nation;
+
     pos_used[i] = FALSE;
+    freelog(LOG_VERBOSE, "%3d : (%2d,%2d) : %d : %s",
+           i, map.start_positions[i].x, map.start_positions[i].y,
+           n, (n >= 0 ? get_nation_name(n) : ""));
   }
   players_iterate(pplayer) {
     start_pos[pplayer->player_no] = NO_START_POS;
   } players_iterate_end;
 
   /* Second, assign a nation to a start position for that nation. */
+  freelog(LOG_VERBOSE, "Assigning matching nations.");
   players_iterate(pplayer) {
     for (i = 0; i < map.num_start_positions; i++) {
       assert(pplayer->nation != NO_NATION_SELECTED);
       if (pplayer->nation == map.start_positions[i].nation) {
+       freelog(LOG_VERBOSE, "Start_pos %d matches player %d (%s).",
+               i, pplayer->player_no, get_nation_name(pplayer->nation));
        start_pos[pplayer->player_no] = i;
        pos_used[i] = TRUE;
        num_used++;
@@ -126,6 +135,7 @@
   } players_iterate_end;
 
   /* Third, assign players randomly to the remaining start positions. */
+  freelog(LOG_VERBOSE, "Assigning random nations.");
   players_iterate(pplayer) {
     if (start_pos[pplayer->player_no] == NO_START_POS) {
       int which = myrand(map.num_start_positions - num_used);
@@ -133,6 +143,9 @@
       for (i = 0; i < map.num_start_positions; i++) {
        if (!pos_used[i]) {
          if (which == 0) {
+           freelog(LOG_VERBOSE,
+                   "Randomly assigning player %d (%s) to pos %d.",
+                   pplayer->player_no, get_nation_name(pplayer->nation), i);
            start_pos[pplayer->player_no] = i;
            pos_used[i] = TRUE;
            num_used++;
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.152
diff -u -r1.152 savegame.c
--- server/savegame.c   19 May 2004 20:11:17 -0000      1.152
+++ server/savegame.c   22 May 2004 06:05:49 -0000
@@ -292,20 +292,29 @@
 ***************************************************************/
 static void map_startpos_load(struct section_file *file)
 {
-  int i=0, pos;
+  int i;
 
   map.fixed_start_positions = secfile_lookup_bool_default(file, FALSE, 
"map.fixed_start_positions");
 
+  for (i = 0; secfile_lookup_int_default(file, -1, "map.r%dsx", i) != -1;
+       i++) {
+    /* Nothing. */
+  }
+
+  map.num_start_positions = i;
+  if (map.num_start_positions == 0) {
+    /* This scenario has no preset start positions. */
+    return;
+  }
+
   map.start_positions = fc_realloc(map.start_positions,
-                                  game.max_players
+                                  map.num_start_positions
                                   * sizeof(*map.start_positions));
-  while (i < game.max_players
-        && (pos = secfile_lookup_int_default(file, -1,
-                                             "map.r%dsx", i)) != -1) {
+  for (i = 0; i < map.num_start_positions; i++) {
     char *nation = secfile_lookup_str_default(file, NULL, "map.r%dsnation",
                                              i);
 
-    map.start_positions[i].x = pos;
+    map.start_positions[i].x = secfile_lookup_int(file, "map.r%dsx", i);
     map.start_positions[i].y = secfile_lookup_int(file, "map.r%dsy", i);
 
     if (nation) {
@@ -318,19 +327,15 @@
        * randomly. */
       map.start_positions[i].nation = NO_NATION_SELECTED;
     }
-
-    i++;
   }
 
-  if (i < game.max_players) {
+  if (map.num_start_positions < game.max_players) {
     freelog(LOG_VERBOSE,
            _("Number of starts (%d) are lower than max_players (%d),"
              " lowering max_players."),
-           i, game.max_players);
-    game.max_players = i;
+           map.num_start_positions, game.max_players);
+    game.max_players = map.num_start_positions;
   }
-
-  map.num_start_positions = i;
 }
 
 /***************************************************************

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#8803) num_start_positions limited by max_players, Jason Short <=