def generate_path(self, view_enemys, me, home_pos): airs = [] for enemy in view_enemys: if enemy.unit_type in md.COMBAT_AIR_UNITS: dist = md.calculate_distance(me.float_attr.pos_x, me.float_attr.pos_y, enemy.float_attr.pos_x, enemy.float_attr.pos_y) if dist < SCOUT_SAFE_RANGE: airs.append(enemy) else: continue enemy_pos = None total_x = 0.0 total_y = 0.0 if len(airs) > 0: for unit in airs: total_x += unit.float_attr.pos_x total_y += unit.float_attr.pos_y enemy_pos = (total_x / len(airs), total_y / len(airs)) else: total_x = me.float_attr.pos_x + 1 total_y = me.float_attr.pos_y + 1 enemy_pos = (total_x, total_y) self._generate_path(home_pos, (me.float_attr.pos_x, me.float_attr.pos_y), enemy_pos)
def _detect_enemy(self, view_enemys, dc): spool = dc.dd.scout_pool armys = [] eggs = [] spawning_on = False for enemy in view_enemys: if enemy.unit_type in md.COMBAT_UNITS: armys.append(enemy) elif enemy.unit_type == tp.UNIT_TYPEID.ZERG_EGG.value: eggs.append(enemy) elif enemy.unit_type == tp.UNIT_TYPEID.ZERG_SPAWNINGPOOL.value: if enemy.float_attr.build_progress >= st.BUILD_PROGRESS_FINISH: spawning_on = True else: pass me = (self._scout.unit().float_attr.pos_x, self._scout.unit().float_attr.pos_y) scout_armys = [] for unit in armys: dist = md.calculate_distance(me[0], me[1], unit.float_attr.pos_x, unit.float_attr.pos_y) if dist < st.SCOUT_CRUISE_RANGE: scout_armys.append(unit) if len(eggs) > 0 and spawning_on: #print("SCOUT escape, may be zergling is building") return True return len(scout_armys) > 0
def _check_in_base_range(self): dist = md.calculate_distance(self._scout.unit().float_attr.pos_x, self._scout.unit().float_attr.pos_y, self._target.pos[0], self._target.pos[1]) if dist < st.SCOUT_CRUISE_ARRIVAED_RANGE: return True else: return False
def _check_arrived_pos(self, pos): dist = md.calculate_distance(self._scout.unit().float_attr.pos_x, self._scout.unit().float_attr.pos_y, pos[0], pos[1]) if dist < st.SCOUT_CRUISE_ARRIVAED_RANGE: return True else: return False
def curr_arrived(self, me_pos): curr_pos = self._paths[self._curr] dist = md.calculate_distance(curr_pos[0], curr_pos[1], me_pos[0], me_pos[1]) if dist <= SCOUT_CRUISE_ARRIVAED_RANGE: return True else: return False
def _init_scout_base_target(self): areas = self._dd.base_pool.resource_cluster if 0 == len(areas): raise Exception('resource areas is none') for area in areas: scout_target = ScoutBaseTarget() scout_target.area = area scout_target.pos = area.ideal_base_pos dist = md.calculate_distance(self.home_pos[0], self.home_pos[1], scout_target.pos[0], scout_target.pos[1]) if dist > MAX_AREA_DISTANCE: self._scout_base_target.append(scout_target)
def check_end(self, view_enemys, dc): find_base = False find_queue = False for enemy in view_enemys: if enemy.unit_type == md.UNIT_TYPEID.ZERG_QUEEN.value: dist = md.calculate_distance(self._target.pos[0], self._target.pos[1], enemy.float_attr.pos_x, enemy.float_attr.pos_y) if dist < SCOUT_BASE_RANGE: find_queue = True break elif enemy.unit_type in md.BASE_UNITS: dist = md.calculate_distance(self._target.pos[0], self._target.pos[1], enemy.float_attr.pos_x, enemy.float_attr.pos_y) if dist < SCOUT_BASE_RANGE: find_base = True break else: continue return find_base or find_queue
def find_forced_scout_target(self): candidates = [] for target in self._scout_base_target: if target.has_scout: continue if target.has_enemy_base or target.has_army: candidates.append(target) furthest_dist = 0.0 furthest_candidate = None for candidate in candidates: dist = md.calculate_distance(self.home_pos[0], self.home_pos[1], candidate.pos[0], candidate.pos[1]) if furthest_dist < dist: furthest_dist = dist furthest_candidate = candidate return furthest_candidate
def _detect_enemy(self, view_enemys, dc): spool = dc.dd.scout_pool armys = [] for enemy in view_enemys: if enemy.unit_type in md.COMBAT_UNITS: armys.append(enemy) me = (self._scout.unit().float_attr.pos_x, self._scout.unit().float_attr.pos_y) scout_armys = [] for unit in armys: dist = md.calculate_distance(me[0], me[1], unit.float_attr.pos_x, unit.float_attr.pos_y) if dist < st.SCOUT_CRUISE_RANGE: scout_armys.append(unit) break if len(scout_armys) > 0: alarm = sp.ScoutAlarm() alarm.enmey_armys = scout_armys if not spool.alarms.full(): spool.alarms.put(alarm)
def _detect_enemy(self, view_enemys, dc): bases = [] queues = [] airs = [] armys = [] main_base_buildings = [] for enemy in view_enemys: if enemy.unit_type in md.BASE_UNITS: bases.append(enemy) elif enemy.unit_type == md.UNIT_TYPEID.ZERG_QUEEN.value: queues.append(enemy) elif enemy.unit_type in md.COMBAT_UNITS: armys.append(enemy) elif enemy.unit_type in md.COMBAT_AIR_UNITS: airs.append(enemy) elif enemy.unit_type in md.MAIN_BASE_BUILDS: main_base_buildings.append(enemy) else: continue find_base = False air_force = False for base in bases: dist = md.calculate_distance(self._target.pos[0], self._target.pos[1], base.float_attr.pos_x, base.float_attr.pos_y) #print('SCOUT base distance={}, base_range={}'.format(dist, SCOUT_BASE_RANGE)) if dist < st.SCOUT_BASE_RANGE: self._target.has_enemy_base = True self._target.enemy_unit = base if len(armys) > 0: self._target.has_army = True #print('Scout find base, is_main_base:', dc.dd.scout_pool.has_enemy_main_base()) if not dc.dd.scout_pool.has_enemy_main_base(): #print('SCOUT find base, set main base') self._target.is_main = True if not find_base: find_base = True #print('SCOUT find enemy base, job finish, target=', str(self._target)) for build in main_base_buildings: dist = md.calculate_distance(self._target.pos[0], self._target.pos[1], build.float_attr.pos_x, build.float_attr.pos_y) if dist < st.SCOUT_BASE_RANGE: #print('SCOUT find main_building in main base') self._target.has_enemy_base= True self._target.is_main = True if len(armys) > 0: self._target.has_army = True if not find_base: find_base = True for queue in queues: dist = md.calculate_distance(self._target.pos[0], self._target.pos[1], queue.float_attr.pos_x, queue.float_attr.pos_y) if dist < st.SCOUT_BASE_RANGE: self._target.has_enemy_base = True self._target.has_army = True if not dc.dd.scout_pool.has_enemy_main_base(): #print('SCOUT find queue, set main base') self._target.is_main = True #print('SCOUT find enemy queue, job finish, target=', str(self._target)) if not find_base: find_base = True if not air_force: air_force = True for unit in airs: dist = md.calculate_distance(self._scout.unit().float_attr.pos_x, self._scout.unit().float_attr.pos_y, unit.float_attr.pos_x, unit.float_attr.pos_y) if dist < st.SCOUT_SAFE_RANGE: #print('SCOUT deteck air unit around me, run') if not air_force: air_force = True break view_armys = [] for enemy in armys: dist = md.calculate_distance(self._scout.unit().float_attr.pos_x, self._scout.unit().float_attr.pos_y, enemy.float_attr.pos_x, enemy.float_attr.pos_y) if dist < st.SCOUT_VIEW_RANGE: view_armys.append(enemy) if len(view_armys) > 0: self._scout.snapshot_armys = view_armys else: self._scout.snapshot_armys = None return find_base, air_force