Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2002:
[Freeciv-Dev] Re: [PATCH] get rid of floating point calculations (PR#130
Home

[Freeciv-Dev] Re: [PATCH] get rid of floating point calculations (PR#130

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Cc: bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: [PATCH] get rid of floating point calculations (PR#1309)
From: Markus Linnala <maage@xxxxxxxxx>
Date: Sun, 10 Mar 2002 09:47:07 -0800 (PST)

Get rid of floating point calculations, take 2, now it actually compiles.

diff -ur -X freeciv/diff_ignore freeciv/ai/advmilitary.c 
freeciv-cleanups/ai/advmilitary.c
--- freeciv/ai/advmilitary.c    Wed Mar  6 12:05:09 2002
+++ freeciv-cleanups/ai/advmilitary.c   Sun Mar 10 19:44:00 2002
@@ -59,7 +59,7 @@
   unit_list_iterate(map_get_tile(pcity->x, pcity->y)->units, punit)
     v = get_defense_power(punit) * punit->hp *
         (is_sailing_unit(punit) ? 1 : unit_type(punit)->firepower);
-    if (is_ground_unit(punit)) v *= 1.5;
+    if (is_ground_unit(punit)) v += v / 2;
     v /= 30;
     if (!igwall && city_got_citywalls(pcity) && is_ground_unit(punit)) {
       v *= l; v /= 10;
@@ -82,7 +82,7 @@
   int v;
   v = get_defense_power(punit) * punit->hp *
       (is_sailing_unit(punit) ? 1 : unit_type(punit)->firepower);
-  if (is_ground_unit(punit)) v *= 1.5;
+  if (is_ground_unit(punit)) v += v / 2;
   v /= 30;
   v *= v;
   if (!igwall && city_got_citywalls(pcity) && is_ground_unit(punit)) {
diff -ur -X freeciv/diff_ignore freeciv/ai/aiunit.c freeciv-cleanups/ai/aiunit.c
--- freeciv/ai/aiunit.c Wed Mar  6 07:27:57 2002
+++ freeciv-cleanups/ai/aiunit.c        Sun Mar 10 19:44:00 2002
@@ -1105,7 +1105,7 @@
                                     SINGLE_MOVE) * unit_types[d_type].hp;
     }
     d_val /= (unit_type(punit)->move_rate / SINGLE_MOVE);
-    if (unit_flag(punit, F_IGTER)) d_val /= 1.5;
+    if (unit_flag(punit, F_IGTER)) d_val -= d_val / 3;
     freelog(LOG_DEBUG,
            "%s@(%d,%d) looking for bodyguard, d_val=%d, my_val=%d",
            unit_type(punit)->name, punit->x, punit->y, d_val,
@@ -1555,7 +1555,7 @@
             n = ai_choose_defender_versus(acity, punit->type);
             v = get_virtual_defense_power(punit->type, n, acity->x, acity->y) *
                 unit_types[n].hp * unit_types[n].firepower *
-                (do_make_unit_veteran(acity, n) ? 1.5 : 1.0) / 30;
+                (do_make_unit_veteran(acity, n) ? 3 : 2) / 2 / 30;
             if (v * v >= d) { d = v * v; b = unit_types[n].build_cost + 40; }
           } /* let's hope this works! */
           if (!is_ground_unit(punit) && !is_heli_unit(punit) &&
diff -ur -X freeciv/diff_ignore freeciv/common/city.c 
freeciv-cleanups/common/city.c
--- freeciv/common/city.c       Fri Mar  8 19:06:23 2002
+++ freeciv-cleanups/common/city.c      Sun Mar 10 19:44:00 2002
@@ -1407,7 +1407,7 @@
     if (city_affected_by_wonder(pcity, B_HOOVER) ||
        city_got_building(pcity, B_POWER) ||
        city_got_building(pcity, B_HYDRO) ||
-       city_got_building(pcity, B_NUCLEAR)) tmp *= 1.5;
+       city_got_building(pcity, B_NUCLEAR)) tmp += tmp / 2;
   }
 
   pcity->shield_bonus = tmp + 100;
diff -ur -X freeciv/diff_ignore freeciv/common/combat.c 
freeciv-cleanups/common/combat.c
--- freeciv/common/combat.c     Fri Mar  8 16:23:36 2002
+++ freeciv-cleanups/common/combat.c    Sun Mar 10 19:44:28 2002
@@ -254,10 +254,7 @@
   int power;
 
   power = get_unit_type(type)->attack_strength * POWER_FACTOR;
-  if (veteran) {
-    /* Veterans get +50% bonus. */
-    power = (power * 3) / 2;
-  }
+  if (veteran) power += power / 2;
 
   if (!unit_type_flag(type, F_IGTIRED) && moves_left < SINGLE_MOVE) {
     power = (power * moves_left) / SINGLE_MOVE;
@@ -278,10 +275,7 @@
       || punit->type>=game.num_unit_types)
     abort();
   power = unit_type(punit)->defense_strength * POWER_FACTOR;
-  if (punit->veteran) {
-    power *= 3;
-    power /= 2;
-  }
+  if (punit->veteran) power += power / 2;
   terra=map_get_terrain(punit->x, punit->y);
   db = get_tile_type(terra)->defense_bonus;
   if (map_has_special(punit->x, punit->y, S_RIVER))
@@ -327,7 +321,7 @@
   if (map_has_special(x, y, S_FORTRESS) && !pcity)
     defensepower+=(defensepower*terrain_control.fortress_defense_bonus)/100;
   if (pcity && unit_types[d_type].move_type == LAND_MOVING)
-    defensepower*=1.5;
+    defensepower += defensepower / 2;
 
   return defensepower;
 }
@@ -374,7 +368,7 @@
   if (map_has_special(x, y, S_FORTRESS) && !pcity)
     defensepower+=(defensepower*terrain_control.fortress_defense_bonus)/100;
   if (pcity && unit_types[d_type].move_type == LAND_MOVING)
-    defensepower*=1.5;
+    defensepower += defensepower / 2;
 
   return defensepower;
 }
@@ -410,7 +404,7 @@
   if ((defender->activity == ACTIVITY_FORTIFIED || 
        map_get_city(defender->x, defender->y)) && 
       is_ground_unit(defender))
-    defensepower*=1.5;
+    defensepower += defensepower / 2;
 
   return defensepower;
 }


--
//Markus



[Prev in Thread] Current Thread [Next in Thread]