Esempio n. 1
0
int main (int argc, char** argv)
{
    bool quiet = false;
    for(int i = 1; i < argc; i++)
    {
        string test = argv[i];
        if(test == "-q")
        {
            quiet = true;
        }
    }

    DFHack::Position * Position = 0;
    DFHack::ContextManager DFMgr("Memory.xml");
    DFHack::Context * DF;
    try
    {
        DF = DFMgr.getSingleContext();
        DF->Attach();
        Position = DF->getPosition();
    }
    catch (exception& e)
    {
        cerr << e.what() << endl;
        #ifndef LINUX_BUILD
            cin.ignore();
        #endif
        return 1;
    }
    if (Position)
    {
       int32_t x,y,z;
       int32_t width,height;

       if(Position->getViewCoords(x,y,z))
            cout << "view coords: " << x << "/" << y << "/" << z << endl;
       if(Position->getCursorCoords(x,y,z))
            cout << "cursor coords: " << x << "/" << y << "/" << z << endl;
       if(Position->getWindowSize(width,height))
           cout << "window size : " << width << " " << height << endl;
    }
    else
    {
        cerr << "cursor and window parameters are unsupported on your version of DF" << endl;
    }

    if(!DF->Detach())
    {
        cerr << "Can't detach from DF" << endl;
    }

    #ifndef LINUX_BUILD
        if(!quiet)
        {
            cout << "Done. Press any key to continue" << endl;
            cin.ignore();
        }
    #endif
    return 0;
}
QList<QImage> DwarfClipboardPng::getImagesForRange(QList<cursorIdx> range)
{
    QList<QImage> retImages;
    DFHack::Position * Pos = DF->getPosition();
    DFHack::WindowIO * Win = DF->getWindowIO();
    dfLocationIterator itr(range[0],range[1]);
    cursorIdx begin = itr.begin();
    cursorIdx end = itr.end();
    cursorIdx size;
    size.x = (end.x-begin.x)+1;
    size.y = (end.y-begin.y)+1;
    size.z = begin.z-end.z+1;
    cursorIdx oldCursor,oldPosition;
    START_READ
    Pos->getCursorCoords(oldCursor.x,oldCursor.y,oldCursor.z);
    Pos->getViewCoords(oldPosition.x,oldPosition.y,oldPosition.z);
    Pos->setCursorCoords(-30000,oldCursor.y,oldCursor.z);
    int32_t screenWidth,screenHeight;
    Pos->getWindowSize(screenWidth,screenHeight);
    int32_t effectiveWidth = screenWidth-2-55; // 55 is the width of the map and the menus
    int32_t effectiveHeight = screenHeight-2;

    DFHack::t_screen *screen;
    screen = new DFHack::t_screen[screenWidth*screenHeight];
    QString rawComplete = QString("%1,%2,%3|").arg(size.x).arg(size.y).arg(size.z);
    for(int zitr = 0;zitr < size.z;zitr++){
        QVector<QVector<QString> > rawNumbers(size.x,QVector<QString>(size.y));
        for(int xIdx = 0;xIdx < int(size.x/effectiveWidth)+1;xIdx++){
            for(int yIdx=0;yIdx < int(size.y/effectiveHeight)+1;yIdx++){
                Pos->setViewCoords(begin.x+xIdx*effectiveWidth,begin.y+yIdx*effectiveHeight,begin.z-zitr);
		END_READ
                Win->TypeSpecial(DFHack::WAIT,1,delay);
		START_READ
                Pos->getScreenTiles(screenWidth,screenHeight,screen);
		END_READ
                int ylim = effectiveHeight;
                int xlim = effectiveWidth;
                if(yIdx == int(size.y/effectiveHeight)){
                    ylim = size.y % effectiveHeight;
                }
                if(xIdx == int(size.x/effectiveWidth)){
                    xlim = size.x % effectiveWidth;
                }
                for(int yitr = 1;yitr < ylim+1;yitr++){
                    for(int xitr = 1;xitr < xlim+1;xitr++){
                        QString test = stringFromScreen(screen[yitr*screenWidth+xitr]);
                        rawNumbers[effectiveWidth*xIdx + xitr-1][effectiveHeight*yIdx + yitr-1] = test;
                    }
                }
            }
        }
        for(int yitr = 0;yitr < rawNumbers[0].size();yitr++){
            for(int xitr = 0;xitr < rawNumbers.size();xitr++){
                rawComplete.append(rawNumbers[xitr][yitr]);
            }
            rawComplete.append(':');
        }
        rawComplete.append("|");
    }
    START_READ
    Pos->setViewCoords(oldPosition.x,oldPosition.y,oldPosition.z);
    Pos->setCursorCoords(oldCursor.x,oldCursor.y,oldCursor.z);
    END_READ
    retImages = ImagesFromString(rawComplete); // this is a little weird, but it will be easier to only have to debug one way to get the images
    for(int itr = 0;itr<retImages.size();itr++){
        retImages[itr].setText("rawNumbers",rawComplete);
    }
    delete screen;
    return(retImages);
}