MCPcopy Create free account
hub / github.com/DFHack/dfhack / GetBlockList

Function GetBlockList

plugins/remotefortressreader/remotefortressreader.cpp:1377–1562  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1375}
1376
1377static command_result GetBlockList(color_ostream &stream, const BlockRequest *in, BlockList *out)
1378{
1379 int x, y, z;
1380 DFHack::Maps::getPosition(x, y, z);
1381 out->set_map_x(x);
1382 out->set_map_y(y);
1383 MapExtras::MapCache MC;
1384 int center_x = (in->min_x() + in->max_x()) / 2;
1385 int center_y = (in->min_y() + in->max_y()) / 2;
1386
1387 int NUMBER_OF_POINTS = ((in->max_x() - center_x + 1) * 2) * ((in->max_y() - center_y + 1) * 2);
1388 int blocks_needed;
1389 if (in->has_blocks_needed())
1390 blocks_needed = in->blocks_needed();
1391 else
1392 blocks_needed = NUMBER_OF_POINTS * (in->max_z() - in->min_z());
1393 int blocks_sent = 0;
1394 int min_x = in->min_x();
1395 int min_y = in->min_y();
1396 int max_x = in->max_x();
1397 int max_y = in->max_y();
1398 int min_z = in->min_z();
1399 int max_z = in->max_z();
1400 bool forceReload = in->force_reload();
1401 bool firstBlock = true; //Always send all the buildings needed on the first block, and none on the rest.
1402 //stream.print("Got request for blocks from (%d, %d, %d) to (%d, %d, %d).\n", in->min_x(), in->min_y(), in->min_z(), in->max_x(), in->max_y(), in->max_z());
1403 for (int zz = max_z - 1; zz >= min_z; zz--)
1404 {
1405 // (di, dj) is a vector - direction in which we move right now
1406 int di = 1;
1407 int dj = 0;
1408 // length of current segment
1409 int segment_length = 1;
1410 // current position (i, j) and how much of current segment we passed
1411 int i = center_x;
1412 int j = center_y;
1413 int segment_passed = 0;
1414 for (int k = 0; k < NUMBER_OF_POINTS; ++k)
1415 {
1416 if (blocks_sent >= blocks_needed)
1417 break;
1418 if (!(i < min_x || i >= max_x || j < min_y || j >= max_y))
1419 {
1420 DFCoord pos = DFCoord(i, j, zz);
1421 df::map_block * block = DFHack::Maps::getBlock(pos);
1422 if (block != NULL)
1423 {
1424 bool nonAir = false;
1425 for (int xxx = 0; xxx < 16; xxx++)
1426 for (int yyy = 0; yyy < 16; yyy++)
1427 {
1428 if ((DFHack::tileShapeBasic(DFHack::tileShape(block->tiletype[xxx][yyy])) != df::tiletype_shape_basic::None &&
1429 DFHack::tileShapeBasic(DFHack::tileShape(block->tiletype[xxx][yyy])) != df::tiletype_shape_basic::Open)
1430 || block->designation[xxx][yyy].bits.flow_size > 0
1431 || block->occupancy[xxx][yyy].bits.building > 0)
1432 {
1433 nonAir = true;
1434 goto ItsAir;

Callers

nothing calls this directly

Calls 15

getBlockFunction · 0.85
tileShapeBasicFunction · 0.85
tileShapeFunction · 0.85
IsTiletypeChangedFunction · 0.85
IsDesignationChangedFunction · 0.85
IsspatterChangedFunction · 0.85
CopyBlockFunction · 0.85
CopyDesignationFunction · 0.85
CopyBuildingsFunction · 0.85
CopyProjectilesFunction · 0.85
CopyspattersFunction · 0.85
CopyItemsFunction · 0.85

Tested by

no test coverage detected