Ejemplo n.º 1
0
def process_smoke(smoke):
    if smoke['disappear']:
        smoke['intensity'] -= smoke['decay']
    else:
        if smoke['intensity'] < smoke['max_intensity']:
            smoke['intensity'] += smoke['grow']
        else:
            smoke['disappear'] = True

    if smoke['intensity'] < 0 and smoke['disappear']:
        unregister_effect(smoke)

        return False

    if smoke['interp_wind']:
        smoke['velocity'] = numbers.lerp_velocity(smoke['velocity'],
                                                  weather.get_wind_velocity(),
                                                  0.05)

    smoke['float_pos'][0] += smoke['velocity'][0]
    smoke['float_pos'][1] += smoke['velocity'][1]

    _in_frame = gfx.position_is_in_frame(smoke['pos'])
    _old_pos = smoke['pos'][:2]

    if _in_frame:
        gfx.refresh_view_position(smoke['pos'][0] - CAMERA_POS[0],
                                  smoke['pos'][1] - CAMERA_POS[1], 'map')

    EFFECT_MAP[smoke['pos'][0]][smoke['pos'][1]].remove(smoke['id'])

    smoke['pos'] = [
        int(round(smoke['float_pos'][0])),
        int(round(smoke['float_pos'][1]))
    ]

    if _in_frame and not smoke['pos'] == _old_pos:
        gfx.refresh_view_position(smoke['pos'][0] - CAMERA_POS[0],
                                  smoke['pos'][1] - CAMERA_POS[1], 'map')

    if smoke['pos'][0] < 0 or smoke['pos'][1] < 0 or smoke['pos'][
            0] >= MAP_SIZE[0] - 1 or smoke['pos'][1] >= MAP_SIZE[1] - 1:
        unregister_effect(smoke, remove_from_effect_map=False)
        return False

    EFFECT_MAP[smoke['pos'][0]][smoke['pos'][1]].append(smoke['id'])
Ejemplo n.º 2
0
def process_smoke(smoke):
	if smoke['disappear']:
		smoke['intensity'] -= smoke['decay']
	else:
		if smoke['intensity'] < smoke['max_intensity']:
			smoke['intensity'] += smoke['grow']
		else:
			smoke['disappear'] = True
	
	if smoke['intensity'] < 0 and smoke['disappear']:
		unregister_effect(smoke)
		
		return False
	
	if smoke['interp_wind']:
		smoke['velocity'] = numbers.lerp_velocity(smoke['velocity'], weather.get_wind_velocity(), 0.05)
	
	smoke['float_pos'][0] += smoke['velocity'][0]
	smoke['float_pos'][1] += smoke['velocity'][1]
	
	_in_frame = gfx.position_is_in_frame(smoke['pos'])
	_old_pos = smoke['pos'][:2]
	
	if _in_frame:
		gfx.refresh_view_position(smoke['pos'][0]-CAMERA_POS[0], smoke['pos'][1]-CAMERA_POS[1], 'map')
	
	EFFECT_MAP[smoke['pos'][0]][smoke['pos'][1]].remove(smoke['id'])
	
	smoke['pos'] = [int(round(smoke['float_pos'][0])), int(round(smoke['float_pos'][1]))]
	
	if _in_frame and not smoke['pos'] == _old_pos:
		gfx.refresh_view_position(smoke['pos'][0]-CAMERA_POS[0], smoke['pos'][1]-CAMERA_POS[1], 'map')
	
	if smoke['pos'][0]<0 or smoke['pos'][1]<0 or smoke['pos'][0]>=MAP_SIZE[0]-1 or smoke['pos'][1]>=MAP_SIZE[1]-1:
		unregister_effect(smoke, remove_from_effect_map=False)
		return False
	
	EFFECT_MAP[smoke['pos'][0]][smoke['pos'][1]].append(smoke['id'])
Ejemplo n.º 3
0
def move_camera(pos, scroll=False):
    _orig_pos = CAMERA_POS[:]

    if SETTINGS['controlling'] and SETTINGS['following'] == SETTINGS[
            'controlling'] and locks.is_locked('camera_free'):
        _life = LIFE[SETTINGS['controlling']]
        _top_left = MAP_SIZE[:]
        _bot_right = [0, 0, 0]
        _seen = False

        for life_id in LIFE[SETTINGS['controlling']]['seen']:
            if LIFE[life_id]['dead']:
                continue

            if brain.knows_alife_by_id(
                    LIFE[SETTINGS['controlling']],
                    life_id)['alignment'] in ['trust', 'feign_trust']:
                continue

            _seen = True

            if LIFE[life_id]['pos'][0] < _top_left[0]:
                _top_left[0] = LIFE[life_id]['pos'][0]

            if LIFE[life_id]['pos'][1] < _top_left[1]:
                _top_left[1] = LIFE[life_id]['pos'][1]

            if LIFE[life_id]['pos'][0] > _bot_right[0]:
                _bot_right[0] = LIFE[life_id]['pos'][0]

            if LIFE[life_id]['pos'][1] > _bot_right[1]:
                _bot_right[1] = LIFE[life_id]['pos'][1]

            _target_pos = numbers.lerp_velocity(_top_left, _bot_right, 0.5)
            pos = numbers.lerp_velocity(pos, _target_pos, .35)[:2]
            pos.append(2)

            brain.flag(_life, 'camera_lean', value=_target_pos[:])
            brain.flag(_life, 'camera_lean_time', value=WORLD_INFO['ticks'])

            _future_time = brain.get_flag(_life, 'camera_lean_time_future')
            if not _future_time or WORLD_INFO['ticks'] > _future_time:
                brain.flag(_life,
                           'camera_lean_time_future',
                           value=WORLD_INFO['ticks'] + 30)

        if brain.get_flag(_life, 'camera_lean'):
            if _seen:
                _st = WORLD_INFO['ticks'] - (
                    brain.get_flag(_life, 'camera_lean_time_future') - 30)
                _et = brain.get_flag(_life, 'camera_lean_time_future') - (
                    brain.get_flag(_life, 'camera_lean_time_future') - 30)
                _lerp = 1 - numbers.clip(_st / float(_et), 0, 1.0)

                pos = numbers.lerp_velocity(
                    pos, brain.get_flag(_life, 'camera_lean'), _lerp)[:2]
                pos.append(2)
            else:
                if WORLD_INFO['ticks'] - brain.get_flag(
                        _life, 'camera_lean_time') <= 20:
                    _lerp = .45 - numbers.clip(
                        (WORLD_INFO['ticks'] - brain.get_flag(
                            _life, 'camera_lean_time')) / 30.0, 0, .45)
                    pos = numbers.lerp_velocity(
                        pos, brain.get_flag(_life, 'camera_lean'), _lerp)[:2]
                    pos.append(2)
                else:
                    brain.unflag(_life, 'camera_lean')
                    brain.unflag(_life, 'camera_lean_time')

    CAMERA_POS[0] = int(
        round(
            numbers.clip(pos[0] - (MAP_WINDOW_SIZE[0] / 2), 0,
                         MAP_SIZE[0] - MAP_WINDOW_SIZE[0])))
    CAMERA_POS[1] = int(
        round(
            numbers.clip(pos[1] - (MAP_WINDOW_SIZE[1] / 2), 0,
                         MAP_SIZE[1] - MAP_WINDOW_SIZE[1])))
    CAMERA_POS[2] = int(round(pos[2]))

    if not _orig_pos == CAMERA_POS:
        gfx.refresh_view('map')
    elif SETTINGS['controlling'] and not alife.brain.get_flag(
            LIFE[SETTINGS['controlling']], 'redraw') == pos:
        gfx.refresh_view('map')

    if SETTINGS['controlling']:
        alife.brain.flag(LIFE[SETTINGS['controlling']], 'redraw', value=pos[:])
