Ejemplo n.º 1
0
def build_filled_generator(protocol, x1, y1, z1, x2, y2, z2, color, god = False, god_build = False):
    # create a player instance, freed when the generator is done
    # other scripts that also use ServerPlayer won't get the same id!
    # this won't be necessary in 1.0
    splayer = cbc.ServerPlayer()
    
    line = BlockLine()
    line.player_id = splayer.player_id
    
    set_color = SetColor()
    set_color.value = make_color(*color)
    set_color.player_id = splayer.player_id
    protocol.send_contained(set_color, save = True)
    packets = 1
    
    check_protected = hasattr(protocol, 'protected')
    if god_build and protocol.god_blocks is None:
        protocol.god_blocks = set()
    
    map = protocol.map
    
    ranges = [xrange(min(x1 , x2) , max(x1 , x2)+1)
            , xrange(min(y1 , y2) , max(y1 , y2)+1)
            , xrange(min(z1 , z2) , max(z1 , z2)+1)]
    
    order = zip(*sorted(zip([len(x) for x in ranges], [0, 1, 2])))[1]
    
    # set the first block position
    prod = ordered_product(ranges, order)
    line.x1, line.y1, line.z1 = prod.next()
    line.x2 = line.x1
    line.y2 = line.y1
    line.z2 = line.z1
    map.set_point(line.x1, line.y1, line.z1, color)
    
    for x, y, z in prod:
        packets = 0
        if not god and check_protected and protocol.is_protected(x, y, z):
            continue
        if god_build:
            protocol.god_blocks.add((x, y, z))
        changed = (line.x1 != x or line.x2 != x) + (line.y1 != y or line.y2 != y) + (line.z1 != z or line.z2 != z)
        dist = abs(line.x1 - x) + abs(line.y1 - y) + abs(line.z1 - z)
        if changed > 1 or dist >= MAX_LINE_BLOCKS:
            protocol.send_contained(line, save = True)
            packets += 2
            line.x1 = x
            line.y1 = y
            line.z1 = z
        line.x2 = x
        line.y2 = y
        line.z2 = z
        map.set_point(x, y, z, color)
        
        yield packets, 0
    protocol.send_contained(line, save = True)
    yield 1, 0
Ejemplo n.º 2
0
        def build_box_filled_generator(self, x1, y1, z1, x2, y2, z2, boxcolor):
            line = BlockLine()
            line.player_id = self.player_id
            # line.value = BUILD_BLOCK

            protocol = self.protocol
            check_protected = hasattr(protocol, 'protected')
            if self.god_build and protocol.god_blocks is None:
                protocol.god_blocks = set()

            ranges = [
                xrange(min(x1, x2),
                       max(x1, x2) + 1),
                xrange(min(y1, y2),
                       max(y1, y2) + 1),
                xrange(min(z1, z2),
                       max(z1, z2) + 1)
            ]

            order = zip(*sorted(zip([len(x) for x in ranges], [0, 1, 2])))[1]

            # set the first block position
            prod = ordered_product(ranges, order)
            line.x1, line.y1, line.z1 = prod.next()
            line.x2 = line.x1
            line.y2 = line.y1
            line.z2 = line.z1

            for x, y, z in prod:
                packets = 0
                if not self.god and check_protected and protocol.is_protected(
                        x, y, z):
                    continue
                if self.god_build:
                    protocol.god_blocks.add((x, y, z))
                changed = (line.x1 != x or line.x2 != x) + (
                    line.y1 != y or line.y2 != y) + (line.z1 != z
                                                     or line.z2 != z)
                dist = abs(line.x1 - x) + abs(line.y1 - y) + abs(line.z1 - z)
                if changed > 1 or dist >= MAX_LINE_BLOCKS:
                    protocol.send_contained(line)
                    packets += 1
                    line.x1 = x
                    line.y1 = y
                    line.z1 = z
                line.x2 = x
                line.y2 = y
                line.z2 = z
                protocol.map.set_point(x, y, z, boxcolor)

                yield packets, 0
            protocol.send_contained(line)
            yield 1, 0
