Complete.Org: Mailing Lists: Archives: freeciv-dev: June 2005:
[Freeciv-Dev] (PR#13340) Owner change and happyborders
Home

[Freeciv-Dev] (PR#13340) Owner change and happyborders

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#13340) Owner change and happyborders
From: "Mateusz Stefek" <mstefek@xxxxxxxxx>
Date: Mon, 27 Jun 2005 05:32:47 -0700
Reply-to: bugs@xxxxxxxxxxx

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

The version with hash map.
--
mateusz
Index: server/maphand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/maphand.c,v
retrieving revision 1.165
diff -u -r1.165 maphand.c
--- server/maphand.c    7 Jun 2005 06:17:13 -0000       1.165
+++ server/maphand.c    27 Jun 2005 12:30:01 -0000
@@ -20,6 +20,7 @@
 #include "events.h"
 #include "fcintl.h"
 #include "game.h"
+#include "hash.h"
 #include "log.h"
 #include "map.h"
 #include "mem.h"
@@ -1662,6 +1663,14 @@
 *************************************************************************/
 static void map_update_borders_recalculate_position(struct tile *ptile)
 {
+  struct hash_table* cities_to_refresh = NULL;
+  int i;
+  
+  if (game.info.happyborders > 0) {
+    cities_to_refresh = hash_new_nentries(hash_fval_int, hash_fcmp_int,
+      game.info.borders * game.info.borders + 1);
+  }
+  
   if (game.info.borders > 0) {
     iterate_outward(ptile, game.info.borders, tile1) {
       struct city *pccity = map_get_closest_city(tile1);
@@ -1674,9 +1683,30 @@
         * before; it's not stored in the playermap. */
        send_tile_info(NULL, tile1);
        tile_update_owner(tile1);
+       /* Update happiness */
+       if (game.info.happyborders > 0) {
+         unit_list_iterate(tile1->units, unit) {
+           struct city* homecity = find_city_by_id(unit->homecity);
+           if (!homecity) continue;
+           hash_insert(cities_to_refresh, &(homecity->id), NULL);
+         } unit_list_iterate_end;
+       }
       }
     } iterate_outward_end;
   }
+ 
+  /* Update happiness in all homecities we have collected */ 
+  if (game.info.happyborders > 0) {
+    int entries = hash_num_entries(cities_to_refresh);
+    for (i = 0; i < entries; i++) {
+      int id = *(int*)hash_key_by_number(cities_to_refresh, i);
+      struct city* to_refresh = find_city_by_id(id);
+      assert(to_refresh);
+      city_refresh(to_refresh);
+      send_city_info(city_owner(to_refresh), to_refresh);
+    }
+    hash_free(cities_to_refresh);
+  }
 }
 
 /*************************************************************************

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