コード例 #1
0
ファイル: groups.py プロジェクト: hovatterz/Reactor-3
def manage_territory(life, group_id):
	_shelter = get_shelter(life, group_id)
	
	if not _shelter:
		return False
	
	_shelter_chunk = chunks.get_nearest_chunk_in_list(life['pos'], references.get_reference(_shelter))
	
	for known_group_id in life['known_groups']:
		if group_id == known_group_id:
			continue
		
		_opposing_shelter = get_possible_group_location(life, known_group_id)
		if not _opposing_shelter:
			continue
		
		_distance = chunks.get_distance_to_nearest_chunk_in_list(WORLD_INFO['chunk_map'][_shelter_chunk]['pos'], references.get_reference(_opposing_shelter))
		
		if _distance<=30:
			print '2 CLOSE 2 HANDLE'
	
	for seen_life_id in life['seen']:
		_target = brain.knows_alife_by_id(life, seen_life_id)
		
		if not _target or _target['alignment'] == 'trust' or not _target['last_seen_at'] or _target['dead']:
			continue
		
		if chunks.get_distance_to_nearest_chunk_in_list(_target['last_seen_at'], references.get_reference(_shelter))>30:
			continue
		
		print 'L@@K'* 20
		print life['name'], LIFE[seen_life_id]['name'], _target['alignment']
		
		memory.create_question(life, seen_life_id, 'territory_violation', ignore_if_said_in_last=-1)
コード例 #2
0
ファイル: groups.py プロジェクト: flags/Reactor-3
def find_and_announce_shelter(life, group_id):
	if get_stage(life, group_id) >= STAGE_RAIDING:
		return False
	
	_shelter = get_shelter(life, group_id)
	
	if get_motive(life, group_id) == 'crime' and logic.is_night():
		if _shelter:
			set_shelter(life, group_id, None)
			announce(life, group_id, 'update_group_shelter',
				    filter_if=lambda alife_id: not get_shelter(LIFE[alife_id], group_id))
			
		#print 'MOTIVATED BY CRIME' * 20
		
		return False
	
	if _shelter:
		if get_stage(life, group_id) < STAGE_SETTLED:
			set_stage(life, group_id, STAGE_SETTLED)
		
		if references.is_in_reference(life['pos'], references.get_reference(_shelter)):
			announce(life, group_id, 'update_group_shelter',
				    filter_if=lambda alife_id: get_shelter(LIFE[alife_id], group_id)==_shelter)
	else:
		find_shelter(life, group_id)
コード例 #3
0
def find_and_announce_shelter(life, group_id):
    if get_stage(life, group_id) >= STAGE_RAIDING:
        return False

    _shelter = get_shelter(life, group_id)

    if get_motive(life, group_id) == 'crime' and logic.is_night():
        if _shelter:
            set_shelter(life, group_id, None)
            announce(life,
                     group_id,
                     'update_group_shelter',
                     filter_if=lambda alife_id: not get_shelter(
                         LIFE[alife_id], group_id))

        #print 'MOTIVATED BY CRIME' * 20

        return False

    if _shelter:
        if get_stage(life, group_id) < STAGE_SETTLED:
            set_stage(life, group_id, STAGE_SETTLED)

        if references.is_in_reference(life['pos'],
                                      references.get_reference(_shelter)):
            announce(life,
                     group_id,
                     'update_group_shelter',
                     filter_if=lambda alife_id: get_shelter(
                         LIFE[alife_id], group_id) == _shelter)
    else:
        find_shelter(life, group_id)
コード例 #4
0
ファイル: groups.py プロジェクト: flags/Reactor-3
def fight_or_flight(life, group_id, target_group_id):
	_distance = chunks.get_distance_to_nearest_chunk_in_list(life['pos'], references.get_reference(get_shelter(life, target_group_id)))
	
	if is_combat_ready(life, group_id):
		stats.declare_group_hostile(life, target_group_id)
	elif _distance<=100:
		stats.declare_group_scared(life, target_group_id)
	else:
		prepare_for_raid(life, group_id)
コード例 #5
0
def fight_or_flight(life, group_id, target_group_id):
    _distance = chunks.get_distance_to_nearest_chunk_in_list(
        life['pos'],
        references.get_reference(get_shelter(life, target_group_id)))

    if is_combat_ready(life, group_id):
        stats.declare_group_hostile(life, target_group_id)
    elif _distance <= 100:
        stats.declare_group_scared(life, target_group_id)
    else:
        prepare_for_raid(life, group_id)
