Exemplo n.º 1
0
def occupied_track_positions(track):
    positions = {}
    for block in track:
        name = get_block_name(block[BID], STADIUM_BLOCKS)
        if not name:
            continue

        try:
            if is_on_ground(block) and name in DYNAMIC_GROUND_OFFSETS:
                offsets = DYNAMIC_GROUND_OFFSETS[name]
            else:
                offsets = STADIUM_BLOCK_OFFSETS[name]
        except KeyError:
            continue

        offsets, _, _ = rotate_block_offsets(offsets, block[BROT])
        block_positions = []
        for offset in offsets:
            block_positions.append(
                Vector3(block[BX] + offset[0], block[BY] + offset[1],
                        block[BZ] + offset[2]))

        positions[block] = block_positions

    return positions
Exemplo n.º 2
0
def is_on_ground(block):
    try:
        offsets = STADIUM_BLOCK_OFFSETS[get_block_name(block[BID],
                                                       STADIUM_BLOCKS)]
        for offset in offsets:
            if block[BY] + offset[1] == 1:
                return True
    except KeyError:
        pass

    return False
Exemplo n.º 3
0
    def write_block(self, block: tuple):
        bname = get_block_name(block[BID], STADIUM_BLOCKS)
        self.write_lookback_string(bname)
        self.write_byte(block[BROT])
        self.write_byte(max(0, block[BX]))
        self.write_byte(max(1, block[BY]))
        self.write_byte(max(0, block[BZ]))

        flags = 0
        if len(block) > 5:
            flags = block[5]
            if flags & 0x8000:
                flags &= 0x0fff

            if flags & 0x100000:
                flags &= 0x0fffff

        self.write_uint32(flags)
Exemplo n.º 4
0
def write_block(stored_strings, seen_lookback, block):
    bstr = bytearray()

    bname = get_block_name(block[BID], STADIUM_BLOCKS)
    bstr += write_lookback_string(stored_strings, seen_lookback, bname)

    bstr += struct.pack('B', block[BROT])
    bstr += struct.pack('B', max(0, block[BX]))
    bstr += struct.pack('B', max(1, block[BY]))
    bstr += struct.pack('B', max(0, block[BZ]))

    flags = 0
    if len(block) > 5:
        flags = block[5]
        if flags & 0x8000:
            flags &= 0x0fff

        if flags & 0x100000:
            flags &= 0x0fffff

    bstr += struct.pack('I', flags)
    return bstr
Exemplo n.º 5
0
def is_on_ground(block: tuple) -> bool:
    '''
    Determines whether the block is on the ground.

    Gets the offsets for the block and checks if any of them
    is on the level 1.

    Args:
        block (tuple): the block to check
    
    Returns:
        bool: whether the block is on the ground
    '''
    try:
        offsets = STADIUM_BLOCK_OFFSETS[get_block_name(block[BID],
                                                       STADIUM_BLOCKS)]
        for offset in offsets:
            if block[BY] + offset[1] == 1:
                return True
    except KeyError:
        pass

    return False
Exemplo n.º 6
0
def occupied_track_positions(track: list) -> dict:
    '''
    Produces a dict of each block and its occupied positions.

    Some blocks may have different offsets depending on whether
    they are on the ground or not.

    Args:
        track (list): the list of block tuples
    
    Returns:
        dict: blocks as keys and their occupied positions as values
    '''
    positions = {}
    for block in track:
        name = get_block_name(block[BID], STADIUM_BLOCKS)
        if not name:
            continue

        try:
            if is_on_ground(block) and name in DYNAMIC_GROUND_OFFSETS:
                offsets = DYNAMIC_GROUND_OFFSETS[name]
            else:
                offsets = STADIUM_BLOCK_OFFSETS[name]
        except KeyError:
            continue

        offsets, _, _ = rotate_block_offsets(offsets, block[BROT])
        block_positions = []
        for offset in offsets:
            block_positions.append(
                Vector3(block[BX] + offset[0], block[BY] + offset[1],
                        block[BZ] + offset[2]))

        positions[block] = block_positions

    return positions