forked from github/server
compat fixes for old datafiles (turn 287)
This commit is contained in:
parent
363c2e0d5b
commit
f54037295a
2 changed files with 24 additions and 27 deletions
|
@ -144,7 +144,7 @@ destroy_curse(curse * c)
|
||||||
{
|
{
|
||||||
cunhash(c);
|
cunhash(c);
|
||||||
|
|
||||||
if (c->data.v && c->type->typ == CURSETYP_UNIT) {
|
if (c->data.v && c->type && c->type->typ == CURSETYP_UNIT) {
|
||||||
free(c->data.v);
|
free(c->data.v);
|
||||||
}
|
}
|
||||||
free(c);
|
free(c);
|
||||||
|
@ -164,7 +164,7 @@ read_ccompat(const char * cursename, struct storage * store)
|
||||||
const char * tokens;
|
const char * tokens;
|
||||||
} * seek, old_curses[] = { {"disorientationzone", ""}, {"shipdisorientation", ""}, { NULL, NULL } } ;
|
} * seek, old_curses[] = { {"disorientationzone", ""}, {"shipdisorientation", ""}, { NULL, NULL } } ;
|
||||||
for (seek=old_curses;seek->name;++seek) {
|
for (seek=old_curses;seek->name;++seek) {
|
||||||
if (strcmp(seek->name, cursename)==0) {
|
if (strcmp(seek->tokens, cursename)==0) {
|
||||||
const char * p;
|
const char * p;
|
||||||
for (p=seek->name;p;++p) {
|
for (p=seek->name;p;++p) {
|
||||||
switch (*p) {
|
switch (*p) {
|
||||||
|
@ -185,7 +185,6 @@ int
|
||||||
curse_read(attrib * a, struct storage * store)
|
curse_read(attrib * a, struct storage * store)
|
||||||
{
|
{
|
||||||
curse * c = (curse*)a->data.v;
|
curse * c = (curse*)a->data.v;
|
||||||
const curse_type * ct;
|
|
||||||
int ur;
|
int ur;
|
||||||
char cursename[64];
|
char cursename[64];
|
||||||
unsigned int flags;
|
unsigned int flags;
|
||||||
|
@ -207,36 +206,33 @@ curse_read(attrib * a, struct storage * store)
|
||||||
ur = read_reference(&c->magician, store, read_unit_reference, resolve_unit);
|
ur = read_reference(&c->magician, store, read_unit_reference, resolve_unit);
|
||||||
}
|
}
|
||||||
c->effect.i = store->r_int(store);
|
c->effect.i = store->r_int(store);
|
||||||
ct = ct_find(cursename);
|
c->type = ct_find(cursename);
|
||||||
if (ct==NULL) {
|
if (c->type==NULL) {
|
||||||
int result = read_ccompat(cursename, store);
|
int result = read_ccompat(cursename, store);
|
||||||
if (result!=0) {
|
if (result!=0) {
|
||||||
log_error(("missing curse %s, no compatibility code either.\n", cursename));
|
log_error(("missing curse %s, no compatibility code either.\n", cursename));
|
||||||
}
|
}
|
||||||
assert(result!=0);
|
assert(result!=0);
|
||||||
|
return AT_READ_FAIL;
|
||||||
}
|
}
|
||||||
c->type = ct;
|
|
||||||
|
|
||||||
if (store->version < CURSEFLAGS_VERSION) {
|
if (store->version < CURSEFLAGS_VERSION) {
|
||||||
c_setflag(c, flags);
|
c_setflag(c, flags);
|
||||||
} else {
|
} else {
|
||||||
c->flags = flags;
|
c->flags = flags;
|
||||||
}
|
}
|
||||||
c_clearflag(c, CURSE_ISNEW);
|
c_clearflag(c, CURSE_ISNEW);
|
||||||
|
|
||||||
if (c->type) {
|
if (c->type->read) c->type->read(store, c);
|
||||||
if (c->type->read) c->type->read(store, c);
|
else if (c->type->typ==CURSETYP_UNIT) {
|
||||||
else if (c->type->typ==CURSETYP_UNIT) {
|
curse_unit * cc = calloc(1, sizeof(curse_unit));
|
||||||
curse_unit * cc = calloc(1, sizeof(curse_unit));
|
|
||||||
|
c->data.v = cc;
|
||||||
c->data.v = cc;
|
cc->cursedmen = store->r_int(store);
|
||||||
cc->cursedmen = store->r_int(store);
|
}
|
||||||
}
|
if (c->type->typ == CURSETYP_REGION) {
|
||||||
if (c->type->typ == CURSETYP_REGION) {
|
int rr = read_reference(&c->data.v, store, read_region_reference, RESOLVE_REGION(store->version));
|
||||||
int rr = read_reference(&c->data.v, store, read_region_reference, RESOLVE_REGION(store->version));
|
if (ur==0 && rr==0 && !c->data.v) {
|
||||||
if (ur==0 && rr==0 && !c->data.v) {
|
return AT_READ_FAIL;
|
||||||
return AT_READ_FAIL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,11 +315,6 @@ ct_find(const char *c)
|
||||||
if (!strncasecmp(c, ctl->type->cname, k)) return ctl->type;
|
if (!strncasecmp(c, ctl->type->cname, k)) return ctl->type;
|
||||||
ctl = ctl->next;
|
ctl = ctl->next;
|
||||||
}
|
}
|
||||||
/* disable this assert to be able to remove certain curses from the game
|
|
||||||
* make sure that all locations using that curse can deal with a NULL
|
|
||||||
* return value.
|
|
||||||
*/
|
|
||||||
assert(!"unknown cursetype");
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -82,6 +82,11 @@ function test_md5()
|
||||||
-- write_game("572.txt", "text")
|
-- write_game("572.txt", "text")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function test_287()
|
||||||
|
read_game("287", "text")
|
||||||
|
write_game("287.dat", "binary")
|
||||||
|
end
|
||||||
|
|
||||||
loadscript("default.lua")
|
loadscript("default.lua")
|
||||||
run_scripts()
|
run_scripts()
|
||||||
-- go
|
-- go
|
||||||
|
@ -89,7 +94,8 @@ run_scripts()
|
||||||
-- test_bmark()
|
-- test_bmark()
|
||||||
-- test_realloc()
|
-- test_realloc()
|
||||||
-- test_hse()
|
-- test_hse()
|
||||||
test_md5()
|
-- test_md5()
|
||||||
|
test_287()
|
||||||
-- io.stdin:read("*line")
|
-- io.stdin:read("*line")
|
||||||
-- text: 50.574
|
-- text: 50.574
|
||||||
-- bin0: 19.547
|
-- bin0: 19.547
|
||||||
|
|
Loading…
Reference in a new issue