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


C++ MapCache::BlockAt方法代码示例

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


在下文中一共展示了MapCache::BlockAt方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例3: changelayer

command_result changelayer (color_ostream &out, std::vector <std::string> & parameters)
{
    CoreSuspender suspend; 

    string material;
    bool force = false;
    bool all_biomes = false;
    bool all_layers = false;
    bool verbose = false;
    warned = false;

    for(size_t i = 0; i < parameters.size();i++)
    {
        if(parameters[i] == "help" || parameters[i] == "?")
        {
            out.print(changelayer_help.c_str());
            return CR_OK;
        }
        if(parameters[i] == "trouble")
        {
            out.print(changelayer_trouble.c_str());
            return CR_OK;
        }
        if(parameters[i] == "force")
            force = true;
        if(parameters[i] == "all_biomes")
            all_biomes = true;
        if(parameters[i] == "all_layers")
            all_layers = true;
        if(parameters[i] == "verbose")
            verbose = true;
    }

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

    if (parameters.empty())
    {
        out.printerr("You need to specify a material!\n");
        return CR_WRONG_USAGE;
    }

    material = parameters[0];

    MaterialInfo mat_new;
    if (!mat_new.findInorganic(material))
    {
        out.printerr("No such material!\n");
        return CR_FAILURE;
    }

    // check if specified material is stone or gem or soil
    if (mat_new.inorganic->material.flags.is_set(material_flags::IS_METAL) ||
        mat_new.inorganic->material.flags.is_set(material_flags::NO_STONE_STOCKPILE))
    {
        out.printerr("Invalid material - you must select a type of stone or gem or soil.\n");
        return CR_FAILURE;
    }


    MapExtras::MapCache mc;

    int32_t regionX, regionY, regionZ;
    Maps::getPosition(regionX,regionY,regionZ);

    int32_t cursorX, cursorY, cursorZ;
    Gui::getCursorCoords(cursorX,cursorY,cursorZ);
    if(cursorX == -30000)
    {
        out.printerr("No cursor; place cursor over tile.\n");
        return CR_FAILURE;
    }
    DFCoord cursor (cursorX,cursorY,cursorZ);

    uint32_t blockX = cursorX / 16;
    uint32_t tileX = cursorX % 16;
    uint32_t blockY = cursorY / 16;
    uint32_t tileY = cursorY % 16;

    MapExtras::Block * b = mc.BlockAt(cursor/16);
    if(!b || !b->is_valid())
    {
        out.printerr("No data.\n");
        return CR_OK;
    }

    df::tile_designation des = b->DesignationAt(cursor%16);

    // get biome and geolayer at cursor position
    uint32_t biome = des.bits.biome;
    uint32_t layer = des.bits.geolayer_index;
    if(verbose)
    {
        out << "biome: " << biome << endl
            << "geolayer: " << layer << endl;
    }

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

示例4: digcircle


//.........这里部分代码省略.........
                        "      # = 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;
    c->Suspend();
    Gui * gui = c->getGui();
    Maps * maps = c->getMaps();
    if(!maps->Start())
    {
        c->Resume();
        c->con.printerr("Can't init the map...\n");
        return CR_FAILURE;
    }

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

    MapExtras::MapCache MCache (maps);
    if(!gui->getCursorCoords(cx,cy,cz) || cx == -30000)
    {
        c->Resume();
        c->con.printerr("Can't get the cursor coords...\n");
        return CR_FAILURE;
    }
    auto dig = [&](int32_t x, int32_t y, int32_t z) -> bool
    {
        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;
        }
        uint16_t tt = MCache.tiletypeAt(at);
        t_designation des = MCache.designationAt(at);
        // could be potentially used to locate hidden constructions?
        if(tileMaterial(tt) == CONSTRUCTED && !des.bits.hidden)
            return false;
        TileShape ts = tileShape(tt);
        if(ts == EMPTY)
            return false;
        if(!des.bits.hidden)
        {
            do
            {
                if(isWallTerrain(tt))
                {
                    std::cerr << "allowing tt" << tt << ", is wall\n";
                    break;
                }
                if(isFloorTerrain(tt)
                   && (type == designation_d_stair || type == designation_channel)
                   && ts != TREE_OK
开发者ID:gsvslto,项目名称:dfhack,代码行数:67,代码来源:vdig.cpp

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

示例6: prospector

command_result prospector (color_ostream &con, vector <string> & parameters)
{
    bool showHidden = false;
    bool showPlants = true;
    bool showValue = false;
    bool showHFS = 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 = showHFS = 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 blockFeature;

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

    matdata liquidWater;
    matdata liquidMagma;
    matdata aquiferTiles;
    matdata hfsTiles;

    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->GetFeature(&blockFeature);

                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
                        if (des.bits.water_table)
                        {
                            hasAquifer = true;
                            aquiferTiles.add(global_z);
                        }

//.........这里部分代码省略.........
开发者ID:mstram,项目名称:dfhack-40d,代码行数:101,代码来源:prospector.cpp

示例7: df_probe

command_result df_probe (color_ostream &out, vector <string> & parameters)
{
    //bool showBlock, showDesig, showOccup, showTile, showMisc;

    /*
    if (!parseOptions(parameters, showBlock, showDesig, showOccup,
                      showTile, showMisc))
    {
        out.printerr("Unknown parameters!\n");
        return CR_FAILURE;
    }
    */

    CoreSuspender suspend;

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

    std::vector<t_matglossInorganic> inorganic;
    bool hasmats = Materials->CopyInorganicMaterials(inorganic);

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

    int32_t regionX, regionY, regionZ;
    Maps::getPosition(regionX,regionY,regionZ);

    int32_t cursorX, cursorY, cursorZ;
    Gui::getCursorCoords(cursorX,cursorY,cursorZ);
    if(cursorX == -30000)
    {
        out.printerr("No cursor; place cursor over tile to probe.\n");
        return CR_FAILURE;
    }
    DFCoord cursor (cursorX,cursorY,cursorZ);

    uint32_t blockX = cursorX / 16;
    uint32_t tileX = cursorX % 16;
    uint32_t blockY = cursorY / 16;
    uint32_t tileY = cursorY % 16;

    MapExtras::Block * b = mc.BlockAt(cursor/16);
    if(!b || !b->is_valid())
    {
        out.printerr("No data.\n");
        return CR_OK;
    }

    auto &block = *b->getRaw();
    out.print("block addr: 0x%x\n\n", &block);
/*
    if (showBlock)
    {
        out.print("block flags:\n");
        print_bits<uint32_t>(block.blockflags.whole,out);
        out.print("\n\n");
    }
*/
    df::tiletype tiletype = mc.tiletypeAt(cursor);
    df::tile_designation &des = block.designation[tileX][tileY];
    df::tile_occupancy &occ = block.occupancy[tileX][tileY];
/*
    if(showDesig)
    {
        out.print("designation\n");
        print_bits<uint32_t>(block.designation[tileX][tileY].whole,
                                out);
        out.print("\n\n");
    }

    if(showOccup)
    {
        out.print("occupancy\n");
        print_bits<uint32_t>(block.occupancy[tileX][tileY].whole,
                                out);
        out.print("\n\n");
    }
*/

    // tiletype
    out.print("tiletype: ");
    describeTile(out, tiletype);
    out.print("static: ");
    describeTile(out, mc.staticTiletypeAt(cursor));
    out.print("base: ");
    describeTile(out, mc.baseTiletypeAt(cursor));

    out.print("temperature1: %d U\n",mc.temperature1At(cursor));
    out.print("temperature2: %d U\n",mc.temperature2At(cursor));

    int offset = block.region_offset[des.bits.biome];
    int bx = clip_range(block.region_pos.x + (offset % 3) - 1, 0, world->world_data->world_width-1);
    int by = clip_range(block.region_pos.y + (offset / 3) - 1, 0, world->world_data->world_height-1);

    auto biome = &world->world_data->region_map[bx][by];

    int sav = biome->savagery;
//.........这里部分代码省略.........
开发者ID:AlexanderStarr,项目名称:dfhack,代码行数:101,代码来源:probe.cpp

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

示例9: drawBuffer


//.........这里部分代码省略.........
                }
            }
            bool inliquid=false;
            bool unDug= (sp!=df::tiletype_special::SMOOTH && shape==df::tiletype_shape::WALL);
            if (d.bits.flow_size>0)
            {
                curTile.tile='0'+d.bits.flow_size;
                curTile.fg=(d.bits.liquid_type)?(COLOR_RED):(COLOR_BLUE);
                curTile.bold=true;
                inliquid=true;
            }    
            if(!inliquid && shape!=df::tiletype_shape::RAMP_TOP)
            {
                curTile.tile=tilePics[tt];
                colorTile(tileMat,cache,coord,curTile,unDug);
                if(!unDug)
                {
                    curTile.bg=0;
                }
            }
            else
            {
                if(shape==df::tiletype_shape::RAMP || shape==df::tiletype_shape::BROOK_BED || shape==df::tiletype_shape::RAMP_TOP)
                    curTile.tile=tilePics[tt];
                if(!inliquid)
                    colorTile(tileMat,cache,coord,curTile,true);
            }

        }
        //plants
        for(int bx=window.first.x/16;bx<=window.second.x/16;bx++) //blocks have items by id. So yeah each item a search would be slow
            for(int by=window.first.y/16;by<=window.second.y/16;by++)
            {
                MapExtras::Block* b=cache.BlockAt(DFCoord(bx,by,z));
                if(!b || !b->getRaw())
                    continue;
                std::vector<df::plant*>& plants=b->getRaw()->plants;
                for(int i=0;i<plants.size();i++)
                {
                    df::plant* p=plants[i];
                    if(p->pos.z==z && isInRect(df::coord2d(p->pos.x,p->pos.y),window))
                    {
                        int wx=p->pos.x-window.first.x;
                        int wy=p->pos.y-window.first.y;
                        screenTile& curTile=buffer[wx*h+wy];
                        drawPlant(p,curTile);
                    }
                }
                std::vector<df::block_square_event*>& events=b->getRaw()->block_events;
                for(size_t i=0;i<events.size();i++)//maybe aggregate all the events to one array and move to a function.
                {
                    df::block_square_event* e=events[i];
                    switch(e->getType())
                    {
                    case df::block_square_event_type::grass:
                        {
                            df::block_square_event_grassst* grass=static_cast<df::block_square_event_grassst*>(e);
                            MaterialInfo mat(419, grass->plant_index);
                            if(mat.isPlant())
                            {
                                df::plant_raw* p=mat.plant;
                                for(int x=0;x<16;x++)
                                for(int y=0;y<16;y++)
                                {
                                    int wx=x+bx*16-window.first.x;
                                    int wy=y+by*16-window.first.y;
开发者ID:warmist,项目名称:dfhack,代码行数:67,代码来源:Offscreen.cpp

示例10: mapexport


//.........这里部分代码省略.........
    {
        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;

    out.print("Writing map block information");

    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++)
            {
                if (b_x == 0 && b_y == 0 && z % 10 == 0) out.print(".");
                // 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->valid)
                {
                    continue;
                }

                dfproto::Block protoblock;
                protoblock.set_x(b_x);
                protoblock.set_y(b_y);
                protoblock.set_z(z);

                { // Find features
                    uint32_t index = b->raw.global_feature;
                    if (index != -1)
                        Maps::GetGlobalFeature(blockFeatureGlobal, index);

                    index = b->raw.local_feature;
                    if (index != -1)
                        Maps::GetLocalFeature(blockFeatureLocal, blockCoord, index);
                }

                int global_z = df::global::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
开发者ID:AnnanFay,项目名称:dfhack,代码行数:67,代码来源:mapexport.cpp

示例11: df_probe

command_result df_probe (Core * c, vector <string> & parameters)
{
    //bool showBlock, showDesig, showOccup, showTile, showMisc;
    Console & con = c->con;
    /*
    if (!parseOptions(parameters, showBlock, showDesig, showOccup,
                      showTile, showMisc))
    {
        con.printerr("Unknown parameters!\n");
        return CR_FAILURE;
    }
    */

    CoreSuspender suspend(c);

    DFHack::Gui *Gui = c->getGui();
    DFHack::Materials *Materials = c->getMaterials();
    DFHack::VersionInfo* mem = c->vinfo;
    std::vector<t_matglossInorganic> inorganic;
    bool hasmats = Materials->CopyInorganicMaterials(inorganic);

    if (!Maps::IsValid())
    {
        c->con.printerr("Map is not available!\n");
        return CR_FAILURE;
    }
    MapExtras::MapCache mc;

    int32_t regionX, regionY, regionZ;
    Maps::getPosition(regionX,regionY,regionZ);

    int32_t cursorX, cursorY, cursorZ;
    Gui->getCursorCoords(cursorX,cursorY,cursorZ);
    if(cursorX == -30000)
    {
        con.printerr("No cursor; place cursor over tile to probe.\n");
        return CR_FAILURE;
    }
    DFCoord cursor (cursorX,cursorY,cursorZ);

    uint32_t blockX = cursorX / 16;
    uint32_t tileX = cursorX % 16;
    uint32_t blockY = cursorY / 16;
    uint32_t tileY = cursorY % 16;

    MapExtras::Block * b = mc.BlockAt(cursor/16);
    if(!b && !b->valid)
    {
        con.printerr("No data.\n");
        return CR_OK;
    }
    mapblock40d & block = b->raw;
    con.print("block addr: 0x%x\n\n", block.origin);
/*
    if (showBlock)
    {
        con.print("block flags:\n");
        print_bits<uint32_t>(block.blockflags.whole,con);
        con.print("\n\n");
    }
*/
    df::tiletype tiletype = mc.tiletypeAt(cursor);
    df::tile_designation &des = block.designation[tileX][tileY];
/*
    if(showDesig)
    {
        con.print("designation\n");
        print_bits<uint32_t>(block.designation[tileX][tileY].whole,
                                con);
        con.print("\n\n");
    }

    if(showOccup)
    {
        con.print("occupancy\n");
        print_bits<uint32_t>(block.occupancy[tileX][tileY].whole,
                                con);
        con.print("\n\n");
    }
*/

    // tiletype
    con.print("tiletype: %d", tiletype);
    if(tileName(tiletype))
        con.print(" = %s",tileName(tiletype));
    con.print("\n");

    df::tiletype_shape shape = tileShape(tiletype);
    df::tiletype_material material = tileMaterial(tiletype);
    df::tiletype_special special = tileSpecial(tiletype);
    df::tiletype_variant variant = tileVariant(tiletype);
    con.print("%-10s: %4d %s\n","Class"    ,shape,
            ENUM_KEY_STR(tiletype_shape, shape));
    con.print("%-10s: %4d %s\n","Material" ,
            material, ENUM_KEY_STR(tiletype_material, material));
    con.print("%-10s: %4d %s\n","Special"  ,
            special, ENUM_KEY_STR(tiletype_special, special));
    con.print("%-10s: %4d %s\n"   ,"Variant"  ,
            variant, ENUM_KEY_STR(tiletype_variant, variant));
    con.print("%-10s: %s\n"    ,"Direction",
//.........这里部分代码省略.........
开发者ID:lxnt,项目名称:dfhack,代码行数:101,代码来源:probe.cpp

示例12: doOcupancyAndLights

void lightingEngineViewscreen::doOcupancyAndLights()
{
    float daycol;
    if(dayHour<0)
    {
        int length=1200/daySpeed;
        daycol= (*df::global::cur_year_tick % length)/ (float)length;
    }
    else
        daycol= fmod(dayHour,24.0f)/24.0f; //1->12h 0->24h
    
    rgbf sky_col=getSkyColor(daycol);
    lightSource sky(sky_col, -1);//auto calculate best size
    
    MapExtras::MapCache cache;
    doSun(sky,cache);

    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=coord2d(window_x,window_y)/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);
   
    for(int blockX=blockVp.first.x;blockX<=blockVp.second.x;blockX++)
    for(int blockY=blockVp.first.y;blockY<=blockVp.second.y;blockY++)
    {
        MapExtras::Block* b=cache.BlockAt(DFCoord(blockX,blockY,window_z));
        MapExtras::Block* bDown=cache.BlockAt(DFCoord(blockX,blockY,window_z-1));
        if(!b)
            continue; //empty blocks fixed by sun propagation
        
        for(int block_x = 0; block_x < 16; block_x++)
        for(int block_y = 0; block_y < 16; block_y++)
        {
            df::coord2d pos;
            pos.x = blockX*16+block_x;
            pos.y = blockY*16+block_y;
            df::coord2d gpos=pos;
            pos=worldToViewportCoord(pos,vp,window2d);
            if(!isInRect(pos,vp))
                continue;
            int tile=getIndex(pos.x,pos.y);
            rgbf& curCell=ocupancy[tile];
            curCell=matAmbience.transparency;
            

            df::tiletype type = b->tiletypeAt(gpos);
            df::tile_designation d = b->DesignationAt(gpos);
            if(d.bits.hidden)
            {
                curCell=rgbf(0,0,0);
                continue; // do not process hidden stuff, TODO other hidden stuff
            }
            //df::tile_occupancy o = b->OccupancyAt(gpos);
            df::tiletype_shape shape = ENUM_ATTR(tiletype,shape,type);
            df::tiletype_shape_basic basic_shape = ENUM_ATTR(tiletype_shape, basic_shape, shape);
            df::tiletype_material tileMat= ENUM_ATTR(tiletype,material,type);
            
            DFHack::t_matpair mat=b->staticMaterialAt(gpos);
            
            matLightDef* lightDef=getMaterialDef(mat.mat_type,mat.mat_index);
            if(!lightDef || !lightDef->isTransparent)
                lightDef=&matWall;
            if(shape==df::tiletype_shape::BROOK_BED )
            {
                curCell=rgbf(0,0,0);
            }
            else if(shape==df::tiletype_shape::WALL)
            {
                if(tileMat==df::tiletype_material::FROZEN_LIQUID)
                    applyMaterial(tile,matIce);
                else
                    applyMaterial(tile,*lightDef);
            }
            else if(!d.bits.liquid_type && d.bits.flow_size>0 )
            {
                applyMaterial(tile,matWater, (float)d.bits.flow_size/7.0f, (float)d.bits.flow_size/7.0f);
            }
            if(d.bits.liquid_type && d.bits.flow_size>0) 
            {
                applyMaterial(tile,matLava,(float)d.bits.flow_size/7.0f,(float)d.bits.flow_size/7.0f);
            }
            else if(shape==df::tiletype_shape::EMPTY || shape==df::tiletype_shape::RAMP_TOP 
                || shape==df::tiletype_shape::STAIR_DOWN || shape==df::tiletype_shape::STAIR_UPDOWN)
            {
                if(bDown)
                {
                   df::tile_designation d2=bDown->DesignationAt(gpos);
                   if(d2.bits.liquid_type && d2.bits.flow_size>0)
                   {
                       applyMaterial(tile,matLava);
                   }
                }
            }
//.........这里部分代码省略.........
开发者ID:warmist,项目名称:dfhack,代码行数:101,代码来源:renderer_light.cpp


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