forked from github/server
Merge pull request #597 from ennorehling/develop
FIX: glaciers made with snowglobes have no luxuries
This commit is contained in:
commit
7e8b54c996
|
@ -474,9 +474,6 @@ static int tolua_region_create(lua_State * L)
|
|||
}
|
||||
if (result) {
|
||||
terraform_region(result, terrain);
|
||||
if (result->land) {
|
||||
fix_demand(result);
|
||||
}
|
||||
}
|
||||
|
||||
tolua_pushusertype(L, result, TOLUA_CAST "region");
|
||||
|
|
|
@ -20,7 +20,7 @@ order.test.c
|
|||
plane.test.c
|
||||
pool.test.c
|
||||
race.test.c
|
||||
# region.test.c
|
||||
region.test.c
|
||||
# resources.test.c
|
||||
save.test.c
|
||||
ship.test.c
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <kernel/save.h>
|
||||
#include <kernel/unit.h>
|
||||
#include <util/attrib.h>
|
||||
#include <util/rng.h>
|
||||
#include <util/gamedata.h>
|
||||
#include <util/message.h>
|
||||
#include <binarystore.h>
|
||||
|
@ -175,6 +176,43 @@ static void test_curse_cache(CuTest *tc)
|
|||
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 *suite = CuSuiteNew();
|
||||
|
@ -186,5 +224,7 @@ CuSuite *get_curse_suite(void)
|
|||
SUITE_ADD_TEST(suite, test_bad_dreams);
|
||||
SUITE_ADD_TEST(suite, test_memstream);
|
||||
SUITE_ADD_TEST(suite, test_write_flag);
|
||||
SUITE_ADD_TEST(suite, test_curse_flags);
|
||||
SUITE_ADD_TEST(suite, test_curse_ids);
|
||||
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)
|
||||
{
|
||||
/* 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);
|
||||
freset(r, RF_ENCOUNTER);
|
||||
freset(r, RF_MALLORN);
|
||||
/* Beschreibung und Namen löschen */
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1082,6 +1095,7 @@ void terraform_region(region * r, const terrain_type * terrain)
|
|||
r->land->ownership = NULL;
|
||||
region_set_morale(r, MORALE_DEFAULT, -1);
|
||||
region_setname(r, makename());
|
||||
fix_demand(r);
|
||||
for (d = 0; d != MAXDIRECTIONS; ++d) {
|
||||
region *nr = rconnect(r, d);
|
||||
if (nr && nr->land) {
|
||||
|
|
|
@ -160,6 +160,7 @@ extern "C" {
|
|||
|
||||
#define reg_hashkey(r) (r->index)
|
||||
|
||||
extern int fix_demand(struct region *r);
|
||||
int distance(const struct region *, const struct region *);
|
||||
int koor_distance(int ax, int ay, int bx, int by);
|
||||
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);
|
||||
r_setdemand(r, rtype->ltype, n);
|
||||
}
|
||||
if (!r->land->demands) {
|
||||
fix_demand(r);
|
||||
}
|
||||
read_items(data->store, &r->land->items);
|
||||
if (data->version >= REGIONOWNER_VERSION) {
|
||||
READ_INT(data->store, &n);
|
||||
|
|
|
@ -1717,7 +1717,7 @@ void renumber_unit(unit *u, int no) {
|
|||
uunhash(u);
|
||||
if (!ualias(u)) {
|
||||
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;
|
||||
uhash(u);
|
||||
|
|
|
@ -8,9 +8,10 @@
|
|||
#include <kernel/race.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/spell.h>
|
||||
#include <util/attrib.h>
|
||||
#include <util/base36.h>
|
||||
#include <util/language.h>
|
||||
#include <util/attrib.h>
|
||||
#include <util/rng.h>
|
||||
#include <spells/regioncurse.h>
|
||||
#include <alchemy.h>
|
||||
#include <laws.h>
|
||||
|
@ -454,6 +455,19 @@ static void test_remove_unit(CuTest *tc) {
|
|||
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 *suite = CuSuiteNew();
|
||||
|
@ -476,5 +490,6 @@ CuSuite *get_unit_suite(void)
|
|||
SUITE_ADD_TEST(suite, test_age_familiar);
|
||||
SUITE_ADD_TEST(suite, test_inside_building);
|
||||
SUITE_ADD_TEST(suite, test_limited_skills);
|
||||
SUITE_ADD_TEST(suite, test_renumber_unit);
|
||||
return suite;
|
||||
}
|
||||
|
|
|
@ -132,20 +132,6 @@ static bool f_nolux(const region * r)
|
|||
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) {
|
||||
region_list *rl, *rlist = NULL;
|
||||
recurse_regions(rd, &rlist, f_nolux);
|
||||
|
|
|
@ -35,7 +35,6 @@ extern "C" {
|
|||
|
||||
extern int autoseed(newfaction ** players, int nsize, int max_agediff);
|
||||
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
|
||||
*terrains[], int distribution[], int size);
|
||||
|
||||
|
|
|
@ -100,6 +100,7 @@ int RunAllTests(int argc, char *argv[])
|
|||
ADD_SUITE(magic);
|
||||
ADD_SUITE(alchemy);
|
||||
ADD_SUITE(reports);
|
||||
ADD_SUITE(region);
|
||||
ADD_SUITE(save);
|
||||
ADD_SUITE(ship);
|
||||
ADD_SUITE(spellbook);
|
||||
|
@ -111,7 +112,7 @@ int RunAllTests(int argc, char *argv[])
|
|||
ADD_SUITE(messages);
|
||||
/* gamecode */
|
||||
ADD_SUITE(report);
|
||||
// ADD_SUITE(creport);
|
||||
ADD_SUITE(creport);
|
||||
ADD_SUITE(prefix);
|
||||
ADD_SUITE(summary);
|
||||
ADD_SUITE(names);
|
||||
|
|
Loading…
Reference in New Issue