Skip to content

Commit 32ed4f6

Browse files
authored
Merge pull request #4974 from Bumber64/blueprint_changes
Small blueprint.cpp changes
2 parents 141e91e + 96cc1b2 commit 32ed4f6

1 file changed

Lines changed: 29 additions & 24 deletions

File tree

plugins/blueprint.cpp

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@
4141
#include "df/world.h"
4242

4343
using std::endl;
44+
using std::map;
4445
using std::ofstream;
46+
using std::ostringstream;
4547
using std::pair;
46-
using std::map;
4748
using std::string;
4849
using std::vector;
4950
using namespace DFHack;
@@ -242,7 +243,7 @@ static const char * cache(const string &str) {
242243
}
243244

244245
// Convenience wrapper for std::ostringstream.
245-
static const char * cache(std::ostringstream &str) {
246+
static const char * cache(ostringstream &str) {
246247
return cache(str.str());
247248
}
248249

@@ -622,7 +623,7 @@ static const char * get_constructed_track_str(df::tiletype *tt,
622623
if (!dir.whole)
623624
return "~";
624625

625-
std::ostringstream str;
626+
ostringstream str;
626627
str << base;
627628
if (dir.north) str << "N";
628629
if (dir.south) str << "S";
@@ -810,7 +811,7 @@ static const char * get_trap_str(df::building *b) {
810811
case trap_type::CageTrap: return "Tc";
811812
case trap_type::TrackStop:
812813
{
813-
std::ostringstream buf;
814+
ostringstream buf;
814815
buf << "CS";
815816
if (trap->track_stop_info.track_flags.bits.use_dump) {
816817
if (trap->track_stop_info.dump_x_shift == 0) {
@@ -1022,7 +1023,7 @@ static const char * add_expansion_syntax(const df::building *bld,
10221023
const char *keys) {
10231024
if (!keys)
10241025
return "~";
1025-
std::ostringstream s;
1026+
ostringstream s;
10261027
pair<uint32_t, uint32_t> size = get_building_size(bld);
10271028
s << keys << "(" << size.first << "x" << size.second << ")";
10281029
return cache(s);
@@ -1037,7 +1038,7 @@ static const char * add_label(const tile_context &ctx, const char *keys) {
10371038
if (!keys)
10381039
return "~";
10391040
auto bld = ctx.b;
1040-
std::ostringstream s;
1041+
ostringstream s;
10411042
// use building's id as the unique label
10421043
s << keys << "/" << "bld_" << bld->id;
10431044
return cache(s);
@@ -1124,7 +1125,7 @@ static const char * get_zone_keys(const df::building_civzonest *zone) {
11241125
df::building_civzonest::T_gather_flags::mask_gather_fallen;
11251126
static const df::hospital_supplies DEFAULT_HOSPITAL;
11261127
1127-
std::ostringstream keys;
1128+
ostringstream keys;
11281129
const df::building_civzonest::T_zone_flags &flags = zone->zone_flags;
11291130
11301131
// inverted logic for Active since it's on by default
@@ -1216,12 +1217,12 @@ static const char * get_tile_zone(const df::coord &pos,
12161217
// surrounds the given string in quotes and replaces internal double quotes (")
12171218
// with double double quotes ("") (as per the csv spec)
12181219
static string csv_quote(const string &str) {
1219-
std::ostringstream outstr;
1220+
ostringstream outstr;
12201221
outstr << "\"";
12211222
12221223
size_t start = 0;
12231224
auto end = str.find('"');
1224-
while (end != std::string::npos) {
1225+
while (end != string::npos) {
12251226
outstr << str.substr(start, end - start);
12261227
outstr << "\"\"";
12271228
start = end + 1;
@@ -1254,7 +1255,7 @@ static const char * get_tile_query(const df::coord &pos,
12541255
if (!bld_name.size() && !zone_name.size())
12551256
return NULL;
12561257
1257-
std::ostringstream str;
1258+
ostringstream str;
12581259
if (bld_name.size())
12591260
str << "{givename name=" + csv_quote(bld_name) + "}";
12601261
if (zone_name.size())
@@ -1286,7 +1287,7 @@ static const char * get_tile_rooms(const df::coord &, const tile_context &ctx) {
12861287
case 4: return "r+&";
12871288
}
12881289
1289-
std::ostringstream str;
1290+
ostringstream str;
12901291
str << "r{+ " << (max_dim - 3) << "}&";
12911292
return cache(str);
12921293
}
@@ -1348,11 +1349,11 @@ static void write_minimal(ofstream &ofile, const blueprint_options &opts,
13481349
const string z_key = opts.depth > 0 ? "#<" : "#>";
13491350

13501351
int16_t zprev = 0;
1351-
for (auto area : mapdata) {
1352+
for (auto &area : mapdata) {
13521353
for ( ; zprev < area.first; ++zprev)
13531354
ofile << z_key << endl;
13541355
int16_t yprev = 0;
1355-
for (auto row : area.second) {
1356+
for (auto &row : area.second) {
13561357
for ( ; yprev < row.first; ++yprev)
13571358
ofile << endl;
13581359
size_t xprev = 0;
@@ -1398,7 +1399,7 @@ static void write_pretty(ofstream &ofile, const blueprint_options &opts,
13981399

13991400
static string get_modeline(color_ostream &out, const blueprint_options &opts,
14001401
const string &mode, const string &phase) {
1401-
std::ostringstream modeline;
1402+
ostringstream modeline;
14021403
modeline << "#" << mode << " label(" << phase << ")";
14031404
if (opts.playback_start.x > 0) {
14041405
modeline << " start(" << opts.playback_start.x
@@ -1415,7 +1416,7 @@ static string get_modeline(color_ostream &out, const blueprint_options &opts,
14151416
}
14161417

14171418
static bool write_blueprint(color_ostream &out,
1418-
std::map<string, ofstream*> &output_files,
1419+
map<string, ofstream*> &output_files,
14191420
const blueprint_options &opts,
14201421
const blueprint_processor &processor,
14211422
bool pretty, int32_t ordinal) {
@@ -1437,9 +1438,9 @@ static bool write_blueprint(color_ostream &out,
14371438
}
14381439

14391440
static void write_meta_blueprint(color_ostream &out,
1440-
std::map<string, ofstream*> &output_files,
1441+
map<string, ofstream*> &output_files,
14411442
const blueprint_options &opts,
1442-
const std::vector<string> & meta_phases,
1443+
const vector<string> & meta_phases,
14431444
int32_t ordinal) {
14441445
string fname;
14451446
get_filename(fname, out, opts, meta_phases.front(), ordinal);
@@ -1545,7 +1546,7 @@ static bool do_transform(color_ostream &out,
15451546
}
15461547
}
15471548

1548-
std::vector<string> meta_phases;
1549+
vector<string> meta_phases;
15491550
for (blueprint_processor &processor : processors) {
15501551
if (processor.mapdata.empty() && !processor.force_create)
15511552
continue;
@@ -1557,7 +1558,7 @@ static bool do_transform(color_ostream &out,
15571558

15581559
bool in_meta = false;
15591560
int32_t ordinal = 0;
1560-
std::map<string, ofstream*> output_files;
1561+
map<string, ofstream*> output_files;
15611562
for (blueprint_processor &processor : processors) {
15621563
if (processor.mapdata.empty() && !processor.force_create)
15631564
continue;
@@ -1593,7 +1594,7 @@ static command_result do_blueprint(color_ostream &out,
15931594
CoreSuspender suspend;
15941595

15951596
if (parameters.size() >= 1 && parameters[0] == "gui") {
1596-
std::ostringstream command;
1597+
ostringstream command;
15971598
command << "gui/blueprint";
15981599
for (size_t i = 1; i < parameters.size(); ++i) {
15991600
command << " " << parameters[i];
@@ -1619,7 +1620,7 @@ static command_result do_blueprint(color_ostream &out,
16191620

16201621
// start coordinates can come from either the commandline or the map cursor
16211622
df::coord start(options.start);
1622-
if (start.x == -30000) {
1623+
if (!start.isValid()) {
16231624
if (!Gui::getCursorCoords(start)) {
16241625
out.printerr("Can't get cursor coords! Make sure you specify the"
16251626
" --cursor parameter or have an active cursor in DF.\n");
@@ -1686,9 +1687,13 @@ command_result blueprint(color_ostream &out, vector<string> &parameters) {
16861687
vector<string> files;
16871688
command_result cr = do_blueprint(out, parameters, files);
16881689
if (cr == CR_OK) {
1689-
out.print("Generated blueprint file(s):\n");
1690-
for (string &fname : files)
1691-
out.print(" %s\n", fname.c_str());
1690+
if (files.empty()) // Just natural walls, etc.
1691+
out.print("No resulting blueprint.\n");
1692+
else {
1693+
out.print("Generated blueprint file(s):\n");
1694+
for (string &fname : files)
1695+
out.print(" %s\n", fname.c_str());
1696+
}
16921697
}
16931698
return cr;
16941699
}

0 commit comments

Comments
 (0)