Ejemplo n.º 4
0
def move_camera(pos, scroll=False):
	_orig_pos = CAMERA_POS[:]
	
	if SETTINGS['controlling'] and SETTINGS['following'] == SETTINGS['controlling'] and locks.is_locked('camera_free'):
		_life = LIFE[SETTINGS['controlling']]
		_top_left = MAP_SIZE[:]
		_bot_right = [0, 0, 0]
		_seen = False
		
		for life_id in LIFE[SETTINGS['controlling']]['seen']:
			if LIFE[life_id]['dead']:
				continue
			
			if brain.knows_alife_by_id(LIFE[SETTINGS['controlling']], life_id)['alignment'] in ['trust', 'feign_trust']:
				continue
			
			_seen = True
			
			if LIFE[life_id]['pos'][0] < _top_left[0]:
				_top_left[0] = LIFE[life_id]['pos'][0]
			
			if LIFE[life_id]['pos'][1] < _top_left[1]:
				_top_left[1] = LIFE[life_id]['pos'][1]
			
			if LIFE[life_id]['pos'][0] > _bot_right[0]:
				_bot_right[0] = LIFE[life_id]['pos'][0]
			
			if LIFE[life_id]['pos'][1] > _bot_right[1]:
				_bot_right[1] = LIFE[life_id]['pos'][1]
			
			_target_pos = numbers.lerp_velocity(_top_left, _bot_right, 0.5)
			pos = numbers.lerp_velocity(pos, _target_pos, .35)[:2]
			pos.append(2)
			
			brain.flag(_life, 'camera_lean', value=_target_pos[:])
			brain.flag(_life, 'camera_lean_time', value=WORLD_INFO['ticks'])
			
			_future_time = brain.get_flag(_life, 'camera_lean_time_future')
			if not _future_time or WORLD_INFO['ticks']>_future_time:
				brain.flag(_life, 'camera_lean_time_future', value=WORLD_INFO['ticks']+30)
		
		if brain.get_flag(_life, 'camera_lean'):
			if _seen:
				_st = WORLD_INFO['ticks']-(brain.get_flag(_life, 'camera_lean_time_future')-30)
				_et = brain.get_flag(_life, 'camera_lean_time_future')-(brain.get_flag(_life, 'camera_lean_time_future')-30)
				_lerp = 1-numbers.clip(_st/float(_et), 0, 1.0)
				
				pos = numbers.lerp_velocity(pos, brain.get_flag(_life, 'camera_lean'), _lerp)[:2]
				pos.append(2)
			else:
				if WORLD_INFO['ticks']-brain.get_flag(_life, 'camera_lean_time')<=20:
					_lerp = .45-numbers.clip((WORLD_INFO['ticks']-brain.get_flag(_life, 'camera_lean_time'))/30.0, 0, .45)
					pos = numbers.lerp_velocity(pos, brain.get_flag(_life, 'camera_lean'), _lerp)[:2]
					pos.append(2)
				else:
					brain.unflag(_life, 'camera_lean')
					brain.unflag(_life, 'camera_lean_time')
	
	CAMERA_POS[0] = int(round(numbers.clip(pos[0]-(MAP_WINDOW_SIZE[0]/2), 0, MAP_SIZE[0]-MAP_WINDOW_SIZE[0])))
	CAMERA_POS[1] = int(round(numbers.clip(pos[1]-(MAP_WINDOW_SIZE[1]/2), 0, MAP_SIZE[1]-MAP_WINDOW_SIZE[1])))
	CAMERA_POS[2] = int(round(pos[2]))
	
	if not _orig_pos == CAMERA_POS:
		gfx.refresh_view('map')
	elif SETTINGS['controlling'] and not alife.brain.get_flag(LIFE[SETTINGS['controlling']], 'redraw') == pos:
		gfx.refresh_view('map')
	
	if SETTINGS['controlling']:
		alife.brain.flag(LIFE[SETTINGS['controlling']], 'redraw', value=pos[:])
