aboutsummaryrefslogtreecommitdiff
path: root/diplomacy/engine
diff options
context:
space:
mode:
authornotoraptor <stevenbocco@gmail.com>2019-08-27 21:04:36 -0400
committerPhilip Paquette <pcpaquette@gmail.com>2019-08-28 06:15:47 -0400
commitb0521bedc67dfee438acc26645e1339f0caafbe2 (patch)
treef74dee7473856c3ac76c572e66197493590a780a /diplomacy/engine
parent2e26ae581062ca636dd02718e7cbbf71e022b04a (diff)
Make sure to clear all orders before setting a new game state.
Diffstat (limited to 'diplomacy/engine')
-rw-r--r--diplomacy/engine/game.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/diplomacy/engine/game.py b/diplomacy/engine/game.py
index 4c87362..8da3480 100644
--- a/diplomacy/engine/game.py
+++ b/diplomacy/engine/game.py
@@ -1448,6 +1448,10 @@ class Game(Jsonable):
Previous phase data in given list will replace current game history.
:param clear_history: Indicate if we must clear game history fields before update.
"""
+ # In the following code, we use Game.method instead of self.method to make sure
+ # game internal state is correctly set without calling any asynchronous
+ # overriden method from a derived class (especially NetworkGame class).
+
if not phase_data:
return
if isinstance(phase_data, GamePhaseData):
@@ -1457,15 +1461,19 @@ class Game(Jsonable):
if clear_history:
self._clear_history()
+ else:
+ # Clear orders and vote - Messages will be totally overwritten below.
+ Game.clear_vote(self)
+ Game.clear_orders(self)
for game_phase_data in phase_data[:-1]: # type: GamePhaseData
- self.extend_phase_history(game_phase_data)
+ Game.extend_phase_history(self, game_phase_data)
current_phase_data = phase_data[-1] # type: GamePhaseData
- self.set_state(current_phase_data.state, clear_history=False)
+ Game.set_state(self, current_phase_data.state, clear_history=False)
for power_name, power_orders in current_phase_data.orders.items():
if power_orders is not None:
- self.set_orders(power_name, power_orders)
+ Game.set_orders(self, power_name, power_orders)
self.messages = current_phase_data.messages.copy()
# We ignore 'results' for current phase data.