예제 #1
0
def group_judge_group(life, group_id, target_group_id):
	_group1 = groups.get_group(life, group_id)
	_group2 = groups.get_group(life, target_group_id)
	
	_group1_combat = groups.get_combat_score(life, group_id)
	_group2_combat = groups.get_combat_score(life, target_group_id)
	
	if _group1_combat > _group2_combat:
		pass
예제 #2
0
def group_judge_group(life, group_id, target_group_id):
    _group1 = groups.get_group(life, group_id)
    _group2 = groups.get_group(life, target_group_id)

    _group1_combat = groups.get_combat_score(life, group_id)
    _group2_combat = groups.get_combat_score(life, target_group_id)

    if _group1_combat > _group2_combat:
        pass
예제 #3
0
def announce(life, gist, public=False, trusted=False, group=None, filter_if=None, **kwargs):
	"""Sends `gist` to any known ALife. If `public`, then send to everyone."""
	if public:
		_announce_to = [LIFE[i] for i in LIFE if not i == life['id']]
	elif trusted:
		_announce_to = [life['know'][i]['life'] for i in life['know'] if life['know'][i]['alignment'] == 'trust']
	elif group:
		_announce_to = [LIFE[i] for i in groups.get_group(life, group)['members'] if not i == life['id']]
	else:
		_announce_to = [life['know'][i]['life'] for i in life['know'] if not judgement.is_target_dangerous(life, i)]
	
	for target in _announce_to:
		if not stats.can_talk_to(life, target['id']):
			continue
		
		if filter_if and filter_if(life):
			return False
		
		_radio = False
		if not sight.can_see_position(life, target['pos']):
			if lfe.get_all_inventory_items(life, matches=[{'name': 'radio'}]):
				_radio = True
			else:
				continue
	
		memory.create_question(life, target['id'], gist, **kwargs)
	
	return True
예제 #4
0
파일: speech.py 프로젝트: penny64/Reactor-3
def inform_of_group(life, life_id):
    memory.create_question(life,
                           life_id,
                           'group_exists',
                           group_id=life['group'],
                           group_list=groups.get_group(
                               life, life['group'])['members'])
예제 #5
0
def is_group_hostile(life, group_id):
    _group = groups.get_group(life, group_id)

    if judge_group(life, group_id) >= 0:
        return False

    return True
예제 #6
0
 def get(self, group_number):
     json_out = {}
     group = groups.get_group(int(group_number))
     if group:
         json_out = group.group_json()
     self.set_header('Content-Type', 'application/json')
     self.write(json_out)
예제 #7
0
def is_group_hostile(life, group_id):
	_group = groups.get_group(life, group_id)
	
	if judge_group(life, group_id)>=0:
		return False
	
	return True
예제 #8
0
def judge_camp(life, camp, for_founding=False):
    # This is kinda complicated so I'll do my best to describe what's happening.
    # The ALife keeps track of chunks it's aware of, which we'll use when
    # calculating how much of a camp we know about (value between 0..1)
    # First we score the camp based on what we DO know, which is pretty cut and dry:
    #
    # We consider:
    # 	How big the camp is vs. how many people we think we're going to need to fit in it (not a factor ATM)
    # 		A big camp won't be attractive to just one ALife, but a faction will love the idea of having a larger base
    # 	Distance from other camps
    # 		Certain ALife will prefer isolation
    #
    # After scoring this camp, we simply multiply by the percentage of the camp
    # that is known. This will encourage ALife to discover a camp first before
    # moving in.

    # In addition to all that, we want to prevent returning camps that are too close
    # to other camps. This is hardcoded (can't think of a reason why the ALife would want this)

    if for_founding:
        for _known_camp in [c["reference"] for c in life["known_camps"].values()]:
            for _pos1 in _known_camp:
                pos1 = [int(i) for i in _pos1.split(",")]
                for _pos2 in camp:
                    pos2 = [int(i) for i in _pos2.split(",")]
                    _dist = numbers.distance(pos1, pos2) / WORLD_INFO["chunk_size"]

                    if _dist <= 15:
                        return 0

    _known_chunks_of_camp = references.get_known_chunks_in_reference(life, camp)

    _current_population = 0
    _current_trust = 0
    for _target in life["know"].values():
        if not references.is_in_reference(_target["last_seen_at"], camp):
            continue

        _current_population += 1

        if can_trust(life, _target["life"]["id"]):
            _current_trust += _target["trust"]
        else:
            _current_trust -= _target["danger"]

    _percent_known = len(_known_chunks_of_camp) / float(len(camp))
    _score = _current_trust
    _camp = camps.get_camp_via_reference(camp)

    if _camp:
        _score += judge_group(life, camps.get_controlling_group(_camp))

    if stats.desires_to_create_camp(life):
        _score += len(groups.get_group(life, life["group"])["members"]) / 2 <= len(_known_chunks_of_camp)

        # TODO: Why does this cause a crash?
        # return int(round(_percent_known*10))
        # print 'camp score:',(len(camp)*_percent_known),_score,(len(camp)*_percent_known)*_score
    return (len(camp) * _percent_known) * _score
