| 677 | } |
| 678 | |
| 679 | void MapExtras::Block::WriteVeins(TileInfo *tiles, BasematInfo *bmats) |
| 680 | { |
| 681 | // Classify modified tiles into distinct buckets |
| 682 | typedef std::pair<int, df::inclusion_type> t_vein_key; |
| 683 | std::map<t_vein_key, df::tile_bitmask> added; |
| 684 | std::set<t_vein_key> discovered; |
| 685 | |
| 686 | for (int y = 0; y < 16; y++) |
| 687 | { |
| 688 | if (!bmats->vein_dirty[y]) |
| 689 | continue; |
| 690 | |
| 691 | for (int x = 0; x < 16; x++) |
| 692 | { |
| 693 | using namespace df::enums::tiletype_material; |
| 694 | |
| 695 | if (!bmats->vein_dirty.getassignment(x,y)) |
| 696 | continue; |
| 697 | |
| 698 | int matidx = bmats->veinmat[x][y]; |
| 699 | if (matidx >= 0) |
| 700 | { |
| 701 | t_vein_key key(matidx, (df::inclusion_type)bmats->veintype[x][y]); |
| 702 | |
| 703 | added[key].setassignment(x,y,true); |
| 704 | if (!designation[x][y].bits.hidden) |
| 705 | discovered.insert(key); |
| 706 | } |
| 707 | } |
| 708 | } |
| 709 | |
| 710 | // Adjust existing veins |
| 711 | for (int i = block->block_events.size()-1; i >= 0; i--) |
| 712 | { |
| 713 | auto event = block->block_events[i]; |
| 714 | auto vein = strict_virtual_cast<df::block_square_event_mineralst>(event); |
| 715 | if (!vein) |
| 716 | continue; |
| 717 | |
| 718 | // First clear all dirty tiles |
| 719 | vein->tile_bitmask -= bmats->vein_dirty; |
| 720 | |
| 721 | // Then add new if there are any matching ones |
| 722 | t_vein_key key(vein->inorganic_mat, BlockInfo::getVeinType(vein->flags)); |
| 723 | |
| 724 | if (added.count(key)) |
| 725 | { |
| 726 | vein->tile_bitmask |= added[key]; |
| 727 | if (discovered.count(key)) |
| 728 | vein->flags.bits.discovered = true; |
| 729 | |
| 730 | added.erase(key); |
| 731 | discovered.erase(key); |
| 732 | } |
| 733 | |
| 734 | // Delete if became empty |
| 735 | if (!vein->tile_bitmask.has_assignments()) |
| 736 | { |