当前位置: 首页>>代码示例>>C++>>正文


C++ dfhack::Maps类代码示例

本文整理汇总了C++中dfhack::Maps的典型用法代码示例。如果您正苦于以下问题:C++ Maps类的具体用法?C++ Maps怎么用?C++ Maps使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Maps类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char *argv[])
{
    bool temporary_terminal = TemporaryTerminal();

    uint32_t x_max = 0, y_max = 0, z_max = 0;
    DFHack::ContextManager manager("Memory.xml");

    DFHack::Context *context = manager.getSingleContext();
    if (!context->Attach())
    {
        std::cerr << "Unable to attach to DF!" << std::endl;
        if(temporary_terminal)
            std::cin.ignore();
        return 1;
    }

    DFHack::Maps *maps = context->getMaps();
    if (!maps->Start())
    {
        std::cerr << "Cannot get map info!" << std::endl;
        context->Detach();
        if(temporary_terminal)
            std::cin.ignore();
        return 1;
    }
    maps->getSize(x_max, y_max, z_max);
    MapExtras::MapCache map(maps);

    for(uint32_t z = 0; z < z_max; z++)
    {
        for(uint32_t b_y = 0; b_y < y_max; b_y++)
        {
            for(uint32_t b_x = 0; b_x < x_max; b_x++)
            {
                // Get the map block
                DFHack::DFCoord blockCoord(b_x, b_y);
                MapExtras::Block *b = map.BlockAt(DFHack::DFCoord(b_x, b_y, z));
                if (!b || !b->valid)
                {
                    continue;
                }

                DFHack::t_blockflags flags = b->BlockFlags();
                flags.whole = flags.whole ^ 0xFFFFFFFF;
                b->setBlockFlags(flags);
                b->Write();
            } // block x
        } // block y
    } // z

    maps->Finish();
    context->Detach();
    return 0;
}
开发者ID:kaypy,项目名称:dfhack,代码行数:54,代码来源:blockflags.cpp

示例2: main

int main(int argc, char** argv) {
  if(argc < 2) {
    ::std::cout << "gimme a file!" << ::std::endl;
    return 1;
  }

  ::std::ifstream map_in(argv[1]);

  ::std::vector< ::std::string > dig_map;
  while (map_in.good() && !map_in.eof() && !map_in.bad()) {
    ::std::string line;
    map_in >> line;

    dig_map.push_back(line);
  }
  dig_map.resize(dig_map.size() - 1);

  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
    ::std::cin.ignore();
#endif
    return 1;
  }

  DFHack::Maps *layers = DF->getMaps();
  if (layers && layers->Start()) {

    dig(layers, DF->getGui(), dig_map, true);

    ::std::cout << "Finished digging" << ::std::endl;
    layers->Finish();

    if (!DF->Detach()) {
      ::std::cerr << "Unable to detach DF process" << ::std::endl;
    }

  } else {
    ::std::cerr << "Unable to init map" << ::std::endl;
  }

#ifndef LINUX_BUILD
  ::std::cout << "Done. Press any key to continue" << ::std::endl;
  ::std::cin.ignore();
#endif
  return 0;
}
开发者ID:AlexanderStarr,项目名称:dfhack,代码行数:52,代码来源:digger2.cpp

示例3: df_flows

