[freeciv-ai] Re: [Freeciv-Dev] (PR#9866) S1_14: AI fixes
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: |
undisclosed-recipients: ; |
Subject: |
[freeciv-ai] Re: [Freeciv-Dev] (PR#9866) S1_14: AI fixes |
From: |
"Per I. Mathisen" <per@xxxxxxxxxxx> |
Date: |
Tue, 31 Aug 2004 08:31:35 -0700 |
Reply-to: |
rt@xxxxxxxxxxx |
<URL: http://rt.freeciv.org/Ticket/Display.html?id=9866 >
On Sun, 29 Aug 2004, Gregory Berkolaiko wrote:
> Your latest patch in the "fun Ai game" thread does much better job: it
> retains the check for whether we got assigned to the city and it compares
> with defense rather than 0.
>
> So I suggest we use it to fix S-branch.
Ok, here is the latest patch for cvs head, as I commit it. Changes since
last version is a check that we don't accidentially make an allied city to
our homecity, and assert in ai_unit_make_homecity() that this is not
attempted by other code. And some extra comments.
- Per
Index: ai/aitools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aitools.c,v
retrieving revision 1.120
diff -u -r1.120 aitools.c
--- ai/aitools.c 27 Aug 2004 17:36:52 -0000 1.120
+++ ai/aitools.c 31 Aug 2004 15:29:16 -0000
@@ -399,6 +399,8 @@
bool ai_unit_make_homecity(struct unit *punit, struct city *pcity)
{
CHECK_UNIT(punit);
+ assert(punit->owner == pcity->owner);
+
if (punit->homecity == 0 && !unit_has_role(punit->type, L_EXPLORER)) {
/* This unit doesn't pay any upkeep while it doesn't have a homecity,
* so it would be stupid to give it one. There can also be good reasons
Index: ai/aiunit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.c,v
retrieving revision 1.330
diff -u -r1.330 aiunit.c
--- ai/aiunit.c 29 Aug 2004 20:14:41 -0000 1.330
+++ ai/aiunit.c 31 Aug 2004 15:29:16 -0000
@@ -328,7 +328,7 @@
/**************************************************************************
Return whether we should stay and defend a square, usually a city. Will
- protect allied cities temporarily.
+ protect allied cities temporarily in case of grave danger.
FIXME: We should check for fortresses here.
**************************************************************************/
@@ -336,30 +336,40 @@
{
struct city *pcity = map_get_city(punit->x, punit->y);
bool has_defense = FALSE;
-
- CHECK_UNIT(punit);
+ int mydef;
+ int units = -2; /* WAG for grave danger threshold, seems to work */
if (!pcity) {
return FALSE;
}
+ mydef = assess_defense_unit(pcity, punit, FALSE);
unit_list_iterate(map_get_tile(pcity->x, pcity->y)->units, pdef) {
- if (assess_defense_unit(pcity, punit, FALSE) >= 0
+ if (assess_defense_unit(pcity, pdef, FALSE) >= mydef
&& pdef != punit
&& pdef->homecity == pcity->id) {
has_defense = TRUE;
}
+ units++;
} unit_list_iterate_end;
/* Guess I better stay / you can live at home now */
- if (!has_defense && pcity->ai.danger > 0) {
- /* change homecity to this city */
+ if (!has_defense && pcity->ai.danger > 0 && punit->owner == pcity->owner) {
+ /* Change homecity to this city */
if (ai_unit_make_homecity(punit, pcity)) {
/* Very important, or will not stay -- Syela */
ai_unit_new_role(punit, AIUNIT_DEFEND_HOME, pcity->x, pcity->y);
return TRUE;
- }
+ } /* else city cannot upkeep us! */
}
+
+ /* Treat grave danger anyway if danger is over threshold, which is the
+ * number of units currently in the city. */
+ if (pcity->ai.grave_danger > units) {
+ ai_unit_new_role(punit, AIUNIT_DEFEND_HOME, pcity->x, pcity->y);
+ return TRUE;
+ }
+
return FALSE;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freeciv-ai] Re: [Freeciv-Dev] (PR#9866) S1_14: AI fixes,
Per I. Mathisen <=
|
|