luxusgut-korrektur in neu erschaffenen Inseln.

This commit is contained in:
Enno Rehling 2005-04-11 21:49:30 +00:00
parent 192a52a4b6
commit 61e63eed3c
3 changed files with 255 additions and 243 deletions

View File

@ -16,6 +16,7 @@
/* kernel includes */ /* kernel includes */
#include <kernel/alliance.h> #include <kernel/alliance.h>
#include <kernel/item.h>
#include <kernel/region.h> #include <kernel/region.h>
#include <kernel/plane.h> #include <kernel/plane.h>
#include <kernel/faction.h> #include <kernel/faction.h>
@ -32,6 +33,126 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
static int
count_demand(const region *r)
{
struct demand *dmd;
int c = 0;
if (r->land) {
for (dmd=r->land->demands;dmd;dmd=dmd->next) c++;
}
return c;
}
static int
recurse_regions(region *r, region_list **rlist, boolean(*fun)(const region *r))
{
if (!fun(r)) return 0;
else {
int len = 0;
direction_t d;
region_list * rl = calloc(sizeof(region_list), 1);
rl->next = *rlist;
rl->data = r;
(*rlist) = rl;
fset(r, FL_MARK);
for (d=0;d!=MAXDIRECTIONS;++d) {
region * nr = rconnect(r, d);
if (nr && !fval(nr, FL_MARK)) len += recurse_regions(nr, rlist, fun);
}
return len+1;
}
}
static int maxluxuries = 0;
static boolean
f_nolux(const region * r)
{
if (r->land && count_demand(r) != maxluxuries) return true;
return false;
}
int
fix_demand(region *r)
{
region_list *rl, *rlist = NULL;
static const struct luxury_type **mlux = 0, ** ltypes;
const luxury_type *sale = NULL;
int maxlux = 0;
if (maxluxuries==0) for (sale=luxurytypes;sale;sale=sale->next) {
++maxluxuries;
}
recurse_regions(r, &rlist, f_nolux);
if (mlux==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) {
ltypes[i++] = sale;
}
}
else {
int i;
for (i=0;i!=maxluxuries;++i) mlux[i] = 0;
}
for (rl=rlist;rl;rl=rl->next) {
region * r = rl->data;
direction_t d;
for (d=0;d!=MAXDIRECTIONS;++d) {
region * nr = rconnect(r, d);
if (nr && nr->land && nr->land->demands) {
struct demand * dmd;
for (dmd = nr->land->demands;dmd;dmd=dmd->next) {
if (dmd->value == 0) {
int i;
for (i=0;i!=maxluxuries;++i) {
if (mlux[i]==NULL) {
maxlux = i;
mlux[i] = dmd->type;
break;
} else if (mlux[i]==dmd->type) {
break;
}
}
break;
}
}
}
}
freset(r, FL_MARK); /* undo recursive marker */
}
if (maxlux<2) {
int i;
for (i=maxlux;i!=2;++i) {
int j;
do {
int k = rand() % maxluxuries;
mlux[i] = ltypes[k];
for (j=0;j!=i;++j) {
if (mlux[j]==mlux[i]) break;
}
} while (j!=i);
}
maxlux=2;
}
for (rl=rlist;rl;rl=rl->next) {
region * r = rl->data;
if (!fval(r, RF_CHAOTIC)) {
log_warning(("fixing demand in %s\n", regionname(r, NULL)));
}
setluxuries(r, mlux[rand() % maxlux]);
}
while (rlist) {
rl = rlist->next;
free(rlist);
rlist = rl;
}
return 0;
}
newfaction * newfaction *
read_newfactions(const char * filename) read_newfactions(const char * filename)
{ {
@ -47,10 +168,12 @@ read_newfactions(const char * filename)
if (alliances!=NULL) { if (alliances!=NULL) {
/* email;race;locale;startbonus;subscription;alliance */ /* email;race;locale;startbonus;subscription;alliance */
if (fscanf(F, "%s %s %s %d %d %s %d", email, race, lang, &bonus, &subscription, password, &alliance)<=0) break; if (fscanf(F, "%s %s %s %d %d %s %d", email, race, lang, &bonus,
&subscription, password, &alliance)<=0) break;
} else { } else {
/* email;race;locale;startbonus;subscription */ /* email;race;locale;startbonus;subscription */
if (fscanf(F, "%s %s %s %d %d %s", email, race, lang, &bonus, &subscription, password)<=0) break; if (fscanf(F, "%s %s %s %d %d %s", email, race, lang, &bonus,
&subscription, password)<=0) break;
} }
for (f=factions;f;f=f->next) { for (f=factions;f;f=f->next) {
if (strcmp(f->email, email)==0 && f->subscription) break; if (strcmp(f->email, email)==0 && f->subscription) break;
@ -62,7 +185,8 @@ read_newfactions(const char * filename)
if (nf) continue; if (nf) continue;
nf = calloc(sizeof(newfaction), 1); nf = calloc(sizeof(newfaction), 1);
if (set_email(&nf->email, email)!=0) { if (set_email(&nf->email, email)!=0) {
log_error(("Invalid email address for subscription %s: %s\n", itoa36(subscription), email)); log_error(("Invalid email address for subscription %s: %s\n",
itoa36(subscription), email));
continue; continue;
} }
nf->password = strdup(password); nf->password = strdup(password);
@ -346,7 +470,7 @@ autoseed(newfaction ** players, int nsize)
*/ */
for (r=regions;r;r=r->next) { for (r=regions;r;r=r->next) {
struct plane * p = rplane(r); struct plane * p = rplane(r);
if (r->terrain==T_OCEAN && p==NULL && (rmin==NULL || r->age<=MAXAGEDIFF)) { if (r->terrain==T_OCEAN && p==0 && (rmin==NULL || r->age<=MAXAGEDIFF)) {
direction_t d; direction_t d;
for (d=0;d!=MAXDIRECTIONS;++d) { for (d=0;d!=MAXDIRECTIONS;++d) {
if (rconnect(r, d)==NULL) break; if (rconnect(r, d)==NULL) break;
@ -401,8 +525,8 @@ autoseed(newfaction ** players, int nsize)
isize += REGIONS_PER_FACTION; isize += REGIONS_PER_FACTION;
terraform(r, preferred_terrain(nextf->race)); terraform(r, preferred_terrain(nextf->race));
++tsize; ++tsize;
u = addplayer(r, addfaction(nextf->email, nextf->password, nextf->race, nextf->lang, u = addplayer(r, addfaction(nextf->email, nextf->password, nextf->race,
nextf->subscription)); nextf->lang, nextf->subscription));
u->faction->alliance = nextf->allies; u->faction->alliance = nextf->allies;
/* remove duplicate email addresses */ /* remove duplicate email addresses */
@ -425,6 +549,11 @@ autoseed(newfaction ** players, int nsize)
} }
} }
if (r!=NULL) {
/* reicht das? */
fix_demand(r);
}
if (nsize!=0) { if (nsize!=0) {
log_error(("Could not place all factions on the same island as requested\n")); log_error(("Could not place all factions on the same island as requested\n"));
} }

View File

@ -35,6 +35,7 @@ typedef struct newfaction {
extern int autoseed(newfaction ** players, int nsize); extern int autoseed(newfaction ** players, int nsize);
extern newfaction * read_newfactions(const char * filename); extern newfaction * read_newfactions(const char * filename);
extern void get_island(struct region * root, struct region_list ** rlist); extern void get_island(struct region * root, struct region_list ** rlist);
extern int fix_demand(struct region *r);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -25,6 +25,7 @@
#include <attributes/key.h> #include <attributes/key.h>
#include <attributes/otherfaction.h> #include <attributes/otherfaction.h>
#include <modules/xecmd.h> #include <modules/xecmd.h>
#include <modules/autoseed.h>
/* gamecode includes */ /* gamecode includes */
#include <gamecode/economy.h> #include <gamecode/economy.h>
@ -330,127 +331,6 @@ fix_age(void)
} }
} }
#if 1
static int
count_demand(const region *r)
{
struct demand *dmd;
int c = 0;
if (r->land) {
for (dmd=r->land->demands;dmd;dmd=dmd->next) c++;
}
return c;
}
#endif
static int
recurse_regions(region * r, region_list **rlist, boolean(*fun)(const region * r))
{
if (!fun(r)) return 0;
else {
int len = 0;
direction_t d;
region_list * rl = calloc(sizeof(region_list), 1);
rl->next = *rlist;
rl->data = r;
(*rlist) = rl;
fset(r, FL_MARK);
for (d=0;d!=MAXDIRECTIONS;++d) {
region * nr = rconnect(r, d);
if (nr && !fval(nr, FL_MARK)) len += recurse_regions(nr, rlist, fun);
}
return len+1;
}
}
#if 1
static int maxluxuries = 0;
static boolean
f_nolux(const region * r)
{
if (r->land && count_demand(r) != maxluxuries) return true;
return false;
}
static int
fix_demand_region(region *r)
{
region_list *rl, *rlist = NULL;
static const luxury_type **mlux = 0, ** ltypes;
const luxury_type *sale = NULL;
int maxlux = 0;
recurse_regions(r, &rlist, f_nolux);
if (mlux==0) {
int i = 0;
if (maxluxuries==0) for (sale=luxurytypes;sale;sale=sale->next) {
maxluxuries++;
}
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) {
ltypes[i++] = sale;
}
}
else {
int i;
for (i=0;i!=maxluxuries;++i) mlux[i] = 0;
}
for (rl=rlist;rl;rl=rl->next) {
region * r = rl->data;
direction_t d;
for (d=0;d!=MAXDIRECTIONS;++d) {
region * nr = rconnect(r, d);
if (nr && nr->land && nr->land->demands) {
struct demand * dmd;
for (dmd = nr->land->demands;dmd;dmd=dmd->next) {
if (dmd->value == 0) {
int i;
for (i=0;i!=maxluxuries;++i) {
if (mlux[i]==NULL) {
maxlux = i;
mlux[i] = dmd->type;
break;
} else if (mlux[i]==dmd->type) {
break;
}
}
break;
}
}
}
}
freset(r, FL_MARK); /* undo recursive marker */
}
if (maxlux<2) {
int i;
for (i=maxlux;i!=2;++i) {
int j;
do {
int k = rand() % maxluxuries;
mlux[i] = ltypes[k];
for (j=0;j!=i;++j) {
if (mlux[j]==mlux[i]) break;
}
} while (j!=i);
}
maxlux=2;
}
for (rl=rlist;rl;rl=rl->next) {
region * r = rl->data;
if (!fval(r, RF_CHAOTIC)) log_warning(("fixing demand in %s\n", regionname(r, NULL)));
setluxuries(r, mlux[rand() % maxlux]);
}
while (rlist) {
rl = rlist->next;
free(rlist);
rlist = rl;
}
return 0;
}
#endif
static void static void
fix_firewalls(void) fix_firewalls(void)
@ -532,9 +412,10 @@ update_gms(void)
} }
} }
#if 1 static int maxluxuries = 0;
static int static int
fix_demand(void) fix_demands(void)
{ {
region *r; region *r;
const luxury_type *sale = NULL; const luxury_type *sale = NULL;
@ -542,13 +423,14 @@ fix_demand(void)
if (maxluxuries==0) for (sale=luxurytypes;sale;sale=sale->next) ++maxluxuries; if (maxluxuries==0) for (sale=luxurytypes;sale;sale=sale->next) ++maxluxuries;
for (r=regions; r; r=r->next) { for (r=regions; r; r=r->next) {
if (r->land!=NULL && r->land->peasants>=100 && count_demand(r) != maxluxuries) { if (r->land!=NULL && r->land->peasants>=100) {
fix_demand_region(r); if (count_demand(r) != maxluxuries) {
fix_demand(r);
}
} }
} }
return 0; return 0;
} }
#endif
#include "group.h" #include "group.h"
static void static void
@ -1114,7 +996,7 @@ korrektur(void)
/* seems something fishy is going on, do this just /* seems something fishy is going on, do this just
* to be on the safe side: * to be on the safe side:
*/ */
fix_demand(); fix_demands();
fix_otherfaction(); fix_otherfaction();
/* trade_orders(); */ /* trade_orders(); */