DFhackCExport command_result df_flows (Core * c, vector <string> & parameters)
{
    uint32_t x_max,y_max,z_max;
    DFHack::designations40d designations;
    DFHack::Maps *Maps;

    c->Suspend();
    Maps = c->getMaps();
    // init the map
    if(!Maps->Start())
    {
        c->con.printerr("Can't init map.\n");
        c->Resume();
        return CR_FAILURE;
    }
    DFHack::t_blockflags bflags;
    Maps->getSize(x_max,y_max,z_max);
    // walk the map, count flowing tiles, magma, water
    uint32_t flow1=0, flow2=0, flowboth=0, water=0, magma=0;
    c->con.print("Counting flows and liquids ...\n");
    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->getBlock(x,y,z))
                {
                    Maps->ReadBlockFlags(x, y, z, bflags);
                    Maps->ReadDesignations(x, y, z, &designations);
                    if (bflags.bits.liquid_1)
                        flow1++;
                    if (bflags.bits.liquid_2)
                        flow2++;
                    if (bflags.bits.liquid_1 && bflags.bits.liquid_2)
                        flowboth++;
                    for (uint32_t i = 0; i < 16;i++) for (uint32_t j = 0; j < 16;j++)
                    {
                        if (designations[i][j].bits.liquid_type == DFHack::liquid_magma)
                            magma++;
                        if (designations[i][j].bits.liquid_type == DFHack::liquid_water)
                            water++;
                    }
                }
            }
        }
    }
    c->con.print("Blocks with liquid_1=true: %d\n"
                 "Blocks with liquid_2=true: %d\n"
                 "Blocks with both:          %d\n"
                 "Water tiles:               %d\n"
                 "Magma tiles:               %d\n"
                 ,flow1, flow2, flowboth, water, magma
                );
    c->Resume();
    return CR_OK;
}
开发者ID:gsvslto,项目名称:dfhack,代码行数:57,代码来源:flows.cpp

示例4: cleanmap

DFhackCExport command_result cleanmap (Core * c, vector <string> & parameters)
{
    const uint32_t water_idx = 6;
    const uint32_t mud_idx = 12;

    bool snow = false;
    bool mud = false;
    bool help = false;
    for(int i = 0; i < parameters.size();i++)
    {
        if(parameters[i] == "snow")
            snow = true;
        else if(parameters[i] == "mud")
            mud = true;
        else if(parameters[i] == "help" ||parameters[i] == "?")
        {
            help = true;
        }
    }
    if(help)
    {
        c->con.print("This command cleans the coverings from the map. Snow and mud are ignored by default.\n"
                     "Options:\n"
                     "snow   - also remove snow\n"
                     "mud    - also remove mud\n"
                    );
        return CR_OK;
    }
    c->Suspend();
    vector<DFHack::t_spattervein *> splatter;
    DFHack::Maps *Mapz = c->getMaps();

    // init the map
    if(!Mapz->Start())
    {
        c->con << "Can't init map." << std::endl;
        c->Resume();
        return CR_FAILURE;
    }

    uint32_t x_max,y_max,z_max;
    Mapz->getSize(x_max,y_max,z_max);

    // walk the map
    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++)
            {
                df_block * block = Mapz->getBlock(x,y,z);
                if(block)
                {
                    Mapz->SortBlockEvents(x,y,z,0,0,&splatter);
                    for(int i = 0; i < 16; i++)
                        for(int j = 0; j < 16; j++)
                        {
                            block->occupancy[i][j].bits.arrow_color = 0;
                            block->occupancy[i][j].bits.broken_arrows_variant = 0;
                        }
                    for(uint32_t i = 0; i < splatter.size(); i++)
                    {
                        DFHack::t_spattervein * vein = splatter[i];
                        // filter snow
                        if(!snow && vein->mat1 == water_idx && vein->matter_state == DFHack::state_powder)
                            continue;
                        // filter mud
                        if(!mud && vein->mat1 == mud_idx && vein->matter_state == DFHack::state_solid)
                            continue;
                        Mapz->RemoveBlockEvent(x,y,z,(t_virtual *) vein);
                    }
                }
            }
        }
    }
    c->Resume();
    return CR_OK;
}
开发者ID:gsvslto,项目名称:dfhack,代码行数:78,代码来源:cleanmap.cpp

示例5: filltraffic

