Petr Mrázek 2012-02-05 19:50:15 +01:00
commit 71b29b67cf
1 changed files with 33 additions and 31 deletions

@ -79,11 +79,11 @@ DFhackCExport command_result mapexport (Core * c, std::vector <std::string> & pa
return CR_FAILURE; return CR_FAILURE;
} }
if (parameters.size() < filenameParameter) if (parameters.size() < filenameParameter)
{ {
c->con.printerr("Please supply a filename.\n"); c->con.printerr("Please supply a filename.\n");
c->Resume(); c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
std::string filename = parameters[filenameParameter-1]; std::string filename = parameters[filenameParameter-1];
@ -93,9 +93,9 @@ DFhackCExport command_result mapexport (Core * c, std::vector <std::string> & pa
std::ofstream output_file(filename, std::ios::out | std::ios::trunc | std::ios::binary); std::ofstream output_file(filename, std::ios::out | std::ios::trunc | std::ios::binary);
if (!output_file.is_open()) if (!output_file.is_open())
{ {
c->con.printerr("Couldn't open the output file.\n"); c->con.printerr("Couldn't open the output file.\n");
c->Resume(); c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
ZeroCopyOutputStream *raw_output = new OstreamOutputStream(&output_file); ZeroCopyOutputStream *raw_output = new OstreamOutputStream(&output_file);
GzipOutputStream *zip_output = new GzipOutputStream(raw_output); GzipOutputStream *zip_output = new GzipOutputStream(raw_output);
@ -203,44 +203,44 @@ DFhackCExport command_result mapexport (Core * c, std::vector <std::string> & pa
if (des.bits.flow_size) if (des.bits.flow_size)
{ {
prototile->set_liquid_type((dfproto::Tile::LiquidType)des.bits.liquid_type); prototile->set_liquid_type((dfproto::Tile::LiquidType)des.bits.liquid_type);
prototile->set_flow_size(des.bits.flow_size); prototile->set_flow_size(des.bits.flow_size);
} }
uint16_t type = b->TileTypeAt(coord); uint16_t type = b->TileTypeAt(coord);
const DFHack::TileRow *info = DFHack::getTileRow(type); const DFHack::TileRow *info = DFHack::getTileRow(type);
prototile->set_type((dfproto::Tile::TileType)info->shape); prototile->set_type((dfproto::Tile::TileType)info->shape);
prototile->set_material_type((dfproto::Tile::MaterialType)info->material); prototile->set_material_type((dfproto::Tile::MaterialType)info->material);
df::coord map_pos = df::coord(b_x*16+x,b_y*16+y,z); df::coord map_pos = df::coord(b_x*16+x,b_y*16+y,z);
switch (info->material) switch (info->material)
{ {
case DFHack::SOIL: case DFHack::SOIL:
case DFHack::STONE: case DFHack::STONE:
prototile->set_material_index(0); prototile->set_material_index(0);
prototile->set_material(b->baseMaterialAt(coord)); prototile->set_material(b->baseMaterialAt(coord));
break; break;
case DFHack::VEIN: case DFHack::VEIN:
prototile->set_material_index(0); prototile->set_material_index(0);
prototile->set_material(b->veinMaterialAt(coord)); prototile->set_material(b->veinMaterialAt(coord));
break; break;
case DFHack::FEATSTONE: case DFHack::FEATSTONE:
if (blockFeatureLocal.type != -1 && des.bits.feature_local) if (blockFeatureLocal.type != -1 && des.bits.feature_local)
{ {
if (blockFeatureLocal.type == df::feature_type::deep_special_tube if (blockFeatureLocal.type == df::feature_type::deep_special_tube
&& blockFeatureLocal.main_material == 0) // stone && blockFeatureLocal.main_material == 0) // stone
{ {
prototile->set_material_index(0); prototile->set_material_index(0);
prototile->set_material(blockFeatureLocal.sub_material); prototile->set_material(blockFeatureLocal.sub_material);
} }
if (blockFeatureGlobal.type != -1 && des.bits.feature_global if (blockFeatureGlobal.type != -1 && des.bits.feature_global
&& blockFeatureGlobal.type == df::feature_type::feature_underworld_from_layer && blockFeatureGlobal.type == df::feature_type::feature_underworld_from_layer
&& blockFeatureGlobal.main_material == 0) // stone && blockFeatureGlobal.main_material == 0) // stone
{ {
prototile->set_material_index(0); prototile->set_material_index(0);
prototile->set_material(blockFeatureGlobal.sub_material); prototile->set_material(blockFeatureGlobal.sub_material);
} }
} }
break; break;
case DFHack::CONSTRUCTED: case DFHack::CONSTRUCTED:
@ -250,7 +250,7 @@ DFhackCExport command_result mapexport (Core * c, std::vector <std::string> & pa
prototile->set_material(constructionMaterials[map_pos].second); prototile->set_material(constructionMaterials[map_pos].second);
} }
break; break;
} }
} }
} }
@ -265,14 +265,16 @@ DFhackCExport command_result mapexport (Core * c, std::vector <std::string> & pa
loc = loc % 16; loc = loc % 16;
if (showHidden || !b->DesignationAt(loc).bits.hidden) if (showHidden || !b->DesignationAt(loc).bits.hidden)
{ {
protoplant->set_x(loc.x);
protoplant->set_y(loc.y);
protoplant->set_is_shrub(plant.flags.bits.is_shrub); protoplant->set_is_shrub(plant.flags.bits.is_shrub);
protoplant->set_material(plant.material); protoplant->set_material(plant.material);
} }
} }
} }
coded_output->WriteVarint32(protoblock.ByteSize()); coded_output->WriteVarint32(protoblock.ByteSize());
protoblock.SerializeToCodedStream(coded_output); protoblock.SerializeToCodedStream(coded_output);
} // block x } // block x
// Clean uneeded memory // Clean uneeded memory
map.trash(); map.trash();
@ -280,7 +282,7 @@ DFhackCExport command_result mapexport (Core * c, std::vector <std::string> & pa
} // z } // z
delete coded_output; delete coded_output;
delete zip_output; delete zip_output;
delete raw_output; delete raw_output;
mats->Finish(); mats->Finish();