コード例 #1
0
ファイル: movement.py プロジェクト: hovatterz/Reactor-3
def position_to_attack(life, target):
	if lfe.find_action(life, [{'action': 'dijkstra_move', 'reason': 'positioning for attack'}]):
		if not lfe.ticker(life, 'attack_position', 4):
			return False
	
	_target_positions, _zones = combat.get_target_positions_and_zones(life, [target])
	_nearest_target_score = zones.dijkstra_map(life['pos'], _target_positions, _zones, return_score=True)
	
	#TODO: Short or long-range weapon?
	#if _nearest_target_score >= sight.get_vision(life)/2:
	if not sight.can_see_position(life, brain.knows_alife_by_id(life, target)['last_seen_at'], block_check=True, strict=True) or sight.view_blocked_by_life(life, _target_positions[0], allow=[target]):
		print life['name'], 'changing position for combat...', life['name'], LIFE[target]['name']
		
		_avoid_positions = []
		for life_id in life['seen']:
			if life_id == target or life['id'] == life_id:
				continue
			
			if alife.judgement.can_trust(life, life_id):
				_avoid_positions.append(lfe.path_dest(LIFE[life_id]))
			else:
				_avoid_positions.append(brain.knows_alife_by_id(life, life_id)['last_seen_at'])
		
		_cover = _target_positions
		
		_zones = []
		for pos in _cover:
			_zone = zones.get_zone_at_coords(pos)
			
			if not _zone in _zones:
				_zones.append(_zone)
		
		if not lfe.find_action(life, [{'action': 'dijkstra_move', 'orig_goals': _cover[:], 'avoid_positions': _avoid_positions}]):
			lfe.stop(life)
			lfe.add_action(life, {'action': 'dijkstra_move',
				                  'rolldown': True,
				                  'goals': _cover[:],
			                      'orig_goals': _cover[:],
			                      'avoid_positions': _avoid_positions,
			                      'reason': 'positioning for attack'},
				           999)
			
			return False
		else:
			return False
	elif life['path']:
		lfe.stop(life)
	
	return True
コード例 #2
0
ファイル: movement.py プロジェクト: athros/Reactor-3
def position_to_attack(life, target, engage_distance):
    if lfe.find_action(life, [{"action": "dijkstra_move", "reason": "positioning for attack"}]):
        if not lfe.ticker(life, "attack_position", 4):
            return False

    _target_positions, _zones = combat.get_target_positions_and_zones(life, [target])
    _can_see = alife.sight.can_see_position(life, _target_positions[0], get_path=True)
    _distance = numbers.distance(life["pos"], _target_positions[0])

    if _can_see and len(_can_see) < engage_distance * 0.85:
        if life["path"]:
            lfe.stop(life)
    elif _distance < engage_distance * 0.9:
        _avoid_positions = set()
        _target_area = set()

        for life_id in alife.judgement.get_trusted(life, visible=False, only_recent=True):
            fov.fov(
                LIFE[life_id]["pos"],
                int(round(sight.get_vision(life) * 0.25)),
                callback=lambda pos: _avoid_positions.add(pos),
            )

        fov.fov(
            _target_positions[0], int(round(sight.get_vision(life) * 0.15)), callback=lambda pos: _target_area.add(pos)
        )

        _min_view_distance = int(round(sight.get_vision(life) * 0.25))
        _max_view_distance = int(round(sight.get_vision(life) * 0.5))
        _attack_positions = set(
            zones.dijkstra_map(
                life["pos"],
                _target_positions,
                _zones,
                rolldown=True,
                return_score_in_range=[_min_view_distance, _max_view_distance],
            )
        )

        _attack_positions = _attack_positions - _target_area

        if not _attack_positions:
            return False

        if not lfe.find_action(
            life,
            [
                {
                    "action": "dijkstra_move",
                    "orig_goals": list(_attack_positions),
                    "avoid_positions": list(_avoid_positions),
                }
            ],
        ):
            lfe.stop(life)

            lfe.add_action(
                life,
                {
                    "action": "dijkstra_move",
                    "rolldown": True,
                    "goals": [list(p) for p in random.sample(_attack_positions, len(_attack_positions) / 2)],
                    "orig_goals": list(_attack_positions),
                    "avoid_positions": list(_avoid_positions),
                    "reason": "positioning for attack",
                },
                999,
            )

            return False
    else:
        _can_see_positions = set()
        _target_area = set()
        _avoid_positions = set()

        fov.fov(
            life["pos"], int(round(sight.get_vision(life) * 0.75)), callback=lambda pos: _can_see_positions.add(pos)
        )
        fov.fov(
            _target_positions[0], int(round(sight.get_vision(life) * 0.75)), callback=lambda pos: _target_area.add(pos)
        )

        for life_id in alife.judgement.get_trusted(life, visible=False, only_recent=True):
            _path_dest = lfe.path_dest(LIFE[life_id])

            if not _path_dest:
                continue

            if len(_path_dest) == 2:
                _path_dest = list(_path_dest[:])
                _path_dest.append(LIFE[life_id]["pos"][2])

            fov.fov(_path_dest, 5, callback=lambda pos: _avoid_positions.add(pos))

        _avoid_positions = list(_avoid_positions)
        _sneak_positions = _can_see_positions - _target_area
        _move_positions = zones.dijkstra_map(LIFE[target]["pos"], list(_sneak_positions), _zones, rolldown=True)

        if not _move_positions:
            travel_to_position(life, list(_target_positions[0]))
            return False

        if not lfe.find_action(
            life, [{"action": "dijkstra_move", "orig_goals": _move_positions, "avoid_positions": _avoid_positions}]
        ):
            lfe.stop(life)

            lfe.add_action(
                life,
                {
                    "action": "dijkstra_move",
                    "rolldown": True,
                    "goals": [list(p) for p in _move_positions],
                    "orig_goals": _move_positions,
                    "avoid_positions": _avoid_positions,
                    "reason": "positioning for attack",
                },
                999,
            )

            return False

    return True