forked from github/server
when terraforming, remove roads.
This commit is contained in:
parent
11ce5a2f32
commit
d53a901d8a
5 changed files with 136 additions and 124 deletions
|
@ -64,8 +64,8 @@ function test_force_leave_off()
|
|||
end
|
||||
|
||||
function test_make_temp()
|
||||
local r = region.create(0, 0, "plain")
|
||||
local f1 = faction.create("human", "temp@eressea.de", "de")
|
||||
local r = region.create(0, 0, "plain")
|
||||
local u1 = unit.create(f1, r, 10)
|
||||
local u, u2
|
||||
|
||||
|
|
|
@ -1103,13 +1103,13 @@ void init_region(region *r)
|
|||
}
|
||||
}
|
||||
|
||||
void terraform_region(region * r, const terrain_type * terrain)
|
||||
{
|
||||
/* Resourcen, die nicht mehr vorkommen koennen, loeschen */
|
||||
const terrain_type *oldterrain = r->terrain;
|
||||
/* Resourcen loeschen, die im aktuellen terrain nicht (mehr) vorkommen koennen */
|
||||
static void reset_rawmaterials(region *r) {
|
||||
const terrain_type * terrain = r->terrain;
|
||||
rawmaterial **lrm = &r->resources;
|
||||
|
||||
assert(terrain);
|
||||
|
||||
while (*lrm) {
|
||||
rawmaterial *rm = *lrm;
|
||||
const resource_type *rtype = NULL;
|
||||
|
@ -1131,32 +1131,9 @@ void terraform_region(region * r, const terrain_type * terrain)
|
|||
lrm = &rm->next;
|
||||
}
|
||||
}
|
||||
|
||||
r->terrain = terrain;
|
||||
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 void create_land(region *r) {
|
||||
static struct surround {
|
||||
struct surround *next;
|
||||
const luxury_type *type;
|
||||
|
@ -1166,8 +1143,11 @@ void terraform_region(region * r, const terrain_type * terrain)
|
|||
direction_t d;
|
||||
int mnr = 0;
|
||||
|
||||
r->land = calloc(1, sizeof(land_region));
|
||||
if (!r->land) abort();
|
||||
assert(r);
|
||||
assert(r->land);
|
||||
assert(r->terrain);
|
||||
assert(fval(r->terrain, LAND_REGION));
|
||||
|
||||
r->land->ownership = NULL;
|
||||
region_set_morale(r, MORALE_DEFAULT, -1);
|
||||
region_setname(r, makename());
|
||||
|
@ -1196,8 +1176,9 @@ void terraform_region(region * r, const terrain_type * terrain)
|
|||
sr->value = 1;
|
||||
nb = sr;
|
||||
}
|
||||
else
|
||||
sr->value++;
|
||||
else {
|
||||
++sr->value;
|
||||
}
|
||||
++mnr;
|
||||
}
|
||||
}
|
||||
|
@ -1227,11 +1208,8 @@ void terraform_region(region * r, const terrain_type * terrain)
|
|||
trash = nb;
|
||||
nb = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (fval(terrain, LAND_REGION)) {
|
||||
const item_type *itype = NULL;
|
||||
|
||||
if (r->terrain->herbs) {
|
||||
int len = 0;
|
||||
while (r->terrain->herbs[len])
|
||||
|
@ -1246,16 +1224,46 @@ void terraform_region(region * r, const terrain_type * terrain)
|
|||
else {
|
||||
rsetherbtype(r, NULL);
|
||||
}
|
||||
if (oldterrain == NULL || !fval(oldterrain, LAND_REGION)) {
|
||||
if (rng_int() % 100 < 3)
|
||||
|
||||
if (rng_int() % 100 < 3) {
|
||||
fset(r, RF_MALLORN);
|
||||
else
|
||||
}
|
||||
else {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** 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);
|
||||
}
|
||||
|
||||
void destroy_all_roads(region * r)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < MAXDIRECTIONS; i++) {
|
||||
rsetroad(r, (direction_t)i, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -214,6 +214,7 @@ extern "C" {
|
|||
void terraform_region(struct region *r, const struct terrain_type *terrain);
|
||||
void init_region(struct region *r);
|
||||
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_y[MAXDIRECTIONS];
|
||||
|
|
|
@ -29,7 +29,9 @@ void test_terraform(CuTest *tc) {
|
|||
CuAssertPtrNotNull(tc, r->land->demands);
|
||||
CuAssertPtrEquals(tc, itype, (void *)r->land->demands->type->itype);
|
||||
CuAssertIntEquals(tc, 0, r->land->demands->type->price);
|
||||
rsetroad(r, D_NORTHWEST, 10);
|
||||
terraform_region(r, t_ocean);
|
||||
CuAssertIntEquals(tc, 0, rroad(r, D_NORTHWEST));
|
||||
CuAssertPtrEquals(tc, NULL, r->land);
|
||||
test_teardown();
|
||||
}
|
||||
|
|
|
@ -1619,15 +1619,6 @@ static int sp_create_stonegolem(castorder * co)
|
|||
* (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)
|
||||
{
|
||||
unit *u;
|
||||
|
|
Loading…
Reference in a new issue