Beispiel #1
0
def get_items_at(position, check_bodies=False):
	"""Returns list of all items at a given position."""
	_items = []
	_chunk = alife.chunks.get_chunk(alife.chunks.get_chunk_key_at(position))
	
	for _item in _chunk['items']:
		if not _item in ITEMS:
			continue		
		
		item = ITEMS[_item]
		
		if item['name'] == 'gib':
			continue
		
		if is_item_owned(_item):
			continue
		
		if tuple(item['pos']) == tuple(position):
			_items.append(item)
	
	#TODO: This is awful
	if check_bodies:
		#for pos in [(-1, 0), (1, 0), (0, -1), (0, 1), (-1, -1), (1, -1), (-1, 1), (1, 1), (0, 0)]:
		#	__pos = (_pos[0]+pos[0], _pos[1]+pos[1], _pos[2])
		#	_items.extend(items.get_items_at(__pos))
			
		#Sue me again.
		for life_id in LIFE[SETTINGS['controlling']]['seen']:
			if bad_numbers.distance(LIFE[SETTINGS['controlling']]['pos'], LIFE[life_id]['pos'])>1:
				continue
			
			for item_uid in life.get_all_equipped_items(LIFE[life_id]):
				_items.append(ITEMS[item_uid])
	
	return _items
Beispiel #2
0
def get_player_situation():
	if not SETTINGS['controlling']:
		return False
	
	_life = LIFE[SETTINGS['controlling']]
	
	_situation = {}
	_situation['armed'] = alife.combat.has_potentially_usable_weapon(_life)
	_situation['friends'] = len([l for l in _life['know'].values() if l['alignment'] in ['trust', 'feign_trust']])
	_situation['group'] = _life['group']
	_situation['online_alife'] = [l for l in LIFE.values() if l['online'] and not l['dead'] and not l['id'] == _life['id']]
	_situation['trusted_online_alife'] = [l for l in _situation['online_alife'] if alife.judgement.can_trust(_life, l['id'])]
	_situation['has_radio'] = len(lfe.get_all_inventory_items(_life, matches=[{'type': 'radio'}]))>0
	_situation['weapons'] = alife.combat.get_weapons(_life)
	_situation['equipped_gear'] = lfe.get_all_equipped_items(_life)	
	_active_factions = set()
	_enemy_factions = set()
	
	for life in _situation['online_alife']:
		if not life['faction'] in _active_factions:
			_active_factions.add(life['faction'])
		
		if alife.factions.is_enemy(_life, life['id']) and not life['faction'] in _enemy_factions:
			_enemy_factions.add(life['faction'])
	
	_situation['active_factions'] = list(_active_factions)
	_situation['friendly_factions'] = list(_enemy_factions-_active_factions)
	_situation['active_factions'] = list(_active_factions)
	_situation['enemy_factions'] = list(_enemy_factions)
	
	return _situation
Beispiel #3
0
def get_items_at(position, check_bodies=False):
	"""Returns list of all items at a given position."""
	_items = []
	_chunk = alife.chunks.get_chunk(alife.chunks.get_chunk_key_at(position))
	
	for _item in _chunk['items']:
		if not _item in ITEMS:
			continue
		
		item = ITEMS[_item]
		
		if is_item_owned(_item):
			continue
		
		if tuple(item['pos']) == tuple(position):
			_items.append(item)
	
	#TODO: This is awful
	if check_bodies:
		#for pos in [(-1, 0), (1, 0), (0, -1), (0, 1), (-1, -1), (1, -1), (-1, 1), (1, 1), (0, 0)]:
		#	__pos = (_pos[0]+pos[0], _pos[1]+pos[1], _pos[2])
		#	_items.extend(items.get_items_at(__pos))
			
		#Sue me again.
		for life_id in LIFE[SETTINGS['controlling']]['seen']:
			if numbers.distance(LIFE[SETTINGS['controlling']]['pos'], LIFE[life_id]['pos'])>1:
				continue
			
			for item_uid in life.get_all_equipped_items(LIFE[life_id]):
				_items.append(ITEMS[item_uid])
	
	return _items
