| 811 | } |
| 812 | |
| 813 | void MapExtras::BlockInfo::prepare(Block *mblock) |
| 814 | { |
| 815 | this->mblock = mblock; |
| 816 | |
| 817 | block = mblock->getRaw(); |
| 818 | parent = mblock->getParent(); |
| 819 | column = Maps::getBlockColumn((block->map_pos.x / 48) * 3, (block->map_pos.y / 48) * 3); |
| 820 | |
| 821 | SquashVeins(block, veinmats, veintype); |
| 822 | SquashGrass(block, grass); |
| 823 | |
| 824 | for (size_t i = 0; i < column->plants.size(); i++) |
| 825 | { |
| 826 | auto pp = column->plants[i]; |
| 827 | // A plant without tree_info is single tile |
| 828 | // TODO: verify that x any y lie inside the block. |
| 829 | if (!pp->tree_info) |
| 830 | { |
| 831 | if (pp->pos.z == block->map_pos.z) |
| 832 | plants[pp->pos] = pp; |
| 833 | continue; |
| 834 | } |
| 835 | |
| 836 | // tree_info contains vertical slices of the tree. This ensures there's a slice for our Z-level. |
| 837 | df::plant_tree_info * info = pp->tree_info; |
| 838 | if (!((pp->pos.z - info->roots_depth <= block->map_pos.z) && ((pp->pos.z + info->body_height) > block->map_pos.z))) |
| 839 | continue; |
| 840 | |
| 841 | // Parse through a single horizontal slice of the tree. |
| 842 | for (int xx = 0; xx < info->dim_x; xx++) |
| 843 | for (int yy = 0; yy < info->dim_y; yy++) |
| 844 | { |
| 845 | // Any non-zero value here other than blocked means there's some sort of branch here. |
| 846 | // If the block is at or above the plant's base level, we use the body array |
| 847 | // otherwise we use the roots. |
| 848 | // TODO: verify that the tree bounds intersect the block. |
| 849 | bool has_tree_tile = false; |
| 850 | int z_diff = block->map_pos.z - pp->pos.z; |
| 851 | if (z_diff >= 0) { |
| 852 | df::plant_tree_tile tile = info->body[z_diff][xx + (yy * info->dim_x)]; |
| 853 | has_tree_tile = tile.whole && !(tile.bits.blocked); |
| 854 | } else { |
| 855 | df::plant_root_tile tile = info->roots[-1 - z_diff][xx + (yy * info->dim_x)]; |
| 856 | has_tree_tile = tile.whole && !(tile.bits.blocked); |
| 857 | } |
| 858 | if (has_tree_tile) { |
| 859 | df::coord pos = pp->pos; |
| 860 | pos.x = pos.x - (info->dim_x / 2) + xx; |
| 861 | pos.y = pos.y - (info->dim_y / 2) + yy; |
| 862 | pos.z = block->map_pos.z; |
| 863 | plants[pos] = pp; |
| 864 | } |
| 865 | } |
| 866 | } |
| 867 | |
| 868 | global_feature = Maps::getGlobalInitFeature(block->global_feature); |
| 869 | local_feature = Maps::getLocalInitFeature(block->region_pos, block->local_feature); |
| 870 | } |