<commit_before>from globals import *
import life as lfe

import judgement
import movement
import dialog
import speech
import groups
import stats
import raids
import brain
import camps
import jobs

import logging
import random

ENTRY_SCORE = 0
TIER = TIER_PASSIVE

def conditions(life, alife_seen, alife_not_seen, targets_seen, targets_not_seen, source_map):
	#Note: We don't want to change the state because we're running this module alongside
	#other modules that will (most likely) be changing states for us...
	#Instead we're going to read the current state and react accordingly via flipping
	#life['flags'] and spawning conversations based on that (and the state of course).
	#The main focus is to provide effective output rather than a lot of it, so the less
	#conversations we spawn the better.
	
	return RETURN_SKIP

def tick(life, alife_seen, alife_not_seen, targets_seen, targets_not_seen, source_map):
	#TODO: Add these two values to an array called PANIC_STATES
	#if not alife_seen:
	#	return False
	
	if brain.retrieve_from_memory(life, 'tension_spike') >= 10:
		lfe.say(life, '@n panics!', action=True)
	
	for ai in alife_seen:
		if life['state'] in ['combat']:
			break
		
		if jobs.alife_has_job(ai['life']):
			break
		
		if not stats.can_talk_to(life, ai['life']['id']):
			continue
		
		if judgement.is_target_dangerous(life, ai['life']['id']):
			if not speech.discussed(life, ai['life'], 'looks_hostile'):
				speech.communicate(life, 'looks_hostile', msg='...', matches=[{'id': ai['life']['id']}])
				speech.send(life, ai['life'], 'looks_hostile')
		else:
			if not speech.discussed(life, ai['life'], 'greeting'):
				if stats.is_compatible_with(life, ai['life']['id']):
					speech.communicate(life, 'greeting', matches=[{'id': ai['life']['id']}])
				
				speech.send(life, ai['life'], 'greeting')
	
	_potential_talking_targets = []
	for ai in alife_seen:
		if life['state'] in ['combat', 'hiding', 'hidden']:
			break
		
		if judgement.is_target_dangerous(life, ai['life']['id']):
			continue
		
		if not stats.can_talk_to(life, ai['life']['id']):
			continue		
		
		if not stats.desires_conversation_with(life, ai['life']['id']):
			continue
		
		#TODO: Not always true.
		if ai['life']['state'] in ['hiding', 'hidden']:
			break
		
		_potential_talking_targets.append(ai['life'])
	
	#TODO: Score these
	random.shuffle(_potential_talking_targets)
	
	for target in _potential_talking_targets:
		if life['dialogs']:
			print 'existing'
			break
		
		if not lfe.get_memory(life, matches={'text': 'met', 'target': target['id']}) and stats.desires_interaction(life):
			if stats.desires_life(life, target['id']):
				speech.start_dialog(life, target['id'], 'introduction')
			elif not stats.desires_life(life, target['id']) and not brain.get_alife_flag(life, target['id'], 'not_friend'):
				speech.start_dialog(life, target['id'], 'introduction_negative')
				brain.flag_alife(life, target['id'], 'not_friend')
		elif lfe.get_questions(life, target=target['id']):
			if _potential_talking_targets:
				speech.start_dialog(life, target['id'], 'questions')
		elif stats.wants_group_member(life, target['id']) and not groups.is_member(life['group'], target['id']):
			brain.flag_alife(life, target['id'], 'invited_to_group')
			speech.start_dialog(life, target['id'], 'ask_to_join_group')
	
	if life['dialogs']:
		_dialog = life['dialogs'][0]
		dialog.tick(life, _dialog)	
	
	if not judgement.is_safe(life):
		_combat_targets = judgement.get_combat_targets(life)
		
		if _combat_targets:
			if life['camp'] and camps.is_in_camp(life, lfe.get_current_camp(life)):
				_nearest_camp = camps.get_nearest_known_camp(life)
				raids.create_raid(_nearest_camp['id'], join=life['id'])
				raids.add_raiders(_nearest_camp['id'], _combat_targets)
				
				#TODO: Remove memory call
				speech.announce(life,
					'camp_raid',
					camp=_nearest_camp,
					raiders=_combat_targets)
			
			if life['group']:
				for target in _combat_targets:
					_last_seen_at = None
					_know = brain.knows_alife_by_id(life, target)
					
					if _know:
						_last_seen_at = _know['last_seen_at']
						
					groups.distribute(life, 'under_attack', attacker=target, last_seen_at=_last_seen_at)
		
		for target in judgement.get_combat_targets(life):
			_last_seen_at = None
			_know = brain.knows_alife_by_id(life, target)
			
			if _know:
				_last_seen_at = _know['last_seen_at']

			speech.announce(life, 'under_attack', trusted=True, attacker=target, last_seen_at=_last_seen_at)
<commit_msg>Fixed under_attack announcing too often<commit_after>from globals import *
import life as lfe

import judgement
import movement
import dialog
import speech
import groups
import stats
import raids
import brain
import camps
import jobs

import logging
import random

ENTRY_SCORE = 0
TIER = TIER_PASSIVE

def conditions(life, alife_seen, alife_not_seen, targets_seen, targets_not_seen, source_map):
	#Note: We don't want to change the state because we're running this module alongside
	#other modules that will (most likely) be changing states for us...
	#Instead we're going to read the current state and react accordingly via flipping
	#life['flags'] and spawning conversations based on that (and the state of course).
	#The main focus is to provide effective output rather than a lot of it, so the less
	#conversations we spawn the better.
	
	return RETURN_SKIP

def tick(life, alife_seen, alife_not_seen, targets_seen, targets_not_seen, source_map):
	#TODO: Add these two values to an array called PANIC_STATES
	#if not alife_seen:
	#	return False
	
	if brain.retrieve_from_memory(life, 'tension_spike') >= 10:
		lfe.say(life, '@n panics!', action=True)
	
	for ai in alife_seen:
		if life['state'] in ['combat']:
			break
		
		if jobs.alife_has_job(ai['life']):
			break
		
		if not stats.can_talk_to(life, ai['life']['id']):
			continue
		
		if judgement.is_target_dangerous(life, ai['life']['id']):
			if not speech.discussed(life, ai['life'], 'looks_hostile'):
				speech.communicate(life, 'looks_hostile', msg='...', matches=[{'id': ai['life']['id']}])
				speech.send(life, ai['life'], 'looks_hostile')
		else:
			if not speech.discussed(life, ai['life'], 'greeting'):
				if stats.is_compatible_with(life, ai['life']['id']):
					speech.communicate(life, 'greeting', matches=[{'id': ai['life']['id']}])
				
				speech.send(life, ai['life'], 'greeting')
	
	_potential_talking_targets = []
	for ai in alife_seen:
		if life['state'] in ['combat', 'hiding', 'hidden']:
			break
		
		if judgement.is_target_dangerous(life, ai['life']['id']):
			continue
		
		if not stats.can_talk_to(life, ai['life']['id']):
			continue		
		
		if not stats.desires_conversation_with(life, ai['life']['id']):
			continue
		
		#TODO: Not always true.
		if ai['life']['state'] in ['hiding', 'hidden']:
			break
		
		_potential_talking_targets.append(ai['life'])
	
	#TODO: Score these
	random.shuffle(_potential_talking_targets)
	
	for target in _potential_talking_targets:
		if life['dialogs']:
			print 'existing'
			break
		
		if not lfe.get_memory(life, matches={'text': 'met', 'target': target['id']}) and stats.desires_interaction(life):
			if stats.desires_life(life, target['id']):
				speech.start_dialog(life, target['id'], 'introduction')
			elif not stats.desires_life(life, target['id']) and not brain.get_alife_flag(life, target['id'], 'not_friend'):
				speech.start_dialog(life, target['id'], 'introduction_negative')
				brain.flag_alife(life, target['id'], 'not_friend')
		elif lfe.get_questions(life, target=target['id']):
			if _potential_talking_targets:
				speech.start_dialog(life, target['id'], 'questions')
		elif stats.wants_group_member(life, target['id']) and not groups.is_member(life['group'], target['id']):
			brain.flag_alife(life, target['id'], 'invited_to_group')
			speech.start_dialog(life, target['id'], 'ask_to_join_group')
	
	if life['dialogs']:
		_dialog = life['dialogs'][0]
		dialog.tick(life, _dialog)	
	
	if not judgement.is_safe(life) and lfe.ticker(life, 'call_for_help', 90, fire=True):
		_combat_targets = judgement.get_ready_combat_targets(life)
		
		if _combat_targets:
			if life['camp'] and camps.is_in_camp(life, lfe.get_current_camp(life)):
				_nearest_camp = camps.get_nearest_known_camp(life)
				raids.create_raid(_nearest_camp['id'], join=life['id'])
				raids.add_raiders(_nearest_camp['id'], _combat_targets)
				
				#TODO: Remove memory call
				speech.announce(life,
					'camp_raid',
					camp=_nearest_camp,
					raiders=_combat_targets)
			
			if life['group']:
				for target in _combat_targets:
					_last_seen_at = None
					_know = brain.knows_alife_by_id(life, target)
					
					if _know:
						_last_seen_at = _know['last_seen_at']
						
					groups.distribute(life, 'under_attack', attacker=target, last_seen_at=_last_seen_at)
		
		for target in judgement.get_ready_combat_targets(life):
			_last_seen_at = None
			_know = brain.knows_alife_by_id(life, target)
			
			if _know:
				_last_seen_at = _know['last_seen_at']

			speech.announce(life, 'under_attack', trusted=True, attacker=target, last_seen_at=_last_seen_at)

{'fraction_non_alphanumeric': 0.13435467871707263, 'fraction_numerical': 0.0011021712774165104, 'mean_word_length': 4.911400651465798, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5587982', 'n_tokens_mistral': 3623, 'n_tokens_neox': 3068, 'n_words': 739}