[freeciv-ai] Re: (PR#6567) AI has too many boats.
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=6567 >
On Sun, 19 Oct 2003, Gregory Berkolaiko wrote:
> I did some experimenting with the passenger/ferry numbers computed by
> aidata module. Here is a typical printout line:
Attaching the diffs for posterity. boats_reporting.diff is for printing
the stats mentioned in the first email of the thread. boats_counting are
the fixes which make the counting consistent. boats_counting can probably
be committed.
G.
Index: ai/aidata.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aidata.c,v
retrieving revision 1.21
diff -u -r1.21 aidata.c
--- ai/aidata.c 2003/10/09 00:07:33 1.21
+++ ai/aidata.c 2003/11/21 18:16:25
@@ -22,6 +22,7 @@
#include "city.h"
#include "game.h"
#include "government.h"
+#include "log.h"
#include "map.h"
#include "mem.h"
#include "rand.h"
@@ -36,6 +37,7 @@
#include "advdiplomacy.h"
#include "advmilitary.h"
#include "aicity.h"
+#include "ailog.h"
#include "aihand.h"
#include "aitools.h"
#include "aiunit.h"
@@ -420,8 +422,44 @@
ai->stats.available_boats++;
punit->ai.passenger = FERRY_AVAILABLE;
} else if (passenger) {
+ if (punit->ai.passenger == FERRY_AVAILABLE) {
+ struct ai_data *ai = ai_data_get(unit_owner(punit));
+ ai->stats.available_boats--;
+ }
punit->ai.passenger = passenger->id;
}
+}
+
+/****************************************************************************
+ Print ferry system statistics, in particular to check if the real numbers
+ of available boats and waiting passengers agree with the ones in the
+ register.
+****************************************************************************/
+void ai_ferry_stats(struct player *pplayer)
+{
+ int psngrs = 0;
+ int tot_boats = 0;
+ int boats = 0;
+ struct ai_data *ai = ai_data_get(pplayer);
+
+ freelog(LOG_DEBUG, "Spoof call");
+
+ unit_list_iterate(pplayer->units, punit) {
+ if (is_sailing_unit(punit) && is_ground_units_transport(punit)) {
+ tot_boats++;
+ if (punit->ai.passenger == FERRY_AVAILABLE) {
+ boats++;
+ }
+ }
+ if (punit->ai.ferryboat == FERRY_WANTED) {
+ UNIT_LOG(LOG_NORMAL, punit,
+ "Wants a boat, %d free boats counted so far", boats);
+ psngrs++;
+ }
+ } unit_list_iterate_end;
+ freelog(LOG_NORMAL, "%s: Boats %d(%d)/%d, waiting psngrs: %d(%d)",
+ pplayer->name, ai->stats.available_boats, boats, tot_boats,
+ ai->stats.passengers, psngrs);
}
/**************************************************************************
Index: ai/aidata.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aidata.h,v
retrieving revision 1.11
diff -u -r1.11 aidata.h
--- ai/aidata.h 2003/10/09 00:07:33 1.11
+++ ai/aidata.h 2003/11/21 18:16:25
@@ -138,6 +138,7 @@
void ai_set_passenger(struct unit *punit, struct unit *passenger);
void ai_set_ferry(struct unit *punit, struct unit *ferry);
void ai_clear_ferry(struct unit *punit);
+void ai_ferry_stats(struct player *pplayer);
#endif
Index: ai/aitools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aitools.c,v
retrieving revision 1.95
diff -u -r1.95 aitools.c
--- ai/aitools.c 2003/11/15 12:47:21 1.95
+++ ai/aitools.c 2003/11/21 18:16:25
@@ -293,7 +293,7 @@
UNIT_LOG(LOGLEVEL_GOTHERE, punit, "got boat[%d], going (%d,%d)",
ferryboat->id, dest_x, dest_y);
handle_unit_activity_request(punit, ACTIVITY_SENTRY);
- ferryboat->ai.passenger = punit->id;
+ ai_set_passenger(ferryboat, punit);
/* If the location is not accessible directly from sea
* or is defended and we are not marines, we will need a
Index: ai/aiunit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.c,v
retrieving revision 1.303
diff -u -r1.303 aiunit.c
--- ai/aiunit.c 2003/11/15 12:47:21 1.303
+++ ai/aiunit.c 2003/11/21 18:16:25
@@ -2331,7 +2331,7 @@
&& !unit_list_find(&ptile->units, punit->ai.passenger)) {
UNIT_LOG(LOGLEVEL_FERRY, punit, "lost passenger-in-charge[%d], resetting",
punit->ai.passenger);
- punit->ai.passenger = 0;
+ ai_set_passenger(punit, NULL);
}
if (punit->ai.passenger <= 0) {
@@ -2670,6 +2670,8 @@
unit_list_iterate_safe(pplayer->units, punit) {
ai_manage_unit(pplayer, punit);
} unit_list_iterate_safe_end;
+
+ ai_ferry_stats(pplayer);
}
/**************************************************************************
Index: ai/aidata.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aidata.c,v
retrieving revision 1.21
diff -u -r1.21 aidata.c
--- ai/aidata.c 2003/10/09 00:07:33 1.21
+++ ai/aidata.c 2003/11/21 18:37:23
@@ -420,6 +420,10 @@
ai->stats.available_boats++;
punit->ai.passenger = FERRY_AVAILABLE;
} else if (passenger) {
+ if (punit->ai.passenger == FERRY_AVAILABLE) {
+ struct ai_data *ai = ai_data_get(unit_owner(punit));
+ ai->stats.available_boats--;
+ }
punit->ai.passenger = passenger->id;
}
}
Index: ai/aitools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aitools.c,v
retrieving revision 1.95
diff -u -r1.95 aitools.c
--- ai/aitools.c 2003/11/15 12:47:21 1.95
+++ ai/aitools.c 2003/11/21 18:37:23
@@ -293,7 +293,7 @@
UNIT_LOG(LOGLEVEL_GOTHERE, punit, "got boat[%d], going (%d,%d)",
ferryboat->id, dest_x, dest_y);
handle_unit_activity_request(punit, ACTIVITY_SENTRY);
- ferryboat->ai.passenger = punit->id;
+ ai_set_passenger(ferryboat, punit);
/* If the location is not accessible directly from sea
* or is defended and we are not marines, we will need a
Index: ai/aiunit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.c,v
retrieving revision 1.303
diff -u -r1.303 aiunit.c
--- ai/aiunit.c 2003/11/15 12:47:21 1.303
+++ ai/aiunit.c 2003/11/21 18:37:23
@@ -2331,7 +2331,7 @@
&& !unit_list_find(&ptile->units, punit->ai.passenger)) {
UNIT_LOG(LOGLEVEL_FERRY, punit, "lost passenger-in-charge[%d], resetting",
punit->ai.passenger);
- punit->ai.passenger = 0;
+ ai_set_passenger(punit, NULL);
}
if (punit->ai.passenger <= 0) {
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freeciv-ai] Re: (PR#6567) AI has too many boats.,
Gregory Berkolaiko <=
|
|