diff --git a/src/common/gamecode/economy.c b/src/common/gamecode/economy.c index f27c34a8c..166a0d89f 100644 --- a/src/common/gamecode/economy.c +++ b/src/common/gamecode/economy.c @@ -2544,14 +2544,14 @@ breedtrees(region *r, unit *u, int raw) { int n, i, skill, planted = 0; const resource_type * rtype; - static int thisturn = -1; + static int gamecookie = -1; static int current_season; - if (thisturn!=turn) { + if (gamecookie!=global.cookie) { gamedate date; get_gamedate(turn, &date); current_season = date.season; - thisturn = turn; + gamecookie = global.cookie; } /* Bäume züchten geht nur im Frühling */ diff --git a/src/common/gamecode/laws.c b/src/common/gamecode/laws.c index 77349dc65..5feb5dc0b 100644 --- a/src/common/gamecode/laws.c +++ b/src/common/gamecode/laws.c @@ -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 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. * even though passwords are technically UTF8 strings, the server receives * 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 */ - add_proc_global(p, &reset_rng, NULL); add_proc_region(p, &do_siege, "Belagern"); 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"); p+=10; /* rest rng again before economics */ - add_proc_global(p, &reset_rng, NULL); add_proc_region(p, &economics, "Zerstoeren, Geben, Rekrutieren, Vergessen"); p+=10; @@ -3878,7 +3867,6 @@ init_processor(void) add_proc_order(p, K_TEACH, &teach_cmd, PROC_THISORDER|PROC_LONGORDER, "Lehren"); } p+=10; - add_proc_region(p, &reset_rng_region, NULL); add_proc_order(p, K_STUDY, &learn_cmd, PROC_THISORDER|PROC_LONGORDER, "Lernen"); p+=10; @@ -3905,7 +3893,6 @@ init_processor(void) p+=10; add_proc_global(p, &encounters, "Zufallsbegegnungen"); p+=10; - add_proc_global(p, &reset_rng, NULL); add_proc_unit(p, &monsters_kill_peasants, "Monster fressen und vertreiben Bauern"); p+=10; diff --git a/src/common/gamecode/report.c b/src/common/gamecode/report.c index 6e5db4dc3..71fe07256 100644 --- a/src/common/gamecode/report.c +++ b/src/common/gamecode/report.c @@ -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 int thisseason = -1; static int nextseason = -1; - static int thisturn = -1; - if (thisturn!=turn) { + static int gamecookie = -1; + if (gamecookie!=global.cookie) { gamedate date; get_gamedate(turn+1, &date); thisseason = date.season; get_gamedate(turn+2, &date); nextseason = date.season; - thisturn = turn; + gamecookie = global.cookie; } if (F==NULL) { diff --git a/src/common/kernel/eressea.c b/src/common/kernel/eressea.c index 97d2952ec..ce85776b8 100644 --- a/src/common/kernel/eressea.c +++ b/src/common/kernel/eressea.c @@ -92,7 +92,7 @@ /* exported variables */ region *regions; faction *factions; -settings global; +settings global = { 0 }; FILE *logfile; FILE *updatelog; const struct race * new_race[MAXRACES]; @@ -2502,10 +2502,10 @@ lifestyle(const unit * u) { int need; static plane * astralspace; - static int thisturn = -1; - if (thisturn!=turn) { + static int gamecookie = -1; + if (gamecookie!=global.cookie) { astralspace = getplanebyname("Astralraum"); - thisturn = turn; + gamecookie = global.cookie; } if (is_monsters(u->faction)) return 0; @@ -2972,7 +2972,6 @@ kernel_init(void) translation_init(); if (!turn) turn = lastturn(); - rng_init(turn?turn:(int)time(0)); if (sqlpatch) { sprintf(zBuffer, "%s/patch-%d.sql", datapath(), turn); sql_init(zBuffer); @@ -3031,4 +3030,5 @@ free_gamedata(void) while (global.attribs) { a_remove(&global.attribs, global.attribs); } -} \ No newline at end of file + ++global.cookie; /* readgame() already does this, but sjust in case */ +} diff --git a/src/common/kernel/eressea.h b/src/common/kernel/eressea.h index 9059149e5..32c326566 100644 --- a/src/common/kernel/eressea.h +++ b/src/common/kernel/eressea.h @@ -369,11 +369,12 @@ extern const struct race * new_race[]; /* globale settings des Spieles */ typedef struct settings { - const char *gamename; - boolean unitsperalliance; - unsigned int maxunits; + int cookie; + const char *gamename; + boolean unitsperalliance; + unsigned int maxunits; struct attrib *attribs; - unsigned int data_turn; + unsigned int data_turn; boolean disabled[MAXKEYWORDS]; struct param * parameters; void * vm_state; diff --git a/src/common/kernel/faction.c b/src/common/kernel/faction.c index 5420b6592..22200c108 100644 --- a/src/common/kernel/faction.c +++ b/src/common/kernel/faction.c @@ -51,10 +51,10 @@ faction * get_monsters(void) { static faction * monsters; - static int thisturn = -1; - if (thisturn!=turn) { + static int gamecookie = -1; + if (gamecookie!=global.cookie) { monsters = NULL; - thisturn = turn; + gamecookie = global.cookie; } if (!monsters) { diff --git a/src/common/kernel/move.c b/src/common/kernel/move.c index 414517707..80c353b92 100644 --- a/src/common/kernel/move.c +++ b/src/common/kernel/move.c @@ -880,14 +880,14 @@ is_guarded(region * r, unit * u, unsigned int mask) unit *u2 = NULL; int i; static unit * guardcache[MAXGUARDCACHE], * lastguard; /* STATIC_XCALL: used across calls */ - static int thisturn = -1; - if (thisturn!=turn) { - if (thisturn>=0) { + static int gamecookie = -1; + if (gamecookie!=global.cookie) { + if (gamecookie>=0) { /* clear the previous turn's cache */ memset(guardcache, 0, sizeof(guardcache)); lastguard = NULL; } - thisturn = turn; + gamecookie = global.cookie; } 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)) { int stormchance; static int stormyness; - static int thisturn = -1; + static int gamecookie = -1; - if (thisturn != turn) { + if (gamecookie != global.cookie) { gamedate date; get_gamedate(turn, &date); stormyness = storms[date.month] * 5; - thisturn = turn; + gamecookie = global.cookie; } /* storms should be the first thing we do. */ diff --git a/src/common/kernel/save.c b/src/common/kernel/save.c index 12d8bce56..16d02f5c4 100644 --- a/src/common/kernel/save.c +++ b/src/common/kernel/save.c @@ -1376,7 +1376,7 @@ readgame(const char * filename, int mode, int backup) const struct building_type * bt_lighthouse = bt_find("lighthouse"); storage my_store = (mode==IO_BINARY)?binary_store:text_store; storage * store = &my_store; - + sprintf(path, "%s/%s", datapath(), filename); log_printf("- reading game data from %s\n", filename); if (backup) create_backup(path); @@ -1411,6 +1411,7 @@ readgame(const char * filename, int mode, int backup) a_read(store, &global.attribs); global.data_turn = turn = store->r_int(store); rng_init(turn); + ++global.cookie; store->r_int(store); /* max_unique_id = */ nextborder = store->r_int(store); diff --git a/src/common/kernel/teleport.c b/src/common/kernel/teleport.c index 0723496c2..d4f4565b2 100644 --- a/src/common/kernel/teleport.c +++ b/src/common/kernel/teleport.c @@ -164,10 +164,10 @@ plane * get_astralplane(void) { static plane * astralspace; - static int thisturn = -1; - if (thisturn!=turn) { + static int gamecookie = -1; + if (gamecookie!=global.cookie) { astralspace = getplanebyname("Astralraum"); - thisturn = turn; + gamecookie = global.cookie; } if (astralspace==NULL) { diff --git a/src/eressea/editing.c b/src/eressea/editing.c index 0c516ca5c..cf76382c1 100644 --- a/src/eressea/editing.c +++ b/src/eressea/editing.c @@ -24,7 +24,6 @@ seed_players(const char * filename, boolean new_island) { newfaction * players = read_newfactions(filename); if (players!=NULL) { - rng_init(players->subscription); while (players) { int n = listlen(players); int k = (n+ISLANDSIZE-1)/ISLANDSIZE; diff --git a/src/eressea/korrektur.c b/src/eressea/korrektur.c index 03a5e22ae..bca842e25 100644 --- a/src/eressea/korrektur.c +++ b/src/eressea/korrektur.c @@ -75,6 +75,7 @@ #include #include #include +#include #include #include @@ -883,6 +884,7 @@ fix_groups(void) void korrektur(void) { + int i = rng_int(); #if GLOBAL_WARMING gamedate date; get_gamedate(turn, &date); diff --git a/src/eressea/lua/eressea.cpp b/src/eressea/lua/eressea.cpp index 5d3ac5381..9af304270 100644 --- a/src/eressea/lua/eressea.cpp +++ b/src/eressea/lua/eressea.cpp @@ -130,7 +130,6 @@ lua_autoseed(const char * filename, bool new_island) { newfaction * players = read_newfactions(filename); if (players!=NULL) { - rng_init(players->subscription); while (players) { int n = listlen(players); int k = (n+ISLANDSIZE-1)/ISLANDSIZE; diff --git a/src/eressea/lua/gamecode.cpp b/src/eressea/lua/gamecode.cpp index 71f1224ba..3a44bd32b 100644 --- a/src/eressea/lua/gamecode.cpp +++ b/src/eressea/lua/gamecode.cpp @@ -67,7 +67,6 @@ lua_planmonsters(void) faction * f = get_monsters(); if (f==NULL) return; - rng_init(turn?turn:(int)time(0)); plan_monsters(); for (u=f->units;u;u=u->nextF) { call_script(u); @@ -207,7 +206,6 @@ readshortpwds() static int process_orders(void) { - rng_init(turn?turn:(int)time(0)); #ifdef SHORTPWDS readshortpwds("passwords"); #endif diff --git a/src/scripts/eressea.lua b/src/scripts/eressea.lua index 2b167fc31..e2d3bd782 100644 --- a/src/scripts/eressea.lua +++ b/src/scripts/eressea.lua @@ -26,7 +26,7 @@ function change_locales() end end -function run_scripts() +function load_scripts() scripts = { "spells.lua", "extensions.lua", @@ -35,8 +35,8 @@ function run_scripts() "eressea/wedding-jadee.lua", "eressea/ponnuki.lua", "eressea/items.lua", - "eressea/xmas2004.lua", "eressea/10years.lua", + "eressea/xmas2004.lua", "eressea/xmas2005.lua", "eressea/xmas2006.lua", "eressea/embassy.lua", @@ -61,7 +61,7 @@ function process(orders) init_summary() -- kill multi-players (external script) - loadscript("eressea/multis.lua") + -- loadscript("eressea/multis.lua") -- run the turn: set_encoding("utf8") @@ -69,7 +69,6 @@ function process(orders) print("could not read " .. orders) return -1 end - run_scripts() plan_monsters() @@ -114,6 +113,7 @@ end -- -- orderfile: contains the name of the orders. +load_scripts() if orderfile==nil then print "you must specify an orderfile" else diff --git a/src/scripts/eressea/xmas2004.lua b/src/scripts/eressea/xmas2004.lua index 515ce915c..6a6bcfa63 100644 --- a/src/scripts/eressea/xmas2004.lua +++ b/src/scripts/eressea/xmas2004.lua @@ -22,4 +22,4 @@ function xmas2004() end end -xmas2004() +-- xmas2004() diff --git a/src/scripts/eressea/xmas2005.lua b/src/scripts/eressea/xmas2005.lua index c1e82a12c..f64e4e8d0 100644 --- a/src/scripts/eressea/xmas2005.lua +++ b/src/scripts/eressea/xmas2005.lua @@ -28,4 +28,4 @@ function xmas2005() end end -xmas2005() +-- xmas2005() diff --git a/src/scripts/eressea/xmas2006.lua b/src/scripts/eressea/xmas2006.lua index 25f15d84f..3eb665f3c 100644 --- a/src/scripts/eressea/xmas2006.lua +++ b/src/scripts/eressea/xmas2006.lua @@ -51,4 +51,4 @@ function xmas2006() end end -xmas2006() +-- xmas2006()