本文整理汇总了C++中mapextras::MapCache::testCoord方法的典型用法代码示例。如果您正苦于以下问题:C++ MapCache::testCoord方法的具体用法?C++ MapCache::testCoord怎么用?C++ MapCache::testCoord使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mapextras::MapCache
的用法示例。
在下文中一共展示了MapCache::testCoord方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
}
//.........这里部分代码省略.........
示例2: vdig
command_result vdig (Core * c, vector <string> & parameters)
{
// HOTKEY COMMAND: CORE ALREADY SUSPENDED
uint32_t x_max,y_max,z_max;
bool updown = false;
for(size_t i = 0; i < parameters.size();i++)
{
if(parameters.size() && parameters[0]=="x")
updown = true;
else
return CR_WRONG_USAGE;
}
Console & con = c->con;
if (!Maps::IsValid())
{
c->con.printerr("Map is not available!\n");
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");
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");
return CR_FAILURE;
}
MapExtras::MapCache * MCache = new MapExtras::MapCache;
df::tile_designation des = MCache->designationAt(xy);
df::tiletype tt = MCache->tiletypeAt(xy);
int16_t veinmat = MCache->veinMaterialAt(xy);
if( veinmat == -1 )
{
con.printerr("This tile is not a vein.\n");
delete MCache;
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
df::tile_designation des = MCache->designationAt(current);
df::tile_designation des_minus;
df::tile_designation des_plus;
des_plus.whole = des_minus.whole = 0;
int16_t vmat_minus = -1;
int16_t vmat_plus = -1;
bool below = 0;
bool above = 0;
if(updown)
{
if(MCache->testCoord(current-1))
{
below = 1;
des_minus = MCache->designationAt(current-1);
vmat_minus = MCache->veinMaterialAt(current-1);
}
if(MCache->testCoord(current+1))
{
above = 1;
des_plus = MCache->designationAt(current+1);
vmat_plus = MCache->veinMaterialAt(current+1);
}
}
if(MCache->testCoord(current))
{
MCache->clearMaterialAt(current);
if(current.x < tx_max - 2)
{
flood.push(DFHack::DFCoord(current.x + 1, current.y, current.z));
if(current.y < ty_max - 2)
{
flood.push(DFHack::DFCoord(current.x + 1, current.y + 1,current.z));
flood.push(DFHack::DFCoord(current.x, current.y + 1,current.z));
}
if(current.y > 1)
{
//.........这里部分代码省略.........
示例3: filltraffic
//.........这里部分代码省略.........
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");
delete MCache;
c->Resume();
return CR_FAILURE;
}
if(checkpit && DFHack::isOpenTerrain(tt))
{
c->con.printerr("This tile is a hole. Please select a passable tile.\n");
delete MCache;
c->Resume();
return CR_FAILURE;
}
if(checkbuilding && oc.bits.building)
{
c->con.printerr("This tile contains a building. Please select an empty tile.\n");
delete MCache;
c->Resume();
return CR_FAILURE;
}
c->con.print("%d/%d/%d ... FILLING!\n", cx,cy,cz);
//Naive four-way or six-way flood fill with possible tiles on a stack.
stack <DFHack::DFCoord> flood;
flood.push(xy);
while(!flood.empty())
{
xy = flood.top();
flood.pop();
des = MCache->designationAt(xy);
if (des.bits.traffic != source) continue;
tt = MCache->tiletypeAt(xy);
if(DFHack::isWallTerrain(tt)) continue;
if(checkpit && DFHack::isOpenTerrain(tt)) continue;
if (checkbuilding)
{
oc = MCache->occupancyAt(xy);
if(oc.bits.building) continue;
}
//This tile is ready. Set its traffic level and add surrounding tiles.
if (MCache->testCoord(xy))
{
des.bits.traffic = target;
MCache->setDesignationAt(xy,des);
if (xy.x > 0)
{
flood.push(DFHack::DFCoord(xy.x - 1, xy.y, xy.z));
}
if (xy.x < tx_max - 1)
{
flood.push(DFHack::DFCoord(xy.x + 1, xy.y, xy.z));
}
if (xy.y > 0)
{
flood.push(DFHack::DFCoord(xy.x, xy.y - 1, xy.z));
}
if (xy.y < ty_max - 1)
{
flood.push(DFHack::DFCoord(xy.x, xy.y + 1, xy.z));
}
if (updown)
{
if (xy.z > 0 && DFHack::LowPassable(tt))
{
flood.push(DFHack::DFCoord(xy.x, xy.y, xy.z - 1));
}
if (xy.z < z_max && DFHack::HighPassable(tt))
{
flood.push(DFHack::DFCoord(xy.x, xy.y, xy.z + 1));
}
}
}
}
MCache->WriteAll();
c->Resume();
return CR_OK;
}
示例4: filltraffic
//.........这里部分代码省略.........
MapExtras::MapCache MCache;
df::tile_designation des = MCache.designationAt(xy);
df::tiletype tt = MCache.tiletypeAt(xy);
df::tile_occupancy oc;
if (checkbuilding)
oc = MCache.occupancyAt(xy);
source = (df::tile_traffic)des.bits.traffic;
if(source == target)
{
out.printerr("This tile is already set to the target traffic type.\n");
return CR_FAILURE;
}
if(isWallTerrain(tt))
{
out.printerr("This tile is a wall. Please select a passable tile.\n");
return CR_FAILURE;
}
if(checkpit && isOpenTerrain(tt))
{
out.printerr("This tile is a hole. Please select a passable tile.\n");
return CR_FAILURE;
}
if(checkbuilding && oc.bits.building)
{
out.printerr("This tile contains a building. Please select an empty tile.\n");
return CR_FAILURE;
}
out.print("%d/%d/%d ... FILLING!\n", cx,cy,cz);
//Naive four-way or six-way flood fill with possible tiles on a stack.
stack <DFCoord> flood;
flood.push(xy);
while(!flood.empty())
{
xy = flood.top();
flood.pop();
des = MCache.designationAt(xy);
if (des.bits.traffic != source) continue;
tt = MCache.tiletypeAt(xy);
if(isWallTerrain(tt)) continue;
if(checkpit && isOpenTerrain(tt)) continue;
if (checkbuilding)
{
oc = MCache.occupancyAt(xy);
if(oc.bits.building) continue;
}
//This tile is ready. Set its traffic level and add surrounding tiles.
if (MCache.testCoord(xy))
{
des.bits.traffic = target;
MCache.setDesignationAt(xy,des);
if (xy.x > 0)
{
flood.push(DFCoord(xy.x - 1, xy.y, xy.z));
}
if (xy.x < int32_t(tx_max) - 1)
{
flood.push(DFCoord(xy.x + 1, xy.y, xy.z));
}
if (xy.y > 0)
{
flood.push(DFCoord(xy.x, xy.y - 1, xy.z));
}
if (xy.y < int32_t(ty_max) - 1)
{
flood.push(DFCoord(xy.x, xy.y + 1, xy.z));
}
if (updown)
{
if (xy.z > 0 && LowPassable(tt))
{
flood.push(DFCoord(xy.x, xy.y, xy.z - 1));
}
if (xy.z < int32_t(z_max) && HighPassable(tt))
{
flood.push(DFCoord(xy.x, xy.y, xy.z + 1));
}
}
}
}
MCache.WriteAll();
return CR_OK;
}