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

Function GetPlantList

plugins/remotefortressreader/remotefortressreader.cpp:1585–1633  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1583}
1584
1585static command_result GetPlantList(color_ostream &stream, const BlockRequest *in, PlantList *out)
1586{
1587 int min_x = in->min_x() / 3;
1588 int min_y = in->min_y() / 3;
1589 int min_z = in->min_z();
1590 int max_x = in->max_x() / 3;
1591 int max_y = in->max_y() / 3;
1592 int max_z = in->max_z();
1593
1594#if DF_VERSION_INT < 40001
1595 //plants are gotten differently here
1596#else
1597 for (int xx = min_x; xx < max_x; xx++)
1598 for (int yy = min_y; yy < max_y; yy++)
1599 {
1600 if (xx < 0 || yy < 0 || xx >= world->map.x_count_block || yy >= world->map.y_count_block)
1601 continue;
1602 df::map_block_column * column = world->map.column_index[xx][yy];
1603 for (size_t i = 0; i < column->plants.size(); i++)
1604 {
1605 df::plant * plant = column->plants[i];
1606 if (!plant->tree_info)
1607 {
1608 if (plant->pos.z < min_z || plant->pos.z >= max_z)
1609 continue;
1610 if (plant->pos.x < in->min_x() * 16 || plant->pos.x >= in->max_x() * 16)
1611 continue;
1612 if (plant->pos.y < in->min_y() * 16 || plant->pos.y >= in->max_y() * 16)
1613 continue;
1614 }
1615 else
1616 {
1617 if (plant->pos.z - plant->tree_info->roots_depth < min_z || plant->pos.z + plant->tree_info->body_height > max_z)
1618 continue;
1619 if (plant->pos.x - plant->tree_info->dim_x / 2 < in->min_x() * 16 || plant->pos.x + plant->tree_info->dim_x / 2 >= in->max_x() * 16)
1620 continue;
1621 if (plant->pos.y - plant->tree_info->dim_y / 2 < in->min_y() * 16 || plant->pos.y + plant->tree_info->dim_y / 2 >= in->max_y() * 16)
1622 continue;
1623 }
1624 RemoteFortressReader::PlantDef * out_plant = out->add_plant_list();
1625 out_plant->set_index(plant->material);
1626 out_plant->set_pos_x(plant->pos.x);
1627 out_plant->set_pos_y(plant->pos.y);
1628 out_plant->set_pos_z(plant->pos.z);
1629 }
1630 }
1631#endif
1632 return CR_OK;
1633}
1634
1635static command_result GetUnitList(color_ostream &stream, const EmptyMessage *in, UnitList *out)
1636{

Callers

nothing calls this directly

Calls 3

min_zMethod · 0.80
max_zMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected