Author: sveinung
Date: Wed Jan 14 03:39:48 2015
New Revision: 27673

URL: http://svn.gna.org/viewcvs/freeciv?rev=27673&view=rev
Log:
Introduce extras that spreads on their own.

Some real world objects that is natural to model as an extra in a Freeciv
ruleset spreads on their own. Examples are paths spreading out of a
settlement, Terra forming Algae spreading from the area where they were
released and a crop killing pest spreading from farm to farm.

A spreading extra has a 1.5% base probability to spread each turn. If the
dice rolls in its favor it will pick a random direction, test if it can
legally spread to the tile in that direction and then, if legal, spread.

Use cases:
 * Path (auto on city tile) spreads out of a city, providing the only non
   natural roads until Road Building have been researched.
 * The Terra Former unit can release Algae on any tile where the terrain has
   the LiquidWater flag. Algae give a bit food and makes it possible to
   release or spread Small Fish (luxury and food bonus) to the tile. Since
   Algae and Small fish spreads it may not be smart to release them in a
   lake where another player have many cities. Releasing them in a chess
   board pattern hoping that nature will do your work for you in stead of
   releasing to every tile may also be a good idea.
 * Map comes with Potato Blight on some tiles. It can spread to neighbor
   tiles with Irrigation, dramatically reducing food production. It is
   therefore smart to avoid irrigating tiles next to Potato Blight unit the
   tech to remove it is researched. It can be released (in enemy terrain) by
   the War Biologist unit.

This patch is aimed at ruleset authors that don't want to do any Lua
programming.

See patch #5616

Modified:
    trunk/client/helpdata.c
    trunk/common/events.c
    trunk/common/events.h
    trunk/common/extras.c
    trunk/common/extras.h
    trunk/data/alien/terrain.ruleset
    trunk/data/civ1/terrain.ruleset
    trunk/data/civ2/terrain.ruleset
    trunk/data/civ2civ3/terrain.ruleset
    trunk/data/classic/terrain.ruleset
    trunk/data/experimental/terrain.ruleset
    trunk/data/misc/events.spec
    trunk/data/multiplayer/terrain.ruleset
    trunk/data/stdsounds.soundspec
    trunk/data/stub/terrain.ruleset
    trunk/fc_version
    trunk/server/srv_main.c

Modified: trunk/client/helpdata.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/helpdata.c?rev=27673&r1=27672&r2=27673&view=diff
==============================================================================
--- trunk/client/helpdata.c     (original)
+++ trunk/client/helpdata.c     Wed Jan 14 03:39:48 2015
@@ -4270,6 +4270,11 @@
             _("* Placed by mapgenerator.\n"));
   }
 
