[Freeciv-Dev] (PR#12554) Improve bodyguard grabbing
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: |
[Freeciv-Dev] (PR#12554) Improve bodyguard grabbing |
From: |
"Per I. Mathisen" <per@xxxxxxxxxxx> |
Date: |
Sat, 19 Mar 2005 15:45:10 -0800 |
Reply-to: |
bugs@xxxxxxxxxxx |
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12554 >
This small hack significantly improves the success rate of bodyguard
grabbing. Previous to this attacking units would usually run off without a
bodyguard simply because the potential guards did not have time to react.
I realize this may clash with Benedict's larger work on bodyguards, so I
am not sure this should be committed.
- Per
Index: ai/aitools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aitools.c,v
retrieving revision 1.139
diff -u -r1.139 aitools.c
--- ai/aitools.c 14 Mar 2005 20:26:24 -0000 1.139
+++ ai/aitools.c 19 Mar 2005 23:39:40 -0000
@@ -203,6 +238,31 @@
}
}
+ /* Grab a bodyguard from starting tile, if we can. This makes
+ * the problem of us racing away from any potential bodyguards
+ * slightly less. FIXME: This duplicates look_for_charge(),
+ * but is necessary since look_for_charge() may be run long
+ * after we're gone. */
+ if (punit->ai.bodyguard == BODYGUARD_WANTED) {
+ unit_list_iterate(punit->tile->units, aunit) {
+ int own_defense = DEFENCE_POWER(punit);
+
+ if (aunit->ai.ai_role == AIUNIT_NONE
+ && aunit->ai.charge <= BODYGUARD_NONE
+ && aunit->ai.bodyguard == BODYGUARD_NONE
+ && unit_type(punit)->move_type == unit_type(aunit)->move_type
+ && unit_move_rate(aunit) >= unit_move_rate(punit)
+ && DEFENCE_POWER(aunit) > own_defense
+ && ATTACK_POWER(aunit) < ATTACK_POWER(punit)) {
+ ai_unit_new_role(aunit, AIUNIT_ESCORT, NULL);
+ aunit->ai.charge = punit->id;
+ punit->ai.bodyguard = aunit->id;
+ BODYGUARD_LOG(LOGLEVEL_BODYGUARD, aunit, "grabbed on the way");
+ break;
+ }
+ } unit_list_iterate_end;
+ }
+
/* What if we have a bodyguard, but don't need one? */
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#12554) Improve bodyguard grabbing,
Per I. Mathisen <=
|
|