Exemplo n.º 1
0
def create_snapshot(life):
	_snapshot = {'damage': lfe.get_damage(life),
		'appearance': 0,
		'visible_items': [],
		'generated': time.time()}

	for item in lfe.get_all_visible_items(life):
		_snapshot['visible_items'].append(str(item))
	
	return _snapshot
Exemplo n.º 2
0
def create_snapshot(life):
    _snapshot = {
        'damage': lfe.get_damage(life),
        'appearance': 0,
        'visible_items': [],
        'generated': time.time()
    }

    for item in lfe.get_all_visible_items(life):
        _snapshot['visible_items'].append(str(item))

    return _snapshot
Exemplo n.º 3
0
def get_ranged_combat_rating_of_target(life, life_id):
    target = LIFE[life_id]
    _score = 1

    for item in [ITEMS[i] for i in lfe.get_all_visible_items(target) if i in ITEMS]:
        if not logic.matches(item, {"type": "gun"}):
            continue

        if numbers.distance(life["pos"], target["pos"]) > sight.get_vision(life) / 2:
            _score += item["accuracy"] / 2
        else:
            _score += item["accuracy"]

    return _score
Exemplo n.º 4
0
def react_to_tension(life, life_id):
    if brain.knows_alife_by_id(life, life_id)['alignment'] in ['hostile']:
        return False

    if life['group'] and not groups.is_leader(
            life, life['group'], life['id']) and groups.get_leader(
                life, life['group']):
        if sight.can_see_target(life, groups.get_leader(
                life, life['group'])) and sight.can_see_target(
                    LIFE[life_id], groups.get_leader(life, life['group'])):
            return False

    _disarm = brain.get_alife_flag(life, life_id, 'disarm')

    if _disarm:
        #For now...
        if not sight.can_see_position(life, LIFE[life_id]['pos']):
            groups.announce(life,
                            life['group'],
                            'attacked_by_hostile',
                            filter_if=lambda life_id: brain.knows_alife_by_id(
                                life, life_id)['last_seen_time'] <= 30,
                            target_id=life_id)

            return False

        for item_uid in lfe.get_all_visible_items(LIFE[life_id]):
            if ITEMS[item_uid]['type'] == 'gun':
                break
        else:
            brain.unflag_alife(life, life_id, 'disarm')
            speech.start_dialog(life, life_id, 'clear_drop_weapon')

            return False

        _time_elapsed = WORLD_INFO['ticks'] - _disarm

        if _time_elapsed > 135 and not speech.has_sent(life, life_id,
                                                       'threaten'):
            speech.start_dialog(life, life_id, 'threaten')
            speech.send(life, life_id, 'threaten')
        elif _time_elapsed > 185:
            speech.start_dialog(life, life_id, 'establish_hostile')
    elif not speech.has_sent(life, life_id, 'confront'):
        speech.start_dialog(life, life_id, 'confront')
        speech.send(life, life_id, 'confront')
Exemplo n.º 5
0
def get_ranged_combat_rating_of_target(life, life_id, inventory_check=True):
	target = LIFE[life_id]
	_score = 1
	_score_mod = 1
	
	_items = [ITEMS[i] for i in lfe.get_all_visible_items(target) if i in ITEMS and logic.matches(ITEMS[i], {'type': 'gun'})]
	
	if not _items and inventory_check:
		_items = [i for i in lfe.get_all_inventory_items(target) if i['uid'] in ITEMS and logic.matches(i, {'type': 'gun'})]
		_score_mod = .5
	
	for item in _items:
		if bad_numbers.distance(life['pos'], target['pos']) > combat.get_engage_distance(target):
			_score += item['accuracy']/2
		else:
			_score += item['accuracy']
	
	if _score:
		_score += 2*(life['stats']['firearms']/10.0)
	
	return _score*_score_mod
