def main():
    rpgbs_init()
    while 1:
        SimpleIOHandler().println("<b>AVAILABLE TEAMS:</b>")
        for team in sorted(rental_teams.keys()):
            names = []
            for teammate in rental_teams[team]:
                names.append(teammate.name)
            SimpleIOHandler().println(str(team) + ":", ", ".join(names))
        SimpleIOHandler().println("c: Custom team")
        SimpleIOHandler().println("q: Quit")
        team1 = False
        if len(sys.argv) > 1:
            if not os.path.isdir(sys.argv[1]):
                team1 = sys.argv[1]
        while not team1 in rental_teams.keys() and not os.path.exists(str(team1)) and not os.path.isdir(str(team1)):
            team1 = SimpleIOHandler().input("Enter the name of your selection here (Team 1): ")
            if team1.lower() == "q" or team1.lower() == "quit":
                sys.exit()
            elif team1.lower() == "c":
                while not os.path.exists(team1) and not os.path.isdir(str(team1)) and not team1.lower() == "r":
                    team1 = SimpleIOHandler().input("Enter a valid pathname here (r: return): ")
                if not team1.lower() == "r":
                    break
        if os.path.exists(team1) and not os.path.isdir(team1):
            if team1.endswith(".rbst"):
                file_ = open(team1, "rb")
                team1 = pickle.load(file_)
            else:
                file_ = open(team1, "r")
                team1 = team_from_rbs2(json.load(file_))
            file_.close()
        else:
            team1 = copy.deepcopy(rental_teams[team1])
        team2 = False
        if len(sys.argv) > 2:
            if not os.path.isdir(sys.argv[2]):
                team2 = sys.argv[2]
        while not team2 in rental_teams.keys() and not os.path.exists(str(team2)) and not os.path.isdir(str(team2)):
            team2 = SimpleIOHandler().input("Enter the name of your selection here (Team 2): ")
            if team2.lower() == "q" or team2.lower() == "quit":
                sys.exit()
            elif team2.lower() == "c":
                while not os.path.exists(team2) and not os.path.isdir(str(team2)) and not team2.lower() == "r":
                    team2 = SimpleIOHandler().input("Enter a valid pathname here (r: return): ")
                if not team2.lower() == "r":
                    break
        if os.path.exists(team2) and not os.path.isdir(team2):
            if team2.endswith(".rbst"):
                file_ = open(team2, "rb")
                team2 = pickle.load(file_)
            else:
                file_ = open(team2, "r")
                team2 = team_from_rbs2(json.load(file_))
        else:
            team2 = copy.deepcopy(rental_teams[team2])
        for character in team1:
            if not character.is_approved():
                SimpleIOHandler().input("<b>WARNING:</b> At least one of the characters in Team 1 has not been approved for normal play.")
                break
        for character in team2:
            if not character.is_approved():
                SimpleIOHandler().input("<b>WARNING:</b> At least one of the characters in Team 2 has not been approved for normal play.")
                break
        versus = False
        while not versus == "y" and not versus == "n":
            versus = SimpleIOHandler().input("Is this a 2-player match? (y/n): ")
        if versus == "n":
            difficulty = False
            while 1:
                SimpleIOHandler().println()
                SimpleIOHandler().println("<b>AVAILABLE AIS:</b>")
                for a in all_ais.list_ais():
                    SimpleIOHandler().println(a)
                difficulty = SimpleIOHandler().input("Enter your selection here:")
                try: exec("import ai." + difficulty)
                except: pass
                else: break
        else:
            difficulty = 0
        if not "-a" in sys.argv:
            mode = "priority"
        else:
            SimpleIOHandler().println()
            SimpleIOHandler().println("<b>AVAILABLE MODES:</b>")
            for m in modes:
                SimpleIOHandler().println(m)
            mode = False
            while not mode in modes:
                mode = SimpleIOHandler().input("Enter a mode here: ")
        SimpleIOHandler().println()
        SimpleIOHandler().println("<b>AVAILABLE WEATHER:</b>")
        for w in matchups.get_all_weather().keys():
            SimpleIOHandler().println(w)
        weather = False
        while not weather in matchups.get_all_weather():
            weather = SimpleIOHandler().input("Enter a weather here: ")
        SimpleIOHandler().println()
        SimpleIOHandler().println("<b>AVAILABLE TERRAIN:</b>")
        for t in matchups.get_all_terrain().keys():
            SimpleIOHandler().println(t)
        terrain = False
        while not terrain in matchups.get_all_terrain():
            terrain = SimpleIOHandler().input("Enter a terrain here: ")
        try:
            SimpleIOHandler().println()
            battle = Battle(team1, team2, True if versus == "y" else False, difficulty, mode, weather=weather, terrain=terrain, io_handler=DialogIOHandler())
            battle.start()
        except:
            logging.exception("Something awful happened!")
        logging.debug("Finishing battle...")
        SimpleIOHandler().println("")
