Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2005:
[Freeciv-Dev] (PR#12545) [Patch] ai.invasion cleanup
Home

[Freeciv-Dev] (PR#12545) [Patch] ai.invasion cleanup

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12545) [Patch] ai.invasion cleanup
From: "Marko Lindqvist" <marko.lindqvist@xxxxxxxxxxx>
Date: Sat, 19 Mar 2005 04:57:21 -0800
Reply-to: bugs@xxxxxxxxxxx

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


  I had hard time trying to figure out how ai.invasion works. Attached 
patch makes it a bit more obvious.
  No behavior changes, even though (IMHO) this less obscure code makes 
some weaknesses more obvious.


  - ML


diff -Nurd -X.diff_ignore freeciv/ai/advmilitary.c freeciv/ai/advmilitary.c
--- freeciv/ai/advmilitary.c    2005-03-16 09:16:09.325246200 +0200
+++ freeciv/ai/advmilitary.c    2005-03-16 14:34:56.308586200 +0200
@@ -887,10 +887,11 @@
       if (move_type != LAND_MOVING && vuln == 0) {
         desire = 0;
         
-      } else if ((move_type == LAND_MOVING || move_type == HELI_MOVING)
-                 && acity && acity->ai.invasion == 2) {
+      } else if ((move_type == LAND_MOVING || move_type == HELI_MOVING) && 
acity
+                 && TEST_BIT(acity->ai.invasion, INVASION_ATTACK)
+                 && !TEST_BIT(acity->ai.invasion, INVASION_OCCUPY)) {
         desire = bcost * SHIELD_WEIGHTING;
-        
+
       } else {
         if (!acity) {
           desire = kill_desire(value, attack, bcost, vuln, victim_count);
@@ -1096,7 +1097,7 @@
         def_type = pdef->type; 
       }
     }
-    if (COULD_OCCUPY(myunit) || TEST_BIT(acity->ai.invasion, 0)) {
+    if (COULD_OCCUPY(myunit) || TEST_BIT(acity->ai.invasion, INVASION_OCCUPY)) 
{
       /* bonus for getting the city */
       benefit += 40;
     }
diff -Nurd -X.diff_ignore freeciv/ai/aiair.c freeciv/ai/aiair.c
--- freeciv/ai/aiair.c  2005-03-16 09:16:09.403176200 +0200
+++ freeciv/ai/aiair.c  2005-03-16 14:35:34.572216200 +0200
@@ -73,7 +73,7 @@
   /* TODO: There is a danger of producing too many units that will not 
    * attack anything.  Production should not happen if there is an idle 
    * unit of the same type nearby */
-  if (acity && !TEST_BIT(acity->ai.invasion, 0) && punit->id != 0) {
+  if (acity && !TEST_BIT(acity->ai.invasion, INVASION_OCCUPY) && punit->id != 
0) {
     /* No ground troups are invading */
     freelog(LOG_DEBUG, "Don't want to attack %s, although we could", 
             acity->name);
diff -Nurd -X.diff_ignore freeciv/ai/aiunit.c freeciv/ai/aiunit.c
--- freeciv/ai/aiunit.c 2005-03-16 09:16:10.104546200 +0200
+++ freeciv/ai/aiunit.c 2005-03-16 15:16:56.138625000 +0200
@@ -1398,21 +1398,22 @@
     /* dealing with invasion stuff */
     if (IS_ATTACKER(aunit)) {
       if (aunit->activity == ACTIVITY_GOTO) {
-        invasion_funct(aunit, TRUE, 0, (COULD_OCCUPY(aunit) ? 1 : 2));
+        invasion_funct(aunit, TRUE, 0,
+                       (COULD_OCCUPY(aunit) ? INVASION_OCCUPY : 
INVASION_ATTACK));
         if ((pcity = map_get_city(aunit->goto_tile))) {
           pcity->ai.attack += unit_att_rating(aunit);
           pcity->ai.bcost += unit_build_shield_cost(aunit->type);
         } 
       }
       invasion_funct(aunit, FALSE, unit_move_rate(aunit) / SINGLE_MOVE,
-                     (COULD_OCCUPY(aunit) ? 1 : 2));
+                     (COULD_OCCUPY(aunit) ? INVASION_OCCUPY : 
INVASION_ATTACK));
     } else if (aunit->ai.passenger != 0 &&
                !same_pos(aunit->tile, punit->tile)) {
       /* It's a transport with reinforcements */
       if (aunit->activity == ACTIVITY_GOTO) {
-        invasion_funct(aunit, TRUE, 1, 1);
+        invasion_funct(aunit, TRUE, 1, INVASION_OCCUPY);
       }
-      invasion_funct(aunit, FALSE, 2, 1);
+      invasion_funct(aunit, FALSE, 2, INVASION_OCCUPY);
     }
   } unit_list_iterate_end;
   /* end horrible initialization subroutine */
@@ -1529,7 +1530,7 @@
         }
       }
 
-      if (COULD_OCCUPY(punit) || TEST_BIT(acity->ai.invasion, 0)) {
+      if (COULD_OCCUPY(punit) || TEST_BIT(acity->ai.invasion, 
INVASION_OCCUPY)) {
         /* There are units able to occupy the city! */
         benefit += 40;
       }
@@ -1551,7 +1552,9 @@
       } else if (move_time > THRESHOLD) {
         /* Too far! */
         want = 0;
-      } else if (COULD_OCCUPY(punit) && acity->ai.invasion == 2) {
+      } else if (TEST_BIT(acity->ai.invasion, INVASION_ATTACK)
+                 && !TEST_BIT(acity->ai.invasion, INVASION_OCCUPY)
+                 && COULD_OCCUPY(punit)) {
         /* Units able to occupy really needed there! */
         want = bcost * SHIELD_WEIGHTING;
       } else {
diff -Nurd -X.diff_ignore freeciv/ai/aiunit.h freeciv/ai/aiunit.h
--- freeciv/ai/aiunit.h 2005-03-16 09:16:10.104546200 +0200
+++ freeciv/ai/aiunit.h 2005-03-16 15:17:11.201125000 +0200
@@ -42,6 +42,9 @@
   (ut->pop_cost * 3 + ut->happy_cost                                   \
    + ut->upkeep[O_SHIELD] + ut->upkeep[O_FOOD] + ut->upkeep[O_GOLD])
 
+#define INVASION_OCCUPY  (1)
+#define INVASION_ATTACK  (1 << 1)
+
 struct ai_choice;
 struct pf_path;
 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#12545) [Patch] ai.invasion cleanup, Marko Lindqvist <=