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 desires_weapon(life): if not combat.get_weapons(life): return True #if life['stats']['firearms'] >= 5: return False