Unicode WIP

- Bugfix region::connect structure not initialized
- set encoding from Lua
This commit is contained in:
Enno Rehling 2007-08-16 06:53:00 +00:00
parent 9c88e406fd
commit cae7e67fdf
10 changed files with 78 additions and 49 deletions

View file

@ -3692,6 +3692,8 @@ void
process(void) process(void)
{ {
processor *proc = processors; processor *proc = processors;
faction * f;
while (proc) { while (proc) {
int prio = proc->priority; int prio = proc->priority;
region *r; 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); } static void enter_1(region * r) { do_misc(r, false); }

View file

@ -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]); buffer[dir] = rfindhash(r->x + delta_x[dir], r->y + delta_y[dir]);
set |= (1<<dir); set |= (1<<dir);
#ifdef FAST_CONNECT #ifdef FAST_CONNECT
if (buffer[dir]) {
rmodify->connect[dir] = buffer[dir]; rmodify->connect[dir] = buffer[dir];
buffer[dir]->connect[back[dir]] = rmodify;
}
#endif #endif
return buffer[dir]; return buffer[dir];
} }

View file

@ -88,7 +88,6 @@ const char * xmlfile = "eressea.xml";
const char * g_datadir; const char * g_datadir;
int firstx = 0, firsty = 0; int firstx = 0, firsty = 0;
int enc_gamedata = 0; int enc_gamedata = 0;
int enc_orderfile = 0;
/* local symbols */ /* local symbols */
static region * current_region; static region * current_region;
@ -652,20 +651,19 @@ igetparam (const char *s, const struct locale *lang)
} }
int int
readorders(const char *filename, const char * encoding) readorders(const char *filename)
{ {
FILE * F = NULL; FILE * F = NULL;
const char *b; const char *b;
int nfactions=0; int nfactions=0;
struct faction *f = NULL; struct faction *f = NULL;
int enc = xmlParseCharEncoding(encoding);
if (filename) F = cfopen(filename, "rt"); if (filename) F = cfopen(filename, "rt");
if (F==NULL) return 0; if (F==NULL) return 0;
puts(" - lese Befehlsdatei...\n"); puts(" - lese Befehlsdatei...\n");
b = getbuf(F, enc); b = getbuf(F, enc_gamedata);
/* Auffinden der ersten Partei, und danach abarbeiten bis zur letzten /* Auffinden der ersten Partei, und danach abarbeiten bis zur letzten
* Partei */ * Partei */
@ -685,7 +683,7 @@ readorders(const char *filename, const char * encoding)
} }
#endif #endif
b = getbuf(F, enc); b = getbuf(F, enc_gamedata);
break; break;
case P_GAMENAME: case P_GAMENAME:
case P_FACTION: case P_FACTION:
@ -694,7 +692,7 @@ readorders(const char *filename, const char * encoding)
++nfactions; ++nfactions;
} }
b = getbuf(F, enc); b = getbuf(F, enc_gamedata);
break; break;
/* in factionorders wird nur eine zeile gelesen: /* in factionorders wird nur eine zeile gelesen:
@ -703,8 +701,8 @@ readorders(const char *filename, const char * encoding)
* vermerkt. */ * vermerkt. */
case P_UNIT: case P_UNIT:
if (!f || !unitorders(F, enc, f)) do { if (!f || !unitorders(F, enc_gamedata, f)) do {
b = getbuf(F, enc); b = getbuf(F, enc_gamedata);
if (!b) break; if (!b) break;
p = igetparam(b, lang); p = igetparam(b, lang);
} while ((p != P_UNIT || !f) && p != P_FACTION && p != P_NEXT && p != P_GAMENAME); } 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: case P_NEXT:
f = NULL; f = NULL;
b = getbuf(F, enc); b = getbuf(F, enc_gamedata);
break; break;
default: default:
b = getbuf(F, enc); b = getbuf(F, enc_gamedata);
break; break;
} }
} }
@ -1736,7 +1734,7 @@ writefaction(FILE * F, const faction * f)
} }
int int
readgame(const char * filename, int backup, int encoding) readgame(const char * filename, int backup)
{ {
int i, n, p; int i, n, p;
faction *f, **fp; faction *f, **fp;
@ -1795,7 +1793,7 @@ readgame(const char * filename, int backup, int encoding)
while(--n >= 0) { while(--n >= 0) {
plane *pl = calloc(1, sizeof(plane)); plane *pl = calloc(1, sizeof(plane));
pl->id = ri(F); pl->id = ri(F);
xrds(F, &pl->name, encoding); xrds(F, &pl->name, enc_gamedata);
pl->minx = (short)ri(F); pl->minx = (short)ri(F);
pl->maxx = (short)ri(F); pl->maxx = (short)ri(F);
pl->miny = (short)ri(F); pl->miny = (short)ri(F);
@ -1830,7 +1828,7 @@ readgame(const char * filename, int backup, int encoding)
/* fflush (stdout); */ /* fflush (stdout); */
while (--n >= 0) { while (--n >= 0) {
faction * f = readfaction(F, encoding); faction * f = readfaction(F, enc_gamedata);
*fp = f; *fp = f;
fp = &f->next; fp = &f->next;
@ -1888,7 +1886,7 @@ readgame(const char * filename, int backup, int encoding)
} }
--rmax; --rmax;
r = readregion(F, encoding, x, y); r = readregion(F, enc_gamedata, x, y);
/* Burgen */ /* Burgen */
p = ri(F); p = ri(F);
@ -1901,9 +1899,9 @@ readgame(const char * filename, int backup, int encoding)
*bp = b; *bp = b;
bp = &b->next; bp = &b->next;
bhash(b); bhash(b);
xrds(F, &b->name, encoding); xrds(F, &b->name, enc_gamedata);
if (lomem) rds(F, 0); if (lomem) rds(F, 0);
else xrds(F, &b->display, encoding); else xrds(F, &b->display, enc_gamedata);
b->size = ri(F); b->size = ri(F);
if (global.data_version < TYPES_VERSION) { if (global.data_version < TYPES_VERSION) {
assert(!"data format is no longer supported"); assert(!"data format is no longer supported");
@ -1928,9 +1926,9 @@ readgame(const char * filename, int backup, int encoding)
*shp = sh; *shp = sh;
shp = &sh->next; shp = &sh->next;
shash(sh); shash(sh);
xrds(F, &sh->name, encoding); xrds(F, &sh->name, enc_gamedata);
if (lomem) rds(F, NULL); if (lomem) rds(F, NULL);
else xrds(F, &sh->display, encoding); else xrds(F, &sh->display, enc_gamedata);
rss(F, token, sizeof(token)); rss(F, token, sizeof(token));
sh->type = st_find(token); sh->type = st_find(token);
@ -1956,7 +1954,7 @@ readgame(const char * filename, int backup, int encoding)
up = &r->units; up = &r->units;
while (--p >= 0) { while (--p >= 0) {
unit * u = readunit(F, encoding); unit * u = readunit(F, enc_gamedata);
sc_mage * mage; sc_mage * mage;
assert(u->region==NULL); assert(u->region==NULL);
@ -1984,19 +1982,6 @@ readgame(const char * filename, int backup, int encoding)
if (quiet<2) printf("\n - Referenzen initialisieren...\n"); if (quiet<2) printf("\n - Referenzen initialisieren...\n");
resolve(); 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) { for (r=regions;r;r=r->next) {
building * b; building * b;
for (b=r->buildings;b;b=b->next) update_lighthouse(b); for (b=r->buildings;b;b=b->next) update_lighthouse(b);

View file

@ -34,9 +34,9 @@ double version(void);
* dass hier ein Fehler (fehlende ") vorliegt */ * dass hier ein Fehler (fehlende ") vorliegt */
FILE * cfopen(const char *filename, const char *mode); FILE * cfopen(const char *filename, const char *mode);
int readorders(const char *filename, const char * encoding); int readorders(const char *filename);
int creategame(void); 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); int writegame(const char *filename, int quiet);
extern void rsf(FILE * F, char *s, size_t len); extern void rsf(FILE * F, char *s, size_t len);
@ -48,7 +48,6 @@ extern int maxregions;
extern int firstx, firsty; extern int firstx, firsty;
extern const char *xmlfile; extern const char *xmlfile;
extern int enc_gamedata; extern int enc_gamedata;
extern int enc_orderfile;
extern void init_locales(void); extern void init_locales(void);
extern int lastturn(void); extern int lastturn(void);

View file

@ -1343,7 +1343,7 @@ gmmain(int argc, char *argv[])
if (turn>first_turn) { if (turn>first_turn) {
char datafile[12]; char datafile[12];
sprintf(datafile, "%u", turn); sprintf(datafile, "%u", turn);
readgame(datafile, 0, enc_gamedata); readgame(datafile, 0);
} }
run_mapper(); run_mapper();

View file

@ -107,11 +107,22 @@ message_region(unit& sender, const char * str)
ADDMSG(&sender.region->msgs, msg_message("mail_result", "unit message", &sender, str)); ADDMSG(&sender.region->msgs, msg_message("mail_result", "unit message", &sender, str));
} }
static int static void
read_game(const char * filename, const char * encoding) set_encoding(const char * str)
{ {
int enc = xmlParseCharEncoding(encoding); enc_gamedata = xmlParseCharEncoding(str);
int rv = readgame(filename, false, enc); }
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); printf(" - Korrekturen Runde %d\n", turn);
korrektur(); korrektur();
return rv; return rv;
@ -214,6 +225,9 @@ bind_gamecode(lua_State * L)
def("read_game", &read_game), def("read_game", &read_game),
def("write_game", &write_game), def("write_game", &write_game),
def("get_encoding", &get_encoding),
def("set_encoding", &set_encoding),
def("init_summary", &init_summary), def("init_summary", &init_summary),
def("write_summary", &write_summary), def("write_summary", &write_summary),

View file

@ -615,10 +615,8 @@ load_inifile(const char * filename)
lomem = iniparser_getint(d, "common:lomem", lomem)?1:0; lomem = iniparser_getint(d, "common:lomem", lomem)?1:0;
memdebug = iniparser_getint(d, "common:memcheck", memdebug); 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); 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; quiet = iniparser_getint(d, "eressea:verbose", 0)?0:1;
battledebug = iniparser_getint(d, "eressea:debug", battledebug)?1:0; battledebug = iniparser_getint(d, "eressea:debug", battledebug)?1:0;

View file

@ -9,9 +9,10 @@ function write_emails(locales)
local faction local faction
for faction in factions() do for faction in factions() do
-- print(faction.id .. " - " .. faction.locale) if faction.email~="" then
files[faction.locale]:write(faction.email .. "\n") files[faction.locale]:write(faction.email .. "\n")
end end
end
for key, file in pairs(files) do for key, file in pairs(files) do
file:close() file:close()

View file

@ -56,7 +56,8 @@ function process(orders)
equipment_setitem("new_faction", "money", "4200"); equipment_setitem("new_faction", "money", "4200");
file = "" .. get_turn() 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") print("could not read game")
return -1 return -1
end end

View file

@ -432,5 +432,17 @@ if 0==1 then
end end
-- test_moving() -- test_moving()
if 0==1 then
read_game("530", "ISO-8859-1") 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