Example #1
0
def _search_for_target(entity, target_id):
    _nodes = flags.get_flag(entity, 'search_nodes')

    if not _nodes:
        flags.delete_flag(entity, 'search_nodes')

        entities.trigger_event(entity,
                               'target_search_failed',
                               target_id=target_id)

        return

    _node_list = _nodes.keys()
    _node_list.sort()
    _node_x, _node_y = _nodes[_node_list[0]][0]
    _distance = numbers.distance(movement.get_position(entity),
                                 (_node_x, _node_y))

    if _distance <= 15 and life.can_see_position(entity, (_node_x, _node_y)):
        _nodes[_node_list[0]].remove((_node_x, _node_y))

        if not _nodes[_node_list[0]]:
            del _nodes[_node_list[0]]
    else:
        movement.walk_to_position(entity, _node_x, _node_y,
                                  zones.get_active_astar_map(),
                                  zones.get_active_weight_map())
Example #2
0
def show_noise(entity, x, y, accuracy, direction, text, show_on_sight, callback):
	if settings.OBSERVER_MODE:
		return
	
	if not zones.is_zone_active():
		return
	
	if life.can_see_position(entity, (x, y)) and not show_on_sight:
		return
	
	#TODO: Hearing stat
	if accuracy <= .75 and accuracy < random.uniform(0, 1):
		return
	
	if not direction == -1000:
		_moving = True
		_move_direction = direction
	else:
		_moving = False
		_move_direction = 90
	
	#TODO: Redo
	if not show_on_sight:
		_i = 100
		
		while _i:
			_nx, _ny = numbers.velocity(random.randint(0, 359), 5 * (1-accuracy))
			_x = int(round(x + _nx))
			_y = int(round(y + _ny))
			
			if not life.can_see_position(entity, (_x, _y)):
				break
			
			_i -= 1
	else:
		_x, _y = x, y
		
		if show_on_sight:
			_y -= 1
	
	return printer(_x, _y, text, moving=_moving, move_direction=_move_direction, show_mod=1, speed_mod=0.3, free_tick=True)
Example #3
0
def frag_grenade_explode(entity):
	_x, _y = movement.get_position(entity)
	_damage = entity['damage']
	_size = 3 * int(round((_damage * .01)))
	
	effects.explosion(_x, _y, _size)
	
	for entity_id in entities.get_entity_group('life'):
		_entity = entities.get_entity(entity_id)
		_distance = numbers.distance((_x, _y), movement.get_position(_entity))
		
		if _distance - 1 > _size or not life.can_see_position(_entity, (_x, _y)):
			continue
		
		entities.trigger_event(_entity, 'hit', projectile=entity, damage_mod=1 - ((_distance - 1) / float(_size)))
Example #4
0
def frag_grenade_explode(entity):
    _x, _y = movement.get_position(entity)
    _damage = entity['damage']
    _size = 3 * int(round((_damage * .01)))

    effects.explosion(_x, _y, _size)

    for entity_id in entities.get_entity_group('life'):
        _entity = entities.get_entity(entity_id)
        _distance = numbers.distance((_x, _y), movement.get_position(_entity))

        if _distance - 1 > _size or not life.can_see_position(
                _entity, (_x, _y)):
            continue

        entities.trigger_event(_entity,
                               'hit',
                               projectile=entity,
                               damage_mod=1 - ((_distance - 1) / float(_size)))
Example #5
0
def _search_for_target(entity, target_id):
	_nodes = flags.get_flag(entity, 'search_nodes')
	
	if not _nodes:
		flags.delete_flag(entity, 'search_nodes')
		
		entities.trigger_event(entity, 'target_search_failed', target_id=target_id)
		
		return
	
	_node_list = _nodes.keys()
	_node_list.sort()	
	_node_x, _node_y = _nodes[_node_list[0]][0]
	_distance = numbers.distance(movement.get_position(entity), (_node_x, _node_y))
	
	if _distance <= 15 and life.can_see_position(entity, (_node_x, _node_y)):
		_nodes[_node_list[0]].remove((_node_x, _node_y))
		
		if not _nodes[_node_list[0]]:
			del _nodes[_node_list[0]]
	else:
		movement.walk_to_position(entity, _node_x, _node_y, zones.get_active_astar_map(), zones.get_active_weight_map())
