[Freeciv-Dev] (PR#7324) orders and AI goto conflict
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=7324 >
> ...
>
> Either an assertion
>
> assert(ai_role_unit(...) == AIUNIT_NONE);
>
> or a check
>
> ai_set_role_unit(..., AIUNIT_NONE);
>
> should be added to handle_unit_orders, eventually.
>
> jason
>
>
Done. Used ai_unit_set_role.
diff -ruN -X freeciv-cvs-Jan-27/diff_ignore freeciv-cvs-Jan-27/ai/aitools.c
freeciv-cvs-Jan-27-ai-orders-fix/ai/aitools.c
--- freeciv-cvs-Jan-27/ai/aitools.c 2003-11-28 22:05:21.000000000 -0800
+++ freeciv-cvs-Jan-27-ai-orders-fix/ai/aitools.c 2004-01-28
18:13:55.000000000 -0800
@@ -429,6 +429,8 @@
struct unit *charge = find_unit_by_id(punit->ai.charge);
struct unit *bodyguard = find_unit_by_id(punit->ai.bodyguard);
+ assert(!unit_has_orders(punit));
+
/* Free our ferry. Most likely it has been done already. */
if (task == AIUNIT_NONE || task == AIUNIT_DEFEND_HOME) {
ai_clear_ferry(punit);
diff -ruN -X freeciv-cvs-Jan-27/diff_ignore freeciv-cvs-Jan-27/ai/aiunit.c
freeciv-cvs-Jan-27-ai-orders-fix/ai/aiunit.c
--- freeciv-cvs-Jan-27/ai/aiunit.c 2004-01-11 22:16:14.000000000 -0800
+++ freeciv-cvs-Jan-27-ai-orders-fix/ai/aiunit.c 2004-01-28
18:13:55.000000000 -0800
@@ -2586,6 +2586,13 @@
CHECK_UNIT(punit);
+ /* Make sure the unit doesn't have orders - human control always has
+ * precedence. */
+ if (unit_has_orders(punit)) {
+ punit->ai.ai_role = AIUNIT_NONE;
+ return;
+ }
+
/* retire useless barbarian units here, before calling the management
function */
if( is_barbarian(pplayer) ) {
diff -ruN -X freeciv-cvs-Jan-27/diff_ignore
freeciv-cvs-Jan-27/server/settlers.c
freeciv-cvs-Jan-27-ai-orders-fix/server/settlers.c
--- freeciv-cvs-Jan-27/server/settlers.c 2004-01-11 22:16:30.000000000
-0800
+++ freeciv-cvs-Jan-27-ai-orders-fix/server/settlers.c 2004-01-28
18:13:55.000000000 -0800
@@ -1312,10 +1312,16 @@
freelog(LOG_DEBUG, "Warmth = %d, game.globalwarming=%d",
pplayer->ai.warmth, game.globalwarming);
+
+ /* Auto-settle with a settler unit if it's under AI control (e.g. human
+ * player auto-settler mode) or if the player is an AI. But don't
+ * auto-settle with a unit under orders even for an AI player - these come
+ * from the human player and take precedence. */
unit_list_iterate(pplayer->units, punit) {
if ((punit->ai.control || pplayer->ai.control)
&& (unit_flag(punit, F_SETTLERS)
- || unit_flag(punit, F_CITIES))) {
+ || unit_flag(punit, F_CITIES))
+ && !unit_has_orders(punit)) {
freelog(LOG_DEBUG, "%s's settler at (%d, %d) is ai controlled.",
pplayer->name, punit->x, punit->y);
if (punit->activity == ACTIVITY_SENTRY) {
diff -ruN -X freeciv-cvs-Jan-27/diff_ignore
freeciv-cvs-Jan-27/server/unithand.c
freeciv-cvs-Jan-27-ai-orders-fix/server/unithand.c
--- freeciv-cvs-Jan-27/server/unithand.c 2004-01-27 22:15:49.000000000
-0800
+++ freeciv-cvs-Jan-27-ai-orders-fix/server/unithand.c 2004-01-28
18:26:27.000000000 -0800
@@ -1,4 +1,4 @@
-/**********************************************************************
+/**********************************************************************
Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1517,7 +1517,9 @@
}
}
+ /* Free any current orders and any AI role */
free_unit_orders(punit);
+ ai_unit_new_role(punit, AIUNIT_NONE, -1, -1);
if (packet->length == 0) {
assert(!unit_has_orders(punit));
|
|