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