- LUA-Erweiterungen:

- Einheitenlisten für Gebäude
  - Einheiten in Gebäude setzen
This commit is contained in:
Enno Rehling 2004-07-10 12:54:25 +00:00
parent 9c3b51a1d0
commit 6883de2c22
2 changed files with 61 additions and 1 deletions

View File

@ -1,16 +1,21 @@
#include <config.h> #include <config.h>
#include <cstring> #include <cstring>
#include <eressea.h> #include <eressea.h>
#include "list.h"
// kernel includes // kernel includes
#include <building.h> #include <building.h>
#include <region.h> #include <region.h>
#include <unit.h>
// lua includes // lua includes
#include <lua.hpp> #include <lua.hpp>
#include <luabind/luabind.hpp> #include <luabind/luabind.hpp>
#include <luabind/iterator_policy.hpp> #include <luabind/iterator_policy.hpp>
// util includes
#include <util/base36.h>
using namespace luabind; using namespace luabind;
static building * static building *
@ -130,6 +135,44 @@ building_setname(building& b, const char * name)
set_string(&b.name, name); set_string(&b.name, name);
} }
static std::ostream&
operator<<(std::ostream& stream, building& b)
{
stream << b.name;
stream << " (" << itoa36(b.no) << ")";
stream << ", " << b.type->_name;
stream << " size " << b.size;
return stream;
}
static bool
operator==(const building& a, const building&b)
{
return a.no==b.no;
}
class buildingunit {
public:
static unit * next(unit * node) {
building * b = node->building;
do {
node = node->next;
} while (node !=NULL && node->building!=b);
return node;
}
static unit * value(unit * node) { return node; }
};
static eressea::list<unit *, unit *, buildingunit>
building_units(const building& b) {
region * r = b.region;
unit * u = r->units;
while (u!=NULL && u->building!=&b) u=u->next;
return eressea::list<unit *, unit *, buildingunit>(u);
}
void void
bind_building(lua_State * L) bind_building(lua_State * L)
{ {
@ -139,10 +182,13 @@ bind_building(lua_State * L)
def("add_building", &add_building), def("add_building", &add_building),
class_<struct building>("building") class_<struct building>("building")
.def(tostring(self))
.def(self == building())
.property("name", &building_getname, &building_setname) .property("name", &building_getname, &building_setname)
.property("info", &building_getinfo, &building_setinfo)
.property("units", &building_units, return_stl_iterator)
.def_readonly("region", &building::region) .def_readonly("region", &building::region)
.def_readonly("id", &building::no) .def_readonly("id", &building::no)
.property("info", &building_getinfo, &building_setinfo)
.def_readwrite("size", &building::size) .def_readwrite("size", &building::size)
.def("add_effect", &building_addeffect) .def("add_effect", &building_addeffect)
]; ];

View File

@ -229,6 +229,19 @@ unit_getregion(const unit& u)
return u.region; return u.region;
} }
static void
unit_setbuilding(unit& u, building& b)
{
leave(u.region, u);
u.building = &b;
}
static building *
unit_getbuilding(const unit& u)
{
return u.building;
}
static int static int
unit_getid(const unit& u) unit_getid(const unit& u)
{ {
@ -398,6 +411,7 @@ bind_unit(lua_State * L)
.def("remove_spell", &unit_removespell) .def("remove_spell", &unit_removespell)
.property("magic", &unit_getmagic, &unit_setmagic) .property("magic", &unit_getmagic, &unit_setmagic)
.property("aura", &unit_getaura, &unit_setaura) .property("aura", &unit_getaura, &unit_setaura)
.property("building", &unit_getbuilding, &unit_setbuilding)
.property("region", &unit_getregion, &unit_setregion) .property("region", &unit_getregion, &unit_setregion)
.property("is_familiar", &unit_isfamiliar) .property("is_familiar", &unit_isfamiliar)
.property("spells", &unit_spells, return_stl_iterator) .property("spells", &unit_spells, return_stl_iterator)