Beispiel #4
0
def manage_inventory(life):
	if manage_hands(life):
		return False
	
	for weapon_uid in combat.get_equipped_weapons(life):
		if not combat.weapon_is_working(life, weapon_uid):
			if combat.weapon_is_in_preferred_working_condition(life, weapon_uid):
				if not len(lfe.find_action(life,matches=[{'action': 'refillammo'}])):
					combat.reload_weapon(life, weapon_uid)
				
					return True
	
	_item_to_wear = {'score': 0, 'item_uid': None}
	_item_to_equip = {'score': 0, 'item_uid': None}
		
	for item in [lfe.get_inventory_item(life, item) for item in lfe.get_all_unequipped_items(life)]:
		judgement.judge_item(life, item['uid'])
		_known_item = brain.get_remembered_item(life, item['uid'])
		
		if _known_item['score']:
			if lfe.can_wear_item(life, item['uid']):
				if _known_item['score'] > _item_to_wear['score']:
					_item_to_wear['score'] = _known_item['score']
					_item_to_wear['item_uid'] = item['uid']
			else:
				if rawparse.raw_has_section(life, 'items') and rawparse.raw_section_has_identifier(life, 'items', item['type']):
					_action = lfe.execute_raw(life, 'items', item['type'])
					
					if item['type'] == 'gun' and lfe.get_all_equipped_items(life, matches=[{'type': 'gun'}]):
						continue
					
					if _action == 'equip':
						if _known_item['score'] > _item_to_equip['score']:
							_item_to_equip['score'] = _known_item['score']
							_item_to_equip['item_uid'] = item['uid']
	
	_item = None
	if _item_to_wear['score'] > _item_to_equip['score']:
		_item = _item_to_wear['item_uid']
	elif _item_to_equip['item_uid']:
		_item = _item_to_equip['item_uid']
	
	if _item:
		_equip_action = {'action': 'equipitem', 'item': _item}
		
		if len(lfe.find_action(life, matches=[_equip_action])):
			return False
		
		lfe.add_action(life,
			_equip_action,
			401,
			delay=lfe.get_item_access_time(life, _item))
		
		return False
	
	return True
Beispiel #5
0
def manage_strategy(life, group_id):
	_last_strat = get_flag(life, group_id, 'strategy')
	
	if _last_strat and _last_strat['ready'] and WORLD_INFO['ticks']-_last_strat['updated']<100:
		return False
	
	if _last_strat:
		_strat = _last_strat
	else:
		_strat = {'ready': False, 'gear_track': {}}
		
	flag(life, group_id, 'strategy', _strat)
	
	_gear_track = _strat['gear_track']
	_group = get_group(life, group_id)
	_members_combat_ready = 0
	
	#Get inventory...
	for member_id in _group['members']:
		#TODO: Handle this
		if member_id == life['id']:
			continue
		
		if not member_id in _gear_track:
			_gear_track[member_id] = {'has_weapon': len(lfe.get_all_equipped_items(LIFE[member_id], matches=[{'type': 'gun'}]))>0,
			                          'has_ammo': False,
			                          'asked': [],
			                          'mia': False}
		
		_track = _gear_track[member_id]

		if brain.knows_alife_by_id(life, member_id)['last_seen_time'] <= 100:
			if 'mia_check' in _track['asked']:
				_track['asked'].remove('mia_check')
			
			_track['mia'] = False
		else:
			_track['mia'] = True
		
		if _track['mia']:
			if not 'mia_check' in _track['asked']:
				_track['asked'].append('mia_check')
				_size = get_group_size(life, group_id)
				
				memory.create_question(life, member_id, 'order_status_report_%s' % _size)
		elif _track['has_weapon']:
			if _track['has_ammo']:
				_members_combat_ready.append(member_id)
		elif not 'order_equip_weapon' in _track['asked']:
			_track['asked'].append('order_equip_weapon')
			
			memory.create_question(life, member_id, 'order_equip_weapon')
