Esempio n. 1
0
/*
 +-----------------------------------------------------------+
 * @desc	FIXME
 +-----------------------------------------------------------+
 */
err
RLFL_fov_permissive(unsigned int m, unsigned int ox, unsigned int oy, unsigned int radius, bool light_walls)
{
	if(!RLFL_map_valid(m))
		return RLFL_ERR_NO_MAP;

	if(!RLFL_cell_valid(m, ox, oy))
		return RLFL_ERR_OUT_OF_BOUNDS;

	if(radius >= RLFL_MAX_RADIUS)
		return RLFL_ERR_GENERIC;

	RLFL_map_t *map = RLFL_map_store[m];
	int minx, maxx, miny, maxy;

	/* The origin is always seen */
	RLFL_set_flag(m, ox, oy, CELL_FOV);

	/* preallocate views and bumps */
	views = (view_t *)calloc(sizeof(view_t), map->width*map->height);
	bumps = (viewbump_t *)calloc(sizeof(viewbump_t), map->width*map->height);

	/* set the fov range */
	if (radius > 0)
	{
		minx = MIN(ox, radius);
		maxx = MIN(map->width-ox - 1, radius);
		miny = MIN(oy, radius);
		maxy = MIN(map->height-oy - 1, radius);
	}
	else
	{
		minx = ox;
		maxx = map->width - ox - 1;
		miny = oy;
		maxy = map->height - oy -1;
	}

	/* calculate fov. precise permissive field of view */
	bumpidx = 0;
	check_quadrant(map, ox, oy, 1, 1, maxx, maxy, light_walls);
	bumpidx = 0;
	check_quadrant(map, ox, oy, 1, -1, maxx, miny, light_walls);
	bumpidx = 0;
	check_quadrant(map, ox, oy, -1, -1, minx, miny, light_walls);
	bumpidx = 0;
	check_quadrant(map, ox, oy, -1, 1, minx, maxy, light_walls);

	/* cleanup */
	free(bumps);
	free(views);

	return RLFL_SUCCESS;
}
Esempio n. 2
0
void TCOD_map_compute_fov_permissive2(TCOD_map_t map, int player_x, int player_y, int max_radius, bool light_walls, int fovType) {
    int c,minx,maxx,miny,maxy;
    map_t *m = (map_t *)map;
    if ( (unsigned)fovType>8 ) TCOD_fatal("Bad permissiveness %d for FOV_PERMISSIVE. Accepted range is [0,8].\n",fovType);
    offset=8-fovType;
    limit=8+fovType;
    // clean the map
    for (c=m->nbcells-1; c >= 0; c--) {
        m->cells[c].fov=0;
    }
    m->cells[player_x+player_y*m->width].fov=1;
    // preallocate views and bumps
    views=(view_t *)calloc(sizeof(view_t),m->width*m->height);
    bumps=(viewbump_t *)calloc(sizeof(viewbump_t),m->width*m->height);
    // set the fov range
    if ( max_radius > 0 ) {
        minx=MIN(player_x,max_radius);
        maxx=MIN(m->width-player_x-1,max_radius);
        miny=MIN(player_y,max_radius);
        maxy=MIN(m->height-player_y-1,max_radius);
    } else {
        minx=player_x;
        maxx=m->width-player_x-1;
        miny=player_y;
        maxy=m->height-player_y-1;
    }
    // calculate fov. precise permissive field of view
    bumpidx=0;
    check_quadrant(m,player_x,player_y,1,1,maxx,maxy, light_walls);
    bumpidx=0;
    check_quadrant(m,player_x,player_y,1,-1,maxx,miny, light_walls);
    bumpidx=0;
    check_quadrant(m,player_x,player_y,-1,-1,minx,miny, light_walls);
    bumpidx=0;
    check_quadrant(m,player_x,player_y,-1,1,minx,maxy, light_walls);
    free(bumps);
    free(views);
}