Exemplo n.º 6
0
def react_to_tension(life, life_id):
	if brain.knows_alife_by_id(life, life_id)['alignment'] in ['hostile']:
		return False
	
	if life['group'] and not groups.is_leader(life, life['group'], life['id']) and groups.get_leader(life, life['group']):
		if sight.can_see_target(life, groups.get_leader(life, life['group'])) and sight.can_see_target(LIFE[life_id], groups.get_leader(life, life['group'])):
			return False
	
	_disarm = brain.get_alife_flag(life, life_id, 'disarm')
	
	if _disarm:
		#For now...
		if not sight.can_see_position(life, LIFE[life_id]['pos']):
			groups.announce(life,
			                life['group'],
			                'attacked_by_hostile',
			                filter_if=lambda life_id: brain.knows_alife_by_id(life, life_id)['last_seen_time']<=30,
			                target_id=life_id)
			
			return False
		
		for item_uid in lfe.get_all_visible_items(LIFE[life_id]):
			if ITEMS[item_uid]['type'] == 'gun':
				break
		else:
			brain.unflag_alife(life, life_id, 'disarm')
			speech.start_dialog(life, life_id, 'clear_drop_weapon')
			
			return False
		
		_time_elapsed = WORLD_INFO['ticks']-_disarm
		
		if _time_elapsed>135 and not speech.has_sent(life, life_id, 'threaten'):
			speech.start_dialog(life, life_id, 'threaten')
			speech.send(life, life_id, 'threaten')
		elif _time_elapsed>185:
			speech.start_dialog(life, life_id, 'establish_hostile')
	elif not speech.has_sent(life, life_id, 'confront'):
		speech.start_dialog(life, life_id, 'confront')
		speech.send(life, life_id, 'confront')
Exemplo n.º 7
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)
Exemplo n.º 8
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)
Exemplo n.º 9
0
def bullet_hit(life, bullet, limb):
	_owner = LIFE[bullet['shot_by']]
	_actual_limb = lfe.get_limb(life, limb)
	_items_to_check = []
	_msg = []
	
	#if 'player' in _owner:
	#	if bullet['aim_at_limb'] == limb:
	#		_hit = True
	#		_msg = ['The round hits']
	#	elif not limb in life['body']:
	#		return 'The round misses entirely!'
	#	else:
	#		_msg = ['The round misses slightly']
	#	_detailed = True
	#
	#elif 'player' in life:
	#	_msg = ['The round hits']
	#else:
	#	_msg = ['%s hits %s\'s %s' % (items.get_name(bullet), life['name'][0], limb)]
	
	for item_uid in lfe.get_items_attached_to_limb(life, limb):
		_items_to_check.append({'item': item_uid, 'visible': True})
		_item = items.get_item_from_uid(item_uid)
		
		if 'storing' in _item:
			for item_in_container_uid in _item['storing']:
				_chance_of_hitting_item = _item['capacity']/float(_item['max_capacity'])
				
				if random.uniform(0, 1)<_chance_of_hitting_item:
					break
				
				_items_to_check.append({'item': item_in_container_uid, 'visible': False})
		
	for entry in _items_to_check:
		_item = items.get_item_from_uid(entry['item'])
		_item_damage = get_puncture_value(bullet, _item, target_structure_name=_item['name'])
		_item['thickness'] = bad_numbers.clip(_item['thickness']-_item_damage, 0, _item['max_thickness'])
		
		if 'material' in _item and not _item['material'] == 'cloth':
			_speed_mod = _item_damage
			_can_stop = True
			
			bullet['speed'] *= _speed_mod
			bullet['velocity'][0] *= _speed_mod
			bullet['velocity'][1] *= _speed_mod
		else:
			_can_stop = False
		
		if not _item['thickness']:
			if _item['uid'] in lfe.get_all_visible_items(life):
				if 'player' in _owner:
					_msg.append('%s\'s %s is destroyed!' % (' '.join(life['name']), _item['name']))

			if _item['type'] == 'explosive':
				items.explode(_item)
			else:
				items.delete_item(_item)
		#else:
		#	if bullet['speed']<=1 and _can_stop:
		#		#if 'player' in _owner:
		#		#	_msg.append(', lodging itself in %s' % items.get_name(_item))
		#		#_ret_string = own_language(life, _msg)
		#	
		#		if _ret_string.endswith('!'):
		#			return _ret_string
		#		else:
		#			return _ret_string+'.'
		#	#else:
		#	#	if 'material' in _item:
		#	#		if _item['material'] == 'metal':
		#	#			_msg.append(', puncturing the %s' % _item['name'])
		#	#		else:
		#	#			_msg.append(', ripping through the %s' % _item['name'])
	
	_damage = get_puncture_value(bullet, _actual_limb, target_structure_name=limb)
	_actual_limb['thickness'] = bad_numbers.clip(_actual_limb['thickness']-_damage, 0, _actual_limb['max_thickness'])

	if not _actual_limb['thickness']:
		lfe.sever_limb(life, limb, (0, 0, 0))
	
	_damage_mod = 1-(_actual_limb['thickness']/float(_actual_limb['max_thickness']))
	
	if limb in life['body']:
		_msg.append(lfe.add_wound(life, limb, cut=_damage*_damage_mod, impact_velocity=bullet['velocity']))
	
	#_ret_string = own_language(life, _msg)
	
	return ' '.join(_msg)