diff options
| author | Mike Stewart | 2012-02-04 13:05:41 -0800 |
|---|---|---|
| committer | Mike Stewart | 2012-02-04 13:05:41 -0800 |
| commit | e5b2c7812291bd59ac0ffefa70a14aaa2027d473 (patch) | |
| tree | ec7b22523bb3ff52d3bba06b77107f2d01f1e7e6 /plugins/mapexport | |
| parent | 4b3a2bfe0577715bf1561c92941e02344b72bbd3 (diff) | |
| download | dfhack-e5b2c7812291bd59ac0ffefa70a14aaa2027d473.tar.gz dfhack-e5b2c7812291bd59ac0ffefa70a14aaa2027d473.tar.bz2 dfhack-e5b2c7812291bd59ac0ffefa70a14aaa2027d473.tar.xz | |
Added plant and material export to mapexport, and made constructions have the proper material.
Diffstat (limited to 'plugins/mapexport')
| -rw-r--r-- | plugins/mapexport/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | plugins/mapexport/mapexport.cpp | 96 | ||||
| -rw-r--r-- | plugins/mapexport/proto/Block.proto | 2 | ||||
| -rw-r--r-- | plugins/mapexport/proto/Map.proto | 4 | ||||
| -rw-r--r-- | plugins/mapexport/proto/Material.proto | 8 | ||||
| -rw-r--r-- | plugins/mapexport/proto/Plant.proto | 10 | ||||
| -rw-r--r-- | plugins/mapexport/proto/Tile.proto | 7 |
7 files changed, 119 insertions, 10 deletions
diff --git a/plugins/mapexport/CMakeLists.txt b/plugins/mapexport/CMakeLists.txt index b738c1c4..d3ff2585 100644 --- a/plugins/mapexport/CMakeLists.txt +++ b/plugins/mapexport/CMakeLists.txt @@ -27,7 +27,9 @@ mapexport.cpp SET(PROJECT_PROTOS ${CMAKE_CURRENT_SOURCE_DIR}/proto/Tile.proto +${CMAKE_CURRENT_SOURCE_DIR}/proto/Plant.proto ${CMAKE_CURRENT_SOURCE_DIR}/proto/Block.proto +${CMAKE_CURRENT_SOURCE_DIR}/proto/Material.proto ${CMAKE_CURRENT_SOURCE_DIR}/proto/Map.proto ) diff --git a/plugins/mapexport/mapexport.cpp b/plugins/mapexport/mapexport.cpp index 57e697f3..23b5695c 100644 --- a/plugins/mapexport/mapexport.cpp +++ b/plugins/mapexport/mapexport.cpp @@ -13,11 +13,15 @@ using namespace google::protobuf::io; #include "DataDefs.h" #include "df/world.h" +#include "modules/Constructions.h" #include "proto/Map.pb.h" #include "proto/Block.pb.h" -using namespace DFHack::Simple; +using namespace DFHack; +using df::global::world; + +typedef std::vector<df::plant *> PlantList; DFhackCExport command_result mapexport (Core * c, std::vector <std::string> & parameters); @@ -42,18 +46,29 @@ DFhackCExport command_result plugin_shutdown ( Core * c ) DFhackCExport command_result mapexport (Core * c, std::vector <std::string> & parameters) { + bool showHidden = false; + + int filenameParameter = 1; + for(size_t i = 0; i < parameters.size();i++) { if(parameters[i] == "help" || parameters[i] == "?") { c->con.print("Exports the currently visible map to a file.\n" - "Usage: mapexport <filename>\n" + "Usage: mapexport [options] <filename>\n" + "Example: mapexport all embark.dfmap\n" + "Options:\n" + " all - Export the entire map, not just what's revealed." ); return CR_OK; } + if (parameters[i] == "all") + { + showHidden = true; + filenameParameter++; + } } - bool showHidden = true; uint32_t x_max=0, y_max=0, z_max=0; c->Suspend(); @@ -64,14 +79,16 @@ DFhackCExport command_result mapexport (Core * c, std::vector <std::string> & pa return CR_FAILURE; } - if (parameters.size() < 1) + if (parameters.size() < filenameParameter) { c->con.printerr("Please supply a filename.\n"); c->Resume(); return CR_FAILURE; } - std::string filename = parameters[0]; + std::string filename = parameters[filenameParameter-1]; + if (filename.rfind(".dfmap") == std::string::npos) filename += ".dfmap"; + c->con << "Writing to " << filename << "..." << std::endl; std::ofstream output_file(filename, std::ios::out | std::ios::trunc | std::ios::binary); if (!output_file.is_open()) @@ -90,23 +107,54 @@ DFhackCExport command_result mapexport (Core * c, std::vector <std::string> & pa MapExtras::MapCache map; DFHack::Materials *mats = c->getMaterials(); + c->con << "Writing map info..." << std::endl; + dfproto::Map protomap; protomap.set_x_size(x_max); protomap.set_y_size(y_max); protomap.set_z_size(z_max); + c->con << "Writing material dictionary..." << std::endl; + + for (size_t i = 0; i < world->raws.inorganics.size(); i++) + { + dfproto::Material *protomaterial = protomap.add_inorganic_material(); + protomaterial->set_type(i); + protomaterial->set_name(world->raws.inorganics[i]->id); + } + + for (size_t i = 0; i < world->raws.plants.all.size(); i++) + { + dfproto::Material *protomaterial = protomap.add_organic_material(); + protomaterial->set_type(i); + protomaterial->set_name(world->raws.plants.all[i]->id); + } + + std::map<df::coord,std::pair<uint32_t,uint16_t> > constructionMaterials; + if (Constructions::isValid()) + { + for (uint32_t i = 0; i < Constructions::getCount(); i++) + { + df::construction *construction = Constructions::getConstruction(i); + constructionMaterials[construction->pos] = std::make_pair(construction->mat_index, construction->mat_type); + } + } + coded_output->WriteVarint32(protomap.ByteSize()); protomap.SerializeToCodedStream(coded_output); - + DFHack::t_feature blockFeatureGlobal; DFHack::t_feature blockFeatureLocal; + c->con.print("Writing map block information"); + for(uint32_t z = 0; z < z_max; z++) { for(uint32_t b_y = 0; b_y < y_max; b_y++) { for(uint32_t b_x = 0; b_x < x_max; b_x++) { + if (b_x == 0 && b_y == 0 && z % 10 == 0) c->con.print("."); // Get the map block df::coord2d blockCoord(b_x, b_y); MapExtras::Block *b = map.BlockAt(DFHack::DFCoord(b_x, b_y, z)); @@ -163,13 +211,18 @@ DFhackCExport command_result mapexport (Core * c, std::vector <std::string> & pa prototile->set_type((dfproto::Tile::TileType)info->shape); prototile->set_material_type((dfproto::Tile::MaterialType)info->material); + + df::coord map_pos = df::coord(b_x*16+x,b_y*16+y,z); + switch (info->material) { case DFHack::SOIL: case DFHack::STONE: + prototile->set_material_index(0); prototile->set_material(b->baseMaterialAt(coord)); break; case DFHack::VEIN: + prototile->set_material_index(0); prototile->set_material(b->veinMaterialAt(coord)); break; case DFHack::FEATSTONE: @@ -178,18 +231,46 @@ DFhackCExport command_result mapexport (Core * c, std::vector <std::string> & pa if (blockFeatureLocal.type == df::feature_type::deep_special_tube && blockFeatureLocal.main_material == 0) // stone { + prototile->set_material_index(0); prototile->set_material(blockFeatureLocal.sub_material); } if (blockFeatureGlobal.type != -1 && des.bits.feature_global && blockFeatureGlobal.type == df::feature_type::feature_underworld_from_layer && blockFeatureGlobal.main_material == 0) // stone { + prototile->set_material_index(0); prototile->set_material(blockFeatureGlobal.sub_material); } } + break; + case DFHack::CONSTRUCTED: + if (constructionMaterials.find(map_pos) != constructionMaterials.end()) + { + prototile->set_material_index(constructionMaterials[map_pos].first); + prototile->set_material(constructionMaterials[map_pos].second); + } + break; } } } + + PlantList *plants; + if (Maps::ReadVegetation(b_x, b_y, z, plants)) + { + for (PlantList::const_iterator it = plants->begin(); it != plants->end(); it++) + { + dfproto::Plant *protoplant = protoblock.add_plant(); + const df::plant & plant = *(*it); + df::coord2d loc(plant.pos.x, plant.pos.y); + loc = loc % 16; + if (showHidden || !b->DesignationAt(loc).bits.hidden) + { + protoplant->set_is_shrub(plant.flags.bits.is_shrub); + protoplant->set_material(plant.material); + } + } + } + coded_output->WriteVarint32(protoblock.ByteSize()); protoblock.SerializeToCodedStream(coded_output); } // block x @@ -202,7 +283,8 @@ DFhackCExport command_result mapexport (Core * c, std::vector <std::string> & pa delete zip_output; delete raw_output; - c->con.print("Map succesfully exported.\n"); + mats->Finish(); + c->con.print("\nMap succesfully exported!\n"); c->Resume(); return CR_OK; } diff --git a/plugins/mapexport/proto/Block.proto b/plugins/mapexport/proto/Block.proto index cba809b5..1540ce52 100644 --- a/plugins/mapexport/proto/Block.proto +++ b/plugins/mapexport/proto/Block.proto @@ -2,6 +2,7 @@ package dfproto; option optimize_for = LITE_RUNTIME; import "Tile.proto"; +import "Plant.proto"; message Block { @@ -9,4 +10,5 @@ message Block required uint32 y = 2; required uint32 z = 3; repeated Tile tile = 4; + repeated Plant plant = 5; }
\ No newline at end of file diff --git a/plugins/mapexport/proto/Map.proto b/plugins/mapexport/proto/Map.proto index e73dab5c..bf3e7bd2 100644 --- a/plugins/mapexport/proto/Map.proto +++ b/plugins/mapexport/proto/Map.proto @@ -1,9 +1,13 @@ package dfproto; option optimize_for = LITE_RUNTIME; +import "Material.proto"; + message Map { required uint32 x_size = 1; required uint32 y_size = 2; required uint32 z_size = 3; + repeated Material inorganic_material = 4; + repeated Material organic_material = 5; }
\ No newline at end of file diff --git a/plugins/mapexport/proto/Material.proto b/plugins/mapexport/proto/Material.proto new file mode 100644 index 00000000..af8ebcd4 --- /dev/null +++ b/plugins/mapexport/proto/Material.proto @@ -0,0 +1,8 @@ +package dfproto; +option optimize_for = LITE_RUNTIME; + +message Material +{ + required uint32 type = 1; + required string name = 2; +}
\ No newline at end of file diff --git a/plugins/mapexport/proto/Plant.proto b/plugins/mapexport/proto/Plant.proto new file mode 100644 index 00000000..74500d17 --- /dev/null +++ b/plugins/mapexport/proto/Plant.proto @@ -0,0 +1,10 @@ +package dfproto; +option optimize_for = LITE_RUNTIME; + +message Plant +{ + required uint32 x = 1; + required uint32 y = 2; + required bool is_shrub = 3; + optional uint32 material = 4; +}
\ No newline at end of file diff --git a/plugins/mapexport/proto/Tile.proto b/plugins/mapexport/proto/Tile.proto index 082896c2..51ffcc0e 100644 --- a/plugins/mapexport/proto/Tile.proto +++ b/plugins/mapexport/proto/Tile.proto @@ -60,7 +60,8 @@ message Tile required uint32 y = 2; required TileType type = 3; optional MaterialType material_type = 4; - optional uint32 material = 5; - optional LiquidType liquid_type = 6; - optional uint32 flow_size = 7; + optional uint32 material_index = 5; + optional uint32 material = 6; + optional LiquidType liquid_type = 7; + optional uint32 flow_size = 8; } |
