Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2002:
[Freeciv-Dev] Re: (PR#2413) ai diplomacy patch
Home

[Freeciv-Dev] Re: (PR#2413) ai diplomacy patch

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: per@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#2413) ai diplomacy patch
From: "jorneg@xxxxxxxxxxx via RT" <rt@xxxxxxxxxxxxxx>
Date: Mon, 25 Nov 2002 16:48:07 -0800
Reply-to: rt@xxxxxxxxxxxxxx


En/na Per I. Mathisen via RT ha escrit:

>/********************************************************************** 
>  Only ever called for AI players and never for barbarians.
>***********************************************************************/
>void ai_diplomacy_calculate(struct player *pplayer, struct ai_data *ai)
>{
>  int war_desire = 0;
>  int war_fear = 0;
>  struct player *target = NULL;
>
>  /* Stop war against a dead player */
>  if (ai->diplomacy.target && !ai->diplomacy.target->is_alive) {
>    freelog(LOG_DIPL, "(%s ai diplo) Target player %s is dead. Victory!",
>            pplayer->name, ai->diplomacy.target->name);
>    ai->diplomacy.timer = 0;
>    ai->diplomacy.target = NULL;
>    if (ai->diplomacy.strategy == WIN_CAPITAL) {
>      ai->diplomacy.strategy = WIN_OPEN;
>    }
>  }
>
>  /* Calculate our military strength */
>  ai->diplomacy.mil_strength = 1;
>  unit_list_iterate(pplayer->units, punit) {
>     ai->diplomacy.mil_strength += ai_unit_attack_desirability(punit->type);
>  } unit_list_iterate_end;
>
>  /* Ensure that we don't prematurely end an ongoing war */
>  if (ai->diplomacy.timer-- > 0) {
>    return;
>  }
>
>  /* Calculate our fears and desires, and find desired war target */
>  players_iterate(aplayer) {
>    enum diplstate_type ds = pplayer_get_diplstate(pplayer, aplayer)->type;
>
>    /* We don't fear/hate ourselves, those we don't know and those we're
>     * allied to (unless we're the backstabbing type) */
>    if (aplayer == pplayer
>        || ds == DS_NO_CONTACT
>        || (ds == DS_ALLIANCE && !ai_attitude(ai, DIP_BACKSTABBER))) {
>      continue;
>    }
>    ai->diplomacy.other[aplayer->player_no].war_desire =
>      ai_war_desire(pplayer, aplayer, ai);
>    ai->diplomacy.other[aplayer->player_no].war_fear =
>      ai_war_fear(pplayer, aplayer, ai);
>
>    /* Loyalty: hate our allies' enemies */
>    players_iterate(eplayer) {
>      if (pplayers_allied(pplayer, eplayer)
>          && !ai_attitude(ai, DIP_BACKSTABBER)
>          && pplayers_at_war(aplayer, eplayer)) {
>        ai->diplomacy.other[aplayer->player_no].war_desire *= 2;
>      }
>    } players_iterate_end;
>
>    /* Strongly prefer players we are at war with already */
>    if (pplayers_non_attack(pplayer, aplayer)) {
>      ai->diplomacy.other[aplayer->player_no].war_desire /= 2;
>    }
>    freelog(LOG_DEBUG, "(%s ai diplo) Against %s we have war desire "
>            "%d and fear %d", pplayer->name, aplayer->name,
>            ai->diplomacy.other[aplayer->player_no].war_desire,
>            ai->diplomacy.other[aplayer->player_no].war_fear);
>
>    /* Find best target */
>    if (ai->diplomacy.other[aplayer->player_no].war_desire > war_desire) {
>      target = aplayer;
>      war_desire = ai->diplomacy.other[aplayer->player_no].war_desire;
>      war_fear = ai->diplomacy.other[aplayer->player_no].war_fear;
>    }
>  } players_iterate_end;
>
>  if (!target) {
>    freelog(LOG_DEBUG, "(%s ai diplo) Found no target.", pplayer->name);
>
    ai->diplomacy.target = NULL;

>    return;
>  }
>
>  
>
    Maybe we should remember that state...





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