From d783bf8bc7c9503f7effd374a03efac76e679bdd Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 10 Jul 2004 10:59:47 +0000 Subject: [PATCH] =?UTF-8?q?LUA-Erweiterungen:=20-=20Key-Attribute=20an=20E?= =?UTF-8?q?inheiten=20setzen=20und=20Abfragen=20k=C3=B6nnen.=20-=20Bessere?= =?UTF-8?q?s=20tostring()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/eressea/lua/unit.cpp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/eressea/lua/unit.cpp b/src/eressea/lua/unit.cpp index e47b94085..8ed9d1bc2 100644 --- a/src/eressea/lua/unit.cpp +++ b/src/eressea/lua/unit.cpp @@ -5,6 +5,7 @@ // Atributes includes #include +#include // kernel includes #include @@ -269,10 +270,32 @@ unit_setinfo(unit& u, const char * info) set_string(&u.display, info); } +static bool +get_flag(const unit& u, const char * name) +{ + int flag = atoi36(name); + attrib * a = find_key(u.attribs, flag); + return (a!=NULL); +} + +static void +set_flag(unit& u, const char * name, bool value) +{ + int flag = atoi36(name); + attrib * a = find_key(u.attribs, flag); + if (a==NULL && value) { + add_key(&u.attribs, flag); + } else if (a!=NULL && !value) { + a_remove(&u.attribs, a); + } +} + static std::ostream& operator<<(std::ostream& stream, unit& u) { - stream << u.name << " (" << itoa36(u.no) << ")"; + const char * rcname = get_racename(u.attribs); + stream << u.name << " (" << itoa36(u.no) << "), " << u.number << " " << u.race->_name[0]; + if (rcname) stream << "/" << rcname; return stream; } @@ -359,6 +382,10 @@ bind_unit(lua_State * L) .def("clear_orders", &unit_clearorders) .property("orders", &unit_orders, return_stl_iterator) + // key-attribute: + .def("set_flag", &set_flag) + .def("get_flag", &get_flag) + // items: .def("get_item", &unit_getitem) .def("add_item", &unit_additem)