Complete.Org: Mailing Lists: Archives: freeciv-dev: June 2006:
[Freeciv-Dev] Editor: allow to change homecity [Was: Re: (PR#18113) cara
Home

[Freeciv-Dev] Editor: allow to change homecity [Was: Re: (PR#18113) cara

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] Editor: allow to change homecity [Was: Re: (PR#18113) caravan with no homecity crashes server]
From: "Egor Vyscrebentsov" <evyscr@xxxxxxxxx>
Date: Wed, 28 Jun 2006 13:20:49 -0700
Reply-to: bugs@xxxxxxxxxxx

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

Good daytime!

On Mon, 26 Jun 2006 23:33:07 -0700
Per I. Mathisen wrote:

> >> If one load a .sav file which contain caravan with no homecity,
> >> server will crash next turn. Problem is that aicore caravan code
> >> assume that caravan always has homecity, and server does not check
> >> for this when load a game. Also, it seems to me that editor allows
>
> I think the best short-term solution is to allow changing homecity of 
> caravans in editor mode, so that scenario editing can add valid
> caravans, and delete with LOG_ERROR any caravans that do not have
> homecity on savegame loading. That way the scenario editing user will
> notice what is amiss and can fix it easily.

I think, that allowing changing homecity for any unit should be in
editor. So, I take it as first thing.

And first breakdown.

From common/unit.c:426

bool can_unit_change_homecity_to(const struct unit *punit,
                                 const struct city *pcity)
{
  /* Requirements to change homecity: 
   * 
   * 1. Homeless cities can't change homecity (this is a feature since 
   *    being homeless is a big benefit). 
   * 2. The unit must be inside the city it is rehoming to. 
   * 3. Of course you can only have your own cities as homecity. 
   * 4. You can't rehome to the current homecity. */
  return (punit && pcity
          && punit->homecity > 0
          && punit->tile->city
          && punit->tile->city->owner == punit->owner
          && punit->homecity != punit->tile->city->id);
}

"Any feature is a bug unless it can be turned off." I think that there
might be a situation when player have to give homeless unit a homecity
for some benefit. I /vote for removing this constraint.

BTW, aren't number 2 wrong (because we have no check for
punit->tile->city == pcity)? We have direct calls to this function (from
at least client/gui-gtk-2.0/citydlg.c)...

Anyway, simplest patch that allow to give homecity for such units in
edit mode is attached. (I don't check for unit to be inside city and
for equivalence of punit->tile->city and pcity, and don't planned to
add these checks.) Now it works only for units in city, but I hope to
upgrade behavior. (Or to wait until somebody make this upgrade-)

PS Comments are my weakest side... (since my english is terrible)

PPS Is there any docs/manuals on using editor?-) I'm shamed but I can't
understand many things, for example, how to switch between players while
making scenario (other than reconnect as another player.) If I
connected as global observer, I lose several important options (like
changing city production). If I make two connections, clients eat my
cpu and freeze (race?).

-- 
Thanks, evyscr

Index: common/unit.c
===================================================================
--- common/unit.c       (revision 12033)
+++ common/unit.c       (working copy)
@@ -435,12 +435,18 @@
    *    being homeless is a big benefit).
    * 2. The unit must be inside the city it is rehoming to.
    * 3. Of course you can only have your own cities as homecity.
-   * 4. You can't rehome to the current homecity. */
+   * 4. You can't rehome to the current homecity.
+   *
+   * This requirements, however, are ignored if game is in edit mode.
+   * (Except number 3 and 4.) */
   return (punit && pcity
-         && punit->homecity > 0
-         && punit->tile->city
-         && punit->tile->city->owner == punit->owner
-         && punit->homecity != punit->tile->city->id);
+         && ((punit->homecity > 0
+              && punit->tile->city
+              && punit->tile->city->owner == punit->owner
+              && punit->homecity != punit->tile->city->id)
+             || (game.info.is_edit_mode
+                 && pcity->owner == punit->owner
+                 && punit->homecity != pcity->id)));
 }
 
 /**************************************************************************

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