From 2a59d6861316fd5dbaa3f9c61e6b5cc56f450669 Mon Sep 17 00:00:00 2001 From: Steffen Mecke Date: Mon, 9 Aug 2021 14:20:39 +0200 Subject: [PATCH] write new default orders to cr --- src/creport.c | 12 +++++------- src/creport.test.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/src/creport.c b/src/creport.c index c5dd62408..7e014319f 100644 --- a/src/creport.c +++ b/src/creport.c @@ -477,7 +477,7 @@ static int cr_spell(variant var, const char *name, char *buffer, const void *use spell *sp = (spell *)var.v; if (sp != NULL) { sprintf(buffer, "\"%s\";%s\n", spell_name(mkname_spell(sp), report->locale), name); - } + } else { sprintf(buffer, "\"\";%s\n", name); } @@ -597,7 +597,7 @@ static void cr_output_battles(FILE * F, faction * f) } /* prints a building */ -static void cr_output_building(struct stream *out, building *b, +static void cr_output_building(struct stream *out, building *b, const unit *owner, int fno, faction *f) { const char *bname, *billusion; @@ -881,11 +881,9 @@ void cr_output_unit(stream *out, const faction * f, stream_printf(out, "COMMANDS\n"); for (ord = u->old_orders; ord; ord = ord->next) { /* this new order will replace the old defaults */ - if (is_persistent(ord)) { - swrite("\"", 1, 1, out); - stream_order(out, ord, lang, true); - swrite("\"\n", 1, 2, out); - } + swrite("\"", 1, 1, out); + stream_order(out, ord, lang, true); + swrite("\"\n", 1, 2, out); } for (ord = u->orders; ord; ord = ord->next) { keyword_t kwd = getkeyword(ord); diff --git a/src/creport.test.c b/src/creport.test.c index 5081e66c6..90f1bf212 100644 --- a/src/creport.test.c +++ b/src/creport.test.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -502,6 +503,39 @@ static void test_cr_factionstealth(CuTest *tc) { test_teardown(); } +static void test_cr_default(CuTest *tc) { + stream strm; + char line[1024]; + faction *f; + region *r; + unit *u; + order *order = 0; + + test_setup(); + f = test_create_faction(); + r = test_create_region(0, 0, NULL); + u = test_create_unit(f, r); + + order = create_order(K_MOVE, f->locale, shortdirections[D_EAST] + 4); + addlist(&u->old_orders, order); + order = create_order(K_GIVE, f->locale, "0 1 silver"); + addlist(&u->old_orders, order); + + mstream_init(&strm); + cr_output_unit(&strm, f, u, seen_unit); + strm.api->rewind(strm.handle); + do { + CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); + } while (strcmp("COMMANDS", line) != 0); + CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); + CuAssertStrEquals(tc, "\"move east\"", line); + CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); + CuAssertStrEquals(tc, "\"give 0 1 silver\"", line); + CuAssertIntEquals(tc, -1, strm.api->readln(strm.handle, line, sizeof(line))); + mstream_done(&strm); + test_teardown(); +} + CuSuite *get_creport_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -511,5 +545,6 @@ CuSuite *get_creport_suite(void) SUITE_ADD_TEST(suite, test_cr_mallorn); SUITE_ADD_TEST(suite, test_cr_hiderace); SUITE_ADD_TEST(suite, test_cr_factionstealth); + SUITE_ADD_TEST(suite, test_cr_default); return suite; }