+  if (extra_has_flag(pextra, EF_SPREADS)) {
+    CATLSTR(buf, bufsz,
+            _(" * May spread to neighbor tiles.\n"));
+  }
+
   /* XXX Non-zero requirement vector is not a good test of whether
    * insert_requirement() will give any output. */
   if (requirement_vector_size(&pextra->reqs) > 0) {

Modified: trunk/common/events.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/events.c?rev=27673&r1=27672&r2=27673&view=diff
==============================================================================
--- trunk/common/events.c       (original)
+++ trunk/common/events.c       Wed Jan 14 03:39:48 2015
@@ -204,6 +204,7 @@
   GEN_EV(E_SCRIPT,             E_S_XYZZY,      N_("Scenario/ruleset script 
message")),
   /* TRANS: Event name for when the game year changes. */
   GEN_EV(E_NEXT_YEAR,          E_S_XYZZY,      N_("Year Advance")),
+  GEN_EV(E_EXTRA_SPREAD,        E_S_XYZZY,      N_("Extra Spreads"))
   /* The sound system also generates "e_game_quit", although there's no
    * corresponding identifier E_GAME_QUIT. */
 };

Modified: trunk/common/events.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/events.h?rev=27673&r1=27672&r2=27673&view=diff
==============================================================================
--- trunk/common/events.h       (original)
+++ trunk/common/events.h       Wed Jan 14 03:39:48 2015
@@ -151,6 +151,7 @@
 #define SPECENUM_VALUE113 E_TECH_EMBASSY
 #define SPECENUM_VALUE114 E_MY_SPY_STEAL_GOLD
 #define SPECENUM_VALUE115 E_ENEMY_SPY_STEAL_GOLD
+#define SPECENUM_VALUE116 E_EXTRA_SPREAD
 /*
  * Note: If you add a new event, make sure you make a similar change
  * to the events array in "common/events.c" using GEN_EV, to

Modified: trunk/common/extras.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/extras.c?rev=27673&r1=27672&r2=27673&view=diff
==============================================================================
--- trunk/common/extras.c       (original)
+++ trunk/common/extras.c       Wed Jan 14 03:39:48 2015
@@ -541,6 +541,22 @@
   return are_reqs_active(NULL, NULL, NULL, NULL, ptile,
                          NULL, NULL, NULL, NULL,
                          &pextra->reqs, RPT_POSSIBLE);
+}
+
+/****************************************************************************
+  Returns TRUE iff an extra that conflicts with pextra exists at ptile.
+****************************************************************************/
+bool extra_conflicting_on_tile(const struct extra_type *pextra,
+                               const struct tile *ptile)
+{
+  extra_type_iterate(old_extra) {
+    if (tile_has_extra(ptile, old_extra)
+        && !can_extras_coexist(old_extra, pextra)) {
+      return TRUE;
+    }
+  } extra_type_iterate_end;
+
+  return FALSE;
 }
 
 /****************************************************************************

Modified: trunk/common/extras.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/extras.h?rev=27673&r1=27672&r2=27673&view=diff
==============================================================================
--- trunk/common/extras.h       (original)
+++ trunk/common/extras.h       Wed Jan 14 03:39:48 2015
@@ -47,6 +47,9 @@
 /* Counts towards Nuclear Winter */
 #define SPECENUM_VALUE7 EF_NUCLEAR_WINTER
 #define SPECENUM_VALUE7NAME "NuclearWinter"
+/* May spread to neighbor tiles. */
+#define SPECENUM_VALUE8 EF_SPREADS
+#define SPECENUM_VALUE8NAME "Spreads"
 #define SPECENUM_COUNT EF_COUNT
 #define SPECENUM_BITVECTOR bv_extra_flags
 #include "specenum_gen.h"
@@ -172,6 +175,8 @@
                               const struct unit_type *punittype);
 bool is_native_tile_to_extra(const struct extra_type *pextra,
                              const struct tile *ptile);
+bool extra_conflicting_on_tile(const struct extra_type *pextra,
+                               const struct tile *ptile);
 
 bool extra_has_flag(const struct extra_type *pextra, enum extra_flag_id flag);
 

Modified: trunk/data/alien/terrain.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/alien/terrain.ruleset?rev=27673&r1=27672&r2=27673&view=diff
==============================================================================
--- trunk/data/alien/terrain.ruleset    (original)
+++ trunk/data/alien/terrain.ruleset    Wed Jan 14 03:39:48 2015
@@ -630,6 +630,7 @@
 ;                           Global Warming
 ;   - "NuclearWinter"     = Instances of this extra on map count towards
 ;                           Nuclear Winter
+;   - "Spreads"           = This extra may spread to neighbor tiles.
 ; helptext                = optional help text string; should escape all raw
 ;                           newlines so that xgettext parsing works
 ;

Modified: trunk/data/civ1/terrain.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/civ1/terrain.ruleset?rev=27673&r1=27672&r2=27673&view=diff
==============================================================================
--- trunk/data/civ1/terrain.ruleset     (original)
+++ trunk/data/civ1/terrain.ruleset     Wed Jan 14 03:39:48 2015
@@ -787,6 +787,7 @@
 ;                           Global Warming
 ;   - "NuclearWinter"     = Instances of this extra on map count towards
 ;                           Nuclear Winter
+;   - "Spreads"           = This extra may spread to neighbor tiles.
 ; helptext                = optional help text string; should escape all raw
 ;                           newlines so that xgettext parsing works
 ;

Modified: trunk/data/civ2/terrain.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/civ2/terrain.ruleset?rev=27673&r1=27672&r2=27673&view=diff
==============================================================================
--- trunk/data/civ2/terrain.ruleset     (original)
+++ trunk/data/civ2/terrain.ruleset     Wed Jan 14 03:39:48 2015
@@ -893,6 +893,7 @@
 ;                           Global Warming
 ;   - "NuclearWinter"     = Instances of this extra on map count towards
 ;                           Nuclear Winter
+;   - "Spreads"           = This extra may spread to neighbor tiles.
 ; helptext                = optional help text string; should escape all raw
 ;                           newlines so that xgettext parsing works
 ;

Modified: trunk/data/civ2civ3/terrain.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/civ2civ3/terrain.ruleset?rev=27673&r1=27672&r2=27673&view=diff
==============================================================================
--- trunk/data/civ2civ3/terrain.ruleset (original)
+++ trunk/data/civ2civ3/terrain.ruleset Wed Jan 14 03:39:48 2015
@@ -1072,6 +1072,7 @@
 ;                           Global Warming
 ;   - "NuclearWinter"     = Instances of this extra on map count towards
 ;                           Nuclear Winter
+;   - "Spreads"           = This extra may spread to neighbor tiles.
 ; helptext                = optional help text string; should escape all raw
 ;                           newlines so that xgettext parsing works
 ;

Modified: trunk/data/classic/terrain.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/classic/terrain.ruleset?rev=27673&r1=27672&r2=27673&view=diff
==============================================================================
--- trunk/data/classic/terrain.ruleset  (original)
+++ trunk/data/classic/terrain.ruleset  Wed Jan 14 03:39:48 2015
@@ -1072,6 +1072,7 @@
 ;                           Global Warming
 ;   - "NuclearWinter"     = Instances of this extra on map count towards
 ;                           Nuclear Winter
+;   - "Spreads"           = This extra may spread to neighbor tiles.
 ; helptext                = optional help text string; should escape all raw
 ;                           newlines so that xgettext parsing works
 ;

Modified: trunk/data/experimental/terrain.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/experimental/terrain.ruleset?rev=27673&r1=27672&r2=27673&view=diff
==============================================================================
--- trunk/data/experimental/terrain.ruleset     (original)
+++ trunk/data/experimental/terrain.ruleset     Wed Jan 14 03:39:48 2015
@@ -1048,6 +1048,7 @@
 ;                           Global Warming
 ;   - "NuclearWinter"     = Instances of this extra on map count towards
 ;                           Nuclear Winter
+;   - "Spreads"           = This extra may spread to neighbor tiles.
 ; helptext                = optional help text string; should escape all raw
 ;                           newlines so that xgettext parsing works
 ;

Modified: trunk/data/misc/events.spec
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/misc/events.spec?rev=27673&r1=27672&r2=27673&view=diff
==============================================================================
--- trunk/data/misc/events.spec (original)
+++ trunk/data/misc/events.spec Wed Jan 14 03:39:48 2015
@@ -100,4 +100,6 @@
   4,  8, "e_revolt_done"
   4,  9, "e_revolt_start"
   4, 10, "e_spaceship"
+
+  1, 2, "e_extra_spread"
 }