DFhackCExport command_result filltraffic(DFHack::Core * c, std::vector<std::string> & params)
{
	//Maximum map size.
	uint32_t x_max,y_max,z_max;
	//Source and target traffic types.
	e_traffic source = traffic_normal;
	e_traffic target = traffic_normal;
	//Option flags
	bool updown        = false;
	bool checkpit      = true;
	bool checkbuilding = true;

	//Loop through parameters
    for(int i = 0; i < params.size();i++)
    {
        if(params[i] == "help" || params[i] == "?")
        {
            c->con.print("Flood-fill selected traffic type from the cursor.\n"
                         "Traffic Type Codes:\n"
                         "\tH: High Traffic\n"
                         "\tN: Normal Traffic\n"
                         "\tL: Low Traffic\n"
                         "\tR: Restricted Traffic\n"
                         "Other Options:\n"
                         "\tX: Fill accross z-levels.\n"
                         "\tB: Include buildings and stockpiles.\n"
                         "\tP: Include empty space.\n"
                         "Example:\n"
                         "'filltraffic H' - When used in a room with doors,\n"
                         "                  it will set traffic to HIGH in just that room."
            );
            return CR_OK;
        }

        switch (toupper(params[i][0]))
        {
            case 'H':
                target = traffic_high; break;
            case 'N':
                target = traffic_normal; break;
            case 'L':
                target = traffic_low; break;
            case 'R':
                target = traffic_restricted; break;
            case 'X':
                updown = true; break;
            case 'B':
                checkbuilding = false; break;
            case 'P':
                checkpit = false; break;
        }
    }

    //Initialization.
    c->Suspend();

    DFHack::Maps * Maps = c->getMaps();
    DFHack::Gui * Gui = c->getGui();
    // init the map
    if(!Maps->Start())
    {
        c->con.printerr("Can't init map. Make sure you have a map loaded in DF.\n");
        c->Resume();
        return CR_FAILURE;
    }

	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)
    {
        c->con.printerr("Cursor is not active.\n");
        c->Resume();
        return CR_FAILURE;
    }

    DFHack::DFCoord xy ((uint32_t)cx,(uint32_t)cy,cz);
    MapExtras::MapCache * MCache = new MapExtras::MapCache(Maps);

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

    if (checkbuilding)
        oc = MCache->occupancyAt(xy);

    source = des.bits.traffic;
    if(source == target)
    {
        c->con.printerr("This tile is already set to the target traffic type.\n");
        delete MCache;
        c->Resume();
        return CR_FAILURE;
    }

    if(DFHack::isWallTerrain(tt))
    {
        c->con.printerr("This tile is a wall. Please select a passable tile.\n");
//.........这里部分代码省略.........
开发者ID:gsvslto,项目名称:dfhack,代码行数:101,代码来源:filltraffic.cpp

示例6: tiletraffic

DFhackCExport command_result tiletraffic(DFHack::Core * c, std::vector<std::string> & params)
{
	//Target traffic types.
	e_traffic target = traffic_normal;
	//!!! Options Later !!!

	//Loop through parameters
    for(int i = 0; i < params.size();i++)
    {
        if(params[i] == "help" || params[i] == "?")
        {
            c->con.print("Set traffic types for all tiles on the map.\n"
						 "Traffic Type Codes:\n"
						 "	H: High Traffic\n"
						 "	N: Normal Traffic\n"
						 "	L: Low Traffic\n"
						 "	R: Restricted Traffic\n"
            );
            return CR_OK;
        }

		switch (toupper(params[i][0]))
		{
			case 'H':
				target = traffic_high; break;
			case 'N':
				target = traffic_normal; break;
			case 'L':
				target = traffic_low; break;
			case 'R':
				target = traffic_restricted; break;
		}
    }

	//Initialization.
	c->Suspend();

	DFHack::Maps * Maps = c->getMaps();
    DFHack::Gui * Gui = c->getGui();
    // init the map
    if(!Maps->Start())
    {
        c->con.printerr("Can't init map. Make sure you have a map loaded in DF.\n");
        c->Resume();
        return CR_FAILURE;
    }

	//Maximum map size.
	uint32_t x_max,y_max,z_max;
    Maps->getSize(x_max,y_max,z_max);
    uint32_t tx_max = x_max * 16;
    uint32_t ty_max = y_max * 16;

	MapExtras::MapCache * MCache = new MapExtras::MapCache(Maps);

	c->con.print("Entire map ... FILLING!\n");

	//Loop through every single tile
	for(uint32_t x = 0; x <= tx_max; x++)
	{
		for(uint32_t y = 0; y <= ty_max; y++)
		{
			for(uint32_t z = 0; z <= z_max; z++)
			{
				DFHack::DFCoord tile = DFHack::DFCoord(x, y, z);
				DFHack::t_designation des = MCache->designationAt(tile);

				des.bits.traffic = target;
				MCache->setDesignationAt(tile, des);
			}
		}
	}

	MCache->WriteAll();
    c->Resume();
    return CR_OK;
}
开发者ID:gsvslto,项目名称:dfhack,代码行数:77,代码来源:filltraffic.cpp

示例7: main


//.........这里部分代码省略.........
    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;
开发者ID:AlexanderStarr,项目名称:dfhack,代码行数:66,代码来源:copypaste.cpp

示例8: vdig

DFhackCExport command_result vdig (Core * c, vector <string> & parameters)
{
    uint32_t x_max,y_max,z_max;
    bool updown = false;
    for(int i = 0; i < parameters.size();i++)
    {
        if(parameters.size() && parameters[0]=="x")
            updown = true;
        else if(parameters[i] == "help" || parameters[i] == "?")
        {
            c->con.print("Designates a whole vein under the cursor for digging.\n"
                         "Options:\n"
                         "x        - follow veins through z-levels with stairs.\n"
            );
            return CR_OK;
        }
    }

    Console & con = c->con;

    c->Suspend();
    DFHack::Maps * Maps = c->getMaps();
    DFHack::Gui * Gui = c->getGui();
    // init the map
    if(!Maps->Start())
    {
        con.printerr("Can't init map. Make sure you have a map loaded in DF.\n");
        c->Resume();
        return CR_FAILURE;
    }

    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)
    {
        con.printerr("Cursor is not active. Point the cursor at a vein.\n");
        c->Resume();
        return CR_FAILURE;
    }
    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)
    {
        con.printerr("I won't dig the borders. That would be cheating!\n");
        c->Resume();
        return CR_FAILURE;
    }
    MapExtras::MapCache * MCache = new MapExtras::MapCache(Maps);
    DFHack::t_designation des = MCache->designationAt(xy);
    int16_t tt = MCache->tiletypeAt(xy);
    int16_t veinmat = MCache->veinMaterialAt(xy);
    if( veinmat == -1 )
    {
        con.printerr("This tile is not a vein.\n");
        delete MCache;
        c->Resume();
        return CR_FAILURE;
    }
    con.print("%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);
            }
        }
