Update fixveins to also handle feature stones (e.g. adamantine vein floors)

develop
Quietust 2012-01-27 11:33:51 -06:00
parent ccad6efeb8
commit 331be2c821
1 changed files with 25 additions and 23 deletions

@ -22,6 +22,19 @@ using namespace df::enums;
using df::global::world; using df::global::world;
bool setTileMaterial(int16_t &tile, const TileMaterial mat)
{
int16_t newTile = findTileType(tileShape(tile), mat, tileVariant(tile), tileSpecial(tile), tileDirection(tile));
if (newTile == -1)
return false;
if (newTile != tile)
{
tile = newTile;
return true;
}
return false;
}
DFhackCExport command_result df_fixveins (Core * c, vector <string> & parameters) DFhackCExport command_result df_fixveins (Core * c, vector <string> & parameters)
{ {
if (parameters.size()) if (parameters.size())
@ -35,8 +48,8 @@ DFhackCExport command_result df_fixveins (Core * c, vector <string> & parameters
return CR_FAILURE; return CR_FAILURE;
} }
int removed = 0; int mineral_removed = 0, feature_removed = 0;
int added = 0; int mineral_added = 0, feature_added = 0;
int num_blocks = 0, blocks_total = world->map.map_blocks.size(); int num_blocks = 0, blocks_total = world->map.map_blocks.size();
for (int i = 0; i < blocks_total; i++) for (int i = 0; i < blocks_total; i++)
@ -57,33 +70,22 @@ DFhackCExport command_result df_fixveins (Core * c, vector <string> & parameters
for (int y = 0; y < 16; y++) for (int y = 0; y < 16; y++)
{ {
int16_t oldT = block->tiletype[x][y]; int16_t oldT = block->tiletype[x][y];
int16_t newT = oldT;
TileMaterial mat = tileMaterial(oldT); TileMaterial mat = tileMaterial(oldT);
if ((mat == VEIN) && !(has_mineral[y] & (1 << x))) if ((mat == VEIN) && !(has_mineral[y] & (1 << x)))
{ mineral_removed += setTileMaterial(block->tiletype[x][y], STONE);
newT = findTileType(tileShape(oldT), STONE, tileVariant(oldT), tileSpecial(oldT), tileDirection(oldT));
if ((newT != -1) && (newT != oldT))
{
block->tiletype[x][y] = newT;
removed++;
}
}
if ((mat == STONE) && (has_mineral[y] & (1 << x))) if ((mat == STONE) && (has_mineral[y] & (1 << x)))
{ mineral_added += setTileMaterial(block->tiletype[x][y], VEIN);
newT = findTileType(tileShape(oldT), VEIN, tileVariant(oldT), tileSpecial(oldT), tileDirection(oldT)); if ((mat == FEATSTONE) && !(block->designation[x][y].bits.feature_local || block->designation[x][y].bits.feature_global))
if ((newT != -1) && (newT != oldT)) feature_removed += setTileMaterial(block->tiletype[x][y], STONE);
{ if ((mat == STONE) && (block->designation[x][y].bits.feature_local || block->designation[x][y].bits.feature_global))
block->tiletype[x][y] = newT; feature_added += setTileMaterial(block->tiletype[x][y], FEATSTONE);
added++;
}
}
} }
} }
} }
if (removed) if (mineral_removed || feature_removed)
c->con.print("Removed %i invalid references to mineral inclusions.\n", removed); c->con.print("Removed invalid references from %i mineral inclusion and %i map feature tiles.\n", mineral_removed, feature_removed);
if (added) if (mineral_added || feature_added)
c->con.print("Restored %i missing references to mineral inclusions.\n", added); c->con.print("Restored missing references to %i mineral inclusion and %i map feature tiles.\n", mineral_added, feature_added);
return CR_OK; return CR_OK;
} }