Modified: trunk/data/multiplayer/terrain.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/multiplayer/terrain.ruleset?rev=27673&r1=27672&r2=27673&view=diff
==============================================================================
--- trunk/data/multiplayer/terrain.ruleset      (original)
+++ trunk/data/multiplayer/terrain.ruleset      Wed Jan 14 03:39:48 2015
@@ -1046,6 +1046,7 @@
 ;                           Global Warming
 ;   - "NuclearWinter"     = Instances of this extra on map count towards
 ;                           Nuclear Winter
+;   - "Spreads"           = This extra may spread to neighbor tiles.
 ; helptext                = optional help text string; should escape all raw
 ;                           newlines so that xgettext parsing works
 ;

Modified: trunk/data/stdsounds.soundspec
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/stdsounds.soundspec?rev=27673&r1=27672&r2=27673&view=diff
==============================================================================
--- trunk/data/stdsounds.soundspec      (original)
+++ trunk/data/stdsounds.soundspec      Wed Jan 14 03:39:48 2015
@@ -316,5 +316,7 @@
 ;e_wonder_will_be_built = ""
 ;e_worklist = ""
 
+;e_extra_spread = ""
+
 ; This pseudo-event is only used in the sound system.
 ;e_game_quit = ""

Modified: trunk/data/stub/terrain.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/stub/terrain.ruleset?rev=27673&r1=27672&r2=27673&view=diff
==============================================================================
--- trunk/data/stub/terrain.ruleset     (original)
+++ trunk/data/stub/terrain.ruleset     Wed Jan 14 03:39:48 2015
@@ -343,6 +343,7 @@
 ;                           Global Warming
 ;   - "NuclearWinter"     = Instances of this extra on map count towards
 ;                           Nuclear Winter
