[Freeciv-Dev] (PR#12232) don't allow invasions during peace treaties
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12232 >
As discussed on IRC and in numerous other threads...
This patch disallows invasions between nations at peace.
- When entering a peace treaty (through dipldialog, canceling of
alliance, or loading a saved game) resolve_unit_stacks is called to
bounce the units. (Yes, this uses bouncing which is ugly. Feel free to
suggest something else.)
- Units are not allowed to enter territory of nations they are at peace
with.
The AI is surely bound by this but doesn't know it has to break its
peace treaty to invade. But then the AI never, ever makes peace
treaties (it always goes straight to alliance).
It is untested.
-jason
Index: common/player.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.c,v
retrieving revision 1.167
diff -u -r1.167 player.c
--- common/player.c 22 Jan 2005 19:45:43 -0000 1.167
+++ common/player.c 13 Feb 2005 00:23:36 -0000
@@ -672,6 +672,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
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.h,v
retrieving revision 1.138
diff -u -r1.138 player.h
--- common/player.h 22 Jan 2005 19:45:43 -0000 1.138
+++ common/player.h 13 Feb 2005 00:23:36 -0000
@@ -292,6 +292,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,
Index: common/unit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unit.c,v
retrieving revision 1.227
diff -u -r1.227 unit.c
--- common/unit.c 10 Feb 2005 17:55:08 -0000 1.227
+++ common/unit.c 13 Feb 2005 00:23:37 -0000
@@ -1550,6 +1550,7 @@
8) there are no peaceful but un-allied units on the target tile
9) there is not a peaceful but un-allied city on the target tile
10) there is no non-allied unit blocking (zoc) [or igzoc is true]
+ 11) it's not the territory of a player we're at peace with
**************************************************************************/
enum unit_move_result test_unit_move_to_tile(Unit_Type_id type,
const struct player *unit_owner,
@@ -1619,6 +1620,13 @@
return MR_ZOC;
}
+ /* 11) */
+ if (!unit_type_flag(type, F_NONMIL) && ptotile->owner
+ && ptotile->owner != unit_owner
+ && players_non_invade(unit_owner, ptotile->owner)) {
+ return MR_PEACE;
+ }
+
return MR_OK;
}
Index: common/unit.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unit.h,v
retrieving revision 1.136
diff -u -r1.136 unit.h
--- common/unit.h 10 Feb 2005 17:55:08 -0000 1.136
+++ common/unit.h 13 Feb 2005 00:23:37 -0000
@@ -70,7 +70,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_SEA_TRANSPORTER_CAPACITY,
Index: server/diplhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/diplhand.c,v
retrieving revision 1.91
diff -u -r1.91 diplhand.c
--- server/diplhand.c 22 Jan 2005 20:31:11 -0000 1.91
+++ server/diplhand.c 13 Feb 2005 00:23:37 -0000
@@ -433,6 +433,7 @@
gamelog(GAMELOG_TREATY, GL_PEACE, pgiver, pdest);
check_city_workers(pplayer);
check_city_workers(pother);
+ resolve_unit_stacks(pother, pplayer, TRUE);
break;
case CLAUSE_ALLIANCE:
pgiver->diplstates[pdest->player_no].type=DS_ALLIANCE;
Index: server/maphand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/maphand.c,v
retrieving revision 1.156
diff -u -r1.156 maphand.c
--- server/maphand.c 29 Jan 2005 19:01:32 -0000 1.156
+++ server/maphand.c 13 Feb 2005 00:23:37 -0000
@@ -1617,11 +1617,24 @@
*************************************************************************/
static void tile_update_owner(struct tile *ptile)
{
+ struct player *tileowner = ptile->owner;
+
/* This implementation is horribly inefficient, but this doesn't cause
* problems since it's not called often. */
cities_iterate(pcity) {
update_city_tile_status_map(pcity, ptile);
} cities_iterate_end;
+
+ if (ptile->owner) {
+ unit_list_iterate_safe(ptile->units, punit) {
+ struct player *unitowner = unit_owner(punit);
+
+ if (unitowner != tileowner
+ && players_non_invade(unitowner, tileowner)) {
+ bounce_unit(punit, TRUE);
+ }
+ } unit_list_iterate_safe_end;
+ }
}
/*************************************************************************
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.219
diff -u -r1.219 savegame.c
--- server/savegame.c 5 Feb 2005 07:41:54 -0000 1.219
+++ server/savegame.c 13 Feb 2005 00:23:38 -0000
@@ -3512,7 +3512,8 @@
initialize_globals();
apply_unit_ordering();
- /* Rebuild national borders. */
+ /* Rebuild national borders. This must be done before the
+ * resolve_unit_stacks calls below. */
map_calculate_borders();
/* Make sure everything is consistent. */
Index: server/unithand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unithand.c,v
retrieving revision 1.319
diff -u -r1.319 unithand.c
--- server/unithand.c 5 Feb 2005 07:41:54 -0000 1.319
+++ server/unithand.c 13 Feb 2005 00:23:38 -0000
@@ -945,6 +945,9 @@
notify_player_ex(unit_owner(punit), src_tile,
E_NOEVENT,
_("Game: Cannot attack unless you declare war first."));
+ } else if (reason == MR_PEACE) {
+ notify_player_ex(unit_owner(punit), src_tile, E_NOEVENT,
+ _("Game: Cannot invade unless you break peace first."));
} else if (reason == MR_ZOC) {
notify_player_ex(unit_owner(punit), src_tile, E_NOEVENT,
_("Game: %s can only move into your own zone of control."),
Index: server/unittools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unittools.c,v
retrieving revision 1.318
diff -u -r1.318 unittools.c
--- server/unittools.c 5 Feb 2005 07:41:54 -0000 1.318
+++ server/unittools.c 13 Feb 2005 00:23:39 -0000
@@ -1233,7 +1233,7 @@
If verbose is true, pplayer gets messages about where each units goes.
**************************************************************************/
-static void throw_units_from_illegal_cities(struct player *pplayer,
+static void throw_units_from_illegal_tiles(struct player *pplayer,
bool verbose)
{
unit_list_iterate_safe(pplayer->units, punit) {
@@ -1241,6 +1241,9 @@
if (ptile->city && !pplayers_allied(city_owner(ptile->city), pplayer)) {
bounce_unit(punit, verbose);
+ } else if (ptile->owner && ptile->owner != pplayer
+ && players_non_invade(pplayer, ptile->owner)) {
+ bounce_unit(punit, verbose);
}
} unit_list_iterate_safe_end;
}
@@ -1285,8 +1288,8 @@
void resolve_unit_stacks(struct player *pplayer, struct player *aplayer,
bool verbose)
{
- throw_units_from_illegal_cities(pplayer, verbose);
- throw_units_from_illegal_cities(aplayer, verbose);
+ throw_units_from_illegal_tiles(pplayer, verbose);
+ throw_units_from_illegal_tiles(aplayer, verbose);
resolve_stack_conflicts(pplayer, aplayer, verbose);
resolve_stack_conflicts(aplayer, pplayer, verbose);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#12232) don't allow invasions during peace treaties,
Jason Short <=
|
|