forked from github/server
- LUA-Erweiterungen:
- Einheitenlisten für Gebäude - Einheiten in Gebäude setzen
This commit is contained in:
parent
9c3b51a1d0
commit
6883de2c22
|
@ -1,16 +1,21 @@
|
|||
#include <config.h>
|
||||
#include <cstring>
|
||||
#include <eressea.h>
|
||||
#include "list.h"
|
||||
|
||||
// kernel includes
|
||||
#include <building.h>
|
||||
#include <region.h>
|
||||
#include <unit.h>
|
||||
|
||||
// lua includes
|
||||
#include <lua.hpp>
|
||||
#include <luabind/luabind.hpp>
|
||||
#include <luabind/iterator_policy.hpp>
|
||||
|
||||
// util includes
|
||||
#include <util/base36.h>
|
||||
|
||||
using namespace luabind;
|
||||
|
||||
static building *
|
||||
|
@ -130,6 +135,44 @@ building_setname(building& b, const char * 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
|
||||
bind_building(lua_State * L)
|
||||
{
|
||||
|
@ -139,10 +182,13 @@ bind_building(lua_State * L)
|
|||
def("add_building", &add_building),
|
||||
|
||||
class_<struct building>("building")
|
||||
.def(tostring(self))
|
||||
.def(self == building())
|
||||
.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("id", &building::no)
|
||||
.property("info", &building_getinfo, &building_setinfo)
|
||||
.def_readwrite("size", &building::size)
|
||||
.def("add_effect", &building_addeffect)
|
||||
];
|
||||
|
|
|
@ -229,6 +229,19 @@ unit_getregion(const unit& u)
|
|||
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
|
||||
unit_getid(const unit& u)
|
||||
{
|
||||
|
@ -398,6 +411,7 @@ bind_unit(lua_State * L)
|
|||
.def("remove_spell", &unit_removespell)
|
||||
.property("magic", &unit_getmagic, &unit_setmagic)
|
||||
.property("aura", &unit_getaura, &unit_setaura)
|
||||
.property("building", &unit_getbuilding, &unit_setbuilding)
|
||||
.property("region", &unit_getregion, &unit_setregion)
|
||||
.property("is_familiar", &unit_isfamiliar)
|
||||
.property("spells", &unit_spells, return_stl_iterator)
|
||||
|
|
Loading…
Reference in New Issue