예제 #9
0
def judge_camp(life, camp, for_founding=False):
	#This is kinda complicated so I'll do my best to describe what's happening.
	#The ALife keeps track of chunks it's aware of, which we'll use when
	#calculating how much of a camp we know about (value between 0..1)
	#First we score the camp based on what we DO know, which is pretty cut and dry:
	#
	#We consider:
	#	How big the camp is vs. how many people we think we're going to need to fit in it (not a factor ATM)
	#		A big camp won't be attractive to just one ALife, but a faction will love the idea of having a larger base
	#	Distance from other camps
	#		Certain ALife will prefer isolation
	#
	#After scoring this camp, we simply multiply by the percentage of the camp
	#that is known. This will encourage ALife to discover a camp first before
	#moving in.
	
	#In addition to all that, we want to prevent returning camps that are too close
	#to other camps. This is hardcoded (can't think of a reason why the ALife would want this)
	
	if for_founding:
		for _known_camp in [c['reference'] for c in life['known_camps'].values()]:
			for _pos1 in _known_camp:
				pos1 = [int(i) for i in _pos1.split(',')]
				for _pos2 in camp:
					pos2 = [int(i) for i in _pos2.split(',')]
					_dist = bad_numbers.distance(pos1, pos2) / WORLD_INFO['chunk_size']
					
					if _dist <= 15:
						return 0
	
	_known_chunks_of_camp = references.get_known_chunks_in_reference(life, camp)
	
	_current_population = 0
	_current_trust = 0
	for _target in life['know'].values():
		if not references.is_in_reference(_target['last_seen_at'], camp):
			continue
		
		_current_population += 1
		
		if can_trust(life, _target['life']['id']):
			_current_trust += _target['trust']
		else:
			_current_trust -= _target['danger']
	
	_percent_known = len(_known_chunks_of_camp)/float(len(camp))
	_score = _current_trust
	_camp = camps.get_camp_via_reference(camp)
	
	if _camp:
		_score += judge_group(life, camps.get_controlling_group(_camp))
	
	if stats.desires_to_create_camp(life):
		_score += len(groups.get_group(life, life['group'])['members'])/2<=len(_known_chunks_of_camp)
	
	#TODO: Why does this cause a crash?
	#return int(round(_percent_known*10))
	#print 'camp score:',(len(camp)*_percent_known),_score,(len(camp)*_percent_known)*_score
	return (len(camp)*_percent_known)*_score
예제 #10
0
파일: speech.py 프로젝트: penny64/Reactor-3
def inform_of_group_members(life, life_id, group_id):
    if 'player' in life:
        _dialog_id = lfe.has_dialog_with(life, life_id)
        _menu_items = []

        for target_id in life['know']:
            if target_id == life['id'] or target_id == life_id:
                continue

            if groups.is_member(life, group_id, target_id):
                _colors = (tcod.green, tcod.white)
                _values = ['Member', 'Not Member']
            else:
                _colors = (tcod.red, tcod.white)
                _values = ['Not Member', 'Member']

            _menu_items.append(
                menus.create_item('list',
                                  ' '.join(LIFE[target_id]['name']),
                                  _values,
                                  group=group_id,
                                  target_id=target_id,
                                  members=_menu_items,
                                  color=_colors,
                                  dialog_id=_dialog_id))

        if not _menu_items:
            return False

        _menu = menus.create_menu(menu=_menu_items,
                                  title='Inform of Group Members',
                                  format_str='$k: $v',
                                  on_select=confirm_inform_of_group_members,
                                  close_on_select=True)
        menus.activate_menu(_menu)
    else:
        for target_id in groups.get_group(life, group_id)['members']:
            if life['id'] == target_id:
                continue

            memory.create_question(life,
                                   target_id,
                                   'group_list',
                                   group_id=group_id,
                                   group_list=groups.get_group(
                                       life, group_id)['members'])
예제 #11
0
파일: speech.py 프로젝트: penny64/Reactor-3
def announce_combat_to_group(life, group_id):
    _number_of_members = len(groups.get_group(life, group_id)['members'])

    if _number_of_members >= 5:
        groups.announce(life, group_id, 'group_prepare_for_combat_large')
    elif _number_of_members > 2:
        groups.announce(life, group_id, 'group_prepare_for_combat_small')
    else:
        groups.announce(life, group_id, 'group_prepare_for_combat_partner')
