Esempio n. 1
0
def create_position_map(squad):
	_coverage_positions = set()
	_known_targets = set()
	_known_squads = set()

	for member_id in squad['members']:
		_member = entities.get_entity(member_id)
		_x, _y = movement.get_position(_member)
		_sight = stats.get_vision(_member)
		
		if member_id in squad['member_position_maps']:
			_old_coverage_positions = squad['member_position_maps'][member_id].copy()
		
		else:
			_old_coverage_positions = set()
		
		_map_size = zones.get_active_size()
		squad['member_position_maps'][member_id] = set()
		squad['member_los_maps'][member_id] = tcod.map_new(_map_size[0], _map_size[1])
		
		tcod.map_copy(zones.get_active_los_map(), squad['member_los_maps'][member_id])
		
		_t = time.time()
		
		tcod.map_compute_fov(squad['member_los_maps'][member_id], _x, _y, radius=_sight, light_walls=False, algo=tcod.FOV_PERMISSIVE_2)
		
		for pos in shapes.circle(_x, _y, _sight):
			if pos[0] < 0 or pos[0] >= _map_size[0] or pos[1] < 0 or pos[1] >= _map_size[1]:
				continue
			
			if not tcod.map_is_in_fov(squad['member_los_maps'][member_id], pos[0], pos[1]):
				continue
		
			_coverage_positions.add(pos)
			squad['member_position_maps'][member_id].add(pos)
	
		#TODO: Do this elsewhere
		for target_id in _member['ai']['visible_targets']:
			if not target_id in entities.ENTITIES:
				continue
			
			_target = entities.get_entity(target_id)
			_known_squads.add((_target['ai']['faction'], _target['ai']['squad']))
		
		#TODO: Is this right?
		_known_targets.update(_member['ai']['visible_targets'])
		_positions_to_remove = _old_coverage_positions - _coverage_positions
	
		squad['known_targets'].update(_known_targets)
		squad['known_squads'].update(_known_squads)
		squad['coverage_positions'].update(_coverage_positions)
		squad['coverage_positions'] = squad['coverage_positions'] - _positions_to_remove
	
	if squad['known_targets']:
		update_position_maps(squad)
		
		logging.debug('Updated local position map - requesting squad update')
	
	else:
		logging.debug('Updated local position map.')
Esempio n. 2
0
	def add_map(self, fov):
		new_map = libtcod.map_new(self.width, self.height)
		if self.libtcod_map is None:
			self.init_map()
		
		self.libtcod_map_owners.append(fov.owner)
		libtcod.map_copy(self.libtcod_map, new_map)
		
		return new_map
Esempio n. 3
0
def test_map():
    map = libtcodpy.map_new(16, 16)
    assert libtcodpy.map_get_width(map) == 16
    assert libtcodpy.map_get_height(map) == 16
    libtcodpy.map_copy(map, map)
    libtcodpy.map_clear(map)
    libtcodpy.map_set_properties(map, 0, 0, True, True)
    assert libtcodpy.map_is_transparent(map, 0, 0)
    assert libtcodpy.map_is_walkable(map, 0, 0)
    libtcodpy.map_is_in_fov(map, 0, 0)
    libtcodpy.map_delete(map)
Esempio n. 4
0
	def get_fovmap(self, origin, radius):
		key = origin,radius

		if key in self.fovmaps: fovmap = self.fovmaps[key]
		else:
			fovmap = tc.map_new(self.width, self.height)
			tc.map_copy(self.base_map, fovmap)
			self.fovmaps[key] = fovmap

			x,y = origin
			tc.map_compute_fov(fovmap, x,y, radius, algo=tc.FOV_DIAMOND)

		return fovmap
Esempio n. 5
0
def update_all_fovmaps():
    for creat in list_creatures():
        if has_sight(creat):
            fovMap=creat.fov_map
            libtcod.map_copy(Ref.Map.fov_map,fovMap)
            update_fov(tt)
Esempio n. 6
0
def fov_init():  # normal type FOV map init
    fovMap=libtcod.map_new(ROOMW,ROOMH)
    libtcod.map_copy(Ref.Map.fov_map,fovMap)  # get properties from Map
    return fovMap
Esempio n. 7
0
def create_position_map(squad):
    _coverage_positions = set()
    _known_targets = set()
    _known_squads = set()

    for member_id in squad['members']:
        _member = entities.get_entity(member_id)
        _x, _y = movement.get_position(_member)
        _sight = stats.get_vision(_member)

        if member_id in squad['member_position_maps']:
            _old_coverage_positions = squad['member_position_maps'][
                member_id].copy()

        else:
            _old_coverage_positions = set()

        _map_size = zones.get_active_size()
        squad['member_position_maps'][member_id] = set()
        squad['member_los_maps'][member_id] = tcod.map_new(
            _map_size[0], _map_size[1])

        tcod.map_copy(zones.get_active_los_map(),
                      squad['member_los_maps'][member_id])

        _t = time.time()

        tcod.map_compute_fov(squad['member_los_maps'][member_id],
                             _x,
                             _y,
                             radius=_sight,
                             light_walls=False,
                             algo=tcod.FOV_PERMISSIVE_2)

        for pos in shapes.circle(_x, _y, _sight):
            if pos[0] < 0 or pos[0] >= _map_size[0] or pos[1] < 0 or pos[
                    1] >= _map_size[1]:
                continue

            if not tcod.map_is_in_fov(squad['member_los_maps'][member_id],
                                      pos[0], pos[1]):
                continue

            _coverage_positions.add(pos)
            squad['member_position_maps'][member_id].add(pos)

        #TODO: Do this elsewhere
        for target_id in _member['ai']['visible_targets']:
            if not target_id in entities.ENTITIES:
                continue

            _target = entities.get_entity(target_id)
            _known_squads.add(
                (_target['ai']['faction'], _target['ai']['squad']))

        #TODO: Is this right?
        _known_targets.update(_member['ai']['visible_targets'])
        _positions_to_remove = _old_coverage_positions - _coverage_positions

        squad['known_targets'].update(_known_targets)
        squad['known_squads'].update(_known_squads)
        squad['coverage_positions'].update(_coverage_positions)
        squad['coverage_positions'] = squad[
            'coverage_positions'] - _positions_to_remove

    if squad['known_targets']:
        update_position_maps(squad)

        logging.debug('Updated local position map - requesting squad update')

    else:
        logging.debug('Updated local position map.')