forked from github/server
Automatischer Parteienaussetzer für den Newbie-Testserver.
This commit is contained in:
parent
589d897622
commit
278731ec04
2 changed files with 106 additions and 20 deletions
|
@ -22,6 +22,7 @@
|
|||
/* libc includes */
|
||||
#include <limits.h>
|
||||
#include <memory.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1084,6 +1084,10 @@ movearound(int rx, int ry) {
|
|||
seed_dropouts();
|
||||
modified = 1;
|
||||
break;
|
||||
case 'm':
|
||||
mkisland(20);
|
||||
modified = 1;
|
||||
break;
|
||||
case 'S':
|
||||
if (modified)
|
||||
if (yes_no(0, "Daten abspeichern?", 'j')) {
|
||||
|
@ -1477,6 +1481,7 @@ main(int argc, char *argv[])
|
|||
boolean backup = true;
|
||||
boolean logging = false;
|
||||
boolean readlog = false;
|
||||
boolean autoseeding = false;
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
|
@ -1532,6 +1537,9 @@ main(int argc, char *argv[])
|
|||
case 'r':
|
||||
g_resourcedir = argv[++i];
|
||||
break;
|
||||
case 'a':
|
||||
autoseeding = true;
|
||||
break;
|
||||
case 'o':
|
||||
strcpy(datafile, argv[++i]);
|
||||
break;
|
||||
|
@ -1605,33 +1613,43 @@ main(int argc, char *argv[])
|
|||
if (readlog) {
|
||||
log_read("mapper.log");
|
||||
}
|
||||
if (logging) {
|
||||
log_start("mapper.log");
|
||||
log_newstuff();
|
||||
}
|
||||
#ifdef OLD_ITEMS
|
||||
make_xref();
|
||||
#endif
|
||||
setminmax();
|
||||
srand(time((time_t *) NULL));
|
||||
|
||||
#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);
|
||||
if (autoseeding) {
|
||||
while (newfactions) {
|
||||
int n = listlen(newfactions);
|
||||
int k = (n+19)/20;
|
||||
k = n / k;
|
||||
mkisland(k);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue