replacing read/write_default with a function that doesn't abuse layout of the union or endianness. new savefile-format

removeing some old attributes that were never used.
This commit is contained in:
Enno Rehling 2006-02-10 19:48:43 +00:00
parent 102a68f01e
commit 3efd05206e
30 changed files with 369 additions and 344 deletions

View File

@ -16,15 +16,16 @@
#include "eressea.h"
#include "iceberg.h"
#include <attrib.h>
#include <kernel/save.h>
#include <util/attrib.h>
attrib_type at_iceberg = {
"iceberg_drift",
NULL,
NULL,
NULL,
a_writedefault,
a_readdefault,
a_writeint,
a_readint,
ATF_UNIQUE
};

View File

@ -15,15 +15,16 @@
#include <config.h>
#include "key.h"
#include <attrib.h>
#include <kernel/save.h>
#include <util/attrib.h>
attrib_type at_key = {
"key",
NULL,
NULL,
NULL,
a_writedefault,
a_readdefault,
a_writeint,
a_readint,
};
attrib *

View File

@ -16,15 +16,16 @@
#include "eressea.h"
#include "option.h"
#include <attrib.h>
#include <kernel/save.h>
#include <util/attrib.h>
attrib_type at_option_news = {
"option_news",
NULL,
NULL,
NULL,
a_writedefault,
a_readdefault,
a_writeint,
a_readint,
ATF_UNIQUE
};

View File

@ -15,14 +15,15 @@
#include <config.h>
#include "orcification.h"
#include <attrib.h>
#include <kernel/save.h>
#include <util/attrib.h>
/*
* simple attributes that do not yet have their own file
*/
attrib_type at_orcification = {
"orcification", NULL, NULL, NULL, a_writedefault, a_readdefault, ATF_UNIQUE
"orcification", NULL, NULL, NULL, a_writeint, a_readint, ATF_UNIQUE
};
attrib *

View File

@ -15,6 +15,7 @@
#include <config.h>
#include <eressea.h>
#include "overrideroads.h"
#include <kernel/save.h>
attrib_type at_overrideroads = {
"roads_override", NULL, NULL, NULL, &a_writestring, &a_readstring

View File

@ -16,7 +16,8 @@
#include <eressea.h>
#include "racename.h"
#include <attrib.h>
#include <kernel/save.h>
#include <util/attrib.h>
/* libc includes */
#include <stdlib.h>

View File

@ -15,6 +15,7 @@
#include <config.h>
#include <eressea.h>
#include "raceprefix.h"
#include <kernel/save.h>
#include <util/attrib.h>

View File

@ -14,8 +14,8 @@
#include <config.h>
#include "reduceproduction.h"
#include <attrib.h>
#include <kernel/save.h>
#include <util/attrib.h>
static int
age_reduceproduction(attrib *a)
@ -31,8 +31,8 @@ attrib_type at_reduceproduction = {
NULL,
NULL,
age_reduceproduction,
a_writedefault,
a_readdefault,
a_writeshorts,
a_readshorts,
ATF_UNIQUE
};

View File

@ -15,11 +15,13 @@
#include <config.h>
#include "targetregion.h"
#include <eressea.h>
#include <region.h>
#include <kernel/eressea.h>
#include <kernel/region.h>
#include <kernel/save.h>
#include <attrib.h>
#include <resolve.h>
#include <util/attrib.h>
#include <util/resolve.h>
static void
write_targetregion(const attrib * a, FILE * F)
@ -31,7 +33,7 @@ static int
read_targetregion(attrib * a, FILE * F)
{
if (global.data_version < BASE36IDS_VERSION) {
a_readdefault(a, F);
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);

View File

@ -1439,9 +1439,6 @@ randomevents(void)
double nv = normalvariate(k, k/4);
int inv = (int)nv;
int delta = min(n, inv);
if (inv<0) {
nv = normalvariate(k, k/4);
}
i_change(itmp, itm->type, -delta);
}
if (itm==*itmp) itmp=&itm->next;

View File

@ -20,6 +20,7 @@
#include <kernel/region.h>
#include <kernel/faction.h>
#include <kernel/unit.h>
#include <kernel/save.h>
#include <kernel/skill.h>
#include <kernel/curse.h>
#include <kernel/message.h>
@ -49,8 +50,8 @@ static attrib_type at_peaceimmune = {
"peaceimmune",
NULL, NULL,
age_peaceimmune,
a_writedefault,
a_readdefault
a_writeint,
a_readint
};
static int

View File

@ -2089,17 +2089,11 @@ attack(battle *b, troop ta, const att *a, int numattack)
ta.fighter->action_counter++;
}
if (td.fighter->unit->ship) {
if(a_find(td.fighter->unit->ship->attribs, &at_nodestroy) == NULL) {
td.fighter->unit->ship->damage += DAMAGE_SCALE * dice_rand(a->data.dice);
}
} else if (td.fighter->unit->building) {
if(a_find(td.fighter->unit->building->attribs, &at_nodestroy) == NULL) {
damage_building(b, td.fighter->unit->building,
dice_rand(a->data.dice));
damage_building(b, td.fighter->unit->building, dice_rand(a->data.dice));
}
}
}
}
void

View File

@ -16,9 +16,10 @@
#include "eressea.h"
#include "border.h"
#include "unit.h"
#include "terrain.h"
#include "region.h"
#include "save.h"
#include "terrain.h"
#include "unit.h"
/* libc includes */
#include <assert.h>
@ -219,8 +220,8 @@ attrib_type at_countdown = {
DEFAULT_INIT,
DEFAULT_FINALIZE,
a_agecountdown,
DEFAULT_WRITE,
DEFAULT_READ
a_writeint,
a_readint
};
void

View File

@ -383,10 +383,6 @@ destroy_cmd(unit * u, struct order * ord)
if (u->building) {
building *b = u->building;
if (a_find(b->attribs, &at_nodestroy)) {
cmistake(u, ord, 14, MSG_EVENT);
return 0;
}
if(n >= b->size) {
/* destroy completly */
@ -407,10 +403,6 @@ destroy_cmd(unit * u, struct order * ord)
}
} else if (u->ship) {
sh = u->ship;
if (a_find(sh->attribs, &at_nodestroy)) {
cmistake(u, ord, 14, MSG_EVENT);
return 0;
}
if (fval(r->terrain, SEA_REGION)) {
cmistake(u, ord, 14, MSG_EVENT);

View File

@ -103,14 +103,6 @@ attrib_type at_building_action = {
lc_write, lc_read
};
attrib_type at_nodestroy = {
"nodestroy",
NULL, NULL, NULL,
a_writedefault,
a_readdefault,
ATF_UNIQUE
};
building_typelist *buildingtypes;
const building_type *

View File

@ -142,7 +142,6 @@ extern struct building *findbuilding(int n);
extern struct unit * buildingowner(const struct region * r, const struct building * b);
extern attrib_type at_nodestroy;
extern attrib_type at_building_action;
#ifdef WDW_PYRAMID

View File

@ -483,8 +483,8 @@ static attrib_type at_maxmagicians = {
init_maxmagicians,
NULL,
NULL,
a_writedefault,
a_readdefault,
a_writeint,
a_readint,
ATF_UNIQUE
};
@ -500,8 +500,8 @@ static attrib_type at_npcfaction = {
init_npcfaction,
NULL,
NULL,
a_writedefault,
a_readdefault,
a_writeint,
a_readint,
ATF_UNIQUE
};
@ -2398,8 +2398,8 @@ attrib_type at_germs = {
DEFAULT_INIT,
DEFAULT_FINALIZE,
DEFAULT_AGE,
DEFAULT_WRITE,
DEFAULT_READ,
a_writeshorts,
a_readshorts,
ATF_UNIQUE
};
@ -2411,8 +2411,8 @@ attrib_type at_guard = {
DEFAULT_INIT,
DEFAULT_FINALIZE,
DEFAULT_AGE,
DEFAULT_WRITE,
DEFAULT_READ,
a_writeint,
a_readint,
ATF_UNIQUE
};
@ -3108,7 +3108,6 @@ attrib_init(void)
at_register(&at_deathcount);
at_register(&at_chaoscount);
at_register(&at_woodcount);
at_register(&at_road);
/* neue UNIT-Attribute */
at_register(&at_siege);
@ -3140,7 +3139,6 @@ attrib_init(void)
at_register(&at_xontormiaexpress); /* required for old datafiles */
#endif
at_register(&at_speedup);
at_register(&at_nodestroy);
at_register(&at_building_action);
}

View File

@ -173,6 +173,7 @@ struct building_type;
#define SPELLNAME_VERSION 321 /* reference spells by name */
#define TERRAIN_VERSION 322 /* terrains are a full type and saved by name */
#define REGIONITEMS_VERSION 323 /* regions have items */
#define ATTRIBREAD_VERSION 324 /* remove a_readint */
#define MIN_VERSION CURSETYPE_VERSION
#define REGIONOWNERS_VERSION 400
@ -180,7 +181,7 @@ struct building_type;
#ifdef ENEMIES
# define RELEASE_VERSION ENEMIES_VERSION
#else
# define RELEASE_VERSION REGIONITEMS_VERSION
# define RELEASE_VERSION ATTRIBREAD_VERSION
#endif
#if RESOURCE_CONVERSION

View File

@ -19,6 +19,7 @@
/* kernel includes */
#include "unit.h"
#include "save.h"
#include "race.h"
#include "region.h"
#include "item.h"
@ -39,7 +40,7 @@
#include <stdlib.h>
attrib_type at_faction_special = {
"faction_special", NULL, NULL, NULL, a_writedefault, a_readdefault
"faction_special", NULL, NULL, NULL, a_writeshorts, a_readshorts
};
int
@ -48,7 +49,7 @@ age_prayer_timeout(attrib *a) {
}
attrib_type at_prayer_timeout = {
"prayer_timeout", NULL, NULL, age_prayer_timeout, a_writedefault, a_readdefault
"prayer_timeout", NULL, NULL, age_prayer_timeout, a_writeshorts, a_readshorts
};
attrib_type at_prayer_effect = {
@ -56,15 +57,15 @@ attrib_type at_prayer_effect = {
};
attrib_type at_wyrm = {
"wyrm", NULL, NULL, NULL, a_writedefault, a_readdefault
"wyrm", NULL, NULL, NULL, a_writeint, a_readint
};
attrib_type at_fshidden = {
"fshidden", NULL, NULL, NULL, a_writedefault, a_readdefault
"fshidden", NULL, NULL, NULL, a_writeint, a_readint
};
attrib_type at_jihad = {
"jihad", NULL, NULL, NULL, a_writedefault, a_readdefault
"jihad", NULL, NULL, NULL, a_writeshorts, a_readshorts
};
struct fspecialdata fspecials[MAXFACTIONSPECIALS] = {

View File

@ -38,6 +38,7 @@
#include "race.h"
#include "region.h"
#include "render.h"
#include "save.h"
#include "ship.h"
#include "skill.h"
#include "terrain.h"
@ -45,8 +46,9 @@
#include "unit.h"
/* util includes */
#include <util/goodies.h>
#include <util/attrib.h>
#include <util/base36.h>
#include <util/goodies.h>
#include <util/language.h>
#include <util/rand.h>
@ -76,8 +78,8 @@ static attrib_type at_traveldir = {
DEFAULT_INIT,
DEFAULT_FINALIZE,
DEFAULT_AGE, /* Weil normales Aging an ungünstiger Stelle */
DEFAULT_WRITE,
DEFAULT_READ
a_writechars,
a_readchars
};
typedef struct follower {
@ -170,8 +172,8 @@ attrib_type at_speedup = {
"speedup",
NULL, NULL,
age_speedup,
a_writedefault,
a_readdefault
a_writeint,
a_readint
};
/* ------------------------------------------------------------- */

View File

@ -34,6 +34,7 @@
#include "plane.h"
#include "region.h"
#include "resources.h"
#include "save.h"
#include "terrain.h"
#include "terrainid.h"
#include "unit.h"
@ -481,8 +482,8 @@ attrib_type at_chaoscount = {
DEFAULT_INIT,
DEFAULT_FINALIZE,
DEFAULT_AGE,
DEFAULT_WRITE,
DEFAULT_READ,
a_writeint,
a_readint,
ATF_UNIQUE
};
@ -494,8 +495,8 @@ attrib_type at_deathcount = {
DEFAULT_INIT,
DEFAULT_FINALIZE,
DEFAULT_AGE,
DEFAULT_WRITE,
DEFAULT_READ,
a_writeint,
a_readint,
ATF_UNIQUE
};
@ -507,8 +508,8 @@ attrib_type at_woodcount = {
DEFAULT_INIT,
DEFAULT_FINALIZE,
DEFAULT_AGE,
DEFAULT_WRITE,
DEFAULT_READ,
a_writeint,
a_readint,
ATF_UNIQUE
};
@ -558,22 +559,6 @@ rlaen(const region * r)
return a->data.i;
}
/***************/
/* at_road */
/***************/
attrib_type at_road = {
"road",
DEFAULT_INIT,
DEFAULT_FINALIZE,
DEFAULT_AGE,
#if RELEASE_VERSION<NEWROAD_VERSION
DEFAULT_WRITE,
#else
NULL,
#endif
DEFAULT_READ
};
void
rsetroad(region * r, direction_t d, short val)
{

View File

@ -151,7 +151,6 @@ extern attrib_type at_chaoscount;
extern attrib_type at_woodcount;
extern attrib_type at_deathcount;
extern attrib_type at_travelunit;
extern attrib_type at_road;
extern attrib_type at_laen;
void initrhash(void);

View File

@ -2105,3 +2105,104 @@ writegame(const char *filename, char quiet)
printf("\nOk.\n");
return 0;
}
int
a_readint(attrib * a, FILE * f)
{
/* assert(sizeof(int)==sizeof(a->data)); */
fscanf(f, "%d", &a->data.i);
return AT_READ_OK;
}
void
a_writeint(const attrib * a, FILE * f)
{
fprintf(f, "%d ", a->data.i);
}
int
a_readshorts(attrib * a, FILE * f)
{
if (global.data_version<ATTRIBREAD_VERSION) {
return a_readint(a, f);
}
fscanf(f, "%hd %hd", &a->data.sa[0], &a->data.sa[1]);
return AT_READ_OK;
}
void
a_writeshorts(const attrib * a, FILE * f)
{
fprintf(f, "%hd %hd ", a->data.sa[0], a->data.sa[1]);
}
int
a_readchars(attrib * a, FILE * f)
{
if (global.data_version<ATTRIBREAD_VERSION) {
return a_readint(a, f);
}
fscanf(f, "%c %c %c %c",
&a->data.ca[0], &a->data.ca[1], &a->data.ca[2], &a->data.ca[3]);
return AT_READ_OK;
}
void
a_writechars(const attrib * a, FILE * f)
{
fprintf(f, "%c %c %c %c ",
a->data.ca[0], a->data.ca[1], a->data.ca[2], a->data.ca[3]);
}
int
a_readvoid(attrib * a, FILE * f)
{
if (global.data_version<ATTRIBREAD_VERSION) {
return a_readint(a, f);
}
return AT_READ_OK;
}
void
a_writevoid(const attrib * a, FILE * f)
{
}
static char *
read_quoted(FILE * f, char *c, size_t size)
{
char * s = c;
do {
*s = (char) fgetc(f);
} while (*s!='"');
for (;;) {
*s = (char) fgetc(f);
if (*s=='"') break;
if (s<c+size) ++s;
}
*s = 0;
return c;
}
int
a_readstring(attrib * a, FILE * f)
{
char zText[4096];
read_quoted(f, zText, sizeof(zText));
a->data.v = strdup(zText);
return AT_READ_OK;
}
void
a_writestring(const attrib * a, FILE * f)
{
assert(a->data.v);
fprintf(f, "\"%s\" ", (char*)a->data.v);
}
void
a_finalizestring(attrib * a)
{
free(a->data.v);
}

View File

@ -71,6 +71,18 @@ extern struct faction * readfaction(FILE * stream);
extern void fwriteorder(FILE * F, const struct order * ord, const struct locale * lang);
extern int a_readint(struct attrib * a, FILE * F);
extern void a_writeint(const struct attrib * a, FILE * F);
extern int a_readshorts(struct attrib * a, FILE * F);
extern void a_writeshorts(const struct attrib * a, FILE * F);
extern int a_readchars(struct attrib * a, FILE * F);
extern void a_writechars(const struct attrib * a, FILE * F);
extern int a_readvoid(struct attrib * a, FILE * F);
extern void a_writevoid(const struct attrib * a, FILE * F);
extern int a_readstring(struct attrib * a, FILE * F);
extern void a_writestring(const struct attrib * a, FILE * F);
extern void a_finalizestring(struct attrib * a);
#ifdef __cplusplus
}
#endif

View File

@ -34,6 +34,7 @@
#include "plane.h"
#include "race.h"
#include "region.h"
#include "save.h"
#include "ship.h"
#include "skill.h"
#include "terrain.h"
@ -42,10 +43,10 @@
/* util includes */
#include <util/base36.h>
#include <event.h>
#include <goodies.h>
#include <resolve.h>
#include <variant.h>
#include <util/event.h>
#include <util/goodies.h>
#include <util/resolve.h>
#include <util/variant.h>
/* libc includes */
#include <assert.h>
@ -546,7 +547,7 @@ read_unit_reference(unit ** up, FILE * F)
}
attrib_type at_stealth = {
"stealth", NULL, NULL, NULL, DEFAULT_WRITE, DEFAULT_READ
"stealth", NULL, NULL, NULL, a_writeint, a_readint
};
void

View File

@ -50,7 +50,7 @@
#define PFL_MUSEUM PFL_NOMONSTERS | PFL_NOCOORDS | PFL_NORECRUITS | PFL_NOGIVE | PFL_NOATTACK | PFL_NOTERRAIN | PFL_NOMAGIC | PFL_NOSTEALTH | PFL_NOTEACH | PFL_NOBUILD | PFL_NOFEED
attrib_type at_museumexit = {
"museumexit", NULL, NULL, NULL, a_writedefault, a_readdefault
"museumexit", NULL, NULL, NULL, a_writeshorts, a_readshorts
};
static void
@ -90,7 +90,7 @@ attrib_type at_museumgivebackcookie = {
};
attrib_type at_warden = {
"itemwarden", NULL, NULL, NULL, a_writedefault, a_readdefault
"itemwarden", NULL, NULL, NULL, a_writeint, a_readint
};
static void

View File

@ -26,6 +26,7 @@
#include <kernel/message.h>
#include <kernel/order.h>
#include <kernel/region.h>
#include <kernel/save.h>
#include <kernel/ship.h>
#include <kernel/unit.h>
@ -39,8 +40,8 @@ attrib_type at_xontormiaexpress = {
DEFAULT_INIT,
DEFAULT_FINALIZE,
DEFAULT_AGE,
DEFAULT_WRITE,
DEFAULT_READ,
a_writeint,
a_readint,
ATF_UNIQUE
};

View File

@ -42,6 +42,7 @@ extern void ct_register(const struct curse_type * ct);
#include <kernel/pool.h>
#include <kernel/race.h>
#include <kernel/region.h>
#include <kernel/save.h>
#include <kernel/ship.h>
#include <kernel/skill.h>
#include <kernel/spell.h>
@ -91,11 +92,11 @@ extern void ct_register(const struct curse_type * ct);
static variant zero_effect = { 0 };
attrib_type at_unitdissolve = {
"unitdissolve", NULL, NULL, NULL, a_writedefault, a_readdefault
"unitdissolve", NULL, NULL, NULL, a_writechars, a_readchars
};
attrib_type at_wdwpyramid = {
"wdwpyramid", NULL, NULL, NULL, a_writedefault, a_readdefault
"wdwpyramid", NULL, NULL, NULL, a_writevoid, a_readvoid
};
/* ----------------------------------------------------------------------- */

View File

@ -180,59 +180,6 @@ a_new(const attrib_type * at) {
return a;
}
int
a_readdefault(attrib * a, FILE * f)
{
/* assert(sizeof(int)==sizeof(a->data)); */
fscanf(f, "%d", &a->data.i);
return AT_READ_OK;
}
void
a_writedefault(const attrib * a, FILE * f)
{
fprintf(f, "%d ", a->data.i);
}
static char *
read_quoted(FILE * f, char *c, size_t size)
{
char * s = c;
do {
*s = (char) fgetc(f);
} while (*s!='"');
for (;;) {
*s = (char) fgetc(f);
if (*s=='"') break;
if (s<c+size) ++s;
}
*s = 0;
return c;
}
int
a_readstring(attrib * a, FILE * f)
{
char zText[4096];
read_quoted(f, zText, sizeof(zText));
a->data.v = strdup(zText);
return AT_READ_OK;
}
void
a_writestring(const attrib * a, FILE * f)
{
assert(a->data.v);
fprintf(f, "\"%s\" ", (char*)a->data.v);
}
void
a_finalizestring(attrib * a)
{
free(a->data.v);
}
int
a_age(attrib ** p)
{

View File

@ -55,13 +55,6 @@ typedef struct attrib_type {
unsigned int hashkey;
} attrib_type;
extern int a_readdefault(attrib * a, FILE * f);
extern void a_writedefault(const attrib * a, FILE * f);
extern int a_readstring(attrib * a, FILE * f);
extern void a_writestring(const attrib * a, FILE * f);
extern void a_finalizestring(attrib * a);
extern void at_register(attrib_type * at);
extern attrib * a_select(attrib * a, const void * data, boolean(*compare)(const attrib *, const void *));
@ -74,14 +67,12 @@ extern attrib * a_new(const attrib_type * at);
extern void a_free(attrib * a);
extern int a_age(attrib ** attribs);
extern int a_read(FILE * f, attrib ** attribs);
extern void a_write(FILE * f, const attrib * attribs);
extern int a_read(FILE * F, attrib ** attribs);
extern void a_write(FILE * F, const attrib * attribs);
#define DEFAULT_AGE NULL
#define DEFAULT_INIT NULL
#define DEFAULT_FINALIZE NULL
#define DEFAULT_WRITE a_writedefault
#define DEFAULT_READ a_readdefault
#define NO_WRITE NULL
#define NO_READ NULL