Example #6
0
def _animal_logic(entity):
    if timers.has_timer_with_name(entity, "passout"):
        return

    ai_visuals.build_item_list(entity)
    ai_visuals.build_life_list(entity)

    _old_meta = entity["ai"]["meta"].copy()

    entity["ai"]["meta"]["in_engagement"] = len(entity["ai"]["targets"]) > 0
    entity["ai"]["meta"]["in_enemy_los"] = (
        len([t for t in entity["ai"]["targets"] if entity["ai"]["life_memory"][t]["in_los"]]) > 0
    )

    if not entity["ai"]["meta"] == _old_meta:
        entities.trigger_event(entity, "meta_change")

    if entity["ai"]["meta"]["in_engagement"]:
        _target = entity["ai"]["nearest_target"]
        _target_distance = numbers.distance(movement.get_position_via_id(_target), movement.get_position(entity))

        entity["ai"]["meta"]["is_target_near"] = _target_distance <= 25

        if not entity["ai"]["meta"]["in_enemy_los"] and life.can_see_position(
            entity, entity["ai"]["life_memory"][_target]["last_seen_at"]
        ):
            entity["ai"]["meta"]["has_lost_target"] = entity["ai"]["meta"]["is_target_near"]

        elif entity["ai"]["meta"]["in_enemy_los"]:
            if flags.has_flag(entity, "search_nodes"):
                flags.delete_flag(entity, "search_nodes")

            entity["ai"]["meta"]["is_in_melee_range"] = _target_distance == 1

    else:
        entity["ai"]["meta"]["is_target_near"] = False

    entity["ai"]["meta"]["is_target_armed"] = (
        len([t for t in entity["ai"]["targets"] if entity["ai"]["life_memory"][t]["is_armed"]]) > 0
    )
    # entity['ai']['meta']['is_panicked'] = skeleton.has_critical_injury(entity)
    entity["ai"]["meta"]["is_injured"] = skeleton.has_critical_injury(entity)
    entity["ai"]["meta"]["is_panicked"] = entity["ai"]["meta"]["is_injured"]

    if entity["ai"]["is_player"]:
        return

    _goap = _handle_goap(entity)

    if not _goap:
        entity["ai"]["current_action"] = "idle"

        return

    _plan = _goap[0]
    _plan["planner"].trigger_callback(entity, _plan["actions"][0]["name"])
    # print time.time() - _t

    if not entity["ai"]["last_action"] == _plan["actions"][0]["name"]:
        logging.debug("%s: %s -> %s" % (entity["_id"], entity["ai"]["last_action"], _plan["actions"][0]["name"]))

        entity["ai"]["last_action"] = _plan["actions"][0]["name"]

    entity["ai"]["current_action"] = _plan["actions"][0]["name"]
Example #7
0
File: ai.py Project: penny64/r3-tdw
def _animal_logic(entity):
    if timers.has_timer_with_name(entity, 'passout'):
        return

    ai_visuals.build_item_list(entity)
    ai_visuals.build_life_list(entity)

    _old_meta = entity['ai']['meta'].copy()

    entity['ai']['meta']['in_engagement'] = len(entity['ai']['targets']) > 0
    entity['ai']['meta']['in_enemy_los'] = len([
        t for t in entity['ai']['targets']
        if entity['ai']['life_memory'][t]['in_los']
    ]) > 0

    if not entity['ai']['meta'] == _old_meta:
        entities.trigger_event(entity, 'meta_change')

    if entity['ai']['meta']['in_engagement']:
        _target = entity['ai']['nearest_target']
        _target_distance = numbers.distance(
            movement.get_position_via_id(_target),
            movement.get_position(entity))

        entity['ai']['meta']['is_target_near'] = _target_distance <= 25

        if not entity['ai']['meta']['in_enemy_los'] and life.can_see_position(
                entity, entity['ai']['life_memory'][_target]['last_seen_at']):
            entity['ai']['meta']['has_lost_target'] = entity['ai']['meta'][
                'is_target_near']

        elif entity['ai']['meta']['in_enemy_los']:
            if flags.has_flag(entity, 'search_nodes'):
                flags.delete_flag(entity, 'search_nodes')

            entity['ai']['meta']['is_in_melee_range'] = _target_distance == 1

    else:
        entity['ai']['meta']['is_target_near'] = False

    entity['ai']['meta']['is_target_armed'] = len([
        t for t in entity['ai']['targets']
        if entity['ai']['life_memory'][t]['is_armed']
    ]) > 0
    #entity['ai']['meta']['is_panicked'] = skeleton.has_critical_injury(entity)
    entity['ai']['meta']['is_injured'] = skeleton.has_critical_injury(entity)
    entity['ai']['meta']['is_panicked'] = entity['ai']['meta']['is_injured']

    if entity['ai']['is_player']:
        return

    _goap = _handle_goap(entity)

    if not _goap:
        entity['ai']['current_action'] = 'idle'

        return

    _plan = _goap[0]
    _plan['planner'].trigger_callback(entity, _plan['actions'][0]['name'])
    #print time.time() - _t

    if not entity['ai']['last_action'] == _plan['actions'][0]['name']:
        logging.debug('%s: %s -> %s' %
                      (entity['_id'], entity['ai']['last_action'],
                       _plan['actions'][0]['name']))

        entity['ai']['last_action'] = _plan['actions'][0]['name']

    entity['ai']['current_action'] = _plan['actions'][0]['name']