Ejemplo n.º 1
0
int main (void)
{
    string blah;
    DFHack::ContextManager DFMgr("Memory.xml");
    DFHack::Context * DF;
    try
    {
        DF = DFMgr.getSingleContext();
        DF->Attach();
    }
    catch (exception& e)
    {
        cerr << e.what() << endl;
        #ifndef LINUX_BUILD
            cin.ignore();
        #endif
        return 1;
    }
    cout << "Attached, DF should be suspended now" << endl;
    getline(cin, blah);
    
    DF->Resume();
    cout << "Resumed, DF should be running" << endl;
    getline(cin, blah);
    
    DF->Suspend();
    cout << "Suspended, DF should be suspended now" << endl;
    getline(cin, blah);
    
    DF->Resume();
    cout << "Resumed, testing ForceResume. Suspend using SysInternals Process Explorer" << endl;
    getline(cin, blah);

    DF->ForceResume();
    cout << "ForceResumed. DF should be running." << endl;
    getline(cin, blah);

    if(!DF->Detach())
    {
        cerr << "Can't detach from DF" << endl;
        return 1;
    }
    cout << "Detached, DF should be running again" << endl;
    getline(cin, blah);
    
    return 0;
}
Ejemplo n.º 2
0
int main (int numargs, const char ** args)
{
    map<string, string> buildCommands;
    buildCommands["building_stockpilest"]="";
    buildCommands["building_zonest"]="";
    buildCommands["building_construction_blueprintst"]="";
    buildCommands["building_wagonst"]="";
    buildCommands["building_armor_standst"]="a";
    buildCommands["building_bedst"]="b";
    buildCommands["building_seatst"]="c";
    buildCommands["building_burial_receptaclest"]="n";
    buildCommands["building_doorst"]="d";
    buildCommands["building_floodgatest"]="x";
    buildCommands["building_floor_hatchst"]="H";
    buildCommands["building_wall_gratest"]="W";
    buildCommands["building_floor_gratest"]="G";
    buildCommands["building_vertical_barsst"]="B";
    buildCommands["building_floor_barsst"]="alt-b";
    buildCommands["building_cabinetst"]="f";
    buildCommands["building_containerst"]="h";
    buildCommands["building_shopst"]="";
    buildCommands["building_workshopst"]="";
    buildCommands["building_alchemists_laboratoryst"]="wa";
    buildCommands["building_carpenters_workshopst"]="wc";
    buildCommands["building_farmers_workshopst"]="ww";
    buildCommands["building_masons_workshopst"]="wm";
    buildCommands["building_craftdwarfs_workshopst"]="wr";
    buildCommands["building_jewelers_workshopst"]="wj";
    buildCommands["building_metalsmiths_workshopst"]="wf";
    buildCommands["building_magma_forgest"]="";
    buildCommands["building_bowyers_workshopst"]="wb";
    buildCommands["building_mechanics_workshopst"]="wt";
    buildCommands["building_siege_workshopst"]="ws";
    buildCommands["building_butchers_shopst"]="wU";
    buildCommands["building_leather_worksst"]="we";
    buildCommands["building_tanners_shopst"]="wn";
    buildCommands["building_clothiers_shopst"]="wk";
    buildCommands["building_fisheryst"]="wh";
    buildCommands["building_stillst"]="wl";
    buildCommands["building_loomst"]="wo";
    buildCommands["building_quernst"]="wq";
    buildCommands["building_kennelsst"]="k";
    buildCommands["building_kitchenst"]="wz";
    buildCommands["building_asheryst"]="wy";
    buildCommands["building_dyers_shopst"]="wd";
    buildCommands["building_millstonest"]="wM";
    buildCommands["building_farm_plotst"]="p";
    buildCommands["building_weapon_rackst"]="r";
    buildCommands["building_statuest"]="s";
    buildCommands["building_tablest"]="t";
    buildCommands["building_paved_roadst"]="o";
    buildCommands["building_bridgest"]="g";
    buildCommands["building_wellst"]="l";
    buildCommands["building_siege enginest"]="i";
    buildCommands["building_catapultst"]="ic";
    buildCommands["building_ballistast"]="ib";
    buildCommands["building_furnacest"]="";
    buildCommands["building_wood_furnacest"]="ew";
    buildCommands["building_smelterst"]="es";
    buildCommands["building_glass_furnacest"]="ek";
    buildCommands["building_kilnst"]="ek";
    buildCommands["building_magma_smelterst"]="es";
    buildCommands["building_magma_glass_furnacest"]="ek";
    buildCommands["building_magma_kilnst"]="ek";
    buildCommands["building_glass_windowst"]="y";
    buildCommands["building_gem_windowst"]="Y";
    buildCommands["building_tradedepotst"]="D";
    buildCommands["building_mechanismst"]="";
    buildCommands["building_leverst"]="Tl";
    buildCommands["building_pressure_platest"]="Tp";
    buildCommands["building_cage_trapst"]="Tc";
    buildCommands["building_stonefall_trapst"]="Ts";
    buildCommands["building_weapon_trapst"]="Tw";
    buildCommands["building_spikest"]="";
    buildCommands["building_animal_trapst"]="m";
    buildCommands["building_screw_pumpst"]="Ms";
    buildCommands["building_water_wheelst"]="Mw";
    buildCommands["building_windmillst"]="Mm";
    buildCommands["building_gear_assemblyst"]="Mg";
    buildCommands["building_horizontal_axlest"]="Mh";
    buildCommands["building_vertical_axlest"]="Mv";
    buildCommands["building_supportst"]="S";
    buildCommands["building_cagest"]="j";
    buildCommands["building_archery_targetst"]="A";
    buildCommands["building_restraintst"]="v";

    DFHack::ContextManager DFMgr("Memory.xml");
    DFHack::Context *DF = DFMgr.getSingleContext();
    
    try
    {
        DF->Attach();
    }
    catch (std::exception& e)
    {
        std::cerr << e.what() << std::endl;
        #ifndef LINUX_BUILD
            cin.ignore();
        #endif
        return 1;
    }
    
    DFHack::Gui *Gui = DF->getGui();
    DFHack::VersionInfo* mem = DF->getMemoryInfo();
    DFHack::Process * p = DF->getProcess();
    OffsetGroup * OG_Maps = mem->getGroup("Maps");
    OffsetGroup * OG_MapBlock = OG_Maps->getGroup("block");
    OffsetGroup * OG_LocalFt = OG_Maps->getGroup("features")->getGroup("local");
    uint32_t designations = OG_MapBlock->getOffset("designation");
    uint32_t block_feature1 = OG_MapBlock->getOffset("feature_local");
    uint32_t block_feature2 = OG_MapBlock->getOffset("feature_global");
    uint32_t region_x_offset = OG_Maps->getAddress("region_x");
    uint32_t region_y_offset = OG_Maps->getAddress("region_y");
    uint32_t region_z_offset = OG_Maps->getAddress("region_z");
    uint32_t feature1_start_ptr = OG_LocalFt->getAddress("start_ptr");
    int32_t regionX, regionY, regionZ;
    
    // read position of the region inside DF world
    p->readDWord (region_x_offset, (uint32_t &)regionX);
    p->readDWord (region_y_offset, (uint32_t &)regionY);
    p->readDWord (region_z_offset, (uint32_t &)regionZ);
    while(1){
    int32_t cx1,cy1,cz1;
    cx1 = -30000;
    while(cx1 == -30000)
    {
        DF->ForceResume();
        cout << "Set cursor at first position, then press any key";
        cin.ignore();
        DF->Suspend();
        Gui->getCursorCoords(cx1,cy1,cz1);
    }

    uint32_t tx1,ty1,tz1;
    tx1 = cx1/16;
    ty1 = cy1/16;
    tz1 = cz1;

    int32_t cx2,cy2,cz2;
    cx2 = -30000;
    while(cx2 == -30000)
    {
        DF->Resume();
        cout << "Set cursor at second position, then press any key";
        cin.ignore();
        DF->Suspend();
        Gui->getCursorCoords(cx2,cy2,cz2);
    }
    uint32_t tx2,ty2,tz2;
    tx2 = cx2/16;
    ty2 = cy2/16;
    tz2 = cz2;
    sort(tx1,tx2);
    sort(ty1,ty2);
    sort(tz1,tz2);
    sort(cx1,cx2);
    sort(cy1,cy2);
    sort(cz1,cz2);

    vector <vector<vector<string> > >dig(cz2-cz1+1,vector<vector<string> >(cy2-cy1+1,vector<string>(cx2-cx1+1)));
    vector <vector<vector<string> > >build(cz2-cz1+1,vector<vector<string> >(cy2-cy1+1,vector<string>(cx2-cx1+1)));
    mapblock40d block;
    DFHack::Maps *Maps = DF->getMaps();
    Maps->Start();
    for(uint32_t y = ty1;y<=ty2;y++)
    {
        for(uint32_t x = tx1;x<=tx2;x++)
        {
            for(uint32_t z = tz1;z<=tz2;z++)
            {
                if(Maps->isValidBlock(x,y,z))
                {
                    if(Maps->ReadBlock40d(x,y,z,&block))
                    {
                        int ystart,yend,xstart,xend;
                        ystart=xstart=0;
                        yend=xend=15;
                        if(y == ty2)
                        {
                            yend = cy2 % 16;
                        }
                        if(y == ty1)
                        {
                            ystart = cy1 % 16;
                        }
                        if(x == tx2)
                        {
                            xend = cx2 % 16;
                        }
                        if(x == tx1)
                        {
                            xstart = cx1 % 16;
                        }
                        int zidx = z-tz1;
                        for(int yy = ystart; yy <= yend;yy++)
                        {
                            int yidx = yy+(16*(y-ty1)-(cy1%16));
                            for(int xx = xstart; xx <= xend;xx++)
                            {
                                int xidx = xx+(16*(x-tx1)-(cx1%16));
                                int16_t tt = block.tiletypes[xx][yy];
                                DFHack::TileShape ts = DFHack::tileShape(tt);
                                if(DFHack::isOpenTerrain(tt) || DFHack::isFloorTerrain(tt))
                                {
                                    dig[zidx][yidx][xidx] = "d";
                                }
                                else if(DFHack::STAIR_DOWN == ts)
                                {
                                    dig [zidx][yidx][xidx] = "j";
                                    build [zidx][yidx][xidx] = "Cd";
                                }
                                else if(DFHack::STAIR_UP == ts)
                                {
                                    dig [zidx][yidx][xidx] = "u";
                                    build [zidx][yidx][xidx] = "Cu";
                                }
                                else if(DFHack::STAIR_UPDOWN == ts)
                                {
                                    dig [zidx][yidx][xidx] = "i";
                                    build [zidx][yidx][xidx] = "Cx";
                                }
                                else if(DFHack::isRampTerrain(tt))
                                {
                                    dig [zidx][yidx][xidx] = "r";
                                    build [zidx][yidx][xidx] = "Cr";
                                }
                                else if(DFHack::isWallTerrain(tt))
                                {
                                    build [zidx][yidx][xidx] = "Cw";
                                }
                            }
                            yidx++;
                        }
                    }
                }
            }
        }
    }
    DFHack::Buildings * Bld = DF->getBuildings();
    std::map <uint32_t, std::string> custom_workshop_types;
    uint32_t numBuildings;
    if(Bld->Start(numBuildings))
    {
        Bld->ReadCustomWorkshopTypes(custom_workshop_types);
        for(uint32_t i = 0; i < numBuildings; i++)
        {
            DFHack::t_building temp;
            Bld->Read(i, temp);
            if(temp.type != 0xFFFFFFFF) // check if type isn't invalid
            {
                std::string typestr;
                mem->resolveClassIDToClassname(temp.type, typestr);
                if(temp.z == cz1 && cx1 <= temp.x1 && cx2 >= temp.x2 && cy1 <= temp.y1 && cy2 >= temp.y2)
                {
                    string currStr = build[temp.z-cz1][temp.y1-cy1][temp.x1-cx1];
                    stringstream stream;
                    string newStr = buildCommands[typestr];
                    if(temp.x1 != temp.x2)
                    {
                        stream << "(" << temp.x2-temp.x1+1 << "x" << temp.y2-temp.y1+1 << ")";
                        newStr += stream.str();
                    }
                    build[temp.z-cz1][temp.y1-cy1][temp.x1-cx1] = newStr + currStr;
                }
            }
        }
    }
// for testing purposes
    //ofstream outfile("test.txt");
//    printVecOfVec(outfile, dig,'\t');
//    outfile << endl;
//   printVecOfVec(outfile, build,'\t');
//    outfile << endl;
//    outfile.close();

    int32_t cx3,cy3,cz3,cx4,cy4,cz4;
    uint32_t tx3,ty3,tz3,tx4,ty4,tz4;
    char result;
    while(1){
        cx3 = -30000;
        while(cx3 == -30000){
            DF->Resume();
            cout << "Set cursor at new position, then press any key:";
            result = cin.get();
            DF->Suspend();
            Gui->getCursorCoords(cx3,cy3,cz3);
        }
        if(result == 'q'){
            break;
        }
        cx4 = cx3+cx2-cx1;
        cy4 = cy3+cy2-cy1;
        cz4 = cz3+cz2-cz1;
        tx3=cx3/16;
        ty3=cy3/16;
        tz3=cz3;
        tx4=cx4/16;
        ty4=cy4/16;
        tz4=cz4;
        DFHack::WindowIO * Win = DF->getWindowIO();
        designations40d designationBlock;
        for(uint32_t y = ty3;y<=ty4;y++)
        {
            for(uint32_t x = tx3;x<=tx4;x++)
            {
                for(uint32_t z = tz3;z<=tz4;z++)
                {
                    Maps->Start();
                    Maps->ReadBlock40d(x,y,z,&block);
                    Maps->ReadDesignations(x,y,z,&designationBlock);
                    int ystart,yend,xstart,xend;
                    ystart=xstart=0;
                    yend=xend=15;
                    if(y == ty4){
                        yend = cy4 % 16;
                    }
                    if(y == ty3){
                        ystart = cy3 % 16;
                    }
                    if(x == tx4){
                        xend = cx4 % 16;
                    }
                    if(x == tx3){
                        xstart = cx3 % 16;
                    }
                    int zidx = z-tz3;
                    for(int yy = ystart; yy <= yend;yy++){
                        int yidx = yy+(16*(y-ty3)-(cy3%16));
                        for(int xx = xstart; xx <= xend;xx++){
                            int xidx = xx+(16*(x-tx3)-(cx3%16));
                                if(dig[zidx][yidx][xidx] != ""){
                                    char test = dig[zidx][yidx][xidx].c_str()[0];
                                    switch (test){
                                        case 'd':
                                            designationBlock[xx][yy].bits.dig = DFHack::designation_default;
                                            break;
                                        case 'i':
                                            designationBlock[xx][yy].bits.dig = DFHack::designation_ud_stair;
                                            break;
                                        case 'u':
                                            designationBlock[xx][yy].bits.dig = DFHack::designation_u_stair;
                                            break;
                                        case 'j':
                                            designationBlock[xx][yy].bits.dig = DFHack::designation_d_stair;
                                            break;
                                        case 'r':
                                            designationBlock[xx][yy].bits.dig = DFHack::designation_ramp;
                                            break;
                                    }
                                
                                }
                        }
                        yidx++;
                    }
                    Maps->Start();
                    Maps->WriteDesignations(x,y,z,&designationBlock);
                }
            }
        }
    }
    }
    DF->Detach();
    #ifndef LINUX_BUILD
    std::cout << "Done. Press any key to continue" << std::endl;
    cin.ignore();
    #endif
    return 0;
}
Ejemplo n.º 3
0
int main (int argc, char* argv[])
{
    // Command line options
    bool updown = false;
    if(argc > 1 && strcmp(argv[1],"-x") == 0)
        updown = true;

    DFHack::ContextManager DFMgr("Memory.xml");
    DFHack::Context * DF;
    try
    {
        DF = DFMgr.getSingleContext();
        DF->Attach();
    }
    catch (exception& e)
    {
        cerr << e.what() << endl;
        #ifndef LINUX_BUILD
            cin.ignore();
        #endif
        return 1;
    }

    uint32_t x_max,y_max,z_max;
    DFHack::Maps * Maps = DF->getMaps();
    DFHack::Gui * Gui = DF->getGui();

    // init the map
    if(!Maps->Start())
    {
        cerr << "Can't init map. Make sure you have a map loaded in DF." << endl;
        DF->Detach();
        #ifndef LINUX_BUILD
            cin.ignore();
        #endif
        return 1;
    }

    int32_t cx, cy, cz;
    Maps->getSize(x_max,y_max,z_max);
    uint32_t tx_max = x_max * 16;
    uint32_t ty_max = y_max * 16;

    Gui->getCursorCoords(cx,cy,cz);
    while(cx == -30000)
    {
        cerr << "Cursor is not active. Point the cursor at a vein." << endl;
        DF->Resume();
        cin.ignore();
        DF->Suspend();
        Gui->getCursorCoords(cx,cy,cz);
    }
    DFHack::DFCoord xy ((uint32_t)cx,(uint32_t)cy,cz);
    if(xy.x == 0 || xy.x == tx_max - 1 || xy.y == 0 || xy.y == ty_max - 1)
    {
        cerr << "I won't dig the borders. That would be cheating!" << endl;
        DF->Detach();
        #ifndef LINUX_BUILD
            cin.ignore();
        #endif
        return 1;
    }
    MapCache * MCache = new MapCache(Maps);

    DFHack::t_designation des = MCache->designationAt(xy);
    int16_t tt = MCache->tiletypeAt(xy);
    int16_t veinmat = MCache->veinMaterialAt(xy);

    if( veinmat == -1 )
    {
        cerr << "This tile is non-vein. Bye :)" << endl;
        delete MCache;
        DF->Detach();
        #ifndef LINUX_BUILD
            cin.ignore();
        #endif
        return 1;
    }
    printf("%d/%d/%d tiletype: %d, veinmat: %d, designation: 0x%x ... DIGGING!\n", cx,cy,cz, tt, veinmat, des.whole);
    stack <DFHack::DFCoord> flood;
    flood.push(xy);


    while( !flood.empty() )
    {
        DFHack::DFCoord current = flood.top();
        flood.pop();
        int16_t vmat2 = MCache->veinMaterialAt(current);
        tt = MCache->tiletypeAt(current);
        if(!DFHack::isWallTerrain(tt))
            continue;
        if(vmat2!=veinmat)
            continue;

        // found a good tile, dig+unset material
        DFHack::t_designation des = MCache->designationAt(current);
        DFHack::t_designation des_minus;
        DFHack::t_designation des_plus;
        des_plus.whole = des_minus.whole = 0;
        int16_t vmat_minus = -1;
        int16_t vmat_plus = -1;
        bool below = 0;
        bool above = 0;
        if(updown)
        {
            if(MCache->testCoord(current-1))
            {
                below = 1;
                des_minus = MCache->designationAt(current-1);
                vmat_minus = MCache->veinMaterialAt(current-1);
            }

            if(MCache->testCoord(current+1))
            {
                above = 1;
                des_plus = MCache->designationAt(current+1);
                vmat_plus = MCache->veinMaterialAt(current+1);
            }
        }
        if(MCache->testCoord(current))
        {
            MCache->clearMaterialAt(current);
            if(current.x < tx_max - 2)
            {
                flood.push(DFHack::DFCoord(current.x + 1, current.y, current.z));
                if(current.y < ty_max - 2)
                {
                    flood.push(DFHack::DFCoord(current.x + 1, current.y + 1,current.z));
                    flood.push(DFHack::DFCoord(current.x, current.y + 1,current.z));
                }
                if(current.y > 1)
                {
                    flood.push(DFHack::DFCoord(current.x + 1, current.y - 1,current.z));
                    flood.push(DFHack::DFCoord(current.x, current.y - 1,current.z));
                }
            }
            if(current.x > 1)
            {
                flood.push(DFHack::DFCoord(current.x - 1, current.y,current.z));
                if(current.y < ty_max - 2)
                {
                    flood.push(DFHack::DFCoord(current.x - 1, current.y + 1,current.z));
                    flood.push(DFHack::DFCoord(current.x, current.y + 1,current.z));
                }
                if(current.y > 1)
                {
                    flood.push(DFHack::DFCoord(current.x - 1, current.y - 1,current.z));
                    flood.push(DFHack::DFCoord(current.x, current.y - 1,current.z));
                }
            }
            if(updown)
            {
                if(current.z > 0 && below && vmat_minus == vmat2)
                {
                    flood.push(current-1);

                    if(des_minus.bits.dig == DFHack::designation_d_stair)
                        des_minus.bits.dig = DFHack::designation_ud_stair;
                    else
                        des_minus.bits.dig = DFHack::designation_u_stair;
                    MCache->setDesignationAt(current-1,des_minus);

                    des.bits.dig = DFHack::designation_d_stair;
                }
                if(current.z < z_max - 1 && above && vmat_plus == vmat2)
                {
                    flood.push(current+ 1);

                    if(des_plus.bits.dig == DFHack::designation_u_stair)
                        des_plus.bits.dig = DFHack::designation_ud_stair;
                    else
                        des_plus.bits.dig = DFHack::designation_d_stair;
                    MCache->setDesignationAt(current+1,des_plus);

                    if(des.bits.dig == DFHack::designation_d_stair)
                        des.bits.dig = DFHack::designation_ud_stair;
                    else
                        des.bits.dig = DFHack::designation_u_stair;
                }
            }
            if(des.bits.dig == DFHack::designation_no)
                des.bits.dig = DFHack::designation_default;
            MCache->setDesignationAt(current,des);
        }
    }
    MCache->WriteAll();
    delete MCache;
    DF->Detach();
    #ifndef LINUX_BUILD
        cout << "Done. Press any key to continue" << endl;
        cin.ignore();
    #endif
    return 0;
}
Ejemplo n.º 4
0
int main(int argc, char *argv[])
{
    /* initialize your non-curses data structures here */

    signal(SIGINT, finish);      /* arrange interrupts to terminate */
    setlocale(LC_ALL,"");
    initscr();      /* initialize the curses library */
    keypad(stdscr, TRUE);  /* enable keyboard mapping */
    nonl();         /* tell curses not to do NL->CR/NL on output */
    cbreak();       /* take input chars one at a time, no wait for \n */
    noecho();       /* don't echo input */
    //nodelay(stdscr, true); 

    keypad(stdscr, TRUE);
    scrollok(stdscr, TRUE);

    if (has_colors())
    {
        start_color();

        /*
         * Simple color assignment, often all we need.
         */
        init_pair(COLOR_BLACK, COLOR_BLACK, COLOR_BLACK);
        init_pair(COLOR_GREEN, COLOR_GREEN, COLOR_BLACK);
        init_pair(COLOR_RED, COLOR_RED, COLOR_BLACK);
        init_pair(COLOR_BLUE, COLOR_BLUE, COLOR_BLACK);
        init_pair(COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK);

        init_color(COLOR_CYAN, 700, 700, 700); // lt grey
        init_color(COLOR_MAGENTA, 500, 500, 500); // dk grey
        init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK);
        init_pair(COLOR_CYAN, COLOR_CYAN, COLOR_BLACK);
        init_pair(COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);
    }
    
    int x_max,y_max,z_max;
    uint32_t x_max_a,y_max_a,z_max_a;
    /*
    uint16_t tiletypes[16][16];
    DFHack::t_designation designations[16][16];
    uint8_t regionoffsets[16];
    */
    map <int16_t, uint32_t> materials;
    materials.clear();
    mapblock40d blocks[3][3];
    vector<DFHack::t_effect_df40d> effects;
    vector< vector <uint16_t> > layerassign;
    vector<t_vein> veinVector;
    vector<t_frozenliquidvein> IceVeinVector;
    vector<t_spattervein> splatter;
    vector<t_grassvein> grass;
    vector<t_worldconstruction> wconstructs;
    t_temperatures b_temp1;
    t_temperatures b_temp2;

    DFHack::Materials * Mats = 0;
    DFHack::Maps * Maps = 0;
    
    
    DFHack::ContextManager DFMgr("Memory.xml");
    DFHack::Context* DF;
    try
    {
        pDF = DF = DFMgr.getSingleContext();
        DF->Attach();
        Maps = DF->getMaps();
    }
    catch (exception& e)
    {
        cerr << e.what() << endl;
        #ifndef LINUX_BUILD
            cin.ignore();
        #endif
        finish(0);
    }
    bool hasmats = true;
    try
    {
        Mats = DF->getMaterials();
    }
    catch (exception& e)
    {
        hasmats = false;
    }
    
    // init the map
    if(!Maps->Start())
    {
        error = "Can't find a map to look at.";
        finish(0);
    }

    Maps->getSize(x_max_a,y_max_a,z_max_a);
    x_max = x_max_a;
    y_max = y_max_a;
    z_max = z_max_a;
    
    bool hasInorgMats = false;
    bool hasPlantMats = false;
    bool hasCreatureMats = false;

    if(hasmats)
    {
        // get stone matgloss mapping
        if(Mats->ReadInorganicMaterials())
        {
            hasInorgMats = true;
        }
        if(Mats->ReadCreatureTypes())
        {
            hasCreatureMats = true;
        }
        if(Mats->ReadOrganicMaterials())
        {
            hasPlantMats = true;
        }
    }
/*
    // get region geology
    if(!DF.ReadGeology( layerassign ))
    {
        error = "Can't read local geology.";
        pDF = 0;
        finish(0);
    }
*/
    // FIXME: could fail on small forts
    int cursorX = x_max/2 - 1;
    int cursorY = y_max/2 - 1;
    int cursorZ = z_max/2 - 1;
    
    
    bool dig = false;
    bool dump = false;
    bool digbit = false;
    bool dotwiddle;
    unsigned char twiddle = 0;
    int vein = 0;
    int filenum = 0;
    bool dirtybit = false;
    uint32_t blockaddr = 0;
    uint32_t blockaddr2 = 0;
    t_blockflags bflags;
    bflags.whole = 0;
    enum e_tempmode
    {
        TEMP_NO,
        TEMP_1,
        TEMP_2,
        WATER_SALT,
        WATER_STAGNANT
    };
    e_tempmode temperature = TEMP_NO;
    
    // resume so we don't block DF while we wait for input
    DF->Resume();
    
    for (;;)
    {
        dig = false;
        dump = false;
        dotwiddle = false;
        digbit = false;
        
        int c = getch();     /* refresh, accept single keystroke of input */
        flushinp();
        clrscr();
        /* process the command keystroke */
        switch(c)
        {
            case KEY_DOWN:
                cursorY ++;
                break;
            case KEY_UP:
                cursorY --;
                break;
            case KEY_LEFT:
                cursorX --;
                break;
            case KEY_RIGHT:
                cursorX ++;
                break;
            case KEY_NPAGE:
                cursorZ --;
                break;
            case KEY_PPAGE:
                cursorZ ++;
                break;
            case '+':
                vein ++;
                break;
            case 'd':
                dig = true;
                break;
            case 'o':
                dump = true;
                break;
            case '-':
                vein --;
                break;
            case 'z':
                digbit = true;
                break;
            case '/':
                if(twiddle != 0) twiddle--;
                break;
            case '*':
                twiddle++;
                break;
            case 't':
                dotwiddle = true;
                break;
            case 'b':
                temperature = TEMP_NO;
                break;
            case 'n':
                temperature = TEMP_1;
                break;
            case 'm':
                temperature = TEMP_2;
                break;
            case 'c':
                temperature = WATER_SALT;
                break;
            case 'v':
                temperature = WATER_STAGNANT;
                break;
            case 27: // escape key
                DF->Detach();
                return 0;
                break;
            default:
                break;
        }
        cursorX = max(cursorX, 0);
        cursorY = max(cursorY, 0);
        cursorZ = max(cursorZ, 0);
        
        cursorX = min(cursorX, x_max - 1);
        cursorY = min(cursorY, y_max - 1);
        cursorZ = min(cursorZ, z_max - 1);
        
        if(twiddle > 31)
            twiddle = 31;
        
        // clear data before we suspend
        memset(blocks,0,sizeof(blocks));
        veinVector.clear();
        IceVeinVector.clear();
        effects.clear();
        splatter.clear();
        grass.clear();
        dirtybit = 0;
        
        // Supend, read/write data
        DF->Suspend();
        // restart cleared modules
        Maps->Start();
        if(hasmats)
        {
            Mats->Start();
            if(hasInorgMats)
            {
                Mats->ReadInorganicMaterials();
            }
            if(hasPlantMats)
            {
                Mats->ReadOrganicMaterials();
            }
            if(hasCreatureMats)
            {
                Mats->ReadCreatureTypes();
            }
        }
        /*
        if(DF.InitReadEffects(effectnum))
        {
            for(uint32_t i = 0; i < effectnum;i++)
            {
                t_effect_df40d effect;
                DF.ReadEffect(i,effect);
                effects.push_back(effect);
            }
        }
        */
        for(int i = -1; i <= 1; i++) for(int j = -1; j <= 1; j++)
        {
            mapblock40d * Block = &blocks[i+1][j+1];
            if(Maps->isValidBlock(cursorX+i,cursorY+j,cursorZ))
            {
                Maps->ReadBlock40d(cursorX+i,cursorY+j,cursorZ, Block);
                // extra processing of the block in the middle
                if(i == 0 && j == 0)
                {
                    if(hasInorgMats)
                        do_features(DF, Block, cursorX, cursorY, 50,10, Mats->inorganic);
                    // read veins
                    Maps->ReadVeins(cursorX+i,cursorY+j,cursorZ,&veinVector,&IceVeinVector,&splatter,&grass, &wconstructs);

                    // get pointer to block
                    blockaddr = Maps->getBlockPtr(cursorX+i,cursorY+j,cursorZ);
                    blockaddr2 = Block->origin;

                    // dig all veins and trees
                    if(dig)
                    {
                        for(int x = 0; x < 16; x++) for(int y = 0; y < 16; y++)
                        {
                            int16_t tiletype = Block->tiletypes[x][y];
                            TileShape tc = tileShape(tiletype);
                            TileMaterial tm = tileMaterial(tiletype);
                            if( tc == WALL && tm == VEIN || tc == TREE_OK || tc == TREE_DEAD)
                            {
                                Block->designation[x][y].bits.dig = designation_default;
                            }
                        }
                        Maps->WriteDesignations(cursorX+i,cursorY+j,cursorZ, &(Block->designation));
                    }
                    
                    // read temperature data
                    Maps->ReadTemperatures(cursorX+i,cursorY+j,cursorZ,&b_temp1, &b_temp2 );
                    if(dotwiddle)
                    {
                        bitset<32> bs = Block->designation[0][0].whole;
                        bs.flip(twiddle);
                        Block->designation[0][0].whole = bs.to_ulong();
                        Maps->WriteDesignations(cursorX+i,cursorY+j,cursorZ, &(Block->designation));
                        dotwiddle = false;
                    }
                    
                    // do a dump of the block data
                    if(dump)
                    {
                        hexdump(DF,blockaddr,0x1E00,filenum);
                        filenum++;
                    }
                    // read/write dirty bit of the block
                    Maps->ReadDirtyBit(cursorX+i,cursorY+j,cursorZ,dirtybit);
                    Maps->ReadBlockFlags(cursorX+i,cursorY+j,cursorZ,bflags);
                    if(digbit)
                    {
                        dirtybit = !dirtybit;
                        Maps->WriteDirtyBit(cursorX+i,cursorY+j,cursorZ,dirtybit);
                    }
                }
            }
        }
        // Resume, print stuff to the terminal
        DF->Resume();
        for(int i = -1; i <= 1; i++) for(int j = -1; j <= 1; j++)
        {
            mapblock40d * Block = &blocks[i+1][j+1];
            for(int x = 0; x < 16; x++) for(int y = 0; y < 16; y++)
            {
                int color = COLOR_BLACK;
                color = pickColor(Block->tiletypes[x][y]);
                /*
                if(!Block->designation[x][y].bits.hidden)
                {
                    puttile(x+(i+1)*16,y+(j+1)*16,Block->tiletypes[x][y], color);
                }
                else*/
                {
                    
                    attron(A_STANDOUT);
                    puttile(x+(i+1)*16,y+(j+1)*16,Block->tiletypes[x][y], color);
                    attroff(A_STANDOUT);
                    
                }
            }
            // print effects for the center tile
            /*
            if(i == 0 && j == 0)
            {
                for(uint zz = 0; zz < effects.size();zz++)
                {
                    if(effects[zz].z == cursorZ && !effects[zz].isHidden)
                    {
                        // block coords to tile coords
                        uint16_t x = effects[zz].x - (cursorX * 16);
                        uint16_t y = effects[zz].y - (cursorY * 16);
                        if(x < 16 && y < 16)
                        {
                            putch(x + 16,y + 16,'@',COLOR_WHITE);
                        }
                    }
                }
            }
            */
        }
        gotoxy(50,0);
        cprintf("arrow keys, PGUP, PGDN = navigate");
        gotoxy(50,1);
        cprintf("+,-                    = switch vein");
        gotoxy(50,2);
        uint32_t mineralsize = veinVector.size();
        uint32_t icesize = IceVeinVector.size();
        uint32_t splattersize = splatter.size();
        uint32_t grasssize = grass.size();
        uint32_t wconstrsize = wconstructs.size();
        uint32_t totalVeinSize =  mineralsize+ icesize + splattersize + grasssize + wconstrsize;
        if(vein == totalVeinSize) vein = totalVeinSize - 1;
        if(vein < -1) vein = -1;
        cprintf("X %d/%d, Y %d/%d, Z %d/%d. Vein %d of %d",cursorX+1,x_max,cursorY+1,y_max,cursorZ,z_max,vein+1,totalVeinSize);
        if(!veinVector.empty() || !IceVeinVector.empty() || !splatter.empty() || !grass.empty() || !wconstructs.empty())
        {
            if(vein != -1 && vein < totalVeinSize)
            {
                uint32_t realvein = 0;
                if(vein < mineralsize)
                {
                    realvein = vein;
                    //iterate through vein rows
                    for(uint32_t j = 0;j<16;j++)
                    {
                        //iterate through the bits
                        for (uint32_t k = 0; k< 16;k++)
                        {
                            // and the bit array with a one-bit mask, check if the bit is set
                            bool set = !!(((1 << k) & veinVector[realvein].assignment[j]) >> k);
                            if(set)
                            {
                                putch(k+16,j+16,'$',COLOR_RED);
                            }
                        }
                    }
                    if(hasInorgMats)
                    {
                        gotoxy(50,3);
                        cprintf("Mineral: %s",Mats->inorganic[veinVector[vein].type].id);
                    }
                }
                else if (vein < mineralsize + icesize)
                {
                    realvein = vein - mineralsize;
                    t_frozenliquidvein &frozen = IceVeinVector[realvein];
                    for(uint32_t i = 0;i<16;i++)
                    {
                        for (uint32_t j = 0; j< 16;j++)
                        {
                            int color = COLOR_BLACK;
                            int tile = frozen.tiles[i][j];
                            color = pickColor(tile);
                            
                            attron(A_STANDOUT);
                            puttile(i+16,j+16,tile, color);
                            attroff(A_STANDOUT);
                        }
                    }
                    gotoxy(50,3);
                    cprintf("ICE");
                }
                else if(vein < mineralsize + icesize + splattersize)
                {
                    realvein = vein - mineralsize - icesize;
                    for(uint32_t yyy = 0; yyy < 16; yyy++)
                    {
                        for(uint32_t xxx = 0; xxx < 16; xxx++) 
                        {
                            uint8_t intensity = splatter[realvein].intensity[xxx][yyy];
                            if(intensity)
                            {
                                attron(A_STANDOUT);
                                putch(xxx+16,yyy+16,'*', COLOR_RED);
                                attroff(A_STANDOUT);
                            }
                        }
                    }
                    if(hasCreatureMats)
                    {
                        gotoxy(50,3);
                        cprintf("Spatter: %s",PrintSplatterType(splatter[realvein].mat1,splatter[realvein].mat2,Mats->race).c_str());
                    }
                }
                else if(vein < mineralsize + icesize + splattersize + grasssize)
                {
                    realvein = vein - mineralsize - icesize - splattersize;
                    t_grassvein & grassy =grass[realvein];
                    for(uint32_t yyy = 0; yyy < 16; yyy++)
                    {
                        for(uint32_t xxx = 0; xxx < 16; xxx++) 
                        {
                            uint8_t intensity = grassy.intensity[xxx][yyy];
                            if(intensity)
                            {
                                attron(A_STANDOUT);
                                putch(xxx+16,yyy+16,'X', COLOR_RED);
                                attroff(A_STANDOUT);
                            }
                        }
                    }
                    if(hasPlantMats)
                    {
                        gotoxy(50,3);
                        cprintf("Grass: 0x%x, %s",grassy.address_of, Mats->organic[grassy.material].id);
                    }
                }
                else
                {
                    realvein = vein - mineralsize - icesize - splattersize - grasssize;
                    t_worldconstruction & wconstr=wconstructs[realvein];
                    for(uint32_t j = 0; j < 16; j++)
                    {
                        for(uint32_t k = 0; k < 16; k++) 
                        {
                            bool set = !!(((1 << k) & wconstr.assignment[j]) >> k);
                            if(set)
                            {
                                putch(k+16,j+16,'$',COLOR_RED);
                            }
                        }
                    }
                    if(hasInorgMats)
                    {
                        gotoxy(50,3);
                        cprintf("Road: 0x%x, %d - %s", wconstr.address_of, wconstr.material,Mats->inorganic[wconstr.material].id);
                    }
                }
            }
Ejemplo n.º 5
0
int main (void)
{
    uint32_t x_max,y_max,z_max;
    DFHack::designations40d designations;
    
    DFHack::ContextManager DFMgr("Memory.xml");
    DFHack::Context *DF;
    try
    {
        DF = DFMgr.getSingleContext();
        DF->Attach();
    }
    catch (exception& e)
    {
        cerr << e.what() << endl;
        #ifndef LINUX_BUILD
            cin.ignore();
        #endif
        return 1;
    }
    
    DFHack::Maps *Maps =DF->getMaps();
    DFHack::Gui *Gui =DF->getGui();
    // walk the map, save the hide bits, reveal.
    cout << "Pausing..." << endl;

    // horrible hack to make sure the pause is really set
    // preblem here is that we could be 'arriving' at the wrong time and DF could be in the middle of a frame.
    // that could mean that revealing, even with suspending DF's thread, would mean unleashing hell *in the same frame* 
    // this here hack sets the pause state, resumes DF, waits a second for it to enter the pause (I know, BS value.) and suspends.
    Gui->SetPauseState(true);
    DF->Resume();
    waitmsec(1000);
    DF->Suspend();

    // init the map
    if(!Maps->Start())
    {
        cerr << "Can't init map." << endl;
        #ifndef LINUX_BUILD
            cin.ignore();
        #endif
        return 1;
    }

    cout << "Revealing, please wait..." << endl;

    Maps->getSize(x_max,y_max,z_max);
    vector <hideblock> hidesaved;

    for(uint32_t x = 0; x< x_max;x++)
    {
        for(uint32_t y = 0; y< y_max;y++)
        {
            for(uint32_t z = 0; z< z_max;z++)
            {
                if(Maps->isValidBlock(x,y,z))
                {
                    hideblock hb;
                    hb.x = x;
                    hb.y = y;
                    hb.z = z;
                    // read block designations
                    Maps->ReadDesignations(x,y,z, &designations);
                    // change the hidden flag to 0
                    for (uint32_t i = 0; i < 16;i++) for (uint32_t j = 0; j < 16;j++)
                    {
                        hb.hiddens[i][j] = designations[i][j].bits.hidden;
                        designations[i][j].bits.hidden = 0;
                    }
                    hidesaved.push_back(hb);
                    // write the designations back
                    Maps->WriteDesignations(x,y,z, &designations);
                }
            }
        }
    }
    // FIXME: force game pause here!
    DF->Detach();
    cout << "Map revealed. The game has been paused for you." << endl;
    cout << "Unpausing can unleash the forces of hell!" << endl << endl;
    cout << "Press any key to unreveal." << endl;
    cout << "Close to keep the map revealed." << endl;
    cin.ignore();
    cout << "Unrevealing... please wait." << endl;
    // FIXME: do some consistency checks here!
    DF->Attach();
    Maps = DF->getMaps();
    Maps->Start();
    for(int i = 0; i < hidesaved.size();i++)
    {
        hideblock & hb = hidesaved[i];
        Maps->ReadDesignations(hb.x,hb.y,hb.z, &designations);
        for (uint32_t i = 0; i < 16;i++) for (uint32_t j = 0; j < 16;j++)
        {
            designations[i][j].bits.hidden = hb.hiddens[i][j];
        }
        Maps->WriteDesignations(hb.x,hb.y,hb.z, &designations);
    }
    #ifndef LINUX_BUILD
    cout << "Done. Press any key to continue" << endl;
    cin.ignore();
    #endif
    return 0;
}
Ejemplo n.º 6
0
int main (void)
{
    int32_t x,y,z,tx,ty;
    //DFHack::designations40d designations;
    DFHack::tiletypes40d tiles;
    //DFHack::t_temperatures temp1,temp2;
    uint32_t x_max,y_max,z_max;
    int32_t oldT, newT;
	int count, dirty;

	//Brush defaults
	DFHack::TileShape BrushClass = DFHack::WALL;
	DFHack::TileMaterial BrushMat = DFHack::tilematerial_invalid;
	int BrushType = -1;

    DFHack::ContextManager DFMgr("Memory.xml");
    DFHack::Context *DF;
    DFHack::Maps * Maps;
    DFHack::Gui * Gui;
    try
    {
        DF=DFMgr.getSingleContext();
        DF->Attach();
        Maps = DF->getMaps();
        Maps->Start();
        Maps->getSize(x_max,y_max,z_max);
        Gui = DF->getGui();
    }
    catch (exception& e)
    {
        cerr << e.what() << endl;
        #ifndef LINUX_BUILD
            cin.ignore();
        #endif
        return 1;
    }
    bool end = false;
    cout << "Welcome to the Tile Drawing tool.\nType 'help' or ? for a list of available commands, 'q' to quit" << endl;
    string mode = "wall";
    string command = "";

	while(!end)
	{
        DF->Resume();

		cout << endl << ":";
		getline(cin, command);
		int ch = command[0];
		if(command.length()<=0) ch=0;
		if( ((int)command.find("help")) >=0 ) ch='?';  //under windows, find was casting unsigned!
		switch(ch)
        {
		case '?':
            cout << "Modes:" << endl
				 << "O             - draw Open Space" << endl
                 << "M             - draw material only (shape unchanged)" << endl
                 << "m number      - use Material value entered" << endl
                 << "r             - use Rock/stone material" << endl
                 << "l             - use Soil material" << endl
                 << "v             - use Vein material" << endl
                 << "H             - draw tile shape only (material unchanged)" << endl
				 << "h number      - draw Tile Shape value entered" << endl
                 << "w             - draw Wall tiles" << endl
                 << "f             - draw Floor tiles" << endl
				 << "t number      - draw exact tile type entered" << endl
                 << "Commands:" << endl
                 << "p             - print tile shapes and materials, and current brush" << endl
                 << "P             - print all tile types" << endl
                 << "q             - quit" << endl
                 << "help OR ?     - print this list of commands" << endl
                 << "d             - being drawing" << endl
                 << endl
                 << "Usage:\nChoose a mode (default is walls), then enter 'd' to being drawing.\nMove the cursor in DF wherever you want to draw.\nPress any key to pause drawing." << endl;
			break;
		case 'p':
			//Classes
			printf("\nTile Type Classes:\n");
			for(int i=0;i<DFHack::tileshape_count;++i)
			{
				printf("%4i ; %s\n", i, DFHack::TileShapeString[i] ,0 );
			}
			//Materials
			printf("\nTile Type Materials:\n");
			for(int i=0;i<DFHack::tilematerial_count;++i)
			{
				printf("%4i ; %s\n", i, DFHack::TileMaterialString[i] ,0 );
			}
			//fall through...
		case 10:
		case 13:
		case 0:
			//Print current cursor & brush settings.
			cout << "\nCurrent Brush:\n";
			cout << "tile = ";
			if(BrushClass<0) cout<<"(not drawing)"; else cout<<DFHack::TileShapeString[BrushClass]; cout << endl;
			cout << "mat  = ";
			if(BrushMat<0) cout<<"(not drawing)"; else cout<<DFHack::TileMaterialString[BrushMat]; cout << endl;
			cout << "type = ";
			if(BrushType<0){
				cout<<"(not drawing)";
			}else{
				printtiletype(BrushType);
			}
			break;
		case 'P':
			cout << "\nAll Valid Tile Types:\n";
			for(int i=0;i<TILE_TYPE_ARRAY_LENGTH;++i)
			{
				if( DFHack::tileTypeTable[i].name )
					printtiletype(i);
			}
		case 'w':
			BrushType=-1;
            BrushClass = DFHack::WALL;
            cout << "Tile brush shape set to Wall." << endl;
			break;
		case 'f':
			BrushType=-1;
            BrushClass = DFHack::FLOOR;
            cout << "Tile brush shape set to Floor." << endl;
			break;
		case 'h':
			BrushType=-1;
			BrushClass = (DFHack::TileShape)atol( command.c_str()+1 );
            cout << "Tile brush shape set to " << BrushClass << endl;
			break;
		case 'M':
            BrushClass = DFHack::tileshape_invalid;
            cout << "Tile brush will not draw tile shape." << endl;
			break;
		case 'r':
			BrushType=-1;
            BrushMat = DFHack::STONE;
            cout << "Tile brush material set to Rock." << endl;
			break;
		case 'l':
			BrushType=-1;
            BrushMat = DFHack::SOIL;
            cout << "Tile brush material set to Soil." << endl;
			break;
		case 'v':
			BrushType=-1;
            BrushMat = DFHack::VEIN;
            cout << "Tile brush material set to Vein." << endl;
			break;
		case 'm':
			BrushType=-1;
			BrushMat = (DFHack::TileMaterial)atol( command.c_str()+1 );
            cout << "Tile brush material set to " << BrushMat << endl;
			break;
		case 'H':
            BrushMat = DFHack::tilematerial_invalid;
            cout << "Tile brush will not draw material." << endl;
			break;
		case 'O':
			BrushType=-1;
			BrushClass = DFHack::EMPTY;
			BrushMat = DFHack::AIR;
            cout << "Tile brush will draw Open Space." << endl;
			break;
		case 't':
			BrushClass = DFHack::tileshape_invalid ;
			BrushMat = DFHack::tilematerial_invalid;
			BrushType = atol( command.c_str()+1 );
			cout << "Tile brush type set to:" << endl;
			printtiletype(BrushType);
			break;
		case 'q':
            end = true;
            cout << "Bye!" << endl;
			break;
		case 'd':
        {
			count=0;
			cout << "Beginning to draw at cursor." << endl << "Press any key to stop drawing." << endl;
            //DF->Suspend();
			kbhit(); //throw away, just to be sure.
            for(;;)
            {
				if(!Maps->Start())
                {
                    cout << "Can't see any DF map loaded." << endl;
                    break;
                }
                if(!Gui->getCursorCoords(x,y,z))
                {
                    cout << "Can't get cursor coords! Make sure you have a cursor active in DF." << endl;
                    break;
                }
                //cout << "cursor coords: " << x << "/" << y << "/" << z << endl;
				tx=x%16; ty=y%16;

                if(!Maps->isValidBlock(x/16,y/16,z))
                {
                    cout << "Invalid block." << endl;
                    break;
                }

				//Read the tiles.
				dirty=0;
				Maps->ReadTileTypes((x/16),(y/16),z, &tiles);
                oldT = tiles[tx][ty];

				newT = -1;
				if( 0<BrushType ){
					//Explicit tile type set.  Trust the user.
					newT = BrushType;
				}else if( 0==BrushMat && 0==BrushClass ){
					//Special case, Empty Air.
					newT = 32;
				}else if( BrushMat>=0 && BrushClass>=0 && ( BrushClass != DFHack::tileTypeTable[oldT].shape || BrushMat != DFHack::tileTypeTable[oldT].material) ){
					//Set tile material and class
					newT = DFHack::findTileType(BrushClass,BrushMat, DFHack::tileTypeTable[oldT].variant , DFHack::tileTypeTable[oldT].special , DFHack::tileTypeTable[oldT].direction );
					if(newT<0) newT = DFHack::findTileType(BrushClass,BrushMat, DFHack::tilevariant_invalid, DFHack::tileTypeTable[oldT].special , DFHack::tileTypeTable[oldT].direction );
					if(newT<0) newT = DFHack::findTileType(BrushClass,BrushMat, DFHack::tilevariant_invalid , DFHack::tileTypeTable[oldT].special , (uint32_t)0 );
				}else if( BrushMat<0 && BrushClass>=0 && BrushClass != DFHack::tileTypeTable[oldT].shape ){
					//Set current tile class only, as accurately as can be expected
                    newT = DFHack::findSimilarTileType(oldT,BrushClass);
				}else if( BrushClass<0 && BrushMat>=0 && BrushMat != DFHack::tileTypeTable[oldT].material ){
					//Set current tile material only
					newT = DFHack::findTileType(DFHack::tileTypeTable[oldT].shape,BrushMat, DFHack::tileTypeTable[oldT].variant , DFHack::tileTypeTable[oldT].special , DFHack::tileTypeTable[oldT].direction );
					if(newT<0) newT = DFHack::findTileType(DFHack::tileTypeTable[oldT].shape,BrushMat, DFHack::tilevariant_invalid , DFHack::tileTypeTable[oldT].special , DFHack::tileTypeTable[oldT].direction );
					if(newT<0) newT = DFHack::findTileType(DFHack::tileTypeTable[oldT].shape,BrushMat, DFHack::tilevariant_invalid , DFHack::tileTypeTable[oldT].special , (uint32_t)0 );
				}
                //If no change, skip it (couldn't find a good tile type, or already what we want)
				if ( newT > 0 && oldT != newT ){
                    //Set new tile type
                    tiles[tx][ty] = newT;
                    dirty=-1;
				}
                //If anything was changed, write it all.
                if (dirty)
                {
                    //Maps->WriteDesignations(x/16,y/16,z/16, &designations);
                    Maps->WriteTileTypes(x/16,y/16,z, &tiles);
					printf("(%4d,%4d,%4d)",x,y,z);
                    ++count;
                }

                Maps->Finish();

				Sleep(10);
				if( kbhit() ) break;				
            }
			cin.clear();
			cout << endl << count << " tiles were drawn." << endl << "Drawing halted.  Entering command mode." << endl;
		}
			continue;
			break;
		default:
			cout << "Unknown command: " << command << endl;
		}

    }
    DF->Detach();
    #ifndef LINUX_BUILD
    cout << "Done. Press any key to continue" << endl;
    cin.ignore();
    #endif
    return 0;
}
Ejemplo n.º 7
0
int main (int argc, char** argv)
{
    string command = "";
    bool quiet = false;
    bool cmdarg = false;
    for(int i = 1; i < argc; i++)
    {
        string test = argv[i];
        if(test == "-q")
        {
            quiet = true;
        }
        else
        {
            command = test;
            cmdarg = true;
        }
    }

    DFHack::ContextManager DFMgr("Memory.xml");
    DFHack::Context *DF = DFMgr.getSingleContext();

    try
    {
        DF->Attach();
    }
    catch (std::exception& e)
    {
        std::cerr << e.what() << std::endl;
        #ifndef LINUX_BUILD
            cin.ignore();
        #endif
        return 1;
    }

    World *W = DF->getWorld();
    W->Start();
    bool end = false;
    while(!end)
    {
        WeatherType current = (WeatherType) W->ReadCurrentWeather();
        DF->Resume();
        printWeather(current);
        if (command == "") getline(cin, command); // only read from stdin if command hasn't been passed on the console
        DF->Suspend();
        if(command == "c")
        {
            W->SetCurrentWeather(CLEAR);
        }
        else if(command == "r")
        {
            W->SetCurrentWeather(RAINING);
        }
        else if(command == "s")
        {
            W->SetCurrentWeather(SNOWING);
        }
        else if(command == "q")
        {
            end = true;
        }
        command = "";
        if(cmdarg) end = true; // exit the loop when a cmd line arg has been passed.
    }
    #ifndef LINUX_BUILD
        if (!quiet)
        {
            std::cout << "Done. Press any key to continue" << std::endl;
            cin.ignore();
        }
    #endif
    DF->Resume();
    DF->Detach();
    return 0;
}
Ejemplo n.º 8
0
int main (int argc, char** argv)
{
    bool temporary_terminal = TemporaryTerminal();
    bool quiet = false;
    for(int i = 1; i < argc; i++)
    {
        string test = argv[i];
        if(test == "-q")
        {
            quiet = true;
        }
    }
    int32_t x,y,z;

    uint32_t x_max,y_max,z_max;

    DFHack::ContextManager DFMgr("Memory.xml");
    DFHack::Context *DF;
    DFHack::Maps * Maps;
    DFHack::Gui * Position;
    Brush * brush = new RectangleBrush(1,1);
    string brushname = "point";
    try
    {
        DF=DFMgr.getSingleContext();
        DF->Attach();
        Maps = DF->getMaps();
        Maps->Start();
        Maps->getSize(x_max,y_max,z_max);
        Position = DF->getGui();
    }
    catch (exception& e)
    {
        cerr << e.what() << endl;
        if(temporary_terminal)
            cin.ignore();
        return 1;
    }
    bool end = false;
    cout << "Welcome to the liquid spawner.\nType 'help' or '?' for a list of available commands, 'q' to quit.\nPress return after a command to confirm." << endl;
    string mode="magma";

    string flowmode="f+";
    string setmode ="s.";
    unsigned int amount = 7;
    int width = 1, height = 1, z_levels = 1;
    while(!end)
    {
        DF->Resume();
        string command = "";
        cout <<"[" << mode << ":" << brushname << ":" << amount << ":" << flowmode << ":" << setmode << "]# ";
        getline(cin, command);
        if (std::cin.eof())
        {
            command = "q";
            std::cout << std::endl; // No newline from the user here!
        }
        if(command=="help" || command == "?")
        {
            cout << "Modes:" << endl
                 << "m             - switch to magma" << endl
                 << "w             - switch to water" << endl
                 << "o             - make obsidian wall instead" << endl
                 << "of            - make obsidian floors" << endl
                 << "rs            - make a river source" << endl
                 << "f             - flow bits only" << endl
                 << "Set-Modes (only for magma/water):" << endl
                 << "s+            - only add" << endl
                 << "s.            - set" << endl
                 << "s-            - only remove" << endl
                 << "Properties (only for magma/water):" << endl
                 << "f+            - make the spawned liquid flow" << endl
                 << "f.            - don't change flow state (read state in flow mode)" << endl
                 << "f-            - make the spawned liquid static" << endl
                 << "0-7           - set liquid amount" << endl
                 << "Brush:" << endl
                 << "point         - single tile [p]" << endl
                 << "range         - block with cursor at bottom north-west [r]" << endl
                 << "                (any place, any size)" << endl
                 << "block         - DF map block with cursor in it" << endl
                 << "                (regular spaced 16x16x1 blocks)" << endl
                 << "column        - Column from cursor, up through free space" << endl
                 << "Other:" << endl
                 << "q             - quit" << endl
                 << "help or ?     - print this list of commands" << endl
                 << "empty line    - put liquid" << endl
                 << endl
                 << "Usage: point the DF cursor at a tile you want to modify" << endl
                 << "and use the commands available :)" << endl;
        }
        else if(command == "m")
        {
            mode = "magma";
        }
        else if(command == "o")
        {
            mode = "obsidian";
        }
        else if(command == "of")
        {
            mode = "obsidian_floor";
        }
        else if(command == "w")
        {
            mode = "water";
        }
        else if(command == "f")
        {
            mode = "flowbits";
        }
        else if(command == "rs")
        {
            mode = "riversource";
        }
        else if(command == "point" || command == "p")
        {
            delete brush;
            brushname = "point";
            brush = new RectangleBrush(1,1);
        }
        else if(command == "range" || command == "r")
        {
            cout << " :set range width<" << width << "># ";
            getline(cin, command);
            width = command == "" ? width : atoi (command.c_str());
            if(width < 1) width = 1;

            cout << " :set range height<" << height << "># ";
            getline(cin, command);
            height = command == "" ? height : atoi (command.c_str());
            if(height < 1) height = 1;

            cout << " :set range z-levels<" << z_levels << "># ";
            getline(cin, command);
            z_levels = command == "" ? z_levels : atoi (command.c_str());
            if(z_levels < 1) z_levels = 1;
            delete brush;
            if(width == 1 && height == 1 && z_levels == 1)
            {
                brushname="point";
            }
            else
            {
                brushname = "range";
            }
            brush = new RectangleBrush(width,height,z_levels,0,0,0);
        }
        else if(command == "block")
        {
            delete brush;
            brushname = "block";
            brush = new BlockBrush();
        }
        else if(command == "column")
        {
            delete brush;
            brushname = "column";
            brush = new ColumnBrush();
        }
        else if(command == "q")
        {
            end = true;
        }
        else if(command == "f+")
        {
            flowmode = "f+";
        }
        else if(command == "f-")
        {
            flowmode = "f-";
        }
        else if(command == "f.")
        {
            flowmode = "f.";
        }
        else if(command == "s+")
        {
            setmode = "s+";
        }
        else if(command == "s-")
        {
            setmode = "s-";
        }
        else if(command == "s.")
        {
            setmode = "s.";
        }
        // blah blah, bad code, bite me.
        else if(command == "0")
            amount = 0;
        else if(command == "1")
            amount = 1;
        else if(command == "2")
            amount = 2;
        else if(command == "3")
            amount = 3;
        else if(command == "4")
            amount = 4;
        else if(command == "5")
            amount = 5;
        else if(command == "6")
            amount = 6;
        else if(command == "7")
            amount = 7;
        else if(command.empty())
        {
            DF->Suspend();
            do
            {
                if(!Maps->Start())
                {
                    cout << "Can't see any DF map loaded." << endl;
                    break;
                }
                if(!Position->getCursorCoords(x,y,z))
                {
                    cout << "Can't get cursor coords! Make sure you have a cursor active in DF." << endl;
                    break;
                }
                cout << "cursor coords: " << x << "/" << y << "/" << z << endl;
                MapCache mcache(Maps);
                DFHack::DFCoord cursor(x,y,z);
                coord_vec all_tiles = brush->points(mcache,cursor);
                cout << "working..." << endl;
                if(mode == "obsidian")
                {
                    coord_vec::iterator iter = all_tiles.begin();
                    while (iter != all_tiles.end())
                    {
                        mcache.setTiletypeAt(*iter, 331);
                        mcache.setTemp1At(*iter,10015);
                        mcache.setTemp2At(*iter,10015);
                        DFHack::t_designation des = mcache.designationAt(*iter);
                        des.bits.flow_size = 0;
                        mcache.setDesignationAt(*iter, des);
                        iter ++;
                    }
                }
                if(mode == "obsidian_floor")
                {
                    coord_vec::iterator iter = all_tiles.begin();
                    while (iter != all_tiles.end())
                    {
                        mcache.setTiletypeAt(*iter, 340);
                        iter ++;
                    }
                }
                else if(mode == "riversource")
                {
                    set <Block *> seen_blocks;
                    coord_vec::iterator iter = all_tiles.begin();
                    while (iter != all_tiles.end())
                    {
                        mcache.setTiletypeAt(*iter, 90);

                        DFHack::t_designation a = mcache.designationAt(*iter);
                        a.bits.liquid_type = DFHack::liquid_water;
                        a.bits.liquid_static = false;
                        a.bits.flow_size = 7;
                        mcache.setTemp1At(*iter,10015);
                        mcache.setTemp2At(*iter,10015);
                        mcache.setDesignationAt(*iter,a);

                        Block * b = mcache.BlockAt((*iter)/16);
                        DFHack::t_blockflags bf = b->BlockFlags();
                        bf.bits.liquid_1 = true;
                        bf.bits.liquid_2 = true;
                        b->setBlockFlags(bf);

                        iter++;
                    }
                }
                else if(mode== "magma" || mode== "water" || mode == "flowbits")
                {
                    set <Block *> seen_blocks;
                    coord_vec::iterator iter = all_tiles.begin();
                    while (iter != all_tiles.end())
                    {
                        DFHack::DFCoord current = *iter;
                        DFHack::t_designation des = mcache.designationAt(current);
                        uint16_t tt = mcache.tiletypeAt(current);
                        DFHack::naked_designation & flow = des.bits;
                        // don't put liquids into places where they don't belong...
                        if(!DFHack::FlowPassable(tt))
                        {
                            iter++;
                            continue;
                        }
                        if(mode != "flowbits")
                        {
                            if(setmode == "s.")
                            {
                                flow.flow_size = amount;
                            }
                            else if(setmode == "s+")
                            {
                                if(flow.flow_size < amount)
                                    flow.flow_size = amount;
                            }
                            else if(setmode == "s-")
                            {
                                if (flow.flow_size > amount)
                                    flow.flow_size = amount;
                            }
                            if(amount != 0 && mode == "magma")
                            {
                                flow.liquid_type =  DFHack::liquid_magma;
                                mcache.setTemp1At(current,12000);
                                mcache.setTemp2At(current,12000);
                            }
                            else if(amount != 0 && mode == "water")
                            {
                                flow.liquid_type =  DFHack::liquid_water;
                                mcache.setTemp1At(current,10015);
                                mcache.setTemp2At(current,10015);
                            }
                            else if(amount == 0 && (mode == "water" || mode == "magma"))
                            {
                                // reset temperature to sane default
                                mcache.setTemp1At(current,10015);
                                mcache.setTemp2At(current,10015);
                            }
                            mcache.setDesignationAt(current,des);
                        }
                        seen_blocks.insert(mcache.BlockAt((*iter) / 16));
                        iter++;
                    }
                    set <Block *>::iterator biter = seen_blocks.begin();
                    while (biter != seen_blocks.end())
                    {
                        DFHack::t_blockflags bflags = (*biter)->BlockFlags();
                        if(flowmode == "f+")
                        {
                            bflags.bits.liquid_1 = true;
                            bflags.bits.liquid_2 = true;
                            (*biter)->setBlockFlags(bflags);
                        }
                        else if(flowmode == "f-")
                        {
                            bflags.bits.liquid_1 = false;
                            bflags.bits.liquid_2 = false;
                            (*biter)->setBlockFlags(bflags);
                        }
                        else
                        {
                            cout << "flow bit 1 = " << bflags.bits.liquid_1 << endl; 
                            cout << "flow bit 2 = " << bflags.bits.liquid_2 << endl;
                        }
                        biter ++;
                    }
                }
                if(mcache.WriteAll())
                    cout << "OK" << endl;
                else
                    cout << "Something failed horribly! RUN!" << endl;
                Maps->Finish();
            } while (0);
        }
        else
        {
            cout << command << " : unknown command." << endl;
        }
    }
    DF->Detach();
    if(temporary_terminal && !quiet)
    {
        cout << "Done. Press any key to continue" << endl;
        cin.ignore();
    }
    return 0;
}