Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2002:
[Freeciv-Dev] Re: [PATCH] new moving type: unknown (PR#1316)
Home

[Freeciv-Dev] Re: [PATCH] new moving type: unknown (PR#1316)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: [PATCH] new moving type: unknown (PR#1316)
From: Markus Linnala <maage@xxxxxxxxx>
Date: 16 Mar 2002 09:43:36 +0200
Reply-to: Markus Linnala <maage@xxxxxxxxx>

Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx> writes:

> On Sun, Mar 10, 2002 at 08:33:24AM -0800, Markus Linnala wrote:
> > 
> > New moving type type unknown. Use it instead of 0.
> 
> No. Instead add a flag "bool accept_any_move_type" to
> ai_choose_defender_limited.

Use ANY_MOVING when we don't care. Use UNKNOWN_MOVING whe we
don't know. Add flag "bool accept_any_move_type" to
ai_choose_defender_limited.

Reason to use symbolic values instead of 0's is that 0's are not
part of "enum unit_move_type".

diff -ur -X freeciv/diff_ignore freeciv/ai/aicity.c freeciv-moving/ai/aicity.c
--- freeciv/ai/aicity.c Sat Mar 16 09:26:48 2002
+++ freeciv-moving/ai/aicity.c  Sat Mar 16 09:36:19 2002
@@ -442,7 +442,7 @@
         freelog(LOG_VERBOSE, "%s is DOOMED!", pcity->name);
          try_to_sell_stuff(pplayer, pcity); /* and don't buy stuff */
          pcity->currently_building = ai_choose_defender_limited(pcity,
-                  pcity->shield_stock + pcity->shield_surplus, 0);
+                  pcity->shield_stock + pcity->shield_surplus, ANY_MOVING, 
TRUE);
       }
 #endif
       else if ((pplayer->economic.gold-pplayer->ai.est_upkeep) >= buycost
@@ -464,7 +464,7 @@
               really_handle_city_buy(pplayer, pcity);
 /* don't need to waste gold here, but may as well spend our production */
             else pcity->currently_building = ai_choose_defender_limited(pcity,
-                  pcity->shield_stock + pcity->shield_surplus, 0);
+                  pcity->shield_stock + pcity->shield_surplus, ANY_MOVING, 
TRUE);
           } else if (buycost > pplayer->ai.maxbuycost) pplayer->ai.maxbuycost 
= buycost;
 /* possibly upgrade units here */
         } /* end panic subroutine */
@@ -674,7 +674,7 @@
 }
 
 Unit_Type_id ai_choose_defender_limited(struct city *pcity, int n,
-                                        enum unit_move_type which)
+                                        enum unit_move_type which, bool 
accept_any_move_type)
 {
   Unit_Type_id bestid = 0; /* ??? Zero is legal value! (Settlers by default) */
   int j, m;
@@ -687,7 +687,7 @@
     m = unit_types[i].move_type;
     if (can_build_unit(pcity, i) && get_unit_type(i)->build_cost <= n &&
         (m == LAND_MOVING || m == SEA_MOVING) &&
-        (m == which || which == 0)) {
+        (m == which || accept_any_move_type)) {
       j = unit_desirability(i, TRUE);
       j *= j;
       if (unit_type_flag(i, F_FIELDUNIT) && !isdef) j = 0; /* This is now 
confirmed */
@@ -706,12 +706,12 @@
 Unit_Type_id ai_choose_defender_by_type(struct city *pcity,
                                         enum unit_move_type which)
 {
-  return (ai_choose_defender_limited(pcity, pcity->shield_stock + 40, which));
+  return (ai_choose_defender_limited(pcity, pcity->shield_stock + 40, which, 
FALSE));
 }
 
 Unit_Type_id ai_choose_defender(struct city *pcity)
 {
-  return (ai_choose_defender_limited(pcity, pcity->shield_stock + 40, 0));
+  return (ai_choose_defender_limited(pcity, pcity->shield_stock + 40, 
ANY_MOVING, TRUE));
 }
 
 #ifdef UNUSED
diff -ur -X freeciv/diff_ignore freeciv/ai/aicity.h freeciv-moving/ai/aicity.h
--- freeciv/ai/aicity.h Sat Mar  2 20:02:44 2002
+++ freeciv-moving/ai/aicity.h  Sat Mar 16 09:36:19 2002
@@ -23,7 +23,7 @@
 void ai_choose_ferryboat(struct player *pplayer, struct city *pcity, struct 
ai_choice *choice);
 Unit_Type_id ai_choose_defender_versus(struct city *pcity, Unit_Type_id v);
 Unit_Type_id ai_choose_defender_limited(struct city *pcity, int n,
-                                        enum unit_move_type which);
+                                        enum unit_move_type which, bool 
accept_any_move_type);
 Unit_Type_id ai_choose_defender_by_type(struct city *pcity,
                                         enum unit_move_type which);
 Unit_Type_id ai_choose_defender(struct city *pcity);
diff -ur -X freeciv/diff_ignore freeciv/common/unittype.c 
freeciv-moving/common/unittype.c
--- freeciv/common/unittype.c   Wed Mar  6 12:05:16 2002
+++ freeciv-moving/common/unittype.c    Sat Mar 16 09:36:19 2002
@@ -351,7 +351,7 @@
       return i;
     }
   }
-  return 0;
+  return UNKNOWN_MOVING;
 }
 
 /**************************************************************************
diff -ur -X freeciv/diff_ignore freeciv/common/unittype.h 
freeciv-moving/common/unittype.h
--- freeciv/common/unittype.h   Wed Mar  6 12:05:16 2002
+++ freeciv-moving/common/unittype.h    Sat Mar 16 09:36:19 2002
@@ -52,7 +52,7 @@
 */
 
 enum unit_move_type {
-  LAND_MOVING = 1, SEA_MOVING, HELI_MOVING, AIR_MOVING
+  UNKNWON_MOVING = 0, ANY_MOVING = 0, LAND_MOVING = 1, SEA_MOVING, 
HELI_MOVING, AIR_MOVING
 };
 
 /* Classes for unit types.


-- 
//Markus


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