Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2004:
[Freeciv-Dev] (PR#9361) new function is_capital
Home

[Freeciv-Dev] (PR#9361) new function is_capital

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#9361) new function is_capital
From: "Jason Dorje Short" <jdorje@xxxxxxxxxxx>
Date: Tue, 13 Jul 2004 00:15:57 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=9361 >

This patch adds a new function is_capital().  This function is called in 
place of a hard-coded check of B_PALACE.  This is a small step (2-3%) 
toward effects.  Because of all the special-cases for capitals I think 
any effects patch will want this function, at least to start.  It 
unifies all of the special-cases into just one check.

In the process I found a significant bug introduced by the effects patch 
in building_lost().  This is why I think the patch needs to be split up 
to get sufficient scrutiny.

Support is included for all clients.

The only question may be one of naming.  Should the function be called 
city_is_capital()?

(Background: I took a simple part of Vasco's effects patch: the change 
to client/gui-gtk-2.0/diplodlg.c.  I split this off as its own small 
patch.  This means adding the new function is_capital() and using it in 
lots of places.)

jason

Index: ai/advdiplomacy.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/advdiplomacy.c,v
retrieving revision 1.22
diff -u -r1.22 advdiplomacy.c
--- ai/advdiplomacy.c   12 Jul 2004 20:19:17 -0000      1.22
+++ ai/advdiplomacy.c   13 Jul 2004 07:08:47 -0000
@@ -378,7 +378,7 @@
     } else if (give) {
       /* AI must be crazy to trade away its cities */
       worth -= city_gold_worth(offer);
-      if (city_got_building(offer, B_PALACE)) {
+      if (is_capital(offer)) {
         worth = -BIG_NUMBER; /* Never! Ever! */
       } else {
         worth *= 15;
Index: client/gui-gtk/diplodlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/diplodlg.c,v
retrieving revision 1.43
diff -u -r1.43 diplodlg.c
--- client/gui-gtk/diplodlg.c   5 May 2004 20:39:15 -0000       1.43
+++ client/gui-gtk/diplodlg.c   13 Jul 2004 07:08:47 -0000
@@ -255,7 +255,7 @@
   }
 
   city_list_iterate(pgiver->cities, pcity) {
-    if (!city_got_effect(pcity, B_PALACE)) {
+    if (!is_capital(pcity)) {
       city_list_ptrs[i] = pcity;
       i++;
     }
Index: client/gui-gtk-2.0/diplodlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/diplodlg.c,v
retrieving revision 1.21
diff -u -r1.21 diplodlg.c
--- client/gui-gtk-2.0/diplodlg.c       5 May 2004 20:39:15 -0000       1.21
+++ client/gui-gtk-2.0/diplodlg.c       13 Jul 2004 07:08:47 -0000
@@ -281,7 +281,7 @@
     }
 
     city_list_iterate(plr0->cities, pcity) {
-      if (!city_got_effect(pcity, B_PALACE)) {
+      if (!is_capital(pcity)) {
        city_list_ptrs[i] = pcity;
        i++;
       }
Index: client/gui-mui/diplodlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/diplodlg.c,v
retrieving revision 1.17
diff -u -r1.17 diplodlg.c
--- client/gui-mui/diplodlg.c   5 May 2004 20:39:16 -0000       1.17
+++ client/gui-mui/diplodlg.c   13 Jul 2004 07:08:48 -0000
@@ -290,7 +290,7 @@
   Object *entry;
 
   city_list_iterate(plr0->cities, pcity) {
-    if(!city_got_effect(pcity, B_PALACE)){
+    if (!is_capital(pcity)) {
       entry = MUI_MakeObject(MUIO_Menuitem,pcity->name,NULL,0,0);
       set(entry,MUIA_UserData,pcity->id);
       DoMethod(entry,MUIM_Notify,MUIA_Menuitem_Trigger, MUIV_EveryTime, 
entry,6, MUIM_CallHook, &civstandard_hook, diplomacy_city, pdialog, 
plr0->player_no,entry);
Index: client/gui-sdl/diplodlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/diplodlg.c,v
retrieving revision 1.14
diff -u -r1.14 diplodlg.c
--- client/gui-sdl/diplodlg.c   4 Dec 2003 13:53:12 -0000       1.14
+++ client/gui-sdl/diplodlg.c   13 Jul 2004 07:08:48 -0000
@@ -699,7 +699,7 @@
     if (n > 0) {
       city_list_ptrs = MALLOC(sizeof(struct city *) * n);
       city_list_iterate(pPlayer0->cities, pCity) {
-        if (!city_got_effect(pCity, B_PALACE)) {
+        if (!is_capital(pCity)) {
          city_list_ptrs[i] = pCity;
          i++;
         }
Index: client/gui-win32/diplodlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/diplodlg.c,v
retrieving revision 1.17
diff -u -r1.17 diplodlg.c
--- client/gui-win32/diplodlg.c 5 May 2004 20:39:16 -0000       1.17
+++ client/gui-win32/diplodlg.c 13 Jul 2004 07:08:48 -0000
@@ -211,7 +211,7 @@
   }
   
   city_list_iterate(plr0->cities, pcity) {
-    if(!city_got_effect(pcity, B_PALACE)){
+    if (!is_capital(pcity)) {
       city_list_ptrs[i] = pcity;
       i++;
     }
Index: client/gui-xaw/diplodlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/diplodlg.c,v
retrieving revision 1.38
diff -u -r1.38 diplodlg.c
--- client/gui-xaw/diplodlg.c   5 May 2004 20:39:16 -0000       1.38
+++ client/gui-xaw/diplodlg.c   13 Jul 2004 07:08:48 -0000
@@ -285,7 +285,7 @@
   }
 
   city_list_iterate(plr0->cities, pcity) {
-    if(!city_got_effect(pcity, B_PALACE)){
+    if (!is_capital(pcity)) {
       city_list_ptrs[i] = pcity;
       i++;
     }
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.226
diff -u -r1.226 city.c
--- common/city.c       12 Jul 2004 03:03:28 -0000      1.226
+++ common/city.c       13 Jul 2004 07:08:49 -0000
@@ -1162,6 +1162,15 @@
 }
 
 /**************************************************************************
+  Return TRUE iff this city is its nation's capital.  The capital city is
+  special-cased in a number of ways.
+**************************************************************************/
+bool is_capital(const struct city *pcity)
+{
+  return city_got_building(pcity, B_PALACE);
+}
+
+/**************************************************************************
  Whether a city has its own City Walls, or the same effect via a wonder.
 **************************************************************************/
 bool city_got_citywalls(const struct city *pcity)
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.151
diff -u -r1.151 city.h
--- common/city.h       12 Jul 2004 03:03:28 -0000      1.151
+++ common/city.h       13 Jul 2004 07:08:49 -0000
@@ -368,6 +368,7 @@
 bool city_got_building(const struct city *pcity,  Impr_Type_id id); 
 bool city_affected_by_wonder(const struct city *pcity, Impr_Type_id id);
 bool city_got_effect(const struct city *pcity, Impr_Type_id id);
+bool is_capital(const struct city *pcity);
 bool city_got_citywalls(const struct city *pcity);
 bool wonder_replacement(const struct city *pcity, Impr_Type_id id);
 int city_change_production_penalty(const struct city *pcity,
Index: common/player.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.c,v
retrieving revision 1.140
diff -u -r1.140 player.c
--- common/player.c     7 Jul 2004 07:32:03 -0000       1.140
+++ common/player.c     13 Jul 2004 07:08:49 -0000
@@ -523,10 +523,11 @@
 **************************************************************************/
 struct city *find_palace(struct player *pplayer)
 {
-  city_list_iterate(pplayer->cities, pcity) 
-    if (city_got_building(pcity, B_PALACE)) 
+  city_list_iterate(pplayer->cities, pcity) {
+    if (is_capital(pcity)) {
       return pcity;
-  city_list_iterate_end;
+    }
+  } city_list_iterate_end;
   return NULL;
 }
 
Index: server/citytools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/citytools.c,v
retrieving revision 1.261
diff -u -r1.261 citytools.c
--- server/citytools.c  14 Jun 2004 23:43:08 -0000      1.261
+++ server/citytools.c  13 Jul 2004 07:08:51 -0000
@@ -1327,13 +1327,13 @@
      - Kris Bubendorfer
      Also check spaceships --dwp
   */
-  if (city_got_building(pcity, B_PALACE)
+  if (is_capital(pcity)
       && (cplayer->spaceship.state == SSHIP_STARTED
           || cplayer->spaceship.state == SSHIP_LAUNCHED)) {
     spaceship_lost(cplayer);
   }
   
-  if (city_got_building(pcity, B_PALACE)
+  if (is_capital(pcity)
       && city_list_size(&cplayer->cities) >= game.civilwarsize
       && game.nplayers < game.nation_count
       && game.civilwarsize < GAME_MAX_CIVILWARSIZE
@@ -1444,8 +1444,7 @@
 
   packet->size = pdcity->size;
 
-  if (pcity && pcity->id == pdcity->id
-      && city_got_building(pcity, B_PALACE)) {
+  if (pcity && pcity->id == pdcity->id && is_capital(pcity)) {
     packet->capital = TRUE;
   } else {
     packet->capital = FALSE;
@@ -1903,11 +1902,14 @@
 void building_lost(struct city *pcity, Impr_Type_id id)
 {
   struct player *owner = city_owner(pcity);
+  bool was_capital = is_capital(pcity);
 
   city_remove_improvement(pcity,id);
-  if (id == B_PALACE
+  if ((was_capital && !is_capital(pcity))
       && (owner->spaceship.state == SSHIP_STARTED
          || owner->spaceship.state == SSHIP_LAUNCHED)) {
+    /* If the capital was lost (by destruction of the palace) production on
+     * the spaceship is lost. */
     spaceship_lost(owner);
   }
 }
Index: server/diplhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/diplhand.c,v
retrieving revision 1.81
diff -u -r1.81 diplhand.c
--- server/diplhand.c   5 May 2004 20:39:16 -0000       1.81
+++ server/diplhand.c   13 Jul 2004 07:08:51 -0000
@@ -168,7 +168,7 @@
                          pcity->name);
            return;
          }
-         if (city_got_building(pcity, B_PALACE)) {
+         if (is_capital(pcity)) {
            notify_player(pplayer,
                          _("Game: Your capital (%s) is requested, "
                            "you can't accept treaty."),
@@ -273,7 +273,7 @@
                          pcity->name);
            goto cleanup;
          }
-         if (city_got_building(pcity, B_PALACE)) {
+         if (is_capital(pcity)) {
            notify_player(pother,
                          _("Game: Your capital (%s) is requested, "
                            "you can't accept treaty."), pcity->name);
Index: server/plrhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.c,v
retrieving revision 1.312
diff -u -r1.312 plrhand.c
--- server/plrhand.c    17 Jun 2004 19:50:41 -0000      1.312
+++ server/plrhand.c    13 Jul 2004 07:08:52 -0000
@@ -1975,7 +1975,7 @@
   i = city_list_size(&pplayer->cities)/2;   /* number to flip */
   j = city_list_size(&pplayer->cities);            /* number left to process */
   city_list_iterate(pplayer->cities, pcity) {
-    if (!city_got_building(pcity, B_PALACE)) {
+    if (!is_capital(pcity)) {
       if (i >= j || (i > 0 && myrand(2) == 1)) {
        /* Transfer city and units supported by this city to the new owner
 
Index: server/sanitycheck.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/sanitycheck.c,v
retrieving revision 1.43
diff -u -r1.43 sanitycheck.c
--- server/sanitycheck.c        25 Jun 2004 23:30:00 -0000      1.43
+++ server/sanitycheck.c        13 Jul 2004 07:08:52 -0000
@@ -332,7 +332,7 @@
     int found_palace = 0;
 
     city_list_iterate(pplayer->cities, pcity) {
-      if (city_got_building(pcity, B_PALACE)) {
+      if (is_capital(pcity)) {
        found_palace++;
       }
       assert(found_palace <= 1);

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#9361) new function is_capital, Jason Dorje Short <=