Esempio n. 1
0
    def move(self, how_many, where, delay):
        sess = Session.object_session(self)

        already = sess.query(MarchingOrder).filter_by(leader=self).first()
        if already:
            raise InProgressException(already)

        fighting = (sess.query(SkirmishAction).
                    filter_by(participant=self).first())
        if fighting:
            raise InProgressException(fighting)

        if how_many > self.loyalists:
            # TODO: Attempt to pick up loyalists
            raise InsufficientException(how_many, self.loyalists, "loyalists")

        # TODO: Drop off loyalists
        where = forcelist(where)
        locations = [self.region] + where
        for src, dest in pairwise(locations):
            if not dest in src.borders:
                raise NonAdjacentException(src, dest)

            if not dest.enterable_by(self.team):
                raise TeamException(dest)

        orders = []
        if(delay > 0):
            orders = []
            step = 0
            for src, dest in pairwise(locations):
                step += 1
                mo = MarchingOrder(arrival=time.mktime(time.localtime())
                                    + delay * step,
                                   leader=self,
                                   source=src,
                                   dest=dest)
                orders.append(mo)
                sess.add(mo)
        else:
            self.region = where[-1]
        # TODO: Change number of loyalists
        self.defectable = False
        sess.commit()

        return orders
Esempio n. 2
0
    def move(self, how_many, where, delay, sector=0, conf=None):
        sess = Session.object_session(self)
        where = forcelist(where)

        already = sess.query(MarchingOrder).filter_by(leader=self).first()
        if already:
            raise InProgressException(already)

        fighting = (sess.query(SkirmishAction).
                    filter_by(participant=self).first())
        if fighting:
            allow = False
            if conf:
                if len(where) == 1 and where[0] == self.region:
                    allow = conf["game"].get("allow_sector_retreat", False)

            if not allow:
                raise InProgressException(fighting)

        if how_many > self.loyalists:
            # TODO: Attempt to pick up loyalists
            raise InsufficientException(how_many, self.loyalists, "loyalists")

        # Is that sector even real?
        if conf:
            num_sectors = conf["game"].get("num_sectors", 1)
            if sector < 0 or sector > num_sectors:
                raise NoSuchSectorException(sector, num_sectors)
            elif sector == 0:  # Assign a random sector
                sector = random.randint(1, num_sectors)

        # TODO: Drop off loyalists
        locations = [self.region] + where
        for src, dest in pairwise(locations):
            if src == dest:
                continue
            if dest not in src.borders:
                raise NonAdjacentException(src, dest)

            traverse_neutrals = False
            if conf:
                traverse_neutrals = conf["game"].get("traversable_neutrals", False)
            if not dest.enterable_by(self.team,
                                     traverse_neutrals=traverse_neutrals):
                raise TeamException(dest)

        orders = []
        if delay > 0:
            orders = []
            total_delay = 0
            for src, dest in pairwise(locations):
                travel_mult = max(src.travel_multiplier, dest.travel_multiplier)
                if src != dest:
                    total_delay += (delay * travel_mult)
                else:
                    if conf:
                        intrasector = conf["game"].get("intrasector_travel",
                                                       900)
                        # Travel multiplier doesn't apply to intrasector
                        total_delay += intrasector
                mo = MarchingOrder(arrival=time.mktime(time.localtime())
                                   + total_delay,
                                   leader=self,
                                   source=src,
                                   dest=dest,
                                   dest_sector=sector)
                orders.append(mo)
                sess.add(mo)
        else:
            self.region = where[-1]
            self.sector = sector
        # TODO: Change number of loyalists
        self.defectable = False
        sess.commit()

        return orders
Esempio n. 3
0
    def move(self, how_many, where, delay, sector=0, conf=None):
        sess = Session.object_session(self)
        where = forcelist(where)

        already = sess.query(MarchingOrder).filter_by(leader=self).first()
        if already:
            raise InProgressException(already)

        fighting = (sess.query(SkirmishAction).filter_by(
            participant=self).first())
        if fighting:
            allow = False
            if conf:
                if len(where) == 1 and where[0] == self.region:
                    allow = conf["game"].get("allow_sector_retreat", False)

            if not allow:
                raise InProgressException(fighting)

        if how_many > self.loyalists:
            # TODO: Attempt to pick up loyalists
            raise InsufficientException(how_many, self.loyalists, "loyalists")

        # Is that sector even real?
        if conf:
            num_sectors = conf["game"].get("num_sectors", 1)
            if sector < 0 or sector > num_sectors:
                raise NoSuchSectorException(sector, num_sectors)
            elif sector == 0:  # Assign a random sector
                sector = random.randint(1, num_sectors)

        # TODO: Drop off loyalists
        locations = [self.region] + where
        for src, dest in pairwise(locations):
            if src == dest:
                continue
            if dest not in src.borders:
                raise NonAdjacentException(src, dest)

            traverse_neutrals = False
            if conf:
                traverse_neutrals = conf["game"].get("traversable_neutrals",
                                                     False)
            if not dest.enterable_by(self.team,
                                     traverse_neutrals=traverse_neutrals):
                raise TeamException(dest)

        orders = []
        if delay > 0:
            orders = []
            total_delay = 0
            for src, dest in pairwise(locations):
                travel_mult = max(src.travel_multiplier,
                                  dest.travel_multiplier)
                if src != dest:
                    total_delay += (delay * travel_mult)
                else:
                    if conf:
                        intrasector = conf["game"].get("intrasector_travel",
                                                       900)
                        # Travel multiplier doesn't apply to intrasector
                        total_delay += intrasector
                mo = MarchingOrder(arrival=time.mktime(time.localtime()) +
                                   total_delay,
                                   leader=self,
                                   source=src,
                                   dest=dest,
                                   dest_sector=sector)
                orders.append(mo)
                sess.add(mo)
        else:
            self.region = where[-1]
            self.sector = sector
        # TODO: Change number of loyalists
        self.defectable = False
        sess.commit()

        return orders