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>, freeciv-ai@xxxxxxxxxxx
Subject: [freeciv-ai] Re: quizz
From: Raahul Kumar <raahul_da_man@xxxxxxxxx>
Date: Sat, 17 Aug 2002 04:36:13 -0700 (PDT)

--- "Per I. Mathisen" <per@xxxxxxxxxxx> wrote:
> This function gets called every turn on every unit. What is fundamentally
> wrong with it?


Well for starters if it gets called for every unit there is a huge problem with
air and ship units. It should at the very least exclude those units.

It also gets called a lot. 

> (Note that the comment is slightly wrong: It should say "should stay"
> instead of "stayed".)
> 
> /**************************************************************************
> Returns whether we stayed in the (eventual) city on the square to defend
> 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;
>   if (pcity->owner != punit->owner) return FALSE;
> 
>   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;
> 
>   /* 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
> */
>     packet.unit_id = punit->id;
>     packet.city_id = pcity->id;
>     handle_unit_change_homecity(unit_owner(punit), &packet);
>     return TRUE;
>   }
>   return FALSE;
> }
> 
> Yours
> Per
> 
> 


__________________________________________________
Do You Yahoo!?
HotJobs - Search Thousands of New Jobs
http://www.hotjobs.com


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