Ejemplo n.º 5
0
def manage_combat(life, group_id):
    if has_flag(life, group_id, 'confident'):
        _was_confident = get_flag(life, group_id, 'confident')

        if _was_confident == stats.is_confident(life) and not lfe.ticker(
                life, 'decision_wait', 16):
            return False

    flag(life, group_id, 'confident', stats.is_confident(life))

    _existing_friendlies = get_flag(life, group_id, 'friendlies')
    _existing_targets = get_flag(life, group_id, 'targets')
    _last_focal_point = get_flag(life, group_id, 'last_focal_point')

    if not _existing_friendlies:
        _existing_friendlies = {}

    if not _existing_targets:
        _existing_targets = {}

    for life_id in get_group(life, group_id)['members']:
        if not life_id in _existing_friendlies:
            _existing_friendlies[life_id] = {'updated': -900}

    flag(life, group_id, 'friendlies', _existing_friendlies)

    _checked_targets = []
    for target_id in judgement.get_threats(life):
        if target_id in _existing_targets:
            _existing_targets[target_id]['time'] = 0
        else:
            _existing_targets[target_id] = {
                'time': 0,
                'pos': brain.knows_alife_by_id(life,
                                               target_id)['last_seen_at'][:]
            }

        _checked_targets.append(target_id)

    _enemy_focal_pos = None

    for target_id in _existing_targets:
        if not _enemy_focal_pos:
            _enemy_focal_pos = _existing_targets[target_id]['pos'][:]
        else:
            _enemy_focal_pos = numbers.lerp_velocity(
                _enemy_focal_pos, _existing_targets[target_id]['pos'], 0.5)

        if target_id in _checked_targets:
            continue

        _existing_targets[target_id]['time'] += 1

        if _existing_targets[target_id]['time'] > 100:
            del _existing_targets[target_id]

            continue

    _hostile_chunks = get_flag(life, group_id, 'hostile_chunks')
    _previous_visible_chunks = brain.get_flag(life, 'group_combat_vis_chunks')

    if _previous_visible_chunks and _previous_visible_chunks[
            'from_pos'] == life['pos']:
        _visible_chunks = _previous_visible_chunks['visible_chunks']
    else:
        _visible_chunks = chunks.get_visible_chunks_from(
            life['pos'], life['vision_max'] * .75)

        brain.flag(life,
                   'group_combat_vis_chunks',
                   value={
                       'from_pos': life['pos'][:],
                       'visible_chunks': _visible_chunks
                   })

    if _enemy_focal_pos:
        lfe.clear_ticker(life, 'group_command_reset')

        if not _last_focal_point or numbers.distance(_enemy_focal_pos,
                                                     _last_focal_point) > 30:
            _hostile_chunks = chunks.get_visible_chunks_from(
                (int(round(_enemy_focal_pos[0])),
                 int(round(_enemy_focal_pos[1])), 2), life['vision_max'] * 1.5)

            flag(life, group_id, 'hostile_chunks', _hostile_chunks)
            flag(life, group_id, 'visible_chunks', _visible_chunks)
            flag(life, group_id, 'last_focal_point', _enemy_focal_pos)

    else:
        _ticker = lfe.ticker(life, 'group_command_reset', 48)

        if get_stage(life, group_id) == STAGE_ATTACKING:
            if _ticker:
                set_stage(life, group_id, STAGE_FORMING)
                flag(life, group_id, 'friendlies', None)
                flag(life, group_id, 'strategy', None)
            else:
                manage_strategy(life, group_id)

        return False

    if not get_stage(life, group_id) == STAGE_ATTACKING:
        speech.announce_combat_to_group(life, group_id)
        set_stage(life, group_id, STAGE_ATTACKING)

    if not lfe.ticker(life, 'group_command_rate', 3):
        return False

    _orig_visible_chunks = _visible_chunks[:]

    #TODO: Check distance to threat
    for hostile_chunk_key in _hostile_chunks:
        if hostile_chunk_key in _visible_chunks:
            _visible_chunks.remove(hostile_chunk_key)

    #TODO: Additional stages: PLANNING, EXECUTING
    if _visible_chunks and stats.is_confident(life):
        for target_id in order_spread_out(
                life,
                group_id,
                _visible_chunks,
                filter_by=lambda life_id: WORLD_INFO[
                    'ticks'] - _existing_friendlies[life_id]['updated'] > 100):
            _existing_friendlies[target_id]['updated'] = WORLD_INFO['ticks']
    else:
        _distant_chunk = {'distance': -1, 'chunk_key': None}
        _unchecked_members = get_group(life, group_id)['members'][:]

        for chunk_key in _orig_visible_chunks:
            _distance = numbers.distance((int(round(
                _enemy_focal_pos[0])), int(round(_enemy_focal_pos[1]))),
                                         chunks.get_chunk(chunk_key)['pos'])
            _distance *= numbers.clip(
                numbers.distance(life['pos'], _enemy_focal_pos), 1, 35) / 35.0

            if chunk_key in _visible_chunks:
                _distance *= 2

            for member_id in _unchecked_members:
                if life['id'] == member_id:
                    continue

                _target = brain.knows_alife_by_id(life, member_id)

                if _target['last_seen_time'] <= 25 and chunks.get_chunk_key_at(
                        _target['last_seen_at']) == chunk_key:
                    _distance *= (2.5 * (1 - (numbers.clip(
                        _target['last_seen_time'], 0, 25) / 25.0)))

            if _distance > _distant_chunk['distance']:
                _distant_chunk['distance'] = _distance
                _distant_chunk['chunk_key'] = chunk_key

        if _distant_chunk['chunk_key']:
            for target_id in order_move_to(
                    life,
                    group_id,
                    _distant_chunk['chunk_key'],
                    filter_by=lambda life_id: WORLD_INFO['ticks'] -
                    _existing_friendlies[life_id]['updated'] > 100):
                _existing_friendlies[target_id]['updated'] = WORLD_INFO[
                    'ticks']

        return False
