[Freeciv-Dev] Re: (PR#4119) Reducing want when we AI has many units
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
On Wed, 30 Apr 2003, ue80@xxxxxxxxxxxxxxxxxxxxx wrote:
> AI doesn't stop building something after it has much of that unit.
Yes. This is a beginning: This patch stops the AI from churning out
diplomat after diplomat, turn after turn, towards a city at a distance
which takes several turns to reach.
It also removes the ugly already_considered_for_diplomat hack.
- Per
Index: ai/aidata.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aidata.c,v
retrieving revision 1.13
diff -u -r1.13 aidata.c
--- ai/aidata.c 29 Apr 2003 08:40:11 -0000 1.13
+++ ai/aidata.c 30 Apr 2003 14:15:04 -0000
@@ -190,10 +190,20 @@
ai->stats.average_production += pcity->shield_surplus;
} city_list_iterate_end;
ai->stats.average_production /= MAX(1, city_list_size(&pplayer->cities));
+ BV_CLR_ALL(ai->stats.diplomat_reservations);
unit_list_iterate(pplayer->units, punit) {
struct tile *ptile = map_get_tile(punit->x, punit->y);
+
if (!is_ocean(ptile->terrain) && unit_flag(punit, F_SETTLERS)) {
ai->stats.workers[(int)map_get_continent(punit->x, punit->y)]++;
+ }
+ if (unit_flag(punit, F_DIPLOMAT) && punit->ai.ai_role == AIUNIT_ATTACK) {
+ /* Heading somewhere on a mission, reserve target. */
+ struct city *pcity = map_get_city(punit->goto_dest_x,
+ punit->goto_dest_y);
+ if (pcity) {
+ BV_SET(ai->stats.diplomat_reservations, pcity->id);
+ }
}
} unit_list_iterate_end;
Index: ai/aidata.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aidata.h,v
retrieving revision 1.7
diff -u -r1.7 aidata.h
--- ai/aidata.h 29 Apr 2003 08:40:11 -0000 1.7
+++ ai/aidata.h 30 Apr 2003 14:15:04 -0000
@@ -13,6 +13,9 @@
#ifndef FC__AIDATA_H
#define FC__AIDATA_H
+/* max size of a short */
+#define MAX_NUM_ID 32767
+
#include "shared.h" /* bool type */
struct player;
@@ -30,6 +33,7 @@
bool is_allied_with_ally;
};
+BV_DEFINE(bv_id, MAX_NUM_ID);
struct ai_data {
/* AI diplomacy and opinions on other players */
struct {
@@ -54,12 +58,13 @@
bool sea_done; /* nothing more to explore at sea */
} explore;
- /* this struct is used for statistical unit building, to ensure
+ /* This struct is used for statistical unit building, to ensure
that we don't build too few or too many units of a given type */
struct {
int *workers; /* cities to workers on continent*/
int *cities; /* number of cities on continent */
int average_production;
+ bv_id diplomat_reservations;
} stats;
int num_continents; /* last time we updated our continent data */
Index: ai/aidiplomat.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aidiplomat.c,v
retrieving revision 1.17
diff -u -r1.17 aidiplomat.c
--- ai/aidiplomat.c 18 Apr 2003 17:51:14 -0000 1.17
+++ ai/aidiplomat.c 30 Apr 2003 14:15:04 -0000
@@ -48,6 +48,7 @@
#include "advmilitary.h"
#include "aicity.h"
+#include "aidata.h"
#include "aihand.h"
#include "ailog.h"
#include "aitools.h"
@@ -137,6 +138,7 @@
struct ai_choice *choice)
{
Unit_Type_id u = best_role_unit(pcity, F_DIPLOMAT);
+ struct ai_data *ai = ai_data_get(pplayer);
if (u >= U_LAST) {
/* We don't know diplomats yet! */
@@ -159,7 +161,7 @@
find_city_to_diplomat(pplayer, punit, &acity, &time_to_dest);
- if (acity == NULL || acity->ai.already_considered_for_diplomat) {
+ if (acity == NULL || BV_ISSET(ai->stats.diplomat_reservations, acity->id))
{
/* Found no target or city already considered */
return;
}
@@ -222,7 +224,7 @@
choice->want = want;
choice->type = CT_NONMIL; /* so we don't build barracks for it */
choice->choice = u;
- acity->ai.already_considered_for_diplomat = TRUE;
+ BV_SET(ai->stats.diplomat_reservations, acity->id);
}
destroy_unit_virtual(punit);
}
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.125
diff -u -r1.125 city.h
--- common/city.h 4 Feb 2003 17:07:43 -0000 1.125
+++ common/city.h 30 Apr 2003 14:15:05 -0000
@@ -202,9 +202,6 @@
int invasion; /* who's coming to kill us, for attack co-ordination */
int attack, bcost; /* This is also for invasion - total power and value of
* all units coming to kill us. */
-
- /* Used by _other_ cities temporarily while assigning diplomat targets */
- bool already_considered_for_diplomat;
};
struct city {
Index: server/citytools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/citytools.c,v
retrieving revision 1.215
diff -u -r1.215 citytools.c
--- server/citytools.c 17 Apr 2003 20:06:36 -0000 1.215
+++ server/citytools.c 30 Apr 2003 14:15:05 -0000
@@ -1057,7 +1057,6 @@
pcity->ai.danger = 0;
pcity->ai.urgency = 0;
pcity->ai.grave_danger = 0;
- pcity->ai.already_considered_for_diplomat = FALSE;
pcity->corruption = 0;
pcity->shield_waste = 0;
pcity->shield_bonus = 100;
Index: server/cityturn.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityturn.c,v
retrieving revision 1.210
diff -u -r1.210 cityturn.c
--- server/cityturn.c 9 Apr 2003 03:54:46 -0000 1.210
+++ server/cityturn.c 30 Apr 2003 14:15:05 -0000
@@ -397,7 +397,6 @@
void begin_cities_turn(struct player *pplayer)
{
city_list_iterate(pplayer->cities, pcity) {
- pcity->ai.already_considered_for_diplomat = FALSE; /* ai hack */
define_orig_production_values(pcity);
} city_list_iterate_end;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] Re: (PR#4119) Reducing want when we AI has many units,
Per I. Mathisen <=
|
|