| 40 | } |
| 41 | |
| 42 | command_result df_fixveins (color_ostream &out, vector <string> & parameters) |
| 43 | { |
| 44 | if (parameters.size()) |
| 45 | return CR_WRONG_USAGE; |
| 46 | |
| 47 | if (!Maps::IsValid()) |
| 48 | { |
| 49 | out.printerr("Map is not available!\n"); |
| 50 | return CR_FAILURE; |
| 51 | } |
| 52 | |
| 53 | int mineral_removed = 0, feature_removed = 0; |
| 54 | int mineral_added = 0, feature_added = 0; |
| 55 | |
| 56 | int blocks_total = world->map.map_blocks.size(); |
| 57 | for (int i = 0; i < blocks_total; i++) |
| 58 | { |
| 59 | df::map_block *block = world->map.map_blocks[i]; |
| 60 | uint16_t has_mineral[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; |
| 61 | for (size_t j = 0; j < block->block_events.size(); j++) |
| 62 | { |
| 63 | df::block_square_event *evt = block->block_events[j]; |
| 64 | if (evt->getType() != block_square_event_type::mineral) |
| 65 | continue; |
| 66 | df::block_square_event_mineralst *mineral = (df::block_square_event_mineralst *)evt; |
| 67 | for (int k = 0; k < 16; k++) |
| 68 | has_mineral[k] |= mineral->tile_bitmask[k]; |
| 69 | } |
| 70 | t_feature local, global; |
| 71 | Maps::ReadFeatures(block, &local, &global); |
| 72 | for (int x = 0; x < 16; x++) |
| 73 | { |
| 74 | for (int y = 0; y < 16; y++) |
| 75 | { |
| 76 | bool has_feature = ((block->designation[x][y].bits.feature_global) && (global.main_material != -1) && (global.sub_material != -1)) || |
| 77 | ((block->designation[x][y].bits.feature_local) && (local.main_material != -1) && (local.sub_material != -1)); |
| 78 | bool has_vein = has_mineral[y] & (1 << x); |
| 79 | if (has_feature) |
| 80 | has_vein = false; |
| 81 | df::tiletype oldT = block->tiletype[x][y]; |
| 82 | df::tiletype_material mat = tileMaterial(oldT); |
| 83 | if ((mat == tiletype_material::MINERAL) && !has_vein) |
| 84 | mineral_removed += setTileMaterial(block->tiletype[x][y], tiletype_material::STONE); |
| 85 | if ((mat == tiletype_material::STONE) && has_vein) |
| 86 | mineral_added += setTileMaterial(block->tiletype[x][y], tiletype_material::MINERAL); |
| 87 | if ((mat == tiletype_material::FEATURE) && !has_feature) |
| 88 | feature_removed += setTileMaterial(block->tiletype[x][y], tiletype_material::STONE); |
| 89 | if ((mat == tiletype_material::STONE) && has_feature) |
| 90 | feature_added += setTileMaterial(block->tiletype[x][y], tiletype_material::FEATURE); |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | if (mineral_removed || feature_removed) |
| 95 | out.print("Removed invalid references from {} mineral inclusion and {} map feature tiles.\n", mineral_removed, feature_removed); |
| 96 | if (mineral_added || feature_added) |
| 97 | out.print("Restored missing references to {} mineral inclusion and {} map feature tiles.\n", mineral_added, feature_added); |
| 98 | return CR_OK; |
| 99 | } |
nothing calls this directly
no test coverage detected