[freeciv-ai] Re: (PR#3467) AI idles fortifying units that do not move
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Quoting Gregory Berkolaiko <Gregory.Berkolaiko@xxxxxxxxxxxx>:
> On Wed, 19 Feb 2003, Per I. Mathisen wrote:
>
> > And why can't you use ai_unit_goto()? And why didn't you tell my earlier
> > so I could fix it?
>
> Sorry. I looked up my earlier email, it's a different thing we can't use:
> ======
> Problem 2: verrrry slow. The problem is two-fold. First, you don't set
> activity to IDLE, so handle_unit_move_request fails and you have to
> generate warmap for _every_ move.
> ======
> And I guess we can/should use ai_unit_goto instead of
> handle_unit_move_request.
>
> I would prefer to fix this as a part of a bigger patch, changing EXPLORE
> from activity to auto-mode. If you have no objections, I will talk to
> Cameron about it.
Talked to Cameron,he said he is too busy. I also cannot be bothered to change
EXPLORE into an auto-mode (yeah, okay, it would be right thing to do so, but it
wouldn't influence much). So I cooked up a quick fix, together with some
cleaning up and commenting. Essentially I moved IDLEing to where it is
immediately needed.
G.
? core.1854
? core.9656
? core.9661
Index: ai/aiunit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.c,v
retrieving revision 1.270
diff -u -r1.270 aiunit.c
--- ai/aiunit.c 2003/03/07 05:08:41 1.270
+++ ai/aiunit.c 2003/03/22 19:04:25
@@ -498,6 +498,9 @@
explores unknown territory, finds huts.
Returns whether there is any more territory to be explored.
+
+TODO: Convert to using new Path Finding, thus unifying Parts 1 and 2 (in
+doing so one should aim to break the PF-loop early, to avoid slow-down).
**************************************************************************/
bool ai_manage_explorer(struct unit *punit)
{
@@ -505,12 +508,6 @@
/* The position of the unit; updated inside the function */
int x = punit->x, y = punit->y;
- /* Idle unit, since otherwise handle_unit_move_request fails!
- * TODO: Fix it and remove this idling */
- if (punit->activity != ACTIVITY_IDLE) {
- handle_unit_activity_request(punit, ACTIVITY_IDLE);
- }
-
/*
* PART 1: Move into unexplored territory
* Move the unit as long as moving will unveil unknown territory
@@ -549,28 +546,40 @@
/* We can die because easy AI may stumble on huts and so disappear
* in the wilderness - unit_id is used to check this */
int unit_id = punit->id;
- bool broken = TRUE; /* failed movement */
+ bool move_success;
/* Some tile has unexplored territory adjacent, let's move there. */
/* ai_unit_move for AI players, handle_unit_move_request for humans */
- if ((pplayer->ai.control && ai_unit_move(punit, best_x, best_y))
- || (!pplayer->ai.control
- && handle_unit_move_request(punit, best_x, best_y,
- FALSE, FALSE))) {
- x = punit->x;
- y = punit->y;
- broken = FALSE;
+ if (pplayer->ai.control) {
+ move_success = ai_unit_move(punit, best_x, best_y);
+ } else {
+ /* Need to idle unit otherwise handle_unit_move_request fails.
+ * We can use ai_unit_goto, but it's a bit wasteful here... */
+
+ if (punit->activity != ACTIVITY_IDLE) {
+ handle_unit_activity_request(punit, ACTIVITY_IDLE);
+ }
+ move_success = handle_unit_move_request(punit, best_x, best_y,
+ FALSE, FALSE);
}
if (!player_find_unit_by_id(pplayer, unit_id)) {
/* We're dead. */
return FALSE;
}
+
+ if (move_success) {
+ /* We moved, update our current position */
+ x = punit->x;
+ y = punit->y;
+ } else {
+ /* Move failed, break to avoid an endless loop */
+ break;
+ }
- if (broken) { break; } /* a move failed, so danger of endless loop */
} else {
- /* Everything is already explored. */
+ /* Everything immediately beside us is already explored. */
break;
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freeciv-ai] Re: (PR#3467) AI idles fortifying units that do not move,
Gregory Berkolaiko <=
|
|