• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ mapextras::MapCache类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: cursor

    StockpileInfo(building_stockpilest *sp_) : sp(sp_)
    {
        MapExtras::MapCache mc;

        z = sp_->z;
        x1 = sp_->room.x;
        x2 = sp_->room.x + sp_->room.width;
        y1 = sp_->room.y;
        y2 = sp_->room.y + sp_->room.height;
        int e = 0;
        size = 0;
        free = 0;
        for (int y = y1; y < y2; y++)
            for (int x = x1; x < x2; x++)
                if (sp_->room.extents[e++] == 1)
                {
                    size++;
                    DFCoord cursor (x,y,z);
                    uint32_t blockX = x / 16;
                    uint32_t tileX = x % 16;
                    uint32_t blockY = y / 16;
                    uint32_t tileY = y % 16;
                    MapExtras::Block * b = mc.BlockAt(cursor/16);
                    if(b && b->is_valid())
                    {
                        auto &block = *b->getRaw();
                        df::tile_occupancy &occ = block.occupancy[tileX][tileY];
                        if (!occ.bits.item)
                            free++;
                    }
                }
    }
开发者ID:AlexanderStarr,项目名称:dfhack,代码行数:32,代码来源:stockcheck.cpp


示例2: GetEmbarkTile

static command_result GetEmbarkTile(color_ostream &stream, const TileRequest *in, EmbarkTile *out)
{
    MapExtras::MapCache MC;
    gather_embark_tile(in->want_x() * 3, in->want_y() * 3, out, &MC);
    MC.trash();
    return CR_OK;
}
开发者ID:Alloyed,项目名称:dfhack,代码行数:7,代码来源:isoworldremote.cpp


示例3: readFlag