예제 #12
0
def update_group_members(life, target_id, group_id, group_list):
	_known_members = groups.get_group(life, group_id)['members'][:]
	_group_list = group_list[:]
	_send = []
	
	for member in _group_list:
		if not member in _known_members:
			_known_members.append(member)
			groups.add_member(life, group_id, member)
	
	for member in _known_members:
		if not member in group_list:
			_send.append(member)
	
	if _send:
		memory.create_question(life, target_id, 'group_list',
		                       group_id=life['group'],
		                       group_list=groups.get_group(life, life['group'])['members'])
예제 #13
0
def debug_camps():
    for camp_id in WORLD_INFO['camps']:
        _group = get_controlling_group_global(camp_id)
        if not _group:
            continue

        print camp_id, 'is controlled by', _group
        _actual_group = groups.get_group(life, _group)
        print '\t%s member(s)' % len(_actual_group['members'])
예제 #14
0
파일: camps.py 프로젝트: flags/Reactor-3
def debug_camps():
	for camp_id in WORLD_INFO['camps']:
		_group = get_controlling_group_global(camp_id)
		if not _group:
			continue
		
		print camp_id, 'is controlled by', _group
		_actual_group = groups.get_group(life, _group)
		print '\t%s member(s)' % len(_actual_group['members'])
예제 #15
0
파일: stats.py 프로젝트: athros/Reactor-3
def desires_to_create_camp(life):
	if not 'CAN_GROUP' in life['life_flags']:
		return False
		
	if life['group'] and not groups.get_camp(life['group']) and groups.is_leader(life, life['group'], life['id']):
		if len(groups.get_group(life, life['group'])['members'])>1:
			return True
	
	return False
예제 #16
0
파일: speech.py 프로젝트: athros/Reactor-3
def announce_combat_to_group(life, group_id):
	_number_of_members = len(groups.get_group(life, group_id)['members'])
	
	if _number_of_members>=5:
		groups.announce(life, group_id, 'group_prepare_for_combat_large')
	elif _number_of_members>2:
		groups.announce(life, group_id, 'group_prepare_for_combat_small')
	else:
		groups.announce(life, group_id, 'group_prepare_for_combat_partner')
예제 #17
0
def inform_of_group_members(life, life_id, group_id):
	if 'player' in life:
		_dialog_id = lfe.has_dialog_with(life, life_id)
		_menu_items = []
		
		for target_id in life['know']:
			if target_id == life['id'] or target_id == life_id:
				continue
			
			if groups.is_member(life, group_id, target_id):
				_colors = (tcod.green, tcod.white)
				_values = ['Member', 'Not Member']
			else:
				_colors = (tcod.red, tcod.white)
				_values = ['Not Member', 'Member']
			
			_menu_items.append(menus.create_item('list',
			                                     ' '.join(LIFE[target_id]['name']),
			                                     _values,
			                                     group=group_id,
			                                     target_id=target_id,
			                                     members=_menu_items,
			                                     color=_colors,
			                                     dialog_id=_dialog_id))
		
		if not _menu_items:
			return False
		
		_menu = menus.create_menu(menu=_menu_items,
		                          title='Inform of Group Members',
		                          format_str='$k: $v',
		                          on_select=confirm_inform_of_group_members,
		                          close_on_select=True)
		menus.activate_menu(_menu)
	else:
		for target_id in groups.get_group(life, group_id)['members']:
			if life['id'] == target_id:
				continue
			
			memory.create_question(life, target_id, 'group_list',
				                   group_id=group_id,
				                   group_list=groups.get_group(life, group_id)['members'])
예제 #18
0
파일: stats.py 프로젝트: penny64/Reactor-3
def desires_to_create_camp(life):
    if not 'CAN_GROUP' in life['life_flags']:
        return False

    if life['group'] and not groups.get_camp(
            life['group']) and groups.is_leader(life, life['group'],
                                                life['id']):
        if len(groups.get_group(life, life['group'])['members']) > 1:
            return True

    return False
예제 #19
0
파일: speech.py 프로젝트: penny64/Reactor-3
def update_group_members(life, target_id, group_id, group_list):
    _known_members = groups.get_group(life, group_id)['members'][:]
    _group_list = group_list[:]
    _send = []

    for member in _group_list:
        if not member in _known_members:
            _known_members.append(member)
            groups.add_member(life, group_id, member)

    for member in _known_members:
        if not member in group_list:
            _send.append(member)

    if _send:
        memory.create_question(life,
                               target_id,
                               'group_list',
                               group_id=life['group'],
                               group_list=groups.get_group(
                                   life, life['group'])['members'])
