forked from github/server
kill gc_add and gc_done, they were terrible ideas.
This commit is contained in:
parent
4e94a95835
commit
108a909131
|
@ -1647,17 +1647,16 @@ static void expandbuying(region * r, request * buyorders)
|
||||||
const luxury_type *type;
|
const luxury_type *type;
|
||||||
int number;
|
int number;
|
||||||
int multi;
|
int multi;
|
||||||
} *trades, *trade;
|
} trades[MAXLUXURIES], *trade;
|
||||||
static int ntrades = 0;
|
static int ntrades = 0;
|
||||||
int i, j;
|
int i, j;
|
||||||
const luxury_type *ltype;
|
const luxury_type *ltype;
|
||||||
|
|
||||||
if (ntrades == 0) {
|
if (ntrades == 0) {
|
||||||
for (ltype = luxurytypes; ltype; ltype = ltype->next)
|
for (ntrades = 0, ltype = luxurytypes; ltype; ltype = ltype->next) {
|
||||||
++ntrades;
|
assert(ntrades < MAXLUXURIES);
|
||||||
trades = gc_add(calloc(sizeof(struct trade), ntrades));
|
trades[ntrades++].type = ltype;
|
||||||
for (i = 0, ltype = luxurytypes; i != ntrades; ++i, ltype = ltype->next)
|
}
|
||||||
trades[i].type = ltype;
|
|
||||||
}
|
}
|
||||||
for (i = 0; i != ntrades; ++i) {
|
for (i = 0; i != ntrades; ++i) {
|
||||||
trades[i].number = 0;
|
trades[i].number = 0;
|
||||||
|
@ -1887,18 +1886,17 @@ static void expandselling(region * r, request * sellorders, int limit)
|
||||||
building *b;
|
building *b;
|
||||||
unit *u;
|
unit *u;
|
||||||
unit *hafenowner;
|
unit *hafenowner;
|
||||||
static int *counter;
|
static int counter[MAXLUXURIES];
|
||||||
static int ncounter = 0;
|
static int ncounter = 0;
|
||||||
|
|
||||||
if (ncounter == 0) {
|
if (ncounter == 0) {
|
||||||
const luxury_type *ltype;
|
const luxury_type *ltype;
|
||||||
for (ltype = luxurytypes; ltype; ltype = ltype->next)
|
for (ltype = luxurytypes; ltype; ltype = ltype->next) {
|
||||||
|
assert(ncounter < MAXLUXURIES);
|
||||||
++ncounter;
|
++ncounter;
|
||||||
counter = (int *)gc_add(calloc(sizeof(int), ncounter));
|
|
||||||
}
|
}
|
||||||
else {
|
}
|
||||||
memset(counter, 0, sizeof(int) * ncounter);
|
memset(counter, 0, sizeof(int) * ncounter);
|
||||||
}
|
|
||||||
|
|
||||||
if (!sellorders) { /* NEIN, denn Insekten können in || !r->buildings) */
|
if (!sellorders) { /* NEIN, denn Insekten können in || !r->buildings) */
|
||||||
return; /* Sümpfen und Wüsten auch so handeln */
|
return; /* Sümpfen und Wüsten auch so handeln */
|
||||||
|
@ -1958,6 +1956,7 @@ static void expandselling(region * r, request * sellorders, int limit)
|
||||||
int i;
|
int i;
|
||||||
int use = 0;
|
int use = 0;
|
||||||
for (i = 0, search = luxurytypes; search != ltype; search = search->next) {
|
for (i = 0, search = luxurytypes; search != ltype; search = search->next) {
|
||||||
|
// TODO: this is slow and lame!
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
if (counter[i] >= limit)
|
if (counter[i] >= limit)
|
||||||
|
|
|
@ -916,36 +916,6 @@ int maxworkingpeasants(const struct region *r)
|
||||||
return _max(size-treespace, _min(size / 10 , 200));
|
return _max(size-treespace, _min(size / 10 , 200));
|
||||||
}
|
}
|
||||||
|
|
||||||
void **blk_list[1024];
|
|
||||||
int list_index;
|
|
||||||
int blk_index;
|
|
||||||
|
|
||||||
static void gc_done(void)
|
|
||||||
{
|
|
||||||
int i, k;
|
|
||||||
for (i = 0; i != list_index; ++i) {
|
|
||||||
for (k = 0; k != 1024; ++k)
|
|
||||||
free(blk_list[i][k]);
|
|
||||||
free(blk_list[i]);
|
|
||||||
}
|
|
||||||
for (k = 0; k != blk_index; ++k)
|
|
||||||
free(blk_list[list_index][k]);
|
|
||||||
free(blk_list[list_index]);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void *gc_add(void *p)
|
|
||||||
{
|
|
||||||
if (blk_index == 0) {
|
|
||||||
blk_list[list_index] = (void **)malloc(1024 * sizeof(void *));
|
|
||||||
}
|
|
||||||
blk_list[list_index][blk_index] = p;
|
|
||||||
blk_index = (blk_index + 1) % 1024;
|
|
||||||
if (!blk_index)
|
|
||||||
++list_index;
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char * parameter_key(int i)
|
static const char * parameter_key(int i)
|
||||||
{
|
{
|
||||||
assert(i < MAXPARAMS && i >= 0);
|
assert(i < MAXPARAMS && i >= 0);
|
||||||
|
@ -1173,7 +1143,6 @@ void kernel_done(void)
|
||||||
* calling it is optional, e.g. a release server will most likely not do it.
|
* calling it is optional, e.g. a release server will most likely not do it.
|
||||||
*/
|
*/
|
||||||
translation_done();
|
translation_done();
|
||||||
gc_done();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
attrib_type at_germs = {
|
attrib_type at_germs = {
|
||||||
|
@ -1186,9 +1155,6 @@ attrib_type at_germs = {
|
||||||
ATF_UNIQUE
|
ATF_UNIQUE
|
||||||
};
|
};
|
||||||
|
|
||||||
/*********************/
|
|
||||||
/* at_guard */
|
|
||||||
/*********************/
|
|
||||||
attrib_type at_guard = {
|
attrib_type at_guard = {
|
||||||
"guard",
|
"guard",
|
||||||
DEFAULT_INIT,
|
DEFAULT_INIT,
|
||||||
|
|
|
@ -40,6 +40,7 @@ extern "C" {
|
||||||
#ifndef MAXUNITS
|
#ifndef MAXUNITS
|
||||||
# define MAXUNITS 1048573 /* must be prime for hashing. 524287 was >90% full */
|
# define MAXUNITS 1048573 /* must be prime for hashing. 524287 was >90% full */
|
||||||
#endif
|
#endif
|
||||||
|
#define MAXLUXURIES 16 /* there must be no more than MAXLUXURIES kinds of luxury goods in any game */
|
||||||
|
|
||||||
#define TREESIZE (8) /* space used by trees (in #peasants) */
|
#define TREESIZE (8) /* space used by trees (in #peasants) */
|
||||||
|
|
||||||
|
@ -183,9 +184,6 @@ extern "C" {
|
||||||
bool idle(struct faction *f);
|
bool idle(struct faction *f);
|
||||||
bool unit_has_cursed_item(const struct unit *u);
|
bool unit_has_cursed_item(const struct unit *u);
|
||||||
|
|
||||||
/* simple garbage collection: */
|
|
||||||
void *gc_add(void *p);
|
|
||||||
|
|
||||||
/* grammatik-flags: */
|
/* grammatik-flags: */
|
||||||
#define GF_NONE 0
|
#define GF_NONE 0
|
||||||
/* singular, ohne was dran */
|
/* singular, ohne was dran */
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||||
Katja Zedel <katze@felidae.kn-bremen.de
|
Katja Zedel <katze@felidae.kn-bremen.de
|
||||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -118,7 +118,8 @@ const char *write_regionname(const region * r, const faction * f, char *buffer,
|
||||||
const struct locale *lang = f ? f->locale : 0;
|
const struct locale *lang = f ? f->locale : 0;
|
||||||
if (r == NULL) {
|
if (r == NULL) {
|
||||||
strlcpy(buf, "(null)", size);
|
strlcpy(buf, "(null)", size);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
plane *pl = rplane(r);
|
plane *pl = rplane(r);
|
||||||
int nx = r->x, ny = r->y;
|
int nx = r->x, ny = r->y;
|
||||||
pnormalize(&nx, &ny, pl);
|
pnormalize(&nx, &ny, pl);
|
||||||
|
@ -132,7 +133,7 @@ const char *regionname(const region * r, const faction * f)
|
||||||
{
|
{
|
||||||
static int index = 0;
|
static int index = 0;
|
||||||
static char buf[2][NAMESIZE];
|
static char buf[2][NAMESIZE];
|
||||||
index = 1-index;
|
index = 1 - index;
|
||||||
return write_regionname(r, f, buf[index], sizeof(buf[index]));
|
return write_regionname(r, f, buf[index], sizeof(buf[index]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,18 +180,18 @@ void a_initmoveblock(attrib * a)
|
||||||
|
|
||||||
int a_readmoveblock(attrib * a, void *owner, struct storage *store)
|
int a_readmoveblock(attrib * a, void *owner, struct storage *store)
|
||||||
{
|
{
|
||||||
moveblock *m = (moveblock *) (a->data.v);
|
moveblock *m = (moveblock *)(a->data.v);
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
READ_INT(store, &i);
|
READ_INT(store, &i);
|
||||||
m->dir = (direction_t) i;
|
m->dir = (direction_t)i;
|
||||||
return AT_READ_OK;
|
return AT_READ_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
a_writemoveblock(const attrib * a, const void *owner, struct storage *store)
|
a_writemoveblock(const attrib * a, const void *owner, struct storage *store)
|
||||||
{
|
{
|
||||||
moveblock *m = (moveblock *) (a->data.v);
|
moveblock *m = (moveblock *)(a->data.v);
|
||||||
WRITE_INT(store, (int)m->dir);
|
WRITE_INT(store, (int)m->dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,7 +203,7 @@ attrib_type at_moveblock = {
|
||||||
#define RMAXHASH MAXREGIONS
|
#define RMAXHASH MAXREGIONS
|
||||||
static region *regionhash[RMAXHASH];
|
static region *regionhash[RMAXHASH];
|
||||||
static int dummy_data;
|
static int dummy_data;
|
||||||
static region *dummy_ptr = (region *) & dummy_data; /* a funny hack */
|
static region *dummy_ptr = (region *)& dummy_data; /* a funny hack */
|
||||||
|
|
||||||
typedef struct uidhashentry {
|
typedef struct uidhashentry {
|
||||||
int uid;
|
int uid;
|
||||||
|
@ -214,7 +215,7 @@ struct region *findregionbyid(int uid)
|
||||||
{
|
{
|
||||||
int key = uid % MAXREGIONS;
|
int key = uid % MAXREGIONS;
|
||||||
while (uidhash[key].uid != 0 && uidhash[key].uid != uid) {
|
while (uidhash[key].uid != 0 && uidhash[key].uid != uid) {
|
||||||
if (++key==MAXREGIONS) key = 0;
|
if (++key == MAXREGIONS) key = 0;
|
||||||
}
|
}
|
||||||
return uidhash[key].r;
|
return uidhash[key].r;
|
||||||
}
|
}
|
||||||
|
@ -335,7 +336,7 @@ region *r_connect(const region * r, direction_t dir)
|
||||||
region *result;
|
region *result;
|
||||||
int x, y;
|
int x, y;
|
||||||
#ifdef FAST_CONNECT
|
#ifdef FAST_CONNECT
|
||||||
region *rmodify = (region *) r;
|
region *rmodify = (region *)r;
|
||||||
assert(dir >= 0 && dir < MAXDIRECTIONS);
|
assert(dir >= 0 && dir < MAXDIRECTIONS);
|
||||||
if (r->connect[dir])
|
if (r->connect[dir])
|
||||||
return r->connect[dir];
|
return r->connect[dir];
|
||||||
|
@ -381,10 +382,12 @@ static int koor_distance_orig(int x1, int y1, int x2, int y2)
|
||||||
if (dx >= 0) {
|
if (dx >= 0) {
|
||||||
int result = dx + dy;
|
int result = dx + dy;
|
||||||
return result;
|
return result;
|
||||||
} else if (-dx >= dy) {
|
}
|
||||||
|
else if (-dx >= dy) {
|
||||||
int result = -dx;
|
int result = -dx;
|
||||||
return result;
|
return result;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return dy;
|
return dy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -441,7 +444,8 @@ int koor_distance(int x1, int y1, int x2, int y2)
|
||||||
int height = plane_height(p1);
|
int height = plane_height(p1);
|
||||||
if (width && height) {
|
if (width && height) {
|
||||||
return koor_distance_wrap_xy(x1, y1, x2, y2, width, height);
|
return koor_distance_wrap_xy(x1, y1, x2, y2, width, height);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return koor_distance_orig(x1, y1, x2, y2);
|
return koor_distance_orig(x1, y1, x2, y2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -463,7 +467,7 @@ void free_regionlist(region_list * rl)
|
||||||
|
|
||||||
void add_regionlist(region_list ** rl, region * r)
|
void add_regionlist(region_list ** rl, region * r)
|
||||||
{
|
{
|
||||||
region_list *rl2 = (region_list *) malloc(sizeof(region_list));
|
region_list *rl2 = (region_list *)malloc(sizeof(region_list));
|
||||||
|
|
||||||
rl2->data = r;
|
rl2->data = r;
|
||||||
rl2->next = *rl;
|
rl2->next = *rl;
|
||||||
|
@ -553,7 +557,8 @@ void rsetroad(region * r, direction_t d, short val)
|
||||||
}
|
}
|
||||||
if (r == b->from) {
|
if (r == b->from) {
|
||||||
b->data.sa[0] = val;
|
b->data.sa[0] = val;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
b->data.sa[1] = val;
|
b->data.sa[1] = val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -598,7 +603,7 @@ bool is_coastregion(region * r)
|
||||||
if (rn && fval(rn->terrain, SEA_REGION))
|
if (rn && fval(rn->terrain, SEA_REGION))
|
||||||
res++;
|
res++;
|
||||||
}
|
}
|
||||||
return res!=0;
|
return res != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rpeasants(const region * r)
|
int rpeasants(const region * r)
|
||||||
|
@ -791,7 +796,7 @@ void region_setresource(region * r, const resource_type * rtype, int value)
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; r->terrain->production[i].type; ++i) {
|
for (i = 0; r->terrain->production[i].type; ++i) {
|
||||||
const terrain_production *production = r->terrain->production + i;
|
const terrain_production *production = r->terrain->production + i;
|
||||||
if (production->type==rtype) {
|
if (production->type == rtype) {
|
||||||
add_resource(r, 1, value, dice_rand(production->divisor), rtype);
|
add_resource(r, 1, value, dice_rand(production->divisor), rtype);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -923,7 +928,8 @@ static char *makename(void)
|
||||||
k = rng_int() % (int)nk;
|
k = rng_int() % (int)nk;
|
||||||
name[p] = kons[k];
|
name[p] = kons[k];
|
||||||
p++;
|
p++;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
k = rng_int() % (int)ns;
|
k = rng_int() % (int)ns;
|
||||||
name[p] = start[k];
|
name[p] = start[k];
|
||||||
p++;
|
p++;
|
||||||
|
@ -936,7 +942,8 @@ static char *makename(void)
|
||||||
name[p] = end[e];
|
name[p] = end[e];
|
||||||
p++;
|
p++;
|
||||||
x = 1;
|
x = 1;
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
x = 0;
|
x = 0;
|
||||||
}
|
}
|
||||||
name[p] = '\0';
|
name[p] = '\0';
|
||||||
|
@ -989,7 +996,8 @@ void terraform_region(region * r, const terrain_type * terrain)
|
||||||
if (rtype == NULL) {
|
if (rtype == NULL) {
|
||||||
*lrm = rm->next;
|
*lrm = rm->next;
|
||||||
free(rm);
|
free(rm);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
lrm = &rm->next;
|
lrm = &rm->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1018,11 +1026,12 @@ void terraform_region(region * r, const terrain_type * terrain)
|
||||||
|
|
||||||
if (r->land) {
|
if (r->land) {
|
||||||
int d;
|
int d;
|
||||||
for (d=0;d!=MAXDIRECTIONS;++d) {
|
for (d = 0; d != MAXDIRECTIONS; ++d) {
|
||||||
rsetroad(r, d, 0);
|
rsetroad(r, d, 0);
|
||||||
}
|
}
|
||||||
i_freeall(&r->land->items);
|
i_freeall(&r->land->items);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
static struct surround {
|
static struct surround {
|
||||||
struct surround *next;
|
struct surround *next;
|
||||||
const luxury_type *type;
|
const luxury_type *type;
|
||||||
|
@ -1050,20 +1059,23 @@ void terraform_region(region * r, const terrain_type * terrain)
|
||||||
if (trash) {
|
if (trash) {
|
||||||
sr = trash;
|
sr = trash;
|
||||||
trash = trash->next;
|
trash = trash->next;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
sr = calloc(1, sizeof(struct surround));
|
sr = calloc(1, sizeof(struct surround));
|
||||||
}
|
}
|
||||||
sr->next = nb;
|
sr->next = nb;
|
||||||
sr->type = sale->type;
|
sr->type = sale->type;
|
||||||
sr->value = 1;
|
sr->value = 1;
|
||||||
nb = sr;
|
nb = sr;
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
sr->value++;
|
sr->value++;
|
||||||
++mnr;
|
++mnr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!nb) {
|
if (!nb) {
|
||||||
|
// TODO: this is really lame
|
||||||
int i = get_maxluxuries();
|
int i = get_maxluxuries();
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
i = rng_int() % i;
|
i = rng_int() % i;
|
||||||
|
@ -1071,7 +1083,8 @@ void terraform_region(region * r, const terrain_type * terrain)
|
||||||
while (i--)
|
while (i--)
|
||||||
ltype = ltype->next;
|
ltype = ltype->next;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
int i = rng_int() % mnr;
|
int i = rng_int() % mnr;
|
||||||
struct surround *srd = nb;
|
struct surround *srd = nb;
|
||||||
while (i > srd->value) {
|
while (i > srd->value) {
|
||||||
|
@ -1106,7 +1119,8 @@ void terraform_region(region * r, const terrain_type * terrain)
|
||||||
if (itype != NULL) {
|
if (itype != NULL) {
|
||||||
rsetherbtype(r, itype);
|
rsetherbtype(r, itype);
|
||||||
rsetherbs(r, (short)(50 + rng_int() % 31));
|
rsetherbs(r, (short)(50 + rng_int() % 31));
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
rsetherbtype(r, NULL);
|
rsetherbtype(r, NULL);
|
||||||
}
|
}
|
||||||
if (oldterrain == NULL || !fval(oldterrain, LAND_REGION)) {
|
if (oldterrain == NULL || !fval(oldterrain, LAND_REGION)) {
|
||||||
|
@ -1126,9 +1140,11 @@ void terraform_region(region * r, const terrain_type * terrain)
|
||||||
if (rng_int() % 100 < 40) {
|
if (rng_int() % 100 < 40) {
|
||||||
rsettrees(r, 2, terrain->size * (30 + rng_int() % 40) / 1000);
|
rsettrees(r, 2, terrain->size * (30 + rng_int() % 40) / 1000);
|
||||||
}
|
}
|
||||||
} else if (chance(0.2)) {
|
}
|
||||||
|
else if (chance(0.2)) {
|
||||||
rsettrees(r, 2, terrain->size * (30 + rng_int() % 40) / 1000);
|
rsettrees(r, 2, terrain->size * (30 + rng_int() % 40) / 1000);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
rsettrees(r, 2, 0);
|
rsettrees(r, 2, 0);
|
||||||
}
|
}
|
||||||
rsettrees(r, 1, rtrees(r, 2) / 4);
|
rsettrees(r, 1, rtrees(r, 2) / 4);
|
||||||
|
@ -1164,10 +1180,10 @@ int resolve_region_coor(variant id, void *address)
|
||||||
{
|
{
|
||||||
region *r = findregion(id.sa[0], id.sa[1]);
|
region *r = findregion(id.sa[0], id.sa[1]);
|
||||||
if (r) {
|
if (r) {
|
||||||
*(region **) address = r;
|
*(region **)address = r;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
*(region **) address = NULL;
|
*(region **)address = NULL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1177,11 +1193,11 @@ int resolve_region_id(variant id, void *address)
|
||||||
if (id.i != 0) {
|
if (id.i != 0) {
|
||||||
r = findregionbyid(id.i);
|
r = findregionbyid(id.i);
|
||||||
if (r == NULL) {
|
if (r == NULL) {
|
||||||
*(region **) address = NULL;
|
*(region **)address = NULL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*(region **) address = r;
|
*(region **)address = r;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1194,7 +1210,8 @@ variant read_region_reference(struct storage * store)
|
||||||
result.sa[0] = (short)n;
|
result.sa[0] = (short)n;
|
||||||
READ_INT(store, &n);
|
READ_INT(store, &n);
|
||||||
result.sa[1] = (short)n;
|
result.sa[1] = (short)n;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
READ_INT(store, &result.i);
|
READ_INT(store, &result.i);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -1204,7 +1221,8 @@ void write_region_reference(const region * r, struct storage *store)
|
||||||
{
|
{
|
||||||
if (r) {
|
if (r) {
|
||||||
WRITE_INT(store, r->uid);
|
WRITE_INT(store, r->uid);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
WRITE_INT(store, 0);
|
WRITE_INT(store, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1221,7 +1239,7 @@ struct message_list *r_getmessages(const struct region *r,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct message *r_addmessage(struct region *r, const struct faction *viewer,
|
struct message *r_addmessage(struct region *r, const struct faction *viewer,
|
||||||
struct message *msg)
|
struct message *msg)
|
||||||
{
|
{
|
||||||
assert(r);
|
assert(r);
|
||||||
if (viewer) {
|
if (viewer) {
|
||||||
|
@ -1299,16 +1317,19 @@ faction *update_owners(region * r)
|
||||||
r->land->ownership->flags |= OWNER_MOURNING;
|
r->land->ownership->flags |= OWNER_MOURNING;
|
||||||
f = NULL;
|
f = NULL;
|
||||||
}
|
}
|
||||||
} else if (u->faction != f) {
|
}
|
||||||
|
else if (u->faction != f) {
|
||||||
if (!r->land->ownership) {
|
if (!r->land->ownership) {
|
||||||
/* there has never been a prior owner */
|
/* there has never been a prior owner */
|
||||||
region_set_morale(r, MORALE_DEFAULT, turn);
|
region_set_morale(r, MORALE_DEFAULT, turn);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
alliance *al = region_get_alliance(r);
|
alliance *al = region_get_alliance(r);
|
||||||
if (al && u->faction->alliance == al) {
|
if (al && u->faction->alliance == al) {
|
||||||
int morale = _max(0, r->land->morale - MORALE_TRANSFER);
|
int morale = _max(0, r->land->morale - MORALE_TRANSFER);
|
||||||
region_set_morale(r, morale, turn);
|
region_set_morale(r, morale, turn);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
region_set_morale(r, MORALE_TAKEOVER, turn);
|
region_set_morale(r, MORALE_TAKEOVER, turn);
|
||||||
if (f) {
|
if (f) {
|
||||||
r->land->ownership->flags |= OWNER_MOURNING;
|
r->land->ownership->flags |= OWNER_MOURNING;
|
||||||
|
@ -1319,7 +1340,8 @@ faction *update_owners(region * r)
|
||||||
f = u->faction;
|
f = u->faction;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (r->land->ownership && r->land->ownership->owner) {
|
}
|
||||||
|
else if (r->land->ownership && r->land->ownership->owner) {
|
||||||
r->land->ownership->flags |= OWNER_MOURNING;
|
r->land->ownership->flags |= OWNER_MOURNING;
|
||||||
region_set_owner(r, NULL, turn);
|
region_set_owner(r, NULL, turn);
|
||||||
f = NULL;
|
f = NULL;
|
||||||
|
|
|
@ -1030,11 +1030,12 @@ void writeregion(struct gamedata *data, const region * r)
|
||||||
WRITE_INT(data->store, rherbs(r));
|
WRITE_INT(data->store, rherbs(r));
|
||||||
WRITE_INT(data->store, rpeasants(r));
|
WRITE_INT(data->store, rpeasants(r));
|
||||||
WRITE_INT(data->store, rmoney(r));
|
WRITE_INT(data->store, rmoney(r));
|
||||||
if (r->land)
|
if (r->land) {
|
||||||
for (demand = r->land->demands; demand; demand = demand->next) {
|
for (demand = r->land->demands; demand; demand = demand->next) {
|
||||||
WRITE_TOK(data->store, resourcename(demand->type->itype->rtype, 0));
|
WRITE_TOK(data->store, resourcename(demand->type->itype->rtype, 0));
|
||||||
WRITE_INT(data->store, demand->value);
|
WRITE_INT(data->store, demand->value);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
WRITE_TOK(data->store, "end");
|
WRITE_TOK(data->store, "end");
|
||||||
write_items(data->store, r->land->items);
|
write_items(data->store, r->land->items);
|
||||||
WRITE_SECTION(data->store);
|
WRITE_SECTION(data->store);
|
||||||
|
|
|
@ -644,7 +644,7 @@ static weapon_type *xml_readweapon(xmlXPathContextPtr xpath, item_type * itype)
|
||||||
xmlFree(propValue);
|
xmlFree(propValue);
|
||||||
|
|
||||||
propValue = xmlGetProp(node, BAD_CAST "value");
|
propValue = xmlGetProp(node, BAD_CAST "value");
|
||||||
wtype->damage[pos] = gc_add(_strdup((const char *)propValue));
|
wtype->damage[pos] = _strdup((const char *)propValue); // TODO: this is a memory leak
|
||||||
if (k == 0)
|
if (k == 0)
|
||||||
wtype->damage[1 - pos] = wtype->damage[pos];
|
wtype->damage[1 - pos] = wtype->damage[pos];
|
||||||
xmlFree(propValue);
|
xmlFree(propValue);
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
This program may not be used, modified or distributed
|
This program may not be used, modified or distributed
|
||||||
without prior permission by the authors of Eressea.
|
without prior permission by the authors of Eressea.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <platform.h>
|
#include <platform.h>
|
||||||
#include <kernel/config.h>
|
#include <kernel/config.h>
|
||||||
|
@ -70,7 +70,8 @@ const terrain_type *random_terrain(const terrain_type * terrains[],
|
||||||
}
|
}
|
||||||
assert(i < size);
|
assert(i < size);
|
||||||
terrain = terrains[i];
|
terrain = terrains[i];
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
terrain = terrains[n];
|
terrain = terrains[n];
|
||||||
}
|
}
|
||||||
return terrain;
|
return terrain;
|
||||||
|
@ -103,7 +104,7 @@ static int count_demand(const region * r)
|
||||||
|
|
||||||
static int
|
static int
|
||||||
recurse_regions(region * r, region_list ** rlist,
|
recurse_regions(region * r, region_list ** rlist,
|
||||||
bool(*fun) (const region * r))
|
bool(*fun) (const region * r))
|
||||||
{
|
{
|
||||||
if (!fun(r))
|
if (!fun(r))
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -134,30 +135,27 @@ static bool f_nolux(const region * r)
|
||||||
int fix_demand(region * rd)
|
int fix_demand(region * rd)
|
||||||
{
|
{
|
||||||
region_list *rl, *rlist = NULL;
|
region_list *rl, *rlist = NULL;
|
||||||
static const struct luxury_type **mlux = 0, **ltypes;
|
static const luxury_type *mlux[MAXLUXURIES];
|
||||||
|
const luxury_type *ltypes[MAXLUXURIES];
|
||||||
const luxury_type *sale = NULL;
|
const luxury_type *sale = NULL;
|
||||||
int maxlux = 0;
|
int maxlux = 0;
|
||||||
int maxluxuries = get_maxluxuries();
|
static int maxluxuries = 0;
|
||||||
|
|
||||||
if (maxluxuries == 0)
|
|
||||||
return 0;
|
|
||||||
recurse_regions(rd, &rlist, f_nolux);
|
recurse_regions(rd, &rlist, f_nolux);
|
||||||
if (mlux == 0) {
|
if (maxluxuries == 0) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
mlux =
|
|
||||||
(const luxury_type **)gc_add(calloc(maxluxuries,
|
|
||||||
sizeof(const luxury_type *)));
|
|
||||||
ltypes =
|
|
||||||
(const luxury_type **)gc_add(calloc(maxluxuries,
|
|
||||||
sizeof(const luxury_type *)));
|
|
||||||
for (sale = luxurytypes; sale; sale = sale->next) {
|
for (sale = luxurytypes; sale; sale = sale->next) {
|
||||||
|
mlux[i] = 0;
|
||||||
ltypes[i++] = sale;
|
ltypes[i++] = sale;
|
||||||
}
|
}
|
||||||
} else {
|
maxluxuries = i;
|
||||||
|
}
|
||||||
|
else {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i != maxluxuries; ++i)
|
for (i = 0; i != maxluxuries; ++i) {
|
||||||
mlux[i] = 0;
|
mlux[i] = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
for (rl = rlist; rl; rl = rl->next) {
|
for (rl = rlist; rl; rl = rl->next) {
|
||||||
region *r = rl->data;
|
region *r = rl->data;
|
||||||
direction_t d;
|
direction_t d;
|
||||||
|
@ -173,7 +171,8 @@ int fix_demand(region * rd)
|
||||||
maxlux = i;
|
maxlux = i;
|
||||||
mlux[i] = dmd->type;
|
mlux[i] = dmd->type;
|
||||||
break;
|
break;
|
||||||
} else if (mlux[i] == dmd->type) {
|
}
|
||||||
|
else if (mlux[i] == dmd->type) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -274,7 +273,8 @@ newfaction *read_newfactions(const char *filename)
|
||||||
al = makealliance(alliance, zText);
|
al = makealliance(alliance, zText);
|
||||||
}
|
}
|
||||||
nf->allies = al;
|
nf->allies = al;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
nf->allies = NULL;
|
nf->allies = NULL;
|
||||||
}
|
}
|
||||||
if (nf->race == NULL) {
|
if (nf->race == NULL) {
|
||||||
|
@ -360,13 +360,13 @@ static bool virgin_region(const region * r)
|
||||||
|
|
||||||
static quicklist * get_island(region * root)
|
static quicklist * get_island(region * root)
|
||||||
{
|
{
|
||||||
quicklist * ql, * result = 0;
|
quicklist * ql, *result = 0;
|
||||||
int qi = 0;
|
int qi = 0;
|
||||||
|
|
||||||
fset(root, RF_MARK);
|
fset(root, RF_MARK);
|
||||||
ql_push(&result, root);
|
ql_push(&result, root);
|
||||||
|
|
||||||
for (ql=result,qi=0; ql; ql_advance(&ql, &qi, 1)) {
|
for (ql = result, qi = 0; ql; ql_advance(&ql, &qi, 1)) {
|
||||||
int dir;
|
int dir;
|
||||||
region *r = (region *)ql_get(ql, qi);
|
region *r = (region *)ql_get(ql, qi);
|
||||||
region * next[MAXDIRECTIONS];
|
region * next[MAXDIRECTIONS];
|
||||||
|
@ -382,7 +382,7 @@ static quicklist * get_island(region * root)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ql=result,qi=0; ql; ql_advance(&ql, &qi, 1)) {
|
for (ql = result, qi = 0; ql; ql_advance(&ql, &qi, 1)) {
|
||||||
region *r = (region *)ql_get(ql, qi);
|
region *r = (region *)ql_get(ql, qi);
|
||||||
freset(r, RF_MARK);
|
freset(r, RF_MARK);
|
||||||
}
|
}
|
||||||
|
@ -398,7 +398,7 @@ get_island_info(region * root, int *size_p, int *inhabited_p, int *maxage_p)
|
||||||
ql_push(&island, root);
|
ql_push(&island, root);
|
||||||
fset(root, RF_MARK);
|
fset(root, RF_MARK);
|
||||||
|
|
||||||
for (ql=island,qi=0; ql; ql_advance(&ql, &qi, 1)) {
|
for (ql = island, qi = 0; ql; ql_advance(&ql, &qi, 1)) {
|
||||||
int d;
|
int d;
|
||||||
region *r = (region *)ql_get(ql, qi);
|
region *r = (region *)ql_get(ql, qi);
|
||||||
if (r->units) {
|
if (r->units) {
|
||||||
|
@ -419,7 +419,7 @@ get_island_info(region * root, int *size_p, int *inhabited_p, int *maxage_p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (ql=island,qi=0; ql; ql_advance(&ql, &qi, 1)) {
|
for (ql = island, qi = 0; ql; ql_advance(&ql, &qi, 1)) {
|
||||||
region *r = (region *)ql_get(ql, qi);
|
region *r = (region *)ql_get(ql, qi);
|
||||||
freset(r, RF_MARK);
|
freset(r, RF_MARK);
|
||||||
}
|
}
|
||||||
|
@ -568,7 +568,7 @@ int autoseed(newfaction ** players, int nsize, int max_agediff)
|
||||||
quicklist *ql, *rlist = get_island(rmin);
|
quicklist *ql, *rlist = get_island(rmin);
|
||||||
int qi;
|
int qi;
|
||||||
|
|
||||||
for (ql=rlist,qi=0;ql;ql_advance(&ql, &qi, 1)) {
|
for (ql = rlist, qi = 0; ql; ql_advance(&ql, &qi, 1)) {
|
||||||
region *r = (region *)ql_get(ql, qi);
|
region *r = (region *)ql_get(ql, qi);
|
||||||
unit *u;
|
unit *u;
|
||||||
for (u = r->units; u; u = u->next) {
|
for (u = r->units; u; u = u->next) {
|
||||||
|
@ -667,7 +667,8 @@ int autoseed(newfaction ** players, int nsize, int max_agediff)
|
||||||
}
|
}
|
||||||
if (volcano_terrain != NULL && (rng_int() % VOLCANO_CHANCE == 0)) {
|
if (volcano_terrain != NULL && (rng_int() % VOLCANO_CHANCE == 0)) {
|
||||||
terraform_region(r, volcano_terrain);
|
terraform_region(r, volcano_terrain);
|
||||||
} else if (nsize && (rng_int() % isize == 0 || rsize == 0)) {
|
}
|
||||||
|
else if (nsize && (rng_int() % isize == 0 || rsize == 0)) {
|
||||||
newfaction **nfp, *nextf = *players;
|
newfaction **nfp, *nextf = *players;
|
||||||
faction *f;
|
faction *f;
|
||||||
unit *u;
|
unit *u;
|
||||||
|
@ -690,7 +691,8 @@ int autoseed(newfaction ** players, int nsize, int max_agediff)
|
||||||
if (strcmp(nextf->email, nf->email) == 0) {
|
if (strcmp(nextf->email, nf->email) == 0) {
|
||||||
*nfp = nf->next;
|
*nfp = nf->next;
|
||||||
free_newfaction(nf);
|
free_newfaction(nf);
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
nfp = &nf->next;
|
nfp = &nf->next;
|
||||||
}
|
}
|
||||||
*players = nextf->next;
|
*players = nextf->next;
|
||||||
|
@ -701,7 +703,8 @@ int autoseed(newfaction ** players, int nsize, int max_agediff)
|
||||||
--isize;
|
--isize;
|
||||||
if (psize >= PLAYERS_PER_ISLAND)
|
if (psize >= PLAYERS_PER_ISLAND)
|
||||||
break;
|
break;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
terraform_region(r, random_terrain(terrainarr, distribution, nterrains));
|
terraform_region(r, random_terrain(terrainarr, distribution, nterrains));
|
||||||
--isize;
|
--isize;
|
||||||
}
|
}
|
||||||
|
@ -740,7 +743,8 @@ int autoseed(newfaction ** players, int nsize, int max_agediff)
|
||||||
if (rng_int() % SPECIALCHANCE < special) {
|
if (rng_int() % SPECIALCHANCE < special) {
|
||||||
terrain = random_terrain(terrainarr, distribution, nterrains);
|
terrain = random_terrain(terrainarr, distribution, nterrains);
|
||||||
special = SPECIALCHANCE / 3; /* 33% chance auf noch eines */
|
special = SPECIALCHANCE / 3; /* 33% chance auf noch eines */
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
special = 1;
|
special = 1;
|
||||||
}
|
}
|
||||||
terraform_region(rn, terrain);
|
terraform_region(rn, terrain);
|
||||||
|
@ -821,14 +825,14 @@ static struct geo {
|
||||||
terrain_t type;
|
terrain_t type;
|
||||||
} geography_e3[GEOMAX] = {
|
} geography_e3[GEOMAX] = {
|
||||||
{
|
{
|
||||||
8, T_OCEAN}, {
|
8, T_OCEAN }, {
|
||||||
3, T_SWAMP}, {
|
3, T_SWAMP }, {
|
||||||
1, T_VOLCANO}, {
|
1, T_VOLCANO }, {
|
||||||
3, T_DESERT}, {
|
3, T_DESERT }, {
|
||||||
4, T_HIGHLAND}, {
|
4, T_HIGHLAND }, {
|
||||||
3, T_MOUNTAIN}, {
|
3, T_MOUNTAIN }, {
|
||||||
2, T_GLACIER}, {
|
2, T_GLACIER }, {
|
||||||
1, T_PLAIN}
|
1, T_PLAIN }
|
||||||
};
|
};
|
||||||
|
|
||||||
const terrain_type *random_terrain_e3(direction_t dir)
|
const terrain_type *random_terrain_e3(direction_t dir)
|
||||||
|
@ -851,7 +855,7 @@ const terrain_type *random_terrain_e3(direction_t dir)
|
||||||
|
|
||||||
int
|
int
|
||||||
random_neighbours(region * r, region_list ** rlist,
|
random_neighbours(region * r, region_list ** rlist,
|
||||||
const terrain_type * (*terraformer) (direction_t))
|
const terrain_type * (*terraformer) (direction_t))
|
||||||
{
|
{
|
||||||
int nsize = 0;
|
int nsize = 0;
|
||||||
direction_t dir;
|
direction_t dir;
|
||||||
|
@ -993,7 +997,8 @@ int build_island_e3(int x, int y, int numfactions, int minsize)
|
||||||
if (r->land) {
|
if (r->land) {
|
||||||
if (nsize < minsize) {
|
if (nsize < minsize) {
|
||||||
nsize += random_neighbours(r, &rlist, &random_terrain_e3);
|
nsize += random_neighbours(r, &rlist, &random_terrain_e3);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
nsize += random_neighbours(r, &rlist, &get_ocean);
|
nsize += random_neighbours(r, &rlist, &get_ocean);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1047,7 +1052,8 @@ int build_island_e3(int x, int y, int numfactions, int minsize)
|
||||||
prepare_starting_region(r);
|
prepare_starting_region(r);
|
||||||
}
|
}
|
||||||
r->land->money = 50000; /* 2% = 1000 silver */
|
r->land->money = 50000; /* 2% = 1000 silver */
|
||||||
} else if (r->land) {
|
}
|
||||||
|
else if (r->land) {
|
||||||
r->land->money *= 4;
|
r->land->money *= 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue