コード例 #1
0
ファイル: scripting.py プロジェクト: athros/Reactor-3
def execute(script, **kvargs):
	for function in script:
		_args = parse_arguments(script[function], **kvargs)
		
		if function == 'CREATE_AND_OWN_ITEM':
			_i = items.create_item(_args[0], position=_args[1])
			life.add_item_to_inventory(kvargs['owner'], _i)
		elif function == 'DELETE':
			items.delete_item(ITEMS[kvargs['item_uid']])
		elif function == 'LIGHT_FOLLOW':
			_item = ITEMS[kvargs['item_uid']]
			
			effects.create_light(items.get_pos(kvargs['item_uid']),
			                     (255, 255, 255),
			                     _item['brightness'],
			                     _item['light_shake'],
			                     follow_item=kvargs['item_uid'])
		elif function == 'LIGHT_FOLLOW_REMOVE':
			_item = ITEMS[kvargs['item_uid']]
			
			effects.delete_light_at(items.get_pos(kvargs['item_uid']))
		elif function == 'TOGGLE_BLOCK':
			_item = ITEMS[kvargs['item_uid']]
			
			if _item['blocking']:
				_item['blocking'] = False
			else:
				_item['blocking'] = True
		else:
			logging.error('Script: \'%s\' is not a valid function.' % function)
コード例 #2
0
def execute(script, **kvargs):
    for function in script:
        _args = parse_arguments(script[function], **kvargs)

        if function == 'CREATE_AND_OWN_ITEM':
            _i = items.create_item(_args[0], position=_args[1])
            life.add_item_to_inventory(kvargs['owner'], _i)
        elif function == 'DELETE':
            items.delete_item(ITEMS[kvargs['item_uid']])
        elif function == 'LIGHT_FOLLOW':
            _item = ITEMS[kvargs['item_uid']]

            effects.create_light(items.get_pos(kvargs['item_uid']),
                                 (255, 255, 255),
                                 _item['brightness'],
                                 _item['light_shake'],
                                 follow_item=kvargs['item_uid'])
        elif function == 'LIGHT_FOLLOW_REMOVE':
            _item = ITEMS[kvargs['item_uid']]

            effects.delete_light_at(items.get_pos(kvargs['item_uid']))
        elif function == 'TOGGLE_BLOCK':
            _item = ITEMS[kvargs['item_uid']]

            if _item['blocking']:
                _item['blocking'] = False
            else:
                _item['blocking'] = True
        else:
            logging.error('Script: \'%s\' is not a valid function.' % function)