def main():
    rpgbs_init()
    finalarg = sys.argv[len(sys.argv) - 1]
    if "-a" in sys.argv or "-e" in sys.argv or "-m" in sys.argv or "-c" in sys.argv:
        print("Preparing to build documentation...")
    for folder in markdown_doc.values():
        if not path.isdir(folder):
            makedirs(folder)
    for folder in html_doc.values():
        if not path.isdir(folder):
            makedirs(folder)
    if "-a" in sys.argv or "-c" in sys.argv or finalarg in character_names:
        if finalarg in character_names:
            print("Preparing to build character documentation for %s...".replace("%s", finalarg))
        else:
            print(
                "Preparing to build character documentation... (%s characters total)".replace(
                    "%s", str(len(characters))
                )
            )
        charcount = 0
        for character in characters:
            if finalarg not in ["-a", "-c", character.name]:
                continue
            charcount += 1
            if "-v" in sys.argv:
                print("Building documentation for %s...".replace("%s", character.name))
            moves = """<table>
<tr>
<th>Level</th>
<th>Move</th>
</tr>"""
            for move, level in sorted(character.all_attacks.items(), key=itemgetter(1)):
                moves += """
<tr>
<td>%s</td>
<td>%s</td>
</tr>""" % tuple(
                    (level, move)
                )
            moves += "\n</table>"
            markdown = """%s
================

![%s](../../../graphics/portraits/%s.png?raw=true)<br/>
![%s](../../../graphics/%s.png?raw=true)

Attributes
----------------

%s**Gender:** %s<br/>
**Sexual orientation:** %s<br/>
**Color:** %s<br/>
**Element 1:** %s<br/>
**Element 2:** %s<br/>
**Quirk:** %s<br/>
**Form:** %s<br/>
**Bio:** %s<br/>

Base stats
----------------
**HP:** %s<br/>
**MP:** %s<br/>
**Attack:** %s<br/>
**Defense:** %s<br/>
**Special:** %s<br/>
**Resistance:** %s<br/>
**Speed:** %s<br/>
**Luck:** %s<br/>
**Accuracy:** %s<br/>
**Evasion:** %s<br/>

Movepool
----------------
%s""" % tuple(
                (
                    character.name,
                    character.name,
                    quote(character.name)
                    if path.exists(path.join(app_lib, "graphics", "portraits", character.name + ".png"))
                    else "unknown",
                    character.name,
                    quote(character.name)
                    if path.exists(path.join(app_lib, "graphics", character.name + ".png"))
                    else "unknown",
                    '**Quote:** "' + character.get_attribute("quote") + '"<br/>\n'
                    if "quote" in character.attributes.keys()
                    else "",
                    character.get_gender(),
                    character.get_orientation_string().title(),
                    character.get_attribute("color").title() if "color" in character.attributes.keys() else "None",
                    character.get_attribute("element").title(),
                    character.get_attribute("element2").title()
                    if "element2" in character.attributes.keys()
                    else "None",
                    character.get_attribute("quirk").title() if "quirk" in character.attributes.keys() else "None",
                    character.get_attribute("form").title() if "form" in character.attributes.keys() else "Humanoid",
                    character.get_attribute("bio") if "bio" in character.attributes.keys() else "not available",
                    # character.get_attribute("quote") if "quote" in character.attributes.keys() else "not available",
                    character.base_stats["HP"],
                    character.base_stats["MP"],
                    character.base_stats["Attack"],
                    character.base_stats["Defense"],
                    character.base_stats["Special"],
                    character.base_stats["Resistance"],
                    character.base_stats["Speed"],
                    character.base_stats["Luck"],
                    character.base_stats["Accuracy"],
                    character.base_stats["Evasion"],
                    moves,
                )
            )
            file_ = open(path.join(markdown_doc["characters"], character.name + ".md"), "w")
            file_.write(markdown)
            file_.close()
        chdir(app_lib)
        for fname in sorted(listdir(markdown_doc["characters"])):
            system(
                'perl ./markdown.pl "%s" > "%s"'
                % tuple(
                    (
                        path.join(markdown_doc["characters"], fname),
                        path.join(html_doc["characters"], rchop(fname, ".md") + ".html"),
                    )
                )
            )
        print("Character documentation successfully built.")
    if "-a" in sys.argv or "-m" in sys.argv:
        header = """
<tr>
<th style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">Name</th>
<th style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">Element</th>
<th style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">Element2</th>
<th style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">Attacking</th>
<th style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">Defending</th>
<th style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">Mana cost</th>
<th style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">HP cost</th>
<th style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">Power</th>
<th style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">Accuracy</th>
<th style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">Priority</th>
<th style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">Target</th>
<th style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">Pierce</th>
<th style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">Quirky</th>
<th style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">Lucky</th>
<th style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">Never-miss</th>
<th style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">Signature</th>
<th style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">Status</th>
<th style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">Status accuracy</th>
<th style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">Stat changes (target)</th>
<th style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">Stat changes (user)</th>
<th style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">Counters (target)</th>
<th style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">Counters (user)</th>
</tr>"""
        moves_html = (
            """All moves
================
Notes
----------------
**Attacking:** Default means the move uses its element's standard stat for attack.<br/>
**Defending:** The stat that the target defends with.<br/>
**Priority:** Only applies to Priority battles. Higher priority means the user will move earlier, regardless of Speed.<br/>
**Target:** 1 = One target, 2 = All foes, 3 = Everyone else, 4 = All teammates<br/>
**Pierce:** If yes, the attack ignores the opponent's stat multipliers.<br/>
**Quirky:** If a move is quirky, it obeys the target's quirk. If not, it ignores them.<br/>
<table>"""
            + header
        )
        print("Preparing to build move documentation... (%s moves total)".replace("%s", str(len(get_moves()))))
        counter = 0
        for move in sorted(get_moves().keys()):
            if "-v" in sys.argv:
                print("Building summary for " + move + "...")
            details = get_moves()[move]
            stat_changes = ""
            if "stat_changes" in details.keys():
                stat_changes_list = []
                for stat, levels in details["stat_changes"].items():
                    stat_changes_list.append(
                        "%s%s %s"
                        % tuple(("=" if type(levels) is float else ("+" if levels >= 0 else ""), levels, stat.title()))
                    )
                stat_changes = "<br>\n".join(stat_changes_list)
            stat_changes_self = ""
            if "stat_changes_self" in details.keys():
                stat_changes_list = []
                for stat, levels in details["stat_changes_self"].items():
                    stat_changes_list.append(
                        "%s%s %s"
                        % tuple(("=" if type(levels) is float else ("+" if levels >= 0 else ""), levels, stat.title()))
                    )
                stat_changes_self = "<br>\n".join(stat_changes_list)
            characters_with_this_move = []
            for character in characters:
                if move in character.get_all_attacks():
                    try:
                        unicode(character.get_name())
                    except:
                        pass
                    else:
                        characters_with_this_move.append(character.get_name())
            moves_html += """
<tr>
<td style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\"><b>%s</b></td>
<td style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">%s</td>
<td style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">%s</td>
<td style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">%s</td>
<td style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">%s</td>
<td style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">%s%s</td>
<td style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">%s%s</td>
<td style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">%s%s</td>
<td style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">%s/100</td>
<td style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">%s</td>
<td style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">%s</td>
<td style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">%s</td>
<td style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">%s</td>
<td style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">%s</td>
<td style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">%s</td>
<td style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">%s</td>
<td style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">%s</td>
<td style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">%s%s</td>
<td style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">%s</td>
<td style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">%s</td>
<td style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">%s</td>
<td style=\"padding: 0 !important; font-family: Liberation Sans Narrow, Arial Narrow, sans-serif !important; font-size: 10pt !important;\">%s</td>
</tr>
<tr>
<td colspan="22" style="padding: 0 !important; font-size: 10pt !important;">%s</td>
</tr>
<tr>
<td colspan="22" style="padding: 0 !important; font-size: 10pt !important; border-bottom: 1px solid ThreeDShadow !important;"><b>Characters that have this move (%s):</b> %s</td>
</tr>""" % tuple(
                (
                    move,
                    details["element"][0].upper() + details["element"][1 : len(details["element"])],
                    details["element2"][0].upper() + details["element2"][1 : len(details["element2"])]
                    if "element2" in details.keys()
                    else "None",
                    "Default"
                    if "special" not in details.keys()
                    else ("Special" if details["special"] is True else "Physical"),
                    "Default"
                    if "defending_stat" not in details.keys()
                    else details["defending_stat"][0].upper()
                    + details["defending_stat"][1 : len(details["defending_stat"])],
                    details["cost"] if type(details["cost"]) is int else details["cost"] * 100,
                    "%" if type(details["cost"]) is float else "",
                    0
                    if "hp_cost" not in details.keys()
                    else (details["hp_cost"] if type(details["hp_cost"]) is int else details["hp_cost"] * 100),
                    "" if "hp_cost" not in details.keys() else ("" if type(details["hp_cost"]) is int else "%"),
                    details["power"]
                    if type(details["power"]) is int
                    else str(details["power"] * 100)
                    + ("% of target's health" if "healing_source" not in details.keys() else ""),
                    ""
                    if "healing_source" not in details.keys()
                    else ("% of user's health" if details["healing_source"] == "self" else "% of target's health"),
                    details["accuracy"],
                    details["priority"] if "priority" in details.keys() else 0,
                    details["target"],
                    "No" if "pierce" not in details.keys() else ("Yes" if details["pierce"] is True else "No"),
                    "Yes"
                    if "ignore_quirks" not in details.keys()
                    else ("No" if details["ignore_quirks"] is True else "Yes"),
                    "No" if "lucky" not in details.keys() else ("Yes" if details["lucky"] is True else "No"),
                    "No" if "force_hit" not in details.keys() else ("Yes" if details["force_hit"] is True else "No"),
                    "No" if "signature" not in details.keys() else ("Yes" if details["signature"] is True else "No"),
                    "None"
                    if "effect" not in details.keys()
                    else (
                        details["effect"][0].upper() + details["effect"][1 : len(details["effect"])]
                        if type(details["effect"]) is not list
                        else ", ".join(details["effect"])
                    ),
                    "N/A" if "effect_accuracy" not in details.keys() else details["effect_accuracy"],
                    "" if "effect_accuracy" not in details.keys() else "%",
                    stat_changes,
                    stat_changes_self,
                    "None"
                    if "counters" not in details.keys()
                    else "</br>".join(list(x.title() for x in details["counters"])),
                    "None"
                    if "counters_self" not in details.keys()
                    else "</br>".join(list(x.title() for x in details["counters_self"])),
                    details["summary"] if "summary" in details.keys() else "No description.",
                    len(characters_with_this_move),
                    ", ".join(characters_with_this_move),
                )
            )
            counter += 1
            if counter == 10:
                moves_html += header
                counter = 0
        moves_html += """
</table>"""
        file_ = open(path.join(markdown_doc["attacks"], "index.md"), "w")
        file_.write(moves_html)
        file_.close()
        system(
            'perl ./markdown.pl "%s" > "%s"'
            % tuple((path.join(markdown_doc["attacks"], "index.md"), path.join(html_doc["attacks"], "index.html")))
        )
        print("Move documentation successfully built.")
    if "-e" in sys.argv or "-a" in sys.argv:
        print("Preparing to build element matchup documentation... (%s elements total)" % len(get_matchups().keys()))
        e = 0
        for key in sorted(get_matchups().keys()):
            try:
                get_matchups()[key]["quirk"]
            except:
                e += 1
        matchup_markup = """Element matchups
================
<h3>Mouse over the abbreviations to view their full element names.</h3>
<table style="text-align: center !important;">
<tr>
<td></td>
<th colspan="%s" style=\"padding: 0 !important; background-color: #ef2929 !important; color: #1a1a1a !important;\">Atk.</th>
</tr>
<tr>
<th style=\"padding: 0 !important; background-color: #729fcf !important; color: #1a1a1a !important;\">Def.</th>
""".replace(
            "%s", str(e)
        )
        for key in sorted(get_matchups().keys()):
            try:
                get_matchups()[key]["quirk"]
            except:
                matchup_markup += (
                    '<th style="padding: 0 !important; background-color: #ef2929 !important; color: #1a1a1a !important;" title="%s">%s</th>'
                    % tuple((key.title(), get_element_abbreviation(key)))
                )
        matchup_markup += "\n</tr>"
        for key in sorted(get_matchups().keys()):
            matchup_markup += """<tr>
<th style=\"padding: 0 !important; background-color: #729fcf !important; color: #1a1a1a !important;\" title=\"%s\">%s</th>""" % tuple(
                (key.title(), get_element_abbreviation(key))
            )
            for key2 in sorted(get_matchups().keys()):
                try:
                    get_matchups()[key2]["quirk"]
                except:
                    matchup_markup += (
                        '<td style="text-align: center !important; padding: 0 !important; background-color: %s !important;">%s</td>'
                        % tuple(
                            (
                                "#4e9a06 !important; color: white"
                                if (
                                    do_element_matchup(key2, key)
                                    if not "quirk" in get_matchups()[key]
                                    else do_element_matchup(key2, "", "", key)
                                )
                                > 1
                                else (
                                    "#1a1a1a !important; color: white"
                                    if (
                                        (
                                            do_element_matchup(key2, key)
                                            if not "quirk" in get_matchups()[key]
                                            else do_element_matchup(key2, "", "", key)
                                        )
                                    )
                                    == 0
                                    else (
                                        "#cc0000 !important; color: white"
                                        if (
                                            (
                                                do_element_matchup(key2, key)
                                                if not "quirk" in get_matchups()[key]
                                                else do_element_matchup(key2, "", "", key)
                                            )
                                        )
                                        < 1
                                        else ""
                                    )
                                ),
                                str(float(do_element_matchup(key2, key)))
                                if not "quirk" in get_matchups()[key]
                                else str(float(do_element_matchup(key2, "", "", key))),
                            )
                        )
                    )
            matchup_markup += """</td>
</tr>"""
        file_ = open(path.join(markdown_doc["elements"], "index.md"), "w")
        file_.write(matchup_markup)
        file_.close()
        system(
            'perl ./markdown.pl "%s" > "%s"'
            % tuple((path.join(markdown_doc["elements"], "index.md"), path.join(html_doc["elements"], "index.html")))
        )
        print("Element matchup documentation successfully built.")
    if "-a" in sys.argv or "-q" in sys.argv:
        quirks = get_quirks()
        markdown = """Quirks
================\n\n"""
        custom_text = ""
        if path.exists(path.join(markdown_doc["quirks"], "custom.md")):
            f = open(path.join(markdown_doc["quirks"], "custom.md"), "r")
            custom_text = f.read()
            f.close()
        for quirk in quirks:
            r = get_resists(quirk)
            w = get_weaknesses(quirk)
            i = get_immunities(quirk)
            f = get_fuels(quirk)
            i2 = get_status_immunities(quirk)
            append = """**%s**<br/>
This character resists %s, is weak against %s, is immune to %s, and is recharged by %s. This character is immune to %s.<br/>
<br/>\n""" % tuple(
                (
                    quirk,
                    ", ".join(r) if len(r) > 0 else "no additional elements",
                    ", ".join(w) if len(w) > 0 else "no additional elements",
                    ", ".join(i) if len(i) > 0 else "no additional elements",
                    ", ".join(f) if len(f) > 0 else "no additional elements",
                    "being " + ", ".join(i2) if len(i2) > 0 else "no additional status conditions",
                )
            )
            markdown += append
        markdown += custom_text
        f = open(path.join(markdown_doc["quirks"], "index.md"), "w")
        f.write(markdown)
        f.close()
        system(
            'perl ./markdown.pl "%s" > "%s"'
            % tuple((path.join(markdown_doc["quirks"], "index.md"), path.join(html_doc["quirks"], "index.html")))
        )
        print("Quirk documentation successfully built.")
    if "-q" in sys.argv or "-a" in sys.argv or "-e" in sys.argv or "-m" in sys.argv or "-c" in sys.argv:
        print("Documentation successfully built.")
    else:
        print(
            """Usage:
-a    Build all documentation
-c    Build character documentation
-m    Build move documentation
-e    Build element matchup documentation"""
        )
