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>
|
2022-04-01 12:36:19 -06:00
|
|
|
#include <unordered_map>
|
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"
|
2021-10-04 15:44:41 -06:00
|
|
|
#include "df/building_civzonest.h"
|
2015-01-09 14:00:47 -07:00
|
|
|
#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"
|
2022-04-01 12:36:19 -06:00
|
|
|
#include "df/engraving.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::endl;
|
|
|
|
using std::ofstream;
|
2015-01-14 12:08:54 -07:00
|
|
|
using std::pair;
|
2021-09-10 13:46:07 -06:00
|
|
|
using std::map;
|
2021-09-09 01:46:33 -06:00
|
|
|
using std::string;
|
|
|
|
using std::vector;
|
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;
|
|
|
|
|
2021-09-10 13:46:07 -06:00
|
|
|
// output file format. this could be an enum if we set up the boilerplate
|
|
|
|
// for it.
|
|
|
|
string format;
|
|
|
|
|
2021-09-17 12:07:42 -06:00
|
|
|
// offset and comment to write in the quickfort start() modeline marker
|
|
|
|
// if not set, coordinates are set to 0 and the comment will be empty
|
|
|
|
df::coord2d playback_start = df::coord2d(0, 0);
|
|
|
|
string playback_start_comment;
|
|
|
|
|
2021-09-09 01:46:33 -06:00
|
|
|
// file splitting strategy. this could be an enum if we set up the
|
|
|
|
// boilerplate for it.
|
|
|
|
string split_strategy;
|
|
|
|
|
2021-05-04 14:19:49 -06:00
|
|
|
// 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;
|
|
|
|
|
2022-04-01 12:36:19 -06:00
|
|
|
// whether to capture engravings and smooth the tiles that will be engraved
|
|
|
|
bool engrave = false;
|
|
|
|
|
2021-05-04 14:19:49 -06:00
|
|
|
// whether to autodetect which phases to output
|
|
|
|
bool auto_phase = false;
|
|
|
|
|
|
|
|
// if not autodetecting, which phases to output
|
|
|
|
bool dig = false;
|
2022-04-01 12:36:19 -06:00
|
|
|
bool carve = false;
|
2021-05-04 14:19:49 -06:00
|
|
|
bool build = false;
|
|
|
|
bool place = false;
|
2021-10-04 15:44:41 -06:00
|
|
|
bool zone = false;
|
2021-05-04 14:19:49 -06:00
|
|
|
bool query = false;
|
|
|
|
|
|
|
|
static struct_identity _identity;
|
|
|
|
};
|
|
|
|
static const struct_field_info blueprint_options_fields[] = {
|
2021-09-17 12:07:42 -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, "format", offsetof(blueprint_options, format), df::identity_traits<string>::get(), 0, 0 },
|
|
|
|
{ struct_field_info::SUBSTRUCT, "playback_start", offsetof(blueprint_options, playback_start), &df::coord2d::_identity, 0, 0 },
|
|
|
|
{ struct_field_info::PRIMITIVE, "playback_start_comment", offsetof(blueprint_options, playback_start_comment), df::identity_traits<string>::get(), 0, 0 },
|
|
|
|
{ struct_field_info::PRIMITIVE, "split_strategy", offsetof(blueprint_options, split_strategy), df::identity_traits<string>::get(), 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 },
|
2022-04-01 12:36:19 -06:00
|
|
|
{ struct_field_info::PRIMITIVE, "engrave", offsetof(blueprint_options, engrave), &df::identity_traits<bool>::identity, 0, 0 },
|
2021-09-17 12:07:42 -06:00
|
|
|
{ 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 },
|
2022-04-01 12:36:19 -06:00
|
|
|
{ struct_field_info::PRIMITIVE, "carve", offsetof(blueprint_options, carve), &df::identity_traits<bool>::identity, 0, 0 },
|
2021-09-17 12:07:42 -06:00
|
|
|
{ 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 },
|
2021-10-04 15:44:41 -06:00
|
|
|
{ struct_field_info::PRIMITIVE, "zone", offsetof(blueprint_options, zone), &df::identity_traits<bool>::identity, 0, 0 },
|
2021-09-17 12:07:42 -06:00
|
|
|
{ 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-09-10 13:46:07 -06:00
|
|
|
DFhackCExport command_result plugin_init(color_ostream &, vector<PluginCommand> &commands) {
|
2022-07-18 17:32:43 -06:00
|
|
|
commands.push_back(
|
|
|
|
PluginCommand("blueprint",
|
|
|
|
"Record a live game map in a quickfort blueprint.",
|
|
|
|
blueprint));
|
2015-01-07 14:27:48 -07:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2021-09-10 13:46:07 -06:00
|
|
|
DFhackCExport command_result plugin_shutdown(color_ostream &) {
|
2015-01-07 14:27:48 -07:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2021-09-10 13:46:07 -06:00
|
|
|
struct tile_context {
|
|
|
|
bool pretty = false;
|
|
|
|
df::building* b = NULL;
|
|
|
|
};
|
|
|
|
|
2022-04-01 12:36:19 -06:00
|
|
|
// global engravings cache, cleared when the string cache is cleared
|
|
|
|
struct PosHash {
|
|
|
|
size_t operator()(const df::coord &c) const {
|
|
|
|
return c.x * 65537 + c.y * 513 + c.z;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
static std::unordered_map<df::coord, df::engraving *, PosHash> engravings_cache;
|
|
|
|
|
2021-09-10 21:40:36 -06:00
|
|
|
// We use const char * throughout this code instead of std::string to avoid
|
|
|
|
// having to allocate memory for all the small string literals. This
|
|
|
|
// significantly speeds up processing and allows us to handle very large maps
|
|
|
|
// (e.g. 16x16 embarks) without running out of memory. This cache provides a
|
|
|
|
// mechanism for storing dynamically created strings so their memory stays
|
|
|
|
// allocated until we write out the blueprints at the end.
|
|
|
|
// If NULL is passed as the str, the cache is cleared.
|
2021-09-10 15:19:50 -06:00
|
|
|
static const char * cache(const char *str) {
|
|
|
|
// this local static assumes that no two blueprints are being generated at
|
|
|
|
// the same time, which is currently ensured by the higher-level DFHack
|
|
|
|
// command handling code. if this assumption ever becomes untrue, we'll
|
|
|
|
// need to protect the cache with thread synchronization primitives.
|
|
|
|
static std::set<string> _cache;
|
|
|
|
if (!str) {
|
|
|
|
_cache.clear();
|
2022-04-01 12:36:19 -06:00
|
|
|
engravings_cache.clear();
|
2021-09-10 15:19:50 -06:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return _cache.emplace(str).first->c_str();
|
2021-09-10 13:46:07 -06:00
|
|
|
}
|
|
|
|
|
2021-09-10 21:40:36 -06:00
|
|
|
// Convenience wrapper for std::string.
|
|
|
|
static const char * cache(const string &str) {
|
|
|
|
return cache(str.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convenience wrapper for std::ostringstream.
|
|
|
|
static const char * cache(std::ostringstream &str) {
|
|
|
|
return cache(str.str());
|
|
|
|
}
|
|
|
|
|
2021-09-10 15:19:50 -06:00
|
|
|
static const char * get_tile_dig(const df::coord &pos, const tile_context &) {
|
2021-09-10 13:46:07 -06:00
|
|
|
df::tiletype *tt = Maps::getTileType(pos);
|
2021-09-29 22:35:56 -06:00
|
|
|
if (!tt)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
switch (tileShape(*tt))
|
2015-01-08 10:17:18 -07:00
|
|
|
{
|
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:
|
2021-09-10 15:19:50 -06: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:
|
2021-09-10 15:19:50 -06:00
|
|
|
return "d";
|
2015-01-09 14:00:47 -07:00
|
|
|
case tiletype_shape::STAIR_UP:
|
2021-09-10 15:19:50 -06:00
|
|
|
return "u";
|
2015-01-09 14:00:47 -07:00
|
|
|
case tiletype_shape::STAIR_DOWN:
|
2021-09-10 15:19:50 -06:00
|
|
|
return "j";
|
2015-01-09 14:00:47 -07:00
|
|
|
case tiletype_shape::STAIR_UPDOWN:
|
2021-09-10 15:19:50 -06:00
|
|
|
return "i";
|
2015-01-09 14:00:47 -07:00
|
|
|
case tiletype_shape::RAMP:
|
2021-09-10 15:19:50 -06:00
|
|
|
return "r";
|
2021-09-10 13:46:07 -06:00
|
|
|
case tiletype_shape::WALL:
|
2015-01-08 10:17:18 -07:00
|
|
|
default:
|
2021-09-10 15:19:50 -06:00
|
|
|
return NULL;
|
2015-01-08 10:17:18 -07:00
|
|
|
}
|
|
|
|
}
|
2015-01-07 14:27:48 -07:00
|
|
|
|
2022-04-01 12:36:19 -06:00
|
|
|
static const char * get_tile_smooth_minimal(const df::coord &pos,
|
|
|
|
const tile_context &) {
|
|
|
|
df::tiletype *tt = Maps::getTileType(pos);
|
|
|
|
if (!tt)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
switch (tileShape(*tt))
|
|
|
|
{
|
|
|
|
case tiletype_shape::FORTIFICATION:
|
|
|
|
return "s";
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char * get_tile_smooth(const df::coord &pos,
|
|
|
|
const tile_context &tc) {
|
|
|
|
const char * smooth_minimal = get_tile_smooth_minimal(pos, tc);
|
|
|
|
if (smooth_minimal)
|
|
|
|
return smooth_minimal;
|
|
|
|
|
|
|
|
df::tiletype *tt = Maps::getTileType(pos);
|
|
|
|
if (!tt)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
switch (tileShape(*tt))
|
|
|
|
{
|
|
|
|
case tiletype_shape::FLOOR:
|
|
|
|
case tiletype_shape::WALL:
|
|
|
|
if (tileSpecial(*tt) == tiletype_special::SMOOTH &&
|
|
|
|
engravings_cache.count(pos))
|
|
|
|
return "s";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-10-04 12:14:44 -06:00
|
|
|
static const char * get_track_str(const char *prefix, df::tiletype tt) {
|
|
|
|
TileDirection tdir = tileDirection(tt);
|
|
|
|
|
|
|
|
string dir;
|
|
|
|
if (tdir.north) dir += "N";
|
|
|
|
if (tdir.south) dir += "S";
|
|
|
|
if (tdir.east) dir += "E";
|
|
|
|
if (tdir.west) dir += "W";
|
|
|
|
|
|
|
|
return cache(prefix + dir);
|
|
|
|
}
|
|
|
|
|
2022-04-01 12:36:19 -06:00
|
|
|
static const char * get_tile_carve_minimal(const df::coord &pos,
|
|
|
|
const tile_context &) {
|
2021-10-04 12:14:44 -06:00
|
|
|
df::tiletype *tt = Maps::getTileType(pos);
|
|
|
|
if (!tt)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
switch (tileShape(*tt))
|
|
|
|
{
|
|
|
|
case tiletype_shape::FLOOR:
|
|
|
|
if (tileSpecial(*tt) == tiletype_special::TRACK)
|
|
|
|
return get_track_str("track", *tt);
|
|
|
|
break;
|
|
|
|
case tiletype_shape::RAMP:
|
|
|
|
if (tileSpecial(*tt) == tiletype_special::TRACK)
|
|
|
|
return get_track_str("trackramp", *tt);
|
|
|
|
break;
|
2022-04-01 12:36:19 -06:00
|
|
|
case tiletype_shape::FORTIFICATION:
|
|
|
|
return "F";
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char * get_tile_carve(const df::coord &pos, const tile_context &tc) {
|
|
|
|
const char * tile_carve_minimal = get_tile_carve_minimal(pos, tc);
|
|
|
|
if (tile_carve_minimal)
|
|
|
|
return tile_carve_minimal;
|
|
|
|
|
|
|
|
df::tiletype *tt = Maps::getTileType(pos);
|
|
|
|
if (!tt)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
switch (tileShape(*tt))
|
|
|
|
{
|
|
|
|
case tiletype_shape::FLOOR:
|
|
|
|
case tiletype_shape::WALL:
|
|
|
|
if (tileSpecial(*tt) == tiletype_special::SMOOTH &&
|
|
|
|
engravings_cache.count(pos))
|
|
|
|
return "e";
|
|
|
|
break;
|
2021-10-04 12:14:44 -06:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-10-04 15:44:41 -06:00
|
|
|
static pair<uint32_t, uint32_t> get_building_size(const df::building *b) {
|
2021-09-10 15:19:50 -06:00
|
|
|
return pair<uint32_t, uint32_t>(b->x2 - b->x1 + 1, b->y2 - b->y1 + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char * if_pretty(const tile_context &ctx, const char *c) {
|
2021-09-10 21:40:36 -06:00
|
|
|
return ctx.pretty ? c : NULL;
|
2021-09-10 15:19:50 -06:00
|
|
|
}
|
|
|
|
|
2021-10-04 15:44:41 -06:00
|
|
|
static bool is_rectangular(const df::building *bld) {
|
|
|
|
const df::building_extents &room = bld->room;
|
2021-10-02 13:30:08 -06:00
|
|
|
if (!room.extents)
|
|
|
|
return true;
|
|
|
|
for (int32_t y = 0; y < room.height; ++y) {
|
|
|
|
for (int32_t x = 0; x < room.width; ++x) {
|
|
|
|
if (!room.extents[y * room.width + x])
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-10-04 15:44:41 -06:00
|
|
|
static bool is_rectangular(const tile_context &ctx) {
|
|
|
|
return is_rectangular(ctx.b);
|
|
|
|
}
|
|
|
|
|
2021-09-10 15:19:50 -06:00
|
|
|
static const char * do_block_building(const tile_context &ctx, const char *s,
|
|
|
|
bool at_target_pos,
|
|
|
|
bool *add_size = NULL) {
|
2021-09-10 13:46:07 -06:00
|
|
|
if(!at_target_pos) {
|
2021-09-10 15:19:50 -06:00
|
|
|
return if_pretty(ctx, "`");
|
2021-09-10 13:46:07 -06:00
|
|
|
}
|
|
|
|
if (add_size)
|
|
|
|
*add_size = true;
|
2021-09-10 15:19:50 -06:00
|
|
|
return s;
|
2021-09-10 13:46:07 -06:00
|
|
|
}
|
|
|
|
|
2021-10-03 08:36:52 -06:00
|
|
|
static const char * do_extent_building(const tile_context &ctx, const char *s,
|
|
|
|
bool at_target_pos,
|
|
|
|
bool *add_size = NULL) {
|
|
|
|
// use expansion syntax for rectangular or one-tile buildings
|
|
|
|
if (is_rectangular(ctx))
|
|
|
|
return do_block_building(ctx, s, at_target_pos, add_size);
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2021-09-10 15:19:50 -06:00
|
|
|
static const char * get_bridge_str(df::building *b) {
|
2021-09-10 13:46:07 -06:00
|
|
|
df::building_bridgest *bridge = virtual_cast<df::building_bridgest>(b);
|
|
|
|
if (!bridge)
|
|
|
|
return "g";
|
|
|
|
|
|
|
|
switch(bridge->direction) {
|
|
|
|
case df::building_bridgest::T_direction::Retracting: return "gs";
|
|
|
|
case df::building_bridgest::T_direction::Left: return "ga";
|
|
|
|
case df::building_bridgest::T_direction::Right: return "gd";
|
|
|
|
case df::building_bridgest::T_direction::Up: return "gw";
|
|
|
|
case df::building_bridgest::T_direction::Down: return "gx";
|
|
|
|
default:
|
|
|
|
return "g";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-10 15:19:50 -06:00
|
|
|
static const char * get_siege_str(df::building *b) {
|
2021-09-10 13:46:07 -06:00
|
|
|
df::building_siegeenginest *se =
|
|
|
|
virtual_cast<df::building_siegeenginest>(b);
|
|
|
|
return !se || se->type == df::siegeengine_type::Catapult ? "ic" : "ib";
|
|
|
|
}
|
|
|
|
|
2021-09-10 15:19:50 -06:00
|
|
|
static const char * get_workshop_str(df::building *b) {
|
2021-09-10 13:46:07 -06:00
|
|
|
df::building_workshopst *ws = virtual_cast<df::building_workshopst>(b);
|
|
|
|
if (!ws)
|
|
|
|
return "~";
|
|
|
|
|
|
|
|
switch (ws->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";
|
|
|
|
case workshop_type::Kennels: return "k";
|
|
|
|
case workshop_type::Custom:
|
2021-10-01 22:35:50 -06:00
|
|
|
{
|
|
|
|
int32_t custom = b->getCustomType();
|
|
|
|
if (custom == 0) return "wS";
|
|
|
|
if (custom == 1) return "wp";
|
|
|
|
}
|
|
|
|
// fallthrough
|
2021-09-10 13:46:07 -06:00
|
|
|
case workshop_type::Tool:
|
|
|
|
default:
|
|
|
|
return "~";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-10 15:19:50 -06:00
|
|
|
static const char * get_furnace_str(df::building *b) {
|
2021-09-10 13:46:07 -06:00
|
|
|
df::building_furnacest *furnace = virtual_cast<df::building_furnacest>(b);
|
|
|
|
if (!furnace)
|
|
|
|
return "~";
|
|
|
|
|
|
|
|
switch (furnace->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:
|
|
|
|
default:
|
|
|
|
return "~";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-10 15:19:50 -06:00
|
|
|
static const char * get_construction_str(df::building *b) {
|
2021-09-10 13:46:07 -06:00
|
|
|
df::building_constructionst *cons =
|
|
|
|
virtual_cast<df::building_constructionst>(b);
|
|
|
|
if (!cons)
|
|
|
|
return "~";
|
|
|
|
|
|
|
|
switch (cons->type) {
|
|
|
|
case construction_type::Fortification: return "CF";
|
2021-10-01 22:35:50 -06:00
|
|
|
case construction_type::Wall: return "Cw";
|
2021-09-10 13:46:07 -06:00
|
|
|
case construction_type::Floor: return "Cf";
|
|
|
|
case construction_type::UpStair: return "Cu";
|
2021-10-01 22:35:50 -06:00
|
|
|
case construction_type::DownStair: return "Cd";
|
2021-09-10 13:46:07 -06:00
|
|
|
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 construction_type::NONE:
|
|
|
|
default:
|
|
|
|
return "~";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-10 15:19:50 -06:00
|
|
|
static const char * get_trap_str(df::building *b) {
|
2021-09-10 13:46:07 -06:00
|
|
|
df::building_trapst *trap = virtual_cast<df::building_trapst>(b);
|
|
|
|
if (!trap)
|
|
|
|
return "~";
|
|
|
|
|
|
|
|
switch (trap->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:
|
|
|
|
{
|
|
|
|
std::ostringstream buf;
|
|
|
|
buf << "CS";
|
|
|
|
if (trap->use_dump) {
|
|
|
|
if (trap->dump_x_shift == 0) {
|
|
|
|
buf << "d";
|
|
|
|
if (trap->dump_y_shift > 0)
|
|
|
|
buf << "d";
|
|
|
|
} else {
|
|
|
|
buf << "ddd";
|
|
|
|
if (trap->dump_x_shift < 0)
|
|
|
|
buf << "d";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// each case falls through and is additive
|
|
|
|
switch (trap->friction) {
|
|
|
|
case 10: buf << "a";
|
|
|
|
case 50: buf << "a";
|
|
|
|
case 500: buf << "a";
|
|
|
|
case 10000: buf << "a";
|
|
|
|
}
|
2021-09-10 21:40:36 -06:00
|
|
|
return cache(buf);
|
2021-09-10 13:46:07 -06:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
return "~";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-10 15:19:50 -06:00
|
|
|
static const char * get_screw_pump_str(df::building *b) {
|
2021-09-10 13:46:07 -06:00
|
|
|
df::building_screw_pumpst *sp = virtual_cast<df::building_screw_pumpst>(b);
|
|
|
|
if (!sp)
|
|
|
|
return "~";
|
|
|
|
|
|
|
|
switch (sp->direction)
|
2015-01-09 14:00:47 -07:00
|
|
|
{
|
2021-09-10 13:46:07 -06:00
|
|
|
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";
|
|
|
|
default:
|
|
|
|
return "~";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-10 15:19:50 -06:00
|
|
|
static const char * get_water_wheel_str(df::building *b) {
|
2021-09-10 13:46:07 -06:00
|
|
|
df::building_water_wheelst *ww =
|
|
|
|
virtual_cast<df::building_water_wheelst>(b);
|
|
|
|
if (!ww)
|
|
|
|
return "~";
|
|
|
|
|
|
|
|
return ww->is_vertical ? "Mw" : "Mws";
|
|
|
|
}
|
|
|
|
|
2021-09-10 15:19:50 -06:00
|
|
|
static const char * get_axle_str(df::building *b) {
|
2021-09-10 13:46:07 -06:00
|
|
|
df::building_axle_horizontalst *ah =
|
|
|
|
virtual_cast<df::building_axle_horizontalst>(b);
|
|
|
|
if (!ah)
|
|
|
|
return "~";
|
|
|
|
|
|
|
|
return ah->is_vertical ? "Mhs" : "Mh";
|
|
|
|
}
|
|
|
|
|
2021-10-01 22:35:50 -06:00
|
|
|
static const char * add_speed_suffix(df::building_rollersst *r,
|
|
|
|
const char *prefix) {
|
|
|
|
int32_t speed = r->speed;
|
|
|
|
if (speed >= 50000) return prefix;
|
|
|
|
string sprefix(prefix);
|
|
|
|
if (speed >= 40000) return cache(sprefix + "q");
|
|
|
|
if (speed >= 30000) return cache(sprefix + "qq");
|
|
|
|
if (speed >= 20000) return cache(sprefix + "qqq");
|
|
|
|
return cache(sprefix + "qqqq");
|
|
|
|
}
|
|
|
|
|
2021-09-10 15:19:50 -06:00
|
|
|
static const char * get_roller_str(df::building *b) {
|
2021-09-10 13:46:07 -06:00
|
|
|
df::building_rollersst *r = virtual_cast<df::building_rollersst>(b);
|
|
|
|
if (!r)
|
|
|
|
return "~";
|
|
|
|
|
|
|
|
switch (r->direction) {
|
2021-10-01 22:35:50 -06:00
|
|
|
case screw_pump_direction::FromNorth: return add_speed_suffix(r, "Mr");
|
|
|
|
case screw_pump_direction::FromEast: return add_speed_suffix(r, "Mrs");
|
|
|
|
case screw_pump_direction::FromSouth: return add_speed_suffix(r, "Mrss");
|
|
|
|
case screw_pump_direction::FromWest: return add_speed_suffix(r, "Mrsss");
|
2021-09-10 13:46:07 -06:00
|
|
|
default:
|
|
|
|
return "~";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-10 15:19:50 -06:00
|
|
|
static const char * get_build_keys(const df::coord &pos,
|
|
|
|
const tile_context &ctx,
|
|
|
|
bool &add_size) {
|
2021-09-10 13:46:07 -06:00
|
|
|
bool at_nw_corner = static_cast<int32_t>(pos.x) == ctx.b->x1
|
|
|
|
&& static_cast<int32_t>(pos.y) == ctx.b->y1;
|
|
|
|
bool at_se_corner = static_cast<int32_t>(pos.x) == ctx.b->x2
|
|
|
|
&& static_cast<int32_t>(pos.y) == ctx.b->y2;
|
|
|
|
bool at_center = static_cast<int32_t>(pos.x) == ctx.b->centerx
|
|
|
|
&& static_cast<int32_t>(pos.y) == ctx.b->centery;
|
|
|
|
|
|
|
|
switch(ctx.b->getType()) {
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::Armorstand:
|
2021-09-10 15:19:50 -06:00
|
|
|
return "a";
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::Bed:
|
2021-09-10 15:19:50 -06:00
|
|
|
return "b";
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::Chair:
|
2021-09-10 15:19:50 -06:00
|
|
|
return "c";
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::Door:
|
2021-09-10 15:19:50 -06:00
|
|
|
return "d";
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::Floodgate:
|
2021-09-10 15:19:50 -06:00
|
|
|
return "x";
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::Cabinet:
|
2021-09-10 15:19:50 -06:00
|
|
|
return "f";
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::Box:
|
2021-09-10 15:19:50 -06:00
|
|
|
return "h";
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::FarmPlot:
|
2021-10-03 08:36:52 -06:00
|
|
|
return do_extent_building(ctx, "p", at_nw_corner, &add_size);
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::Weaponrack:
|
2021-09-10 15:19:50 -06:00
|
|
|
return "r";
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::Statue:
|
2021-09-10 15:19:50 -06:00
|
|
|
return "s";
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::Table:
|
2021-09-10 15:19:50 -06:00
|
|
|
return "t";
|
2021-10-01 22:35:50 -06:00
|
|
|
case building_type::Coffin:
|
|
|
|
return "n";
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::RoadPaved:
|
2021-10-03 08:36:52 -06:00
|
|
|
return do_extent_building(ctx, "o", at_nw_corner, &add_size);
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::RoadDirt:
|
2021-10-03 08:36:52 -06:00
|
|
|
return do_extent_building(ctx, "O", at_nw_corner, &add_size);
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::Bridge:
|
2021-09-10 15:19:50 -06:00
|
|
|
return do_block_building(ctx, get_bridge_str(ctx.b), at_nw_corner,
|
2021-09-10 13:46:07 -06:00
|
|
|
&add_size);
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::Well:
|
2021-09-10 15:19:50 -06:00
|
|
|
return "l";
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::SiegeEngine:
|
2021-09-10 15:19:50 -06:00
|
|
|
return do_block_building(ctx, get_siege_str(ctx.b), at_center);
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::Workshop:
|
2021-09-10 15:19:50 -06:00
|
|
|
return do_block_building(ctx, get_workshop_str(ctx.b), at_center);
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::Furnace:
|
2021-09-10 15:19:50 -06:00
|
|
|
return do_block_building(ctx, get_furnace_str(ctx.b), at_center);
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::WindowGlass:
|
2021-09-10 15:19:50 -06:00
|
|
|
return "y";
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::WindowGem:
|
2021-09-10 15:19:50 -06:00
|
|
|
return "Y";
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::Construction:
|
2021-09-10 15:19:50 -06:00
|
|
|
return get_construction_str(ctx.b);
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::Shop:
|
2021-09-10 15:19:50 -06:00
|
|
|
return do_block_building(ctx, "z", at_center);
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::AnimalTrap:
|
2021-09-10 15:19:50 -06:00
|
|
|
return "m";
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::Chain:
|
2021-09-10 15:19:50 -06:00
|
|
|
return "v";
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::Cage:
|
2021-09-10 15:19:50 -06:00
|
|
|
return "j";
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::TradeDepot:
|
2021-09-10 15:19:50 -06:00
|
|
|
return do_block_building(ctx, "D", at_center);
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::Trap:
|
2021-09-10 15:19:50 -06:00
|
|
|
return get_trap_str(ctx.b);
|
2021-10-01 22:35:50 -06:00
|
|
|
case building_type::Weapon:
|
|
|
|
return "TS";
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::ScrewPump:
|
2021-09-10 15:19:50 -06:00
|
|
|
return do_block_building(ctx, get_screw_pump_str(ctx.b), at_se_corner);
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::WaterWheel:
|
2021-09-10 15:19:50 -06:00
|
|
|
return do_block_building(ctx, get_water_wheel_str(ctx.b), at_center);
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::Windmill:
|
2021-09-10 15:19:50 -06:00
|
|
|
return do_block_building(ctx, "Mm", at_center);
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::GearAssembly:
|
2021-09-10 15:19:50 -06:00
|
|
|
return "Mg";
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::AxleHorizontal:
|
2021-09-10 15:19:50 -06:00
|
|
|
return do_block_building(ctx, get_axle_str(ctx.b), at_nw_corner,
|
|
|
|
&add_size);
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::AxleVertical:
|
2021-09-10 15:19:50 -06:00
|
|
|
return "Mv";
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::Rollers:
|
2021-09-10 15:19:50 -06:00
|
|
|
return do_block_building(ctx, get_roller_str(ctx.b), at_nw_corner,
|
|
|
|
&add_size);
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::Support:
|
2021-09-10 15:19:50 -06:00
|
|
|
return "S";
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::ArcheryTarget:
|
2021-09-10 15:19:50 -06:00
|
|
|
return "A";
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::TractionBench:
|
2021-09-10 15:19:50 -06:00
|
|
|
return "R";
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::Hatch:
|
2021-09-10 15:19:50 -06:00
|
|
|
return "H";
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::Slab:
|
2021-10-01 22:35:50 -06:00
|
|
|
return "~s";
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::NestBox:
|
2021-09-10 15:19:50 -06:00
|
|
|
return "N";
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::Hive:
|
2021-10-01 22:35:50 -06:00
|
|
|
return "~h";
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::GrateWall:
|
2021-09-10 15:19:50 -06:00
|
|
|
return "W";
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::GrateFloor:
|
2021-09-10 15:19:50 -06:00
|
|
|
return "G";
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::BarsVertical:
|
2021-09-10 15:19:50 -06:00
|
|
|
return "B";
|
2015-01-09 14:00:47 -07:00
|
|
|
case building_type::BarsFloor:
|
2021-10-01 22:35:50 -06:00
|
|
|
return "~b";
|
|
|
|
case building_type::Bookcase:
|
|
|
|
return "~c";
|
|
|
|
case building_type::DisplayFurniture:
|
|
|
|
return "F";
|
|
|
|
case building_type::OfferingPlace:
|
|
|
|
return "~a";
|
2015-01-09 14:00:47 -07:00
|
|
|
default:
|
2021-09-10 15:19:50 -06:00
|
|
|
return "~";
|
2015-01-09 14:00:47 -07:00
|
|
|
}
|
|
|
|
}
|
2015-01-08 10:17:18 -07:00
|
|
|
|
2021-09-10 15:19:50 -06:00
|
|
|
// returns "~" if keys is NULL; otherwise returns the keys with the building
|
|
|
|
// dimensions in the expansion syntax
|
2021-10-04 15:44:41 -06:00
|
|
|
static const char * add_expansion_syntax(const df::building *bld,
|
2021-09-10 15:19:50 -06:00
|
|
|
const char *keys) {
|
|
|
|
if (!keys)
|
|
|
|
return "~";
|
|
|
|
std::ostringstream s;
|
2021-10-04 15:44:41 -06:00
|
|
|
pair<uint32_t, uint32_t> size = get_building_size(bld);
|
2021-09-10 15:19:50 -06:00
|
|
|
s << keys << "(" << size.first << "x" << size.second << ")";
|
2021-09-10 21:40:36 -06:00
|
|
|
return cache(s);
|
2021-09-10 15:19:50 -06:00
|
|
|
}
|
2021-09-10 13:46:07 -06:00
|
|
|
|
2021-10-04 15:44:41 -06:00
|
|
|
static const char * add_expansion_syntax(const tile_context &ctx,
|
|
|
|
const char *keys) {
|
|
|
|
return add_expansion_syntax(ctx.b, keys);
|
|
|
|
}
|
|
|
|
|
2021-09-10 15:19:50 -06:00
|
|
|
static const char * get_tile_build(const df::coord &pos,
|
|
|
|
const tile_context &ctx) {
|
|
|
|
if (!ctx.b || ctx.b->getType() == building_type::Stockpile) {
|
|
|
|
return NULL;
|
2021-09-10 13:46:07 -06:00
|
|
|
}
|
|
|
|
|
2021-09-10 15:19:50 -06:00
|
|
|
bool add_size = false;
|
|
|
|
const char *keys = get_build_keys(pos, ctx, add_size);
|
|
|
|
|
|
|
|
if (!add_size)
|
|
|
|
return keys;
|
|
|
|
return add_expansion_syntax(ctx, keys);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char * get_place_keys(const tile_context &ctx) {
|
2021-09-10 13:46:07 -06:00
|
|
|
df::building_stockpilest* sp =
|
|
|
|
virtual_cast<df::building_stockpilest>(ctx.b);
|
|
|
|
if (!sp) {
|
2021-09-10 15:19:50 -06:00
|
|
|
return NULL;
|
2021-09-10 13:46:07 -06:00
|
|
|
}
|
|
|
|
|
2021-10-02 13:30:08 -06:00
|
|
|
string keys;
|
|
|
|
df::stockpile_group_set &flags = sp->settings.flags;
|
|
|
|
if (flags.bits.animals) keys += 'a';
|
|
|
|
if (flags.bits.food) keys += 'f';
|
|
|
|
if (flags.bits.furniture) keys += 'u';
|
|
|
|
if (flags.bits.coins) keys += 'n';
|
|
|
|
if (flags.bits.corpses) keys += 'y';
|
|
|
|
if (flags.bits.refuse) keys += 'r';
|
|
|
|
if (flags.bits.stone) keys += 's';
|
|
|
|
if (flags.bits.wood) keys += 'w';
|
|
|
|
if (flags.bits.gems) keys += 'e';
|
|
|
|
if (flags.bits.bars_blocks) keys += 'b';
|
|
|
|
if (flags.bits.cloth) keys += 'h';
|
|
|
|
if (flags.bits.leather) keys += 'l';
|
|
|
|
if (flags.bits.ammo) keys += 'z';
|
|
|
|
if (flags.bits.sheet) keys += 'S';
|
|
|
|
if (flags.bits.finished_goods) keys += 'g';
|
|
|
|
if (flags.bits.weapons) keys += 'p';
|
|
|
|
if (flags.bits.armor) keys += 'd';
|
|
|
|
|
|
|
|
if (keys.empty())
|
2021-10-04 12:14:44 -06:00
|
|
|
return "c";
|
2021-10-02 13:30:08 -06:00
|
|
|
return cache(keys);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool is_single_tile(const tile_context &ctx) {
|
|
|
|
return ctx.b->x1 == ctx.b->x2 && ctx.b->y1 == ctx.b->y2;
|
2021-09-10 15:19:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char * get_tile_place(const df::coord &pos,
|
|
|
|
const tile_context &ctx) {
|
|
|
|
if (!ctx.b || ctx.b->getType() != building_type::Stockpile)
|
|
|
|
return NULL;
|
|
|
|
|
2021-10-02 13:30:08 -06:00
|
|
|
if (!is_rectangular(ctx) || is_single_tile(ctx))
|
|
|
|
return get_place_keys(ctx);
|
|
|
|
|
2021-09-10 15:19:50 -06:00
|
|
|
if (ctx.b->x1 != static_cast<int32_t>(pos.x)
|
|
|
|
|| ctx.b->y1 != static_cast<int32_t>(pos.y)) {
|
|
|
|
return if_pretty(ctx, "`");
|
2015-01-13 12:28:28 -07:00
|
|
|
}
|
2021-09-10 13:46:07 -06:00
|
|
|
|
2021-09-10 15:19:50 -06:00
|
|
|
return add_expansion_syntax(ctx, get_place_keys(ctx));
|
2015-01-13 12:28:28 -07:00
|
|
|
}
|
|
|
|
|
2021-10-04 15:44:41 -06:00
|
|
|
static bool hospital_maximums_eq(const df::hospital_supplies &a,
|
|
|
|
const df::hospital_supplies &b) {
|
|
|
|
return a.max_thread == b.max_thread &&
|
|
|
|
a.max_cloth == b.max_cloth &&
|
|
|
|
a.max_splints == b.max_splints &&
|
|
|
|
a.max_crutches == b.max_crutches &&
|
|
|
|
a.max_plaster == b.max_plaster &&
|
|
|
|
a.max_buckets == b.max_buckets &&
|
|
|
|
a.max_soap == b.max_soap;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char * get_zone_keys(const df::building_civzonest *zone) {
|
|
|
|
static const uint32_t DEFAULT_GATHER_FLAGS =
|
|
|
|
df::building_civzonest::T_gather_flags::mask_pick_trees |
|
|
|
|
df::building_civzonest::T_gather_flags::mask_pick_shrubs |
|
|
|
|
df::building_civzonest::T_gather_flags::mask_gather_fallen;
|
|
|
|
static const df::hospital_supplies DEFAULT_HOSPITAL;
|
|
|
|
|
|
|
|
std::ostringstream keys;
|
|
|
|
const df::building_civzonest::T_zone_flags &flags = zone->zone_flags;
|
|
|
|
|
|
|
|
// inverted logic for Active since it's on by default
|
|
|
|
if (!flags.bits.active) keys << 'a';
|
|
|
|
|
|
|
|
// in UI order
|
|
|
|
if (flags.bits.water_source) keys << 'w';
|
|
|
|
if (flags.bits.fishing) keys << 'f';
|
|
|
|
if (flags.bits.gather) {
|
|
|
|
keys << 'g';
|
|
|
|
if (zone->gather_flags.whole != DEFAULT_GATHER_FLAGS) {
|
|
|
|
keys << 'G';
|
|
|
|
// logic is inverted since they're all on by default
|
|
|
|
if (!zone->gather_flags.bits.pick_trees) keys << 't';
|
|
|
|
if (!zone->gather_flags.bits.pick_shrubs) keys << 's';
|
|
|
|
if (!zone->gather_flags.bits.gather_fallen) keys << 'f';
|
|
|
|
keys << '^';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (flags.bits.garbage_dump) keys << 'd';
|
|
|
|
if (flags.bits.pen_pasture) keys << 'n';
|
|
|
|
if (flags.bits.pit_pond) {
|
|
|
|
keys << 'p';
|
|
|
|
if (zone->pit_flags.bits.is_pond)
|
|
|
|
keys << "Pf^";
|
|
|
|
}
|
|
|
|
if (flags.bits.sand) keys << 's';
|
|
|
|
if (flags.bits.clay) keys << 'c';
|
|
|
|
if (flags.bits.meeting_area) keys << 'm';
|
|
|
|
if (flags.bits.hospital) {
|
|
|
|
keys << 'h';
|
|
|
|
const df::hospital_supplies &hospital = zone->hospital;
|
|
|
|
if (!hospital_maximums_eq(hospital, DEFAULT_HOSPITAL)) {
|
|
|
|
keys << "H{hospital";
|
|
|
|
if (hospital.max_thread != DEFAULT_HOSPITAL.max_thread)
|
|
|
|
keys << " thread=" << hospital.max_thread;
|
|
|
|
if (hospital.max_cloth != DEFAULT_HOSPITAL.max_cloth)
|
|
|
|
keys << " cloth=" << hospital.max_cloth;
|
|
|
|
if (hospital.max_splints != DEFAULT_HOSPITAL.max_splints)
|
|
|
|
keys << " splints=" << hospital.max_splints;
|
|
|
|
if (hospital.max_crutches != DEFAULT_HOSPITAL.max_crutches)
|
|
|
|
keys << " crutches=" << hospital.max_crutches;
|
|
|
|
if (hospital.max_plaster != DEFAULT_HOSPITAL.max_plaster)
|
|
|
|
keys << " plaster=" << hospital.max_plaster;
|
|
|
|
if (hospital.max_buckets != DEFAULT_HOSPITAL.max_buckets)
|
|
|
|
keys << " buckets=" << hospital.max_buckets;
|
|
|
|
if (hospital.max_soap != DEFAULT_HOSPITAL.max_soap)
|
|
|
|
keys << " soap=" << hospital.max_soap;
|
|
|
|
keys << "}^";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (flags.bits.animal_training) keys << 't';
|
|
|
|
|
|
|
|
string keys_str = keys.str();
|
|
|
|
|
|
|
|
// there is no way to represent an active, but empty zone in quickfort
|
|
|
|
if (keys_str.empty())
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
// remove final '^' character if there is one
|
|
|
|
if (keys_str.back() == '^')
|
|
|
|
keys_str.pop_back();
|
|
|
|
|
|
|
|
return cache(keys_str);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char * get_tile_zone(const df::coord &pos,
|
|
|
|
const tile_context &ctx) {
|
|
|
|
vector<df::building_civzonest*> civzones;
|
|
|
|
if (!Buildings::findCivzonesAt(&civzones, pos))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
// we only have one "zone" blueprint, so use the "topmost" zone (that is,
|
|
|
|
// the one that is highlighted when the cursor is over this tile).
|
|
|
|
// overlapping zones are outside the scope of this plugin, I think.
|
|
|
|
df::building_civzonest *zone = civzones.back();
|
|
|
|
|
|
|
|
if (!is_rectangular(zone))
|
|
|
|
return get_zone_keys(zone);
|
|
|
|
|
|
|
|
if (zone->x1 != static_cast<int32_t>(pos.x)
|
|
|
|
|| zone->y1 != static_cast<int32_t>(pos.y)) {
|
|
|
|
return if_pretty(ctx, "`");
|
|
|
|
}
|
|
|
|
|
|
|
|
return add_expansion_syntax(zone, get_zone_keys(zone));
|
|
|
|
}
|
|
|
|
|
2021-09-10 15:19:50 -06:00
|
|
|
static const char * get_tile_query(const df::coord &, const tile_context &ctx) {
|
|
|
|
if (!ctx.b || !ctx.b->is_room)
|
|
|
|
return NULL;
|
|
|
|
return "r+";
|
2021-09-10 13:46:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool create_output_dir(color_ostream &out,
|
|
|
|
const blueprint_options &opts) {
|
|
|
|
string basename = "blueprints/" + opts.name;
|
|
|
|
size_t last_slash = basename.find_last_of("/");
|
|
|
|
string parent_path = basename.substr(0, last_slash);
|
|
|
|
|
|
|
|
// create output directory if it doesn't already exist
|
|
|
|
if (!Filesystem::mkdir_recursive(parent_path)) {
|
|
|
|
out.printerr("could not create output directory: '%s'\n",
|
|
|
|
parent_path.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2015-01-13 14:15:54 -07:00
|
|
|
}
|
|
|
|
|
2021-09-09 01:46:33 -06:00
|
|
|
static bool get_filename(string &fname,
|
|
|
|
color_ostream &out,
|
|
|
|
blueprint_options opts, // copy because we can't const
|
2021-09-10 13:46:07 -06:00
|
|
|
const string &phase) {
|
2021-09-09 01:46:33 -06:00
|
|
|
auto L = Lua::Core::State;
|
|
|
|
Lua::StackUnwinder top(L);
|
|
|
|
|
|
|
|
if (!lua_checkstack(L, 3) ||
|
|
|
|
!Lua::PushModulePublic(
|
2021-09-10 13:46:07 -06:00
|
|
|
out, L, "plugins.blueprint", "get_filename")) {
|
2021-09-09 01:46:33 -06:00
|
|
|
out.printerr("Failed to load blueprint Lua code\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Lua::Push(L, &opts);
|
|
|
|
Lua::Push(L, phase);
|
|
|
|
|
2021-09-10 13:46:07 -06:00
|
|
|
if (!Lua::SafeCall(out, L, 2, 1)) {
|
2021-09-09 01:46:33 -06:00
|
|
|
out.printerr("Failed Lua call to get_filename\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *s = lua_tostring(L, -1);
|
2021-09-10 13:46:07 -06:00
|
|
|
if (!s) {
|
2021-09-09 01:46:33 -06:00
|
|
|
out.printerr("Failed to retrieve filename from get_filename\n");
|
2021-06-29 15:25:30 -06:00
|
|
|
return false;
|
2021-09-09 01:46:33 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fname = s;
|
|
|
|
return true;
|
2021-06-29 15:25:30 -06:00
|
|
|
}
|
|
|
|
|
2021-09-10 21:16:37 -06:00
|
|
|
typedef vector<const char *> bp_row; // index is x coordinate
|
|
|
|
typedef map<int16_t, bp_row> bp_area; // key is y coordinate
|
|
|
|
typedef map<int16_t, bp_area> bp_volume; // key is z coordinate
|
2021-09-10 13:46:07 -06:00
|
|
|
|
2021-09-10 15:19:50 -06:00
|
|
|
typedef const char * (get_tile_fn)(const df::coord &pos,
|
|
|
|
const tile_context &ctx);
|
2021-09-10 13:46:07 -06:00
|
|
|
typedef void (init_ctx_fn)(const df::coord &pos, tile_context &ctx);
|
|
|
|
|
|
|
|
struct blueprint_processor {
|
|
|
|
bp_volume mapdata;
|
2021-10-04 12:14:44 -06:00
|
|
|
const string mode;
|
2021-09-10 15:19:50 -06:00
|
|
|
const string phase;
|
2021-10-02 13:52:43 -06:00
|
|
|
const bool force_create;
|
2021-09-10 15:19:50 -06:00
|
|
|
get_tile_fn * const get_tile;
|
|
|
|
init_ctx_fn * const init_ctx;
|
2021-10-04 12:14:44 -06:00
|
|
|
blueprint_processor(const string &mode, const string &phase,
|
|
|
|
bool force_create, get_tile_fn *get_tile,
|
2021-10-04 15:44:41 -06:00
|
|
|
init_ctx_fn *init_ctx)
|
2021-10-04 12:14:44 -06:00
|
|
|
: mode(mode), phase(phase), force_create(force_create),
|
|
|
|
get_tile(get_tile), init_ctx(init_ctx) { }
|
2021-09-10 13:46:07 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
static void write_minimal(ofstream &ofile, const blueprint_options &opts,
|
|
|
|
const bp_volume &mapdata) {
|
|
|
|
if (mapdata.begin() == mapdata.end())
|
|
|
|
return;
|
|
|
|
|
|
|
|
const string z_key = opts.depth > 0 ? "#<" : "#>";
|
|
|
|
|
|
|
|
int16_t zprev = 0;
|
|
|
|
for (auto area : mapdata) {
|
|
|
|
for ( ; zprev < area.first; ++zprev)
|
|
|
|
ofile << z_key << endl;
|
|
|
|
int16_t yprev = 0;
|
|
|
|
for (auto row : area.second) {
|
|
|
|
for ( ; yprev < row.first; ++yprev)
|
|
|
|
ofile << endl;
|
2021-09-10 21:16:37 -06:00
|
|
|
size_t xprev = 0;
|
|
|
|
auto &tiles = row.second;
|
|
|
|
size_t rowsize = tiles.size();
|
|
|
|
for (size_t x = 0; x < rowsize; ++x) {
|
|
|
|
if (!tiles[x])
|
|
|
|
continue;
|
|
|
|
for ( ; xprev < x; ++xprev)
|
2021-09-10 13:46:07 -06:00
|
|
|
ofile << ",";
|
2021-09-10 21:16:37 -06:00
|
|
|
ofile << tiles[x];
|
2021-09-10 13:46:07 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ofile << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void write_pretty(ofstream &ofile, const blueprint_options &opts,
|
|
|
|
const bp_volume &mapdata) {
|
|
|
|
const string z_key = opts.depth > 0 ? "#<" : "#>";
|
|
|
|
|
|
|
|
int16_t absdepth = abs(opts.depth);
|
|
|
|
for (int16_t z = 0; z < absdepth; ++z) {
|
|
|
|
const bp_area *area = NULL;
|
|
|
|
if (mapdata.count(z))
|
|
|
|
area = &mapdata.at(z);
|
|
|
|
for (int16_t y = 0; y < opts.height; ++y) {
|
|
|
|
const bp_row *row = NULL;
|
|
|
|
if (area && area->count(y))
|
|
|
|
row = &area->at(y);
|
|
|
|
for (int16_t x = 0; x < opts.width; ++x) {
|
2021-09-10 15:19:50 -06:00
|
|
|
const char *tile = NULL;
|
2021-09-10 21:16:37 -06:00
|
|
|
if (row)
|
2021-09-10 15:19:50 -06:00
|
|
|
tile = row->at(x);
|
|
|
|
ofile << (tile ? tile : " ") << ",";
|
2021-09-10 13:46:07 -06:00
|
|
|
}
|
|
|
|
ofile << "#" << endl;
|
|
|
|
}
|
|
|
|
if (z < absdepth - 1)
|
|
|
|
ofile << z_key << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-04 12:14:44 -06:00
|
|
|
static string get_modeline(const blueprint_options &opts, const string &mode,
|
|
|
|
const string &phase) {
|
2021-09-09 11:08:50 -06:00
|
|
|
std::ostringstream modeline;
|
2021-10-04 12:14:44 -06:00
|
|
|
modeline << "#" << mode << " label(" << phase << ")";
|
2021-09-17 12:07:42 -06:00
|
|
|
if (opts.playback_start.x > 0) {
|
|
|
|
modeline << " start(" << opts.playback_start.x
|
|
|
|
<< ";" << opts.playback_start.y;
|
|
|
|
if (!opts.playback_start_comment.empty()) {
|
|
|
|
modeline << ";" << opts.playback_start_comment;
|
|
|
|
}
|
|
|
|
modeline << ")";
|
|
|
|
}
|
2021-09-09 11:08:50 -06:00
|
|
|
|
|
|
|
return modeline.str();
|
|
|
|
}
|
|
|
|
|
2021-09-09 01:46:33 -06:00
|
|
|
static bool write_blueprint(color_ostream &out,
|
|
|
|
std::map<string, ofstream*> &output_files,
|
|
|
|
const blueprint_options &opts,
|
2021-09-10 13:46:07 -06:00
|
|
|
const blueprint_processor &processor,
|
|
|
|
bool pretty) {
|
2021-09-09 01:46:33 -06:00
|
|
|
string fname;
|
2021-09-10 13:46:07 -06:00
|
|
|
if (!get_filename(fname, out, opts, processor.phase))
|
2021-09-09 01:46:33 -06:00
|
|
|
return false;
|
|
|
|
if (!output_files.count(fname))
|
|
|
|
output_files[fname] = new ofstream(fname, ofstream::trunc);
|
|
|
|
|
|
|
|
ofstream &ofile = *output_files[fname];
|
2021-10-04 12:14:44 -06:00
|
|
|
ofile << get_modeline(opts, processor.mode, processor.phase) << endl;
|
2021-09-10 13:46:07 -06:00
|
|
|
|
|
|
|
if (pretty)
|
|
|
|
write_pretty(ofile, opts, processor.mapdata);
|
|
|
|
else
|
|
|
|
write_minimal(ofile, opts, processor.mapdata);
|
|
|
|
|
2021-09-09 01:46:33 -06:00
|
|
|
return true;
|
2020-07-15 17:57:14 -06:00
|
|
|
}
|
|
|
|
|
2021-09-10 15:44:24 -06:00
|
|
|
static void ensure_building(const df::coord &pos, tile_context &ctx) {
|
2021-09-10 13:46:07 -06:00
|
|
|
if (ctx.b)
|
|
|
|
return;
|
|
|
|
ctx.b = Buildings::findAtTile(pos);
|
|
|
|
}
|
|
|
|
|
2021-10-04 15:44:41 -06:00
|
|
|
static void add_processor(vector<blueprint_processor> &processors,
|
|
|
|
const blueprint_options &opts, const char *mode,
|
|
|
|
const char *phase, bool require_phase,
|
|
|
|
get_tile_fn * const get_tile,
|
|
|
|
init_ctx_fn * const init_ctx = NULL) {
|
|
|
|
if (opts.auto_phase || require_phase)
|
|
|
|
processors.push_back(blueprint_processor(mode, phase, require_phase,
|
|
|
|
get_tile, init_ctx));
|
|
|
|
}
|
|
|
|
|
2021-09-09 01:46:33 -06:00
|
|
|
static bool do_transform(color_ostream &out,
|
2021-09-10 13:46:07 -06:00
|
|
|
const df::coord &start, const df::coord &end,
|
2021-09-09 01:46:33 -06:00
|
|
|
const blueprint_options &opts,
|
2021-09-10 13:46:07 -06:00
|
|
|
vector<string> &filenames) {
|
2021-09-10 21:16:37 -06:00
|
|
|
// empty map instances to pass to emplace() below
|
|
|
|
static const bp_area EMPTY_AREA;
|
|
|
|
static const bp_row EMPTY_ROW;
|
|
|
|
|
2022-04-01 12:36:19 -06:00
|
|
|
if (opts.engrave) {
|
|
|
|
// initialize the engravings cache
|
|
|
|
for (auto engraving : world->engravings) {
|
|
|
|
engravings_cache.emplace(engraving->pos, engraving);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-10 13:46:07 -06:00
|
|
|
vector<blueprint_processor> processors;
|
2020-07-15 17:57:14 -06:00
|
|
|
|
2021-10-04 15:44:41 -06:00
|
|
|
add_processor(processors, opts, "dig", "dig", opts.dig, get_tile_dig);
|
2022-04-01 12:36:19 -06:00
|
|
|
add_processor(processors, opts, "dig", "smooth", opts.carve,
|
|
|
|
opts.engrave ? get_tile_smooth : get_tile_smooth_minimal);
|
|
|
|
add_processor(processors, opts, "dig", "carve", opts.carve,
|
|
|
|
opts.engrave ? get_tile_carve : get_tile_carve_minimal);
|
2021-10-04 15:44:41 -06:00
|
|
|
add_processor(processors, opts, "build", "build", opts.build,
|
|
|
|
get_tile_build, ensure_building);
|
|
|
|
add_processor(processors, opts, "place", "place", opts.place,
|
|
|
|
get_tile_place, ensure_building);
|
|
|
|
add_processor(processors, opts, "zone", "zone", opts.zone, get_tile_zone);
|
|
|
|
add_processor(processors, opts, "query", "query", opts.query,
|
|
|
|
get_tile_query, ensure_building);
|
2020-07-15 17:57:14 -06:00
|
|
|
|
2021-09-10 13:46:07 -06:00
|
|
|
if (processors.empty()) {
|
|
|
|
out.printerr("no phases requested! nothing to do!\n");
|
2021-05-21 07:52:16 -06:00
|
|
|
return false;
|
2020-07-15 17:57:14 -06:00
|
|
|
}
|
|
|
|
|
2021-09-10 13:46:07 -06:00
|
|
|
if (!create_output_dir(out, opts))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const bool pretty = opts.format != "minimal";
|
2021-05-04 14:19:49 -06:00
|
|
|
const int32_t z_inc = start.z < end.z ? 1 : -1;
|
2021-09-10 13:46:07 -06:00
|
|
|
for (int32_t z = start.z; z != end.z; z += z_inc) {
|
|
|
|
for (int32_t y = start.y; y < end.y; y++) {
|
|
|
|
for (int32_t x = start.x; x < end.x; x++) {
|
|
|
|
df::coord pos(x, y, z);
|
|
|
|
tile_context ctx;
|
|
|
|
ctx.pretty = pretty;
|
|
|
|
for (blueprint_processor &processor : processors) {
|
|
|
|
if (processor.init_ctx)
|
|
|
|
processor.init_ctx(pos, ctx);
|
2021-09-10 15:19:50 -06:00
|
|
|
const char *tile_str = processor.get_tile(pos, ctx);
|
|
|
|
if (tile_str) {
|
2021-09-10 13:46:07 -06:00
|
|
|
// ensure our z-index is in the order we want to write
|
|
|
|
auto area = processor.mapdata.emplace(abs(z - start.z),
|
2021-09-10 21:16:37 -06:00
|
|
|
EMPTY_AREA);
|
2021-09-10 13:46:07 -06:00
|
|
|
auto row = area.first->second.emplace(y - start.y,
|
2021-09-10 21:16:37 -06:00
|
|
|
EMPTY_ROW);
|
|
|
|
auto &tiles = row.first->second;
|
|
|
|
if (row.second)
|
|
|
|
tiles.resize(opts.width);
|
|
|
|
tiles[x - start.x] = tile_str;
|
2021-09-10 13:46:07 -06:00
|
|
|
}
|
|
|
|
}
|
2015-01-07 14:27:48 -07:00
|
|
|
}
|
2015-01-09 14:00:47 -07:00
|
|
|
}
|
2015-01-07 14:27:48 -07:00
|
|
|
}
|
2021-09-09 01:46:33 -06:00
|
|
|
|
|
|
|
std::map<string, ofstream*> output_files;
|
2021-09-10 13:46:07 -06:00
|
|
|
for (blueprint_processor &processor : processors) {
|
2021-10-02 13:52:43 -06:00
|
|
|
if (processor.mapdata.empty() && !processor.force_create)
|
|
|
|
continue;
|
2021-09-10 13:46:07 -06:00
|
|
|
if (!write_blueprint(out, output_files, opts, processor, pretty))
|
2021-09-10 15:44:24 -06:00
|
|
|
break;
|
2021-09-09 01:46:33 -06:00
|
|
|
}
|
|
|
|
|
2021-09-10 13:46:07 -06:00
|
|
|
for (auto &it : output_files) {
|
2021-09-09 01:46:33 -06:00
|
|
|
filenames.push_back(it.first);
|
|
|
|
it.second->close();
|
|
|
|
delete(it.second);
|
|
|
|
}
|
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(
|
2021-09-10 13:46:07 -06:00
|
|
|
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-09-10 13:46:07 -06:00
|
|
|
static void print_help(color_ostream &out) {
|
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,
|
2021-09-10 13:46:07 -06:00
|
|
|
vector<string> &files) {
|
2021-05-15 13:05:32 -06:00
|
|
|
CoreSuspender suspend;
|
|
|
|
|
2021-09-10 13:46:07 -06:00
|
|
|
if (parameters.size() >= 1 && parameters[0] == "gui") {
|
2021-05-15 00:02:04 -06:00
|
|
|
std::ostringstream command;
|
|
|
|
command << "gui/blueprint";
|
2021-09-10 13:46:07 -06:00
|
|
|
for (size_t i = 1; i < parameters.size(); ++i) {
|
2021-09-09 01:24:00 -06:00
|
|
|
command << " " << parameters[i];
|
2021-05-15 00:02:04 -06:00
|
|
|
}
|
|
|
|
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-09-10 13:46:07 -06:00
|
|
|
if (!get_options(out, options, parameters) || options.help) {
|
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
|
|
|
}
|
|
|
|
|
2021-09-10 13:46:07 -06:00
|
|
|
if (!Maps::IsValid()) {
|
2015-01-07 14:27:48 -07:00
|
|
|
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
|
2021-09-10 13:46:07 -06:00
|
|
|
df::coord start(options.start);
|
|
|
|
if (start.x == -30000) {
|
|
|
|
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-09-10 13:46:07 -06:00
|
|
|
if (!Maps::isValidTilePos(start)) {
|
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.
|
2021-09-10 13:46:07 -06:00
|
|
|
df::coord end(start.x + options.width, start.y + options.height,
|
|
|
|
start.z + options.depth);
|
2021-05-04 14:19:49 -06:00
|
|
|
|
|
|
|
// 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
|
|
|
|
2021-09-10 15:19:50 -06:00
|
|
|
bool ok = do_transform(out, start, end, options, files);
|
|
|
|
cache(NULL);
|
|
|
|
return ok;
|
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
|
2021-09-10 13:46:07 -06:00
|
|
|
static int run(lua_State *L) {
|
2021-05-21 07:52:16 -06:00
|
|
|
int argc = lua_gettop(L);
|
|
|
|
vector<string> argv;
|
|
|
|
|
2021-09-10 13:46:07 -06:00
|
|
|
for (int i = 1; i <= argc; ++i) {
|
2021-05-21 07:52:16 -06:00
|
|
|
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();
|
2021-09-10 13:46:07 -06:00
|
|
|
if (do_blueprint(*out, argv, files)) {
|
2021-05-21 07:52:16 -06:00
|
|
|
Lua::PushVector(L, files);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-09-10 13:46:07 -06:00
|
|
|
command_result blueprint(color_ostream &out, vector<string> ¶meters) {
|
2021-05-21 07:52:16 -06:00
|
|
|
vector<string> files;
|
2021-09-10 13:46:07 -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
|
|
|
|
};
|