command_result readFlag (Core * c, vector <string> & parameters)
{
    c->Suspend();

    // init the map
    if(!Maps::IsValid())
    {
        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;
    if(!Gui::getCursorCoords(cx,cy,cz))
    {
        c->con.printerr("Cursor is not active.\n");
        c->Resume();
        return CR_FAILURE;
    }

    DFCoord cursor = DFCoord(cx,cy,cz);

    MapExtras::MapCache * MCache = new MapExtras::MapCache();
    t_occupancy oc = MCache->occupancyAt(cursor);

    c->con.print("Current Value: %d\n", oc.bits.building);

    c->Resume();
    return CR_OK;
}
开发者ID:TroZ,项目名称:dfhack,代码行数:30,代码来源:buildprobe.cpp


示例4: df_grow

command_result df_grow (color_ostream &out, vector <string> & parameters)
{
    for(size_t i = 0; i < parameters.size();i++)
    {
        if(parameters[i] == "help" || parameters[i] == "?")
        {
            out << "Usage:\n"
                "This command turns all living saplings on the map into full-grown trees.\n"
                "With active cursor, work on the targetted one only.\n";
            return CR_OK;
        }
    }

    CoreSuspender suspend;

    if (!Maps::IsValid())
    {
        out.printerr("Map is not available!\n");
        return CR_FAILURE;
    }
    MapExtras::MapCache map;
    int32_t x,y,z;
    if(Gui::getCursorCoords(x,y,z))
    {
        auto block = Maps::getTileBlock(x,y,z);
        stl::vector<df::plant *> *alltrees = &world->plants.all;
        if(alltrees)
        {
            for(size_t i = 0 ; i < alltrees->size(); i++)
            {
                df::plant * tree = alltrees->at(i);
                if(tree->pos.x == x && tree->pos.y == y && tree->pos.z == z)
                {
                    if(tileShape(map.tiletypeAt(DFCoord(x,y,z))) == tiletype_shape::SAPLING &&
                        tileSpecial(map.tiletypeAt(DFCoord(x,y,z))) != tiletype_special::DEAD)
                    {
                        tree->grow_counter = sapling_to_tree_threshold;
                    }
                    break;
                }
            }
        }
    }
    else
    {
        int grown = 0;
        for(size_t i = 0 ; i < world->plants.all.size(); i++)
        {
            df::plant *p = world->plants.all[i];
            df::tiletype ttype = map.tiletypeAt(df::coord(p->pos.x,p->pos.y,p->pos.z));
            bool is_shrub = p->flags >= plant_flags::shrub_forest;
            if(!is_shrub && tileShape(ttype) == tiletype_shape::SAPLING && tileSpecial(ttype) != tiletype_special::DEAD)
            {
                p->grow_counter = sapling_to_tree_threshold;
            }
        }
    }

    return CR_OK;
}
开发者ID:quietust,项目名称:dfhack-23a,代码行数:60,代码来源:plants.cpp


示例5: restrictLiquidProc

//Restrict traffic if tile is visible and liquid is present.
void restrictLiquidProc(DFCoord coord, MapExtras::MapCache &map)
{
    df::tile_designation des = map.designationAt(coord);
    if ((des.bits.hidden == 0) && (des.bits.flow_size != 0))
    {
        des.bits.traffic = tile_traffic::Restricted;
        map.setDesignationAt(coord, des);
    }
}
开发者ID:DFHack,项目名称:dfhack,代码行数:10,代码来源:filltraffic.cpp


示例6: df_grow

command_result df_grow (color_ostream &out, vector <string> & parameters)
{
    for(size_t i = 0; i < parameters.size();i++)
    {
        if(parameters[i] == "help" || parameters[i] == "?")
        {
            out.print("This command turns all living saplings into full-grown trees.\n");
            return CR_OK;
        }
    }
    CoreSuspender suspend;

    if (!Maps::IsValid())
    {
        out.printerr("Map is not available!\n");
        return CR_FAILURE;
    }
    MapExtras::MapCache map;
    int32_t x,y,z;
    if(Gui::getCursorCoords(x,y,z))
    {
        vector<df::plant *> * alltrees;
        if(Maps::ReadVegetation(x/16,y/16,z,alltrees))
        {
            for(size_t i = 0 ; i < alltrees->size(); i++)
            {
                df::plant * tree = alltrees->at(i);
                if(tree->pos.x == x && tree->pos.y == y && tree->pos.z == z)
                {
                    if(tileShape(map.tiletypeAt(DFCoord(x,y,z))) == tiletype_shape::SAPLING &&
                        tileSpecial(map.tiletypeAt(DFCoord(x,y,z))) != tiletype_special::DEAD)
                    {
                        tree->grow_counter = Vegetation::sapling_to_tree_threshold;
                    }
                    break;
                }
            }
        }
    }
    else
    {
        int grown = 0;
        for(size_t i = 0 ; i < world->plants.all.size(); i++)
        {
            df::plant *p = world->plants.all[i];
            df::tiletype ttype = map.tiletypeAt(df::coord(p->pos.x,p->pos.y,p->pos.z));
            if(!p->flags.bits.is_shrub && tileShape(ttype) == tiletype_shape::SAPLING && tileSpecial(ttype) != tiletype_special::DEAD)
            {
                p->grow_counter = Vegetation::sapling_to_tree_threshold;
            }
        }
    }

    return CR_OK;
}
开发者ID:AnnanFay,项目名称:dfhack,代码行数:55,代码来源:plants.cpp


示例7: restrictIceProc

//Restrict traffice if tile is above visible ice wall.
void restrictIceProc(DFCoord coord, MapExtras::MapCache &map)
{
    //There is no ice below the bottom of the map.
    if (coord.z == 0)
        return;

    DFCoord tile_below = DFCoord(coord.x, coord.y, coord.z - 1);
    df::tiletype tt = map.tiletypeAt(tile_below);
    df::tile_designation des = map.designationAt(tile_below);

    if ((des.bits.hidden == 0) && (tileMaterial(tt) == tiletype_material::FROZEN_LIQUID))
    {
        des = map.designationAt(coord);
        des.bits.traffic = tile_traffic::Restricted;
        map.setDesignationAt(coord, des);
    }
}
开发者ID:DFHack,项目名称:dfhack,代码行数:18,代码来源:filltraffic.cpp


示例8: putOnGround

static void putOnGround(MapExtras::MapCache &mc, df::item *item, df::coord pos)
{
    item->pos = pos;
    item->flags.bits.on_ground = true;

    if (!mc.addItemOnGround(item))
        Core::printerr("Could not add item %d to ground at (%d,%d,%d)\n",
                       item->id, pos.x, pos.y, pos.z);
}
开发者ID:Pheosics,项目名称:dfhack,代码行数:9,代码来源:Items.cpp


示例9: doSun

void lightingEngineViewscreen::doSun(const lightSource& sky,MapExtras::MapCache& map)
{
    //TODO fix this mess
    int window_x=*df::global::window_x;
    int window_y=*df::global::window_y;
    coord2d window2d(window_x,window_y);
    int window_z=*df::global::window_z;
    rect2d vp=getMapViewport();
    coord2d vpSize=rect_size(vp);
    rect2d blockVp;
    blockVp.first=window2d/16;
    blockVp.second=(window2d+vpSize)/16;
    blockVp.second.x=std::min(blockVp.second.x,(int16_t)df::global::world->map.x_count_block);
    blockVp.second.y=std::min(blockVp.second.y,(int16_t)df::global::world->map.y_count_block);
    //endof mess
    for(int blockX=blockVp.first.x;blockX<=blockVp.second.x;blockX++)
    for(int blockY=blockVp.first.y;blockY<=blockVp.second.y;blockY++)
    {
        rgbf cellArray[16][16];
        for(int block_x = 0; block_x < 16; block_x++)
        for(int block_y = 0; block_y < 16; block_y++)
            cellArray[block_x][block_y] = sky.power;

        int emptyCell=0;
        for(int z=window_z;z< df::global::world->map.z_count && emptyCell<256;z++)
        {
            MapExtras::Block* b=map.BlockAt(DFCoord(blockX,blockY,z));
            if(!b)
                continue;
            emptyCell=0;
            for(int block_x = 0; block_x < 16; block_x++)
            for(int block_y = 0; block_y < 16; block_y++)
            {
                rgbf& curCell=cellArray[block_x][block_y];
                curCell=propogateSun(b,block_x,block_y,curCell,z==window_z);
                if(curCell.dot(curCell)<0.003f)
                    emptyCell++;                
            }
        }
        if(emptyCell==256)
            continue;
        for(int block_x = 0; block_x < 16; block_x++)
        for(int block_y = 0; block_y < 16; block_y++)
        {
            rgbf& curCell=cellArray[block_x][block_y];
            df::coord2d pos;
            pos.x = blockX*16+block_x;
            pos.y = blockY*16+block_y;
            pos=worldToViewportCoord(pos,vp,window2d);
            if(isInRect(pos,vp) && curCell.dot(curCell)>0.003f)
            {
                lightSource sun=lightSource(curCell,15);
                addLight(getIndex(pos.x,pos.y),sun);
            }
        }
    }
}
开发者ID:warmist,项目名称:dfhack,代码行数:57,代码来源:renderer_light.cpp


示例10: onDig

void onDig(color_ostream& out, void* ptr) {
    CoreSuspender bob;
    df::job* job = (df::job*)ptr;
    if ( job->completion_timer > 0 )
        return;

    if ( job->job_type != df::enums::job_type::Dig &&
         job->job_type != df::enums::job_type::CarveUpwardStaircase &&
         job->job_type != df::enums::job_type::CarveDownwardStaircase &&
         job->job_type != df::enums::job_type::CarveUpDownStaircase &&
         job->job_type != df::enums::job_type::CarveRamp &&
         job->job_type != df::enums::job_type::DigChannel )
        return;

    set<df::coord> jobLocations;
    for ( df::job_list_link* link = &world->job_list; link != NULL; link = link->next ) {
        if ( link->item == NULL )
            continue;

        if ( link->item->job_type != df::enums::job_type::Dig &&
             link->item->job_type != df::enums::job_type::CarveUpwardStaircase &&
             link->item->job_type != df::enums::job_type::CarveDownwardStaircase &&
             link->item->job_type != df::enums::job_type::CarveUpDownStaircase &&
             link->item->job_type != df::enums::job_type::CarveRamp &&
             link->item->job_type != df::enums::job_type::DigChannel )
            continue;

        jobLocations.insert(link->item->pos);
    }

    MapExtras::MapCache cache;
    df::coord pos = job->pos;
    for ( int16_t a = -1; a <= 1; a++ ) {
        for ( int16_t b = -1; b <= 1; b++ ) {
            maybeExplore(out, cache, df::coord(pos.x+a,pos.y+b,pos.z), jobLocations);
        }
    }
    cache.trash();
}
开发者ID:Dimble,项目名称:dfhack,代码行数:39,代码来源:digFlood.cpp


示例11: maybeExplore

void maybeExplore(color_ostream& out, MapExtras::MapCache& cache, df::coord pt, set<df::coord>& jobLocations) {
    if ( !Maps::isValidTilePos(pt) ) {
        return;
    }

    df::map_block* block = Maps::getTileBlock(pt);
    if (!block)
        return;

    if ( block->designation[pt.x&0xF][pt.y&0xF].bits.hidden )
        return;

    df::tiletype type = block->tiletype[pt.x&0xF][pt.y&0xF];
    if ( ENUM_ATTR(tiletype, material, type) != df::enums::tiletype_material::MINERAL )
        return;
    if ( ENUM_ATTR(tiletype, shape, type) != df::enums::tiletype_shape::WALL )
        return;

    if ( block->designation[pt.x&0xF][pt.y&0xF].bits.dig != df::enums::tile_dig_designation::No )
        return;

    uint32_t xMax,yMax,zMax;
    Maps::getSize(xMax,yMax,zMax);
    if ( pt.x == 0 || pt.y == 0 || pt.x+1 == xMax*16 || pt.y+1 == yMax*16 )
        return;
    if ( jobLocations.find(pt) != jobLocations.end() ) {
        return;
    }

    int16_t mat = cache.veinMaterialAt(pt);
    if ( mat == -1 )
        return;
    if ( !digAll ) {
        df::inorganic_raw* inorganic = world->raws.inorganics[mat];
        if ( autodigMaterials.find(inorganic->id) == autodigMaterials.end() ) {
            return;
        }
    }

    block->designation[pt.x&0xF][pt.y&0xF].bits.dig = df::enums::tile_dig_designation::Default;
    block->flags.bits.designated = true;
//    *process_dig  = true;
//    *process_jobs = true;
}
开发者ID:Dimble,项目名称:dfhack,代码行数:44,代码来源:digFlood.cpp


示例12: dig

bool dig (MapExtras::MapCache & MCache,
    circle_what what,
    df::tile_dig_designation type,
    int32_t x, int32_t y, int32_t z,
    int x_max, int y_max
    )
{
    DFCoord at (x,y,z);
    auto b = MCache.BlockAt(at/16);
    if(!b || !b->valid)
        return false;
    if(x == 0 || x == x_max * 16 - 1)
    {
        //c->con.print("not digging map border\n");
        return false;
    }
    if(y == 0 || y == y_max * 16 - 1)
    {
        //c->con.print("not digging map border\n");
        return false;
    }
    df::tiletype tt = MCache.tiletypeAt(at);
    df::tile_designation des = MCache.designationAt(at);
    // could be potentially used to locate hidden constructions?
    if(tileMaterial(tt) == df::tiletype_material::CONSTRUCTION && !des.bits.hidden)
        return false;
    df::tiletype_shape ts = tileShape(tt);
    if (ts == tiletype_shape::EMPTY)
        return false;
    if(!des.bits.hidden)
    {
        do
        {
            df::tiletype_shape_basic tsb = ENUM_ATTR(tiletype_shape, basic_shape, ts);
            if(tsb == tiletype_shape_basic::Wall)
            {
                std::cerr << "allowing tt" << (int)tt << ", is wall\n";
                break;
            }
            if (tsb == tiletype_shape_basic::Floor
                && (type == tile_dig_designation::DownStair || type == tile_dig_designation::Channel)
                && ts != tiletype_shape::TREE
                )
            {
                std::cerr << "allowing tt" << (int)tt << ", is floor\n";
                break;
            }
            if (tsb == tiletype_shape_basic::Stair && type == tile_dig_designation::Channel )
                break;
            return false;
        }
        while(0);
    }
    switch(what)
    {
    case circle_set:
        if(des.bits.dig == tile_dig_designation::No)
        {
            des.bits.dig = type;
        }
        break;
    case circle_unset:
        if (des.bits.dig != tile_dig_designation::No)
        {
            des.bits.dig = tile_dig_designation::No;
        }
        break;
    case circle_invert:
        if(des.bits.dig == tile_dig_designation::No)
        {
            des.bits.dig = type;
        }
        else
        {
            des.bits.dig = tile_dig_designation::No;
        }
        break;
    }
    std::cerr << "allowing tt" << (int)tt << "\n";
    MCache.setDesignationAt(at,des);
    return true;
};
开发者ID:TroZ,项目名称:dfhack,代码行数:82,代码来源:vdig.cpp


示例13: digcircle


//.........这里部分代码省略.........
            " filled = Set the circle to filled\n"
            "\n"
            "    set = set designation\n"
            "  unset = unset current designation\n"
            " invert = invert current designation\n"
            "\n"
            "    dig = normal digging\n"
            "   ramp = ramp digging\n"
            " ustair = staircase up\n"
            " dstair = staircase down\n"
            " xstair = staircase up/down\n"
            "   chan = dig channel\n"
            "\n"
            "      # = diameter in tiles (default = 0)\n"
            "\n"
            "After you have set the options, the command called with no options\n"
            "repeats with the last selected parameters:\n"
            "'digcircle filled 3' = Dig a filled circle with radius = 3.\n"
            "'digcircle' = Do it again.\n"
            );
        return CR_OK;
    }
    int32_t cx, cy, cz;
    CoreSuspender suspend(c);
    if (!Maps::IsValid())
    {
        c->con.printerr("Map is not available!\n");
        return CR_FAILURE;
    }

    uint32_t x_max, y_max, z_max;
    Maps::getSize(x_max,y_max,z_max);

    MapExtras::MapCache MCache;
    if(!Gui::getCursorCoords(cx,cy,cz) || cx == -30000)
    {
        c->con.printerr("Can't get the cursor coords...\n");
        return CR_FAILURE;
    }
    int r = diameter / 2;
    int iter;
    bool adjust;
    if(diameter % 2)
    {
        // paint center
        if(filled)
        {
            lineY(MCache,what,type, cx - r, cx + r, cy, cz,x_max,y_max);
        }
        else
        {
            dig(MCache, what, type,cx - r, cy, cz,x_max,y_max);
            dig(MCache, what, type,cx + r, cy, cz,x_max,y_max);
        }
        adjust = false;
        iter = 2;
    }
    else
    {
        adjust = true;
        iter = 1;
    }
    int lastwhole = r;
    for(; iter <= diameter - 1; iter +=2)
    {
        // top, bottom coords
开发者ID:TroZ,项目名称:dfhack,代码行数:67,代码来源:vdig.cpp


示例14: setAllMatching

//Helper function for writing new functions that check every tile on the map.
//newTraffic is the traffic designation to set.
//check takes a coordinate and the map cache as arguments, and returns true if the criteria is met.
//minCoord and maxCoord can be used to specify a bounding cube.
DFhackCExport command_result setAllMatching(DFHack::Core * c, checkTile checkProc,
											DFHack::DFCoord minCoord, DFHack::DFCoord maxCoord)
{
	//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;

	//Ensure maximum coordinate is within map.  Truncate to map edge.
	maxCoord.x = std::min((uint32_t) maxCoord.x, tx_max);
	maxCoord.y = std::min((uint32_t) maxCoord.y, ty_max);
	maxCoord.z = std::min(maxCoord.z,  z_max);

	//Check minimum co-ordinates against maximum map size
	if (minCoord.x > maxCoord.x) 
	{
		c->con.printerr("Minimum x coordinate is greater than maximum x coordinate.\n");
        c->Resume();
        return CR_FAILURE;
	}
	if (minCoord.y > maxCoord.y) 
	{
		c->con.printerr("Minimum y coordinate is greater than maximum y coordinate.\n");
        c->Resume();
        return CR_FAILURE;
	}
	if (minCoord.z > maxCoord.y) 
	{
		c->con.printerr("Minimum z coordinate is greater than maximum z coordinate.\n");
        c->Resume();
        return CR_FAILURE;
	}

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

	c->con.print("Setting traffic...\n");

	//Loop through every single tile
	for(uint32_t x = minCoord.x; x <= maxCoord.x; x++)
	{
		for(uint32_t y = minCoord.y; y <= maxCoord.y; y++)
		{
			for(uint32_t z = minCoord.z; z <= maxCoord.z; z++)
			{
				DFHack::DFCoord tile = DFHack::DFCoord(x, y, z);
				checkProc(tile, MCache);
			}
		}
	}

	MCache->WriteAll();
	c->con.print("Complete!\n");
    c->Resume();
    return CR_OK;
}
开发者ID:kaypy,项目名称:dfhack,代码行数:73,代码来源:filltraffic.cpp


示例15: mapexport

command_result mapexport (color_ostream &out, std::vector <std::string> & parameters)
{
    bool showHidden = false;

    int filenameParameter = 1;

    for(size_t i = 0; i < parameters.size();i++)
    {
        if(parameters[i] == "help" || parameters[i] == "?")
        {
            out.print("Exports the currently visible map to a file.\n"
                         "Usage: mapexport [options] <filename>\n"
                         "Example: mapexport all embark.dfmap\n"
                         "Options:\n"
                         "   all   - Export the entire map, not just what's revealed.\n"
            );
            return CR_OK;
        }
        if (parameters[i] == "all")
        {
            showHidden = true;
            filenameParameter++;
        }
    }

    CoreSuspender suspend;

    uint32_t x_max=0, y_max=0, z_max=0;

    if (!Maps::IsValid())
    {
        out.printerr("Map is not available!\n");
        return CR_FAILURE;
    }

    if (parameters.size() < filenameParameter)
    {
        out.printerr("Please supply a filename.\n");
        return CR_FAILURE;
    }

    std::string filename = parameters[filenameParameter-1];
    if (filename.rfind(".dfmap") == std::string::npos) filename += ".dfmap";
    out << "Writing to " << filename << "..." << std::endl;

    std::ofstream output_file(filename, std::ios::out | std::ios::trunc | std::ios::binary);
    if (!output_file.is_open())
    {
        out.printerr("Couldn't open the output file.\n");
        return CR_FAILURE;
    }
    ZeroCopyOutputStream *raw_output = new OstreamOutputStream(&output_file);
    GzipOutputStream *zip_output = new GzipOutputStream(raw_output);
    CodedOutputStream *coded_output = new CodedOutputStream(zip_output);

    coded_output->WriteLittleEndian32(0x50414DDF); //Write our file header

    Maps::getSize(x_max, y_max, z_max);
    MapExtras::MapCache map;
    DFHack::Materials *mats = Core::getInstance().getMaterials();

    out << "Writing  map info..." << std::endl;

    dfproto::Map protomap;
    protomap.set_x_size(x_max);
    protomap.set_y_size(y_max);
    protomap.set_z_size(z_max);

    out << "Writing material dictionary..." << std::endl;
    
    for (size_t i = 0; i < world->raws.inorganics.size(); i++)
    {
        dfproto::Material *protomaterial = protomap.add_inorganic_material();
        protomaterial->set_index(i);
        protomaterial->set_name(world->raws.inorganics[i]->id);
    }

    for (size_t i = 0; i < world->raws.plants.all.size(); i++)
    {
        dfproto::Material *protomaterial = protomap.add_organic_material();
        protomaterial->set_index(i);
        protomaterial->set_name(world->raws.plants.all[i]->id);
    }

    std::map<df::coord,std::pair<uint32_t,uint16_t> > constructionMaterials;
    if (Constructions::isValid())
    {
        for (uint32_t i = 0; i < Constructions::getCount(); i++)
        {
            df::construction *construction = Constructions::getConstruction(i);
            constructionMaterials[construction->pos] = std::make_pair(construction->mat_index, construction->mat_type);
        }
    }
        
    coded_output->WriteVarint32(protomap.ByteSize());
    protomap.SerializeToCodedStream(coded_output);
    
    DFHack::t_feature blockFeatureGlobal;
    DFHack::t_feature blockFeatureLocal;

//.........这里部分代码省略.........
开发者ID:AnnanFay,项目名称:dfhack,代码行数:101,代码来源:mapexport.cpp


示例16: expdig


//.........这里部分代码省略.........
        int x = 0,mx = 16;
        if(bx == 0)
            x = 1;
        if(bx == x_max - 1)
            mx = 15;
        for(; x < mx; x++)
        {
            int y = 0,my = 16;
            if(by == 0)
                y = 1;
            if(by == y_max - 1)
                my = 15;
            for(; y < my; y++)
            {
                naked_designation & des = bl->designation[x][y].bits;
                short unsigned int tt = bl->tiletype[x][y];
                // could be potentially used to locate hidden constructions?
                if(tileMaterial(tt) == CONSTRUCTED && !des.hidden)
                    continue;
                if(!isWallTerrain(tt) && !des.hidden)
                    continue;
                if(how == EXPLO_CLEAR)
                {
                    des.dig = designation_no;
                    continue;
                }
                if(dm[y][x])
                {
                    if(what == EXPLO_ALL
                        || des.dig == designation_default && what == EXPLO_DESIGNATED
                        || des.hidden && what == EXPLO_HIDDEN)
                    {
                        des.dig = designation_default;
                    }
                }
                else if(what == EXPLO_DESIGNATED)
                {
                    des.dig = designation_no;
                }
            }
        }
        bl->flags.set(BLOCK_DESIGNATED);
        return true;
    };
    if(how == EXPLO_DIAG5)
    {
        int which;
        for(uint32_t x = 0; x < x_max; x++)
        {
            for(int32_t y = 0 ; y < y_max; y++)
            {
                which = (4*x + y) % 5;
                apply(x,y_max - 1 - y,diag5[which]);
            }
        }
    }
    else if(how == EXPLO_LADDER)
    {
        int which;
        for(uint32_t x = 0; x < x_max; x++)
        {
            which = x % 3;
            for(int32_t y = 0 ; y < y_max; y++)
            {
                apply(x,y,ladder[which]);
            }
        }
    }
    else if(how == EXPLO_CROSS)
    {
        // middle + recentering for the image
        int xmid = x_max * 8 - 8;
        int ymid = y_max * 8 - 8;
        MapExtras::MapCache mx (maps);
        for(int x = 0; x < 16; x++)
            for(int y = 0; y < 16; y++)
            {
                DFCoord pos(xmid+x,ymid+y,z_level);
                short unsigned int tt = mx.tiletypeAt(pos);
                if(tt == 0)
                    continue;
                t_designation des = mx.designationAt(pos);
                if(tileMaterial(tt) == CONSTRUCTED && !des.bits.hidden)
                    continue;
                if(!isWallTerrain(tt) && !des.bits.hidden)
                    continue;
                if(cross[y][x])
                {
                    des.bits.dig = designation_default;
                    mx.setDesignationAt(pos,des);
                }
            }
        mx.WriteAll();
    }
    else for(uint32_t x = 0; x < x_max; x++)
        for(int32_t y = 0 ; y < y_max; y++)
            apply(x,y,all_tiles);
    c->Resume();
    return CR_OK;
}
开发者ID:gsvslto,项目名称:dfhack,代码行数:101,代码来源:vdig.cpp


