2021-04-25 10:43:40 -06:00
|
|
|
/**
|
|
|
|
* Translates a region of tiles specified by the cursor and arguments/prompts
|
|
|
|
* into a series of blueprint files suitable for replay via quickfort.
|
|
|
|
*
|
|
|
|
* Written by cdombroski.
|
|
|
|
*/
|
2015-01-07 14:27:48 -07:00
|
|
|
|
2016-01-05 17:03:19 -07:00
|
|
|
#include <algorithm>
|
2020-07-15 17:57:14 -06:00
|
|
|
#include <sstream>
|
2016-01-05 17:03:19 -07:00
|
|
|
|
2021-05-04 14:19:49 -06:00
|
|
|
#include "Console.h"
|
|
|
|
#include "DataDefs.h"
|
2021-05-21 07:52:16 -06:00
|
|
|
#include "DataFuncs.h"
|
2021-05-04 14:19:49 -06:00
|
|
|
#include "DataIdentity.h"
|
2018-05-08 12:42:41 -06:00
|
|
|
#include "LuaTools.h"
|
2021-05-04 14:19:49 -06:00
|
|
|
#include "PluginManager.h"
|
2021-04-25 11:12:00 -06:00
|
|
|
#include "TileTypes.h"
|
2015-01-07 14:27:48 -07:00
|
|
|
|
2015-01-12 09:52:46 -07:00
|
|
|
#include "modules/Buildings.h"
|
2020-07-15 22:35:21 -06:00
|
|
|
#include "modules/Filesystem.h"
|
2015-01-12 09:52:46 -07:00
|
|
|
#include "modules/Gui.h"
|
|
|
|
|
2015-01-09 14:00:47 -07:00
|
|
|
#include "df/building_axle_horizontalst.h"
|
|
|
|
#include "df/building_bridgest.h"
|
|
|
|
#include "df/building_constructionst.h"
|
|
|
|
#include "df/building_furnacest.h"
|
|
|
|
#include "df/building_rollersst.h"
|
|
|
|
#include "df/building_screw_pumpst.h"
|
|
|
|
#include "df/building_siegeenginest.h"
|
|
|
|
#include "df/building_trapst.h"
|
|
|
|
#include "df/building_water_wheelst.h"
|
|
|
|
#include "df/building_workshopst.h"
|
2021-05-04 14:19:49 -06:00
|
|
|
#include "df/world.h"
|
2015-01-09 14:00:47 -07:00
|
|
|
|
2015-01-07 14:27:48 -07:00
|
|
|
using std::string;
|
|
|
|
using std::endl;
|
|
|
|
using std::vector;
|
|
|
|
using std::ofstream;
|
2015-01-14 12:08:54 -07:00
|
|
|
using std::pair;
|
2015-01-07 14:27:48 -07:00
|
|
|
using namespace DFHack;
|
|
|
|
|
|
|
|
DFHACK_PLUGIN("blueprint");
|
2021-05-04 14:19:49 -06:00
|
|
|
REQUIRE_GLOBAL(world);
|
2015-01-07 14:27:48 -07:00
|
|
|
|
2021-05-04 14:19:49 -06:00
|
|
|
struct blueprint_options {
|
|
|
|
// whether to display help
|
|
|
|
bool help = false;
|
2015-01-07 14:27:48 -07:00
|
|
|
|
2021-05-04 14:19:49 -06:00
|
|
|
// starting tile coordinate of the translation area (if not set then all
|
|
|
|
// coordinates are set to -30000)
|
|
|
|
df::coord start;
|
|
|
|
|
|
|
|
// dimensions of translation area. width and height are guaranteed to be
|
|
|
|
// greater than 0. depth can be positive or negative, but not zero.
|
|
|
|
int32_t width = 0;
|
|
|
|
int32_t height = 0;
|
|
|
|
int32_t depth = 0;
|
|
|
|
|
|
|
|
// base name to use for generated files
|
|
|
|
string name;
|
|
|
|
|
|
|
|
// whether to autodetect which phases to output
|
|
|
|
bool auto_phase = false;
|
|
|
|
|
|
|
|
// if not autodetecting, which phases to output
|
|
|
|
bool dig = false;
|
|
|
|
bool build = false;
|
|
|
|
bool place = false;
|
|
|
|
bool query = false;
|
|
|
|
|
|
|
|
static struct_identity _identity;
|
|
|
|
};
|
|
|
|
static const struct_field_info blueprint_options_fields[] = {
|
2021-05-05 14:16:04 -06:00
|
|
|
{ struct_field_info::PRIMITIVE, "help", offsetof(blueprint_options, help), &df::identity_traits<bool>::identity, 0, 0 },
|
|
|
|
{ struct_field_info::SUBSTRUCT, "start", offsetof(blueprint_options, start), &df::coord::_identity, 0, 0 },
|
|
|
|
{ struct_field_info::PRIMITIVE, "width", offsetof(blueprint_options, width), &df::identity_traits<int32_t>::identity, 0, 0 },
|
|
|
|
{ struct_field_info::PRIMITIVE, "height", offsetof(blueprint_options, height), &df::identity_traits<int32_t>::identity, 0, 0 },
|
|
|
|
{ struct_field_info::PRIMITIVE, "depth", offsetof(blueprint_options, depth), &df::identity_traits<int32_t>::identity, 0, 0 },
|
|
|
|
{ struct_field_info::PRIMITIVE, "name", offsetof(blueprint_options, name), df::identity_traits<string>::get(), 0, 0 },
|
|
|
|
{ struct_field_info::PRIMITIVE, "auto_phase", offsetof(blueprint_options, auto_phase), &df::identity_traits<bool>::identity, 0, 0 },
|
|
|
|
{ struct_field_info::PRIMITIVE, "dig", offsetof(blueprint_options, dig), &df::identity_traits<bool>::identity, 0, 0 },
|
|
|
|
{ struct_field_info::PRIMITIVE, "build", offsetof(blueprint_options, build), &df::identity_traits<bool>::identity, 0, 0 },
|
|
|
|
{ struct_field_info::PRIMITIVE, "place", offsetof(blueprint_options, place), &df::identity_traits<bool>::identity, 0, 0 },
|
|
|
|
{ struct_field_info::PRIMITIVE, "query", offsetof(blueprint_options, query), &df::identity_traits<bool>::identity, 0, 0 },
|
2021-05-04 14:19:49 -06:00
|
|
|
{ struct_field_info::END }
|
|
|
|
};
|
|
|
|
struct_identity blueprint_options::_identity(sizeof(blueprint_options), &df::allocator_fn<blueprint_options>, NULL, "blueprint_options", NULL, blueprint_options_fields);
|
|
|
|
|
2021-05-21 07:52:16 -06:00
|
|
|
command_result blueprint(color_ostream &, vector<string> &);
|
2015-01-07 14:27:48 -07:00
|
|
|
|
2021-05-21 07:52:16 -06:00
|
|
|
DFhackCExport command_result plugin_init(color_ostream &, vector<PluginCommand> &commands)
|
2015-01-07 14:27:48 -07:00
|
|
|
{
|
2021-04-25 10:43:40 -06:00
|
|
|
commands.push_back(PluginCommand("blueprint", "Record the structure of a live game map in a quickfort blueprint", blueprint, false));
|
2015-01-07 14:27:48 -07:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2021-05-21 07:52:16 -06:00
|
|
|
DFhackCExport command_result plugin_shutdown(color_ostream &)
|
2015-01-07 14:27:48 -07:00
|
|
|
{
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2021-05-21 07:52:16 -06:00
|
|
|
static pair<uint32_t, uint32_t> get_building_size(df::building* b)
|
2015-01-14 12:08:54 -07:00
|
|
|
{
|
|
|
|
return pair<uint32_t, uint32_t>(b->x2 - b->x1 + 1, b->y2 - b->y1 + 1);
|
|
|
|
}
|
|
|
|
|
2021-05-21 07:52:16 -06:00
|
|
|
static char get_tile_dig(int32_t x, int32_t y, int32_t z)
|
2015-01-08 10:17:18 -07:00
|
|
|
{
|
2021-05-21 07:52:16 -06:00
|
|
|
df::tiletype *tt = Maps::getTileType(x, y, z);
|
2021-04-25 11:17:51 -06:00
|
|
|
df::tiletype_shape ts = tileShape(tt ? *tt : tiletype::Void);
|
2015-01-08 10:17:18 -07:00
|
|
|
switch (ts)
|
|
|
|
{
|
2015-01-09 14:00:47 -07:00
|
|
|
case tiletype_shape::EMPTY:
|
2015-02-14 20:53:06 -07:00
|
|
|
case tiletype_shape::RAMP_TOP:
|
2015-01-08 10:17:18 -07:00
|
|
|
return 'h';
|
2015-01-09 14:00:47 -07:00
|
|
|
case tiletype_shape::FLOOR:
|
|
|
|
case tiletype_shape::BOULDER:
|
|
|
|
case tiletype_shape::PEBBLES:
|
|
|
|
case tiletype_shape::BROOK_TOP:
|
2015-01-08 10:17:18 -07:00
|
|
|
return 'd';
|
2015-01-09 14:00:47 -07:00
|
|
|
case tiletype_shape::FORTIFICATION:
|
|
|
|
return 'F';
|
|
|
|
case tiletype_shape::STAIR_UP:
|
2015-01-08 10:17:18 -07:00
|
|
|
return 'u';
|
2015-01-09 14:00:47 -07:00
|
|
|
case tiletype_shape::STAIR_DOWN:
|
2015-01-08 10:17:18 -07:00
|
|
|
return 'j';
|
2015-01-09 14:00:47 -07:00
|
|
|
case tiletype_shape::STAIR_UPDOWN:
|
2015-01-08 10:17:18 -07:00
|
|
|
return 'i';
|
2015-01-09 14:00:47 -07:00
|
|
|
case tiletype_shape::RAMP:
|
2015-01-08 10:17:18 -07:00
|
|
|
return 'r';
|
|
|
|
default:
|
|
|
|
return ' ';
|
|
|
|
}
|
|
|
|
}
|
2015-01-07 14:27:48 -07:00
|
|
|
|
2021-05-21 07:52:16 -06:00
|
|
|
static string get_tile_build(uint32_t x, uint32_t y, df::building* b)
|
2015-01-09 14:00:47 -07:00
|
|
|
{
|
2015-02-14 20:53:06 -07:00
|
|
|
if (! b)
|
2015-01-12 09:52:46 -07:00
|
|
|
return " ";
|
2018-04-06 00:18:15 -06:00
|
|
|
bool at_nw_corner = int32_t(x) == b->x1 && int32_t(y) == b->y1;
|
|
|
|
bool at_se_corner = int32_t(x) == b->x2 && int32_t(y) == b->y2;
|
|
|
|
bool at_center = int32_t(x) == b->centerx && int32_t(y) == b->centery;
|
2015-01-14 12:08:54 -07:00
|
|
|
pair<uint32_t, uint32_t> size = get_building_size(b);
|
2015-01-16 01:27:14 -07:00
|
|
|
stringstream out;// = stringstream();
|
2015-01-09 14:00:47 -07:00
|
|
|
switch(b->getType())
|
|
|
|
{
|
|
|
|
case building_type::Armorstand:
|
|
|
|
return "a";
|
|
|
|
case building_type::Bed:
|
|
|
|
return "b";
|
|
|
|
case building_type::Chair:
|
|
|
|
return "c";
|
|
|
|
case building_type::Door:
|
|
|
|
return "d";
|
|
|
|
case building_type::Floodgate:
|
|
|
|
return "x";
|
|
|
|
case building_type::Cabinet:
|
|
|
|
return "f";
|
|
|
|
case building_type::Box:
|
|
|
|
return "h";
|
|
|
|
//case building_type::Kennel is missing
|
|
|
|
case building_type::FarmPlot:
|
2015-01-14 12:08:54 -07:00
|
|
|
if(!at_nw_corner)
|
|
|
|
return "`";
|
|
|
|
out << "p(" << size.first << "x" << size.second << ")";
|
|
|
|
return out.str();
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::Weaponrack:
|
|
|
|
return "r";
|
|
|
|
case building_type::Statue:
|
|
|
|
return "s";
|
|
|
|
case building_type::Table:
|
|
|
|
return "t";
|
|
|
|
case building_type::RoadPaved:
|
2015-01-14 12:08:54 -07:00
|
|
|
if(! at_nw_corner)
|
|
|
|
return "`";
|
|
|
|
out << "o(" << size.first << "x" << size.second << ")";
|
|
|
|
return out.str();
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::RoadDirt:
|
2015-01-14 12:08:54 -07:00
|
|
|
if(! at_nw_corner)
|
|
|
|
return "`";
|
|
|
|
out << "O(" << size.first << "x" << size.second << ")";
|
|
|
|
return out.str();
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::Bridge:
|
2015-01-14 12:08:54 -07:00
|
|
|
if(! at_nw_corner)
|
|
|
|
return "`";
|
2015-01-09 14:00:47 -07:00
|
|
|
switch(((df::building_bridgest*) b)->direction)
|
|
|
|
{
|
|
|
|
case df::building_bridgest::T_direction::Down:
|
2015-01-14 12:08:54 -07:00
|
|
|
out << "gx";
|
|
|
|
break;
|
2015-01-09 14:00:47 -07:00
|
|
|
case df::building_bridgest::T_direction::Left:
|
2015-01-14 12:08:54 -07:00
|
|
|
out << "ga";
|
|
|
|
break;
|
2015-01-09 14:00:47 -07:00
|
|
|
case df::building_bridgest::T_direction::Up:
|
2015-01-14 12:08:54 -07:00
|
|
|
out << "gw";
|
|
|
|
break;
|
2015-01-09 14:00:47 -07:00
|
|
|
case df::building_bridgest::T_direction::Right:
|
2015-01-14 12:08:54 -07:00
|
|
|
out << "gd";
|
|
|
|
break;
|
2015-01-09 14:00:47 -07:00
|
|
|
case df::building_bridgest::T_direction::Retracting:
|
2015-01-14 12:08:54 -07:00
|
|
|
out << "gs";
|
|
|
|
break;
|
2015-01-09 14:00:47 -07:00
|
|
|
}
|
2015-01-14 12:08:54 -07:00
|
|
|
out << "(" << size.first << "x" << size.second << ")";
|
|
|
|
return out.str();
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::Well:
|
|
|
|
return "l";
|
|
|
|
case building_type::SiegeEngine:
|
2015-01-14 12:08:54 -07:00
|
|
|
if (! at_center)
|
|
|
|
return "`";
|
2015-01-12 09:52:46 -07:00
|
|
|
return ((df::building_siegeenginest*) b)->type == df::siegeengine_type::Ballista ? "ib" : "ic";
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::Workshop:
|
2015-01-14 12:08:54 -07:00
|
|
|
if (! at_center)
|
|
|
|
return "`";
|
2015-01-09 14:00:47 -07:00
|
|
|
switch (((df::building_workshopst*) b)->type)
|
|
|
|
{
|
|
|
|
case workshop_type::Leatherworks:
|
|
|
|
return "we";
|
|
|
|
case workshop_type::Quern:
|
|
|
|
return "wq";
|
|
|
|
case workshop_type::Millstone:
|
|
|
|
return "wM";
|
|
|
|
case workshop_type::Loom:
|
|
|
|
return "wo";
|
|
|
|
case workshop_type::Clothiers:
|
|
|
|
return "wk";
|
|
|
|
case workshop_type::Bowyers:
|
|
|
|
return "wb";
|
|
|
|
case workshop_type::Carpenters:
|
|
|
|
return "wc";
|
|
|
|
case workshop_type::MetalsmithsForge:
|
|
|
|
return "wf";
|
|
|
|
case workshop_type::MagmaForge:
|
|
|
|
return "wv";
|
|
|
|
case workshop_type::Jewelers:
|
|
|
|
return "wj";
|
|
|
|
case workshop_type::Masons:
|
|
|
|
return "wm";
|
|
|
|
case workshop_type::Butchers:
|
|
|
|
return "wu";
|
|
|
|
case workshop_type::Tanners:
|
|
|
|
return "wn";
|
|
|
|
case workshop_type::Craftsdwarfs:
|
|
|
|
return "wr";
|
|
|
|
case workshop_type::Siege:
|
|
|
|
return "ws";
|
|
|
|
case workshop_type::Mechanics:
|
|
|
|
return "wt";
|
|
|
|
case workshop_type::Still:
|
|
|
|
return "wl";
|
|
|
|
case workshop_type::Farmers:
|
|
|
|
return "ww";
|
|
|
|
case workshop_type::Kitchen:
|
|
|
|
return "wz";
|
|
|
|
case workshop_type::Fishery:
|
|
|
|
return "wh";
|
|
|
|
case workshop_type::Ashery:
|
|
|
|
return "wy";
|
|
|
|
case workshop_type::Dyers:
|
|
|
|
return "wd";
|
2018-04-06 00:18:15 -06:00
|
|
|
case workshop_type::Kennels:
|
|
|
|
return "k";
|
2015-01-09 14:00:47 -07:00
|
|
|
case workshop_type::Custom:
|
2018-04-06 00:18:15 -06:00
|
|
|
case workshop_type::Tool:
|
2015-01-09 14:00:47 -07:00
|
|
|
//can't do anything with custom workshop
|
2015-01-14 12:08:54 -07:00
|
|
|
return "`";
|
2015-01-09 14:00:47 -07:00
|
|
|
}
|
|
|
|
case building_type::Furnace:
|
2015-01-14 12:08:54 -07:00
|
|
|
if (! at_center)
|
|
|
|
return "`";
|
2015-01-09 14:00:47 -07:00
|
|
|
switch (((df::building_furnacest*) b)->type)
|
|
|
|
{
|
|
|
|
case furnace_type::WoodFurnace:
|
|
|
|
return "ew";
|
|
|
|
case furnace_type::Smelter:
|
|
|
|
return "es";
|
|
|
|
case furnace_type::GlassFurnace:
|
|
|
|
return "eg";
|
|
|
|
case furnace_type::Kiln:
|
|
|
|
return "ek";
|
|
|
|
case furnace_type::MagmaSmelter:
|
|
|
|
return "el";
|
|
|
|
case furnace_type::MagmaGlassFurnace:
|
|
|
|
return "ea";
|
|
|
|
case furnace_type::MagmaKiln:
|
|
|
|
return "en";
|
|
|
|
case furnace_type::Custom:
|
|
|
|
//can't do anything with custom furnace
|
2015-01-14 12:08:54 -07:00
|
|
|
return "`";
|
2015-01-09 14:00:47 -07:00
|
|
|
}
|
|
|
|
case building_type::WindowGlass:
|
|
|
|
return "y";
|
|
|
|
case building_type::WindowGem:
|
|
|
|
return "Y";
|
|
|
|
case building_type::Construction:
|
|
|
|
switch (((df::building_constructionst*) b)->type)
|
|
|
|
{
|
2018-04-06 00:18:15 -06:00
|
|
|
case construction_type::NONE:
|
|
|
|
return "`";
|
2015-01-09 14:00:47 -07:00
|
|
|
case construction_type::Fortification:
|
|
|
|
return "CF";
|
|
|
|
case construction_type::Wall:
|
|
|
|
return "CW";
|
|
|
|
case construction_type::Floor:
|
|
|
|
return "Cf";
|
|
|
|
case construction_type::UpStair:
|
|
|
|
return "Cu";
|
|
|
|
case construction_type::DownStair:
|
|
|
|
return "Cj";
|
|
|
|
case construction_type::UpDownStair:
|
|
|
|
return "Cx";
|
|
|
|
case construction_type::Ramp:
|
|
|
|
return "Cr";
|
|
|
|
case construction_type::TrackN:
|
|
|
|
return "trackN";
|
|
|
|
case construction_type::TrackS:
|
|
|
|
return "trackS";
|
|
|
|
case construction_type::TrackE:
|
|
|
|
return "trackE";
|
|
|
|
case construction_type::TrackW:
|
|
|
|
return "trackW";
|
|
|
|
case construction_type::TrackNS:
|
|
|
|
return "trackNS";
|
|
|
|
case construction_type::TrackNE:
|
|
|
|
return "trackNE";
|
|
|
|
case construction_type::TrackNW:
|
|
|
|
return "trackNW";
|
|
|
|
case construction_type::TrackSE:
|
|
|
|
return "trackSE";
|
|
|
|
case construction_type::TrackSW:
|
|
|
|
return "trackSW";
|
|
|
|
case construction_type::TrackEW:
|
|
|
|
return "trackEW";
|
|
|
|
case construction_type::TrackNSE:
|
|
|
|
return "trackNSE";
|
|
|
|
case construction_type::TrackNSW:
|
|
|
|
return "trackNSW";
|
|
|
|
case construction_type::TrackNEW:
|
|
|
|
return "trackNEW";
|
|
|
|
case construction_type::TrackSEW:
|
|
|
|
return "trackSEW";
|
|
|
|
case construction_type::TrackNSEW:
|
|
|
|
return "trackNSEW";
|
|
|
|
case construction_type::TrackRampN:
|
|
|
|
return "trackrampN";
|
|
|
|
case construction_type::TrackRampS:
|
|
|
|
return "trackrampS";
|
|
|
|
case construction_type::TrackRampE:
|
|
|
|
return "trackrampE";
|
|
|
|
case construction_type::TrackRampW:
|
|
|
|
return "trackrampW";
|
|
|
|
case construction_type::TrackRampNS:
|
|
|
|
return "trackrampNS";
|
|
|
|
case construction_type::TrackRampNE:
|
|
|
|
return "trackrampNE";
|
|
|
|
case construction_type::TrackRampNW:
|
|
|
|
return "trackrampNW";
|
|
|
|
case construction_type::TrackRampSE:
|
|
|
|
return "trackrampSE";
|
|
|
|
case construction_type::TrackRampSW:
|
|
|
|
return "trackrampSW";
|
|
|
|
case construction_type::TrackRampEW:
|
|
|
|
return "trackrampEW";
|
|
|
|
case construction_type::TrackRampNSE:
|
|
|
|
return "trackrampNSE";
|
|
|
|
case construction_type::TrackRampNSW:
|
|
|
|
return "trackrampNSW";
|
|
|
|
case construction_type::TrackRampNEW:
|
|
|
|
return "trackrampNEW";
|
|
|
|
case construction_type::TrackRampSEW:
|
|
|
|
return "trackrampSEW";
|
|
|
|
case construction_type::TrackRampNSEW:
|
|
|
|
return "trackrampNSEW";
|
|
|
|
}
|
|
|
|
case building_type::Shop:
|
2015-01-14 12:08:54 -07:00
|
|
|
if (! at_center)
|
|
|
|
return "`";
|
2015-01-09 14:00:47 -07:00
|
|
|
return "z";
|
|
|
|
case building_type::AnimalTrap:
|
|
|
|
return "m";
|
|
|
|
case building_type::Chain:
|
|
|
|
return "v";
|
|
|
|
case building_type::Cage:
|
|
|
|
return "j";
|
|
|
|
case building_type::TradeDepot:
|
2015-01-14 12:08:54 -07:00
|
|
|
if (! at_center)
|
|
|
|
return "`";
|
2015-01-09 14:00:47 -07:00
|
|
|
return "D";
|
|
|
|
case building_type::Trap:
|
|
|
|
switch (((df::building_trapst*) b)->trap_type)
|
|
|
|
{
|
|
|
|
case trap_type::StoneFallTrap:
|
|
|
|
return "Ts";
|
|
|
|
case trap_type::WeaponTrap:
|
|
|
|
return "Tw";
|
|
|
|
case trap_type::Lever:
|
|
|
|
return "Tl";
|
|
|
|
case trap_type::PressurePlate:
|
|
|
|
return "Tp";
|
|
|
|
case trap_type::CageTrap:
|
|
|
|
return "Tc";
|
|
|
|
case trap_type::TrackStop:
|
|
|
|
df::building_trapst* ts = (df::building_trapst*) b;
|
2015-01-14 12:08:54 -07:00
|
|
|
out << "CS";
|
2015-01-09 14:00:47 -07:00
|
|
|
if (ts->use_dump)
|
|
|
|
{
|
2015-02-14 20:53:06 -07:00
|
|
|
if (ts->dump_x_shift == 0)
|
2015-01-09 14:00:47 -07:00
|
|
|
{
|
|
|
|
if (ts->dump_y_shift > 0)
|
2015-01-14 12:08:54 -07:00
|
|
|
out << "dd";
|
2015-01-09 14:00:47 -07:00
|
|
|
else
|
2015-01-14 12:08:54 -07:00
|
|
|
out << "d";
|
2015-01-09 14:00:47 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (ts->dump_x_shift > 0)
|
2015-01-14 12:08:54 -07:00
|
|
|
out << "ddd";
|
2015-01-09 14:00:47 -07:00
|
|
|
else
|
2015-01-14 12:08:54 -07:00
|
|
|
out << "dddd";
|
2015-01-09 14:00:47 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
switch (ts->friction)
|
|
|
|
{
|
|
|
|
case 10:
|
2015-01-14 12:08:54 -07:00
|
|
|
out << "a";
|
2015-01-09 14:00:47 -07:00
|
|
|
case 50:
|
2015-01-14 12:08:54 -07:00
|
|
|
out << "a";
|
2015-01-09 14:00:47 -07:00
|
|
|
case 500:
|
2015-01-14 12:08:54 -07:00
|
|
|
out << "a";
|
2015-01-09 14:00:47 -07:00
|
|
|
case 10000:
|
2015-01-14 12:08:54 -07:00
|
|
|
out << "a";
|
2015-01-09 14:00:47 -07:00
|
|
|
}
|
2015-01-14 12:08:54 -07:00
|
|
|
return out.str();
|
2015-01-09 14:00:47 -07:00
|
|
|
}
|
|
|
|
case building_type::ScrewPump:
|
2015-01-14 12:08:54 -07:00
|
|
|
if (! at_se_corner) //screw pumps anchor at bottom/right
|
|
|
|
return "`";
|
2015-01-09 14:00:47 -07:00
|
|
|
switch (((df::building_screw_pumpst*) b)->direction)
|
|
|
|
{
|
|
|
|
case screw_pump_direction::FromNorth:
|
|
|
|
return "Msu";
|
|
|
|
case screw_pump_direction::FromEast:
|
|
|
|
return "Msk";
|
|
|
|
case screw_pump_direction::FromSouth:
|
|
|
|
return "Msm";
|
|
|
|
case screw_pump_direction::FromWest:
|
|
|
|
return "Msh";
|
|
|
|
}
|
|
|
|
case building_type::WaterWheel:
|
2015-01-14 12:08:54 -07:00
|
|
|
if (! at_center)
|
|
|
|
return "`";
|
2015-01-09 14:00:47 -07:00
|
|
|
//s swaps orientation which defaults to vertical
|
2015-01-14 12:08:54 -07:00
|
|
|
return ((df::building_water_wheelst*) b)->is_vertical ? "Mw" : "Mws";
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::Windmill:
|
2015-01-14 12:08:54 -07:00
|
|
|
if (! at_center)
|
|
|
|
return "`";
|
2015-01-09 14:00:47 -07:00
|
|
|
return "Mm";
|
|
|
|
case building_type::GearAssembly:
|
|
|
|
return "Mg";
|
|
|
|
case building_type::AxleHorizontal:
|
2015-01-14 12:08:54 -07:00
|
|
|
if (! at_nw_corner) //a guess based on how constructions work
|
|
|
|
return "`";
|
2015-01-09 14:00:47 -07:00
|
|
|
//same as water wheel but reversed
|
2015-01-14 12:08:54 -07:00
|
|
|
out << "Mh" << (((df::building_axle_horizontalst*) b)->is_vertical ? "s" : "")
|
|
|
|
<< "(" << size.first << "x" << size.second << ")";
|
|
|
|
return out.str();
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::AxleVertical:
|
|
|
|
return "Mv";
|
|
|
|
case building_type::Rollers:
|
2015-02-14 20:53:06 -07:00
|
|
|
if (! at_nw_corner)
|
2015-01-14 12:08:54 -07:00
|
|
|
return "`";
|
|
|
|
out << "Mr";
|
2015-01-09 14:00:47 -07:00
|
|
|
switch (((df::building_rollersst*) b)->direction)
|
|
|
|
{
|
|
|
|
case screw_pump_direction::FromNorth:
|
|
|
|
break;
|
|
|
|
case screw_pump_direction::FromEast:
|
2015-01-14 12:08:54 -07:00
|
|
|
out << "s";
|
2015-01-09 14:00:47 -07:00
|
|
|
case screw_pump_direction::FromSouth:
|
2015-01-14 12:08:54 -07:00
|
|
|
out << "s";
|
2015-02-14 20:53:06 -07:00
|
|
|
case screw_pump_direction::FromWest:
|
2015-01-14 12:08:54 -07:00
|
|
|
out << "s";
|
2015-01-09 14:00:47 -07:00
|
|
|
}
|
2015-01-14 12:08:54 -07:00
|
|
|
out << "(" << size.first << "x" << size.second << ")";
|
|
|
|
return out.str();
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::Support:
|
|
|
|
return "S";
|
|
|
|
case building_type::ArcheryTarget:
|
|
|
|
return "A";
|
|
|
|
case building_type::TractionBench:
|
|
|
|
return "R";
|
|
|
|
case building_type::Hatch:
|
|
|
|
return "H";
|
|
|
|
case building_type::Slab:
|
|
|
|
//how to mine alt key?!?
|
|
|
|
//alt+s
|
|
|
|
return " ";
|
|
|
|
case building_type::NestBox:
|
|
|
|
return "N";
|
|
|
|
case building_type::Hive:
|
|
|
|
//alt+h
|
|
|
|
return " ";
|
|
|
|
case building_type::GrateWall:
|
|
|
|
return "W";
|
|
|
|
case building_type::GrateFloor:
|
|
|
|
return "G";
|
|
|
|
case building_type::BarsVertical:
|
|
|
|
return "B";
|
|
|
|
case building_type::BarsFloor:
|
|
|
|
//alt+b
|
|
|
|
return " ";
|
|
|
|
default:
|
|
|
|
return " ";
|
|
|
|
}
|
|
|
|
}
|
2015-01-08 10:17:18 -07:00
|
|
|
|
2021-05-21 07:52:16 -06:00
|
|
|
static string get_tile_place(uint32_t x, uint32_t y, df::building* b)
|
2015-01-13 12:28:28 -07:00
|
|
|
{
|
|
|
|
if (! b || b->getType() != building_type::Stockpile)
|
2015-01-14 12:08:54 -07:00
|
|
|
return " ";
|
2018-04-06 00:18:15 -06:00
|
|
|
if (b->x1 != int32_t(x) || b->y1 != int32_t(y))
|
2015-01-14 12:08:54 -07:00
|
|
|
return "`";
|
|
|
|
pair<uint32_t, uint32_t> size = get_building_size(b);
|
2015-01-13 12:28:28 -07:00
|
|
|
df::building_stockpilest* sp = (df::building_stockpilest*) b;
|
2015-01-16 01:27:14 -07:00
|
|
|
stringstream out;// = stringstream();
|
2015-01-13 12:28:28 -07:00
|
|
|
switch (sp->settings.flags.whole)
|
|
|
|
{
|
|
|
|
case df::stockpile_group_set::mask_animals:
|
2015-01-14 12:08:54 -07:00
|
|
|
out << "a";
|
|
|
|
break;
|
2015-01-13 12:28:28 -07:00
|
|
|
case df::stockpile_group_set::mask_food:
|
2015-01-14 12:08:54 -07:00
|
|
|
out << "f";
|
|
|
|
break;
|
2015-01-13 12:28:28 -07:00
|
|
|
case df::stockpile_group_set::mask_furniture:
|
2015-01-14 12:08:54 -07:00
|
|
|
out << "u";
|
|
|
|
break;
|
2015-01-13 12:28:28 -07:00
|
|
|
case df::stockpile_group_set::mask_corpses:
|
2015-01-14 12:08:54 -07:00
|
|
|
out << "y";
|
|
|
|
break;
|
2015-01-13 12:28:28 -07:00
|
|
|
case df::stockpile_group_set::mask_refuse:
|
2015-01-14 12:08:54 -07:00
|
|
|
out << "r";
|
|
|
|
break;
|
2015-01-13 12:28:28 -07:00
|
|
|
case df::stockpile_group_set::mask_wood:
|
2015-01-14 12:08:54 -07:00
|
|
|
out << "w";
|
|
|
|
break;
|
2015-01-13 12:28:28 -07:00
|
|
|
case df::stockpile_group_set::mask_stone:
|
2015-01-14 12:08:54 -07:00
|
|
|
out << "s";
|
|
|
|
break;
|
2015-01-13 12:28:28 -07:00
|
|
|
case df::stockpile_group_set::mask_gems:
|
2015-01-14 12:08:54 -07:00
|
|
|
out << "e";
|
|
|
|
break;
|
2015-01-13 12:28:28 -07:00
|
|
|
case df::stockpile_group_set::mask_bars_blocks:
|
2015-01-14 12:08:54 -07:00
|
|
|
out << "b";
|
|
|
|
break;
|
2015-01-13 12:28:28 -07:00
|
|
|
case df::stockpile_group_set::mask_cloth:
|
2015-01-14 12:08:54 -07:00
|
|
|
out << "h";
|
|
|
|
break;
|
2015-01-13 12:28:28 -07:00
|
|
|
case df::stockpile_group_set::mask_leather:
|
2015-01-14 12:08:54 -07:00
|
|
|
out << "l";
|
|
|
|
break;
|
2015-01-13 12:28:28 -07:00
|
|
|
case df::stockpile_group_set::mask_ammo:
|
2015-01-14 12:08:54 -07:00
|
|
|
out << "z";
|
|
|
|
break;
|
2015-01-13 12:28:28 -07:00
|
|
|
case df::stockpile_group_set::mask_coins:
|
2015-01-14 12:08:54 -07:00
|
|
|
out << "n";
|
|
|
|
break;
|
2015-01-13 12:28:28 -07:00
|
|
|
case df::stockpile_group_set::mask_finished_goods:
|
2015-01-14 12:08:54 -07:00
|
|
|
out << "g";
|
|
|
|
break;
|
2015-01-13 12:28:28 -07:00
|
|
|
case df::stockpile_group_set::mask_weapons:
|
2015-01-14 12:08:54 -07:00
|
|
|
out << "p";
|
|
|
|
break;
|
2015-01-13 12:28:28 -07:00
|
|
|
case df::stockpile_group_set::mask_armor:
|
2015-02-14 20:53:06 -07:00
|
|
|
out << "d";
|
2015-01-14 12:08:54 -07:00
|
|
|
break;
|
2015-01-13 12:28:28 -07:00
|
|
|
default: //multiple stockpile type
|
2015-01-14 12:08:54 -07:00
|
|
|
return "`";
|
2015-01-13 12:28:28 -07:00
|
|
|
}
|
2015-01-14 12:08:54 -07:00
|
|
|
out << "("<< size.first << "x" << size.second << ")";
|
|
|
|
return out.str();
|
2015-01-13 12:28:28 -07:00
|
|
|
}
|
|
|
|
|
2021-05-21 07:52:16 -06:00
|
|
|
static string get_tile_query(df::building* b)
|
2015-01-13 14:15:54 -07:00
|
|
|
{
|
|
|
|
if (b && b->is_room)
|
|
|
|
return "r+";
|
|
|
|
return " ";
|
|
|
|
}
|
|
|
|
|
2021-06-29 15:25:30 -06:00
|
|
|
// can remove once we move to C++20
|
|
|
|
static bool ends_with(const string &str, const string &sv)
|
|
|
|
{
|
|
|
|
if (sv.size() > str.size())
|
|
|
|
return false;
|
|
|
|
return str.substr(str.size() - sv.size()) == sv;
|
|
|
|
}
|
|
|
|
|
2021-05-21 07:52:16 -06:00
|
|
|
// returns filename
|
|
|
|
static string init_stream(ofstream &out, string basename, string target)
|
2020-07-15 17:57:14 -06:00
|
|
|
{
|
2020-07-15 22:35:21 -06:00
|
|
|
std::ostringstream out_path;
|
2021-06-29 15:25:30 -06:00
|
|
|
string separator = ends_with(basename, "/") ? "" : "-";
|
|
|
|
out_path << basename << separator << target << ".csv";
|
2021-05-21 07:52:16 -06:00
|
|
|
string path = out_path.str();
|
|
|
|
out.open(path, ofstream::trunc);
|
2020-07-15 17:57:14 -06:00
|
|
|
out << "#" << target << endl;
|
2021-05-21 07:52:16 -06:00
|
|
|
return path;
|
2020-07-15 17:57:14 -06:00
|
|
|
}
|
|
|
|
|
2021-05-21 07:52:16 -06:00
|
|
|
static bool do_transform(const DFCoord &start, const DFCoord &end,
|
|
|
|
const blueprint_options &options,
|
|
|
|
vector<string> &files,
|
|
|
|
std::ostringstream &err)
|
2015-01-07 14:27:48 -07:00
|
|
|
{
|
|
|
|
ofstream dig, build, place, query;
|
2020-07-15 17:57:14 -06:00
|
|
|
|
2021-05-04 14:19:49 -06:00
|
|
|
string basename = "blueprints/" + options.name;
|
2020-07-15 22:35:21 -06:00
|
|
|
size_t last_slash = basename.find_last_of("/");
|
2021-05-04 14:19:49 -06:00
|
|
|
string parent_path = basename.substr(0, last_slash);
|
2020-07-15 17:57:14 -06:00
|
|
|
|
|
|
|
// create output directory if it doesn't already exist
|
|
|
|
std::error_code ec;
|
2020-07-15 22:35:21 -06:00
|
|
|
if (!Filesystem::mkdir_recursive(parent_path))
|
2020-07-15 17:57:14 -06:00
|
|
|
{
|
2020-07-15 22:35:21 -06:00
|
|
|
err << "could not create output directory: '" << parent_path << "'";
|
2021-05-21 07:52:16 -06:00
|
|
|
return false;
|
2020-07-15 17:57:14 -06:00
|
|
|
}
|
|
|
|
|
2021-05-21 07:52:16 -06:00
|
|
|
if (options.auto_phase || options.dig)
|
2015-01-07 14:27:48 -07:00
|
|
|
{
|
2021-05-21 07:52:16 -06:00
|
|
|
files.push_back(init_stream(dig, basename, "dig"));
|
2015-01-14 12:58:15 -07:00
|
|
|
}
|
2021-05-21 07:52:16 -06:00
|
|
|
if (options.auto_phase || options.build)
|
2015-01-14 12:58:15 -07:00
|
|
|
{
|
2021-05-21 07:52:16 -06:00
|
|
|
files.push_back(init_stream(build, basename, "build"));
|
2015-01-14 12:58:15 -07:00
|
|
|
}
|
2021-05-21 07:52:16 -06:00
|
|
|
if (options.auto_phase || options.place)
|
2015-01-14 12:58:15 -07:00
|
|
|
{
|
2021-05-21 07:52:16 -06:00
|
|
|
files.push_back(init_stream(place, basename, "place"));
|
2015-01-14 12:58:15 -07:00
|
|
|
}
|
2021-05-21 07:52:16 -06:00
|
|
|
if (options.auto_phase || options.query)
|
2015-01-14 12:58:15 -07:00
|
|
|
{
|
2021-05-21 07:52:16 -06:00
|
|
|
files.push_back(init_stream(query, basename, "query"));
|
2015-01-07 14:27:48 -07:00
|
|
|
}
|
|
|
|
|
2021-05-04 14:19:49 -06:00
|
|
|
const int32_t z_inc = start.z < end.z ? 1 : -1;
|
|
|
|
const string z_key = start.z < end.z ? "#<" : "#>";
|
|
|
|
for (int32_t z = start.z; z != end.z; z += z_inc)
|
2015-01-07 14:27:48 -07:00
|
|
|
{
|
2015-01-08 10:17:18 -07:00
|
|
|
for (int32_t y = start.y; y < end.y; y++)
|
2015-01-07 14:27:48 -07:00
|
|
|
{
|
2015-01-08 10:17:18 -07:00
|
|
|
for (int32_t x = start.x; x < end.x; x++)
|
2015-01-07 14:27:48 -07:00
|
|
|
{
|
2021-05-04 14:19:49 -06:00
|
|
|
df::building* b = Buildings::findAtTile(DFCoord(x, y, z));
|
|
|
|
if (options.auto_phase || options.query)
|
2015-01-13 14:15:54 -07:00
|
|
|
query << get_tile_query(b) << ',';
|
2021-05-04 14:19:49 -06:00
|
|
|
if (options.auto_phase || options.place)
|
2015-01-14 12:08:54 -07:00
|
|
|
place << get_tile_place(x, y, b) << ',';
|
2021-05-04 14:19:49 -06:00
|
|
|
if (options.auto_phase || options.build)
|
2015-01-14 12:08:54 -07:00
|
|
|
build << get_tile_build(x, y, b) << ',';
|
2021-05-04 14:19:49 -06:00
|
|
|
if (options.auto_phase || options.dig)
|
2021-04-25 10:43:40 -06:00
|
|
|
dig << get_tile_dig(x, y, z) << ',';
|
2015-01-07 14:27:48 -07:00
|
|
|
}
|
2021-05-04 14:19:49 -06:00
|
|
|
if (options.auto_phase || options.query)
|
2015-01-07 14:27:48 -07:00
|
|
|
query << "#" << endl;
|
2021-05-04 14:19:49 -06:00
|
|
|
if (options.auto_phase || options.place)
|
2015-01-07 14:27:48 -07:00
|
|
|
place << "#" << endl;
|
2021-05-04 14:19:49 -06:00
|
|
|
if (options.auto_phase || options.build)
|
2015-01-08 10:17:18 -07:00
|
|
|
build << "#" << endl;
|
2021-05-04 14:19:49 -06:00
|
|
|
if (options.auto_phase || options.dig)
|
2015-01-07 14:27:48 -07:00
|
|
|
dig << "#" << endl;
|
|
|
|
}
|
2021-05-04 14:19:49 -06:00
|
|
|
if (z != end.z - z_inc)
|
2015-01-14 12:58:15 -07:00
|
|
|
{
|
2021-05-04 14:19:49 -06:00
|
|
|
if (options.auto_phase || options.query)
|
|
|
|
query << z_key << endl;
|
|
|
|
if (options.auto_phase || options.place)
|
|
|
|
place << z_key << endl;
|
|
|
|
if (options.auto_phase || options.build)
|
|
|
|
build << z_key << endl;
|
|
|
|
if (options.auto_phase || options.dig)
|
|
|
|
dig << z_key << endl;
|
2015-01-09 14:00:47 -07:00
|
|
|
}
|
2015-01-07 14:27:48 -07:00
|
|
|
}
|
2021-05-04 14:19:49 -06:00
|
|
|
if (options.auto_phase || options.query)
|
2015-01-07 14:27:48 -07:00
|
|
|
query.close();
|
2021-05-04 14:19:49 -06:00
|
|
|
if (options.auto_phase || options.place)
|
2015-01-07 14:27:48 -07:00
|
|
|
place.close();
|
2021-05-04 14:19:49 -06:00
|
|
|
if (options.auto_phase || options.build)
|
2015-01-08 10:17:18 -07:00
|
|
|
build.close();
|
2021-05-04 14:19:49 -06:00
|
|
|
if (options.auto_phase || options.dig)
|
2015-01-07 14:27:48 -07:00
|
|
|
dig.close();
|
2021-05-04 14:19:49 -06:00
|
|
|
|
2021-05-21 07:52:16 -06:00
|
|
|
return true;
|
2015-01-07 14:27:48 -07:00
|
|
|
}
|
|
|
|
|
2021-06-01 03:16:48 -06:00
|
|
|
static bool get_options(color_ostream &out,
|
|
|
|
blueprint_options &opts,
|
2021-05-04 14:19:49 -06:00
|
|
|
const vector<string> ¶meters)
|
|
|
|
{
|
|
|
|
auto L = Lua::Core::State;
|
|
|
|
Lua::StackUnwinder top(L);
|
|
|
|
|
|
|
|
if (!lua_checkstack(L, parameters.size() + 2) ||
|
|
|
|
!Lua::PushModulePublic(
|
|
|
|
out, L, "plugins.blueprint", "parse_commandline"))
|
|
|
|
{
|
2021-05-15 00:02:04 -06:00
|
|
|
out.printerr("Failed to load blueprint Lua code\n");
|
2021-05-04 14:19:49 -06:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Lua::Push(L, &opts);
|
|
|
|
|
|
|
|
for (const string ¶m : parameters)
|
|
|
|
Lua::Push(L, param);
|
|
|
|
|
|
|
|
if (!Lua::SafeCall(out, L, parameters.size() + 1, 0))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-06-01 03:16:48 -06:00
|
|
|
static void print_help(color_ostream &out)
|
2015-01-14 12:58:15 -07:00
|
|
|
{
|
2021-05-04 14:19:49 -06:00
|
|
|
auto L = Lua::Core::State;
|
|
|
|
Lua::StackUnwinder top(L);
|
|
|
|
|
|
|
|
if (!lua_checkstack(L, 1) ||
|
|
|
|
!Lua::PushModulePublic(out, L, "plugins.blueprint", "print_help") ||
|
|
|
|
!Lua::SafeCall(out, L, 0, 0))
|
|
|
|
{
|
2021-05-15 00:02:04 -06:00
|
|
|
out.printerr("Failed to load blueprint Lua code\n");
|
2021-05-04 14:19:49 -06:00
|
|
|
}
|
2015-01-14 12:58:15 -07:00
|
|
|
}
|
|
|
|
|
2021-05-21 07:52:16 -06:00
|
|
|
// returns whether blueprint generation was successful. populates files with the
|
|
|
|
// names of the files that were generated
|
|
|
|
static bool do_blueprint(color_ostream &out,
|
|
|
|
const vector<string> ¶meters,
|
|
|
|
vector<string> &files)
|
2015-01-07 14:27:48 -07:00
|
|
|
{
|
2021-05-15 13:05:32 -06:00
|
|
|
CoreSuspender suspend;
|
|
|
|
|
2021-05-08 08:34:29 -06:00
|
|
|
if (parameters.size() >= 1 && parameters[0] == "gui")
|
2021-05-04 14:19:49 -06:00
|
|
|
{
|
2021-05-15 00:02:04 -06:00
|
|
|
std::ostringstream command;
|
|
|
|
command << "gui/blueprint";
|
|
|
|
for (const string ¶m : parameters)
|
|
|
|
{
|
|
|
|
command << " " << param;
|
|
|
|
}
|
|
|
|
string command_str = command.str();
|
|
|
|
out.print("launching %s\n", command_str.c_str());
|
|
|
|
|
|
|
|
Core::getInstance().setHotkeyCmd(command_str);
|
|
|
|
return CR_OK;
|
2021-05-04 14:19:49 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
blueprint_options options;
|
2021-06-01 03:16:48 -06:00
|
|
|
if (!get_options(out, options, parameters) || options.help)
|
2021-05-04 14:19:49 -06:00
|
|
|
{
|
2021-06-01 03:16:48 -06:00
|
|
|
print_help(out);
|
2021-05-21 07:52:16 -06:00
|
|
|
return options.help;
|
2021-05-04 14:19:49 -06:00
|
|
|
}
|
|
|
|
|
2015-01-07 14:27:48 -07:00
|
|
|
if (!Maps::IsValid())
|
|
|
|
{
|
|
|
|
out.printerr("Map is not available!\n");
|
2021-05-21 07:52:16 -06:00
|
|
|
return false;
|
2015-01-07 14:27:48 -07:00
|
|
|
}
|
2021-05-04 14:19:49 -06:00
|
|
|
|
|
|
|
// start coordinates can come from either the commandline or the map cursor
|
|
|
|
DFCoord start(options.start);
|
2021-05-21 07:32:41 -06:00
|
|
|
if (start.x == -30000)
|
2020-07-15 17:57:14 -06:00
|
|
|
{
|
2021-05-21 07:32:41 -06:00
|
|
|
if (!Gui::getCursorCoords(start))
|
2021-05-04 14:19:49 -06:00
|
|
|
{
|
|
|
|
out.printerr("Can't get cursor coords! Make sure you specify the"
|
|
|
|
" --cursor parameter or have an active cursor in DF.\n");
|
2021-05-21 07:52:16 -06:00
|
|
|
return false;
|
2021-05-04 14:19:49 -06:00
|
|
|
}
|
2020-07-15 17:57:14 -06:00
|
|
|
}
|
2021-05-04 14:19:49 -06:00
|
|
|
if (!Maps::isValidTilePos(start))
|
2020-07-15 17:57:14 -06:00
|
|
|
{
|
2021-05-04 14:19:49 -06:00
|
|
|
out.printerr("Invalid start position: %d,%d,%d\n",
|
|
|
|
start.x, start.y, start.z);
|
2021-05-21 07:52:16 -06:00
|
|
|
return false;
|
2020-07-15 17:57:14 -06:00
|
|
|
}
|
2018-05-08 12:42:41 -06:00
|
|
|
|
2021-05-04 14:19:49 -06:00
|
|
|
// end coords are one beyond the last processed coordinate. note that
|
|
|
|
// options.depth can be negative.
|
|
|
|
DFCoord end(start.x + options.width, start.y + options.height,
|
|
|
|
start.z + options.depth);
|
|
|
|
|
|
|
|
// crop end coordinate to map bounds. we've already verified that start is
|
|
|
|
// a valid coordinate, and width, height, and depth are non-zero, so our
|
2021-05-05 14:18:43 -06:00
|
|
|
// final area is always going to be at least 1x1x1.
|
2021-05-04 14:19:49 -06:00
|
|
|
df::world::T_map &map = df::global::world->map;
|
|
|
|
if (end.x > map.x_count)
|
|
|
|
end.x = map.x_count;
|
|
|
|
if (end.y > map.y_count)
|
|
|
|
end.y = map.y_count;
|
|
|
|
if (end.z > map.z_count)
|
|
|
|
end.z = map.z_count;
|
|
|
|
if (end.z < -1)
|
|
|
|
end.z = -1;
|
2018-05-08 12:42:41 -06:00
|
|
|
|
2020-07-15 17:57:14 -06:00
|
|
|
std::ostringstream err;
|
2021-05-21 07:52:16 -06:00
|
|
|
if (!do_transform(start, end, options, files, err))
|
|
|
|
{
|
2021-05-04 14:19:49 -06:00
|
|
|
out.printerr("%s\n", err.str().c_str());
|
2021-05-21 07:52:16 -06:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2018-05-08 12:42:41 -06:00
|
|
|
}
|
2021-05-21 07:52:16 -06:00
|
|
|
|
|
|
|
// entrypoint when called from Lua. returns the names of the generated files
|
|
|
|
static int run(lua_State *L)
|
|
|
|
{
|
|
|
|
int argc = lua_gettop(L);
|
|
|
|
vector<string> argv;
|
|
|
|
|
|
|
|
for (int i = 1; i <= argc; ++i)
|
|
|
|
{
|
|
|
|
const char *s = lua_tostring(L, i);
|
|
|
|
if (s == NULL)
|
|
|
|
luaL_error(L, "all parameters must be strings");
|
|
|
|
argv.push_back(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<string> files;
|
2021-06-01 03:16:48 -06:00
|
|
|
color_ostream *out = Lua::GetOutput(L);
|
|
|
|
if (!out)
|
|
|
|
out = &Core::getInstance().getConsole();
|
|
|
|
if (do_blueprint(*out, argv, files))
|
2021-05-21 07:52:16 -06:00
|
|
|
{
|
|
|
|
Lua::PushVector(L, files);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
command_result blueprint(color_ostream &out, vector<string> ¶meters)
|
|
|
|
{
|
|
|
|
vector<string> files;
|
2021-06-01 03:16:48 -06:00
|
|
|
if (do_blueprint(out, parameters, files))
|
2021-05-21 07:52:16 -06:00
|
|
|
{
|
|
|
|
out.print("Generated blueprint file(s):\n");
|
|
|
|
for (string &fname : files)
|
|
|
|
out.print(" %s\n", fname.c_str());
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFHACK_PLUGIN_LUA_COMMANDS {
|
|
|
|
DFHACK_LUA_COMMAND(run),
|
|
|
|
DFHACK_LUA_END
|
|
|
|
};
|