when terraforming, remove roads.
This commit is contained in:
Enno Rehling 2020-08-16 20:04:56 +02:00
parent 11ce5a2f32
commit d53a901d8a
5 changed files with 136 additions and 124 deletions

View file

@ -64,8 +64,8 @@ function test_force_leave_off()
end end
function test_make_temp() function test_make_temp()
local r = region.create(0, 0, "plain")
local f1 = faction.create("human", "temp@eressea.de", "de") local f1 = faction.create("human", "temp@eressea.de", "de")
local r = region.create(0, 0, "plain")
local u1 = unit.create(f1, r, 10) local u1 = unit.create(f1, r, 10)
local u, u2 local u, u2

View file

@ -1103,13 +1103,13 @@ void init_region(region *r)
} }
} }
void terraform_region(region * r, const terrain_type * terrain) /* Resourcen loeschen, die im aktuellen terrain nicht (mehr) vorkommen koennen */
{ static void reset_rawmaterials(region *r) {
/* Resourcen, die nicht mehr vorkommen koennen, loeschen */ const terrain_type * terrain = r->terrain;
const terrain_type *oldterrain = r->terrain;
rawmaterial **lrm = &r->resources; rawmaterial **lrm = &r->resources;
assert(terrain); assert(terrain);
while (*lrm) { while (*lrm) {
rawmaterial *rm = *lrm; rawmaterial *rm = *lrm;
const resource_type *rtype = NULL; const resource_type *rtype = NULL;
@ -1131,32 +1131,9 @@ void terraform_region(region * r, const terrain_type * terrain)
lrm = &rm->next; lrm = &rm->next;
} }
} }
}
r->terrain = terrain; static void create_land(region *r) {
terraform_resources(r);
if (!fval(terrain, LAND_REGION)) {
if (r->land) {
free_land(r->land);
r->land = NULL;
}
rsettrees(r, 0, 0);
rsettrees(r, 1, 0);
rsettrees(r, 2, 0);
rsethorses(r, 0);
rsetpeasants(r, 0);
rsetmoney(r, 0);
freset(r, RF_MALLORN);
return;
}
if (r->land) {
int d;
for (d = 0; d != MAXDIRECTIONS; ++d) {
rsetroad(r, d, 0);
}
}
else {
static struct surround { static struct surround {
struct surround *next; struct surround *next;
const luxury_type *type; const luxury_type *type;
@ -1166,8 +1143,11 @@ void terraform_region(region * r, const terrain_type * terrain)
direction_t d; direction_t d;
int mnr = 0; int mnr = 0;
r->land = calloc(1, sizeof(land_region)); assert(r);
if (!r->land) abort(); assert(r->land);
assert(r->terrain);
assert(fval(r->terrain, LAND_REGION));
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());
@ -1196,8 +1176,9 @@ void terraform_region(region * r, const terrain_type * terrain)
sr->value = 1; sr->value = 1;
nb = sr; nb = sr;
} }
else else {
sr->value++; ++sr->value;
}
++mnr; ++mnr;
} }
} }
@ -1227,11 +1208,8 @@ void terraform_region(region * r, const terrain_type * terrain)
trash = nb; trash = nb;
nb = NULL; nb = NULL;
} }
}
if (fval(terrain, LAND_REGION)) {
const item_type *itype = NULL; const item_type *itype = NULL;
if (r->terrain->herbs) { if (r->terrain->herbs) {
int len = 0; int len = 0;
while (r->terrain->herbs[len]) while (r->terrain->herbs[len])
@ -1246,16 +1224,46 @@ void terraform_region(region * r, const terrain_type * terrain)
else { else {
rsetherbtype(r, NULL); rsetherbtype(r, NULL);
} }
if (oldterrain == NULL || !fval(oldterrain, LAND_REGION)) {
if (rng_int() % 100 < 3) if (rng_int() % 100 < 3) {
fset(r, RF_MALLORN); fset(r, RF_MALLORN);
else }
else {
freset(r, RF_MALLORN); freset(r, RF_MALLORN);
} }
if (oldterrain == NULL || terrain->size != oldterrain->size) { }
void terraform_region(region * r, const terrain_type * terrain)
{
assert(r);
assert(terrain);
r->terrain = terrain;
reset_rawmaterials(r);
terraform_resources(r);
if (!fval(terrain, LAND_REGION)) {
if (r->land) {
rsettrees(r, 0, 0);
rsettrees(r, 1, 0);
rsettrees(r, 2, 0);
rsethorses(r, 0);
rsetpeasants(r, 0);
rsetmoney(r, 0);
destroy_all_roads(r);
free_land(r->land);
r->land = NULL;
}
freset(r, RF_MALLORN);
}
else {
if (!r->land) {
r->land = calloc(1, sizeof(land_region));
create_land(r);
}
init_region(r); init_region(r);
} }
}
} }
/** ENNO: /** ENNO:
@ -1510,3 +1518,13 @@ bool is_mourning(const region * r, int in_turn)
r->land->ownership->last_owner && r->land->ownership->owner && r->land->ownership->last_owner && r->land->ownership->owner &&
r->land->ownership->last_owner != r->land->ownership->owner); r->land->ownership->last_owner != r->land->ownership->owner);
} }
void destroy_all_roads(region * r)
{
int i;
for (i = 0; i < MAXDIRECTIONS; i++) {
rsetroad(r, (direction_t)i, 0);
}
}

View file

@ -214,6 +214,7 @@ extern "C" {
void terraform_region(struct region *r, const struct terrain_type *terrain); void terraform_region(struct region *r, const struct terrain_type *terrain);
void init_region(struct region *r); void init_region(struct region *r);
void pnormalize(int *x, int *y, const struct plane *pl); void pnormalize(int *x, int *y, const struct plane *pl);
void destroy_all_roads(struct region * r);
extern const int delta_x[MAXDIRECTIONS]; extern const int delta_x[MAXDIRECTIONS];
extern const int delta_y[MAXDIRECTIONS]; extern const int delta_y[MAXDIRECTIONS];

View file

@ -29,7 +29,9 @@ void test_terraform(CuTest *tc) {
CuAssertPtrNotNull(tc, r->land->demands); CuAssertPtrNotNull(tc, r->land->demands);
CuAssertPtrEquals(tc, itype, (void *)r->land->demands->type->itype); CuAssertPtrEquals(tc, itype, (void *)r->land->demands->type->itype);
CuAssertIntEquals(tc, 0, r->land->demands->type->price); CuAssertIntEquals(tc, 0, r->land->demands->type->price);
rsetroad(r, D_NORTHWEST, 10);
terraform_region(r, t_ocean); terraform_region(r, t_ocean);
CuAssertIntEquals(tc, 0, rroad(r, D_NORTHWEST));
CuAssertPtrEquals(tc, NULL, r->land); CuAssertPtrEquals(tc, NULL, r->land);
test_teardown(); test_teardown();
} }

View file

@ -1619,15 +1619,6 @@ static int sp_create_stonegolem(castorder * co)
* (FARCASTING | REGIONSPELL | TESTRESISTANCE) * (FARCASTING | REGIONSPELL | TESTRESISTANCE)
*/ */
static void destroy_all_roads(region * r)
{
int i;
for (i = 0; i < MAXDIRECTIONS; i++) {
rsetroad(r, (direction_t)i, 0);
}
}
static int sp_great_drought(castorder * co) static int sp_great_drought(castorder * co)
{ {
unit *u; unit *u;