Author: sveinung
Date: Wed Aug 26 13:37:46 2015
New Revision: 29682

URL: http://svn.gna.org/viewcvs/freeciv?rev=29682&view=rev
Log:
Add a common check if a city is occupied

Where to look when checking if a city is occupied depends on who is doing
it. The server is supposed to check units at the tile. The client has the
occupied city property.

This can cause copy past errors.

Add the new common function city_is_occupied(). It will check its context
before looking in the correct place.

Use it in the popup info text generation so Freeciv-web won't start claiming
that occupied cities are unoccupied if it is copied again.

Reported by Nook in his Let's Play Freeciv Youtube video at
https://youtu.be/NzJhIDeVEnE?t=29m21s

See bug #23813

Modified:
    trunk/client/text.c
    trunk/common/city.c
    trunk/common/city.h

Modified: trunk/client/text.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/text.c?rev=29682&r1=29681&r2=29682&view=diff
==============================================================================
--- trunk/client/text.c (original)
+++ trunk/client/text.c Wed Aug 26 13:37:46 2015
@@ -284,7 +284,7 @@
         astr_add(&str, _(" | Not occupied."));
       }
     } else {
-      if (pcity->client.occupied) {
+      if (city_is_occupied(pcity)) {
         astr_add(&str, _(" | Occupied."));
       } else {
         astr_add(&str, _(" | Not occupied."));

Modified: trunk/common/city.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/city.c?rev=29682&r1=29681&r2=29682&view=diff
==============================================================================
--- trunk/common/city.c (original)
+++ trunk/common/city.c Wed Aug 26 13:37:46 2015
@@ -1583,6 +1583,20 @@
 }
 
 /**************************************************************************
+  Returns TRUE iff the city is occupied.
+**************************************************************************/
+bool city_is_occupied(const struct city *pcity)
+{
+  if (is_server()) {
+    /* The server sees the units inside the city. */
+    return (unit_list_size(city_tile(pcity)->units) > 0);
+  } else {
+    /* The client gets the occupied property from the server. */
+    return pcity->client.occupied;
+  }
+}
+
+/**************************************************************************
   Find city with given id from list.
 **************************************************************************/
 struct city *city_list_find_number(struct city_list *This, int id)

Modified: trunk/common/city.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/city.h?rev=29682&r1=29681&r2=29682&view=diff
==============================================================================
--- trunk/common/city.h (original)
+++ trunk/common/city.h Wed Aug 26 13:37:46 2015
@@ -541,6 +541,7 @@
 bool base_city_celebrating(const struct city *pcity);
 bool city_celebrating(const struct city *pcity);            /* love the king 
??? */
 bool city_rapture_grow(const struct city *pcity);
+bool city_is_occupied(const struct city *pcity);
 
 /* city related improvement and unit functions */
 


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

Reply via email to