forked from github/server
new seed/sapling/tree code, now with spread to the neighbours
This commit is contained in:
parent
c64905d1b4
commit
3248d11618
4 changed files with 43 additions and 13 deletions
|
@ -722,14 +722,14 @@ extern struct attrib_type at_germs;
|
||||||
static void
|
static void
|
||||||
growing_trees_e3(region * r, const int current_season, const int last_weeks_season)
|
growing_trees_e3(region * r, const int current_season, const int last_weeks_season)
|
||||||
{
|
{
|
||||||
const int transform[4][3] = {
|
const static int transform[4][3] = {
|
||||||
{ -1, -1, 0 },
|
{ -1, -1, 0 },
|
||||||
{ TREE_SEED, TREE_SAPLING, 2 },
|
{ TREE_SEED, TREE_SAPLING, 2 },
|
||||||
{ TREE_SAPLING, TREE_TREE, 2 },
|
{ TREE_SAPLING, TREE_TREE, 2 },
|
||||||
{ TREE_TREE, TREE_SEED, 2 }
|
{ TREE_TREE, TREE_SEED, 2 }
|
||||||
};
|
};
|
||||||
|
|
||||||
if (current_season!=last_weeks_season && transform[current_season][2]) {
|
if (r->land && current_season!=last_weeks_season && transform[current_season][2]) {
|
||||||
int src_type = transform[current_season][0];
|
int src_type = transform[current_season][0];
|
||||||
int dst_type = transform[current_season][1];
|
int dst_type = transform[current_season][1];
|
||||||
int src = rtrees(r, src_type);
|
int src = rtrees(r, src_type);
|
||||||
|
@ -737,6 +737,35 @@ growing_trees_e3(region * r, const int current_season, const int last_weeks_seas
|
||||||
int grow = src/transform[current_season][2];
|
int grow = src/transform[current_season][2];
|
||||||
rsettrees(r, src_type, src-grow);
|
rsettrees(r, src_type, src-grow);
|
||||||
rsettrees(r, dst_type, dst+grow);
|
rsettrees(r, dst_type, dst+grow);
|
||||||
|
|
||||||
|
if (dst_type==TREE_SEED && r->terrain->size) {
|
||||||
|
region * rn[MAXDIRECTIONS];
|
||||||
|
int d, total_size = 0;
|
||||||
|
get_neighbours(r, rn);
|
||||||
|
for (d=0;d!=MAXDIRECTIONS;++d) {
|
||||||
|
if (rn[d] && rn[d]->land) {
|
||||||
|
total_size += rn[d]->terrain->size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (total_size>0) {
|
||||||
|
double scale = 1.0;
|
||||||
|
if (total_size<r->terrain->size) {
|
||||||
|
scale = total_size/(double)r->terrain->size;
|
||||||
|
}
|
||||||
|
for (d=0;d!=MAXDIRECTIONS;++d) {
|
||||||
|
region * rx = rn[d];
|
||||||
|
if (rx && rx->land) {
|
||||||
|
int size = rx->terrain->size;
|
||||||
|
int d = rtrees(rx, dst_type);
|
||||||
|
double fg = grow * scale * size / MAXDIRECTIONS / total_size;
|
||||||
|
int g = (int)fg;
|
||||||
|
double ch = fg - g;
|
||||||
|
if (chance(ch)) ++g;
|
||||||
|
rsettrees(rx, dst_type, d + g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1503,6 +1503,15 @@ int region_get_morale(const region * r)
|
||||||
void region_set_morale(region * r, int morale)
|
void region_set_morale(region * r, int morale)
|
||||||
{
|
{
|
||||||
if (r->land) {
|
if (r->land) {
|
||||||
r->land->morale = morale;
|
r->land->morale = (short)morale;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void get_neighbours(const region * r, region ** list)
|
||||||
|
{
|
||||||
|
direction_t dir;
|
||||||
|
for (dir=0;dir!=MAXDIRECTIONS;++dir) {
|
||||||
|
list[dir] = rconnect(r, dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -276,7 +276,7 @@ int region_getresource(const struct region * r, const struct resource_type * rty
|
||||||
void region_setresource(struct region * r, const struct resource_type * rtype, int value);
|
void region_setresource(struct region * r, const struct resource_type * rtype, int value);
|
||||||
|
|
||||||
extern const struct item_type * r_luxury(struct region * r);
|
extern const struct item_type * r_luxury(struct region * r);
|
||||||
|
extern void get_neighbours(const struct region * r, struct region ** list);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -760,14 +760,6 @@ autoseed(newfaction ** players, int nsize, int max_agediff)
|
||||||
return tsize;
|
return tsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void get_neighbours(const region * r, region ** list)
|
|
||||||
{
|
|
||||||
direction_t dir;
|
|
||||||
for (dir=0;dir!=MAXDIRECTIONS;++dir) {
|
|
||||||
list[dir] = rconnect(r, dir);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
region_list * regionqueue_push(region_list ** rlist, region * r)
|
region_list * regionqueue_push(region_list ** rlist, region * r)
|
||||||
{
|
{
|
||||||
region_list * rnew = malloc(sizeof(region_list));
|
region_list * rnew = malloc(sizeof(region_list));
|
||||||
|
|
Loading…
Reference in a new issue