Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2004:
[Freeciv-Dev] Re: (PR#11249) freeciv-2.0.0-beta4: Segmentation fault aft
Home

[Freeciv-Dev] Re: (PR#11249) freeciv-2.0.0-beta4: Segmentation fault aft

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: anfi@xxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#11249) freeciv-2.0.0-beta4: Segmentation fault after diplomatic action against displomat
From: "Marko Lindqvist" <marko.lindqvist@xxxxxxxxxxx>
Date: Sat, 18 Dec 2004 04:15:01 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=11249 >


  Attached, untested, patch avoids using results from division of zero 
by zero. Can you test if this helps?


  - ML

diff -Nurd -X.diff_ignore freeciv/server/diplomats.c freeciv/server/diplomats.c
--- freeciv/server/diplomats.c  2004-12-18 13:27:43.968750000 +0200
+++ freeciv/server/diplomats.c  2004-12-18 14:15:46.875000000 +0200
@@ -1414,6 +1414,7 @@
   struct city *capital;
   int dist;
   int default_hp = unit_type(punit)->hp;
+  float hp_fraction;
 
   cost = unit_owner(punit)->economic.gold + 750;
   capital = find_palace(unit_owner(punit));
@@ -1435,11 +1436,17 @@
 
   /* Cost now contains the basic bribe cost.  We now reduce it by:
 
-     cost = basecost/2 + basecost/2 * damage/hp
+     cost = basecost/2 + basecost/2 * current_hp/max_hp
      
    */
+
+  if (default_hp == 0) {
+    hp_fraction = 1;
+  } else {
+    hp_fraction = (float)punit->hp/(float)default_hp;
+  }
   
-  cost = (int)((float)cost/(float)2 + ((float)punit->hp/(float)default_hp) * 
((float)cost/(float)2));
+  cost = (int)((float)cost/(float)2 + hp_fraction * ((float)cost/(float)2));
   
   return cost;
 }

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] Re: (PR#11249) freeciv-2.0.0-beta4: Segmentation fault after diplomatic action against displomat, Marko Lindqvist <=