Author: sveinung
Date: Tue Aug 16 19:54:48 2016
New Revision: 33627

URL: http://svn.gna.org/viewcvs/freeciv?rev=33627&view=rev
Log:
Stop handling bombardment in unit_versus_unit().

Factor out bombardment handling from the regular attack handling in
unit_versus_unit(). Put it in the new function unit_bombs_unit().

See patch #7603

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

Modified: trunk/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.c?rev=33627&r1=33626&r2=33627&view=diff
==============================================================================
--- trunk/server/unithand.c     (original)
+++ trunk/server/unithand.c     Tue Aug 16 19:54:48 2016
@@ -2896,7 +2896,7 @@
          * defenders when bombarding */
       }
 
-      unit_versus_unit(punit, pdefender, TRUE, &att_hp, &def_hp);
+      unit_bombs_unit(punit, pdefender, &att_hp, &def_hp);
 
       see_combat(punit, pdefender);
 
@@ -3129,7 +3129,7 @@
 
   old_unit_vet = punit->veteran;
   old_defender_vet = pdefender->veteran;
-  unit_versus_unit(punit, pdefender, FALSE, &att_hp, &def_hp);
+  unit_versus_unit(punit, pdefender, &att_hp, &def_hp);
 
   if ((att_hp <= 0 || uclass_has_flag(unit_class_get(punit), UCF_MISSILE))
       && unit_transported(punit)) {

Modified: trunk/server/unittools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unittools.c?rev=33627&r1=33626&r2=33627&view=diff
==============================================================================
--- trunk/server/unittools.c    (original)
+++ trunk/server/unittools.c    Tue Aug 16 19:54:48 2016
@@ -246,14 +246,12 @@
 /**************************************************************************
   This is the basic unit versus unit combat routine.
   1) ALOT of modifiers bonuses etc is added to the 2 units rates.
-  2) If the attack is a bombardment, do rate attacks and don't kill the
-     defender, then return.
-  3) the combat loop, which continues until one of the units are dead
-  4) the aftermath, the loser (and potentially the stack which is below it)
+  2) the combat loop, which continues until one of the units are dead
+  3) the aftermath, the loser (and potentially the stack which is below it)
      is wiped, and the winner gets a chance of gaining veteran status
 **************************************************************************/
 void unit_versus_unit(struct unit *attacker, struct unit *defender,
-                     bool bombard, int *att_hp, int *def_hp)
+                      int *att_hp, int *def_hp)
 {
   int attackpower = get_total_attack_power(attacker, defender);
   int defensepower = get_total_defense_power(attacker, defender);
@@ -273,23 +271,6 @@
   plr1->last_war_action = game.info.turn;
   plr2->last_war_action = game.info.turn;
 
-  if (bombard) {
-    int i;
-    int rate = unit_type_get(attacker)->bombard_rate;
-
-    for (i = 0; i < rate; i++) {
-      if (fc_rand(attackpower+defensepower) >= defensepower) {
-        *def_hp -= attack_firepower;
-      }
-    }
-
-    /* Don't kill the target. */
-    if (*def_hp <= 0) {
-      *def_hp = 1;
-    }
-    return;
-  }
-
   if (attackpower == 0) {
     *att_hp = 0; 
   } else if (defensepower == 0) {
@@ -307,6 +288,47 @@
   }
   if (*def_hp < 0) {
     *def_hp = 0;
+  }
+}
+
+/**************************************************************************
+  This is the basic unit versus unit classic bombardment routine.
+  1) ALOT of modifiers bonuses etc is added to the 2 units rates.
+  2) Do rate attacks and don't kill the defender, then return.
+**************************************************************************/
+void unit_bombs_unit(struct unit *attacker, struct unit *defender,
+                     int *att_hp, int *def_hp)
+{
+  int i;
+  int rate = unit_type_get(attacker)->bombard_rate;
+
+  int attackpower = get_total_attack_power(attacker, defender);
+  int defensepower = get_total_defense_power(attacker, defender);
+  int attack_firepower, defense_firepower;
+  struct player *plr1 = unit_owner(attacker);
+  struct player *plr2 = unit_owner(defender);
+
+  *att_hp = attacker->hp;
+  *def_hp = defender->hp;
+  get_modified_firepower(attacker, defender,
+                         &attack_firepower, &defense_firepower);
+
+  log_verbose("attack:%d, defense:%d, attack firepower:%d, "
+              "defense firepower:%d", attackpower, defensepower,
+              attack_firepower, defense_firepower);
+
+  plr1->last_war_action = game.info.turn;
+  plr2->last_war_action = game.info.turn;
+
+  for (i = 0; i < rate; i++) {
+    if (fc_rand(attackpower + defensepower) >= defensepower) {
+      *def_hp -= attack_firepower;
+    }
+  }
+
+  /* Don't kill the target. */
+  if (*def_hp <= 0) {
+    *def_hp = 1;
   }
 }
 

Modified: trunk/server/unittools.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unittools.h?rev=33627&r1=33626&r2=33627&view=diff
==============================================================================
--- trunk/server/unittools.h    (original)
+++ trunk/server/unittools.h    Tue Aug 16 19:54:48 2016
@@ -77,7 +77,9 @@
 bool maybe_make_veteran(struct unit *punit);
 void notify_unit_experience(struct unit *punit);
 void unit_versus_unit(struct unit *attacker, struct unit *defender,
-                      bool bombard, int *att_hp, int *def_hp);
+                      int *att_hp, int *def_hp);
+void unit_bombs_unit(struct unit *attacker, struct unit *defender,
+                     int *att_hp, int *def_hp);
 void combat_veterans(struct unit *attacker, struct unit *defender);
 
 /* move check related */


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

Reply via email to