[freeciv-ai] Re: [Freeciv-Dev] (PR#12545) [Patch] ai.invasion cleanup
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12545 >
Marko Lindqvist wrote:
> Marko Lindqvist wrote:
>>
>> I had hard time trying to figure out how ai.invasion works. Attached
>> patch makes it a bit more obvious.
>> No behavior changes, even though (IMHO) this less obscure code makes
>> some weaknesses more obvious.
>
> This forgotten patch still seems to apply without update. I'll test
> that it also works and then commit.
It was buggy. New version got through my regression tests ok.
- ML
diff -Nurd -X.diff_ignore freeciv/ai/advmilitary.c freeciv/ai/advmilitary.c
--- freeciv/ai/advmilitary.c 2006-07-02 17:26:26.562500000 +0300
+++ freeciv/ai/advmilitary.c 2006-07-02 19:56:20.937500000 +0300
@@ -892,10 +892,11 @@
if (move_type != LAND_MOVING && vuln == 0) {
desire = 0;
- } else if ((move_type == LAND_MOVING || move_type == HELI_MOVING)
- && acity && acity->ai.invasion == 2) {
+ } else if ((move_type == LAND_MOVING || move_type == HELI_MOVING) &&
acity
+ && TEST_BIT(acity->ai.invasion, INVASION_ATTACK)
+ && !TEST_BIT(acity->ai.invasion, INVASION_OCCUPY)) {
desire = bcost * SHIELD_WEIGHTING;
-
+
} else {
if (!acity) {
desire = kill_desire(value, attack, bcost, vuln, victim_count);
@@ -1103,7 +1104,7 @@
def_owner = pdef->owner;
}
}
- if (COULD_OCCUPY(myunit) || TEST_BIT(acity->ai.invasion, 0)) {
+ if (COULD_OCCUPY(myunit) || TEST_BIT(acity->ai.invasion, INVASION_OCCUPY))
{
/* bonus for getting the city */
benefit += 40;
}
diff -Nurd -X.diff_ignore freeciv/ai/aiair.c freeciv/ai/aiair.c
--- freeciv/ai/aiair.c 2006-07-02 17:26:26.890625000 +0300
+++ freeciv/ai/aiair.c 2006-07-02 18:57:35.546875000 +0300
@@ -75,7 +75,7 @@
/* TODO: There is a danger of producing too many units that will not
* attack anything. Production should not happen if there is an idle
* unit of the same type nearby */
- if (acity && !TEST_BIT(acity->ai.invasion, 0) && punit->id != 0) {
+ if (acity && !TEST_BIT(acity->ai.invasion, INVASION_OCCUPY) && punit->id !=
0) {
/* No ground troups are invading */
freelog(LOG_DEBUG, "Don't want to attack %s, although we could",
acity->name);
diff -Nurd -X.diff_ignore freeciv/ai/aiunit.c freeciv/ai/aiunit.c
--- freeciv/ai/aiunit.c 2006-07-02 17:26:28.031250000 +0300
+++ freeciv/ai/aiunit.c 2006-07-02 20:15:03.125000000 +0300
@@ -1140,10 +1140,9 @@
Mark invasion possibilities of punit in the surrounding cities. The
given radius limites the area which is searched for cities. The
center of the area is either the unit itself (dest == FALSE) or the
- destiniation of the current goto (dest == TRUE). The invasion threat
- is marked in pcity->ai.invasion via ORing the "which" argument (to
- tell attack from sea apart from ground unit attacks). Note that
- "which" should only have one bit set.
+ destination of the current goto (dest == TRUE). The invasion threat
+ is marked in pcity->ai.invasion by setting the "which" bit (to
+ tell attack from sea apart from ground unit attacks).
If dest == TRUE then a valid goto is presumed.
**************************************************************************/
@@ -1167,9 +1166,9 @@
if (pcity
&& HOSTILE_PLAYER(pplayer, ai, city_owner(pcity))
- && (pcity->ai.invasion & which) != which
+ && !TEST_BIT(pcity->ai.invasion, which)
&& (dest || !has_defense(pcity))) {
- pcity->ai.invasion |= which;
+ pcity->ai.invasion |= COND_SET_BIT(TRUE, which);
}
} square_iterate_end;
}
@@ -1268,21 +1267,22 @@
/* dealing with invasion stuff */
if (IS_ATTACKER(aunit)) {
if (aunit->activity == ACTIVITY_GOTO) {
- invasion_funct(aunit, TRUE, 0, (COULD_OCCUPY(aunit) ? 1 : 2));
+ invasion_funct(aunit, TRUE, 0,
+ (COULD_OCCUPY(aunit) ? INVASION_OCCUPY :
INVASION_ATTACK));
if ((pcity = tile_get_city(aunit->goto_tile))) {
pcity->ai.attack += unit_att_rating(aunit);
pcity->ai.bcost += unit_build_shield_cost(aunit->type);
}
}
invasion_funct(aunit, FALSE, unit_move_rate(aunit) / SINGLE_MOVE,
- (COULD_OCCUPY(aunit) ? 1 : 2));
+ (COULD_OCCUPY(aunit) ? INVASION_OCCUPY :
INVASION_ATTACK));
} else if (aunit->ai.passenger != 0 &&
!same_pos(aunit->tile, punit->tile)) {
/* It's a transport with reinforcements */
if (aunit->activity == ACTIVITY_GOTO) {
- invasion_funct(aunit, TRUE, 1, 1);
+ invasion_funct(aunit, TRUE, 1, INVASION_OCCUPY);
}
- invasion_funct(aunit, FALSE, 2, 1);
+ invasion_funct(aunit, FALSE, 2, INVASION_OCCUPY);
}
} unit_list_iterate_end;
/* end horrible initialization subroutine */
@@ -1400,7 +1400,7 @@
}
}
- if (COULD_OCCUPY(punit) || TEST_BIT(acity->ai.invasion, 0)) {
+ if (COULD_OCCUPY(punit) || TEST_BIT(acity->ai.invasion,
INVASION_OCCUPY)) {
/* There are units able to occupy the city! */
benefit += 40;
}
@@ -1422,7 +1422,9 @@
} else if (move_time > THRESHOLD) {
/* Too far! */
want = 0;
- } else if (COULD_OCCUPY(punit) && acity->ai.invasion == 2) {
+ } else if (COULD_OCCUPY(punit)
+ && TEST_BIT(acity->ai.invasion, INVASION_ATTACK)
+ && !TEST_BIT(acity->ai.invasion, INVASION_OCCUPY)) {
/* Units able to occupy really needed there! */
want = bcost * SHIELD_WEIGHTING;
} else {
diff -Nurd -X.diff_ignore freeciv/ai/aiunit.h freeciv/ai/aiunit.h
--- freeciv/ai/aiunit.h 2006-07-02 17:26:28.046875000 +0300
+++ freeciv/ai/aiunit.h 2006-07-02 19:06:07.484375000 +0300
@@ -49,6 +49,10 @@
(ut->pop_cost * 3 + ut->happy_cost \
+ ut->upkeep[O_SHIELD] + ut->upkeep[O_FOOD] + ut->upkeep[O_GOLD])
+/* INVASION bits */
+#define INVASION_OCCUPY 0
+#define INVASION_ATTACK 1
+
struct ai_choice;
struct pf_path;
|
|