Skip to content

Commit 43c2447

Browse files
Merge pull request #164 from ChrisNeedham24/MCR-157
MCR-157 Added client-server synchronisation checks for multiplayer games, and fixed a few other bugs.
2 parents a3ca223 + 265fa9c commit 43c2447

27 files changed

+1039
-393
lines changed

source/display/board.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def __init__(self, cfg: GameConfig, namer: Namer, quads: typing.List[typing.List
7474
self.player_idx: int = player_idx
7575
self.game_name: typing.Optional[str] = game_name
7676
self.waiting_for_other_players: bool = False
77+
self.checking_game_sync: bool = False
7778

7879
def draw(self, players: typing.List[Player], map_pos: (int, int), turn: int, heathens: typing.List[Heathen],
7980
is_night: bool, turns_until_change: int): # pragma: no cover
@@ -190,6 +191,7 @@ def draw(self, players: typing.List[Player], map_pos: (int, int), turn: int, hea
190191
(heathen.location[1] - map_pos[1]) * 8 + 4, 0, heathen_x, 60, 8, 8)
191192
# Outline a heathen if the player can attack it.
192193
if self.selected_unit is not None and not isinstance(self.selected_unit, Heathen) and \
194+
self.selected_unit in players[self.player_idx].units and \
193195
not self.selected_unit.has_acted and \
194196
abs(self.selected_unit.location[0] - heathen.location[0]) <= 1 and \
195197
abs(self.selected_unit.location[1] - heathen.location[1]) <= 1:
@@ -333,12 +335,13 @@ def draw(self, players: typing.List[Player], map_pos: (int, int), turn: int, hea
333335
for setl_quad in self.selected_settlement.quads:
334336
for i in range(setl_quad.location[0] - 1, setl_quad.location[0] + 2):
335337
for j in range(setl_quad.location[1] - 1, setl_quad.location[1] + 2):
336-
if not any(s_q.location == (i, j) for s_q in self.selected_settlement.quads):
338+
if not any(s_q.location == (i, j) for s_q in self.selected_settlement.quads) and \
339+
0 <= i <= 99 and 0 <= j <= 89:
337340
pyxel.rectb((i - map_pos[0]) * 8 + 4, (j - map_pos[1]) * 8 + 4, 8, 8, pyxel.COLOR_WHITE)
338341
if self.deploying_army_from_unit:
339342
for i in range(self.selected_unit.location[0] - 1, self.selected_unit.location[0] + 2):
340343
for j in range(self.selected_unit.location[1] - 1, self.selected_unit.location[1] + 2):
341-
if self.selected_unit.location != (i, j):
344+
if self.selected_unit.location != (i, j) and 0 <= i <= 99 and 0 <= j <= 89:
342345
pyxel.rectb((i - map_pos[0]) * 8 + 4, (j - map_pos[1]) * 8 + 4, 8, 8, pyxel.COLOR_WHITE)
343346

344347
# Also display the number of units the player can move at the bottom-right of the screen.
@@ -356,10 +359,14 @@ def draw(self, players: typing.List[Player], map_pos: (int, int), turn: int, hea
356359
# There are a few situations in which we override the default help text:
357360
# - If the current game has multiplayer enabled, and the player is waiting for other players to finish their
358361
# turn.
362+
# - If the current game has multiplayer enabled, and the player's local game state is being validated to ensure
363+
# that it is in sync with the game server.
359364
# - If a unit is selected that can settle, alerting the player as to the settle button.
360365
# - If a unit is selected that can heal other units, alerting the player as to how to heal other units.
361366
if self.game_config.multiplayer and self.waiting_for_other_players:
362367
pyxel.text(2, 189, "Waiting for other players...", pyxel.COLOR_WHITE)
368+
elif self.game_config.multiplayer and self.checking_game_sync:
369+
pyxel.text(2, 189, "Checking game sync, please wait...", pyxel.COLOR_WHITE)
363370
elif self.selected_unit is not None and self.selected_unit.plan.can_settle:
364371
pyxel.text(2, 189, "S: Found new settlement", pyxel.COLOR_WHITE)
365372
elif self.selected_unit is not None and self.selected_unit.plan.heals and not self.selected_unit.has_acted:
@@ -606,7 +613,7 @@ def process_left_click(self, mouse_x: int, mouse_y: int, settled: bool,
606613
new_settl.strength *= 2
607614
new_settl.max_strength *= 2
608615
case Faction.FRONTIERSMEN:
609-
new_settl.satisfaction = 75
616+
new_settl.satisfaction = 75.0
610617
case Faction.IMPERIALS:
611618
new_settl.strength /= 2
612619
new_settl.max_strength /= 2
@@ -927,7 +934,7 @@ def handle_new_settlement(self, player: Player):
927934
[self.quads[self.selected_unit.location[1]][self.selected_unit.location[0]]],
928935
setl_resources, [])
929936
if player.faction == Faction.FRONTIERSMEN:
930-
new_settl.satisfaction = 75
937+
new_settl.satisfaction = 75.0
931938
elif player.faction == Faction.IMPERIALS:
932939
new_settl.strength /= 2
933940
new_settl.max_strength /= 2

source/display/menu.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ def draw(self):
519519
if self.blessing_boundaries[0] <= idx <= self.blessing_boundaries[1]:
520520
adj_idx = idx - self.blessing_boundaries[0]
521521
pyxel.text(20, 50 + adj_idx * 25, str(blessing.name), pyxel.COLOR_WHITE)
522-
pyxel.text(160, 50 + adj_idx * 25, str(blessing.cost), pyxel.COLOR_WHITE)
522+
pyxel.text(160, 50 + adj_idx * 25, str(round(blessing.cost)), pyxel.COLOR_WHITE)
523523
pyxel.text(20, 57 + adj_idx * 25, str(blessing.description), pyxel.COLOR_WHITE)
524524
imps = get_unlockable_improvements(blessing)
525525
pyxel.blt(20, 64 + adj_idx * 25, 0, 32, 44, 8, 8)
@@ -550,7 +550,7 @@ def draw(self):
550550
if self.improvement_boundaries[0] <= idx <= self.improvement_boundaries[1]:
551551
adj_offset = (idx - self.improvement_boundaries[0]) * 25
552552
pyxel.text(20, 50 + adj_offset, str(imp.name), pyxel.COLOR_WHITE)
553-
cost_str: str = str(imp.cost)
553+
cost_str: str = str(round(imp.cost))
554554
if res := imp.req_resources:
555555
if res.ore:
556556
cost_str += f", {res.ore} ore"
@@ -561,23 +561,23 @@ def draw(self):
561561
pyxel.text(125, 50 + adj_offset, cost_str, pyxel.COLOR_WHITE)
562562
pyxel.text(20, 57 + adj_offset, str(imp.description), pyxel.COLOR_WHITE)
563563
effects = 0
564-
if (wealth := imp.effect.wealth) != 0:
564+
if (wealth := round(imp.effect.wealth)) != 0:
565565
pyxel.text(20 + effects * 25, 64 + adj_offset, f"{wealth:+}", pyxel.COLOR_YELLOW)
566566
effects += 1
567-
if (harvest := imp.effect.harvest) != 0:
567+
if (harvest := round(imp.effect.harvest)) != 0:
568568
pyxel.text(20 + effects * 25, 64 + adj_offset, f"{harvest:+}", pyxel.COLOR_GREEN)
569569
effects += 1
570-
if (zeal := imp.effect.zeal) != 0:
570+
if (zeal := round(imp.effect.zeal)) != 0:
571571
pyxel.text(20 + effects * 25, 64 + adj_offset, f"{zeal:+}", pyxel.COLOR_RED)
572572
effects += 1
573-
if (fortune := imp.effect.fortune) != 0:
573+
if (fortune := round(imp.effect.fortune)) != 0:
574574
pyxel.text(20 + effects * 25, 64 + adj_offset, f"{fortune:+}", pyxel.COLOR_PURPLE)
575575
effects += 1
576-
if (strength := imp.effect.strength) != 0:
576+
if (strength := round(imp.effect.strength)) != 0:
577577
pyxel.blt(20 + effects * 25, 64 + adj_offset, 0, 0, 28, 8, 8)
578578
pyxel.text(30 + effects * 25, 64 + adj_offset, f"{strength:+}", pyxel.COLOR_WHITE)
579579
effects += 1
580-
if (satisfaction := imp.effect.satisfaction) != 0:
580+
if (satisfaction := round(imp.effect.satisfaction)) != 0:
581581
satisfaction_u = 8 if satisfaction >= 0 else 16
582582
pyxel.blt(20 + effects * 25, 64 + adj_offset, 0, satisfaction_u, 28, 8, 8)
583583
pyxel.text(30 + effects * 25, 64 + adj_offset, f"{satisfaction:+}", pyxel.COLOR_WHITE)
@@ -639,10 +639,11 @@ def draw(self):
639639
if self.unit_boundaries[0] <= idx <= self.unit_boundaries[1]:
640640
adj_idx = idx - self.unit_boundaries[0]
641641
pyxel.text(20, 50 + adj_idx * 10, str(unit.name), pyxel.COLOR_WHITE)
642-
pyxel.text(160, 50 + adj_idx * 10, str(unit.cost), pyxel.COLOR_WHITE)
643-
pyxel.text(88, 50 + adj_idx * 10, str(unit.max_health), pyxel.COLOR_WHITE)
642+
pyxel.text(160, 50 + adj_idx * 10, str(round(unit.cost)), pyxel.COLOR_WHITE)
643+
pyxel.text(88, 50 + adj_idx * 10, str(round(unit.max_health)), pyxel.COLOR_WHITE)
644644
pyxel.text(108, 50 + adj_idx * 10,
645-
str(unit.max_capacity if isinstance(unit, DeployerUnitPlan) else unit.power),
645+
str(unit.max_capacity if isinstance(unit, DeployerUnitPlan)
646+
else round(unit.power)),
646647
pyxel.COLOR_WHITE)
647648
pyxel.text(132, 50 + adj_idx * 10, str(unit.total_stamina), pyxel.COLOR_WHITE)
648649
case _:

0 commit comments

Comments
 (0)