def react_to_attack(life, life_id): _knows = brain.knows_alife_by_id(life, life_id) if not _knows['alignment'] == 'hostile': speech.start_dialog(life, _knows['life']['id'], 'establish_hostile') if life['group']: groups.announce(life, life['group'], 'attacked_by_hostile', target_id=_knows['life']['id'])
def react_to_attack(life, life_id): _knows = brain.knows_alife_by_id(life, life_id) if not _knows['alignment'] == 'hostile': speech.start_dialog(life, _knows['life']['id'], 'establish_hostile') if life['group']: groups.announce(life, life['group'], 'attacked_by_hostile', target_id=_knows['life']['id'], filter_if=lambda life_id: brain.knows_alife_by_id(life, life_id)['last_seen_time']<=30, ignore_if_said_in_last=150)
def order_spread_out(life, group_id, chunk_keys, filter_by=None): _group = get_group(life, group_id) _ordered_targets = [] for life_id in _group['members']: if not filter_by(life_id): continue if life_id == life['id']: movement.set_focus_point(life, random.choice(chunk_keys)) continue _ordered_targets.append(life_id) if lfe.get_current_chunk_id(LIFE[life_id]) in chunk_keys: speech.start_dialog(life, life_id, 'order_wait_%s' % get_group_size(life, group_id), remote=True) else: speech.start_dialog(life, life_id, 'order_move_to_chunk', chunk_key=random.choice(chunk_keys), remote=True) return _ordered_targets
def react_to_tension(life, life_id): if brain.knows_alife_by_id(life, life_id)['alignment'] in ['hostile']: return False if life['group'] and not groups.is_leader(life, life['group'], life['id']) and groups.get_leader(life, life['group']): if sight.can_see_target(life, groups.get_leader(life, life['group'])) and sight.can_see_target(LIFE[life_id], groups.get_leader(life, life['group'])): return False _disarm = brain.get_alife_flag(life, life_id, 'disarm') if _disarm: #For now... if not sight.can_see_position(life, LIFE[life_id]['pos']): groups.announce(life, life['group'], 'attacked_by_hostile', filter_if=lambda life_id: brain.knows_alife_by_id(life, life_id)['last_seen_time']<=30, target_id=life_id) return False for item_uid in lfe.get_all_visible_items(LIFE[life_id]): if ITEMS[item_uid]['type'] == 'gun': break else: brain.unflag_alife(life, life_id, 'disarm') speech.start_dialog(life, life_id, 'clear_drop_weapon') return False _time_elapsed = WORLD_INFO['ticks']-_disarm if _time_elapsed>135 and not speech.has_sent(life, life_id, 'threaten'): speech.start_dialog(life, life_id, 'threaten') speech.send(life, life_id, 'threaten') elif _time_elapsed>185: speech.start_dialog(life, life_id, 'establish_hostile') elif not speech.has_sent(life, life_id, 'confront'): speech.start_dialog(life, life_id, 'confront') speech.send(life, life_id, 'confront')
def setup(life): #TODO: Add these two values to an array called PANIC_STATES #if not alife_seen: # return False #if brain.retrieve_from_memory(life, 'tension_spike') >= 10: # lfe.say(life, '@n panics!', action=True) _potential_talking_targets = [] for ai in life['seen']: if not stats.can_talk_to(life, ai): continue #print life['name'], LIFE[ai]['name'], judgement.get_tension_with(life, ai) if stats.has_attacked_self(life, ai): stats.react_to_attack(life, ai) elif 0<judgement.get_tension_with(life, ai)<=judgement.get_max_tension_with(life, ai): stats.react_to_tension(life, ai) else: #if not stats.desires_first_contact_with(life, ai) and not stats.desires_conversation_with(life, ai): # continue if not stats.desires_conversation_with(life, ai): continue _potential_talking_targets.append(ai) if not _potential_talking_targets: if life['dialogs']: _dialog = life['dialogs'][0] dialog.process(life, _dialog) if not lfe.ticker(life, 'talk', 6): return False if lfe.get_all_inventory_items(life, matches=[{'type': 'radio'}]): for ai in life['know']: if ai in _potential_talking_targets: continue if not stats.can_talk_to(life, ai): continue _potential_talking_targets.append(ai) #TODO: Score these random.shuffle(_potential_talking_targets) for target in _potential_talking_targets: if life['dialogs']: break #if stats.desires_first_contact_with(life, target): # memory.create_question(life, target, 'establish_relationship', ignore_if_said_in_last=-1) if memory.get_questions_for_target(life, target): _question = memory.ask_target_question(life, target) speech.start_dialog(life, target, _question['gist'], **_question['args']) elif memory.get_orders_for_target(life, target): speech.start_dialog(life, target, 'give_order') elif stats.wants_group_member(life, target): memory.create_question(life, target, 'recruit', ignore_if_said_in_last=-1, group_id=life['group']) if life['dialogs']: _dialog = life['dialogs'][0] dialog.process(life, _dialog) if not judgement.is_safe(life) and lfe.ticker(life, 'call_for_help', 90, fire=True): _combat_targets = judgement.get_ready_combat_targets(life) if _combat_targets: if life['camp'] and camps.is_in_camp(life, lfe.get_current_camp(life)): _nearest_camp = camps.get_nearest_known_camp(life) raids.create_raid(_nearest_camp['id'], join=life['id']) raids.add_raiders(_nearest_camp['id'], _combat_targets) #TODO: Remove memory call speech.announce(life, 'camp_raid', camp=_nearest_camp, raiders=_combat_targets) if life['group']: for target in _combat_targets: _last_seen_at = None _know = brain.knows_alife_by_id(life, target) if _know: _last_seen_at = _know['last_seen_at'] groups.distribute(life, 'under_attack', attacker=target, last_seen_at=_last_seen_at) for target in judgement.get_ready_combat_targets(life): _last_seen_at = None _know = brain.knows_alife_by_id(life, target) if _know: _last_seen_at = _know['last_seen_at'] speech.announce(life, 'attacked_by_hostile', trusted=True, target_id=target, last_seen_at=_last_seen_at) _visible_items = [life['know_items'][item] for item in life['know_items'] if not life['know_items'][item]['last_seen_time'] and not 'parent_id' in ITEMS[life['know_items'][item]['item']]] for ai in [life['know'][i] for i in life['know']]: if judgement.is_target_dangerous(life, ai['life']['id']): continue #if life['state'] == 'combat': # break if ai['life']['state'] in ['hiding', 'hidden']: break if not stats.can_talk_to(life, ai['life']['id']): continue for item in _visible_items: #TODO: Check if brain.has_shared_item_with(life, ai['life'], item['item']): continue if not item['item'] in ITEMS: continue brain.share_item_with(life, ai['life'], item['item']) speech.communicate(life, 'share_item_info', item=item['item'], matches=[ai['life']['id']])
def listen(life): for event in life['heard'][:]: if not event['from']['id'] in life['know']: pass if not brain.knows_alife(life, event['from']): brain.meet_alife(life, event['from']) logging.info('%s learned about %s via listen.' % (' '.join(life['name']), ' '.join(event['from']['name']))) if event['gist'] == 'looks_hostile': #speech.communicate(life, 'surrender', matches=[{'id': event['from']['id']}]) pass elif event['gist'] == 'camp_raid': print '*' * 10 print 'RAID IN EFFECT!!!!!!!!!!' print '*' * 10 _knows = brain.knows_alife(life, event['from']) _raid = raids.defend_camp(event['camp']['id'], life['id']) if _knows and not judgement.is_target_dangerous(life, _knows['life']['id']): lfe.memory(life, 'heard about a camp raid', camp=event['camp']['id']) _raid_score = judgement.judge_raid(life, event['raiders'], event['camp']['id']) speech.announce(life, 'raid_score', raid_score=_raid_score) elif event['gist'] == 'raid_score': print life['name'],'Got friendly raid score:', event['raid_score'] elif event['gist'] == 'share_item_info': if event['item'] in ITEMS: if not brain.has_remembered_item(life, event['item']): lfe.memory(life, 'heard about an item', item=event['item'], target=event['from']['id']) brain.remember_item(life, ITEMS[event['item']]) elif event['gist'] == 'camp_founder': lfe.memory(life, 'heard about camp', camp=event['camp'], target=event['founder'], founder=event['founder']) print 'Thanks for the camp founder info!' elif event['gist'] == 'under_attack': _knows_attacker = True if life['id'] == event['attacker']: pass else: print life['name'], 'HEARD CALL FOR HELP FROM', event['from']['name'] if not brain.knows_alife_by_id(life, event['attacker']): brain.meet_alife(life, LIFE[event['attacker']]) _knows_attacker = False _target = brain.knows_alife_by_id(life, event['attacker']) _believes = judgement.believe_which_alife(life, [event['from']['id'], event['attacker']]) #SITUATION 1: We believe it if _believes == event['from']['id']: lfe.memory(life, 'heard about attack', attacker=event['attacker'], target=event['from']['id']) lfe.memory(life, 'target attacked victim', target=event['attacker'], victim=event['from']['id']) if event['last_seen_at']: _target['last_seen_at'] = event['last_seen_at'][:] else: _target['last_seen_at'] = event['from']['pos'][:] judgement.judge_life(life, event['attacker']) else: lfe.memory(life, 'reject under_attack: attacker is trusted', attacker=event['attacker'], target=event['from']['id']) elif event['gist'] == 'bit': #React to attack... this needs to be a function in stats.py if event['target'] == life['id']: pass else: _trust_sender = judgement.can_trust(life, event['from']['id']) if brain.knows_alife_by_id(life, event['target']): _trust_target = judgement.can_trust(life, event['target'], low=5) else: brain.meet_alife(life, LIFE[event['target']]) _trust_target = False if _trust_target and not _trust_sender and 1==4: lfe.memory(life, 'trusted target attacked by', victim=event['target'], target=event['from']['id']) elif event['gist'] == 'consume_item': lfe.memory(life, 'consume_item', target=event['from']['id']) elif event['gist'] == 'call': if judgement.can_trust(life, event['from']['id']): speech.start_dialog(life, event['from']['id'], 'call_accepted', remote=True) elif event['gist'] == 'order_attack': lfe.memory(life, 'ordered to attack', target=event['target']) elif event['gist'] == 'threw_an_item': print 'CHECK THIS HERE' * 100 pass elif event['gist'] == '_group_leader_state_change': life['think_rate'] = 0 elif event['gist'] == 'dialog': if not 'player' in life and not event['dialog_id'] in life['dialogs']: life['dialogs'].append(event['dialog_id']) else: logging.warning('Unhandled ALife context: %s' % event['gist']) life['heard'].remove(event)
def ask_for_help(life, life_id): _bleeding_limbs = len(lfe.get_bleeding_limbs(life)) if not speech.has_sent(life, life_id, 'hurt'): speech.start_dialog(life, life_id, 'hurt') speech.send(life, life_id, 'hurt')