コード例 #6
0
ファイル: judgement.py プロジェクト: hovatterz/Reactor-3
def judge_reference(life, reference_id, known_penalty=False):
    # TODO: Length
    _score = 0
    _count = 0
    _closest_chunk_key = {"key": None, "distance": -1}

    for key in references.get_reference(reference_id):
        if known_penalty and key in life["known_chunks"]:
            continue

        _count += 1
        _chunk = maps.get_chunk(key)
        _chunk_center = (
            _chunk["pos"][0] + (WORLD_INFO["chunk_size"] / 2),
            _chunk["pos"][1] + (WORLD_INFO["chunk_size"] / 2),
        )
        _distance = numbers.distance(life["pos"], _chunk_center)

        if not _closest_chunk_key["key"] or _distance < _closest_chunk_key["distance"]:
            _closest_chunk_key["key"] = key
            _closest_chunk_key["distance"] = _distance

            # Judge: ALife
        for ai in _chunk["life"]:
            if ai == life["id"]:
                continue

            if not sight.can_see_target(life, ai):
                continue

            _knows = brain.knows_alife(life, LIFE[ai])
            if not _knows:
                continue

                # How long since we've been here?
                # if key in life['known_chunks']:
                # 	_last_visit = numbers.clip(abs((life['known_chunks'][key]['last_visited']-WORLD_INFO['ticks'])/FPS), 2, 99999)
                # 	_score += _last_visit
                # else:
                # 	_score += WORLD_INFO['ticks']/FPS

                # Take length into account
    _score += _count

    # Subtract distance in chunks
    _score -= _closest_chunk_key["distance"] / WORLD_INFO["chunk_size"]

    # TODO: Average time since last visit (check every key in reference)
    # TODO: For tracking last visit use world ticks

    return _score
コード例 #7
0
def judge_reference(life, reference_id, known_penalty=False):
	#TODO: Length
	_score = 0
	_count = 0
	_closest_chunk_key = {'key': None, 'distance': -1}
	
	for key in references.get_reference(reference_id):
		if known_penalty and key in life['known_chunks']:
			continue
		
		_count += 1
		_chunk = maps.get_chunk(key)
		_chunk_center = (_chunk['pos'][0]+(WORLD_INFO['chunk_size']/2),
			_chunk['pos'][1]+(WORLD_INFO['chunk_size']/2))
		_distance = bad_numbers.distance(life['pos'], _chunk_center)
		
		if not _closest_chunk_key['key'] or _distance<_closest_chunk_key['distance']:
			_closest_chunk_key['key'] = key
			_closest_chunk_key['distance'] = _distance
		
		#Judge: ALife
		for ai in _chunk['life']:
			if ai == life['id']:
				continue
			
			if not sight.can_see_target(life, ai):
				continue
			
			_knows = brain.knows_alife(life, LIFE[ai])
			if not _knows:
				continue
		
		#How long since we've been here?
		#if key in life['known_chunks']:
		#	_last_visit = bad_numbers.clip(abs((life['known_chunks'][key]['last_visited']-WORLD_INFO['ticks'])/FPS), 2, 99999)
		#	_score += _last_visit
		#else:
		#	_score += WORLD_INFO['ticks']/FPS
		
	#Take length into account
	_score += _count
	
	#Subtract distance in chunks
	_score -= _closest_chunk_key['distance']/WORLD_INFO['chunk_size']
	
	#TODO: Average time since last visit (check every key in reference)
	#TODO: For tracking last visit use world ticks
	
	return _score
