Describe role changes better

Per Inge Mathisen <per-0/[email protected]> Sun, 20 Mar 2005 11:01:41 +0000 (GMT)
Newsgroups gmane.games.freeciv.ai
Message-ID <[email protected]>
This patch makes us show strings instead of cryptic numbers in the role
changing function's freelog output.

  - Per
roledesc.diff (text/plain, 2.5 KB)
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	20 Mar 2005 11:00:29 -0000
@@ -57,6 +57,39 @@
 #include "aitools.h"
 
 /**************************************************************************
+  Return a string describing a unit's AI role.
+**************************************************************************/
+const char *get_ai_role_str(enum ai_unit_task task)
+{
+  switch(task) {
+   case AIUNIT_NONE:
+     return "None";
+   case AIUNIT_AUTO_SETTLER:
+     return "Auto settler";
+   case AIUNIT_BUILD_CITY:
+     return "Build city";
+   case AIUNIT_DEFEND_HOME:
+     return "Defend home";
+   case AIUNIT_ATTACK:
+     return "Attack";
+   case AIUNIT_ESCORT:
+     return "Escort";
+   case AIUNIT_EXPLORE:
+     return "Explore";
+   case AIUNIT_RECOVER:
+     return "Recover";
+   case AIUNIT_HUNTER:
+     return "Hunter";
+   case AIUNIT_PILLAGE:
+   case AIUNIT_RUNAWAY:
+   case AIUNIT_FORTIFY:
+     return "Unused";
+  }
+  assert(FALSE);
+  return NULL;
+}
+
+/**************************************************************************
   Amortize a want modified by the shields (build_cost) we risk losing.
   We add the build time of the unit(s) we risk to amortize delay.  The
   build time is claculated as the build cost divided by the production
@@ -312,8 +345,8 @@
   /* If the unit is under (human) orders we shouldn't control it. */
   assert(!unit_has_orders(punit));
 
-  UNIT_LOG(LOG_DEBUG, punit, "changing role from %d to %d",
-           punit->activity, task);
+  UNIT_LOG(LOG_DEBUG, punit, "changing role from %s to %s",
+           get_ai_role_str(punit->activity), get_ai_role_str(task));
 
   /* Free our ferry.  Most likely it has been done already. */
   if (task == AIUNIT_NONE || task == AIUNIT_DEFEND_HOME) {
Index: ai/aitools.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aitools.h,v
retrieving revision 1.50
diff -u -r1.50 aitools.h
--- ai/aitools.h	3 Feb 2005 09:48:53 -0000	1.50
+++ ai/aitools.h	20 Mar 2005 11:00:29 -0000
@@ -37,6 +37,8 @@
   BODYGUARD_NONE
 };
 
+const char *get_ai_role_str(enum ai_unit_task task);
+
 int military_amortize(struct player *pplayer, struct city *pcity, 
                       int value, int delay, int build_cost);
 int stack_cost(struct unit *pdef);