Return to repo list

heart-of-gold

Tactical RPG written in python, using pygame.
Return to HMagellan.com

commit da2ee7b3a66c28869faf2a9b3393a1b25e1e1470
parent cceaaaa865a8e243c1d12c46e4121c4e063f9cc9
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Sat, 14 Nov 2020 03:58:11 -0600

Turn order calc should be working now

Diffstat:
Mdata/board/testmap1/testmap1.json | 8++++----
Msrc/turn.py | 34++++++++++++++++++----------------
2 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/data/board/testmap1/testmap1.json b/data/board/testmap1/testmap1.json @@ -132,7 +132,7 @@ "HP" : 100, "ATK" : 10, "DEF" : 6, - "SPD" : 12, + "SPD" : 1, "ACC" : 7, "INT" : 5, "WIS" : 6, @@ -151,7 +151,7 @@ "HP" : 100, "ATK" : 10, "DEF" : 6, - "SPD" : 12, + "SPD" : 1, "ACC" : 7, "INT" : 5, "WIS" : 6, @@ -190,7 +190,7 @@ "HP" : 100, "ATK" : 10, "DEF" : 6, - "SPD" : 1, + "SPD" : 11, "ACC" : 7, "INT" : 5, "WIS" : 6, @@ -209,7 +209,7 @@ "HP" : 100, "ATK" : 10, "DEF" : 6, - "SPD" : 1, + "SPD" : 11, "ACC" : 7, "INT" : 5, "WIS" : 6, diff --git a/src/turn.py b/src/turn.py @@ -27,10 +27,11 @@ class TurnManager(manager.Manager): super().__init__(game, bus, name) # Important values - self.current_turn = 0 - self.current_tick = 0 + self.current_turn = 1 self.current_active_piece = None - self.turn_projection = [] + #self.turn_projection = [] + self.turn_order = [] + self.turn_tick = 0 self.in_play_pieces = [] self.turn_depth = 10 @@ -47,6 +48,9 @@ class TurnManager(manager.Manager): # TODO: Probably shouldn't be hardcoded self.turn_tray.set_position((898, 28)) self.turn_icons = [] + self.turn_projection = [] + self.former_candidates = [] + self.current_turn = 1 self.shift_turns() def shift_turns(self): @@ -67,11 +71,8 @@ class TurnManager(manager.Manager): if pc.readiness >= 100: candidates.append(pc) - # Generate a list of next turn candidates - # Note that the tick is only iterated here. A tick only occurs when the pieces' - # readiness is increased, so if the while loop is skipped, no ticking takes place + # Generate a list of next turn candidates. Readiness is increased only here while len(candidates) == 0: - self.current_tick += 1 for p in self.in_play_pieces: p.readiness += p.active_stats["INIT"] + min(1, (p.active_stats["SPD"] // 3)) if p.readiness >= 100: @@ -82,12 +83,12 @@ class TurnManager(manager.Manager): candidates.sort(reverse = True, key = lambda can: (can.readiness, can.active_stats["SPD"])) # Set the 0th candidate as the current active piece and let it take a turn - self.current_active_piece = candidates[0] + self.current_active_piece = candidates.pop(0) self.current_active_piece.taking_turn = True - self.current_active_piece.readiness -= 100 # Predict the next turn order self.project_turn_order() + self.current_active_piece.readiness -= 100 def project_turn_order(self): """ @@ -97,8 +98,7 @@ class TurnManager(manager.Manager): projected turns). """ # Initial setup - pt = self.current_tick - self.turn_projection = [self.current_active_piece] + self.turn_projection = [] self.turn_icons = [] next_turn_candidates = [] rds = { i : i.readiness for i in self.in_play_pieces } @@ -111,21 +111,23 @@ class TurnManager(manager.Manager): rds[fc] -= 100 # If we did the above, reverse-sort the turn projection - if len(self.turn_projection) > 1: + if len(self.turn_projection) > 0: self.turn_projection.sort(reverse = True, key = lambda g: (g.readiness, g.active_stats["SPD"])) # Until we have the desired amount of projected turns, keep trying # to add new ones while len(self.turn_projection) < self.turn_depth: - pt += 1 for p in rds: rds[p] += p.active_stats["INIT"] + min(1, (p.active_stats["SPD"] // 3)) - if rds[p] >= 100 and len(self.turn_projection) < self.turn_depth: + if rds[p] >= 100: next_turn_candidates.append(p) rds[p] -= 100 - next_turn_candidates.sort(reverse = True, key = lambda can: (can.readiness, can.active_stats["SPD"])) + if len(next_turn_candidates) > 0: + next_turn_candidates.sort(reverse = True, key = lambda can: (rds[can] + 100, can.active_stats["SPD"])) for ntc in next_turn_candidates: - self.turn_projection.append(ntc) + if len(self.turn_projection) < self.turn_depth: + self.turn_projection.append(ntc) + next_turn_candidates = [] # Fill up the turn icons j = 0