Пример #1
0
def get_cover_position(squad, member_id):
    _member = entities.get_entity(member_id)
    _best_coverage = {'position': None, 'score': 0}
    _inside = zones.get_active_inside_positions()

    if _member['movement']['path']['destination']:
        _hide_pos = _member['movement']['path']['destination']

    else:
        _hide_pos = movement.get_position(_member)

    if _hide_pos in squad['position_map_scores']:
        _scores = squad['position_map_scores'][_hide_pos]
        _score = _scores['coverage'] + _scores['member_coverage']

        if not _scores['targets'] and _score > 0:
            return _hide_pos

    for pos in squad['position_map_scores']:
        _scores = squad['position_map_scores'][pos]
        #TODO: Add or subtract here? Subtraction will make some NPCs run away from teammates
        _score = _scores['coverage'] + _scores['member_coverage']

        if not pos in _inside:
            continue

        if _scores['targets'] or _score <= 0:
            continue

        if _score > _best_coverage['score']:
            _best_coverage['score'] = _score
            _best_coverage['position'] = pos[:]

    if not _best_coverage['position']:
        #print 'no good coverage position'
        return

    _x, _y = movement.get_position(_member)

    for coverage_pos in shapes.circle(_best_coverage['position'][0],
                                      _best_coverage['position'][1], 6):
        if not coverage_pos in squad['position_map_scores']:
            continue

        _c_dist = 10 * (1 - (numbers.distance(coverage_pos, (_x, _y)) / 3.0))

        squad['position_map_scores'][coverage_pos][
            'member_coverage'] += _c_dist

    squad['position_map_scores'][
        _best_coverage['position']]['member_coverage'] += 15

    return _best_coverage['position']
Пример #2
0
def get_cover_position(squad, member_id):
	_member = entities.get_entity(member_id)
	_best_coverage = {'position': None, 'score': 0}
	_inside = zones.get_active_inside_positions()
	
	if _member['movement']['path']['destination']:
		_hide_pos = _member['movement']['path']['destination']
	
	else:
		_hide_pos = movement.get_position(_member)
	
	if _hide_pos in squad['position_map_scores']:
		_scores = squad['position_map_scores'][_hide_pos]
		_score = _scores['coverage'] + _scores['member_coverage']
		
		if not _scores['targets'] and _score > 0:
			return _hide_pos
	
	for pos in squad['position_map_scores']:
		_scores = squad['position_map_scores'][pos]
		#TODO: Add or subtract here? Subtraction will make some NPCs run away from teammates
		_score = _scores['coverage'] + _scores['member_coverage']
		
		if not pos in _inside:
			continue
		
		if _scores['targets'] or _score <= 0:
			continue

		if _score > _best_coverage['score']:
			_best_coverage['score'] = _score
			_best_coverage['position'] = pos[:]
	
	if not _best_coverage['position']:
		#print 'no good coverage position'
		return
	
	_x, _y = movement.get_position(_member)
	
	for coverage_pos in shapes.circle(_best_coverage['position'][0], _best_coverage['position'][1], 6):
		if not coverage_pos in squad['position_map_scores']:
			continue
		
		_c_dist = 10 * (1 - (numbers.distance(coverage_pos, (_x, _y)) / 3.0))
		
		squad['position_map_scores'][coverage_pos]['member_coverage'] += _c_dist
	
	squad['position_map_scores'][_best_coverage['position']]['member_coverage'] += 15
	
	return _best_coverage['position']
Пример #3
0
def search_for_target(entity):
	_lost_targets = entity['ai']['targets_to_search']
	_inside = zones.get_active_inside_positions()
	
	if not _lost_targets:
		print 'Trying to search with no lost targets'
		
		return
	
	_closest_target = {'distance': 0, 'target_id': None}
	
	for target_id in _lost_targets:
		_memory = entity['ai']['life_memory'][target_id]
		_distance = numbers.distance(movement.get_position(entity), _memory['last_seen_at'])
		
		if not _closest_target['target_id'] or _distance < _closest_target['distance']:
			_closest_target['target_id'] = target_id
			_closest_target['distance'] = _distance
	
	_target = entities.get_entity(_closest_target['target_id'])
	_solids = zones.get_active_solids(entity)
	
	if flags.has_flag(entity, 'search_nodes'):
		_search_for_target(entity, _target['_id'])
		
		return
	
	_x, _y = movement.get_position(entity)
	_tx, _ty = entity['ai']['life_memory'][_target['_id']]['last_seen_at']
	_nodes_to_search = {}
	
	if entity['ai']['life_memory'][_target['_id']]['last_seen_velocity']:
		_vx, _vy = entity['ai']['life_memory'][_target['_id']]['last_seen_velocity']
		_tx + _vx*6
		_ty + _vy*6
	
	entities.trigger_event(entity, 'set_flag', flag='search_nodes', value=_nodes_to_search)
	
	for node_x, node_y in zones.get_active_node_grid():
		_distance = numbers.distance((_tx, _ty), (node_x, node_y))
		
		if _distance >= 30:
			continue
		
		if not (node_x, node_y) in _inside:
			continue
		
		_continue = False
		
		for pos in shapes.line((_tx, _ty), (node_x, node_y)):
			if pos in _solids:
				_continue = True
				
				break
		
		if _continue:
			continue
		
		if _distance in _nodes_to_search:
			if not (node_x, node_y) in _nodes_to_search[_distance]:
				_nodes_to_search[_distance].append((node_x, node_y))
		else:
			_nodes_to_search[_distance] = [(node_x, node_y)]
Пример #4
0
def search_for_target(entity):
    _lost_targets = entity['ai']['targets_to_search']
    _inside = zones.get_active_inside_positions()

    if not _lost_targets:
        print 'Trying to search with no lost targets'

        return

    _closest_target = {'distance': 0, 'target_id': None}

    for target_id in _lost_targets:
        _memory = entity['ai']['life_memory'][target_id]
        _distance = numbers.distance(movement.get_position(entity),
                                     _memory['last_seen_at'])

        if not _closest_target[
                'target_id'] or _distance < _closest_target['distance']:
            _closest_target['target_id'] = target_id
            _closest_target['distance'] = _distance

    _target = entities.get_entity(_closest_target['target_id'])
    _solids = zones.get_active_solids(entity)

    if flags.has_flag(entity, 'search_nodes'):
        _search_for_target(entity, _target['_id'])

        return

    _x, _y = movement.get_position(entity)
    _tx, _ty = entity['ai']['life_memory'][_target['_id']]['last_seen_at']
    _nodes_to_search = {}

    if entity['ai']['life_memory'][_target['_id']]['last_seen_velocity']:
        _vx, _vy = entity['ai']['life_memory'][
            _target['_id']]['last_seen_velocity']
        _tx + _vx * 6
        _ty + _vy * 6

    entities.trigger_event(entity,
                           'set_flag',
                           flag='search_nodes',
                           value=_nodes_to_search)

    for node_x, node_y in zones.get_active_node_grid():
        _distance = numbers.distance((_tx, _ty), (node_x, node_y))

        if _distance >= 30:
            continue

        if not (node_x, node_y) in _inside:
            continue

        _continue = False

        for pos in shapes.line((_tx, _ty), (node_x, node_y)):
            if pos in _solids:
                _continue = True

                break

        if _continue:
            continue

        if _distance in _nodes_to_search:
            if not (node_x, node_y) in _nodes_to_search[_distance]:
                _nodes_to_search[_distance].append((node_x, node_y))
        else:
            _nodes_to_search[_distance] = [(node_x, node_y)]