Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2004:
[Freeciv-Dev] (PR#11399) get_num_providers function
Home

[Freeciv-Dev] (PR#11399) get_num_providers function

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#11399) get_num_providers function
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 7 Dec 2004 21:18:51 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=11399 >

This patch replaces some WAG values that the AI code uses and that don't 
really work with changing specialists in the ruleset, with some new WAG 
values that also don't really work with changing specialists in the 
ruleset but at least compile.

Basically, in 2.0 the AI code assumes that if you can get 2 luxury or 1 
happiness from some source (like a temple or marketplace) and you have 
an elvis in play, you can put that elvis to work in the fields and get 
the full benefit of the best available workable tile.  Of course this is 
only accurate if an elvis-type specialist exists and if it provides 
exactly 2 luxury.

This patch just replaces that WAG with a similar one.  Any specialist 
that produces at least 2 luxury is assumed to be a luxury "provider" and 
counts for this bonus.

-jason

Index: ai/advdomestic.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/advdomestic.c,v
retrieving revision 1.123
diff -u -r1.123 advdomestic.c
--- ai/advdomestic.c    8 Dec 2004 04:18:09 -0000       1.123
+++ ai/advdomestic.c    8 Dec 2004 04:57:25 -0000
@@ -39,6 +39,42 @@
 
 #include "advdomestic.h"
 
+/**************************************************************************
+  Return the number of "providers".  This is the number of specialists
+  who provide at least 2 of the given output type.
+
+  The AI assumes that for any specialist that provides 2 luxury, if we
+  can get 2 luxury from some other source it allows the specialist to
+  become a worker.  The benefits from an extra worker are weighed against
+  the losses from acquiring the two extra luxury.
+
+  This is a very bad model if the abilities of specialists are changed.
+  But as long as the civ2 model of specialists is used it will continue
+  to work okay.
+**************************************************************************/
+int get_num_providers(Output_type_id otype,
+                     const struct city *pcity)
+{
+  int providers = 0;
+
+  specialist_type_iterate(i) {
+    if (game.rgame.specialists[i].bonus[otype] >= 2) {
+      providers += pcity->specialists[i];
+    }
+  } specialist_type_iterate_end;
+
+  return providers;
+}
+
+/**************************************************************************
+  Return the number of "non-providers".  See get_num_providers().
+**************************************************************************/
+int get_num_nonproviders(Output_type_id otype,
+                        const struct city *pcity)
+{
+  return city_specialists(pcity) - get_num_providers(otype, pcity);
+}
+
 /***************************************************************************
  * Evaluate the need for units (like caravans) that aid wonder construction.
  * If another city is building wonder and needs help but pplayer is not
@@ -149,9 +185,8 @@
   Unit_Type_id unit_type;
   /* Food surplus assuming that workers and elvii are already accounted for
    * and properly balanced. */
-  int est_food = pcity->surplus[O_FOOD]
-                 + 2 * pcity->specialists[SP_SCIENTIST]
-                 + 2 * pcity->specialists[SP_TAXMAN];
+  int est_food = (pcity->surplus[O_FOOD]
+                 + 2 * get_num_nonproviders(O_LUXURY, pcity));
 
   init_choice(choice);
 
Index: ai/advdomestic.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/advdomestic.h,v
retrieving revision 1.8
diff -u -r1.8 advdomestic.h
--- ai/advdomestic.h    13 Sep 2004 15:54:49 -0000      1.8
+++ ai/advdomestic.h    8 Dec 2004 04:57:25 -0000
@@ -17,6 +17,9 @@
 
 struct ai_choice;
 
+int get_num_providers(Output_type_id otype, const struct city *pcity);
+int get_num_nonproviders(Output_type_id otype, const struct city *pcity);
+
 void ai_eval_threat_init(struct player *pplayer);
 void ai_eval_threat_done(struct player *pplayer);
 void domestic_advisor_choose_build(struct player *pplayer, struct city *pcity,
Index: ai/aicity.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aicity.c,v
retrieving revision 1.179
diff -u -r1.179 aicity.c
--- ai/aicity.c 5 Dec 2004 09:01:00 -0000       1.179
+++ ai/aicity.c 8 Dec 2004 04:57:25 -0000
@@ -272,18 +272,21 @@
             /* TODO */
             break;
          case EFT_NO_UNHAPPY:
-            v += (pcity->specialists[SP_ELVIS] + pcity->ppl_unhappy[4]) * 20;
+            v += (get_num_providers(O_LUXURY, pcity)
+                 + pcity->ppl_unhappy[4]) * 20;
             break;
          case EFT_FORCE_CONTENT:
            if (!government_has_flag(gov, G_NO_UNHAPPY_CITIZENS)) {
-             v += (pcity->ppl_unhappy[4] + pcity->specialists[SP_ELVIS]) * 20;
+             v += (pcity->ppl_unhappy[4]
+                   + get_num_providers(O_LUXURY, pcity)) * 20;
              v += 5 * c;
            }
            break;
          case EFT_MAKE_CONTENT_MIL_PER:
          case EFT_MAKE_CONTENT:
            if (!government_has_flag(gov, G_NO_UNHAPPY_CITIZENS)) {
-              v += MIN(pcity->ppl_unhappy[4] + pcity->specialists[SP_ELVIS],
+              v += MIN(pcity->ppl_unhappy[4]
+                      + get_num_providers(O_LUXURY, pcity),
                        amount) * 20;
               v += MIN(amount, 5) * c;
            }
@@ -1062,7 +1065,7 @@
       is_valid = map_to_city_map(&city_map_x, &city_map_y, acity, ptile);
       assert(is_valid);
       server_remove_worker_city(acity, city_map_x, city_map_y);
-      acity->specialists[SP_ELVIS]++;
+      acity->specialists[DEFAULT_SPECIALIST]++;
       if (!city_list_find_id(&minilist, acity->id)) {
        city_list_insert(&minilist, acity);
       }

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#11399) get_num_providers function, Jason Short <=