예제 #1
0
def select_choice(dialog_id):
    _dialog = get_dialog(dialog_id)

    if not _dialog['choices']:
        print 'No choice'
        return False

    _choice = _dialog['choices'][_dialog['cursor_index']]

    _loop = False
    if _choice in _dialog['loop_choices']:
        _loop = True

    _text = _choice['text']
    _text = _text[_text.index('\"') + 1:_text.index('\"') - 1]

    if not _text.endswith('...'):
        logic.show_event(_text, life=LIFE[SETTINGS['controlling']])

    add_message(LIFE[SETTINGS['controlling']],
                _dialog['id'],
                _choice['gist'],
                _choice['text'],
                _choice['result'],
                loop=_loop)
예제 #2
0
def conditions(life, alife_seen, alife_not_seen, targets_seen, targets_not_seen, source_map):
	RETURN_VALUE = STATE_UNCHANGED
	
	_mode = None
	if lfe.execute_raw(life, 'state', 'combat'):
		_mode = 'combat'
	
	if not _mode and lfe.execute_raw(life, 'state', 'hunt'):
		_mode = 'hunt'
	
	if not _mode:
		return False
	
	if not lfe.execute_raw(life, 'combat', 'ranged') and not lfe.execute_raw(life, 'combat', 'melee'):
		return False
	
	if not life['state'] == STATE:
		life['state_flags'] = {}
		stats.battle_cry(life)
		
		if gfx.position_is_in_frame(life['pos']) and SETTINGS['controlling']:
			_can_see = sight.can_see_position(life, LIFE[SETTINGS['controlling']]['pos'])
			
			if _can_see:
				_knows = brain.knows_alife_by_id(life, SETTINGS['controlling'])
				
				if _knows and judgement.can_trust(life, SETTINGS['controlling']):
					if lfe.ticker(life, 'enter_combat_message', 3, fire=True):
						logic.show_event('%s readies up.' % ' '.join(life['name']), life=life)
		
		RETURN_VALUE = STATE_CHANGE
	
	brain.flag(life, 'combat_mode', value=_mode)
	
	return RETURN_VALUE
예제 #3
0
def say_via_gist(life, dialog_id, gist, loop=False, **kwargs):
    _dialog = get_dialog(dialog_id)
    _chosen_message = random.choice(get_matching_message(
        life, dialog_id, gist))
    _target = get_listener(dialog_id)
    _text = _chosen_message[
        'text']  #reformat_text(life, _target, dialog_id, _chosen_message['text'])
    _loop = False

    _dialog['flags'].update(**kwargs)

    if not loop:
        while _text.startswith('>'):
            _text = _text[1:]
            _chosen_message = random.choice(
                get_matching_message(life, dialog_id, _text))
            _text = _chosen_message['text']
            _loop = True

    if 'player' in life:
        logic.show_event(_text.replace('\"', ''), life=life)

    add_message(life,
                dialog_id,
                _chosen_message['gist'],
                _chosen_message['text'],
                _chosen_message['result'],
                loop=_loop)
예제 #4
0
파일: brain.py 프로젝트: athros/Reactor-3
def update_known_life(life, life_id, flag, value):
	_knows = knows_alife_by_id(life, life_id)
	_knows[flag] = value
	
	if 'player' in life:
		if flag == 'last_seen_at':
			logic.show_event('<Updated location of %s>' % (' '.join(LIFE[life_id]['name'])), pos=value, delay=2)
	
	logging.debug('%s updated location of %s: %s' % (' '.join(life['name']), ' '.join(LIFE[life_id]['name']), value))
예제 #5
0
def set_focus_point(life, chunk_key):
    lfe.delete_memory(life, matches={"text": "focus_on_chunk"})

    lfe.memory(life, "focus_on_chunk", chunk_key=chunk_key)

    if "player" in life:
        _center_chunk_pos = maps.get_chunk(chunk_key)["pos"]
        _center_chunk_pos.append(2)

        logic.show_event("<Movement Order>", pos=_center_chunk_pos)
예제 #6
0
파일: movement.py 프로젝트: flags/Reactor-3
def set_focus_point(life, chunk_key):
	lfe.delete_memory(life, matches={'text': 'focus_on_chunk'})
	
	lfe.memory(life, 'focus_on_chunk', chunk_key=chunk_key)
	
	if 'player' in life:
		_center_chunk_pos = maps.get_chunk(chunk_key)['pos']
		_center_chunk_pos.append(2)
		
		logic.show_event('<Movement Order>', pos=_center_chunk_pos)
예제 #7
0
def set_focus_point(life, chunk_key):
    lfe.delete_memory(life, matches={'text': 'focus_on_chunk'})

    lfe.memory(life, 'focus_on_chunk', chunk_key=chunk_key)

    if 'player' in life:
        _center_chunk_pos = maps.get_chunk(chunk_key)['pos']
        _center_chunk_pos.append(2)

        logic.show_event('<Movement Order>', pos=_center_chunk_pos)
