forked from github/server
Merge branch 'develop' of https://github.com/ennorehling/eressea into develop
This commit is contained in:
commit
bf61a2284e
6 changed files with 114 additions and 13 deletions
|
@ -3339,7 +3339,6 @@ int pay_cmd(unit * u, struct order *ord)
|
|||
cmistake(u, ord, 6, MSG_EVENT);
|
||||
}
|
||||
else {
|
||||
building *b = NULL;
|
||||
param_t p;
|
||||
int id;
|
||||
|
||||
|
@ -3355,13 +3354,12 @@ int pay_cmd(unit * u, struct order *ord)
|
|||
}
|
||||
else {
|
||||
/* If no building id is given or it is the id of our building, just set the do-not-pay flag */
|
||||
if (id == 0 || id == u->building->no)
|
||||
{
|
||||
if (id == 0 || id == u->building->no) {
|
||||
u->building->flags |= BLD_DONTPAY;
|
||||
}
|
||||
else {
|
||||
/* Find the building that matches to the given id*/
|
||||
b = findbuilding(id);
|
||||
building *b = findbuilding(id);
|
||||
/* If there is a building and it is in the same region as the unit continue, else: error */
|
||||
if (b && b->region == u->region)
|
||||
{
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include <string.h>
|
||||
|
||||
static void begin_orders(unit *u) {
|
||||
if (u->flags & UFL_ORDERS) {
|
||||
if ((u->flags & UFL_ORDERS) == 0) {
|
||||
order **ordp;
|
||||
/* alle wiederholbaren, langen befehle werden gesichert: */
|
||||
u->flags |= UFL_ORDERS;
|
||||
|
@ -47,13 +47,12 @@ static void begin_orders(unit *u) {
|
|||
u->orders = NULL;
|
||||
}
|
||||
|
||||
static unit *unitorders(input *in, faction *f)
|
||||
static void unitorders(input *in, faction *f)
|
||||
{
|
||||
int i;
|
||||
unit *u;
|
||||
|
||||
if (!f)
|
||||
return NULL;
|
||||
assert(f);
|
||||
|
||||
i = getid();
|
||||
u = findunit(i);
|
||||
|
@ -120,10 +119,6 @@ static unit *unitorders(input *in, faction *f)
|
|||
}
|
||||
|
||||
}
|
||||
else {
|
||||
return NULL;
|
||||
}
|
||||
return u;
|
||||
}
|
||||
|
||||
static faction *factionorders(void)
|
||||
|
@ -189,7 +184,8 @@ int read_orders(input *in)
|
|||
* vermerkt. */
|
||||
|
||||
case P_UNIT:
|
||||
if (!f || !unitorders(in, f)) {
|
||||
if (f) {
|
||||
unitorders(in, f);
|
||||
do {
|
||||
b = in->getbuf(in->data);
|
||||
if (!b) {
|
||||
|
|
|
@ -3,9 +3,20 @@
|
|||
|
||||
#include "orderfile.h"
|
||||
|
||||
#include "direction.h"
|
||||
|
||||
#include <kernel/calendar.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/order.h>
|
||||
#include <kernel/unit.h>
|
||||
|
||||
#include <util/base36.h>
|
||||
#include <util/keyword.h>
|
||||
#include <util/language.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/message.h>
|
||||
#include <util/param.h>
|
||||
#include <util/password.h>
|
||||
|
||||
#include <CuTest.h>
|
||||
#include <tests.h>
|
||||
|
@ -24,6 +35,52 @@ static void test_read_orders(CuTest *tc) {
|
|||
test_teardown();
|
||||
}
|
||||
|
||||
static const char *getbuf_strings(void *data)
|
||||
{
|
||||
strlist **listp = (strlist **)data;
|
||||
if (listp && *listp) {
|
||||
strlist *list = *listp;
|
||||
*listp = list->next;
|
||||
return list->s;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void test_unit_orders(CuTest *tc) {
|
||||
input in;
|
||||
unit *u;
|
||||
faction *f;
|
||||
strlist *orders = NULL, *backup;
|
||||
char buf[64];
|
||||
|
||||
test_setup();
|
||||
u = test_create_unit(f = test_create_faction(NULL), test_create_plain(0, 0));
|
||||
f->locale = test_create_locale();
|
||||
u->orders = create_order(K_ENTERTAIN, f->locale, NULL);
|
||||
faction_setpassword(f, password_hash("password", PASSWORD_DEFAULT));
|
||||
snprintf(buf, sizeof(buf), "%s %s %s",
|
||||
LOC(f->locale, parameters[P_FACTION]), itoa36(f->no), "password");
|
||||
addstrlist(&orders, buf);
|
||||
snprintf(buf, sizeof(buf), "%s %s",
|
||||
LOC(f->locale, parameters[P_UNIT]), itoa36(u->no));
|
||||
addstrlist(&orders, buf);
|
||||
snprintf(buf, sizeof(buf), "%s %s", keyword_name(K_MOVE, f->locale),
|
||||
LOC(f->locale, shortdirections[D_WEST]));
|
||||
backup = orders;
|
||||
addstrlist(&orders, buf);
|
||||
in.data = &orders;
|
||||
in.getbuf = getbuf_strings;
|
||||
CuAssertIntEquals(tc, 0, read_orders(&in));
|
||||
CuAssertPtrNotNull(tc, u->old_orders);
|
||||
CuAssertPtrNotNull(tc, u->orders);
|
||||
CuAssertPtrEquals(tc, NULL, orders);
|
||||
CuAssertIntEquals(tc, K_MOVE, getkeyword(u->orders));
|
||||
CuAssertIntEquals(tc, K_ENTERTAIN, getkeyword(u->old_orders));
|
||||
CuAssertIntEquals(tc, UFL_ORDERS, u->flags & UFL_ORDERS);
|
||||
freestrlist(backup);
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
typedef struct order_list {
|
||||
const char **orders;
|
||||
int next;
|
||||
|
@ -85,6 +142,7 @@ CuSuite *get_orderfile_suite(void)
|
|||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_read_orders);
|
||||
SUITE_ADD_TEST(suite, test_unit_orders);
|
||||
SUITE_ADD_TEST(suite, test_faction_password_okay);
|
||||
SUITE_ADD_TEST(suite, test_faction_password_bad);
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "kernel/building.h"
|
||||
#include "kernel/faction.h"
|
||||
#include "kernel/item.h"
|
||||
#include "kernel/messages.h"
|
||||
#include "kernel/race.h"
|
||||
#include "kernel/region.h"
|
||||
#include "kernel/ship.h"
|
||||
|
@ -29,6 +30,7 @@
|
|||
#include "util/language.h"
|
||||
#include "util/lists.h"
|
||||
#include "util/message.h"
|
||||
#include "util/nrmessage.h"
|
||||
|
||||
#include "attributes/attributes.h"
|
||||
#include "attributes/key.h"
|
||||
|
@ -906,6 +908,46 @@ static void test_visible_unit(CuTest *tc) {
|
|||
test_teardown();
|
||||
}
|
||||
|
||||
static void test_eval_functions(CuTest *tc)
|
||||
{
|
||||
message *msg;
|
||||
message_type *mtype;
|
||||
item *items = NULL;
|
||||
char buf[1024];
|
||||
struct locale * lang;
|
||||
|
||||
test_setup();
|
||||
init_resources();
|
||||
test_create_itemtype("stone");
|
||||
test_create_itemtype("iron");
|
||||
|
||||
lang = test_create_locale();
|
||||
locale_setstring(lang, "nr_claims", "$resources($items)");
|
||||
register_reports();
|
||||
mtype = mt_create_va(mt_new("nr_claims", NULL), "items:items", MT_NEW_END);
|
||||
nrt_register(mtype);
|
||||
|
||||
msg = msg_message("nr_claims", "items", items);
|
||||
nr_render(msg, lang, buf, sizeof(buf), NULL);
|
||||
CuAssertStrEquals(tc, "", buf);
|
||||
msg_release(msg);
|
||||
|
||||
i_change(&items, get_resourcetype(R_IRON)->itype, 1);
|
||||
msg = msg_message("nr_claims", "items", items);
|
||||
nr_render(msg, lang, buf, sizeof(buf), NULL);
|
||||
CuAssertStrEquals(tc, "1 Eisen", buf);
|
||||
msg_release(msg);
|
||||
|
||||
i_change(&items, get_resourcetype(R_STONE)->itype, 2);
|
||||
msg = msg_message("nr_claims", "items", items);
|
||||
nr_render(msg, lang, buf, sizeof(buf), NULL);
|
||||
CuAssertStrEquals(tc, "1 Eisen, 2 Steine", buf);
|
||||
msg_release(msg);
|
||||
i_freeall(&items);
|
||||
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
CuSuite *get_reports_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
|
@ -936,5 +978,6 @@ CuSuite *get_reports_suite(void)
|
|||
SUITE_ADD_TEST(suite, test_insect_warnings);
|
||||
SUITE_ADD_TEST(suite, test_newbie_warning);
|
||||
SUITE_ADD_TEST(suite, test_visible_unit);
|
||||
SUITE_ADD_TEST(suite, test_eval_functions);
|
||||
return suite;
|
||||
}
|
||||
|
|
|
@ -88,6 +88,11 @@ bool keyword_disabled(keyword_t kwd) {
|
|||
return disabled_kwd[kwd];
|
||||
}
|
||||
|
||||
const char *keyword_name(keyword_t kwd, const struct locale *lang)
|
||||
{
|
||||
return LOC(lang, mkname("keyword", keywords[kwd]));
|
||||
}
|
||||
|
||||
const char *keywords[MAXKEYWORDS] = {
|
||||
"//",
|
||||
"banner",
|
||||
|
|
|
@ -83,6 +83,7 @@ extern "C"
|
|||
void init_keywords(const struct locale *lang);
|
||||
void init_keyword(const struct locale *lang, keyword_t kwd, const char *str);
|
||||
bool keyword_disabled(keyword_t kwd);
|
||||
const char *keyword_name(keyword_t kwd, const struct locale *lang);
|
||||
void enable_keyword(keyword_t kwd, bool enabled);
|
||||
const char *keyword(keyword_t kwd);
|
||||
|
||||
|
|
Loading…
Reference in a new issue