Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2005:
[Freeciv-Dev] Re: (PR#13401) AIs unable to declare war in Republic/Democ
Home

[Freeciv-Dev] Re: (PR#13401) AIs unable to declare war in Republic/Democ

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] Re: (PR#13401) AIs unable to declare war in Republic/Democracy
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Mon, 4 Jul 2005 13:19:56 -0700
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=13401 >

On Sun, 3 Jul 2005, Per I. Mathisen wrote:
> The latest change to Senate has made the AI incapable of declaring war in
> Republic/Democracy governments. This needs to be fixed...

Untested patch attached.

  - Per

Index: ai/advdiplomacy.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/advdiplomacy.c,v
retrieving revision 1.82
diff -u -r1.82 advdiplomacy.c
--- ai/advdiplomacy.c   4 Jul 2005 17:48:35 -0000       1.82
+++ ai/advdiplomacy.c   4 Jul 2005 20:14:35 -0000
@@ -1077,7 +1077,13 @@
     remove_shared_vision(pplayer, target);
   }
 
-  /* will take us straight to war */
+  /* Check for Senate obstruction.  If so, dissolve it. */
+  if (!pplayer_can_declare_war(pplayer, target)) {
+    handle_player_change_government(pplayer, 
+                                    game.info.government_when_anarchy);
+  }
+
+  /* This will take us straight to war. */
   handle_diplomacy_cancel_pact(pplayer, target->player_no, CLAUSE_LAST);
 
   /* Continue war at least in this arbitrary number of turns to show 
Index: common/player.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.c,v
retrieving revision 1.187
diff -u -r1.187 player.c
--- common/player.c     4 Jul 2005 17:48:37 -0000       1.187
+++ common/player.c     4 Jul 2005 20:14:55 -0000
@@ -34,6 +34,22 @@
 #include "player.h"
 
 /***************************************************************
+  Returns true iff p1 can declare war on p2.
+
+  The senate may not allow you to break the treaty.  In this 
+  case you must first dissolve the senate then you can break 
+  it.  This is waived if you have statue of liberty since you 
+  could easily just dissolve and then recreate it. 
+***************************************************************/
+bool pplayer_can_declare_war(const struct player *p1, 
+                             const struct player *p2)
+{
+  return (p1->diplstates[p2->player_no].has_reason_to_cancel > 0
+          || get_player_bonus(p1, EFT_HAS_SENATE) == 0
+          || get_player_bonus(p1, EFT_ANY_GOVERNMENT) > 0);
+}
+
+/***************************************************************
   Returns true iff p1 can ally p2. There is only one condition:
   We are not at war with any of p2's allies. Note that for an
   alliance to be made, we need to check this both ways.
Index: common/player.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.h,v
retrieving revision 1.157
diff -u -r1.157 player.h
--- common/player.h     21 Jun 2005 16:21:01 -0000      1.157
+++ common/player.h     4 Jul 2005 20:14:55 -0000
@@ -299,6 +299,8 @@
                                                     *pplayer2);
 bool are_diplstates_equal(const struct player_diplstate *pds1,
                          const struct player_diplstate *pds2);
+bool pplayer_can_declare_war(const struct player *p1,
+                             const struct player *p2);
 bool pplayer_can_ally(const struct player *p1, const struct player *p2);
 bool pplayers_at_war(const struct player *pplayer,
                    const struct player *pplayer2);
Index: server/plrhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.c,v
retrieving revision 1.396
diff -u -r1.396 plrhand.c
--- server/plrhand.c    4 Jul 2005 17:48:38 -0000       1.396
+++ server/plrhand.c    4 Jul 2005 20:14:58 -0000
@@ -511,12 +511,8 @@
 repeat_break_treaty:
 
   /* The senate may not allow you to break the treaty.  In this case you
-   * must first dissolve the senate then you can break it.  This is waived
-   * if you have statue of liberty since you could easily just dissolve and
-   * then recreate it. */
-  if (pplayer->diplstates[pplayer2->player_no].has_reason_to_cancel <= 0
-      && get_player_bonus(pplayer, EFT_HAS_SENATE) > 0
-      && get_player_bonus(pplayer, EFT_ANY_GOVERNMENT) == 0) {
+   * must first dissolve the senate then you can break it. */
+  if (!pplayer_can_declare_war(pplayer, pplayer2)) {
     notify_player_ex(pplayer, NULL, E_TREATY_BROKEN,
                     _("The senate will not allow you to break treaty "
                       "with the %s.  You must either dissolve the senate "

[Prev in Thread] Current Thread [Next in Thread]