From 478ee8d153850cc281d2e8dd58a99fc18b632a83 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 11 May 2008 22:20:03 +0000 Subject: [PATCH] Lua: faction:renumber_faction(no) gmtool: save as binary --- src/common/gamecode/laws.c | 9 +-------- src/common/kernel/faction.c | 13 +++++++++++++ src/common/kernel/faction.h | 1 + src/common/kernel/save.h | 2 ++ src/eressea/gmtool.c | 2 +- src/eressea/lua/faction.cpp | 7 +++++++ src/scripts/run-tests.lua | 4 ++-- 7 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/common/gamecode/laws.c b/src/common/gamecode/laws.c index 0ce94437b..874c7342c 100644 --- a/src/common/gamecode/laws.c +++ b/src/common/gamecode/laws.c @@ -2567,14 +2567,7 @@ renumber_factions(void) for (rp=renum;rp;rp=rp->next) { f = rp->faction; a_remove(&f->attribs, rp->attrib); - if (f->subscription) { - sql_print(("UPDATE subscriptions set faction='%s' where id=%u;\n", - itoa36(rp->want), f->subscription)); - } - funhash(f); - f->no = rp->want; - fhash(f); - fset(f, FFL_NEWID); + renumber_faction(f, rp->want); } while (renum) { rp = renum->next; diff --git a/src/common/kernel/faction.c b/src/common/kernel/faction.c index 9b765121d..ec70e5182 100644 --- a/src/common/kernel/faction.c +++ b/src/common/kernel/faction.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -324,6 +325,18 @@ set_alliance(faction * a, faction * b, int status) (*sfp)->status |= status; } +void renumber_faction(faction * f, int no) +{ + if (f->subscription) { + sql_print(("UPDATE subscriptions set faction='%s' where id=%u;\n", + itoa36(no), f->subscription)); + } + funhash(f); + f->no = no; + fhash(f); + fset(f, FFL_NEWID); +} + #ifdef SMART_INTERVALS void update_interval(struct faction * f, struct region * r) diff --git a/src/common/kernel/faction.h b/src/common/kernel/faction.h index fb690097a..69db1b81e 100644 --- a/src/common/kernel/faction.h +++ b/src/common/kernel/faction.h @@ -141,6 +141,7 @@ extern void remove_enemy(struct faction * f, struct faction * enemy); extern void write_faction_reference(const struct faction * f, struct storage * store); extern int read_faction_reference(struct faction ** f, struct storage * store); +void renumber_faction(faction * f, int no); #ifdef SMART_INTERVALS extern void update_interval(struct faction * f, struct region * r); diff --git a/src/common/kernel/save.h b/src/common/kernel/save.h index ed1ea783a..b4e731bbe 100644 --- a/src/common/kernel/save.h +++ b/src/common/kernel/save.h @@ -46,6 +46,8 @@ extern void rsf(FILE * F, char *s, size_t len); #define IO_BINARY 0x04 #define IO_TEXT 0x08 +#define IO_DEFAULT IO_BINARY + /* Versionsänderungen: */ extern int data_version; extern const char *xmlfile; diff --git a/src/eressea/gmtool.c b/src/eressea/gmtool.c index 67ffb6215..1a4ded24b 100644 --- a/src/eressea/gmtool.c +++ b/src/eressea/gmtool.c @@ -730,7 +730,7 @@ handlekey(state * st, int c) if (strlen(datafile)>0) { create_backup(datafile); remove_empty_units(); - writegame(datafile, IO_TEXT); + writegame(datafile, IO_DEFAULT); st->modified = 0; } } diff --git a/src/eressea/lua/faction.cpp b/src/eressea/lua/faction.cpp index fd786db30..a4e8c1c41 100644 --- a/src/eressea/lua/faction.cpp +++ b/src/eressea/lua/faction.cpp @@ -297,6 +297,12 @@ faction_countheroes(const faction& f) return countheroes(&f); } +static void +faction_renumber(faction& f, int no) +{ + renumber_faction(&f, no); +} + static int faction_maxheroes(const faction& f) { @@ -342,6 +348,7 @@ bind_faction(lua_State * L) .property("y", &faction_getorigin_y, &faction_setorigin_y) //.property("origin", &faction_getorigin, &faction_setorigin, pure_out_value(_2) + pure_out_value(_3), copy) + .def("renum", &faction_renumber) .def("add_notice", &faction_addnotice) .property("password", &faction_get_passw, &faction_set_passw) .property("info", &faction_get_banner, &faction_set_banner) diff --git a/src/scripts/run-tests.lua b/src/scripts/run-tests.lua index 6abedc559..8f9dc4396 100644 --- a/src/scripts/run-tests.lua +++ b/src/scripts/run-tests.lua @@ -22,7 +22,7 @@ print(elapsed) -- bin1: 18.953 f = get_faction(0) -renumber(f, 666) +--renumber(f, 666) --write_game("566.dat", "binary") -io.stdin:read("*line") +--io.stdin:read("*line")