[Freeciv-Dev] Re: (PR#18566) [Patch] Remove F_CARRIER checks from AI cod
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: |
[Freeciv-Dev] Re: (PR#18566) [Patch] Remove F_CARRIER checks from AI code |
From: |
"Marko Lindqvist" <cazfi74@xxxxxxxxx> |
Date: |
Thu, 13 Jul 2006 15:31:31 -0700 |
Reply-to: |
bugs@xxxxxxxxxxx |
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=18566 >
Marko Lindqvist wrote:
>
> Marko Lindqvist wrote:
>> This replaces F_CARRIER and F_MISSILE_CARRIER checks with calls to
>> can_unit_type_transport() in AI code.
>
> Missed one F_MISSILE_CARRIER check.
> That code (ai_fill_unit_param()) tagged normal carriers as ferries.
> Have to check if that was intentional and what to do if it was.
I don't understand how, but I had managed to miss still one
F_MISSILE_CARRIER case.
- ML
diff -Nurd -X.diff_ignore freeciv/ai/aihunt.c freeciv/ai/aihunt.c
--- freeciv/ai/aihunt.c 2006-07-14 00:57:05.062500000 +0300
+++ freeciv/ai/aihunt.c 2006-07-14 00:57:45.265625000 +0300
@@ -83,10 +83,14 @@
* ut->move_rate
+ ut->defense_strength) / MAX(UNITTYPE_COSTS(ut), 1);
- if (unit_type_flag(ut, F_CARRIER)
- || unit_type_flag(ut, F_MISSILE_CARRIER)) {
- desire += desire / 6;
- }
+ unit_class_iterate(uclass) {
+ if (can_unit_type_transport(ut, uclass)
+ && unit_class_flag(uclass, UCF_MISSILE)) {
+ desire += desire / 6;
+ break;
+ }
+ } unit_class_iterate_end;
+
if (unit_type_flag(ut, F_IGTER)) {
desire += desire / 2;
}
@@ -123,20 +127,24 @@
{
int best = -1;
struct unit_type *best_unit_type = NULL;
- bool have_hunter = FALSE;
+ struct unit *hunter = NULL;
unit_list_iterate(pcity->tile->units, punit) {
- if (ai_hunter_qualify(pplayer, punit)
- && (unit_flag(punit, F_MISSILE_CARRIER)
- || unit_flag(punit, F_CARRIER))) {
- /* There is a potential hunter in our city which we can equip
- * with a missile. Do it. */
- have_hunter = TRUE;
- break;
+ if (ai_hunter_qualify(pplayer, punit)) {
+ unit_class_iterate(uclass) {
+ if (can_unit_type_transport(unit_type(punit), uclass)
+ && unit_class_flag(uclass, UCF_MISSILE)) {
+ hunter = punit;
+ break;
+ }
+ } unit_class_iterate_end;
+ if (hunter) {
+ break;
+ }
}
} unit_list_iterate_end;
- if (!have_hunter) {
+ if (!hunter) {
return;
}
@@ -147,6 +155,10 @@
continue;
}
+ if (!can_unit_type_transport(unit_type(hunter), get_unit_class(ut))) {
+ continue;
+ }
+
/* FIXME: We need to store some data that can tell us if
* enemy transports are protected by anti-missile technology.
* In this case, want nuclear much more! */
diff -Nurd -X.diff_ignore freeciv/ai/aitools.c freeciv/ai/aitools.c
--- freeciv/ai/aitools.c 2006-07-14 00:57:05.125000000 +0300
+++ freeciv/ai/aitools.c 2006-07-14 00:57:45.281250000 +0300
@@ -642,9 +642,6 @@
struct ai_risk_cost *risk_cost,
struct unit *punit, struct tile *ptile)
{
- const bool is_ferry = get_transporter_capacity(punit) > 0
- && !unit_flag(punit, F_MISSILE_CARRIER)
- && punit->ai.ai_role != AIUNIT_HUNTER;
const bool is_air = is_air_unit(punit)
&& punit->ai.ai_role != AIUNIT_ESCORT;
const bool long_path = LONG_TIME < (map_distance(punit->tile, punit->tile)
@@ -652,6 +649,18 @@
/ unit_type(punit)->move_rate);
const bool barbarian = is_barbarian(unit_owner(punit));
const bool is_ai = unit_owner(punit)->ai.control;
+ bool is_ferry = FALSE;
+
+ if (punit->ai.ai_role != AIUNIT_HUNTER
+ && get_transporter_capacity(punit) > 0) {
+ unit_class_iterate(uclass) {
+ if (can_unit_type_transport(unit_type(punit), uclass)
+ && uclass->move_type == LAND_MOVING) {
+ is_ferry = TRUE;
+ break;
+ }
+ } unit_class_iterate_end;
+ }
if (is_ferry) {
/* The destination may be a coastal land tile,
@@ -858,20 +867,17 @@
UNIT_LOG(LOGLEVEL_HUNT, target, "is being hunted");
/* Grab missiles lying around and bring them along */
- if (unit_flag(punit, F_MISSILE_CARRIER)
- || unit_flag(punit, F_CARRIER)) {
- unit_list_iterate(punit->tile->units, missile) {
- if (missile->ai.ai_role != AIUNIT_ESCORT
- && missile->transported_by == -1
- && missile->owner == punit->owner
- && unit_class_flag(get_unit_class(unit_type(missile)), UCF_MISSILE)
- && can_unit_load(missile, punit)) {
- UNIT_LOG(LOGLEVEL_HUNT, missile, "loaded on hunter");
- ai_unit_new_role(missile, AIUNIT_ESCORT, target->tile);
- load_unit_onto_transporter(missile, punit);
- }
- } unit_list_iterate_end;
- }
+ unit_list_iterate(punit->tile->units, missile) {
+ if (missile->ai.ai_role != AIUNIT_ESCORT
+ && missile->transported_by == -1
+ && missile->owner == punit->owner
+ && unit_class_flag(get_unit_class(unit_type(missile)), UCF_MISSILE)
+ && can_unit_load(missile, punit)) {
+ UNIT_LOG(LOGLEVEL_HUNT, missile, "loaded on hunter");
+ ai_unit_new_role(missile, AIUNIT_ESCORT, target->tile);
+ load_unit_onto_transporter(missile, punit);
+ }
+ } unit_list_iterate_end;
}
}
diff -Nurd -X.diff_ignore freeciv/ai/aiunit.c freeciv/ai/aiunit.c
--- freeciv/ai/aiunit.c 2006-07-14 00:45:01.984375000 +0300
+++ freeciv/ai/aiunit.c 2006-07-14 01:08:00.781250000 +0300
@@ -2077,6 +2077,7 @@
void ai_manage_unit(struct player *pplayer, struct unit *punit)
{
struct unit *bodyguard = aiguard_guard_of(punit);
+ bool is_ferry = FALSE;
CHECK_UNIT(punit);
@@ -2111,6 +2112,15 @@
return;
}
+ if (get_transporter_capacity(punit) > 0) {
+ unit_class_iterate(pclass) {
+ if (pclass->move_type == LAND_MOVING
+ && can_unit_type_transport(unit_type(punit), pclass)) {
+ is_ferry = TRUE;
+ }
+ } unit_class_iterate_end;
+ }
+
if ((unit_flag(punit, F_DIPLOMAT))
|| (unit_flag(punit, F_SPY))) {
TIMING_LOG(AIT_DIPLOMAT, TIMER_START);
@@ -2133,9 +2143,7 @@
} else if (unit_flag(punit, F_PARATROOPERS)) {
ai_manage_paratrooper(pplayer, punit);
return;
- } else if (get_transporter_capacity(punit) > 0
- && !unit_flag(punit, F_MISSILE_CARRIER)
- && punit->ai.ai_role != AIUNIT_HUNTER) {
+ } else if (is_ferry && punit->ai.ai_role != AIUNIT_HUNTER) {
TIMING_LOG(AIT_FERRY, TIMER_START);
ai_manage_ferryboat(pplayer, punit);
TIMING_LOG(AIT_FERRY, TIMER_STOP);
|
|