本文整理汇总了C++中mapextras::MapCache类的典型用法代码示例。如果您正苦于以下问题:C++ MapCache类的具体用法?C++ MapCache怎么用?C++ MapCache使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MapCache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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++;
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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);
}
示例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);
}
}
}
}
示例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();
}
示例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;
}
示例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;
};
示例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
示例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;
}
示例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;
//.........这里部分代码省略.........