예제 #1
0
파일: threads.py 프로젝트: athros/Reactor-3
    def check_chunks(self, force=False):
        if not force and WORLD_INFO["ticks"] - self.last_checked < self.check_every:
            return False

        self.last_checked = WORLD_INFO["ticks"]

        for life in [l for l in LIFE.values() if l["online"]]:
            _x_min = numbers.clip(life["pos"][0] - MAP_WINDOW_SIZE[0], 0, MAP_SIZE[0] - 1 - MAP_WINDOW_SIZE[0])
            _y_min = numbers.clip(life["pos"][1] - MAP_WINDOW_SIZE[1], 0, MAP_SIZE[1] - 1 - MAP_WINDOW_SIZE[1])
            _x_max = numbers.clip(life["pos"][0] + MAP_WINDOW_SIZE[0], 0, MAP_SIZE[0] - 1)
            _y_max = numbers.clip(life["pos"][1] + MAP_WINDOW_SIZE[1], 0, MAP_SIZE[1] - 1)
            _refresh = False

            for y in range(_y_min, _y_max, WORLD_INFO["chunk_size"]):
                for x in range(_x_min, _x_max, WORLD_INFO["chunk_size"]):
                    maps.load_cluster_at_position_if_needed((x, y))

                    SETTINGS["loading"] = True

                    if "player" in life:
                        _refresh = True

            if _refresh:
                gfx.refresh_view("map")

        SETTINGS["loading"] = False
예제 #2
0
	def check_chunks(self, force=False):
		if not force and WORLD_INFO['ticks']-self.last_checked<self.check_every:
			return False
		
		self.last_checked = WORLD_INFO['ticks']
		
		for life in [l for l in LIFE.values() if l['online']]:
			_x_min = bad_numbers.clip(life['pos'][0]-MAP_WINDOW_SIZE[0], 0, MAP_SIZE[0]-1-MAP_WINDOW_SIZE[0])
			_y_min = bad_numbers.clip(life['pos'][1]-MAP_WINDOW_SIZE[1], 0, MAP_SIZE[1]-1-MAP_WINDOW_SIZE[1])
			_x_max = bad_numbers.clip(life['pos'][0]+MAP_WINDOW_SIZE[0], 0, MAP_SIZE[0]-1)
			_y_max = bad_numbers.clip(life['pos'][1]+MAP_WINDOW_SIZE[1], 0, MAP_SIZE[1]-1)
			_refresh = False
			
			for y in range(_y_min, _y_max, WORLD_INFO['chunk_size']):
				for x in range(_x_min, _x_max, WORLD_INFO['chunk_size']):
					maps.load_cluster_at_position_if_needed((x, y))
					
					SETTINGS['loading'] = True
					
					if 'player' in life:
						_refresh = True
			
			if _refresh:
				gfx.refresh_view('map')
		
		SETTINGS['loading'] = False
예제 #3
0
파일: effects.py 프로젝트: flags/Reactor-3
def create_smoke_cloud(pos, size, color=tcod.gray, age=0, factor_distance=False):
	if not gfx.position_is_in_frame(pos):
		return False
	
	for new_pos in render_los.draw_circle(pos[0], pos[1], size):
		if not gfx.position_is_in_frame(new_pos):
			continue
		 
		maps.load_cluster_at_position_if_needed(new_pos)
		 
		if not alife.sight._can_see_position(pos, new_pos, distance=False):
			continue
		
		_age_mod = 1
		if factor_distance:
			_age_mod = 1-bad_numbers.clip(bad_numbers.distance(pos, new_pos)/float(size), 0.1, 1)
		
		create_smoke(new_pos, color=color, age=age*_age_mod)
예제 #4
0
def create_smoke_cloud(pos,
                       size,
                       color=tcod.gray,
                       age=0,
                       factor_distance=False):
    if not gfx.position_is_in_frame(pos):
        return False

    for new_pos in render_los.draw_circle(pos[0], pos[1], size):
        if not gfx.position_is_in_frame(new_pos):
            continue

        maps.load_cluster_at_position_if_needed(new_pos)

        if not alife.sight._can_see_position(pos, new_pos, distance=False):
            continue

        _age_mod = 1
        if factor_distance:
            _age_mod = 1 - bad_numbers.clip(
                bad_numbers.distance(pos, new_pos) / float(size), 0.1, 1)

        create_smoke(new_pos, color=color, age=age * _age_mod)
예제 #5
0
파일: items.py 프로젝트: flags/Reactor-3
def create_item(name, position=[0,0,2], item=None):
	"""Initiates and returns a copy of an item type."""
	if not item:
		item = ITEM_TYPES[name].copy()
	
	if 'marked_for_reint' in item:
		for key in item['marked_for_reint']:
			item[key] = item['marked_for_reint'][key][:]
		
		del item['marked_for_reint']

	item['uid'] = str(WORLD_INFO['itemid'])
	item['pos'] = list(position)
	item['realpos'] = list(position)
	item['velocity'] = [0.0, 0.0, 0.0]
	item['friction'] = 0
	item['gravity'] = WORLD_INFO['world_gravity']
	item['lock'] = None
	item['owner'] = None
	item['aim_at_limb'] = None
	
	if not 'blocking' in item:
		item['blocking'] = False
	
	if not 'examine_keys' in item:
		item['examine_keys'] = ['description']
	
	item['speed'] = 0
	
	add_to_chunk(item)
	maps.load_cluster_at_position_if_needed(position)
	ITEMS[item['uid']] = item
	ACTIVE_ITEMS.add(item['uid'])
	
	WORLD_INFO['itemid'] += 1
	return item['uid']
예제 #6
0
def create_item(name, position=[0, 0, 2], item=None):
    """Initiates and returns a copy of an item type."""
    if not item:
        item = ITEM_TYPES[name].copy()

    if 'marked_for_reint' in item:
        for key in item['marked_for_reint']:
            item[key] = item['marked_for_reint'][key][:]

        del item['marked_for_reint']

    item['uid'] = str(WORLD_INFO['itemid'])
    item['pos'] = list(position)
    item['realpos'] = list(position)
    item['velocity'] = [0.0, 0.0, 0.0]
    item['friction'] = 0
    item['gravity'] = WORLD_INFO['world_gravity']
    item['lock'] = None
    item['owner'] = None
    item['aim_at_limb'] = None

    if not 'blocking' in item:
        item['blocking'] = False

    if not 'examine_keys' in item:
        item['examine_keys'] = ['description']

    item['speed'] = 0

    add_to_chunk(item)
    maps.load_cluster_at_position_if_needed(position)
    ITEMS[item['uid']] = item
    ACTIVE_ITEMS.add(item['uid'])

    WORLD_INFO['itemid'] += 1
    return item['uid']
예제 #7
0
def astar(life, start, end, zones, chunk_mode=False, terraform=None, avoid_tiles=[], avoid_chunk_types=[], map_size=MAP_SIZE):	
	_stime = time.time()
	
	_path = {'start': tuple(start),
	         'end': tuple(end),
	         'olist': [tuple(start)],
	         'clist': [],
	         'segments': [],
	         'map': [],
	         'map_size': map_size,
	         'chunk_mode': chunk_mode}
	
	if terraform:
		_path['map_size'] = terraform['size']
	else:
		maps.load_cluster_at_position_if_needed(end)
	
	if chunk_mode:
		_path['start'] = (_path['start'][0]/WORLD_INFO['chunk_size'], _path['start'][1]/WORLD_INFO['chunk_size'])
		_path['end'] = (_path['end'][0]/WORLD_INFO['chunk_size'], _path['end'][1]/WORLD_INFO['chunk_size'])
		_path['olist'][0] = (_path['start'][0], _path['start'][1])

	_path['fmap'] = numpy.zeros((_path['map_size'][1], _path['map_size'][0]), dtype=numpy.int16)
	_path['gmap'] = numpy.zeros((_path['map_size'][1], _path['map_size'][0]), dtype=numpy.int16)
	_path['hmap'] = numpy.zeros((_path['map_size'][1], _path['map_size'][0]), dtype=numpy.int16)
	_path['pmap'] = []
	_path['tmap'] = numpy.zeros((_path['map_size'][0], _path['map_size'][1]), dtype=numpy.int16)
	
	for x in range(_path['map_size'][0]):
		_path['pmap'].append([0] * _path['map_size'][1])

	_path['map'] = numpy.zeros((_path['map_size'][1], _path['map_size'][0]))
	_path['map'] -= 2
	
	#KEY:
	#0: Unwalkable
	#1: Walkable
	
	if terraform:
		_start_chunk_key = '%s,%s' % ((start[0]/terraform['chunk_size'])*terraform['chunk_size'],
		                            (start[1]/terraform['chunk_size'])*terraform['chunk_size'])
		_end_chunk_key = '%s,%s' % ((end[0]/terraform['chunk_size'])*terraform['chunk_size'],
		                            (end[1]/terraform['chunk_size'])*terraform['chunk_size'])
		
		if chunk_mode:
			_increment = terraform['chunk_size']
		else:
			_increment = 1
		
		for y in range(0, terraform['size'][1], _increment):
			for x in range(0, terraform['size'][0], _increment):
				if chunk_mode:
					_chunk_key = '%s,%s' % ((x/terraform['chunk_size'])*terraform['chunk_size'],
						                    (y/terraform['chunk_size'])*terraform['chunk_size'])
					
					if not _chunk_key in [_start_chunk_key, _end_chunk_key]:
						if terraform['chunk_map'][_chunk_key]['type'] in avoid_chunk_types:
							continue
		
					_path['map'][y/terraform['chunk_size'], x/terraform['chunk_size']] = 1
				else:
					_map_pos = terraform['map'][x][y][2]
				
					if _map_pos['id'] in avoid_tiles:
						continue
					
					if not (x, y) in [_path['start'], path['end']]:
						_path['map'][y, x] = 1
		
	else:
		if chunk_mode:
			for y in range(MAP_SIZE[1]/WORLD_INFO['chunk_size']):
				for x in range(MAP_SIZE[0]/WORLD_INFO['chunk_size']):
					_chunk_key = '%s,%s' % (x*WORLD_INFO['chunk_size'],
				                            y*WORLD_INFO['chunk_size'])
					
					_path['map'][y, x] = 1
		else:
			_path['map'] = numpy.zeros((_path['map_size'][1], _path['map_size'][0]))
			
			for z in zones:
				_slice_map = WORLD_INFO['path_map'][str(z)]
				_path['map'] += _slice_map
			
			_path['map'] = _path['map'].clip(-2, 1)
	
	_path['hmap'][_path['start'][1], _path['start'][0]] = (abs(_path['start'][0]-_path['end'][0])+abs(_path['start'][1]-_path['end'][1]))*10
	_path['fmap'][_path['start'][1], _path['start'][0]] = _path['hmap'][_path['start'][1],_path['start'][0]]

	return walk_path({}, _path)
