From 968f67a567c249cac1616bd58a247559dcd6e198 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 27 Apr 2019 18:30:30 +0200 Subject: [PATCH] delete intermittent test: ents have no special guarding powers. --- scripts/eressea/wedding.lua | 2 +- scripts/tests/e2/init.lua | 6 ------ scripts/tests/economy.lua | 18 ------------------ src/bind_unit.c | 28 ++++++++++++++++++++++++++-- src/monsters.c | 2 +- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/scripts/eressea/wedding.lua b/scripts/eressea/wedding.lua index 71664eec9..1732392fb 100644 --- a/scripts/eressea/wedding.lua +++ b/scripts/eressea/wedding.lua @@ -15,7 +15,7 @@ local function wedding_travellers(b) local units = {} for u in b.units do - if u:get_flag('wdgt') then + if u:get_key('wdgt') then units[u] = u end end diff --git a/scripts/tests/e2/init.lua b/scripts/tests/e2/init.lua index 55feab5bf..fde840f98 100644 --- a/scripts/tests/e2/init.lua +++ b/scripts/tests/e2/init.lua @@ -1,9 +1,3 @@ -function dump_messages(f) - for k, v in ipairs(f.messages) do - print(v) - end -end - require 'tests.e2.movement' require 'tests.e2.astral' require 'tests.e2.spells' diff --git a/scripts/tests/economy.lua b/scripts/tests/economy.lua index 3379b2ab7..9c72e7e70 100644 --- a/scripts/tests/economy.lua +++ b/scripts/tests/economy.lua @@ -216,21 +216,3 @@ function test_sawmill() assert_equal(6, u:get_item("log")) assert_equal(97, r:get_resource("tree")) end - -function test_ent_guards_trees() - local r = region.create(0, 0, "plain") - r:set_resource("tree", 100) - local u = unit.create(faction.create("human"), r) - u:set_skill("mining", 1) - local guard = unit.create(get_monsters(), r, 1, "ent") - u:set_skill("forestry", 1) - guard:clear_orders() - u:clear_orders() - - guard:add_order("BEWACHEN") - u:add_order("MACHE HOLZ") - process_orders() - assert_equal(1, u:get_item("log")) - process_orders() - assert_equal(1, u:get_item("log")) -end diff --git a/src/bind_unit.c b/src/bind_unit.c index d75323f0b..c5954082b 100644 --- a/src/bind_unit.c +++ b/src/bind_unit.c @@ -760,7 +760,7 @@ static int tolua_unit_has_attrib(lua_State *L) { return 1; } -static int tolua_unit_get_flag(lua_State * L) +static int tolua_unit_get_key(lua_State * L) { unit *self = (unit *)tolua_tousertype(L, 1, 0); const char *name = tolua_tostring(L, 2, 0); @@ -769,7 +769,7 @@ static int tolua_unit_get_flag(lua_State * L) return 1; } -static int tolua_unit_set_flag(lua_State * L) +static int tolua_unit_set_key(lua_State * L) { unit *self = (unit *)tolua_tousertype(L, 1, 0); const char *name = tolua_tostring(L, 2, 0); @@ -784,6 +784,28 @@ static int tolua_unit_set_flag(lua_State * L) return 0; } +static int tolua_unit_get_flag(lua_State * L) +{ + unit *self = (unit *)tolua_tousertype(L, 1, NULL); + int bit = (int)tolua_tonumber(L, 2, 0); + + lua_pushboolean(L, (self->flags & (1 << bit))); + return 1; +} + +static int tolua_unit_set_flag(lua_State * L) +{ + unit *self = (unit *)tolua_tousertype(L, 1, NULL); + int bit = (int)tolua_tonumber(L, 2, 0); + int set = tolua_toboolean(L, 3, 1); + + if (set) + self->flags |= (1 << bit); + else + self->flags &= ~(1 << bit); + return 0; +} + static int tolua_unit_get_weight(lua_State * L) { unit *self = (unit *)tolua_tousertype(L, 1, 0); @@ -959,6 +981,8 @@ void tolua_unit_open(lua_State * L) tolua_function(L, TOLUA_CAST "has_attrib", tolua_unit_has_attrib); /* key-attributes for named flags: */ + tolua_function(L, TOLUA_CAST "set_key", tolua_unit_set_key); + tolua_function(L, TOLUA_CAST "get_key", tolua_unit_get_key); tolua_function(L, TOLUA_CAST "set_flag", tolua_unit_set_flag); tolua_function(L, TOLUA_CAST "get_flag", tolua_unit_get_flag); tolua_variable(L, TOLUA_CAST "guard", tolua_unit_get_guard, diff --git a/src/monsters.c b/src/monsters.c index 290cbdb87..535e03166 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -442,7 +442,7 @@ static order *monster_move(region * r, unit * u) if (fval(u_race(u), RCF_DRAGON)) { d = richest_neighbour(r, u->faction, 1); } - else if (get_race(RC_TREEMAN)==u_race(u)) { + else if (get_race(RC_TREEMAN) == u_race(u)) { d = treeman_neighbour(r); } else {