Example #1
0
def tick_effects(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
	
	create_effects(item, item['pos'], item['pos'][2], 2)
Example #2
0
def tick_effects(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

    create_effects(item, item['pos'], item['pos'][2], 2)
Example #3
0
def calculate_fire(fire):
	_neighbor_intensity = 0
	_neighbor_lit = False
	
	for x in range(-1, 2):
		_x = fire['pos'][0]+x
		
		if _x<0 or _x>=MAP_SIZE[0]:
			continue
		
		for y in range(-1, 2):
			if not x and not y:
				continue
			
			_y = fire['pos'][1]+y
			
			if _y<0 or _y>=MAP_SIZE[1]:
				continue
			
			_effects = [EFFECTS[eid] for eid in EFFECT_MAP[_x][_y] if EFFECTS[eid]['type'] == 'fire']
			for effect in _effects:
				_neighbor_intensity += effect['intensity']
				
				if 'light' in effect:
					_neighbor_lit = True
			
			if not _effects:
				_tile = WORLD_INFO['map'][_x][_y][fire['pos'][2]]
				_raw_tile = tiles.get_raw_tile(_tile)
				
				_heat = tiles.get_flag(WORLD_INFO['map'][_x][_y][fire['pos'][2]], 'heat')
				_current_burn = int(round(fire['intensity']))
				_max_burn = int(round(_current_burn*.23))
				
				if tiles.flag(_tile, 'heat', numbers.clip(_heat+(fire['intensity']*.01), 0, 8))>=_raw_tile['burnable']:
					if _raw_tile['burnable'] and _max_burn:
						create_fire((_x, _y, fire['pos'][2]), intensity=random.randint(1, numbers.clip(1+_max_burn, 2, 8)))
	
	_intensity = ((64-_neighbor_intensity)/64.0)*random.uniform(0, SETTINGS['fire burn rate'])
	fire['intensity'] -= _intensity
	
	for life in [LIFE[life_id] for life_id in LIFE_MAP[fire['pos'][0]][fire['pos'][1]]]:
		lfe.burn(life, fire['intensity'])
	
	for item in items.get_items_at(fire['pos']):
		items.burn(item, fire['intensity'])
	
	update_effect(fire)
	
	if fire['intensity'] <= 0.25:
		unregister_effect(fire)
	
	if 'light' in fire:
		fire['light']['brightness'] -= numbers.clip(_intensity*.015, 0, 5)
	elif not _neighbor_lit:
		fire['light'] = create_light(fire['pos'], (255, 69, 0), 17*(fire['intensity']/8.0), 0.25)
Example #4
0
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)
Example #5
0
def calculate_fire(fire):
    _neighbor_intensity = 0
    _neighbor_lit = False

    for x in range(-1, 2):
        _x = fire['pos'][0] + x

        if _x < 0 or _x >= MAP_SIZE[0]:
            continue

        for y in range(-1, 2):
            if not x and not y:
                continue

            _y = fire['pos'][1] + y

            if _y < 0 or _y >= MAP_SIZE[1]:
                continue

            maps.load_cluster_at_position_if_needed((_x, _y, fire['pos'][2]))

            _effects = [
                EFFECTS[eid] for eid in EFFECT_MAP[_x][_y]
                if EFFECTS[eid]['type'] == 'fire'
            ]
            for effect in _effects:
                _neighbor_intensity += effect['intensity']

                if 'light' in effect:
                    _neighbor_lit = True

            if not _effects:
                _tile = WORLD_INFO['map'][_x][_y][fire['pos'][2]]
                _raw_tile = tiles.get_raw_tile(_tile)

                _heat = tiles.get_flag(
                    WORLD_INFO['map'][_x][_y][fire['pos'][2]], 'heat')
                _current_burn = int(round(fire['intensity']))
                _max_burn = int(round(_current_burn * .23))

                if tiles.flag(
                        _tile, 'heat',
                        bad_numbers.clip(_heat + (fire['intensity'] * .8), 0,
                                         8)) >= _raw_tile['burnable']:
                    if _raw_tile['burnable'] and _max_burn:
                        create_fire((_x, _y, fire['pos'][2]),
                                    intensity=random.randint(
                                        1,
                                        bad_numbers.clip(1 + _max_burn, 2, 8)))

    _intensity = ((64 - _neighbor_intensity) / 64.0) * random.uniform(
        0, SETTINGS['fire burn rate'])
    fire['intensity'] -= _intensity

    if random.randint(0, 1):
        _pos = fire['pos'][:2]
        _pos.append(2)

        create_smoke(_pos,
                     direction=random.randint(0, 369),
                     speed=random.uniform(0.3, 0.85),
                     age=0.2,
                     max_opacity=0.9,
                     decay=0.03)

    for life in [
            LIFE[life_id]
            for life_id in LIFE_MAP[fire['pos'][0]][fire['pos'][1]]
    ]:
        lfe.burn(life, fire['intensity'])

    for item in items.get_items_at(fire['pos']):
        items.burn(item, fire['intensity'])

    update_effect(fire)

    if fire['intensity'] <= 0.25:
        unregister_effect(fire)

    if 'light' in fire:
        fire['light']['brightness'] -= bad_numbers.clip(
            _intensity * .015, 0, 5)
    elif not _neighbor_lit:
        fire['light'] = create_light(fire['pos'], (255, 69, 0),
                                     17 * (fire['intensity'] / 8.0), 0.25)