From 278731ec04382fb4eb2f1bba1386024abea04420 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 11 Apr 2002 17:37:06 +0000 Subject: [PATCH] =?UTF-8?q?Automatischer=20Parteienaussetzer=20f=C3=BCr=20?= =?UTF-8?q?den=20Newbie-Testserver.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mapper/autoseed.c | 68 +++++++++++++++++++++++++++++++++++++++++++ src/mapper/mapper.c | 58 +++++++++++++++++++++++------------- 2 files changed, 106 insertions(+), 20 deletions(-) diff --git a/src/mapper/autoseed.c b/src/mapper/autoseed.c index 580d46111..45d450a42 100644 --- a/src/mapper/autoseed.c +++ b/src/mapper/autoseed.c @@ -22,6 +22,7 @@ /* libc includes */ #include #include +#include #include 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; + } + } + } +} + diff --git a/src/mapper/mapper.c b/src/mapper/mapper.c index 71bdecf3b..e90701942 100644 --- a/src/mapper/mapper.c +++ b/src/mapper/mapper.c @@ -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; }