Ejemplo n.º 6
0
def manage_combat(life, group_id):
	if has_flag(life, group_id, 'confident'):
		_was_confident = get_flag(life, group_id, 'confident')
		
		if _was_confident == stats.is_confident(life) and not lfe.ticker(life, 'decision_wait', 16):
			return False
	
	flag(life, group_id, 'confident', stats.is_confident(life))
	
	_existing_friendlies = get_flag(life, group_id, 'friendlies')
	_existing_targets = get_flag(life, group_id, 'targets')
	_last_focal_point = get_flag(life, group_id, 'last_focal_point')
	
	if not _existing_friendlies:
		_existing_friendlies = {}
	
	if not _existing_targets:
		_existing_targets = {}
	
	for life_id in get_group(life, group_id)['members']:
		if not life_id in _existing_friendlies:
			_existing_friendlies[life_id] = {'updated': -900}
	
	flag(life, group_id, 'friendlies', _existing_friendlies)
	
	_checked_targets = []
	for target_id in judgement.get_threats(life):
		if target_id in _existing_targets:
			_existing_targets[target_id]['time'] = 0
		else:
			_existing_targets[target_id] = {'time': 0, 'pos': brain.knows_alife_by_id(life, target_id)['last_seen_at'][:]}
		
		_checked_targets.append(target_id)

	_enemy_focal_pos = None

	for target_id in _existing_targets:
		if not _enemy_focal_pos:
			_enemy_focal_pos = _existing_targets[target_id]['pos'][:]
		else:
			_enemy_focal_pos = numbers.lerp_velocity(_enemy_focal_pos, _existing_targets[target_id]['pos'], 0.5)
		
		if target_id in _checked_targets:
			continue
		
		_existing_targets[target_id]['time'] += 1
		
		if _existing_targets[target_id]['time']>100:
			del _existing_targets[target_id]
			
			continue
	
	_hostile_chunks = get_flag(life, group_id, 'hostile_chunks')
	_previous_visible_chunks = brain.get_flag(life, 'group_combat_vis_chunks')
	
	if _previous_visible_chunks and _previous_visible_chunks['from_pos'] == life['pos']:
		_visible_chunks = _previous_visible_chunks['visible_chunks']
	else:
		_visible_chunks = chunks.get_visible_chunks_from(life['pos'], life['vision_max']*.75)
		
		brain.flag(life, 'group_combat_vis_chunks', value={'from_pos': life['pos'][:],
		                                                   'visible_chunks': _visible_chunks})
	
	if _enemy_focal_pos:
		lfe.clear_ticker(life, 'group_command_reset')
		
		if not _last_focal_point or numbers.distance(_enemy_focal_pos, _last_focal_point)>30:
			_hostile_chunks = chunks.get_visible_chunks_from((int(round(_enemy_focal_pos[0])), int(round(_enemy_focal_pos[1])), 2), life['vision_max']*1.5)
			
			flag(life, group_id, 'hostile_chunks', _hostile_chunks)
			flag(life, group_id, 'visible_chunks', _visible_chunks)
			flag(life, group_id, 'last_focal_point', _enemy_focal_pos)
			
	else:
		_ticker = lfe.ticker(life, 'group_command_reset', 48)
		
		if get_stage(life, group_id) == STAGE_ATTACKING:
			if _ticker:
				set_stage(life, group_id, STAGE_FORMING)
				flag(life, group_id, 'friendlies', None)
				flag(life, group_id, 'strategy', None)
			else:
				manage_strategy(life, group_id)
		
		return False
	
	if not get_stage(life, group_id) == STAGE_ATTACKING:
		speech.announce_combat_to_group(life, group_id)
		set_stage(life, group_id, STAGE_ATTACKING)
	
	if not lfe.ticker(life, 'group_command_rate', 3):
		return False
	
	_orig_visible_chunks = _visible_chunks[:]
	
	#TODO: Check distance to threat
	for hostile_chunk_key in _hostile_chunks:
		if hostile_chunk_key in _visible_chunks:
			_visible_chunks.remove(hostile_chunk_key)
		
	#TODO: Additional stages: PLANNING, EXECUTING
	if _visible_chunks and stats.is_confident(life):
		for target_id in order_spread_out(life, group_id, _visible_chunks, filter_by=lambda life_id: WORLD_INFO['ticks']-_existing_friendlies[life_id]['updated']>100):
			_existing_friendlies[target_id]['updated'] = WORLD_INFO['ticks']
	else:
		_distant_chunk = {'distance': -1, 'chunk_key': None}
		_unchecked_members = get_group(life, group_id)['members'][:]
		
		for chunk_key in _orig_visible_chunks:
			_distance = numbers.distance((int(round(_enemy_focal_pos[0])), int(round(_enemy_focal_pos[1]))), chunks.get_chunk(chunk_key)['pos'])
			_distance *= numbers.clip(numbers.distance(life['pos'], _enemy_focal_pos), 1, 35)/35.0
			
			if chunk_key in _visible_chunks:
				_distance *= 2
			
			for member_id in _unchecked_members:
				if life['id'] == member_id:
					continue
				
				_target = brain.knows_alife_by_id(life, member_id)
				
				if _target['last_seen_time'] <= 25 and chunks.get_chunk_key_at(_target['last_seen_at']) == chunk_key:
					_distance *= (2.5*(1-(numbers.clip(_target['last_seen_time'], 0, 25)/25.0)))
			
			if _distance>_distant_chunk['distance']:
				_distant_chunk['distance'] = _distance
				_distant_chunk['chunk_key'] = chunk_key
		
		if _distant_chunk['chunk_key']:
			for target_id in order_move_to(life, group_id, _distant_chunk['chunk_key'], filter_by=lambda life_id: WORLD_INFO['ticks']-_existing_friendlies[life_id]['updated']>100):
				_existing_friendlies[target_id]['updated'] = WORLD_INFO['ticks']
		
		return False