Complete.Org: Mailing Lists: Archives: freeciv-dev: June 2005:
[Freeciv-Dev] Re: (PR#10191) City and tile owner information
Home

[Freeciv-Dev] Re: (PR#10191) City and tile owner information

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] Re: (PR#10191) City and tile owner information
From: "Marko Lindqvist" <marko.lindqvist@xxxxxxxxxxx>
Date: Sat, 25 Jun 2005 02:42:36 -0700
Reply-to: bugs@xxxxxxxxxxx

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

Marko Lindqvist wrote:
> 
> Marko Lindqvist wrote:
> 
>>  Tile owner information itself is sent to everybody knowing the tile, 
>>even if it's fogged. It's not even part of player_tile as 
>>player_tile.owner would never differ from real_tile.owner. This is a 
>>rule (ie feature), not a bug. Both keeping it as it is, or changing it 
>>is okay with me.
> 
>   But if this is not changed, we have to send also city owner 
> information  to everybody knowing tile. Currently client thinks that 
> tile is owned by different player than city on top of it. (user visible 
> effect is that city is surrounded by tiles owned by another player)

  Attached patch makes tile owner information part of player map.


  - ML


diff -Nurd -X.diff_ignore freeciv/server/maphand.c freeciv/server/maphand.c
--- freeciv/server/maphand.c    2005-06-24 18:18:22.593750000 +0300
+++ freeciv/server/maphand.c    2005-06-25 12:11:56.171875000 +0300
@@ -456,7 +456,6 @@
 
   info.x = ptile->x;
   info.y = ptile->y;
-  info.owner = ptile->owner ? ptile->owner->player_no : MAP_TILE_OWNER_NULL;
   if (ptile->spec_sprite) {
     sz_strlcpy(info.spec_sprite, ptile->spec_sprite);
   } else {
@@ -477,13 +476,14 @@
        info.special[spe] = BV_ISSET(ptile->special, spe);
       }
       info.continent = ptile->continent;
+      info.owner = ptile->owner ? ptile->owner->player_no : 
MAP_TILE_OWNER_NULL;
       send_packet_tile_info(pconn, &info);
     } else if (pplayer && map_is_known(ptile, pplayer)
               && map_get_seen(ptile, pplayer) == 0) {
-      /* Just update the owner */
       struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
       info.known = TILE_KNOWN_FOGGED;
       info.type = plrtile->terrain;
+      info.owner = plrtile->owner >= 0 ? plrtile->owner : MAP_TILE_OWNER_NULL;
       for (spe = 0; spe < S_LAST; spe++) {
        info.special[spe] = BV_ISSET(plrtile->special, spe);
       }
@@ -1131,8 +1131,9 @@
 
   plrtile->last_updated = GAME_START_YEAR;
   plrtile->own_seen = plrtile->seen_count;
+  plrtile->owner = -1;
 }
- 
+
 /****************************************************************************
   Players' information of tiles is tracked so that fogged area can be kept
   consistent even when the client disconnects.  This function returns the
@@ -1158,9 +1159,16 @@
 
   if (plrtile->terrain != ptile->terrain
       || memcmp(&plrtile->special, &ptile->special,
-               sizeof(plrtile->special)) != 0) {
+               sizeof(plrtile->special)) != 0
+      || (ptile->owner && plrtile->owner != ptile->owner->player_no)
+      || (!ptile->owner && plrtile->owner >= 0)) {
     plrtile->terrain = ptile->terrain;
     plrtile->special = ptile->special;
+    if(ptile->owner) {
+      plrtile->owner = ptile->owner->player_no;
+    } else {
+      plrtile->owner = -1;
+    }
     return TRUE;
   }
   return FALSE;
@@ -1228,6 +1236,7 @@
       map_set_known(ptile, pdest);
       dest_tile->terrain = from_tile->terrain;
       dest_tile->special = from_tile->special;
+      dest_tile->owner = from_tile->owner;
       dest_tile->last_updated = from_tile->last_updated;
       send_tile_info_always(pdest, pdest->connections, ptile);
        
@@ -1669,10 +1678,7 @@
 
       if (new_owner != tile_get_owner(tile1)) {
        tile_set_owner(tile1, new_owner);
-       /* Note we call send_tile_info, not update_tile_knowledge here.
-        * Borders information is sent to everyone who has seen the tile
-        * before; it's not stored in the playermap. */
-       send_tile_info(NULL, tile1);
+        update_tile_knowledge(tile1);
        tile_update_owner(tile1);
       }
     } iterate_outward_end;
