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;
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 */

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 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;

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 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) {

View file

@ -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);
}
++global.cookie; /* readgame() already does this, but sjust in case */
}

View file

@ -369,6 +369,7 @@ extern const struct race * new_race[];
/* globale settings des Spieles */
typedef struct settings {
int cookie;
const char *gamename;
boolean unitsperalliance;
unsigned int maxunits;

View file

@ -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) {

View file

@ -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. */

View file

@ -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);

View file

@ -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) {

View file

@ -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;

View file

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

View file

@ -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;

View file

@ -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

View file

@ -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

View file

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

View file

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

View file

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