Merge remote-tracking branch 'origin/perSaveScripts' into scriptOrganization
Conflicts: plugins/CMakeLists.txtdevelop
commit
0a16bc2e12
@ -1 +1 @@
|
|||||||
Subproject commit 8c0d23090539be98bc9c67b9070cbe080383ae9f
|
Subproject commit c66ab33071842bcfb7d37c3993f6a024923ca358
|
@ -0,0 +1,116 @@
|
|||||||
|
package RemoteFortressReader;
|
||||||
|
|
||||||
|
//Attempts to provide a complete framework for reading everything from a fortress needed for vizualization
|
||||||
|
option optimize_for = LITE_RUNTIME;
|
||||||
|
|
||||||
|
//We use shapes, etc, because the actual tiletypes may differ between DF versions.
|
||||||
|
enum TiletypeShape {
|
||||||
|
NO_SHAPE = -1;
|
||||||
|
EMPTY = 0;
|
||||||
|
FLOOR = 1;
|
||||||
|
BOULDER = 2;
|
||||||
|
PEBBLES = 3;
|
||||||
|
WALL = 4;
|
||||||
|
FORTIFICATION = 5;
|
||||||
|
STAIR_UP = 6;
|
||||||
|
STAIR_DOWN = 7;
|
||||||
|
STAIR_UPDOWN = 8;
|
||||||
|
RAMP = 9;
|
||||||
|
RAMP_TOP = 10;
|
||||||
|
BROOK_BED = 11;
|
||||||
|
BROOK_TOP = 12;
|
||||||
|
TREE = 13;
|
||||||
|
SAPLING = 14;
|
||||||
|
SHRUB = 15;
|
||||||
|
ENDLESS_PIT = 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum TiletypeSpecial {
|
||||||
|
NO_SPECIAL = -1;
|
||||||
|
NORMAL = 0;
|
||||||
|
RIVER_SOURCE = 1;
|
||||||
|
WATERFALL = 2;
|
||||||
|
SMOOTH = 3;
|
||||||
|
FURROWED = 4;
|
||||||
|
WET = 5;
|
||||||
|
DEAD = 6;
|
||||||
|
WORN_1 = 7;
|
||||||
|
WORN_2 = 8;
|
||||||
|
WORN_3 = 9;
|
||||||
|
TRACK = 10;
|
||||||
|
};
|
||||||
|
enum TiletypeMaterial {
|
||||||
|
NO_MATERIAL = -1;
|
||||||
|
AIR = 0;
|
||||||
|
SOIL = 1;
|
||||||
|
STONE = 2;
|
||||||
|
FEATURE = 3;
|
||||||
|
LAVA_STONE = 4;
|
||||||
|
MINERAL = 5;
|
||||||
|
FROZEN_LIQUID = 6;
|
||||||
|
CONSTRUCTION = 7;
|
||||||
|
GRASS_LIGHT = 8;
|
||||||
|
GRASS_DARK = 9;
|
||||||
|
GRASS_DRY = 10;
|
||||||
|
GRASS_DEAD = 11;
|
||||||
|
PLANT = 12;
|
||||||
|
HFS = 13;
|
||||||
|
CAMPFIRE = 14;
|
||||||
|
FIRE = 15;
|
||||||
|
ASHES = 16;
|
||||||
|
MAGMA = 17;
|
||||||
|
DRIFTWOOD = 18;
|
||||||
|
POOL = 19;
|
||||||
|
BROOK = 20;
|
||||||
|
RIVER = 21;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
message MatPair {
|
||||||
|
required int32 mat_type = 1;
|
||||||
|
required int32 mat_index = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ColorDefinition {
|
||||||
|
required int32 red = 1;
|
||||||
|
required int32 green = 2;
|
||||||
|
required int32 blue = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message MaterialDefinition{
|
||||||
|
required MatPair mat_pair = 1;
|
||||||
|
optional string id = 2;
|
||||||
|
optional string name = 3;
|
||||||
|
optional ColorDefinition state_color = 4; //Simplifying colors to assume room temperature.
|
||||||
|
}
|
||||||
|
|
||||||
|
message MaterialList{
|
||||||
|
repeated MaterialDefinition material_list = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message BlockRequest
|
||||||
|
{
|
||||||
|
optional int32 blocks_needed = 1;
|
||||||
|
optional int32 min_x = 2;
|
||||||
|
optional int32 max_x = 3;
|
||||||
|
optional int32 min_y = 4;
|
||||||
|
optional int32 max_y = 5;
|
||||||
|
optional int32 min_z = 6;
|
||||||
|
optional int32 max_z = 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
message BlockList
|
||||||
|
{
|
||||||
|
repeated MapBlock map_blocks = 1;
|
||||||
|
optional int32 map_x = 2;
|
||||||
|
optional int32 map_y = 3;
|
||||||
|
}
|
@ -0,0 +1,235 @@
|
|||||||
|
// 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 <Console.h>
|
||||||
|
#include <Export.h>
|
||||||
|
#include <PluginManager.h>
|
||||||
|
|
||||||
|
// DF data structure definition headers
|
||||||
|
#include "DataDefs.h"
|
||||||
|
#include "df/world.h"
|
||||||
|
#include "df/ui.h"
|
||||||
|
#include "df/item.h"
|
||||||
|
#include "df/creature_raw.h"
|
||||||
|
#include "df/caste_raw.h"
|
||||||
|
#include "df/body_part_raw.h"
|
||||||
|
#include "df/historical_figure.h"
|
||||||
|
|
||||||
|
#include "df/job_item.h"
|
||||||
|
#include "df/job_material_category.h"
|
||||||
|
#include "df/dfhack_material_category.h"
|
||||||
|
#include "df/matter_state.h"
|
||||||
|
#include "df/material_vec_ref.h"
|
||||||
|
#include "df/builtin_mats.h"
|
||||||
|
|
||||||
|
#include "df/descriptor_color.h"
|
||||||
|
#include "df/descriptor_pattern.h"
|
||||||
|
#include "df/descriptor_shape.h"
|
||||||
|
|
||||||
|
#include "df/physical_attribute_type.h"
|
||||||
|
#include "df/mental_attribute_type.h"
|
||||||
|
#include <df/color_modifier_raw.h>
|
||||||
|
|
||||||
|
//DFhack specific headers
|
||||||
|
#include "modules/Maps.h"
|
||||||
|
#include "modules/MapCache.h"
|
||||||
|
#include "modules/Materials.h"
|
||||||
|
#include "TileTypes.h"
|
||||||
|
|
||||||
|
//Needed for writing the protobuff stuff to a file.
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "RemoteFortressReader.pb.h"
|
||||||
|
|
||||||
|
#include "RemoteServer.h"
|
||||||
|
|
||||||
|
using namespace DFHack;
|
||||||
|
using namespace df::enums;
|
||||||
|
using namespace RemoteFortressReader;
|
||||||
|
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 GetMaterialList(color_ostream &stream, const EmptyMessage *in, MaterialList *out);
|
||||||
|
static command_result GetBlockList(color_ostream &stream, const BlockRequest *in, BlockList *out);
|
||||||
|
void CopyBlock(df::map_block * DfBlock, RemoteFortressReader::MapBlock * NetBlock);
|
||||||
|
void FindChangedBlocks();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 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("RemoteFortressReader");
|
||||||
|
|
||||||
|
// Mandatory init function. If you have some global state, create it here.
|
||||||
|
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
|
||||||
|
{
|
||||||
|
//// Fill the command list with your commands.
|
||||||
|
//commands.push_back(PluginCommand(
|
||||||
|
// "isoworldremote", "Dump north-west embark tile to text file for debug purposes.",
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
DFhackCExport RPCService *plugin_rpcconnect(color_ostream &)
|
||||||
|
{
|
||||||
|
RPCService *svc = new RPCService();
|
||||||
|
svc->addFunction("GetMaterialList", GetMaterialList);
|
||||||
|
svc->addFunction("GetBlockList", GetBlockList);
|
||||||
|
return svc;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
mat_def->mutable_state_color()->set_green(color->green);
|
||||||
|
mat_def->mutable_state_color()->set_blue(color->blue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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->add_tiletype_shapes((RemoteFortressReader::TiletypeShape)tileShape(tile));
|
||||||
|
NetBlock->add_tiletype_materials((RemoteFortressReader::TiletypeMaterial)tileMaterial(tile));
|
||||||
|
NetBlock->add_tiletype_specials((RemoteFortressReader::TiletypeSpecial)tileSpecial(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;
|
||||||
|
}
|
@ -1 +1 @@
|
|||||||
Subproject commit c0a2a9a2a6909cc79f9a564c8039caf8103010a8
|
Subproject commit 0d19548402932c970c8a0d45404808cbe8fe1bcd
|
@ -0,0 +1,31 @@
|
|||||||
|
-- Shows the warning about missing configuration file.
|
||||||
|
|
||||||
|
local gui = require 'gui'
|
||||||
|
local dlg = require 'gui.dialogs'
|
||||||
|
|
||||||
|
local dfhack_init = { text = 'dfhack.init', pen = COLOR_LIGHTCYAN }
|
||||||
|
local dfhack_init_example = { text = 'dfhack.init-example', pen = COLOR_LIGHTCYAN }
|
||||||
|
|
||||||
|
local message = {
|
||||||
|
'The ', dfhack_init, ' configuration file is missing. To customize', NEWLINE,
|
||||||
|
'your DFHack installation, rename the ', dfhack_init_example, ' file', NEWLINE,
|
||||||
|
'to ', dfhack_init, ' and edit it to suit your needs.', NEWLINE, NEWLINE,
|
||||||
|
'For now, ', dfhack_init_example, ' will be used instead.'
|
||||||
|
}
|
||||||
|
|
||||||
|
dfhack.print('\n')
|
||||||
|
|
||||||
|
for k,v in ipairs(message) do
|
||||||
|
if type(v) == 'table' then
|
||||||
|
dfhack.color(v.pen)
|
||||||
|
dfhack.print(v.text)
|
||||||
|
else
|
||||||
|
dfhack.color(COLOR_YELLOW)
|
||||||
|
dfhack.print(v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
dfhack.color(COLOR_RESET)
|
||||||
|
dfhack.print('\n\n')
|
||||||
|
|
||||||
|
dlg.showMessage('DFHack is not configured', message, COLOR_YELLOW)
|
Loading…
Reference in New Issue