예제 #8
0
def add_member(life, group_id, life_id):
    if is_member(life, group_id, life_id):
        raise Exception(
            '%s failed to add new member: %s is already a member of group: %s'
            % (' '.join(life['name']), ' '.join(
                LIFE[life_id]['name']), group_id))

    if not life['id'] == life_id:
        _target = brain.knows_alife_by_id(life, life_id)

        if _target:
            if _target['group'] == group_id:
                pass
            elif _target and _target['group']:
                lfe.memory(LIFE[life_id],
                           'left group for group',
                           left_group=_target['group'],
                           group=group_id)
                remove_member(life, _target['group'], life_id)

            _target['group'] = group_id
        else:
            _target = brain.meet_alife(life, LIFE[life_id])

        stats.establish_trust(life, life_id)
    elif life['id'] == life_id and life[
            'group'] and not life['group'] == group_id:
        remove_member(life, life['group'], life_id)

    _group = get_group(life, group_id)
    for member in _group['members']:
        brain.meet_alife(LIFE[member], LIFE[life_id])

    if _group['shelter']:
        LIFE[life_id]['shelter'] = _group['shelter']
        lfe.memory(LIFE[life_id],
                   'shelter founder',
                   shelter=_group['shelter'],
                   founder=_group['leader'])

    _group['members'].append(life_id)

    if _group['leader'] and 'player' in LIFE[_group['leader']]:
        _text = '%s has joined your group.' % ' '.join(LIFE[life_id]['name'])
        gfx.message(_text, style='good')

        if sight.can_see_target(LIFE[_group['leader']], life_id):
            logic.show_event(_text, life=LIFE[life_id], delay=1)

    logging.debug(
        '%s added %s to group \'%s\'' %
        (' '.join(life['name']), ' '.join(LIFE[life_id]['name']), group_id))
예제 #9
0
def update_known_life(life, life_id, flag, value):
    _knows = knows_alife_by_id(life, life_id)
    _knows[flag] = value

    if 'player' in life:
        if flag == 'last_seen_at':
            logic.show_event('<Updated location of %s>' %
                             (' '.join(LIFE[life_id]['name'])),
                             pos=value,
                             delay=2)

    logging.debug(
        '%s updated location of %s: %s' %
        (' '.join(life['name']), ' '.join(LIFE[life_id]['name']), value))
예제 #10
0
def select_choice(dialog_id):
	_dialog = get_dialog(dialog_id)
	
	if not _dialog['choices']:
		return False
	
	_choice = _dialog['choices'][_dialog['cursor_index']]
	
	_loop = False
	if _choice in _dialog['loop_choices']:
		_loop = True
	
	_text = _choice['text']
	_text = _text[_text.index('\"')+1:_text.index('\"')-1]
	
	if not _text.endswith('...'):
		logic.show_event(_text, life=LIFE[SETTINGS['controlling']])
	
	add_message(LIFE[SETTINGS['controlling']], _dialog['id'], _choice['gist'], _choice['text'], _choice['result'], loop=_loop)
예제 #11
0
def say_via_gist(life, dialog_id, gist, loop=False, **kwargs):
	_dialog = get_dialog(dialog_id)
	_chosen_message = random.choice(get_matching_message(life, dialog_id, gist))
	_target = get_listener(dialog_id)
	_text = _chosen_message['text']#reformat_text(life, _target, dialog_id, _chosen_message['text'])
	_loop = False
	
	_dialog['flags'].update(**kwargs)

	if not loop:
		while _text.startswith('>'):
			_text = _text[1:]
			_chosen_message = random.choice(get_matching_message(life, dialog_id, _text))
			_text = _chosen_message['text']
			_loop = True
	
	if 'player' in life:
		logic.show_event(_text.replace('\"', ''), life=life)
	
	add_message(life, dialog_id, _chosen_message['gist'], _chosen_message['text'], _chosen_message['result'], loop=_loop)
예제 #12
0
def conditions(life, alife_seen, alife_not_seen, targets_seen,
               targets_not_seen, source_map):
    RETURN_VALUE = STATE_UNCHANGED

    _mode = None
    if lfe.execute_raw(life, 'state', 'combat'):
        _mode = 'combat'

    if not _mode and lfe.execute_raw(life, 'state', 'hunt'):
        _mode = 'hunt'

    if not _mode:
        return False

    if not lfe.execute_raw(life, 'combat', 'ranged') and not lfe.execute_raw(
            life, 'combat', 'melee'):
        return False

    if not life['state'] == STATE:
        life['state_flags'] = {}
        stats.battle_cry(life)

        if gfx.position_is_in_frame(life['pos']) and SETTINGS['controlling']:
            _can_see = sight.can_see_position(
                life, LIFE[SETTINGS['controlling']]['pos'])

            if _can_see:
                _knows = brain.knows_alife_by_id(life, SETTINGS['controlling'])

                if _knows and judgement.can_trust(life,
                                                  SETTINGS['controlling']):
                    if lfe.ticker(life, 'enter_combat_message', 3, fire=True):
                        logic.show_event('%s readies up.' %
                                         ' '.join(life['name']),
                                         life=life)

        RETURN_VALUE = STATE_CHANGE

    brain.flag(life, 'combat_mode', value=_mode)

    return RETURN_VALUE
