Complete.Org: Mailing Lists: Archives: freeciv-ai: August 2002:
[freeciv-ai] Re: quizz
Home

[freeciv-ai] Re: quizz

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: "Per I. Mathisen" <per@xxxxxxxxxxx>
Cc: freeciv-ai@xxxxxxxxxxx
Subject: [freeciv-ai] Re: quizz
From: "Anthony J. Stuckey" <astuckey@xxxxxxxx>
Date: Sat, 17 Aug 2002 09:47:10 -0500

On Sat, Aug 17, 2002 at 11:24:09AM +0000, Per I. Mathisen wrote:
> This function gets called every turn on every unit. What is fundamentally
> wrong with it?
> 
> static bool stay_and_defend_city(struct unit *punit)
> {
>   struct city *pcity = map_get_city(punit->x, punit->y);
>   bool has_defense = FALSE;
> 
>   if (!pcity) return FALSE;
>   if (pcity->id == punit->homecity) return FALSE;

        No quibbles yet up to here.

>   if (pcity->owner != punit->owner) return FALSE;

        This might want different logic.  We still might be the best defender
for an allied city.  However, the code below would need some protection.

>   unit_list_iterate(map_get_tile(pcity->x, pcity->y)->units, pdef) {
>     if (assess_defense_unit(pcity, punit, FALSE) >= 0
>         && pdef != punit
>         && pdef->homecity == pcity->id) {
>       has_defense = TRUE;
>     }
>   } unit_list_iterate_end;

        This iterates the unit list looking to see if there is a different,
native, unit which could be a defender here.
        No rating is made to see if they are a better defender or not.
        No check is made to see if we are interfering with another unit
mission: going to defend a city in greater danger, bodyguarding, etc.

>   /* Guess I better stay / you can live at home now */
>   if (!has_defense) {
>     struct packet_unit_request packet;
> 
>     /* Very important, or will not stay -- Syela */
>     ai_unit_new_role(punit, AIUNIT_DEFEND_HOME);
> 
>     /* change homecity to this city */
>     /* FIXME: it is stupid to change homecity if the unit has no homecity
>        in advance or the new city does not have enough shields to support it 
> */

        Wise words.

>     packet.unit_id = punit->id;
>     packet.city_id = pcity->id;
>     handle_unit_change_homecity(unit_owner(punit), &packet);
>     return TRUE;
>   }
>   return FALSE;
> }


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