diff --git a/scripts/fix-death.lua b/scripts/fix-death.lua new file mode 100644 index 000000000..8f0b52e08 --- /dev/null +++ b/scripts/fix-death.lua @@ -0,0 +1,76 @@ +require 'config' + +eressea.read_game('1137.dat') + +local dead = {"cwz", "rama"} + + +local function list_items(f) + local items = {} + for u in f.units do + local r = u.region + for name in u.items do + local count = u:get_item(name) + if not items[r.id] then + items[r.id] = {} + end + if not items[r.id][name] then + items[r.id][name] = count + else + items[r.id][name] = items[r.id][name] + count + end + end + end + return items +end + +gifts = {} +info = {} + +for _, no in ipairs(dead) do + f = get_faction(no) + gifts[f.id] = list_items(f) + local allies = {} + for fno, as in pairs(f.allies) do + local f2 = get_faction(fno) + if f2:get_ally(f, 'give') then + allies[fno] = as + end + end + info[f.id] = { + ['name'] = f.name, + ['race'] = f.race, + ['allies'] = allies + } +end + +eressea.free_game() +eressea.read_game('1138.dat') + +newf = {} + +for fid, rlist in pairs(gifts) do + local name = "Erben von " .. info[fid].name + local race = info[fid].race + local f = faction.create(race, "noreply@eressea.de") + f.name = name + f.age = 10 + f.lastturn = 1130 + table.insert(newf, f) + for rid, items in pairs(rlist) do + local r = get_region_by_id(rid) + local u = unit.create(f, r, 1) + for name, count in pairs(items) do + u:add_item(name, count) + end + end + for fno, as in pairs(info[fid].allies) do + local f2 = get_faction(fno) + for _, s in ipairs(as) do + f:set_ally(f2, s) + end + f2:set_ally(f, "give") + end +end + +eressea.write_game('1138.new.dat') diff --git a/scripts/tests/e2/allies.lua b/scripts/tests/e2/allies.lua new file mode 100644 index 000000000..ef38a97bf --- /dev/null +++ b/scripts/tests/e2/allies.lua @@ -0,0 +1,30 @@ +require "lunit" + +module("tests.e2.allies", package.seeall, lunit.testcase) + +function skip_test_get_set_ally() + local f1 = faction.create("human") + local f2 = faction.create("human") + + assert_equal(false, f1:get_ally(f2, "guard")) + f1:set_ally(f2, "guard", true) + assert_equal(true, f1:get_ally(f2, "guard")) + assert_equal(false, f1:get_ally(f2, "give")) + f1:set_ally(f2, "give", true) + assert_equal(true, f1:get_ally(f2, "give")) +end + +function test_get_allies() + local f1 = faction.create("human") + local f2 = faction.create("human") + + local allies = f1.allies + assert_equal('table', type(allies)) + assert_equal(0, #allies) + f1:set_ally(f2, "give", true) + allies = f1.allies + assert_not_nil(allies[f2.id]) + assert_equal('table', type(allies[f2.id])) + assert_equal(1, #allies[f2.id]) + assert_equal("give", allies[f2.id][1]) +end diff --git a/scripts/tests/e2/init.lua b/scripts/tests/e2/init.lua index 28d7ebc9b..afe0ac5ad 100644 --- a/scripts/tests/e2/init.lua +++ b/scripts/tests/e2/init.lua @@ -1,5 +1,5 @@ require 'tests.e2.carts' -require 'tests.e2.quit' +require 'tests.e2.allies' require 'tests.e2.movement' require 'tests.e2.astral' require 'tests.e2.spells' diff --git a/src/bind_faction.c b/src/bind_faction.c index f71e334d1..56164785d 100644 --- a/src/bind_faction.c +++ b/src/bind_faction.c @@ -7,6 +7,7 @@ #include "bindings.h" #include "magic.h" +#include #include #include #include @@ -31,7 +32,10 @@ #include #include #include -#include +#include // for bool +#include // for puts + +struct allies; int tolua_factionlist_next(lua_State * L) { @@ -48,13 +52,13 @@ int tolua_factionlist_next(lua_State * L) static int tolua_faction_get_units(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); + faction *f = (faction *)tolua_tousertype(L, 1, NULL); unit **unit_ptr = (unit **)lua_newuserdata(L, sizeof(unit *)); luaL_getmetatable(L, TOLUA_CAST "unit"); lua_setmetatable(L, -2); - *unit_ptr = self->units; + *unit_ptr = f->units; lua_pushcclosure(L, tolua_unitlist_nextf, 1); return 1; @@ -62,7 +66,7 @@ static int tolua_faction_get_units(lua_State * L) int tolua_faction_add_item(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); + faction *f = (faction *)tolua_tousertype(L, 1, NULL); const char *iname = tolua_tostring(L, 2, NULL); int number = (int)tolua_tonumber(L, 3, 0); int result = -1; @@ -70,7 +74,7 @@ int tolua_faction_add_item(lua_State * L) if (iname != NULL) { const resource_type *rtype = rt_find(iname); if (rtype && rtype->itype) { - item *i = i_change(&self->items, rtype->itype, number); + item *i = i_change(&f->items, rtype->itype, number); result = i ? i->number : 0; } /* if (itype!=NULL) */ } @@ -80,38 +84,38 @@ int tolua_faction_add_item(lua_State * L) static int tolua_faction_get_maxheroes(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); - lua_pushinteger(L, maxheroes(self)); + faction *f = (faction *)tolua_tousertype(L, 1, NULL); + lua_pushinteger(L, maxheroes(f)); return 1; } static int tolua_faction_get_heroes(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); - lua_pushinteger(L, countheroes(self)); + faction *f = (faction *)tolua_tousertype(L, 1, NULL); + lua_pushinteger(L, countheroes(f)); return 1; } static int tolua_faction_get_score(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); - lua_pushnumber(L, (lua_Number)self->score); + faction *f = (faction *)tolua_tousertype(L, 1, NULL); + lua_pushnumber(L, (lua_Number)f->score); return 1; } static int tolua_faction_get_id(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); - lua_pushinteger(L, self->no); + faction *f = (faction *)tolua_tousertype(L, 1, NULL); + lua_pushinteger(L, f->no); return 1; } static int tolua_faction_set_id(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); + faction *f = (faction *)tolua_tousertype(L, 1, NULL); int id = (int)tolua_tonumber(L, 2, 0); if (findfaction(id) == NULL) { - renumber_faction(self, id); + renumber_faction(f, id); lua_pushboolean(L, 1); } else { @@ -122,20 +126,20 @@ static int tolua_faction_set_id(lua_State * L) static int tolua_faction_get_magic(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); - lua_pushstring(L, magic_school[self->magiegebiet]); + faction *f = (faction *)tolua_tousertype(L, 1, NULL); + lua_pushstring(L, magic_school[f->magiegebiet]); return 1; } static int tolua_faction_set_magic(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); + faction *f = (faction *)tolua_tousertype(L, 1, NULL); const char *type = tolua_tostring(L, 2, NULL); int mtype; for (mtype = 0; mtype != MAXMAGIETYP; ++mtype) { if (strcmp(magic_school[mtype], type) == 0) { - self->magiegebiet = (magic_t)mtype; + f->magiegebiet = (magic_t)mtype; break; } } @@ -144,89 +148,89 @@ static int tolua_faction_set_magic(lua_State * L) static int tolua_faction_get_age(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); - lua_pushinteger(L, self->age); + faction *f = (faction *)tolua_tousertype(L, 1, NULL); + lua_pushinteger(L, f->age); return 1; } static int tolua_faction_set_age(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); + faction *f = (faction *)tolua_tousertype(L, 1, NULL); int age = (int)tolua_tonumber(L, 2, 0); - self->age = age; + f->age = age; return 0; } static int tolua_faction_get_flags(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); - lua_pushinteger(L, self->flags); + faction *f = (faction *)tolua_tousertype(L, 1, NULL); + lua_pushinteger(L, f->flags); return 1; } static int tolua_faction_set_flags(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); - int flags = (int)tolua_tonumber(L, 2, self->flags); - self->flags = flags; + faction *f = (faction *)tolua_tousertype(L, 1, NULL); + int flags = (int)tolua_tonumber(L, 2, f->flags); + f->flags = flags; return 1; } static int tolua_faction_get_options(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); - lua_pushinteger(L, self->options); + faction *f = (faction *)tolua_tousertype(L, 1, NULL); + lua_pushinteger(L, f->options); return 1; } static int tolua_faction_set_options(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); - int options = (int)tolua_tonumber(L, 2, self->options); - self->options = options; + faction *f = (faction *)tolua_tousertype(L, 1, NULL); + int options = (int)tolua_tonumber(L, 2, f->options); + f->options = options; return 1; } static int tolua_faction_get_lastturn(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); - lua_pushinteger(L, self->lastorders); + faction *f = (faction *)tolua_tousertype(L, 1, NULL); + lua_pushinteger(L, f->lastorders); return 1; } static int tolua_faction_set_lastturn(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); - if (self) { - self->lastorders = (int)tolua_tonumber(L, 2, self->lastorders); + faction *f = (faction *)tolua_tousertype(L, 1, NULL); + if (f) { + f->lastorders = (int)tolua_tonumber(L, 2, f->lastorders); } return 0; } static int tolua_faction_renumber(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); + faction *f = (faction *)tolua_tousertype(L, 1, NULL); int no = (int)tolua_tonumber(L, 2, 0); - renumber_faction(self, no); + renumber_faction(f, no); return 0; } static int tolua_faction_addnotice(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); + faction *f = (faction *)tolua_tousertype(L, 1, NULL); const char *str = tolua_tostring(L, 2, NULL); - addmessage(NULL, self, str, MSG_MESSAGE, ML_IMPORTANT); + addmessage(NULL, f, str, MSG_MESSAGE, ML_IMPORTANT); return 0; } static int tolua_faction_getkey(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); + faction *f = (faction *)tolua_tousertype(L, 1, NULL); const char *name = tolua_tostring(L, 2, NULL); int flag = atoi36(name); - int value = key_get(self->attribs, flag); + int value = key_get(f->attribs, flag); if (value != 0) { lua_pushinteger(L, value); return 1; @@ -236,16 +240,16 @@ static int tolua_faction_getkey(lua_State * L) static int tolua_faction_setkey(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); + faction *f = (faction *)tolua_tousertype(L, 1, NULL); const char *name = tolua_tostring(L, 2, NULL); int value = (int)tolua_tonumber(L, 3, 1); int flag = atoi36(name); if (value) { - key_set(&self->attribs, flag, value); + key_set(&f->attribs, flag, value); } else { - key_unset(&self->attribs, flag); + key_unset(&f->attribs, flag); } return 0; } @@ -269,14 +273,14 @@ static int tolua_faction_debug_messages(lua_State * L) static int tolua_faction_get_messages(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); + faction *f = (faction *)tolua_tousertype(L, 1, NULL); int i = 1; mlist *ml; - if (!self->msgs) { + if (!f->msgs) { return 0; } lua_newtable(L); - for (ml = self->msgs->begin; ml; ml = ml->next, ++i) { + for (ml = f->msgs->begin; ml; ml = ml->next, ++i) { lua_pushnumber(L, i); lua_pushstring(L, ml->msg->type->name); lua_rawset(L, -3); @@ -285,11 +289,11 @@ static int tolua_faction_get_messages(lua_State * L) } static int tolua_faction_count_msg_type(lua_State *L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); + faction *f = (faction *)tolua_tousertype(L, 1, NULL); const char *str = tolua_tostring(L, 2, NULL); int n = 0; - if (self->msgs) { - mlist * ml = self->msgs->begin; + if (f->msgs) { + mlist * ml = f->msgs->begin; while (ml) { if (strcmp(str, ml->msg->type->name) == 0) { ++n; @@ -330,9 +334,9 @@ static int tolua_faction_set_origin(lua_State * L) static int tolua_faction_get_origin(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); + faction *f = (faction *)tolua_tousertype(L, 1, NULL); int x = 0, y = 0; - faction_getorigin(self, 0, &x, &y); + faction_getorigin(f, 0, &x, &y); lua_pushinteger(L, x); lua_pushinteger(L, y); @@ -380,48 +384,48 @@ static int tolua_faction_create(lua_State * L) static int tolua_faction_get_password(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); - tolua_pushstring(L, faction_getpassword(self)); + faction *f = (faction *)tolua_tousertype(L, 1, NULL); + tolua_pushstring(L, faction_getpassword(f)); return 1; } static int tolua_faction_set_password(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); + faction *f = (faction *)tolua_tousertype(L, 1, NULL); const char * passw = tolua_tostring(L, 2, NULL); - faction_setpassword(self, + faction_setpassword(f, passw ? password_hash(passw, PASSWORD_DEFAULT) : NULL); return 0; } static int tolua_faction_get_email(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); - tolua_pushstring(L, faction_getemail(self)); + faction *f = (faction *)tolua_tousertype(L, 1, NULL); + tolua_pushstring(L, faction_getemail(f)); return 1; } static int tolua_faction_set_email(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); - faction_setemail(self, tolua_tostring(L, 2, NULL)); + faction *f = (faction *)tolua_tousertype(L, 1, NULL); + faction_setemail(f, tolua_tostring(L, 2, NULL)); return 0; } static int tolua_faction_get_locale(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); - tolua_pushstring(L, locale_name(self->locale)); + faction *f = (faction *)tolua_tousertype(L, 1, NULL); + tolua_pushstring(L, locale_name(f->locale)); return 1; } static int tolua_faction_set_locale(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); + faction *f = (faction *)tolua_tousertype(L, 1, NULL); const char *name = tolua_tostring(L, 2, NULL); const struct locale *loc = get_locale(name); if (loc) { - self->locale = loc; + f->locale = loc; } else { tolua_pushstring(L, "invalid locale"); @@ -432,18 +436,18 @@ static int tolua_faction_set_locale(lua_State * L) static int tolua_faction_get_race(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); - tolua_pushstring(L, self->race->_name); + faction *f = (faction *)tolua_tousertype(L, 1, NULL); + tolua_pushstring(L, f->race->_name); return 1; } static int tolua_faction_set_race(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); + faction *f = (faction *)tolua_tousertype(L, 1, NULL); const char *name = tolua_tostring(L, 2, NULL); const race *rc = rc_find(name); if (rc != NULL) { - self->race = rc; + f->race = rc; } return 0; @@ -451,15 +455,15 @@ static int tolua_faction_set_race(lua_State * L) static int tolua_faction_get_name(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); - tolua_pushstring(L, faction_getname(self)); + faction *f = (faction *)tolua_tousertype(L, 1, NULL); + tolua_pushstring(L, faction_getname(f)); return 1; } static int tolua_faction_set_name(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); - faction_setname(self, tolua_tostring(L, 2, NULL)); + faction *f = (faction *)tolua_tousertype(L, 1, NULL); + faction_setname(f, tolua_tostring(L, 2, NULL)); return 0; } @@ -479,44 +483,108 @@ static int tolua_faction_set_uid(lua_State * L) static int tolua_faction_get_info(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); - tolua_pushstring(L, faction_getbanner(self)); + faction *f = (faction *)tolua_tousertype(L, 1, NULL); + tolua_pushstring(L, faction_getbanner(f)); return 1; } static int tolua_faction_set_info(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); - faction_setbanner(self, tolua_tostring(L, 2, NULL)); + faction *f = (faction *)tolua_tousertype(L, 1, NULL); + faction_setbanner(f, tolua_tostring(L, 2, NULL)); return 0; } -static int tolua_faction_get_alliance(lua_State * L) +/* TODO: this is probably useful elsewhere */ +static const char *status_names[] = { + "money", "fight", "observe", "give", "guard", "stealth", "travel", NULL +}; + +static int cb_ally_push(struct allies *af, struct faction *f, int status, void *udata) { + struct lua_State *L = (struct lua_State *)udata; + int len = 1; + int i; + + lua_pushnumber(L, f->no); + lua_newtable(L); + for (i = 0; status_names[i]; ++i) { + int flag = 1 << i; + if (status & flag) { + lua_pushstring(L, status_names[i]); + lua_rawseti(L, -2, len++); + } + } + + lua_rawset(L, -3); + return 0; +} + +static int tolua_faction_get_allies(lua_State * L) { + faction *f = (faction *)tolua_tousertype(L, 1, NULL); + lua_newtable(L); + allies_walk(f->allies, cb_ally_push, L); + return 1; +} + +static int tolua_faction_set_ally(lua_State * L) { + faction *f1 = (faction *)tolua_tousertype(L, 1, NULL); + faction *f2 = (faction *)tolua_tousertype(L, 2, NULL); + const char *status = tolua_tostring(L, 3, NULL); + bool value = tolua_toboolean(L, 4, 1); + if (status) { + int flag = ally_status(status); + int flags = ally_get(f1->allies, f2); + if (value) { + flags |= flag; + } + else { + flags &= ~flag; + } + ally_set(&f1->allies, f2, flags); + } + return 0; +} + +static int tolua_faction_get_ally(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); - tolua_pushusertype(L, f_get_alliance(self), TOLUA_CAST "alliance"); + faction *f1 = (faction *)tolua_tousertype(L, 1, NULL); + faction *f2 = (faction *)tolua_tousertype(L, 2, NULL); + const char *status = tolua_tostring(L, 3, NULL); + if (f1 && f2 && status) { + int test = ally_status(status); + int flags = ally_get(f1->allies, f2); + lua_pushboolean(L, (test & flags) == test); + return 1; + } + return 0; +} + +static int tolua_faction_get_alliances(lua_State * L) +{ + faction *f = (faction *)tolua_tousertype(L, 1, NULL); + tolua_pushusertype(L, f_get_alliance(f), TOLUA_CAST "alliance"); return 1; } static int tolua_faction_set_alliance(lua_State * L) { - struct faction *self = (struct faction *)tolua_tousertype(L, 1, NULL); + struct faction *f = (struct faction *)tolua_tousertype(L, 1, NULL); struct alliance *alli = (struct alliance *) tolua_tousertype(L, 2, NULL); - setalliance(self, alli); + setalliance(f, alli); return 0; } static int tolua_faction_get_items(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); + faction *f = (faction *)tolua_tousertype(L, 1, NULL); item **item_ptr = (item **)lua_newuserdata(L, sizeof(item *)); luaL_getmetatable(L, TOLUA_CAST "item"); lua_setmetatable(L, -2); - *item_ptr = self->items; + *item_ptr = f->items; lua_pushcclosure(L, tolua_itemlist_next, 1); @@ -525,8 +593,8 @@ static int tolua_faction_get_items(lua_State * L) static int tolua_faction_tostring(lua_State * L) { - faction *self = (faction *)tolua_tousertype(L, 1, NULL); - lua_pushstring(L, factionname(self)); + faction *f = (faction *)tolua_tousertype(L, 1, NULL); + lua_pushstring(L, factionname(f)); return 1; } @@ -569,8 +637,6 @@ void tolua_faction_open(lua_State * L) tolua_faction_set_locale); tolua_variable(L, TOLUA_CAST "race", tolua_faction_get_race, tolua_faction_set_race); - tolua_variable(L, TOLUA_CAST "alliance", tolua_faction_get_alliance, - tolua_faction_set_alliance); tolua_variable(L, TOLUA_CAST "score", tolua_faction_get_score, NULL); tolua_variable(L, TOLUA_CAST "magic", tolua_faction_get_magic, tolua_faction_set_magic); @@ -582,6 +648,13 @@ void tolua_faction_open(lua_State * L) tolua_variable(L, TOLUA_CAST "lastturn", tolua_faction_get_lastturn, tolua_faction_set_lastturn); + tolua_variable(L, TOLUA_CAST "alliance", tolua_faction_get_alliances, + tolua_faction_set_alliance); + + tolua_variable(L, TOLUA_CAST "allies", tolua_faction_get_allies, NULL); + tolua_function(L, TOLUA_CAST "set_ally", tolua_faction_set_ally); + tolua_function(L, TOLUA_CAST "get_ally", tolua_faction_get_ally); + tolua_function(L, TOLUA_CAST "get_origin", tolua_faction_get_origin); tolua_function(L, TOLUA_CAST "set_origin", tolua_faction_set_origin); tolua_function(L, TOLUA_CAST "normalize", tolua_faction_normalize); diff --git a/src/kernel/ally.c b/src/kernel/ally.c index 4ee6b0f57..300d64e15 100644 --- a/src/kernel/ally.c +++ b/src/kernel/ally.c @@ -185,6 +185,29 @@ static int ally_flag(const char *s, int help_mask) return 0; } +int ally_status(const char *s) +{ + if (strcmp(s, "give") == 0) { + return HELP_GIVE; + } + else if (strcmp(s, "fight") == 0) { + return HELP_FIGHT; + } + else if (strcmp(s, "money") == 0) { + return HELP_MONEY; + } + else if (strcmp(s, "travel") == 0) { + return HELP_TRAVEL; + } + else if (strcmp(s, "guard") == 0) { + return HELP_GUARD; + } + else if (strcmp(s, "all") == 0) { + return HELP_ALL; + } + return 0; +} + /** Specifies automatic alliance modes. * If this returns a value then the bits set are immutable between alliance * partners (faction::alliance) and cannot be changed with the HELP command. diff --git a/src/kernel/ally.h b/src/kernel/ally.h index c6cb8fe51..ac7ff6238 100644 --- a/src/kernel/ally.h +++ b/src/kernel/ally.h @@ -14,6 +14,7 @@ struct allies; extern struct attrib_type at_npcfaction; +int ally_status(const char *s); int ally_get(struct allies *al, const struct faction *f); void ally_set(struct allies **p_al, struct faction *f, int status); void write_allies(struct gamedata * data, const struct allies *alist); diff --git a/src/kernel/faction.c b/src/kernel/faction.c index b6bd02659..882c1333a 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -408,9 +408,6 @@ void destroyfaction(faction ** fp) f->next = dead_factions; dead_factions = f; - fset(f, FFL_QUIT); - f->_alive = false; - if (f->spellbook) { spellbook_clear(f->spellbook); free(f->spellbook); @@ -463,6 +460,8 @@ void destroyfaction(faction ** fp) setalliance(f, NULL); } + fset(f, FFL_QUIT); + f->_alive = false; funhash(f); /* units of other factions that were disguised as this faction diff --git a/src/spells/combatspells.c b/src/spells/combatspells.c index 51059b546..f4b8b6954 100644 --- a/src/spells/combatspells.c +++ b/src/spells/combatspells.c @@ -952,8 +952,7 @@ int sp_hero(struct castorder * co) } } - m = - msg_message("cast_hero_effect", "mage spell amount", fi->unit, sp, targets); + m = msg_message("cast_hero_effect", "mage spell amount", fi->unit, sp, targets); message_all(b, m); msg_release(m);