it is not a good idea to use the turn to check whether the gamedata has changed. we use a cookie instead that is different each time we load.

This commit is contained in:
Enno Rehling 2008-05-22 21:44:23 +00:00
parent 644d0d9a4a
commit 88ce120991
17 changed files with 41 additions and 54 deletions

View File

@ -2544,14 +2544,14 @@ breedtrees(region *r, unit *u, int raw)
{ {
int n, i, skill, planted = 0; int n, i, skill, planted = 0;
const resource_type * rtype; const resource_type * rtype;
static int thisturn = -1; static int gamecookie = -1;
static int current_season; static int current_season;
if (thisturn!=turn) { if (gamecookie!=global.cookie) {
gamedate date; gamedate date;
get_gamedate(turn, &date); get_gamedate(turn, &date);
current_season = date.season; current_season = date.season;
thisturn = turn; gamecookie = global.cookie;
} }
/* Bäume züchten geht nur im Frühling */ /* Bäume züchten geht nur im Frühling */

View File

@ -3746,15 +3746,6 @@ static void maintain_buildings_1(region * r) { maintain_buildings(r, false); }
static void maintain_buildings_2(region * r) { maintain_buildings(r,true); } static void maintain_buildings_2(region * r) { maintain_buildings(r,true); }
static void reset_moved(unit * u) { freset(u, UFL_MOVED); } static void reset_moved(unit * u) { freset(u, UFL_MOVED); }
static void reset_rng(void) {
rng_init(turn?turn:(int)time(0));
}
static void reset_rng_region(region * r)
{
rng_init(r->index+turn);
}
/** warn about passwords that are not US ASCII. /** warn about passwords that are not US ASCII.
* even though passwords are technically UTF8 strings, the server receives * even though passwords are technically UTF8 strings, the server receives
* them as part of the Subject of an email when reports are requested. * them as part of the Subject of an email when reports are requested.
@ -3851,7 +3842,6 @@ init_processor(void)
} }
p+=10; /* after combat, reset rng */ p+=10; /* after combat, reset rng */
add_proc_global(p, &reset_rng, NULL);
add_proc_region(p, &do_siege, "Belagern"); add_proc_region(p, &do_siege, "Belagern");
p+=10; /* can't allow reserve before siege (weapons) */ p+=10; /* can't allow reserve before siege (weapons) */
@ -3860,7 +3850,6 @@ init_processor(void)
add_proc_unit(p, &follow_unit, "Folge auf Einheiten setzen"); add_proc_unit(p, &follow_unit, "Folge auf Einheiten setzen");
p+=10; /* rest rng again before economics */ p+=10; /* rest rng again before economics */
add_proc_global(p, &reset_rng, NULL);
add_proc_region(p, &economics, "Zerstoeren, Geben, Rekrutieren, Vergessen"); add_proc_region(p, &economics, "Zerstoeren, Geben, Rekrutieren, Vergessen");
p+=10; p+=10;
@ -3878,7 +3867,6 @@ init_processor(void)
add_proc_order(p, K_TEACH, &teach_cmd, PROC_THISORDER|PROC_LONGORDER, "Lehren"); add_proc_order(p, K_TEACH, &teach_cmd, PROC_THISORDER|PROC_LONGORDER, "Lehren");
} }
p+=10; p+=10;
add_proc_region(p, &reset_rng_region, NULL);
add_proc_order(p, K_STUDY, &learn_cmd, PROC_THISORDER|PROC_LONGORDER, "Lernen"); add_proc_order(p, K_STUDY, &learn_cmd, PROC_THISORDER|PROC_LONGORDER, "Lernen");
p+=10; p+=10;
@ -3905,7 +3893,6 @@ init_processor(void)
p+=10; p+=10;
add_proc_global(p, &encounters, "Zufallsbegegnungen"); add_proc_global(p, &encounters, "Zufallsbegegnungen");
p+=10; p+=10;
add_proc_global(p, &reset_rng, NULL);
add_proc_unit(p, &monsters_kill_peasants, "Monster fressen und vertreiben Bauern"); add_proc_unit(p, &monsters_kill_peasants, "Monster fressen und vertreiben Bauern");
p+=10; p+=10;

View File

@ -1921,14 +1921,14 @@ report_plaintext(const char * filename, report_context * ctx, const char * chars
/* static variables can cope with writing for different turns */ /* static variables can cope with writing for different turns */
static int thisseason = -1; static int thisseason = -1;
static int nextseason = -1; static int nextseason = -1;
static int thisturn = -1; static int gamecookie = -1;
if (thisturn!=turn) { if (gamecookie!=global.cookie) {
gamedate date; gamedate date;
get_gamedate(turn+1, &date); get_gamedate(turn+1, &date);
thisseason = date.season; thisseason = date.season;
get_gamedate(turn+2, &date); get_gamedate(turn+2, &date);
nextseason = date.season; nextseason = date.season;
thisturn = turn; gamecookie = global.cookie;
} }
if (F==NULL) { if (F==NULL) {

View File

@ -92,7 +92,7 @@
/* exported variables */ /* exported variables */
region *regions; region *regions;
faction *factions; faction *factions;
settings global; settings global = { 0 };
FILE *logfile; FILE *logfile;
FILE *updatelog; FILE *updatelog;
const struct race * new_race[MAXRACES]; const struct race * new_race[MAXRACES];
@ -2502,10 +2502,10 @@ lifestyle(const unit * u)
{ {
int need; int need;
static plane * astralspace; static plane * astralspace;
static int thisturn = -1; static int gamecookie = -1;
if (thisturn!=turn) { if (gamecookie!=global.cookie) {
astralspace = getplanebyname("Astralraum"); astralspace = getplanebyname("Astralraum");
thisturn = turn; gamecookie = global.cookie;
} }
if (is_monsters(u->faction)) return 0; if (is_monsters(u->faction)) return 0;
@ -2972,7 +2972,6 @@ kernel_init(void)
translation_init(); translation_init();
if (!turn) turn = lastturn(); if (!turn) turn = lastturn();
rng_init(turn?turn:(int)time(0));
if (sqlpatch) { if (sqlpatch) {
sprintf(zBuffer, "%s/patch-%d.sql", datapath(), turn); sprintf(zBuffer, "%s/patch-%d.sql", datapath(), turn);
sql_init(zBuffer); sql_init(zBuffer);
@ -3031,4 +3030,5 @@ free_gamedata(void)
while (global.attribs) { while (global.attribs) {
a_remove(&global.attribs, global.attribs); a_remove(&global.attribs, global.attribs);
} }
} ++global.cookie; /* readgame() already does this, but sjust in case */
}

View File

@ -369,11 +369,12 @@ extern const struct race * new_race[];
/* globale settings des Spieles */ /* globale settings des Spieles */
typedef struct settings { typedef struct settings {
const char *gamename; int cookie;
boolean unitsperalliance; const char *gamename;
unsigned int maxunits; boolean unitsperalliance;
unsigned int maxunits;
struct attrib *attribs; struct attrib *attribs;
unsigned int data_turn; unsigned int data_turn;
boolean disabled[MAXKEYWORDS]; boolean disabled[MAXKEYWORDS];
struct param * parameters; struct param * parameters;
void * vm_state; void * vm_state;

View File

@ -51,10 +51,10 @@ faction *
get_monsters(void) get_monsters(void)
{ {
static faction * monsters; static faction * monsters;
static int thisturn = -1; static int gamecookie = -1;
if (thisturn!=turn) { if (gamecookie!=global.cookie) {
monsters = NULL; monsters = NULL;
thisturn = turn; gamecookie = global.cookie;
} }
if (!monsters) { if (!monsters) {

View File

@ -880,14 +880,14 @@ is_guarded(region * r, unit * u, unsigned int mask)
unit *u2 = NULL; unit *u2 = NULL;
int i; int i;
static unit * guardcache[MAXGUARDCACHE], * lastguard; /* STATIC_XCALL: used across calls */ static unit * guardcache[MAXGUARDCACHE], * lastguard; /* STATIC_XCALL: used across calls */
static int thisturn = -1; static int gamecookie = -1;
if (thisturn!=turn) { if (gamecookie!=global.cookie) {
if (thisturn>=0) { if (gamecookie>=0) {
/* clear the previous turn's cache */ /* clear the previous turn's cache */
memset(guardcache, 0, sizeof(guardcache)); memset(guardcache, 0, sizeof(guardcache));
lastguard = NULL; lastguard = NULL;
} }
thisturn = turn; gamecookie = global.cookie;
} }
if (!fval(r, RF_GUARDED)) { if (!fval(r, RF_GUARDED)) {
@ -1649,13 +1649,13 @@ sail(unit * u, order * ord, boolean move_on_land, region_list **routep)
if (!flying_ship(sh)) { if (!flying_ship(sh)) {
int stormchance; int stormchance;
static int stormyness; static int stormyness;
static int thisturn = -1; static int gamecookie = -1;
if (thisturn != turn) { if (gamecookie != global.cookie) {
gamedate date; gamedate date;
get_gamedate(turn, &date); get_gamedate(turn, &date);
stormyness = storms[date.month] * 5; stormyness = storms[date.month] * 5;
thisturn = turn; gamecookie = global.cookie;
} }
/* storms should be the first thing we do. */ /* storms should be the first thing we do. */

View File

@ -1376,7 +1376,7 @@ readgame(const char * filename, int mode, int backup)
const struct building_type * bt_lighthouse = bt_find("lighthouse"); const struct building_type * bt_lighthouse = bt_find("lighthouse");
storage my_store = (mode==IO_BINARY)?binary_store:text_store; storage my_store = (mode==IO_BINARY)?binary_store:text_store;
storage * store = &my_store; storage * store = &my_store;
sprintf(path, "%s/%s", datapath(), filename); sprintf(path, "%s/%s", datapath(), filename);
log_printf("- reading game data from %s\n", filename); log_printf("- reading game data from %s\n", filename);
if (backup) create_backup(path); if (backup) create_backup(path);
@ -1411,6 +1411,7 @@ readgame(const char * filename, int mode, int backup)
a_read(store, &global.attribs); a_read(store, &global.attribs);
global.data_turn = turn = store->r_int(store); global.data_turn = turn = store->r_int(store);
rng_init(turn); rng_init(turn);
++global.cookie;
store->r_int(store); /* max_unique_id = */ store->r_int(store); /* max_unique_id = */
nextborder = store->r_int(store); nextborder = store->r_int(store);

View File

@ -164,10 +164,10 @@ plane *
get_astralplane(void) get_astralplane(void)
{ {
static plane * astralspace; static plane * astralspace;
static int thisturn = -1; static int gamecookie = -1;
if (thisturn!=turn) { if (gamecookie!=global.cookie) {
astralspace = getplanebyname("Astralraum"); astralspace = getplanebyname("Astralraum");
thisturn = turn; gamecookie = global.cookie;
} }
if (astralspace==NULL) { if (astralspace==NULL) {

View File

@ -24,7 +24,6 @@ seed_players(const char * filename, boolean new_island)
{ {
newfaction * players = read_newfactions(filename); newfaction * players = read_newfactions(filename);
if (players!=NULL) { if (players!=NULL) {
rng_init(players->subscription);
while (players) { while (players) {
int n = listlen(players); int n = listlen(players);
int k = (n+ISLANDSIZE-1)/ISLANDSIZE; int k = (n+ISLANDSIZE-1)/ISLANDSIZE;

View File

@ -75,6 +75,7 @@
#include <util/log.h> #include <util/log.h>
#include <util/rand.h> #include <util/rand.h>
#include <util/resolve.h> #include <util/resolve.h>
#include <util/rng.h>
#include <util/sql.h> #include <util/sql.h>
#include <util/vset.h> #include <util/vset.h>
@ -883,6 +884,7 @@ fix_groups(void)
void void
korrektur(void) korrektur(void)
{ {
int i = rng_int();
#if GLOBAL_WARMING #if GLOBAL_WARMING
gamedate date; gamedate date;
get_gamedate(turn, &date); get_gamedate(turn, &date);

View File

@ -130,7 +130,6 @@ lua_autoseed(const char * filename, bool new_island)
{ {
newfaction * players = read_newfactions(filename); newfaction * players = read_newfactions(filename);
if (players!=NULL) { if (players!=NULL) {
rng_init(players->subscription);
while (players) { while (players) {
int n = listlen(players); int n = listlen(players);
int k = (n+ISLANDSIZE-1)/ISLANDSIZE; int k = (n+ISLANDSIZE-1)/ISLANDSIZE;

View File

@ -67,7 +67,6 @@ lua_planmonsters(void)
faction * f = get_monsters(); faction * f = get_monsters();
if (f==NULL) return; if (f==NULL) return;
rng_init(turn?turn:(int)time(0));
plan_monsters(); plan_monsters();
for (u=f->units;u;u=u->nextF) { for (u=f->units;u;u=u->nextF) {
call_script(u); call_script(u);
@ -207,7 +206,6 @@ readshortpwds()
static int static int
process_orders(void) process_orders(void)
{ {
rng_init(turn?turn:(int)time(0));
#ifdef SHORTPWDS #ifdef SHORTPWDS
readshortpwds("passwords"); readshortpwds("passwords");
#endif #endif

View File

@ -26,7 +26,7 @@ function change_locales()
end end
end end
function run_scripts() function load_scripts()
scripts = { scripts = {
"spells.lua", "spells.lua",
"extensions.lua", "extensions.lua",
@ -35,8 +35,8 @@ function run_scripts()
"eressea/wedding-jadee.lua", "eressea/wedding-jadee.lua",
"eressea/ponnuki.lua", "eressea/ponnuki.lua",
"eressea/items.lua", "eressea/items.lua",
"eressea/xmas2004.lua",
"eressea/10years.lua", "eressea/10years.lua",
"eressea/xmas2004.lua",
"eressea/xmas2005.lua", "eressea/xmas2005.lua",
"eressea/xmas2006.lua", "eressea/xmas2006.lua",
"eressea/embassy.lua", "eressea/embassy.lua",
@ -61,7 +61,7 @@ function process(orders)
init_summary() init_summary()
-- kill multi-players (external script) -- kill multi-players (external script)
loadscript("eressea/multis.lua") -- loadscript("eressea/multis.lua")
-- run the turn: -- run the turn:
set_encoding("utf8") set_encoding("utf8")
@ -69,7 +69,6 @@ function process(orders)
print("could not read " .. orders) print("could not read " .. orders)
return -1 return -1
end end
run_scripts()
plan_monsters() plan_monsters()
@ -114,6 +113,7 @@ end
-- --
-- orderfile: contains the name of the orders. -- orderfile: contains the name of the orders.
load_scripts()
if orderfile==nil then if orderfile==nil then
print "you must specify an orderfile" print "you must specify an orderfile"
else else

View File

@ -22,4 +22,4 @@ function xmas2004()
end end
end end
xmas2004() -- xmas2004()

View File

@ -28,4 +28,4 @@ function xmas2005()
end end
end end
xmas2005() -- xmas2005()

View File

@ -51,4 +51,4 @@ function xmas2006()
end end
end end
xmas2006() -- xmas2006()