예제 #1
0
파일: TMap.cpp 프로젝트: SlySven/Mudlet2
void TMap::initGraph()
{
    QTime _time; _time.start();
    locations.clear();
    roomidToIndex.clear();
    g.clear();
    g = mygraph_t();
    weightmap = get(edge_weight, g);
    QList<TRoom*> roomList = mpRoomDB->getRoomPtrList();
    int roomCount=0;
    int edgeCount=0;
    for( int _k=0; _k<roomList.size(); _k++ )
    {
        TRoom * pR = roomList[_k];
        int i = pR->getId();
        if( pR->isLocked || i < 1 )
        {
            continue;
        }
        roomCount++;
//        int roomExits = edgeCount;
        location l;
        l.x = pR->x;
        l.y = pR->y;
        l.z = pR->z;
        l.id = pR->getId();
        l.area = pR->getAreaId();
        locations.push_back( l );
    }
    for(unsigned int i=0;i<locations.size();i++){
        roomidToIndex[locations[i].id] = i;
        indexToRoomid[i] = locations[i].id;
    }
    for( int _k=0; _k<roomList.size(); _k++ ){
        TRoom * pR = roomList[_k];
        if( pR->isLocked || !roomidToIndex.contains(pR->getId()) )
        {
            continue;
        }
        int roomIndex = roomidToIndex[pR->getId()];
        TRoom * pN = mpRoomDB->getRoom( pR->getNorth() );
        TRoom * pNW = mpRoomDB->getRoom( pR->getNorthwest() );
        TRoom * pNE = mpRoomDB->getRoom( pR->getNortheast() );
        TRoom * pS = mpRoomDB->getRoom( pR->getSouth() );
        TRoom * pSW = mpRoomDB->getRoom( pR->getSouthwest() );
        TRoom * pSE = mpRoomDB->getRoom( pR->getSoutheast() );
        TRoom * pW = mpRoomDB->getRoom( pR->getWest() );
        TRoom * pE = mpRoomDB->getRoom( pR->getEast() );
        TRoom * pUP = mpRoomDB->getRoom( pR->getUp() );
        TRoom * pDOWN = mpRoomDB->getRoom( pR->getDown() );
        TRoom * pIN = mpRoomDB->getRoom( pR->getIn() );
        TRoom * pOUT = mpRoomDB->getRoom( pR->getOut() );


        QMap<QString, int> exitWeights = pR->getExitWeights();

        if( pN && !pN->isLocked )
        {
            if( !pR->hasExitLock( DIR_NORTH ) )
            {
                //edgeCount++;
                edge_descriptor e;
                bool inserted;
                tie(e, inserted) = add_edge( roomIndex,
                                             roomidToIndex[pR->getNorth()],
                                            g );
                if( exitWeights.contains("n"))
                    weightmap[e] = pR->getExitWeight("n");
                else
                    weightmap[e] = pN->getWeight();
            }
        }
        if( pS && !pS->isLocked )
        {
            if( !pR->hasExitLock( DIR_SOUTH ) )
            {
                //edgeCount++;
                edge_descriptor e;
                bool inserted;
                tie(e, inserted) = add_edge( roomIndex,
                                            roomidToIndex[pR->getSouth()],
                                            g );
                if( exitWeights.contains("s"))
                    weightmap[e] = pR->getExitWeight("s");
                else
                    weightmap[e] = pS->getWeight();
            }
        }
        if( pNE && !pNE->isLocked )
        {
            if( !pR->hasExitLock( DIR_NORTHEAST ) )
            {
//                edgeCount++;
                edge_descriptor e;
                bool inserted;
                tie(e, inserted) = add_edge( roomIndex,
                                            roomidToIndex[pR->getNortheast()],
                                            g );
                if( exitWeights.contains("ne"))
                    weightmap[e] = pR->getExitWeight("ne");
                else
                    weightmap[e] = pNE->getWeight();
            }
        }
        if( pE && !pE->isLocked )
        {
            if( !pR->hasExitLock( DIR_EAST ) )
            {
               //edgeCount++;
               edge_descriptor e;
               bool inserted;
               tie(e, inserted) = add_edge( roomIndex,
                                           roomidToIndex[pR->getEast()],
                                           g );
               if( exitWeights.contains("e"))
                   weightmap[e] = pR->getExitWeight("e");
               else
                   weightmap[e] = pE->getWeight();
            }
        }
        if( pW && !pW->isLocked )
        {
            if( !pR->hasExitLock( DIR_WEST ) )
            {
//                edgeCount++;
                edge_descriptor e;
                bool inserted;
                tie(e, inserted) = add_edge( roomIndex,
                                            roomidToIndex[pR->getWest()],
                                            g );
                if( exitWeights.contains("w"))
                    weightmap[e] = pR->getExitWeight("w");
                else
                    weightmap[e] = pW->getWeight();
            }
        }
        if( pSW && !pSW->isLocked )
        {
            if( !pR->hasExitLock( DIR_SOUTHWEST ) )
            {
//                edgeCount++;
                edge_descriptor e;
                bool inserted;
                tie(e, inserted) = add_edge( roomIndex,
                                            roomidToIndex[pR->getSouthwest()],
                                            g );
                if( exitWeights.contains("sw"))
                    weightmap[e] = pR->getExitWeight("sw");
                else
                    weightmap[e] = pSW->getWeight();
            }
        }
        if( pSE && !pSE->isLocked )
        {
            if( !pR->hasExitLock( DIR_SOUTHEAST ) )
            {
//                edgeCount++;
                edge_descriptor e;
                bool inserted;
                tie(e, inserted) = add_edge( roomIndex,
                                            roomidToIndex[pR->getSoutheast()],
                                            g );
                if( exitWeights.contains("se"))
                    weightmap[e] = pR->getExitWeight("se");
                else
                    weightmap[e] = pSE->getWeight();
            }
        }
        if( pNW && !pNW->isLocked )
        {
            if( !pR->hasExitLock( DIR_NORTHWEST ) )
            {
//                edgeCount++;
                edge_descriptor e;
                bool inserted;
                tie(e, inserted) = add_edge( roomIndex,
                                            roomidToIndex[pR->getNorthwest()],
                                            g );
                if( exitWeights.contains("nw"))
                    weightmap[e] = pR->getExitWeight("nw");
                else
                    weightmap[e] = pNW->getWeight();
            }
        }
        if( pUP && !pUP->isLocked )
        {
            if( !pR->hasExitLock( DIR_UP ) )
            {
//                edgeCount++;
                edge_descriptor e;
                bool inserted;
                tie(e, inserted) = add_edge( roomIndex,
                                            roomidToIndex[pR->getUp()],
                                            g );
                if( exitWeights.contains("up"))
                    weightmap[e] = pR->getExitWeight("up");
                else
                    weightmap[e] = pUP->getWeight();
            }
        }
        if( pDOWN && !pDOWN->isLocked )
        {
            if( !pR->hasExitLock( DIR_DOWN ) )
            {
//                edgeCount++;
                edge_descriptor e;
                bool inserted;
                tie(e, inserted) = add_edge( roomIndex,
                                            roomidToIndex[pR->getDown()],
                                            g );
                if( exitWeights.contains("down"))
                    weightmap[e] = pR->getExitWeight("down");
                else
                    weightmap[e] = pDOWN->getWeight();
            }
        }
        if( pIN && !pIN->isLocked )
        {
            if( !pR->hasExitLock( DIR_IN ) )
            {
//                edgeCount++;
                edge_descriptor e;
                bool inserted;
                tie(e, inserted) = add_edge( roomIndex,
                                            roomidToIndex[pR->getIn()],
                                            g );
                if( exitWeights.contains("in"))
                    weightmap[e] = pR->getExitWeight("in");
                else
                    weightmap[e] = pIN->getWeight();
            }
        }
        if( pOUT && !pOUT->isLocked )
        {
            if( !pR->hasExitLock( DIR_OUT ) )
            {
//                 edgeCount++;
                 edge_descriptor e;
                 bool inserted;
                 tie(e, inserted) = add_edge( roomIndex,
                                              roomidToIndex[pR->getOut()],
                                             g );
                 if( exitWeights.contains("out"))
                     weightmap[e] = pR->getExitWeight("out");
                 else
                     weightmap[e] = pOUT->getWeight();
            }
        }
        if( pR->getOtherMap().size() > 0 )
        {
            QMapIterator<int, QString> it( pR->getOtherMap() );
            while( it.hasNext() )
            {
                it.next();
                int _id = it.key();
                QString _cmd = it.value();
                if( _cmd.size()>0 ) _cmd.remove(0,1);//strip special exit lock information
                TRoom * pSpecial = mpRoomDB->getRoom( _id );
                if( !pSpecial || pR->hasSpecialExitLock( _id, _cmd ) || pSpecial->isLocked)
                    continue;
                else
                {
//                    edgeCount++;
                    edge_descriptor e;
                    bool inserted;
                    tie(e, inserted) = add_edge( roomIndex,
                                                roomidToIndex[pSpecial->getId()],
                                                g );
                    if( exitWeights.contains(_cmd))
                    {
                        weightmap[e] = pR->getExitWeight(_cmd);
                    }
                    else
                    {
                        weightmap[e] = pSpecial->getWeight();
                    }

                }
            }
        }
//        if( roomExits == edgeCount ) locations.pop_back();
    }

    mMapGraphNeedsUpdate = false;
    qDebug("TMap::initGraph(): nodes/room Counts: %i / %i edges: %i   run time: %imSec.",
           locations.size(),
           roomCount,
           edgeCount,
           _time.elapsed());
}
예제 #2
0
void dlgRoomExits::init( int id )
{
    TRoom * pR = mpHost->mpMap->mpRoomDB->getRoom( id );
    if( !pR ) return;

    if( pR->hasExitLock(DIR_NORTH) )
    {
        n->setDisabled(true);
        ln->setChecked(true);
    }
    else
    {
        n->setDisabled(false);
        ln->setChecked(false);
    }
    if( pR->hasExitLock(DIR_NORTHEAST) )
    {
        ne->setDisabled(true);
        lne->setChecked(true);
    }
    else
    {
        ne->setDisabled(false);
        le->setChecked(false);
    }
    if( pR->hasExitLock(DIR_NORTHWEST) )
    {
        nw->setDisabled(true);
        lnw->setChecked(true);
    }
    else
    {
        nw->setDisabled(false);
        lnw->setChecked(false);
    }
    if( pR->hasExitLock(DIR_SOUTH) )
    {
        s->setDisabled(true);
        ls->setChecked(true);
    }
    else
    {
        s->setDisabled(false);
        ls->setChecked(false);
    }
    if( pR->hasExitLock(DIR_SOUTHEAST) )
    {
        se->setDisabled(true);
        lse->setChecked(true);
    }
    else
    {
        se->setDisabled(false);
        lse->setChecked(false);
    }
    if( pR->hasExitLock(DIR_SOUTHWEST) )
    {
        sw->setDisabled(true);
        lsw->setChecked(true);
    }
    else
    {
        sw->setDisabled(false);
        lsw->setChecked(false);
    }
    if( pR->hasExitLock(DIR_WEST) )
    {
        w->setDisabled(true);
        lw->setChecked(true);
    }
    else
    {
        w->setDisabled(false);
        lw->setChecked(false);
    }
    if( pR->hasExitLock(DIR_EAST) )
    {
        e->setDisabled(true);
        le->setChecked(true);
    }
    else
    {
        e->setDisabled(false);
        le->setChecked(false);
    }
    if( pR->hasExitLock(DIR_UP) )
    {
        up->setDisabled(true);
        lup->setChecked(true);
    }
    else
    {
        up->setDisabled(false);
        lup->setChecked(false);
    }
    if( pR->hasExitLock(DIR_DOWN) )
    {
        down->setDisabled(true);
        ldown->setChecked(true);
    }
    else
    {
        down->setDisabled(false);
        ldown->setChecked(false);
    }
    if( pR->hasExitLock(DIR_IN) )
    {
        in->setDisabled(true);
        lin->setChecked(true);
    }
    else
    {
        in->setDisabled(false);
        lin->setChecked(false);
    }
    if( pR->hasExitLock(DIR_OUT) )
    {
        out->setDisabled(true);
        lout->setChecked(true);
    }
    else
    {
        out->setDisabled(false);
        lout->setChecked(false);
    }

    if( pR->getNorth() > 0 )
        n->setText(QString::number(pR->getNorth()));
    if( pR->getSouth() > 0 )
        s->setText(QString::number(pR->getSouth()));
    if( pR->getWest() > 0 )
        w->setText(QString::number(pR->getWest()));
    if( pR->getEast() > 0 )
        e->setText(QString::number(pR->getEast()));
    if( pR->getNorthwest() > 0 )
        nw->setText(QString::number(pR->getNorthwest()));
    if( pR->getNortheast() > 0 )
        ne->setText(QString::number(pR->getNortheast()));
    if( pR->getSouthwest() > 0 )
        sw->setText(QString::number(pR->getSouthwest()));
    if( pR->getSoutheast() > 0 )
        se->setText(QString::number(pR->getSoutheast()));
    if( pR->getUp() > 0 )
        up->setText(QString::number(pR->getUp()));
    if( pR->getDown() > 0 )
        down->setText(QString::number(pR->getDown()));
    if( pR->getIn() > 0 )
        in->setText(QString::number(pR->getIn()));
    if( pR->getOut() > 0 )
        out->setText(QString::number(pR->getOut()));

    QMapIterator<int, QString> it(pR->getOtherMap());
    while( it.hasNext() )
    {
        it.next();
        int id_to = it.key();
        QString dir = it.value();
        if( dir.size() < 1 )
            continue;
        QTreeWidgetItem * pI = new QTreeWidgetItem(specialExits);
        if( pR->hasSpecialExitLock( id_to, dir ) )
            pI->setCheckState( 0, Qt::Checked );
        else
            pI->setCheckState( 0, Qt::Unchecked );
        pI->setText( 1, QString::number(id_to) );
        qDebug()<<"dir="<<dir;
        if( dir.startsWith('0') || dir.startsWith('1') ) dir = dir.mid(1);

        pI->setText( 2, dir );
    }
    mRoomID = id;
}