Beispiel #1
0
    def load_battle_setup(self, battle_setup_id):
        assert not self.battle
        setup = data_bank.get_battle_setup(battle_setup_id)
        assert setup is not None

        squads = OrderedDict()
        for player_info in setup.data['players']:
            player_class = Player if player_info[
                'control'] == 'human' else PlayerAI
            p = player_class(self, player_info['name'],
                             Color(player_info['color']))
            squads[p] = []
            for unit_info in player_info['squad']:
                template = data_bank.get_unit_template(unit_info['template'])
                u = Unit(template)
                for weapon_name in unit_info['weapons']:
                    w = p.add_weapon(weapon_name)
                    u.equip(w)
                p.add_unit(u)
                squads[p].append(u)
                u.move_to(hex_coords=Hex(*unit_info['position']),
                          orientation=Hex(*unit_info['orientation']))
            self.players.append(p)

        self.battle = Battle(setup.data['board'], self.players)
        self.battle.set_tie(self.players[0], self.players[1], TieType.enemy)
        self.battle.deploy(squads)
Beispiel #2
0
    def __init__(self, file_id, data, **kwargs):
        super(BoardTemplate, self).__init__(file_id, **kwargs)
        attr.get_from_dict(self, data, *BoardTemplate.__attributes)
        self.type = BoardType[data['type']]
        self.holes = [Hex(*qr)
                      for qr in data['holes']] if 'holes' in data else []
        self.tiles = [Hex(*qr)
                      for qr in data['adds']] if 'adds' in data else []
        self.walls = [Wall(d)
                      for d in data['walls']] if 'walls' in data else []

        # call the appropriate creator
        BoardTemplate.__creators[self.type](self.tiles, self.holes,
                                            **self.info)
Beispiel #3
0
def build_hexagon(tiles, holes, radius):
    for q in range(-radius, radius + 1):
        r1 = max(-radius, -q - radius)
        r2 = min(radius, -q + radius)
        for r in range(r1, r2 + 1):
            if (q, r) not in holes:
                tiles.append(Hex(q, r))
Beispiel #4
0
    def __init__(self, q=0, r=0, layout=None, radius=None, **kwargs):
        self.hex_coords = Hex(q, r)
        self.hex_layout = layout
        self.radius = radius or layout.size.x if layout else 0

        super(HexWidget, self).__init__(size_hint=(None, None), **kwargs)
        self.pos = layout.hex_to_pixel(
            self.hex_coords).tup if layout and self.hex_coords else self.pos
Beispiel #5
0
    def __init__(self, file_id, data, get_skill, get_actions_tree, **kwargs):
        super(UnitTemplate, self).__init__(file_id, **kwargs)
        attr.get_from_dict(self, data, *UnitTemplate.__attributes)
        self.actions_tree = get_actions_tree(data['actions_tree_name'],
                                             parent=self)

        self.skills = [
            RankedSkill(get_skill(n, parent=self), Rank[rank])
            for n, rank in data['skills'].items()
        ] if 'skills' in data else []

        self.shape = [Hex(0, 0)]
        if 'shape' in data:
            self.shape = []
            shape_def = data['shape']
            for index in range(0, len(shape_def), 2):
                self.shape.append(
                    Hex(q=shape_def[index], r=shape_def[index + 1]))

        self.name = LocStr(self.loc_key_name)
        self.description = LocStr(self.loc_key_desc)
Beispiel #6
0
    def load_grid(self, content_hexes=None):
        self.unload_grid()
        if content_hexes:
            self.content_hexes = content_hexes
        self.hex_layout = Layout(origin=self.center,
                                 size=self.hex_radius,
                                 flat=game_instance.flat_layout,
                                 margin=self.hex_margin)

        if len(self.content_hexes) == 0:
            self.grid_hexes.add(Hex(0, 0))
        else:
            for h in self.content_hexes:
                tile = self.create_content_tile(h)
                self.add_widget(tile)
                self.tiles.append(tile)
                self.grid_hexes.update(self.get_close_grid_tiles(h))

        for h in self.grid_hexes:
            tile = self.create_grid_tile(h)
            self.add_widget(tile)
            self.tiles.append(tile)
Beispiel #7
0
 def test_length(self):
     h1 = Hex(2, 2)
     self.assertEqual(h1.length, 4)
Beispiel #8
0
 def __init__(self, data):
     self.origin = Hex(*data[0:2])
     self.destination = Hex(*data[2:4])
     self.types = [WallType(x) for x in data[4:]]
Beispiel #9
0
 def get_neighbours(h: Hex):
     for neighbour in h.get_neighbours():
         if neighbour not in self.content_hexes:
             yield neighbour
Beispiel #10
0
 def test_sub_inplace(self):
     h1 = Hex(3, -7, 4)
     h1 -= Hex(-1, 3, -2)
     self.assertEqual(h1, self.result)
Beispiel #11
0
def build_rectangle(tiles, holes, height, width):
    for r in range(height):
        r_offset = floor(r / 2.)
        for q in range(-r_offset, width - r_offset):
            if (q, r) not in holes:
                tiles.append(Hex(q, r))
Beispiel #12
0
 def test_add_inplace(self):
     h1 = Hex(3, -7, 4)
     h1 += Hex(1, -3, 2)
     self.assertEqual(h1, self.result)
Beispiel #13
0
 def test_sub(self):
     h1 = Hex(3, -7, 4)
     h2 = Hex(-1, 3, -2)
     result = h1 - h2
     self.assertEqual(result, self.result)
Beispiel #14
0
 def setUp(self):
     self.result = Hex(4, -10, 6)
Beispiel #15
0
 def test_add(self):
     h1 = Hex(3, -7, 4)
     h2 = Hex(1, -3, 2)
     result = h1 + h2
     self.assertEqual(result, self.result)
Beispiel #16
0
def build_triangle(tiles, holes, size):
    for q in range(size + 1):
        for r in range(size - q, size + 1):
            if (q, r) not in holes:
                tiles.append(Hex(q, r))
Beispiel #17
0
 def test_properties(self):
     h1 = Hex(5, 2)
     self.assertEqual(h1.q, 5)
     self.assertEqual(h1.r, 2)
     self.assertEqual(h1.s, -7)
Beispiel #18
0
def build_parallelogram(tiles, holes, q1, q2, r1, r2):
    for q in range(q1, q2 + 1):
        for r in range(r1, r2 + 1):
            if (q, r) not in holes:
                tiles.append(Hex(q, r))
Beispiel #19
0
 def heuristic(a: Hex, b: Hex):
     return a.distance(b)
Beispiel #20
0
 def setup(self, q, r, layout, radius=None):
     self.hex_coords = Hex(q, r)
     self.hex_layout = layout
     self.radius = radius or layout.size.x if layout else 0
     self.pos = layout.hex_to_pixel(self.hex_coords)