Author: sveinung
Date: Mon Jun 13 02:14:56 2016
New Revision: 32843

URL: http://svn.gna.org/viewcvs/freeciv?rev=32843&view=rev
Log:
Split regular attacks from unit_move_handling().

Put the code responsible for performing a regular attack against the units
at the target tile in the new function do_attack().

See patch #7257

Modified:
    trunk/server/unithand.c

Modified: trunk/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.c?rev=32843&r1=32842&r2=32843&view=diff
==============================================================================
--- trunk/server/unithand.c     (original)
+++ trunk/server/unithand.c     Mon Jun 13 02:14:56 2016
@@ -185,6 +185,7 @@
 static bool do_unit_upgrade(struct player *pplayer,
                             struct unit *punit, struct city *pcity,
                             enum action_requester ordered_by);
+static bool do_attack(struct unit *actor_unit, struct tile *target_tile);
 
 /**************************************************************************
  Upgrade all units of a given type.
@@ -3181,6 +3182,29 @@
 }
 
 /**************************************************************************
+  Do a "regular" attack.
+
+  This function assumes the attack is legal. The calling function should
+  have already made all necessary checks.
+
+  Returns TRUE iff action could be done, FALSE if it couldn't. Even if
+  this returns TRUE, unit may have died during the action.
+**************************************************************************/
+static bool do_attack(struct unit *actor_unit, struct tile *target_tile)
+{
+  struct unit *victim;
+
+  victim = get_defender(actor_unit, target_tile);
+
+  if (victim) {
+    unit_attack_handling(actor_unit, victim);
+    return TRUE;
+  } else {
+    return FALSE;
+  }
+}
+
+/**************************************************************************
   see also aiunit could_unit_move_to_tile()
 **************************************************************************/
 static bool can_unit_move_to_tile_with_notify(struct unit *punit,
@@ -3453,10 +3477,8 @@
     }
 
     /* The attack is legal wrt the alliances */
-    victim = get_defender(punit, pdesttile);
-
-    if (victim) {
-      unit_attack_handling(punit, victim);
+
+    if (do_attack(punit, pdesttile)) {
       return TRUE;
     } else {
       fc_assert_ret_val(is_enemy_city_tile(pdesttile, pplayer) != NULL,


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

Reply via email to