Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2002:
[Freeciv-Dev] Re: [PATCH] use enum values for ai_choice at aicity.c (PR#
Home

[Freeciv-Dev] Re: [PATCH] use enum values for ai_choice at aicity.c (PR#

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: rf13@xxxxxxxxxxxxxxxxxxxxxx
Cc: Markus Linnala <maage@xxxxxxxxx>, freeciv-dev@xxxxxxxxxxx, bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: [PATCH] use enum values for ai_choice at aicity.c (PR#1313)
From: Petr Baudis <pasky@xxxxxxxxxxx>
Date: Wed, 13 Mar 2002 15:37:26 +0100

Dear diary, on Wed, Mar 13, 2002 at 11:28:23AM CET, I got a letter,
where Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx> told me, that...
> On Sun, Mar 10, 2002 at 08:21:04AM -0800, Markus Linnala wrote:
> > 
> > Use enum values instead of plain ints.
> > 
> > diff -ur -X freeciv/diff_ignore freeciv/ai/aicity.c 
> > freeciv-ct-none/ai/aicity.c
> > --- freeciv/ai/aicity.c     Fri Mar  8 19:06:18 2002
> > +++ freeciv-ct-none/ai/aicity.c     Sun Mar 10 18:17:37 2002
> > @@ -424,14 +424,14 @@
> >        buycost = city_buy_cost(pcity);
> >        if (pcity->shield_stock == 0) {
> >     /* nothing */
> > -      } else if (bestchoice.type == 0 && is_wonder(bestchoice.choice) &&
> > +      } else if (bestchoice.type == CT_NONE && 
> > is_wonder(bestchoice.choice) &&
> 
> See <http://arch.freeciv.org/freeciv-dev-200109/msg00919.html>

Oops! Good catch, Raimar! :)

Cleaned up code from my first round of cleanups looks like:


      /* building wonder and much remaining yet */
      else if (bestchoice.type == CT_BUILDING &&
               is_wonder(bestchoice.choice) && buycost >= 200)
        /* wait for more caravans */;

      /* settlers in city where they can't be built yet */
      else if (bestchoice.type > CT_BUILDING &&
               unit_type_flag(bestchoice.choice, F_CITIES) &&
               !city_got_effect(pcity, B_GRANARY) &&
               (pcity->size < 2 ||
                pcity->food_stock < city_granary_size(pcity->size - 1)))
        /* wait until it'll grow */;


      /* not a defender or building and still too expensive anyway */
      else if (bestchoice.type > CT_BUILDING &&
               bestchoice.type < CT_DEFENDER &&
               buycost > unit_types[bestchoice.choice].build_cost * 2) {
        /* but a caravan */
        if (unit_type_flag(bestchoice.choice, F_CARAVAN) &&
            pplayer->ai.maxbuycost < 100)
          /* save money for it */
          pplayer->ai.maxbuycost = 100;
      }


(yes, I would do it differently, today :)

However, it should logically really check against CT_BUILDING. When looking
through that patch for first time, I overlooked that CT_BUILDING is zero as
well :/.

-- 

                                Petr "Pasky" Baudis

* elinks maintainer                * IPv6 guy (XS26 co-coordinator)
* IRCnet operator                  * FreeCiv AI hacker
.
"If you have acquired knowledge, what do you lack?
    If you lack knowledge, what have you acquired?"
Lev. R. 1:6
.
Public PGP key && geekcode && homepage: http://pasky.ji.cz/~pasky/


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