示例17: 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


示例18: 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


示例19: prospector

command_result prospector (color_ostream &con, vector <string> & parameters)
{
    bool showHidden = false;
    bool showPlants = true;
    bool showSlade = true;
    bool showTemple = true;
    bool showValue = false;
    bool showTube = false;

    for(size_t i = 0; i < parameters.size();i++)
    {
        if (parameters[i] == "all")
        {
            showHidden = true;
        }
        else if (parameters[i] == "value")
        {
            showValue = true;
        }
        else if (parameters[i] == "hell")
        {
            showHidden = showTube = true;
        }
        else
            return CR_WRONG_USAGE;
    }

    CoreSuspender suspend;

    // Embark screen active: estimate using world geology data
    if (VIRTUAL_CAST_VAR(screen, df::viewscreen_choose_start_sitest, Core::getTopViewscreen()))
        return embark_prospector(con, screen, showHidden, showValue);

    if (!Maps::IsValid())
    {
        con.printerr("Map is not available!\n");
        return CR_FAILURE;
    }

    uint32_t x_max = 0, y_max = 0, z_max = 0;
    Maps::getSize(x_max, y_max, z_max);
    MapExtras::MapCache map;

    DFHack::Materials *mats = Core::getInstance().getMaterials();

    DFHack::t_feature blockFeatureGlobal;
    DFHack::t_feature blockFeatureLocal;

    bool hasAquifer = false;
    bool hasDemonTemple = false;
    bool hasLair = false;
    MatMap baseMats;
    MatMap layerMats;
    MatMap veinMats;
    MatMap plantMats;
    MatMap treeMats;

    matdata liquidWater;
    matdata liquidMagma;
    matdata aquiferTiles;
    matdata tubeTiles;

    uint32_t vegCount = 0;

    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
                df::coord2d blockCoord(b_x, b_y);
                MapExtras::Block *b = map.BlockAt(DFHack::DFCoord(b_x, b_y, z));
                if (!b || !b->is_valid())
                {
                    continue;
                }

                // Find features
                b->GetGlobalFeature(&blockFeatureGlobal);
                b->GetLocalFeature(&blockFeatureLocal);

                int global_z = world->map.region_z + z;

                // Iterate over all the tiles in the block
                for(uint32_t y = 0; y < 16; y++)
                {
                    for(uint32_t x = 0; x < 16; x++)
                    {
                        df::coord2d coord(x, y);
                        df::tile_designation des = b->DesignationAt(coord);
                        df::tile_occupancy occ = b->OccupancyAt(coord);

                        // Skip hidden tiles
                        if (!showHidden && des.bits.hidden)
                        {
                            continue;
                        }

                        // Check for aquifer
//.........这里部分代码省略.........
开发者ID:Pheosics,项目名称:dfhack,代码行数:101,代码来源:prospector.cpp


示例20: colorTile

void colorTile(const df::tiletype_material& tileMat,MapExtras::MapCache& cache,const DFCoord& pos,screenTile& trg,bool isUndug=false)
{
    t_matpair mat;

    switch(tileMat)
    {
    case df::tiletype_material::ASHES:
        trg.fg=COLOR_GREY;
        trg.bold=false;
        break;
    case df::tiletype_material::CAMPFIRE:
        trg.fg=COLOR_YELLOW;
        trg.bold=true;
        break;
    case df::tiletype_material::SOIL:
        mat=cache.baseMaterialAt(pos);
        {
            df::material* m=lookupMaterial(mat,trg);
            if(m && isUndug)
            {
                trg.tile=m->tile;
            }
            break;
        }
    case df::tiletype_material::STONE:
    case df::tiletype_material::LAVA_STONE:
        mat=cache.baseMaterialAt(pos);
        lookupMaterial(mat,trg);
        break;
    case df::tiletype_material::CONSTRUCTION:
        mat=cache.staticMaterialAt(pos);
        lookupMaterial(mat,trg,true);
        break;
    case df::tiletype_material::MINERAL:
        mat.mat_index=cache.veinMaterialAt(pos);
        mat.mat_type=0;//inorganic
        {
            df::material* m=lookupMaterial(mat,trg);
            if(m && isUndug)
            {
                trg.tile=m->tile;
            }
        }


        break;

    case df::tiletype_material::FROZEN_LIQUID:
        trg.fg=COLOR_CYAN;
        trg.bold=true;
        break;
    case df::tiletype_material::PLANT:
    case df::tiletype_m 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ mapnik::Map类代码示例发布时间:2022-05-31
下一篇:
C++ mapcallbacklist::iterator类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap