From 2d5ec9e45d65c2aa09f8f7aacca2ccb4a784c08a Mon Sep 17 00:00:00 2001 From: JapaMala Date: Tue, 15 Jul 2014 17:48:12 +0530 Subject: [PATCH 1/7] remotefortressreader can send over more info over the sockets. --- plugins/proto/RemoteFortressReader.proto | 38 +++++++++++++--- plugins/remotefortressreader.cpp | 55 +++++++++++++++++++++--- 2 files changed, 80 insertions(+), 13 deletions(-) diff --git a/plugins/proto/RemoteFortressReader.proto b/plugins/proto/RemoteFortressReader.proto index e6e4a3123..37d746308 100644 --- a/plugins/proto/RemoteFortressReader.proto +++ b/plugins/proto/RemoteFortressReader.proto @@ -4,7 +4,8 @@ package RemoteFortressReader; option optimize_for = LITE_RUNTIME; //We use shapes, etc, because the actual tiletypes may differ between DF versions. -enum TiletypeShape { +enum TiletypeShape +{ NO_SHAPE = -1; EMPTY = 0; FLOOR = 1; @@ -25,7 +26,8 @@ enum TiletypeShape { ENDLESS_PIT = 16; } -enum TiletypeSpecial { +enum TiletypeSpecial +{ NO_SPECIAL = -1; NORMAL = 0; RIVER_SOURCE = 1; @@ -39,7 +41,8 @@ enum TiletypeSpecial { WORN_3 = 9; TRACK = 10; }; -enum TiletypeMaterial { +enum TiletypeMaterial +{ NO_MATERIAL = -1; AIR = 0; SOIL = 1; @@ -64,15 +67,38 @@ enum TiletypeMaterial { BROOK = 20; RIVER = 21; } +enum TiletypeVariant +{ + NO_VARIANT = -1; + VAR_1 = 0; + VAR_2 = 1; + VAR_3 = 3; + VAR_4 = 4; +}; + +message Tiletype +{ + required int32 id = 1; + optional string name = 2; + optional string caption = 3; + optional TiletypeShape shape = 4; + optional TiletypeSpecial special = 5; + optional TiletypeMaterial material = 6; + optional TiletypeVariant variant = 7; + optional uint32 direction = 8; +}; + +message TiletypeList +{ + repeated Tiletype tiletype_list = 1; +} message MapBlock { required int32 map_x = 1; required int32 map_y = 2; required int32 map_z = 3; - repeated TiletypeShape tiletype_shapes = 4; - repeated TiletypeSpecial tiletype_specials = 5; - repeated TiletypeMaterial tiletype_materials = 6; + repeated int32 tiles = 4; } message MatPair { diff --git a/plugins/remotefortressreader.cpp b/plugins/remotefortressreader.cpp index 411b0b646..8effe1046 100644 --- a/plugins/remotefortressreader.cpp +++ b/plugins/remotefortressreader.cpp @@ -53,6 +53,7 @@ using namespace std; // mostly to allow having the mandatory stuff on top of the file and commands on the bottom static command_result GetMaterialList(color_ostream &stream, const EmptyMessage *in, MaterialList *out); +static command_result GetTiletypeList(color_ostream &stream, const EmptyMessage *in, TiletypeList *out); static command_result GetBlockList(color_ostream &stream, const BlockRequest *in, BlockList *out); static command_result CheckHashes(color_ostream &stream, const EmptyMessage *in); void CopyBlock(df::map_block * DfBlock, RemoteFortressReader::MapBlock * NetBlock); @@ -86,6 +87,7 @@ DFhackCExport RPCService *plugin_rpcconnect(color_ostream &) svc->addFunction("GetMaterialList", GetMaterialList); svc->addFunction("GetBlockList", GetBlockList); svc->addFunction("CheckHashes", CheckHashes); + svc->addFunction("GetTiletypeList", GetTiletypeList); return svc; } @@ -184,9 +186,9 @@ static command_result GetMaterialList(color_ostream &stream, const EmptyMessage if (raws->mat_table.builtin[i]->state_color[GetState(raws->mat_table.builtin[i])] < raws->language.colors.size()) { df::descriptor_color *color = raws->language.colors[raws->mat_table.builtin[i]->state_color[GetState(raws->mat_table.builtin[i])]]; - mat_def->mutable_state_color()->set_red(color->red); - mat_def->mutable_state_color()->set_green(color->green); - mat_def->mutable_state_color()->set_blue(color->blue); + mat_def->mutable_state_color()->set_red(color->red*255); + mat_def->mutable_state_color()->set_green(color->green*255); + mat_def->mutable_state_color()->set_blue(color->blue*255); } } } @@ -210,6 +212,26 @@ static command_result GetMaterialList(color_ostream &stream, const EmptyMessage } } } + for (int i = 0; i < raws->plants.all.size(); i++) + { + df::plant_raw * plant = raws->plants.all[i]; + for (int j = 0; j < plant->material.size(); j++) + { + mat.decode(j + 419, i); + MaterialDefinition *mat_def = out->add_material_list(); + mat_def->mutable_mat_pair()->set_mat_index(j + 419); + mat_def->mutable_mat_pair()->set_mat_type(i); + mat_def->set_id(mat.getToken()); + mat_def->set_name(mat.toString()); //find the name at cave temperature; + if (plant->material[j]->state_color[GetState(plant->material[j])] < raws->language.colors.size()) + { + df::descriptor_color *color = raws->language.colors[plant->material[j]->state_color[GetState(plant->material[j])]]; + mat_def->mutable_state_color()->set_red(color->red); + mat_def->mutable_state_color()->set_green(color->green); + mat_def->mutable_state_color()->set_blue(color->blue); + } + } + } return CR_OK; } @@ -223,9 +245,7 @@ void CopyBlock(df::map_block * DfBlock, RemoteFortressReader::MapBlock * NetBloc for (int xx = 0; xx < 16; xx++) { df::tiletype tile = DfBlock->tiletype[xx][yy]; - NetBlock->add_tiletype_shapes((RemoteFortressReader::TiletypeShape)tileShape(tile)); - NetBlock->add_tiletype_materials((RemoteFortressReader::TiletypeMaterial)tileMaterial(tile)); - NetBlock->add_tiletype_specials((RemoteFortressReader::TiletypeSpecial)tileSpecial(tile)); + NetBlock->add_tiles(tile); } } } @@ -248,4 +268,25 @@ static command_result GetBlockList(color_ostream &stream, const BlockRequest *in } } return CR_OK; -} \ No newline at end of file +} + +static command_result GetTiletypeList(color_ostream &stream, const EmptyMessage *in, TiletypeList *out) +{ + int count = 0; + FOR_ENUM_ITEMS(tiletype, tt) + { + Tiletype * type = out->add_tiletype_list(); + type->set_id(tt); + type->set_name(ENUM_KEY_STR(tiletype, tt)); + const char * name = tileName(tt); + if (name != NULL && name[0] != 0) + type->set_caption(name); + type->set_shape((RemoteFortressReader::TiletypeShape)tileShape(tt)); + type->set_special((RemoteFortressReader::TiletypeSpecial)tileSpecial(tt)); + type->set_material((RemoteFortressReader::TiletypeMaterial)tileMaterial(tt)); + type->set_variant((RemoteFortressReader::TiletypeVariant)tileVariant(tt)); + type->set_direction(tileDirection(tt).whole); + count++; + } + return CR_OK; +} From 216019e5af61af410944c197e2c89792433049b3 Mon Sep 17 00:00:00 2001 From: JapaMala Date: Thu, 17 Jul 2014 17:46:00 +0530 Subject: [PATCH 2/7] Disconnected the RemoteReader values from the DF enums. --- plugins/proto/RemoteFortressReader.proto | 14 +- plugins/remotefortressreader.cpp | 523 +++++++++++++++++------ 2 files changed, 396 insertions(+), 141 deletions(-) diff --git a/plugins/proto/RemoteFortressReader.proto b/plugins/proto/RemoteFortressReader.proto index 37d746308..15d60c8ed 100644 --- a/plugins/proto/RemoteFortressReader.proto +++ b/plugins/proto/RemoteFortressReader.proto @@ -20,10 +20,13 @@ enum TiletypeShape RAMP_TOP = 10; BROOK_BED = 11; BROOK_TOP = 12; - TREE = 13; + TREE_SHAPE = 13; SAPLING = 14; SHRUB = 15; ENDLESS_PIT = 16; + BRANCH = 17; + TRUNK_BRANCH = 18; + TWIG = 19; } enum TiletypeSpecial @@ -40,6 +43,7 @@ enum TiletypeSpecial WORN_2 = 8; WORN_3 = 9; TRACK = 10; + SMOOTH_DEAD = 11; }; enum TiletypeMaterial { @@ -66,14 +70,18 @@ enum TiletypeMaterial POOL = 19; BROOK = 20; RIVER = 21; + ROOT = 22; + TREE_MATERIAL = 23; + MUSHROOM = 24; + UNDERWORLD_GATE = 25; } enum TiletypeVariant { NO_VARIANT = -1; VAR_1 = 0; VAR_2 = 1; - VAR_3 = 3; - VAR_4 = 4; + VAR_3 = 2; + VAR_4 = 3; }; message Tiletype diff --git a/plugins/remotefortressreader.cpp b/plugins/remotefortressreader.cpp index 8effe1046..cfef6fcf7 100644 --- a/plugins/remotefortressreader.cpp +++ b/plugins/remotefortressreader.cpp @@ -1,4 +1,7 @@ -// This is a generic plugin that does nothing useful apart from acting as an example... of a plugin that does nothing :D + +//define which version of DF this is being built for. +#define DF_VER_040 +//#define DF_VER_034 // some headers required for a plugin. Nothing special, just the basics. #include "Core.h" @@ -66,7 +69,7 @@ void FindChangedBlocks(); DFHACK_PLUGIN("RemoteFortressReader"); // Mandatory init function. If you have some global state, create it here. -DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) +DFhackCExport command_result plugin_init(color_ostream &out, std::vector &commands) { //// Fill the command list with your commands. //commands.push_back(PluginCommand( @@ -84,15 +87,15 @@ DFhackCExport command_result plugin_init ( color_ostream &out, std::vector addFunction("GetMaterialList", GetMaterialList); - svc->addFunction("GetBlockList", GetBlockList); - svc->addFunction("CheckHashes", CheckHashes); + svc->addFunction("GetMaterialList", GetMaterialList); + svc->addFunction("GetBlockList", GetBlockList); + svc->addFunction("CheckHashes", CheckHashes); svc->addFunction("GetTiletypeList", GetTiletypeList); return svc; } // This is called right before the plugin library is removed from memory. -DFhackCExport command_result plugin_shutdown ( color_ostream &out ) +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 @@ -102,116 +105,360 @@ DFhackCExport command_result plugin_shutdown ( color_ostream &out ) uint16_t fletcher16(uint8_t const *data, size_t bytes) { - uint16_t sum1 = 0xff, sum2 = 0xff; - - while (bytes) { - size_t tlen = bytes > 20 ? 20 : bytes; - bytes -= tlen; - do { - sum2 += sum1 += *data++; - } while (--tlen); - sum1 = (sum1 & 0xff) + (sum1 >> 8); - sum2 = (sum2 & 0xff) + (sum2 >> 8); - } - /* Second reduction step to reduce sums to 8 bits */ - sum1 = (sum1 & 0xff) + (sum1 >> 8); - sum2 = (sum2 & 0xff) + (sum2 >> 8); - return sum2 << 8 | sum1; + uint16_t sum1 = 0xff, sum2 = 0xff; + + while (bytes) { + size_t tlen = bytes > 20 ? 20 : bytes; + bytes -= tlen; + do { + sum2 += sum1 += *data++; + } while (--tlen); + sum1 = (sum1 & 0xff) + (sum1 >> 8); + sum2 = (sum2 & 0xff) + (sum2 >> 8); + } + /* Second reduction step to reduce sums to 8 bits */ + sum1 = (sum1 & 0xff) + (sum1 >> 8); + sum2 = (sum2 & 0xff) + (sum2 >> 8); + return sum2 << 8 | sum1; +} + +RemoteFortressReader::TiletypeMaterial TranslateMaterial(df::tiletype_material material) +{ + switch (material) + { + case df::enums::tiletype_material::NONE: + return RemoteFortressReader::NO_MATERIAL; + break; + case df::enums::tiletype_material::AIR: + return RemoteFortressReader::AIR; + break; + case df::enums::tiletype_material::SOIL: + return RemoteFortressReader::SOIL; + break; + case df::enums::tiletype_material::STONE: + return RemoteFortressReader::STONE; + break; + case df::enums::tiletype_material::FEATURE: + return RemoteFortressReader::FEATURE; + break; + case df::enums::tiletype_material::LAVA_STONE: + return RemoteFortressReader::LAVA_STONE; + break; + case df::enums::tiletype_material::MINERAL: + return RemoteFortressReader::MINERAL; + break; + case df::enums::tiletype_material::FROZEN_LIQUID: + return RemoteFortressReader::FROZEN_LIQUID; + break; + case df::enums::tiletype_material::CONSTRUCTION: + return RemoteFortressReader::CONSTRUCTION; + break; + case df::enums::tiletype_material::GRASS_LIGHT: + return RemoteFortressReader::GRASS_LIGHT; + break; + case df::enums::tiletype_material::GRASS_DARK: + return RemoteFortressReader::GRASS_DARK; + break; + case df::enums::tiletype_material::GRASS_DRY: + return RemoteFortressReader::GRASS_DRY; + break; + case df::enums::tiletype_material::GRASS_DEAD: + return RemoteFortressReader::GRASS_DEAD; + break; + case df::enums::tiletype_material::PLANT: + return RemoteFortressReader::PLANT; + break; + case df::enums::tiletype_material::HFS: + return RemoteFortressReader::HFS; + break; + case df::enums::tiletype_material::CAMPFIRE: + return RemoteFortressReader::CAMPFIRE; + break; + case df::enums::tiletype_material::FIRE: + return RemoteFortressReader::FIRE; + break; + case df::enums::tiletype_material::ASHES: + return RemoteFortressReader::ASHES; + break; + case df::enums::tiletype_material::MAGMA: + return RemoteFortressReader::MAGMA; + break; + case df::enums::tiletype_material::DRIFTWOOD: + return RemoteFortressReader::DRIFTWOOD; + break; + case df::enums::tiletype_material::POOL: + return RemoteFortressReader::POOL; + break; + case df::enums::tiletype_material::BROOK: + return RemoteFortressReader::BROOK; + break; + case df::enums::tiletype_material::RIVER: + return RemoteFortressReader::RIVER; + break; + case df::enums::tiletype_material::ROOT: + return RemoteFortressReader::ROOT; + break; + case df::enums::tiletype_material::TREE: + return RemoteFortressReader::TREE_MATERIAL; + break; + case df::enums::tiletype_material::MUSHROOM: + return RemoteFortressReader::MUSHROOM; + break; + case df::enums::tiletype_material::UNDERWORLD_GATE: + return RemoteFortressReader::UNDERWORLD_GATE; + break; + default: + return RemoteFortressReader::NO_MATERIAL; + break; + } + return RemoteFortressReader::NO_MATERIAL; +} + +RemoteFortressReader::TiletypeSpecial TranslateSpecial(df::tiletype_special special) +{ + switch (special) + { + case df::enums::tiletype_special::NONE: + return RemoteFortressReader::NO_SPECIAL; + break; + case df::enums::tiletype_special::NORMAL: + return RemoteFortressReader::NORMAL; + break; + case df::enums::tiletype_special::RIVER_SOURCE: + return RemoteFortressReader::RIVER_SOURCE; + break; + case df::enums::tiletype_special::WATERFALL: + return RemoteFortressReader::WATERFALL; + break; + case df::enums::tiletype_special::SMOOTH: + return RemoteFortressReader::SMOOTH; + break; + case df::enums::tiletype_special::FURROWED: + return RemoteFortressReader::FURROWED; + break; + case df::enums::tiletype_special::WET: + return RemoteFortressReader::WET; + break; + case df::enums::tiletype_special::DEAD: + return RemoteFortressReader::DEAD; + break; + case df::enums::tiletype_special::WORN_1: + return RemoteFortressReader::WORN_1; + break; + case df::enums::tiletype_special::WORN_2: + return RemoteFortressReader::WORN_2; + break; + case df::enums::tiletype_special::WORN_3: + return RemoteFortressReader::WORN_3; + break; + case df::enums::tiletype_special::TRACK: + return RemoteFortressReader::TRACK; + break; + case df::enums::tiletype_special::SMOOTH_DEAD: + return RemoteFortressReader::SMOOTH_DEAD; + break; + default: + return RemoteFortressReader::NO_SPECIAL; + break; + } + return RemoteFortressReader::NO_SPECIAL; +} + +RemoteFortressReader::TiletypeShape TranslateShape(df::tiletype_shape shape) +{ + switch (shape) + { + case df::enums::tiletype_shape::NONE: + return RemoteFortressReader::NO_SHAPE; + break; + case df::enums::tiletype_shape::EMPTY: + return RemoteFortressReader::EMPTY; + break; + case df::enums::tiletype_shape::FLOOR: + return RemoteFortressReader::FLOOR; + break; + case df::enums::tiletype_shape::BOULDER: + return RemoteFortressReader::BOULDER; + break; + case df::enums::tiletype_shape::PEBBLES: + return RemoteFortressReader::PEBBLES; + break; + case df::enums::tiletype_shape::WALL: + return RemoteFortressReader::WALL; + break; + case df::enums::tiletype_shape::FORTIFICATION: + return RemoteFortressReader::FORTIFICATION; + break; + case df::enums::tiletype_shape::STAIR_UP: + return RemoteFortressReader::STAIR_UP; + break; + case df::enums::tiletype_shape::STAIR_DOWN: + return RemoteFortressReader::STAIR_DOWN; + break; + case df::enums::tiletype_shape::STAIR_UPDOWN: + return RemoteFortressReader::STAIR_UPDOWN; + break; + case df::enums::tiletype_shape::RAMP: + return RemoteFortressReader::RAMP; + break; + case df::enums::tiletype_shape::RAMP_TOP: + return RemoteFortressReader::RAMP_TOP; + break; + case df::enums::tiletype_shape::BROOK_BED: + return RemoteFortressReader::BROOK_BED; + break; + case df::enums::tiletype_shape::BROOK_TOP: + return RemoteFortressReader::BROOK_TOP; + break; + case df::enums::tiletype_shape::BRANCH: + return RemoteFortressReader::BRANCH; + break; +#ifdef DF_VER_034 + case df::enums::tiletype_shape::TREE: + return RemoteFortressReader::TREE; + break; +#endif + case df::enums::tiletype_shape::TRUNK_BRANCH: + return RemoteFortressReader::TRUNK_BRANCH; + break; + case df::enums::tiletype_shape::TWIG: + return RemoteFortressReader::TWIG; + break; + case df::enums::tiletype_shape::SAPLING: + return RemoteFortressReader::SAPLING; + break; + case df::enums::tiletype_shape::SHRUB: + return RemoteFortressReader::SHRUB; + break; + case df::enums::tiletype_shape::ENDLESS_PIT: + return RemoteFortressReader::EMPTY; + break; + default: + return RemoteFortressReader::NO_SHAPE; + break; + } + return RemoteFortressReader::NO_SHAPE; +} + +RemoteFortressReader::TiletypeVariant TranslateVariant(df::tiletype_variant variant) +{ + switch (variant) + { + case df::enums::tiletype_variant::NONE: + return RemoteFortressReader::NO_VARIANT; + break; + case df::enums::tiletype_variant::VAR_1: + return RemoteFortressReader::VAR_1; + break; + case df::enums::tiletype_variant::VAR_2: + return RemoteFortressReader::VAR_2; + break; + case df::enums::tiletype_variant::VAR_3: + return RemoteFortressReader::VAR_3; + break; + case df::enums::tiletype_variant::VAR_4: + return RemoteFortressReader::VAR_4; + break; + default: + return RemoteFortressReader::NO_VARIANT; + break; + } + return RemoteFortressReader::NO_VARIANT; } static command_result CheckHashes(color_ostream &stream, const EmptyMessage *in) { - clock_t start = clock(); - for (int i = 0; i < df::global::world->map.map_blocks.size(); i++) - { - df::map_block * block = df::global::world->map.map_blocks[i]; - fletcher16((uint8_t*)(block->tiletype), 16 * 16 * sizeof(df::enums::tiletype::tiletype)); - } - clock_t end = clock(); - double elapsed_secs = double(end - start) / CLOCKS_PER_SEC; - stream.print("Checking all hashes took %f seconds.", elapsed_secs); - return CR_OK; + clock_t start = clock(); + for (int i = 0; i < df::global::world->map.map_blocks.size(); i++) + { + df::map_block * block = df::global::world->map.map_blocks[i]; + fletcher16((uint8_t*)(block->tiletype), 16 * 16 * sizeof(df::enums::tiletype::tiletype)); + } + clock_t end = clock(); + double elapsed_secs = double(end - start) / CLOCKS_PER_SEC; + stream.print("Checking all hashes took %f seconds.", elapsed_secs); + return CR_OK; } df::matter_state GetState(df::material * mat, uint16_t temp = 10015) { - df::matter_state state = matter_state::Solid; - if (temp >= mat->heat.melting_point) - state = df::matter_state::Liquid; - if (temp >= mat->heat.boiling_point) - state = matter_state::Gas; - return state; + df::matter_state state = matter_state::Solid; + if (temp >= mat->heat.melting_point) + state = df::matter_state::Liquid; + if (temp >= mat->heat.boiling_point) + state = matter_state::Gas; + return state; } static command_result GetMaterialList(color_ostream &stream, const EmptyMessage *in, MaterialList *out) { - if (!Core::getInstance().isWorldLoaded()) { - //out->set_available(false); - return CR_OK; - } - - - - df::world_raws *raws = &df::global::world->raws; - MaterialInfo mat; - for (int i = 0; i < raws->inorganics.size(); i++) - { - mat.decode(0, i); - MaterialDefinition *mat_def = out->add_material_list(); - mat_def->mutable_mat_pair()->set_mat_index(0); - mat_def->mutable_mat_pair()->set_mat_type(i); - mat_def->set_id(mat.getToken()); - mat_def->set_name(mat.toString()); //find the name at cave temperature; - if (raws->inorganics[i]->material.state_color[GetState(&raws->inorganics[i]->material)] < raws->language.colors.size()) - { - df::descriptor_color *color = raws->language.colors[raws->inorganics[i]->material.state_color[GetState(&raws->inorganics[i]->material)]]; - mat_def->mutable_state_color()->set_red(color->red); - mat_def->mutable_state_color()->set_green(color->green); - mat_def->mutable_state_color()->set_blue(color->blue); - } - } - for (int i = 1; i < 19; i++) - { - int k = 0; - if (i == 7) - k = 1;// for coal. - for (int j = 0; j <= k; j++) - { - mat.decode(i, j); - MaterialDefinition *mat_def = out->add_material_list(); - mat_def->mutable_mat_pair()->set_mat_index(i); - mat_def->mutable_mat_pair()->set_mat_type(j); - mat_def->set_id(mat.getToken()); - mat_def->set_name(mat.toString()); //find the name at cave temperature; - if (raws->mat_table.builtin[i]->state_color[GetState(raws->mat_table.builtin[i])] < raws->language.colors.size()) - { - df::descriptor_color *color = raws->language.colors[raws->mat_table.builtin[i]->state_color[GetState(raws->mat_table.builtin[i])]]; - mat_def->mutable_state_color()->set_red(color->red*255); - mat_def->mutable_state_color()->set_green(color->green*255); - mat_def->mutable_state_color()->set_blue(color->blue*255); - } - } - } - for (int i = 0; i < raws->creatures.all.size(); i++) - { - df::creature_raw * creature = raws->creatures.all[i]; - for (int j = 0; j < creature->material.size(); j++) - { - mat.decode(j + 19, i); - MaterialDefinition *mat_def = out->add_material_list(); - mat_def->mutable_mat_pair()->set_mat_index(j+19); - mat_def->mutable_mat_pair()->set_mat_type(i); - mat_def->set_id(mat.getToken()); - mat_def->set_name(mat.toString()); //find the name at cave temperature; - if (creature->material[j]->state_color[GetState(creature->material[j])] < raws->language.colors.size()) - { - df::descriptor_color *color = raws->language.colors[creature->material[j]->state_color[GetState(creature->material[j])]]; - mat_def->mutable_state_color()->set_red(color->red); - mat_def->mutable_state_color()->set_green(color->green); - mat_def->mutable_state_color()->set_blue(color->blue); - } - } - } + if (!Core::getInstance().isWorldLoaded()) { + //out->set_available(false); + return CR_OK; + } + + + + df::world_raws *raws = &df::global::world->raws; + MaterialInfo mat; + for (int i = 0; i < raws->inorganics.size(); i++) + { + mat.decode(0, i); + MaterialDefinition *mat_def = out->add_material_list(); + mat_def->mutable_mat_pair()->set_mat_index(0); + mat_def->mutable_mat_pair()->set_mat_type(i); + mat_def->set_id(mat.getToken()); + mat_def->set_name(mat.toString()); //find the name at cave temperature; + if (raws->inorganics[i]->material.state_color[GetState(&raws->inorganics[i]->material)] < raws->language.colors.size()) + { + df::descriptor_color *color = raws->language.colors[raws->inorganics[i]->material.state_color[GetState(&raws->inorganics[i]->material)]]; + mat_def->mutable_state_color()->set_red(color->red * 255); + mat_def->mutable_state_color()->set_green(color->green * 255); + mat_def->mutable_state_color()->set_blue(color->blue * 255); + } + } + for (int i = 1; i < 19; i++) + { + int k = 0; + if (i == 7) + k = 1;// for coal. + for (int j = 0; j <= k; j++) + { + mat.decode(i, j); + MaterialDefinition *mat_def = out->add_material_list(); + mat_def->mutable_mat_pair()->set_mat_index(i); + mat_def->mutable_mat_pair()->set_mat_type(j); + mat_def->set_id(mat.getToken()); + mat_def->set_name(mat.toString()); //find the name at cave temperature; + if (raws->mat_table.builtin[i]->state_color[GetState(raws->mat_table.builtin[i])] < raws->language.colors.size()) + { + df::descriptor_color *color = raws->language.colors[raws->mat_table.builtin[i]->state_color[GetState(raws->mat_table.builtin[i])]]; + mat_def->mutable_state_color()->set_red(color->red * 255); + mat_def->mutable_state_color()->set_green(color->green * 255); + mat_def->mutable_state_color()->set_blue(color->blue * 255); + } + } + } + for (int i = 0; i < raws->creatures.all.size(); i++) + { + df::creature_raw * creature = raws->creatures.all[i]; + for (int j = 0; j < creature->material.size(); j++) + { + mat.decode(j + 19, i); + MaterialDefinition *mat_def = out->add_material_list(); + mat_def->mutable_mat_pair()->set_mat_index(j + 19); + mat_def->mutable_mat_pair()->set_mat_type(i); + mat_def->set_id(mat.getToken()); + mat_def->set_name(mat.toString()); //find the name at cave temperature; + if (creature->material[j]->state_color[GetState(creature->material[j])] < raws->language.colors.size()) + { + df::descriptor_color *color = raws->language.colors[creature->material[j]->state_color[GetState(creature->material[j])]]; + mat_def->mutable_state_color()->set_red(color->red * 255); + mat_def->mutable_state_color()->set_green(color->green * 255); + mat_def->mutable_state_color()->set_blue(color->blue * 255); + } + } + } for (int i = 0; i < raws->plants.all.size(); i++) { df::plant_raw * plant = raws->plants.all[i]; @@ -226,48 +473,48 @@ static command_result GetMaterialList(color_ostream &stream, const EmptyMessage if (plant->material[j]->state_color[GetState(plant->material[j])] < raws->language.colors.size()) { df::descriptor_color *color = raws->language.colors[plant->material[j]->state_color[GetState(plant->material[j])]]; - mat_def->mutable_state_color()->set_red(color->red); - mat_def->mutable_state_color()->set_green(color->green); - mat_def->mutable_state_color()->set_blue(color->blue); + mat_def->mutable_state_color()->set_red(color->red * 255); + mat_def->mutable_state_color()->set_green(color->green * 255); + mat_def->mutable_state_color()->set_blue(color->blue * 255); } } } - return CR_OK; + return CR_OK; } void CopyBlock(df::map_block * DfBlock, RemoteFortressReader::MapBlock * NetBlock) { - NetBlock->set_map_x(DfBlock->map_pos.x); - NetBlock->set_map_y(DfBlock->map_pos.y); - NetBlock->set_map_z(DfBlock->map_pos.z); - for (int yy = 0; yy < 16; yy++) - { - for (int xx = 0; xx < 16; xx++) - { - df::tiletype tile = DfBlock->tiletype[xx][yy]; + NetBlock->set_map_x(DfBlock->map_pos.x); + NetBlock->set_map_y(DfBlock->map_pos.y); + NetBlock->set_map_z(DfBlock->map_pos.z); + for (int yy = 0; yy < 16; yy++) + { + for (int xx = 0; xx < 16; xx++) + { + df::tiletype tile = DfBlock->tiletype[xx][yy]; NetBlock->add_tiles(tile); - } - } + } + } } static command_result GetBlockList(color_ostream &stream, const BlockRequest *in, BlockList *out) { - //stream.print("Got request for blocks from (%d, %d, %d) to (%d, %d, %d).\n", in->min_x(), in->min_y(), in->min_z(), in->max_x(), in->max_y(), in->max_z()); - for (int zz = in->min_z(); zz < in->max_z(); zz++) - { - for (int yy = in->min_y(); yy < in->max_y(); yy++) - { - for (int xx = in->min_x(); xx < in->max_x(); xx++) - { - df::map_block * block = DFHack::Maps::getBlock(xx, yy, zz); - if (block == NULL) - continue; - RemoteFortressReader::MapBlock *net_block = out->add_map_blocks(); - CopyBlock(block, net_block); - } - } - } - return CR_OK; + //stream.print("Got request for blocks from (%d, %d, %d) to (%d, %d, %d).\n", in->min_x(), in->min_y(), in->min_z(), in->max_x(), in->max_y(), in->max_z()); + for (int zz = in->min_z(); zz < in->max_z(); zz++) + { + for (int yy = in->min_y(); yy < in->max_y(); yy++) + { + for (int xx = in->min_x(); xx < in->max_x(); xx++) + { + df::map_block * block = DFHack::Maps::getBlock(xx, yy, zz); + if (block == NULL) + continue; + RemoteFortressReader::MapBlock *net_block = out->add_map_blocks(); + CopyBlock(block, net_block); + } + } + } + return CR_OK; } static command_result GetTiletypeList(color_ostream &stream, const EmptyMessage *in, TiletypeList *out) @@ -281,10 +528,10 @@ static command_result GetTiletypeList(color_ostream &stream, const EmptyMessage const char * name = tileName(tt); if (name != NULL && name[0] != 0) type->set_caption(name); - type->set_shape((RemoteFortressReader::TiletypeShape)tileShape(tt)); - type->set_special((RemoteFortressReader::TiletypeSpecial)tileSpecial(tt)); - type->set_material((RemoteFortressReader::TiletypeMaterial)tileMaterial(tt)); - type->set_variant((RemoteFortressReader::TiletypeVariant)tileVariant(tt)); + type->set_shape(TranslateShape(tileShape(tt))); + type->set_special(TranslateSpecial(tileSpecial(tt))); + type->set_material(TranslateMaterial(tileMaterial(tt))); + type->set_variant(TranslateVariant(tileVariant(tt))); type->set_direction(tileDirection(tt).whole); count++; } From bc5e0f6ad63045ffee4ff4d0632e4f27d8014a80 Mon Sep 17 00:00:00 2001 From: JapaMala Date: Wed, 23 Jul 2014 19:57:47 +0530 Subject: [PATCH 3/7] Made DFHack buildable. Also added plant proto definitions --- library/modules/Items.cpp | 2 +- library/modules/MapCache.cpp | 50 ++++---- library/modules/Maps.cpp | 18 +-- library/modules/Materials.cpp | 2 +- library/modules/Translation.cpp | 22 ++-- library/xml | 2 +- plugins/CMakeLists.txt | 152 +++++++++++------------ plugins/proto/RemoteFortressReader.proto | 13 ++ plugins/stonesense | 2 +- 9 files changed, 139 insertions(+), 124 deletions(-) diff --git a/library/modules/Items.cpp b/library/modules/Items.cpp index 31640dbb5..c0017fb9b 100644 --- a/library/modules/Items.cpp +++ b/library/modules/Items.cpp @@ -1158,7 +1158,7 @@ int Items::getItemBaseValue(int16_t item_type, int16_t item_subtype, int16_t mat case item_type::MEAT: case item_type::PLANT: - case item_type::LEAVES: +// case item_type::LEAVES: case item_type::CHEESE: value = 2; break; diff --git a/library/modules/MapCache.cpp b/library/modules/MapCache.cpp index da7683351..32f3e1248 100644 --- a/library/modules/MapCache.cpp +++ b/library/modules/MapCache.cpp @@ -728,9 +728,9 @@ void MapExtras::BlockInfo::prepare(Block *mblock) block = mblock->getRaw(); parent = mblock->getParent(); - column = Maps::getBlockColumn((block->map_pos.x/48)*3, (block->map_pos.y/48)*3); + column = Maps::getBlockColumn((block->map_pos.x / 48) * 3, (block->map_pos.y / 48) * 3); - SquashVeins(block,veinmats,veintype); + SquashVeins(block, veinmats, veintype); SquashGrass(block, grass); for (size_t i = 0; i < column->plants.size(); i++) @@ -738,40 +738,41 @@ void MapExtras::BlockInfo::prepare(Block *mblock) auto pp = column->plants[i]; // A plant without tree_info is single tile // TODO: verify that x any y lie inside the block. - if(!pp->tree_info) + if (!pp->tree_info) { - if(pp->pos.z == block->map_pos.z) + if (pp->pos.z == block->map_pos.z) plants[pp->pos] = pp; continue; } // tree_info contains vertical slices of the tree. This ensures there's a slice for our Z-level. df::plant_tree_info * info = pp->tree_info; - if(!((pp->pos.z-1 <= block->map_pos.z) && ((pp->pos.z+info->z_dim) > block->map_pos.z))) + if (!((pp->pos.z - info->roots_depth <= block->map_pos.z) && ((pp->pos.z + info->body_height) > block->map_pos.z))) continue; // Parse through a single horizontal slice of the tree. - for(int xx = 0; xx < info->x_dim;xx++) - for(int yy = 0; yy < info->y_dim;yy++) + for (int xx = 0; xx < info->dim_x; xx++) + for (int yy = 0; yy < info->dim_y; yy++) + { + // Any non-zero value here other than blocked means there's some sort of branch here. + // If the block is at or above the plant's base level, we use the body array + // otherwise we use the roots. + // TODO: verify that the tree bounds intersect the block. + df::plant_tree_tile tile; + int z_diff = block->map_pos.z - pp->pos.z; + if (z_diff >= 0) + tile = info->body[z_diff][xx + (yy*info->dim_x)]; + else + tile = info->roots[info->roots_depth - 1 - z_diff][xx + (yy*info->dim_x)]; + if (tile.whole && !(tile.bits.blocked)) { - // Any non-zero value here other than blocked means there's some sort of branch here. - // If the block is at or above the plant's base level, we use the body array - // otherwise we use the roots. - // TODO: verify that the tree bounds intersect the block. - df::plant_tree_tile tile; - int z_diff = block->map_pos.z-pp->pos.z; - if(z_diff >= 0) - tile = info->body[z_diff][xx+(yy*info->x_dim)]; - else tile = info->roots[0][xx+(yy*info->x_dim)]; - if(tile.whole && !(tile.bits.blocked)) - { - df::coord pos=pp->pos; - pos.x = pos.x - (info->x_dim/2) + xx; - pos.y = pos.y - (info->y_dim/2) + yy; - pos.z = block->map_pos.z; - plants[pos] = pp; - } + df::coord pos = pp->pos; + pos.x = pos.x - (info->dim_x / 2) + xx; + pos.y = pos.y - (info->dim_y / 2) + yy; + pos.z = block->map_pos.z; + plants[pos] = pp; } + } } global_feature = Maps::getGlobalInitFeature(block->global_feature); @@ -842,6 +843,7 @@ t_matpair MapExtras::BlockInfo::getBaseMaterial(df::tiletype tt, df::coord2d pos rv.mat_index = mblock->biomeInfoAt(pos).lava_stone; break; + case MUSHROOM: case ROOT: case TREE: case PLANT: diff --git a/library/modules/Maps.cpp b/library/modules/Maps.cpp index 2ad1f7821..6fa06d941 100644 --- a/library/modules/Maps.cpp +++ b/library/modules/Maps.cpp @@ -253,15 +253,15 @@ void Maps::enableBlockUpdates(df::map_block *blk, bool flow, bool temperature) blk->flags.bits.update_liquid_twice = true; } - auto z_flags = world->map.z_level_flags; - int z_level = blk->map_pos.z; - - if (z_flags && z_level >= 0 && z_level < world->map.z_count_block) - { - z_flags += z_level; - z_flags->bits.update = true; - z_flags->bits.update_twice = true; - } + //auto z_flags = world->map.z_level_flags; + //int z_level = blk->map_pos.z; + + //if (z_flags && z_level >= 0 && z_level < world->map.z_count_block) + //{ + // z_flags += z_level; + // z_flags->bits.update = true; + // z_flags->bits.update_twice = true; + //} } df::flow_info *Maps::spawnFlow(df::coord pos, df::flow_type type, int mat_type, int mat_index, int density) diff --git a/library/modules/Materials.cpp b/library/modules/Materials.cpp index 60a35fa2b..1fd4b80a1 100644 --- a/library/modules/Materials.cpp +++ b/library/modules/Materials.cpp @@ -479,7 +479,7 @@ void MaterialInfo::getMatchBits(df::job_item_flags1 &ok, df::job_item_flags1 &ma TEST(extract_bearing_fish, false); TEST(extract_bearing_vermin, false); TEST(processable_to_vial, structural && FLAG(plant, plant_raw_flags::EXTRACT_VIAL)); - TEST(processable_to_bag, structural && FLAG(plant, plant_raw_flags::LEAVES)); +// TEST(processable_to_bag, structural && FLAG(plant, plant_raw_flags::LEAVES)); TEST(processable_to_barrel, structural && FLAG(plant, plant_raw_flags::EXTRACT_BARREL)); TEST(solid, !(MAT_FLAG(ALCOHOL_PLANT) || MAT_FLAG(ALCOHOL_CREATURE) || diff --git a/library/modules/Translation.cpp b/library/modules/Translation.cpp index 90f8bbb81..53ec3bfba 100644 --- a/library/modules/Translation.cpp +++ b/library/modules/Translation.cpp @@ -153,17 +153,17 @@ string Translation::TranslateName(const df::language_name * name, bool inEnglish if (!name->nickname.empty()) { word = "`" + name->nickname + "'"; - switch (d_init ? d_init->nickname_dwarf : d_init_nickname::CENTRALIZE) - { - case d_init_nickname::REPLACE_ALL: - out = word; - return out; - case d_init_nickname::REPLACE_FIRST: - out = ""; - break; - case d_init_nickname::CENTRALIZE: - break; - } + //switch (d_init ? d_init->nickname_dwarf : d_init_nickname::CENTRALIZE) + //{ + //case d_init_nickname::REPLACE_ALL: + // out = word; + // return out; + //case d_init_nickname::REPLACE_FIRST: + // out = ""; + // break; + //case d_init_nickname::CENTRALIZE: + // break; + //} addNameWord(out, word); } } diff --git a/library/xml b/library/xml index c66ab3307..03ae01781 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit c66ab33071842bcfb7d37c3993f6a024923ca358 +Subproject commit 03ae01781aa1578a1d7a53dc09fe9bf33f59a356 diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index f2983a2ca..085cb7ba9 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -82,84 +82,84 @@ 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(3dveins 3dveins.cpp) - DFHACK_PLUGIN(add-spatter add-spatter.cpp) - DFHACK_PLUGIN(advtools advtools.cpp) - DFHACK_PLUGIN(autodump autodump.cpp) - DFHACK_PLUGIN(autolabor autolabor.cpp) - DFHACK_PLUGIN(automaterial automaterial.cpp) - DFHACK_PLUGIN(autotrade autotrade.cpp) - DFHACK_PLUGIN(burrows burrows.cpp LINK_LIBRARIES lua) - DFHACK_PLUGIN(building-hacks building-hacks.cpp LINK_LIBRARIES lua) - DFHACK_PLUGIN(buildingplan buildingplan.cpp) - DFHACK_PLUGIN(catsplosion catsplosion.cpp) - DFHACK_PLUGIN(changeitem changeitem.cpp) - DFHACK_PLUGIN(changelayer changelayer.cpp) - DFHACK_PLUGIN(changevein changevein.cpp) - DFHACK_PLUGIN(cleanconst cleanconst.cpp) - DFHACK_PLUGIN(cleaners cleaners.cpp) - DFHACK_PLUGIN(cleanowned cleanowned.cpp) - DFHACK_PLUGIN(colonies colonies.cpp) - DFHACK_PLUGIN(command-prompt command-prompt.cpp) - DFHACK_PLUGIN(createitem createitem.cpp) - DFHACK_PLUGIN(cursecheck cursecheck.cpp) - DFHACK_PLUGIN(deramp deramp.cpp) - DFHACK_PLUGIN(dig dig.cpp) - DFHACK_PLUGIN(digFlood digFlood.cpp) - add_subdirectory(diggingInvaders) - DFHACK_PLUGIN(drybuckets drybuckets.cpp) - DFHACK_PLUGIN(dwarfmonitor dwarfmonitor.cpp) - DFHACK_PLUGIN(embark-tools embark-tools.cpp) - DFHACK_PLUGIN(eventful eventful.cpp LINK_LIBRARIES lua) - DFHACK_PLUGIN(fastdwarf fastdwarf.cpp) - DFHACK_PLUGIN(feature feature.cpp) - DFHACK_PLUGIN(filltraffic filltraffic.cpp) - DFHACK_PLUGIN(fix-armory fix-armory.cpp) - DFHACK_PLUGIN(fixpositions fixpositions.cpp) - DFHACK_PLUGIN(fixveins fixveins.cpp) - DFHACK_PLUGIN(flows flows.cpp) - DFHACK_PLUGIN(follow follow.cpp) - DFHACK_PLUGIN(forceequip forceequip.cpp) - DFHACK_PLUGIN(getplants getplants.cpp) - DFHACK_PLUGIN(infiniteSky infiniteSky.cpp) - DFHACK_PLUGIN(initflags initflags.cpp) +# DFHACK_PLUGIN(3dveins 3dveins.cpp) +# DFHACK_PLUGIN(add-spatter add-spatter.cpp) +# DFHACK_PLUGIN(advtools advtools.cpp) +# DFHACK_PLUGIN(autodump autodump.cpp) +# DFHACK_PLUGIN(autolabor autolabor.cpp) +# DFHACK_PLUGIN(automaterial automaterial.cpp) +# DFHACK_PLUGIN(autotrade autotrade.cpp) +# DFHACK_PLUGIN(burrows burrows.cpp LINK_LIBRARIES lua) +# DFHACK_PLUGIN(building-hacks building-hacks.cpp LINK_LIBRARIES lua) +# DFHACK_PLUGIN(buildingplan buildingplan.cpp) +# DFHACK_PLUGIN(catsplosion catsplosion.cpp) +# DFHACK_PLUGIN(changeitem changeitem.cpp) +# DFHACK_PLUGIN(changelayer changelayer.cpp) +# DFHACK_PLUGIN(changevein changevein.cpp) +# DFHACK_PLUGIN(cleanconst cleanconst.cpp) +# DFHACK_PLUGIN(cleaners cleaners.cpp) +# DFHACK_PLUGIN(cleanowned cleanowned.cpp) +# DFHACK_PLUGIN(colonies colonies.cpp) +# DFHACK_PLUGIN(command-prompt command-prompt.cpp) +# DFHACK_PLUGIN(createitem createitem.cpp) +# DFHACK_PLUGIN(cursecheck cursecheck.cpp) +# DFHACK_PLUGIN(deramp deramp.cpp) +# DFHACK_PLUGIN(dig dig.cpp) +# DFHACK_PLUGIN(digFlood digFlood.cpp) +# add_subdirectory(diggingInvaders) +# DFHACK_PLUGIN(drybuckets drybuckets.cpp) +# DFHACK_PLUGIN(dwarfmonitor dwarfmonitor.cpp) +# DFHACK_PLUGIN(embark-tools embark-tools.cpp) +# DFHACK_PLUGIN(eventful eventful.cpp LINK_LIBRARIES lua) +# DFHACK_PLUGIN(fastdwarf fastdwarf.cpp) +# DFHACK_PLUGIN(feature feature.cpp) +# DFHACK_PLUGIN(filltraffic filltraffic.cpp) +# DFHACK_PLUGIN(fix-armory fix-armory.cpp) +# DFHACK_PLUGIN(fixpositions fixpositions.cpp) +# DFHACK_PLUGIN(fixveins fixveins.cpp) +# DFHACK_PLUGIN(flows flows.cpp) +# DFHACK_PLUGIN(follow follow.cpp) +# DFHACK_PLUGIN(forceequip forceequip.cpp) +# DFHACK_PLUGIN(getplants getplants.cpp) +# DFHACK_PLUGIN(infiniteSky infiniteSky.cpp) +# DFHACK_PLUGIN(initflags initflags.cpp) DFHACK_PLUGIN(isoworldremote isoworldremote.cpp PROTOBUFS isoworldremote) - DFHACK_PLUGIN(jobutils jobutils.cpp) - DFHACK_PLUGIN(lair lair.cpp) - DFHACK_PLUGIN(liquids liquids.cpp Brushes.h LINK_LIBRARIES lua) - DFHACK_PLUGIN(manipulator manipulator.cpp) - DFHACK_PLUGIN(mode mode.cpp) - DFHACK_PLUGIN(misery misery.cpp) - DFHACK_PLUGIN(mousequery mousequery.cpp) - DFHACK_PLUGIN(petcapRemover petcapRemover.cpp) - DFHACK_PLUGIN(plants plants.cpp) - DFHACK_PLUGIN(probe probe.cpp) - DFHACK_PLUGIN(prospector prospector.cpp) - DFHACK_PLUGIN(power-meter power-meter.cpp LINK_LIBRARIES lua) - DFHACK_PLUGIN(regrass regrass.cpp) +# DFHACK_PLUGIN(jobutils jobutils.cpp) +# DFHACK_PLUGIN(lair lair.cpp) +# DFHACK_PLUGIN(liquids liquids.cpp Brushes.h LINK_LIBRARIES lua) +# DFHACK_PLUGIN(manipulator manipulator.cpp) +# DFHACK_PLUGIN(mode mode.cpp) +# DFHACK_PLUGIN(misery misery.cpp) +# DFHACK_PLUGIN(mousequery mousequery.cpp) +# DFHACK_PLUGIN(petcapRemover petcapRemover.cpp) +# DFHACK_PLUGIN(plants plants.cpp) +# DFHACK_PLUGIN(probe probe.cpp) +# DFHACK_PLUGIN(prospector prospector.cpp) +# DFHACK_PLUGIN(power-meter power-meter.cpp LINK_LIBRARIES lua) +# DFHACK_PLUGIN(regrass regrass.cpp) DFHACK_PLUGIN(remotefortressreader remotefortressreader.cpp PROTOBUFS RemoteFortressReader) - DFHACK_PLUGIN(rename rename.cpp LINK_LIBRARIES lua PROTOBUFS rename) - add_subdirectory(rendermax) - DFHACK_PLUGIN(resume resume.cpp) - DFHACK_PLUGIN(reveal reveal.cpp) - DFHACK_PLUGIN(search search.cpp) - DFHACK_PLUGIN(seedwatch seedwatch.cpp) - DFHACK_PLUGIN(showmood showmood.cpp) - DFHACK_PLUGIN(siege-engine siege-engine.cpp LINK_LIBRARIES lua) - DFHACK_PLUGIN(sort sort.cpp LINK_LIBRARIES lua) - DFHACK_PLUGIN(steam-engine steam-engine.cpp) - DFHACK_PLUGIN(stockflow stockflow.cpp LINK_LIBRARIES lua) - DFHACK_PLUGIN(stockpiles stockpiles.cpp) - DFHACK_PLUGIN(stocks stocks.cpp) - DFHACK_PLUGIN(strangemood strangemood.cpp) - DFHACK_PLUGIN(tiletypes tiletypes.cpp Brushes.h) - DFHACK_PLUGIN(treefarm treefarm.cpp) - DFHACK_PLUGIN(tubefill tubefill.cpp) - DFHACK_PLUGIN(tweak tweak.cpp) - DFHACK_PLUGIN(weather weather.cpp) - DFHACK_PLUGIN(workflow workflow.cpp LINK_LIBRARIES lua) - DFHACK_PLUGIN(workNow workNow.cpp) - DFHACK_PLUGIN(zone zone.cpp LINK_LIBRARIES lua) +# DFHACK_PLUGIN(rename rename.cpp LINK_LIBRARIES lua PROTOBUFS rename) +# add_subdirectory(rendermax) +# DFHACK_PLUGIN(resume resume.cpp) +# DFHACK_PLUGIN(reveal reveal.cpp) +# DFHACK_PLUGIN(search search.cpp) +# DFHACK_PLUGIN(seedwatch seedwatch.cpp) +# DFHACK_PLUGIN(showmood showmood.cpp) +# DFHACK_PLUGIN(siege-engine siege-engine.cpp LINK_LIBRARIES lua) +# DFHACK_PLUGIN(sort sort.cpp LINK_LIBRARIES lua) +# DFHACK_PLUGIN(steam-engine steam-engine.cpp) +# DFHACK_PLUGIN(stockflow stockflow.cpp LINK_LIBRARIES lua) +# DFHACK_PLUGIN(stockpiles stockpiles.cpp) +# DFHACK_PLUGIN(stocks stocks.cpp) +# DFHACK_PLUGIN(strangemood strangemood.cpp) +# DFHACK_PLUGIN(tiletypes tiletypes.cpp Brushes.h) +# DFHACK_PLUGIN(treefarm treefarm.cpp) +# DFHACK_PLUGIN(tubefill tubefill.cpp) +# DFHACK_PLUGIN(tweak tweak.cpp) +# DFHACK_PLUGIN(weather weather.cpp) +# DFHACK_PLUGIN(workflow workflow.cpp LINK_LIBRARIES lua) +# DFHACK_PLUGIN(workNow workNow.cpp) +# DFHACK_PLUGIN(zone zone.cpp LINK_LIBRARIES lua) endif() # this is the skeleton plugin. If you want to make your own, make a copy and then change it diff --git a/plugins/proto/RemoteFortressReader.proto b/plugins/proto/RemoteFortressReader.proto index 15d60c8ed..b8f48a73b 100644 --- a/plugins/proto/RemoteFortressReader.proto +++ b/plugins/proto/RemoteFortressReader.proto @@ -147,4 +147,17 @@ message BlockList repeated MapBlock map_blocks = 1; optional int32 map_x = 2; optional int32 map_y = 3; +} + +message PlantDef +{ + required int32 pos_x = 1; + required int32 pos_y = 2; + required int32 pos_z = 3; + required int32 index = 4; +} + +message PlantList +{ + repeated PlantDef plant_list = 1; } \ No newline at end of file diff --git a/plugins/stonesense b/plugins/stonesense index 0d1954840..1b883efc2 160000 --- a/plugins/stonesense +++ b/plugins/stonesense @@ -1 +1 @@ -Subproject commit 0d19548402932c970c8a0d45404808cbe8fe1bcd +Subproject commit 1b883efc2a736b69c41316cc7c6eff4498d6aa9a From 08da62392e09f895cc09fa7c1c95c3e4bbec4fb0 Mon Sep 17 00:00:00 2001 From: JapaMala Date: Sat, 2 Aug 2014 17:09:59 +0530 Subject: [PATCH 4/7] Fixed a mistake where MapCache was using the wrong range for root depth. --- library/modules/MapCache.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/modules/MapCache.cpp b/library/modules/MapCache.cpp index 32f3e1248..5fc48789f 100644 --- a/library/modules/MapCache.cpp +++ b/library/modules/MapCache.cpp @@ -762,8 +762,8 @@ void MapExtras::BlockInfo::prepare(Block *mblock) int z_diff = block->map_pos.z - pp->pos.z; if (z_diff >= 0) tile = info->body[z_diff][xx + (yy*info->dim_x)]; - else - tile = info->roots[info->roots_depth - 1 - z_diff][xx + (yy*info->dim_x)]; + else + tile = info->roots[-1 - z_diff][xx + (yy*info->dim_x)]; if (tile.whole && !(tile.bits.blocked)) { df::coord pos = pp->pos; From b7c871eed76a16991fe5a094a6e2d37cee6dd493 Mon Sep 17 00:00:00 2001 From: JapaMala Date: Sat, 2 Aug 2014 17:12:19 +0530 Subject: [PATCH 5/7] gave t_matglossPair a few operator overloads so it can be used in std::map --- library/include/Types.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/library/include/Types.h b/library/include/Types.h index 5412b443b..6b175d180 100644 --- a/library/include/Types.h +++ b/library/include/Types.h @@ -38,6 +38,19 @@ namespace DFHack { int16_t type; int32_t index; + bool operator<(const t_matglossPair &b) const + { + if (type != b.type) return (type < b.type); + return (index < b.index); + } + bool operator==(const t_matglossPair &b) const + { + return (type == b.type) && (index == b.index); + } + bool operator!=(const t_matglossPair &b) const + { + return (type != b.type) || (index != b.index); + } }; template From 756485c4db0b15bc33663d6d2d0a1794b408b11e Mon Sep 17 00:00:00 2001 From: JapaMala Date: Fri, 8 Aug 2014 20:35:57 +0530 Subject: [PATCH 6/7] Added support for getting a list of plant growths with fake material names. --- library/xml | 2 +- plugins/CMakeLists.txt | 2 +- plugins/isoworld | 2 +- plugins/proto/RemoteFortressReader.proto | 1 + plugins/remotefortressreader.cpp | 118 ++++++++++++++++++++--- plugins/stonesense | 2 +- 6 files changed, 112 insertions(+), 15 deletions(-) diff --git a/library/xml b/library/xml index 03ae01781..0d6d3ae7e 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit 03ae01781aa1578a1d7a53dc09fe9bf33f59a356 +Subproject commit 0d6d3ae7ea6f2836b72472739f696a94ec2a3f01 diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 085cb7ba9..143d5dce3 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -133,7 +133,7 @@ if (BUILD_SUPPORTED) # DFHACK_PLUGIN(mousequery mousequery.cpp) # DFHACK_PLUGIN(petcapRemover petcapRemover.cpp) # DFHACK_PLUGIN(plants plants.cpp) -# DFHACK_PLUGIN(probe probe.cpp) + DFHACK_PLUGIN(probe probe.cpp) # DFHACK_PLUGIN(prospector prospector.cpp) # DFHACK_PLUGIN(power-meter power-meter.cpp LINK_LIBRARIES lua) # DFHACK_PLUGIN(regrass regrass.cpp) diff --git a/plugins/isoworld b/plugins/isoworld index aa3b1bd51..c1ceaf8f8 160000 --- a/plugins/isoworld +++ b/plugins/isoworld @@ -1 +1 @@ -Subproject commit aa3b1bd51f269c07b3235392fd7ed21fe9171f3f +Subproject commit c1ceaf8f8d55238843d983019339e20434040f74 diff --git a/plugins/proto/RemoteFortressReader.proto b/plugins/proto/RemoteFortressReader.proto index b8f48a73b..e65345b3e 100644 --- a/plugins/proto/RemoteFortressReader.proto +++ b/plugins/proto/RemoteFortressReader.proto @@ -107,6 +107,7 @@ message MapBlock required int32 map_y = 2; required int32 map_z = 3; repeated int32 tiles = 4; + repeated MatPair materials = 5; } message MatPair { diff --git a/plugins/remotefortressreader.cpp b/plugins/remotefortressreader.cpp index cfef6fcf7..538eb9696 100644 --- a/plugins/remotefortressreader.cpp +++ b/plugins/remotefortressreader.cpp @@ -25,6 +25,10 @@ #include "df/matter_state.h" #include "df/material_vec_ref.h" #include "df/builtin_mats.h" +#include "df/map_block_column.h" +#include "df/plant.h" +#include "df/plant_tree_info.h" +#include "df/plant_growth.h" #include "df/descriptor_color.h" #include "df/descriptor_pattern.h" @@ -55,11 +59,13 @@ using namespace std; // Here go all the command declarations... // mostly to allow having the mandatory stuff on top of the file and commands on the bottom +static command_result GetGrowthList(color_ostream &stream, const EmptyMessage *in, MaterialList *out); static command_result GetMaterialList(color_ostream &stream, const EmptyMessage *in, MaterialList *out); static command_result GetTiletypeList(color_ostream &stream, const EmptyMessage *in, TiletypeList *out); static command_result GetBlockList(color_ostream &stream, const BlockRequest *in, BlockList *out); +static command_result GetPlantList(color_ostream &stream, const BlockRequest *in, PlantList *out); static command_result CheckHashes(color_ostream &stream, const EmptyMessage *in); -void CopyBlock(df::map_block * DfBlock, RemoteFortressReader::MapBlock * NetBlock); +void CopyBlock(df::map_block * DfBlock, RemoteFortressReader::MapBlock * NetBlock, MapExtras::MapCache * MC); void FindChangedBlocks(); @@ -88,9 +94,11 @@ DFhackCExport RPCService *plugin_rpcconnect(color_ostream &) { RPCService *svc = new RPCService(); svc->addFunction("GetMaterialList", GetMaterialList); + svc->addFunction("GetGrowthList", GetGrowthList); svc->addFunction("GetBlockList", GetBlockList); svc->addFunction("CheckHashes", CheckHashes); svc->addFunction("GetTiletypeList", GetTiletypeList); + svc->addFunction("GetPlantList", GetPlantList); return svc; } @@ -405,8 +413,8 @@ static command_result GetMaterialList(color_ostream &stream, const EmptyMessage { mat.decode(0, i); MaterialDefinition *mat_def = out->add_material_list(); - mat_def->mutable_mat_pair()->set_mat_index(0); - mat_def->mutable_mat_pair()->set_mat_type(i); + mat_def->mutable_mat_pair()->set_mat_type(0); + mat_def->mutable_mat_pair()->set_mat_index(i); mat_def->set_id(mat.getToken()); mat_def->set_name(mat.toString()); //find the name at cave temperature; if (raws->inorganics[i]->material.state_color[GetState(&raws->inorganics[i]->material)] < raws->language.colors.size()) @@ -426,8 +434,8 @@ static command_result GetMaterialList(color_ostream &stream, const EmptyMessage { mat.decode(i, j); MaterialDefinition *mat_def = out->add_material_list(); - mat_def->mutable_mat_pair()->set_mat_index(i); - mat_def->mutable_mat_pair()->set_mat_type(j); + mat_def->mutable_mat_pair()->set_mat_type(i); + mat_def->mutable_mat_pair()->set_mat_index(j); mat_def->set_id(mat.getToken()); mat_def->set_name(mat.toString()); //find the name at cave temperature; if (raws->mat_table.builtin[i]->state_color[GetState(raws->mat_table.builtin[i])] < raws->language.colors.size()) @@ -446,8 +454,8 @@ static command_result GetMaterialList(color_ostream &stream, const EmptyMessage { mat.decode(j + 19, i); MaterialDefinition *mat_def = out->add_material_list(); - mat_def->mutable_mat_pair()->set_mat_index(j + 19); - mat_def->mutable_mat_pair()->set_mat_type(i); + mat_def->mutable_mat_pair()->set_mat_type(j + 19); + mat_def->mutable_mat_pair()->set_mat_index(i); mat_def->set_id(mat.getToken()); mat_def->set_name(mat.toString()); //find the name at cave temperature; if (creature->material[j]->state_color[GetState(creature->material[j])] < raws->language.colors.size()) @@ -466,8 +474,8 @@ static command_result GetMaterialList(color_ostream &stream, const EmptyMessage { mat.decode(j + 419, i); MaterialDefinition *mat_def = out->add_material_list(); - mat_def->mutable_mat_pair()->set_mat_index(j + 419); - mat_def->mutable_mat_pair()->set_mat_type(i); + mat_def->mutable_mat_pair()->set_mat_type(j + 419); + mat_def->mutable_mat_pair()->set_mat_index(i); mat_def->set_id(mat.getToken()); mat_def->set_name(mat.toString()); //find the name at cave temperature; if (plant->material[j]->state_color[GetState(plant->material[j])] < raws->language.colors.size()) @@ -482,23 +490,64 @@ static command_result GetMaterialList(color_ostream &stream, const EmptyMessage return CR_OK; } -void CopyBlock(df::map_block * DfBlock, RemoteFortressReader::MapBlock * NetBlock) +static command_result GetGrowthList(color_ostream &stream, const EmptyMessage *in, MaterialList *out) +{ + if (!Core::getInstance().isWorldLoaded()) { + //out->set_available(false); + return CR_OK; + } + + + + df::world_raws *raws = &df::global::world->raws; + for (int i = 0; i < raws->plants.all.size(); i++) + { + df::plant_raw * pp = raws->plants.all[i]; + if (!pp) + continue; + MaterialDefinition * basePlant = out->add_material_list(); + basePlant->set_id(pp->id + ":BASE"); + basePlant->set_name(pp->name); + basePlant->mutable_mat_pair()->set_mat_type(-1); + basePlant->mutable_mat_pair()->set_mat_index(i); + for (int g = 0; g < pp->growths.size(); g++) + { + df::plant_growth* growth = pp->growths[g]; + if (!growth) + continue; + MaterialDefinition * out_growth = out->add_material_list(); + out_growth->set_id(pp->id + ":" + growth->id); + out_growth->set_name(growth->name); + out_growth->mutable_mat_pair()->set_mat_type(g); + out_growth->mutable_mat_pair()->set_mat_index(i); + } + } + return CR_OK; +} + +void CopyBlock(df::map_block * DfBlock, RemoteFortressReader::MapBlock * NetBlock, MapExtras::MapCache * MC) { NetBlock->set_map_x(DfBlock->map_pos.x); NetBlock->set_map_y(DfBlock->map_pos.y); NetBlock->set_map_z(DfBlock->map_pos.z); + + MapExtras::Block * block = MC->BlockAtTile(DfBlock->map_pos); for (int yy = 0; yy < 16; yy++) { for (int xx = 0; xx < 16; xx++) { df::tiletype tile = DfBlock->tiletype[xx][yy]; NetBlock->add_tiles(tile); + RemoteFortressReader::MatPair * material = NetBlock->add_materials(); + material->set_mat_type(block->baseMaterialAt(df::coord2d(xx, yy)).mat_index); + material->set_mat_index(block->baseMaterialAt(df::coord2d(xx, yy)).mat_type); } } } static command_result GetBlockList(color_ostream &stream, const BlockRequest *in, BlockList *out) { + MapExtras::MapCache MC; //stream.print("Got request for blocks from (%d, %d, %d) to (%d, %d, %d).\n", in->min_x(), in->min_y(), in->min_z(), in->max_x(), in->max_y(), in->max_z()); for (int zz = in->min_z(); zz < in->max_z(); zz++) { @@ -510,10 +559,11 @@ static command_result GetBlockList(color_ostream &stream, const BlockRequest *in if (block == NULL) continue; RemoteFortressReader::MapBlock *net_block = out->add_map_blocks(); - CopyBlock(block, net_block); + CopyBlock(block, net_block,&MC); } } } + MC.trash(); return CR_OK; } @@ -537,3 +587,49 @@ static command_result GetTiletypeList(color_ostream &stream, const EmptyMessage } return CR_OK; } + +static command_result GetPlantList(color_ostream &stream, const BlockRequest *in, PlantList *out) +{ + int min_x = in->min_x() / 3; + int min_y = in->min_y() / 3; + int min_z = in->min_z(); + int max_x = in->max_x() / 3; + int max_y = in->max_y() / 3; + int max_z = in->max_z(); + + for (int xx = min_x; xx < max_x; xx++) + for (int yy = min_y; yy < max_y; yy++) + { + if (xx < 0 || yy < 0 || xx >= df::global::world->map.x_count_block || yy >= df::global::world->map.y_count_block) + continue; + df::map_block_column * column = df::global::world->map.column_index[xx][yy]; + for (int i = 0; i < column->plants.size(); i++) + { + df::plant * plant = column->plants[i]; + if (!plant->tree_info) + { + if (plant->pos.z < min_z || plant->pos.z >= max_z) + continue; + if (plant->pos.x < in->min_x() * 16 || plant->pos.x >= in->max_x() * 16) + continue; + if (plant->pos.y < in->min_y() * 16 || plant->pos.y >= in->max_y() * 16) + continue; + } + else + { + if (plant->pos.z - plant->tree_info->roots_depth < min_z || plant->pos.z + plant->tree_info->body_height > max_z) + continue; + if (plant->pos.x - plant->tree_info->dim_x / 2 < in->min_x() * 16 || plant->pos.x + plant->tree_info->dim_x / 2 >= in->max_x() * 16) + continue; + if (plant->pos.y - plant->tree_info->dim_y / 2 < in->min_y() * 16 || plant->pos.y + plant->tree_info->dim_y / 2 >= in->max_y() * 16) + continue; + } + RemoteFortressReader::PlantDef * out_plant = out->add_plant_list(); + out_plant->set_index(plant->material); + out_plant->set_pos_x(plant->pos.x); + out_plant->set_pos_y(plant->pos.y); + out_plant->set_pos_z(plant->pos.z); + } + } + return CR_OK; +} diff --git a/plugins/stonesense b/plugins/stonesense index 1b883efc2..6ecbe21ac 160000 --- a/plugins/stonesense +++ b/plugins/stonesense @@ -1 +1 @@ -Subproject commit 1b883efc2a736b69c41316cc7c6eff4498d6aa9a +Subproject commit 6ecbe21ac317d86806e501ca8e21f7f0eaf4333d From 493dd47383403851c219c29bafc1fbca981b2244 Mon Sep 17 00:00:00 2001 From: JapaMala Date: Fri, 15 Aug 2014 19:28:03 +0530 Subject: [PATCH 7/7] Updated df-structures and isoworld --- library/xml | 2 +- plugins/isoworld | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library/xml b/library/xml index fc3c5ce33..79039faae 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit fc3c5ce3329edcdca5dadb4c1f8b03b0c98f0472 +Subproject commit 79039faae62c88e59898264d4f50672995e83ed6 diff --git a/plugins/isoworld b/plugins/isoworld index c1ceaf8f8..cc9d48d02 160000 --- a/plugins/isoworld +++ b/plugins/isoworld @@ -1 +1 @@ -Subproject commit c1ceaf8f8d55238843d983019339e20434040f74 +Subproject commit cc9d48d02b3f1b6e70b8d5687915c7b770d965cc