commit 7954932e7a00a06197d93a48519f474300b5705f
parent 08df1ae377189703c03a7c9f17a06c19ee007249
Author: Erik Letson <hmagellan@hmagellan.com>
Date: Mon, 2 Nov 2020 14:23:25 -0600
Some basic turn ordering functions, will greatly change
Diffstat:
3 files changed, 84 insertions(+), 7 deletions(-)
diff --git a/data/json/ents/testmap1.json b/data/json/ents/testmap1.json
@@ -3,12 +3,24 @@
"name" : "Jisella",
"type" : "Piece",
"sheet" : "jisella_1",
- "sprite" : [0, 0],
+ "sprite" : [0, 0],
"visible" : true,
"animation" : "stand_L",
"animated" : true,
"passable" : false,
"tile" : [5, 4],
"team" : "Player"
- }
+ },
+ "testent2" : {
+ "name" : "Fakella",
+ "type" : "Piece",
+ "sheet" : "jisella_1",
+ "sprite" : [0, 0],
+ "visible" : true,
+ "animation" : "stand_R",
+ "animated" : true,
+ "passable" : false,
+ "tile" : [0, 2],
+ "team" : "Player"
+ }
}
diff --git a/src/turn.py b/src/turn.py
@@ -27,14 +27,42 @@ class TurnManager(manager.Manager):
super().__init__(game)
# Important values
- self.current_turn = 1
+ self.current_turn_number = 1
self.current_active_piece = None
- self.turn_order = []
+ self.current_turn_order = []
self.turn_tray = None
+ self.turn_depth = 10 # How many turns to calculate in advance
+ self.initiative_scores = {}
+
+ def initialize_turns(self, pieces):
+ """
+ Load up the turns for the first time.
+ """
+ self.initiative_scores = { p.name : 0 for p in self.game.entity_manager.pieces }
-##############################
-# Section 2 - TurnTray class #
-##############################
+ def calculate_turn_order(self):
+ """
+ Calculate turn order based on Piece stats.
+ """
+ self.current_turn_order = []
+ while len(self.current_turn_order) - 1 < self.turn_depth:
+ for p in self.initiative_scores:
+ if self.initiative_scores[p] >= 100:
+ self.current_turn_order.append(p)
+ workent = self.game.entity_manager.get_entity_by_name(p)
+ result = workent.active_stats["INIT"] + int(workent.active_stats["SPD"] / 10)
+ self.initiative_scores[p] += result
+
+ def update_turn_entities(self, surface):
+ """
+ Update the entities this manager controls.
+ """
+ if surface != None:
+ pass
+
+#############################
+# Section 2 - Turn Entities #
+#############################
class TurnTray(vgo.Entity):
"""
@@ -49,3 +77,16 @@ class TurnTray(vgo.Entity):
# Parent initialization
super().__init__(sheet, sprite, animation, animated)
+class TurnButton(vgo.Entity):
+ """
+ Class representing the buttons with icons and names
+ that appear in order inside the TurnTray object.
+ Clicking one will lock the cursor on that Piece.
+ """
+
+ def __init__(self, name, ent_id, sheet, sprite = (0, 0), animation = None, animated = False):
+
+ # Parent initialization
+ super().__init__(sheet, sprite, animation, animated)
+
+
diff --git a/src/vgo.py b/src/vgo.py
@@ -363,6 +363,7 @@ class EntityManager(manager.Manager):
self.tile_cursor = None
self.selected_entity = None
self.total_entities = 0 # total number of unique entities loaded
+ self.pieces = []
def add_entity(self, entity):
"""
@@ -391,6 +392,7 @@ class EntityManager(manager.Manager):
self.game.sheet_manager.animations[j[e]["sheet"]][j[e]["animation"]],
j[e]["animated"], j[e]["passable"], unit.Unit(self, self.game.unit_manager.get_stats(j[e]["name"])),
j[e]["team"])
+ self.pieces.append(ne)
ne.assign_tile(self.game.board_manager.get_tile_at_tile_pos(tuple(j[e]["tile"])))
ne.snap_to_tile()
self.add_entity(ne)
@@ -403,6 +405,28 @@ class EntityManager(manager.Manager):
self.tile_cursor.set_animation(self.game.sheet_manager.animations["cursor1"]["pulse"], True)
self.add_entity(self.tile_cursor)
+ def get_entity_by_id(self, idnum):
+ """
+ Returns an entity by its id number.
+ """
+ ent = None
+ for e in self.loaded_entities:
+ if e.ent_id == idnum:
+ ent = e
+ break
+ return ent
+
+ def get_entity_by_name(self, name):
+ """
+ Returns an entity matching name.
+ """
+ ent = None
+ for e in self.loaded_entities:
+ if e.name == name
+ ent = e
+ break
+ return ent
+
def position_tile_cursor(self, tile_def):
"""
Snap the TileCursor object's position to 'pos' and set the