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

 This patch creates huts also when game is running. This behaviour is
controlled by new hutinterval server setting.
 One might set initial huts to zero.

 Currently hut cannot appear ocean tiles, cities or tiles with units.
We may want to add fortress and airbase tiles to that list.

 For now this is only a test how such a feature would work. If I'm
happy with it, I may consider committing it.


 - ML

diff -Nurd -X.diff_ignore freeciv/common/events.c freeciv/common/events.c
--- freeciv/common/events.c	2006-07-17 23:56:44.000000000 +0300
+++ freeciv/common/events.c	2007-01-14 12:18:42.000000000 +0200
@@ -96,6 +96,7 @@
   GEN_EV(N_("Year Advance"),                    E_NEXT_YEAR),
   GEN_EV(N_("Global: Eco-Disaster"),                  E_GLOBAL_ECO),
   GEN_EV(N_("Global: Nuke Detonated"),                E_NUKE),
+  GEN_EV(N_("Hut: New hut appears"),                  E_NEW_HUT),
   GEN_EV(N_("Hut: Barbarians in a Hut Roused"),       E_HUT_BARB),
   GEN_EV(N_("Hut: City Founded from Hut"),            E_HUT_CITY),
   GEN_EV(N_("Hut: Gold Found in Hut"),                E_HUT_GOLD),
diff -Nurd -X.diff_ignore freeciv/common/events.h freeciv/common/events.h
--- freeciv/common/events.h	2006-07-17 23:56:44.000000000 +0300
+++ freeciv/common/events.h	2007-01-14 12:19:14.000000000 +0200
@@ -72,6 +72,7 @@
   E_NEXT_YEAR,
   E_GLOBAL_ECO,
   E_NUKE,
+  E_NEW_HUT,         /* New hut appears */
   E_HUT_BARB,
   E_HUT_CITY,
   E_HUT_GOLD,
diff -Nurd -X.diff_ignore freeciv/common/game.c freeciv/common/game.c
--- freeciv/common/game.c	2007-01-13 03:18:47.000000000 +0200
+++ freeciv/common/game.c	2007-01-14 12:55:38.000000000 +0200
@@ -232,6 +232,7 @@
   game.info.barbarianrate = GAME_DEFAULT_BARBARIANRATE;
   game.info.onsetbarbarian= GAME_DEFAULT_ONSETBARBARIAN;
   game.info.nbarbarians   = 0;
+  game.info.hut_interval  = GAME_DEFAULT_HUTINTERVAL;
   game.info.occupychance  = GAME_DEFAULT_OCCUPYCHANCE;
   game.info.autoattack    = GAME_DEFAULT_AUTOATTACK;
   game.info.revolution_length = GAME_DEFAULT_REVOLUTION_LENGTH;
@@ -261,6 +262,7 @@
 
   game.seed = GAME_DEFAULT_SEED;
   game.scorelog    = GAME_DEFAULT_SCORELOG;
+  game.since_hut_creation = 0;
   game.fogofwar_old = game.info.fogofwar;
   sz_strlcpy(game.save_name, GAME_DEFAULT_SAVE_NAME);
   sz_strlcpy(game.rulesetdir, GAME_DEFAULT_RULESETDIR);
diff -Nurd -X.diff_ignore freeciv/common/game.h freeciv/common/game.h
--- freeciv/common/game.h	2007-01-13 03:18:47.000000000 +0200
+++ freeciv/common/game.h	2007-01-14 12:55:10.000000000 +0200
@@ -81,6 +81,7 @@
   char save_name[MAX_LEN_NAME];
   bool scorelog;
   int seed;
+  int since_hut_creation;
   bool fogofwar_old;	/* as the fog_of_war bit get changed by setting
 			   the server we need to remember the old setting */
   int ai_goal_government;	/* kludge */
@@ -320,6 +321,10 @@
 #define GAME_MIN_BARBARIANRATE       0
 #define GAME_MAX_BARBARIANRATE       4
 
+#define GAME_DEFAULT_HUTINTERVAL     0
+#define GAME_MIN_HUTINTERVAL         0
+#define GAME_MAX_HUTINTERVAL         500
+
 #define GAME_DEFAULT_ONSETBARBARIAN  (GAME_START_YEAR+ \
 				      ((GAME_DEFAULT_END_YEAR-(GAME_START_YEAR))/3))
 #define GAME_MIN_ONSETBARBARIAN      GAME_START_YEAR
