Author: sveinung
Date: Thu Nov  5 18:57:41 2015
New Revision: 30417

URL: http://svn.gna.org/viewcvs/freeciv?rev=30417&view=rev
Log:
ai: turn the war_reason enum into a specenum

The default AI code stores numbers representing war_reason values in save
games. It would be good if the save games containing it had information
about the war reason order. It would be better if the meaning could be
stored directly.

Changing the way the war_reason values are stored in the save game involves
many moving parts. How save game loading, storage and upgrade will
interface with the default AI code isn't decided yet. Making war_reason a
specenum will probably help no matter how the interface ends up.

Add a DAI_ namespace prefix to the value names as Marko Lindqvist <cazfi>
requested.

See patch #6527

Modified:
    trunk/ai/default/advdiplomacy.c
    trunk/ai/default/aidata.c
    trunk/ai/default/aidata.h

Modified: trunk/ai/default/advdiplomacy.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/default/advdiplomacy.c?rev=30417&r1=30416&r2=30417&view=diff
==============================================================================
--- trunk/ai/default/advdiplomacy.c     (original)
+++ trunk/ai/default/advdiplomacy.c     Thu Nov  5 18:57:41 2015
@@ -1266,35 +1266,35 @@
   fc_assert_ret(target->is_alive);
 
   switch (reason) {
-  case WAR_REASON_SPACE:
+  case DAI_WR_SPACE:
     notify(target, _("*%s (AI)* Space will never be yours. "),
            player_name(pplayer));
     adip->countdown = -10;
     break;
-  case WAR_REASON_BEHAVIOUR:
+  case DAI_WR_BEHAVIOUR:
     notify(target, _("*%s (AI)* I have tolerated your vicious antics "
            "long enough! To war!"),
            player_name(pplayer));
     adip->countdown = -20;
     break;
-  case WAR_REASON_NONE:
+  case DAI_WR_NONE:
     notify(target, _("*%s (AI)* Peace in ... some other time."),
            player_name(pplayer));
     adip->countdown = -10;
     break;
-  case WAR_REASON_HATRED:
+  case DAI_WR_HATRED:
     notify(target, _("*%s (AI)* Finally I get around to you! Did "
            "you really think you could get away with your crimes?"),
            player_name(pplayer));
     adip->countdown = -20;
     break;
-  case WAR_REASON_EXCUSE:
+  case DAI_WR_EXCUSE:
     notify(target, _("*%s (AI)* Your covert hostilities brought "
            "this war upon you!"),
            player_name(pplayer));
     adip->countdown = -20;
     break;
-  case WAR_REASON_ALLIANCE:
+  case DAI_WR_ALLIANCE:
     if (adip->at_war_with_ally) {
       notify(target, _("*%s (AI)* Your aggression against %s was "
                        "your last mistake!"),
@@ -1378,7 +1378,7 @@
     }
 
     switch (reason) {
-    case WAR_REASON_SPACE:
+    case DAI_WR_SPACE:
       notify(ally, PL_("*%s (AI)* We will be launching an all-out war "
                       "against %s in %d turn to stop the spaceship "
                       "launch.",
@@ -1393,8 +1393,8 @@
                      "Long live our glorious alliance!"),
              player_name(pplayer));
       break;
-    case WAR_REASON_BEHAVIOUR:
-    case WAR_REASON_EXCUSE:
+    case DAI_WR_BEHAVIOUR:
+    case DAI_WR_EXCUSE:
       notify(ally, PL_("*%s (AI)* %s has grossly violated his treaties "
                       "with us for own gain.  We will answer in force in "
                       "%d turn and expect you to honor your alliance "
@@ -1407,7 +1407,7 @@
             player_name(target),
             countdown);
       break;
-    case WAR_REASON_NONE:
+    case DAI_WR_NONE:
       notify(ally, PL_("*%s (AI)* We intend to pillage and plunder the rich "
                       "civilization of %s. We declare war in %d turn.",
                       "*%s (AI)* We intend to pillage and plunder the rich "
@@ -1420,7 +1420,7 @@
                      "free to join in the action!"),
              player_name(pplayer));
       break;
-    case WAR_REASON_HATRED:
+    case DAI_WR_HATRED:
       notify(ally, PL_("*%s (AI)* We have had it with %s. Let us tear this "
                       "pathetic civilization apart. We declare war in "
                       "%d turn.",
@@ -1435,7 +1435,7 @@
                      "help in this war."),
              player_name(pplayer));
       break;
-    case WAR_REASON_ALLIANCE:
+    case DAI_WR_ALLIANCE:
       if (WAR(ally, target)) {
         notify(ally, PL_("*%s (AI)* We will honor our alliance and declare "
                         "war on %s in %d turn.  Hold on - we are coming!",
@@ -1496,7 +1496,7 @@
         && dai_diplomacy_get(ait, pplayer, aplayer)->countdown == -1) {
       DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "Plans war in revenge");
       war_countdown(ait, pplayer, aplayer, map_size_checked(),
-                    WAR_REASON_BEHAVIOUR);
+                    DAI_WR_BEHAVIOUR);
     }
   } players_iterate_end;
 
@@ -1548,7 +1548,7 @@
         pplayer->ai_common.love[player_index(aplayer)] -= MAX_AI_LOVE / 2;
         DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "plans war due to 
spaceship");
         war_countdown(ait, pplayer, aplayer, 4 + map_size_checked(),
-                      WAR_REASON_SPACE);
+                      DAI_WR_SPACE);
       }
     } players_iterate_alive_end;
   }
