Exemplo n.º 1
0
    def __init__(self, obj):
        super(NPC, self).__init__()

        pos = floored_tuple(obj.worldPosition)
        obj.worldPosition = Vector(pos)
        self._pos = obj.worldPosition

        self.last_voxel = logic.chunks.quick_voxel(self.pos)
        self.register(self.last_voxel)
        self.obj = obj
        self.visual = obj.children.get(obj.name + '_visual')
        self.info = obj.children.get(obj.name + '_text')
        self.alive = True

        self.target = None
        self.path = None

        self.stupid = True

        self.energy = 0

        NPC.COUNT += 1
        self.name = 'NPC_BASIC'

        self.old_trace = 0, None
    def __init__(self, obj):
        super(NPC, self).__init__()

        pos = floored_tuple(obj.worldPosition)
        obj.worldPosition = Vector(pos)
        self._pos = obj.worldPosition

        self.last_voxel = logic.chunks.quick_voxel(self.pos)
        self.register(self.last_voxel)
        self.obj = obj
        self.visual = obj.children.get(obj.name + '_visual')
        self.info = obj.children.get(obj.name + '_text')
        self.alive = True

        self.target = None
        self.path = None

        self.stupid = True

        self.energy = 0

        NPC.COUNT += 1
        self.name = 'NPC_BASIC'

        self.old_trace = 0, None
    def path_generator_factory(self):
        if logic.marker:
            node_x, node_y, node_z = self.pos
            broken = False
            for delta_vector, airspace in POSSIBLE_MOVES_DICT.items():
                new_x, new_y, new_z = node_x + delta_vector[0], node_y + delta_vector[1], node_z + delta_vector[2]
                new_ground_pos = new_x, new_y, new_z - 1
                ground = logic.chunks.quick_voxel(new_ground_pos)
                if not is_solid(ground):
                    continue
                broken = False
                for delta_air_x, delta_air_y, delta_air_z in airspace:
                    new_air_pos = (
                        node_x + delta_air_x,
                        node_y + delta_air_y,
                        node_z + delta_air_z,
                    )
                    current_voxel = logic.chunks.quick_voxel(new_air_pos)
                    if is_npc(current_voxel) and current_voxel.NPC != self:
                        broken = True
                        break
                if not broken:
                    break
            if broken:
                return

            start = floored_tuple(self.pos)
            return self.path_generator(start, logic.marker, self, search_limit=4000, destructive=randint(0, 1))
Exemplo n.º 4
0
    def path_generator_factory(self):
        if logic.marker:
            node_x, node_y, node_z = self.pos
            broken = False
            for delta_vector, airspace in POSSIBLE_MOVES_DICT.items():
                new_x, new_y, new_z = node_x + delta_vector[
                    0], node_y + delta_vector[1], node_z + delta_vector[2]
                new_ground_pos = new_x, new_y, new_z - 1
                ground = logic.chunks.quick_voxel(new_ground_pos)
                if not is_solid(ground):
                    continue
                broken = False
                for delta_air_x, delta_air_y, delta_air_z in airspace:
                    new_air_pos = (
                        node_x + delta_air_x,
                        node_y + delta_air_y,
                        node_z + delta_air_z,
                    )
                    current_voxel = logic.chunks.quick_voxel(new_air_pos)
                    if is_npc(current_voxel) and current_voxel.NPC != self:
                        broken = True
                        break
                if not broken:
                    break
            if broken:
                return

            start = floored_tuple(self.pos)
            return self.path_generator(start,
                                       logic.marker,
                                       self,
                                       search_limit=4000,
                                       destructive=randint(0, 1))
def raycast(checkPos):
    chunkKey = tuple_to_chunk_key(checkPos)
    chunk = logic.chunks.get(chunkKey)

    if chunk:
        localPos = floored_tuple(Vector(checkPos) - Vector(chunkKey))

        voxelIndex = tuple_to_index(localPos)
        if chunk.voxels[voxelIndex]:
            return chunk, voxelIndex
        return chunk, None
    return None, None
def raycast(checkPos):
    chunkKey = tuple_to_chunk_key(checkPos)
    chunk = logic.chunks.get(chunkKey)

    if chunk:
        localPos = floored_tuple(Vector(checkPos) - Vector(chunkKey))

        voxelIndex = tuple_to_index(localPos)
        if chunk.voxels[voxelIndex]:
            return chunk, voxelIndex
        return chunk, None
    return None, None
    def check_move(self, vector):
        x, y, z = self.pos
        air_space = POSSIBLE_MOVES_DICT.get(floored_tuple(vector))
        if air_space is None:
            return False

        ground = logic.chunks.quick_voxel((x, y, z - 1))
        if is_air(ground):
            return False

        for dx, dy, dz in air_space:
            if not is_air(logic.chunks.quick_voxel((x + dx, y + dy, z + dz))):
                return False
        return True
Exemplo n.º 8
0
    def check_move(self, vector):
        x, y, z = self.pos
        air_space = POSSIBLE_MOVES_DICT.get(floored_tuple(vector))
        if air_space is None:
            return False

        ground = logic.chunks.quick_voxel((x, y, z - 1))
        if is_air(ground):
            return False

        for dx, dy, dz in air_space:
            if not is_air(logic.chunks.quick_voxel((x + dx, y + dy, z + dz))):
                return False
        return True
