Merge branch 'IsoRemote' of github.com:JapaMala/dfhack into IsoRemote

Conflicts:
	plugins/CMakeLists.txt
	plugins/isoworldremote.cpp
develop
Japa 2013-03-30 13:03:22 +05:30
commit 9981d21965
2 changed files with 386 additions and 386 deletions

@ -1,148 +1,148 @@
INCLUDE(Plugins.cmake) INCLUDE(Plugins.cmake)
# Dfusion plugin # Dfusion plugin
IF(UNIX) IF(UNIX)
OPTION(BUILD_DFUSION "Build DFusion." OFF) OPTION(BUILD_DFUSION "Build DFusion." OFF)
ELSE() ELSE()
OPTION(BUILD_DFUSION "Build DFusion." ON) OPTION(BUILD_DFUSION "Build DFusion." ON)
ENDIF() ENDIF()
if(BUILD_DFUSION) if(BUILD_DFUSION)
add_subdirectory (Dfusion) add_subdirectory (Dfusion)
endif() endif()
OPTION(BUILD_STONESENSE "Build stonesense (needs a checkout first)." OFF) OPTION(BUILD_STONESENSE "Build stonesense (needs a checkout first)." OFF)
if(BUILD_STONESENSE) if(BUILD_STONESENSE)
add_subdirectory (stonesense) add_subdirectory (stonesense)
endif() endif()
OPTION(BUILD_DEV_PLUGINS "Build developer plugins." OFF) OPTION(BUILD_DEV_PLUGINS "Build developer plugins." OFF)
if(BUILD_DEV_PLUGINS) if(BUILD_DEV_PLUGINS)
add_subdirectory (devel) add_subdirectory (devel)
endif() endif()
#It's dead :< #It's dead :<
#OPTION(BUILD_DF2MC "Build DF2MC (needs a checkout first)." OFF) #OPTION(BUILD_DF2MC "Build DF2MC (needs a checkout first)." OFF)
#if(BUILD_DF2MC) #if(BUILD_DF2MC)
# add_subdirectory (df2mc) # add_subdirectory (df2mc)
#endif() #endif()
OPTION(BUILD_MAPEXPORT "Build map exporter." ON) OPTION(BUILD_MAPEXPORT "Build map exporter." ON)
if (BUILD_MAPEXPORT) if (BUILD_MAPEXPORT)
add_subdirectory (mapexport) add_subdirectory (mapexport)
endif() endif()
OPTION(BUILD_DWARFEXPORT "Build dwarf exporter." ON) OPTION(BUILD_DWARFEXPORT "Build dwarf exporter." ON)
if (BUILD_DWARFEXPORT) if (BUILD_DWARFEXPORT)
add_subdirectory (dwarfexport) add_subdirectory (dwarfexport)
endif() endif()
OPTION(BUILD_RUBY "Build ruby binding." ON) OPTION(BUILD_RUBY "Build ruby binding." ON)
if (BUILD_RUBY) if (BUILD_RUBY)
add_subdirectory (ruby) add_subdirectory (ruby)
endif() endif()
install(DIRECTORY lua/ install(DIRECTORY lua/
DESTINATION ${DFHACK_LUA_DESTINATION}/plugins DESTINATION ${DFHACK_LUA_DESTINATION}/plugins
FILES_MATCHING PATTERN "*.lua") FILES_MATCHING PATTERN "*.lua")
install(DIRECTORY raw/ install(DIRECTORY raw/
DESTINATION ${DFHACK_DATA_DESTINATION}/raw DESTINATION ${DFHACK_DATA_DESTINATION}/raw
FILES_MATCHING PATTERN "*.txt") FILES_MATCHING PATTERN "*.txt")
install(DIRECTORY raw/ install(DIRECTORY raw/
DESTINATION ${DFHACK_DATA_DESTINATION}/raw DESTINATION ${DFHACK_DATA_DESTINATION}/raw
FILES_MATCHING PATTERN "*.diff") FILES_MATCHING PATTERN "*.diff")
# Protobuf # Protobuf
FILE(GLOB PROJECT_PROTOS ${CMAKE_CURRENT_SOURCE_DIR}/proto/*.proto) FILE(GLOB PROJECT_PROTOS ${CMAKE_CURRENT_SOURCE_DIR}/proto/*.proto)
STRING(REPLACE ".proto" ".pb.cc" PROJECT_PROTO_SRCS "${PROJECT_PROTOS}") STRING(REPLACE ".proto" ".pb.cc" PROJECT_PROTO_SRCS "${PROJECT_PROTOS}")
STRING(REPLACE ".proto" ".pb.h" PROJECT_PROTO_HDRS "${PROJECT_PROTOS}") STRING(REPLACE ".proto" ".pb.h" PROJECT_PROTO_HDRS "${PROJECT_PROTOS}")
ADD_CUSTOM_COMMAND( ADD_CUSTOM_COMMAND(
OUTPUT ${PROJECT_PROTO_SRCS} ${PROJECT_PROTO_HDRS} OUTPUT ${PROJECT_PROTO_SRCS} ${PROJECT_PROTO_HDRS}
COMMAND protoc-bin -I=${dfhack_SOURCE_DIR}/library/proto/ COMMAND protoc-bin -I=${dfhack_SOURCE_DIR}/library/proto/
-I=${CMAKE_CURRENT_SOURCE_DIR}/proto/ -I=${CMAKE_CURRENT_SOURCE_DIR}/proto/
--cpp_out=${CMAKE_CURRENT_SOURCE_DIR}/proto/ --cpp_out=${CMAKE_CURRENT_SOURCE_DIR}/proto/
${PROJECT_PROTOS} ${PROJECT_PROTOS}
DEPENDS protoc-bin ${PROJECT_PROTOS} DEPENDS protoc-bin ${PROJECT_PROTOS}
) )
SET_SOURCE_FILES_PROPERTIES( Brushes.h PROPERTIES HEADER_FILE_ONLY TRUE ) SET_SOURCE_FILES_PROPERTIES( Brushes.h PROPERTIES HEADER_FILE_ONLY TRUE )
# Plugins # Plugins
OPTION(BUILD_SUPPORTED "Build the supported plugins (reveal, probe, etc.)." ON) OPTION(BUILD_SUPPORTED "Build the supported plugins (reveal, probe, etc.)." ON)
if (BUILD_SUPPORTED) if (BUILD_SUPPORTED)
DFHACK_PLUGIN(reveal reveal.cpp) DFHACK_PLUGIN(reveal reveal.cpp)
DFHACK_PLUGIN(probe probe.cpp) DFHACK_PLUGIN(probe probe.cpp)
# this is a plugin which helps detect cursed creatures (vampires, necromancers, werebeasts, ...) # this is a plugin which helps detect cursed creatures (vampires, necromancers, werebeasts, ...)
DFHACK_PLUGIN(cursecheck cursecheck.cpp) DFHACK_PLUGIN(cursecheck cursecheck.cpp)
# automatically assign labors to dwarves! # automatically assign labors to dwarves!
DFHACK_PLUGIN(autolabor autolabor.cpp) DFHACK_PLUGIN(autolabor autolabor.cpp)
DFHACK_PLUGIN(dig dig.cpp) DFHACK_PLUGIN(dig dig.cpp)
DFHACK_PLUGIN(drybuckets drybuckets.cpp) DFHACK_PLUGIN(drybuckets drybuckets.cpp)
DFHACK_PLUGIN(getplants getplants.cpp) DFHACK_PLUGIN(getplants getplants.cpp)
DFHACK_PLUGIN(plants plants.cpp) DFHACK_PLUGIN(plants plants.cpp)
DFHACK_PLUGIN(fastdwarf fastdwarf.cpp) DFHACK_PLUGIN(fastdwarf fastdwarf.cpp)
DFHACK_PLUGIN(prospector prospector.cpp) DFHACK_PLUGIN(prospector prospector.cpp)
DFHACK_PLUGIN(cleaners cleaners.cpp) DFHACK_PLUGIN(cleaners cleaners.cpp)
DFHACK_PLUGIN(weather weather.cpp) DFHACK_PLUGIN(weather weather.cpp)
DFHACK_PLUGIN(colonies colonies.cpp) DFHACK_PLUGIN(colonies colonies.cpp)
DFHACK_PLUGIN(mode mode.cpp) DFHACK_PLUGIN(mode mode.cpp)
DFHACK_PLUGIN(liquids liquids.cpp Brushes.h LINK_LIBRARIES lua) DFHACK_PLUGIN(liquids liquids.cpp Brushes.h LINK_LIBRARIES lua)
DFHACK_PLUGIN(tiletypes tiletypes.cpp Brushes.h) DFHACK_PLUGIN(tiletypes tiletypes.cpp Brushes.h)
DFHACK_PLUGIN(tubefill tubefill.cpp) DFHACK_PLUGIN(tubefill tubefill.cpp)
DFHACK_PLUGIN(autodump autodump.cpp) DFHACK_PLUGIN(autodump autodump.cpp)
DFHACK_PLUGIN(cleanowned cleanowned.cpp) DFHACK_PLUGIN(cleanowned cleanowned.cpp)
DFHACK_PLUGIN(deramp deramp.cpp) DFHACK_PLUGIN(deramp deramp.cpp)
DFHACK_PLUGIN(flows flows.cpp) DFHACK_PLUGIN(flows flows.cpp)
DFHACK_PLUGIN(filltraffic filltraffic.cpp) DFHACK_PLUGIN(filltraffic filltraffic.cpp)
DFHACK_PLUGIN(seedwatch seedwatch.cpp) DFHACK_PLUGIN(seedwatch seedwatch.cpp)
DFHACK_PLUGIN(initflags initflags.cpp) DFHACK_PLUGIN(initflags initflags.cpp)
DFHACK_PLUGIN(stockpiles stockpiles.cpp) DFHACK_PLUGIN(stockpiles stockpiles.cpp)
DFHACK_PLUGIN(rename rename.cpp LINK_LIBRARIES lua PROTOBUFS rename) DFHACK_PLUGIN(rename rename.cpp LINK_LIBRARIES lua PROTOBUFS rename)
DFHACK_PLUGIN(jobutils jobutils.cpp) DFHACK_PLUGIN(jobutils jobutils.cpp)
DFHACK_PLUGIN(workflow workflow.cpp LINK_LIBRARIES lua) DFHACK_PLUGIN(workflow workflow.cpp LINK_LIBRARIES lua)
DFHACK_PLUGIN(showmood showmood.cpp) DFHACK_PLUGIN(showmood showmood.cpp)
DFHACK_PLUGIN(fixveins fixveins.cpp) DFHACK_PLUGIN(fixveins fixveins.cpp)
DFHACK_PLUGIN(fixpositions fixpositions.cpp) DFHACK_PLUGIN(fixpositions fixpositions.cpp)
DFHACK_PLUGIN(follow follow.cpp) DFHACK_PLUGIN(follow follow.cpp)
DFHACK_PLUGIN(changevein changevein.cpp) DFHACK_PLUGIN(changevein changevein.cpp)
DFHACK_PLUGIN(changelayer changelayer.cpp) DFHACK_PLUGIN(changelayer changelayer.cpp)
DFHACK_PLUGIN(changeitem changeitem.cpp) DFHACK_PLUGIN(changeitem changeitem.cpp)
DFHACK_PLUGIN(advtools advtools.cpp) DFHACK_PLUGIN(advtools advtools.cpp)
DFHACK_PLUGIN(tweak tweak.cpp) DFHACK_PLUGIN(tweak tweak.cpp)
DFHACK_PLUGIN(feature feature.cpp) DFHACK_PLUGIN(feature feature.cpp)
DFHACK_PLUGIN(lair lair.cpp) DFHACK_PLUGIN(lair lair.cpp)
DFHACK_PLUGIN(zone zone.cpp) DFHACK_PLUGIN(zone zone.cpp)
DFHACK_PLUGIN(catsplosion catsplosion.cpp) DFHACK_PLUGIN(catsplosion catsplosion.cpp)
DFHACK_PLUGIN(regrass regrass.cpp) DFHACK_PLUGIN(regrass regrass.cpp)
DFHACK_PLUGIN(forceequip forceequip.cpp) DFHACK_PLUGIN(forceequip forceequip.cpp)
DFHACK_PLUGIN(manipulator manipulator.cpp) DFHACK_PLUGIN(manipulator manipulator.cpp)
DFHACK_PLUGIN(search search.cpp) DFHACK_PLUGIN(search search.cpp)
DFHACK_PLUGIN(automaterial automaterial.cpp) DFHACK_PLUGIN(automaterial automaterial.cpp)
# this one exports functions to lua # this one exports functions to lua
DFHACK_PLUGIN(burrows burrows.cpp LINK_LIBRARIES lua) DFHACK_PLUGIN(burrows burrows.cpp LINK_LIBRARIES lua)
DFHACK_PLUGIN(sort sort.cpp LINK_LIBRARIES lua) DFHACK_PLUGIN(sort sort.cpp LINK_LIBRARIES lua)
DFHACK_PLUGIN(steam-engine steam-engine.cpp) DFHACK_PLUGIN(steam-engine steam-engine.cpp)
DFHACK_PLUGIN(power-meter power-meter.cpp LINK_LIBRARIES lua) DFHACK_PLUGIN(power-meter power-meter.cpp LINK_LIBRARIES lua)
DFHACK_PLUGIN(siege-engine siege-engine.cpp LINK_LIBRARIES lua) DFHACK_PLUGIN(siege-engine siege-engine.cpp LINK_LIBRARIES lua)
DFHACK_PLUGIN(eventful eventful.cpp LINK_LIBRARIES lua) DFHACK_PLUGIN(eventful eventful.cpp LINK_LIBRARIES lua)
DFHACK_PLUGIN(add-spatter add-spatter.cpp) DFHACK_PLUGIN(add-spatter add-spatter.cpp)
DFHACK_PLUGIN(fix-armory fix-armory.cpp) DFHACK_PLUGIN(fix-armory fix-armory.cpp)
# not yet. busy with other crud again... # not yet. busy with other crud again...
#DFHACK_PLUGIN(versionosd versionosd.cpp) #DFHACK_PLUGIN(versionosd versionosd.cpp)
DFHACK_PLUGIN(misery misery.cpp) DFHACK_PLUGIN(misery misery.cpp)
DFHACK_PLUGIN(workNow workNow.cpp) DFHACK_PLUGIN(workNow workNow.cpp)
#DFHACK_PLUGIN(dfstream dfstream.cpp LINK_LIBRARIES clsocket dfhack-tinythread) #DFHACK_PLUGIN(dfstream dfstream.cpp LINK_LIBRARIES clsocket dfhack-tinythread)
DFHACK_PLUGIN(autoSyndrome autoSyndrome.cpp) DFHACK_PLUGIN(autoSyndrome autoSyndrome.cpp)
DFHACK_PLUGIN(trueTransformation trueTransformation.cpp) DFHACK_PLUGIN(trueTransformation trueTransformation.cpp)
DFHACK_PLUGIN(infiniteSky infiniteSky.cpp) DFHACK_PLUGIN(infiniteSky infiniteSky.cpp)
DFHACK_PLUGIN(createitem createitem.cpp) DFHACK_PLUGIN(createitem createitem.cpp)
DFHACK_PLUGIN(isoworldremote isoworldremote.cpp PROTOBUFS isoworldremote) DFHACK_PLUGIN(isoworldremote isoworldremote.cpp PROTOBUFS isoworldremote)
endif() endif()
# this is the skeleton plugin. If you want to make your own, make a copy and then change it # 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) OPTION(BUILD_SKELETON "Build the skeleton plugin." OFF)
if(BUILD_SKELETON) if(BUILD_SKELETON)
add_subdirectory(skeleton) add_subdirectory(skeleton)
endif() endif()

@ -1,239 +1,239 @@
// This is a generic plugin that does nothing useful apart from acting as an example... of a plugin that does nothing :D // 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. // some headers required for a plugin. Nothing special, just the basics.
#include "Core.h" #include "Core.h"
#include <Console.h> #include <Console.h>
#include <Export.h> #include <Export.h>
#include <PluginManager.h> #include <PluginManager.h>
// DF data structure definition headers // DF data structure definition headers
#include "DataDefs.h" #include "DataDefs.h"
#include "df/world.h" #include "df/world.h"
#include "df/map_block.h" #include "df/map_block.h"
#include "df/builtin_mats.h" #include "df/builtin_mats.h"
#include "df/tile_designation.h" #include "df/tile_designation.h"
//DFhack specific headers //DFhack specific headers
#include "modules/Maps.h" #include "modules/Maps.h"
#include "modules/MapCache.h" #include "modules/MapCache.h"
#include "modules/Materials.h" #include "modules/Materials.h"
//Needed for writing the protobuff stuff to a file. //Needed for writing the protobuff stuff to a file.
#include <fstream> #include <fstream>
#include <string> #include <string>
#include <iomanip> #include <iomanip>
#include "isoworldremote.pb.h" #include "isoworldremote.pb.h"
using namespace DFHack; using namespace DFHack;
using namespace df::enums; using namespace df::enums;
using namespace isoworldremote; using namespace isoworldremote;
// Here go all the command declarations... // Here go all the command declarations...
// mostly to allow having the mandatory stuff on top of the file and commands on the bottom // 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 <std::string> & parameters); command_result isoWorldRemote (color_ostream &out, std::vector <std::string> & parameters);
void gather_embark_tile_layer(int EmbX, int EmbY, int EmbZ, EmbarkTileLayer * tile, MapExtras::MapCache * MP); 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); bool gather_embark_tile(int EmbX, int EmbY, EmbarkTile * tile, MapExtras::MapCache * MP);
// A plugin must be able to return its name and version. // 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 // The name string provided must correspond to the filename - skeleton.plug.so or skeleton.plug.dll in this case
DFHACK_PLUGIN("skeleton"); DFHACK_PLUGIN("skeleton");
// Mandatory init function. If you have some global state, create it here. // Mandatory init function. If you have some global state, create it here.
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands) DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
{ {
// Fill the command list with your commands. // Fill the command list with your commands.
commands.push_back(PluginCommand( commands.push_back(PluginCommand(
"isoworldremote", "Do nothing, look pretty.", "isoworldremote", "Do nothing, look pretty.",
isoWorldRemote, false, /* true means that the command can't be used from non-interactive user interface */ 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: // Extended help string. Used by CR_WRONG_USAGE and the help command:
" This command does nothing at all.\n" " This command does nothing at all.\n"
"Example:\n" "Example:\n"
" isoworldremote\n" " isoworldremote\n"
" Does nothing.\n" " Does nothing.\n"
)); ));
return CR_OK; return CR_OK;
} }
// This is called right before the plugin library is removed from memory. // 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. // You *MUST* kill all threads you created before this returns.
// If everything fails, just return CR_FAILURE. Your plugin will be // If everything fails, just return CR_FAILURE. Your plugin will be
// in a zombie state, but things won't crash. // in a zombie state, but things won't crash.
return CR_OK; return CR_OK;
} }
// Called to notify the plugin about important state changes. // Called to notify the plugin about important state changes.
// Invoked with DF suspended, and always before the matching plugin_onupdate. // Invoked with DF suspended, and always before the matching plugin_onupdate.
// More event codes may be added in the future. // More event codes may be added in the future.
/* /*
DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event) DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event)
{ {
switch (event) { switch (event) {
case SC_GAME_LOADED: case SC_GAME_LOADED:
// initialize from the world just loaded // initialize from the world just loaded
break; break;
case SC_GAME_UNLOADED: case SC_GAME_UNLOADED:
// cleanup // cleanup
break; break;
default: default:
break; break;
} }
return CR_OK; return CR_OK;
} }
*/ */
// Whatever you put here will be done in each game step. Don't abuse it. // 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. // 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 ) DFhackCExport command_result plugin_onupdate ( color_ostream &out )
{ {
// whetever. You don't need to suspend DF execution here. // whetever. You don't need to suspend DF execution here.
return CR_OK; return CR_OK;
} }
*/ */
// A command! It sits around and looks pretty. And it's nice and friendly. // A command! It sits around and looks pretty. And it's nice and friendly.
command_result isoWorldRemote (color_ostream &out, std::vector <std::string> & parameters) command_result isoWorldRemote (color_ostream &out, std::vector <std::string> & parameters)
{ {
// It's nice to print a help message you get invalid options // It's nice to print a help message you get invalid options
// from the user instead of just acting strange. // from the user instead of just acting strange.
// This can be achieved by adding the extended help string to the // This can be achieved by adding the extended help string to the
// PluginCommand registration as show above, and then returning // PluginCommand registration as show above, and then returning
// CR_WRONG_USAGE from the function. The same string will also // CR_WRONG_USAGE from the function. The same string will also
// be used by 'help your-command'. // be used by 'help your-command'.
if (!parameters.empty()) if (!parameters.empty())
return CR_WRONG_USAGE; return CR_WRONG_USAGE;
// Commands are called from threads other than the DF one. // Commands are called from threads other than the DF one.
// Suspend this thread until DF has time for us. If you // Suspend this thread until DF has time for us. If you
// use CoreSuspender, it'll automatically resume DF when // use CoreSuspender, it'll automatically resume DF when
// execution leaves the current scope. // execution leaves the current scope.
CoreSuspender suspend; CoreSuspender suspend;
// Actually do something here. Yay. // Actually do something here. Yay.
out.print("Doing a test...\n"); out.print("Doing a test...\n");
MapExtras::MapCache MC; MapExtras::MapCache MC;
EmbarkTile test_tile; EmbarkTile test_tile;
if(!gather_embark_tile(0,0, &test_tile, &MC)) if(!gather_embark_tile(0,0, &test_tile, &MC))
return CR_FAILURE; return CR_FAILURE;
//test-write the file to check it. //test-write the file to check it.
std::ofstream output_file("tile.p", std::ios_base::binary); std::ofstream output_file("tile.p", std::ios_base::binary);
output_file << test_tile.SerializeAsString(); output_file << test_tile.SerializeAsString();
output_file.close(); output_file.close();
//load it again to verify. //load it again to verify.
std::ifstream input_file("tile.p", std::ios_base::binary); std::ifstream input_file("tile.p", std::ios_base::binary);
std::string input_string( (std::istreambuf_iterator<char>(input_file) ), std::string input_string( (std::istreambuf_iterator<char>(input_file) ),
(std::istreambuf_iterator<char>() ) ); (std::istreambuf_iterator<char>() ) );
EmbarkTile verify_tile; EmbarkTile verify_tile;
verify_tile.ParseFromString(input_string); verify_tile.ParseFromString(input_string);
//write contents to text file. //write contents to text file.
std::ofstream debug_text("tile.txt", std::ios_base::trunc); 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; 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++) { for(int i = 0; i < verify_tile.tile_layer_size(); i++) {
debug_text << "layer: " << i << std::endl; debug_text << "layer: " << i << std::endl;
for(int j = 0; j < 48; j++) { for(int j = 0; j < 48; j++) {
debug_text << " "; debug_text << " ";
for(int k = 0; k < 48; k++) { for(int k = 0; k < 48; k++) {
debug_text << verify_tile.tile_layer(i).mat_type_table(j*48+k) << ","; debug_text << verify_tile.tile_layer(i).mat_type_table(j*48+k) << ",";
} }
debug_text << " "; debug_text << " ";
for(int k = 0; k < 48; k++) { 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::setw(3) << verify_tile.tile_layer(i).mat_subtype_table(j*48+k) << ",";
} }
debug_text << std::endl; debug_text << std::endl;
} }
debug_text << std::endl; debug_text << std::endl;
} }
//clean everything up. //clean everything up.
google::protobuf::ShutdownProtobufLibrary(); google::protobuf::ShutdownProtobufLibrary();
// Give control back to DF. // Give control back to DF.
return CR_OK; return CR_OK;
} }
int coord_to_index_48(int x, int y) { int coord_to_index_48(int x, int y) {
return y*48+x; return y*48+x;
} }
bool gather_embark_tile(int EmbX, int EmbY, EmbarkTile * tile, MapExtras::MapCache * MP) { bool gather_embark_tile(int EmbX, int EmbY, EmbarkTile * tile, MapExtras::MapCache * MP) {
DFCoord base_coord; DFCoord base_coord;
base_coord.x = EmbX; base_coord.x = EmbX;
base_coord.y = EmbY; base_coord.y = EmbY;
base_coord.z = 0; base_coord.z = 0;
MapExtras::Block * b = MP->BlockAt(base_coord); MapExtras::Block * b = MP->BlockAt(base_coord);
if(!b) return 0; if(!b) return 0;
df::coord map_pos = b->getRaw()->map_pos; df::coord map_pos = b->getRaw()->map_pos;
df::coord2d region_pos = b->getRaw()->region_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_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_y(region_pos.y*16+map_pos.y/3);
tile->set_world_z(map_pos.z); tile->set_world_z(map_pos.z);
for(int z = 0; z < MP->maxZ(); z++) for(int z = 0; z < MP->maxZ(); z++)
{ {
EmbarkTileLayer * tile_layer = tile->add_tile_layer(); EmbarkTileLayer * tile_layer = tile->add_tile_layer();
gather_embark_tile_layer(EmbX, EmbY, z, tile_layer, MP); gather_embark_tile_layer(EmbX, EmbY, z, tile_layer, MP);
} }
return 1; return 1;
} }
void gather_embark_tile_layer(int EmbX, int EmbY, int EmbZ, EmbarkTileLayer * tile, MapExtras::MapCache * MP) 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. 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_type_table(AIR);
tile->add_mat_subtype_table(0); tile->add_mat_subtype_table(0);
} }
for(int yy = 0; yy < 3; yy++) { for(int yy = 0; yy < 3; yy++) {
for(int xx = 0; xx < 3; xx++) { for(int xx = 0; xx < 3; xx++) {
DFCoord current_coord; DFCoord current_coord;
current_coord.x = EmbX+xx; current_coord.x = EmbX+xx;
current_coord.y = EmbY+yy; current_coord.y = EmbY+yy;
current_coord.z = EmbZ; current_coord.z = EmbZ;
MapExtras::Block * b = MP->BlockAt(current_coord); MapExtras::Block * b = MP->BlockAt(current_coord);
if(b && b->getRaw()) { if(b && b->getRaw()) {
for(int block_y=0; block_y<16; block_y++) { for(int block_y=0; block_y<16; block_y++) {
for(int block_x=0; block_x<16; block_x++) { for(int block_x=0; block_x<16; block_x++) {
df::coord2d block_coord; df::coord2d block_coord;
block_coord.x = block_x; block_coord.x = block_x;
block_coord.y = block_y; block_coord.y = block_y;
DFHack::t_matpair actual_mat = b->staticMaterialAt(block_coord); DFHack::t_matpair actual_mat = b->staticMaterialAt(block_coord);
df::tiletype tile_type = b->staticTiletypeAt(block_coord); df::tiletype tile_type = b->staticTiletypeAt(block_coord);
df::tile_designation designation = b->DesignationAt(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); 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 //make a new fake material at the given index
if(tileMaterial(tile_type) == tiletype_material::FROZEN_LIQUID) { //Ice. 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_type_table(array_index, BasicMaterial::LIQUID); //Ice is totally a liquid, shut up.
tile->set_mat_subtype_table(array_index, 0); tile->set_mat_subtype_table(array_index, 0);
} }
else if(designation.bits.flow_size) { //Contains either water or lava. else if(designation.bits.flow_size) { //Contains either water or lava.
tile->set_mat_type_table(array_index, BasicMaterial::LIQUID); tile->set_mat_type_table(array_index, BasicMaterial::LIQUID);
if(designation.bits.liquid_type) //Magma if(designation.bits.liquid_type) //Magma
tile->set_mat_subtype_table(array_index, 2); tile->set_mat_subtype_table(array_index, 2);
else //water else //water
tile->set_mat_subtype_table(array_index, 1); tile->set_mat_subtype_table(array_index, 1);
} }
else if(tileShapeBasic(tileShape(tile_type)) != tiletype_shape_basic::Open) { else if(tileShapeBasic(tileShape(tile_type)) != tiletype_shape_basic::Open) {
if(actual_mat.mat_type == builtin_mats::INORGANIC) { //inorganic if(actual_mat.mat_type == builtin_mats::INORGANIC) { //inorganic
tile->set_mat_type_table(array_index, BasicMaterial::INORGANIC); tile->set_mat_type_table(array_index, BasicMaterial::INORGANIC);
tile->set_mat_subtype_table(array_index, actual_mat.mat_index); tile->set_mat_subtype_table(array_index, actual_mat.mat_index);
} }
else if(actual_mat.mat_type >= 419) { //Wooden constructions. Different from growing plants. 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_type_table(array_index, BasicMaterial::WOOD);
tile->set_mat_subtype_table(array_index, actual_mat.mat_index); tile->set_mat_subtype_table(array_index, actual_mat.mat_index);
} }
else { //Unknown and unsupported stuff. Will just be drawn as grey. else { //Unknown and unsupported stuff. Will just be drawn as grey.
tile->set_mat_type_table(array_index, BasicMaterial::OTHER); tile->set_mat_type_table(array_index, BasicMaterial::OTHER);
tile->set_mat_subtype_table(array_index, actual_mat.mat_type); tile->set_mat_subtype_table(array_index, actual_mat.mat_type);
} }
} }
else { else {
tile->set_mat_type_table(array_index, BasicMaterial::AIR); tile->set_mat_type_table(array_index, BasicMaterial::AIR);
} }
} }
} }
} }
} }
} }
} }