def game_step(self):
        super(DroneUnloadState, self).game_step()

        if self.unit.distance_to(self.strategy.chosen_target
                                 ) <= theme.CARGO_TRANSITION_DISTANCE:
            self.transition = CargoTransition(
                cargo_from=self.unit.cargo,
                cargo_to=self.strategy.chosen_target.cargo)

            turn_target = self.strategy.get_near_rate_asteroid()
            self.unit.turn_to(turn_target)

        if self.transition:
            self.transition.game_step()
    def game_step(self):
        super(DroneLoadState, self).game_step()
        if self.unit.distance_to(self.strategy.chosen_target
                                 ) <= theme.CARGO_TRANSITION_DISTANCE:
            self.transition = CargoTransition(
                cargo_from=self.strategy.chosen_target.cargo,
                cargo_to=self.unit.cargo)

            if self.unit.free_space < self.strategy.chosen_target.cargo.payload:
                self.unit.turn_to(self.unit.mothership)
            else:
                self.unit.turn_to(self.strategy.chosen_target)

        if self.transition:
            self.transition.game_step()
Exemple #3
0
 def game_step(self):
     super(DroneStateHarvest, self).game_step()
     # TODO: harvest any possible targets on the way to self._target
     if self._transition:
         self._transition.game_step()
         target = self.strategy.get_unload_target()
         if target:
             self.unit.turn_to(target)
         else:
             self.unit.turn_to(self.unit.mothership)
     if self._target is None:
         target = self.strategy.get_harvest_target()
         if target is not None:
             self._target = get_point_on_way_to(
                 self.unit, target, theme.CARGO_TRANSITION_DISTANCE * 0.9)
             self._target_cargo = target.cargo
             self.unit.move_at(self._target.copy())
             self.strategy.data._targets[self.unit.id] = target
         elif self._transition is not None:
             return
     if self._transition is None and self._target and int(
             self.unit.distance_to(self._target)) <= 1:
         # print(u"\u001b[36;1mNew cargo transition: {} -> {}\u001b[0m".format(self._target_cargo.owner.id,
         #                                                                     self.unit.id))
         self._transition = CargoTransition(cargo_from=self._target_cargo,
                                            cargo_to=self.unit.cargo)
 def __init__(self, unit=None, target_unit=None, distance=0, **kwargs):
     super(StrategyApproachAndUnload, self).__init__(
         StrategyApproach(unit=unit,
                          target_point=target_unit.coord,
                          distance=distance),
         StrategyCargoUnloading(CargoTransition(cargo_from=unit.cargo,
                                                cargo_to=target_unit.cargo),
                                unit=unit,
                                is_group_unique=True),
         unit=unit,
         id="approach&unload",
         group="approach",
         is_group_unique=True)
     self.__cargo_unloading = None
 def __init__(self, unit=None, target_unit=None, distance=None, **kwargs):
     if distance is None:
         distance = theme.LOAD_DISTANCE
     super(StrategyApproachAndLoad, self).__init__(
         StrategyApproach(unit=unit,
                          target_point=target_unit.coord,
                          distance=distance,
                          condition=self.check_target_have_elerium),
         StrategyCargoLoading(CargoTransition(cargo_from=target_unit.cargo,
                                              cargo_to=unit.cargo),
                              unit=unit,
                              is_group_unique=True),
         unit=unit,
         id="approach&load",
         group="approach",
         is_group_unique=True)
     self.__target_unit = target_unit
Exemple #6
0
 def game_step(self):
     super(self.__class__, self).game_step()
     if self._target is None:
         target = self.strategy.get_unload_target()
         if target is None:
             target = self.unit.mothership
         self._target = target
         self._target_point = get_point_on_way_to(self.unit, target, theme.CARGO_TRANSITION_DISTANCE * 0.9)
         self._target_cargo = target.cargo
         self.strategy.data._targets[self.unit.id] = self._target_point
         self.unit.move_at(self._target_point)
     if self._transition:
         self._transition.game_step()
         target = self.strategy.get_harvest_target()
         if target is None:
             target = self.unit.mothership
         self.unit.turn_to(target)
     elif self.unit.distance_to(self._target_point) <= 1.0:
         self._transition = CargoTransition(cargo_from=self.unit.cargo, cargo_to=self._target_cargo)
Exemple #7
0
 def __init__(self, unit=None, target_unit=None, distance=None, **kwargs):
     if distance is None:
         distance = theme.CARGO_TRANSITION_DISTANCE - 1
     try:
         self.strategies = [
             StrategyApproach(unit=unit,
                              target_point=target_unit.coord,
                              distance=distance,
                              condition=self.check_target_have_elerium),
             StrategyCargoLoading(CargoTransition(
                 cargo_from=target_unit.cargo, cargo_to=unit.cargo),
                                  unit=unit,
                                  is_group_unique=True),
         ]
     except CargoException as exc:
         print(exc)
         self.strategies = []
     super(StrategyApproachAndLoad, self).__init__(*self.strategies,
                                                   unit=unit,
                                                   id="approach&load",
                                                   group="approach",
                                                   is_group_unique=True)
     self.__target_unit = target_unit