예제 #20
0
def judge_group(life, group_id):
	_score = 0
	for member in groups.get_group(life, group_id)['members']:
		if member == life['id']:
			continue
		
		_knows = brain.knows_alife_by_id(life, member)
		if not _knows:
			continue
		
		if is_target_dangerous(life, member):
			_score += get_trust(life, member)
		else:
			_score += get_trust(life, member)
	
	return _score
예제 #21
0
파일: stats.py 프로젝트: penny64/Reactor-3
def wants_to_abandon_group(life, group_id):
    _trusted = 0
    _hostile = 0

    for member in groups.get_group(life, group_id)['members']:
        if life['id'] == member:
            continue

        _knows = brain.knows_alife_by_id(life, member)

        if _knows['alignment'] == 'hostile':
            _hostile += 1
        else:
            _trusted += 1

    return _hostile > _trusted
예제 #22
0
def judge_group(life, group_id):
    _score = 0
    for member in groups.get_group(life, group_id)["members"]:
        if member == life["id"]:
            continue

        _knows = brain.knows_alife_by_id(life, member)
        if not _knows:
            continue

        if is_target_dangerous(life, member):
            _score += get_trust(life, member)
        else:
            _score += get_trust(life, member)

    return _score
예제 #23
0
파일: stats.py 프로젝트: athros/Reactor-3
def wants_to_abandon_group(life, group_id):
	_trusted = 0
	_hostile = 0
	
	for member in groups.get_group(life, group_id)['members']:
		if life['id'] == member:
			continue
		
		_knows = brain.knows_alife_by_id(life, member)
		
		if _knows['alignment'] == 'hostile':
			_hostile += 1
		else:
			_trusted += 1
	
	return _hostile>_trusted
예제 #24
0
파일: speech.py 프로젝트: penny64/Reactor-3
def announce(life,
             gist,
             public=False,
             trusted=False,
             group=None,
             filter_if=None,
             **kwargs):
    """Sends `gist` to any known ALife. If `public`, then send to everyone."""
    if public:
        _announce_to = [LIFE[i] for i in LIFE if not i == life['id']]
    elif trusted:
        _announce_to = [
            life['know'][i]['life'] for i in life['know']
            if life['know'][i]['alignment'] == 'trust'
        ]
    elif group:
        _announce_to = [
            LIFE[i] for i in groups.get_group(life, group)['members']
            if not i == life['id']
        ]
    else:
        _announce_to = [
            life['know'][i]['life'] for i in life['know']
            if not judgement.is_target_dangerous(life, i)
        ]

    for target in _announce_to:
        if not stats.can_talk_to(life, target['id']):
            continue

        if filter_if and filter_if(target['id']):
            continue

        _radio = False
        if not sight.can_see_position(life, target['pos']):
            if lfe.get_all_inventory_items(life, matches=[{'name': 'radio'}]):
                _radio = True
            else:
                continue

        memory.create_question(life, target['id'], gist, **kwargs)

    return True
예제 #25
0
def setup(life):
	if not life['group']:
		#if not stats.desires_to_create_group(life):
		#	return False
		
		#groups.create_group(life)
		return False
	
	if not groups.is_leader_of_any_group(life):
		return False
	
	_group = groups.get_group(life, life['group'])
	
	groups.find_and_announce_shelter(life, life['group'])
	groups.manage_jobs(life, life['group'])
	groups.manage_territory(life, life['group'])
	#groups.manage_resources(life, life['group'])
	#groups.manage_known_groups(life, life['group'])
	#groups.manage_combat(life, life['group'])
예제 #26
0
def setup(life):
    if not life['group']:
        #if not stats.desires_to_create_group(life):
        #	return False

        #groups.create_group(life)
        return False

    if not groups.is_leader_of_any_group(life):
        return False

    _group = groups.get_group(life, life['group'])

    #groups.manage_jobs(life, life['group'])
    #groups.manage_territory(life, life['group'])
    groups.manage_combat(life, life['group'])
    groups.manage_raid(life, life['group'])
    #groups.manage_resources(life, life['group'])
    #groups.manage_known_groups(life, life['group'])
    #groups.manage_combat(life, life['group'])
