Author: sveinung
Date: Wed Oct 21 17:57:17 2015
New Revision: 30154

URL: http://svn.gna.org/viewcvs/freeciv?rev=30154&view=rev
Log:
Split disband unit from packet handling

Separate disbanding a unit (without reusing its shields) from handling the
order to do so in the unit_disband packet.

See patch #6448

Modified:
    trunk/server/unithand.c
    trunk/server/unithand.h
    trunk/server/unittools.c

Modified: trunk/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.c?rev=30154&r1=30153&r2=30154&view=diff
==============================================================================
--- trunk/server/unithand.c     (original)
+++ trunk/server/unithand.c     Wed Oct 21 17:57:17 2015
@@ -1945,20 +1945,37 @@
 }
 
 /**************************************************************************
-  Disband a unit.
-
-  No shields spent to build the unit is added to the city's shield stock
-  for the current production.
+  Handle an incoming packet ordering a unit to disband.
 **************************************************************************/
 void handle_unit_disband(struct player *pplayer, int unit_id)
 {
-  struct action *blocker;
   struct unit *punit = player_unit_by_number(pplayer, unit_id);
 
   if (NULL == punit) {
     /* Probably died or bribed. */
     log_verbose("handle_unit_disband() invalid unit %d", unit_id);
     return;
+  }
+
+  (void)do_unit_disband(pplayer, punit);
+}
+
+/**************************************************************************
+  Disband a unit.
+
+  No shields spent to build the unit is added to the shield stock of any
+  city even if the unit is located inside it.
+
+  Returns TRUE iff the action could be done, FALSE if it couldn't. Even if
+  this returns TRUE, the unit may have died during the action.
+**************************************************************************/
+bool do_unit_disband(struct player *pplayer, struct unit *punit)
+{
+  struct action *blocker;
+
+  if (!punit || !unit_alive(punit->id)) {
+    /* The actor is dead. */
+    return FALSE;
   }
 
   if (unit_has_type_flag(punit, UTYF_UNDISBANDABLE)) {
@@ -1967,7 +1984,7 @@
                   E_BAD_COMMAND, ftc_server,
                   _("%s refuses to disband!"),
                   unit_link(punit));
-    return;
+    return FALSE;
   }
 
   if ((blocker = action_blocks_disband(punit))) {
@@ -1977,10 +1994,13 @@
                   /* TRANS: ... Help Wonder ... */
                   _("Regular disband not allowed. Try %s in stead."),
                   action_get_ui_name(blocker->id));
-    return;
+    return FALSE;
   }
 
   wipe_unit(punit, ULR_DISBANDED, NULL);
+
+  /* The unit is now disbanded. */
+  return TRUE;
 }
 
 /**************************************************************************

Modified: trunk/server/unithand.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.h?rev=30154&r1=30153&r2=30154&view=diff
==============================================================================
--- trunk/server/unithand.h     (original)
+++ trunk/server/unithand.h     Wed Oct 21 17:57:17 2015
@@ -37,6 +37,8 @@
                          const char *name,
                          const enum gen_action action_type);
 
+bool do_unit_disband(struct player *pplayer, struct unit *punit);
+
 void illegal_action_msg(struct player *pplayer,
                         const enum event_type event,
                         struct unit *actor,

Modified: trunk/server/unittools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unittools.c?rev=30154&r1=30153&r2=30154&view=diff
==============================================================================
--- trunk/server/unittools.c    (original)
+++ trunk/server/unittools.c    Wed Oct 21 17:57:17 2015
@@ -3799,7 +3799,7 @@
   }
 
   /* All shields will be wasted. */
-  handle_unit_disband(owner, punit->id);
+  do_unit_disband(owner, punit);
 }
 
 /**************************************************************************


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

Reply via email to