Skip to content

Commit b78af72

Browse files
committed
record built constructions in blueprint
1 parent aa4b1ef commit b78af72

4 files changed

Lines changed: 122 additions & 62 deletions

File tree

docs/plugins/blueprint.rst

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ blueprint
77

88
With ``blueprint``, you can export the structure of a portion of your fortress
99
in a blueprint file that you (or anyone else) can later play back with
10-
`quickfort`.
10+
`gui/quickfort`.
1111

1212
Blueprints are ``.csv`` or ``.xlsx`` files created in the ``blueprints``
1313
subdirectory of your DF folder. The map area to turn into a blueprint is either
14-
selected interactively with the ``blueprint gui`` command or, if the GUI is not
14+
selected interactively with the ``gui/blueprint`` command or, if the GUI is not
1515
used, starts at the active cursor location and extends right and down for the
1616
requested width and height.
1717

@@ -27,16 +27,16 @@ Examples
2727
--------
2828

2929
``blueprint gui``
30-
Runs `gui/blueprint`, the interactive frontend, where all configuration for
31-
a ``blueprint`` command can be set visually and interactively.
30+
Runs `gui/blueprint`, the GUI frontend, where all configuration for a
31+
``blueprint`` command can be set visually and interactively.
3232
``blueprint 30 40 bedrooms``
3333
Generates blueprints for an area 30 tiles wide by 40 tiles tall, starting
3434
from the active cursor on the current z-level. Blueprints are written to
3535
``bedrooms.csv`` in the ``blueprints`` directory.
3636
``blueprint 30 40 bedrooms dig --cursor 108,100,150``
3737
Generates only the ``#dig`` blueprint in the ``bedrooms.csv`` file, and
38-
the start of the blueprint area is set to a specific value instead of using
39-
the in-game cursor position.
38+
the start of the blueprint area is set to a specific coordinate instead of
39+
using the in-game cursor position.
4040

4141
Positional parameters
4242
---------------------
@@ -66,8 +66,12 @@ phases; just separate them with a space.
6666
Generate quickfort ``#dig`` blueprints for digging natural stone.
6767
``carve``
6868
Generate quickfort ``#dig`` blueprints for smoothing and carving.
69+
``construct``
70+
Generate quickfort ``#build`` blueprints for constructions (e.g. flooring
71+
and walls).
6972
``build``
70-
Generate quickfort ``#build`` blueprints for constructions and buildings.
73+
Generate quickfort ``#build`` blueprints for buildings (including
74+
furniture).
7175
``place``
7276
Generate quickfort ``#place`` blueprints for placing stockpiles.
7377
``zone``