예제 #27
0
    def post(self, group_number):
        json_out = {}
        group = groups.get_group(int(group_number))
        cmd = self.get_argument("cmd", default=None, strip=False)

        if group:
            if cmd == 'call':
                group.call()
            if cmd == 'drop':
                group.drop()

            if cmd == 'studiolight-disable':
                group.set_studio_light('DISABLED')
            if cmd == 'studiolight-off-air':
                group.set_studio_light('OFF-AIR')
            if cmd == 'studiolight-on-air':
                group.set_studio_light('ON-AIR')

            if cmd == 'switchboard-off-air':
                group.change_switchboard_status('off-air')
            if cmd == 'switchboard-on-air':
                group.change_switchboard_status('on-air')

            if cmd == 'mastercontrol-off-air':
                group.set_studio_light('OFF-AIR')
                group.change_switchboard_status('off-air')

            if cmd == 'mastercontrol-queue':
                group.set_studio_light('DISABLED')
                group.change_switchboard_status('on-air')

            if cmd == 'mastercontrol-on-air':
                group.set_studio_light('ON-AIR')
                group.change_switchboard_status('on-air')


        self.set_header('Content-Type', 'application/json')
        self.write(json_out)
예제 #28
0
def inform_of_group(life, life_id):
	memory.create_question(life, life_id, 'group_exists',
	                       group_id=life['group'],
	                       group_list=groups.get_group(life, life['group'])['members'])
예제 #29
0
def convertFile(pathName, fileName):
    from groups import get_group
    import os, shutil
    os.chdir(str(pathName))

    if os.path.exists('test_clean'):
        shutil.rmtree('test_clean')

    if not os.path.exists('test_clean'):
        os.mkdir('test_clean')

    os.chdir(str(pathName) + '/test_clean')

    if not os.path.exists('constant'):
        os.mkdir('constant')

    if not os.path.exists('0'):
        os.mkdir('0')

    if not os.path.exists('system'):
        os.mkdir('system')

    os.chdir(str(pathName) + '/test_clean/constant/')
    if not os.path.exists('triSurface'):
        os.mkdir('triSurface')

    test_clean = open(str(fileName), "r")

    # Get number of nodes
    line = test_clean.readline()
    while ("NPOIN" not in line):
        line = test_clean.readline()
    nodes = int(line[line.rfind(" "):])
    #print(nodes)

    # Loop to read xyz node coordinates into list
    points = []
    for n in range(nodes):
        coord = test_clean.readline()
        coord = coord[:coord.rfind(" ")]
        #points.append(coord)
        point = [float(x) for x in coord.split(" ")]
        points.append(point)
    #print(points)

    # Find minimum and maximum x coords, y coords, and z coords
    x_coords = []
    y_coords = []
    z_coords = []
    for i in range(len(points)):
        x_coords.append(points[i][0])
        y_coords.append(points[i][1])
        z_coords.append(points[i][2])
    x_min = min(x_coords)
    x_max = max(x_coords)
    y_min = min(y_coords)
    y_max = max(y_coords)
    z_min = min(z_coords)
    z_max = max(z_coords)

    # Center stl by finding its center and shifting it to (0 0 0)
    x_mid = (x_max + x_min) / 2
    y_mid = (y_max + y_min) / 2
    z_mid = (z_max + z_min) / 2

    for i in range(len(x_coords)):
        x_coords[i] -= x_mid
        y_coords[i] -= y_mid
        z_coords[i] -= z_mid

    # Update minimum and maxium coordinates for blockMeshDict vertices
    x_min = min(x_coords)
    x_max = max(x_coords)
    y_min = min(y_coords)
    y_max = max(y_coords)
    z_min = min(z_coords)
    z_max = max(z_coords)

    # Shifting stl
    for i in range(len(points)):
        points[i][0] -= x_mid
        points[i][1] -= y_mid
        points[i][2] -= z_mid

    # Get number of groups
    line = test_clean.readline()
    while ("NMARK" not in line):
        line = test_clean.readline()
    groups = int(line[line.rfind(" "):])
    #print(groups)
    group_names = []
    # print out stl for each group
    for group in range(groups):
        lst_of_group_names = get_group(pathName, test_clean, group_names,
                                       points)
    lst_of_group_names_ext = lst_of_group_names.copy()
    return (x_min, x_max, y_min, y_max, z_min, z_max, lst_of_group_names,
            lst_of_group_names_ext)
예제 #30
0
파일: stats.py 프로젝트: penny64/Reactor-3
def get_minimum_camp_score(life):
    if life['group'] and groups.is_leader(life, life['group'], life['id']):
        return len(groups.get_group(life, life['group'])['members'])

    return 3
예제 #31
0
파일: stats.py 프로젝트: athros/Reactor-3
def get_minimum_camp_score(life):
	if life['group'] and groups.is_leader(life, life['group'], life['id']):
		return len(groups.get_group(life, life['group'])['members'])
	
	return 3