Complete.Org: Mailing Lists: Archives: freeciv-ai: October 2002:
[freeciv-ai] Re: Findjob
Home

[freeciv-ai] Re: Findjob

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv ai <freeciv-ai@xxxxxxxxxxx>
Subject: [freeciv-ai] Re: Findjob
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Sun, 27 Oct 2002 11:03:39 +0000 (GMT)

On Sat, 26 Oct 2002, Jordi Negrevernis i Font wrote:
> In aiunit.c:ai_military_findjob() there is this code...
>
> if (punit->ai.charge != BODYGUARD_NONE) { /* I am a bodyguard */
>   aunit = player_find_unit_by_id(pplayer, punit->ai.charge);
>   acity = find_city_by_id(punit->ai.charge);
>
>   /* Check if city we are on our way to rescue is still in danger,
>    * or unit we should protect is still alive */
>   if ((acity && acity->owner == punit->owner && acity->ai.urgency != 0 &&
>         acity->ai.danger > assess_defense_quadratic(acity))
>       || aunit) {
>     if (punit->ai.ai_role != AIUNIT_ESCORT) {
>       /* We forgot what we were doing. Incredible! */
>       BODYGUARD_LOG(LOG_ERROR, punit, "lost role as bodyguard in
> findjob");
>       punit->ai.ai_role = AIUNIT_ESCORT; /* do not use
> ai_unit_new_role() */
>     }
>     return;
>   } else {
>     ai_unit_ready(punit);
>   }
> }
>
> The 3th line assigns an id of a unit to a city!!!!
> Is this an error?

Incredibly, no. punit->ai.charge can be either a unit or a city id. This
id is unique for all units and cities, thus no city or unit ever has the
same id. So one of acity and aunit will always be NULL above.

  - Per



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