Ejemplo n.º 1
0
void overmapbuffer::despawn_monster(const monster &critter)
{
    // Get absolute coordinates of the monster in map squares, translate to submap position
    tripoint sm = ms_to_sm_copy( g->m.getabs( critter.pos3() ) );
    // Get the overmap coordinates and get the overmap, sm is now local to that overmap
    const point omp = sm_to_om_remain( sm.x, sm.y );
    overmap &om = get( omp.x, omp.y );
    // Store the monster using coordinates local to the overmap.
    om.monster_map.insert( std::make_pair( sm, critter ) );
}
Ejemplo n.º 2
0
bool Creature_tracker::add( monster &critter )
{
    if( critter.type->id == "mon_null" ) { // Don't wanna spawn null monsters o.O
        return false;
    }

    if( -1 != mon_at( critter.pos3() ) ) {
        debugmsg( "add_zombie: there's already a monster at %d,%d,%d", 
                  critter.posx(), critter.posy(), critter.posz() );
        return false;
    }

    if( monster_is_blacklisted(critter.type) ) {
        return false;
    }

    monsters_by_location[critter.pos3()] = monsters_list.size();
    monsters_list.push_back(new monster(critter));
    return true;
}
Ejemplo n.º 3
0
void Creature_tracker::remove_from_location_map( const monster &critter )
{
    const tripoint &loc = critter.pos3();
    const auto pos_iter = monsters_by_location.find( loc );
    if( pos_iter != monsters_by_location.end() ) {
        const auto &other = find( pos_iter->second );
        if( &other == &critter ) {
            monsters_by_location.erase( pos_iter );
        }
    }
}
Ejemplo n.º 4
0
bool Creature_tracker::update_pos(const monster &critter, const tripoint &new_pos)
{
    const auto old_pos = critter.pos3();
    if( critter.is_dead() ) {
        // mon_at ignores dead critters anyway, changing their position in the
        // monsters_by_location map is useless.
        remove_from_location_map( critter );
        return true;
    }

    bool success = false;
    const int critter_id = mon_at( old_pos );
    const int new_critter_id = mon_at( new_pos );
    if( new_critter_id >= 0 ) {
        debugmsg("update_zombie_pos: new location %d,%d,%d already has zombie %d",
                 new_pos.x, new_pos.y, new_pos.z, new_critter_id);
    } else if( critter_id >= 0 ) {
        if( &critter == monsters_list[critter_id] ) {
            monsters_by_location.erase( old_pos );
            monsters_by_location[new_pos] = critter_id;
            success = true;
        } else {
            debugmsg("update_zombie_pos: old location %d,%d had zombie %d instead",
                     old_pos.x, old_pos.y, critter_id);
        }
    } else {
        // We're changing the x/y/z coordinates of a zombie that hasn't been added
        // to the game yet. add_zombie() will update monsters_by_location for us.
        debugmsg("update_zombie_pos: no such zombie at %d,%d,%d (moving to %d,%d,%d)",
                 old_pos.x, old_pos.y, old_pos.z, new_pos.x, new_pos.y, new_pos.z );
        // Rebuild cache in case the monster actually IS in the game, just bugged
        rebuild_cache();
    }

    return success;
}