Exemplo n.º 1
0
void overmapbuffer::move_hordes()
{
    // arbitrary radius to include nearby overmaps (aside from the current one)
    const auto radius = MAPSIZE * 2;
    const auto center = g->u.global_sm_location();
    for( auto &om : get_overmaps_near( center, radius ) ) {
        om->move_hordes();
    }
}
Exemplo n.º 2
0
void overmapbuffer::signal_hordes( const tripoint &center, const int sig_power )
{
    const auto radius = sig_power;
    for( auto &om : get_overmaps_near( center, radius ) ) {
        const point abs_pos_om = om_to_sm_copy( om->pos() );
        const tripoint rel_pos( center.x - abs_pos_om.x, center.y - abs_pos_om.y, center.z );
        // overmap::signal_hordes expects a coordinate relative to the overmap, this is easier
        // for processing as the monster group stores is location as relative coordinates, too.
        om->signal_hordes( rel_pos, sig_power );
    }
}
Exemplo n.º 3
0
radio_tower_reference overmapbuffer::find_radio_station( const int frequency )
{
    const auto center = g->u.global_sm_location();
    for( auto &om : get_overmaps_near( center, RADIO_MAX_STRENGTH ) ) {
        for( auto &tower : om->radios ) {
            const auto rref = create_radio_tower_reference( *om, tower, center );
            if( rref.signal_strength > 0 && tower.frequency == frequency ) {
                return rref;
            }
        }
    }
    return radio_tower_reference{ nullptr, nullptr, point( 0, 0 ), 0 };
}
Exemplo n.º 4
0
std::vector<radio_tower_reference> overmapbuffer::find_all_radio_stations()
{
    std::vector<radio_tower_reference> result;
    const auto center = g->u.global_sm_location();
    // perceived signal strength is distance (in submaps) - signal strength, so towers
    // further than RADIO_MAX_STRENGTH submaps away can never be received at all.
    const int radius = RADIO_MAX_STRENGTH;
    for( auto &om : get_overmaps_near( center, radius ) ) {
        for( auto &tower : om->radios ) {
            const auto rref = create_radio_tower_reference( *om, tower, center );
            if( rref.signal_strength > 0 ) {
                result.push_back( rref );
            }
        }
    }
    return result;
}
Exemplo n.º 5
0
// If z == INT_MIN, allow all z-levels
std::vector<std::shared_ptr<npc>> overmapbuffer::get_npcs_near_omt( int x, int y, int z,
                               int radius )
{
    std::vector<std::shared_ptr<npc>> result;
    for( auto &it : get_overmaps_near( omt_to_sm_copy( x, y ), radius ) ) {
        auto temp = it->get_npcs( [&]( const npc & guy ) {
            // Global position of NPC, in submap coordinates
            tripoint pos = guy.global_omt_location();
            if( z != INT_MIN && pos.z != z ) {
                return false;
            }
            return square_dist( x, y, pos.x, pos.y ) <= radius;
        } );
        result.insert( result.end(), temp.begin(), temp.end() );
    }
    return result;
}
Exemplo n.º 6
0
// If z == INT_MIN, allow all z-levels
std::vector<npc*> overmapbuffer::get_npcs_near_omt(int x, int y, int z, int radius)
{
    std::vector<npc*> result;
    for( auto &it : get_overmaps_near( omt_to_sm_copy( x, y ), radius ) ) {
        for( auto &np : it->npcs ) {
            // Global position of NPC, in submap coordiantes
            tripoint pos = np->global_omt_location();
            if( z != INT_MIN && pos.z != z) {
                continue;
            }
            const int npc_offset = square_dist( x, y, pos.x, pos.y );
            if (npc_offset <= radius) {
                result.push_back(np);
            }
        }
    }
    return result;
}
Exemplo n.º 7
0
std::vector<npc*> overmapbuffer::get_npcs_near(int x, int y, int z, int radius)
{
    std::vector<npc*> result;
    for( auto &it : get_overmaps_near( point( x, y ), radius ) ) {
        for( auto &elem : it->npcs ) {
            npc *p = elem;
            // Global position of NPC, in submap coordiantes
            const tripoint pos = p->global_sm_location();
            if (pos.z != z) {
                continue;
            }
            const int npc_offset = square_dist(x, y, pos.x, pos.y);
            if (npc_offset <= radius) {
                result.push_back(p);
            }
        }
    }
    return result;
}
Exemplo n.º 8
0
city_reference overmapbuffer::closest_city( const tripoint &center )
{
    // a whole overmap (because it's in submap coordinates, OMAPX is overmap terrain coordinates)
    auto const radius = OMAPX * 2;
    // Starting with distance = INT_MAX, so the first city is already closer
    city_reference result{ nullptr, nullptr, tripoint( 0, 0, 0 ), INT_MAX };
    for( auto &om : get_overmaps_near( center, radius ) ) {
        const auto abs_pos_om = om_to_sm_copy( om->pos() );
        for( auto &city : om->cities ) {
            const auto rel_pos_city = omt_to_sm_copy( point( city.x, city.y ) );
            // TODO: Z-level cities. This 0 has to be here until mapgen understands non-0 zlev cities
            const auto abs_pos_city = tripoint( abs_pos_om + rel_pos_city, 0 );
            const auto distance = rl_dist( abs_pos_city, center );
            const city_reference cr{ om, &city, abs_pos_city, distance };
            if( distance < result.distance ) {
                result = cr;
            } else if( distance == result.distance && result.city->s < city.s ) {
                result = cr;
            }
        }
    }
    return result;
}
Exemplo n.º 9
0
std::vector<city_reference> overmapbuffer::get_cities_near( const tripoint &location, int radius )
{
    std::vector<city_reference> result;

    for( const auto om : get_overmaps_near( location, radius ) ) {
        const auto abs_pos_om = om_to_sm_copy( om->pos() );
        result.reserve( result.size() + om->cities.size() );
        std::transform( om->cities.begin(), om->cities.end(), std::back_inserter( result ),
        [&]( city & element ) {
            const auto rel_pos_city = omt_to_sm_copy( element.pos );
            const auto abs_pos_city = tripoint( rel_pos_city + abs_pos_om, 0 );
            const auto distance = rl_dist( abs_pos_city, location );

            return city_reference{ &element, abs_pos_city, distance };
        } );
    }

    std::sort( result.begin(), result.end(), []( const city_reference & lhs,
    const city_reference & rhs ) {
        return lhs.get_distance_from_bounds() < rhs.get_distance_from_bounds();
    } );

    return result;
}
Exemplo n.º 10
0
std::vector<overmap *> overmapbuffer::get_overmaps_near( const point &p, const int radius )
{
    return get_overmaps_near( tripoint( p.x, p.y, 0 ), radius );
}