コード例 #8
0
ファイル: groups.py プロジェクト: hovatterz/Reactor-3
def manage_combat(life, group_id):
	if get_stage(life, group_id) == STAGE_RAIDING:
		prepare_for_raid(life, group_id)
		return False
	
	for known_group_id in life['known_groups']:
		if group_id == known_group_id:
			continue
		
		if get_group_memory(life, known_group_id, 'alignment') == 'neutral':
			_known_group_members = get_group_memory(life, known_group_id, 'members')
			
			announce(life, group_id, 'inform_of_known_group', group_id=known_group_id,
			         filter_if=lambda alife: group_exists(alife, known_group_id))
			
			if _known_group_members:
				update_group_memory(life, known_group_id, 'shelter', get_possible_group_location(life, known_group_id))
				
				_people_to_ask_about = []
				for member in _known_group_members:
					_target = brain.knows_alife_by_id(life, member)
					
					if not _target['last_seen_at'] or not _target['state'] in ['idle', 'shelter']:
						continue
					
					_people_to_ask_about.append(member)
				
				if get_group_memory(life, known_group_id, 'shelter'):
					fight_or_flight(life, group_id, known_group_id)
				elif _people_to_ask_about:
					announce(life, group_id, 'last_seen_target', target_id=random.choice(_people_to_ask_about))
				else:
					print 'Nobody to ask about group location'
					print 'LOST' * 100
		
		elif get_group_memory(life, known_group_id, 'alignment') == 'scared':
			_known_group_shelter = get_group(life, known_group_id)['shelter']
			
			if not _known_group_shelter:
				print 'FREE-FLOATING ANXIETY'
				continue
			
			_distance = chunks.get_distance_to_nearest_chunk_in_list(life['pos'], references.get_reference(_known_group_shelter))
			
			if get_stage(life, group_id) >= STAGE_SETTLED:
				if _distance<=100:
					set_stage(life, group_id, STAGE_SETTLING)
					set_shelter(life, group_id, None)
コード例 #9
0
def manage_jobs(life, group_id):
    _shelter = get_shelter(life, group_id)

    if not _shelter:
        return False

    if not get_stage(life, group_id) == STAGE_SETTLED:
        return False

    if get_flag(life, life['group'], 'guard_chunk_keys'):
        return False

    _guard_chunk_keys = []
    _potential_guard_chunk_keys = []
    _group_members = get_group(life, life['group'])['members']
    _shelter_chunks = references.get_reference(_shelter)[:]

    #TODO: This is horrible... like the worst possible way to do this
    for chunk_key in WORLD_INFO['chunk_map']:
        if chunk_key in _shelter_chunks:
            _shelter_chunks.remove(chunk_key)
            continue

        if bad_numbers.distance(life['pos'],
                                chunks.get_chunk(chunk_key)['pos']) > 50:
            continue

        _potential_guard_chunk_keys.append(chunk_key)

    if not _potential_guard_chunk_keys:
        return False

    for member_id in _group_members:
        if member_id == life['id']:
            continue

        _chunk_key = _potential_guard_chunk_keys.pop(
            random.randint(0,
                           len(_potential_guard_chunk_keys) - 1))
        _guard_chunk_keys.append(_chunk_key)
        lfe.memory(LIFE[member_id], 'focus_on_chunk', chunk_key=_chunk_key)

        if not _potential_guard_chunk_keys:
            break

    flag(life, life['group'], 'guard_chunk_keys', _guard_chunk_keys)
コード例 #10
0
ファイル: groups.py プロジェクト: flags/Reactor-3
def manage_jobs(life, group_id):
	_shelter = get_shelter(life, group_id)
	
	if not _shelter:
		return False
	
	if not get_stage(life, group_id) == STAGE_SETTLED:
		return False
	
	if get_flag(life, life['group'], 'guard_chunk_keys'):
		return False
	
	_guard_chunk_keys = []
	_potential_guard_chunk_keys = []
	_group_members = get_group(life, life['group'])['members']
	_shelter_chunks = references.get_reference(_shelter)[:]
	
	#TODO: This is horrible... like the worst possible way to do this
	for chunk_key in WORLD_INFO['chunk_map']:
		if chunk_key in _shelter_chunks:
			_shelter_chunks.remove(chunk_key)
			continue
		
		if bad_numbers.distance(life['pos'], chunks.get_chunk(chunk_key)['pos'])>50:
			continue
		
		_potential_guard_chunk_keys.append(chunk_key)
	
	if not _potential_guard_chunk_keys:
		return False
	
	for member_id in _group_members:
		if member_id == life['id']:
			continue
		
		_chunk_key = _potential_guard_chunk_keys.pop(random.randint(0, len(_potential_guard_chunk_keys)-1))
		_guard_chunk_keys.append(_chunk_key)
		lfe.memory(LIFE[member_id], 'focus_on_chunk', chunk_key=_chunk_key)
		
		if not _potential_guard_chunk_keys:
			break
	
	flag(life, life['group'], 'guard_chunk_keys', _guard_chunk_keys)