示例#1
0
void TRoomDB::buildAreas()
{
    QTime _time; _time.start();
    QMapIterator<int, TRoom *> it( rooms );
    while( it.hasNext() )
    {
       it.next();
       int id = it.key();
       TRoom * pR = getRoom(id);
       if( !pR ) continue;
       TArea * pA = getArea(pR->getAreaId());
       if( !pA )
       {
           areas[pR->getAreaId()] = new TArea( mpMap, this );
       }
    }

    // if the area has been created without any rooms add the area ID
    QMapIterator<int, QString> it2( areaNamesMap );
    while( it2.hasNext() )
    {
       it2.next();
       int id = it2.key();
       if( ! areas.contains( id ) )
       {
           areas[id] = new TArea( mpMap, this );
       }
    }
    qDebug()<<"BUILD AREAS run time:"<<_time.elapsed();
}
示例#2
0
文件: TMap.cpp 项目: SlySven/Mudlet2
QList<int> TMap::detectRoomCollisions( int id )
{
    TRoom * pR = mpRoomDB->getRoom( id );
    if( !pR )
    {
        QList<int> l;
        return l;
    }
    int _areaId = pR->getAreaId();
    int _x = pR->x;
    int _y = pR->y;
    int _z = pR->z;
    QList<int> collList;
    TArea * pA = mpRoomDB->getArea( _areaId );
    if( !pA )
    {
        QList<int> l;
        return l;
    }
    for( int i=0; i< pA->rooms.size(); i++ )
    {
        pR = mpRoomDB->getRoom( pA->rooms[i] );
        if( !pR ) continue;
        if( pR->x == _x && pR->y == _y && pR->z == _z )
        {
            collList.push_back( pA->rooms[i] );
        }
    }

    return collList;
}
示例#3
0
文件: TMap.cpp 项目: SlySven/Mudlet2
bool TMap::setExit( int from, int to, int dir )
{
    TRoom * pR = mpRoomDB->getRoom( from );
    TRoom * pR_to = mpRoomDB->getRoom( to );

    if( !pR ) return false;
    if( !pR_to && to > 0 ) return false;
    if( to < 1 ) to = -1;

    mPlausaOptOut = 0;
    bool ret = true;

    switch( dir )
    {
        case DIR_NORTH:
            pR->setNorth(to);
            break;
        case DIR_NORTHEAST:
            pR->setNortheast(to);
            break;
        case DIR_NORTHWEST:
            pR->setNorthwest(to);
            break;
        case DIR_EAST:
            pR->setEast(to);
            break;
        case DIR_WEST:
            pR->setWest(to);
            break;
        case DIR_SOUTH:
            pR->setSouth(to);
            break;
        case DIR_SOUTHEAST:
            pR->setSoutheast(to);
            break;
        case DIR_SOUTHWEST:
            pR->setSouthwest(to);
            break;
        case DIR_UP:
            pR->setUp(to);
            break;
        case DIR_DOWN:
            pR->setDown(to);
            break;
        case DIR_IN:
            pR->setIn(to);
            break;
        case DIR_OUT:
            pR->setOut(to);
            break;
        default:
            ret = false;
    }
    pR->setExitStub(dir, 0);
    mMapGraphNeedsUpdate = true;
    TArea * pA = mpRoomDB->getArea( pR->getAreaId() );
    pA->fast_ausgaengeBestimmen(pR->getId());
    return ret;
}
示例#4
0
// this is call by TRoom destructor only
bool TRoomDB::__removeRoom( int id )
{
    if( rooms.contains(id ) && id > 0 )
    {

        TRoom * pR = getRoom( id );
        if( !pR )
            return false;
        QMapIterator<int, TRoom *> it( rooms );
        while( it.hasNext() )
        {
            it.next();
            TRoom * r = it.value();
            if( r->getNorth() == id ) r->setNorth(-1);
            if( r->getNortheast() == id ) r->setNortheast(-1);
            if( r->getNorthwest() == id ) r->setNorthwest(-1);
            if( r->getEast() == id ) r->setEast(-1);
            if( r->getWest() == id ) r->setWest(-1);
            if( r->getSouth() == id ) r->setSouth(-1);
            if( r->getSoutheast() == id ) r->setSoutheast(-1);
            if( r->getSouthwest() == id ) r->setSouthwest(-1);
            if( r->getUp() == id ) r->setUp(-1);
            if( r->getDown() == id ) r->setDown(-1);
            if( r->getIn() == id ) r->setIn(-1);
            if( r->getOut() == id ) r->setOut(-1);
            r->removeAllSpecialExitsToRoom( id );
        }
        int _areaId = pR->getAreaId();
        TArea * pA = getArea( _areaId );
        if( !pA )
            return false;
        pA->rooms.removeAll( id );
        pA->exits.remove( id ); //note: this removes *all* keys=id
        mpMap->mMapGraphNeedsUpdate = true;
    }
    QList<QString> keyList = hashTable.keys();
    QList<int> valueList = hashTable.values();
    for( int i=0; i<valueList.size(); i++ )
    {
        if( valueList[i] == id )
        {
            hashTable.remove( keyList[i] );
        }
    }
    return true;
}
示例#5
0
文件: TMap.cpp 项目: SlySven/Mudlet2
bool TMap::serialize( QDataStream & ofs )
{
    version = CURRENT_MAP_VERSION;
    ofs << version;
    ofs << envColors;
    ofs << mpRoomDB->getAreaNamesMap();
    ofs << customEnvColors;
    ofs << mpRoomDB->hashTable;

    ofs << mpRoomDB->getAreaMap().size();
    // serialize area table
    QMapIterator<int, TArea *> itAreaList(mpRoomDB->getAreaMap());
    while( itAreaList.hasNext() )
    {
        itAreaList.next();
        int areaId = itAreaList.key();
        TArea * pA = itAreaList.value();
        ofs << areaId;
        ofs << pA->rooms;
        ofs << pA->ebenen;
        ofs << pA->exits;
        ofs << pA->gridMode;
        ofs << pA->max_x;
        ofs << pA->max_y;
        ofs << pA->max_z;
        ofs << pA->min_x;
        ofs << pA->min_y;
        ofs << pA->min_z;
        ofs << pA->span;
        ofs << pA->xmaxEbene;
        ofs << pA->ymaxEbene;
        ofs << pA->zmaxEbene;
        ofs << pA->xminEbene;
        ofs << pA->yminEbene;
        ofs << pA->zminEbene;
        ofs << pA->pos;
        ofs << pA->isZone;
        ofs << pA->zoneAreaRef;
    }

    if (mRoomId)
        ofs << mRoomId;
    else{
        mRoomId = 0;
        ofs << mRoomId;
    }
    ofs << mapLabels.size(); //anzahl der areas
    QMapIterator<int, QMap<int, TMapLabel> > itL1(mapLabels);
    while( itL1.hasNext() )
    {
        itL1.next();
        int i = itL1.key();
        ofs << itL1.value().size();//anzahl der labels pro area
        ofs << itL1.key(); //area id
        QMapIterator<int, TMapLabel> itL2(mapLabels[i]);
        while( itL2.hasNext() )
        {
            itL2.next();
// N/U:             int ii = itL2.key();
            ofs << itL2.key();//label ID
            TMapLabel label = itL2.value();
            ofs << label.pos;
            ofs << label.pointer;
            ofs << label.size;
            ofs << label.text;
            ofs << label.fgColor;
            ofs << label.bgColor;
            ofs << label.pix;
            ofs << label.noScaling;
            ofs << label.showOnTop;
        }
    }
    QMapIterator<int, TRoom *> it( mpRoomDB->getRoomMap() );
    while( it.hasNext() )
    {

        it.next();
// N/U:         int i = it.key();
        TRoom * pR = it.value();
        ofs << pR->getId();
        ofs << pR->getAreaId();
        ofs << pR->x;
        ofs << pR->y;
        ofs << pR->z;
        ofs << pR->getNorth();
        ofs << pR->getNortheast();
        ofs << pR->getEast();
        ofs << pR->getSoutheast();
        ofs << pR->getSouth();
        ofs << pR->getSouthwest();
        ofs << pR->getWest();
        ofs << pR->getNorthwest();
        ofs << pR->getUp();
        ofs << pR->getDown();
        ofs << pR->getIn();
        ofs << pR->getOut();
        ofs << pR->environment;
        ofs << pR->getWeight();
//        ofs << rooms[i]->xRot;
//        ofs << rooms[i]->yRot;
//        ofs << rooms[i]->zRot;
//        ofs << rooms[i]->zoom;
        ofs << pR->name;
        ofs << pR->isLocked;
        ofs << pR->getOtherMap();
        ofs << pR->c;
        ofs << pR->userData;
        ofs << pR->customLines;
        ofs << pR->customLinesArrow;
        ofs << pR->customLinesColor;
        ofs << pR->customLinesStyle;
        ofs << pR->exitLocks;
        ofs << pR->exitStubs;
        ofs << pR->getExitWeights();
        ofs << pR->doors;
    }

    return true;
}
示例#6
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());
}
示例#7
0
文件: TMap.cpp 项目: SlySven/Mudlet2
void TMap::connectExitStub(int roomId, int dirType)
{
    TRoom * pR = mpRoomDB->getRoom( roomId );
    if( !pR )
        return;
    int areaId = pR->getAreaId();
    int minDistance = 999999;
    int minDistanceRoom=0, meanSquareDistance=0;
    if( !unitVectors.contains( dirType ) )
        return;
    QVector3D unitVector = unitVectors[dirType];
    int ux = unitVector.x(), uy = unitVector.y(), uz = unitVector.z();
    int rx = pR->x, ry = pR->y, rz = pR->z;
    int dx=0,dy=0,dz=0;
    TArea * pA = mpRoomDB->getArea(areaId);
    if( !pA )
        return;
    for( int i=0; i< pA->rooms.size(); i++ )
    {
        pR = mpRoomDB->getRoom( pA->rooms[i] );
        if( !pR )
            continue;
        if( pR->getId() == roomId )
            continue;
        if(uz)
        {
            dz = (int)pR->z-rz;
            if(!compSign(dz,uz) || !dz) continue;
        }
        else
        {
            //to avoid lower/upper floors from stealing stubs
            if((int)pR->z != rz) continue;
        }
        if(ux)
        {
            dx = (int)pR->x-rx;
            if (!compSign(dx,ux) || !dx) //we do !dx to make sure we have a component in the desired direction
                continue;
        }
        else
        {
            //to avoid rooms on same plane from stealing stubs
            if((int)pR->x != rx) continue;
        }
        if(uy)
        {
            dy = (int)pR->y-ry;
            //if the sign is the SAME here we keep it b/c we flip our y coordinate.
            if (compSign(dy,uy) || !dy)
                continue;
        }
        else
        {
            //to avoid rooms on same plane from stealing stubs
            if((int)pR->y != ry) continue;
        }
        meanSquareDistance=dx*dx+dy*dy+dz*dz;
        if(meanSquareDistance < minDistance)
        {
            minDistanceRoom=pR->getId();
            minDistance=meanSquareDistance;
        }
    }
    if(minDistanceRoom)
    {
        pR = mpRoomDB->getRoom(minDistanceRoom);
        if( !pR ) return;
        if(pR->exitStubs.contains(reverseDirections[dirType]))
        {
            setExit( roomId, minDistanceRoom, dirType);
            setExit( minDistanceRoom, roomId, reverseDirections[dirType]);
        }
    }
}