library/include/TileTypes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ namespace DFHack
116116
//This is a static string, overwritten with every call!
117117
//Support values > 2 even though they should never happen.
118118
//Copy string if it will be used.
119-
inline char * getStr() const
119+
inline const char * getStr() const
120120
{
121121
static char str[16];
122122

plugins/blueprint.cpp

Lines changed: 109 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,12 @@ struct blueprint_options {
8585
bool auto_phase = false;
8686

8787
// if not autodetecting, which phases to output
88-
bool dig = false;
88+
bool dig = false;
8989
bool carve = false;
90+
bool construct = false;
9091
bool build = false;
9192
bool place = false;
92-
bool zone = false;
93+
bool zone = false;
9394
bool query = false;
9495

9596
static struct_identity _identity;
@@ -110,6 +111,7 @@ static const struct_field_info blueprint_options_fields[] = {
110111
{ struct_field_info::PRIMITIVE, "auto_phase", offsetof(blueprint_options, auto_phase), &df::identity_traits<bool>::identity, 0, 0 },
111112
{ struct_field_info::PRIMITIVE, "dig", offsetof(blueprint_options, dig), &df::identity_traits<bool>::identity, 0, 0 },
112113
{ struct_field_info::PRIMITIVE, "carve", offsetof(blueprint_options, carve), &df::identity_traits<bool>::identity, 0, 0 },
114+
{ struct_field_info::PRIMITIVE, "construct", offsetof(blueprint_options, construct), &df::identity_traits<bool>::identity, 0, 0 },
113115
{ struct_field_info::PRIMITIVE, "build", offsetof(blueprint_options, build), &df::identity_traits<bool>::identity, 0, 0 },
114116
{ struct_field_info::PRIMITIVE, "place", offsetof(blueprint_options, place), &df::identity_traits<bool>::identity, 0, 0 },
115117
{ struct_field_info::PRIMITIVE, "zone", offsetof(blueprint_options, zone), &df::identity_traits<bool>::identity, 0, 0 },
@@ -332,6 +334,108 @@ static const char * get_tile_carve(const df::coord &pos, const tile_context &tc)
332334
return NULL;
333335
}
334336

337+
static const char * get_construction_str(df::building *b) {
338+
df::building_constructionst *cons =
339+
virtual_cast<df::building_constructionst>(b);
340+
if (!cons)
341+
return "~";
342+
343+
switch (cons->type) {
344+
case construction_type::Fortification: return "CF";
345+
case construction_type::Wall: return "Cw";
346+
case construction_type::Floor: return "Cf";
347+
case construction_type::UpStair: return "Cu";
348+
case construction_type::DownStair: return "Cd";
349+
case construction_type::UpDownStair: return "Cx";
350+
case construction_type::Ramp: return "Cr";
351+
case construction_type::TrackN: return "trackN";
352+
case construction_type::TrackS: return "trackS";
353+
case construction_type::TrackE: return "trackE";
354+
case construction_type::TrackW: return "trackW";
355+
case construction_type::TrackNS: return "trackNS";
356+
case construction_type::TrackNE: return "trackNE";
357+
case construction_type::TrackNW: return "trackNW";
358+
case construction_type::TrackSE: return "trackSE";
359+
case construction_type::TrackSW: return "trackSW";
360+
case construction_type::TrackEW: return "trackEW";
361+
case construction_type::TrackNSE: return "trackNSE";
362+
case construction_type::TrackNSW: return "trackNSW";
363+
case construction_type::TrackNEW: return "trackNEW";
364+
case construction_type::TrackSEW: return "trackSEW";
365+
case construction_type::TrackNSEW: return "trackNSEW";
366+
case construction_type::TrackRampN: return "trackrampN";
367+
case construction_type::TrackRampS: return "trackrampS";
368+
case construction_type::TrackRampE: return "trackrampE";
369+
case construction_type::TrackRampW: return "trackrampW";
370+
case construction_type::TrackRampNS: return "trackrampNS";
371+
case construction_type::TrackRampNE: return "trackrampNE";
372+
case construction_type::TrackRampNW: return "trackrampNW";
373+
case construction_type::TrackRampSE: return "trackrampSE";
374+
case construction_type::TrackRampSW: return "trackrampSW";
375+
case construction_type::TrackRampEW: return "trackrampEW";
376+
case construction_type::TrackRampNSE: return "trackrampNSE";
377+
case construction_type::TrackRampNSW: return "trackrampNSW";
378+
case construction_type::TrackRampNEW: return "trackrampNEW";
379+
case construction_type::TrackRampSEW: return "trackrampSEW";
380+
case construction_type::TrackRampNSEW: return "trackrampNSEW";
381+
case construction_type::NONE:
382+
default:
383+
return "~";
384+
}
385+
}
386+
387+
static const char * get_constructed_track_str(df::tiletype *tt,
388+
const char * base) {
389+
TileDirection dir = tileDirection(*tt);
390+
if (!dir.whole)
391+
return "~";
392+
393+
std::ostringstream str;
394+
str << base;
395+
if (dir.north) str << "N";
396+
if (dir.south) str << "S";
397+
if (dir.east) str << "E";
398+
if (dir.west) str << "W";
399+
400+
return cache(str);
401+
}
402+
403+
static const char * get_constructed_floor_str(df::tiletype *tt) {
404+
if (tileSpecial(*tt) != df::tiletype_special::TRACK)
405+
return "Cf";
406+
return get_constructed_track_str(tt, "track");
407+
}
408+
409+
static const char * get_constructed_ramp_str(df::tiletype *tt) {
410+
if (tileSpecial(*tt) != df::tiletype_special::TRACK)
411+
return "Cr";
412+
return get_constructed_track_str(tt, "trackramp");
413+
}
414+
415+
static const char * get_tile_construct(const df::coord &pos,
416+
const tile_context &ctx) {
417+
if (ctx.b && ctx.b->getType() == building_type::Construction)
418+
return get_construction_str(ctx.b);
419+
420+
df::tiletype *tt = Maps::getTileType(pos);
421+
if (!tt || tileMaterial(*tt) != df::tiletype_material::CONSTRUCTION)
422+
return NULL;
423+
424+
switch (tileShape(*tt)) {
425+
case tiletype_shape::WALL: return "Cw";
426+
case tiletype_shape::FLOOR: return get_constructed_floor_str(tt);
427+
case tiletype_shape::RAMP: return get_constructed_ramp_str(tt);
428+
case tiletype_shape::FORTIFICATION: return "CF";
429+
case tiletype_shape::STAIR_UP: return "Cu";
430+
case tiletype_shape::STAIR_DOWN: return "Cd";
431+
case tiletype_shape::STAIR_UPDOWN: return "Cx";
432+
default:
433+
return "~";
434+
}
435+
436+
return NULL;
437+
}
438+
335439
static pair<uint32_t, uint32_t> get_building_size(const df::building *b) {
336440
return pair<uint32_t, uint32_t>(b->x2 - b->x1 + 1, b->y2 - b->y1 + 1);
337441
}
@@ -461,56 +565,6 @@ static const char * get_furnace_str(df::building *b) {
461565
}
462566
}
463567

464-
static const char * get_construction_str(df::building *b) {
465-
df::building_constructionst *cons =
466-
virtual_cast<df::building_constructionst>(b);
467-
if (!cons)
468-
return "~";
469-
470-
switch (cons->type) {
471-
case construction_type::Fortification: return "CF";
472-
case construction_type::Wall: return "Cw";
473-
case construction_type::Floor: return "Cf";
474-
case construction_type::UpStair: return "Cu";
475-
case construction_type::DownStair: return "Cd";
476-
case construction_type::UpDownStair: return "Cx";
477-
case construction_type::Ramp: return "Cr";
478-
case construction_type::TrackN: return "trackN";
479-
case construction_type::TrackS: return "trackS";
480-
case construction_type::TrackE: return "trackE";
481-
case construction_type::TrackW: return "trackW";
482-
case construction_type::TrackNS: return "trackNS";
483-
case construction_type::TrackNE: return "trackNE";
484-
case construction_type::TrackNW: return "trackNW";
485-
case construction_type::TrackSE: return "trackSE";
486-
case construction_type::TrackSW: return "trackSW";
487-
case construction_type::TrackEW: return "trackEW";
488-
case construction_type::TrackNSE: return "trackNSE";
489-
case construction_type::TrackNSW: return "trackNSW";
490-
case construction_type::TrackNEW: return "trackNEW";
491-
case construction_type::TrackSEW: return "trackSEW";
492-
case construction_type::TrackNSEW: return "trackNSEW";
493-
case construction_type::TrackRampN: return "trackrampN";
494-
case construction_type::TrackRampS: return "trackrampS";
495-
case construction_type::TrackRampE: return "trackrampE";
496-
case construction_type::TrackRampW: return "trackrampW";
497-
case construction_type::TrackRampNS: return "trackrampNS";
498-
case construction_type::TrackRampNE: return "trackrampNE";
499-
case construction_type::TrackRampNW: return "trackrampNW";
500-
case construction_type::TrackRampSE: return "trackrampSE";
501-
case construction_type::TrackRampSW: return "trackrampSW";
502-
case construction_type::TrackRampEW: return "trackrampEW";
503-
case construction_type::TrackRampNSE: return "trackrampNSE";
504-
case construction_type::TrackRampNSW: return "trackrampNSW";
505-
case construction_type::TrackRampNEW: return "trackrampNEW";
506-
case construction_type::TrackRampSEW: return "trackrampSEW";
507-
case construction_type::TrackRampNSEW: return "trackrampNSEW";
508-
case construction_type::NONE:
509-
default:
510-
return "~";
511-
}
512-
}
513-
514568
static const char * get_trap_str(df::building *b) {
515569
df::building_trapst *trap = virtual_cast<df::building_trapst>(b);
516570
if (!trap)
@@ -622,6 +676,7 @@ static const char * get_build_keys(const df::coord &pos,
622676
bool at_center = static_cast<int32_t>(pos.x) == ctx.b->centerx
623677
&& static_cast<int32_t>(pos.y) == ctx.b->centery;
624678

679+
// building_type::Construction is handled by the construction phase
625680
switch(ctx.b->getType()) {
626681
case building_type::Armorstand:
627682
return "a";
@@ -666,8 +721,6 @@ static const char * get_build_keys(const df::coord &pos,
666721
return "y";
667722
case building_type::WindowGem:
668723
return "Y";
669-
case building_type::Construction:
670-
return get_construction_str(ctx.b);
671724
case building_type::Shop:
672725
return do_block_building(ctx, "z", at_center);
673726
case building_type::AnimalTrap:
@@ -1132,6 +1185,8 @@ static bool do_transform(color_ostream &out,
11321185
smooth_get_tile_fn);
11331186
add_processor(processors, opts, "dig", "carve", opts.carve,
11341187
opts.engrave ? get_tile_carve : get_tile_carve_minimal);
1188+
add_processor(processors, opts, "build", "construct", opts.construct,
1189+
get_tile_construct, ensure_building);
11351190
add_processor(processors, opts, "build", "build", opts.build,
11361191
get_tile_build, ensure_building);
11371192
add_processor(processors, opts, "place", "place", opts.place,

plugins/lua/blueprint.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ local utils = require('utils')
66
local valid_phase_list = {
77
'dig',
88
'carve',
9+
'construct',
910
'build',
1011
'place',
1112
'zone',

0 commit comments

Comments
 (0)