Example #1
0
    def describe_wall_brush(self, tile_coords):
        params = self.params
        cfg = self.cfg
        tilemap = self.tilemap
        x, y = tile_coords
        tile = tilemap[x, y]
        partition_map = cfg.TILE_PARTITION_MAP
        pushwall_entity = cfg.ENTITY_PARTITION_MAP['pushwall'][0]
        face_shaders = []

        for direction, displacement in enumerate(DIR_TO_DISPL[:4]):
            facing_coords = [(x + displacement[0]), (y + displacement[1])]
            facing = tilemap.get(facing_coords)
            if facing is None:
                shader = 'common/caulk'
            else:
                if facing[1] == pushwall_entity:
                    facing_partition = 'floor'
                else:
                    facing_partition = find_partition(facing[0], partition_map, count_sign=1)

                if facing_partition == 'wall':
                    shader = 'common/caulk'
                else:
                    if facing_partition == 'floor':
                        texture = tile[0] - partition_map['wall'][0]
                    elif facing_partition in ('door', 'door_elevator', 'door_silver', 'door_gold'):
                        texture = partition_map['door_hinge'][0] - partition_map['wall'][0]
                    else:
                        raise ValueError((tile_coords, facing_partition))

                    shader = '{}_wall/{}__{}'.format(params.short_name, cfg.TEXTURE_NAMES[texture],
                                                     (direction & 1))
            face_shaders.append(shader)

        face_shaders.append('common/caulk')
        face_shaders.append('common/caulk')

        if any(shader != 'common/caulk' for shader in face_shaders):
            return self.describe_textured_cube(tile_coords, face_shaders, self.unit_offsets)
        else:
            return ()
Example #2
0
    def describe_entities(self):  # TODO
        cfg = self.cfg
        dimensions = self.tilemap.dimensions
        tilemap = self.tilemap
        lines = []
        turn_coords = []
        enemy_coords = []

        for tile_y in range(dimensions[1]):
            for tile_x in range(dimensions[0]):
                tile_coords = (tile_x, tile_y)
                tile = tilemap[tile_coords]

                if tile[1]:
                    partition = find_partition(tile[1], cfg.ENTITY_PARTITION_MAP, count_sign=-1)
                    lines.append('// {} @ {!r} = entity 0x{:04X}'.format(partition, tile_coords, tile[1]))

                    if partition == 'start':
                        lines += self.describe_player_start(tile_coords)
                    elif partition == 'turn':
                        turn_coords.append(tile_coords)
                    elif partition == 'enemy':
                        enemy_coords.append(tile_coords)
                    elif partition == 'pushwall':
                        lines += self.describe_pushwall(tile_coords)
                    elif partition == 'object' and cfg.ENTITY_OBJECT_MAP[tile[1]] in cfg.COLLECTABLE_OBJECT_NAMES:
                        lines += self.describe_object(tile_coords)

                if tile[0]:
                    if tile[0] in cfg.DOOR_MAP:
                        lines.append('// {} @ {!r} = door 0x{:04X}'.format(partition, tile_coords, tile[0]))
                        lines += self.describe_door(tile_coords)

        for coords in turn_coords:
            lines += self.describe_turn(coords, turn_coords)

        for coords in enemy_coords:
            lines += self.describe_enemy(coords, turn_coords)

        return lines
Example #3
0
    def describe_worldspawn(self):
        params = self.params
        cfg = self.cfg
        dimensions = self.tilemap.dimensions
        tilemap = self.tilemap
        pushwall_entity = cfg.ENTITY_PARTITION_MAP['pushwall'][0]
        music_name = cfg.MUSIC_NAMES[cfg.TILEMAP_MUSIC_INDICES[self.tilemap_index]]

        lines = ['{',
                 'classname worldspawn',
                 'message "{}"'.format(tilemap.name),
                 'music "music/{}/{}"'.format(params.short_name, music_name),
                 'ambient 100',
                 '_color "1 1 1"']

        for tile_y in range(dimensions[1]):
            for tile_x in range(dimensions[0]):
                tile_coords = (tile_x, tile_y)
                tile = tilemap[tile_coords]

                if tile[0]:
                    partition = find_partition(tile[0], cfg.TILE_PARTITION_MAP, count_sign=1)
                    lines.append('// {} @ {!r} = tile 0x{:04X}'.format(partition, tile_coords, tile[0]))

                    if (partition in ('floor', 'door', 'door_silver', 'door_gold', 'door_elevator') or
                        tile[1] == pushwall_entity):
                        lines.extend(self.describe_area_brushes(tile_coords))
                    elif partition == 'wall':
                        lines.extend(self.describe_wall_brush(tile_coords))
                    else:
                        raise ValueError((tile_coords, partition))

                if tile[1]:
                    object_name = cfg.ENTITY_OBJECT_MAP.get(tile[1])
                    if object_name and object_name in cfg.STATIC_OBJECT_NAMES:
                        lines += self.describe_sprite(tile_coords)

        lines.append('}  // worldspawn')
        return lines