+;   - "Spreads"           = This extra may spread to neighbor tiles.
 ; helptext                = optional help text string; should escape all raw
 ;                           newlines so that xgettext parsing works
 ;

Modified: trunk/fc_version
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/fc_version?rev=27673&r1=27672&r2=27673&view=diff
==============================================================================
--- trunk/fc_version    (original)
+++ trunk/fc_version    Wed Jan 14 03:39:48 2015
@@ -54,7 +54,7 @@
 #   - Avoid adding a new mandatory capability to the development branch for
 #     as long as possible.  We want to maintain network compatibility with
 #     the stable branch for as long as possible.
-NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-3.0-2015.Jan.11b"
+NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-3.0-2015.Jan.14"
 NETWORK_CAPSTRING_OPTIONAL=""
 
 FREECIV_DISTRIBUTOR=""

Modified: trunk/server/srv_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/srv_main.c?rev=27673&r1=27672&r2=27673&view=diff
==============================================================================
--- trunk/server/srv_main.c     (original)
+++ trunk/server/srv_main.c     Wed Jan 14 03:39:48 2015
@@ -1260,6 +1260,63 @@
                                &game.info.coolinglevel, nuclear_winter);
   }
 
+  extra_type_iterate(pextra) {
+    if (extra_has_flag(pextra, EF_SPREADS)) {
+      whole_map_iterate(src_tile) {
+        if (tile_has_extra(src_tile, pextra)
+            /* Each spreading extra has a 1,5% chance of spreading each
+             * turn. This extra spreading speed makes it relatively rare
+             * but not unheard of. */
+            /* TODO: Put probability that an extra will spread in an
+             * effect ("Extra_Spread_Pm") on the source tile.
+             * With a cache of what extra types that has any chance of
+             * spreading at all it could replace the EF_SPREADS extra flag
+             * without killing performance. */
+            && fc_rand(1000) < 15) {
+          struct tile *tgt_tile;
+
+          /* Select tile to spread to. */
+          tgt_tile = mapstep(src_tile, rand_direction());
+
+          if (!tgt_tile) {
+            /* Non existing target tile. */
+            continue;
+          }
+
+          if (tile_has_extra(tgt_tile, pextra)
+              || !is_native_tile_to_extra(pextra, tgt_tile)
+              /* TODO: Make it ruleset configurable if an extra should
+               * spread to a tile and replace any conflicting extras or if
+               * it shouldn't spread to a tile with a conflicting extra. */
+              || extra_conflicting_on_tile(pextra, tgt_tile)) {
+            /* Can't spread to target tile. */
+            continue;
+          }
+
+          tile_add_extra(tgt_tile, pextra);
+
+          update_tile_knowledge(tgt_tile);
+
+          if (tile_owner(tgt_tile) != NULL) {
+            notify_player(tile_owner(tgt_tile), tgt_tile,
+                          E_EXTRA_SPREAD, ftc_server,
+                          /* TRANS: Small Fish spreads to (32, 72). */
+                          _("%s spreads to %s."),
+                          extra_name_translation(pextra),
+                          tile_link(tgt_tile));
+          }
+
+          /* Unit activities at the target tile and its neighbors may now
+           * be illegal because of !present reqs. */
+          unit_activities_cancel_all_illegal(tgt_tile);
+          adjc_iterate(tgt_tile, n_tile) {
+            unit_activities_cancel_all_illegal(n_tile);
+          } adjc_iterate_end;
+        }
+      } whole_map_iterate_end;
+    }
+  } extra_type_iterate_end;
+
   update_diplomatics();
   make_history_report();
   settings_turn();


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to