//.........这里部分代码省略.........
开发者ID:gsvslto,项目名称:dfhack,代码行数:101,代码来源:vdig.cpp

示例9: main

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
//.........这里部分代码省略.........
开发者ID:nickrart,项目名称:dfhack,代码行数:101,代码来源:reveal.cpp

示例10: main

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)";
//.........这里部分代码省略.........
开发者ID:gsvslto,项目名称:dfhack,代码行数:101,代码来源:drawtile.cpp

示例11: immolations

/**
 * Book of Immolations, chapter 1, verse 35:
 * Armok emerged from the hellish depths and beheld the sunny realms for the first time.
 * And he cursed the plants and trees for their bloodless wood, turning them into ash and smoldering ruin.
 * Armok was pleased and great temples were built by the dwarves, for they shared his hatred for trees and plants.
 */
static command_result immolations (Core * c, do_what what, bool shrubs, bool trees, bool help)
{
    static const char * what1 = "destroys";
    static const char * what2 = "burns";
    if(help)
    {
        c->con.print("Without any options, this command %s a plant under the cursor.\n"
        "Options:\n"
        "shrubs   - affect all shrubs\n"
        "trees    - affect all trees\n"
        "all      - affect all plants\n",
        what == do_immolate? what2 : what1
        );
        return CR_OK;
    }
    c->Suspend();
    DFHack::Maps *maps = c->getMaps();
    if (!maps->Start())
    {
        c->con.printerr( "Cannot get map info!\n");
        c->Resume();
        return CR_FAILURE;
    }
    DFHack::Gui * Gui = c->getGui();
    uint32_t x_max, y_max, z_max;
    maps->getSize(x_max, y_max, z_max);
    MapExtras::MapCache map(maps);
    DFHack::Vegetation *veg = c->getVegetation();
    if (!veg->all_plants)
    {
        std::cerr << "Unable to read vegetation!" << std::endl;
        return CR_FAILURE;
    }
    if(shrubs || trees)
    {
        int destroyed = 0;
        for(size_t i = 0 ; i < veg->all_plants->size(); i++)
        {
            DFHack::df_plant *p = veg->all_plants->at(i);
            if(shrubs && p->is_shrub || trees && !p->is_shrub)
            {
                if (what == do_immolate)
                    p->is_burning = true;
                p->hitpoints = 0;
                destroyed ++;
            }
        }
        c->con.print("Praise Armok!\n");
    }
    else
    {
        int32_t x,y,z;
        if(Gui->getCursorCoords(x,y,z))
        {
            vector<DFHack::df_plant *> * alltrees;
            if(maps->ReadVegetation(x/16,y/16,z,alltrees))
            {
                bool didit = false;
                for(size_t i = 0 ; i < alltrees->size(); i++)
                {
                    DFHack::df_plant * tree = alltrees->at(i);
                    if(tree->x == x && tree->y == y && tree->z == z)
                    {
                        if(what == do_immolate)
                            tree->is_burning = true;
                        tree->hitpoints = 0;
                        didit = true;
                        break;
                    }
                }
                /*
                if(!didit)
                {
                    cout << "----==== There's NOTHING there! ====----" << endl;
                }
                */
            }
        }
        else
        {
            c->con.printerr("No mass destruction and no cursor...\n" );
        }
    }
    // Cleanup
    veg->Finish();
    maps->Finish();
    c->Resume();
    return CR_OK;
}
开发者ID:kaypy,项目名称:dfhack,代码行数:95,代码来源:plants.cpp

