diff --git a/model.py b/model.py index 111a5cb..16c8fb7 100644 --- a/model.py +++ b/model.py @@ -6,6 +6,7 @@ def __init__(self, row_num, column_num, paths, units, kings, cells): self.row_num = row_num self.column_num = column_num self.paths = paths + self.paths_dict = dict([(path.id, path) for path in paths]) self.units = units self.kings = kings self.cells = cells @@ -19,10 +20,7 @@ def clear_units(self): cell.clear_units() def get_path_by_id(self, path_id): - for path in self.paths: - if path.path_id == path_id: - return path - return None + return self.paths_dict[path_id] def add_unit_in_cell(self, row, column, unit): self.cells[row][column].add_unit(unit) diff --git a/world.py b/world.py index 63fb2d4..e9c4be5 100644 --- a/world.py +++ b/world.py @@ -420,11 +420,17 @@ def get_current_turn(self): # put unit_id in path_id in position 'index' all spells of one kind have the same id def cast_unit_spell(self, unit_id, path_id, index, spell=None, spell_id=None): + if spell is None and spell_id is None: + return None path = None for p in self.map.paths: if p.path_id == path_id: path = p break + if path is None: + return None + if index < len(path.cells): + return None cell = path.cells[index] if spell is None: spell = self.get_spell_by_type_id(spell_id)