[Freeciv-Dev] Re: [Patch] for to players_iterate
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
On Thu, Feb 21, 2002 at 06:21:16PM -0600, Tony Stuckey wrote:
> On Wed, Feb 20, 2002 at 12:05:52AM +0100, Raimar Falke wrote:
> > Can somebody look at
> > the change of ai_manage_diplomat? Especially what
> >
> > if (!ctarget && aplayer) {
> >
> > should mean?
>
> Ctarget is the city that this diplomat would want to target. It is
> not guaranteed to be set to a useful value. If it is unset at this point,
> we haven't found a useful foreign city to do anything with.
> Aplayer may or may not be guaranteed to be set
for( i = 0; i < game.nplayers; i++) {
aplayer = &game.players[i];
if (aplayer == pplayer) continue;
/* sneaky way of avoiding foul diplomat capture -AJS */
has_emb=player_has_embassy(pplayer, aplayer) || pdiplomat->foul;
city_list_iterate(aplayer->cities, acity)
if (handicap && !map_get_known(acity->x, acity->y, pplayer)) continue;
if (continent != map_get_continent(acity->x, acity->y)) continue;
city_incite_cost(acity);
/* figure our incite cost */
oic = acity->incite_revolt_cost;
if (pplayer->player_no == acity->original) oic = oic / 2;
rmd=real_map_distance(pdiplomat->x, pdiplomat->y, acity->x, acity->y);
if (!ctarget || (dist > rmd)) {
if (!has_emb || !acity->steal || (oic <
pplayer->economic.gold - pplayer->ai.est_upkeep)) {
/* We have the closest enemy city so far on the same continent */
ctarget = acity;
dist = rmd;
}
}
city_list_iterate_end;
}
if (!ctarget && aplayer) {
So aplayer won't be changed by the for loop iff there are no players
in the game. This is fishy. Also also turns out that aplayer will have
the value NULL if the for loop is entered.
> , I haven't retraced all code paths. This might be there to avoid
> segfaults when dereferencing aplayer->cities immediately after this
> line.
> What exactly are you asking?
What was the real intend? To test for empty games? I don't think so.
Raimar
--
email: rf13@xxxxxxxxxxxxxxxxx
This customer comes into the computer store. "I'm looking for a mystery
Adventure Game with lots of graphics. You know, something realy
challenging". "Well," replied the clerk, "have you tried Windows 98 ?"
|
|