示例12: df_grow

DFhackCExport command_result df_grow (Core * c, vector <string> & parameters)
{
    for(int i = 0; i < parameters.size();i++)
    {
        if(parameters[i] == "help" || parameters[i] == "?")
        {
            c->con.print("This command turns all living saplings into full-grown trees.\n");
            return CR_OK;
        }
    }
    c->Suspend();
    DFHack::Maps *maps = c->getMaps();
    Console & con = c->con;
    if (!maps->Start())
    {
        con.printerr("Cannot get map info!\n");
        c->Resume();
        return CR_FAILURE;
    }
    //maps->getSize(x_max, y_max, z_max);
    MapExtras::MapCache map(maps);
    DFHack::Vegetation *veg = c->getVegetation();
    if (!veg->all_plants)
    {
        con.printerr("Unable to read vegetation!\n");
        c->Resume();
        return CR_FAILURE;
    }
    DFHack::Gui *Gui = c->getGui();
    int32_t x,y,z;
    if(Gui->getCursorCoords(x,y,z))
    {
        vector<DFHack::df_plant *> * alltrees;
        if(maps->ReadVegetation(x/16,y/16,z,alltrees))
        {
            for(size_t i = 0 ; i < alltrees->size(); i++)
            {
                DFHack::df_plant * tree = alltrees->at(i);
                if(tree->x == x && tree->y == y && tree->z == z)
                {
                    if(DFHack::tileShape(map.tiletypeAt(DFHack::DFCoord(x,y,z))) == DFHack::SAPLING_OK)
                    {
                        tree->grow_counter = DFHack::sapling_to_tree_threshold;
                    }
                    break;
                }
            }
        }
    }
    else
    {
        int grown = 0;
        for(size_t i = 0 ; i < veg->all_plants->size(); i++)
        {
            DFHack::df_plant *p = veg->all_plants->at(i);
            uint16_t ttype = map.tiletypeAt(DFHack::DFCoord(p->x,p->y,p->z));
            if(!p->is_shrub && DFHack::tileShape(ttype) == DFHack::SAPLING_OK)
            {
                p->grow_counter = DFHack::sapling_to_tree_threshold;
            }
        }
    }

    // Cleanup
    veg->Finish();
    maps->Finish();
    c->Resume();
    return CR_OK;
}
开发者ID:kaypy,项目名称:dfhack,代码行数:69,代码来源:plants.cpp

