Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2005:
[Freeciv-Dev] Re: (PR#14827) save ppms of map in the server
Home

[Freeciv-Dev] Re: (PR#14827) save ppms of map in the server

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] Re: (PR#14827) save ppms of map in the server
From: "Mike Kaufman" <kaufman@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 18 Dec 2005 10:06:55 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=14827 >

here's the patch for S2_0

-mike

Index: server/civserver.c
===================================================================
--- server/civserver.c  (revision 11362)
+++ server/civserver.c  (working copy)
@@ -130,6 +130,8 @@
     } else if (is_option("--Newusers", argv[inx])) {
       srvarg.auth_allow_newusers = TRUE;
 #endif
+    } else if (is_option("--Ppm", argv[inx])) {
+      srvarg.save_ppm = TRUE;
     } else if ((option = get_option("--Serverid", argv, &inx, argc))) {
       sz_strlcpy(srvarg.serverid, option);
     } else if ((option = get_option("--saves", argv, &inx, argc))) {
@@ -191,6 +193,8 @@
               _("  -s, --saves DIR\tSave games to directory DIR\n"));
     fc_fprintf(stderr,
               _("  -S, --Serverid ID\tSets the server id to ID\n"));
+    fc_fprintf(stderr,
+            _("  -P, --Ppm\t\tSave ppms of the map when saving the game.\n"));
     fc_fprintf(stderr, _("  -r, --read FILE\tRead startup script FILE\n"));
     fc_fprintf(stderr, _("  -v, --version\t\tPrint the version number\n"));
     fc_fprintf(stderr, _("Report bugs to <%s>.\n"), BUG_EMAIL_ADDRESS);
Index: server/score.c
===================================================================
--- server/score.c      (revision 11362)
+++ server/score.c      (working copy)
@@ -19,9 +19,14 @@
 #include <string.h>
 
 #include "improvement.h"
+#include "log.h"
 #include "map.h"
 #include "mem.h"
 #include "player.h"
+#include "srv_main.h"
+#include "shared.h"
+#include "support.h"
+#include "terrain.h"
 #include "score.h"
 #include "unit.h"
 
@@ -486,3 +491,70 @@
          + pplayer->score.elvis
          + pplayer->score.taxmen);
 }
+
+/**************************************************************************
+ save a ppm file which is a representation of the map of the current turn.
+ this can later be turned into a animated gif.
+
+ terrain type, units, and cities are saved.
+**************************************************************************/
+void save_ppm(void)
+{
+  char filename[600];
+  char tmpname[600];
+  FILE *fp;
+  int i, j;
+
+  /* put this file in the same place we put savegames */
+  my_snprintf(filename, sizeof(filename),
+              "%s%+05d.int.ppm", game.save_name, game.year);
+
+  /* Ensure the saves directory exists. */
+  make_dir(srvarg.saves_pathname);
+
+  sz_strlcpy(tmpname, srvarg.saves_pathname);
+  if (tmpname[0] != '\0') {
+    sz_strlcat(tmpname, "/");
+  }
+  sz_strlcat(tmpname, filename);
+  sz_strlcpy(filename, tmpname);
+
+  fp = fopen(filename, "w");
+
+  if (!fp) {
+    freelog(LOG_ERROR, "couldn't open file ppm save: %s\n", filename);
+    return;
+  }
+
+  fprintf(fp, "P3\n# An intermediate map from saved Freeciv game %s%+05d\n",
+          game.save_name, game.year);
+
+  for (i = 0; i < game.nplayers; i++) {
+    struct player *pplayer = get_player(i);
+    fprintf(fp, "# playerno:%d:race:%d:name:\"%s\"\n", pplayer->player_no,
+            pplayer->nation, pplayer->name);
+  }
+  terrain_type_iterate(pterrain) {
+    fprintf(fp, "# terrain:%d:name:\"%s\"\n", pterrain, 
+            get_terrain_name(pterrain));
+  } terrain_type_iterate_end;
+
+  fprintf(fp, "%d %d\n", map.xsize, map.ysize);
+  fprintf(fp, "255\n");
+
+  for (j = 0; j < map.ysize; j++) {
+    for (i = 0; i < map.xsize; i++) {
+       struct tile *ptile = native_pos_to_tile(i, j);
+       int R, G, B;
+
+       R = (ptile->city) ? city_owner(ptile->city)->nation + 1 : 0;
+       G = (unit_list_size(&ptile->units) > 0) ?
+            unit_owner(unit_list_get(&ptile->units, 0))->nation + 1 : 0;
+       B = ptile->terrain;
+
+       fprintf(fp, "%d %d %d\n", R, G, B);
+    }
+  }
+
+  fclose(fp);
+}
Index: server/srv_main.c
===================================================================
--- server/srv_main.c   (revision 11362)
+++ server/srv_main.c   (working copy)
@@ -198,6 +198,8 @@
   /* initialize teams */
   team_init();
 
+  srvarg.save_ppm = FALSE;
+
   /* mark as initialized */
   has_been_srv_init = TRUE;
 
@@ -765,6 +767,7 @@
   my_snprintf(filename, sizeof(filename),
              "%s%+05d.sav", game.save_name, game.year);
   save_game(filename);
+  save_ppm();
   gamelog(GAMELOG_STATUS);
 }
 
Index: server/score.h
===================================================================
--- server/score.h      (revision 11362)
+++ server/score.h      (working copy)
@@ -20,4 +20,6 @@
 int get_civ_score(const struct player *pplayer);
 int total_player_citizens(const struct player *pplayer);
 
+void save_ppm(void);
+
 #endif /* FC__SCORE_H */
Index: server/srv_main.h
===================================================================
--- server/srv_main.h   (revision 11362)
+++ server/srv_main.h   (working copy)
@@ -39,6 +39,8 @@
   char *script_filename;
   char *saves_pathname;
   char serverid[256];
+  /* save a ppm of the map? */
+  bool save_ppm;
   /* quit if there no players after a given time interval */
   int quitidle;
   /* exit the server on game ending */

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