autoseed, creating island controlled from script.

bugfix empty orders in savefile
This commit is contained in:
Enno Rehling 2005-08-07 13:48:18 +00:00
parent 3b671396c1
commit e639a1258b
8 changed files with 29 additions and 29 deletions

View File

@ -1015,7 +1015,7 @@ void
fwriteorder(FILE * F, const order * ord, const struct locale * lang) fwriteorder(FILE * F, const order * ord, const struct locale * lang)
{ {
write_order(ord, lang, buf, sizeof(buf)); write_order(ord, lang, buf, sizeof(buf));
fwritestr(F, buf); if (buf[0]) fwritestr(F, buf);
} }
unit * unit *
@ -1252,24 +1252,24 @@ writeunit(FILE * F, const unit * u)
fputc(' ', F); fputc(' ', F);
} }
#endif #endif
for (ord = u->orders; ord; ord=ord->next) { for (ord = u->orders; ord; ord=ord->next) {
if (u->old_orders && is_repeated(ord)) continue; /* has new defaults */ if (u->old_orders && is_repeated(ord)) continue; /* has new defaults */
if (is_persistent(ord)) { if (is_persistent(ord)) {
fwriteorder(F, ord, u->faction->locale); fwriteorder(F, ord, u->faction->locale);
fputc(' ', F); fputc(' ', F);
} }
} }
/* write an empty string to terminate the list */ /* write an empty string to terminate the list */
fwriteorder(F, NULL, u->faction->locale); fputs("\"\"", F);
wnl(F); wnl(F);
#if RELEASE_VERSION<NOLASTORDER_VERSION #if RELEASE_VERSION<NOLASTORDER_VERSION
/* the current default order */ /* the current default order */
fwriteorder(F, u->lastorder, u->faction->locale); fwriteorder(F, u->lastorder, u->faction->locale);
wnl(F); wnl(F);
#endif #endif
assert(u->number <= UNIT_MAXSIZE); assert(u->number <= UNIT_MAXSIZE);
assert(u->race); assert(u->race);
for (i=0;i!=u->skill_size;++i) { for (i=0;i!=u->skill_size;++i) {
skill * sv = u->skills+i; skill * sv = u->skills+i;

View File

@ -355,7 +355,6 @@ preferred_terrain(const struct race * rc)
#define REGIONS_PER_FACTION 2 #define REGIONS_PER_FACTION 2
#define PLAYERS_PER_ISLAND 20 #define PLAYERS_PER_ISLAND 20
#define TURNS_PER_ISLAND 3
#define MINFACTIONS 1 #define MINFACTIONS 1
#define MAXAGEDIFF 5 #define MAXAGEDIFF 5
#define VOLCANO_CHANCE 100 #define VOLCANO_CHANCE 100
@ -412,18 +411,18 @@ get_island(region * root, region_list ** rlist)
* returns the number of players placed on the new island. * returns the number of players placed on the new island.
*/ */
int int
autoseed(newfaction ** players, int nsize) autoseed(newfaction ** players, int nsize, boolean new_island)
{ {
short x = 0, y = 0; short x = 0, y = 0;
region * r = NULL; region * r = NULL;
region_list * rlist = NULL; region_list * rlist = NULL;
int rsize, tsize = 0; int rsize, tsize = 0;
int isize = REGIONS_PER_FACTION; /* target size for the island */ int isize = REGIONS_PER_FACTION; /* target size for the island */
int psize = 0; /* players on this island */ int psize = 0; /* players on this island */
if (listlen(*players)<MINFACTIONS) return 0; if (listlen(*players)<MINFACTIONS) return 0;
if (turn % TURNS_PER_ISLAND) { if (!new_island) {
region * rmin = NULL; region * rmin = NULL;
/* find a spot that's adjacent to the previous island, but virgin. /* find a spot that's adjacent to the previous island, but virgin.
* like the last land virgin ocean region adjacent to land. * like the last land virgin ocean region adjacent to land.

View File

@ -32,7 +32,7 @@ typedef struct newfaction {
struct alliance * allies; struct alliance * allies;
} newfaction; } newfaction;
extern int autoseed(newfaction ** players, int nsize); extern int autoseed(newfaction ** players, int nsize, boolean new_island);
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); extern int fix_demand(struct region *r);

View File

@ -166,15 +166,16 @@ race_setscript(const char * rcname, const functor<void>& f)
} }
#define ISLANDSIZE 20 #define ISLANDSIZE 20
#define TURNS_PER_ISLAND 3
static void static void
lua_autoseed(const char * filename) lua_autoseed(const char * filename, bool new_island)
{ {
newfaction * players = read_newfactions(filename); newfaction * players = read_newfactions(filename);
while (players) { while (players) {
int n = listlen(players); int n = listlen(players);
int k = (n+ISLANDSIZE-1)/ISLANDSIZE; int k = (n+ISLANDSIZE-1)/ISLANDSIZE;
k = n / k; k = n / k;
autoseed(&players, k); autoseed(&players, k, new_island || (turn % TURNS_PER_ISLAND)==0);
} }
} }

View File

@ -265,7 +265,7 @@ processturn(char *filename)
int n = listlen(players); int n = listlen(players);
int k = (n+ISLANDSIZE-1)/ISLANDSIZE; int k = (n+ISLANDSIZE-1)/ISLANDSIZE;
k = n / k; k = n / k;
autoseed(&players, k); autoseed(&players, k, true);
} }
score(); score();
remove_unequipped_guarded(); remove_unequipped_guarded();

View File

@ -144,12 +144,12 @@ newfaction * newfactions = NULL;
static void static void
runautoseed(void) runautoseed(void)
{ {
while (newfactions) { while (newfactions) {
int n = listlen(newfactions); int n = listlen(newfactions);
int k = (n+ISLANDSIZE-1)/ISLANDSIZE; int k = (n+ISLANDSIZE-1)/ISLANDSIZE;
k = n / k; k = n / k;
autoseed(&newfactions, k); autoseed(&newfactions, k, true);
} }
} }
void void

View File

@ -40,7 +40,7 @@ function process(orders)
add_equipment("money", 4200); add_equipment("money", 4200);
-- use newfactions file to place out new players -- use newfactions file to place out new players
autoseed(basepath .. "/newfactions") autoseed(basepath .. "/newfactions", true)
write_passwords() write_passwords()
write_reports() write_reports()

View File

@ -82,7 +82,7 @@ function process(orders)
change_locales() change_locales()
-- use newfactions file to place out new players -- use newfactions file to place out new players
autoseed(basepath .. "/newfactions") autoseed(basepath .. "/newfactions", false)
write_passwords() write_passwords()
write_reports() write_reports()