Author: sveinung
Date: Sun Jan 11 01:50:10 2015
New Revision: 27613

URL: http://svn.gna.org/viewcvs/freeciv?rev=27613&view=rev
Log:
Server: Put the unit capture handling code in a separate function.

See patch #5686

Modified:
    trunk/server/unithand.c

Modified: trunk/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.c?rev=27613&r1=27612&r2=27613&view=diff
==============================================================================
--- trunk/server/unithand.c     (original)
+++ trunk/server/unithand.c     Sun Jan 11 01:50:10 2015
@@ -208,6 +208,55 @@
 }
 
 /**************************************************************************
+  Capture all the units at pdesttile using punit.
+**************************************************************************/
+static void do_capture_units(struct player *pplayer,
+                             struct unit *punit,
+                             struct tile *pdesttile)
+{
+  char capturer_link[MAX_LEN_LINK];
+  const char *capturer_nation = nation_plural_for_player(pplayer);
+
+  /* N.B: unit_link() always returns the same pointer. */
+  sz_strlcpy(capturer_link, unit_link(punit));
+
+  unit_list_iterate(pdesttile->units, to_capture) {
+    struct player *uplayer = unit_owner(to_capture);
+    const char *victim_link;
+
+    unit_owner(to_capture)->score.units_lost++;
+    to_capture = unit_change_owner(to_capture, pplayer,
+                                   (game.server.homecaughtunits
+                                    ? punit->homecity
+                                    : IDENTITY_NUMBER_ZERO),
+                                   ULR_CAPTURED);
+    /* As unit_change_owner() currently remove the old unit and
+       * replace by a new one (with a new id), we want to make link to
+       * the new unit. */
+    victim_link = unit_link(to_capture);
+
+    /* Notify players */
+    notify_player(pplayer, pdesttile, E_MY_DIPLOMAT_BRIBE, ftc_server,
+                  /* TRANS: <unit> ... <unit> */
+                  _("Your %s succeeded in capturing the %s."),
+                  capturer_link, victim_link);
+    notify_player(uplayer, pdesttile,
+                  E_ENEMY_DIPLOMAT_BRIBE, ftc_server,
+                  /* TRANS: <unit> ... <Poles> */
+                  _("Your %s was captured by the %s."),
+                  victim_link, capturer_nation);
+  } unit_list_iterate_end;
+
+  /* Subtract movement point from capturer */
+  punit->moves_left -= SINGLE_MOVE;
+  if (punit->moves_left < 0) {
+    punit->moves_left = 0;
+  }
+
+  send_unit_info(NULL, punit);
+}
+
+/**************************************************************************
   Returns TRUE iff, from the point of view of the owner of the actor unit,
   it looks like the actor unit may be able to perform a non action
   enabler controlled action against a unit or city on the target_tile by
@@ -1961,45 +2010,7 @@
       } unit_list_iterate_end;
 
       if (capture_possible) {
-        char capturer_link[MAX_LEN_LINK];
-        const char *capturer_nation = nation_plural_for_player(pplayer);
-
-        /* N.B: unit_link() always returns the same pointer. */
-        sz_strlcpy(capturer_link, unit_link(punit));
-
-        unit_list_iterate(pdesttile->units, to_capture) {
-          struct player *uplayer = unit_owner(to_capture);
-          const char *victim_link;
-
-          unit_owner(to_capture)->score.units_lost++;
-          to_capture = unit_change_owner(to_capture, pplayer,
-                                         (game.server.homecaughtunits
-                                          ? punit->homecity
-                                          : IDENTITY_NUMBER_ZERO),
-                                         ULR_CAPTURED);
-          /* As unit_change_owner() currently remove the old unit and
-           * replace by a new one (with a new id), we want to make link to
-           * the new unit. */
-          victim_link = unit_link(to_capture);
-
-          /* Notify players */
-          notify_player(pplayer, pdesttile, E_MY_DIPLOMAT_BRIBE, ftc_server,
-                        /* TRANS: <unit> ... <unit> */
-                        _("Your %s succeeded in capturing the %s."),
-                        capturer_link, victim_link);
-          notify_player(uplayer, pdesttile,
-                        E_ENEMY_DIPLOMAT_BRIBE, ftc_server,
-                        /* TRANS: <unit> ... <Poles> */
-                        _("Your %s was captured by the %s."),
-                        victim_link, capturer_nation);
-        } unit_list_iterate_end;
-
-        /* Subtract movement point from capturer */
-        punit->moves_left -= SINGLE_MOVE;
-        if (punit->moves_left < 0) {
-          punit->moves_left = 0;
-        }
-        send_unit_info(NULL, punit);
+        do_capture_units(pplayer, punit, pdesttile);
 
         return TRUE;
       }


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

Reply via email to