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

I have updated Jason's patch, and integrated it with recent (in Freeciv
time) treaties work. Unless I have forgotten something, this should
complete the treaties changes for 2.2 (and 2.1?).

  - Per
Index: server/unithand.c
===================================================================
--- server/unithand.c	(revision 12614)
+++ server/unithand.c	(working copy)
@@ -951,7 +951,12 @@
     notify_player(unit_owner(punit), src_tile, E_BAD_COMMAND,
 		     _("%s can only move into your own zone of control."),
 		     unit_type(punit)->name);
+  } else if (reason == MR_PEACE) {
+    notify_player(unit_owner(punit), src_tile, E_BAD_COMMAND,
+                   _("Game: Cannot invade unless you break peace with "
+                     "%s first."), dest_tile->owner->name);
   }
+
   return FALSE;
 }
 
Index: common/unit.h
===================================================================
--- common/unit.h	(revision 12614)
+++ common/unit.h	(working copy)
@@ -69,7 +69,10 @@
 };
 
 enum unit_move_result {
-  MR_OK, MR_BAD_TYPE_FOR_CITY_TAKE_OVER, MR_NO_WAR, MR_ZOC,
+  MR_OK, MR_BAD_TYPE_FOR_CITY_TAKE_OVER,
+  MR_NO_WAR, /* Can't move here without declaring war. */
+  MR_PEACE, /* Can't move here because of a peace treaty. */
+  MR_ZOC,
   MR_BAD_ACTIVITY, MR_BAD_DESTINATION, MR_BAD_MAP_POSITION,
   MR_DESTINATION_OCCUPIED_BY_NON_ALLIED_UNIT,
   MR_NO_TRANSPORTER_CAPACITY,
Index: common/movement.c
===================================================================
--- common/movement.c	(revision 12614)
+++ common/movement.c	(working copy)
@@ -374,6 +374,7 @@
     6) There are no peaceful but un-allied units on the target tile.
     7) There is not a peaceful but un-allied city on the target tile.
     8) There is no non-allied unit blocking (zoc) [or igzoc is true].
+    9) It is not the territory of a player we are at peace with.
 **************************************************************************/
 enum unit_move_result test_unit_move_to_tile(const struct unit_type *punittype,
 					     const struct player *unit_owner,
@@ -452,6 +453,14 @@
     return MR_ZOC;
   }
 
+  /* 9) */
+  if (!unit_type_flag(punittype, F_NONMIL)
+      && dst_tile->owner
+      && dst_tile->owner != unit_owner
+      && players_non_invade(unit_owner, dst_tile->owner)) {
+    return MR_PEACE;
+  }
+
   return MR_OK;
 }
 
Index: common/player.c
===================================================================
--- common/player.c	(revision 12614)
+++ common/player.c	(working copy)
@@ -730,6 +730,17 @@
   return (ds == DS_PEACE || ds == DS_ALLIANCE || ds == DS_TEAM);
 }
 
+/****************************************************************************
+  Returns TRUE if players can't enter each others' territory.  Undefined if
+  the players are equal.
+****************************************************************************/
+bool players_non_invade(const struct player *pplayer1,
+			const struct player *pplayer2)
+{
+  assert(pplayer1 != pplayer2);
+  return pplayers_in_peace(pplayer1, pplayer2);
+}
+
 /***************************************************************
   Returns true iff players have peace or cease-fire.
 ***************************************************************/
Index: common/player.h
===================================================================
--- common/player.h	(revision 12614)
+++ common/player.h	(working copy)
@@ -273,6 +273,8 @@
 		    const struct player *pplayer2);
 bool pplayers_in_peace(const struct player *pplayer,
                     const struct player *pplayer2);
+bool players_non_invade(const struct player *pplayer1,
+			const struct player *pplayer2);
 bool pplayers_non_attack(const struct player *pplayer,
 			const struct player *pplayer2);
 bool players_on_same_team(const struct player *pplayer1,
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to