Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2005:
[Freeciv-Dev] Re: (PR#13510) disbanded-city settlers starts in wrong pla
Home

[Freeciv-Dev] Re: (PR#13510) disbanded-city settlers starts in wrong pla

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jdorje@xxxxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#13510) disbanded-city settlers starts in wrong place
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Thu, 21 Jul 2005 12:10:57 -0700
Reply-to: bugs@xxxxxxxxxxx

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

On Thu, 21 Jul 2005, Jason Short wrote:
> I built a settler by disbanding my city.Instead of being created on
> the spot of the old city the settler is created on the tile of the new
> homecity it took.

Patch attached (untested) - fixteleport1.diff. Also attached is an equally
untested cleanup of disband_city(), which allows you to disband your last
city, if you really want to.

   - Per

Index: server/citytools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/citytools.c,v
retrieving revision 1.335
diff -u -r1.335 citytools.c
--- server/citytools.c  18 Jul 2005 22:46:28 -0000      1.335
+++ server/citytools.c  21 Jul 2005 19:10:15 -0000
@@ -508,6 +508,8 @@
       notify_player(from_player, _("Changed homecity of %s to %s."),
                    unit_name(punit->type), tocity->name);
     }
+    real_unit_change_homecity(punit, tocity, FALSE);
+    return;
   } else {
     struct city *in_city = tile_get_city(punit->tile);
     if (in_city) {
@@ -541,7 +543,7 @@
       return;
     }
   }
-  real_unit_change_homecity(punit, tocity);
+  real_unit_change_homecity(punit, tocity, TRUE);
 }
 
 /*********************************************************************
Index: server/unithand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unithand.c,v
retrieving revision 1.344
diff -u -r1.344 unithand.c
--- server/unithand.c   21 Jul 2005 08:07:19 -0000      1.344
+++ server/unithand.c   21 Jul 2005 19:10:21 -0000
@@ -264,13 +264,14 @@
   in its new homecity, it will be moved there. This new homecity must
   be valid for this unit.
 **************************************************************************/
-void real_unit_change_homecity(struct unit *punit, struct city *new_pcity)
+void real_unit_change_homecity(struct unit *punit, struct city *new_pcity,
+                               bool do_move_unit)
 {
   struct city *old_pcity = find_city_by_id(punit->homecity);
   struct player *old_owner = unit_owner(punit);
   struct player *new_owner = city_owner(new_pcity);
 
-  if (!same_pos(punit->tile, new_pcity->tile)) {
+  if (do_move_unit && !same_pos(punit->tile, new_pcity->tile)) {
     assert(can_unit_exist_at_tile(punit, new_pcity->tile));
     move_unit(punit, new_pcity->tile, 0); /* teleport to location */
   }
@@ -335,7 +336,7 @@
             new_pcity->tile->y);
     return;
   }
-  real_unit_change_homecity(punit, new_pcity);
+  real_unit_change_homecity(punit, new_pcity, FALSE);
 }
 
 /**************************************************************************
Index: server/unithand.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unithand.h,v
retrieving revision 1.38
diff -u -r1.38 unithand.h
--- server/unithand.h   1 May 2005 05:42:04 -0000       1.38
+++ server/unithand.h   21 Jul 2005 19:10:21 -0000
@@ -22,6 +22,7 @@
                             bool igzoc, bool move_diplomat_city);
 void handle_unit_activity_request(struct unit *punit, 
                                  enum unit_activity new_activity);
-void real_unit_change_homecity(struct unit *punit, struct city *new_pcity);
+void real_unit_change_homecity(struct unit *punit, struct city *new_pcity,
+                               bool move_unit);
 
 #endif  /* FC__UNITHAND_H */
Index: server/cityturn.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityturn.c,v
retrieving revision 1.323
diff -u -r1.323 cityturn.c
--- server/cityturn.c   4 Jul 2005 17:48:38 -0000       1.323
+++ server/cityturn.c   21 Jul 2005 19:06:47 -0000
@@ -1529,40 +1529,29 @@
 {
   struct player *pplayer = city_owner(pcity);
   struct tile *ptile = pcity->tile;
-  struct city *rcity=NULL;
-  struct unit_type *utype = get_unit_type(pcity->currently_building);
+  struct city *rcity = NULL;
+  int cid = 0, uid = pcity->currently_building;
 
   /* find closest city other than pcity */
   rcity = find_closest_owned_city(pplayer, ptile, FALSE, pcity);
 
-  if (!rcity) {
-    /* What should we do when we try to disband our only city? */
-    notify_player_ex(pplayer, ptile, E_CITY_CANTBUILD,
-                    _("%s can't build %s yet, "
-                    "and we can't disband our only city."),
-                    pcity->name, unit_name(pcity->currently_building));
-    script_signal_emit("unit_cant_be_built", 3,
-                      API_TYPE_UNIT_TYPE, utype,
-                      API_TYPE_CITY, pcity,
-                      API_TYPE_STRING, "pop_cost");
-    return FALSE;
+  if (rcity) {
+    /* Unless we are disbanding our only city, set support to nearest
+     * other city. */
+    cid = rcity->id;
   }
 
-  (void) create_unit(pplayer, ptile, pcity->currently_building,
-                    do_make_unit_veteran(pcity, pcity->currently_building),
-                    pcity->id, 0);
-
-  /* Shift all the units supported by pcity (including the new unit)
-   * to rcity.  transfer_city_units does not make sure no units are
-   * left floating without a transport, but since all units are
-   * transferred this is not a problem. */
+  /* Shift all the units supported by pcity to rcity. */
   transfer_city_units(pplayer, pplayer, pcity->units_supported, rcity, 
                       pcity, -1, TRUE);
 
+  (void) create_unit(pplayer, ptile, uid, do_make_unit_veteran(pcity, uid),
+                    cid, 0);
+
   notify_player_ex(pplayer, ptile, E_UNIT_BUILT,
                   /* TRANS: Settler production leads to disbanded city. */
-                  _("%s is disbanded into %s."), 
-                  pcity->name, unit_types[pcity->currently_building].name);
+                  _("%s is disbanded into %s."), pcity->name, 
+                   unit_types[uid].name);
   gamelog(GAMELOG_DISBANDCITY, pcity);
 
   remove_city(pcity);

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] Re: (PR#13510) disbanded-city settlers starts in wrong place, Per I. Mathisen <=