Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2002:
[Freeciv-Dev] Re: [PATCH] make ai_choice->type enum choice_type (PR#1318
Home

[Freeciv-Dev] Re: [PATCH] make ai_choice->type enum choice_type (PR#1318

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Markus Linnala <maage@xxxxxxxxx>
Cc: freeciv-dev@xxxxxxxxxxx, bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: [PATCH] make ai_choice->type enum choice_type (PR#1318)
From: Petr Baudis <pasky@xxxxxxxxxxx>
Date: Mon, 11 Mar 2002 11:07:12 +0100

Dear diary, on Sun, Mar 10, 2002 at 05:47:33PM CET, I got a letter, where
Markus Linnala <maage@xxxxxxxxx> told me, that...
> 
> As ai_choice->type is usually of type enum choice_type, make it so. Use
> common initialisation function, clear_ai_choice.  aitech.c used type for
> something else, so add new field tech_want to ai_choice.

Good thing (tm). However, I believe Ross did something similiar.. and it looks
he did it probably better.

+int init_choice(struct ai_choice *cur)
+  static struct ai_choice choice = { A_NONE, 0, CT_NONE };
+
+  *cur = choice;
+  return 1;
+}

I happen to like his approach more and also his choice of function name ;).

> diff -ur -X freeciv/diff_ignore freeciv/ai/aicity.c 
> freeciv-ai-choice-tech-want/ai/aicity.c
> --- freeciv/ai/aicity.c       Fri Mar  8 19:06:18 2002
> +++ freeciv-ai-choice-tech-want/ai/aicity.c   Sun Mar 10 18:42:40 2002
> @@ -240,6 +238,7 @@
>      pcity->ai.choice.choice = bestchoice.choice; /* we want to spend gold 
> later */
>      pcity->ai.choice.want = bestchoice.want; /* so that we spend it in the 
> right city */
>      pcity->ai.choice.type = bestchoice.type; /* instead of the one atop the 
> list */
> +    pcity->ai.choice.tech_want = bestchoice.tech_want;
>    }
>  
>    if (bestchoice.want != 0) { /* Note - on fallbacks, will NOT get stopped 
> building msg */
> @@ -348,15 +347,14 @@
>      if (reserve > pplayer->economic.gold)
>        break;
>  
> -    bestchoice.want = 0;
> -    bestchoice.type = CT_NONE;
> -    bestchoice.choice = 0;
> +    clear_ai_choice(&bestchoice);
>      city_list_iterate(pplayer->cities, acity)
>        if (acity->anarchy != 0) continue;
>        if (acity->ai.choice.want > bestchoice.want && ai_fuzzy(pplayer, 
> TRUE)) {
>          bestchoice.choice = acity->ai.choice.choice;
>          bestchoice.want = acity->ai.choice.want;
>          bestchoice.type = acity->ai.choice.type;
> +        bestchoice.tech_want = acity->ai.choice.tech_want;

Shouldn't we use copy_if_better_choice here?

>          pcity = acity;
>        }
>      city_list_iterate_end;
> diff -ur -X freeciv/diff_ignore freeciv/ai/aitech.c 
> freeciv-ai-choice-tech-want/ai/aitech.c
> --- freeciv/ai/aitech.c       Tue Mar  5 12:20:02 2002
> +++ freeciv-ai-choice-tech-want/ai/aitech.c   Sun Mar 10 18:42:40 2002
> @@ -225,14 +225,14 @@
>    if (choice) {
>      choice->choice = l;
>      choice->want = values[l] / num_cities_nonzero;
> -    choice->type = values[pplayer->research.researching] / 
> num_cities_nonzero;
> +    choice->tech_want = values[pplayer->research.researching] / 
> num_cities_nonzero;
>      /* hijacking this ... in order to leave tech_wants alone */
>    }
>  
>    if (gol) {
>      gol->choice = k;
>      gol->want = goal_values[k] / num_cities_nonzero;
> -    gol->type = goal_values[pplayer->ai.tech_goal] / num_cities_nonzero;
> +    gol->tech_want = goal_values[pplayer->ai.tech_goal] / num_cities_nonzero;
>      freelog(LOG_DEBUG,
>           "Gol->choice = %s, gol->want = %d, goal_value = %d, "
>           "num_cities_nonzero = %d",
> @@ -289,7 +289,7 @@
>    ai_select_tech(pplayer, &choice, &gol);
>    if (choice.choice != pplayer->research.researching) {
>      /* changing */
> -    if ((choice.want - choice.type) > penalty &&
> +    if ((choice.want - choice.tech_want) > penalty &&
>       penalty + pplayer->research.bulbs_researched <=
>       total_bulbs_required(pplayer)) {
>        freelog(LOG_DEBUG, "%s switching from %s to %s with penalty of %d.",
> @@ -301,7 +301,7 @@
>    /* crossing my fingers on this one! -- Syela (seems to have worked!) */
>    if (gol.choice != pplayer->ai.tech_goal) {
>      freelog(LOG_DEBUG, "%s changing goal from %s (want = %d) to %s (want = 
> %d)",
> -         pplayer->name, advances[pplayer->ai.tech_goal].name, gol.type,
> +         pplayer->name, advances[pplayer->ai.tech_goal].name, gol.tech_want,
>           advances[gol.choice].name, gol.want);
>      choose_tech_goal(pplayer, gol.choice);
>    }
..snip..

If this change type -> tech_want generates same savegames, and you didn't
forget anything ;), it's ok for me.

-- 

                                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]