コード例 #3
0
ファイル: items.py プロジェクト: hovatterz/Reactor-3
def tick_item(item):
	if 'CAN_BURN' in item['flags'] and item['burning'] and item['owner']:
		life.burn(LIFE[item['owner']], item['burning'])
	
	if 'stored_in' in item or is_item_owned(item['uid']):
		return False
	
	_z_max = numbers.clip(item['pos'][2], 0, maputils.get_map_size(WORLD_INFO['map'])[2]-1)
	if item['velocity'][:2] == [0.0, 0.0] and WORLD_INFO['map'][item['pos'][0]][item['pos'][1]][_z_max]:
		return False
	
	_x = item['pos'][0]
	_y = item['pos'][1]
	
	#_view = gfx.get_view_by_name('map')
	#if 0<=_x<_view['draw_size'][0] and 0<=_y<_view['draw_size'][1]:
	if gfx.position_is_in_frame((_x, _y)):
		gfx.refresh_view_position(_x-CAMERA_POS[0], _y-CAMERA_POS[1], 'map')
	
	item['realpos'][0] += item['velocity'][0]
	item['realpos'][1] += item['velocity'][1]
	_break = False
	_line = drawing.diag_line(item['pos'],(int(round(item['realpos'][0])),int(round(item['realpos'][1]))))
	
	if not _line:
		item['velocity'][2] -= item['gravity']
		item['realpos'][2] = item['realpos'][2]+item['velocity'][2]
		item['pos'][2] = int(round(item['realpos'][2]))
		
		if item['pos'][0]<0 or item['pos'][0]>=MAP_SIZE[0] or item['pos'][1]<0 or item['pos'][1]>=MAP_SIZE[1]:
			delete_item(item)
			return False
		
		_z_min = numbers.clip(int(round(item['realpos'][2])), 0, maputils.get_map_size(WORLD_INFO['map'])[2]-1)
		if collision_with_solid(item, [item['pos'][0], item['pos'][1], _z_min]):
			pos = item['pos'][:]
			_break = True
		
		create_effects(item, item['pos'], item['realpos'][2], _z_min)
	
	for pos in _line:
		item['realpos'][2] += item['velocity'][2]
		item['velocity'][2] -= item['velocity'][2]*item['gravity']
		
		if 'drag' in item:
			_drag = item['drag']
		else:
			_drag = item['gravity']
			logging.warning('Improper use of gravity.')
			
		_min_x_vel, _min_y_vel, _max_x_vel, _max_y_vel = get_min_max_velocity(item)
		
		if 0<item['velocity'][0]<0.1 or -.1<item['velocity'][0]<0:
			item['velocity'][0] = 0
		
		if 0<item['velocity'][1]<0.1 or -.1<item['velocity'][1]<0:
			item['velocity'][1] = 0
		
		item['velocity'][0] -= numbers.clip(item['velocity'][0]*_drag, _min_x_vel, _max_x_vel)
		item['velocity'][1] -= numbers.clip(item['velocity'][1]*_drag, _min_y_vel, _max_y_vel)
		item['speed'] -= numbers.clip(item['speed']*_drag, 0, 100)
		
		if 0>pos[0] or pos[0]>=MAP_SIZE[0] or 0>pos[1] or pos[1]>=MAP_SIZE[1] or item['realpos'][2]<0 or item['realpos'][2]>=MAP_SIZE[2]-1:
			logging.warning('Item OOM: %s', item['uid'])
			delete_item(item)
			return False
		
		if collision_with_solid(item, [pos[0], pos[1], int(round(item['realpos'][2]))]):
			if item['type'] == 'bullet':
				effects.create_light(item['pos'], (255, 0, 0), 9, 0, fade=0.1)
			
			logging.debug('Item #%s hit a wall.' % item['uid'])
			
			return False
		
		if item['type'] == 'bullet':
			for _life in [LIFE[i] for i in LIFE]:
				if _life['id'] == item['shot_by'] or _life['dead']:
					continue					
				
				if _life['pos'][0] == pos[0] and _life['pos'][1] == pos[1] and _life['pos'][2] == int(round(item['realpos'][2])):
					remove_from_chunk(item)
					item['pos'] = [pos[0],pos[1],_life['pos'][2]]
					add_to_chunk(item)
					life.damage_from_item(_life,item,60)
					
					if item['uid'] in ITEMS:
						delete_item(item)
					
					return False
			
		if _break:
			break
		
		#_z_max = numbers.clip(int(round(item['realpos'][2]))+1, 0, maputils.get_map_size(WORLD_INFO['map'])[2]-1)
		#if MAP[pos[0]][pos[1]][_z_max]:
		#	item['velocity'][0] = 0
		#	item['velocity'][1] = 0
		#	item['velocity'][2] = 0
		#	item['pos'] = [pos[0],pos[1],item['pos'][2]-1]
		#
		#	print 'LANDED',item['pos']	
		#	_break = True
		#	break
	
		_z_min = numbers.clip(int(round(item['realpos'][2])), 0, maputils.get_map_size(WORLD_INFO['map'])[2]-1)
		if collision_with_solid(item, [pos[0], pos[1], _z_min]):
			_break = True
			break
		
		create_effects(item, pos, item['realpos'][2], _z_min)
	
	remove_from_chunk(item)
	
	if _break:
		item['pos'][0] = int(pos[0])
		item['pos'][1] = int(pos[1])
		item['pos'][2] = int(round(item['realpos'][2]))
	else:
		item['pos'][0] = int(round(item['realpos'][0]))
		item['pos'][1] = int(round(item['realpos'][1]))
		item['pos'][2] = int(round(item['realpos'][2]))
	
	add_to_chunk(item)
	
	_x = item['pos'][0]
	_y = item['pos'][1]
	
	if gfx.position_is_in_frame((_x, _y)):
		gfx.refresh_view_position(_x-CAMERA_POS[0], _y-CAMERA_POS[1], 'map')

	if item['pos'][0] < 0 or item['pos'][0] > MAP_SIZE[0] \
          or item['pos'][1] < 0 or item['pos'][1] > MAP_SIZE[1]:
		delete_item(item)
		return False
			
	#elif _break:
	#	maps.refresh_chunk(life.get_current_chunk_id(item))

	_min_x_vel, _min_y_vel, _max_x_vel, _max_y_vel = get_min_max_velocity(item)
	
	if 0<item['velocity'][0]<0.1 or -.1<item['velocity'][0]<0:
		item['velocity'][0] = 0
	
	if 0<item['velocity'][1]<0.1 or -.1<item['velocity'][1]<0:
		item['velocity'][1] = 0
	
	#TODO: This isn't gravity...
	if 'drag' in item:
		_drag = item['drag']
	else:
		_drag = item['gravity']
		logging.warning('Improper use of gravity.')
	
	item['velocity'][0] -= numbers.clip(item['velocity'][0]*_drag, _min_x_vel, _max_x_vel)
	item['velocity'][1] -= numbers.clip(item['velocity'][1]*_drag, _min_y_vel, _max_y_vel)
	item['speed'] -= numbers.clip(item['speed']*_drag, 0, 100)
コード例 #4
0
ファイル: items.py プロジェクト: hovatterz/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'])
	
	alife.noise.create(item['pos'], item['damage']['force']*100, 'an explosion', 'a low rumble')
	
	if item['damage']['force']:
		effects.create_light(item['pos'], (255, 69, 0), item['damage']['force']*6, 1, fade=3)
		effects.create_smoke_cloud(item['pos'],
			                       item['damage']['force']*6,
			                       age=.8,
			                       factor_distance=True)
		
		for i in range(random.randint(1, 3)):
			effects.create_smoke_streamer(item['pos'],
				                          3+random.randint(0, 2),
				                          (item['damage']['force']*2)+random.randint(3, 6),
				                          color=tcod.color_lerp(tcod.gray, tcod.crimson, random.uniform(0.1, 0.3)))
	
	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 numbers.distance(
	
	#TODO: Dirty hack
	for life_id in LIFE:
		_limbs = LIFE[life_id]['body'].keys()
		
		if not _limbs:
			continue
		
		_force = numbers.clip((item['damage']['force']*2)-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 = numbers.direction_to(item['pos'], LIFE[life_id]['pos'])
		
		#TODO: Intelligent(?) limb groups?
		_distance = 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())
			
			#ex: memory(life, 'shot at by (missed)', target=item['owner'], danger=3, trust=-10)
			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'], trust=-10, danger=3)
			
			#for _limb in _limbs:
			life.add_wound(LIFE[life_id], _limb, force_velocity=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 = 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)
コード例 #5
0
ファイル: weapons.py プロジェクト: lawanfalalu/Reactor-3
def fire(life, target, limb=None):
    #TODO: Don't breathe this!
    weapon = get_weapon_to_fire(life)

    if not weapon:
        return False

    _aim_with_limb = None
    for hand in life['hands']:
        if weapon['uid'] in lfe.get_limb(life, hand)['holding']:
            _aim_with_limb = hand

    _ooa = False
    _feed_uid = get_feed(weapon)

    if not _feed_uid:
        if 'player' in life:
            gfx.message('The weapon is unloaded.')

        _ooa = True
        return False

    _feed = items.get_item_from_uid(_feed_uid)

    if not _feed or (_feed and not _feed['rounds']):
        if 'player' in life:
            gfx.message('*Click* (You are out of ammo.)')

        _ooa = True
        return False

    _bullet_deviation = (1 - weapon['accuracy']) + life['recoil']
    _deviation_mod = SETTINGS['aim_difficulty'] * (1 - (
        (life['stats']['firearms'] / 10.0) * SETTINGS['firearms_skill_mod']))
    _direction_deviation = (_bullet_deviation *
                            SETTINGS['aim_difficulty']) * _deviation_mod

    life['recoil'] = bad_numbers.clip(
        life['recoil'] + (weapon['recoil'] * get_stance_recoil_mod(life)), 0.0,
        1.0)

    _bullet_direction = bad_numbers.direction_to(life['pos'], target) + (
        random.uniform(-_direction_deviation, _direction_deviation))

    alife.noise.create(life['pos'],
                       120,
                       '%s fire' % weapon['name'],
                       'something discharge',
                       target=life['id'])

    #TODO: Clean this up...
    _bullet = items.get_item_from_uid(_feed['rounds'].pop())
    _bullet['pos'] = life['pos'][:]
    _bullet['start_pos'] = life['pos'][:]
    _bullet['owner'] = None
    _bullet['shot_by'] = life['id']
    _bullet['aim_at_limb'] = limb

    items.add_to_chunk(_bullet)

    if gfx.position_is_in_frame(life['pos']) or 'player' in life:
        effects.create_light(life['pos'], tcod.yellow, 7, 1, fade=3.2)
        effects.create_light(_bullet['pos'],
                             tcod.yellow,
                             7,
                             .9,
                             fade=.65,
                             follow_item=_bullet['uid'])
        effects.create_smoke_cloud(life['pos'], 3, color=tcod.light_gray)
        effects.create_smoke(life['pos'], color=tcod.yellow)

    _bullet['accuracy'] = int(
        round(get_accuracy(life, weapon['uid'], limb=_aim_with_limb)))

    print 'ACCURACY', _bullet['accuracy']

    del _bullet['parent']
    items.move(_bullet, _bullet_direction, _bullet['max_speed'])
    _bullet['start_velocity'] = _bullet['velocity'][:]
    items.tick_item(_bullet)

    for _life in [LIFE[i] for i in LIFE]:
        if _life['pos'][0] == target[0] and _life['pos'][1] == target[1]:
            life['aim_at'] = _life['id']
            break

    if len(lfe.find_action(life, matches=[{'action': 'shoot'}])) == 1:
        life['firing'] = None
コード例 #6
0
ファイル: weapons.py プロジェクト: hovatterz/Reactor-3
def fire(life, target, limb=None):
	#TODO: Don't breathe this!
	weapon = get_weapon_to_fire(life)
	
	if not weapon:
		return False
	
	_aim_with_limb = None
	for hand in life['hands']:
		if weapon['uid'] in lfe.get_limb(life, hand)['holding']:
			_aim_with_limb = hand
	
	_ooa = False
	_feed_uid = get_feed(weapon)
	
	if not _feed_uid:
		if 'player' in life:
			gfx.message('The weapon is unloaded.')
		
		_ooa = True
		return False
	
	_feed = items.get_item_from_uid(_feed_uid)
	
	if not _feed or (_feed and not _feed['rounds']):
		if 'player' in life:
			gfx.message('*Click* (You are out of ammo.)')
		
		_ooa = True
		return False
	
	direction = numbers.direction_to(life['pos'],target)+(random.uniform(-life['recoil'], life['recoil']))
	
	alife.noise.create(life['pos'], 120, '%s fire' % weapon['name'], 'something discharge')
	
	#TODO: Clean this up...
	_bullet = items.get_item_from_uid(_feed['rounds'].pop())
	_bullet['pos'] = life['pos'][:]
	_bullet['start_pos'] = life['pos'][:]
	_bullet['owner'] = None
	_bullet['shot_by'] = life['id']
	_bullet['aim_at_limb'] = limb
	
	life['recoil'] += _bullet['recoil']*(weapon['recoil']*get_stance_recoil_mod(life))
	
	items.add_to_chunk(_bullet)
	
	if gfx.position_is_in_frame(life['pos']):
		effects.create_light(life['pos'], tcod.yellow, 7, 1, fade=3.5)
		effects.create_light(_bullet['pos'], tcod.yellow, 7, 1, fade=0.65, follow_item=_bullet['uid'])
		effects.create_smoke_cloud(life['pos'], 3, color=tcod.light_gray)
		effects.create_smoke(life['pos'], color=tcod.yellow)
	
	_bullet['accuracy'] = int(round(get_accuracy(life, weapon['uid'], limb=_aim_with_limb)))
	del _bullet['parent']
	items.move(_bullet, direction, _bullet['max_speed'])
	_bullet['start_velocity'] = _bullet['velocity'][:]
	items.tick_item(_bullet)
	
	for _life in [LIFE[i] for i in LIFE]:
		if _life['pos'][0] == target[0] and _life['pos'][1] == target[1]:
			life['aim_at'] = _life['id']
			break
	
	if len(lfe.find_action(life, matches=[{'action': 'shoot'}])) == 1:
		life['firing'] = None