forked from github/server
Merge branch 'develop' of github.com:ennorehling/eressea into develop
This commit is contained in:
commit
cf666f53a2
|
@ -474,9 +474,6 @@ static int tolua_region_create(lua_State * L)
|
||||||
}
|
}
|
||||||
if (result) {
|
if (result) {
|
||||||
terraform_region(result, terrain);
|
terraform_region(result, terrain);
|
||||||
if (result->land) {
|
|
||||||
fix_demand(result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tolua_pushusertype(L, result, TOLUA_CAST "region");
|
tolua_pushusertype(L, result, TOLUA_CAST "region");
|
||||||
|
|
|
@ -20,7 +20,7 @@ order.test.c
|
||||||
plane.test.c
|
plane.test.c
|
||||||
pool.test.c
|
pool.test.c
|
||||||
race.test.c
|
race.test.c
|
||||||
# region.test.c
|
region.test.c
|
||||||
# resources.test.c
|
# resources.test.c
|
||||||
save.test.c
|
save.test.c
|
||||||
ship.test.c
|
ship.test.c
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <kernel/save.h>
|
#include <kernel/save.h>
|
||||||
#include <kernel/unit.h>
|
#include <kernel/unit.h>
|
||||||
#include <util/attrib.h>
|
#include <util/attrib.h>
|
||||||
|
#include <util/rng.h>
|
||||||
#include <util/gamedata.h>
|
#include <util/gamedata.h>
|
||||||
#include <util/message.h>
|
#include <util/message.h>
|
||||||
#include <binarystore.h>
|
#include <binarystore.h>
|
||||||
|
@ -175,6 +176,43 @@ static void test_curse_cache(CuTest *tc)
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_curse_ids(CuTest *tc) {
|
||||||
|
const curse_type ct_dummy = { "dummy", CURSETYP_NORM, 0, M_SUMEFFECT, NULL };
|
||||||
|
curse *c1, *c2;
|
||||||
|
attrib *a1 = 0, *a2 = 0;
|
||||||
|
|
||||||
|
test_setup();
|
||||||
|
rng_init(0);
|
||||||
|
c1 = create_curse(NULL, &a1, &ct_dummy, 1, 1, 1, 1);
|
||||||
|
rng_init(0);
|
||||||
|
c2 = create_curse(NULL, &a2, &ct_dummy, 1, 1, 1, 1);
|
||||||
|
CuAssertTrue(tc, c1->no != c2->no);
|
||||||
|
a_remove(&a1, a1);
|
||||||
|
a_remove(&a2, a2);
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_curse_flags(CuTest *tc) {
|
||||||
|
const curse_type ct_dummy = { "dummy", CURSETYP_NORM, 0, M_SUMEFFECT, NULL };
|
||||||
|
curse *c1, *c2;
|
||||||
|
unit *u;
|
||||||
|
|
||||||
|
test_setup();
|
||||||
|
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
||||||
|
c1 = create_curse(u, &u->attribs, &ct_dummy, 1, 1, 1, 0);
|
||||||
|
CuAssertPtrEquals(tc, u, c1->magician);
|
||||||
|
CuAssertIntEquals(tc, 1, (int)c1->effect);
|
||||||
|
CuAssertIntEquals(tc, 1, (int)c1->vigour);
|
||||||
|
CuAssertIntEquals(tc, 1, c1->duration);
|
||||||
|
c2 = create_curse(u, &u->attribs, &ct_dummy, 1, 1, 1, 0);
|
||||||
|
CuAssertPtrEquals(tc, c1, c2);
|
||||||
|
CuAssertPtrEquals(tc, u, c1->magician);
|
||||||
|
CuAssertIntEquals(tc, 2, (int)c1->effect);
|
||||||
|
CuAssertIntEquals(tc, 1, (int)c1->vigour);
|
||||||
|
CuAssertIntEquals(tc, 1, c1->duration);
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
CuSuite *get_curse_suite(void)
|
CuSuite *get_curse_suite(void)
|
||||||
{
|
{
|
||||||
CuSuite *suite = CuSuiteNew();
|
CuSuite *suite = CuSuiteNew();
|
||||||
|
@ -186,5 +224,7 @@ CuSuite *get_curse_suite(void)
|
||||||
SUITE_ADD_TEST(suite, test_bad_dreams);
|
SUITE_ADD_TEST(suite, test_bad_dreams);
|
||||||
SUITE_ADD_TEST(suite, test_memstream);
|
SUITE_ADD_TEST(suite, test_memstream);
|
||||||
SUITE_ADD_TEST(suite, test_write_flag);
|
SUITE_ADD_TEST(suite, test_write_flag);
|
||||||
|
SUITE_ADD_TEST(suite, test_curse_flags);
|
||||||
|
SUITE_ADD_TEST(suite, test_curse_ids);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1009,6 +1009,20 @@ void setluxuries(region * r, const luxury_type * sale)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int fix_demand(region * rd) {
|
||||||
|
luxury_type * ltype;
|
||||||
|
int maxluxuries = get_maxluxuries();
|
||||||
|
if (maxluxuries > 0) {
|
||||||
|
int sale = rng_int() % maxluxuries;
|
||||||
|
for (ltype = luxurytypes; sale != 0 && ltype; ltype = ltype->next) {
|
||||||
|
--sale;
|
||||||
|
}
|
||||||
|
setluxuries(rd, ltype);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
void terraform_region(region * r, const terrain_type * terrain)
|
void terraform_region(region * r, const terrain_type * terrain)
|
||||||
{
|
{
|
||||||
/* Resourcen, die nicht mehr vorkommen können, löschen */
|
/* Resourcen, die nicht mehr vorkommen können, löschen */
|
||||||
|
@ -1057,7 +1071,6 @@ void terraform_region(region * r, const terrain_type * terrain)
|
||||||
rsetmoney(r, 0);
|
rsetmoney(r, 0);
|
||||||
freset(r, RF_ENCOUNTER);
|
freset(r, RF_ENCOUNTER);
|
||||||
freset(r, RF_MALLORN);
|
freset(r, RF_MALLORN);
|
||||||
/* Beschreibung und Namen löschen */
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1082,6 +1095,7 @@ void terraform_region(region * r, const terrain_type * terrain)
|
||||||
r->land->ownership = NULL;
|
r->land->ownership = NULL;
|
||||||
region_set_morale(r, MORALE_DEFAULT, -1);
|
region_set_morale(r, MORALE_DEFAULT, -1);
|
||||||
region_setname(r, makename());
|
region_setname(r, makename());
|
||||||
|
fix_demand(r);
|
||||||
for (d = 0; d != MAXDIRECTIONS; ++d) {
|
for (d = 0; d != MAXDIRECTIONS; ++d) {
|
||||||
region *nr = rconnect(r, d);
|
region *nr = rconnect(r, d);
|
||||||
if (nr && nr->land) {
|
if (nr && nr->land) {
|
||||||
|
|
|
@ -160,6 +160,7 @@ extern "C" {
|
||||||
|
|
||||||
#define reg_hashkey(r) (r->index)
|
#define reg_hashkey(r) (r->index)
|
||||||
|
|
||||||
|
extern int fix_demand(struct region *r);
|
||||||
int distance(const struct region *, const struct region *);
|
int distance(const struct region *, const struct region *);
|
||||||
int koor_distance(int ax, int ay, int bx, int by);
|
int koor_distance(int ax, int ay, int bx, int by);
|
||||||
struct region *findregion(int x, int y);
|
struct region *findregion(int x, int y);
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
#include <platform.h>
|
||||||
|
|
||||||
|
#include "region.h"
|
||||||
|
#include "terrain.h"
|
||||||
|
#include "item.h"
|
||||||
|
|
||||||
|
#include <CuTest.h>
|
||||||
|
#include <tests.h>
|
||||||
|
|
||||||
|
void test_terraform(CuTest *tc) {
|
||||||
|
region *r;
|
||||||
|
terrain_type *t_plain, *t_ocean;
|
||||||
|
item_type *itype;
|
||||||
|
|
||||||
|
test_setup();
|
||||||
|
itype = test_create_itemtype("ointment");
|
||||||
|
itype->rtype->flags |= (RTF_ITEM | RTF_POOLED);
|
||||||
|
new_luxurytype(itype, 0);
|
||||||
|
|
||||||
|
t_plain = test_create_terrain("plain", LAND_REGION);
|
||||||
|
t_ocean = test_create_terrain("ocean", SEA_REGION);
|
||||||
|
r = test_create_region(0, 0, t_ocean);
|
||||||
|
CuAssertPtrEquals(tc, 0, r->land);
|
||||||
|
terraform_region(r, t_plain);
|
||||||
|
CuAssertPtrNotNull(tc, r->land);
|
||||||
|
CuAssertPtrNotNull(tc, r->land->demands);
|
||||||
|
CuAssertPtrEquals(tc, itype, (void *)r->land->demands->type->itype);
|
||||||
|
CuAssertIntEquals(tc, 0, r->land->demands->type->price);
|
||||||
|
terraform_region(r, t_ocean);
|
||||||
|
CuAssertPtrEquals(tc, 0, r->land);
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
CuSuite *get_region_suite(void)
|
||||||
|
{
|
||||||
|
CuSuite *suite = CuSuiteNew();
|
||||||
|
SUITE_ADD_TEST(suite, test_terraform);
|
||||||
|
return suite;
|
||||||
|
}
|
|
@ -1096,6 +1096,9 @@ static region *readregion(struct gamedata *data, int x, int y)
|
||||||
READ_INT(data->store, &n);
|
READ_INT(data->store, &n);
|
||||||
r_setdemand(r, rtype->ltype, n);
|
r_setdemand(r, rtype->ltype, n);
|
||||||
}
|
}
|
||||||
|
if (!r->land->demands) {
|
||||||
|
fix_demand(r);
|
||||||
|
}
|
||||||
read_items(data->store, &r->land->items);
|
read_items(data->store, &r->land->items);
|
||||||
if (data->version >= REGIONOWNER_VERSION) {
|
if (data->version >= REGIONOWNER_VERSION) {
|
||||||
READ_INT(data->store, &n);
|
READ_INT(data->store, &n);
|
||||||
|
|
|
@ -1717,7 +1717,7 @@ void renumber_unit(unit *u, int no) {
|
||||||
uunhash(u);
|
uunhash(u);
|
||||||
if (!ualias(u)) {
|
if (!ualias(u)) {
|
||||||
attrib *a = a_add(&u->attribs, a_new(&at_alias));
|
attrib *a = a_add(&u->attribs, a_new(&at_alias));
|
||||||
a->data.i = -u->no;
|
a->data.i = -u->no; // TODO: why is the alias negative? confusing!
|
||||||
}
|
}
|
||||||
u->no = no;
|
u->no = no;
|
||||||
uhash(u);
|
uhash(u);
|
||||||
|
|
|
@ -8,9 +8,10 @@
|
||||||
#include <kernel/race.h>
|
#include <kernel/race.h>
|
||||||
#include <kernel/region.h>
|
#include <kernel/region.h>
|
||||||
#include <kernel/spell.h>
|
#include <kernel/spell.h>
|
||||||
|
#include <util/attrib.h>
|
||||||
#include <util/base36.h>
|
#include <util/base36.h>
|
||||||
#include <util/language.h>
|
#include <util/language.h>
|
||||||
#include <util/attrib.h>
|
#include <util/rng.h>
|
||||||
#include <spells/regioncurse.h>
|
#include <spells/regioncurse.h>
|
||||||
#include <alchemy.h>
|
#include <alchemy.h>
|
||||||
#include <laws.h>
|
#include <laws.h>
|
||||||
|
@ -454,6 +455,19 @@ static void test_remove_unit(CuTest *tc) {
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_renumber_unit(CuTest *tc) {
|
||||||
|
unit *u1, *u2;
|
||||||
|
test_setup();
|
||||||
|
u1 = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
||||||
|
u2 = test_create_unit(u1->faction, u1->region);
|
||||||
|
rng_init(0);
|
||||||
|
renumber_unit(u1, 0);
|
||||||
|
rng_init(0);
|
||||||
|
renumber_unit(u2, 0);
|
||||||
|
CuAssertTrue(tc, u1->no != u2->no);
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
CuSuite *get_unit_suite(void)
|
CuSuite *get_unit_suite(void)
|
||||||
{
|
{
|
||||||
CuSuite *suite = CuSuiteNew();
|
CuSuite *suite = CuSuiteNew();
|
||||||
|
@ -476,5 +490,6 @@ CuSuite *get_unit_suite(void)
|
||||||
SUITE_ADD_TEST(suite, test_age_familiar);
|
SUITE_ADD_TEST(suite, test_age_familiar);
|
||||||
SUITE_ADD_TEST(suite, test_inside_building);
|
SUITE_ADD_TEST(suite, test_inside_building);
|
||||||
SUITE_ADD_TEST(suite, test_limited_skills);
|
SUITE_ADD_TEST(suite, test_limited_skills);
|
||||||
|
SUITE_ADD_TEST(suite, test_renumber_unit);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4128,7 +4128,7 @@ int armedmen(const unit * u, bool siege_weapons)
|
||||||
if (effskill(u, wtype->skill, 0) >= wtype->minskill)
|
if (effskill(u, wtype->skill, 0) >= wtype->minskill)
|
||||||
n += itm->number;
|
n += itm->number;
|
||||||
/* if (effskill(u, wtype->skill) >= wtype->minskill) n += itm->number; */
|
/* if (effskill(u, wtype->skill) >= wtype->minskill) n += itm->number; */
|
||||||
if (n > u->number)
|
if (n >= u->number)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
n = _min(n, u->number);
|
n = _min(n, u->number);
|
||||||
|
|
|
@ -1402,6 +1402,42 @@ static void test_demon_hunger(CuTest * tc)
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_armedmen(CuTest *tc) {
|
||||||
|
// TODO: test RCF_NOWEAPONS and SK_WEAPONLESS
|
||||||
|
unit *u;
|
||||||
|
item_type *it_sword;
|
||||||
|
weapon_type *wtype;
|
||||||
|
test_setup();
|
||||||
|
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
||||||
|
it_sword = test_create_itemtype("sword");
|
||||||
|
wtype = new_weapontype(it_sword, 0, 0.5, 0, 0, 0, 0, SK_MELEE, 1);
|
||||||
|
CuAssertIntEquals(tc, 0, armedmen(u, false));
|
||||||
|
CuAssertIntEquals(tc, 0, armedmen(u, true));
|
||||||
|
set_level(u, SK_MELEE, 1);
|
||||||
|
CuAssertIntEquals(tc, 0, armedmen(u, false));
|
||||||
|
i_change(&u->items, it_sword, 1);
|
||||||
|
CuAssertIntEquals(tc, 1, armedmen(u, false));
|
||||||
|
i_change(&u->items, it_sword, 1);
|
||||||
|
CuAssertIntEquals(tc, 1, armedmen(u, false));
|
||||||
|
scale_number(u, 2);
|
||||||
|
set_level(u, SK_MELEE, 1);
|
||||||
|
CuAssertIntEquals(tc, 2, armedmen(u, false));
|
||||||
|
set_level(u, SK_MELEE, 0);
|
||||||
|
CuAssertIntEquals(tc, 0, armedmen(u, false));
|
||||||
|
set_level(u, SK_MELEE, 1);
|
||||||
|
i_change(&u->items, it_sword, -1);
|
||||||
|
CuAssertIntEquals(tc, 1, armedmen(u, false));
|
||||||
|
wtype->minskill = 2;
|
||||||
|
CuAssertIntEquals(tc, 0, armedmen(u, false));
|
||||||
|
set_level(u, SK_MELEE, 2);
|
||||||
|
CuAssertIntEquals(tc, 1, armedmen(u, false));
|
||||||
|
CuAssertIntEquals(tc, 1, armedmen(u, true));
|
||||||
|
wtype->flags |= WTF_SIEGE;
|
||||||
|
CuAssertIntEquals(tc, 0, armedmen(u, false));
|
||||||
|
CuAssertIntEquals(tc, 1, armedmen(u, true));
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
CuSuite *get_laws_suite(void)
|
CuSuite *get_laws_suite(void)
|
||||||
{
|
{
|
||||||
CuSuite *suite = CuSuiteNew();
|
CuSuite *suite = CuSuiteNew();
|
||||||
|
@ -1464,6 +1500,7 @@ CuSuite *get_laws_suite(void)
|
||||||
SUITE_ADD_TEST(suite, test_show_race);
|
SUITE_ADD_TEST(suite, test_show_race);
|
||||||
SUITE_ADD_TEST(suite, test_immigration);
|
SUITE_ADD_TEST(suite, test_immigration);
|
||||||
SUITE_ADD_TEST(suite, test_demon_hunger);
|
SUITE_ADD_TEST(suite, test_demon_hunger);
|
||||||
|
SUITE_ADD_TEST(suite, test_armedmen);
|
||||||
|
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,20 +132,6 @@ static bool f_nolux(const region * r)
|
||||||
return (r->land && count_demand(r) != get_maxluxuries());
|
return (r->land && count_demand(r) != get_maxluxuries());
|
||||||
}
|
}
|
||||||
|
|
||||||
int fix_demand(region * rd) {
|
|
||||||
luxury_type * ltype;
|
|
||||||
int maxluxuries = get_maxluxuries();
|
|
||||||
if (maxluxuries > 0) {
|
|
||||||
int sale = rng_int() % maxluxuries;
|
|
||||||
for (ltype = luxurytypes; sale != 0 && ltype; ltype = ltype->next) {
|
|
||||||
--sale;
|
|
||||||
}
|
|
||||||
setluxuries(rd, ltype);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int fix_all_demand(region *rd) {
|
int fix_all_demand(region *rd) {
|
||||||
region_list *rl, *rlist = NULL;
|
region_list *rl, *rlist = NULL;
|
||||||
recurse_regions(rd, &rlist, f_nolux);
|
recurse_regions(rd, &rlist, f_nolux);
|
||||||
|
|
|
@ -35,7 +35,6 @@ extern "C" {
|
||||||
|
|
||||||
extern int autoseed(newfaction ** players, int nsize, int max_agediff);
|
extern int autoseed(newfaction ** players, int nsize, int max_agediff);
|
||||||
extern newfaction *read_newfactions(const char *filename);
|
extern newfaction *read_newfactions(const char *filename);
|
||||||
extern int fix_demand(struct region *r);
|
|
||||||
extern const struct terrain_type *random_terrain(const struct terrain_type
|
extern const struct terrain_type *random_terrain(const struct terrain_type
|
||||||
*terrains[], int distribution[], int size);
|
*terrains[], int distribution[], int size);
|
||||||
|
|
||||||
|
|
|
@ -100,6 +100,7 @@ int RunAllTests(int argc, char *argv[])
|
||||||
ADD_SUITE(magic);
|
ADD_SUITE(magic);
|
||||||
ADD_SUITE(alchemy);
|
ADD_SUITE(alchemy);
|
||||||
ADD_SUITE(reports);
|
ADD_SUITE(reports);
|
||||||
|
ADD_SUITE(region);
|
||||||
ADD_SUITE(save);
|
ADD_SUITE(save);
|
||||||
ADD_SUITE(ship);
|
ADD_SUITE(ship);
|
||||||
ADD_SUITE(spellbook);
|
ADD_SUITE(spellbook);
|
||||||
|
@ -111,7 +112,7 @@ int RunAllTests(int argc, char *argv[])
|
||||||
ADD_SUITE(messages);
|
ADD_SUITE(messages);
|
||||||
/* gamecode */
|
/* gamecode */
|
||||||
ADD_SUITE(report);
|
ADD_SUITE(report);
|
||||||
// ADD_SUITE(creport);
|
ADD_SUITE(creport);
|
||||||
ADD_SUITE(prefix);
|
ADD_SUITE(prefix);
|
||||||
ADD_SUITE(summary);
|
ADD_SUITE(summary);
|
||||||
ADD_SUITE(names);
|
ADD_SUITE(names);
|
||||||
|
|
Loading…
Reference in New Issue