コード例 #1
0
std::vector<overmap *> overmapbuffer::get_overmaps_near( point location, int radius )
{
    // Grab the corners of a square around the target location at distance radius.
    // Convert to overmap coordinates and iterate from the minimum to the maximum.
    std::set<point> distinct_corners;
    const point upper_left = sm_to_om_copy( point( location.x - radius, location.y - radius ) );
    const point lower_right = sm_to_om_copy( point( location.x + radius, location.y + radius ) );

    for( int x = upper_left.x; x <= lower_right.x; x++ ) {
        for( int y = upper_left.y; y <= lower_right.y; y++ ) {
            distinct_corners.insert( point( x, y ) );
        }
    }
    // Grab references to the overmaps at those coordinates, but only if they exist.
    // Might use this to drive creation of these overmaps at some point if we want to
    // more agressively expand the created overmaps.
    std::vector<overmap *> nearby_overmaps;
    for( auto overmap_origin : distinct_corners ) {
        overmap *nearby_overmap = get_existing( overmap_origin.x, overmap_origin.y );
        if( nearby_overmap ) {
            nearby_overmaps.push_back( nearby_overmap );
        }
    }
    return nearby_overmaps;
}
コード例 #2
0
std::vector<overmap*> overmapbuffer::get_overmaps_near( tripoint const &location, int const radius )
{
    // Grab the corners of a square around the target location at distance radius.
    // Convert to overmap coordinates and iterate from the minimum to the maximum.
    point const start = sm_to_om_copy(location.x - radius, location.y - radius);
    point const end = sm_to_om_copy(location.x + radius, location.y + radius);
    point const offset = end - start;

    std::vector<overmap*> result;
    result.reserve( ( offset.x + 1 ) * ( offset.y + 1 ) );

    for (int x = start.x; x <= end.x; ++x) {
        for (int y = start.y; y <= end.y; ++y) {
            if (auto const existing_om = get_existing(x, y)) {
                result.emplace_back(existing_om);
            }
        }
    }

    return result;
}