Author: cazfi
Date: Fri Mar 20 06:39:17 2015
New Revision: 28590

URL: http://svn.gna.org/viewcvs/freeciv?rev=28590&view=rev
Log:
Refactored extra spreading code to work based on target tile rather than source 
tile.

See patch #5912

Modified:
    trunk/common/extras.c
    trunk/common/extras.h
    trunk/server/srv_main.c

Modified: trunk/common/extras.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/extras.c?rev=28590&r1=28589&r2=28590&view=diff
==============================================================================
--- trunk/common/extras.c       (original)
+++ trunk/common/extras.c       Fri Mar 20 06:39:17 2015
@@ -789,3 +789,15 @@
 {
   return ptile->extras_owner;
 }
+
+/**************************************************************************
+  Are all the requirements for extra to appear on tile fulfilled. Does not
+  check if extra is of appearing type (has EC_SPONTANEOUS cause).
+**************************************************************************/
+bool can_extra_appear(const struct extra_type *pextra, const struct tile 
*ptile)
+{
+  return !tile_has_extra(ptile, pextra)
+    && is_native_tile_to_extra(pextra, ptile)
+    && !extra_conflicting_on_tile(pextra, ptile)
+    && is_extra_near_tile(ptile, pextra);
+}

Modified: trunk/common/extras.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/extras.h?rev=28590&r1=28589&r2=28590&view=diff
==============================================================================
--- trunk/common/extras.h       (original)
+++ trunk/common/extras.h       Fri Mar 20 06:39:17 2015
@@ -196,6 +196,8 @@
 bool can_extras_coexist(const struct extra_type *pextra1,
                         const struct extra_type *pextra2);
 
+bool can_extra_appear(const struct extra_type *pextra, const struct tile 
*ptile);
+
 struct extra_type *next_extra_for_tile(const struct tile *ptile, enum 
extra_cause cause,
                                        const struct player *pplayer,
                                        const struct unit *punit);

Modified: trunk/server/srv_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/srv_main.c?rev=28590&r1=28589&r2=28590&view=diff
==============================================================================
--- trunk/server/srv_main.c     (original)
+++ trunk/server/srv_main.c     Fri Mar 20 06:39:17 2015
@@ -1276,46 +1276,29 @@
   }
 
   extra_type_by_cause_iterate(EC_SPONTANEOUS, pextra) {
-    whole_map_iterate(src_tile) {
-      if (tile_has_extra(src_tile, pextra)
-          && fc_rand(1000) < pextra->appearance_chance) {
-        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,
+    whole_map_iterate(ptile) {
+      if (fc_rand(1000) < pextra->appearance_chance
+          && can_extra_appear(pextra, ptile)) {
+
+        tile_add_extra(ptile, pextra);
+
+        update_tile_knowledge(ptile);
+
+        if (tile_owner(ptile) != NULL) {
+          /* TODO: Should notify players nearby even when borders disabled,
+           *       like in case of barbarian uprising */
+          notify_player(tile_owner(ptile), ptile,
                         E_EXTRA_APPEARS, ftc_server,
                         /* TRANS: Small Fish appears to (32, 72). */
                         _("%s appears to %s."),
                         extra_name_translation(pextra),
-                        tile_link(tgt_tile));
+                        tile_link(ptile));
         }
 
         /* 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(ptile);
+        adjc_iterate(ptile, n_tile) {
           unit_activities_cancel_all_illegal(n_tile);
         } adjc_iterate_end;
       }


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

Reply via email to