Exemplo n.º 9
0
    def complete(self, worker):
        yield PathObject.PATH_WAIT
        while True:
            if worker.energy > 0.3:
                if self.destructible:
                    delta = floored_tuple(
                        Vector(self.pos) - Vector(worker.pos))
                    if not delta in POSSIBLE_MOVES_DICT:
                        yield PathObject.PATH_FAIL

                    for dv in POSSIBLE_MOVES_DICT[delta]:
                        check_pos = Vector(worker.pos) + Vector(dv)
                        voxel = logic.chunks.quick_voxel(check_pos)
                        if is_solid(voxel):
                            logic.work.append(RemoveWork(check_pos, 0))
                            for i in range(20):
                                if voxel.val != 0:
                                    yield PathObject.PATH_WAIT
                                else:
                                    break

                valid_move = worker.relative_move(Vector(self.pos))
                if valid_move:
                    worker.walk_expend()
                    yield PathObject.PATH_SUCCESS
                    break
                else:
                    if DEBUG_NORMAL():
                        print("PathObject: path has changed")
                    voxel = logic.chunks.quick_voxel(self.pos)
                    if is_npc(voxel):
                        for i in range(20):
                            if is_npc(voxel):
                                yield PathObject.PATH_WAIT
                            else:
                                if DEBUG_NORMAL():
                                    print("PathObject: path recovered")
                                for i in range(4):
                                    yield PathObject.PATH_WAIT
                                break
                        else:
                            if DEBUG_NORMAL():
                                print("PathObject: path timed out")
                            yield PathObject.PATH_FAIL
                        continue
                    yield PathObject.PATH_FAIL
            yield PathObject.PATH_WAIT
    def complete(self, worker):
        yield PathObject.PATH_WAIT
        while True:
            if worker.energy > 0.3:
                if self.destructible:
                    delta = floored_tuple(Vector(self.pos) - Vector(worker.pos))
                    if not delta in POSSIBLE_MOVES_DICT:
                        yield PathObject.PATH_FAIL

                    for dv in POSSIBLE_MOVES_DICT[delta]:
                        check_pos = Vector(worker.pos) + Vector(dv)
                        voxel = logic.chunks.quick_voxel(check_pos)
                        if is_solid(voxel):
                            logic.work.append(RemoveWork(check_pos, 0))
                            for i in range(20):
                                if voxel.val != 0:
                                    yield PathObject.PATH_WAIT
                                else:
                                    break

                valid_move = worker.relative_move(Vector(self.pos))
                if valid_move:
                    worker.walk_expend()
                    yield PathObject.PATH_SUCCESS
                    break
                else:
                    if DEBUG_NORMAL():
                        print("PathObject: path has changed")
                    voxel = logic.chunks.quick_voxel(self.pos)
                    if is_npc(voxel):
                        for i in range(20):
                            if is_npc(voxel):
                                yield PathObject.PATH_WAIT
                            else:
                                if DEBUG_NORMAL():
                                    print("PathObject: path recovered")
                                for i in range(4):
                                    yield PathObject.PATH_WAIT
                                break
                        else:
                            if DEBUG_NORMAL():
                                print("PathObject: path timed out")
                            yield PathObject.PATH_FAIL
                        continue
                    yield PathObject.PATH_FAIL
            yield PathObject.PATH_WAIT
    def change_iterator(self):
        pos = floored_tuple(self.add_pos)

        refresh = set()

        new_pos = Vector(pos)
        for dv in logic.BLAST_DELTA:
            chunk, voxel = logic.chunks.raycast(new_pos + dv)
            if voxel and voxel.val != self.type:
                voxel.val = self.type
                refresh.add(chunk.get_key())

            if dv.length >= 0.93 * logic.RADIUS:
                obj = scene.addObject("Explosion", own, 5)
                obj.orientation = 0, 0, 0
                obj.worldPosition = new_pos + dv
            yield False

        to_spawn = set()
        for key in refresh:
            c = logic.chunks.get(key)
            if c:
                for i in range((CHUNK_SIZE + 1) * 3):
                    c.generate_faces_by_index(i)
                    yield False
                yield False
                to_spawn |= set(logic.chunks.update(key, gen_faces=False))
                yield False
        for key in to_spawn:
            c = logic.chunks[key]
            for i in range((CHUNK_SIZE + 1) * 3):
                c.generate_faces_by_index(i)
                yield False
            yield False
            logic.chunks.update(key, gen_faces=False)
            yield False
        yield True
Exemplo n.º 12
0
 def path_generator_factory(self):
     start = floored_tuple(self.pos)
     return NearestTargetPathGenerator(start,
                                       Sheep,
                                       self,
                                       search_limit=70 + int(self.hunger))
 def path_generator_factory(self):
     start = floored_tuple(self.pos)
     return NearestTargetPathGenerator(start, Sheep, self, search_limit=70 + int(self.hunger))
Exemplo n.º 14
0
 def pos(self, vector):
     self.obj.worldPosition = floored_tuple(vector)
     self._pos = self.obj.worldPosition.copy()
     return self._pos
 def path_generator_factory(self):
     start = floored_tuple(self.pos)
     return SimplePathGenerator(start, logic.marker, self)
Exemplo n.º 16
0
 def path_generator_factory(self):
     start = floored_tuple(self.pos)
     return SimplePathGenerator(start, logic.marker, self)
 def pos(self, vector):
     self.obj.worldPosition = floored_tuple(vector)
     self._pos = self.obj.worldPosition.copy()
     return self._pos
 def __init__(self, remove_pos, work_type):
     super(RemoveWork, self).__init__()
     self.remove_pos = floored_tuple(remove_pos)
     self.type = work_type
     self.tool = self.change_iterator