예제 #8
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)
예제 #9
0
def form_scheme(force=False):
    print WORLD_INFO['next_scheme_timer']
    if WORLD_INFO['next_scheme_timer']:
        WORLD_INFO['next_scheme_timer'] -= 1

        return False

    if (WORLD_INFO['scheme'] and not force) or not SETTINGS['controlling']:
        return False

    _overwatch_mood = WORLD_INFO['overwatch']['mood']
    _player = LIFE[SETTINGS['controlling']]
    _player_situation = core.get_player_situation()
    _event_names = []

    if _player_situation['active_factions']:
        if not _player_situation['active_factions'] == [
                'ZES'
        ] and not random.randint(0,
                                 (len(artifacts.get_active_fields()) + 1) * 3):
            _event_names.append('anomaly')

        _event_names.append('capture')

    if not random.randint(0, 8):
        _event_names.append('resupply')

    if not random.randint(0, 4):
        _event_names.append('attract')

    if not _event_names:
        WORLD_INFO['next_scheme_timer'] = 50

        return False

    _event_name = random.choice(_event_names)

    print _event_name

    if _event_name == 'attract':
        if _player_situation['enemy_factions'] and not _player_situation[
                'friendly_factions']:
            for enemy_faction in _player_situation['enemy_factions']:
                for enemy_of_enemy_faction in alife.factions.get_faction_enemies(
                        enemy_faction):
                    _nearest_group = alife.factions.get_nearest_group(
                        enemy_of_enemy_faction, _player['pos'])

                    if not _nearest_group:
                        continue

                    alife.factions.move_group_to(
                        enemy_of_enemy_faction, _nearest_group,
                        lfe.get_current_chunk_id(_player))

                    WORLD_INFO['next_scheme_timer'] = 250

    elif _event_name == 'capture':
        _chosen_faction = random.choice(_player_situation['active_factions'])
        _chosen_group = random.choice(
            alife.factions.get_faction(_chosen_faction)['groups'])

        alife.factions.capture_territory(_chosen_faction, _chosen_group)

        WORLD_INFO['next_scheme_timer'] = 350

    elif _event_name == 'resupply':
        _chunk_key = random.choice(
            WORLD_INFO['territories'][artifacts.find_territory(
                y_min=.5)]['chunk_keys'])
        _pos = WORLD_INFO['chunk_map'][_chunk_key]['pos']
        _storage_items = [{
            'item': 'AK-74',
            'rarity': 1.0
        }, {
            'item': '5.45x39mm round',
            'rarity': 0.6
        }, {
            'item': '5.45x39mm round',
            'rarity': 0.6
        }, {
            'item': '5.45x39mm round',
            'rarity': 0.6
        }, {
            'item': '5.45x39mm round',
            'rarity': 0.6
        }, {
            'item': '5.45x39mm round',
            'rarity': 0.6
        }, {
            'item': '5.45x39mm round',
            'rarity': 0.6
        }, {
            'item': '5.45x39mm round',
            'rarity': 0.6
        }, {
            'item': '5.45x39mm magazine',
            'rarity': 1.0
        }]
        _storage = [{
            'item': 'military crate',
            'rarity': 1.0,
            'spawn_list': _storage_items
        }]

        for faction_name in WORLD_INFO['factions']:
            if faction_name == 'ZES':
                continue

            _faction = WORLD_INFO['factions'][faction_name]

            for group_id in _faction['groups']:
                if not random.randint(0, 3):
                    continue

                #alife.factions.move_group_to(faction_name, group_id, _chunk_key)
                alife.factions.resupply(faction_name, group_id, _chunk_key)

        events.create_cache_drop(_pos, _storage)

        WORLD_INFO['next_scheme_timer'] = 350

    elif _event_name == 'anomaly':
        _territory_id = events.create_anomaly_field(_player_situation,
                                                    y_min=.65)

        for faction_name in _player_situation['active_factions']:
            if faction_name == 'ZES':
                continue

            _faction = WORLD_INFO['factions'][faction_name]

            for group_id in _faction['groups']:
                if random.randint(0, 1):
                    continue

                _chunk_key = random.choice(
                    WORLD_INFO['territories'][_territory_id]['chunk_keys'])

                maps.load_cluster_at_position_if_needed(
                    WORLD_INFO['chunk_map'][_chunk_key]['pos'])
                alife.factions.move_group_to(faction_name, group_id,
                                             _chunk_key)

        WORLD_INFO['next_scheme_timer'] = 350
예제 #10
0
def form_scheme(force=False):
	print WORLD_INFO['next_scheme_timer']
	if WORLD_INFO['next_scheme_timer']:
		WORLD_INFO['next_scheme_timer'] -= 1
		
		return False
	
	if (WORLD_INFO['scheme'] and not force) or not SETTINGS['controlling']:
		return False
	
	_overwatch_mood = WORLD_INFO['overwatch']['mood']
	_player = LIFE[SETTINGS['controlling']]
	_player_situation = core.get_player_situation()
	_event_names = []
	
	if _player_situation['active_factions']:
		if not _player_situation['active_factions'] == ['ZES'] and not random.randint(0, (len(artifacts.get_active_fields())+1)*3):
			_event_names.append('anomaly')
	
		_event_names.append('capture')
	
	if not random.randint(0, 8):
		_event_names.append('resupply')
	
	if not random.randint(0, 4):
		_event_names.append('attract')
	
	if not _event_names:
		WORLD_INFO['next_scheme_timer'] = 50
		
		return False
	
	_event_name = random.choice(_event_names)
	
	print _event_name
	
	if _event_name == 'attract':
		if _player_situation['enemy_factions'] and not _player_situation['friendly_factions']:
			for enemy_faction in _player_situation['enemy_factions']:
				for enemy_of_enemy_faction in alife.factions.get_faction_enemies(enemy_faction):
					_nearest_group = alife.factions.get_nearest_group(enemy_of_enemy_faction, _player['pos'])
				
					if not _nearest_group:
						continue
					
					alife.factions.move_group_to(enemy_of_enemy_faction, _nearest_group, lfe.get_current_chunk_id(_player))
					
					WORLD_INFO['next_scheme_timer'] = 250
	
	elif _event_name == 'capture':
		_chosen_faction = random.choice(_player_situation['active_factions'])
		_chosen_group = random.choice(alife.factions.get_faction(_chosen_faction)['groups'])
		
		alife.factions.capture_territory(_chosen_faction, _chosen_group)
		
		WORLD_INFO['next_scheme_timer'] = 350
	
	elif _event_name == 'resupply':
		_chunk_key = random.choice(WORLD_INFO['territories'][artifacts.find_territory(y_min=.5)]['chunk_keys'])
		_pos = WORLD_INFO['chunk_map'][_chunk_key]['pos']
		_storage_items = [{'item': 'AK-74', 'rarity': 1.0},
			             {'item': '5.45x39mm round', 'rarity': 0.6},
			             {'item': '5.45x39mm round', 'rarity': 0.6},
			             {'item': '5.45x39mm round', 'rarity': 0.6},
			             {'item': '5.45x39mm round', 'rarity': 0.6},
			             {'item': '5.45x39mm round', 'rarity': 0.6},
			             {'item': '5.45x39mm round', 'rarity': 0.6},
			             {'item': '5.45x39mm round', 'rarity': 0.6},
			             {'item': '5.45x39mm magazine', 'rarity': 1.0}]
		_storage = [{'item': 'military crate', 'rarity': 1.0, 'spawn_list': _storage_items}]
		
		for faction_name in WORLD_INFO['factions']:
			if faction_name == 'ZES':
				continue
			
			_faction = WORLD_INFO['factions'][faction_name]
			
			for group_id in _faction['groups']:
				if not random.randint(0, 3):
					continue
				
				#alife.factions.move_group_to(faction_name, group_id, _chunk_key)
				alife.factions.resupply(faction_name, group_id, _chunk_key)
		
		events.create_cache_drop(_pos, _storage)
		
		WORLD_INFO['next_scheme_timer'] = 350
	
	elif _event_name == 'anomaly':
		_territory_id = events.create_anomaly_field(_player_situation, y_min=.65)
		
		for faction_name in _player_situation['active_factions']:
			if faction_name == 'ZES':
				continue
			
			_faction = WORLD_INFO['factions'][faction_name]
			
			for group_id in _faction['groups']:
				if random.randint(0, 1):
					continue
				
				_chunk_key = random.choice(WORLD_INFO['territories'][_territory_id]['chunk_keys'])
				
				maps.load_cluster_at_position_if_needed(WORLD_INFO['chunk_map'][_chunk_key]['pos'])
				alife.factions.move_group_to(faction_name, group_id, _chunk_key)
		
		WORLD_INFO['next_scheme_timer'] = 350
예제 #11
0
파일: effects.py 프로젝트: flags/Reactor-3
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)