def main():
    rpgbs_init()
    team = {}
    carlos = Carlos()
    corina = Corina()

    def restore_health():
        for member in team.values():
            member.recalculate_stats()
            member.health = member.stats["HP"]
            member.mana = member.stats["MP"]

    fancy_input("<b>THE CHRONICLES OF RPG-BATTLE-SYSTEM</b>\n" + "An extremely basic RPG coded by <b>Daniel Sim</b>")
    fancy_println()
    fancy_input("<b>TOWN:</b> Irydia")
    fancy_input("(Carlos is lying under a tree, relaxing)")
    carlos.says("Man, I'm so bored...")
    corina.says("Hi, Carlos!")
    carlos.says("Hey, Corina. Listen, I'm really bored right now. " + "Got any ideas for what we should do?")
    corina.says("Let's trick Charles into doing something " + "stupid again!")
    carlos.says("Nah, that's too easy.")
    corina.says("Um... we could walk around town together?")
    carlos.says("Too mundane.")
    corina.says("Oh, I know! Why don't we go on some crazy " + "adventure like they do in role-playing games?")
    carlos.says("Yes! That's it! I can't believe I " + "didn't think of that before! Let's go!")
    team["Carlos"] = carlos
    team["Corina"] = corina
    fancy_input(
        "(And with that, our heroes head off on a random, "
        + "pointless adventure.\n It is not long before they "
        + "encounter their first obstacle...)"
    )
    carlos.says("Dammit! This stupid rock is in our way! " + "Now how are we going to get through?")
    corina.says("This looks like a good time to " + "practice fighting enemies!")
    no = True
    while 1:
        g = fancy_input(
            '<b>Corina:</b> <magenta>"Shall I explain how ' + 'to declare an attack?"</magenta> (y/n): '
        ).lower()
        if g == "y":
            break
        elif g == "n":
            no = False
            break
    if no == True:
        corina.says(
            "To declare an attack, "
            + "all you have to do is enter in the number of the attack, "
            + "followed by the number of the target. "
            + "It's pretty self-explanatory, so let's begin!"
        )
    else:
        corina.says("Then let's begin!")
    fancy_println()
    battle = Battle(team.values(), [Rock().level_to(3)])
    battle.start()
    fancy_println()
    restore_health()
    for member in team.values():
        member.level_to(6)
        fancy_input(member.name + " grew to level 6!")
    fancy_println()
    corina.says('Yay! We won! And I gained a level, too!" ^^')
    carlos.says("That was really annoying, though... " + "Whoever knew rocks could be so tough?")
    corina.says("Anyway! Let's move on to the next town!")
    fancy_input("(And so our heroes move on to the next town...)")
    fancy_println()
    fancy_input("<b>TOWN:</b> Lindenshire")
    carlos.says("Well, that was fast...")
    corina.says('(pointing) "Carlos! ' + "It looks like a fight's going on over there!")
    carlos.says('(turns to look) "Huh?')
    fancy_input("(Sure enough, two people are facing off.)")
    mook = Mook().rename("Guy With A Gun")
    mook.says("Hand over your goodies!")
    blade = Blade().rename("Guy With A Big Sword").level_to(9001).remove_attack("Kamikaze").remove_attack("Regenerate")
    blade.says("Sorry, don't feel like it.")
    mook.says("Then I challenge you to a fight!")
    carlos.says("What's with this ridiculous scene...?")
    fancy_println()
    fancy_input("(Perspective of Guy With A Gun)")
    fancy_println()
    battle = Battle([mook], [blade])
    battle.start()
    fancy_println()
    fancy_input("(Guy With A Gun slumps to the ground, unconscious.)")
    blade.says("<sigh>")
    carlos.says("Whoa. That was totally insane.")
    corina.says("Talk about a curb-stomp battle!")
    fancy_input("(Guy With A Big Sword walks over to Carlos and Corina.)")
    corina.says("Ack! He's coming this way!")
    blade.says(
        "The two of you... look like you have potential. " + "My name is Blade; I have the feeling we'll meet again..."
    )
    fancy_input("(With that, Blade walks off again.)")
    carlos.says("Well, that was... interesting.")
    corina.says("Anyway! We should rest here for the night!")
    carlos.says("Good idea. Let's do that.")
    fancy_input("(Our heroes find an inn.)")
    fancy_input('<b>Innkeeper:</b> "Welcome. How may I help you?"')
    corina.says("Cheapest room for two, please!")
    fancy_input(
        "<b>Innkeeper:</b> (hands her a pair of keys) \"Room J1702. It's "
        + 'on the 17th floor; the elevators are over there."'
    )
    corina.says("Thank you!")
    fancy_input(
        "(Carlos and Corina head up to the 17th floor. As they head "
        + "out of the elevator, Carlos walks straight into a maid.)"
    )
    carlos.says("Ow!")
    shelly = Shelly().level_to(6).rename("Maid")
    shelly.says("Uwaah! I'm sorry!")
    carlos.says("Nah, it's not a big deal. See ya later!")
    fancy_input("(Carlos and Corina head to their room)")
    if not rpy:
        corina.says("Sorry, that's as far as the story gets for now!")
        fancy_input("<b>THE END</b>")