kingdoms: handling lack of luxuries

This commit is contained in:
Enno Rehling 2005-11-26 00:08:47 +00:00
parent e8a022ae75
commit f0ce33304b
3 changed files with 28 additions and 20 deletions

View File

@ -51,8 +51,17 @@
extern int dice_rand(const char *s);
static int g_maxluxuries = 0;
int
get_maxluxuries()
{
static int maxluxuries = -1;
if (maxluxuries==-1) {
const luxury_type * ltype;
maxluxuries = 0;
for (ltype = luxurytypes;ltype;ltype=ltype->next) ++maxluxuries;
}
return maxluxuries;
}
const short delta_x[MAXDIRECTIONS] =
{
-1, 0, 1, 1, 0, -1
@ -904,7 +913,7 @@ terraform_region(region * r, const terrain_type * terrain)
const luxury_type * type;
int value;
} *trash =NULL, *nb = NULL;
const luxury_type * ltype;
const luxury_type * ltype = NULL;
direction_t d;
int mnr = 0;
@ -935,13 +944,12 @@ terraform_region(region * r, const terrain_type * terrain)
}
}
if (!nb) {
int i;
if (g_maxluxuries==0) {
for (ltype = luxurytypes;ltype;ltype=ltype->next) ++g_maxluxuries;
}
i = rand() % g_maxluxuries;
ltype = luxurytypes;
while (i--) ltype=ltype->next;
int i = get_maxluxuries();
if (i>0) {
i = rand() % i;
ltype = luxurytypes;
while (i--) ltype=ltype->next;
}
} else {
int i = rand() % mnr;
struct surround * srd = nb;

View File

@ -182,6 +182,7 @@ void deathcounts(struct region * r, int delta);
void chaoscounts(struct region * r, int delta);
void setluxuries(struct region * r, const struct luxury_type * sale);
extern int get_maxluxuries();
short rroad(const struct region * r, direction_t d);
void rsetroad(struct region * r, direction_t d, short value);

View File

@ -86,7 +86,6 @@ terrain_create(int climate)
}
static terrain_t newblock[BLOCKSIZE][BLOCKSIZE];
static int g_maxluxuries;
void
block_create(short x1, short y1, int size, char chaotisch, int special, const terrain_type * terrain)
@ -173,16 +172,16 @@ block_create(short x1, short y1, int size, char chaotisch, int special, const te
* Landstriche werden benannt und bevoelkert, und die produkte
* p1 und p2 des Kontinentes werden gesetzt. */
region *r;
int i, i1, i2;
int i, i1 = -1, i2 = -1;
const luxury_type *ltype, *p1 = NULL, *p2=NULL;
if (g_maxluxuries==0) {
for (ltype = luxurytypes;ltype;ltype=ltype->next) ++g_maxluxuries;
}
i1 = (item_t)(rand() % g_maxluxuries);
do {
i2 = (item_t)(rand() % g_maxluxuries);
}
while (i2 == i1);
int maxlux = get_maxluxuries();
if (maxlux>0) {
i1 = (item_t)(rand() % maxlux);
do {
i2 = (item_t)(rand() % maxlux);
}
while (i2 == i1);
}
ltype = luxurytypes;
for (i=0;!p1 || !p2;++i) {
if (i==i1) p1=ltype;