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

View File

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

View File

@ -32,7 +32,7 @@ typedef struct newfaction {
struct alliance * allies;
} 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 void get_island(struct region * root, struct region_list ** rlist);
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 TURNS_PER_ISLAND 3
static void
lua_autoseed(const char * filename)
lua_autoseed(const char * filename, bool new_island)
{
newfaction * players = read_newfactions(filename);
while (players) {
int n = listlen(players);
int k = (n+ISLANDSIZE-1)/ISLANDSIZE;
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 k = (n+ISLANDSIZE-1)/ISLANDSIZE;
k = n / k;
autoseed(&players, k);
autoseed(&players, k, true);
}
score();
remove_unequipped_guarded();

View File

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

View File

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

View File

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