예제 #13
0
def add_member(life, group_id, life_id):
	if not group_id in LIFE[life_id]['known_groups']:
		raise Exception('DOES NOT KNOW')
	
	if is_member(life, group_id, life_id):
		raise Exception('%s failed to add new member: %s is already a member of group: %s' % (' '.join(life['name']), ' '.join(LIFE[life_id]['name']), group_id))
	
	if not life['id'] == life_id:
		_target = brain.knows_alife_by_id(life, life_id)
		
		if _target:
			if _target['group'] == group_id:
				pass
			elif _target and _target['group']:
				lfe.memory(LIFE[life_id], 'left group for group', left_group=_target['group'], group=group_id)
				remove_member(life, _target['group'], life_id)
			
			_target['group'] = group_id
		else:
			brain.meet_alife(life, LIFE[life_id])
	elif life['id'] == life_id and life['group'] and not life['group'] == group_id:
		remove_member(life, life['group'], life_id)
	
	_group = get_group(life, group_id)
	for member in _group['members']:
		brain.meet_alife(LIFE[member], LIFE[life_id])
	
	if _group['shelter']:
		LIFE[life_id]['shelter'] = _group['shelter']
		lfe.memory(LIFE[life_id], 'shelter founder', shelter=_group['shelter'], founder=_group['leader'])
	
	_group['members'].append(life_id)
	
	if _group['leader'] and 'player' in LIFE[_group['leader']]:
		_text = '%s has joined your group.' % ' '.join(LIFE[life_id]['name'])
		gfx.message(_text, style='good')
		
		if sight.can_see_target(LIFE[_group['leader']], life_id):
			logic.show_event(_text, life=LIFE[life_id], delay=1)
	
	logging.debug('%s added %s to group \'%s\'' % (' '.join(life['name']), ' '.join(LIFE[life_id]['name']), group_id))
예제 #14
0
def _create_context_from_phrase(life, phrase):
	_reactions = []
	
	if phrase['gist'] == 'comply':
		_reactions.append({'type': 'say','text': 'I give up!',
			'communicate': 'surrender'})
		
		if lfe.get_held_items(life, matches=[{'type': 'gun'}]):
			_reactions.append({'action': 'action',
				'text': '<Shoot %s>' % ' '.join(phrase['from']['name'])})
	
	elif phrase['gist'] == 'demand_drop_item':
		_reactions.append({'type': 'action','text': 'Drop the item.',
			'action': {'action': 'dropitem','item': phrase['item']},
			'score': 900,
			'delay': lfe.get_item_access_time(life,phrase['item']),
			'communicate': 'dropped_demanded_item'})
	
	elif phrase['gist'] == 'dialog':
		if not phrase['dialog_id'] in LIFE[SETTINGS['controlling']]['dialogs']:
			life['dialogs'].append(phrase['dialog_id'])
		
		if dialog.get_last_message(phrase['dialog_id'])['text']:
			logic.show_event(dialog.get_last_message(phrase['dialog_id'])['text'], life=phrase['from'])
		
		if dialog.is_turn_to_talk(LIFE[SETTINGS['controlling']], phrase['dialog_id']):
			dialog.process(LIFE[SETTINGS['controlling']], phrase['dialog_id'])
	
	elif phrase['gist'] == 'looks_hostile':
		#encounters.create_encounter(life, phrase['from'])
		#logic.show_event(
		alife.speech.start_dialog(phrase['from'], life['id'], 'encounter')
	#else:
	#	logging.warning('Unhandled player context: %s' % phrase['gist'])

	return _reactions
예제 #15
0
def look(life):
    if not 'CAN_SEE' in life['life_flags']:
        return False

    for target_id in life['know']:
        if life['know'][target_id]['last_seen_time']:
            life['know'][target_id]['last_seen_time'] += 1
            life['know'][target_id]['time_visible'] = 0
        else:
            life['know'][target_id]['time_visible'] += 1

    if 'player' in life:
        if life['path'] or not brain.get_flag(life, 'visible_chunks'):
            if SETTINGS['smp']:
                _visible_chunks = post_scan_surroundings(life)
            else:
                _visible_chunks = scan_surroundings(life,
                                                    judge=False,
                                                    get_chunks=True,
                                                    ignore_chunks=0)

            _chunks = [maps.get_chunk(c) for c in _visible_chunks]
            brain.flag(life, 'visible_chunks', value=_visible_chunks)
        elif 'player' in life:
            _visible_chunks = brain.get_flag(life, 'visible_chunks')
            _chunks = [maps.get_chunk(c) for c in _visible_chunks]
        else:
            #This is for optimizing. Be careful if you mess with this...
            _nearby_alife = {}

            for alife in LIFE.values():
                if alife['id'] == life['id']:
                    continue

                if bad_numbers.distance(
                        life['pos'],
                        alife['pos']) <= get_vision(life) and can_see_position(
                            life, alife['pos']):
                    _nearby_alife[alife['id']] = {
                        'pos': alife['pos'][:],
                        'stance': alife['stance']
                    }

            _last_nearby_alife = brain.get_flag(life, '_nearby_alife')

            if not _last_nearby_alife == _nearby_alife:
                brain.flag(life, '_nearby_alife', value=_nearby_alife)
            else:
                for target_id in life['seen']:
                    if life['know'][target_id]['last_seen_time']:
                        life['know'][target_id]['last_seen_time'] = 0

                return False

            _chunks = [
                maps.get_chunk(c)
                for c in brain.get_flag(life, 'visible_chunks')
            ]

    life['seen'] = []
    life['seen_items'] = []

    for item_uid in life['know_items']:
        life['know_items'][item_uid]['last_seen_time'] += 1

    for target_id in life['know']:
        life['know'][target_id]['last_seen_time'] += 1

        if life['know'][target_id]['last_seen_time'] >= 10 and not life[
                'know'][target_id]['escaped']:
            life['know'][target_id]['escaped'] = 1

    if not 'player' in life:
        quick_look(life)

        return False

    for chunk in _chunks:
        judgement.judge_chunk_visually(
            life, '%s,%s' % (chunk['pos'][0], chunk['pos'][1]))
        judgement.judge_chunk_life(
            life, '%s,%s' % (chunk['pos'][0], chunk['pos'][1]))

        for ai in [LIFE[i] for i in chunk['life']]:
            if ai['id'] == life['id']:
                continue

            if not is_in_fov(life, ai['pos']):
                if ai['id'] in life['know']:
                    life['know'][ai['id']]['time_visible'] = 0

                continue

            if not ai['id'] in life['know']:
                brain.meet_alife(life, ai)

            _visibility = get_visiblity_of_position(life, ai['pos'])
            _stealth_coverage = get_stealth_coverage(ai)

            if _visibility < 1 - _stealth_coverage:
                continue

            life['seen'].append(ai['id'])

            if life['think_rate'] == life['think_rate_max']:
                lfe.create_and_update_self_snapshot(LIFE[ai['id']])
                judgement.judge_life(life, ai['id'])

            if ai['dead']:
                if 'player' in life and not life['know'][
                        ai['id']]['dead'] and life['know'][
                            ai['id']]['last_seen_time'] > 25:
                    logic.show_event('You discover the body of %s.' %
                                     ' '.join(ai['name']),
                                     life=ai)

                if life['know'][ai['id']]['group']:
                    groups.remove_member(life, life['know'][ai['id']]['group'],
                                         ai['id'])
                    life['know'][ai['id']]['group'] = None
                    core.record_loss(1)

                life['know'][ai['id']]['dead'] = True
            elif ai['asleep']:
                life['know'][ai['id']]['asleep'] = True
            elif not ai['asleep']:
                life['know'][ai['id']]['asleep'] = False

            life['know'][ai['id']]['last_seen_time'] = 0
            life['know'][ai['id']]['last_seen_at'] = ai['pos'][:]
            life['know'][ai['id']]['escaped'] = False
            life['know'][ai['id']]['state'] = ai['state']
            life['know'][ai['id']]['state_tier'] = ai['state_tier']

            if brain.alife_has_flag(life, ai['id'], 'search_map'):
                brain.unflag_alife(life, ai['id'], 'search_map')

            _chunk_id = lfe.get_current_chunk_id(ai)
            judgement.judge_chunk(life, _chunk_id, seen=True)

        for item in [ITEMS[i] for i in chunk['items'] if i in ITEMS]:
            if not is_in_fov(life, item['pos']):
                continue

            if not item['uid'] in life['know_items']:
                brain.remember_item(life, item)

            if items.is_item_owned(item['uid']):
                #TODO: This doesn't work because we are specifically checking chunks
                if item['owner'] and lfe.item_is_equipped(
                        LIFE[item['owner']], item['uid']):
                    life['know_items'][item['uid']]['last_seen_at'] = LIFE[
                        item['owner']]['pos']
                    life['know_items'][
                        item['uid']]['last_owned_by'] = item['owner']
                    life['know_items'][item['uid']]['last_seen_time'] = 0

                continue

            life['seen_items'].append(item['uid'])
            life['know_items'][item['uid']]['last_seen_at'] = item['pos'][:]
            life['know_items'][item['uid']]['last_seen_time'] = 0
            life['know_items'][item['uid']]['last_owned_by'] = None
            life['know_items'][item['uid']]['score'] = judgement.judge_item(
                life, item['uid'])
            life['know_items'][item['uid']]['lost'] = False
예제 #16
0
파일: items.py 프로젝트: flags/Reactor-3
def explode(item):
	if not item['type'] == 'explosive':
		return False
	
	logging.debug('The %s (item %s) explodes!' % (item['name'], item['uid']))
	
	#TODO: Don't breathe this!
	item['pos'] = get_pos(item['uid'])
	
	if item['damage']['force']:
		effects.create_explosion(item['pos'], item['damage']['force'])
	
	if SETTINGS['controlling'] and alife.sight.can_see_position(LIFE[SETTINGS['controlling']], item['pos']):
		gfx.message('%s explodes!' % get_name(item))
		logic.show_event('%s explodes!' % get_name(item), item=item, delay=0)
		
	#elif bad_numbers.distance(
	
	#TODO: Dirty hack
	for life_id in LIFE:
		_limbs = LIFE[life_id]['body'].keys()
		
		if not _limbs:
			continue
		
		_force = bad_numbers.clip((item['damage']['force']*2)-bad_numbers.distance(LIFE[life_id]['pos'], item['pos']), 0, 100)
		
		if not _force:
			continue
		
		_known_item = alife.brain.remembers_item(LIFE[life_id], item)
		_direction = bad_numbers.direction_to(item['pos'], LIFE[life_id]['pos'])
		
		#TODO: Intelligent(?) limb groups?
		_distance = bad_numbers.distance(LIFE[life_id]['pos'], item['pos'])/2
		
		for i in range(_force-_distance):
			_limb = random.choice(_limbs)
			
			for _attached_limb in life.get_all_attached_limbs(LIFE[life_id], _limb):
				if _attached_limb in _limbs:
					_limbs.remove(_attached_limb)
			
			#_limb = random.choice(LIFE[life_id]['body'].keys())
			
			if _known_item and _known_item['last_seen_time'] < 100 and _known_item['last_owned_by']:
				life.memory(LIFE[life_id], 'blown_up_by', target=_known_item['last_owned_by'])
			
			#for _limb in _limbs:
			life.add_wound(LIFE[life_id], _limb, force_velocity=bad_numbers.velocity(_direction, _force*2))
			
			if not _limbs:
				break
		
		life.push(LIFE[life_id], _direction, _force)
		
		if 'player' in LIFE[life_id]:
			life.say(LIFE[life_id], '@n are thrown by the explosion!', action=True)
		else:
			life.say(LIFE[life_id], '@n is thrown by the explosion!', action=True)
	
	if 'fire' in item['damage']:
		_circle = drawing.draw_circle(item['pos'], item['radius'])
		_zone = zones.get_zone_at_coords(item['pos'])
		
		if _zone:	
			for pos in zones.dijkstra_map(item['pos'], [item['pos']], [_zone], return_score_in_range=[0, item['damage']['fire']]):
				if not pos in _circle:
					continue
				
				if not maps.position_is_in_map(pos):
					continue
				
				for life_id in LIFE_MAP[pos[0]][pos[1]]:
					for _visible_item in [get_item_from_uid(i) for i in life.get_all_visible_items(LIFE[life_id])]:
						if not 'CAN_BURN' in _visible_item['flags']:
							continue
						
						burn(_visible_item, item['damage']['fire'])
				
				if not random.randint(0, 4):
					effects.create_fire((pos[0], pos[1], item['pos'][2]),
					                    intensity=item['damage']['fire']/2)
			
				_dist = bad_numbers.distance(item['pos'], pos)/2
				if not random.randint(0, _dist) or not _dist:
					effects.create_ash(pos)
		
				if gfx.position_is_in_frame(pos):
					_render_pos = gfx.get_render_position(pos)
					gfx.refresh_view_position(_render_pos[0], _render_pos[1], 'map')
	
	#if item['uid'] in ITEMS and ITEMS[item['uid']]['owner'] and item['uid'] in LIFE[ITEMS[item['uid']]['owner']]['inventory']:
	delete_item(item)
예제 #17
0
def explode(item):
    if not item['type'] == 'explosive':
        return False

    logging.debug('The %s (item %s) explodes!' % (item['name'], item['uid']))

    #TODO: Don't breathe this!
    item['pos'] = get_pos(item['uid'])

    if item['damage']['force']:
        effects.create_explosion(item['pos'], item['damage']['force'])

    if SETTINGS['controlling'] and alife.sight.can_see_position(
            LIFE[SETTINGS['controlling']], item['pos']):
        gfx.message('%s explodes!' % get_name(item))
        logic.show_event('%s explodes!' % get_name(item), item=item, delay=0)

    #elif bad_numbers.distance(

    #TODO: Dirty hack
    for life_id in LIFE:
        _limbs = LIFE[life_id]['body'].keys()

        if not _limbs:
            continue

        _force = bad_numbers.clip(
            (item['damage']['force'] * 2) -
            bad_numbers.distance(LIFE[life_id]['pos'], item['pos']), 0, 100)

        if not _force:
            continue

        _known_item = alife.brain.remembers_item(LIFE[life_id], item)
        _direction = bad_numbers.direction_to(item['pos'],
                                              LIFE[life_id]['pos'])

        #TODO: Intelligent(?) limb groups?
        _distance = bad_numbers.distance(LIFE[life_id]['pos'], item['pos']) / 2

        for i in range(_force - _distance):
            _limb = random.choice(_limbs)

            for _attached_limb in life.get_all_attached_limbs(
                    LIFE[life_id], _limb):
                if _attached_limb in _limbs:
                    _limbs.remove(_attached_limb)

            #_limb = random.choice(LIFE[life_id]['body'].keys())

            if _known_item and _known_item[
                    'last_seen_time'] < 100 and _known_item['last_owned_by']:
                life.memory(LIFE[life_id],
                            'blown_up_by',
                            target=_known_item['last_owned_by'])

            #for _limb in _limbs:
            life.add_wound(LIFE[life_id],
                           _limb,
                           force_velocity=bad_numbers.velocity(
                               _direction, _force * 2))

            if not _limbs:
                break

        life.push(LIFE[life_id], _direction, _force)

        if 'player' in LIFE[life_id]:
            life.say(LIFE[life_id],
                     '@n are thrown by the explosion!',
                     action=True)
        else:
            life.say(LIFE[life_id],
                     '@n is thrown by the explosion!',
                     action=True)

    if 'fire' in item['damage']:
        _circle = drawing.draw_circle(item['pos'], item['radius'])
        _zone = zones.get_zone_at_coords(item['pos'])

        if _zone:
            for pos in zones.dijkstra_map(
                    item['pos'], [item['pos']], [_zone],
                    return_score_in_range=[0, item['damage']['fire']]):
                if not pos in _circle:
                    continue

                if not maps.position_is_in_map(pos):
                    continue

                for life_id in LIFE_MAP[pos[0]][pos[1]]:
                    for _visible_item in [
                            get_item_from_uid(i)
                            for i in life.get_all_visible_items(LIFE[life_id])
                    ]:
                        if not 'CAN_BURN' in _visible_item['flags']:
                            continue

                        burn(_visible_item, item['damage']['fire'])

                if not random.randint(0, 4):
                    effects.create_fire((pos[0], pos[1], item['pos'][2]),
                                        intensity=item['damage']['fire'] / 2)

                _dist = bad_numbers.distance(item['pos'], pos) / 2
                if not random.randint(0, _dist) or not _dist:
                    effects.create_ash(pos)

                if gfx.position_is_in_frame(pos):
                    _render_pos = gfx.get_render_position(pos)
                    gfx.refresh_view_position(_render_pos[0], _render_pos[1],
                                              'map')

    #if item['uid'] in ITEMS and ITEMS[item['uid']]['owner'] and item['uid'] in LIFE[ITEMS[item['uid']]['owner']]['inventory']:
    delete_item(item)
예제 #18
0
파일: sight.py 프로젝트: athros/Reactor-3
def quick_look(life):
	_life = []
	_items = []
	_current_chunk = lfe.get_current_chunk_id(life)
	_current_chunk_pos = chunks.get_chunk(_current_chunk)['pos']
	_x_chunk_min = numbers.clip(_current_chunk_pos[0]-((get_vision(life)/WORLD_INFO['chunk_size'])*WORLD_INFO['chunk_size']), 0, MAP_SIZE[0]-WORLD_INFO['chunk_size'])
	_y_chunk_min = numbers.clip(_current_chunk_pos[1]-((get_vision(life)/WORLD_INFO['chunk_size'])*WORLD_INFO['chunk_size']), 0, MAP_SIZE[1]-WORLD_INFO['chunk_size'])
	_x_chunk_max = numbers.clip(_current_chunk_pos[0]+((get_vision(life)/WORLD_INFO['chunk_size'])*WORLD_INFO['chunk_size']), 0, MAP_SIZE[0]-WORLD_INFO['chunk_size'])
	_y_chunk_max = numbers.clip(_current_chunk_pos[1]+((get_vision(life)/WORLD_INFO['chunk_size'])*WORLD_INFO['chunk_size']), 0, MAP_SIZE[1]-WORLD_INFO['chunk_size'])
	_has_ready_weapon = combat.has_ready_weapon(life)
	
	for y in range(_y_chunk_min, _y_chunk_max, WORLD_INFO['chunk_size']):
		for x in range(_x_chunk_min, _x_chunk_max, WORLD_INFO['chunk_size']):
			_chunk_key = '%s,%s' % (x, y)
			_chunk = chunks.get_chunk(_chunk_key)
			
			for life_id in _chunk['life']:
				ai = LIFE[life_id]
				
				if ai['dead']:
					continue
				
				if life_id == life['id']:
					continue
				
				if not can_see_position(life, LIFE[life_id]['pos']):
					continue
				
				_visibility = get_visiblity_of_position(life, ai['pos'])
				_stealth_coverage = get_stealth_coverage(ai)
				
				if _visibility < 1-_stealth_coverage:
					continue
				
				if not ai['id'] in life['know']:
					brain.meet_alife(life, ai)
				
				life['seen'].append(ai['id'])
				
				if life['think_rate'] == life['think_rate_max']:
					lfe.create_and_update_self_snapshot(LIFE[ai['id']])
					judgement.judge_life(life, ai['id'])
				
				if ai['dead']:
					if 'player' in life and not life['know'][ai['id']]['dead'] and life['know'][ai['id']]['last_seen_time']>10:
						logic.show_event('You discover the body of %s.' % ' '.join(ai['name']), life=ai)
					
					if life['know'][ai['id']]['group']:
						groups.remove_member(life, life['know'][ai['id']]['group'], ai['id'])
						life['know'][ai['id']]['group'] = None
					
					life['know'][ai['id']]['dead'] = True
				elif ai['asleep']:
					life['know'][ai['id']]['asleep'] = True
				elif not ai['asleep']:
					life['know'][ai['id']]['asleep'] = False
				
				life['know'][ai['id']]['last_seen_time'] = 0
				life['know'][ai['id']]['last_seen_at'] = ai['pos'][:]
				life['know'][ai['id']]['escaped'] = False
				life['know'][ai['id']]['state'] = ai['state']
				life['know'][ai['id']]['state_tier'] = ai['state_tier']
				
				if brain.alife_has_flag(life, ai['id'], 'search_map'):
					brain.unflag_alife(life, ai['id'], 'search_map')
				
				_chunk_id = lfe.get_current_chunk_id(ai)
				judgement.judge_chunk(life, _chunk_id, seen=True)
				
				_life.append(life_id)
			
			for item_uid in _chunk['items']:
				if not item_uid in ITEMS:
					continue
				
				item = ITEMS[item_uid]
				
				if not item['uid'] in life['know_items']:
					brain.remember_item(life, item)
	
				if items.is_item_owned(item['uid']):
					continue
				
				#	#TODO: This doesn't work because we are specifically checking chunks
				#	if item['owner'] and lfe.item_is_equipped(LIFE[item['owner']], item['uid']):
				#		life['know_items'][item['uid']]['last_seen_at'] = LIFE[item['owner']]['pos']
				#		life['know_items'][item['uid']]['last_owned_by'] = item['owner']
				#		life['know_items'][item['uid']]['last_seen_time'] = 0
				#	
				#	continue
				
				if not can_see_position(life, item['pos']):
					continue
				
				if not item['uid'] in life['know_items']:
					brain.remember_item(life, item)
				
				life['seen_items'].append(item['uid'])
				life['know_items'][item['uid']]['last_seen_at'] = item['pos'][:]
				life['know_items'][item['uid']]['last_seen_time'] = 0
				life['know_items'][item['uid']]['last_owned_by'] = None
				life['know_items'][item['uid']]['score'] = judgement.judge_item(life, item['uid'])
				life['know_items'][item['uid']]['lost'] = False
				
				_items.append(item_uid)
예제 #19
0
파일: sight.py 프로젝트: flags/Reactor-3
def look(life):
	if not 'CAN_SEE' in life['life_flags']:
		return False
	
	for target_id in life['know']:
		if life['know'][target_id]['last_seen_time']:
			life['know'][target_id]['last_seen_time'] += 1
			life['know'][target_id]['time_visible'] = 0
		else:
			life['know'][target_id]['time_visible'] += 1
	
	if 'player' in life:
		if life['path'] or not brain.get_flag(life, 'visible_chunks'):
			if SETTINGS['smp']:
				_visible_chunks = post_scan_surroundings(life)
			else:
				_visible_chunks = scan_surroundings(life, judge=False, get_chunks=True, ignore_chunks=0)
				
			_chunks = [maps.get_chunk(c) for c in _visible_chunks]
			brain.flag(life, 'visible_chunks', value=_visible_chunks)
		elif 'player' in life:
			_visible_chunks = brain.get_flag(life, 'visible_chunks')
			_chunks = [maps.get_chunk(c) for c in _visible_chunks]
		else:
			#This is for optimizing. Be careful if you mess with this...
			_nearby_alife = {}
			
			for alife in LIFE.values():
				if alife['id'] == life['id']:
					continue
				
				if bad_numbers.distance(life['pos'], alife['pos'])<=get_vision(life) and can_see_position(life, alife['pos']):
					_nearby_alife[alife['id']] = {'pos': alife['pos'][:], 'stance': alife['stance']}
			
			_last_nearby_alife = brain.get_flag(life, '_nearby_alife')
			
			if not _last_nearby_alife == _nearby_alife:
				brain.flag(life, '_nearby_alife', value=_nearby_alife)
			else:
				for target_id in life['seen']:
					if life['know'][target_id]['last_seen_time']:
						life['know'][target_id]['last_seen_time'] = 0
				
				return False
			
			_chunks = [maps.get_chunk(c) for c in brain.get_flag(life, 'visible_chunks')]
	
	life['seen'] = []
	life['seen_items'] = []
	
	for item_uid in life['know_items']:
		life['know_items'][item_uid]['last_seen_time'] += 1
	
	for target_id in life['know']:
		life['know'][target_id]['last_seen_time'] += 1
		
		if life['know'][target_id]['last_seen_time']>=10 and not life['know'][target_id]['escaped']:
			life['know'][target_id]['escaped'] = 1
	
	if not 'player' in life:
		quick_look(life)
		
		return False
	
	for chunk in _chunks:
		judgement.judge_chunk_visually(life, '%s,%s' % (chunk['pos'][0], chunk['pos'][1]))
		judgement.judge_chunk_life(life, '%s,%s' % (chunk['pos'][0], chunk['pos'][1]))
		
		for ai in [LIFE[i] for i in chunk['life']]:
			if ai['id'] == life['id']:
				continue
			
			if not is_in_fov(life, ai['pos']):
				if ai['id'] in life['know']:
					life['know'][ai['id']]['time_visible'] = 0
				
				continue
			
			if not ai['id'] in life['know']:
				brain.meet_alife(life, ai)
			
			_visibility = get_visiblity_of_position(life, ai['pos'])
			_stealth_coverage = get_stealth_coverage(ai)
			
			if _visibility < 1-_stealth_coverage:
				continue
			
			life['seen'].append(ai['id'])
			
			if life['think_rate'] == life['think_rate_max']:
				lfe.create_and_update_self_snapshot(LIFE[ai['id']])
				judgement.judge_life(life, ai['id'])
			
			if ai['dead']:
				if 'player' in life and not life['know'][ai['id']]['dead'] and life['know'][ai['id']]['last_seen_time']>25:
					logic.show_event('You discover the body of %s.' % ' '.join(ai['name']), life=ai)
				
				if life['know'][ai['id']]['group']:
					groups.remove_member(life, life['know'][ai['id']]['group'], ai['id'])
					life['know'][ai['id']]['group'] = None
					core.record_loss(1)
				
				life['know'][ai['id']]['dead'] = True
			elif ai['asleep']:
				life['know'][ai['id']]['asleep'] = True
			elif not ai['asleep']:
				life['know'][ai['id']]['asleep'] = False
			
			life['know'][ai['id']]['last_seen_time'] = 0
			life['know'][ai['id']]['last_seen_at'] = ai['pos'][:]
			life['know'][ai['id']]['escaped'] = False
			life['know'][ai['id']]['state'] = ai['state']
			life['know'][ai['id']]['state_tier'] = ai['state_tier']
			
			if brain.alife_has_flag(life, ai['id'], 'search_map'):
				brain.unflag_alife(life, ai['id'], 'search_map')
			
			_chunk_id = lfe.get_current_chunk_id(ai)
			judgement.judge_chunk(life, _chunk_id, seen=True)
	
		for item in [ITEMS[i] for i in chunk['items'] if i in ITEMS]:
			if not is_in_fov(life, item['pos']):
				continue
			
			if not item['uid'] in life['know_items']:
				brain.remember_item(life, item)

			if items.is_item_owned(item['uid']):
				#TODO: This doesn't work because we are specifically checking chunks
				if item['owner'] and lfe.item_is_equipped(LIFE[item['owner']], item['uid']):
					life['know_items'][item['uid']]['last_seen_at'] = LIFE[item['owner']]['pos']
					life['know_items'][item['uid']]['last_owned_by'] = item['owner']
					life['know_items'][item['uid']]['last_seen_time'] = 0
				
				continue
			
			life['seen_items'].append(item['uid'])
			life['know_items'][item['uid']]['last_seen_at'] = item['pos'][:]
			life['know_items'][item['uid']]['last_seen_time'] = 0
			life['know_items'][item['uid']]['last_owned_by'] = None
			life['know_items'][item['uid']]['score'] = judgement.judge_item(life, item['uid'])
			life['know_items'][item['uid']]['lost'] = False
