forked from github/server
kingdoms: handling lack of luxuries
This commit is contained in:
parent
e8a022ae75
commit
f0ce33304b
|
@ -51,8 +51,17 @@
|
||||||
|
|
||||||
extern int dice_rand(const char *s);
|
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] =
|
const short delta_x[MAXDIRECTIONS] =
|
||||||
{
|
{
|
||||||
-1, 0, 1, 1, 0, -1
|
-1, 0, 1, 1, 0, -1
|
||||||
|
@ -904,7 +913,7 @@ terraform_region(region * r, const terrain_type * terrain)
|
||||||
const luxury_type * type;
|
const luxury_type * type;
|
||||||
int value;
|
int value;
|
||||||
} *trash =NULL, *nb = NULL;
|
} *trash =NULL, *nb = NULL;
|
||||||
const luxury_type * ltype;
|
const luxury_type * ltype = NULL;
|
||||||
direction_t d;
|
direction_t d;
|
||||||
int mnr = 0;
|
int mnr = 0;
|
||||||
|
|
||||||
|
@ -935,13 +944,12 @@ terraform_region(region * r, const terrain_type * terrain)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!nb) {
|
if (!nb) {
|
||||||
int i;
|
int i = get_maxluxuries();
|
||||||
if (g_maxluxuries==0) {
|
if (i>0) {
|
||||||
for (ltype = luxurytypes;ltype;ltype=ltype->next) ++g_maxluxuries;
|
i = rand() % i;
|
||||||
}
|
ltype = luxurytypes;
|
||||||
i = rand() % g_maxluxuries;
|
while (i--) ltype=ltype->next;
|
||||||
ltype = luxurytypes;
|
}
|
||||||
while (i--) ltype=ltype->next;
|
|
||||||
} else {
|
} else {
|
||||||
int i = rand() % mnr;
|
int i = rand() % mnr;
|
||||||
struct surround * srd = nb;
|
struct surround * srd = nb;
|
||||||
|
|
|
@ -182,6 +182,7 @@ void deathcounts(struct region * r, int delta);
|
||||||
void chaoscounts(struct region * r, int delta);
|
void chaoscounts(struct region * r, int delta);
|
||||||
|
|
||||||
void setluxuries(struct region * r, const struct luxury_type * sale);
|
void setluxuries(struct region * r, const struct luxury_type * sale);
|
||||||
|
extern int get_maxluxuries();
|
||||||
|
|
||||||
short rroad(const struct region * r, direction_t d);
|
short rroad(const struct region * r, direction_t d);
|
||||||
void rsetroad(struct region * r, direction_t d, short value);
|
void rsetroad(struct region * r, direction_t d, short value);
|
||||||
|
|
|
@ -86,7 +86,6 @@ terrain_create(int climate)
|
||||||
}
|
}
|
||||||
|
|
||||||
static terrain_t newblock[BLOCKSIZE][BLOCKSIZE];
|
static terrain_t newblock[BLOCKSIZE][BLOCKSIZE];
|
||||||
static int g_maxluxuries;
|
|
||||||
|
|
||||||
void
|
void
|
||||||
block_create(short x1, short y1, int size, char chaotisch, int special, const terrain_type * terrain)
|
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
|
* Landstriche werden benannt und bevoelkert, und die produkte
|
||||||
* p1 und p2 des Kontinentes werden gesetzt. */
|
* p1 und p2 des Kontinentes werden gesetzt. */
|
||||||
region *r;
|
region *r;
|
||||||
int i, i1, i2;
|
int i, i1 = -1, i2 = -1;
|
||||||
const luxury_type *ltype, *p1 = NULL, *p2=NULL;
|
const luxury_type *ltype, *p1 = NULL, *p2=NULL;
|
||||||
if (g_maxluxuries==0) {
|
int maxlux = get_maxluxuries();
|
||||||
for (ltype = luxurytypes;ltype;ltype=ltype->next) ++g_maxluxuries;
|
if (maxlux>0) {
|
||||||
}
|
i1 = (item_t)(rand() % maxlux);
|
||||||
i1 = (item_t)(rand() % g_maxluxuries);
|
do {
|
||||||
do {
|
i2 = (item_t)(rand() % maxlux);
|
||||||
i2 = (item_t)(rand() % g_maxluxuries);
|
}
|
||||||
}
|
while (i2 == i1);
|
||||||
while (i2 == i1);
|
}
|
||||||
ltype = luxurytypes;
|
ltype = luxurytypes;
|
||||||
for (i=0;!p1 || !p2;++i) {
|
for (i=0;!p1 || !p2;++i) {
|
||||||
if (i==i1) p1=ltype;
|
if (i==i1) p1=ltype;
|
||||||
|
|
Loading…
Reference in New Issue