def escape(life, targets): _avoid_positions = [] _zones = [zones.get_zone_at_coords(life['pos'])] if lfe.find_action(life, [{'action': 'dijkstra_move', 'reason': 'escape'}]): if lfe.ticker(life, 'escape_refresh', 4): lfe.stop(life) else: return False for target_id in targets: _target = brain.knows_alife_by_id(life, target_id) _zone = zones.get_zone_at_coords(_target['last_seen_at']) if not _zone in _zones: _zones.append(_zone) _avoid_positions.append(_target['last_seen_at']) lfe.add_action(life, {'action': 'dijkstra_move', 'rolldown': False, 'zones': _zones, 'goals': _avoid_positions, 'reason': 'escape'}, 100)
def escape(life, targets): _avoid_positions = [] _zones = [zones.get_zone_at_coords(life['pos'])] if lfe.find_action(life, [{ 'action': 'dijkstra_move', 'reason': 'escape' }]): if lfe.ticker(life, 'escape_refresh', 4): lfe.stop(life) else: return False for target_id in targets: _target = brain.knows_alife_by_id(life, target_id) _zone = zones.get_zone_at_coords(_target['last_seen_at']) if not _zone in _zones: _zones.append(_zone) _avoid_positions.append(_target['last_seen_at']) lfe.add_action( life, { 'action': 'dijkstra_move', 'rolldown': False, 'zones': _zones, 'goals': _avoid_positions, 'reason': 'escape' }, 100)
def get_distance_to_target(life, target_id): target = brain.knows_alife_by_id(life, target_id) _goals = [target["last_seen_at"]] _zones = [zones.get_zone_at_coords(target["last_seen_at"])] _zone = zones.get_zone_at_coords(life["pos"]) if not _zone in _zones: _zones.append(_zone) return zones.dijkstra_map(life["pos"], _goals, _zones, return_score=True)
def get_distance_to_target(life, target_id): target = brain.knows_alife_by_id(life, target_id) _goals = [target['last_seen_at']] _zones = [zones.get_zone_at_coords(target['last_seen_at'])] _zone = zones.get_zone_at_coords(life['pos']) if not _zone in _zones: _zones.append(_zone) return zones.dijkstra_map(life['pos'], _goals, _zones, return_score=True)
def get_target_positions_and_zones(life, targets, ignore_escaped=False): _target_positions = [] _zones = [] for _target in targets: _known_target = brain.knows_alife_by_id(life, _target) if ignore_escaped and _known_target['escaped'] or not _known_target['last_seen_at']: continue _target_positions.append(_known_target['last_seen_at']) _zone = zones.get_zone_at_coords(_known_target['last_seen_at']) if not _zone in _zones: _zones.append(_zone) _zone = zones.get_zone_at_coords(life['pos']) if not _zone in _zones: _zones.append(_zone) return _target_positions, _zones
def position_to_attack(life, target): if lfe.find_action(life, [{'action': 'dijkstra_move', 'reason': 'positioning for attack'}]): if not lfe.ticker(life, 'attack_position', 4): return False _target_positions, _zones = combat.get_target_positions_and_zones(life, [target]) _nearest_target_score = zones.dijkstra_map(life['pos'], _target_positions, _zones, return_score=True) #TODO: Short or long-range weapon? #if _nearest_target_score >= sight.get_vision(life)/2: if not sight.can_see_position(life, brain.knows_alife_by_id(life, target)['last_seen_at'], block_check=True, strict=True) or sight.view_blocked_by_life(life, _target_positions[0], allow=[target]): print life['name'], 'changing position for combat...', life['name'], LIFE[target]['name'] _avoid_positions = [] for life_id in life['seen']: if life_id == target or life['id'] == life_id: continue if alife.judgement.can_trust(life, life_id): _avoid_positions.append(lfe.path_dest(LIFE[life_id])) else: _avoid_positions.append(brain.knows_alife_by_id(life, life_id)['last_seen_at']) _cover = _target_positions _zones = [] for pos in _cover: _zone = zones.get_zone_at_coords(pos) if not _zone in _zones: _zones.append(_zone) if not lfe.find_action(life, [{'action': 'dijkstra_move', 'orig_goals': _cover[:], 'avoid_positions': _avoid_positions}]): lfe.stop(life) lfe.add_action(life, {'action': 'dijkstra_move', 'rolldown': True, 'goals': _cover[:], 'orig_goals': _cover[:], 'avoid_positions': _avoid_positions, 'reason': 'positioning for attack'}, 999) return False else: return False elif life['path']: lfe.stop(life) return True
def escape(life, targets): _avoid_positions = [] _zones = [zones.get_zone_at_coords(life["pos"])] if lfe.find_action(life, [{"action": "dijkstra_move", "reason": "escape"}]): if lfe.ticker(life, "escape_refresh", 4): lfe.stop(life) else: return False for target_id in targets: _target = brain.knows_alife_by_id(life, target_id) _zone = zones.get_zone_at_coords(_target["last_seen_at"]) if not _zone in _zones: _zones.append(_zone) _avoid_positions.append(_target["last_seen_at"]) lfe.add_action( life, {"action": "dijkstra_move", "rolldown": False, "zones": _zones, "goals": _avoid_positions, "reason": "escape"}, 100, )
def ranged_combat(life, targets): _target = brain.knows_alife_by_id(life, get_closest_target(life, targets)) #if not _target: # for target_id in targets: # if brain.knows_alife_by_id(life, target_id)['escaped']: # continue # # brain.knows_alife_by_id(life, target_id)['escaped'] = 1 # # logging.error('No target for ranged combat.') # # return False _engage_distance = get_engage_distance(life) _path_dest = lfe.path_dest(life) if not _path_dest: _path_dest = life['pos'][:] _target_distance = bad_numbers.distance(life['pos'], _target['last_seen_at']) #Get us near the target #if _target['last_seen_at']: movement.position_to_attack(life, _target['life']['id'], _engage_distance) if sight.can_see_position(life, _target['last_seen_at']): if _target_distance <= _engage_distance: if sight.can_see_position(life, _target['life']['pos']): if not sight.view_blocked_by_life(life, _target['life']['pos'], allow=[_target['life']['id']]): lfe.clear_actions(life) if not len(lfe.find_action(life, matches=[{'action': 'shoot'}])) and _target['time_visible']>2: for i in range(weapons.get_rounds_to_fire(weapons.get_weapon_to_fire(life))): lfe.add_action(life, {'action': 'shoot', 'target': _target['last_seen_at'], 'target_id': _target['life']['id'], 'limb': 'chest'}, 300, delay=int(round(life['recoil']-stats.get_recoil_recovery_rate(life)))) else: _friendly_positions, _friendly_zones = get_target_positions_and_zones(life, judgement.get_trusted(life)) _friendly_zones.append(zones.get_zone_at_coords(life['pos'])) _friendly_positions.append(life['pos'][:]) if not lfe.find_action(life, [{'action': 'dijkstra_move', 'orig_goals': [_target['life']['pos'][:]], 'avoid_positions': _friendly_positions}]): lfe.add_action(life, {'action': 'dijkstra_move', 'rolldown': True, 'zones': _friendly_zones, 'goals': [_target['life']['pos'][:]], 'orig_goals': [_target['life']['pos'][:]], 'avoid_positions': _friendly_positions, 'reason': 'combat_position'}, 100) else: lfe.memory(life,'lost sight of %s' % (' '.join(_target['life']['name'])), target=_target['life']['id']) _target['escaped'] = 1 for send_to in judgement.get_trusted(life): speech.communicate(life, 'target_missing', target=_target['life']['id'], matches=[send_to]) #else: #print life['name'] #_friendly_positions, _friendly_zones = get_target_positions_and_zones(life, judgement.get_trusted(life)) #_friendly_zones.append(zones.get_zone_at_coords(life['pos'])) #_friendly_positions.append(life['pos'][:]) #if not lfe.find_action(life, [{'action': 'dijkstra_move', 'orig_goals': [_target['life']['pos'][:]], 'avoid_positions': _friendly_positions}]): # lfe.add_action(life, {'action': 'dijkstra_move', # 'rolldown': True, # 'zones': _friendly_zones, # 'goals': [_target['life']['pos'][:]], # 'orig_goals': [_target['life']['pos'][:]], # 'avoid_positions': _friendly_positions, # 'reason': 'combat_position'}, # 100) # # print '2' else: return False
def explode(item): if not item['type'] == 'explosive': return False logging.debug('The %s (item %s) explodes!' % (item['name'], item['uid'])) #TODO: Don't breathe this! item['pos'] = get_pos(item['uid']) if item['damage']['force']: effects.create_explosion(item['pos'], item['damage']['force']) if SETTINGS['controlling'] and alife.sight.can_see_position(LIFE[SETTINGS['controlling']], item['pos']): gfx.message('%s explodes!' % get_name(item)) logic.show_event('%s explodes!' % get_name(item), item=item, delay=0) #elif bad_numbers.distance( #TODO: Dirty hack for life_id in LIFE: _limbs = LIFE[life_id]['body'].keys() if not _limbs: continue _force = bad_numbers.clip((item['damage']['force']*2)-bad_numbers.distance(LIFE[life_id]['pos'], item['pos']), 0, 100) if not _force: continue _known_item = alife.brain.remembers_item(LIFE[life_id], item) _direction = bad_numbers.direction_to(item['pos'], LIFE[life_id]['pos']) #TODO: Intelligent(?) limb groups? _distance = bad_numbers.distance(LIFE[life_id]['pos'], item['pos'])/2 for i in range(_force-_distance): _limb = random.choice(_limbs) for _attached_limb in life.get_all_attached_limbs(LIFE[life_id], _limb): if _attached_limb in _limbs: _limbs.remove(_attached_limb) #_limb = random.choice(LIFE[life_id]['body'].keys()) if _known_item and _known_item['last_seen_time'] < 100 and _known_item['last_owned_by']: life.memory(LIFE[life_id], 'blown_up_by', target=_known_item['last_owned_by']) #for _limb in _limbs: life.add_wound(LIFE[life_id], _limb, force_velocity=bad_numbers.velocity(_direction, _force*2)) if not _limbs: break life.push(LIFE[life_id], _direction, _force) if 'player' in LIFE[life_id]: life.say(LIFE[life_id], '@n are thrown by the explosion!', action=True) else: life.say(LIFE[life_id], '@n is thrown by the explosion!', action=True) if 'fire' in item['damage']: _circle = drawing.draw_circle(item['pos'], item['radius']) _zone = zones.get_zone_at_coords(item['pos']) if _zone: for pos in zones.dijkstra_map(item['pos'], [item['pos']], [_zone], return_score_in_range=[0, item['damage']['fire']]): if not pos in _circle: continue if not maps.position_is_in_map(pos): continue for life_id in LIFE_MAP[pos[0]][pos[1]]: for _visible_item in [get_item_from_uid(i) for i in life.get_all_visible_items(LIFE[life_id])]: if not 'CAN_BURN' in _visible_item['flags']: continue burn(_visible_item, item['damage']['fire']) if not random.randint(0, 4): effects.create_fire((pos[0], pos[1], item['pos'][2]), intensity=item['damage']['fire']/2) _dist = bad_numbers.distance(item['pos'], pos)/2 if not random.randint(0, _dist) or not _dist: effects.create_ash(pos) if gfx.position_is_in_frame(pos): _render_pos = gfx.get_render_position(pos) gfx.refresh_view_position(_render_pos[0], _render_pos[1], 'map') #if item['uid'] in ITEMS and ITEMS[item['uid']]['owner'] and item['uid'] in LIFE[ITEMS[item['uid']]['owner']]['inventory']: delete_item(item)
def ranged_combat(life, targets): _target = brain.knows_alife_by_id(life, get_closest_target(life, targets)) #if not _target: # for target_id in targets: # if brain.knows_alife_by_id(life, target_id)['escaped']: # continue # # brain.knows_alife_by_id(life, target_id)['escaped'] = 1 # # logging.error('No target for ranged combat.') # # return False _engage_distance = get_engage_distance(life) _path_dest = lfe.path_dest(life) if not _path_dest: _path_dest = life['pos'][:] _target_distance = bad_numbers.distance(life['pos'], _target['last_seen_at']) #Get us near the target #if _target['last_seen_at']: movement.position_to_attack(life, _target['life']['id'], _engage_distance) if sight.can_see_position(life, _target['last_seen_at']): if _target_distance <= _engage_distance: if sight.can_see_position(life, _target['life']['pos']): if not sight.view_blocked_by_life( life, _target['life']['pos'], allow=[_target['life']['id']]): lfe.clear_actions(life) if not len( lfe.find_action( life, matches=[{ 'action': 'shoot' }])) and _target['time_visible'] > 2: for i in range( weapons.get_rounds_to_fire( weapons.get_weapon_to_fire(life))): lfe.add_action( life, { 'action': 'shoot', 'target': _target['last_seen_at'], 'target_id': _target['life']['id'], 'limb': 'chest' }, 300, delay=int( round( life['recoil'] - stats.get_recoil_recovery_rate(life)))) else: _friendly_positions, _friendly_zones = get_target_positions_and_zones( life, judgement.get_trusted(life)) _friendly_zones.append( zones.get_zone_at_coords(life['pos'])) _friendly_positions.append(life['pos'][:]) if not lfe.find_action( life, [{ 'action': 'dijkstra_move', 'orig_goals': [_target['life']['pos'][:]], 'avoid_positions': _friendly_positions }]): lfe.add_action( life, { 'action': 'dijkstra_move', 'rolldown': True, 'zones': _friendly_zones, 'goals': [_target['life']['pos'][:]], 'orig_goals': [_target['life']['pos'][:]], 'avoid_positions': _friendly_positions, 'reason': 'combat_position' }, 100) else: lfe.memory(life, 'lost sight of %s' % (' '.join(_target['life']['name'])), target=_target['life']['id']) _target['escaped'] = 1 for send_to in judgement.get_trusted(life): speech.communicate(life, 'target_missing', target=_target['life']['id'], matches=[send_to]) #else: #print life['name'] #_friendly_positions, _friendly_zones = get_target_positions_and_zones(life, judgement.get_trusted(life)) #_friendly_zones.append(zones.get_zone_at_coords(life['pos'])) #_friendly_positions.append(life['pos'][:]) #if not lfe.find_action(life, [{'action': 'dijkstra_move', 'orig_goals': [_target['life']['pos'][:]], 'avoid_positions': _friendly_positions}]): # lfe.add_action(life, {'action': 'dijkstra_move', # 'rolldown': True, # 'zones': _friendly_zones, # 'goals': [_target['life']['pos'][:]], # 'orig_goals': [_target['life']['pos'][:]], # 'avoid_positions': _friendly_positions, # 'reason': 'combat_position'}, # 100) # # print '2' else: return False
def hide(life, targets): _target_positions = [] _avoid_positions = [] _zones = [zones.get_zone_at_coords(life['pos'])] if lfe.find_action(life, [{ 'action': 'dijkstra_move', 'reason': 'escaping' }]): if not lfe.ticker(life, 'escaping', 6): return False #What can the targets see? for target_id in targets: _target = brain.knows_alife_by_id(life, target_id) _zone = zones.get_zone_at_coords(_target['last_seen_at']) if not _zone in _zones: _zones.append(_zone) fov.fov(_target['last_seen_at'], sight.get_vision(_target['life']), callback=lambda pos: _avoid_positions.append(pos)) #What can we see? _can_see_positions = [] fov.fov(life['pos'], sight.get_vision(life), callback=lambda pos: _can_see_positions.append(pos)) #If there are no visible targets, we could be running away from a position we were attacked from _cover_exposed_at = brain.get_flag(life, 'cover_exposed_at') if _cover_exposed_at: _avoid_exposed_cover_positions = set() for pos in _cover_exposed_at[:]: if tuple(pos[:2]) in _can_see_positions: _cover_exposed_at.remove(pos) continue fov.fov( pos, int(round(sight.get_vision(life) * .25)), callback=lambda pos: _avoid_exposed_cover_positions.add(pos)) for pos in _avoid_exposed_cover_positions: if not pos in _avoid_positions: _avoid_positions.append(pos) else: print 'Something went wrong' return False #Overlay the two, finding positions we can see but the target can't for pos in _can_see_positions[:]: if pos in _avoid_positions: _can_see_positions.remove(pos) continue #Get rid of positions that are too close for target_id in targets: _target = brain.knows_alife_by_id(life, target_id) if bad_numbers.distance(_target['last_seen_at'], pos) < 4: _can_see_positions.remove(pos) break #Now scan for cover to prevent hiding in the open for pos in _can_see_positions[:]: if chunks.get_chunk(chunks.get_chunk_key_at(pos))['max_z'] == 2: _can_see_positions.remove(pos) if not _can_see_positions: if life['pos'] in _cover_exposed_at: _cover_exposed_at.remove(life['pos']) return False if lfe.find_action(life, [{ 'action': 'dijkstra_move', 'goals': _can_see_positions[:] }]): return True lfe.stop(life) lfe.add_action( life, { 'action': 'dijkstra_move', 'rolldown': True, 'zones': _zones, 'goals': _can_see_positions[:], 'reason': 'escaping' }, 200)
def hide(life, targets): _target_positions = [] _avoid_positions = [] _zones = [zones.get_zone_at_coords(life["pos"])] if lfe.find_action(life, [{"action": "dijkstra_move", "reason": "escaping"}]): if not lfe.ticker(life, "escaping", 6): return False # What can the targets see? for target_id in targets: _target = brain.knows_alife_by_id(life, target_id) _zone = zones.get_zone_at_coords(_target["last_seen_at"]) if not _zone in _zones: _zones.append(_zone) fov.fov( _target["last_seen_at"], sight.get_vision(_target["life"]), callback=lambda pos: _avoid_positions.append(pos), ) # What can we see? _can_see_positions = [] fov.fov(life["pos"], sight.get_vision(life), callback=lambda pos: _can_see_positions.append(pos)) # If there are no visible targets, we could be running away from a position we were attacked from _cover_exposed_at = brain.get_flag(life, "cover_exposed_at") if _cover_exposed_at: _avoid_exposed_cover_positions = set() for pos in _cover_exposed_at[:]: if tuple(pos[:2]) in _can_see_positions: _cover_exposed_at.remove(pos) continue fov.fov( pos, int(round(sight.get_vision(life) * 0.25)), callback=lambda pos: _avoid_exposed_cover_positions.add(pos), ) for pos in _avoid_exposed_cover_positions: if not pos in _avoid_positions: _avoid_positions.append(pos) else: print "Something went wrong" return False # Overlay the two, finding positions we can see but the target can't for pos in _can_see_positions[:]: if pos in _avoid_positions: _can_see_positions.remove(pos) continue # Get rid of positions that are too close for target_id in targets: _target = brain.knows_alife_by_id(life, target_id) if numbers.distance(_target["last_seen_at"], pos) < 4: _can_see_positions.remove(pos) break # Now scan for cover to prevent hiding in the open for pos in _can_see_positions[:]: if chunks.get_chunk(chunks.get_chunk_key_at(pos))["max_z"] == 2: _can_see_positions.remove(pos) if not _can_see_positions: if life["pos"] in _cover_exposed_at: _cover_exposed_at.remove(life["pos"]) return False if lfe.find_action(life, [{"action": "dijkstra_move", "goals": _can_see_positions[:]}]): return True lfe.stop(life) lfe.add_action( life, { "action": "dijkstra_move", "rolldown": True, "zones": _zones, "goals": _can_see_positions[:], "reason": "escaping", }, 200, )
def explode(item): if not item['type'] == 'explosive': return False logging.debug('The %s (item %s) explodes!' % (item['name'], item['uid'])) #TODO: Don't breathe this! item['pos'] = get_pos(item['uid']) if item['damage']['force']: effects.create_explosion(item['pos'], item['damage']['force']) if SETTINGS['controlling'] and alife.sight.can_see_position( LIFE[SETTINGS['controlling']], item['pos']): gfx.message('%s explodes!' % get_name(item)) logic.show_event('%s explodes!' % get_name(item), item=item, delay=0) #elif bad_numbers.distance( #TODO: Dirty hack for life_id in LIFE: _limbs = LIFE[life_id]['body'].keys() if not _limbs: continue _force = bad_numbers.clip( (item['damage']['force'] * 2) - bad_numbers.distance(LIFE[life_id]['pos'], item['pos']), 0, 100) if not _force: continue _known_item = alife.brain.remembers_item(LIFE[life_id], item) _direction = bad_numbers.direction_to(item['pos'], LIFE[life_id]['pos']) #TODO: Intelligent(?) limb groups? _distance = bad_numbers.distance(LIFE[life_id]['pos'], item['pos']) / 2 for i in range(_force - _distance): _limb = random.choice(_limbs) for _attached_limb in life.get_all_attached_limbs( LIFE[life_id], _limb): if _attached_limb in _limbs: _limbs.remove(_attached_limb) #_limb = random.choice(LIFE[life_id]['body'].keys()) if _known_item and _known_item[ 'last_seen_time'] < 100 and _known_item['last_owned_by']: life.memory(LIFE[life_id], 'blown_up_by', target=_known_item['last_owned_by']) #for _limb in _limbs: life.add_wound(LIFE[life_id], _limb, force_velocity=bad_numbers.velocity( _direction, _force * 2)) if not _limbs: break life.push(LIFE[life_id], _direction, _force) if 'player' in LIFE[life_id]: life.say(LIFE[life_id], '@n are thrown by the explosion!', action=True) else: life.say(LIFE[life_id], '@n is thrown by the explosion!', action=True) if 'fire' in item['damage']: _circle = drawing.draw_circle(item['pos'], item['radius']) _zone = zones.get_zone_at_coords(item['pos']) if _zone: for pos in zones.dijkstra_map( item['pos'], [item['pos']], [_zone], return_score_in_range=[0, item['damage']['fire']]): if not pos in _circle: continue if not maps.position_is_in_map(pos): continue for life_id in LIFE_MAP[pos[0]][pos[1]]: for _visible_item in [ get_item_from_uid(i) for i in life.get_all_visible_items(LIFE[life_id]) ]: if not 'CAN_BURN' in _visible_item['flags']: continue burn(_visible_item, item['damage']['fire']) if not random.randint(0, 4): effects.create_fire((pos[0], pos[1], item['pos'][2]), intensity=item['damage']['fire'] / 2) _dist = bad_numbers.distance(item['pos'], pos) / 2 if not random.randint(0, _dist) or not _dist: effects.create_ash(pos) if gfx.position_is_in_frame(pos): _render_pos = gfx.get_render_position(pos) gfx.refresh_view_position(_render_pos[0], _render_pos[1], 'map') #if item['uid'] in ITEMS and ITEMS[item['uid']]['owner'] and item['uid'] in LIFE[ITEMS[item['uid']]['owner']]['inventory']: delete_item(item)
def escape(life, targets): _target_positions = [] _avoid_positions = [] _zones = [zones.get_zone_at_coords(life['pos'])] if lfe.find_action(life, [{'action': 'dijkstra_move', 'reason': 'escaping'}]): if not lfe.ticker(life, 'escaping', 4): return False #What can the targets see? for target_id in targets: _target = brain.knows_alife_by_id(life, target_id) _zone = zones.get_zone_at_coords(_target['last_seen_at']) if not _zone in _zones: _zones.append(_zone) fov.fov(_target['last_seen_at'], sight.get_vision(_target['life']), callback=lambda pos: _avoid_positions.append(pos)) #What can we see? _can_see_positions = [] fov.fov(life['pos'], sight.get_vision(life), callback=lambda pos: _can_see_positions.append(pos)) #If there are no visible targets, we could be running away from a position we were attacked from _cover_exposed_at = brain.get_flag(life, 'cover_exposed_at') if _cover_exposed_at: _avoid_exposed_cover_positions = set() for pos in _cover_exposed_at[:]: if tuple(pos[:2]) in _can_see_positions: print 'ok!!!'*20 _cover_exposed_at.remove(pos) continue fov.fov(pos, int(round(sight.get_vision(life)*.25)), callback=lambda pos: _avoid_exposed_cover_positions.add(pos)) for pos in _avoid_exposed_cover_positions: if not pos in _avoid_positions: _avoid_positions.append(pos) #Overlay the two, finding positions we can see but the target can't for pos in _can_see_positions[:]: if pos in _avoid_positions: _can_see_positions.remove(pos) continue #Get rid of positions that are too close for target_id in targets: _target = brain.knows_alife_by_id(life, target_id) #TODO: Unhardcode 15 if numbers.distance(_target['last_seen_at'], pos)<10: _can_see_positions.remove(pos) break #Now scan for cover to prevent hiding in the open for pos in _can_see_positions[:]: if chunks.get_chunk(chunks.get_chunk_key_at(pos))['max_z'] == 2: _can_see_positions.remove(pos) #for target_id in targets: #_target = brain.knows_alife_by_id(life, target_id) #_target_positions.append(_target['last_seen_at'][:]) #_zone = zones.get_zone_at_coords(_target['last_seen_at']) #if not _zone in _zones: # _zones.append(_zone) #for chunk_key in chunks.get_visible_chunks_from(_target['last_seen_at'], sight.get_vision(_target['life'])): # if chunk_key in _visible_target_chunks: # continue # _visible_target_chunks.append(chunk_key) #for friendly_id in life['seen']: # _chunk_key = lfe.get_current_chunk_id(LIFE[friendly_id]) # # if not _chunk_key in _visible_target_chunks: # _visible_target_chunks.append(_chunk_key) #if not _target_positions: # return False #TODO: #combat: For lower limit in return_score_in_range, use range of weapon #_cover = zones.dijkstra_map(life['pos'], # _avoid_positions, # _zones, # avoid_chunks=[], # return_score_in_range=[1, 5]) # sight.get_vision(life) #_cover = [(c[0], c[1], life['pos'][2]) for c in _cover] #if not _cover: # return False #_zones = [zones.get_zone_at_coords(life['pos'])] #for _pos in _cover: # _zone = zones.get_zone_at_coords(_pos) # if not _zone in _zones: # _zones.append(_zone) if not _can_see_positions: return False if lfe.find_action(life, [{'action': 'dijkstra_move', 'goals': _can_see_positions[:]}]): return True lfe.stop(life) lfe.add_action(life, {'action': 'dijkstra_move', 'rolldown': True, 'zones': _zones, 'goals': _can_see_positions[:], 'reason': 'escaping'}, 999)