Unicode WIP:

This code did a full run of turn 531, with all reports.

- replace all calls to strlcat with strlcpy
- change strlcpy to return number of bytes written, not input bytes
- fix some buffer sizes
- write UTF8 BOM into all output files that could use them.
This commit is contained in:
Enno Rehling 2007-08-21 07:04:44 +00:00
parent c3a5631ec7
commit a33d59b21a
23 changed files with 144 additions and 453 deletions

View file

@ -35,14 +35,7 @@ verify_follow(attrib * a)
static int
read_follow(attrib * a, FILE * F)
{
if (global.data_version < BASE36IDS_VERSION) {
variant var;
fscanf(F, "%d", &var.i);
ur_add(var, (void**)&a->data.v, resolve_unit);
} else {
return read_unit_reference(NULL, F);
}
return AT_READ_OK;
return read_unit_reference(NULL, F);
}
attrib_type at_follow = {

View file

@ -40,14 +40,7 @@ write_hate(const attrib * a, FILE * F)
static int
read_hate(attrib * a, FILE * F)
{
if (global.data_version < BASE36IDS_VERSION) {
variant var;
fscanf(F, "%d", &var.i);
ur_add(var, (void**)&a->data.v, resolve_unit);
} else {
return read_unit_reference((unit**)&a->data.v, F);
}
return AT_READ_OK;
return read_unit_reference((unit**)&a->data.v, F);
}
attrib_type at_hate = {

View file

@ -32,13 +32,7 @@ write_targetregion(const attrib * a, FILE * F)
static int
read_targetregion(attrib * a, FILE * F)
{
if (global.data_version < BASE36IDS_VERSION) {
a_readint(a, F);
a->data.v = findregion(a->data.sa[0], a->data.sa[1]);
} else {
return read_region_reference((region**)&a->data.v, F);
}
return AT_READ_OK;
return read_region_reference((region**)&a->data.v, F);
}
attrib_type at_targetregion = {

View file

@ -69,6 +69,8 @@
#include <util/message.h>
#include <util/nrmessage.h>
#include <libxml/encoding.h>
/* libc includes */
#include <assert.h>
#include <errno.h>
@ -1141,10 +1143,15 @@ report_computer(const char * filename, report_context * ctx, const char * charse
#ifdef SCORE_MODULE
int score = 0, avgscore = 0;
#endif
int enc = xmlParseCharEncoding(charset);
FILE * F = fopen(filename, "wt");
if (F==NULL) {
perror(filename);
return -1;
} else if (enc==XML_CHAR_ENCODING_UTF8) {
const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf };
fwrite(utf8_bom, 1, 3, F);
}
/* must call this to get all the neighbour regions */

View file

@ -614,7 +614,7 @@ rp_battles(FILE * F, faction * f)
rnl(F);
while (bm) {
char buf[80];
char buf[256];
RENDER(f, buf, sizeof(buf), ("battle::header", "region", bm->r));
rnl(F);
centre(F, buf, true);
@ -1365,7 +1365,7 @@ static void
allies(FILE * F, const faction * f)
{
const group * g = f->groups;
char buf[8192];
char buf[16384];
if (f->allies) {
if (!f->allies->next) {

View file

@ -149,6 +149,10 @@ report_summary(summary * s, summary * o, boolean full)
}
F = cfopen(zText, "w");
if (!F) return;
else {
const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf };
fwrite(utf8_bom, 1, 3, F);
}
printf("Schreibe Zusammenfassung (parteien)...\n");
fprintf(F, "%s\n%s\n\n", global.gamename, gamedate2(default_locale));
fprintf(F, "Auswertung Nr: %d\n\n", turn);

View file

@ -2774,17 +2774,15 @@ print_header(battle * b)
const char * lastf = NULL;
boolean first = false;
side * s;
size_t size;
char * bufp = zText;
zText[0] = 0;
size = sizeof(zText);
for (s=b->sides; s; s=s->next) {
fighter *df;
for (df=s->fighters;df;df=df->next) {
if (is_attacker(df)) {
if (first) size -= strlcat(zText, ", ", size);
if (first) bufp += strlcpy(bufp, ", ", sizeof(zText) - (bufp-zText));
if (lastf) {
size -= strlcat(zText, (const char *)lastf, size);
bufp += strlcpy(bufp, (const char *)lastf, sizeof(zText) - (bufp-zText));
first = true;
}
if (seematrix(f, s) == true)
@ -2796,11 +2794,11 @@ print_header(battle * b)
}
}
if (first) {
size -= strlcat(zText, " ", size);
size -= strlcat(zText, (const char *)LOC(f->locale, "and"), size);
size -= strlcat(zText, " ", size);
bufp += strlcpy(bufp, " ", sizeof(zText) - (bufp-zText));
bufp += strlcpy(bufp, (const char *)LOC(f->locale, "and"), sizeof(zText) - (bufp-zText));
bufp += strlcpy(bufp, " ", sizeof(zText) - (bufp-zText));
}
if (lastf) size -= strlcat(zText, (const char *)lastf, size);
if (lastf) bufp += strlcpy(bufp, (const char *)lastf, sizeof(zText) - (bufp-zText));
m = msg_message("battle::starters", "factions", zText);
message_faction(b, f, m);
@ -3306,6 +3304,8 @@ make_battle(region * r)
bdebug = fopen(zFilename, "w");
if (!bdebug) log_error(("battles können nicht debugged werden\n"));
else {
const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf };
fwrite(utf8_bom, 1, 3, bdebug);
fprintf(bdebug, "In %s findet ein Kampf statt:\n", rname(r, NULL));
}
obs_count++;
@ -3445,7 +3445,7 @@ battle_report(battle * b)
for (bf=b->factions;bf;bf=bf->next) {
faction * fac = bf->faction;
char buf[1024];
char buf[32*MAXSIDES];
char * bufp = buf;
size_t size = sizeof(buf), rsize;
message * m;

View file

@ -2229,6 +2229,10 @@ remove_empty_factions(boolean writedropouts)
sprintf(zText, "%s/dropouts.%d", basepath(), turn);
if (writedropouts) dofp = fopen(zText, "w");
if (dofp) {
const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf };
fwrite(utf8_bom, 1, 3, dofp);
}
for (fp = &factions; *fp;) {
faction * f = *fp;
@ -2863,7 +2867,6 @@ attrib_init(void)
register_bordertype(&bt_questportal);
at_register(&at_germs);
at_register(&at_laen); /* required for old datafiles */
#ifdef XECMD_MODULE
at_register(&at_xontormiaexpress); /* required for old datafiles */
#endif

View file

@ -189,13 +189,9 @@ int
read_faction_reference(faction ** f, FILE * F)
{
variant id;
if (global.data_version >= BASE36IDS_VERSION) {
char zText[16];
fscanf(F, "%s ", zText);
id.i = atoi36(zText);
} else {
fscanf(F, "%d ", &id.i);
}
char zText[16];
fscanf(F, "%s ", zText);
id.i = atoi36(zText);
if (id.i<0) {
*f = NULL;
return AT_READ_FAIL;

View file

@ -207,8 +207,6 @@ read_groups(FILE * F, faction * f)
if (!a->faction) ur_add(aid, (void**)&a->faction, resolve_faction);
}
*pa = 0;
if(global.data_version >= GROUPATTRIB_VERSION) {
a_read(F, &g->attribs);
}
a_read(F, &g->attribs);
}
}

View file

@ -118,24 +118,16 @@ static int
a_readicastle(attrib * a, FILE * f)
{
icastle_data * data = (icastle_data*)a->data.v;
if (global.data_version<TYPES_VERSION) {
int t;
fscanf(f, "%d", &t);
data->time = 0;
data->type = NULL;
return AT_READ_FAIL;
} else {
variant bno;
char token[32];
fscanf(f, "%s %d %d", token, &bno.i, &data->time);
data->building = findbuilding(bno.i);
if (!data->building) {
/* this shouldn't happen, but just in case it does: */
ur_add(bno, (void**)&data->building, resolve_building);
}
data->type = bt_find(token);
return AT_READ_OK;
variant bno;
char token[32];
fscanf(f, "%s %d %d", token, &bno.i, &data->time);
data->building = findbuilding(bno.i);
if (!data->building) {
/* this shouldn't happen, but just in case it does: */
ur_add(bno, (void**)&data->building, resolve_building);
}
data->type = bt_find(token);
return AT_READ_OK;
}
static void

View file

@ -2258,7 +2258,7 @@ hunt(unit *u, order * ord)
region *rc = u->region;
int moves, id, speed;
char command[256];
size_t size = sizeof(command);
char * bufp = command;
direction_t dir;
if (fval(u, UFL_NOTMOVING)) {
@ -2296,9 +2296,8 @@ hunt(unit *u, order * ord)
return 0;
}
sprintf(command, "%s %s", locale_string(u->faction->locale, keywords[K_MOVE]),
bufp = command + sprintf(command, "%s %s", locale_string(u->faction->locale, keywords[K_MOVE]),
locale_string(u->faction->locale, directions[dir]));
size -= strlen(command);
moves = 1;
speed = getuint();
@ -2311,8 +2310,8 @@ hunt(unit *u, order * ord)
rc = rconnect(rc, dir);
while (moves < speed && (dir = hunted_dir(rc->attribs, id)) != NODIRECTION)
{
size -= strlcat(command, " ", size);
size -= strlcat(command, LOC(u->faction->locale, directions[dir]), size);
bufp += strlcpy(bufp, " ", sizeof(command) - (bufp-command));
bufp += strlcpy(bufp, LOC(u->faction->locale, directions[dir]), sizeof(command) - (bufp-command));
moves++;
rc = rconnect(rc, dir);
}

View file

@ -253,9 +253,10 @@ a_readdirection(attrib *a, FILE *f)
fscanf(f, "%hd %hd %d", &d->x, &d->y, &d->duration);
if (global.data_version<UNICODE_VERSION) {
char lbuf[16];
dir_lookup * dl = dir_name_lookup;
fscanf(f, "%*s ");
fscanf(f, "%s ", lbuf);
dir_lookup * dl = dir_name_lookup;
cstring_i(lbuf);
for (;dl;dl=dl->next) {
@ -630,38 +631,6 @@ attrib_type at_travelunit = {
NO_READ
};
extern int laen_read(attrib * a, FILE * F);
/***************/
/* at_laen */
/***************/
attrib_type at_laen = {
"laen",
DEFAULT_INIT,
DEFAULT_FINALIZE,
DEFAULT_AGE,
NULL,
laen_read,
ATF_UNIQUE
};
void
rsetlaen(region * r, int val)
{
attrib * a = a_find(r->attribs, &at_laen);
if (!a && val>=0) a = a_add(&r->attribs, a_new(&at_laen));
else if (a && val<0) a_remove(&r->attribs, a);
if (val>=0) a->data.i = val;
}
int
rlaen(const region * r)
{
attrib * a = a_find(r->attribs, &at_laen);
if (!a) return -1;
return a->data.i;
}
void
rsetroad(region * r, direction_t d, short val)
{

View file

@ -156,7 +156,6 @@ extern struct attrib_type at_chaoscount;
extern struct attrib_type at_woodcount;
extern struct attrib_type at_deathcount;
extern struct attrib_type at_travelunit;
extern struct attrib_type at_laen;
void initrhash(void);
void rhash(struct region * r);
@ -198,9 +197,6 @@ void rsethorses(const struct region * r, int value);
#define rbuildings(r) ((r)->buildings)
extern int rlaen(const struct region * r);
extern void rsetlaen(struct region * r, int value);
#define rherbtype(r) ((r)->land?(r)->land->herbtype:0)
#define rsetherbtype(r, value) ((r)->land?((r)->land->herbtype=(value)):(value),0)

View file

@ -92,46 +92,6 @@ int enc_gamedata = 0;
/* local symbols */
static region * current_region;
#ifdef RESOURCE_CONVERSION
struct attrib_type at_resources = {
"resources", NULL, NULL, NULL, NULL, NULL, ATF_UNIQUE
};
static void
read_iron(struct region * r, int iron)
{
attrib * a = a_find(r->attribs, &at_resources);
assert(iron>=0);
if (a==NULL) {
a = a_add(&r->attribs, a_new(&at_resources));
a->data.sa[1] = -1;
}
a->data.sa[0] = (short)iron;
}
static void
read_laen(struct region * r, int laen)
{
attrib * a = a_find(r->attribs, &at_resources);
assert(laen>=0);
if (a==NULL) {
a = a_add(&r->attribs, a_new(&at_resources));
a->data.sa[0] = -1;
}
a->data.sa[1] = (short)laen;
}
int
laen_read(attrib * a, FILE * F)
{
int laen;
fscanf(F, "%d", &laen);
read_laen(current_region, laen);
return AT_READ_FAIL;
}
#endif
char *
rns(FILE * f, char *c, size_t size)
{
@ -170,81 +130,6 @@ cfopen(const char *filename, const char *mode)
#define rid(F) ri36(F)
#undef CONVERT_DBLINK
#ifdef CONVERT_DBLINK
typedef struct uniquenode {
struct uniquenode * next;
int id;
faction * f;
} uniquenode;
#define HASHSIZE 2039
static uniquenode * uniquehash[HASHSIZE];
static faction *
uniquefaction(int id)
{
uniquenode * node = uniquehash[id%HASHSIZE];
while (node && node->id!=id) node=node->next;
return node?node->f:NULL;
}
static void
addunique(int id, faction * f)
{
uniquenode * fnode = calloc(1, sizeof(uniquenode));
fnode->f = f;
fnode->id = id;
fnode->next = uniquehash[id%HASHSIZE];
uniquehash[id%HASHSIZE] = fnode;
}
typedef struct mapnode {
struct mapnode * next;
int fno;
int subscription;
} mapnode;
static mapnode * subscriptions[HASHSIZE];
void
convertunique(faction * f)
{
int unique = f->subscription;
static FILE * F = NULL;
mapnode * mnode;
addunique(unique, f);
if (F==NULL) {
static char zText[MAX_PATH];
strcat(strcpy(zText, basepath()), "/subscriptions");
F = fopen(zText, "r");
if (F==NULL) {
log_warning(("could not open %s.\n", zText));
abort();
}
for (;;) {
char zFaction[5];
int subscription, fno;
if (fscanf(F, "%d %s", &subscription, zFaction)<=0) break;
mnode = calloc(1, sizeof(mapnode));
fno = atoi36(zFaction);
mnode->next = subscriptions[fno%HASHSIZE];
mnode->fno = fno;
mnode->subscription = subscription;
subscriptions[fno%HASHSIZE] = mnode;
}
}
mnode = subscriptions[f->no%HASHSIZE];
while (mnode!=NULL && mnode->fno!=f->no) mnode = mnode->next;
if (mnode) f->subscription = mnode->subscription;
else {
log_printf("%s %s %s %s\n",
itoa36(f->no), f->email, f->override, dbrace(f->race));
}
}
#endif
int
freadstr(FILE * F, int encoding, char * start, size_t size)
{
@ -663,6 +548,7 @@ readorders(const char *filename)
puts(" - lese Befehlsdatei...\n");
/* TODO: recognize UTF8 BOM */
b = getbuf(F, enc_gamedata);
/* Auffinden der ersten Partei, und danach abarbeiten bis zur letzten
@ -902,50 +788,6 @@ write_items(FILE *F, item *ilist)
fputs("end ", F);
}
#ifdef USE_PLAYERS
static void
export_players(const char * path)
{
FILE * F;
player * p = get_players();
if (p==NULL) return;
F = cfopen(path, "w");
if (F==NULL) return;
fputs("name;email;passwd;faction;info\n", F);
while (p) {
/* name */
fputc('\"', F);
if (p->name) fputs(p->name, F);
/* email */
fputs("\";\"", F);
if (p->email) fputs(p->email, F);
else if (p->faction) fputs(p->faction->email, F);
fputs("\";\"", F);
/* passwd */
fputs("\";\"", F);
if (p->faction) fputs(p->faction->passw, F);
/* faction */
fputs("\";\"", F);
if (p->faction) fputs(itoa36(p->faction->no), F);
/* info */
fputs("\";\"", F);
if (p->info) fputs(p->info, F);
else if (p->faction) fputs(p->faction->banner, F);
fputs("\"\n", F);
p = next_player(p);
}
fclose(F);
}
#endif
int
lastturn(void)
{
@ -1076,23 +918,6 @@ readunit(FILE * F, int encoding)
}
}
setstatus(u, ri(F));
if (global.data_version < NEWSTATUS_VERSION) {
switch (u->status) {
case 0:
setstatus(u, ST_FIGHT);
break;
case 1:
setstatus(u, ST_BEHIND);
break;
case 2:
setstatus(u, ST_AVOID);
break;
case 3:
setstatus(u, ST_FLEE);
default:
assert(!"unknown status in data");
}
}
if (global.data_version <= 73) {
if (ri(F)) {
guard(u, GUARD_ALL);
@ -1175,29 +1000,6 @@ readunit(FILE * F, int encoding)
u->hp=u->number;
}
if (global.data_version < MAGE_ATTRIB_VERSION) {
int i = ri(F);
if (i != -1){
attrib * a;
int csp = 0;
sc_mage * mage = calloc(1, sizeof(sc_mage));
mage->magietyp = (magic_t) i;
mage->spellpoints = ri(F);
mage->spchange = ri(F);
while ((i = ri(F)) != -1) {
mage->combatspells[csp].sp = find_spellbyid(mage->magietyp, (spellid_t)i);
mage->combatspells[csp].level = ri(F);
csp++;
}
while ((i = ri(F)) != -1) {
add_spell(mage, find_spellbyid(mage->magietyp, (spellid_t)i));
}
mage->spellcount = 0;
a = a_add(&u->attribs, a_new(&at_mage));
a->data.v = mage;
}
}
a_read(F, &u->attribs);
return u;
}
@ -1309,9 +1111,6 @@ readregion(FILE * F, int encoding, short x, short y)
if (global.data_version < TERRAIN_VERSION) {
int ter = ri(F);
if (global.data_version < NOFOREST_VERSION) {
if (ter>T_PLAIN) --ter;
}
terrain = newterrain((terrain_t)ter);
} else {
char name[64];
@ -1325,10 +1124,7 @@ readregion(FILE * F, int encoding, short x, short y)
r->terrain = terrain;
r->flags = (char) ri(F);
if (global.data_version >= REGIONAGE_VERSION)
r->age = (unsigned short) ri(F);
else
r->age = 0;
r->age = (unsigned short) ri(F);
if (fval(r->terrain, LAND_REGION)) {
r->land = calloc(1, sizeof(land_region));
@ -1336,6 +1132,7 @@ readregion(FILE * F, int encoding, short x, short y)
}
if (r->land) {
int i;
rawmaterial ** pres = &r->resources;
if(global.data_version < GROWTREE_VERSION) {
i = ri(F); rsettrees(r, 2, i);
} else {
@ -1362,48 +1159,41 @@ readregion(FILE * F, int encoding, short x, short y)
rsettrees(r, 2, i);
}
i = ri(F); rsethorses(r, i);
if (global.data_version < NEWRESOURCE_VERSION) {
i = ri(F);
#ifdef RESOURCE_CONVERSION
if (i!=0) read_iron(r, i);
#endif
} else {
rawmaterial ** pres = &r->resources;
assert(*pres==NULL);
for (;;) {
rawmaterial * res;
rss(F, token, sizeof(token));
if (strcmp(token, "end")==0) break;
res = malloc(sizeof(rawmaterial));
res->type = rmt_find(token);
if (res->type==NULL) {
log_error(("invalid resourcetype %s in data.\n", token));
}
assert(res->type!=NULL);
res->level = ri(F);
res->amount = ri(F);
res->flags = 0;
if(global.data_version >= RANDOMIZED_RESOURCES_VERSION) {
res->startlevel = ri(F);
res->base = ri(F);
res->divisor = ri(F);
} else {
int i;
for (i=0;r->terrain->production[i].type;++i) {
if (res->type->rtype == r->terrain->production[i].type) break;
}
res->base = dice_rand(r->terrain->production[i].base);
res->divisor = dice_rand(r->terrain->production[i].divisor);
res->startlevel = 1;
}
*pres = res;
pres=&res->next;
assert(*pres==NULL);
for (;;) {
rawmaterial * res;
rss(F, token, sizeof(token));
if (strcmp(token, "end")==0) break;
res = malloc(sizeof(rawmaterial));
res->type = rmt_find(token);
if (res->type==NULL) {
log_error(("invalid resourcetype %s in data.\n", token));
}
*pres = NULL;
assert(res->type!=NULL);
res->level = ri(F);
res->amount = ri(F);
res->flags = 0;
if(global.data_version >= RANDOMIZED_RESOURCES_VERSION) {
res->startlevel = ri(F);
res->base = ri(F);
res->divisor = ri(F);
} else {
int i;
for (i=0;r->terrain->production[i].type;++i) {
if (res->type->rtype == r->terrain->production[i].type) break;
}
res->base = dice_rand(r->terrain->production[i].base);
res->divisor = dice_rand(r->terrain->production[i].divisor);
res->startlevel = 1;
}
*pres = res;
pres=&res->next;
}
*pres = NULL;
rss(F, token, sizeof(token));
if (strcmp(token, "noherb") != 0) {
const resource_type * rtype = rt_find(token);
@ -1574,12 +1364,8 @@ readfaction(FILE * F, int encoding)
f->override = strdup(itoa36(rng_int()));
}
if (global.data_version < LOCALE_VERSION) {
f->locale = find_locale("de");
} else {
rss(F, token, sizeof(token));
f->locale = find_locale(token);
}
rss(F, token, sizeof(token));
f->locale = find_locale(token);
f->lastorders = ri(F);
f->age = ri(F);
if (global.data_version < NEWRACE_VERSION) {
@ -1590,9 +1376,6 @@ readfaction(FILE * F, int encoding)
f->race = rc_find(token);
assert(f->race);
}
#ifdef CONVERT_DBLINK
convertunique(f);
#endif
f->magiegebiet = (magic_t)ri(F);
#ifdef KARMA_MODULE
@ -1630,18 +1413,6 @@ readfaction(FILE * F, int encoding)
f->options = f->options | want(O_REPORT) | want(O_ZUGVORLAGE);
}
if (global.data_version < TYPES_VERSION) {
int sk = ri(F); /* f->seenspell überspringen */
spell_list * slist;
for (slist=spells;slist!=NULL;slist=slist->next) {
spell * sp = slist->data;
if (sp->magietyp==f->magiegebiet && sp->level<=sk) {
a_add(&f->attribs, a_new(&at_seenspell))->data.v = sp;
}
}
}
sfp = &f->allies;
if (global.data_version<ALLIANCES_VERSION) {
int p = ri(F);
@ -1758,10 +1529,11 @@ readgame(const char * filename, int backup)
/* globale Variablen */
/* TODO: recognize UTF8 BOM */
global.data_version = ri(F);
assert(global.data_version>=MIN_VERSION || !"unsupported data format");
assert(global.data_version<=RELEASE_VERSION || !"unsupported data format");
assert(global.data_version >= NEWSOURCE_VERSION);
assert(global.data_version >= GROWTREE_VERSION);
if(global.data_version >= SAVEXMLNAME_VERSION) {
char basefile[1024];
const char *basearg = "(null)";
@ -1780,9 +1552,7 @@ readgame(const char * filename, int backup)
getchar();
}
}
if (global.data_version >= GLOBAL_ATTRIB_VERSION) {
a_read(F, &global.attribs);
}
a_read(F, &global.attribs);
global.data_turn = turn = ri(F);
ri(F); /* max_unique_id = */
nextborder = ri(F);
@ -1903,14 +1673,8 @@ readgame(const char * filename, int backup)
if (lomem) rds(F, 0);
else xrds(F, &b->display, enc_gamedata);
b->size = ri(F);
if (global.data_version < TYPES_VERSION) {
assert(!"data format is no longer supported");
/* b->type = oldbuildings[ri(F)]; */
}
else {
rss(F, token, sizeof(token));
b->type = bt_find(token);
}
rss(F, token, sizeof(token));
b->type = bt_find(token);
b->region = r;
a_read(F, &b->attribs);
}
@ -2018,11 +1782,6 @@ writegame(const char *filename, int quiet)
FILE * F;
char path[MAX_PATH];
#ifdef USE_PLAYERS
sprintf(path, "%s/%d.players", datapath(), turn);
export_players(path);
#endif
sprintf(path, "%s/%s", datapath(), filename);
#ifdef HAVE_UNISTD_H
if (access(path, R_OK) == 0) {
@ -2031,9 +1790,12 @@ writegame(const char *filename, int quiet)
}
#endif
F = cfopen(path, "w");
if (F==NULL)
if (F==NULL) {
return -1;
} else {
const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf };
fwrite(utf8_bom, 1, 3, F);
}
if (!quiet)
printf("Schreibe die %d. Runde...\n", turn);

View file

@ -28,21 +28,6 @@
* 193: curse bekommen id aus struct unit-nummernraum
*/
#define TYPES_VERSION 117
#define ITEMTYPE_VERSION 190
#define NOFOREST_VERSION 191
#define REGIONAGE_VERSION 192
#define CURSE_NO_VERSION 193
#define EFFSTEALTH_VERSION 194
#define MAGE_ATTRIB_VERSION 195
#define GLOBAL_ATTRIB_VERSION 196
#define BASE36IDS_VERSION 197
#define NEWSOURCE_VERSION 197
#define NEWSTATUS_VERSION 198
#define NEWNAMES_VERSION 199
#define LOCALE_VERSION 300
#define GROUPATTRIB_VERSION 301
#define NEWRESOURCE_VERSION 303
#define GROWTREE_VERSION 305
#define RANDOMIZED_RESOURCES_VERSION 306 /* should be the same, but doesn't work */
#define NEWRACE_VERSION 307

View file

@ -244,7 +244,7 @@ read_newfactions(const char * filename)
if (nf->race==NULL) {
char buffer[32];
int outbytes = sizeof(buffer);
int inbytes = strlen(race);
int inbytes = (int)strlen(race);
isolat1ToUTF8((unsigned char *)buffer, &outbytes, (const unsigned char *)race, &inbytes);
nf->race = findrace(buffer, default_locale);
if (nf->race==NULL) {
@ -717,8 +717,6 @@ autoseed(newfaction ** players, int nsize, boolean new_island)
special = 1;
}
terraform_region(rn, terrain);
/* the new region has an extra 15% chance to have laen */
if (rng_int() % 100 < 15) rsetlaen(r, 5 + rng_int() % 5);
/* the new region has an extra 20% chance to have mallorn */
if (rng_int() % 100 < 20) fset(r, RF_MALLORN);
add_regionlist(rend, rn);

View file

@ -167,50 +167,58 @@ score(void)
sprintf(path, "%s/score", basepath());
scoreFP = fopen(path, "w");
for (f = factions; f; f = f->next) if (f->num_total != 0) {
fprintf(scoreFP, "%8d (%8d/%4.2f%%/%5.2f) %30.30s (%3.3s) %5s (%3d)\n",
f->score, f->score - average_score_of_age(f->age, f->age / 24 + 1),
((float) f->score / (float) allscores) * 100.0,
(float) f->score / f->num_total,
f->name, LOC(default_locale, rc_name(f->race, 0)), factionid(f), f->age);
if (scoreFP) {
const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf };
fwrite(utf8_bom, 1, 3, scoreFP);
for (f = factions; f; f = f->next) if (f->num_total != 0) {
fprintf(scoreFP, "%8d (%8d/%4.2f%%/%5.2f) %30.30s (%3.3s) %5s (%3d)\n",
f->score, f->score - average_score_of_age(f->age, f->age / 24 + 1),
((float) f->score / (float) allscores) * 100.0,
(float) f->score / f->num_total,
f->name, LOC(default_locale, rc_name(f->race, 0)), factionid(f), f->age);
}
fclose(scoreFP);
}
fclose(scoreFP);
if (alliances!=NULL) {
alliance *a;
const item_type * token = it_find("conquesttoken");
sprintf(path, "%s/score.alliances", basepath());
scoreFP = fopen(path, "w");
fprintf(scoreFP, "# alliance:factions:persons:score\n");
if (scoreFP) {
const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf };
fwrite(utf8_bom, 1, 3, scoreFP);
for (a = alliances; a; a = a->next) {
int alliance_score = 0, alliance_number = 0, alliance_factions = 0;
int grails = 0;
fprintf(scoreFP, "# alliance:factions:persons:score\n");
for (f = factions; f; f = f->next) {
if (f->alliance && f->alliance->id == a->id) {
alliance_factions++;
alliance_score += f->score;
alliance_number += f->num_total;
if (token!=NULL) {
unit * u = f->units;
while (u!=NULL) {
item ** iitem = i_find(&u->items, token);
if (iitem!=NULL && *iitem!=NULL) {
grails += (*iitem)->number;
for (a = alliances; a; a = a->next) {
int alliance_score = 0, alliance_number = 0, alliance_factions = 0;
int grails = 0;
for (f = factions; f; f = f->next) {
if (f->alliance && f->alliance->id == a->id) {
alliance_factions++;
alliance_score += f->score;
alliance_number += f->num_total;
if (token!=NULL) {
unit * u = f->units;
while (u!=NULL) {
item ** iitem = i_find(&u->items, token);
if (iitem!=NULL && *iitem!=NULL) {
grails += (*iitem)->number;
}
u=u->nextF;
}
u=u->nextF;
}
}
}
}
fprintf(scoreFP, "%d:%d:%d:%d", a->id, alliance_factions, alliance_number, alliance_score);
if (token!=NULL) fprintf(scoreFP, ":%d", grails);
fputc('\n', scoreFP);
fprintf(scoreFP, "%d:%d:%d:%d", a->id, alliance_factions, alliance_number, alliance_score);
if (token!=NULL) fprintf(scoreFP, ":%d", grails);
fputc('\n', scoreFP);
}
fclose(scoreFP);
}
fclose(scoreFP);
}
}

View file

@ -46,5 +46,3 @@
#define SIMPLE_COMBAT
#define SIMPLE_ESCAPE
#define RESOURCE_CONVERSION /* support for data files < NEWRESOURCE_VERSION */

View file

@ -546,7 +546,7 @@ sp_summon_familiar(castorder *co)
direction_t d;
message * msg;
char zText[NAMESIZE];
size_t size;
char * bufp = zText;
if (get_familiar(mage) != NULL ) {
cmistake(mage, co->order, 199, MSG_MAGIC);
@ -593,8 +593,7 @@ sp_summon_familiar(castorder *co)
for (sk=0;sk<MAXSKILLS;sk++) {
if (rc->bonus[sk] > -5) dh++;
}
zText[0] = 0;
size = sizeof(zText);
for (sk=0;sk<MAXSKILLS;sk++) {
if (rc->bonus[sk] > -5) {
dh--;
@ -602,12 +601,12 @@ sp_summon_familiar(castorder *co)
dh1 = 1;
} else {
if (dh == 0) {
size -= strlcat(zText, (const char*)LOC(mage->faction->locale, "list_and"), size);
bufp += strlcpy(bufp, (const char*)LOC(mage->faction->locale, "list_and"), sizeof(zText) - (bufp-zText));
} else {
size -= strlcat(zText, (const char*)", ", size);
bufp += strlcpy(bufp, (const char*)", ", sizeof(zText) - (bufp-zText));
}
}
size -= strlcat(zText, (const char*)skillname(sk, mage->faction->locale), size);
bufp += strlcpy(bufp, (const char*)skillname(sk, mage->faction->locale), sizeof(zText) - (bufp-zText));
}
}
ADDMSG(&mage->faction->msgs, msg_message("familiar_describe",

View file

@ -22,11 +22,10 @@ strlcpy(char *dst, const char *src, size_t siz) /* copied from OpenBSD source
if (n == 0) {
if (siz != 0)
*d = '\0'; /* NUL-terminate dst */
while (*s++)
;
}
return(s - src - 1); /* count does not include NUL */
/* return(s - src - 1); count does not include NUL */
return siz - n - 1;
}

View file

@ -1306,10 +1306,10 @@ load_inifile(const char * filename)
g_resourcedir = iniparser_getstring(d, "common:res", g_resourcedir);
xmlfile = iniparser_getstring(d, "common:xml", xmlfile);
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:locales", "de");
str = iniparser_getstring(d, "common:locales", "de,en");
make_locales(str);
}
inifile = d;

View file

@ -964,6 +964,4 @@ korrektur(void)
/* Immer ausführen! Erschafft neue Teleport-Regionen, wenn nötig */
create_teleport_plane();
if (global.data_version<TYPES_VERSION) fix_icastles();
}