From 6e9de245c253fee93d0250b3afd1e90d8177f4ee Mon Sep 17 00:00:00 2001 From: Japa Date: Wed, 27 Mar 2013 01:24:13 +0530 Subject: [PATCH 1/9] Started work on isoworld remote --- plugins/CMakeLists.txt | 1 + plugins/isoworldremote.cpp | 100 +++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 plugins/isoworldremote.cpp diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 65a550018..e9b537335 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -137,6 +137,7 @@ if (BUILD_SUPPORTED) DFHACK_PLUGIN(trueTransformation trueTransformation.cpp) DFHACK_PLUGIN(infiniteSky infiniteSky.cpp) DFHACK_PLUGIN(createitem createitem.cpp) + DFHACK_PLUGIN(isoworldremote isoworldremote.cpp) endif() diff --git a/plugins/isoworldremote.cpp b/plugins/isoworldremote.cpp new file mode 100644 index 000000000..1dfc9bfab --- /dev/null +++ b/plugins/isoworldremote.cpp @@ -0,0 +1,100 @@ +// This is a generic plugin that does nothing useful apart from acting as an example... of a plugin that does nothing :D + +// some headers required for a plugin. Nothing special, just the basics. +#include "Core.h" +#include +#include +#include + +// DF data structure definition headers +#include "DataDefs.h" +//#include "df/world.h" + +using namespace DFHack; +using namespace df::enums; + + +// Here go all the command declarations... +// mostly to allow having the mandatory stuff on top of the file and commands on the bottom +command_result isoWorldRemote (color_ostream &out, std::vector & parameters); + +// A plugin must be able to return its name and version. +// The name string provided must correspond to the filename - skeleton.plug.so or skeleton.plug.dll in this case +DFHACK_PLUGIN("isoworldremote"); + +// Mandatory init function. If you have some global state, create it here. +DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) +{ + // Fill the command list with your commands. + commands.push_back(PluginCommand( + "isoworldremote", "Do nothing, look pretty.", + isoWorldRemote, false, /* true means that the command can't be used from non-interactive user interface */ + // Extended help string. Used by CR_WRONG_USAGE and the help command: + " This command does nothing at all.\n" + "Example:\n" + " isoworldremote\n" + " Does nothing.\n" + )); + return CR_OK; +} + +// This is called right before the plugin library is removed from memory. +DFhackCExport command_result plugin_shutdown ( color_ostream &out ) +{ + // You *MUST* kill all threads you created before this returns. + // If everything fails, just return CR_FAILURE. Your plugin will be + // in a zombie state, but things won't crash. + return CR_OK; +} + +// Called to notify the plugin about important state changes. +// Invoked with DF suspended, and always before the matching plugin_onupdate. +// More event codes may be added in the future. +/* +DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event) +{ + switch (event) { + case SC_GAME_LOADED: + // initialize from the world just loaded + break; + case SC_GAME_UNLOADED: + // cleanup + break; + default: + break; + } + return CR_OK; +} +*/ + +// Whatever you put here will be done in each game step. Don't abuse it. +// It's optional, so you can just comment it out like this if you don't need it. +/* +DFhackCExport command_result plugin_onupdate ( color_ostream &out ) +{ + // whetever. You don't need to suspend DF execution here. + return CR_OK; +} +*/ + +// A command! It sits around and looks pretty. And it's nice and friendly. +command_result isoWorldRemote (color_ostream &out, std::vector & parameters) +{ + // It's nice to print a help message you get invalid options + // from the user instead of just acting strange. + // This can be achieved by adding the extended help string to the + // PluginCommand registration as show above, and then returning + // CR_WRONG_USAGE from the function. The same string will also + // be used by 'help your-command'. + if (!parameters.empty()) + return CR_WRONG_USAGE; + // Commands are called from threads other than the DF one. + // Suspend this thread until DF has time for us. If you + // use CoreSuspender, it'll automatically resume DF when + // execution leaves the current scope. + CoreSuspender suspend; + // Actually do something here. Yay. + out.print("Hello! I do nothing, remember?\n"); + // Give control back to DF. + return CR_OK; +} From 14369d18dc0321558d1d03a4730370b3fd46d14d Mon Sep 17 00:00:00 2001 From: Japa Date: Sat, 30 Mar 2013 12:38:42 +0530 Subject: [PATCH 2/9] Initial work on the isoworldremote plugin, which sends sections of the map to isoworld. Signed-off-by: Japa --- plugins/CMakeLists.txt | 295 +++++++++++++++-------------- plugins/isoworldremote.cpp | 239 +++++++++++++++++++++++ plugins/proto/isoworldremote.proto | 25 +++ 3 files changed, 412 insertions(+), 147 deletions(-) create mode 100644 plugins/isoworldremote.cpp create mode 100644 plugins/proto/isoworldremote.proto diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 65a550018..2d1268b0e 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -1,147 +1,148 @@ -INCLUDE(Plugins.cmake) - -# Dfusion plugin -IF(UNIX) - OPTION(BUILD_DFUSION "Build DFusion." OFF) -ELSE() - OPTION(BUILD_DFUSION "Build DFusion." ON) -ENDIF() -if(BUILD_DFUSION) - add_subdirectory (Dfusion) -endif() - -OPTION(BUILD_STONESENSE "Build stonesense (needs a checkout first)." OFF) -if(BUILD_STONESENSE) - add_subdirectory (stonesense) -endif() - -OPTION(BUILD_DEV_PLUGINS "Build developer plugins." OFF) -if(BUILD_DEV_PLUGINS) - add_subdirectory (devel) -endif() - -#It's dead :< -#OPTION(BUILD_DF2MC "Build DF2MC (needs a checkout first)." OFF) -#if(BUILD_DF2MC) -# add_subdirectory (df2mc) -#endif() - -OPTION(BUILD_MAPEXPORT "Build map exporter." ON) -if (BUILD_MAPEXPORT) - add_subdirectory (mapexport) -endif() - -OPTION(BUILD_DWARFEXPORT "Build dwarf exporter." ON) -if (BUILD_DWARFEXPORT) - add_subdirectory (dwarfexport) -endif() - -OPTION(BUILD_RUBY "Build ruby binding." ON) -if (BUILD_RUBY) - add_subdirectory (ruby) -endif() - -install(DIRECTORY lua/ - DESTINATION ${DFHACK_LUA_DESTINATION}/plugins - FILES_MATCHING PATTERN "*.lua") -install(DIRECTORY raw/ - DESTINATION ${DFHACK_DATA_DESTINATION}/raw - FILES_MATCHING PATTERN "*.txt") -install(DIRECTORY raw/ - DESTINATION ${DFHACK_DATA_DESTINATION}/raw - FILES_MATCHING PATTERN "*.diff") - -# Protobuf -FILE(GLOB PROJECT_PROTOS ${CMAKE_CURRENT_SOURCE_DIR}/proto/*.proto) - -STRING(REPLACE ".proto" ".pb.cc" PROJECT_PROTO_SRCS "${PROJECT_PROTOS}") -STRING(REPLACE ".proto" ".pb.h" PROJECT_PROTO_HDRS "${PROJECT_PROTOS}") - -ADD_CUSTOM_COMMAND( - OUTPUT ${PROJECT_PROTO_SRCS} ${PROJECT_PROTO_HDRS} - COMMAND protoc-bin -I=${dfhack_SOURCE_DIR}/library/proto/ - -I=${CMAKE_CURRENT_SOURCE_DIR}/proto/ - --cpp_out=${CMAKE_CURRENT_SOURCE_DIR}/proto/ - ${PROJECT_PROTOS} - DEPENDS protoc-bin ${PROJECT_PROTOS} -) - -SET_SOURCE_FILES_PROPERTIES( Brushes.h PROPERTIES HEADER_FILE_ONLY TRUE ) - -# Plugins -OPTION(BUILD_SUPPORTED "Build the supported plugins (reveal, probe, etc.)." ON) -if (BUILD_SUPPORTED) - DFHACK_PLUGIN(reveal reveal.cpp) - DFHACK_PLUGIN(probe probe.cpp) - # this is a plugin which helps detect cursed creatures (vampires, necromancers, werebeasts, ...) - DFHACK_PLUGIN(cursecheck cursecheck.cpp) - # automatically assign labors to dwarves! - DFHACK_PLUGIN(autolabor autolabor.cpp) - DFHACK_PLUGIN(dig dig.cpp) - DFHACK_PLUGIN(drybuckets drybuckets.cpp) - DFHACK_PLUGIN(getplants getplants.cpp) - DFHACK_PLUGIN(plants plants.cpp) - DFHACK_PLUGIN(fastdwarf fastdwarf.cpp) - DFHACK_PLUGIN(prospector prospector.cpp) - DFHACK_PLUGIN(cleaners cleaners.cpp) - DFHACK_PLUGIN(weather weather.cpp) - DFHACK_PLUGIN(colonies colonies.cpp) - DFHACK_PLUGIN(mode mode.cpp) - DFHACK_PLUGIN(liquids liquids.cpp Brushes.h LINK_LIBRARIES lua) - DFHACK_PLUGIN(tiletypes tiletypes.cpp Brushes.h) - DFHACK_PLUGIN(tubefill tubefill.cpp) - DFHACK_PLUGIN(autodump autodump.cpp) - DFHACK_PLUGIN(cleanowned cleanowned.cpp) - DFHACK_PLUGIN(deramp deramp.cpp) - DFHACK_PLUGIN(flows flows.cpp) - DFHACK_PLUGIN(filltraffic filltraffic.cpp) - DFHACK_PLUGIN(seedwatch seedwatch.cpp) - DFHACK_PLUGIN(initflags initflags.cpp) - DFHACK_PLUGIN(stockpiles stockpiles.cpp) - DFHACK_PLUGIN(rename rename.cpp LINK_LIBRARIES lua PROTOBUFS rename) - DFHACK_PLUGIN(jobutils jobutils.cpp) - DFHACK_PLUGIN(workflow workflow.cpp LINK_LIBRARIES lua) - DFHACK_PLUGIN(showmood showmood.cpp) - DFHACK_PLUGIN(fixveins fixveins.cpp) - DFHACK_PLUGIN(fixpositions fixpositions.cpp) - DFHACK_PLUGIN(follow follow.cpp) - DFHACK_PLUGIN(changevein changevein.cpp) - DFHACK_PLUGIN(changelayer changelayer.cpp) - DFHACK_PLUGIN(changeitem changeitem.cpp) - DFHACK_PLUGIN(advtools advtools.cpp) - DFHACK_PLUGIN(tweak tweak.cpp) - DFHACK_PLUGIN(feature feature.cpp) - DFHACK_PLUGIN(lair lair.cpp) - DFHACK_PLUGIN(zone zone.cpp) - DFHACK_PLUGIN(catsplosion catsplosion.cpp) - DFHACK_PLUGIN(regrass regrass.cpp) - DFHACK_PLUGIN(forceequip forceequip.cpp) - DFHACK_PLUGIN(manipulator manipulator.cpp) - DFHACK_PLUGIN(search search.cpp) - DFHACK_PLUGIN(automaterial automaterial.cpp) - # this one exports functions to lua - DFHACK_PLUGIN(burrows burrows.cpp LINK_LIBRARIES lua) - DFHACK_PLUGIN(sort sort.cpp LINK_LIBRARIES lua) - DFHACK_PLUGIN(steam-engine steam-engine.cpp) - DFHACK_PLUGIN(power-meter power-meter.cpp LINK_LIBRARIES lua) - DFHACK_PLUGIN(siege-engine siege-engine.cpp LINK_LIBRARIES lua) - DFHACK_PLUGIN(eventful eventful.cpp LINK_LIBRARIES lua) - DFHACK_PLUGIN(add-spatter add-spatter.cpp) - DFHACK_PLUGIN(fix-armory fix-armory.cpp) - # not yet. busy with other crud again... - #DFHACK_PLUGIN(versionosd versionosd.cpp) - DFHACK_PLUGIN(misery misery.cpp) - DFHACK_PLUGIN(workNow workNow.cpp) - #DFHACK_PLUGIN(dfstream dfstream.cpp LINK_LIBRARIES clsocket dfhack-tinythread) - DFHACK_PLUGIN(autoSyndrome autoSyndrome.cpp) - DFHACK_PLUGIN(trueTransformation trueTransformation.cpp) - DFHACK_PLUGIN(infiniteSky infiniteSky.cpp) - DFHACK_PLUGIN(createitem createitem.cpp) -endif() - - -# this is the skeleton plugin. If you want to make your own, make a copy and then change it -OPTION(BUILD_SKELETON "Build the skeleton plugin." OFF) -if(BUILD_SKELETON) - add_subdirectory(skeleton) -endif() +INCLUDE(Plugins.cmake) + +# Dfusion plugin +IF(UNIX) + OPTION(BUILD_DFUSION "Build DFusion." OFF) +ELSE() + OPTION(BUILD_DFUSION "Build DFusion." ON) +ENDIF() +if(BUILD_DFUSION) + add_subdirectory (Dfusion) +endif() + +OPTION(BUILD_STONESENSE "Build stonesense (needs a checkout first)." OFF) +if(BUILD_STONESENSE) + add_subdirectory (stonesense) +endif() + +OPTION(BUILD_DEV_PLUGINS "Build developer plugins." OFF) +if(BUILD_DEV_PLUGINS) + add_subdirectory (devel) +endif() + +#It's dead :< +#OPTION(BUILD_DF2MC "Build DF2MC (needs a checkout first)." OFF) +#if(BUILD_DF2MC) +# add_subdirectory (df2mc) +#endif() + +OPTION(BUILD_MAPEXPORT "Build map exporter." ON) +if (BUILD_MAPEXPORT) + add_subdirectory (mapexport) +endif() + +OPTION(BUILD_DWARFEXPORT "Build dwarf exporter." ON) +if (BUILD_DWARFEXPORT) + add_subdirectory (dwarfexport) +endif() + +OPTION(BUILD_RUBY "Build ruby binding." ON) +if (BUILD_RUBY) + add_subdirectory (ruby) +endif() + +install(DIRECTORY lua/ + DESTINATION ${DFHACK_LUA_DESTINATION}/plugins + FILES_MATCHING PATTERN "*.lua") +install(DIRECTORY raw/ + DESTINATION ${DFHACK_DATA_DESTINATION}/raw + FILES_MATCHING PATTERN "*.txt") +install(DIRECTORY raw/ + DESTINATION ${DFHACK_DATA_DESTINATION}/raw + FILES_MATCHING PATTERN "*.diff") + +# Protobuf +FILE(GLOB PROJECT_PROTOS ${CMAKE_CURRENT_SOURCE_DIR}/proto/*.proto) + +STRING(REPLACE ".proto" ".pb.cc" PROJECT_PROTO_SRCS "${PROJECT_PROTOS}") +STRING(REPLACE ".proto" ".pb.h" PROJECT_PROTO_HDRS "${PROJECT_PROTOS}") + +ADD_CUSTOM_COMMAND( + OUTPUT ${PROJECT_PROTO_SRCS} ${PROJECT_PROTO_HDRS} + COMMAND protoc-bin -I=${dfhack_SOURCE_DIR}/library/proto/ + -I=${CMAKE_CURRENT_SOURCE_DIR}/proto/ + --cpp_out=${CMAKE_CURRENT_SOURCE_DIR}/proto/ + ${PROJECT_PROTOS} + DEPENDS protoc-bin ${PROJECT_PROTOS} +) + +SET_SOURCE_FILES_PROPERTIES( Brushes.h PROPERTIES HEADER_FILE_ONLY TRUE ) + +# Plugins +OPTION(BUILD_SUPPORTED "Build the supported plugins (reveal, probe, etc.)." ON) +if (BUILD_SUPPORTED) + DFHACK_PLUGIN(reveal reveal.cpp) + DFHACK_PLUGIN(probe probe.cpp) + # this is a plugin which helps detect cursed creatures (vampires, necromancers, werebeasts, ...) + DFHACK_PLUGIN(cursecheck cursecheck.cpp) + # automatically assign labors to dwarves! + DFHACK_PLUGIN(autolabor autolabor.cpp) + DFHACK_PLUGIN(dig dig.cpp) + DFHACK_PLUGIN(drybuckets drybuckets.cpp) + DFHACK_PLUGIN(getplants getplants.cpp) + DFHACK_PLUGIN(plants plants.cpp) + DFHACK_PLUGIN(fastdwarf fastdwarf.cpp) + DFHACK_PLUGIN(prospector prospector.cpp) + DFHACK_PLUGIN(cleaners cleaners.cpp) + DFHACK_PLUGIN(weather weather.cpp) + DFHACK_PLUGIN(colonies colonies.cpp) + DFHACK_PLUGIN(mode mode.cpp) + DFHACK_PLUGIN(liquids liquids.cpp Brushes.h LINK_LIBRARIES lua) + DFHACK_PLUGIN(tiletypes tiletypes.cpp Brushes.h) + DFHACK_PLUGIN(tubefill tubefill.cpp) + DFHACK_PLUGIN(autodump autodump.cpp) + DFHACK_PLUGIN(cleanowned cleanowned.cpp) + DFHACK_PLUGIN(deramp deramp.cpp) + DFHACK_PLUGIN(flows flows.cpp) + DFHACK_PLUGIN(filltraffic filltraffic.cpp) + DFHACK_PLUGIN(seedwatch seedwatch.cpp) + DFHACK_PLUGIN(initflags initflags.cpp) + DFHACK_PLUGIN(stockpiles stockpiles.cpp) + DFHACK_PLUGIN(rename rename.cpp LINK_LIBRARIES lua PROTOBUFS rename) + DFHACK_PLUGIN(jobutils jobutils.cpp) + DFHACK_PLUGIN(workflow workflow.cpp LINK_LIBRARIES lua) + DFHACK_PLUGIN(showmood showmood.cpp) + DFHACK_PLUGIN(fixveins fixveins.cpp) + DFHACK_PLUGIN(fixpositions fixpositions.cpp) + DFHACK_PLUGIN(follow follow.cpp) + DFHACK_PLUGIN(changevein changevein.cpp) + DFHACK_PLUGIN(changelayer changelayer.cpp) + DFHACK_PLUGIN(changeitem changeitem.cpp) + DFHACK_PLUGIN(advtools advtools.cpp) + DFHACK_PLUGIN(tweak tweak.cpp) + DFHACK_PLUGIN(feature feature.cpp) + DFHACK_PLUGIN(lair lair.cpp) + DFHACK_PLUGIN(zone zone.cpp) + DFHACK_PLUGIN(catsplosion catsplosion.cpp) + DFHACK_PLUGIN(regrass regrass.cpp) + DFHACK_PLUGIN(forceequip forceequip.cpp) + DFHACK_PLUGIN(manipulator manipulator.cpp) + DFHACK_PLUGIN(search search.cpp) + DFHACK_PLUGIN(automaterial automaterial.cpp) + # this one exports functions to lua + DFHACK_PLUGIN(burrows burrows.cpp LINK_LIBRARIES lua) + DFHACK_PLUGIN(sort sort.cpp LINK_LIBRARIES lua) + DFHACK_PLUGIN(steam-engine steam-engine.cpp) + DFHACK_PLUGIN(power-meter power-meter.cpp LINK_LIBRARIES lua) + DFHACK_PLUGIN(siege-engine siege-engine.cpp LINK_LIBRARIES lua) + DFHACK_PLUGIN(eventful eventful.cpp LINK_LIBRARIES lua) + DFHACK_PLUGIN(add-spatter add-spatter.cpp) + DFHACK_PLUGIN(fix-armory fix-armory.cpp) + # not yet. busy with other crud again... + #DFHACK_PLUGIN(versionosd versionosd.cpp) + DFHACK_PLUGIN(misery misery.cpp) + DFHACK_PLUGIN(workNow workNow.cpp) + #DFHACK_PLUGIN(dfstream dfstream.cpp LINK_LIBRARIES clsocket dfhack-tinythread) + DFHACK_PLUGIN(autoSyndrome autoSyndrome.cpp) + DFHACK_PLUGIN(trueTransformation trueTransformation.cpp) + DFHACK_PLUGIN(infiniteSky infiniteSky.cpp) + DFHACK_PLUGIN(createitem createitem.cpp) + DFHACK_PLUGIN(isoworldremote isoworldremote.cpp PROTOBUFS isoworldremote) +endif() + + +# this is the skeleton plugin. If you want to make your own, make a copy and then change it +OPTION(BUILD_SKELETON "Build the skeleton plugin." OFF) +if(BUILD_SKELETON) + add_subdirectory(skeleton) +endif() diff --git a/plugins/isoworldremote.cpp b/plugins/isoworldremote.cpp new file mode 100644 index 000000000..ccdbef5a4 --- /dev/null +++ b/plugins/isoworldremote.cpp @@ -0,0 +1,239 @@ +// This is a generic plugin that does nothing useful apart from acting as an example... of a plugin that does nothing :D + +// some headers required for a plugin. Nothing special, just the basics. +#include "Core.h" +#include +#include +#include + +// DF data structure definition headers +#include "DataDefs.h" +#include "df/world.h" +#include "df/map_block.h" +#include "df/builtin_mats.h" +#include "df/tile_designation.h" + +//DFhack specific headers +#include "modules/Maps.h" +#include "modules/MapCache.h" +#include "modules/Materials.h" + +//Needed for writing the protobuff stuff to a file. +#include +#include +#include + +#include "isoworldremote.pb.h" + +using namespace DFHack; +using namespace df::enums; +using namespace isoworldremote; + + +// Here go all the command declarations... +// mostly to allow having the mandatory stuff on top of the file and commands on the bottom +command_result isoWorldRemote (color_ostream &out, std::vector & parameters); + +void gather_embark_tile_layer(int EmbX, int EmbY, int EmbZ, EmbarkTileLayer * tile, MapExtras::MapCache * MP); +bool gather_embark_tile(int EmbX, int EmbY, EmbarkTile * tile, MapExtras::MapCache * MP); + + +// A plugin must be able to return its name and version. +// The name string provided must correspond to the filename - skeleton.plug.so or skeleton.plug.dll in this case +DFHACK_PLUGIN("skeleton"); + +// Mandatory init function. If you have some global state, create it here. +DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) +{ + // Fill the command list with your commands. + commands.push_back(PluginCommand( + "isoworldremote", "Do nothing, look pretty.", + isoWorldRemote, false, /* true means that the command can't be used from non-interactive user interface */ + // Extended help string. Used by CR_WRONG_USAGE and the help command: + " This command does nothing at all.\n" + "Example:\n" + " isoworldremote\n" + " Does nothing.\n" + )); + return CR_OK; +} + +// This is called right before the plugin library is removed from memory. +DFhackCExport command_result plugin_shutdown ( color_ostream &out ) +{ + // You *MUST* kill all threads you created before this returns. + // If everything fails, just return CR_FAILURE. Your plugin will be + // in a zombie state, but things won't crash. + return CR_OK; +} + +// Called to notify the plugin about important state changes. +// Invoked with DF suspended, and always before the matching plugin_onupdate. +// More event codes may be added in the future. +/* +DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event) +{ + switch (event) { + case SC_GAME_LOADED: + // initialize from the world just loaded + break; + case SC_GAME_UNLOADED: + // cleanup + break; + default: + break; + } + return CR_OK; +} +*/ + +// Whatever you put here will be done in each game step. Don't abuse it. +// It's optional, so you can just comment it out like this if you don't need it. +/* +DFhackCExport command_result plugin_onupdate ( color_ostream &out ) +{ + // whetever. You don't need to suspend DF execution here. + return CR_OK; +} +*/ + +// A command! It sits around and looks pretty. And it's nice and friendly. +command_result isoWorldRemote (color_ostream &out, std::vector & parameters) +{ + // It's nice to print a help message you get invalid options + // from the user instead of just acting strange. + // This can be achieved by adding the extended help string to the + // PluginCommand registration as show above, and then returning + // CR_WRONG_USAGE from the function. The same string will also + // be used by 'help your-command'. + if (!parameters.empty()) + return CR_WRONG_USAGE; + // Commands are called from threads other than the DF one. + // Suspend this thread until DF has time for us. If you + // use CoreSuspender, it'll automatically resume DF when + // execution leaves the current scope. + CoreSuspender suspend; + // Actually do something here. Yay. + out.print("Doing a test...\n"); + MapExtras::MapCache MC; + EmbarkTile test_tile; + if(!gather_embark_tile(0,0, &test_tile, &MC)) + return CR_FAILURE; + //test-write the file to check it. + std::ofstream output_file("tile.p", std::ios_base::binary); + output_file << test_tile.SerializeAsString(); + output_file.close(); + + //load it again to verify. + std::ifstream input_file("tile.p", std::ios_base::binary); + std::string input_string( (std::istreambuf_iterator(input_file) ), + (std::istreambuf_iterator() ) ); + EmbarkTile verify_tile; + verify_tile.ParseFromString(input_string); + //write contents to text file. + std::ofstream debug_text("tile.txt", std::ios_base::trunc); + debug_text << "world coords:" << verify_tile.world_x()<< "," << verify_tile.world_y()<< "," << verify_tile.world_z() << std::endl; + for(int i = 0; i < verify_tile.tile_layer_size(); i++) { + debug_text << "layer: " << i << std::endl; + for(int j = 0; j < 48; j++) { + debug_text << " "; + for(int k = 0; k < 48; k++) { + debug_text << verify_tile.tile_layer(i).mat_type_table(j*48+k) << ","; + } + debug_text << " "; + for(int k = 0; k < 48; k++) { + debug_text << std::setw(3) << verify_tile.tile_layer(i).mat_subtype_table(j*48+k) << ","; + } + debug_text << std::endl; + } + debug_text << std::endl; + } + //clean everything up. + google::protobuf::ShutdownProtobufLibrary(); + // Give control back to DF. + return CR_OK; +} + +int coord_to_index_48(int x, int y) { + return y*48+x; +} + +bool gather_embark_tile(int EmbX, int EmbY, EmbarkTile * tile, MapExtras::MapCache * MP) { + DFCoord base_coord; + base_coord.x = EmbX; + base_coord.y = EmbY; + base_coord.z = 0; + MapExtras::Block * b = MP->BlockAt(base_coord); + if(!b) return 0; + df::coord map_pos = b->getRaw()->map_pos; + df::coord2d region_pos = b->getRaw()->region_pos; + tile->set_world_x(region_pos.x*16+map_pos.x/3); //fixme: verify. + tile->set_world_y(region_pos.y*16+map_pos.y/3); + tile->set_world_z(map_pos.z); + for(int z = 0; z < MP->maxZ(); z++) + { + EmbarkTileLayer * tile_layer = tile->add_tile_layer(); + gather_embark_tile_layer(EmbX, EmbY, z, tile_layer, MP); + } + return 1; +} + + +void gather_embark_tile_layer(int EmbX, int EmbY, int EmbZ, EmbarkTileLayer * tile, MapExtras::MapCache * MP) +{ + for(int i = tile->mat_type_table_size(); i < 2304; i++) { //This is needed so we have a full array to work with, otherwise the size isn't updated correctly. + tile->add_mat_type_table(AIR); + tile->add_mat_subtype_table(0); + } + for(int yy = 0; yy < 3; yy++) { + for(int xx = 0; xx < 3; xx++) { + DFCoord current_coord; + current_coord.x = EmbX+xx; + current_coord.y = EmbY+yy; + current_coord.z = EmbZ; + MapExtras::Block * b = MP->BlockAt(current_coord); + if(b && b->getRaw()) { + for(int block_y=0; block_y<16; block_y++) { + for(int block_x=0; block_x<16; block_x++) { + df::coord2d block_coord; + block_coord.x = block_x; + block_coord.y = block_y; + DFHack::t_matpair actual_mat = b->staticMaterialAt(block_coord); + df::tiletype tile_type = b->staticTiletypeAt(block_coord); + df::tile_designation designation = b->DesignationAt(block_coord); + unsigned int array_index = coord_to_index_48(xx*16+block_x, yy*16+block_y); + //make a new fake material at the given index + if(tileMaterial(tile_type) == tiletype_material::FROZEN_LIQUID) { //Ice. + tile->set_mat_type_table(array_index, BasicMaterial::LIQUID); //Ice is totally a liquid, shut up. + tile->set_mat_subtype_table(array_index, 0); + } + else if(designation.bits.flow_size) { //Contains either water or lava. + tile->set_mat_type_table(array_index, BasicMaterial::LIQUID); + if(designation.bits.liquid_type) //Magma + tile->set_mat_subtype_table(array_index, 2); + else //water + tile->set_mat_subtype_table(array_index, 1); + } + else if(tileShapeBasic(tileShape(tile_type)) != tiletype_shape_basic::Open) { + if(actual_mat.mat_type == builtin_mats::INORGANIC) { //inorganic + tile->set_mat_type_table(array_index, BasicMaterial::INORGANIC); + tile->set_mat_subtype_table(array_index, actual_mat.mat_index); + } + else if(actual_mat.mat_type >= 419) { //Wooden constructions. Different from growing plants. + tile->set_mat_type_table(array_index, BasicMaterial::WOOD); + tile->set_mat_subtype_table(array_index, actual_mat.mat_index); + } + else { //Unknown and unsupported stuff. Will just be drawn as grey. + tile->set_mat_type_table(array_index, BasicMaterial::OTHER); + tile->set_mat_subtype_table(array_index, actual_mat.mat_type); + } + } + else { + tile->set_mat_type_table(array_index, BasicMaterial::AIR); + } + } + } + } + } + } +} \ No newline at end of file diff --git a/plugins/proto/isoworldremote.proto b/plugins/proto/isoworldremote.proto new file mode 100644 index 000000000..c0803fa3a --- /dev/null +++ b/plugins/proto/isoworldremote.proto @@ -0,0 +1,25 @@ +package isoworldremote; + +//Describes a very basic material structure for the map embark +option optimize_for = LITE_RUNTIME; + +enum BasicMaterial { + AIR = 0; + OTHER = 1; + INORGANIC = 2; + LIQUID = 3; + PLANT = 4; + WOOD = 5; +}; + +message EmbarkTileLayer { + repeated BasicMaterial mat_type_table = 4 [packed=true]; + repeated int32 mat_subtype_table = 5 [packed=true]; +} + +message EmbarkTile { + required int32 world_X = 1; + required int32 world_Y = 2; + required sint32 world_Z = 3; + repeated EmbarkTileLayer tile_layer = 4; +} From a3de35c32e51597a6ae914acaf7fca20d692e9fa Mon Sep 17 00:00:00 2001 From: Japa Date: Sat, 30 Mar 2013 15:27:37 +0530 Subject: [PATCH 3/9] Added isoworld to the build list. --- plugins/CMakeLists.txt | 5 +++++ plugins/isoworld | 1 + 2 files changed, 6 insertions(+) create mode 160000 plugins/isoworld diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 8528c9028..7ff9ed6b5 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -15,6 +15,11 @@ if(BUILD_STONESENSE) add_subdirectory (stonesense) endif() +OPTION(BUILD_ISOWORLD "Build isoworld (needs a checkout first)." OFF) +if(BUILD_ISOWORLD) + add_subdirectory (isoworld) +endif() + OPTION(BUILD_DEV_PLUGINS "Build developer plugins." OFF) if(BUILD_DEV_PLUGINS) add_subdirectory (devel) diff --git a/plugins/isoworld b/plugins/isoworld new file mode 160000 index 000000000..d8d8a836b --- /dev/null +++ b/plugins/isoworld @@ -0,0 +1 @@ +Subproject commit d8d8a836bb9fb0d27861a17aa1f772a4575acffd From 39390e2749223b19227d52a2621a5c9fb72f9352 Mon Sep 17 00:00:00 2001 From: Japa Date: Sun, 31 Mar 2013 02:42:06 +0530 Subject: [PATCH 4/9] Got a working connection with Isoworld. --- plugins/isoworld | 2 +- plugins/isoworldremote.cpp | 59 ++++++++++++++++++++++++------ plugins/proto/isoworldremote.proto | 27 ++++++++++++-- 3 files changed, 72 insertions(+), 16 deletions(-) diff --git a/plugins/isoworld b/plugins/isoworld index d8d8a836b..9903472d0 160000 --- a/plugins/isoworld +++ b/plugins/isoworld @@ -1 +1 @@ -Subproject commit d8d8a836bb9fb0d27861a17aa1f772a4575acffd +Subproject commit 9903472d031bb90a6b55c7950b4a1298293a6659 diff --git a/plugins/isoworldremote.cpp b/plugins/isoworldremote.cpp index 0a62bd00f..cbf600a6d 100644 --- a/plugins/isoworldremote.cpp +++ b/plugins/isoworldremote.cpp @@ -25,6 +25,8 @@ #include "isoworldremote.pb.h" +#include "RemoteServer.h" + using namespace DFHack; using namespace df::enums; using namespace isoworldremote; @@ -34,13 +36,16 @@ using namespace isoworldremote; // mostly to allow having the mandatory stuff on top of the file and commands on the bottom command_result isoWorldRemote (color_ostream &out, std::vector & parameters); +static command_result GetEmbarkTile(color_ostream &stream, const TileRequest *in, EmbarkTile *out); +static command_result GetEmbarkInfo(color_ostream &stream, const MapRequest *in, MapReply *out); + void gather_embark_tile_layer(int EmbX, int EmbY, int EmbZ, EmbarkTileLayer * tile, MapExtras::MapCache * MP); bool gather_embark_tile(int EmbX, int EmbY, EmbarkTile * tile, MapExtras::MapCache * MP); // A plugin must be able to return its name and version. // The name string provided must correspond to the filename - skeleton.plug.so or skeleton.plug.dll in this case -DFHACK_PLUGIN("skeleton"); +DFHACK_PLUGIN("isoworldremote"); // Mandatory init function. If you have some global state, create it here. DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) @@ -58,6 +63,14 @@ DFhackCExport command_result plugin_init ( color_ostream &out, std::vector addFunction("GetEmbarkTile", GetEmbarkTile); + svc->addFunction("GetEmbarkInfo", GetEmbarkInfo); + return svc; +} + // This is called right before the plugin library is removed from memory. DFhackCExport command_result plugin_shutdown ( color_ostream &out ) { @@ -154,22 +167,44 @@ command_result isoWorldRemote (color_ostream &out, std::vector & p return CR_OK; } +static command_result GetEmbarkTile(color_ostream &stream, const TileRequest *in, EmbarkTile *out) +{ + MapExtras::MapCache MC; + gather_embark_tile(in->want_x(), in->want_y(), out, &MC); + MC.trash(); + return CR_OK; +} + +static command_result GetEmbarkInfo(color_ostream &stream, const MapRequest *in, MapReply *out) +{ + if(!in->has_save_folder()) { //probably should send the stuff anyway, but nah. + out->set_available(false); + return CR_OK; + } + if(!(in->save_folder() == df::global::world->cur_savegame.save_dir)) { //isoworld has a different map loaded, don't bother trying to load tiles for it, we don't have them. + out->set_available(false); + return CR_OK; + } + out->set_available(true); + out->set_current_year(*df::global::cur_year); + out->set_current_season(*df::global::cur_season); + out->set_region_x(df::global::world->map.region_x); + out->set_region_y(df::global::world->map.region_y); + out->set_region_size_x(df::global::world->map.x_count_block); + out->set_region_size_y(df::global::world->map.y_count_block); + return CR_OK; +} + int coord_to_index_48(int x, int y) { return y*48+x; } bool gather_embark_tile(int EmbX, int EmbY, EmbarkTile * tile, MapExtras::MapCache * MP) { - DFCoord base_coord; - base_coord.x = EmbX; - base_coord.y = EmbY; - base_coord.z = 0; - MapExtras::Block * b = MP->BlockAt(base_coord); - if(!b) return 0; - df::coord map_pos = b->getRaw()->map_pos; - df::coord2d region_pos = b->getRaw()->region_pos; - tile->set_world_x(region_pos.x*16+map_pos.x/3); //fixme: verify. - tile->set_world_y(region_pos.y*16+map_pos.y/3); - tile->set_world_z(map_pos.z); + tile->set_world_x(df::global::world->map.region_x + EmbX); //fixme: verify. + tile->set_world_y(df::global::world->map.region_y + EmbY); //fixme: verify. + tile->set_world_z(df::global::world->map.region_z); //fixme: verify. + tile->set_current_year(*df::global::cur_year); + tile->set_current_season(*df::global::cur_season); for(int z = 0; z < MP->maxZ(); z++) { EmbarkTileLayer * tile_layer = tile->add_tile_layer(); diff --git a/plugins/proto/isoworldremote.proto b/plugins/proto/isoworldremote.proto index c0803fa3a..719ffda3b 100644 --- a/plugins/proto/isoworldremote.proto +++ b/plugins/proto/isoworldremote.proto @@ -18,8 +18,29 @@ message EmbarkTileLayer { } message EmbarkTile { - required int32 world_X = 1; - required int32 world_Y = 2; - required sint32 world_Z = 3; + required int32 world_x = 1; + required int32 world_y = 2; + required sint32 world_z = 3; repeated EmbarkTileLayer tile_layer = 4; + optional int32 current_year = 5; + optional int32 current_season = 6; } + +message TileRequest { + optional int32 want_x = 1; + optional int32 want_y = 2; +} + +message MapRequest { + optional string save_folder = 1; +} + +message MapReply { + required bool available = 1; + optional int32 region_x = 2; + optional int32 region_y = 3; + optional int32 region_size_x = 4; + optional int32 region_size_y = 5; + optional int32 current_year = 6; + optional int32 current_season = 7; +} \ No newline at end of file From 4bb80d9865688862d094de63f893d35dba0cdd2a Mon Sep 17 00:00:00 2001 From: Japa Date: Sun, 31 Mar 2013 12:31:44 +0530 Subject: [PATCH 5/9] Added some sanity checks to isoworldremote.cpp Signed-off-by: Japa --- plugins/isoworldremote.cpp | 144 ++++++++++++++++++++----------------- 1 file changed, 78 insertions(+), 66 deletions(-) diff --git a/plugins/isoworldremote.cpp b/plugins/isoworldremote.cpp index cbf600a6d..6493acd92 100644 --- a/plugins/isoworldremote.cpp +++ b/plugins/isoworldremote.cpp @@ -50,16 +50,16 @@ DFHACK_PLUGIN("isoworldremote"); // Mandatory init function. If you have some global state, create it here. DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { - // Fill the command list with your commands. - commands.push_back(PluginCommand( - "isoworldremote", "Do nothing, look pretty.", - isoWorldRemote, false, /* true means that the command can't be used from non-interactive user interface */ - // Extended help string. Used by CR_WRONG_USAGE and the help command: - " This command does nothing at all.\n" - "Example:\n" - " isoworldremote\n" - " Does nothing.\n" - )); + //// Fill the command list with your commands. + //commands.push_back(PluginCommand( + // "isoworldremote", "Do nothing, look pretty.", + // isoWorldRemote, false, /* true means that the command can't be used from non-interactive user interface */ + // // Extended help string. Used by CR_WRONG_USAGE and the help command: + // " This command does nothing at all.\n" + // "Example:\n" + // " isoworldremote\n" + // " Does nothing.\n" + //)); return CR_OK; } @@ -110,62 +110,62 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out ) } */ -// A command! It sits around and looks pretty. And it's nice and friendly. -command_result isoWorldRemote (color_ostream &out, std::vector & parameters) -{ - // It's nice to print a help message you get invalid options - // from the user instead of just acting strange. - // This can be achieved by adding the extended help string to the - // PluginCommand registration as show above, and then returning - // CR_WRONG_USAGE from the function. The same string will also - // be used by 'help your-command'. - if (!parameters.empty()) - return CR_WRONG_USAGE; - // Commands are called from threads other than the DF one. - // Suspend this thread until DF has time for us. If you - // use CoreSuspender, it'll automatically resume DF when - // execution leaves the current scope. - CoreSuspender suspend; - // Actually do something here. Yay. - out.print("Doing a test...\n"); - MapExtras::MapCache MC; - EmbarkTile test_tile; - if(!gather_embark_tile(0,0, &test_tile, &MC)) - return CR_FAILURE; - //test-write the file to check it. - std::ofstream output_file("tile.p", std::ios_base::binary); - output_file << test_tile.SerializeAsString(); - output_file.close(); - - //load it again to verify. - std::ifstream input_file("tile.p", std::ios_base::binary); - std::string input_string( (std::istreambuf_iterator(input_file) ), - (std::istreambuf_iterator() ) ); - EmbarkTile verify_tile; - verify_tile.ParseFromString(input_string); - //write contents to text file. - std::ofstream debug_text("tile.txt", std::ios_base::trunc); - debug_text << "world coords:" << verify_tile.world_x()<< "," << verify_tile.world_y()<< "," << verify_tile.world_z() << std::endl; - for(int i = 0; i < verify_tile.tile_layer_size(); i++) { - debug_text << "layer: " << i << std::endl; - for(int j = 0; j < 48; j++) { - debug_text << " "; - for(int k = 0; k < 48; k++) { - debug_text << verify_tile.tile_layer(i).mat_type_table(j*48+k) << ","; - } - debug_text << " "; - for(int k = 0; k < 48; k++) { - debug_text << std::setw(3) << verify_tile.tile_layer(i).mat_subtype_table(j*48+k) << ","; - } - debug_text << std::endl; - } - debug_text << std::endl; - } - //clean everything up. - google::protobuf::ShutdownProtobufLibrary(); - // Give control back to DF. - return CR_OK; -} +//// A command! It sits around and looks pretty. And it's nice and friendly. +//command_result isoWorldRemote (color_ostream &out, std::vector & parameters) +//{ +// // It's nice to print a help message you get invalid options +// // from the user instead of just acting strange. +// // This can be achieved by adding the extended help string to the +// // PluginCommand registration as show above, and then returning +// // CR_WRONG_USAGE from the function. The same string will also +// // be used by 'help your-command'. +// if (!parameters.empty()) +// return CR_WRONG_USAGE; +// // Commands are called from threads other than the DF one. +// // Suspend this thread until DF has time for us. If you +// // use CoreSuspender, it'll automatically resume DF when +// // execution leaves the current scope. +// CoreSuspender suspend; +// // Actually do something here. Yay. +// out.print("Doing a test...\n"); +// MapExtras::MapCache MC; +// EmbarkTile test_tile; +// if(!gather_embark_tile(0,0, &test_tile, &MC)) +// return CR_FAILURE; +// //test-write the file to check it. +// std::ofstream output_file("tile.p", std::ios_base::binary); +// output_file << test_tile.SerializeAsString(); +// output_file.close(); +// +// //load it again to verify. +// std::ifstream input_file("tile.p", std::ios_base::binary); +// std::string input_string( (std::istreambuf_iterator(input_file) ), +// (std::istreambuf_iterator() ) ); +// EmbarkTile verify_tile; +// verify_tile.ParseFromString(input_string); +// //write contents to text file. +// std::ofstream debug_text("tile.txt", std::ios_base::trunc); +// debug_text << "world coords:" << verify_tile.world_x()<< "," << verify_tile.world_y()<< "," << verify_tile.world_z() << std::endl; +// for(int i = 0; i < verify_tile.tile_layer_size(); i++) { +// debug_text << "layer: " << i << std::endl; +// for(int j = 0; j < 48; j++) { +// debug_text << " "; +// for(int k = 0; k < 48; k++) { +// debug_text << verify_tile.tile_layer(i).mat_type_table(j*48+k) << ","; +// } +// debug_text << " "; +// for(int k = 0; k < 48; k++) { +// debug_text << std::setw(3) << verify_tile.tile_layer(i).mat_subtype_table(j*48+k) << ","; +// } +// debug_text << std::endl; +// } +// debug_text << std::endl; +// } +// //clean everything up. +// google::protobuf::ShutdownProtobufLibrary(); +// // Give control back to DF. +// return CR_OK; +//} static command_result GetEmbarkTile(color_ostream &stream, const TileRequest *in, EmbarkTile *out) { @@ -177,6 +177,18 @@ static command_result GetEmbarkTile(color_ostream &stream, const TileRequest *in static command_result GetEmbarkInfo(color_ostream &stream, const MapRequest *in, MapReply *out) { + if(!df::global::gamemode) { + out->set_available(false); + return CR_OK; + } + if((*df::global::gamemode != game_mode::ADVENTURE) && (*df::global::gamemode != game_mode::DWARF)) { + out->set_available(false); + return CR_OK; + } + if(!DFHack::Maps::IsValid()) { + out->set_available(false); + return CR_OK; + } if(!in->has_save_folder()) { //probably should send the stuff anyway, but nah. out->set_available(false); return CR_OK; From 86a02952f8ce9551160ff6659b42032ef9c59c6f Mon Sep 17 00:00:00 2001 From: Japa Date: Mon, 1 Apr 2013 04:39:30 +0530 Subject: [PATCH 6/9] Changed coords to embark tiles instead of blocks. --- plugins/isoworld | 2 +- plugins/isoworldremote.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/isoworld b/plugins/isoworld index 9903472d0..6a74e3ee9 160000 --- a/plugins/isoworld +++ b/plugins/isoworld @@ -1 +1 @@ -Subproject commit 9903472d031bb90a6b55c7950b4a1298293a6659 +Subproject commit 6a74e3ee9ee9d3e35da746fd3fd1d99c30b2e5ad diff --git a/plugins/isoworldremote.cpp b/plugins/isoworldremote.cpp index 6493acd92..a57c6c633 100644 --- a/plugins/isoworldremote.cpp +++ b/plugins/isoworldremote.cpp @@ -170,7 +170,7 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out ) static command_result GetEmbarkTile(color_ostream &stream, const TileRequest *in, EmbarkTile *out) { MapExtras::MapCache MC; - gather_embark_tile(in->want_x(), in->want_y(), out, &MC); + gather_embark_tile(in->want_x() * 3, in->want_y() * 3, out, &MC); MC.trash(); return CR_OK; } @@ -202,8 +202,8 @@ static command_result GetEmbarkInfo(color_ostream &stream, const MapRequest *in, out->set_current_season(*df::global::cur_season); out->set_region_x(df::global::world->map.region_x); out->set_region_y(df::global::world->map.region_y); - out->set_region_size_x(df::global::world->map.x_count_block); - out->set_region_size_y(df::global::world->map.y_count_block); + out->set_region_size_x(df::global::world->map.x_count_block / 3); + out->set_region_size_y(df::global::world->map.y_count_block / 3); return CR_OK; } From b2f4029f4244ad7bc88bb3a658b24e2b1e59edfb Mon Sep 17 00:00:00 2001 From: Japa Date: Tue, 2 Apr 2013 02:58:06 +0530 Subject: [PATCH 7/9] Added in more sanity checks. Signed-off-by: Japa --- plugins/isoworld | 2 +- plugins/isoworldremote.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/plugins/isoworld b/plugins/isoworld index 6a74e3ee9..510ca8aaa 160000 --- a/plugins/isoworld +++ b/plugins/isoworld @@ -1 +1 @@ -Subproject commit 6a74e3ee9ee9d3e35da746fd3fd1d99c30b2e5ad +Subproject commit 510ca8aaaa6f6da51fbd00b51a2facd61dae07f1 diff --git a/plugins/isoworldremote.cpp b/plugins/isoworldremote.cpp index a57c6c633..6a86d96bc 100644 --- a/plugins/isoworldremote.cpp +++ b/plugins/isoworldremote.cpp @@ -177,6 +177,14 @@ static command_result GetEmbarkTile(color_ostream &stream, const TileRequest *in static command_result GetEmbarkInfo(color_ostream &stream, const MapRequest *in, MapReply *out) { + if(!Core::getInstance().isWorldLoaded()) { + out->set_available(false); + return CR_OK; + } + if(!Core::getInstance().isMapLoaded()) { + out->set_available(false); + return CR_OK; + } if(!df::global::gamemode) { out->set_available(false); return CR_OK; From c0a4db32e933c8d500d88f948a6a0af3a477a823 Mon Sep 17 00:00:00 2001 From: Japa Date: Tue, 2 Apr 2013 11:57:30 +0530 Subject: [PATCH 8/9] Fixed the single tile reported coordinates. --- plugins/isoworld | 2 +- plugins/isoworldremote.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/isoworld b/plugins/isoworld index 510ca8aaa..947c58981 160000 --- a/plugins/isoworld +++ b/plugins/isoworld @@ -1 +1 @@ -Subproject commit 510ca8aaaa6f6da51fbd00b51a2facd61dae07f1 +Subproject commit 947c58981684f61dfdde2a97c495dc3fba4bbba3 diff --git a/plugins/isoworldremote.cpp b/plugins/isoworldremote.cpp index 6a86d96bc..521e56af2 100644 --- a/plugins/isoworldremote.cpp +++ b/plugins/isoworldremote.cpp @@ -220,8 +220,8 @@ int coord_to_index_48(int x, int y) { } bool gather_embark_tile(int EmbX, int EmbY, EmbarkTile * tile, MapExtras::MapCache * MP) { - tile->set_world_x(df::global::world->map.region_x + EmbX); //fixme: verify. - tile->set_world_y(df::global::world->map.region_y + EmbY); //fixme: verify. + tile->set_world_x(df::global::world->map.region_x + (EmbX/3)); //fixme: verify. + tile->set_world_y(df::global::world->map.region_y + (EmbY/3)); //fixme: verify. tile->set_world_z(df::global::world->map.region_z); //fixme: verify. tile->set_current_year(*df::global::cur_year); tile->set_current_season(*df::global::cur_season); From 33f0f0d3f32a13599afa727a7b3e70ee5ec56d05 Mon Sep 17 00:00:00 2001 From: Japa Date: Tue, 2 Apr 2013 22:03:32 +0530 Subject: [PATCH 9/9] Isoworldremote plugin now gives material lists, and verifies weather a map block has anything in it. --- plugins/isoworld | 2 +- plugins/isoworldremote.cpp | 61 +++++++++++++++++++++++++++--- plugins/proto/isoworldremote.proto | 7 ++++ 3 files changed, 64 insertions(+), 6 deletions(-) diff --git a/plugins/isoworld b/plugins/isoworld index 947c58981..889e95e26 160000 --- a/plugins/isoworld +++ b/plugins/isoworld @@ -1 +1 @@ -Subproject commit 947c58981684f61dfdde2a97c495dc3fba4bbba3 +Subproject commit 889e95e26e56bbab836d3f6582a3d4d318735f76 diff --git a/plugins/isoworldremote.cpp b/plugins/isoworldremote.cpp index 521e56af2..7ac7d5f15 100644 --- a/plugins/isoworldremote.cpp +++ b/plugins/isoworldremote.cpp @@ -38,8 +38,9 @@ command_result isoWorldRemote (color_ostream &out, std::vector & p static command_result GetEmbarkTile(color_ostream &stream, const TileRequest *in, EmbarkTile *out); static command_result GetEmbarkInfo(color_ostream &stream, const MapRequest *in, MapReply *out); +static command_result GetRawNames(color_ostream &stream, const MapRequest *in, RawNames *out); -void gather_embark_tile_layer(int EmbX, int EmbY, int EmbZ, EmbarkTileLayer * tile, MapExtras::MapCache * MP); +bool gather_embark_tile_layer(int EmbX, int EmbY, int EmbZ, EmbarkTileLayer * tile, MapExtras::MapCache * MP); bool gather_embark_tile(int EmbX, int EmbY, EmbarkTile * tile, MapExtras::MapCache * MP); @@ -68,6 +69,7 @@ DFhackCExport RPCService *plugin_rpcconnect(color_ostream &) RPCService *svc = new RPCService(); svc->addFunction("GetEmbarkTile", GetEmbarkTile); svc->addFunction("GetEmbarkInfo", GetEmbarkInfo); + svc->addFunction("GetRawNames", GetRawNames); return svc; } @@ -220,26 +222,31 @@ int coord_to_index_48(int x, int y) { } bool gather_embark_tile(int EmbX, int EmbY, EmbarkTile * tile, MapExtras::MapCache * MP) { + tile->set_is_valid(false); tile->set_world_x(df::global::world->map.region_x + (EmbX/3)); //fixme: verify. tile->set_world_y(df::global::world->map.region_y + (EmbY/3)); //fixme: verify. tile->set_world_z(df::global::world->map.region_z); //fixme: verify. tile->set_current_year(*df::global::cur_year); tile->set_current_season(*df::global::cur_season); + int num_valid_layers = 0; for(int z = 0; z < MP->maxZ(); z++) { EmbarkTileLayer * tile_layer = tile->add_tile_layer(); - gather_embark_tile_layer(EmbX, EmbY, z, tile_layer, MP); + num_valid_layers += gather_embark_tile_layer(EmbX, EmbY, z, tile_layer, MP); } + if(num_valid_layers > 0) + tile->set_is_valid(true); return 1; } -void gather_embark_tile_layer(int EmbX, int EmbY, int EmbZ, EmbarkTileLayer * tile, MapExtras::MapCache * MP) +bool gather_embark_tile_layer(int EmbX, int EmbY, int EmbZ, EmbarkTileLayer * tile, MapExtras::MapCache * MP) { for(int i = tile->mat_type_table_size(); i < 2304; i++) { //This is needed so we have a full array to work with, otherwise the size isn't updated correctly. tile->add_mat_type_table(AIR); tile->add_mat_subtype_table(0); } + int num_valid_blocks = 0; for(int yy = 0; yy < 3; yy++) { for(int xx = 0; xx < 3; xx++) { DFCoord current_coord; @@ -254,13 +261,14 @@ void gather_embark_tile_layer(int EmbX, int EmbY, int EmbZ, EmbarkTileLayer * ti block_coord.x = block_x; block_coord.y = block_y; DFHack::t_matpair actual_mat = b->staticMaterialAt(block_coord); - df::tiletype tile_type = b->staticTiletypeAt(block_coord); + df::tiletype tile_type = b->tiletypeAt(block_coord); df::tile_designation designation = b->DesignationAt(block_coord); unsigned int array_index = coord_to_index_48(xx*16+block_x, yy*16+block_y); //make a new fake material at the given index if(tileMaterial(tile_type) == tiletype_material::FROZEN_LIQUID) { //Ice. tile->set_mat_type_table(array_index, BasicMaterial::LIQUID); //Ice is totally a liquid, shut up. tile->set_mat_subtype_table(array_index, 0); + num_valid_blocks++; } else if(designation.bits.flow_size) { //Contains either water or lava. tile->set_mat_type_table(array_index, BasicMaterial::LIQUID); @@ -268,6 +276,7 @@ void gather_embark_tile_layer(int EmbX, int EmbY, int EmbZ, EmbarkTileLayer * ti tile->set_mat_subtype_table(array_index, 2); else //water tile->set_mat_subtype_table(array_index, 1); + num_valid_blocks++; } else if(tileShapeBasic(tileShape(tile_type)) != tiletype_shape_basic::Open) { if(actual_mat.mat_type == builtin_mats::INORGANIC) { //inorganic @@ -282,6 +291,7 @@ void gather_embark_tile_layer(int EmbX, int EmbY, int EmbZ, EmbarkTileLayer * ti tile->set_mat_type_table(array_index, BasicMaterial::OTHER); tile->set_mat_subtype_table(array_index, actual_mat.mat_type); } + num_valid_blocks++; } else { tile->set_mat_type_table(array_index, BasicMaterial::AIR); @@ -291,4 +301,45 @@ void gather_embark_tile_layer(int EmbX, int EmbY, int EmbZ, EmbarkTileLayer * ti } } } -} \ No newline at end of file + return (num_valid_blocks >0); +} + +static command_result GetRawNames(color_ostream &stream, const MapRequest *in, RawNames *out){ + if(!Core::getInstance().isWorldLoaded()) { + out->set_available(false); + return CR_OK; + } + if(!Core::getInstance().isMapLoaded()) { + out->set_available(false); + return CR_OK; + } + if(!df::global::gamemode) { + out->set_available(false); + return CR_OK; + } + if((*df::global::gamemode != game_mode::ADVENTURE) && (*df::global::gamemode != game_mode::DWARF)) { + out->set_available(false); + return CR_OK; + } + if(!DFHack::Maps::IsValid()) { + out->set_available(false); + return CR_OK; + } + if(!in->has_save_folder()) { //probably should send the stuff anyway, but nah. + out->set_available(false); + return CR_OK; + } + if(!(in->save_folder() == df::global::world->cur_savegame.save_dir)) { //isoworld has a different map loaded, don't bother trying to load tiles for it, we don't have them. + out->set_available(false); + return CR_OK; + } + out->set_available(true); + for(int i = 0; i < df::global::world->raws.inorganics.size(); i++){ + out->add_inorganic(df::global::world->raws.inorganics[i]->id); + } + + for(int i = 0; i < df::global::world->raws.plants.all.size(); i++){ + out->add_organic(df::global::world->raws.plants.all[i]->id); + } + return CR_OK; +} diff --git a/plugins/proto/isoworldremote.proto b/plugins/proto/isoworldremote.proto index 719ffda3b..5eface205 100644 --- a/plugins/proto/isoworldremote.proto +++ b/plugins/proto/isoworldremote.proto @@ -24,6 +24,7 @@ message EmbarkTile { repeated EmbarkTileLayer tile_layer = 4; optional int32 current_year = 5; optional int32 current_season = 6; + optional bool is_valid = 7; } message TileRequest { @@ -43,4 +44,10 @@ message MapReply { optional int32 region_size_y = 5; optional int32 current_year = 6; optional int32 current_season = 7; +} + +message RawNames { + required bool available = 1; + repeated string inorganic = 2; + repeated string organic = 3; } \ No newline at end of file