void TCOD_map_compute_fov_restrictive_shadowcasting(TCOD_map_t map, int player_x, int player_y, int max_radius, bool light_walls) { map_t *m = (map_t *)map; int c; int max_obstacles; /*first, zero the FOV map */ for(c = m->nbcells - 1; c >= 0; c--) m->cells[c].fov = false; /*calculate an approximated (excessive, just in case) maximum number of obstacles per octant */ max_obstacles = m->nbcells / 7; /* check memory for angles */ if (max_obstacles > allocated) { allocated = max_obstacles; if (start_angle != NULL) free(start_angle); if (end_angle != NULL) free(end_angle); start_angle = (double*)calloc(max_obstacles, sizeof(double)); end_angle = (double*)calloc(max_obstacles, sizeof(double)); } /*set PC's position as visible */ m->cells[player_x+(player_y*m->width)].fov = true; /*compute the 4 quadrants of the map */ TCOD_map_compute_fov_restrictive_shadowcasting_quadrant (m, player_x, player_y, max_radius, light_walls, 1, 1); TCOD_map_compute_fov_restrictive_shadowcasting_quadrant (m, player_x, player_y, max_radius, light_walls, 1, -1); TCOD_map_compute_fov_restrictive_shadowcasting_quadrant (m, player_x, player_y, max_radius, light_walls, -1, 1); TCOD_map_compute_fov_restrictive_shadowcasting_quadrant (m, player_x, player_y, max_radius, light_walls, -1, -1); }
void TCOD_map_compute_fov_restrictive_shadowcasting(TCOD_map_t map, int player_x, int player_y, int max_radius, bool light_walls) { map_t *m = (map_t *)map; int c; int maxObstacles; //first, zero the FOV map for(c = m->nbcells - 1; c >= 0; c--) { m->cells[c].fov = 0; } //calculate an approximated (excessive, just in case) maximum number of obstacles per octant maxObstacles = m->nbcells / 7; //set PC's position as visible m->cells[player_x+(player_y*m->width)].fov = 1; //compute the 4 quadrants of the map TCOD_map_compute_fov_restrictive_shadowcasting_quadrant (m, player_x, player_y, max_radius, light_walls, maxObstacles, 1, 1); TCOD_map_compute_fov_restrictive_shadowcasting_quadrant (m, player_x, player_y, max_radius, light_walls, maxObstacles, 1, -1); TCOD_map_compute_fov_restrictive_shadowcasting_quadrant (m, player_x, player_y, max_radius, light_walls, maxObstacles, -1, 1); TCOD_map_compute_fov_restrictive_shadowcasting_quadrant (m, player_x, player_y, max_radius, light_walls, maxObstacles, -1, -1); }