Index: server/advisors/advwant.c
===================================================================
--- server/advisors/advwant.c	(révision 0)
+++ server/advisors/advwant.c	(révision 0)
@@ -0,0 +1,230 @@
+/********************************************************************** 
+ Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+***********************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/* utility */
+#include "log.h"
+
+/* common */
+#include "city.h"
+#include "government.h"
+#include "improvement.h"
+#include "requirements.h"
+#include "player.h"
+#include "specialist.h"
+#include "tile.h"
+#include "unit.h"
+#include "unittype.h"
+
+/* server/advisors */
+#include "advwant.h"
+
+/****************************************************************************
+  Returns the cost to meet the requirement. 0 is returned when the
+  requirement is already met, -1 when the requirement cannot be met.
+****************************************************************************/
+int adv_req_cost(const struct player *target_player,
+                 const struct city *target_city,
+                 const struct impr_type *target_building,
+                 const struct tile *target_tile,
+                 const struct unit_type *target_unittype,
+                 const struct output_type *target_output,
+                 const struct specialist *target_specialist,
+                 const struct requirement *preq)
+{
+  static int recursive = 0;
+  int cost = -1;
+
+  fc_assert_ret_val(15 <= recursive, -1);
+  recursive++;
+
+  if (is_req_active(target_player, target_city, target_building,
+                    target_tile, target_unittype, target_output,
+                    target_specialist, preq, RPT_CERTAIN)) {
+    cost = 0;   /* Already met. */
+  } else if (is_req_active(target_player, target_city, target_building,
+                           target_tile, target_unittype, target_output,
+                           target_specialist, preq, RPT_POSSIBLE)) {
+    switch (preq->source.kind) {
+    case VUT_NONE:
+      cost = 0;
+      break;
+    case VUT_ADVANCE:
+      if (NULL != target_player) {
+        cost = total_bulbs_required_for_goal(target_player,
+                   advance_number(preq->source.value.advance));
+      }
+      break;
+    case VUT_GOVERNMENT:
+      cost = adv_reqs_cost(target_player, target_city, target_building,
+                           target_tile, target_unittype, target_output,
+                           target_specialist,
+                           &preq->source.value.govern->reqs);
+      break;
+    case VUT_IMPROVEMENT:
+      cost = adv_reqs_cost(target_player, target_city, target_building,
+                           target_tile, target_unittype, target_output,
+                           target_specialist,
+                           &preq->source.value.building->reqs);
+      cost += impr_build_shield_cost(preq->source.value.building);
+      break;
+    case VUT_SPECIAL:
+      break;    /* Cannot be modified. */
+    case VUT_TERRAIN:
+      /* FIXME */
+      break;
+    case VUT_NATION:
+      break;    /* Cannot change nation. */
+    case VUT_UTYPE:
+      {
+        const struct unit_type *punittype = preq->source.value.utype;
+        struct requirement req = { .survives = FALSE, .negated = FALSE };
+
+        cost = 0;
+        if (NULL != punittype->require_advance) {
+          req.source.kind = VUT_ADVANCE;
+          req.source.value.advance = punittype->require_advance;
+          req.range = REQ_RANGE_PLAYER;
+          cost += adv_req_cost(target_player, target_city, target_building,
+                               target_tile, target_unittype, target_output,
+                               target_specialist, &req);
+        }
+        if (NULL != punittype->need_improvement) {
+          req.source.kind = VUT_IMPROVEMENT;
+          req.source.value.building = punittype->need_improvement;
+          req.range = REQ_RANGE_CITY;
+          cost += adv_req_cost(target_player, target_city, target_building,
+                               target_tile, target_unittype, target_output,
+                               target_specialist, &req);
+        }
+        if (NULL != punittype->need_government) {
+          req.source.kind = VUT_GOVERNMENT;
+          req.source.value.govern = punittype->need_government;
+          req.range = REQ_RANGE_PLAYER;
+          cost += adv_req_cost(target_player, target_city, target_building,
+                               target_tile, target_unittype, target_output,
+                               target_specialist, &req);
+        }
+      }
+      break;
+    case VUT_UTFLAG:
+    case VUT_UCLASS:
+    case VUT_UCFLAG:
+      break;    /* Cannot be changed. */
+    case VUT_OTYPE:
+      break;
+    case VUT_SPECIALIST:
+      cost = adv_reqs_cost(target_player, target_city, target_building,
+                           target_tile, target_unittype, target_output,
+                           target_specialist,
+                           &preq->source.value.specialist->reqs);
+      break;
+    case VUT_MINSIZE:
+      /* FIXME */
+      break;
+    case VUT_AI_LEVEL:
+      break;
+    case VUT_TERRAINCLASS:
+      /* FIXME */
+      break;
+    case VUT_BASE:
+      cost = adv_reqs_cost(target_player, target_city, target_building,
+                           target_tile, target_unittype, target_output,
+                           target_specialist,
+                           &preq->source.value.base->reqs);
+      cost += preq->source.value.base->build_time;
+      break;
+    case VUT_MINYEAR:
+      break;
+    case VUT_TERRAINALTER:
+      /* FIXME */
+      break;
+    case VUT_CITYTILE:
+      break;
+    case VUT_COUNT:
+      break;
+    }
+  }
+
+  recursive--;
+  return cost;
+}
+
+/****************************************************************************
+  Returns the cost to meet all the requirements. 0 is returned when the
+  requirements are already met, -1 when the requirements cannot be met.
+****************************************************************************/
+int adv_reqs_cost(const struct player *target_player,
+                  const struct city *target_city,
+                  const struct impr_type *target_building,
+                  const struct tile *target_tile,
+                  const struct unit_type *target_unittype,
+                  const struct output_type *target_output,
+                  const struct specialist *target_specialist,
+                  const struct requirement_vector *preqs)
+{
+  int total_cost = 0;
+  int cost;
+
+  requirement_vector_iterate(preqs, preq) {
+    cost = adv_req_cost(target_player, target_city, target_building,
+                        target_tile, target_unittype, target_output,
+                        target_specialist, preq);
+    if (-1 == cost) {
+      return -1;
+    } else {
+      total_cost += cost;
+    }
+  } requirement_vector_iterate_end;
+  return total_cost;
+}
+
+/****************************************************************************
+  Returns the cost to meet all the requirements for the city. 0 is returned
+  when the requirements are already met, -1 when the requirements cannot
+  be met.
+****************************************************************************/
+int adv_city_cost(const struct city *pcity,
+                  const struct requirement_vector *preqs)
+{
+  return adv_reqs_cost(city_owner(pcity), pcity, NULL, city_tile(pcity),
+                       NULL, NULL, NULL, preqs);
+}
+
+/****************************************************************************
+  Returns the cost to meet all the requirements for the player. 0 is
+  returned when the requirements are already met, -1 when the requirements
+  cannot be met.
+****************************************************************************/
+int adv_player_cost(const struct player *pplayer,
+                    const struct requirement_vector *preqs)
+{
+  return adv_reqs_cost(pplayer, NULL, NULL, NULL, NULL, NULL, NULL, preqs);
+}
+
+/****************************************************************************
+  Returns the cost to meet all the requirements for the unit. 0 is returned
+  when the requirements are already met, -1 when the requirements cannot
+  be met.
+****************************************************************************/
+int adv_unit_cost(const struct unit *punit,
+                  const struct requirement_vector *preqs)
+{
+  const struct tile *ptile = unit_tile(punit);
+
+  return adv_reqs_cost(unit_owner(punit), tile_city(ptile), NULL, ptile,
+                       unit_type(punit), NULL, NULL, preqs);
+}
Index: server/advisors/advwant.h
===================================================================
--- server/advisors/advwant.h	(révision 0)
+++ server/advisors/advwant.h	(révision 0)
@@ -0,0 +1,44 @@
+/********************************************************************** 
+ Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+***********************************************************************/
+#ifndef FC__ADVWANT_H
+#define FC__ADVWANT_H
+
+/* common */
+#include "fc_types.h"
+#include "requirements.h"
+
+int adv_req_cost(const struct player *target_player,
+                 const struct city *target_city,
+                 const struct impr_type *target_building,
+                 const struct tile *target_tile,
+                 const struct unit_type *target_unittype,
+                 const struct output_type *target_output,
+                 const struct specialist *target_specialist,
+                 const struct requirement *preq);
+int adv_reqs_cost(const struct player *target_player,
+                  const struct city *target_city,
+                  const struct impr_type *target_building,
+                  const struct tile *target_tile,
+                  const struct unit_type *target_unittype,
+                  const struct output_type *target_output,
+                  const struct specialist *target_specialist,
+                  const struct requirement_vector *preqs);
+
+int adv_city_cost(const struct city *pcity,
+                  const struct requirement_vector *preqs);
+int adv_player_cost(const struct player *pplayer,
+                    const struct requirement_vector *preqs);
+int adv_unit_cost(const struct unit *punit,
+                  const struct requirement_vector *preqs);
+
+#endif /* FC__ADVWANT_H */
Index: server/advisors/Makefile.am
===================================================================
--- server/advisors/Makefile.am	(révision 17729)
+++ server/advisors/Makefile.am	(copie de travail)
@@ -10,6 +10,8 @@
 	advgoto.h	\
 	advtools.c	\
 	advtools.h	\
+	advwant.c	\
+	advwant.h	\
 	autoexplorer.c	\
 	autoexplorer.h	\
 	autosettlers.c	\
