From 3efd05206e8445593fb19b099744a9953a64f42f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 10 Feb 2006 19:48:43 +0000 Subject: [PATCH] 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. --- src/common/attributes/iceberg.c | 7 +- src/common/attributes/key.c | 7 +- src/common/attributes/option.c | 7 +- src/common/attributes/orcification.c | 5 +- src/common/attributes/overrideroads.c | 1 + src/common/attributes/racename.c | 3 +- src/common/attributes/raceprefix.c | 1 + src/common/attributes/reduceproduction.c | 8 +- src/common/attributes/targetregion.c | 12 +- src/common/gamecode/randenc.c | 339 +++++++++++------------ src/common/items/artrewards.c | 5 +- src/common/kernel/battle.c | 14 +- src/common/kernel/border.c | 9 +- src/common/kernel/build.c | 8 - src/common/kernel/building.c | 8 - src/common/kernel/building.h | 1 - src/common/kernel/eressea.c | 18 +- src/common/kernel/eressea.h | 3 +- src/common/kernel/karma.c | 11 +- src/common/kernel/movement.c | 12 +- src/common/kernel/region.c | 29 +- src/common/kernel/region.h | 1 - src/common/kernel/save.c | 101 +++++++ src/common/kernel/save.h | 12 + src/common/kernel/unit.c | 11 +- src/common/modules/museum.c | 4 +- src/common/modules/xecmd.c | 5 +- src/common/spells/spells.c | 5 +- src/common/util/attrib.c | 53 ---- src/common/util/attrib.h | 13 +- 30 files changed, 369 insertions(+), 344 deletions(-) diff --git a/src/common/attributes/iceberg.c b/src/common/attributes/iceberg.c index 4f6104216..a182770b5 100644 --- a/src/common/attributes/iceberg.c +++ b/src/common/attributes/iceberg.c @@ -16,15 +16,16 @@ #include "eressea.h" #include "iceberg.h" -#include +#include +#include attrib_type at_iceberg = { "iceberg_drift", NULL, NULL, NULL, - a_writedefault, - a_readdefault, + a_writeint, + a_readint, ATF_UNIQUE }; diff --git a/src/common/attributes/key.c b/src/common/attributes/key.c index d0f508eaf..2f8c12871 100644 --- a/src/common/attributes/key.c +++ b/src/common/attributes/key.c @@ -15,15 +15,16 @@ #include #include "key.h" -#include +#include +#include attrib_type at_key = { "key", NULL, NULL, NULL, - a_writedefault, - a_readdefault, + a_writeint, + a_readint, }; attrib * diff --git a/src/common/attributes/option.c b/src/common/attributes/option.c index 135dca381..369ba667e 100644 --- a/src/common/attributes/option.c +++ b/src/common/attributes/option.c @@ -16,15 +16,16 @@ #include "eressea.h" #include "option.h" -#include +#include +#include attrib_type at_option_news = { "option_news", NULL, NULL, NULL, - a_writedefault, - a_readdefault, + a_writeint, + a_readint, ATF_UNIQUE }; diff --git a/src/common/attributes/orcification.c b/src/common/attributes/orcification.c index a5d0aafd3..f6bc70d44 100644 --- a/src/common/attributes/orcification.c +++ b/src/common/attributes/orcification.c @@ -15,14 +15,15 @@ #include #include "orcification.h" -#include +#include +#include /* * 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 * diff --git a/src/common/attributes/overrideroads.c b/src/common/attributes/overrideroads.c index de49b8664..b9a6fc6ca 100644 --- a/src/common/attributes/overrideroads.c +++ b/src/common/attributes/overrideroads.c @@ -15,6 +15,7 @@ #include #include #include "overrideroads.h" +#include attrib_type at_overrideroads = { "roads_override", NULL, NULL, NULL, &a_writestring, &a_readstring diff --git a/src/common/attributes/racename.c b/src/common/attributes/racename.c index 03f3ee259..8e4956d57 100644 --- a/src/common/attributes/racename.c +++ b/src/common/attributes/racename.c @@ -16,7 +16,8 @@ #include #include "racename.h" -#include +#include +#include /* libc includes */ #include diff --git a/src/common/attributes/raceprefix.c b/src/common/attributes/raceprefix.c index f8c6d0642..90359d2cc 100644 --- a/src/common/attributes/raceprefix.c +++ b/src/common/attributes/raceprefix.c @@ -15,6 +15,7 @@ #include #include #include "raceprefix.h" +#include #include diff --git a/src/common/attributes/reduceproduction.c b/src/common/attributes/reduceproduction.c index 7342a3ce5..b5a3202df 100644 --- a/src/common/attributes/reduceproduction.c +++ b/src/common/attributes/reduceproduction.c @@ -14,8 +14,8 @@ #include #include "reduceproduction.h" - -#include +#include +#include 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 }; diff --git a/src/common/attributes/targetregion.c b/src/common/attributes/targetregion.c index 9e9b12447..d78a69a26 100644 --- a/src/common/attributes/targetregion.c +++ b/src/common/attributes/targetregion.c @@ -15,11 +15,13 @@ #include #include "targetregion.h" -#include -#include +#include +#include +#include -#include -#include + +#include +#include 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); diff --git a/src/common/gamecode/randenc.c b/src/common/gamecode/randenc.c index 67b008166..a5e333f57 100644 --- a/src/common/gamecode/randenc.c +++ b/src/common/gamecode/randenc.c @@ -1224,191 +1224,191 @@ randomevents(void) if (rand() % 100 < prob) { ++increase; } - } - if (increase) { - if (u->race == new_race[RC_ORC]) { - int i; - struct orcskills { - skill_t skill; - int level; - } skills [] = { - { SK_MELEE, 1 }, { SK_SPEAR, 1 }, { SK_TACTICS, 0 }, - { SK_LONGBOW, 0 }, { SK_CROSSBOW, 0 }, { SK_CATAPULT, 0 }, - { SK_AUSDAUER, 0 }, { NOSKILL, 0 } - }; - for (i=0;skills[i].skill!=NOSKILL;++i) { - int k = get_level(u, skills[i].skill); - change_skill(u, skills[i].skill, increase * max(k, s)); - } - } + } + if (increase) { + if (u->race == new_race[RC_ORC]) { + int i; + struct orcskills { + skill_t skill; + int level; + } skills [] = { + { SK_MELEE, 1 }, { SK_SPEAR, 1 }, { SK_TACTICS, 0 }, + { SK_LONGBOW, 0 }, { SK_CROSSBOW, 0 }, { SK_CATAPULT, 0 }, + { SK_AUSDAUER, 0 }, { NOSKILL, 0 } + }; + for (i=0;skills[i].skill!=NOSKILL;++i) { + int k = get_level(u, skills[i].skill); + change_skill(u, skills[i].skill, increase * max(k, s)); + } + } - set_number(u, u->number + increase); + set_number(u, u->number + increase); - u->hp += unit_max_hp(u) * increase; - ADDMSG(&u->faction->msgs, msg_message("orcgrowth", - "unit amount race", u, increase, u->race)); - } - } - } - } + u->hp += unit_max_hp(u) * increase; + ADDMSG(&u->faction->msgs, msg_message("orcgrowth", + "unit amount race", u, increase, u->race)); + } + } + } + } #endif - for (r = regions; r; r = r->next) { + for (r = regions; r; r = r->next) { #if !RACE_ADJUSTMENTS - /* Elfen generieren Wald */ - if (r->land && !fval(r, RF_MALLORN)) { - int trees = rtrees(r, 2); - int maxgen = (production(r) * MAXPEASANTS_PER_AREA)/8; - for (u = r->units; u && maxgen > 0; u = u->next) { - if (u->race == new_race[RC_ELF]) { - for (n = u->number; n && maxgen > 0; n--) { - if (rand() % 1000 < 15) { /* 1.5% Chance */ - trees++; - } - maxgen--; - } - } - } - rsettrees(r, 2, trees); - } /* !RACE_ADJUSTMENTS */ + /* Elfen generieren Wald */ + if (r->land && !fval(r, RF_MALLORN)) { + int trees = rtrees(r, 2); + int maxgen = (production(r) * MAXPEASANTS_PER_AREA)/8; + for (u = r->units; u && maxgen > 0; u = u->next) { + if (u->race == new_race[RC_ELF]) { + for (n = u->number; n && maxgen > 0; n--) { + if (rand() % 1000 < 15) { /* 1.5% Chance */ + trees++; + } + maxgen--; + } + } + } + rsettrees(r, 2, trees); + } /* !RACE_ADJUSTMENTS */ #endif - } + } - /* Orkifizierte Regionen mutieren und mutieren zurück */ + /* Orkifizierte Regionen mutieren und mutieren zurück */ - for (r = regions; r; r = r->next) { - if (fval(r, RF_ORCIFIED)) { - direction_t dir; - double probability = 0.0; - for (dir = 0; dir < MAXDIRECTIONS; dir++) { - region *rc = rconnect(r, dir); - if (rc && rpeasants(rc) > 0 && !fval(rc, RF_ORCIFIED)) probability += 0.02; - } - if (chance(probability)) { - ADDMSG(&r->msgs, msg_message("deorcified", "region", r)); - freset(r, RF_ORCIFIED); - } - } else { - attrib *a = a_find(r->attribs, &at_orcification); - if (a!=NULL) { - double probability = 0.0; - if (rpeasants(r) <= 0) continue; - probability = a->data.i/(double)rpeasants(r); - if (chance(probability)) { - fset(r, RF_ORCIFIED); - a_remove(&r->attribs, a); - ADDMSG(&r->msgs, msg_message("orcified", "region", r)); - } else { - a->data.i -= max(10,a->data.i/10); - if (a->data.i <= 0) a_remove(&r->attribs, a); - } - } - } - } + for (r = regions; r; r = r->next) { + if (fval(r, RF_ORCIFIED)) { + direction_t dir; + double probability = 0.0; + for (dir = 0; dir < MAXDIRECTIONS; dir++) { + region *rc = rconnect(r, dir); + if (rc && rpeasants(rc) > 0 && !fval(rc, RF_ORCIFIED)) probability += 0.02; + } + if (chance(probability)) { + ADDMSG(&r->msgs, msg_message("deorcified", "region", r)); + freset(r, RF_ORCIFIED); + } + } else { + attrib *a = a_find(r->attribs, &at_orcification); + if (a!=NULL) { + double probability = 0.0; + if (rpeasants(r) <= 0) continue; + probability = a->data.i/(double)rpeasants(r); + if (chance(probability)) { + fset(r, RF_ORCIFIED); + a_remove(&r->attribs, a); + ADDMSG(&r->msgs, msg_message("orcified", "region", r)); + } else { + a->data.i -= max(10,a->data.i/10); + if (a->data.i <= 0) a_remove(&r->attribs, a); + } + } + } + } - /* Vulkane qualmen, brechen aus ... */ - for (r = regions; r; r = r->next) { - if (rterrain(r)==T_VOLCANO_SMOKING && a_find(r->attribs, &at_reduceproduction)) { - ADDMSG(&r->msgs, msg_message("volcanostopsmoke", "region", r)); - rsetterrain(r, T_VOLCANO); - } else switch(rterrain(r)) { - case T_VOLCANO: - if (rand()%100 < 4) { - ADDMSG(&r->msgs, msg_message("volcanostartsmoke", "region", r)); - rsetterrain(r, T_VOLCANO_SMOKING); - } - break; - case T_VOLCANO_SMOKING: - if (rand()%100 < 12) { - ADDMSG(&r->msgs, msg_message("volcanostopsmoke", "region", r)); - rsetterrain(r, T_VOLCANO); - } else if (rand()%100 < 8) { - volcano_outbreak(r); - } - break; - } - } + /* Vulkane qualmen, brechen aus ... */ + for (r = regions; r; r = r->next) { + if (rterrain(r)==T_VOLCANO_SMOKING && a_find(r->attribs, &at_reduceproduction)) { + ADDMSG(&r->msgs, msg_message("volcanostopsmoke", "region", r)); + rsetterrain(r, T_VOLCANO); + } else switch(rterrain(r)) { + case T_VOLCANO: + if (rand()%100 < 4) { + ADDMSG(&r->msgs, msg_message("volcanostartsmoke", "region", r)); + rsetterrain(r, T_VOLCANO_SMOKING); + } + break; + case T_VOLCANO_SMOKING: + if (rand()%100 < 12) { + ADDMSG(&r->msgs, msg_message("volcanostopsmoke", "region", r)); + rsetterrain(r, T_VOLCANO); + } else if (rand()%100 < 8) { + volcano_outbreak(r); + } + break; + } + } - /* Monumente zerfallen, Schiffe verfaulen */ + /* Monumente zerfallen, Schiffe verfaulen */ - for (r = regions; r; r = r->next) { - for (b = rbuildings(r); b; b = b2) { - b2 = b->next; - if (fval(b->type, BTF_DECAY) && !buildingowner(r, b)) { - b->size -= max(1, (b->size * 20) / 100); - if (b->size == 0) { - destroy_building(b); - } - } - } - } + for (r = regions; r; r = r->next) { + for (b = rbuildings(r); b; b = b2) { + b2 = b->next; + if (fval(b->type, BTF_DECAY) && !buildingowner(r, b)) { + b->size -= max(1, (b->size * 20) / 100); + if (b->size == 0) { + destroy_building(b); + } + } + } + } /* monster-einheiten desertieren */ - for (r = regions; r; r=r->next) { - for (u=r->units; u; u=u->next) { - if (u->faction->no != MONSTER_FACTION - && (u->race->flags & RCF_DESERT)) { - if (fval(u, UFL_ISNEW)) continue; - if (rand()%100 < 5) { - ADDMSG(&u->faction->msgs, msg_message("desertion", - "unit region", u, r)); - u_setfaction(u, findfaction(MONSTER_FACTION)); - } - } - } - } + for (r = regions; r; r=r->next) { + for (u=r->units; u; u=u->next) { + if (u->faction->no != MONSTER_FACTION + && (u->race->flags & RCF_DESERT)) { + if (fval(u, UFL_ISNEW)) continue; + if (rand()%100 < 5) { + ADDMSG(&u->faction->msgs, msg_message("desertion", + "unit region", u, r)); + u_setfaction(u, findfaction(MONSTER_FACTION)); + } + } + } + } /* lycanthropen werden werwölfe */ - for (f = factions; f; f=f->next) { - int level = fspecial(f, FS_LYCANTROPE); - if(level > 0) { - for(u = f->units; u; u=u->nextF) { - if(rand()%100 < 2*level) { - ADDMSG(&u->faction->msgs, msg_message("becomewere", - "unit region", u, u->region)); - fset(u, UFL_WERE); - } - } - } - } + for (f = factions; f; f=f->next) { + int level = fspecial(f, FS_LYCANTROPE); + if(level > 0) { + for(u = f->units; u; u=u->nextF) { + if(rand()%100 < 2*level) { + ADDMSG(&u->faction->msgs, msg_message("becomewere", + "unit region", u, u->region)); + fset(u, UFL_WERE); + } + } + } + } - /* Frühling, die Bäume schlagen aus. */ + /* Frühling, die Bäume schlagen aus. */ - for (r = regions; r; r = r->next) { - if (fval(r, RF_CHAOTIC) ||(r->x >= -13 && r->x <= -6 && r->y >= 50 && r->y <= 57)) { - if (woodcount(r) >= 40 && rand()%100 < 33) { - int trees = rtrees(r,2); - int treemen = rand()%(max(50,trees)/3); - struct message * msg; + for (r = regions; r; r = r->next) { + if (fval(r, RF_CHAOTIC) ||(r->x >= -13 && r->x <= -6 && r->y >= 50 && r->y <= 57)) { + if (woodcount(r) >= 40 && rand()%100 < 33) { + int trees = rtrees(r,2); + int treemen = rand()%(max(50,trees)/3); + struct message * msg; - treemen = max(25, treemen); - woodcounts(r, -40); - trees = max(0, trees-treemen); - rsettrees(r, 2, trees); - u = createunit(r, findfaction(MONSTER_FACTION),treemen, new_race[RC_TREEMAN]); + treemen = max(25, treemen); + woodcounts(r, -40); + trees = max(0, trees-treemen); + rsettrees(r, 2, trees); + u = createunit(r, findfaction(MONSTER_FACTION),treemen, new_race[RC_TREEMAN]); fset(u, UFL_ISNEW|UFL_MOVED); - set_level(u, SK_OBSERVATION, 2); - if (u->number == 1) - set_string(&u->name, "Ein wütender Ent"); - else - set_string(&u->name, "Wütende Ents"); + set_level(u, SK_OBSERVATION, 2); + if (u->number == 1) + set_string(&u->name, "Ein wütender Ent"); + else + set_string(&u->name, "Wütende Ents"); - log_printf("%d Ents in %s.\n", u->number, regionname(r, NULL)); + log_printf("%d Ents in %s.\n", u->number, regionname(r, NULL)); - msg = msg_message("entrise", "region", r); - add_message(&r->msgs, msg); - for (u=r->units;u;u=u->next) freset(u->faction, FL_DH); - for (u=r->units;u;u=u->next) { - if (fval(u->faction, FL_DH)) continue; - fset(u->faction, FL_DH); - add_message(&u->faction->msgs, msg); - } - msg_release(msg); - } - } - } + msg = msg_message("entrise", "region", r); + add_message(&r->msgs, msg); + for (u=r->units;u;u=u->next) freset(u->faction, FL_DH); + for (u=r->units;u;u=u->next) { + if (fval(u->faction, FL_DH)) continue; + fset(u->faction, FL_DH); + add_message(&u->faction->msgs, msg); + } + msg_release(msg); + } + } + } /* Chaos */ @@ -1435,15 +1435,12 @@ randomevents(void) item * itm = *itmp; int n = itm->number; double k = n*rot_chance/100.0; - if (fval(itm->type, ITF_HERB)) { - 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 (fval(itm->type, ITF_HERB)) { + double nv = normalvariate(k, k/4); + int inv = (int)nv; + int delta = min(n, inv); + i_change(itmp, itm->type, -delta); + } if (itm==*itmp) itmp=&itm->next; } } diff --git a/src/common/items/artrewards.c b/src/common/items/artrewards.c index 23ea15d8d..abbee8f5c 100644 --- a/src/common/items/artrewards.c +++ b/src/common/items/artrewards.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -49,8 +50,8 @@ static attrib_type at_peaceimmune = { "peaceimmune", NULL, NULL, age_peaceimmune, - a_writedefault, - a_readdefault + a_writeint, + a_readint }; static int diff --git a/src/common/kernel/battle.c b/src/common/kernel/battle.c index 63d33d745..ab31fd939 100644 --- a/src/common/kernel/battle.c +++ b/src/common/kernel/battle.c @@ -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); - } + 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 diff --git a/src/common/kernel/border.c b/src/common/kernel/border.c index 99c3f661b..c8b6a040c 100644 --- a/src/common/kernel/border.c +++ b/src/common/kernel/border.c @@ -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 @@ -219,8 +220,8 @@ attrib_type at_countdown = { DEFAULT_INIT, DEFAULT_FINALIZE, a_agecountdown, - DEFAULT_WRITE, - DEFAULT_READ + a_writeint, + a_readint }; void diff --git a/src/common/kernel/build.c b/src/common/kernel/build.c index 9d0121b8b..774f66857 100644 --- a/src/common/kernel/build.c +++ b/src/common/kernel/build.c @@ -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); diff --git a/src/common/kernel/building.c b/src/common/kernel/building.c index 95d131d9a..239f226d0 100644 --- a/src/common/kernel/building.c +++ b/src/common/kernel/building.c @@ -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 * diff --git a/src/common/kernel/building.h b/src/common/kernel/building.h index 80de5c340..321e125ba 100644 --- a/src/common/kernel/building.h +++ b/src/common/kernel/building.h @@ -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 diff --git a/src/common/kernel/eressea.c b/src/common/kernel/eressea.c index 5c345ca70..01009ec1b 100644 --- a/src/common/kernel/eressea.c +++ b/src/common/kernel/eressea.c @@ -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); } diff --git a/src/common/kernel/eressea.h b/src/common/kernel/eressea.h index 5c71a6629..ea2a19deb 100644 --- a/src/common/kernel/eressea.h +++ b/src/common/kernel/eressea.h @@ -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 diff --git a/src/common/kernel/karma.c b/src/common/kernel/karma.c index a6860a4c1..07422ca93 100644 --- a/src/common/kernel/karma.c +++ b/src/common/kernel/karma.c @@ -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 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] = { diff --git a/src/common/kernel/movement.c b/src/common/kernel/movement.c index 6b97e931e..bb880ce0d 100644 --- a/src/common/kernel/movement.c +++ b/src/common/kernel/movement.c @@ -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 +#include #include +#include #include #include @@ -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 }; /* ------------------------------------------------------------- */ diff --git a/src/common/kernel/region.c b/src/common/kernel/region.c index 1f460de09..68141849b 100644 --- a/src/common/kernel/region.c +++ b/src/common/kernel/region.c @@ -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_VERSIONdata)); */ + 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_versiondata.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_versiondata.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_versiondata.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); +} diff --git a/src/common/kernel/save.h b/src/common/kernel/save.h index ad8004893..423931861 100644 --- a/src/common/kernel/save.h +++ b/src/common/kernel/save.h @@ -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 diff --git a/src/common/kernel/unit.c b/src/common/kernel/unit.c index 4dd2be045..90326fba3 100644 --- a/src/common/kernel/unit.c +++ b/src/common/kernel/unit.c @@ -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 -#include -#include -#include -#include +#include +#include +#include +#include /* libc includes */ #include @@ -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 diff --git a/src/common/modules/museum.c b/src/common/modules/museum.c index 530695f53..8d576c0b1 100644 --- a/src/common/modules/museum.c +++ b/src/common/modules/museum.c @@ -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 diff --git a/src/common/modules/xecmd.c b/src/common/modules/xecmd.c index 2cf2e9629..784ccba4b 100644 --- a/src/common/modules/xecmd.c +++ b/src/common/modules/xecmd.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -39,8 +40,8 @@ attrib_type at_xontormiaexpress = { DEFAULT_INIT, DEFAULT_FINALIZE, DEFAULT_AGE, - DEFAULT_WRITE, - DEFAULT_READ, + a_writeint, + a_readint, ATF_UNIQUE }; diff --git a/src/common/spells/spells.c b/src/common/spells/spells.c index 040ebf26e..d791a080d 100644 --- a/src/common/spells/spells.c +++ b/src/common/spells/spells.c @@ -42,6 +42,7 @@ extern void ct_register(const struct curse_type * ct); #include #include #include +#include #include #include #include @@ -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 }; /* ----------------------------------------------------------------------- */ diff --git a/src/common/util/attrib.c b/src/common/util/attrib.c index 5c57c72fe..c2e487dbd 100644 --- a/src/common/util/attrib.c +++ b/src/common/util/attrib.c @@ -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 (sdata.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) { diff --git a/src/common/util/attrib.h b/src/common/util/attrib.h index 64318c962..bab2ab0ed 100644 --- a/src/common/util/attrib.h +++ b/src/common/util/attrib.h @@ -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