diff -Nurd -X.diff_ignore freeciv/common/packets.def freeciv/common/packets.def
--- freeciv/common/packets.def	2007-01-13 03:18:47.000000000 +0200
+++ freeciv/common/packets.def	2007-01-14 12:54:44.000000000 +0200
@@ -456,6 +456,8 @@
 
   STRING start_units[MAX_LEN_STARTUNIT];
 
+  UINT8 hut_interval;
+
   UINT8 num_teams;
   STRING team_names_orig[MAX_NUM_TEAMS:num_teams][MAX_LEN_NAME];
   
diff -Nurd -X.diff_ignore freeciv/server/settings.c freeciv/server/settings.c
--- freeciv/server/settings.c	2007-01-13 03:18:47.000000000 +0200
+++ freeciv/server/settings.c	2007-01-14 13:19:11.000000000 +0200
@@ -392,6 +392,14 @@
 	     "that may be investiged by units."), NULL,
 	  MAP_MIN_HUTS, MAP_MAX_HUTS, MAP_DEFAULT_HUTS)
 
+  GEN_INT("hutinterval", game.info.hut_interval,
+	  SSET_RULES_FLEXIBLE, SSET_GEOLOGY, SSET_VITAL, SSET_TO_CLIENT,
+	  N_("New hut appearance interval"),
+	  N_("Hut appearance interval once game is started. "
+	     "Setting this to 10 will result in one hut creation "
+	     "attempt each turn."), NULL,
+	  GAME_MIN_HUTINTERVAL, GAME_MAX_HUTINTERVAL, GAME_DEFAULT_HUTINTERVAL)
+
   /* Options affecting numbers of players and AI players.  These only
    * affect the start of the game and can not be adjusted after that.
    * (Actually, mirules.nplayers does also affect reloads: you can't start a
diff -Nurd -X.diff_ignore freeciv/server/srv_main.c freeciv/server/srv_main.c
--- freeciv/server/srv_main.c	2007-01-13 08:20:23.000000000 +0200
+++ freeciv/server/srv_main.c	2007-01-14 13:16:09.000000000 +0200
@@ -747,6 +747,45 @@
 
   do_reveal_effects();
   do_have_embassies_effect();
+
+  if (game.info.hut_interval != 0) {
+    /* Hut creation enabled */
+
+    /* There is max 10 huts created each turn, so this is in
+     * tenths of turn. */
+    game.since_hut_creation += 10;
+
+    while(game.since_hut_creation >= game.info.hut_interval) {
+      /* Try to create another hut. */
+      struct tile *ptile;
+
+      game.since_hut_creation -= game.info.hut_interval;
+
+      ptile = &map.tiles[myrand(map_num_tiles()) - 1];
+
+      if (!is_ocean(tile_get_terrain(ptile))
+	  && !ptile->city
+	  && unit_list_size(ptile->units) == 0) {
+	/* Valid tile for hut */
+	freelog(LOG_DEBUG, "New hut at (%d,%d)", ptile->x, ptile->y);
+	
+	tile_set_special(ptile, S_HUT);
+
+	/* Send info to anybody who sees the tile. */
+	send_tile_info(NULL, ptile);
+
+	/* Send event to anybody who sees new hut. */
+	players_iterate(pplayer) {
+	  if (map_is_known_and_seen(ptile, pplayer, V_MAIN)) {
+	    notify_player(pplayer, ptile, E_NEW_HUT,
+			  _("New hut appears."));
+	  }
+	} players_iterate_end;
+      } else {
+	freelog(LOG_DEBUG, "Cannot create hut to (%d,%d)", ptile->x, ptile->y);
+      }
+    }
+  }
 }
 
 /**************************************************************************
diff -Nurd -X.diff_ignore freeciv/version.in freeciv/version.in
--- freeciv/version.in	2006-08-18 10:52:09.000000000 +0300
+++ freeciv/version.in	2007-01-14 11:57:53.000000000 +0200
@@ -24,4 +24,4 @@
 #   - Avoid adding a new manditory capbility to the development branch for
 #     as long as possible.  We want to maintain network compatibility with
 #     the stable branch for as long as possible.
-FREECIV_NETWORK_CAPSTRING("+Freeciv.Devel.2006.Aug.14")
+FREECIV_NETWORK_CAPSTRING("+Freeciv.Devel.2007.Jan.14")
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to