Beispiel #6
0
def manage_inventory(life):
    if manage_hands(life):
        return False

    for weapon_uid in combat.get_equipped_weapons(life):
        if not combat.weapon_is_working(life, weapon_uid):
            if combat.weapon_is_in_preferred_working_condition(
                    life, weapon_uid):
                if not len(
                        lfe.find_action(life,
                                        matches=[{
                                            'action': 'refillammo'
                                        }])):
                    combat.reload_weapon(life, weapon_uid)

                    return True

    _item_to_wear = {'score': 0, 'item_uid': None}
    _item_to_equip = {'score': 0, 'item_uid': None}

    for item in [
            lfe.get_inventory_item(life, item)
            for item in lfe.get_all_unequipped_items(life)
    ]:
        judgement.judge_item(life, item['uid'])
        _known_item = brain.get_remembered_item(life, item['uid'])

        if _known_item['score']:
            if lfe.can_wear_item(life, item['uid']):
                if _known_item['score'] > _item_to_wear['score']:
                    _item_to_wear['score'] = _known_item['score']
                    _item_to_wear['item_uid'] = item['uid']
            else:
                if rawparse.raw_has_section(
                        life, 'items') and rawparse.raw_section_has_identifier(
                            life, 'items', item['type']):
                    _action = lfe.execute_raw(life, 'items', item['type'])

                    if item['type'] == 'gun' and lfe.get_all_equipped_items(
                            life, matches=[{
                                'type': 'gun'
                            }]):
                        continue

                    if _action == 'equip':
                        if _known_item['score'] > _item_to_equip['score']:
                            _item_to_equip['score'] = _known_item['score']
                            _item_to_equip['item_uid'] = item['uid']

    _item = None
    if _item_to_wear['score'] > _item_to_equip['score']:
        _item = _item_to_wear['item_uid']
    elif _item_to_equip['item_uid']:
        _item = _item_to_equip['item_uid']

    if _item:
        _equip_action = {'action': 'equipitem', 'item': _item}

        if len(lfe.find_action(life, matches=[_equip_action])):
            return False

        lfe.add_action(life,
                       _equip_action,
                       401,
                       delay=lfe.get_item_access_time(life, _item))

        return False

    return True
Beispiel #7
0
def manage_strategy(life, group_id):
    _last_strat = get_flag(life, group_id, 'strategy')

    if _last_strat and _last_strat[
            'ready'] and WORLD_INFO['ticks'] - _last_strat['updated'] < 100:
        return False

    if _last_strat:
        _strat = _last_strat
    else:
        _strat = {'ready': False, 'gear_track': {}}

    flag(life, group_id, 'strategy', _strat)

    _gear_track = _strat['gear_track']
    _group = get_group(life, group_id)
    _members_combat_ready = 0

    #Get inventory...
    for member_id in _group['members']:
        #TODO: Handle this
        if member_id == life['id']:
            continue

        if not member_id in _gear_track:
            _gear_track[member_id] = {
                'has_weapon':
                len(
                    lfe.get_all_equipped_items(LIFE[member_id],
                                               matches=[{
                                                   'type': 'gun'
                                               }])) > 0,
                'has_ammo':
                False,
                'asked': [],
                'mia':
                False
            }

        _track = _gear_track[member_id]

        if brain.knows_alife_by_id(life, member_id)['last_seen_time'] <= 100:
            if 'mia_check' in _track['asked']:
                _track['asked'].remove('mia_check')

            _track['mia'] = False
        else:
            _track['mia'] = True

        if _track['mia']:
            if not 'mia_check' in _track['asked']:
                _track['asked'].append('mia_check')
                _size = get_group_size(life, group_id)

                memory.create_question(life, member_id,
                                       'order_status_report_%s' % _size)
        elif _track['has_weapon']:
            if _track['has_ammo']:
                _members_combat_ready.append(member_id)
        elif not 'order_equip_weapon' in _track['asked']:
            _track['asked'].append('order_equip_weapon')

            memory.create_question(life, member_id, 'order_equip_weapon')