diff -Nurd -X.diff_ignore freeciv/server/maphand.h freeciv/server/maphand.h
--- freeciv/server/maphand.h    2005-06-24 18:18:22.640625000 +0300
+++ freeciv/server/maphand.h    2005-06-25 02:15:12.328125000 +0300
@@ -41,6 +41,7 @@
 struct player_tile {
   Terrain_type_id terrain;
   bv_special special;
+  signed char owner;
   unsigned short seen_count;
   unsigned short own_seen;
   /* If you build a city with an unknown square within city radius
diff -Nurd -X.diff_ignore freeciv/server/savegame.c freeciv/server/savegame.c
--- freeciv/server/savegame.c   2005-06-24 18:18:23.015625000 +0300
+++ freeciv/server/savegame.c   2005-06-25 12:33:01.609375000 +0300
@@ -184,7 +184,8 @@
 #define SAVEFILE_OPTIONS "startoptions spacerace2 rulesets" \
 " diplchance_percent worklists2 map_editor known32fix turn " \
 "attributes watchtower rulesetdir client_worklists orders " \
-"startunits turn_last_built improvement_order technology_order embassies"
+"startunits turn_last_built improvement_order technology_order embassies " \
+"owner_player_map"
 
 static const char hex_chars[] = "0123456789abcdef";
 
@@ -2396,6 +2397,7 @@
                            char** improvement_order,
                            int improvement_order_size)
 {
+  char *savefile_options = secfile_lookup_str(file, "savefile.options");
   int i;
 
   if (!plr->is_alive)
@@ -2457,6 +2459,29 @@
                  map_get_player_tile(ptile, plr)->last_updated |=
                  ascii_hex2bin(ch, 3));
 
+    /* get 4-bit segments of 8-bit "owner" field */
+    if (has_capability("owner_player_map", savefile_options)) {
+      LOAD_MAP_DATA(ch, nat_y, ptile,
+                    secfile_lookup_str
+                    (file, "player%d.map_oa%03d", plrno, nat_y),
+                    map_get_player_tile(ptile, plr)->owner =
+                    ascii_hex2bin(ch, 0));
+      LOAD_MAP_DATA(ch, nat_y, ptile,
+                    secfile_lookup_str
+                    (file, "player%d.map_ob%03d", plrno, nat_y),
+                    map_get_player_tile(ptile, plr)->owner =
+                    ascii_hex2bin(ch, 1));
+    } else {
+      int nat_x, nat_y;
+      for (nat_y = 0; nat_y < map.ysize; nat_y++) {
+        for (nat_x = 0; nat_x < map.xsize; nat_x++) {
+          struct tile *ptile = native_pos_to_tile(nat_x, nat_y);
+          map_get_player_tile(ptile, plr)->owner =
+            ptile->owner ? ptile->owner->player_no : -1;
+        }
+      }
+    }
+
     {
       int j;
       struct dumb_city *pdcity;
@@ -3074,6 +3099,14 @@
                         bin2ascii_hex(map_get_player_tile
                                       (ptile, plr)->last_updated, 3));
 
+    /* put 4-bit segments of 8-bit "owner" field */
+    SAVE_PLAYER_MAP_DATA(ptile, file, "player%d.map_oa%03d", plrno,
+                         bin2ascii_hex(map_get_player_tile
+                                       (ptile, plr)->owner, 0));
+    SAVE_PLAYER_MAP_DATA(ptile, file, "player%d.map_ob%03d", plrno,
+                         bin2ascii_hex(map_get_player_tile
+                                       (ptile, plr)->owner, 1));
+
     if (TRUE) {
       struct dumb_city *pdcity;
       char impr_buf[MAX_NUM_ITEMS + 1];

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