forked from github/server
commit
d315d73fa8
38 changed files with 565 additions and 225 deletions
|
@ -34,4 +34,4 @@ fi
|
||||||
tar cjf backup/$TURN.tar.bz2 $files
|
tar cjf backup/$TURN.tar.bz2 $files
|
||||||
echo "uploading game-$GAME/$TURN.tar.bz2"
|
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 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
|
||||||
|
|
|
@ -1058,6 +1058,21 @@ function test_give_silver()
|
||||||
assert_equal(10, u:get_item("money"))
|
assert_equal(10, u:get_item("money"))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function test_build_castle_one_stage()
|
||||||
|
local r = region.create(0, 0, 'plain')
|
||||||
|
local f = faction.create('human')
|
||||||
|
local u = unit.create(f, r, 2)
|
||||||
|
|
||||||
|
u:add_item('stone', 4)
|
||||||
|
|
||||||
|
u:set_skill('building', 1)
|
||||||
|
u:add_order('MACHE BURG')
|
||||||
|
|
||||||
|
process_orders()
|
||||||
|
assert_equal(2, u.building.size)
|
||||||
|
assert_equal(2, u:get_item('stone'))
|
||||||
|
end
|
||||||
|
|
||||||
function test_build_castle()
|
function test_build_castle()
|
||||||
local r = region.create(0, 0, "plain")
|
local r = region.create(0, 0, "plain")
|
||||||
local f = create_faction('human')
|
local f = create_faction('human')
|
||||||
|
|
|
@ -29,6 +29,21 @@ function test_castle_names()
|
||||||
assert_equal("citadel", b:get_typename(6250))
|
assert_equal("citadel", b:get_typename(6250))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function test_build_castle_one_stage()
|
||||||
|
local r = region.create(0, 0, 'plain')
|
||||||
|
local f = faction.create('human')
|
||||||
|
local u = unit.create(f, r, 2)
|
||||||
|
|
||||||
|
u:add_item('stone', 4)
|
||||||
|
|
||||||
|
u:set_skill('building', 1)
|
||||||
|
u:add_order('MACHE BURG')
|
||||||
|
|
||||||
|
process_orders()
|
||||||
|
assert_equal(2, u.building.size)
|
||||||
|
assert_equal(2, u:get_item('stone'))
|
||||||
|
end
|
||||||
|
|
||||||
function test_build_castle_stages()
|
function test_build_castle_stages()
|
||||||
local r = region.create(0,0, "plain")
|
local r = region.create(0,0, "plain")
|
||||||
local f = faction.create("human")
|
local f = faction.create("human")
|
||||||
|
|
|
@ -26,7 +26,6 @@ static void test_herbsearch(CuTest * tc)
|
||||||
const item_type *itype;
|
const item_type *itype;
|
||||||
|
|
||||||
test_setup();
|
test_setup();
|
||||||
test_inject_messagetypes();
|
|
||||||
r = test_create_region(0, 0, NULL);
|
r = test_create_region(0, 0, NULL);
|
||||||
rc = rc_get_or_create("dragon");
|
rc = rc_get_or_create("dragon");
|
||||||
rc->flags |= RCF_UNARMEDGUARD;
|
rc->flags |= RCF_UNARMEDGUARD;
|
||||||
|
|
|
@ -34,17 +34,19 @@ int autostudy_init(scholar scholars[], int max_scholars, region *r)
|
||||||
int nscholars = 0;
|
int nscholars = 0;
|
||||||
|
|
||||||
for (u = r->units; u; u = u->next) {
|
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 (kwd == K_AUTOSTUDY) {
|
||||||
if (long_order_allowed(u) && unit_can_study(u)) {
|
if (long_order_allowed(u)) {
|
||||||
scholar * st = scholars + nscholars;
|
scholar * st = scholars + nscholars;
|
||||||
init_order(u->thisorder, u->faction->locale);
|
skill_t sk = getskill(u->faction->locale);
|
||||||
st->sk = getskill(u->faction->locale);
|
if (check_student(u, u->thisorder, sk)) {
|
||||||
st->level = effskill_study(u, st->sk);
|
st->sk = sk;
|
||||||
st->learn = 0;
|
st->level = effskill_study(u, st->sk);
|
||||||
st->u = u;
|
st->learn = 0;
|
||||||
if (++nscholars == max_scholars) {
|
st->u = u;
|
||||||
log_fatal("you must increase MAXSCHOLARS");
|
if (++nscholars == max_scholars) {
|
||||||
|
log_fatal("you must increase MAXSCHOLARS");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -9,17 +9,22 @@
|
||||||
#include "kernel/region.h"
|
#include "kernel/region.h"
|
||||||
#include "kernel/unit.h"
|
#include "kernel/unit.h"
|
||||||
|
|
||||||
|
#include "util/message.h"
|
||||||
|
|
||||||
#include "tests.h"
|
#include "tests.h"
|
||||||
|
|
||||||
#include <CuTest.h>
|
#include <CuTest.h>
|
||||||
|
|
||||||
static void test_autostudy_init(CuTest *tc) {
|
static void test_autostudy_init(CuTest *tc) {
|
||||||
scholar scholars[4];
|
scholar scholars[4];
|
||||||
unit *u1, *u2, *u3;
|
unit *u1, *u2, *u3, *u4;
|
||||||
faction *f;
|
faction *f;
|
||||||
region *r;
|
region *r;
|
||||||
|
|
||||||
test_setup();
|
test_setup();
|
||||||
|
mt_create_error(77);
|
||||||
|
mt_create_error(771);
|
||||||
|
|
||||||
r = test_create_plain(0, 0);
|
r = test_create_plain(0, 0);
|
||||||
f = test_create_faction(NULL);
|
f = test_create_faction(NULL);
|
||||||
u1 = test_create_unit(f, r);
|
u1 = test_create_unit(f, r);
|
||||||
|
@ -30,8 +35,11 @@ static void test_autostudy_init(CuTest *tc) {
|
||||||
set_level(u2, SK_ENTERTAINMENT, 2);
|
set_level(u2, SK_ENTERTAINMENT, 2);
|
||||||
u3 = test_create_unit(f, r);
|
u3 = test_create_unit(f, r);
|
||||||
u3->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_PERCEPTION]);
|
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;
|
scholars[3].u = NULL;
|
||||||
CuAssertIntEquals(tc, 3, autostudy_init(scholars, 4, r));
|
CuAssertIntEquals(tc, 3, autostudy_init(scholars, 4, r));
|
||||||
|
CuAssertPtrNotNull(tc, test_find_messagetype(u4->faction->msgs, "error77"));
|
||||||
CuAssertPtrEquals(tc, u2, scholars[0].u);
|
CuAssertPtrEquals(tc, u2, scholars[0].u);
|
||||||
CuAssertIntEquals(tc, 2, scholars[0].level);
|
CuAssertIntEquals(tc, 2, scholars[0].level);
|
||||||
CuAssertIntEquals(tc, 0, scholars[0].learn);
|
CuAssertIntEquals(tc, 0, scholars[0].learn);
|
||||||
|
|
|
@ -145,6 +145,7 @@ static struct unit *create_recruiter(void) {
|
||||||
|
|
||||||
static void setup_production(void) {
|
static void setup_production(void) {
|
||||||
init_resources();
|
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("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("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);
|
mt_create_va(mt_new("buy", NULL), "unit:unit", "money:int", MT_NEW_END);
|
||||||
|
@ -737,6 +738,7 @@ static void test_loot(CuTest *tc) {
|
||||||
|
|
||||||
test_setup();
|
test_setup();
|
||||||
setup_production();
|
setup_production();
|
||||||
|
mt_create_error(48); /* unit is unarmed */
|
||||||
it_silver = test_create_silver();
|
it_silver = test_create_silver();
|
||||||
config_set("rules.enable_loot", "1");
|
config_set("rules.enable_loot", "1");
|
||||||
u = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL));
|
u = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||||
|
@ -746,7 +748,7 @@ static void test_loot(CuTest *tc) {
|
||||||
test_clear_messages(f);
|
test_clear_messages(f);
|
||||||
arm_unit(u);
|
arm_unit(u);
|
||||||
produce(u->region);
|
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, 2 * TAXFRACTION, i_get(u->items, it_silver));
|
||||||
CuAssertIntEquals(tc, UFL_LONGACTION | UFL_NOTMOVING, fval(u, UFL_LONGACTION | UFL_NOTMOVING));
|
CuAssertIntEquals(tc, UFL_LONGACTION | UFL_NOTMOVING, fval(u, UFL_LONGACTION | UFL_NOTMOVING));
|
||||||
test_teardown();
|
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", 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);
|
mt_create_va(mt_new("give_peasants", NULL), "unit:unit", "resource:resource", "amount:int", MT_NEW_END);
|
||||||
/* error messages: */
|
/* 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_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("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_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("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("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);
|
mt_create_va(mt_new("nogive_reserved", NULL), "unit:unit", "region:region", "command:order", "resource:resource", "reservation:int", MT_NEW_END);
|
||||||
|
@ -91,7 +94,7 @@ static void test_give_unit(CuTest * tc) {
|
||||||
give_unit(env.src, env.dst, NULL);
|
give_unit(env.src, env.dst, NULL);
|
||||||
CuAssertPtrEquals(tc, env.f2, env.src->faction);
|
CuAssertPtrEquals(tc, env.f2, env.src->faction);
|
||||||
CuAssertIntEquals(tc, 1, env.f2->newbies);
|
CuAssertIntEquals(tc, 1, env.f2->newbies);
|
||||||
CuAssertPtrEquals(tc, 0, env.f1->units);
|
CuAssertPtrEquals(tc, NULL, env.f1->units);
|
||||||
CuAssertPtrNotNull(tc, test_find_messagetype(env.f1->msgs, "give_person"));
|
CuAssertPtrNotNull(tc, test_find_messagetype(env.f1->msgs, "give_person"));
|
||||||
CuAssertPtrNotNull(tc, test_find_messagetype(env.f2->msgs, "receive_person"));
|
CuAssertPtrNotNull(tc, test_find_messagetype(env.f2->msgs, "receive_person"));
|
||||||
test_teardown();
|
test_teardown();
|
||||||
|
@ -159,11 +162,12 @@ static void test_give_men_magicians(CuTest * tc) {
|
||||||
message * msg;
|
message * msg;
|
||||||
|
|
||||||
test_setup_ex(tc);
|
test_setup_ex(tc);
|
||||||
|
mt_create_error(158);
|
||||||
env.f2 = env.f1 = test_create_faction(NULL);
|
env.f2 = env.f1 = test_create_faction(NULL);
|
||||||
setup_give(&env);
|
setup_give(&env);
|
||||||
set_level(env.src, SK_MAGIC, 1);
|
set_level(env.src, SK_MAGIC, 1);
|
||||||
CuAssertPtrNotNull(tc, msg = give_men(1, env.src, env.dst, NULL));
|
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.dst->number);
|
||||||
CuAssertIntEquals(tc, 1, env.src->number);
|
CuAssertIntEquals(tc, 1, env.src->number);
|
||||||
msg_release(msg);
|
msg_release(msg);
|
||||||
|
@ -303,7 +307,7 @@ static void test_give_men_requires_contact(CuTest * tc) {
|
||||||
ord = create_order(K_GIVE, env.f1->locale, "%s ALLES PERSONEN", itoa36(env.dst->no));
|
ord = create_order(K_GIVE, env.f1->locale, "%s ALLES PERSONEN", itoa36(env.dst->no));
|
||||||
test_clear_messages(env.f1);
|
test_clear_messages(env.f1);
|
||||||
give_cmd(env.src, ord);
|
give_cmd(env.src, ord);
|
||||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(env.f1->msgs, "give_person"));
|
CuAssertPtrEquals(tc, NULL, test_find_messagetype(env.f1->msgs, "give_person"));
|
||||||
CuAssertPtrNotNull(tc, test_find_messagetype(env.f1->msgs, "feedback_no_contact"));
|
CuAssertPtrNotNull(tc, test_find_messagetype(env.f1->msgs, "feedback_no_contact"));
|
||||||
|
|
||||||
msg_release(msg);
|
msg_release(msg);
|
||||||
|
@ -407,7 +411,7 @@ static void test_give_okay(CuTest * tc) {
|
||||||
setup_give(&env);
|
setup_give(&env);
|
||||||
|
|
||||||
config_set("rules.give.flags", "0");
|
config_set("rules.give.flags", "0");
|
||||||
CuAssertPtrEquals(tc, 0, check_give(env.src, env.dst, NULL));
|
CuAssertPtrEquals(tc, NULL, check_give(env.src, env.dst, NULL));
|
||||||
test_teardown();
|
test_teardown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -450,7 +454,7 @@ static void test_give_new_unit(CuTest * tc) {
|
||||||
setup_give(&env);
|
setup_give(&env);
|
||||||
env.dst->number = 0;
|
env.dst->number = 0;
|
||||||
fset(env.dst, UFL_ISNEW);
|
fset(env.dst, UFL_ISNEW);
|
||||||
CuAssertPtrEquals(tc, 0, check_give(env.src, env.dst, NULL));
|
CuAssertPtrEquals(tc, NULL, check_give(env.src, env.dst, NULL));
|
||||||
test_teardown();
|
test_teardown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
153
src/gmtool.c
153
src/gmtool.c
|
@ -46,6 +46,7 @@
|
||||||
#include <util/log.h>
|
#include <util/log.h>
|
||||||
#include <util/macros.h>
|
#include <util/macros.h>
|
||||||
#include <util/path.h>
|
#include <util/path.h>
|
||||||
|
#include <util/rand.h>
|
||||||
#include <util/rng.h>
|
#include <util/rng.h>
|
||||||
#include <util/unicode.h>
|
#include <util/unicode.h>
|
||||||
|
|
||||||
|
@ -55,6 +56,7 @@
|
||||||
#include "wormhole.h"
|
#include "wormhole.h"
|
||||||
#include "teleport.h"
|
#include "teleport.h"
|
||||||
|
|
||||||
|
#include <selist.h>
|
||||||
#include <storage.h>
|
#include <storage.h>
|
||||||
#include <lua.h>
|
#include <lua.h>
|
||||||
|
|
||||||
|
@ -451,7 +453,10 @@ static void paint_info_region(window * wnd, const state * st)
|
||||||
line++;
|
line++;
|
||||||
umvwprintw(win, line++, 1, "%s, age %d", r->terrain->_name, r->age);
|
umvwprintw(win, line++, 1, "%s, age %d", r->terrain->_name, r->age);
|
||||||
if (r->land) {
|
if (r->land) {
|
||||||
|
int iron = region_getresource_level(r, get_resourcetype(R_IRON));
|
||||||
|
int stone = region_getresource_level(r, get_resourcetype(R_STONE));
|
||||||
mvwprintw(win, line++, 1, "$:%6d P:%5d", rmoney(r), rpeasants(r));
|
mvwprintw(win, line++, 1, "$:%6d P:%5d", rmoney(r), rpeasants(r));
|
||||||
|
mvwprintw(win, line++, 1, "S:%6d I:%5d", stone, iron);
|
||||||
mvwprintw(win, line++, 1, "H:%6d %s:%5d", rhorses(r),
|
mvwprintw(win, line++, 1, "H:%6d %s:%5d", rhorses(r),
|
||||||
(r->flags & RF_MALLORN) ? "M" : "T",
|
(r->flags & RF_MALLORN) ? "M" : "T",
|
||||||
r->land->trees[1] + r->land->trees[2]);
|
r->land->trees[1] + r->land->trees[2]);
|
||||||
|
@ -529,6 +534,33 @@ static void statusline(WINDOW * win, const char *str)
|
||||||
wnoutrefresh(win);
|
wnoutrefresh(win);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void reset_resources(region *r, const struct terrain_type *terrain)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; terrain->production[i].type; ++i) {
|
||||||
|
rawmaterial *rm;
|
||||||
|
const terrain_production *production = terrain->production + i;
|
||||||
|
const resource_type *rtype = production->type;
|
||||||
|
|
||||||
|
for (rm = r->resources; rm; rm = rm->next) {
|
||||||
|
if (rm->rtype == rtype)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (rm) {
|
||||||
|
struct rawmaterial_type *rmt;
|
||||||
|
set_resource(rm,
|
||||||
|
dice_rand(production->startlevel),
|
||||||
|
dice_rand(production->base),
|
||||||
|
dice_rand(production->divisor));
|
||||||
|
rmt = rmt_get(rtype);
|
||||||
|
if (rmt && rmt->terraform) {
|
||||||
|
rmt->terraform(rm, r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void reset_region(region *r) {
|
static void reset_region(region *r) {
|
||||||
unit **up = &r->units;
|
unit **up = &r->units;
|
||||||
bool players = false;
|
bool players = false;
|
||||||
|
@ -554,6 +586,7 @@ static void reset_region(region *r) {
|
||||||
}
|
}
|
||||||
if (r->land) {
|
if (r->land) {
|
||||||
init_region(r);
|
init_region(r);
|
||||||
|
reset_resources(r, r->terrain);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -599,6 +632,69 @@ static void terraform_at(coordinate * c, const terrain_type * terrain)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void selection_walk(selection * selected, void(*callback)(region *, void *), void *udata) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i != MAXTHASH; ++i) {
|
||||||
|
tag **tp = &selected->tags[i];
|
||||||
|
while (*tp) {
|
||||||
|
region *r;
|
||||||
|
tag *t = *tp;
|
||||||
|
int nx = t->coord.x, ny = t->coord.y;
|
||||||
|
plane *pl = t->coord.pl;
|
||||||
|
|
||||||
|
pnormalize(&nx, &ny, pl);
|
||||||
|
r = findregion(nx, ny);
|
||||||
|
if (r != NULL) {
|
||||||
|
callback(r, udata);
|
||||||
|
}
|
||||||
|
tp = &t->nexthash;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void reset_levels_cb(region *r, void *udata) {
|
||||||
|
struct rawmaterial *res;
|
||||||
|
UNUSED_ARG(udata);
|
||||||
|
for (res = r->resources; res; res = res->next) {
|
||||||
|
if (res->level > 3) {
|
||||||
|
res->level = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BUG 2506: reset drained mountains to level 1
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
fix_selection(selection * selected)
|
||||||
|
{
|
||||||
|
selection_walk(selected, reset_levels_cb, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
reset_selection(selection * selected)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i != MAXTHASH; ++i) {
|
||||||
|
tag **tp = &selected->tags[i];
|
||||||
|
while (*tp) {
|
||||||
|
region *r;
|
||||||
|
tag *t = *tp;
|
||||||
|
int nx = t->coord.x, ny = t->coord.y;
|
||||||
|
plane *pl = t->coord.pl;
|
||||||
|
|
||||||
|
pnormalize(&nx, &ny, pl);
|
||||||
|
r = findregion(nx, ny);
|
||||||
|
if (r != NULL) {
|
||||||
|
reset_region(r);
|
||||||
|
}
|
||||||
|
tp = &t->nexthash;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
terraform_selection(selection * selected, const terrain_type * terrain)
|
terraform_selection(selection * selected, const terrain_type * terrain)
|
||||||
{
|
{
|
||||||
|
@ -708,7 +804,7 @@ void highlight_region(region * r, int toggle)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void select_coordinate(struct selection *selected, int nx, int ny, int toggle)
|
void select_coordinate(struct selection *selected, int nx, int ny, bool toggle)
|
||||||
{
|
{
|
||||||
if (toggle)
|
if (toggle)
|
||||||
tag_region(selected, nx, ny);
|
tag_region(selected, nx, ny);
|
||||||
|
@ -716,7 +812,50 @@ void select_coordinate(struct selection *selected, int nx, int ny, int toggle)
|
||||||
untag_region(selected, nx, ny);
|
untag_region(selected, nx, ny);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum { MODE_MARK, MODE_SELECT, MODE_UNMARK, MODE_UNSELECT };
|
enum select_t { MODE_MARK, MODE_SELECT, MODE_UNMARK, MODE_UNSELECT };
|
||||||
|
|
||||||
|
static void select_island(state *st, int selectmode)
|
||||||
|
{
|
||||||
|
region *r;
|
||||||
|
int nx = st->cursor.x;
|
||||||
|
int ny = st->cursor.y;
|
||||||
|
|
||||||
|
pnormalize(&nx, &ny, st->cursor.pl);
|
||||||
|
r = findregion(nx, ny);
|
||||||
|
if (r && r->land) {
|
||||||
|
selist *ql, *stack = NULL;
|
||||||
|
int qi = 0;
|
||||||
|
|
||||||
|
selist_push(&stack, r);
|
||||||
|
for (ql = stack, qi = 0; ql; selist_advance(&ql, &qi, 1)) {
|
||||||
|
region *r = (region *)selist_get(ql, qi);
|
||||||
|
region *rnext[MAXDIRECTIONS];
|
||||||
|
int i;
|
||||||
|
|
||||||
|
fset(r, RF_MARK);
|
||||||
|
if (selectmode & MODE_SELECT) {
|
||||||
|
select_coordinate(st->selected, r->x, r->y,
|
||||||
|
selectmode == MODE_SELECT);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
highlight_region(r, selectmode == MODE_MARK);
|
||||||
|
}
|
||||||
|
get_neighbours(r, rnext);
|
||||||
|
for (i = 0; i != MAXDIRECTIONS; ++i) {
|
||||||
|
region *rn = rnext[i];
|
||||||
|
if (rn && rn->land && !fval(rn, RF_MARK)) {
|
||||||
|
selist_push(&stack, rn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (ql = stack, qi = 0; ql; selist_advance(&ql, &qi, 1)) {
|
||||||
|
region *r = (region *)selist_get(ql, qi);
|
||||||
|
freset(r, RF_MARK);
|
||||||
|
}
|
||||||
|
selist_free(stack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void select_regions(state * st, int selectmode)
|
static void select_regions(state * st, int selectmode)
|
||||||
{
|
{
|
||||||
|
@ -870,6 +1009,11 @@ static void select_regions(state * st, int selectmode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (findmode == 'i') {
|
||||||
|
sprintf(sbuffer, "%swand: ", status);
|
||||||
|
statusline(st->wnd_status->handle, sbuffer);
|
||||||
|
select_island(st, selectmode);
|
||||||
|
}
|
||||||
else if (findmode == 't') {
|
else if (findmode == 't') {
|
||||||
const struct terrain_type *terrain;
|
const struct terrain_type *terrain;
|
||||||
sprintf(sbuffer, "%sterrain: ", status);
|
sprintf(sbuffer, "%sterrain: ", status);
|
||||||
|
@ -1210,7 +1354,12 @@ static void handlekey(state * st, int c)
|
||||||
statusline(st->wnd_status->handle, "tag-");
|
statusline(st->wnd_status->handle, "tag-");
|
||||||
doupdate();
|
doupdate();
|
||||||
switch (getch()) {
|
switch (getch()) {
|
||||||
|
case 'r':
|
||||||
|
reset_selection(st->selected);
|
||||||
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
|
fix_selection(st->selected);
|
||||||
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
terraform_selection(st->selected, select_terrain(st, NULL));
|
terraform_selection(st->selected, select_terrain(st, NULL));
|
||||||
st->modified = 1;
|
st->modified = 1;
|
||||||
|
|
|
@ -29,7 +29,7 @@ extern "C" {
|
||||||
const char *prompt);
|
const char *prompt);
|
||||||
|
|
||||||
void highlight_region(struct region *r, int on);
|
void highlight_region(struct region *r, int on);
|
||||||
void select_coordinate(struct selection *selected, int x, int y, int on);
|
void select_coordinate(struct selection *selected, int x, int y, bool on);
|
||||||
void run_mapper(void);
|
void run_mapper(void);
|
||||||
|
|
||||||
extern int force_color;
|
extern int force_color;
|
||||||
|
|
|
@ -18,7 +18,6 @@ static void test_manacrystal(CuTest *tc) {
|
||||||
unit *u;
|
unit *u;
|
||||||
|
|
||||||
test_setup();
|
test_setup();
|
||||||
test_inject_messagetypes();
|
|
||||||
|
|
||||||
u = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0));
|
u = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0));
|
||||||
itype = test_create_itemtype("manacrystal");
|
itype = test_create_itemtype("manacrystal");
|
||||||
|
@ -49,7 +48,6 @@ static void test_skillpotion(CuTest *tc) {
|
||||||
int initialWeeks_Magic = 0;
|
int initialWeeks_Magic = 0;
|
||||||
|
|
||||||
test_setup();
|
test_setup();
|
||||||
test_inject_messagetypes();
|
|
||||||
u = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0));
|
u = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0));
|
||||||
itype = test_create_itemtype("skillpotion");
|
itype = test_create_itemtype("skillpotion");
|
||||||
change_resource(u, itype->rtype, 2);
|
change_resource(u, itype->rtype, 2);
|
||||||
|
|
|
@ -500,50 +500,46 @@ static int count_materials(unit *u, const construction *type, int n, int complet
|
||||||
return n;
|
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.
|
/** Use up resources for building an object.
|
||||||
* Build up to 'size' points of 'type', where 'completed'
|
* Build up to 'size' points of 'type', where 'completed'
|
||||||
* of the first object have already been finished. return the
|
* of the first object have already been finished. return the
|
||||||
* actual size that could be built.
|
* actual size that could be built.
|
||||||
*/
|
*/
|
||||||
int build(unit * u, const construction * ctype, int completed, int want, int skill_mod)
|
static int build_limited(unit * u, const construction * con, int completed, int want, int basesk, int *skill_total) {
|
||||||
{
|
int skills = *skill_total;
|
||||||
const construction *con = ctype;
|
|
||||||
int skills = INT_MAX; /* number of skill points remainig */
|
|
||||||
int basesk = 0;
|
|
||||||
int made = 0;
|
int made = 0;
|
||||||
|
|
||||||
if (want <= 0)
|
if (want <= 0) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
if (con == NULL) {
|
if (con == NULL) {
|
||||||
return ENOMATERIALS;
|
return ENOMATERIALS;
|
||||||
}
|
}
|
||||||
if (completed == con->maxsize) {
|
if (completed == con->maxsize) {
|
||||||
return ECOMPLETE;
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (; want > 0 && skills > 0;) {
|
for (; want > 0 && skills > 0;) {
|
||||||
int err, n;
|
int err, n;
|
||||||
|
|
||||||
|
@ -610,9 +606,27 @@ int build(unit * u, const construction * ctype, int completed, int want, int ski
|
||||||
want -= n;
|
want -= n;
|
||||||
completed = completed + n;
|
completed = completed + n;
|
||||||
}
|
}
|
||||||
/* Nur soviel PRODUCEEXP wie auch tatsaechlich gemacht wurde */
|
*skill_total = skills;
|
||||||
produceexp(u, ctype->skill, (made < u->number) ? made : u->number);
|
return made;
|
||||||
|
}
|
||||||
|
|
||||||
|
int build(unit * u, const construction * con, int completed, int want, int skill_mod)
|
||||||
|
{
|
||||||
|
int skills = INT_MAX; /* number of skill points remainig */
|
||||||
|
int made, basesk = 0;
|
||||||
|
|
||||||
|
assert(con->skill != NOSKILL);
|
||||||
|
basesk = effskill(u, con->skill, 0);
|
||||||
|
if (basesk == 0) {
|
||||||
|
return ENEEDSKILL;
|
||||||
|
}
|
||||||
|
|
||||||
|
skills = build_skill(u, basesk, skill_mod);
|
||||||
|
made = build_limited(u, con, completed, want, basesk, &skills);
|
||||||
|
/* Nur soviel PRODUCEEXP wie auch tatsaechlich gemacht wurde */
|
||||||
|
if (made > 0) {
|
||||||
|
produceexp(u, con->skill, (made < u->number) ? made : u->number);
|
||||||
|
}
|
||||||
return made;
|
return made;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -681,7 +695,7 @@ static int build_failure(unit *u, order *ord, const building_type *btype, int wa
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int build_stages(unit *u, const building_type *btype, int built, int n) {
|
static int build_stages(unit *u, const building_type *btype, int built, int n, int basesk, int *skill_total) {
|
||||||
|
|
||||||
const building_stage *stage;
|
const building_stage *stage;
|
||||||
int made = 0;
|
int made = 0;
|
||||||
|
@ -701,7 +715,7 @@ static int build_stages(unit *u, const building_type *btype, int built, int n) {
|
||||||
want = todo;
|
want = todo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = build(u, con, built, want, 0);
|
err = build_limited(u, con, built, want, basesk, skill_total);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
if (made == 0) {
|
if (made == 0) {
|
||||||
/* could not make any part at all */
|
/* could not make any part at all */
|
||||||
|
@ -739,10 +753,14 @@ build_building(unit * u, const building_type * btype, int id, int want, order *
|
||||||
const char *btname;
|
const char *btname;
|
||||||
order *new_order = NULL;
|
order *new_order = NULL;
|
||||||
const struct locale *lang = u->faction->locale;
|
const struct locale *lang = u->faction->locale;
|
||||||
|
int skills, basesk; /* number of skill points remainig */
|
||||||
|
|
||||||
assert(u->number);
|
assert(u->number);
|
||||||
assert(btype->stages && btype->stages->construction);
|
assert(btype->stages && btype->stages->construction);
|
||||||
if (effskill(u, SK_BUILDING, 0) == 0) {
|
|
||||||
|
basesk = effskill(u, SK_BUILDING, 0);
|
||||||
|
skills = build_skill(u, basesk, 0);
|
||||||
|
if (skills == 0) {
|
||||||
cmistake(u, ord, 101, MSG_PRODUCE);
|
cmistake(u, ord, 101, MSG_PRODUCE);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -832,7 +850,7 @@ build_building(unit * u, const building_type * btype, int id, int want, order *
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
built = build_stages(u, btype, built, n);
|
built = build_stages(u, btype, built, n, basesk, &skills);
|
||||||
|
|
||||||
if (built < 0) {
|
if (built < 0) {
|
||||||
return build_failure(u, ord, btype, want, built);
|
return build_failure(u, ord, btype, want, built);
|
||||||
|
|
|
@ -17,8 +17,9 @@
|
||||||
#include <CuTest.h>
|
#include <CuTest.h>
|
||||||
#include <tests.h>
|
#include <tests.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
typedef struct build_fixture {
|
typedef struct build_fixture {
|
||||||
faction *f;
|
faction *f;
|
||||||
|
@ -31,7 +32,6 @@ typedef struct build_fixture {
|
||||||
|
|
||||||
static unit * setup_build(build_fixture *bf) {
|
static unit * setup_build(build_fixture *bf) {
|
||||||
test_setup();
|
test_setup();
|
||||||
test_inject_messagetypes();
|
|
||||||
init_resources();
|
init_resources();
|
||||||
|
|
||||||
test_create_itemtype("stone");
|
test_create_itemtype("stone");
|
||||||
|
@ -53,6 +53,53 @@ static unit * setup_build(build_fixture *bf) {
|
||||||
return bf->u;
|
return bf->u;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static building_type *setup_castle(item_type *it_stone) {
|
||||||
|
building_type *btype;
|
||||||
|
building_stage *stage;
|
||||||
|
construction * cons;
|
||||||
|
|
||||||
|
btype = test_create_buildingtype("castle");
|
||||||
|
stage = btype->stages = calloc(1, sizeof(building_stage));
|
||||||
|
cons = stage->construction = calloc(1, sizeof(construction));
|
||||||
|
cons->materials = calloc(2, sizeof(requirement));
|
||||||
|
cons->materials[0].number = 1;
|
||||||
|
cons->materials[0].rtype = it_stone->rtype;
|
||||||
|
cons->minskill = 1;
|
||||||
|
cons->maxsize = 2;
|
||||||
|
cons->reqsize = 1;
|
||||||
|
cons->skill = SK_BUILDING;
|
||||||
|
stage = stage->next = calloc(1, sizeof(building_stage));
|
||||||
|
cons = stage->construction = calloc(1, sizeof(construction));
|
||||||
|
cons->materials = calloc(2, sizeof(requirement));
|
||||||
|
cons->materials[0].number = 1;
|
||||||
|
cons->materials[0].rtype = it_stone->rtype;
|
||||||
|
cons->minskill = 1;
|
||||||
|
cons->maxsize = 8;
|
||||||
|
cons->reqsize = 1;
|
||||||
|
cons->skill = SK_BUILDING;
|
||||||
|
return btype;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_build_building_stages(CuTest *tc) {
|
||||||
|
building_type *btype;
|
||||||
|
item_type *it_stone;
|
||||||
|
unit *u;
|
||||||
|
|
||||||
|
test_setup();
|
||||||
|
init_resources();
|
||||||
|
it_stone = test_create_itemtype("stone");
|
||||||
|
btype = setup_castle(it_stone);
|
||||||
|
u = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0));
|
||||||
|
set_level(u, SK_BUILDING, 2);
|
||||||
|
i_change(&u->items, it_stone, 4);
|
||||||
|
build_building(u, btype, -1, INT_MAX, NULL);
|
||||||
|
CuAssertPtrNotNull(tc, u->building);
|
||||||
|
CuAssertIntEquals(tc, 2, u->building->size);
|
||||||
|
CuAssertIntEquals(tc, 2, i_get(u->items, it_stone));
|
||||||
|
|
||||||
|
test_teardown();
|
||||||
|
}
|
||||||
|
|
||||||
static void teardown_build(build_fixture *bf) {
|
static void teardown_build(build_fixture *bf) {
|
||||||
free(bf->cons.materials);
|
free(bf->cons.materials);
|
||||||
test_teardown();
|
test_teardown();
|
||||||
|
@ -307,7 +354,6 @@ static void test_build_destroy_road_guard(CuTest *tc)
|
||||||
order *ord;
|
order *ord;
|
||||||
|
|
||||||
test_setup();
|
test_setup();
|
||||||
test_inject_messagetypes();
|
|
||||||
test_create_region(1, 0, 0);
|
test_create_region(1, 0, 0);
|
||||||
r = test_create_region(0, 0, NULL);
|
r = test_create_region(0, 0, NULL);
|
||||||
rsetroad(r, D_EAST, 100);
|
rsetroad(r, D_EAST, 100);
|
||||||
|
@ -340,7 +386,6 @@ static void test_build_destroy_road_limit(CuTest *tc)
|
||||||
order *ord;
|
order *ord;
|
||||||
|
|
||||||
test_setup();
|
test_setup();
|
||||||
test_inject_messagetypes();
|
|
||||||
test_create_region(1, 0, 0);
|
test_create_region(1, 0, 0);
|
||||||
r = test_create_region(0, 0, NULL);
|
r = test_create_region(0, 0, NULL);
|
||||||
rsetroad(r, D_EAST, 100);
|
rsetroad(r, D_EAST, 100);
|
||||||
|
@ -365,6 +410,7 @@ static void test_build_destroy_cmd(CuTest *tc) {
|
||||||
faction *f;
|
faction *f;
|
||||||
|
|
||||||
test_setup();
|
test_setup();
|
||||||
|
mt_create_error(138);
|
||||||
u = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL));
|
u = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||||
u->thisorder = create_order(K_DESTROY, f->locale, NULL);
|
u->thisorder = create_order(K_DESTROY, f->locale, NULL);
|
||||||
CuAssertIntEquals(tc, 138, destroy_cmd(u, u->thisorder));
|
CuAssertIntEquals(tc, 138, destroy_cmd(u, u->thisorder));
|
||||||
|
@ -392,6 +438,7 @@ CuSuite *get_build_suite(void)
|
||||||
SUITE_ADD_TEST(suite, test_build_with_ring);
|
SUITE_ADD_TEST(suite, test_build_with_ring);
|
||||||
SUITE_ADD_TEST(suite, test_build_with_potion);
|
SUITE_ADD_TEST(suite, test_build_with_potion);
|
||||||
SUITE_ADD_TEST(suite, test_build_building_success);
|
SUITE_ADD_TEST(suite, test_build_building_success);
|
||||||
|
SUITE_ADD_TEST(suite, test_build_building_stages);
|
||||||
SUITE_ADD_TEST(suite, test_build_building_with_golem);
|
SUITE_ADD_TEST(suite, test_build_building_with_golem);
|
||||||
SUITE_ADD_TEST(suite, test_build_building_no_materials);
|
SUITE_ADD_TEST(suite, test_build_building_no_materials);
|
||||||
SUITE_ADD_TEST(suite, test_build_destroy_cmd);
|
SUITE_ADD_TEST(suite, test_build_destroy_cmd);
|
||||||
|
|
|
@ -51,7 +51,6 @@ typedef struct {
|
||||||
|
|
||||||
static void setup_curse(curse_fixture *fix, const char *name) {
|
static void setup_curse(curse_fixture *fix, const char *name) {
|
||||||
test_setup();
|
test_setup();
|
||||||
test_inject_messagetypes();
|
|
||||||
fix->r = test_create_region(0, 0, NULL);
|
fix->r = test_create_region(0, 0, NULL);
|
||||||
fix->u = test_create_unit(test_create_faction(NULL), fix->r);
|
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);
|
fix->c = create_curse(fix->u, &fix->r->attribs, ct_find(name), 1.0, 1, 1.0, 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,
|
struct message *msg_feedback(const struct unit *u, struct order *ord,
|
||||||
const char *name, const char *sig, ...)
|
const char *name, const char *sig, ...)
|
||||||
{
|
{
|
||||||
|
@ -80,13 +120,7 @@ struct message *msg_feedback(const struct unit *u, struct order *ord,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mtype) {
|
if (!mtype) {
|
||||||
log_warning("trying to create message of unknown type \"%s\"\n", name);
|
return missing_feedback(name, u, u->region, ord);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var.v = (void *)u;
|
var.v = (void *)u;
|
||||||
|
@ -139,28 +173,6 @@ struct message *msg_feedback(const struct unit *u, struct order *ord,
|
||||||
return msg_create(mtype, args);
|
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, ...)
|
message *msg_message(const char *name, const char *sig, ...)
|
||||||
/* msg_message("oops_error", "unit region command", u, r, cmd) */
|
/* 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);
|
||||||
CuAssertPtrNotNull(tc, msg->type);
|
CuAssertPtrNotNull(tc, msg->type);
|
||||||
CuAssertStrEquals(tc, msg->type->name, "missing_message");
|
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);
|
msg_release(msg);
|
||||||
test_teardown();
|
test_teardown();
|
||||||
}
|
}
|
||||||
|
|
|
@ -342,7 +342,7 @@ order *parse_order(const char *s, const struct locale * lang)
|
||||||
sptr = sp;
|
sptr = sp;
|
||||||
p = parse_token(&sp, token, sizeof(token));
|
p = parse_token(&sp, token, sizeof(token));
|
||||||
sk = get_skill(p, lang);
|
sk = get_skill(p, lang);
|
||||||
if (!expensive_skill(sk)) {
|
if (sk == NOSKILL || !expensive_skill(sk)) {
|
||||||
kwd = K_AUTOSTUDY;
|
kwd = K_AUTOSTUDY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -827,7 +827,7 @@ void free_land(land_region * lr)
|
||||||
free(lr);
|
free(lr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void region_setresource(region * r, const resource_type * rtype, int value)
|
void region_setresource(region * r, const struct resource_type *rtype, int value)
|
||||||
{
|
{
|
||||||
rawmaterial *rm = r->resources;
|
rawmaterial *rm = r->resources;
|
||||||
while (rm) {
|
while (rm) {
|
||||||
|
@ -870,7 +870,18 @@ void region_setresource(region * r, const resource_type * rtype, int value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int region_getresource(const region * r, const resource_type * rtype)
|
int region_getresource_level(const region * r, const struct resource_type * rtype)
|
||||||
|
{
|
||||||
|
const rawmaterial *rm;
|
||||||
|
for (rm = r->resources; rm; rm = rm->next) {
|
||||||
|
if (rm->rtype == rtype) {
|
||||||
|
return rm->level;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int region_getresource(const region * r, const struct resource_type *rtype)
|
||||||
{
|
{
|
||||||
const rawmaterial *rm;
|
const rawmaterial *rm;
|
||||||
for (rm = r->resources; rm; rm = rm->next) {
|
for (rm = r->resources; rm; rm = rm->next) {
|
||||||
|
|
|
@ -261,6 +261,8 @@ extern "C" {
|
||||||
void region_setname(struct region *self, const char *name);
|
void region_setname(struct region *self, const char *name);
|
||||||
const char *region_getinfo(const struct region *self);
|
const char *region_getinfo(const struct region *self);
|
||||||
void region_setinfo(struct region *self, const char *name);
|
void region_setinfo(struct region *self, const char *name);
|
||||||
|
int region_getresource_level(const struct region * r,
|
||||||
|
const struct resource_type * rtype);
|
||||||
int region_getresource(const struct region *r,
|
int region_getresource(const struct region *r,
|
||||||
const struct resource_type *rtype);
|
const struct resource_type *rtype);
|
||||||
void region_setresource(struct region *r, const struct resource_type *rtype,
|
void region_setresource(struct region *r, const struct resource_type *rtype,
|
||||||
|
|
|
@ -46,8 +46,6 @@ void update_resources(region * r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern int dice_rand(const char *s);
|
|
||||||
|
|
||||||
static void update_resource(struct rawmaterial *res, double modifier)
|
static void update_resource(struct rawmaterial *res, double modifier)
|
||||||
{
|
{
|
||||||
double amount = (res->level - res->startlevel) / 100.0 * res->divisor + 1;
|
double amount = (res->level - res->startlevel) / 100.0 * res->divisor + 1;
|
||||||
|
@ -59,6 +57,15 @@ static void update_resource(struct rawmaterial *res, double modifier)
|
||||||
assert(res->amount > 0);
|
assert(res->amount > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_resource(struct rawmaterial *rm, int level, int base, int divisor)
|
||||||
|
{
|
||||||
|
rm->level = level;
|
||||||
|
rm->startlevel = level;
|
||||||
|
rm->base = base;
|
||||||
|
rm->amount = base;
|
||||||
|
rm->divisor = divisor;
|
||||||
|
}
|
||||||
|
|
||||||
struct rawmaterial *
|
struct rawmaterial *
|
||||||
add_resource(region * r, int level, int base, int divisor,
|
add_resource(region * r, int level, int base, int divisor,
|
||||||
const resource_type * rtype)
|
const resource_type * rtype)
|
||||||
|
@ -67,13 +74,9 @@ const resource_type * rtype)
|
||||||
|
|
||||||
rm->next = r->resources;
|
rm->next = r->resources;
|
||||||
r->resources = rm;
|
r->resources = rm;
|
||||||
rm->level = level;
|
|
||||||
rm->startlevel = level;
|
|
||||||
rm->base = base;
|
|
||||||
rm->amount = base;
|
|
||||||
rm->divisor = divisor;
|
|
||||||
rm->flags = 0;
|
rm->flags = 0;
|
||||||
rm->rtype = rtype;
|
rm->rtype = rtype;
|
||||||
|
set_resource(rm, level, base, divisor);
|
||||||
return rm;
|
return rm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,6 +70,7 @@ extern "C" {
|
||||||
const struct resource_type *);
|
const struct resource_type *);
|
||||||
struct rawmaterial_type *rmt_get(const struct resource_type *);
|
struct rawmaterial_type *rmt_get(const struct resource_type *);
|
||||||
|
|
||||||
|
void set_resource(struct rawmaterial *rm, int level, int base, int divisor);
|
||||||
struct rawmaterial *add_resource(struct region *r, int level,
|
struct rawmaterial *add_resource(struct region *r, int level,
|
||||||
int base, int divisor, const struct resource_type *rtype);
|
int base, int divisor, const struct resource_type *rtype);
|
||||||
struct rawmaterial_type *rmt_create(struct resource_type *rtype);
|
struct rawmaterial_type *rmt_create(struct resource_type *rtype);
|
||||||
|
|
|
@ -33,7 +33,6 @@ static void test_create_duplicate_spell(CuTest * tc)
|
||||||
strlist *sl = 0;
|
strlist *sl = 0;
|
||||||
|
|
||||||
test_setup();
|
test_setup();
|
||||||
test_inject_messagetypes();
|
|
||||||
test_log_stderr(0); /* suppress the "duplicate spell" error message */
|
test_log_stderr(0); /* suppress the "duplicate spell" error message */
|
||||||
log = test_log_start(LOG_CPERROR, &sl);
|
log = test_log_start(LOG_CPERROR, &sl);
|
||||||
|
|
||||||
|
|
|
@ -1853,10 +1853,6 @@ bool unit_name_equals_race(const unit *u) {
|
||||||
return false;
|
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)
|
static int read_newunitid(const faction * f, const region * r)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
|
|
|
@ -246,7 +246,6 @@ extern "C" {
|
||||||
const char *unitname(const struct unit *u);
|
const char *unitname(const struct unit *u);
|
||||||
char *write_unitname(const struct unit *u, char *buffer, size_t size);
|
char *write_unitname(const struct unit *u, char *buffer, size_t size);
|
||||||
bool unit_name_equals_race(const struct unit *u);
|
bool unit_name_equals_race(const struct unit *u);
|
||||||
bool unit_can_study(const struct unit *u);
|
|
||||||
|
|
||||||
/* getunit results: */
|
/* getunit results: */
|
||||||
#define GET_UNIT 0
|
#define GET_UNIT 0
|
||||||
|
|
|
@ -153,8 +153,8 @@ static void test_enter_building(CuTest * tc)
|
||||||
rc->flags = RCF_SWIM;
|
rc->flags = RCF_SWIM;
|
||||||
u->building = 0;
|
u->building = 0;
|
||||||
CuAssertIntEquals(tc, 0, enter_building(u, NULL, b->no, false));
|
CuAssertIntEquals(tc, 0, enter_building(u, NULL, b->no, false));
|
||||||
CuAssertPtrEquals(tc, 0, u->building);
|
CuAssertPtrEquals(tc, NULL, u->building);
|
||||||
CuAssertPtrEquals(tc, 0, u->faction->msgs);
|
CuAssertPtrEquals(tc, NULL, u->faction->msgs);
|
||||||
|
|
||||||
CuAssertIntEquals(tc, 0, enter_building(u, NULL, b->no, true));
|
CuAssertIntEquals(tc, 0, enter_building(u, NULL, b->no, true));
|
||||||
CuAssertPtrNotNull(tc, u->faction->msgs);
|
CuAssertPtrNotNull(tc, u->faction->msgs);
|
||||||
|
@ -170,7 +170,6 @@ static void test_enter_ship(CuTest * tc)
|
||||||
race * rc;
|
race * rc;
|
||||||
|
|
||||||
test_setup();
|
test_setup();
|
||||||
|
|
||||||
r = test_create_region(0, 0, NULL);
|
r = test_create_region(0, 0, NULL);
|
||||||
rc = test_create_race("smurf");
|
rc = test_create_race("smurf");
|
||||||
u = test_create_unit(test_create_faction(rc), r);
|
u = test_create_unit(test_create_faction(rc), r);
|
||||||
|
@ -194,8 +193,8 @@ static void test_enter_ship(CuTest * tc)
|
||||||
rc->flags = RCF_SWIM;
|
rc->flags = RCF_SWIM;
|
||||||
u->ship = 0;
|
u->ship = 0;
|
||||||
CuAssertIntEquals(tc, 0, enter_ship(u, NULL, sh->no, false));
|
CuAssertIntEquals(tc, 0, enter_ship(u, NULL, sh->no, false));
|
||||||
CuAssertPtrEquals(tc, 0, u->ship);
|
CuAssertPtrEquals(tc, NULL, u->ship);
|
||||||
CuAssertPtrEquals(tc, 0, u->faction->msgs);
|
CuAssertPtrEquals(tc, NULL, u->faction->msgs);
|
||||||
|
|
||||||
CuAssertIntEquals(tc, 0, enter_ship(u, NULL, sh->no, true));
|
CuAssertIntEquals(tc, 0, enter_ship(u, NULL, sh->no, true));
|
||||||
CuAssertPtrNotNull(tc, u->faction->msgs);
|
CuAssertPtrNotNull(tc, u->faction->msgs);
|
||||||
|
@ -486,6 +485,10 @@ static void test_limit_new_units(CuTest * tc)
|
||||||
alliance *al;
|
alliance *al;
|
||||||
|
|
||||||
test_setup();
|
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");
|
al = makealliance(1, "Hodor");
|
||||||
f = test_create_faction(NULL);
|
f = test_create_faction(NULL);
|
||||||
u = test_create_unit(f, test_create_region(0, 0, NULL));
|
u = test_create_unit(f, test_create_region(0, 0, NULL));
|
||||||
|
@ -901,6 +904,9 @@ static unit * setup_name_cmd(void) {
|
||||||
faction *f;
|
faction *f;
|
||||||
|
|
||||||
test_setup();
|
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_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);
|
mt_create_va(mt_new("renamed_building_notseen", NULL), "region:region", "building:building", MT_NEW_END);
|
||||||
f = test_create_faction(NULL);
|
f = test_create_faction(NULL);
|
||||||
|
@ -1049,8 +1055,8 @@ static void test_long_order_normal(CuTest *tc) {
|
||||||
CuAssertIntEquals(tc, 0, fval(u, UFL_MOVED));
|
CuAssertIntEquals(tc, 0, fval(u, UFL_MOVED));
|
||||||
CuAssertIntEquals(tc, 0, fval(u, UFL_LONGACTION));
|
CuAssertIntEquals(tc, 0, fval(u, UFL_LONGACTION));
|
||||||
CuAssertPtrNotNull(tc, u->orders);
|
CuAssertPtrNotNull(tc, u->orders);
|
||||||
CuAssertPtrEquals(tc, 0, u->faction->msgs);
|
CuAssertPtrEquals(tc, NULL, u->faction->msgs);
|
||||||
CuAssertPtrEquals(tc, 0, u->old_orders);
|
CuAssertPtrEquals(tc, NULL, u->old_orders);
|
||||||
test_teardown();
|
test_teardown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1060,9 +1066,9 @@ static void test_long_order_none(CuTest *tc) {
|
||||||
test_setup();
|
test_setup();
|
||||||
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||||
update_long_order(u);
|
update_long_order(u);
|
||||||
CuAssertPtrEquals(tc, 0, u->thisorder);
|
CuAssertPtrEquals(tc, NULL, u->thisorder);
|
||||||
CuAssertPtrEquals(tc, 0, u->orders);
|
CuAssertPtrEquals(tc, NULL, u->orders);
|
||||||
CuAssertPtrEquals(tc, 0, u->faction->msgs);
|
CuAssertPtrEquals(tc, NULL, u->faction->msgs);
|
||||||
test_teardown();
|
test_teardown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1074,9 +1080,9 @@ static void test_long_order_cast(CuTest *tc) {
|
||||||
unit_addorder(u, create_order(K_CAST, u->faction->locale, NULL));
|
unit_addorder(u, create_order(K_CAST, u->faction->locale, NULL));
|
||||||
unit_addorder(u, create_order(K_CAST, u->faction->locale, NULL));
|
unit_addorder(u, create_order(K_CAST, u->faction->locale, NULL));
|
||||||
update_long_order(u);
|
update_long_order(u);
|
||||||
CuAssertPtrEquals(tc, 0, u->thisorder);
|
CuAssertPtrEquals(tc, NULL, u->thisorder);
|
||||||
CuAssertPtrNotNull(tc, u->orders);
|
CuAssertPtrNotNull(tc, u->orders);
|
||||||
CuAssertPtrEquals(tc, 0, u->faction->msgs);
|
CuAssertPtrEquals(tc, NULL, u->faction->msgs);
|
||||||
test_teardown();
|
test_teardown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1089,9 +1095,9 @@ static void test_long_order_buy_sell(CuTest *tc) {
|
||||||
unit_addorder(u, create_order(K_SELL, u->faction->locale, NULL));
|
unit_addorder(u, create_order(K_SELL, u->faction->locale, NULL));
|
||||||
unit_addorder(u, create_order(K_SELL, u->faction->locale, NULL));
|
unit_addorder(u, create_order(K_SELL, u->faction->locale, NULL));
|
||||||
update_long_order(u);
|
update_long_order(u);
|
||||||
CuAssertPtrEquals(tc, 0, u->thisorder);
|
CuAssertPtrEquals(tc, NULL, u->thisorder);
|
||||||
CuAssertPtrNotNull(tc, u->orders);
|
CuAssertPtrNotNull(tc, u->orders);
|
||||||
CuAssertPtrEquals(tc, 0, u->faction->msgs);
|
CuAssertPtrEquals(tc, NULL, u->faction->msgs);
|
||||||
test_teardown();
|
test_teardown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1099,6 +1105,7 @@ static void test_long_order_multi_long(CuTest *tc) {
|
||||||
/* TODO: write more tests */
|
/* TODO: write more tests */
|
||||||
unit *u;
|
unit *u;
|
||||||
test_setup();
|
test_setup();
|
||||||
|
mt_create_error(52);
|
||||||
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
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_MOVE, u->faction->locale, NULL));
|
||||||
unit_addorder(u, create_order(K_DESTROY, u->faction->locale, NULL));
|
unit_addorder(u, create_order(K_DESTROY, u->faction->locale, NULL));
|
||||||
|
@ -1113,11 +1120,12 @@ static void test_long_order_multi_buy(CuTest *tc) {
|
||||||
/* TODO: write more tests */
|
/* TODO: write more tests */
|
||||||
unit *u;
|
unit *u;
|
||||||
test_setup();
|
test_setup();
|
||||||
|
mt_create_error(52);
|
||||||
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
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));
|
||||||
unit_addorder(u, create_order(K_BUY, u->faction->locale, 0));
|
unit_addorder(u, create_order(K_BUY, u->faction->locale, 0));
|
||||||
update_long_order(u);
|
update_long_order(u);
|
||||||
CuAssertPtrEquals(tc, 0, u->thisorder);
|
CuAssertPtrEquals(tc, NULL, u->thisorder);
|
||||||
CuAssertPtrNotNull(tc, u->orders);
|
CuAssertPtrNotNull(tc, u->orders);
|
||||||
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error52"));
|
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error52"));
|
||||||
test_teardown();
|
test_teardown();
|
||||||
|
@ -1132,9 +1140,9 @@ static void test_long_order_multi_sell(CuTest *tc) {
|
||||||
unit_addorder(u, create_order(K_BUY, u->faction->locale, 0));
|
unit_addorder(u, create_order(K_BUY, u->faction->locale, 0));
|
||||||
unit_addorder(u, create_order(K_SELL, u->faction->locale, 0));
|
unit_addorder(u, create_order(K_SELL, u->faction->locale, 0));
|
||||||
update_long_order(u);
|
update_long_order(u);
|
||||||
CuAssertPtrEquals(tc, 0, u->thisorder);
|
CuAssertPtrEquals(tc, NULL, u->thisorder);
|
||||||
CuAssertPtrNotNull(tc, u->orders);
|
CuAssertPtrNotNull(tc, u->orders);
|
||||||
CuAssertPtrEquals(tc, 0, u->faction->msgs);
|
CuAssertPtrEquals(tc, NULL, u->faction->msgs);
|
||||||
test_teardown();
|
test_teardown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1142,11 +1150,12 @@ static void test_long_order_buy_cast(CuTest *tc) {
|
||||||
/* TODO: write more tests */
|
/* TODO: write more tests */
|
||||||
unit *u;
|
unit *u;
|
||||||
test_setup();
|
test_setup();
|
||||||
|
mt_create_error(52);
|
||||||
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
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));
|
||||||
unit_addorder(u, create_order(K_CAST, u->faction->locale, 0));
|
unit_addorder(u, create_order(K_CAST, u->faction->locale, 0));
|
||||||
update_long_order(u);
|
update_long_order(u);
|
||||||
CuAssertPtrEquals(tc, 0, u->thisorder);
|
CuAssertPtrEquals(tc, NULL, u->thisorder);
|
||||||
CuAssertPtrNotNull(tc, u->orders);
|
CuAssertPtrNotNull(tc, u->orders);
|
||||||
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error52"));
|
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error52"));
|
||||||
test_teardown();
|
test_teardown();
|
||||||
|
@ -1164,7 +1173,7 @@ static void test_long_order_hungry(CuTest *tc) {
|
||||||
update_long_order(u);
|
update_long_order(u);
|
||||||
CuAssertIntEquals(tc, K_WORK, getkeyword(u->thisorder));
|
CuAssertIntEquals(tc, K_WORK, getkeyword(u->thisorder));
|
||||||
CuAssertPtrNotNull(tc, u->orders);
|
CuAssertPtrNotNull(tc, u->orders);
|
||||||
CuAssertPtrEquals(tc, 0, u->faction->msgs);
|
CuAssertPtrEquals(tc, NULL, u->faction->msgs);
|
||||||
test_teardown();
|
test_teardown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1174,9 +1183,10 @@ static void test_ally_cmd_errors(CuTest *tc) {
|
||||||
order *ord;
|
order *ord;
|
||||||
|
|
||||||
test_setup();
|
test_setup();
|
||||||
|
mt_create_error(66);
|
||||||
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||||
fid = u->faction->no + 1;
|
fid = u->faction->no + 1;
|
||||||
CuAssertPtrEquals(tc, 0, findfaction(fid));
|
CuAssertPtrEquals(tc, NULL, findfaction(fid));
|
||||||
|
|
||||||
ord = create_order(K_ALLY, u->faction->locale, itoa36(fid));
|
ord = create_order(K_ALLY, u->faction->locale, itoa36(fid));
|
||||||
ally_cmd(u, ord);
|
ally_cmd(u, ord);
|
||||||
|
@ -1273,25 +1283,25 @@ static void test_ally_cmd(CuTest *tc) {
|
||||||
|
|
||||||
ord = create_order(K_ALLY, f->locale, "%s", itoa36(f->no));
|
ord = create_order(K_ALLY, f->locale, "%s", itoa36(f->no));
|
||||||
ally_cmd(u, ord);
|
ally_cmd(u, ord);
|
||||||
CuAssertPtrEquals(tc, 0, u->faction->msgs);
|
CuAssertPtrEquals(tc, NULL, u->faction->msgs);
|
||||||
CuAssertIntEquals(tc, HELP_ALL, alliedfaction(0, u->faction, f, HELP_ALL));
|
CuAssertIntEquals(tc, HELP_ALL, alliedfaction(0, u->faction, f, HELP_ALL));
|
||||||
free_order(ord);
|
free_order(ord);
|
||||||
|
|
||||||
ord = create_order(K_ALLY, f->locale, "%s %s", itoa36(f->no), LOC(f->locale, parameters[P_NOT]));
|
ord = create_order(K_ALLY, f->locale, "%s %s", itoa36(f->no), LOC(f->locale, parameters[P_NOT]));
|
||||||
ally_cmd(u, ord);
|
ally_cmd(u, ord);
|
||||||
CuAssertPtrEquals(tc, 0, u->faction->msgs);
|
CuAssertPtrEquals(tc, NULL, u->faction->msgs);
|
||||||
CuAssertIntEquals(tc, 0, alliedfaction(0, u->faction, f, HELP_ALL));
|
CuAssertIntEquals(tc, 0, alliedfaction(0, u->faction, f, HELP_ALL));
|
||||||
free_order(ord);
|
free_order(ord);
|
||||||
|
|
||||||
ord = create_order(K_ALLY, f->locale, "%s %s", itoa36(f->no), LOC(f->locale, parameters[P_GUARD]));
|
ord = create_order(K_ALLY, f->locale, "%s %s", itoa36(f->no), LOC(f->locale, parameters[P_GUARD]));
|
||||||
ally_cmd(u, ord);
|
ally_cmd(u, ord);
|
||||||
CuAssertPtrEquals(tc, 0, u->faction->msgs);
|
CuAssertPtrEquals(tc, NULL, u->faction->msgs);
|
||||||
CuAssertIntEquals(tc, HELP_GUARD, alliedfaction(0, u->faction, f, HELP_ALL));
|
CuAssertIntEquals(tc, HELP_GUARD, alliedfaction(0, u->faction, f, HELP_ALL));
|
||||||
free_order(ord);
|
free_order(ord);
|
||||||
|
|
||||||
ord = create_order(K_ALLY, f->locale, "%s %s %s", itoa36(f->no), LOC(f->locale, parameters[P_GUARD]), LOC(f->locale, parameters[P_NOT]));
|
ord = create_order(K_ALLY, f->locale, "%s %s %s", itoa36(f->no), LOC(f->locale, parameters[P_GUARD]), LOC(f->locale, parameters[P_NOT]));
|
||||||
ally_cmd(u, ord);
|
ally_cmd(u, ord);
|
||||||
CuAssertPtrEquals(tc, 0, u->faction->msgs);
|
CuAssertPtrEquals(tc, NULL, u->faction->msgs);
|
||||||
CuAssertIntEquals(tc, 0, alliedfaction(0, u->faction, f, HELP_ALL));
|
CuAssertIntEquals(tc, 0, alliedfaction(0, u->faction, f, HELP_ALL));
|
||||||
free_order(ord);
|
free_order(ord);
|
||||||
|
|
||||||
|
@ -1325,6 +1335,8 @@ static unit * setup_mail_cmd(void) {
|
||||||
faction *f;
|
faction *f;
|
||||||
|
|
||||||
test_setup();
|
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("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("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);
|
mt_create_va(mt_new("mail_result", NULL), "message:string", "unit:unit", MT_NEW_END);
|
||||||
|
@ -1383,7 +1395,7 @@ static void test_mail_unit_no_msg(CuTest *tc) {
|
||||||
f = u->faction;
|
f = u->faction;
|
||||||
ord = create_order(K_MAIL, f->locale, "%s %s", LOC(f->locale, parameters[P_UNIT]), itoa36(u->no));
|
ord = create_order(K_MAIL, f->locale, "%s %s", LOC(f->locale, parameters[P_UNIT]), itoa36(u->no));
|
||||||
mail_cmd(u, ord);
|
mail_cmd(u, ord);
|
||||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "unitmessage"));
|
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "unitmessage"));
|
||||||
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error30"));
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error30"));
|
||||||
free_order(ord);
|
free_order(ord);
|
||||||
test_teardown();
|
test_teardown();
|
||||||
|
@ -1398,7 +1410,7 @@ static void test_mail_faction_no_msg(CuTest *tc) {
|
||||||
f = u->faction;
|
f = u->faction;
|
||||||
ord = create_order(K_MAIL, f->locale, "%s %s", LOC(f->locale, parameters[P_FACTION]), itoa36(f->no));
|
ord = create_order(K_MAIL, f->locale, "%s %s", LOC(f->locale, parameters[P_FACTION]), itoa36(f->no));
|
||||||
mail_cmd(u, ord);
|
mail_cmd(u, ord);
|
||||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "regionmessage"));
|
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "regionmessage"));
|
||||||
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error30"));
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error30"));
|
||||||
free_order(ord);
|
free_order(ord);
|
||||||
test_teardown();
|
test_teardown();
|
||||||
|
@ -1413,7 +1425,7 @@ static void test_mail_faction_no_target(CuTest *tc) {
|
||||||
f = u->faction;
|
f = u->faction;
|
||||||
ord = create_order(K_MAIL, f->locale, "%s %s", LOC(f->locale, parameters[P_FACTION]), itoa36(f->no+1));
|
ord = create_order(K_MAIL, f->locale, "%s %s", LOC(f->locale, parameters[P_FACTION]), itoa36(f->no+1));
|
||||||
mail_cmd(u, ord);
|
mail_cmd(u, ord);
|
||||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "regionmessage"));
|
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "regionmessage"));
|
||||||
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error66"));
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error66"));
|
||||||
free_order(ord);
|
free_order(ord);
|
||||||
test_teardown();
|
test_teardown();
|
||||||
|
@ -1428,7 +1440,7 @@ static void test_mail_region_no_msg(CuTest *tc) {
|
||||||
f = u->faction;
|
f = u->faction;
|
||||||
ord = create_order(K_MAIL, f->locale, LOC(f->locale, parameters[P_REGION]));
|
ord = create_order(K_MAIL, f->locale, LOC(f->locale, parameters[P_REGION]));
|
||||||
mail_cmd(u, ord);
|
mail_cmd(u, ord);
|
||||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(u->region->msgs, "mail_result"));
|
CuAssertPtrEquals(tc, NULL, test_find_messagetype(u->region->msgs, "mail_result"));
|
||||||
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error30"));
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error30"));
|
||||||
free_order(ord);
|
free_order(ord);
|
||||||
test_teardown();
|
test_teardown();
|
||||||
|
@ -1444,6 +1456,8 @@ static void test_show_without_item(CuTest *tc)
|
||||||
struct locale *loc;
|
struct locale *loc;
|
||||||
|
|
||||||
test_setup();
|
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);
|
mt_create_va(mt_new("displayitem", NULL), "weight:int", "item:resource", "description:string", MT_NEW_END);
|
||||||
|
|
||||||
loc = get_or_create_locale("de");
|
loc = get_or_create_locale("de");
|
||||||
|
@ -1466,14 +1480,14 @@ static void test_show_without_item(CuTest *tc)
|
||||||
locale_setstring(loc, "iteminfo::testitem", "testdescription");
|
locale_setstring(loc, "iteminfo::testitem", "testdescription");
|
||||||
|
|
||||||
reshow_cmd(u, ord);
|
reshow_cmd(u, ord);
|
||||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error21"));
|
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error21"));
|
||||||
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error36"));
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error36"));
|
||||||
test_clear_messages(f);
|
test_clear_messages(f);
|
||||||
|
|
||||||
i_add(&(u->items), i_new(itype, 1));
|
i_add(&(u->items), i_new(itype, 1));
|
||||||
reshow_cmd(u, ord);
|
reshow_cmd(u, ord);
|
||||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error21"));
|
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error21"));
|
||||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error36"));
|
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error36"));
|
||||||
test_clear_messages(f);
|
test_clear_messages(f);
|
||||||
|
|
||||||
free_order(ord);
|
free_order(ord);
|
||||||
|
@ -1488,7 +1502,6 @@ static void test_show_race(CuTest *tc) {
|
||||||
message * msg;
|
message * msg;
|
||||||
|
|
||||||
test_setup();
|
test_setup();
|
||||||
|
|
||||||
mt_create_va(mt_new("msg_event", NULL), "string:string", MT_NEW_END);
|
mt_create_va(mt_new("msg_event", NULL), "string:string", MT_NEW_END);
|
||||||
test_create_race("human");
|
test_create_race("human");
|
||||||
rc = test_create_race("elf");
|
rc = test_create_race("elf");
|
||||||
|
@ -1504,8 +1517,8 @@ static void test_show_race(CuTest *tc) {
|
||||||
|
|
||||||
ord = create_order(K_RESHOW, loc, "Mensch");
|
ord = create_order(K_RESHOW, loc, "Mensch");
|
||||||
reshow_cmd(u, ord);
|
reshow_cmd(u, ord);
|
||||||
CuAssertTrue(tc, test_find_messagetype(u->faction->msgs, "error21") != NULL);
|
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error21"));
|
||||||
CuAssertTrue(tc, test_find_messagetype(u->faction->msgs, "msg_event") == NULL);
|
CuAssertPtrEquals(tc, NULL, test_find_messagetype(u->faction->msgs, "msg_event"));
|
||||||
test_clear_messages(u->faction);
|
test_clear_messages(u->faction);
|
||||||
free_order(ord);
|
free_order(ord);
|
||||||
|
|
||||||
|
@ -1618,7 +1631,7 @@ static void test_demon_hunger(CuTest * tc)
|
||||||
get_food(r);
|
get_food(r);
|
||||||
|
|
||||||
CuAssertIntEquals(tc, 20, i_get(u->items, rtype->itype));
|
CuAssertIntEquals(tc, 20, i_get(u->items, rtype->itype));
|
||||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "malnourish"));
|
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "malnourish"));
|
||||||
|
|
||||||
config_set("hunger.demon.peasant_tolerance", "0");
|
config_set("hunger.demon.peasant_tolerance", "0");
|
||||||
|
|
||||||
|
|
|
@ -555,7 +555,7 @@ static order *monster_learn(unit * u)
|
||||||
const struct locale *lang = u->faction->locale;
|
const struct locale *lang = u->faction->locale;
|
||||||
|
|
||||||
/* can these monsters even study? */
|
/* can these monsters even study? */
|
||||||
if (!unit_can_study(u)) {
|
if (!check_student(u, NULL, SK_PERCEPTION)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -828,7 +828,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
|
/* Einheiten, die Waffenlosen Kampf lernen k<>nnten, lernen es um
|
||||||
* zu bewachen: */
|
* zu bewachen: */
|
||||||
if (rc->bonus[SK_WEAPONLESS] != -99) {
|
if (rc->bonus[SK_WEAPONLESS] != -99) {
|
||||||
|
|
|
@ -30,6 +30,8 @@ static void setup_piracy(void) {
|
||||||
st_boat = test_create_shiptype("boat");
|
st_boat = test_create_shiptype("boat");
|
||||||
st_boat->cargo = 1000;
|
st_boat->cargo = 1000;
|
||||||
|
|
||||||
|
mt_create_error(144);
|
||||||
|
mt_create_error(146);
|
||||||
mt_create_va(mt_new("piratenovictim", NULL),
|
mt_create_va(mt_new("piratenovictim", NULL),
|
||||||
"ship:ship", "unit:unit", "region:region", MT_NEW_END);
|
"ship:ship", "unit:unit", "region:region", MT_NEW_END);
|
||||||
mt_create_va(mt_new("piratesawvictim", NULL),
|
mt_create_va(mt_new("piratesawvictim", NULL),
|
||||||
|
|
|
@ -14,12 +14,19 @@
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <CuTest.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) {
|
static void test_renumber_faction(CuTest *tc) {
|
||||||
unit *u;
|
unit *u;
|
||||||
int uno, no;
|
int uno, no;
|
||||||
const struct locale *lang;
|
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 = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||||
no = u->faction->no;
|
no = u->faction->no;
|
||||||
uno = (no > 1) ? no - 1 : no + 1;
|
uno = (no > 1) ? no - 1 : no + 1;
|
||||||
|
@ -37,7 +44,7 @@ static void test_renumber_faction_duplicate(CuTest *tc) {
|
||||||
int no;
|
int no;
|
||||||
const struct locale *lang;
|
const struct locale *lang;
|
||||||
|
|
||||||
test_setup_ex(tc);
|
setup_renumber(tc);
|
||||||
mt_create_va(mt_new("renumber_inuse", NULL), "id:int", MT_NEW_END);
|
mt_create_va(mt_new("renumber_inuse", NULL), "id:int", MT_NEW_END);
|
||||||
f2 = test_create_faction(NULL);
|
f2 = test_create_faction(NULL);
|
||||||
u = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL));
|
u = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||||
|
@ -57,7 +64,7 @@ static void test_renumber_faction_invalid(CuTest *tc) {
|
||||||
int no;
|
int no;
|
||||||
const struct locale *lang;
|
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));
|
u = test_create_unit(f = test_create_faction(0), test_create_region(0, 0, 0));
|
||||||
no = f->no;
|
no = f->no;
|
||||||
lang = f->locale;
|
lang = f->locale;
|
||||||
|
@ -87,7 +94,7 @@ static void test_renumber_building(CuTest *tc) {
|
||||||
int uno, no;
|
int uno, no;
|
||||||
const struct locale *lang;
|
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 = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||||
u->building = test_create_building(u->region, NULL);
|
u->building = test_create_building(u->region, NULL);
|
||||||
no = u->building->no;
|
no = u->building->no;
|
||||||
|
@ -105,7 +112,7 @@ static void test_renumber_building_duplicate(CuTest *tc) {
|
||||||
int uno, no;
|
int uno, no;
|
||||||
const struct locale *lang;
|
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 = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||||
u->building = test_create_building(u->region, NULL);
|
u->building = test_create_building(u->region, NULL);
|
||||||
uno = u->building->no;
|
uno = u->building->no;
|
||||||
|
@ -124,7 +131,7 @@ static void test_renumber_ship(CuTest *tc) {
|
||||||
int uno, no;
|
int uno, no;
|
||||||
const struct locale *lang;
|
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 = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||||
u->ship = test_create_ship(u->region, NULL);
|
u->ship = test_create_ship(u->region, NULL);
|
||||||
no = u->ship->no;
|
no = u->ship->no;
|
||||||
|
@ -141,7 +148,7 @@ static void test_renumber_ship_twice(CuTest *tc) {
|
||||||
int uno, no;
|
int uno, no;
|
||||||
const struct locale *lang;
|
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 = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||||
u->ship = test_create_ship(u->region, NULL);
|
u->ship = test_create_ship(u->region, NULL);
|
||||||
no = u->ship->no;
|
no = u->ship->no;
|
||||||
|
@ -163,7 +170,7 @@ static void test_renumber_ship_duplicate(CuTest *tc) {
|
||||||
int uno, no;
|
int uno, no;
|
||||||
const struct locale *lang;
|
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 = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||||
u->ship = test_create_ship(u->region, NULL);
|
u->ship = test_create_ship(u->region, NULL);
|
||||||
uno = u->ship->no;
|
uno = u->ship->no;
|
||||||
|
@ -182,7 +189,7 @@ static void test_renumber_unit(CuTest *tc) {
|
||||||
int uno, no;
|
int uno, no;
|
||||||
const struct locale *lang;
|
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 = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||||
no = u->no;
|
no = u->no;
|
||||||
uno = (no > 1) ? no - 1 : no + 1;
|
uno = (no > 1) ? no - 1 : no + 1;
|
||||||
|
@ -200,7 +207,7 @@ static void test_renumber_unit_duplicate(CuTest *tc) {
|
||||||
int no;
|
int no;
|
||||||
const struct locale *lang;
|
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 = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||||
no = u->no;
|
no = u->no;
|
||||||
u2 = test_create_unit(f, u->region);
|
u2 = test_create_unit(f, u->region);
|
||||||
|
@ -219,7 +226,7 @@ static void test_renumber_unit_limit(CuTest *tc) {
|
||||||
int no;
|
int no;
|
||||||
const struct locale *lang;
|
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 = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||||
no = u->no;
|
no = u->no;
|
||||||
lang = f->locale;
|
lang = f->locale;
|
||||||
|
@ -237,7 +244,7 @@ static void test_renumber_unit_invalid(CuTest *tc) {
|
||||||
int no;
|
int no;
|
||||||
const struct locale *lang;
|
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 = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||||
no = u->no;
|
no = u->no;
|
||||||
lang = f->locale;
|
lang = f->locale;
|
||||||
|
|
|
@ -791,7 +791,6 @@ static void test_insect_warnings(CuTest *tc) {
|
||||||
|
|
||||||
test_setup();
|
test_setup();
|
||||||
test_create_calendar();
|
test_create_calendar();
|
||||||
test_inject_messagetypes();
|
|
||||||
f = test_create_faction(test_create_race("insect"));
|
f = test_create_faction(test_create_race("insect"));
|
||||||
|
|
||||||
CuAssertIntEquals(tc, SEASON_AUTUMN, get_gamedate(1083, &gd)->season);
|
CuAssertIntEquals(tc, SEASON_AUTUMN, get_gamedate(1083, &gd)->season);
|
||||||
|
@ -819,7 +818,6 @@ static void test_newbie_warning(CuTest *tc) {
|
||||||
faction *f;
|
faction *f;
|
||||||
|
|
||||||
test_setup();
|
test_setup();
|
||||||
test_inject_messagetypes();
|
|
||||||
f = test_create_faction(NULL);
|
f = test_create_faction(NULL);
|
||||||
config_set_int("NewbieImmunity", 3);
|
config_set_int("NewbieImmunity", 3);
|
||||||
|
|
||||||
|
|
|
@ -116,7 +116,9 @@ skill_t get_skill(const char *s, const struct locale * lang)
|
||||||
int skill_cost(skill_t sk) {
|
int skill_cost(skill_t sk) {
|
||||||
static int config;
|
static int config;
|
||||||
static int costs[MAXSKILLS];
|
static int costs[MAXSKILLS];
|
||||||
int cost;
|
int cost = -1;
|
||||||
|
|
||||||
|
assert(sk >= 0 && sk < MAXSKILLS);
|
||||||
switch (sk) {
|
switch (sk) {
|
||||||
case SK_SPY:
|
case SK_SPY:
|
||||||
cost = 100;
|
cost = 100;
|
||||||
|
@ -146,5 +148,6 @@ int skill_cost(skill_t sk) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool expensive_skill(skill_t sk) {
|
bool expensive_skill(skill_t sk) {
|
||||||
|
assert(sk >= 0 && sk < MAXSKILLS);
|
||||||
return (sk == SK_MAGIC) || skill_cost(sk) > 0;
|
return (sk == SK_MAGIC) || skill_cost(sk) > 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,10 +27,6 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
static void setup_spells(void) {
|
|
||||||
test_inject_messagetypes();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void test_good_dreams(CuTest *tc) {
|
static void test_good_dreams(CuTest *tc) {
|
||||||
struct region *r;
|
struct region *r;
|
||||||
struct faction *f1, *f2;
|
struct faction *f1, *f2;
|
||||||
|
@ -40,7 +36,6 @@ static void test_good_dreams(CuTest *tc) {
|
||||||
curse *curse;
|
curse *curse;
|
||||||
|
|
||||||
test_setup();
|
test_setup();
|
||||||
setup_spells();
|
|
||||||
test_create_world();
|
test_create_world();
|
||||||
r = findregion(0, 0);
|
r = findregion(0, 0);
|
||||||
f1 = test_create_faction(NULL);
|
f1 = test_create_faction(NULL);
|
||||||
|
@ -70,7 +65,6 @@ static void test_dreams(CuTest *tc) {
|
||||||
castorder co;
|
castorder co;
|
||||||
|
|
||||||
test_setup();
|
test_setup();
|
||||||
setup_spells();
|
|
||||||
r = test_create_region(0, 0, NULL);
|
r = test_create_region(0, 0, NULL);
|
||||||
f1 = test_create_faction(NULL);
|
f1 = test_create_faction(NULL);
|
||||||
f2 = test_create_faction(NULL);
|
f2 = test_create_faction(NULL);
|
||||||
|
@ -98,7 +92,6 @@ static void test_bad_dreams(CuTest *tc) {
|
||||||
curse *curse;
|
curse *curse;
|
||||||
|
|
||||||
test_setup();
|
test_setup();
|
||||||
setup_spells();
|
|
||||||
test_create_world();
|
test_create_world();
|
||||||
r = findregion(0, 0);
|
r = findregion(0, 0);
|
||||||
f1 = test_create_faction(NULL);
|
f1 = test_create_faction(NULL);
|
||||||
|
@ -129,7 +122,6 @@ static void test_view_reality(CuTest *tc) {
|
||||||
castorder co;
|
castorder co;
|
||||||
|
|
||||||
test_setup();
|
test_setup();
|
||||||
setup_spells();
|
|
||||||
mt_create_va(mt_new("spell_astral_only", NULL),
|
mt_create_va(mt_new("spell_astral_only", NULL),
|
||||||
"unit:unit", "region:region", "command:order", MT_NEW_END);
|
"unit:unit", "region:region", "command:order", MT_NEW_END);
|
||||||
mt_create_va(mt_new("viewreality_effect", NULL),
|
mt_create_va(mt_new("viewreality_effect", NULL),
|
||||||
|
@ -165,7 +157,6 @@ static void test_watch_region(CuTest *tc) {
|
||||||
region *r;
|
region *r;
|
||||||
faction *f;
|
faction *f;
|
||||||
test_setup();
|
test_setup();
|
||||||
setup_spells();
|
|
||||||
r = test_create_region(0, 0, NULL);
|
r = test_create_region(0, 0, NULL);
|
||||||
f = test_create_faction(NULL);
|
f = test_create_faction(NULL);
|
||||||
CuAssertIntEquals(tc, -1, get_observer(r, f));
|
CuAssertIntEquals(tc, -1, get_observer(r, f));
|
||||||
|
|
65
src/study.c
65
src/study.c
|
@ -523,6 +523,48 @@ static void msg_teachers(struct selist *teachers, struct unit *u, skill_t sk) {
|
||||||
selist_foreach_ex(teachers, cb_msg_teach, &cbdata);
|
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)
|
int study_cmd(unit * u, order * ord)
|
||||||
{
|
{
|
||||||
region *r = u->region;
|
region *r = u->region;
|
||||||
|
@ -536,7 +578,6 @@ int study_cmd(unit * u, order * ord)
|
||||||
skill_t sk;
|
skill_t sk;
|
||||||
int maxalchemy = 0;
|
int maxalchemy = 0;
|
||||||
int speed_rule = (study_rule_t)config_get_int("study.speedup", 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 const race *rc_snotling;
|
||||||
static int rc_cache;
|
static int rc_cache;
|
||||||
|
|
||||||
|
@ -544,32 +585,12 @@ int study_cmd(unit * u, order * ord)
|
||||||
rc_snotling = get_race(RC_SNOTLING);
|
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);
|
(void)init_order(ord, u->faction->locale);
|
||||||
sk = getskill(u->faction->locale);
|
sk = getskill(u->faction->locale);
|
||||||
|
|
||||||
if (sk < 0) {
|
if (!check_student(u, ord, sk)) {
|
||||||
cmistake(u, ord, 77, MSG_EVENT);
|
|
||||||
return -1;
|
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 */
|
/* snotlings koennen Talente nur bis T8 lernen */
|
||||||
if (u_race(u) == rc_snotling) {
|
if (u_race(u) == rc_snotling) {
|
||||||
|
|
|
@ -47,6 +47,7 @@ extern "C" {
|
||||||
skill_t getskill(const struct locale *lang);
|
skill_t getskill(const struct locale *lang);
|
||||||
bool is_migrant(struct unit *u);
|
bool is_migrant(struct unit *u);
|
||||||
int study_cost(struct unit *u, skill_t sk);
|
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);
|
typedef void(*learn_fun)(struct unit *u, skill_t sk, int days);
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,11 @@ typedef struct {
|
||||||
} study_fixture;
|
} study_fixture;
|
||||||
|
|
||||||
static void setup_study(void) {
|
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),
|
mt_create_va(mt_new("studycost", NULL),
|
||||||
"unit:unit", "region:region", "cost:int", "skill:int", MT_NEW_END);
|
"unit:unit", "region:region", "cost:int", "skill:int", MT_NEW_END);
|
||||||
mt_create_va(mt_new("teach_teacher", NULL),
|
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;
|
struct locale *lang;
|
||||||
|
|
||||||
assert(fix);
|
assert(fix);
|
||||||
test_setup();
|
setup_study();
|
||||||
config_set("study.random_progress", "0");
|
config_set("study.random_progress", "0");
|
||||||
r = test_create_region(0, 0, NULL);
|
r = test_create_region(0, 0, NULL);
|
||||||
f = test_create_faction(NULL);
|
f = test_create_faction(NULL);
|
||||||
|
@ -148,7 +153,7 @@ static void test_study_bug_2194(CuTest *tc) {
|
||||||
struct locale * loc;
|
struct locale * loc;
|
||||||
building * b;
|
building * b;
|
||||||
|
|
||||||
test_setup();
|
setup_study();
|
||||||
random_source_inject_constant(0.0);
|
random_source_inject_constant(0.0);
|
||||||
init_resources();
|
init_resources();
|
||||||
loc = test_create_locale();
|
loc = test_create_locale();
|
||||||
|
@ -205,7 +210,7 @@ static void test_produceexp(CuTest *tc) {
|
||||||
unit *u;
|
unit *u;
|
||||||
|
|
||||||
g_tc = tc;
|
g_tc = tc;
|
||||||
test_setup();
|
setup_study();
|
||||||
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||||
scale_number(u, 2);
|
scale_number(u, 2);
|
||||||
config_set("study.produceexp", "20");
|
config_set("study.produceexp", "20");
|
||||||
|
@ -220,7 +225,7 @@ static void test_academy_building(CuTest *tc) {
|
||||||
building * b;
|
building * b;
|
||||||
message * msg;
|
message * msg;
|
||||||
|
|
||||||
test_setup();
|
setup_study();
|
||||||
mt_create_va(mt_new("teach_asgood", NULL),
|
mt_create_va(mt_new("teach_asgood", NULL),
|
||||||
"unit:unit", "region:region", "command:order", "student:unit", MT_NEW_END);
|
"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;
|
struct locale * loc;
|
||||||
building * b;
|
building * b;
|
||||||
|
|
||||||
test_setup();
|
|
||||||
setup_study();
|
setup_study();
|
||||||
|
|
||||||
random_source_inject_constant(0.0);
|
random_source_inject_constant(0.0);
|
||||||
|
@ -328,7 +332,8 @@ static void test_academy_bonus(CuTest *tc) {
|
||||||
void test_learn_skill_single(CuTest *tc) {
|
void test_learn_skill_single(CuTest *tc) {
|
||||||
unit *u;
|
unit *u;
|
||||||
skill *sv;
|
skill *sv;
|
||||||
test_setup();
|
|
||||||
|
setup_study();
|
||||||
config_set("study.random_progress", "0");
|
config_set("study.random_progress", "0");
|
||||||
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||||
learn_skill(u, SK_ALCHEMY, STUDYDAYS);
|
learn_skill(u, SK_ALCHEMY, STUDYDAYS);
|
||||||
|
@ -347,7 +352,8 @@ void test_learn_skill_single(CuTest *tc) {
|
||||||
void test_learn_skill_multi(CuTest *tc) {
|
void test_learn_skill_multi(CuTest *tc) {
|
||||||
unit *u;
|
unit *u;
|
||||||
skill *sv;
|
skill *sv;
|
||||||
test_setup();
|
|
||||||
|
setup_study();
|
||||||
config_set("study.random_progress", "0");
|
config_set("study.random_progress", "0");
|
||||||
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||||
scale_number(u, 10);
|
scale_number(u, 10);
|
||||||
|
@ -367,7 +373,8 @@ void test_learn_skill_multi(CuTest *tc) {
|
||||||
static void test_demon_skillchanges(CuTest *tc) {
|
static void test_demon_skillchanges(CuTest *tc) {
|
||||||
unit * u;
|
unit * u;
|
||||||
const race * rc;
|
const race * rc;
|
||||||
test_setup();
|
|
||||||
|
setup_study();
|
||||||
rc = test_create_race("demon");
|
rc = test_create_race("demon");
|
||||||
CuAssertPtrEquals(tc, (void *)rc, (void *)get_race(RC_DAEMON));
|
CuAssertPtrEquals(tc, (void *)rc, (void *)get_race(RC_DAEMON));
|
||||||
u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, NULL));
|
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) {
|
static void test_study_cmd(CuTest *tc) {
|
||||||
unit *u;
|
unit *u;
|
||||||
test_setup();
|
|
||||||
|
setup_study();
|
||||||
init_resources();
|
init_resources();
|
||||||
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||||
u->thisorder = create_order(K_STUDY, u->faction->locale, "CROSSBOW");
|
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 locale *lang;
|
||||||
const struct item_type *itype;
|
const struct item_type *itype;
|
||||||
|
|
||||||
test_setup();
|
|
||||||
setup_study();
|
setup_study();
|
||||||
init_resources();
|
init_resources();
|
||||||
f = test_create_faction(NULL);
|
f = test_create_faction(NULL);
|
||||||
|
@ -432,7 +439,6 @@ static void test_study_magic(CuTest *tc) {
|
||||||
static void test_study_cost_magic(CuTest *tc) {
|
static void test_study_cost_magic(CuTest *tc) {
|
||||||
unit * u;
|
unit * u;
|
||||||
|
|
||||||
test_setup();
|
|
||||||
setup_study();
|
setup_study();
|
||||||
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
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;
|
unit *u;
|
||||||
const struct item_type *itype;
|
const struct item_type *itype;
|
||||||
|
|
||||||
test_setup();
|
|
||||||
setup_study();
|
setup_study();
|
||||||
|
|
||||||
itype = test_create_silver();
|
itype = test_create_silver();
|
||||||
|
@ -484,7 +489,6 @@ static void test_teach_magic(CuTest *tc) {
|
||||||
faction *f;
|
faction *f;
|
||||||
const struct item_type *itype;
|
const struct item_type *itype;
|
||||||
|
|
||||||
test_setup();
|
|
||||||
setup_study();
|
setup_study();
|
||||||
init_resources();
|
init_resources();
|
||||||
itype = get_resourcetype(R_SILVER)->itype;
|
itype = get_resourcetype(R_SILVER)->itype;
|
||||||
|
@ -510,7 +514,8 @@ static void test_teach_magic(CuTest *tc) {
|
||||||
|
|
||||||
static void test_teach_cmd(CuTest *tc) {
|
static void test_teach_cmd(CuTest *tc) {
|
||||||
unit *u, *ut;
|
unit *u, *ut;
|
||||||
test_setup();
|
|
||||||
|
setup_study();
|
||||||
init_resources();
|
init_resources();
|
||||||
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||||
scale_number(u, 10);
|
scale_number(u, 10);
|
||||||
|
@ -530,7 +535,8 @@ static void test_teach_cmd(CuTest *tc) {
|
||||||
|
|
||||||
static void test_teach_two(CuTest *tc) {
|
static void test_teach_two(CuTest *tc) {
|
||||||
unit *u1, *u2, *ut;
|
unit *u1, *u2, *ut;
|
||||||
test_setup();
|
|
||||||
|
setup_study();
|
||||||
init_resources();
|
init_resources();
|
||||||
u1 = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
u1 = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||||
scale_number(u1, 5);
|
scale_number(u1, 5);
|
||||||
|
@ -560,7 +566,7 @@ static void test_teach_two_skills(CuTest *tc) {
|
||||||
faction *f;
|
faction *f;
|
||||||
region *r;
|
region *r;
|
||||||
|
|
||||||
test_setup();
|
setup_study();
|
||||||
init_resources();
|
init_resources();
|
||||||
f = test_create_faction(NULL);
|
f = test_create_faction(NULL);
|
||||||
r = test_create_region(0, 0, 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) {
|
static void test_teach_one_to_many(CuTest *tc) {
|
||||||
unit *u, *ut;
|
unit *u, *ut;
|
||||||
test_setup();
|
|
||||||
|
setup_study();
|
||||||
init_resources();
|
init_resources();
|
||||||
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||||
scale_number(u, 20);
|
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) {
|
static void test_teach_many_to_one(CuTest *tc) {
|
||||||
unit *u, *u1, *u2;
|
unit *u, *u1, *u2;
|
||||||
|
|
||||||
test_setup();
|
setup_study();
|
||||||
init_resources();
|
init_resources();
|
||||||
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||||
scale_number(u, 20);
|
scale_number(u, 20);
|
||||||
|
@ -639,11 +646,7 @@ static void test_teach_message(CuTest *tc) {
|
||||||
ally *al;
|
ally *al;
|
||||||
teaching_info *teach;
|
teaching_info *teach;
|
||||||
|
|
||||||
test_setup();
|
setup_study();
|
||||||
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);
|
|
||||||
init_resources();
|
init_resources();
|
||||||
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||||
scale_number(u, 20);
|
scale_number(u, 20);
|
||||||
|
@ -683,7 +686,7 @@ static void test_teach_many_to_many(CuTest *tc) {
|
||||||
region *r;
|
region *r;
|
||||||
faction *f;
|
faction *f;
|
||||||
|
|
||||||
test_setup();
|
setup_study();
|
||||||
init_resources();
|
init_resources();
|
||||||
f = test_create_faction(NULL);
|
f = test_create_faction(NULL);
|
||||||
r = test_create_region(0, 0, NULL);
|
r = test_create_region(0, 0, NULL);
|
||||||
|
|
|
@ -277,15 +277,10 @@ void test_create_calendar(void) {
|
||||||
month_season[8] = SEASON_SUMMER;
|
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) {
|
void test_setup_test(CuTest *tc, const char *file, int line) {
|
||||||
test_log_stderr(LOG_CPERROR);
|
test_log_stderr(LOG_CPERROR);
|
||||||
test_reset();
|
test_reset();
|
||||||
message_handle_missing(MESSAGE_MISSING_ERROR);
|
message_handle_missing(MESSAGE_MISSING_REPLACE);
|
||||||
if (tc) {
|
if (tc) {
|
||||||
log_debug("start test: %s", tc->name);
|
log_debug("start test: %s", tc->name);
|
||||||
}
|
}
|
||||||
|
@ -297,6 +292,7 @@ void test_setup_test(CuTest *tc, const char *file, int line) {
|
||||||
|
|
||||||
void test_teardown(void)
|
void test_teardown(void)
|
||||||
{
|
{
|
||||||
|
message_handle_missing(MESSAGE_MISSING_IGNORE);
|
||||||
test_reset();
|
test_reset();
|
||||||
test_log_stderr(0);
|
test_log_stderr(0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,6 @@ extern "C" {
|
||||||
void assert_string_parameter(struct CuTest * tc, struct message *msg, int index, const char *arg);
|
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 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)
|
#define DISABLE_TEST(SUITE, TEST) disabled_test(SUITE, TEST, #TEST)
|
||||||
|
|
||||||
|
|
|
@ -198,6 +198,16 @@ message_type *mt_create_va(message_type *mtype, ...)
|
||||||
return mt_create(mtype, args, i - 1);
|
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)
|
static variant copy_arg(const arg_type * atype, variant data)
|
||||||
{
|
{
|
||||||
assert(atype != NULL);
|
assert(atype != NULL);
|
||||||
|
|
|
@ -64,6 +64,8 @@ extern "C" {
|
||||||
struct message_type *mt_new(const char *name, const char *section);
|
struct message_type *mt_new(const char *name, const char *section);
|
||||||
/** message_type registry (optional): **/
|
/** message_type registry (optional): **/
|
||||||
struct message_type *mt_create(struct message_type *, const char *args[], int nargs);
|
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 *, ...);
|
struct message_type *mt_create_va(struct message_type *, ...);
|
||||||
const struct message_type *mt_find(const char *);
|
const struct message_type *mt_find(const char *);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue