Author: sveinung
Date: Wed Dec  2 22:44:08 2015
New Revision: 30848

URL: http://svn.gna.org/viewcvs/freeciv?rev=30848&view=rev
Log:
Add a server unit removal call back

See patch #6645

Modified:
    trunk/common/unit.c
    trunk/common/unit.h
    trunk/server/unittools.c
    trunk/server/unittools.h

Modified: trunk/common/unit.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/unit.c?rev=30848&r1=30847&r2=30848&view=diff
==============================================================================
--- trunk/common/unit.c (original)
+++ trunk/common/unit.c Wed Dec  2 22:44:08 2015
@@ -1756,6 +1756,8 @@
     punit->server.birth_turn = game.info.turn;
 
     punit->server.dying = FALSE;
+
+    punit->server.removal_callback = NULL;
 
     punit->server.ord_map = 0;
     punit->server.ord_city = 0;

Modified: trunk/common/unit.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/unit.h?rev=30848&r1=30847&r2=30848&view=diff
==============================================================================
--- trunk/common/unit.h (original)
+++ trunk/common/unit.h Wed Dec  2 22:44:08 2015
@@ -212,6 +212,9 @@
 
       /* The unit is in the process of dying. */
       bool dying;
+
+      /* Call back to run on unit removal. */
+      void (*removal_callback)(struct unit *punit);
     } server;
   };
 };

Modified: trunk/server/unittools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unittools.c?rev=30848&r1=30847&r2=30848&view=diff
==============================================================================
--- trunk/server/unittools.c    (original)
+++ trunk/server/unittools.c    Wed Dec  2 22:44:08 2015
@@ -1576,6 +1576,28 @@
   return punit;
 }
 
+/**************************************************************************
+  Set the call back to run when the server removes the unit.
+**************************************************************************/
+void unit_set_removal_callback(struct unit *punit,
+                               void (*callback)(struct unit *punit))
+{
+  /* Tried to overwrite another call back. If this assertion is triggered
+   * in a case where two call back are needed it may be time to support
+   * more than one unit removal call back at a time. */
+  fc_assert_ret(punit->server.removal_callback == NULL);
+
+  punit->server.removal_callback = callback;
+}
+
+/**************************************************************************
+  Remove the call back so nothing runs when the server removes the unit.
+**************************************************************************/
+void unit_unset_removal_callback(struct unit *punit)
+{
+  punit->server.removal_callback = NULL;
+}
+
 /****************************************************************************
   We remove the unit and see if it's disappearance has affected the homecity
   and the city it was in.
@@ -1636,6 +1658,11 @@
   if (punit->server.moving != NULL) {
     /* Do not care of this unit for running moves. */
     punit->server.moving->punit = NULL;
+  }
+
+  if (punit->server.removal_callback != NULL) {
+    /* Run the unit removal call back. */
+    punit->server.removal_callback(punit);
   }
 
   /* check if this unit had UTYF_GAMELOSS flag */

Modified: trunk/server/unittools.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unittools.h?rev=30848&r1=30847&r2=30848&view=diff
==============================================================================
--- trunk/server/unittools.h    (original)
+++ trunk/server/unittools.h    Wed Dec  2 22:44:08 2015
@@ -133,6 +133,10 @@
                                int homecity, enum unit_loss_reason reason)
                                fc__warn_unused_result;
 
+void unit_set_removal_callback(struct unit *punit,
+                               void (*callback)(struct unit *punit));
+void unit_unset_removal_callback(struct unit *punit);
+
 /* sending to client */
 void package_unit(struct unit *punit, struct packet_unit_info *packet);
 void package_short_unit(struct unit *punit,


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

Reply via email to