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

[freeciv-ai] quizz

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-ai@xxxxxxxxxxx
Subject: [freeciv-ai] quizz
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Sat, 17 Aug 2002 11:24:09 +0000 (GMT)

This function gets called every turn on every unit. What is fundamentally
wrong with it?

(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



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