Automatischer Parteienaussetzer für den Newbie-Testserver.

This commit is contained in:
Enno Rehling 2002-04-11 17:37:06 +00:00
parent 589d897622
commit 278731ec04
2 changed files with 106 additions and 20 deletions

View file

@ -22,6 +22,7 @@
/* libc includes */ /* libc includes */
#include <limits.h> #include <limits.h>
#include <memory.h> #include <memory.h>
#include <string.h>
#include <stdlib.h> #include <stdlib.h>
newfaction * newfactions = NULL; newfaction * newfactions = NULL;
@ -260,3 +261,70 @@ autoseed(struct regionlist * rlist)
} }
} }
} }
static terrain_t
preferred_terrain(const struct race * rc)
{
return T_PLAIN;
}
#define REGIONS_PER_FACTION 2
void
mkisland(int nsize)
{
int x, y;
region * r;
regionlist * rlist = NULL;
int rsize;
do {
x = (rand() % 2001) - 1000;
y = (rand() % 2001) - 1000;
r = findregion(x, y);
} while (r!=NULL);
r = new_region(x, y);
terraform(r, T_OCEAN);
add_regionlist(&rlist, r);
rsize = 1;
while (rlist && nsize && newfactions) {
int i = rand() % rsize;
regionlist ** rnext = &rlist;
direction_t d;
while (i--) rnext=&(*rnext)->next;
r = (*rnext)->region;
*rnext = (*rnext)->next;
--rsize;
assert(r->terrain==T_OCEAN);
if (rand() % REGIONS_PER_FACTION == 0) {
newfaction ** nfp, * nextf = newfactions;
terraform(r, preferred_terrain(nextf->race));
addplayer(r, nextf->email, nextf->race, nextf->lang);
/* remove duplicate email addresses */
nfp=&newfactions;
while (*nfp) {
newfaction * nf = *nfp;
if (strcmp(nextf->email, nf->email)==0) {
*nfp = nf->next;
if (nextf!=nf) free(nf);
}
else nfp = &nf->next;
}
--nsize;
}
else {
terraform(r, (terrain_t)((rand() % T_GLACIER)+1));
}
for (d=0;d!=MAXDIRECTIONS;++d) {
region * rn = rconnect(r, d);
if (rn==NULL) {
rn = new_region(r->x + delta_x[d], r->y + delta_y[d]);
terraform(rn, T_OCEAN);
add_regionlist(&rlist, rn);
++rsize;
}
}
}
}

View file

@ -1084,6 +1084,10 @@ movearound(int rx, int ry) {
seed_dropouts(); seed_dropouts();
modified = 1; modified = 1;
break; break;
case 'm':
mkisland(20);
modified = 1;
break;
case 'S': case 'S':
if (modified) if (modified)
if (yes_no(0, "Daten abspeichern?", 'j')) { if (yes_no(0, "Daten abspeichern?", 'j')) {
@ -1477,6 +1481,7 @@ main(int argc, char *argv[])
boolean backup = true; boolean backup = true;
boolean logging = false; boolean logging = false;
boolean readlog = false; boolean readlog = false;
boolean autoseeding = false;
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
@ -1532,6 +1537,9 @@ main(int argc, char *argv[])
case 'r': case 'r':
g_resourcedir = argv[++i]; g_resourcedir = argv[++i];
break; break;
case 'a':
autoseeding = true;
break;
case 'o': case 'o':
strcpy(datafile, argv[++i]); strcpy(datafile, argv[++i]);
break; break;
@ -1605,33 +1613,43 @@ main(int argc, char *argv[])
if (readlog) { if (readlog) {
log_read("mapper.log"); log_read("mapper.log");
} }
if (logging) {
log_start("mapper.log");
log_newstuff();
}
#ifdef OLD_ITEMS #ifdef OLD_ITEMS
make_xref(); make_xref();
#endif #endif
setminmax(); setminmax();
srand(time((time_t *) NULL)); srand(time((time_t *) NULL));
#ifndef WIN32 if (autoseeding) {
signal_init(); while (newfactions) {
#endif int n = listlen(newfactions);
init_win(x, y); int k = (n+19)/20;
k = n / k;
hl=-1; mkisland(k);
Tagged=NULL;
movearound(x, y);
if (logging) log_stop();
if (modified) {
beep();
if (yes_no(0, "Daten wurden modifiziert! Abspeichern?", 'j')) {
remove_empty_units();
writegame(datafile, 1);
} }
remove_empty_units();
writegame(datafile, 1);
} else {
if (logging) {
log_start("mapper.log");
log_newstuff();
}
#ifndef WIN32
signal_init();
#endif
init_win(x, y);
hl=-1;
Tagged=NULL;
movearound(x, y);
if (logging) log_stop();
if (modified) {
beep();
if (yes_no(0, "Daten wurden modifiziert! Abspeichern?", 'j')) {
remove_empty_units();
writegame(datafile, 1);
}
}
Exit(0);
} }
Exit(0);
return 0; return 0;
} }