示例13: main

int main (void)
{
    bool temporary_terminal = TemporaryTerminal();
    uint32_t x_max,y_max,z_max;
    DFHack::designations40d designations;
    DFHack::tiletypes40d tiles;

    int32_t oldT, newT;
    uint64_t count = 0;

    int dirty=0;

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

    //Init
    try
    {
        DF->Attach();
    }
    catch (exception& e)
    {
        cerr << e.what() << endl;
        if(temporary_terminal)
            cin.ignore();
        return 1;
    }
    DFHack::Maps *Mapz = DF->getMaps();

    // init the map
    if (!Mapz->Start())
    {
        cerr << "Can't init map." << endl;
        if(temporary_terminal)
            cin.ignore();
        return 1;
    }

    Mapz->getSize(x_max,y_max,z_max);
    if(!Mapz->StartFeatures())
    {
        cerr << "Can't get features." << endl;
        if(temporary_terminal)
            cin.ignore();
        return 1; 
    }

    // walk the map
    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++)
            {
                DFHack::t_feature * locf = 0;
                DFHack::t_feature * glof = 0;
                if (Mapz->ReadFeatures(x,y,z,&locf,&glof))
                {
                    // we're looking for addy tubes
                    if(!locf) continue;
                    if(locf->type != DFHack::feature_Adamantine_Tube) continue;

                    dirty=0;
                    Mapz->ReadDesignations(x,y,z, &designations);
                    Mapz->ReadTileTypes(x,y,z, &tiles);

                    for (uint32_t ty=0;ty<16;++ty)
                    {
                        for (uint32_t tx=0;tx<16;++tx)
                        {
                            if(!designations[tx][ty].bits.feature_local) continue;
                            oldT = tiles[tx][ty];
                            if ( DFHack::tileShape(oldT) != DFHack::WALL )
                            {
                                //Current tile is not a wall.
                                //Set current tile, as accurately as can be expected
                                //newT = DFHack::findSimilarTileType(oldT,DFHack::WALL);
                                newT = DFHack::findTileType( DFHack::WALL, DFHack::FEATSTONE, DFHack::tilevariant_invalid, DFHack::TILE_NORMAL, DFHack::TileDirection() );

                                //If no change, skip it (couldn't find a good tile type)
                                if ( oldT == newT) continue;
                                //Set new tile type, clear designation
                                tiles[tx][ty] = newT;
                                dirty=1;
                                ++count;
                            }
                        }
                    }
                    //If anything was changed, write it all.
                    if (dirty)
                    {
                        Mapz->WriteTileTypes(x,y,z, &tiles);
                    }
                }
            }
        }
    }
    DF->Detach();
    cout << "Found and changed " << count << " tiles." << endl;
    if(temporary_terminal)
//.........这里部分代码省略.........
开发者ID:NonRealDeveloper,项目名称:dfhack,代码行数:101,代码来源:dftubefill.cpp

示例14: main

int main (int argc, const char* argv[])
{
    // Command line options
    bool updown = false;
    bool quiet = true;
    // let's be more useful when double-clicked on windows
    #ifndef LINUX_BUILD
    quiet = false;
    #endif
    int dig_up_n = 5;
    int dig_down_n = 5;

    for(int i = 1; i < argc; i++)
    {
        string arg_cur = argv[i];
        string arg_next = "";
	int arg_next_int = -99999;
	/* Check if argv[i+1] is a number >= 0 */
	if (i < argc-1) {
	    arg_next = argv[i+1];
	    arg_next_int = strtoint(arg_next);
	    if (arg_next != "0" && arg_next_int == 0) {
		arg_next_int = -99999;
	    }
	}
	if (arg_cur == "-x")
	{
	    updown = true;
	}
	else if (arg_cur == "-q")
	{
	    quiet = true;
	}
	else if(arg_cur == "-u" && i < argc-1)
	{
	    if (arg_next_int < 0 || arg_next_int >= 99999) {
		usage(argc, argv);
		return 1;
	    }
	    dig_up_n = arg_next_int;
	    i++;
	}
	else if(arg_cur == "-d" && i < argc-1)
	{
	    if (arg_next_int < 0 || arg_next_int >= 99999) {
		usage(argc, argv);
		return 1;
	    }
	    dig_down_n = arg_next_int;
	    i++;
	}
	else
	{
	    usage(argc, argv);
	    return 1;
	}
    }

    DFHack::ContextManager DFMgr("Memory.xml");
    DFHack::Context * DF;
    try
    {
        DF = DFMgr.getSingleContext();
        DF->Attach();
    }
    catch (exception& e)
    {
        cerr << "Error getting context: " << e.what() << endl;
        if (!quiet)
            cin.ignore();

        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();
        if (!quiet)
            cin.ignore();

        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);
    if (cx == -30000)
    {
        cerr << "Cursor is not active. Point the cursor at the position to dig at." << endl;
        DF->Detach();
        if (!quiet)
//.........这里部分代码省略.........
开发者ID:NonRealDeveloper,项目名称:dfhack,代码行数:101,代码来源:digpattern.cpp

示例15: main

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;
        }
    }

    uint32_t x_max,y_max,z_max;
    vector<DFHack::t_spattervein> splatter;

    DFHack::ContextManager DFMgr("Memory.xml");
    DFHack::Context *DF = DFMgr.getSingleContext();
    try
    {
        DF->Attach();
    }
    catch (exception& e)
    {
        cerr << e.what() << endl;
        if(temporary_terminal)
            cin.ignore();
        return 1;
    }
    DFHack::Maps *Mapz = DF->getMaps();

    // init the map
    if(!Mapz->Start())
    {
        cerr << "Can't init map." << endl;
        if(temporary_terminal)
            cin.ignore();
        return 1;
    }

    Mapz->getSize(x_max,y_max,z_max);

    uint8_t zeroes [16][16] = {{0}};
    DFHack::occupancies40d occ;
    // walk the map
    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(Mapz->isValidBlock(x,y,z))
                {
                    Mapz->ReadVeins(x,y,z,0,0,&splatter);
                    Mapz->ReadOccupancy(x,y,z,&occ);
                    for(int i = 0; i < 16; i++)
                        for(int j = 0; j < 16; j++)
                        {
                            occ[i][j].bits.arrow_color = 0;
                            occ[i][j].bits.broken_arrows_variant = 0;
                        }
                    Mapz->WriteOccupancy(x,y,z,&occ);
                    for(uint32_t i = 0; i < splatter.size(); i++)
                    {
                        DFHack::t_spattervein & vein = splatter[i];
                        // filter snow
                        if(vein.mat1 == water_idx && vein.matter_state == DFHack::state_powder)
                            continue;
                        // filter mud
                        if(vein.mat1 == mud_idx && vein.matter_state == DFHack::state_solid)
                            continue;
                        uint32_t addr = vein.address_of;
                        uint32_t offset = offsetof(DFHack::t_spattervein, intensity);
                        // TODO: make this actually destroy the objects/remove them from the vector?
                        // still, this is safe.
                        DF->WriteRaw(addr + offset,sizeof(zeroes),(uint8_t *) zeroes);
                    }
                }
            }
        }
    }
    DF->Detach();
    if (!quiet && temporary_terminal) 
    {
        cout << "Done. Press any key to continue" << endl;
        cin.ignore();
    }
    return 0;
}
开发者ID:NonRealDeveloper,项目名称:dfhack,代码行数:89,代码来源:cleanmap.cpp


注:本文中的dfhack::Maps类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。