def get_jobs(life, group_id): _group = get_group(life, group_id) _jobs = [] _leader = LIFE[_group['leader']] if not has_camp(group_id): _nearest_camp = camps.get_nearest_known_camp(_leader) if _leader['known_camps']: _j = jobs.create_job(_leader, 'Raid', gist='start_raid', description='Raid camp %s.' % _nearest_camp['id']) _pos = lfe.get_current_chunk(_leader)['pos'] _chunk_key = lfe.get_current_chunk_id(_leader) jobs.add_task(_j, '0', 'announce_to_group', action.make_small_script(function='announce_to_group', kwargs={'group_id': group_id, 'gist': 'announce_group_job', 'message': jobs.get_job(_j)['description'], 'job_id': _j}), player_action=action.make_small_script(function='always'), description='Gather group members.') jobs.add_task(_j, '1', 'move_to_chunk', action.make_small_script(function='travel_to_position', kwargs={'pos': _pos}), player_action=action.make_small_script(function='is_in_chunk', kwargs={'chunk_key': _chunk_key}), description='Travel to position %s, %s' % (_pos[0], _pos[1]), delete_on_finish=False) jobs.add_task(_j, '2', 'wait_for_number_of_group_members_in_chunk', action.make_small_script(function='number_of_alife_in_chunk_matching', kwargs={'amount': 2, 'chunk_key': _chunk_key, 'matching': {'group': _leader['group']}}), description='Wait until everyone arrives.') #jobs.add_task(_j, '3', 'talk', # action.make_small_script(function='travel_to_position', # kwargs={'pos': chunks.get_nearest_chunk_in_list(_leader['pos'], camps.get_camp(_nearest_camp['id'])['reference'])}), # requires=['1'], # delete_on_finish=False) _jobs.append(_j) if len(_leader['known_groups'])>1: _lowest = {'score': 0, 'group': None} for group_id in [g for g in _leader['known_groups'] if not g==_leader['group']]: _score = judgement.judge_group(_leader, group_id) if not _lowest['group'] or _score < _lowest['score']: _lowest['score'] = _score _lowest['group'] = group_id print 'RAID', _lowest else: print 'ony one' return _jobs
def order_to_loot(life, group_id, add_leader=False): #TODO: We should really consider moving the needs portion of this code outside of this function #Because this function really only does something on the first run, rendering it into just another #announce loop... _group = get_group(life, group_id) _requirements = [action.make_small_script(function='has_number_of_items_matching', args={'matching': [{'type': 'drink'}], 'amount': 1})] _j = jobs.create_job(life, 'Loot for group %s.' % life['group'], gist='loot_for_group', description='Collect loot for group.', group=life['group'], requirements=_requirements) if _j: for member in _group['members']: if member == _group['leader'] and not add_leader: continue survival.add_needed_item(LIFE[member], {'type': 'drink'}, amount=1, pass_if=_requirements, satisfy_if=action.make_small_script(function='group_needs_resources', args={'group_id': group_id}), satisfy_callback=action.make_small_script(return_function='pass')) jobs.add_task(_j, '0', 'bring_back_loot', action.make_small_script(function='find_target', kwargs={'target': _group['leader'], 'distance': 5, 'follow': False}), player_action=action.make_small_script(function='can_see_target', kwargs={'target_id': _group['leader']}), description='Drop the item off at the camp', delete_on_finish=False) jobs.add_task(_j, '1', 'flag_item', action.make_small_script(function='flag_item_matching', kwargs={'matching': {'type': 'drink'}, 'flag': 'ignore'}), player_action=action.make_small_script(function='always'), description='Ignore this', delete_on_finish=False) jobs.add_task(_j, '2', 'drop_item', action.make_small_script(function='drop_item_matching', kwargs={'matching': {'type': 'drink'}}), player_action=action.make_small_script(function='never'), description='Drop the item off at the camp', delete_on_finish=False) flag(group_id, 'loot', _j) if lfe.ticker(life, 'resource_announce', 10): _job_id = get_flag(group_id, 'loot') announce(life, life['group'], 'job', 'We need more resources.', job_id=_job_id, order=True, filter_if=[action.make_small_script(function='has_needs_to_meet')])
def generate_needs(life): if not lfe.ticker(life, 'generate_needs', 90, fire=True): return False if stats.desires_weapon(life): brain.flag(life, 'no_weapon') else: brain.unflag(life, 'no_weapon') if combat.get_weapons(life): for weapon in combat.get_weapons(life): _weapon_uid = weapon['uid'] #for _flag in ['ammo', 'feed']: if len(combat.get_all_ammo_for_weapon(life, _weapon_uid)) >= 5: _flag_name = '%s_needs_ammo' % _weapon_uid _need = brain.get_flag(life, _flag_name) if _need: delete_needed_item(life, _need) brain.unflag(life, _flag_name) if combat.get_feeds_for_weapon(life, _weapon_uid): _flag_name = '%s_needs_feed' % _weapon_uid _need = brain.get_flag(life, _flag_name) if _need: delete_needed_item(life, _need) brain.unflag(life, _flag_name) if not combat.has_potentially_usable_weapon( life) and not combat.has_ready_weapon(life): #_weapon_with_feed = None #for weapon in combat.get_weapons(life): # if weapons.get_feed(weapon): # _weapon_with_feed = weapon['uid'] # break #if _weapon_with_feed: # _weapon_uid = weapon['uid'] # _flag_name = '%s_needs_ammo' % _weapon_uid # _n = add_needed_item(life, # {'type': 'bullet', 'owner': None, 'ammotype': weapon['ammotype']}, # satisfy_if=action.make_small_script(function='get_flag', # args={'flag': _flag_name}), # satisfy_callback=action.make_small_script(return_function='pick_up_and_hold_item')) # # brain.flag(life, _flag_name, value=_n) for weapon in combat.get_weapons(life): _weapon_uid = weapon['uid'] _flag_name = '%s_needs_feed' % _weapon_uid if combat.have_feed_and_ammo_for_weapon(life, _weapon_uid): continue #print 'feeds?', combat.get_feeds_for_weapon(life, _weapon_uid), [ITEMS[i]['name'] for i in lfe.get_held_items(life)] if not combat.get_feeds_for_weapon( life, _weapon_uid) and not brain.get_flag( life, _flag_name): _n = add_needed_item( life, { 'type': weapon['feed'], 'owner': None, 'ammotype': weapon['ammotype'] }, satisfy_if=action.make_small_script( function='get_flag', args={'flag': _flag_name}), satisfy_callback=action.make_small_script( return_function='pick_up_and_hold_item')) brain.flag(life, _flag_name, value=_n) _flag_name = '%s_needs_ammo' % _weapon_uid if len(combat.get_all_ammo_for_weapon( life, _weapon_uid)) < 5 and not brain.get_flag( life, _flag_name): _n = add_needed_item( life, { 'type': 'bullet', 'owner': None, 'ammotype': weapon['ammotype'] }, satisfy_if=action.make_small_script( function='get_flag', args={'flag': _flag_name}), satisfy_callback=action.make_small_script( return_function='pick_up_and_hold_item')) brain.flag(life, _flag_name, value=_n)
def generate_needs(life): if not lfe.ticker(life, "generate_needs", 90, fire=True): return False if stats.desires_weapon(life): brain.flag(life, "no_weapon") else: brain.unflag(life, "no_weapon") if combat.get_weapons(life): for weapon in combat.get_weapons(life): _weapon_uid = weapon["uid"] # for _flag in ['ammo', 'feed']: if len(combat.get_all_ammo_for_weapon(life, _weapon_uid)) >= 5: _flag_name = "%s_needs_ammo" % _weapon_uid _need = brain.get_flag(life, _flag_name) if _need: delete_needed_item(life, _need) brain.unflag(life, _flag_name) if combat.get_feeds_for_weapon(life, _weapon_uid): _flag_name = "%s_needs_feed" % _weapon_uid _need = brain.get_flag(life, _flag_name) if _need: delete_needed_item(life, _need) brain.unflag(life, _flag_name) if not combat.has_potentially_usable_weapon(life) and not combat.has_ready_weapon(life): # _weapon_with_feed = None # for weapon in combat.get_weapons(life): # if weapons.get_feed(weapon): # _weapon_with_feed = weapon['uid'] # break # if _weapon_with_feed: # _weapon_uid = weapon['uid'] # _flag_name = '%s_needs_ammo' % _weapon_uid # _n = add_needed_item(life, # {'type': 'bullet', 'owner': None, 'ammotype': weapon['ammotype']}, # satisfy_if=action.make_small_script(function='get_flag', # args={'flag': _flag_name}), # satisfy_callback=action.make_small_script(return_function='pick_up_and_hold_item')) # # brain.flag(life, _flag_name, value=_n) for weapon in combat.get_weapons(life): _weapon_uid = weapon["uid"] _flag_name = "%s_needs_feed" % _weapon_uid if combat.have_feed_and_ammo_for_weapon(life, _weapon_uid): continue # print 'feeds?', combat.get_feeds_for_weapon(life, _weapon_uid), [ITEMS[i]['name'] for i in lfe.get_held_items(life)] if not combat.get_feeds_for_weapon(life, _weapon_uid) and not brain.get_flag(life, _flag_name): _n = add_needed_item( life, {"type": weapon["feed"], "owner": None, "ammotype": weapon["ammotype"]}, satisfy_if=action.make_small_script(function="get_flag", args={"flag": _flag_name}), satisfy_callback=action.make_small_script(return_function="pick_up_and_hold_item"), ) brain.flag(life, _flag_name, value=_n) _flag_name = "%s_needs_ammo" % _weapon_uid if len(combat.get_all_ammo_for_weapon(life, _weapon_uid)) < 5 and not brain.get_flag(life, _flag_name): _n = add_needed_item( life, {"type": "bullet", "owner": None, "ammotype": weapon["ammotype"]}, satisfy_if=action.make_small_script(function="get_flag", args={"flag": _flag_name}), satisfy_callback=action.make_small_script(return_function="pick_up_and_hold_item"), ) brain.flag(life, _flag_name, value=_n)
def get_jobs(life, group_id): _group = get_group(life, group_id) _jobs = [] _leader = LIFE[_group['leader']] if not has_camp(group_id): _nearest_camp = camps.get_nearest_known_camp(_leader) if _leader['known_camps']: _j = jobs.create_job(_leader, 'Raid', gist='start_raid', description='Raid camp %s.' % _nearest_camp['id']) _pos = lfe.get_current_chunk(_leader)['pos'] _chunk_key = lfe.get_current_chunk_id(_leader) jobs.add_task( _j, '0', 'announce_to_group', action.make_small_script(function='announce_to_group', kwargs={ 'group_id': group_id, 'gist': 'announce_group_job', 'message': jobs.get_job(_j)['description'], 'job_id': _j }), player_action=action.make_small_script(function='always'), description='Gather group members.') jobs.add_task( _j, '1', 'move_to_chunk', action.make_small_script(function='travel_to_position', kwargs={'pos': _pos}), player_action=action.make_small_script( function='is_in_chunk', kwargs={'chunk_key': _chunk_key}), description='Travel to position %s, %s' % (_pos[0], _pos[1]), delete_on_finish=False) jobs.add_task(_j, '2', 'wait_for_number_of_group_members_in_chunk', action.make_small_script( function='number_of_alife_in_chunk_matching', kwargs={ 'amount': 2, 'chunk_key': _chunk_key, 'matching': { 'group': _leader['group'] } }), description='Wait until everyone arrives.') #jobs.add_task(_j, '3', 'talk', # action.make_small_script(function='travel_to_position', # kwargs={'pos': chunks.get_nearest_chunk_in_list(_leader['pos'], camps.get_camp(_nearest_camp['id'])['reference'])}), # requires=['1'], # delete_on_finish=False) _jobs.append(_j) if len(_leader['known_groups']) > 1: _lowest = {'score': 0, 'group': None} for group_id in [ g for g in _leader['known_groups'] if not g == _leader['group'] ]: _score = judgement.judge_group(_leader, group_id) if not _lowest['group'] or _score < _lowest['score']: _lowest['score'] = _score _lowest['group'] = group_id print 'RAID', _lowest else: print 'ony one' return _jobs
def order_to_loot(life, group_id, add_leader=False): #TODO: We should really consider moving the needs portion of this code outside of this function #Because this function really only does something on the first run, rendering it into just another #announce loop... _group = get_group(life, group_id) _requirements = [ action.make_small_script(function='has_number_of_items_matching', args={ 'matching': [{ 'type': 'drink' }], 'amount': 1 }) ] _j = jobs.create_job(life, 'Loot for group %s.' % life['group'], gist='loot_for_group', description='Collect loot for group.', group=life['group'], requirements=_requirements) if _j: for member in _group['members']: if member == _group['leader'] and not add_leader: continue survival.add_needed_item(LIFE[member], {'type': 'drink'}, amount=1, pass_if=_requirements, satisfy_if=action.make_small_script( function='group_needs_resources', args={'group_id': group_id}), satisfy_callback=action.make_small_script( return_function='pass')) jobs.add_task(_j, '0', 'bring_back_loot', action.make_small_script(function='find_target', kwargs={ 'target': _group['leader'], 'distance': 5, 'follow': False }), player_action=action.make_small_script( function='can_see_target', kwargs={'target_id': _group['leader']}), description='Drop the item off at the camp', delete_on_finish=False) jobs.add_task( _j, '1', 'flag_item', action.make_small_script(function='flag_item_matching', kwargs={ 'matching': { 'type': 'drink' }, 'flag': 'ignore' }), player_action=action.make_small_script(function='always'), description='Ignore this', delete_on_finish=False) jobs.add_task(_j, '2', 'drop_item', action.make_small_script( function='drop_item_matching', kwargs={'matching': { 'type': 'drink' }}), player_action=action.make_small_script(function='never'), description='Drop the item off at the camp', delete_on_finish=False) flag(group_id, 'loot', _j) if lfe.ticker(life, 'resource_announce', 10): _job_id = get_flag(group_id, 'loot') announce( life, life['group'], 'job', 'We need more resources.', job_id=_job_id, order=True, filter_if=[action.make_small_script(function='has_needs_to_meet')])