def find_pass_loc(engine, x, y, w, direction, dice, checked=None): x0, y0 = x, y if w == 1: if engine.maparray[x0, y0][0] == 'void': return x, y else: return False, False offset = (dice[0] + dice[1] - 17) % w if (dice[0] % 2 == 0): delta = 1 else: delta = -1 for search_pos in range(w): d = (offset + delta * search_pos) % w x1, y1 = advance(x0, y0, back(turn_positive(direction)), d) success = True for i in range(w): x2, y2 = advance(x1, y1, turn_positive(direction), i) if x2 <= 1 or x2 + 1 >= engine.maparray.w: success = False break elif y2 <= 1 or y2 + 1 >= engine.maparray.h: success = False break elif engine.maparray[x2, y2][0] != 'void': success = False break if success is True: return x1, y1 return False, False
def draw_passage_section(engine, x, y, direction, width, length, psquare): o_dir = turn_positive(direction) origins = [advance(x, y, o_dir, i) for i in range(width)] step_out = False blocks = [] for i in range(length): new_origins = origins[:] for x0, y0 in origins: x1, y1 = advance(x0, y0, direction, i) if x1 <= 0 or x1 + 1 >= engine.maparray.w: new_origins.remove((x0, y0)) blocks.append((x1, y1)) elif y1 <= 0 or y1 + 1 >= engine.maparray.h: new_origins.remove((x0, y0)) blocks.append((x1, y1)) elif engine.maparray[x1, y1][0] != 'void': engine.log(":: draw_passage_section block") engine.log("\tblock at {}, remove {}".format((x1, y1), (x0, y0))) new_origins.remove((x0, y0)) blocks.append((x1, y1)) else: engine.maparray[x1, y1] = psquare origins = new_origins if step_out is True: break if len(origins) < width: step_out = True if step_out is False: x2, y2 = advance(x, y, direction, length) return (True, {"next_square": (x2, y2)}) else: return (False, {"blocks": blocks})
def dispatch_door(engine, element, dice): origin = element[1] x = element[2] y = element[3] direction = element[4] if x <= 1 or x >= engine.maparray.w: return (False, ) elif y <= 1 or y >= engine.maparray.h: return (False, ) if engine.maparray[x, y][0] not in ["void", "vwal", "hwal"]: return (False, ) # don't build doors next to doors or open spaces x0, y0 = advance(x, y, left(direction), 1) x1, y1 = advance(x, y, right(direction), 1) if engine.maparray[x0, y0][0] in ['room', 'door', 'hall', 'open']: return (False, ) if engine.maparray[x1, y1][0] in ['room', 'door', 'hall', 'open']: return (False, ) width = element[5] dsquare = element[6] die_roll = dice[0] dice = dice[1:] if dsquare[1] == -1: dsquare = engine.generate_description(dsquare) engine.describe(dsquare[1], {"type": "door", "d": direction}) r1, r2 = simple_door(engine, origin, x, y, direction, width, dsquare, dice) if r1 is True: return (True, ) elif r1 is False and r2 is False: return (False, ) # (False, True) use normal tables if die_roll <= 2: return table_passage_1_2(engine, origin, x, y, direction, width, dsquare, dice) elif die_roll <= 8: return table_passage_3_8(engine, origin, x, y, direction, width, dsquare, dice) elif die_roll <= 18: return table_chamber_9_18(engine, origin, x, y, direction, width, dsquare, dice)
def passage_table_11_12(engine, origin, x, y, direction, width, psquare, dice): catch1 = draw_passage_section(engine, x, y, direction, width, 4, psquare) if catch1[0] is False: return (True, (x, y, width, catch1[1]['blocks'])) px, py = catch1[1]['next_square'] catch = draw_passage_section(engine, px, py, direction, width, width, psquare) if catch[0] is False: return (True, (x, y, width, [])) # funky math to figure out turn coordinates if not is_positive(direction): px, py = catch[1]['next_square'] px, py = advance(px, py, back(direction), 1) px, py = turn_across(px, py, direction, left(direction), width) catch = draw_passage_section(engine, px, py, left(direction), width, 2, psquare) if catch[0] is False: return (True, (x, y, width, [])) px, py = catch[1]['next_square'] engine.add(['hall', 'passage', px, py, left(direction), width, psquare]) return (True, (x, y, width, []))
def passage_table_5(engine, origin, x, y, direction, width, psquare, dice): catch = draw_passage_section(engine, x, y, direction, width, 4, psquare) if catch[0] is False: return (True, (x, y, width, catch[1]['blocks'])) dx, dy = catch[1]['next_square'] dx, dy = advance(dx, dy, turn_positive(direction), middle_value(width, dice[0]) - 1) engine.add(['door', 'passage', dx, dy, direction, 1, ('door', -1)]) return (True, (x, y, width, []))
def place_door_pass(engine, x, y, direction, w, dice): w0 = w x0, y0 = advance(x, y, direction, 1) while w0 > 0: x1, y1 = find_pass_loc(engine, x0, y0, w0, direction, dice) if x1 is not False: return x1, y1, w0 else: if w0 > 2: w0 = w0 - 2 else: w0 = w0 - 1 return False, False, False
def simple_door(engine, origin, x, y, direction, width, dsquare, dice): simp = is_simple(engine.maparray, origin, x, y, direction) if simp == "forbidden": return (False, False) elif simp == "wall": x0, y0 = advance(x, y, direction, 1) engine.immediate_add( ['door', 'door', x0, y0, direction, 1, (dsquare[0], -1)]) if engine.dispatch_immediate()[0] is True: engine.maparray[x, y] = dsquare return (True, True) else: return (False, False) elif simp == "simple": engine.maparray[x, y] = dsquare return (True, True) elif simp == "void": return (False, True)
def is_simple(maparray, origin, x, y, direction): forbidden_tiles = ['bcor', 'tcor'] x0, y0 = advance(x, y, direction, 1) if x0 <= 1 or x0 + 1 >= maparray.w: return "forbidden" elif y0 <= 1 or y0 + 1 >= maparray.h: return "forbidden" dsquare = maparray[x0, y0][0] if dsquare in forbidden_tiles: return "forbidden" elif dsquare == "void": return "void" elif dsquare in ['hwal', 'vwal']: return "wall" else: return "simple"
def door_passage_table_1_2(engine, origin, x, y, direction, width, psquare, dice): catch = draw_passage_section(engine, x, y, direction, width, 2, psquare) if catch[0] is False: return (True, (x, y, width, catch[1]['blocks'])) x0, y0 = catch[1]['next_square'] catch = draw_passage_section(engine, x0, y0, direction, width, width, psquare) if catch[0] is False: return (True, (x, y, width, catch[1]['blocks'])) x1, y1 = catch[1]['next_square'] px, py = x0, y0 if not is_positive(direction): px, py = x1, y1 px, py = advance(px, py, back(direction), 1) rx, ry = turn_across(px, py, direction, right(direction), width) lx, ly = turn_across(px, py, direction, left(direction), width) rcatch = draw_passage_section(engine, rx, ry, right(direction), width, 2, psquare) if rcatch[0] is not False: rx, ry = rcatch[1]['next_square'] engine.add( ['hall', 'passage', rx, ry, right(direction), width, psquare]) lcatch = draw_passage_section(engine, lx, ly, left(direction), width, 2, psquare) if lcatch[0] is not False: lx, ly = lcatch[1]['next_square'] engine.add( ['hall', 'passage', lx, ly, left(direction), width, psquare]) return (True, (x, y, width, []))