Ejemplo n.º 3
0
 def build_box_filled_generator(self, x1, y1, z1, x2, y2, z2, boxcolor):
     line = BlockLine()
     line.player_id = self.player_id
     # line.value = BUILD_BLOCK
     
     protocol = self.protocol
     check_protected = hasattr(protocol, 'protected')
     if self.god_build and protocol.god_blocks is None:
         protocol.god_blocks = set()
     
     ranges = [xrange(min(x1 , x2) , max(x1 , x2)+1)
             , xrange(min(y1 , y2) , max(y1 , y2)+1)
             , xrange(min(z1 , z2) , max(z1 , z2)+1)]
     
     order = zip(*sorted(zip([len(x) for x in ranges], [0, 1, 2])))[1]
     
     # set the first block position
     prod = ordered_product(ranges, order)
     line.x1, line.y1, line.z1 = prod.next()
     line.x2 = line.x1
     line.y2 = line.y1
     line.z2 = line.z1
     
     for x, y, z in prod:
         packets = 0
         if not self.god and check_protected and protocol.is_protected(x, y, z):
             continue
         if self.god_build:
             protocol.god_blocks.add((x, y, z))
         changed = (line.x1 != x or line.x2 != x) + (line.y1 != y or line.y2 != y) + (line.z1 != z or line.z2 != z)
         dist = abs(line.x1 - x) + abs(line.y1 - y) + abs(line.z1 - z)
         if changed > 1 or dist >= MAX_LINE_BLOCKS:
             protocol.send_contained(line)
             packets += 1
             line.x1 = x
             line.y1 = y
             line.z1 = z
         line.x2 = x
         line.y2 = y
         line.z2 = z
         protocol.map.set_point(x, y, z, boxcolor)
         
         yield packets, 0
     protocol.send_contained(line)
     yield 1, 0
Ejemplo n.º 4
0
 def send_line(self, sender, x1, y1, z1, x2, y2, z2):
     block_line = BlockLine()
     block_line.player_id = 32
     block_line.x1 = x1
     block_line.y1 = y1
     block_line.z1 = z1
     block_line.x2 = x2
     block_line.y2 = y2
     block_line.z2 = z2
     sender(block_line, team=self.team)
Ejemplo n.º 5
0
def send_line(protocol, x1, y1, z1, x2, y2, z2):
    block_line = BlockLine()
    block_line.player_id = 32
    block_line.x1 = x1
    block_line.y1 = y1
    block_line.z1 = z1
    block_line.x2 = x2
    block_line.y2 = y2
    block_line.z2 = z2
    protocol.send_contained(block_line, save=True)
Ejemplo n.º 6
0
def build_filled_generator(protocol,
                           x1,
                           y1,
                           z1,
                           x2,
                           y2,
                           z2,
                           color,
                           god=False,
                           god_build=False):
    # create a player instance, freed when the generator is done
    # other scripts that also use ServerPlayer won't get the same id!
    # this won't be necessary in 1.0
    splayer = cbc.ServerPlayer()

    line = BlockLine()
    line.player_id = splayer.player_id

    set_color = SetColor()
    set_color.value = make_color(*color)
    set_color.player_id = splayer.player_id
    protocol.send_contained(set_color, save=True)
    packets = 1

    check_protected = hasattr(protocol, 'protected')
    if god_build and protocol.god_blocks is None:
        protocol.god_blocks = set()

    map = protocol.map

    ranges = [
        xrange(min(x1, x2),
               max(x1, x2) + 1),
        xrange(min(y1, y2),
               max(y1, y2) + 1),
        xrange(min(z1, z2),
               max(z1, z2) + 1)
    ]

    order = zip(*sorted(zip([len(x) for x in ranges], [0, 1, 2])))[1]

    # set the first block position
    prod = ordered_product(ranges, order)
    line.x1, line.y1, line.z1 = prod.next()
    line.x2 = line.x1
    line.y2 = line.y1
    line.z2 = line.z1
    map.set_point(line.x1, line.y1, line.z1, color)

    for x, y, z in prod:
        packets = 0
        if not god and check_protected and protocol.is_protected(x, y, z):
            continue
        if god_build:
            protocol.god_blocks.add((x, y, z))
        changed = (line.x1 != x or line.x2 != x) + (
            line.y1 != y or line.y2 != y) + (line.z1 != z or line.z2 != z)
        dist = abs(line.x1 - x) + abs(line.y1 - y) + abs(line.z1 - z)
        if changed > 1 or dist >= MAX_LINE_BLOCKS:
            protocol.send_contained(line, save=True)
            packets += 2
            line.x1 = x
            line.y1 = y
            line.z1 = z
        line.x2 = x
        line.y2 = y
        line.z2 = z
        map.set_point(x, y, z, color)

        yield packets, 0
    protocol.send_contained(line, save=True)
    yield 1, 0