Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2002:
[Freeciv-Dev] Re: (PR#2280) Transfer or city with allied units inside --
Home

[Freeciv-Dev] Re: (PR#2280) Transfer or city with allied units inside --

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#2280) Transfer or city with allied units inside --> core dump
From: "Davide Pagnin via RT" <rt@xxxxxxxxxxxxxx>
Date: Sat, 9 Nov 2002 09:11:14 -0800
Reply-to: rt@xxxxxxxxxxxxxx

I have worked a little bit on this problem.

I have decided to be as less intrusive as I can, but I have to say that
resolve_stack and related functions are a real big mess!

To solve the problem in a clean way I've decided to patch
"transfer_city_units" function in citytools.c.

This function is used only 2 time in the code.

Anyway my change (but, please check) seems to me as general as the use
of the function require.

In the event that we are transferring units inside a city to another
owner, we apply the old code.
In the event that the units inside the city are owned by a third player,
not allied with the new owner of the city, its units are teleported to
the nearest city.
In the event (Which IMHO can't happen, but I don't know...) that
find_closest_owned_cities return NULL, then the unit is destroyed.
(This same choice and code is used in the resolve_unit_stack function
which I have used as model)

NOTE for Per and other maintainers:
This is a civserver core fix, and deserve to be applied to beta, IMHO.

Review (&& Commit?)

        Ciao, Davide

P.S. The attached diff is made against actual S1_14 branch code.

diff -urN -Xfreeciv/diff_ignore freeciv/server/citytools.c 
freeciv-beta/server/citytools.c
--- freeciv/server/citytools.c  Mon Sep 23 17:00:56 2002
+++ freeciv-beta/server/citytools.c     Sat Nov  9 18:03:30 2002
@@ -620,6 +620,7 @@
 {
   int x = pcity->x;
   int y = pcity->y;
+  struct city *vcity;
 
   /* Transfer enemy units in the city to the new owner.
      Only relevant if we are transfering to another player. */
@@ -631,6 +632,16 @@
        wipe_unit_safe(vunit, &myiter);
        unit_list_unlink(units, vunit);
       }
+      else if (!pplayers_allied(pplayer, unit_owner(vunit))) {
+       vcity = find_closest_owned_city(unit_owner(vunit), x, y,
+                       is_sailing_unit(vunit), NULL);
+       if (vcity) {
+          (void) teleport_unit_to_city(vunit, vcity, 0, verbose);
+       }
+       else {
+          disband_stack_conflict_unit(vunit, verbose);
+       }
+      }
     } unit_list_iterate_end;
   }
 
diff -urN -Xfreeciv/diff_ignore freeciv/server/unittools.c 
freeciv-beta/server/unittools.c
--- freeciv/server/unittools.c  Sun Sep 29 01:00:51 2002
+++ freeciv-beta/server/unittools.c     Sat Nov  9 17:13:45 2002
@@ -1412,7 +1412,7 @@
 /**************************************************************************
 Disband given unit because of a stack conflict.
 **************************************************************************/
-static void disband_stack_conflict_unit(struct unit *punit, bool verbose)
+void disband_stack_conflict_unit(struct unit *punit, bool verbose)
 {
   freelog(LOG_VERBOSE, "Disbanded %s's %s at (%d, %d)",
          unit_owner(punit)->name, unit_name(punit->type),
diff -urN -Xfreeciv/diff_ignore freeciv/server/unittools.h 
freeciv-beta/server/unittools.h
--- freeciv/server/unittools.h  Wed Mar 13 10:56:27 2002
+++ freeciv-beta/server/unittools.h     Sat Nov  9 17:04:39 2002
@@ -43,6 +43,7 @@
 bool teleport_unit_to_city(struct unit *punit, struct city *pcity, int 
move_cost,
                          bool verbose);
 void resolve_unit_stack(int x, int y, bool verbose);
+void disband_stack_conflict_unit(struct unit *punit, bool verbose);
 int get_watchtower_vision(struct unit *punit);
 bool unit_profits_of_watchtower(struct unit *punit);
 

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