forked from github/server
Merge branch 'develop' of https://github.com/ennorehling/eressea into develop
This commit is contained in:
commit
ed6a6b4cf2
|
@ -34,4 +34,4 @@ fi
|
|||
tar cjf backup/$TURN.tar.bz2 $files
|
||||
echo "uploading game-$GAME/$TURN.tar.bz2"
|
||||
curl -s -n -T backup/$TURN.tar.bz2 https://dav.box.com/dav/Eressea/game-$GAME/$TURN.tar.bz2
|
||||
curl -s -n -T eressea.db https://dav.box.com/dav/Eressea/eressea.db
|
||||
#curl -s -n -T eressea.db https://dav.box.com/dav/Eressea/eressea.db
|
||||
|
|
|
@ -26,7 +26,6 @@ static void test_herbsearch(CuTest * tc)
|
|||
const item_type *itype;
|
||||
|
||||
test_setup();
|
||||
test_inject_messagetypes();
|
||||
r = test_create_region(0, 0, NULL);
|
||||
rc = rc_get_or_create("dragon");
|
||||
rc->flags |= RCF_UNARMEDGUARD;
|
||||
|
|
|
@ -34,13 +34,13 @@ int autostudy_init(scholar scholars[], int max_scholars, region *r)
|
|||
int nscholars = 0;
|
||||
|
||||
for (u = r->units; u; u = u->next) {
|
||||
keyword_t kwd = getkeyword(u->thisorder);
|
||||
keyword_t kwd = init_order(u->thisorder, u->faction->locale);
|
||||
if (kwd == K_AUTOSTUDY) {
|
||||
if (long_order_allowed(u)) {
|
||||
if (unit_can_study(u)) {
|
||||
scholar * st = scholars + nscholars;
|
||||
init_order(u->thisorder, u->faction->locale);
|
||||
st->sk = getskill(u->faction->locale);
|
||||
scholar * st = scholars + nscholars;
|
||||
skill_t sk = getskill(u->faction->locale);
|
||||
if (check_student(u, u->thisorder, sk)) {
|
||||
st->sk = sk;
|
||||
st->level = effskill_study(u, st->sk);
|
||||
st->learn = 0;
|
||||
st->u = u;
|
||||
|
@ -48,10 +48,6 @@ int autostudy_init(scholar scholars[], int max_scholars, region *r)
|
|||
log_fatal("you must increase MAXSCHOLARS");
|
||||
}
|
||||
}
|
||||
else {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder, "error_race_nolearn", "race",
|
||||
u_race(u)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,17 +9,22 @@
|
|||
#include "kernel/region.h"
|
||||
#include "kernel/unit.h"
|
||||
|
||||
#include "util/message.h"
|
||||
|
||||
#include "tests.h"
|
||||
|
||||
#include <CuTest.h>
|
||||
|
||||
static void test_autostudy_init(CuTest *tc) {
|
||||
scholar scholars[4];
|
||||
unit *u1, *u2, *u3;
|
||||
unit *u1, *u2, *u3, *u4;
|
||||
faction *f;
|
||||
region *r;
|
||||
|
||||
test_setup();
|
||||
mt_create_error(77);
|
||||
mt_create_error(771);
|
||||
|
||||
r = test_create_plain(0, 0);
|
||||
f = test_create_faction(NULL);
|
||||
u1 = test_create_unit(f, r);
|
||||
|
@ -30,8 +35,11 @@ static void test_autostudy_init(CuTest *tc) {
|
|||
set_level(u2, SK_ENTERTAINMENT, 2);
|
||||
u3 = test_create_unit(f, r);
|
||||
u3->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_PERCEPTION]);
|
||||
u4 = test_create_unit(test_create_faction(NULL), r);
|
||||
u4->thisorder = create_order(K_AUTOSTUDY, f->locale, "Dudelidu");
|
||||
scholars[3].u = NULL;
|
||||
CuAssertIntEquals(tc, 3, autostudy_init(scholars, 4, r));
|
||||
CuAssertPtrNotNull(tc, test_find_messagetype(u4->faction->msgs, "error77"));
|
||||
CuAssertPtrEquals(tc, u2, scholars[0].u);
|
||||
CuAssertIntEquals(tc, 2, scholars[0].level);
|
||||
CuAssertIntEquals(tc, 0, scholars[0].learn);
|
||||
|
|
|
@ -36,12 +36,16 @@ int eressea_write_game(const char * filename) {
|
|||
|
||||
int eressea_read_orders(const char * filename) {
|
||||
FILE * F = fopen(filename, "r");
|
||||
int result;
|
||||
|
||||
if (!F) {
|
||||
perror(filename);
|
||||
return -1;
|
||||
}
|
||||
log_info("reading orders from %s", filename);
|
||||
return parseorders(F);
|
||||
result = parseorders(F);
|
||||
fclose(F);
|
||||
return result;
|
||||
}
|
||||
|
||||
int eressea_export_json(const char * filename, int flags) {
|
||||
|
|
|
@ -145,6 +145,7 @@ static struct unit *create_recruiter(void) {
|
|||
|
||||
static void setup_production(void) {
|
||||
init_resources();
|
||||
mt_create_feedback("error_cannotmake");
|
||||
mt_create_va(mt_new("produce", NULL), "unit:unit", "region:region", "amount:int", "wanted:int", "resource:resource", MT_NEW_END);
|
||||
mt_create_va(mt_new("income", NULL), "unit:unit", "region:region", "amount:int", "wanted:int", "mode:int", MT_NEW_END);
|
||||
mt_create_va(mt_new("buy", NULL), "unit:unit", "money:int", MT_NEW_END);
|
||||
|
@ -738,6 +739,7 @@ static void test_loot(CuTest *tc) {
|
|||
|
||||
test_setup();
|
||||
setup_production();
|
||||
mt_create_error(48); /* unit is unarmed */
|
||||
it_silver = test_create_silver();
|
||||
config_set("rules.enable_loot", "1");
|
||||
u = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||
|
@ -747,7 +749,7 @@ static void test_loot(CuTest *tc) {
|
|||
test_clear_messages(f);
|
||||
arm_unit(u);
|
||||
produce(u->region);
|
||||
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "income")); /* unit is unarmed */
|
||||
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "income"));
|
||||
CuAssertIntEquals(tc, 2 * TAXFRACTION, i_get(u->items, it_silver));
|
||||
CuAssertIntEquals(tc, UFL_LONGACTION | UFL_NOTMOVING, fval(u, UFL_LONGACTION | UFL_NOTMOVING));
|
||||
test_teardown();
|
||||
|
|
|
@ -65,11 +65,14 @@ static void setup_give(struct give *env) {
|
|||
mt_create_va(mt_new("give", NULL), "unit:unit", "target:unit", "resource:resource", "amount:int", MT_NEW_END);
|
||||
mt_create_va(mt_new("give_peasants", NULL), "unit:unit", "resource:resource", "amount:int", MT_NEW_END);
|
||||
/* error messages: */
|
||||
mt_create_error(129);
|
||||
mt_create_error(96);
|
||||
mt_create_error(10);
|
||||
mt_create_feedback("feedback_give_forbidden");
|
||||
mt_create_feedback("peasants_give_invalid");
|
||||
mt_create_va(mt_new("too_many_units_in_faction", NULL), "unit:unit", "region:region", "command:order", "allowed:int", MT_NEW_END);
|
||||
mt_create_va(mt_new("too_many_units_in_alliance", NULL), "unit:unit", "region:region", "command:order", "allowed:int", MT_NEW_END);
|
||||
mt_create_va(mt_new("feedback_no_contact", NULL), "unit:unit", "region:region", "command:order", "target:unit", MT_NEW_END);
|
||||
mt_create_va(mt_new("feedback_give_forbidden", NULL), "unit:unit", "region:region", "command:order", MT_NEW_END);
|
||||
mt_create_va(mt_new("peasants_give_invalid", NULL), "unit:unit", "region:region", "command:order", MT_NEW_END);
|
||||
mt_create_va(mt_new("giverestriction", NULL), "unit:unit", "region:region", "command:order", "turns:int", MT_NEW_END);
|
||||
mt_create_va(mt_new("error_unit_size", NULL), "unit:unit", "region:region", "command:order", "maxsize:int", MT_NEW_END);
|
||||
mt_create_va(mt_new("nogive_reserved", NULL), "unit:unit", "region:region", "command:order", "resource:resource", "reservation:int", MT_NEW_END);
|
||||
|
@ -159,11 +162,12 @@ static void test_give_men_magicians(CuTest * tc) {
|
|||
message * msg;
|
||||
|
||||
test_setup_ex(tc);
|
||||
mt_create_error(158);
|
||||
env.f2 = env.f1 = test_create_faction(NULL);
|
||||
setup_give(&env);
|
||||
set_level(env.src, SK_MAGIC, 1);
|
||||
CuAssertPtrNotNull(tc, msg = give_men(1, env.src, env.dst, NULL));
|
||||
CuAssertStrEquals(tc, "error158", (const char *)msg->parameters[3].v);
|
||||
CuAssertStrEquals(tc, "error158", test_get_messagetype(msg));
|
||||
CuAssertIntEquals(tc, 1, env.dst->number);
|
||||
CuAssertIntEquals(tc, 1, env.src->number);
|
||||
msg_release(msg);
|
||||
|
|
|
@ -18,7 +18,6 @@ static void test_manacrystal(CuTest *tc) {
|
|||
unit *u;
|
||||
|
||||
test_setup();
|
||||
test_inject_messagetypes();
|
||||
|
||||
u = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0));
|
||||
itype = test_create_itemtype("manacrystal");
|
||||
|
@ -49,7 +48,6 @@ static void test_skillpotion(CuTest *tc) {
|
|||
int initialWeeks_Magic = 0;
|
||||
|
||||
test_setup();
|
||||
test_inject_messagetypes();
|
||||
u = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0));
|
||||
itype = test_create_itemtype("skillpotion");
|
||||
change_resource(u, itype->rtype, 2);
|
||||
|
|
|
@ -500,6 +500,28 @@ static int count_materials(unit *u, const construction *type, int n, int complet
|
|||
return n;
|
||||
}
|
||||
|
||||
int build_skill(unit *u, int basesk, int skill_mod) {
|
||||
int effsk, skills;
|
||||
int dm = get_effect(u, oldpotiontype[P_DOMORE]);
|
||||
|
||||
effsk = basesk + skill_mod;
|
||||
assert(effsk >= 0);
|
||||
|
||||
skills = effsk * u->number;
|
||||
|
||||
/* technically, nimblefinge and domore should be in a global set of
|
||||
* "game"-attributes, (as at_skillmod) but for a while, we're leaving
|
||||
* them in here. */
|
||||
|
||||
if (dm != 0) {
|
||||
/* Auswirkung Schaffenstrunk */
|
||||
if (dm > u->number) dm = u->number;
|
||||
change_effect(u, oldpotiontype[P_DOMORE], -dm);
|
||||
skills += dm * effsk;
|
||||
}
|
||||
return skills;
|
||||
}
|
||||
|
||||
/** Use up resources for building an object.
|
||||
* Build up to 'size' points of 'type', where 'completed'
|
||||
* of the first object have already been finished. return the
|
||||
|
@ -521,28 +543,11 @@ int build(unit * u, const construction * ctype, int completed, int want, int ski
|
|||
return ECOMPLETE;
|
||||
}
|
||||
if (con->skill != NOSKILL) {
|
||||
int effsk;
|
||||
int dm = get_effect(u, oldpotiontype[P_DOMORE]);
|
||||
|
||||
basesk = effskill(u, con->skill, 0);
|
||||
if (basesk == 0)
|
||||
return ENEEDSKILL;
|
||||
|
||||
effsk = basesk + skill_mod;
|
||||
assert(effsk >= 0);
|
||||
|
||||
skills = effsk * u->number;
|
||||
|
||||
/* technically, nimblefinge and domore should be in a global set of
|
||||
* "game"-attributes, (as at_skillmod) but for a while, we're leaving
|
||||
* them in here. */
|
||||
|
||||
if (dm != 0) {
|
||||
/* Auswirkung Schaffenstrunk */
|
||||
if (dm > u->number) dm = u->number;
|
||||
change_effect(u, oldpotiontype[P_DOMORE], -dm);
|
||||
skills += dm * effsk;
|
||||
}
|
||||
skills = build_skill(u, basesk, skill_mod);
|
||||
}
|
||||
for (; want > 0 && skills > 0;) {
|
||||
int err, n;
|
||||
|
|
|
@ -36,7 +36,6 @@ typedef struct build_fixture {
|
|||
|
||||
static unit * setup_build(build_fixture *bf) {
|
||||
test_setup();
|
||||
test_inject_messagetypes();
|
||||
init_resources();
|
||||
|
||||
test_create_itemtype("stone");
|
||||
|
@ -312,7 +311,6 @@ static void test_build_destroy_road_guard(CuTest *tc)
|
|||
order *ord;
|
||||
|
||||
test_setup();
|
||||
test_inject_messagetypes();
|
||||
test_create_region(1, 0, 0);
|
||||
r = test_create_region(0, 0, NULL);
|
||||
rsetroad(r, D_EAST, 100);
|
||||
|
@ -345,7 +343,6 @@ static void test_build_destroy_road_limit(CuTest *tc)
|
|||
order *ord;
|
||||
|
||||
test_setup();
|
||||
test_inject_messagetypes();
|
||||
test_create_region(1, 0, 0);
|
||||
r = test_create_region(0, 0, NULL);
|
||||
rsetroad(r, D_EAST, 100);
|
||||
|
@ -370,6 +367,7 @@ static void test_build_destroy_cmd(CuTest *tc) {
|
|||
faction *f;
|
||||
|
||||
test_setup();
|
||||
mt_create_error(138);
|
||||
u = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||
u->thisorder = create_order(K_DESTROY, f->locale, NULL);
|
||||
CuAssertIntEquals(tc, 138, destroy_cmd(u, u->thisorder));
|
||||
|
|
|
@ -51,7 +51,6 @@ typedef struct {
|
|||
|
||||
static void setup_curse(curse_fixture *fix, const char *name) {
|
||||
test_setup();
|
||||
test_inject_messagetypes();
|
||||
fix->r = test_create_region(0, 0, NULL);
|
||||
fix->u = test_create_unit(test_create_faction(NULL), fix->r);
|
||||
fix->c = create_curse(fix->u, &fix->r->attribs, ct_find(name), 1.0, 1, 1.0, 0);
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <sqlite3.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
@ -226,7 +227,11 @@ void db_driver_close(database_t db)
|
|||
FILE * F = fopen(g_swapname, "r");
|
||||
if (F) {
|
||||
fclose(F);
|
||||
remove(g_swapname);
|
||||
if (0 != remove(g_swapname)) {
|
||||
log_error("could not remove %s: %s", g_swapname,
|
||||
strerror(errno));
|
||||
errno = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,6 +67,46 @@ variant v)
|
|||
}
|
||||
}
|
||||
|
||||
static int missing_message_mode;
|
||||
|
||||
void message_handle_missing(int mode) {
|
||||
missing_message_mode = mode;
|
||||
}
|
||||
|
||||
static message *missing_feedback(const char *name, const struct unit *u,
|
||||
const struct region *r, struct order *ord)
|
||||
{
|
||||
if (missing_message_mode == MESSAGE_MISSING_ERROR) {
|
||||
log_error("trying to create undefined feedback of type \"%s\"\n", name);
|
||||
}
|
||||
else if (missing_message_mode == MESSAGE_MISSING_REPLACE) {
|
||||
if (strcmp(name, "missing_feedback") != 0) {
|
||||
if (!mt_find("missing_feedback")) {
|
||||
mt_create_va(mt_new("missing_feedback", NULL), "unit:unit",
|
||||
"region:region", "command:order", "name:string", MT_NEW_END);
|
||||
}
|
||||
return msg_message("missing_feedback", "unit region command name", u, r, ord, name);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static message *missing_message(const char *name) {
|
||||
if (missing_message_mode == MESSAGE_MISSING_ERROR) {
|
||||
log_error("trying to create undefined message of type \"%s\"\n", name);
|
||||
}
|
||||
else if (missing_message_mode == MESSAGE_MISSING_REPLACE) {
|
||||
log_warning("trying to create undefined message of type \"%s\"\n", name);
|
||||
if (strcmp(name, "missing_message") != 0) {
|
||||
if (!mt_find("missing_message")) {
|
||||
mt_create_va(mt_new("missing_message", NULL), "name:string", MT_NEW_END);
|
||||
}
|
||||
return msg_message("missing_message", "name", name);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct message *msg_feedback(const struct unit *u, struct order *ord,
|
||||
const char *name, const char *sig, ...)
|
||||
{
|
||||
|
@ -80,13 +120,7 @@ struct message *msg_feedback(const struct unit *u, struct order *ord,
|
|||
}
|
||||
|
||||
if (!mtype) {
|
||||
log_warning("trying to create message of unknown type \"%s\"\n", name);
|
||||
if (!mt_find("missing_feedback")) {
|
||||
mt_create_va(mt_new("missing_feedback", NULL), "unit:unit",
|
||||
"region:region", "command:order", "name:string", MT_NEW_END);
|
||||
}
|
||||
return msg_message("missing_feedback", "name unit region command",
|
||||
name, u, u->region, ord);
|
||||
return missing_feedback(name, u, u->region, ord);
|
||||
}
|
||||
|
||||
var.v = (void *)u;
|
||||
|
@ -139,28 +173,6 @@ struct message *msg_feedback(const struct unit *u, struct order *ord,
|
|||
return msg_create(mtype, args);
|
||||
}
|
||||
|
||||
static int missing_message_mode;
|
||||
|
||||
void message_handle_missing(int mode) {
|
||||
missing_message_mode = mode;
|
||||
}
|
||||
|
||||
static message *missing_message(const char *name) {
|
||||
if (missing_message_mode == MESSAGE_MISSING_ERROR) {
|
||||
log_error("trying to create undefined message of type \"%s\"\n", name);
|
||||
}
|
||||
else if (missing_message_mode == MESSAGE_MISSING_REPLACE) {
|
||||
log_warning("trying to create undefined message of type \"%s\"\n", name);
|
||||
if (strcmp(name, "missing_message") != 0) {
|
||||
if (!mt_find("missing_message")) {
|
||||
mt_create_va(mt_new("missing_message", NULL), "name:string", MT_NEW_END);
|
||||
}
|
||||
return msg_message("missing_message", "name", name);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
message *msg_message(const char *name, const char *sig, ...)
|
||||
/* msg_message("oops_error", "unit region command", u, r, cmd) */
|
||||
{
|
||||
|
|
|
@ -18,6 +18,21 @@ void test_missing_message(CuTest *tc) {
|
|||
CuAssertPtrNotNull(tc, msg);
|
||||
CuAssertPtrNotNull(tc, msg->type);
|
||||
CuAssertStrEquals(tc, msg->type->name, "missing_message");
|
||||
CuAssertStrEquals(tc, "unknown", (const char *)msg->parameters[0].v);
|
||||
msg_release(msg);
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
void test_missing_feedback(CuTest *tc) {
|
||||
message *msg;
|
||||
|
||||
test_setup();
|
||||
message_handle_missing(MESSAGE_MISSING_REPLACE);
|
||||
msg = msg_error(NULL, NULL, 77);
|
||||
CuAssertPtrNotNull(tc, msg);
|
||||
CuAssertPtrNotNull(tc, msg->type);
|
||||
CuAssertStrEquals(tc, msg->type->name, "missing_feedback");
|
||||
CuAssertStrEquals(tc, "error77", (const char *)msg->parameters[3].v);
|
||||
msg_release(msg);
|
||||
test_teardown();
|
||||
}
|
||||
|
|
|
@ -390,7 +390,7 @@ order *parse_order(const char *s, const struct locale * lang)
|
|||
sptr = sp;
|
||||
p = parse_token(&sp, token, sizeof(token));
|
||||
sk = get_skill(p, lang);
|
||||
if (!expensive_skill(sk)) {
|
||||
if (sk == NOSKILL || !expensive_skill(sk)) {
|
||||
kwd = K_AUTOSTUDY;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@ static void test_create_duplicate_spell(CuTest * tc)
|
|||
strlist *sl = 0;
|
||||
|
||||
test_setup();
|
||||
test_inject_messagetypes();
|
||||
test_log_stderr(0); /* suppress the "duplicate spell" error message */
|
||||
log = test_log_start(LOG_CPERROR, &sl);
|
||||
|
||||
|
|
|
@ -1801,10 +1801,6 @@ bool unit_name_equals_race(const unit *u) {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool unit_can_study(const unit *u) {
|
||||
return !((u_race(u)->flags & RCF_NOLEARN) || fval(u, UFL_WERE));
|
||||
}
|
||||
|
||||
static int read_newunitid(const faction * f, const region * r)
|
||||
{
|
||||
int n;
|
||||
|
|
|
@ -243,7 +243,6 @@ extern "C" {
|
|||
const char *unitname(const struct unit *u);
|
||||
char *write_unitname(const struct unit *u, char *buffer, size_t size);
|
||||
bool unit_name_equals_race(const struct unit *u);
|
||||
bool unit_can_study(const struct unit *u);
|
||||
|
||||
/* getunit results: */
|
||||
#define GET_UNIT 0
|
||||
|
|
|
@ -140,7 +140,6 @@ static void test_enter_ship(CuTest * tc)
|
|||
race * rc;
|
||||
|
||||
test_setup();
|
||||
|
||||
r = test_create_region(0, 0, NULL);
|
||||
rc = test_create_race("smurf");
|
||||
u = test_create_unit(test_create_faction(rc), r);
|
||||
|
@ -475,6 +474,10 @@ static void test_limit_new_units(CuTest * tc)
|
|||
alliance *al;
|
||||
|
||||
test_setup();
|
||||
mt_create_va(mt_new("too_many_units_in_faction", NULL), "unit:unit",
|
||||
"region:region", "command:order", "allowed:int", MT_NEW_END);
|
||||
mt_create_va(mt_new("too_many_units_in_alliance", NULL), "unit:unit",
|
||||
"region:region", "command:order", "allowed:int", MT_NEW_END);
|
||||
al = makealliance(1, "Hodor");
|
||||
f = test_create_faction(NULL);
|
||||
u = test_create_unit(f, test_create_region(0, 0, NULL));
|
||||
|
@ -890,6 +893,9 @@ static unit * setup_name_cmd(void) {
|
|||
faction *f;
|
||||
|
||||
test_setup();
|
||||
mt_create_error(84);
|
||||
mt_create_error(148);
|
||||
mt_create_error(12);
|
||||
mt_create_va(mt_new("renamed_building_seen", NULL), "renamer:unit", "region:region", "building:building", MT_NEW_END);
|
||||
mt_create_va(mt_new("renamed_building_notseen", NULL), "region:region", "building:building", MT_NEW_END);
|
||||
f = test_create_faction(NULL);
|
||||
|
@ -1088,6 +1094,7 @@ static void test_long_order_multi_long(CuTest *tc) {
|
|||
/* TODO: write more tests */
|
||||
unit *u;
|
||||
test_setup();
|
||||
mt_create_error(52);
|
||||
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||
unit_addorder(u, create_order(K_MOVE, u->faction->locale, NULL));
|
||||
unit_addorder(u, create_order(K_DESTROY, u->faction->locale, NULL));
|
||||
|
@ -1102,6 +1109,7 @@ static void test_long_order_multi_buy(CuTest *tc) {
|
|||
/* TODO: write more tests */
|
||||
unit *u;
|
||||
test_setup();
|
||||
mt_create_error(52);
|
||||
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||
unit_addorder(u, create_order(K_BUY, u->faction->locale, 0));
|
||||
unit_addorder(u, create_order(K_BUY, u->faction->locale, 0));
|
||||
|
@ -1131,6 +1139,7 @@ static void test_long_order_buy_cast(CuTest *tc) {
|
|||
/* TODO: write more tests */
|
||||
unit *u;
|
||||
test_setup();
|
||||
mt_create_error(52);
|
||||
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||
unit_addorder(u, create_order(K_BUY, u->faction->locale, 0));
|
||||
unit_addorder(u, create_order(K_CAST, u->faction->locale, 0));
|
||||
|
@ -1163,6 +1172,7 @@ static void test_ally_cmd_errors(CuTest *tc) {
|
|||
order *ord;
|
||||
|
||||
test_setup();
|
||||
mt_create_error(66);
|
||||
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||
fid = u->faction->no + 1;
|
||||
CuAssertPtrEquals(tc, NULL, findfaction(fid));
|
||||
|
@ -1314,6 +1324,8 @@ static unit * setup_mail_cmd(void) {
|
|||
faction *f;
|
||||
|
||||
test_setup();
|
||||
mt_create_error(66);
|
||||
mt_create_error(30);
|
||||
mt_create_va(mt_new("regionmessage", NULL), "region:region", "sender:unit", "string:string", MT_NEW_END);
|
||||
mt_create_va(mt_new("unitmessage", NULL), "region:region", "sender:unit", "string:string", "unit:unit", MT_NEW_END);
|
||||
mt_create_va(mt_new("mail_result", NULL), "message:string", "unit:unit", MT_NEW_END);
|
||||
|
@ -1433,6 +1445,8 @@ static void test_show_without_item(CuTest *tc)
|
|||
struct locale *loc;
|
||||
|
||||
test_setup();
|
||||
mt_create_error(21);
|
||||
mt_create_error(36);
|
||||
mt_create_va(mt_new("displayitem", NULL), "weight:int", "item:resource", "description:string", MT_NEW_END);
|
||||
|
||||
loc = get_or_create_locale("de");
|
||||
|
@ -1477,7 +1491,6 @@ static void test_show_race(CuTest *tc) {
|
|||
message * msg;
|
||||
|
||||
test_setup();
|
||||
|
||||
mt_create_va(mt_new("msg_event", NULL), "string:string", MT_NEW_END);
|
||||
test_create_race("human");
|
||||
rc = test_create_race("elf");
|
||||
|
@ -1493,8 +1506,8 @@ static void test_show_race(CuTest *tc) {
|
|||
|
||||
ord = create_order(K_RESHOW, loc, "Mensch");
|
||||
reshow_cmd(u, ord);
|
||||
CuAssertTrue(tc, test_find_messagetype(u->faction->msgs, "error21") != NULL);
|
||||
CuAssertTrue(tc, test_find_messagetype(u->faction->msgs, "msg_event") == NULL);
|
||||
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error21"));
|
||||
CuAssertPtrEquals(tc, NULL, test_find_messagetype(u->faction->msgs, "msg_event"));
|
||||
test_clear_messages(u->faction);
|
||||
free_order(ord);
|
||||
|
||||
|
|
|
@ -557,7 +557,7 @@ static order *monster_learn(unit * u)
|
|||
const struct locale *lang = u->faction->locale;
|
||||
|
||||
/* can these monsters even study? */
|
||||
if (!unit_can_study(u)) {
|
||||
if (!check_student(u, NULL, SK_PERCEPTION)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -832,8 +832,7 @@ void plan_monsters(faction * f)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (long_order == NULL && unit_can_study(u)) {
|
||||
if (long_order == NULL && check_student(u, NULL, SK_WEAPONLESS)) {
|
||||
/* Einheiten, die Waffenlosen Kampf lernen k<>nnten, lernen es um
|
||||
* zu bewachen: */
|
||||
if (rc->bonus[SK_WEAPONLESS] != -99) {
|
||||
|
|
|
@ -30,6 +30,8 @@ static void setup_piracy(void) {
|
|||
st_boat = test_create_shiptype("boat");
|
||||
st_boat->cargo = 1000;
|
||||
|
||||
mt_create_error(144);
|
||||
mt_create_error(146);
|
||||
mt_create_va(mt_new("piratenovictim", NULL),
|
||||
"ship:ship", "unit:unit", "region:region", MT_NEW_END);
|
||||
mt_create_va(mt_new("piratesawvictim", NULL),
|
||||
|
|
|
@ -15,12 +15,19 @@
|
|||
#include <stddef.h>
|
||||
#include <CuTest.h>
|
||||
|
||||
static void setup_renumber(CuTest *tc) {
|
||||
test_setup_ex(tc);
|
||||
mt_create_error(114);
|
||||
mt_create_error(115);
|
||||
mt_create_error(116);
|
||||
}
|
||||
|
||||
static void test_renumber_faction(CuTest *tc) {
|
||||
unit *u;
|
||||
int uno, no;
|
||||
const struct locale *lang;
|
||||
|
||||
test_setup_ex(tc);
|
||||
setup_renumber(tc);
|
||||
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||
no = u->faction->no;
|
||||
uno = (no > 1) ? no - 1 : no + 1;
|
||||
|
@ -38,7 +45,7 @@ static void test_renumber_faction_duplicate(CuTest *tc) {
|
|||
int no;
|
||||
const struct locale *lang;
|
||||
|
||||
test_setup_ex(tc);
|
||||
setup_renumber(tc);
|
||||
mt_create_va(mt_new("renumber_inuse", NULL), "id:int", MT_NEW_END);
|
||||
f2 = test_create_faction(NULL);
|
||||
u = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||
|
@ -58,7 +65,7 @@ static void test_renumber_faction_invalid(CuTest *tc) {
|
|||
int no;
|
||||
const struct locale *lang;
|
||||
|
||||
test_setup_ex(tc);
|
||||
setup_renumber(tc);
|
||||
u = test_create_unit(f = test_create_faction(0), test_create_region(0, 0, 0));
|
||||
no = f->no;
|
||||
lang = f->locale;
|
||||
|
@ -88,7 +95,7 @@ static void test_renumber_building(CuTest *tc) {
|
|||
int uno, no;
|
||||
const struct locale *lang;
|
||||
|
||||
test_setup_ex(tc);
|
||||
setup_renumber(tc);
|
||||
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||
u->building = test_create_building(u->region, NULL);
|
||||
no = u->building->no;
|
||||
|
@ -106,7 +113,7 @@ static void test_renumber_building_duplicate(CuTest *tc) {
|
|||
int uno, no;
|
||||
const struct locale *lang;
|
||||
|
||||
test_setup_ex(tc);
|
||||
setup_renumber(tc);
|
||||
u = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||
u->building = test_create_building(u->region, NULL);
|
||||
uno = u->building->no;
|
||||
|
@ -125,7 +132,7 @@ static void test_renumber_ship(CuTest *tc) {
|
|||
int uno, no;
|
||||
const struct locale *lang;
|
||||
|
||||
test_setup_ex(tc);
|
||||
setup_renumber(tc);
|
||||
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||
u->ship = test_create_ship(u->region, NULL);
|
||||
no = u->ship->no;
|
||||
|
@ -142,7 +149,7 @@ static void test_renumber_ship_twice(CuTest *tc) {
|
|||
int uno, no;
|
||||
const struct locale *lang;
|
||||
|
||||
test_setup_ex(tc);
|
||||
setup_renumber(tc);
|
||||
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||
u->ship = test_create_ship(u->region, NULL);
|
||||
no = u->ship->no;
|
||||
|
@ -164,7 +171,7 @@ static void test_renumber_ship_duplicate(CuTest *tc) {
|
|||
int uno, no;
|
||||
const struct locale *lang;
|
||||
|
||||
test_setup_ex(tc);
|
||||
setup_renumber(tc);
|
||||
u = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||
u->ship = test_create_ship(u->region, NULL);
|
||||
uno = u->ship->no;
|
||||
|
@ -183,7 +190,7 @@ static void test_renumber_unit(CuTest *tc) {
|
|||
int uno, no;
|
||||
const struct locale *lang;
|
||||
|
||||
test_setup_ex(tc);
|
||||
setup_renumber(tc);
|
||||
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||
no = u->no;
|
||||
uno = (no > 1) ? no - 1 : no + 1;
|
||||
|
@ -201,7 +208,7 @@ static void test_renumber_unit_duplicate(CuTest *tc) {
|
|||
int no;
|
||||
const struct locale *lang;
|
||||
|
||||
test_setup_ex(tc);
|
||||
setup_renumber(tc);
|
||||
u = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||
no = u->no;
|
||||
u2 = test_create_unit(f, u->region);
|
||||
|
@ -220,7 +227,7 @@ static void test_renumber_unit_limit(CuTest *tc) {
|
|||
int no;
|
||||
const struct locale *lang;
|
||||
|
||||
test_setup_ex(tc);
|
||||
setup_renumber(tc);
|
||||
u = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||
no = u->no;
|
||||
lang = f->locale;
|
||||
|
@ -238,7 +245,7 @@ static void test_renumber_unit_invalid(CuTest *tc) {
|
|||
int no;
|
||||
const struct locale *lang;
|
||||
|
||||
test_setup_ex(tc);
|
||||
setup_renumber(tc);
|
||||
u = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||
no = u->no;
|
||||
lang = f->locale;
|
||||
|
|
|
@ -902,6 +902,7 @@ void report_region(struct stream *out, const region * r, faction * f)
|
|||
assert(f);
|
||||
assert(r);
|
||||
|
||||
memset(edges, 0, sizeof(edges));
|
||||
for (d = 0; d != MAXDIRECTIONS; d++) {
|
||||
/* Nachbarregionen, die gesehen werden, ermitteln */
|
||||
region *r2 = rconnect(r, d);
|
||||
|
|
|
@ -789,7 +789,6 @@ static void test_insect_warnings(CuTest *tc) {
|
|||
|
||||
test_setup();
|
||||
test_create_calendar();
|
||||
test_inject_messagetypes();
|
||||
f = test_create_faction(test_create_race("insect"));
|
||||
|
||||
CuAssertIntEquals(tc, SEASON_AUTUMN, get_gamedate(1083, &gd)->season);
|
||||
|
@ -817,7 +816,6 @@ static void test_newbie_warning(CuTest *tc) {
|
|||
faction *f;
|
||||
|
||||
test_setup();
|
||||
test_inject_messagetypes();
|
||||
f = test_create_faction(NULL);
|
||||
config_set_int("NewbieImmunity", 3);
|
||||
|
||||
|
|
|
@ -118,7 +118,9 @@ skill_t get_skill(const char *s, const struct locale * lang)
|
|||
int skill_cost(skill_t sk) {
|
||||
static int config;
|
||||
static int costs[MAXSKILLS];
|
||||
int cost;
|
||||
int cost = -1;
|
||||
|
||||
assert(sk >= 0 && sk < MAXSKILLS);
|
||||
switch (sk) {
|
||||
case SK_SPY:
|
||||
cost = 100;
|
||||
|
@ -148,5 +150,6 @@ int skill_cost(skill_t sk) {
|
|||
}
|
||||
|
||||
bool expensive_skill(skill_t sk) {
|
||||
assert(sk >= 0 && sk < MAXSKILLS);
|
||||
return (sk == SK_MAGIC) || skill_cost(sk) > 0;
|
||||
}
|
||||
|
|
|
@ -27,10 +27,6 @@
|
|||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
static void setup_spells(void) {
|
||||
test_inject_messagetypes();
|
||||
}
|
||||
|
||||
static void test_good_dreams(CuTest *tc) {
|
||||
struct region *r;
|
||||
struct faction *f1, *f2;
|
||||
|
@ -40,7 +36,6 @@ static void test_good_dreams(CuTest *tc) {
|
|||
curse *curse;
|
||||
|
||||
test_setup();
|
||||
setup_spells();
|
||||
test_create_world();
|
||||
r = findregion(0, 0);
|
||||
f1 = test_create_faction(NULL);
|
||||
|
@ -70,7 +65,6 @@ static void test_dreams(CuTest *tc) {
|
|||
castorder co;
|
||||
|
||||
test_setup();
|
||||
setup_spells();
|
||||
r = test_create_region(0, 0, NULL);
|
||||
f1 = test_create_faction(NULL);
|
||||
f2 = test_create_faction(NULL);
|
||||
|
@ -98,7 +92,6 @@ static void test_bad_dreams(CuTest *tc) {
|
|||
curse *curse;
|
||||
|
||||
test_setup();
|
||||
setup_spells();
|
||||
test_create_world();
|
||||
r = findregion(0, 0);
|
||||
f1 = test_create_faction(NULL);
|
||||
|
@ -129,7 +122,6 @@ static void test_view_reality(CuTest *tc) {
|
|||
castorder co;
|
||||
|
||||
test_setup();
|
||||
setup_spells();
|
||||
mt_create_va(mt_new("spell_astral_only", NULL),
|
||||
"unit:unit", "region:region", "command:order", MT_NEW_END);
|
||||
mt_create_va(mt_new("viewreality_effect", NULL),
|
||||
|
@ -165,7 +157,6 @@ static void test_watch_region(CuTest *tc) {
|
|||
region *r;
|
||||
faction *f;
|
||||
test_setup();
|
||||
setup_spells();
|
||||
r = test_create_region(0, 0, NULL);
|
||||
f = test_create_faction(NULL);
|
||||
CuAssertIntEquals(tc, -1, get_observer(r, f));
|
||||
|
|
65
src/study.c
65
src/study.c
|
@ -524,6 +524,48 @@ static void msg_teachers(struct selist *teachers, struct unit *u, skill_t sk) {
|
|||
selist_foreach_ex(teachers, cb_msg_teach, &cbdata);
|
||||
}
|
||||
|
||||
bool check_student(const struct unit *u, struct order *ord, skill_t sk) {
|
||||
int err = 0;
|
||||
|
||||
if (sk < 0) {
|
||||
err = 77;
|
||||
}
|
||||
/* Hack: Talente mit Malus -99 koennen nicht gelernt werden */
|
||||
else if (u_race(u)->bonus[sk] == -99) {
|
||||
err = 771;
|
||||
}
|
||||
else {
|
||||
static int config;
|
||||
static bool learn_newskills;
|
||||
|
||||
if (config_changed(&config)) {
|
||||
learn_newskills = config_get_int("study.newskills", 1) != 0;
|
||||
}
|
||||
if (!learn_newskills) {
|
||||
skill *sv = unit_skill(u, sk);
|
||||
if (sv == NULL) {
|
||||
/* we can only learn skills we already have */
|
||||
err = 771;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (err) {
|
||||
if (ord) {
|
||||
cmistake(u, ord, err, MSG_EVENT);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((u_race(u)->flags & RCF_NOLEARN) || fval(u, UFL_WERE)) {
|
||||
if (ord) {
|
||||
ADDMSG(&u->faction->msgs,
|
||||
msg_feedback(u, ord, "error_race_nolearn", "race", u_race(u)));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int study_cmd(unit * u, order * ord)
|
||||
{
|
||||
region *r = u->region;
|
||||
|
@ -537,7 +579,6 @@ int study_cmd(unit * u, order * ord)
|
|||
skill_t sk;
|
||||
int maxalchemy = 0;
|
||||
int speed_rule = (study_rule_t)config_get_int("study.speedup", 0);
|
||||
bool learn_newskills = config_get_int("study.newskills", 1) != 0;
|
||||
static const race *rc_snotling;
|
||||
static int rc_cache;
|
||||
|
||||
|
@ -545,32 +586,12 @@ int study_cmd(unit * u, order * ord)
|
|||
rc_snotling = get_race(RC_SNOTLING);
|
||||
}
|
||||
|
||||
if (!unit_can_study(u)) {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_race_nolearn", "race",
|
||||
u_race(u)));
|
||||
return -1;
|
||||
}
|
||||
|
||||
(void)init_order(ord, u->faction->locale);
|
||||
sk = getskill(u->faction->locale);
|
||||
|
||||
if (sk < 0) {
|
||||
cmistake(u, ord, 77, MSG_EVENT);
|
||||
if (!check_student(u, ord, sk)) {
|
||||
return -1;
|
||||
}
|
||||
/* Hack: Talente mit Malus -99 koennen nicht gelernt werden */
|
||||
if (u_race(u)->bonus[sk] == -99) {
|
||||
cmistake(u, ord, 771, MSG_EVENT);
|
||||
return -1;
|
||||
}
|
||||
if (!learn_newskills) {
|
||||
skill *sv = unit_skill(u, sk);
|
||||
if (sv == NULL) {
|
||||
/* we can only learn skills we already have */
|
||||
cmistake(u, ord, 771, MSG_EVENT);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* snotlings koennen Talente nur bis T8 lernen */
|
||||
if (u_race(u) == rc_snotling) {
|
||||
|
|
|
@ -48,6 +48,7 @@ extern "C" {
|
|||
skill_t getskill(const struct locale *lang);
|
||||
bool is_migrant(struct unit *u);
|
||||
int study_cost(struct unit *u, skill_t sk);
|
||||
bool check_student(const struct unit *u, struct order *ord, skill_t sk);
|
||||
|
||||
typedef void(*learn_fun)(struct unit *u, skill_t sk, int days);
|
||||
|
||||
|
|
|
@ -58,6 +58,11 @@ typedef struct {
|
|||
} study_fixture;
|
||||
|
||||
static void setup_study(void) {
|
||||
test_setup();
|
||||
mt_create_error(178);
|
||||
mt_create_error(65);
|
||||
mt_create_va(mt_new("teach_asgood", NULL),
|
||||
"unit:unit", "region:region", "command:order", "student:unit", MT_NEW_END);
|
||||
mt_create_va(mt_new("studycost", NULL),
|
||||
"unit:unit", "region:region", "cost:int", "skill:int", MT_NEW_END);
|
||||
mt_create_va(mt_new("teach_teacher", NULL),
|
||||
|
@ -81,7 +86,7 @@ static void setup_teacher(study_fixture *fix, skill_t sk) {
|
|||
struct locale *lang;
|
||||
|
||||
assert(fix);
|
||||
test_setup();
|
||||
setup_study();
|
||||
config_set("study.random_progress", "0");
|
||||
r = test_create_region(0, 0, NULL);
|
||||
f = test_create_faction(NULL);
|
||||
|
@ -148,7 +153,7 @@ static void test_study_bug_2194(CuTest *tc) {
|
|||
struct locale * loc;
|
||||
building * b;
|
||||
|
||||
test_setup();
|
||||
setup_study();
|
||||
random_source_inject_constant(0.0);
|
||||
init_resources();
|
||||
loc = test_create_locale();
|
||||
|
@ -205,7 +210,7 @@ static void test_produceexp(CuTest *tc) {
|
|||
unit *u;
|
||||
|
||||
g_tc = tc;
|
||||
test_setup();
|
||||
setup_study();
|
||||
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||
scale_number(u, 2);
|
||||
config_set("study.produceexp", "20");
|
||||
|
@ -220,7 +225,7 @@ static void test_academy_building(CuTest *tc) {
|
|||
building * b;
|
||||
message * msg;
|
||||
|
||||
test_setup();
|
||||
setup_study();
|
||||
mt_create_va(mt_new("teach_asgood", NULL),
|
||||
"unit:unit", "region:region", "command:order", "student:unit", MT_NEW_END);
|
||||
|
||||
|
@ -271,7 +276,6 @@ static void test_academy_bonus(CuTest *tc) {
|
|||
struct locale * loc;
|
||||
building * b;
|
||||
|
||||
test_setup();
|
||||
setup_study();
|
||||
|
||||
random_source_inject_constant(0.0);
|
||||
|
@ -328,7 +332,8 @@ static void test_academy_bonus(CuTest *tc) {
|
|||
void test_learn_skill_single(CuTest *tc) {
|
||||
unit *u;
|
||||
skill *sv;
|
||||
test_setup();
|
||||
|
||||
setup_study();
|
||||
config_set("study.random_progress", "0");
|
||||
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||
learn_skill(u, SK_ALCHEMY, STUDYDAYS);
|
||||
|
@ -347,7 +352,8 @@ void test_learn_skill_single(CuTest *tc) {
|
|||
void test_learn_skill_multi(CuTest *tc) {
|
||||
unit *u;
|
||||
skill *sv;
|
||||
test_setup();
|
||||
|
||||
setup_study();
|
||||
config_set("study.random_progress", "0");
|
||||
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||
scale_number(u, 10);
|
||||
|
@ -367,7 +373,8 @@ void test_learn_skill_multi(CuTest *tc) {
|
|||
static void test_demon_skillchanges(CuTest *tc) {
|
||||
unit * u;
|
||||
const race * rc;
|
||||
test_setup();
|
||||
|
||||
setup_study();
|
||||
rc = test_create_race("demon");
|
||||
CuAssertPtrEquals(tc, (void *)rc, (void *)get_race(RC_DAEMON));
|
||||
u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, NULL));
|
||||
|
@ -380,7 +387,8 @@ static void test_demon_skillchanges(CuTest *tc) {
|
|||
|
||||
static void test_study_cmd(CuTest *tc) {
|
||||
unit *u;
|
||||
test_setup();
|
||||
|
||||
setup_study();
|
||||
init_resources();
|
||||
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||
u->thisorder = create_order(K_STUDY, u->faction->locale, "CROSSBOW");
|
||||
|
@ -399,7 +407,6 @@ static void test_study_magic(CuTest *tc) {
|
|||
const struct locale *lang;
|
||||
const struct item_type *itype;
|
||||
|
||||
test_setup();
|
||||
setup_study();
|
||||
init_resources();
|
||||
f = test_create_faction(NULL);
|
||||
|
@ -432,7 +439,6 @@ static void test_study_magic(CuTest *tc) {
|
|||
static void test_study_cost_magic(CuTest *tc) {
|
||||
unit * u;
|
||||
|
||||
test_setup();
|
||||
setup_study();
|
||||
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||
|
||||
|
@ -456,7 +462,6 @@ static void test_study_cost(CuTest *tc) {
|
|||
unit *u;
|
||||
const struct item_type *itype;
|
||||
|
||||
test_setup();
|
||||
setup_study();
|
||||
|
||||
itype = test_create_silver();
|
||||
|
@ -484,7 +489,6 @@ static void test_teach_magic(CuTest *tc) {
|
|||
faction *f;
|
||||
const struct item_type *itype;
|
||||
|
||||
test_setup();
|
||||
setup_study();
|
||||
init_resources();
|
||||
itype = get_resourcetype(R_SILVER)->itype;
|
||||
|
@ -510,7 +514,8 @@ static void test_teach_magic(CuTest *tc) {
|
|||
|
||||
static void test_teach_cmd(CuTest *tc) {
|
||||
unit *u, *ut;
|
||||
test_setup();
|
||||
|
||||
setup_study();
|
||||
init_resources();
|
||||
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||
scale_number(u, 10);
|
||||
|
@ -530,7 +535,8 @@ static void test_teach_cmd(CuTest *tc) {
|
|||
|
||||
static void test_teach_two(CuTest *tc) {
|
||||
unit *u1, *u2, *ut;
|
||||
test_setup();
|
||||
|
||||
setup_study();
|
||||
init_resources();
|
||||
u1 = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||
scale_number(u1, 5);
|
||||
|
@ -560,7 +566,7 @@ static void test_teach_two_skills(CuTest *tc) {
|
|||
faction *f;
|
||||
region *r;
|
||||
|
||||
test_setup();
|
||||
setup_study();
|
||||
init_resources();
|
||||
f = test_create_faction(NULL);
|
||||
r = test_create_region(0, 0, NULL);
|
||||
|
@ -590,7 +596,8 @@ static void test_teach_two_skills(CuTest *tc) {
|
|||
|
||||
static void test_teach_one_to_many(CuTest *tc) {
|
||||
unit *u, *ut;
|
||||
test_setup();
|
||||
|
||||
setup_study();
|
||||
init_resources();
|
||||
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||
scale_number(u, 20);
|
||||
|
@ -611,7 +618,7 @@ static void test_teach_one_to_many(CuTest *tc) {
|
|||
static void test_teach_many_to_one(CuTest *tc) {
|
||||
unit *u, *u1, *u2;
|
||||
|
||||
test_setup();
|
||||
setup_study();
|
||||
init_resources();
|
||||
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||
scale_number(u, 20);
|
||||
|
@ -638,11 +645,7 @@ static void test_teach_message(CuTest *tc) {
|
|||
attrib *a;
|
||||
teaching_info *teach;
|
||||
|
||||
test_setup();
|
||||
mt_create_va(mt_new("teach_teacher", NULL),
|
||||
"teacher:unit", "student:unit", "skill:int", "level:int", MT_NEW_END);
|
||||
mt_create_va(mt_new("teach_student", NULL),
|
||||
"teacher:unit", "student:unit", "skill:int", MT_NEW_END);
|
||||
setup_study();
|
||||
init_resources();
|
||||
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||
scale_number(u, 20);
|
||||
|
@ -681,7 +684,7 @@ static void test_teach_many_to_many(CuTest *tc) {
|
|||
region *r;
|
||||
faction *f;
|
||||
|
||||
test_setup();
|
||||
setup_study();
|
||||
init_resources();
|
||||
f = test_create_faction(NULL);
|
||||
r = test_create_region(0, 0, NULL);
|
||||
|
|
|
@ -305,15 +305,10 @@ void test_create_calendar(void) {
|
|||
month_season[8] = SEASON_SUMMER;
|
||||
}
|
||||
|
||||
void test_inject_messagetypes(void)
|
||||
{
|
||||
message_handle_missing(MESSAGE_MISSING_REPLACE);
|
||||
}
|
||||
|
||||
void test_setup_test(CuTest *tc, const char *file, int line) {
|
||||
test_log_stderr(LOG_CPERROR);
|
||||
test_reset();
|
||||
message_handle_missing(MESSAGE_MISSING_ERROR);
|
||||
message_handle_missing(MESSAGE_MISSING_REPLACE);
|
||||
if (tc) {
|
||||
log_debug("start test: %s", tc->name);
|
||||
}
|
||||
|
@ -325,6 +320,7 @@ void test_setup_test(CuTest *tc, const char *file, int line) {
|
|||
|
||||
void test_teardown(void)
|
||||
{
|
||||
message_handle_missing(MESSAGE_MISSING_IGNORE);
|
||||
test_reset();
|
||||
test_log_stderr(0);
|
||||
}
|
||||
|
|
|
@ -76,7 +76,6 @@ extern "C" {
|
|||
void assert_string_parameter(struct CuTest * tc, struct message *msg, int index, const char *arg);
|
||||
|
||||
void disabled_test(void *suite, void (*)(struct CuTest *), const char *name);
|
||||
void test_inject_messagetypes(void);
|
||||
|
||||
#define DISABLE_TEST(SUITE, TEST) disabled_test(SUITE, TEST, #TEST)
|
||||
|
||||
|
|
|
@ -192,6 +192,16 @@ message_type *mt_create_va(message_type *mtype, ...)
|
|||
return mt_create(mtype, args, i - 1);
|
||||
}
|
||||
|
||||
message_type *mt_create_feedback(const char *name) {
|
||||
return mt_create_va(mt_new(name, NULL), "unit:unit", "region:region", "command:order", MT_NEW_END);
|
||||
}
|
||||
|
||||
message_type *mt_create_error(int error) {
|
||||
char name[16];
|
||||
snprintf(name, sizeof(name), "error%d", error);
|
||||
return mt_create_feedback(name);
|
||||
}
|
||||
|
||||
static variant copy_arg(const arg_type * atype, variant data)
|
||||
{
|
||||
assert(atype != NULL);
|
||||
|
|
|
@ -64,6 +64,8 @@ extern "C" {
|
|||
struct message_type *mt_new(const char *name, const char *section);
|
||||
/** message_type registry (optional): **/
|
||||
struct message_type *mt_create(struct message_type *, const char *args[], int nargs);
|
||||
struct message_type *mt_create_feedback(const char *name);
|
||||
struct message_type *mt_create_error(int error);
|
||||
struct message_type *mt_create_va(struct message_type *, ...);
|
||||
const struct message_type *mt_find(const char *);
|
||||
|
||||
|
|
Loading…
Reference in New Issue