Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

write new default orders to cr #945

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/creport.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
35 changes: 35 additions & 0 deletions src/creport.test.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <kernel/building.h>
#include <kernel/faction.h>
#include <kernel/item.h>
#include <kernel/order.h>
#include <kernel/race.h>
#include <kernel/region.h>
#include <kernel/resources.h>
Expand Down Expand Up @@ -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();
Expand All @@ -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;
}