예제 #20
0
파일: sight.py 프로젝트: penny64/Reactor-3
def quick_look(life):
    _life = []
    _items = []
    _current_chunk = lfe.get_current_chunk_id(life)
    _current_chunk_pos = chunks.get_chunk(_current_chunk)['pos']
    _x_chunk_min = numbers.clip(
        _current_chunk_pos[0] -
        ((get_vision(life) / WORLD_INFO['chunk_size']) *
         WORLD_INFO['chunk_size']), 0, MAP_SIZE[0] - WORLD_INFO['chunk_size'])
    _y_chunk_min = numbers.clip(
        _current_chunk_pos[1] -
        ((get_vision(life) / WORLD_INFO['chunk_size']) *
         WORLD_INFO['chunk_size']), 0, MAP_SIZE[1] - WORLD_INFO['chunk_size'])
    _x_chunk_max = numbers.clip(
        _current_chunk_pos[0] +
        ((get_vision(life) / WORLD_INFO['chunk_size']) *
         WORLD_INFO['chunk_size']), 0, MAP_SIZE[0] - WORLD_INFO['chunk_size'])
    _y_chunk_max = numbers.clip(
        _current_chunk_pos[1] +
        ((get_vision(life) / WORLD_INFO['chunk_size']) *
         WORLD_INFO['chunk_size']), 0, MAP_SIZE[1] - WORLD_INFO['chunk_size'])
    _has_ready_weapon = combat.has_ready_weapon(life)

    for y in range(_y_chunk_min, _y_chunk_max, WORLD_INFO['chunk_size']):
        for x in range(_x_chunk_min, _x_chunk_max, WORLD_INFO['chunk_size']):
            _chunk_key = '%s,%s' % (x, y)
            _chunk = chunks.get_chunk(_chunk_key)

            for life_id in _chunk['life']:
                ai = LIFE[life_id]

                if ai['dead']:
                    continue

                if life_id == life['id']:
                    continue

                if not can_see_position(life, LIFE[life_id]['pos']):
                    continue

                _visibility = get_visiblity_of_position(life, ai['pos'])
                _stealth_coverage = get_stealth_coverage(ai)

                if _visibility < 1 - _stealth_coverage:
                    continue

                if not ai['id'] in life['know']:
                    brain.meet_alife(life, ai)

                life['seen'].append(ai['id'])

                if life['think_rate'] == life['think_rate_max']:
                    lfe.create_and_update_self_snapshot(LIFE[ai['id']])
                    judgement.judge_life(life, ai['id'])

                if ai['dead']:
                    if 'player' in life and not life['know'][
                            ai['id']]['dead'] and life['know'][
                                ai['id']]['last_seen_time'] > 10:
                        logic.show_event('You discover the body of %s.' %
                                         ' '.join(ai['name']),
                                         life=ai)

                    if life['know'][ai['id']]['group']:
                        groups.remove_member(life,
                                             life['know'][ai['id']]['group'],
                                             ai['id'])
                        life['know'][ai['id']]['group'] = None

                    life['know'][ai['id']]['dead'] = True
                elif ai['asleep']:
                    life['know'][ai['id']]['asleep'] = True
                elif not ai['asleep']:
                    life['know'][ai['id']]['asleep'] = False

                life['know'][ai['id']]['last_seen_time'] = 0
                life['know'][ai['id']]['last_seen_at'] = ai['pos'][:]
                life['know'][ai['id']]['escaped'] = False
                life['know'][ai['id']]['state'] = ai['state']
                life['know'][ai['id']]['state_tier'] = ai['state_tier']

                if brain.alife_has_flag(life, ai['id'], 'search_map'):
                    brain.unflag_alife(life, ai['id'], 'search_map')

                _chunk_id = lfe.get_current_chunk_id(ai)
                judgement.judge_chunk(life, _chunk_id, seen=True)

                _life.append(life_id)

            for item_uid in _chunk['items']:
                if not item_uid in ITEMS:
                    continue

                item = ITEMS[item_uid]

                if not item['uid'] in life['know_items']:
                    brain.remember_item(life, item)

                if items.is_item_owned(item['uid']):
                    continue

                #	#TODO: This doesn't work because we are specifically checking chunks
                #	if item['owner'] and lfe.item_is_equipped(LIFE[item['owner']], item['uid']):
                #		life['know_items'][item['uid']]['last_seen_at'] = LIFE[item['owner']]['pos']
                #		life['know_items'][item['uid']]['last_owned_by'] = item['owner']
                #		life['know_items'][item['uid']]['last_seen_time'] = 0
                #
                #	continue

                if not can_see_position(life, item['pos']):
                    continue

                if not item['uid'] in life['know_items']:
                    brain.remember_item(life, item)

                life['seen_items'].append(item['uid'])
                life['know_items'][
                    item['uid']]['last_seen_at'] = item['pos'][:]
                life['know_items'][item['uid']]['last_seen_time'] = 0
                life['know_items'][item['uid']]['last_owned_by'] = None
                life['know_items'][
                    item['uid']]['score'] = judgement.judge_item(
                        life, item['uid'])
                life['know_items'][item['uid']]['lost'] = False

                _items.append(item_uid)