Example #1
0
    def expand_path(cls, regions, context):
        if "*" not in regions:
            return [Region.get_region(where, context) for where in regions]
        if regions[-1] == '*':
            context.reply("You can't end a movement command with a "
                          "pathfinding instruction; I have no idea where you "
                          "want to end up!")
            return
        result = []
        curr = context.player.region
        for index, region_name in enumerate(regions):
            if region_name == '*':
                if not curr:
                    continue  # Don't bother if we don't know prev location
                if regions[index + 1] == '*':
                    continue  # Ignore consecutive pathfinding instructions
                dest = Region.get_region(regions[index + 1], context)
                if not dest:
                    return None

                # See if we allow neutral traversal
                conf = context.config
                traverse_neutrals = False
                if conf:
                    traverse_neutrals = conf["game"].get("traversable_neutrals",
                                                         False)
                path = find_path(curr, dest, context.player.team,
                                 traverse_neutrals=traverse_neutrals)
                if path:
                    path = path[1:-1]  # We already have the first and the last
                    if not path:
                        continue  # They were already adjacent!
                    result.extend(path)
                else:
                    context.reply("I couldn't find a friendly-territory path "
                                  "between %s and %s "
                                  % (curr.name, dest.name))
                    return None
                curr = dest
            else:
                dest = Region.get_region(region_name, context)
                if not dest:
                    return None
                result.append(dest)
                curr = dest
        return result
Example #2
0
    def execute(self, context):
        dest = Region.get_region(self.where, context)
        if dest:
            now = time.mktime(time.localtime())
            begins = now + context.config["game"]["battle_delay"]
            battle = None

            if dest.capital is not None:
                invade = context.config['game']['capital_invasion']
                if invade == 'none':
                    context.reply("You cannot invade the enemy capital")
                    return

            try:
                battle = dest.invade(context.player, begins)
                if "battle_lockout" in context.config["game"]:
                    battle.lockout = context.config["game"]["battle_lockout"]
                    context.session.commit()
            except db.RankException:
                context.reply("You don't have the authority "
                              "to invade a region!")
            except db.TeamException:
                context.reply("You can't invade %s, you already own it!" %
                              dest.markdown())
            except db.NonAdjacentException:
                context.reply("%s is not next to any territory you control" %
                              dest.markdown())
            except db.InProgressException as ipe:
                context.reply("%s is %s being invaded!" % (dest.markdown(),
                              ipe.other.markdown("already")))
            except db.TimingException as te:
                context.reply(("%s is too fortified to be attacked.  "
                              "These fortifications will break down by %s") %
                              (dest.markdown(), timestr(te.expected)))

            if battle:
                context.reply("**Confirmed**  Battle will begin at %s" %
                              battle.begins_str())
                title = ("[Invasion] The %s armies march!" %
                 context.team_name())
                submitted = InvadeCommand.post_invasion(title, battle,
                                                        context.reddit)
                if submitted:
                    battle.submission_id = submitted.name
                    context.session.commit()
                else:
                    logging.warn("Couldn't submit invasion thread")
                    context.session.rollback()
Example #3
0
    def execute(self, context):
        dest = Region.get_region(self.where, context)
        if dest:
            now = time.mktime(time.localtime())
            begins = now + context.config["game"]["battle_delay"]
            battle = None

            if dest.capital is not None:
                invade = context.config['game']['capital_invasion']
                if invade == 'none':
                    context.reply("You cannot invade the enemy capital")
                    return

            try:
                battle = dest.invade(context.player, begins)
                if "battle_lockout" in context.config["game"]:
                    battle.lockout = context.config["game"]["battle_lockout"]
                    context.session.commit()
            except db.RankException:
                context.reply("You don't have the authority "
                              "to invade a region!")
            except db.TeamException:
                context.reply("You can't invade %s, you already own it!" %
                              dest.markdown())
            except db.NonAdjacentException:
                context.reply("%s is not next to any territory you control" %
                              dest.markdown())
            except db.InProgressException as ipe:
                context.reply("%s is %s being invaded!" % (dest.markdown(),
                              ipe.other.markdown("already")))
            except db.TimingException as te:
                context.reply(("%s is too fortified to be attacked.  "
                              "These fortifications will break down by %s") %
                              (dest.markdown(), timestr(te.expected)))

            if battle:
                context.reply("**Confirmed**  Battle will begin at %s" %
                              battle.begins_str())
                title = ("[Invasion] The %s armies march on %s!" %
                         (context.team_name(), dest.name))
                submitted = InvadeCommand.post_invasion(title, battle,
                                                        context.reddit)
                if submitted:
                    battle.submission_id = submitted.name
                    context.session.commit()
                else:
                    logging.warn("Couldn't submit invasion thread")
                    context.session.rollback()