@@ -1587,13 +1587,13 @@
     }
     if (player_diplstate_get(pplayer, target)->has_reason_to_cancel > 0) {
       /* We have good reason */
-      war_reason = WAR_REASON_EXCUSE;
+      war_reason = DAI_WR_EXCUSE;
     } else if (pplayer->ai_common.love[player_index(target)] < 0) {
       /* We have a reason of sorts from way back, maybe? */
-      war_reason = WAR_REASON_HATRED;
+      war_reason = DAI_WR_HATRED;
     } else {
       /* We have no legimitate reason... So what? */
-      war_reason = WAR_REASON_NONE;
+      war_reason = DAI_WR_NONE;
     }
     DIPLO_LOG(ait, LOG_DEBUG, pplayer, target, "plans war for spoils");
     war_countdown(ait, pplayer, target, 4 + map_size_checked(), war_reason);
@@ -1613,7 +1613,7 @@
       DIPLO_LOG(ait, LOG_DEBUG, pplayer, aplayer, "plans war to help ally %s",
                 player_name(adip->at_war_with_ally));
       war_countdown(ait, pplayer, aplayer, 2 + map_size_checked(),
-                    WAR_REASON_ALLIANCE);
+                    DAI_WR_ALLIANCE);
     }
   } players_iterate_alive_end;
 

Modified: trunk/ai/default/aidata.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/default/aidata.c?rev=30417&r1=30416&r2=30417&view=diff
==============================================================================
--- trunk/ai/default/aidata.c   (original)
+++ trunk/ai/default/aidata.c   Thu Nov  5 18:57:41 2015
@@ -373,7 +373,7 @@
   /* pseudorandom value */
   player_intel->spam = (player_index(plr1) + player_index(plr2)) % 5;
   player_intel->countdown = -1;
-  player_intel->war_reason = WAR_REASON_NONE;
+  player_intel->war_reason = DAI_WR_NONE;
   player_intel->distance = 1;
   player_intel->ally_patience = 0;
   player_intel->asked_about_peace = 0;

Modified: trunk/ai/default/aidata.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/default/aidata.h?rev=30417&r1=30416&r2=30417&view=diff
==============================================================================
--- trunk/ai/default/aidata.h   (original)
+++ trunk/ai/default/aidata.h   Thu Nov  5 18:57:41 2015
@@ -32,14 +32,20 @@
   WIN_CAPITAL   /* we cannot win unless we take war_target's capital */
 };
 
-enum war_reason {
-  WAR_REASON_BEHAVIOUR,
-  WAR_REASON_SPACE,
-  WAR_REASON_EXCUSE,
-  WAR_REASON_HATRED,
-  WAR_REASON_ALLIANCE,
-  WAR_REASON_NONE
-};
+#define SPECENUM_NAME war_reason
+#define SPECENUM_VALUE0 DAI_WR_BEHAVIOUR
+#define SPECENUM_VALUE0NAME "Behaviour"
+#define SPECENUM_VALUE1 DAI_WR_SPACE
+#define SPECENUM_VALUE1NAME "Space"
+#define SPECENUM_VALUE2 DAI_WR_EXCUSE
+#define SPECENUM_VALUE2NAME "Excuse"
+#define SPECENUM_VALUE3 DAI_WR_HATRED
+#define SPECENUM_VALUE3NAME "Hatred"
+#define SPECENUM_VALUE4 DAI_WR_ALLIANCE
+#define SPECENUM_VALUE4NAME "Alliance"
+#define SPECENUM_VALUE5 DAI_WR_NONE
+#define SPECENUM_VALUE5NAME "None"
+#include "specenum_gen.h"
 
 struct ai_dip_intel {
   /* Remember one example of each for text spam purposes. */


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to