repair spellbooks that broke in E3 and E4 (temporary measure, remember to remove this code).

This commit is contained in:
Enno Rehling 2015-08-20 12:13:09 +02:00
parent ff38d8bf4c
commit 8716e5fdc5
6 changed files with 109 additions and 0 deletions

View File

@ -100,6 +100,7 @@
<param name="magic.power" value="0.5"/> <param name="magic.power" value="0.5"/>
<param name="resource.factor" value="0.25"/> <param name="resource.factor" value="0.25"/>
<param name="fix.spells" value="319"/>
<param name="skills.cost.tactics" value="500"/> <param name="skills.cost.tactics" value="500"/>
<param name="entertain.base" value="0"/> <param name="entertain.base" value="0"/>
<param name="entertain.perlevel" value="20"/> <param name="entertain.perlevel" value="20"/>

View File

@ -101,6 +101,7 @@
<param name="magic.power" value="0.5"/> <param name="magic.power" value="0.5"/>
<param name="resource.factor" value="0.25"/> <param name="resource.factor" value="0.25"/>
<param name="fix.spells" value="67"/>
<param name="skills.cost.tactics" value="500"/> <param name="skills.cost.tactics" value="500"/>
<param name="entertain.base" value="0"/> <param name="entertain.base" value="0"/>
<param name="entertain.perlevel" value="20"/> <param name="entertain.perlevel" value="20"/>

View File

@ -64,6 +64,7 @@ ENDIF()
set (ERESSEA_SRC set (ERESSEA_SRC
move.c move.c
repair.c
spells.c spells.c
battle.c battle.c
alchemy.c alchemy.c

View File

@ -48,6 +48,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "unit.h" #include "unit.h"
#include "lighthouse.h" #include "lighthouse.h"
#include "version.h" #include "version.h"
#include "repair.h"
/* attributes includes */ /* attributes includes */
#include <attributes/key.h> #include <attributes/key.h>
@ -1695,6 +1696,11 @@ int readgame(const char *filename, int backup)
remove_empty_factions(); remove_empty_factions();
} }
log_printf(stdout, "Done loading turn %d.\n", turn); log_printf(stdout, "Done loading turn %d.\n", turn);
n = get_param_int(global.parameters, "fix.spells", -1);
if (n>=turn) {
repair_spells("spells.txt");
}
return 0; return 0;
} }

86
src/repair.c Normal file
View File

@ -0,0 +1,86 @@
#include <platform.h>
#include <kernel/config.h>
#include "repair.h"
#include <kernel/faction.h>
#include <kernel/spellbook.h>
#include <util/log.h>
#include <util/base36.h>
#include <quicklist.h>
#include <stdio.h>
#include <stdlib.h>
static void write_spellbook_states(FILE *F) {
faction *f;
for (f = factions; f; f = f->next) {
spellbook *sb = f->spellbook;
int len = sb ? ql_length(sb->spells) : 0;
fprintf(F, "%s %d %d\n", itoa36(f->no), f->subscription, len);
}
}
static void limit_spellbook(faction *f, int num) {
spellbook *sb = f->spellbook;
int len = sb ? ql_length(sb->spells) : 0;
if (len < num) {
log_error("limit_spellbook: spellbook is shorter than expected, %d < %d", len, num);
}
// delete spells backwards from the end:
while (len > num) {
ql_delete(&sb->spells, len--);
}
}
void repair_spells(const char *filename) {
FILE *F = fopen(filename, "r");
if (F) {
char id[32];
int numspells, sub;
faction *f;
while (fscanf(F, "%s %d %d", id, &sub, &numspells) != EOF) {
int no = atoi36(id);
f = findfaction(no);
if (!f) {
for (f = factions; f; f = f->next) {
if (f->subscription == sub) {
break;
}
}
if (f) {
log_info("repair_spells: faction %s renamed to %s, located by subscription %d", id, itoa36(f->no), sub);
}
else {
log_warning("repair_spells: cannot fix faction %s, no such subscription: %d (%d spells)", id, sub, numspells);
continue;
}
}
if (f->subscription != sub) {
log_warning("repair_spells: subscription mismatch for faction %s, %d!=%d (%d spells)", id, f->subscription, sub, numspells);
}
else {
limit_spellbook(f, numspells);
fset(f, FFL_MARK);
}
}
for (f = factions; f; f = f->next) {
if (!fval(f, FFL_MARK)) {
numspells = ql_length(f->spellbook->spells);
log_warning("repair_spells: faction %s did not get a spellbook fix (%d spells at level)", itoa36(f->no), numspells, f->max_spelllevel);
}
freset(f, FFL_MARK);
}
}
else {
F = fopen(filename, "w");
if (!F) {
perror("repair_spells");
abort();
}
write_spellbook_state(F);
}
fclose(F);
}

14
src/repair.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef H_REPAIR
#define H_REPAIR
#ifdef __cplusplus
extern "C" {
#endif
void repair_spells(const char *filename); // one-time reduction of E3/E4 spellbooks (called at the end of readgame)
#ifdef __cplusplus
}
#endif
#endif