def get_new_formations(areaname, supplement=True): from randomizer import get_namelocdict namelocdict = get_namelocdict() setids = set([]) for key in namelocdict: if type(key) is str and areaname in key: setids |= set(namelocdict[key]) fsets = [fs for fs in get_fsets() if fs.setid in setids] formations = set([]) for fs in fsets: formations |= set(fs.formations) if supplement: lowest = min(formations, key=lambda f: f.rank()).rank() highest = max(formations, key=lambda f: f.rank()).rank() supplemental = [f for f in get_formations() if not f.has_boss and lowest < f.rank() <= highest and not f.battle_event] supplemental = sorted(supplemental, key=lambda f: f.rank()) formations |= set([f for f in supplemental if f.ambusher or f.inescapable]) supplemental = supplemental[len(supplemental)/2:] formations |= set(supplemental) return sorted(formations, key=lambda f: f.formid)
def get_new_formations(areaname, supplement=True): from randomizer import get_namelocdict namelocdict = get_namelocdict() setids = set([]) for key in namelocdict: if type(key) is str and areaname in key: setids |= set(namelocdict[key]) fsets = [fs for fs in get_fsets() if fs.setid in setids] formations = set([]) for fs in fsets: formations |= set(fs.formations) if supplement: lowest = min(formations, key=lambda f: f.rank()).rank() highest = max(formations, key=lambda f: f.rank()).rank() supplemental = [ f for f in get_formations() if not f.has_boss and lowest < f.rank() <= highest and not f.battle_event ] supplemental = sorted(supplemental, key=lambda f: f.rank()) formations |= {f for f in supplemental if f.ambusher or f.inescapable} supplemental = supplemental[len(supplemental) // 2:] formations |= set(supplemental) return sorted(formations, key=lambda f: f.formid)
def get_2pack(formation): fsets = [fs for fs in get_fsets() if fs.setid >= 0x100] for fs in fsets: if fs.formations[0] == formation and fs.formations[1] == formation: return fs unused = [fs for fs in fsets if fs.unused][0] unused.formids = [formation.formid] * 2 return unused
def get_2pack(formation): fsets = [fs for fs in get_fsets() if fs.setid >= 0x100] for fs in fsets: if fs.formations[0] == formation and fs.formations[1] == formation: return fs unused = [fs for fs in fsets if fs.unused][0] unused.formids = [formation.formid] * 2 return unused
def get_new_fsets(areaname, number=10, supplement=True): if areaname in newfsets: return newfsets[areaname] newfsets[areaname] = [] formations = get_new_formations(areaname, supplement=supplement) fsets = get_fsets() unused = [fs for fs in fsets if fs.unused and len(fs.formations) == 4] tempforms = [] for _ in range(number): if len(tempforms) < 4: tempforms = list(formations) setforms = random.sample(tempforms, 4) fset = unused.pop() fset.formids = [f.formid for f in setforms] tempforms = [f for f in tempforms if f not in setforms] newfsets[areaname].append(fset) return get_new_fsets(areaname)
def get_new_fsets(areaname, number=10, supplement=True): if areaname in newfsets: return newfsets[areaname] newfsets[areaname] = [] formations = get_new_formations(areaname, supplement=supplement) fsets = get_fsets() unused = [fs for fs in fsets if fs.unused and len(fs.formations) == 4] tempforms = [] for _ in xrange(number): if len(tempforms) < 4: tempforms = list(formations) setforms = random.sample(tempforms, 4) fset = unused.pop() fset.formids = [f.formid for f in setforms] tempforms = [f for f in tempforms if f not in setforms] newfsets[areaname].append(fset) return get_new_fsets(areaname)
def make_challenge_event(loc, ptr): bg = ch_bgs.pop() formids = random.sample(challenges[loc.restrank], 2) formations = [get_formation(formid) for formid in formids] for formid in formids: challenges[loc.restrank].remove(formid) setcands = [f for f in get_fsets() if f.setid >= 0x100 and f.unused] fset = setcands.pop() fset.formids = formids fset.write_data(fout) timer = max( [e.stats['hp'] for f in formations for e in f.present_enemies]) reverse = False if timer >= 32768: reverse = True timer = 65535 - timer timer = max(timer, 3600) half = None while half is None or random.randint(1, 5) == 5: half = timer // 2 timer = half + random.randint(0, half) + random.randint(0, half) if reverse: timer = 65535 - timer timer = int(round(timer / 1800.0)) timer = max(2, min(timer, 36)) timer = timer * 1800 timer = [timer & 0xFF, timer >> 8] addr1 = ptr + 10 - 0xa0000 addr2 = ptr + (len(enemy_template) - 1) - 0xa0000 addr1 = [addr1 & 0xFF, (addr1 >> 8) & 0xFF, addr1 >> 16] addr2 = [addr2 & 0xFF, (addr2 >> 8) & 0xFF, addr2 >> 16] bytestring = list(enemy_template) bytestring[4:7] = addr1 bytestring[7:10] = addr2 bytestring[11:13] = timer bytestring[17] = fset.setid & 0xFF bytestring[18] = bg assert None not in bytestring sub = Substitution() sub.set_location(ptr) sub.bytestring = bytes(bytestring) sub.write(fout) return ptr + len(enemy_template)
def add_extra_miab(setid): setid |= 0x100 fset = [fs for fs in get_fsets() if fs.setid == setid][0] formation = fset.formations[0] if formation not in extra_miabs: extra_miabs.append(fset.formations[0])
def add_extra_miab(setid): setid |= 0x100 fset = [fs for fs in get_fsets() if fs.setid == setid][0] formation = fset.formations[0] if formation not in extra_miabs: extra_miabs.append(fset.formations[0])
go_to_train_event.y = entrance2.y location2.events.append(go_to_train_event) wrong_entrances = [ e for m in mids for e in m.entrances if e not in (entrance, entrance2) ] wrong_exits = [e for m in (mids + [start]) for e in m.entrances] for e in wrong_entrances: exit = random.choice(wrong_exits) map_entrance_to_exit(e, exit) if __name__ == "__main__": from sys import argv if len(argv) > 1: filename = argv[1] else: filename = "program.rom" from formationrandomizer import get_formations, get_fsets from monsterrandomizer import get_monsters get_monsters(filename) get_formations(filename) get_fsets(filename) locations = get_locations(filename) zones = get_zones(filename) for l in locations: print("%x" % (l.layers_to_animate & 2), l, end=' ') print()
ent for ent in beltroom.entrances if not (ent.x == 36 and ent.y == 25) ] beltroom.entrance_set.entrances.append(e2) final_room = get_location(411) e3 = Entrance() e3.x = 109 e3.y = 46 e3.destx, e3.desty, e3.dest = 82, 46, 412 | 0x2000 final_room.entrance_set.entrances.append(e3) newlocation.attacks = 0 newlocation.setid = 0 newlocation.music = 21 return newlocation, beltroom if __name__ == "__main__": from randomizer import get_monsters get_monsters(filename="program.rom") get_formations(filename="program.rom") get_fsets(filename="program.rom") get_locations(filename="program.rom") routes = randomize_tower("program.rom", ancient=True) for route in routes: print(route) print() print()
for ent in ents: if (locid, ent) in reachdict: raise Exception("Duplicate reachability in table.") reachdict[(locid, ent)] = ents key = entrance.location.locid, entrance.entid if key not in reachdict: return [] entrances = entrance.location.entrances return [e for e in entrances if e.entid in reachdict[key]] if __name__ == "__main__": from sys import argv if len(argv) > 1: filename = argv[1] else: filename = "program.rom" from formationrandomizer import get_formations, get_fsets, get_fset from monsterrandomizer import get_monsters get_monsters(filename) get_formations(filename) get_fsets(filename) locations = get_locations(filename) from formationrandomizer import fsetdict locations = get_locations("program.rom") zones = get_zones("program.rom") for l in locations: print "%x" % (l.layers_to_animate & 2), l, print
e2.destx, e2.desty, e2.dest = e.x, e.y, mapid beltroom.entrance_set.entrances = [ent for ent in beltroom.entrances if not (ent.x == 36 and ent.y == 25)] beltroom.entrance_set.entrances.append(e2) final_room = get_location(411) e3 = Entrance() e3.x = 109 e3.y = 46 e3.destx, e3.desty, e3.dest = 82, 46, 412 | 0x2000 final_room.entrance_set.entrances.append(e3) newlocation.attacks = 0 newlocation.setid = 0 newlocation.music = 21 return newlocation, beltroom if __name__ == "__main__": from randomizer import get_monsters get_monsters(filename="program.rom") get_formations(filename="program.rom") get_fsets(filename="program.rom") get_locations(filename="program.rom") routes = randomize_tower("program.rom", ancient=True) for route in routes: print route print print