diff --git a/src/common/gamecode/laws.c b/src/common/gamecode/laws.c index 0ed332a54..a3bcb8a6d 100644 --- a/src/common/gamecode/laws.c +++ b/src/common/gamecode/laws.c @@ -3692,6 +3692,8 @@ void process(void) { processor *proc = processors; + faction * f; + while (proc) { int prio = proc->priority; region *r; @@ -3775,6 +3777,20 @@ process(void) } } + + if (quiet<2) printf("\n - Leere Gruppen löschen...\n"); + for (f=factions; f; f=f->next) { + group ** gp = &f->groups; + while (*gp) { + group * g = *gp; + if (g->members==0) { + *gp = g->next; + free_group(g); + } else + gp = &g->next; + } + } + } static void enter_1(region * r) { do_misc(r, false); } diff --git a/src/common/kernel/region.c b/src/common/kernel/region.c index be7067cc8..4cd8a273a 100644 --- a/src/common/kernel/region.c +++ b/src/common/kernel/region.c @@ -446,7 +446,10 @@ r_connect(const region * r, direction_t dir) buffer[dir] = rfindhash(r->x + delta_x[dir], r->y + delta_y[dir]); set |= (1<connect[dir] = buffer[dir]; + if (buffer[dir]) { + rmodify->connect[dir] = buffer[dir]; + buffer[dir]->connect[back[dir]] = rmodify; + } #endif return buffer[dir]; } diff --git a/src/common/kernel/save.c b/src/common/kernel/save.c index 394687160..dc50fe966 100644 --- a/src/common/kernel/save.c +++ b/src/common/kernel/save.c @@ -88,7 +88,6 @@ const char * xmlfile = "eressea.xml"; const char * g_datadir; int firstx = 0, firsty = 0; int enc_gamedata = 0; -int enc_orderfile = 0; /* local symbols */ static region * current_region; @@ -652,20 +651,19 @@ igetparam (const char *s, const struct locale *lang) } int -readorders(const char *filename, const char * encoding) +readorders(const char *filename) { FILE * F = NULL; const char *b; int nfactions=0; struct faction *f = NULL; - int enc = xmlParseCharEncoding(encoding); if (filename) F = cfopen(filename, "rt"); if (F==NULL) return 0; puts(" - lese Befehlsdatei...\n"); - b = getbuf(F, enc); + b = getbuf(F, enc_gamedata); /* Auffinden der ersten Partei, und danach abarbeiten bis zur letzten * Partei */ @@ -685,7 +683,7 @@ readorders(const char *filename, const char * encoding) } #endif - b = getbuf(F, enc); + b = getbuf(F, enc_gamedata); break; case P_GAMENAME: case P_FACTION: @@ -694,7 +692,7 @@ readorders(const char *filename, const char * encoding) ++nfactions; } - b = getbuf(F, enc); + b = getbuf(F, enc_gamedata); break; /* in factionorders wird nur eine zeile gelesen: @@ -703,8 +701,8 @@ readorders(const char *filename, const char * encoding) * vermerkt. */ case P_UNIT: - if (!f || !unitorders(F, enc, f)) do { - b = getbuf(F, enc); + if (!f || !unitorders(F, enc_gamedata, f)) do { + b = getbuf(F, enc_gamedata); if (!b) break; p = igetparam(b, lang); } while ((p != P_UNIT || !f) && p != P_FACTION && p != P_NEXT && p != P_GAMENAME); @@ -719,11 +717,11 @@ readorders(const char *filename, const char * encoding) case P_NEXT: f = NULL; - b = getbuf(F, enc); + b = getbuf(F, enc_gamedata); break; default: - b = getbuf(F, enc); + b = getbuf(F, enc_gamedata); break; } } @@ -1736,7 +1734,7 @@ writefaction(FILE * F, const faction * f) } int -readgame(const char * filename, int backup, int encoding) +readgame(const char * filename, int backup) { int i, n, p; faction *f, **fp; @@ -1795,7 +1793,7 @@ readgame(const char * filename, int backup, int encoding) while(--n >= 0) { plane *pl = calloc(1, sizeof(plane)); pl->id = ri(F); - xrds(F, &pl->name, encoding); + xrds(F, &pl->name, enc_gamedata); pl->minx = (short)ri(F); pl->maxx = (short)ri(F); pl->miny = (short)ri(F); @@ -1830,7 +1828,7 @@ readgame(const char * filename, int backup, int encoding) /* fflush (stdout); */ while (--n >= 0) { - faction * f = readfaction(F, encoding); + faction * f = readfaction(F, enc_gamedata); *fp = f; fp = &f->next; @@ -1888,7 +1886,7 @@ readgame(const char * filename, int backup, int encoding) } --rmax; - r = readregion(F, encoding, x, y); + r = readregion(F, enc_gamedata, x, y); /* Burgen */ p = ri(F); @@ -1901,9 +1899,9 @@ readgame(const char * filename, int backup, int encoding) *bp = b; bp = &b->next; bhash(b); - xrds(F, &b->name, encoding); + xrds(F, &b->name, enc_gamedata); if (lomem) rds(F, 0); - else xrds(F, &b->display, encoding); + else xrds(F, &b->display, enc_gamedata); b->size = ri(F); if (global.data_version < TYPES_VERSION) { assert(!"data format is no longer supported"); @@ -1928,9 +1926,9 @@ readgame(const char * filename, int backup, int encoding) *shp = sh; shp = &sh->next; shash(sh); - xrds(F, &sh->name, encoding); + xrds(F, &sh->name, enc_gamedata); if (lomem) rds(F, NULL); - else xrds(F, &sh->display, encoding); + else xrds(F, &sh->display, enc_gamedata); rss(F, token, sizeof(token)); sh->type = st_find(token); @@ -1956,7 +1954,7 @@ readgame(const char * filename, int backup, int encoding) up = &r->units; while (--p >= 0) { - unit * u = readunit(F, encoding); + unit * u = readunit(F, enc_gamedata); sc_mage * mage; assert(u->region==NULL); @@ -1984,19 +1982,6 @@ readgame(const char * filename, int backup, int encoding) if (quiet<2) printf("\n - Referenzen initialisieren...\n"); resolve(); - if (quiet<2) printf("\n - Leere Gruppen löschen...\n"); - for (f=factions; f; f=f->next) { - group ** gp = &f->groups; - while (*gp) { - group * g = *gp; - if (g->members==0) { - *gp = g->next; - free_group(g); - } else - gp = &g->next; - } - } - for (r=regions;r;r=r->next) { building * b; for (b=r->buildings;b;b=b->next) update_lighthouse(b); diff --git a/src/common/kernel/save.h b/src/common/kernel/save.h index 321e2b05f..e5205ca4b 100644 --- a/src/common/kernel/save.h +++ b/src/common/kernel/save.h @@ -34,9 +34,9 @@ double version(void); * dass hier ein Fehler (fehlende ") vorliegt */ FILE * cfopen(const char *filename, const char *mode); -int readorders(const char *filename, const char * encoding); +int readorders(const char *filename); int creategame(void); -extern int readgame(const char * filename, int backup, int encoding); +extern int readgame(const char * filename, int backup); int writegame(const char *filename, int quiet); extern void rsf(FILE * F, char *s, size_t len); @@ -48,7 +48,6 @@ extern int maxregions; extern int firstx, firsty; extern const char *xmlfile; extern int enc_gamedata; -extern int enc_orderfile; extern void init_locales(void); extern int lastturn(void); diff --git a/src/eressea/gmtool.c b/src/eressea/gmtool.c index 724701ba9..109222ac7 100644 --- a/src/eressea/gmtool.c +++ b/src/eressea/gmtool.c @@ -1343,7 +1343,7 @@ gmmain(int argc, char *argv[]) if (turn>first_turn) { char datafile[12]; sprintf(datafile, "%u", turn); - readgame(datafile, 0, enc_gamedata); + readgame(datafile, 0); } run_mapper(); diff --git a/src/eressea/lua/gamecode.cpp b/src/eressea/lua/gamecode.cpp index 3b7748ca5..3ea4d4e70 100644 --- a/src/eressea/lua/gamecode.cpp +++ b/src/eressea/lua/gamecode.cpp @@ -107,11 +107,22 @@ message_region(unit& sender, const char * str) ADDMSG(&sender.region->msgs, msg_message("mail_result", "unit message", &sender, str)); } -static int -read_game(const char * filename, const char * encoding) +static void +set_encoding(const char * str) { - int enc = xmlParseCharEncoding(encoding); - int rv = readgame(filename, false, enc); + enc_gamedata = xmlParseCharEncoding(str); +} + +static const char * +get_encoding(void) +{ + return xmlGetCharEncodingName((xmlCharEncoding)enc_gamedata); +} + +static int +read_game(const char * filename) +{ + int rv = readgame(filename, false); printf(" - Korrekturen Runde %d\n", turn); korrektur(); return rv; @@ -214,6 +225,9 @@ bind_gamecode(lua_State * L) def("read_game", &read_game), def("write_game", &write_game), + def("get_encoding", &get_encoding), + def("set_encoding", &set_encoding), + def("init_summary", &init_summary), def("write_summary", &write_summary), diff --git a/src/eressea/server.cpp b/src/eressea/server.cpp index cc81b566a..e638f49f4 100644 --- a/src/eressea/server.cpp +++ b/src/eressea/server.cpp @@ -615,10 +615,8 @@ load_inifile(const char * filename) lomem = iniparser_getint(d, "common:lomem", lomem)?1:0; memdebug = iniparser_getint(d, "common:memcheck", memdebug); - str = iniparser_getstring(d, "common:gamedata_encoding", NULL); + str = iniparser_getstring(d, "common:encoding", NULL); if (str) enc_gamedata = xmlParseCharEncoding(str); - str = iniparser_getstring(d, "common:orderfile_encoding", NULL); - if (str) enc_orderfile = xmlParseCharEncoding(str); quiet = iniparser_getint(d, "eressea:verbose", 0)?0:1; battledebug = iniparser_getint(d, "eressea:debug", battledebug)?1:0; diff --git a/src/scripts/default.lua b/src/scripts/default.lua index 715986a0e..3872a7954 100644 --- a/src/scripts/default.lua +++ b/src/scripts/default.lua @@ -9,8 +9,9 @@ function write_emails(locales) local faction for faction in factions() do - -- print(faction.id .. " - " .. faction.locale) - files[faction.locale]:write(faction.email .. "\n") + if faction.email~="" then + files[faction.locale]:write(faction.email .. "\n") + end end for key, file in pairs(files) do diff --git a/src/scripts/eressea.lua b/src/scripts/eressea.lua index a9ab87224..f89cb6a11 100644 --- a/src/scripts/eressea.lua +++ b/src/scripts/eressea.lua @@ -56,7 +56,8 @@ function process(orders) equipment_setitem("new_faction", "money", "4200"); file = "" .. get_turn() - if read_game(file, enc_game)~=0 then + set_encoding(enc_game) + if read_game(file)~=0 then print("could not read game") return -1 end diff --git a/src/scripts/samples.lua b/src/scripts/samples.lua index acd276cd3..5eea565de 100644 --- a/src/scripts/samples.lua +++ b/src/scripts/samples.lua @@ -432,5 +432,17 @@ if 0==1 then end -- test_moving() - -read_game("530", "ISO-8859-1") +if 0==1 then + set_encoding("ISO-8859-1") + read_game("530") + -- read_orders("../game/orders.530") + plan_monsters() + process_orders() + write_game("531") +else + set_encoding("UTF-8") + read_game("531") + plan_monsters() + process_orders() + write_game("532") +end