def rangerMap(planetMap, atkRange): enemies = senseAllEnemies(planetMap.planet) enemyLocs = [] if enemies: for e in enemies: loc = e.location.map_location() enemyLocs.append([dmap.flattenXY(loc.x, loc.y), 0]) # If we can't see any enemies head towards where we last saw them. currently only remembers factory locations elif ENEMY_LOCATION_MEMORY: for loc in ENEMY_LOCATION_MEMORY: enemyLocs.append([loc, 0]) # find distances to enemy, ignoring walls, because rangers can shoot over distMap = dmap.dijkstraMap(enemyLocs, NO_WALL_GRAPH) goalLocs = [] realAtkRange = int(math.sqrt(atkRange / 2)) # now find where the distance is right for rangers for idx, value in enumerate(distMap): if value == realAtkRange: goalLocs.append([idx, 0]) # now pathfind to those sweet spot rangerMap = dmap.dijkstraMap(goalLocs, WALL_GRAPH) return rangerMap
def enemyAttackMap(planetMap): eList = [] for e in senseAllEnemies(planetMap.planet): loc = e.location.map_location() if e.unit_type == bc.UnitType.Ranger or e.unit_type == bc.UnitType.Knight or e.unit_type == bc.UnitType.Mage: eList.append([dmap.flattenXY(loc.x,loc.y),-int(math.sqrt(e.attack_range()/2))]) return dmap.dijkstraMap(eList,NO_WALL_GRAPH)
def adjacentToMap(mapLocs): goals = [] for loc in mapLocs: adjacent = gc.all_locations_within(loc, 2) for adjLoc in adjacent: flatxy = dmap.flattenXY(adjLoc.x, adjLoc.y) if not flatxy in THIS_PLANET_WALLS and gc.is_occupiable(adjLoc): goals.append([flatxy, 0]) return dmap.dijkstraMap(goals, WALL_GRAPH)
rangerMapBench.start() RANGER_MAP = rangerMap(THIS_PLANETMAP, rangerAtkRange) rangerMapBench.end() # Healer map. Directs healers to get near rangers to heal them HEALER_MAP = [] if healers: healerMapBench.start() goals = [] for seq in [mages, rangers, knights, workers, healers]: for ally in seq: if ally.health < ally.max_health and ally.location.is_on_map( ): loc = ally.location.map_location() goals.append([ dmap.flattenXY(loc.x, loc.y), int((ally.health - ally.max_health) / 10) ]) HEALER_MAP = dmap.dijkstraMap(goals, WALL_GRAPH) healerMapBench.end() # refresh blueprint map BLUEPRINT_MAP = [] if allBlueprints: factoryMapBench.start() blueprintLocs = [ f.location.map_location() for f in allBlueprints ] BLUEPRINT_MAP = adjacentToMap(blueprintLocs) factoryMapBench.end()
RANGER_MAP = [] if rangers: rangerMapBench.start() RANGER_MAP = rangerMap(THIS_PLANETMAP, rangerAtkRange) rangerMapBench.end() # Healer map. Directs healers to get near rangers to heal them HEALER_MAP = [] if healers: healerMapBench.start() goals = [] for ally in rangers: if ally.health < ally.max_health and ally.location.is_on_map(): loc = ally.location.map_location() goals.append([dmap.flattenXY(loc.x,loc.y), int((ally.health - ally.max_health)/10)]) HEALER_MAP = dmap.dijkstraMap(goals, WALL_GRAPH) healerMapBench.end() # refresh blueprint map BLUEPRINT_MAP = [] if allBlueprints: factoryMapBench.start() blueprintLocs = [f.location.map_location() for f in allBlueprints] BLUEPRINT_MAP = adjacentToMap(blueprintLocs) factoryMapBench.end() rocketMapBench.start() # refresh rocket map ROCKET_MAP = [] if rockets: