diff --git a/core/scripts/tests/common.lua b/core/scripts/tests/common.lua index 664f67d84..1c1cb86a8 100755 --- a/core/scripts/tests/common.lua +++ b/core/scripts/tests/common.lua @@ -30,8 +30,8 @@ local function two_units(r, f1, f2) end local function two_factions() - local f1 = faction.create("noreply@eressea.de", "human", "de") - local f2 = faction.create("noreply@eressea.de", "elf", "de") + local f1 = faction.create("one@eressea.de", "human", "de") + local f2 = faction.create("two@eressea.de", "elf", "de") return f1, f2 end @@ -47,11 +47,26 @@ function setup() eressea.settings.set("rules.peasants.growth", "1") end +function test_flags() + local r = region.create(0, 0, "plain") + local f = faction.create("flags@eressea.de", "halfling", "de") + local u = unit.create(f, r, 1) + local no = itoa36(f.id) + local flags = 587203585 + f.flags = flags + + eressea.write_game("test.dat") + eressea.free_game() + eressea.read_game("test.dat") + f = get_faction(no) + assert_equal(flags, f.flags) +end + function test_elvenhorse_requires_riding_5() local r = region.create(0, 0, "plain") region.create(1, 0, "plain") local goal = region.create(2, 0, "plain") - local f = faction.create("noreply@eressea.de", "halfling", "de") + local f = faction.create("riding@eressea.de", "halfling", "de") local u = unit.create(f, r, 1) u:add_item("elvenhorse", 1) u:set_skill("riding", 6)-- halfling has -1 modifier @@ -65,7 +80,7 @@ function test_cannot_ride_elvenhorse_without_enough_skill() local r = region.create(0, 0, "plain") local goal = region.create(1, 0, "plain") region.create(2, 0, "plain") - local f = faction.create("noreply@eressea.de", "halfling", "de") + local f = faction.create("elvenhorse@eressea.de", "halfling", "de") local u = unit.create(f, r, 1) u:add_item("elvenhorse", 1) u:set_skill("riding", 5) -- halfling has -1 modifier @@ -85,7 +100,7 @@ end function test_demon_food() local r = region.create(0, 0, "plain") - local f = faction.create("noreply@eressea.de", "demon", "de") + local f = faction.create("demonfood@eressea.de", "demon", "de") local u = unit.create(f, r, 1) local p = r:get_resource("peasant") r:set_resource("peasant", 2000) @@ -125,7 +140,7 @@ function test_plane() local nx, ny = plane.normalize(pl, 4, 4) assert_equal(nx, -3, "normalization failed") assert_equal(ny, -3, "normalization failed") - local f = faction.create("noreply@eressea.de", "human", "de") + local f = faction.create("plan@eressea.de", "human", "de") f.id = atoi36("tpla") local r, x, y for x = -3, 3 do for y = -3, 3 do @@ -144,7 +159,7 @@ end function test_read_write() local r = region.create(0, 0, "plain") - local f = faction.create("noreply@eressea.de", "human", "de") + local f = faction.create("readwrite@eressea.de", "human", "de") local u = unit.create(f, r) u.number = 2 local fno = f.id @@ -173,7 +188,7 @@ end function test_descriptions() local info = "Descriptions can be very long. Bug 1984 behauptet, dass es Probleme gibt mit Beschreibungen die laenger als 120 Zeichen sind. This description is longer than 120 characters." local r = region.create(0, 0, "plain") - local f = faction.create("noreply@eressea.de", "human", "de") + local f = faction.create("descriptions@eressea.de", "human", "de") local u = unit.create(f, r, 1) local s = _test_create_ship(r) local b = building.create(r, "castle") @@ -224,7 +239,7 @@ end function test_faction() local r = region.create(0, 0, "plain") - local f = faction.create("noreply@eressea.de", "human", "de") + local f = faction.create("testfaction@eressea.de", "human", "de") assert(f) f.info = "Spazz" assert(f.info=="Spazz") @@ -247,7 +262,7 @@ end function test_unit() local r = region.create(0, 0, "plain") - local f = faction.create("noreply@eressea.de", "human", "de") + local f = faction.create("testunit@eressea.de", "human", "de") local u = unit.create(f, r) u.number = 20 u.name = "Enno" @@ -280,7 +295,7 @@ end function test_building() local u - local f = faction.create("noreply@eressea.de", "human", "de") + local f = faction.create("testbuilding@eressea.de", "human", "de") local r = region.create(0, 0, "plain") local b = building.create(r, "castle") u = unit.create(f, r) @@ -306,7 +321,7 @@ end function test_message() local r = region.create(0, 0, "plain") - local f = faction.create("noreply@eressea.de", "human", "de") + local f = faction.create("testmessage@eressea.de", "human", "de") local u = unit.create(f, r) local msg = message.create("item_create_spell") msg:set_unit("mage", u) @@ -319,7 +334,7 @@ function test_message() end function test_hashtable() - local f = faction.create("noreply@eressea.de", "human", "de") + local f = faction.create("noreply1@eressea.de", "human", "de") f.objects:set("enno", "smart guy") f.objects:set("age", 10) assert(f.objects:get("jesus") == nil) @@ -345,7 +360,7 @@ function test_events() plain = region.create(0, 0, "plain") skill = 8 - f = faction.create("noreply@eressea.de", "elf", "de") + f = faction.create("noreply2@eressea.de", "elf", "de") f.age = 20 u = unit.create(f, plain) @@ -355,7 +370,7 @@ function test_events() u:add_order("NUMMER PARTEI test") u:add_handler("message", msg_handler) msg = "BOTSCHAFT EINHEIT " .. itoa36(u.id) .. " Du~Elf~stinken" - f = faction.create("noreply@eressea.de", "elf", "de") + f = faction.create("noreply3@eressea.de", "elf", "de") f.age = 20 u = unit.create(f, plain) @@ -370,7 +385,7 @@ end function test_recruit2() local r = region.create(0, 0, "plain") - local f = faction.create("noreply@eressea.de", "human", "de") + local f = faction.create("noreply4@eressea.de", "human", "de") local u = unit.create(f, r) u.number = 1 u:add_item("money", 2000) @@ -385,7 +400,7 @@ end function test_guard() region.create(1, 0, "plain") local r = region.create(0, 0, "plain") - local f1 = faction.create("noreply@eressea.de", "human", "de") + local f1 = faction.create("noreply5@eressea.de", "human", "de") f1.age = 20 local u1 = unit.create(f1, r, 10) u1:add_item("sword", 10) @@ -395,7 +410,7 @@ function test_guard() u1:add_order("NACH O") u1.name="Kalle Pimp" - local f2 = faction.create("noreply@eressea.de", "human", "de") + local f2 = faction.create("noreply6@eressea.de", "human", "de") f2.age = 20 local u2 = unit.create(f2, r, 1) local u3 = unit.create(f2, r, 1) @@ -413,7 +428,7 @@ end function test_recruit() local r = region.create(0, 0, "plain") - local f = faction.create("noreply@eressea.de", "human", "de") + local f = faction.create("noreply7@eressea.de", "human", "de") local u = unit.create(f, r) u.number = 1 local n = 3 @@ -430,7 +445,7 @@ end function test_produce() local r = region.create(0, 0, "plain") - local f = faction.create("noreply@eressea.de", "human", "de") + local f = faction.create("noreply8@eressea.de", "human", "de") local u = unit.create(f, r, 1) u:clear_orders() local sword = config.get_resource('sword') @@ -445,7 +460,7 @@ end function test_work() local r = region.create(0, 0, "plain") - local f = faction.create("noreply@eressea.de", "human", "de") + local f = faction.create("noreply9@eressea.de", "human", "de") local u = unit.create(f, r, 1) u:add_item("money", u.number * 10) -- humans cost 10 u:set_skill("herbalism", 5) @@ -458,7 +473,7 @@ end function test_upkeep() eressea.settings.set("rules.economy.food", "0") local r = region.create(0, 0, "plain") - local f = faction.create("noreply@eressea.de", "human", "de") + local f = faction.create("noreply10@eressea.de", "human", "de") local u = unit.create(f, r, 5) u:add_item("money", u.number * 11) u:clear_orders() @@ -470,7 +485,7 @@ end function test_id() local r = region.create(0, 0, "plain") - local f = faction.create("noreply@eressea.de", "human", "de") + local f = faction.create("noreply11@eressea.de", "human", "de") f.id = atoi36("42") assert(get_faction(42)~=f) assert(get_faction("42")==f) @@ -498,7 +513,7 @@ end function test_herbalism() local r = region.create(0, 0, "plain") - local f = faction.create("noreply@eressea.de", "human", "de") + local f = faction.create("noreply12@eressea.de", "human", "de") local u = unit.create(f, r, 1) u:add_item("money", u.number * 100) u:set_skill("herbalism", 5) @@ -517,7 +532,7 @@ function test_mallorn() m:set_resource("tree", 100) assert(m:get_resource("tree")==100) - local f = faction.create("noreply@eressea.de", "human", "de") + local f = faction.create("noreply13@eressea.de", "human", "de") local u1 = unit.create(f, r, 1) u1:add_item("money", u1.number * 100) @@ -554,7 +569,7 @@ function test_coordinate_translation() local pl = plane.create(1, 500, 500, 1001, 1001) -- astralraum local pe = plane.create(1, -8761, 3620, 23, 23) -- eternath local r = region.create(1000, 1000, "plain") - local f = faction.create("noreply@eressea.de", "human", "de") + local f = faction.create("noreply14@eressea.de", "human", "de") assert_not_equal(nil, r) assert_equal(r.x, 1000) assert_equal(r.y, 1000) @@ -600,7 +615,7 @@ end function test_store_unit() local r = region.create(0, 0, "plain") - local f = faction.create("noreply@eressea.de", "human", "de") + local f = faction.create("noreply15@eressea.de", "human", "de") local u = unit.create(f, r, 1) local fid = f.id u:add_item("money", u.number * 100) @@ -612,7 +627,7 @@ function test_store_unit() eressea.free_game() -- recreate world: r = region.create(0, 0, "plain") - f = faction.create("noreply@eressea.de", "human", "de") + f = faction.create("noreply16@eressea.de", "human", "de") f.id = fid store = storage.create(filename, "rb") assert_not_nil(store) @@ -624,8 +639,8 @@ end function test_building_other() local r = region.create(0,0, "plain") - local f1 = faction.create("noreply@eressea.de", "human", "de") - local f2 = faction.create("noreply@eressea.de", "human", "de") + local f1 = faction.create("noreply17@eressea.de", "human", "de") + local f2 = faction.create("noreply18@eressea.de", "human", "de") local b = building.create(r, "castle") b.size = 10 local u1 = unit.create(f1, r, 3) @@ -650,7 +665,7 @@ end local function _test_create_laen() eressea.settings.set("rules.terraform.all", "1") local r = region.create(0,0, "mountain") - local f1 = faction.create("noreply@eressea.de", "human", "de") + local f1 = faction.create("noreply19@eressea.de", "human", "de") local u1 = unit.create(f1, r, 1) r:set_resource("laen", 50) return r, u1 @@ -691,7 +706,7 @@ end function test_mine() local r = region.create(0,0, "mountain") - local f1 = faction.create("noreply@eressea.de", "human", "de") + local f1 = faction.create("noreply20@eressea.de", "human", "de") local u1 = unit.create(f1, r, 1) u1:add_item("money", 1000) @@ -712,9 +727,9 @@ end function test_guard_resources() -- this is not quite http://bugs.eressea.de/view.php?id=1756 local r = region.create(0,0, "mountain") - local f1 = faction.create("noreply@eressea.de", "human", "de") + local f1 = faction.create("noreply21@eressea.de", "human", "de") f1.age=20 - local f2 = faction.create("noreply@eressea.de", "human", "de") + local f2 = faction.create("noreply22@eressea.de", "human", "de") f2.age=20 local u1 = unit.create(f1, r, 1) u1:add_item("money", 100) @@ -742,7 +757,7 @@ end function test_hero_hero_transfer() local r = region.create(0,0, "mountain") - local f = faction.create("noreply@eressea.de", "human", "de") + local f = faction.create("noreply23@eressea.de", "human", "de") f.age=20 local UFL_HERO = 128 @@ -763,7 +778,7 @@ end function test_hero_normal_transfer() local r = region.create(0,0, "mountain") - local f = faction.create("noreply@eressea.de", "human", "de") + local f = faction.create("noreply24@eressea.de", "human", "de") f.age=20 local UFL_HERO = 128 @@ -782,7 +797,7 @@ end function test_expensive_skills_cost_money() local r = region.create(0,0, "mountain") - local f = faction.create("noreply@eressea.de", "elf", "de") + local f = faction.create("noreply25@eressea.de", "elf", "de") local u = unit.create(f, r, 1) u:add_item("money", 10000) u:clear_orders() @@ -794,7 +809,7 @@ end function test_food_is_consumed() local r = region.create(0, 0, "plain") - local f = faction.create("noreply@eressea.de", "human", "de") + local f = faction.create("noreply26@eressea.de", "human", "de") local u = unit.create(f, r, 1) u:add_item("money", 100) u:clear_orders() @@ -806,7 +821,7 @@ end function test_food_can_override() local r = region.create(0, 0, "plain") - local f = faction.create("noreply@eressea.de", "human", "de") + local f = faction.create("noreply27@eressea.de", "human", "de") local u = unit.create(f, r, 1) u:add_item("money", 100) u:clear_orders() @@ -818,7 +833,7 @@ end function test_swim_and_survive() local r = region.create(0, 0, "plain") - local f = faction.create("noreply@eressea.de", "human", "de") + local f = faction.create("noreply28@eressea.de", "human", "de") f.nam = "chaos" local u = unit.create(f, r, 1) process_orders() @@ -832,7 +847,7 @@ end function test_swim_and_die() local r = region.create(0, 0, "plain") - local f = faction.create("noreply@eressea.de", "human", "de") + local f = faction.create("noreply29@eressea.de", "human", "de") local u = unit.create(f, r, 1) local uid = u.id process_orders() @@ -847,7 +862,7 @@ function test_ride_with_horse() region.create(1, 0, "plain") region.create(2, 0, "plain") local r = region.create(0, 0, "plain") - local f = faction.create("noreply@eressea.de", "human", "de") + local f = faction.create("noreply30@eressea.de", "human", "de") local u = unit.create(f, r, 1) u:add_item("horse", 1) local horse_cfg = config.get_resource("horse") @@ -870,7 +885,7 @@ function test_ride_with_horses_and_cart() region.create(1, 0, "plain") region.create(2, 0, "plain") local r = region.create(0, 0, "plain") - local f = faction.create("noreply@eressea.de", "human", "de") + local f = faction.create("noreply31@eressea.de", "human", "de") local u = unit.create(f, r, 1) local horse_cfg = config.get_resource("horse") local cart_cfg = config.get_resource("cart") @@ -923,7 +938,7 @@ function test_walk_and_carry_the_cart() region.create(1, 0, "plain") local r = region.create(2, 0, "plain") local r = region.create(0, 0, "plain") - local f = faction.create("noreply@eressea.de", "human", "de") + local f = faction.create("noreply32@eressea.de", "human", "de") local u = unit.create(f, r, 10) u:add_item("cart", 1) diff --git a/src/bindings.c b/src/bindings.c index 3bd2db543..3d8a83388 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -1218,7 +1218,6 @@ int eressea_run(lua_State *L, const char *luafile) err = lua_pcall(L, 1, 1, -3); if (err != 0) { log_lua_error(L); - abort(); } else { if (lua_isnumber(L, -1)) { err = (int)lua_tonumber(L, -1); diff --git a/src/kernel/faction.h b/src/kernel/faction.h index 2de1f6486..d72fc8622 100644 --- a/src/kernel/faction.h +++ b/src/kernel/faction.h @@ -44,12 +44,12 @@ extern "C" { * (FFL_SELECT muss man vorher initialisieren, * FL_MARK hinterher löschen) */ #define FFL_NOIDLEOUT (1<<24) /* Partei stirbt nicht an NMRs */ +#define FFL_NPC (1<<25) /* eine Partei mit Monstern */ #define FFL_DBENTRY (1<<28) /* Partei ist in Datenbank eingetragen */ #define FFL_NOTIMEOUT (1<<29) /* ignore MaxAge() */ #define FFL_GM (1<<30) /* eine Partei mit Sonderrechten */ -#define FFL_NPC (1<<31) /* eine Partei mit Monstern */ -#define FFL_SAVEMASK (FFL_DEFENDER|FFL_NEWID|FFL_GM|FFL_NPC|FFL_NOTIMEOUT|FFL_DBENTRY|FFL_NOTIMEOUT) +#define FFL_SAVEMASK (FFL_DEFENDER|FFL_NEWID|FFL_GM|FFL_NPC|FFL_NOTIMEOUT|FFL_DBENTRY|FFL_NOIDLEOUT) struct faction *get_monsters(void); #define is_monsters(f) ((f)->flags&FFL_NPC) @@ -65,7 +65,7 @@ extern "C" { #endif int no; int subscription; - unsigned int flags; + int flags; char *name; char *banner; char *email; diff --git a/src/kernel/save.c b/src/kernel/save.c index a0b608e4e..40d13a6b3 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -1266,8 +1266,9 @@ faction *readfaction(struct gamedata * data) READ_INT(data->store, &n); } - READ_UINT(data->store, &f->flags); - if (f->no == 0) { + READ_INT(data->store, &f->flags); + assert((f->flags&FFL_SAVEMASK) == f->flags); + if (f->no==0 || f->no==666) { f->flags |= FFL_NPC; } diff --git a/src/randenc.c b/src/randenc.c index 8340f1f78..834965e77 100644 --- a/src/randenc.c +++ b/src/randenc.c @@ -1209,6 +1209,7 @@ static void rotting_herbs(void) void randomevents(void) { region *r; + faction *monsters = get_monsters(); icebergs(); godcurse(); @@ -1290,21 +1291,23 @@ void randomevents(void) } /* monster-einheiten desertieren */ - for (r = regions; r; r = r->next) { - unit *u; + if (monsters) { + for (r = regions; r; r = r->next) { + unit *u; - for (u = r->units; u; u = u->next) { - if (u->faction && !is_monsters(u->faction) - && (u_race(u)->flags & RCF_DESERT)) { - if (fval(u, UFL_ISNEW)) - continue; - if (rng_int() % 100 < 5) { - ADDMSG(&u->faction->msgs, msg_message("desertion", - "unit region", u, r)); - u_setfaction(u, get_monsters()); - } + for (u = r->units; u; u = u->next) { + if (u->faction && !is_monsters(u->faction) + && (u_race(u)->flags & RCF_DESERT)) { + if (fval(u, UFL_ISNEW)) + continue; + if (rng_int() % 100 < 5) { + ADDMSG(&u->faction->msgs, msg_message("desertion", + "unit region", u, r)); + u_setfaction(u, monsters); + } + } + } } - } } /* Chaos */