2003-11-10 00:36:11 +01:00
|
|
|
#include <config.h>
|
|
|
|
#include <eressea.h>
|
|
|
|
|
2004-02-05 20:04:58 +01:00
|
|
|
// Atributes includes
|
|
|
|
#include <attributes/racename.h>
|
|
|
|
|
2003-11-10 00:36:11 +01:00
|
|
|
// kernel includes
|
2003-12-14 11:02:29 +01:00
|
|
|
#include <kernel/region.h>
|
|
|
|
#include <kernel/item.h>
|
|
|
|
#include <kernel/faction.h>
|
|
|
|
#include <kernel/skill.h>
|
|
|
|
#include <kernel/unit.h>
|
2003-11-10 00:36:11 +01:00
|
|
|
|
|
|
|
// lua includes
|
|
|
|
#include <lua.hpp>
|
|
|
|
#include <luabind/luabind.hpp>
|
|
|
|
#include <luabind/iterator_policy.hpp>
|
|
|
|
|
|
|
|
using namespace luabind;
|
2003-12-14 11:02:29 +01:00
|
|
|
|
2003-12-14 17:34:00 +01:00
|
|
|
static unit *
|
|
|
|
add_unit(faction * f, region * r)
|
|
|
|
{
|
|
|
|
if (f->units==NULL) return addplayer(r, f);
|
|
|
|
return createunit(r, f, 0, f->race);
|
|
|
|
}
|
|
|
|
|
2003-12-14 11:02:29 +01:00
|
|
|
static void
|
|
|
|
unit_setnumber(unit& u, int number)
|
|
|
|
{
|
2003-12-14 20:17:59 +01:00
|
|
|
if (u.number==0) {
|
|
|
|
set_number(&u, number);
|
|
|
|
u.hp = unit_max_hp(&u) * number;
|
|
|
|
}
|
2003-12-14 11:02:29 +01:00
|
|
|
}
|
|
|
|
|
2004-02-05 20:04:58 +01:00
|
|
|
static void
|
|
|
|
unit_setracename(unit& u, const char * name)
|
|
|
|
{
|
|
|
|
set_racename(&u.attribs, name);
|
|
|
|
}
|
|
|
|
|
2003-12-14 11:02:29 +01:00
|
|
|
static int
|
|
|
|
unit_getnumber(const unit& u)
|
|
|
|
{
|
|
|
|
return u.number;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
unit_getitem(const unit& u, const char * iname)
|
|
|
|
{
|
|
|
|
const item_type * itype = it_find(iname);
|
|
|
|
if (itype!=NULL) {
|
|
|
|
return i_get(u.items, itype);
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
unit_additem(unit& u, const char * iname, int number)
|
|
|
|
{
|
|
|
|
const item_type * itype = it_find(iname);
|
|
|
|
if (itype!=NULL) {
|
|
|
|
item * i = i_change(&u.items, itype, number);
|
|
|
|
return i?i->number:0;
|
|
|
|
} // if (itype!=NULL)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
unit_getskill(const unit& u, const char * skname)
|
|
|
|
{
|
|
|
|
skill_t sk = sk_find(skname);
|
|
|
|
if (sk!=NOSKILL) {
|
|
|
|
skill * sv = get_skill(&u, sk);
|
2004-01-04 17:02:02 +01:00
|
|
|
if (sv==NULL) return 0;
|
2003-12-14 11:02:29 +01:00
|
|
|
return sv->level;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
unit_effskill(const unit& u, const char * skname)
|
|
|
|
{
|
|
|
|
skill_t sk = sk_find(skname);
|
|
|
|
if (sk!=NOSKILL) {
|
|
|
|
return effskill(&u, sk);
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
unit_setskill(unit& u, const char * skname, int level)
|
|
|
|
{
|
|
|
|
skill_t sk = sk_find(skname);
|
|
|
|
if (sk!=NOSKILL) {
|
|
|
|
set_level(&u, sk, level);
|
|
|
|
return level;
|
|
|
|
} // if (sk!=NULL)
|
|
|
|
return -1;
|
|
|
|
}
|
2003-11-10 00:36:11 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
bind_unit(lua_State * L)
|
|
|
|
{
|
|
|
|
module(L)[
|
|
|
|
def("get_unit", &findunit),
|
2003-12-14 17:34:00 +01:00
|
|
|
def("add_unit", &add_unit),
|
2003-11-10 00:36:11 +01:00
|
|
|
|
|
|
|
class_<struct unit>("unit")
|
|
|
|
.def_readonly("name", &unit::name)
|
|
|
|
.def_readonly("region", &unit::region)
|
2003-12-14 11:02:29 +01:00
|
|
|
.def_readonly("faction", &unit::faction)
|
2003-11-10 00:36:11 +01:00
|
|
|
.def_readonly("id", &unit::no)
|
2003-12-14 11:02:29 +01:00
|
|
|
.def("get_item", &unit_getitem)
|
|
|
|
.def("add_item", &unit_additem)
|
|
|
|
.def("get_skill", &unit_getskill)
|
|
|
|
.def("eff_skill", &unit_effskill)
|
|
|
|
.def("set_skill", &unit_setskill)
|
2004-02-05 20:04:58 +01:00
|
|
|
.def("set_racename", &unit_setracename)
|
2003-12-14 11:02:29 +01:00
|
|
|
.property("number", &unit_getnumber, &unit_setnumber)
|
2003-11-10 00:36:11 +01:00
|
|
|
];
|
|
|
|
}
|