Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2002:
[Freeciv-Dev] [PATCH] try to cleanup assess_danger (PR#1321)
Home

[Freeciv-Dev] [PATCH] try to cleanup assess_danger (PR#1321)

[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] [PATCH] try to cleanup assess_danger (PR#1321)
From: Markus Linnala <maage@xxxxxxxxx>
Date: Sun, 10 Mar 2002 09:11:47 -0800 (PST)

Change variable names to what they mean.

diff -ur -X freeciv/diff_ignore freeciv/ai/advmilitary.c 
freeciv-cleanup-assess-danger-1/ai/advmilitary.c
--- freeciv/ai/advmilitary.c    Wed Mar  6 12:05:09 2002
+++ freeciv-cleanup-assess-danger-1/ai/advmilitary.c    Sun Mar 10 19:08:28 2002
@@ -228,15 +228,14 @@
 {
   int i, danger = 0, v, dist, m;
   Unit_Type_id utype;
-  int danger2 = 0; /* linear for walls */
-  int danger3 = 0; /* linear for coastal */
-  int danger4 = 0; /* linear for SAM */
-  int danger5 = 0; /* linear for SDI */
+  int danger_wall = 0; /* linear for walls */
+  int danger_coastal = 0; /* linear for coastal */
+  int danger_sam = 0; /* linear for SAM */
+  int danger_sdi = 0; /* linear for SDI */
   struct player *pplayer;
   bool pikemen = FALSE;
-  bool diplomat = FALSE; /* TRUE mean that this town can defend
-                    * against diplomats or spies */
-  int urgency = 0;
+  bool def_against_diplomat = FALSE; /* TRUE mean that this town can defend
+                                     * against diplomats or spies */
   bool igwall;
   int badmojo = 0;
   int boatspeed;
@@ -252,10 +251,11 @@
 
   pcity->ai.grave_danger = 0;
   pcity->ai.diplomat_threat = FALSE;
+  pcity->ai.urgency = 0; /* need to cache this for bodyguards now -- Syela */
 
   unit_list_iterate(map_get_tile(pcity->x, pcity->y)->units, punit)
     if (unit_flag(punit, F_PIKEMEN)) pikemen = TRUE;
-    if (unit_flag(punit, F_DIPLOMAT)) diplomat = TRUE;
+    if (unit_flag(punit, F_DIPLOMAT)) def_against_diplomat = TRUE;
   unit_list_iterate_end;
 
   players_iterate(aplayer) {
@@ -286,7 +286,7 @@
           igwall = unit_really_ignores_citywalls(funit);
           if ((is_ground_unit(funit) && v != 0) ||
               (is_ground_units_transport(funit))) {
-            if (dist <= m * 3) urgency++;
+            if (dist <= m * 3) pcity->ai.urgency++;
             if (dist <= m) pcity->ai.grave_danger++;
 /* NOTE: This should actually implement grave_danger, which is supposed
 to be a feedback-sensitive formula for immediate danger.  I'm having
@@ -304,14 +304,14 @@
           }
 
         if (unit_flag(funit, F_DIPLOMAT) && (dist <= 2 * m)) 
-            pcity->ai.diplomat_threat = !diplomat;
+            pcity->ai.diplomat_threat = !def_against_diplomat;
 
           v *= v;
 
-          if (!igwall) danger2 += v * m / dist;
-          else if (is_sailing_unit(funit)) danger3 += v * m / dist;
-          else if (is_air_unit(funit) && !unit_flag(funit, F_NUCLEAR)) danger4 
+= v * m / dist;
-          if (unit_flag(funit, F_MISSILE)) danger5 += v * m / MAX(m, dist);
+          if (!igwall) danger_wall += v * m / dist;
+          else if (is_sailing_unit(funit)) danger_coastal += v * m / dist;
+          else if (is_air_unit(funit) && !unit_flag(funit, F_NUCLEAR)) 
danger_sam += v * m / dist;
+          if (unit_flag(funit, F_MISSILE)) danger_sdi += v * m / MAX(m, dist);
           if (!unit_flag(funit, F_NUCLEAR)) { /* only SDI helps against 
NUCLEAR */
             v = dangerfunct(v, m, dist);
             danger += v;
@@ -328,7 +328,7 @@
           
         if ((is_ground_unit(punit) && v != 0) ||
             (is_ground_units_transport(punit))) {
-          if (dist <= m * 3) urgency++;
+          if (dist <= m * 3) pcity->ai.urgency++;
           if (dist <= m) pcity->ai.grave_danger++;
 /* NOTE: This should actually implement grave_danger, which is supposed
 to be a feedback-sensitive formula for immediate danger.  I'm having
@@ -346,14 +346,14 @@
         }
 
         if (unit_flag(punit, F_DIPLOMAT) && (dist <= 2 * m))
-            pcity->ai.diplomat_threat = !diplomat;
+            pcity->ai.diplomat_threat = !def_against_diplomat;
 
         v *= v;
 
-        if (!igwall) danger2 += v * m / dist;
-        else if (is_sailing_unit(punit)) danger3 += v * m / dist;
-        else if (is_air_unit(punit) && !unit_flag(punit, F_NUCLEAR)) danger4 
+= v * m / dist;
-        if (unit_flag(punit, F_MISSILE)) danger5 += v * m / MAX(m, dist);
+        if (!igwall) danger_wall += v * m / dist;
+        else if (is_sailing_unit(punit)) danger_coastal += v * m / dist;
+        else if (is_air_unit(punit) && !unit_flag(punit, F_NUCLEAR)) 
danger_sam += v * m / dist;
+        if (unit_flag(punit, F_MISSILE)) danger_sdi += v * m / MAX(m, dist);
         if (!unit_flag(punit, F_NUCLEAR)) { /* only SDI helps against NUCLEAR 
*/
           v = dangerfunct(v, m, dist);
           danger += v;
@@ -370,64 +370,63 @@
   if (danger < 0 || danger > 1<<24) /* I hope never to see this! */
     freelog(LOG_ERROR, "Dangerous danger (%d) in %s.  Beware of overflow.",
            danger, pcity->name);
-  if (danger2 < 0 || danger2 > 1<<24) /* I hope never to see this! */
-    freelog(LOG_ERROR, "Dangerous danger2 (%d) in %s.  Beware of overflow.",
-           danger2, pcity->name);
-  if (danger3 < 0 || danger3 > 1<<24) /* I hope never to see this! */
-    freelog(LOG_ERROR, "Dangerous danger3 (%d) in %s.  Beware of overflow.",
-           danger3, pcity->name);
-  if (danger4 < 0 || danger4 > 1<<24) /* I hope never to see this! */
-    freelog(LOG_ERROR, "Dangerous danger4 (%d) in %s.  Beware of overflow.",
-           danger4, pcity->name);
-  if (danger5 < 0 || danger5 > 1<<24) /* I hope never to see this! */
-    freelog(LOG_ERROR, "Dangerous danger5 (%d) in %s.  Beware of overflow.",
-           danger5, pcity->name);
+  if (danger_wall < 0 || danger_wall > 1<<24) /* I hope never to see this! */
+    freelog(LOG_ERROR, "Dangerous danger_wall (%d) in %s.  Beware of 
overflow.",
+           danger_wall, pcity->name);
+  if (danger_coastal < 0 || danger_coastal > 1<<24) /* I hope never to see 
this! */
+    freelog(LOG_ERROR, "Dangerous danger_coastal (%d) in %s.  Beware of 
overflow.",
+           danger_coastal, pcity->name);
+  if (danger_sam < 0 || danger_sam > 1<<24) /* I hope never to see this! */
+    freelog(LOG_ERROR, "Dangerous danger_sam (%d) in %s.  Beware of overflow.",
+           danger_sam, pcity->name);
+  if (danger_sdi < 0 || danger_sdi > 1<<24) /* I hope never to see this! */
+    freelog(LOG_ERROR, "Dangerous danger_sdi (%d) in %s.  Beware of overflow.",
+           danger_sdi, pcity->name);
   if (pcity->ai.grave_danger != 0)
-    urgency += 10; /* really, REALLY urgent to defend */
+    pcity->ai.urgency += 10; /* really, REALLY urgent to defend */
   pcity->ai.danger = danger;
-  if (pcity->ai.building_want[B_CITY] > 0 && danger2 != 0) {
+  if (pcity->ai.building_want[B_CITY] > 0 && danger_wall != 0) {
     i = assess_defense(pcity);
-    if (i == 0) pcity->ai.building_want[B_CITY] = 100 + urgency;
-    else if (urgency != 0) {
-      if (danger2 > i * 2) pcity->ai.building_want[B_CITY] = 200 + urgency;
-      else pcity->ai.building_want[B_CITY] = danger2 * 100 / i;
+    if (i == 0) pcity->ai.building_want[B_CITY] = 100 + pcity->ai.urgency;
+    else if (pcity->ai.urgency != 0) {
+      if (danger_wall > i * 2) pcity->ai.building_want[B_CITY] = 200 + 
pcity->ai.urgency;
+      else pcity->ai.building_want[B_CITY] = danger_wall * 100 / i;
     } else {
-      if (danger2 > i) pcity->ai.building_want[B_CITY] = 100;
-      else pcity->ai.building_want[B_CITY] = danger2 * 100 / i;
+      if (danger_wall > i) pcity->ai.building_want[B_CITY] = 100;
+      else pcity->ai.building_want[B_CITY] = danger_wall * 100 / i;
     }
   }
 /* My first attempt to allow ng_wa >= 200 led to stupidity in cities with
-no defenders and danger = 0 but danger > 0.  Capping ng_wa at 100 + urgency
-led to a failure to buy walls as required.  Allowing want > 100 with !urgency
+no defenders and danger = 0 but danger > 0.  Capping ng_wa at 100 + 
pcity->ai.urgency
+led to a failure to buy walls as required.  Allowing want > 100 with 
!pcity->ai.urgency
 led to the AI spending too much gold and falling behind on science.  I'm
 trying again, but this will require yet more tedious observation -- Syela */
-  if (pcity->ai.building_want[B_COASTAL] > 0 && danger3 != 0) {
+  if (pcity->ai.building_want[B_COASTAL] > 0 && danger_coastal != 0) {
     i = assess_defense_igwall(pcity);
-    if (i == 0) pcity->ai.building_want[B_COASTAL] = 100 + urgency;
-    else if (urgency != 0) {
-      if (danger3 > i * 2) pcity->ai.building_want[B_COASTAL] = 200 + urgency;
-      else pcity->ai.building_want[B_COASTAL] = danger3 * 100 / i;
+    if (i == 0) pcity->ai.building_want[B_COASTAL] = 100 + pcity->ai.urgency;
+    else if (pcity->ai.urgency != 0) {
+      if (danger_coastal > i * 2) pcity->ai.building_want[B_COASTAL] = 200 + 
pcity->ai.urgency;
+      else pcity->ai.building_want[B_COASTAL] = danger_coastal * 100 / i;
     } else {
-      if (danger3 > i) pcity->ai.building_want[B_COASTAL] = 100;
-      else pcity->ai.building_want[B_COASTAL] = danger3 * 100 / i;
+      if (danger_coastal > i) pcity->ai.building_want[B_COASTAL] = 100;
+      else pcity->ai.building_want[B_COASTAL] = danger_coastal * 100 / i;
     }
   }
 /* COASTAL and SAM are TOTALLY UNTESTED and could be VERY WRONG -- Syela */
 /* update 980803; COASTAL seems to work; still don't know about SAM. -- Syela 
*/
-  if (pcity->ai.building_want[B_SAM] > 0 && danger4 != 0) {
+  if (pcity->ai.building_want[B_SAM] > 0 && danger_sam != 0) {
     i = assess_defense_igwall(pcity);
-    if (i == 0) pcity->ai.building_want[B_SAM] = 100 + urgency;
-    else if (danger4 > i * 2) pcity->ai.building_want[B_SAM] = 200 + urgency;
-    else pcity->ai.building_want[B_SAM] = danger4 * 100 / i;
+    if (i == 0) pcity->ai.building_want[B_SAM] = 100 + pcity->ai.urgency;
+    else if (danger_sam > i * 2) pcity->ai.building_want[B_SAM] = 200 + 
pcity->ai.urgency;
+    else pcity->ai.building_want[B_SAM] = danger_sam * 100 / i;
   }
-  if (pcity->ai.building_want[B_SDI] > 0 && danger5 != 0) {
+  if (pcity->ai.building_want[B_SDI] > 0 && danger_sdi != 0) {
     i = assess_defense_igwall(pcity);
-    if (i == 0) pcity->ai.building_want[B_SDI] = 100 + urgency;
-    else if (danger5 > i * 2) pcity->ai.building_want[B_SDI] = 200 + urgency;
-    else pcity->ai.building_want[B_SDI] = danger5 * 100 / i;
+    if (i == 0) pcity->ai.building_want[B_SDI] = 100 + pcity->ai.urgency;
+    else if (danger_sdi > i * 2) pcity->ai.building_want[B_SDI] = 200 + 
pcity->ai.urgency;
+    else pcity->ai.building_want[B_SDI] = danger_sdi * 100 / i;
   }
-  pcity->ai.urgency = urgency; /* need to cache this for bodyguards now -- 
Syela */
-  return(urgency);
+  return(pcity->ai.urgency);
 }
 
 /************************************************************************** 

-- 
//Markus



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