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)