示例#1
0
    def get_requirements(self, target, amount=1, task_list=None):
        if not task_list:
            task_list = algorithms.Queue()

        if not target["Production"]:
            return task_list

        production_list = target["Production"]
        for product in production_list:
            target_group = product[0]           # Unit, Structure
            target_type = product[1]            # Worker, Explorer, Smithy, etc.
            target_amount = product[2]          # How many is needed/ordered
            target_class = entities.to_class(target_type)    # Class instance

            # already completed -> skip
            if self.has_num_entities(target_class, target_amount):
                continue
            # deduct already owned resources (if any)
            else:
                amount -= len(self.entities_where(lambda e: isinstance(e, target_class)))
            # chain multiplikation
            if not target_group == "Structure":
                target_amount *= amount
            # get sub-requirements
            self.get_requirements(g_vars[target_group][target_type], target_amount, task_list)
            # append parent task last
            task_list.put([target_group, target_type, target_amount])

        return task_list
示例#2
0
 def visual_helper(self, use_stack=False):
     self.pathqueue = alg.Stack() if use_stack else alg.Queue()
     self.pathprocess = []
     for child, parent in self.path.items():
         # first node has no parent
         if parent is None:
             continue
         chi = tuple(x * settings.TILE_SIZE + settings.TILE_SIZE / 2 for x in child)
         par = tuple(x * settings.TILE_SIZE + settings.TILE_SIZE / 2 for x in parent)
         self.pathqueue.put((chi, par))
示例#3
0
 def __init__(self, gamemap, start_position):
     self.gamemap = gamemap
     self.start_position = start_position
     self.fsm = fsm.StateMachine(self)
     self.fsm.globalState = ai_state.AIGlobalState()
     self.fsm.currentState = ai_state.AIStateIdle()
     self.dispatcher = dispatch.MessageDispatcher()
     self.entity_list = []
     self.production_list = []
     self.resource_map = {}
     self.current_goal = []
     self.current_task = None
     self.target_resource = None
     self.task_list = algorithms.Queue()
     self.time_since_lask_task_update = 0
示例#4
0
 def update_task_list(self): # Not used atm
     if not self.current_goal:
         return
     self.task_list = algorithms.Queue()
     # loop through current goal(s)
     for goal in self.current_goal:
         (target_group, target_class, target_amount) = goal
         # get all requirements
         task_list = self.get_requirements(g_vars[target_group][target_class], target_amount)
         # re-queue them
         while not task_list.empty():
             self.task_list.put(task_list.get())
         # given task need to be put as last task
         self.task_list.put([target_group, target_class, target_amount])
     # clear current task
     self.current_task = None
     # tasks has been updated
     self.time_since_lask_task_update = 0