2003-11-10 00:36:11 +01:00
|
|
|
#include <config.h>
|
2008-04-19 18:12:13 +02:00
|
|
|
#include <kernel/eressea.h>
|
2005-11-26 16:28:11 +01:00
|
|
|
#include "objects.h"
|
2003-11-10 00:36:11 +01:00
|
|
|
|
|
|
|
// kernel includes
|
2007-12-17 18:55:51 +01:00
|
|
|
#include <kernel/build.h>
|
|
|
|
#include <kernel/ship.h>
|
|
|
|
#include <kernel/region.h>
|
|
|
|
#include <kernel/move.h>
|
2003-11-10 00:36:11 +01:00
|
|
|
|
|
|
|
// lua includes
|
2008-04-20 16:48:15 +02:00
|
|
|
#ifdef _MSC_VER
|
2007-10-27 17:09:36 +02:00
|
|
|
#pragma warning (push)
|
|
|
|
#pragma warning (disable: 4127)
|
2008-04-20 16:48:15 +02:00
|
|
|
#endif
|
2003-11-10 00:36:11 +01:00
|
|
|
#include <lua.hpp>
|
|
|
|
#include <luabind/luabind.hpp>
|
|
|
|
#include <luabind/iterator_policy.hpp>
|
2006-01-02 21:24:33 +01:00
|
|
|
#if LUABIND_BETA >= 7
|
2004-09-26 21:16:07 +02:00
|
|
|
# include <luabind/operator.hpp>
|
|
|
|
#endif
|
2008-04-20 16:48:15 +02:00
|
|
|
#ifdef _MSC_VER
|
2007-10-27 17:09:36 +02:00
|
|
|
#pragma warning (pop)
|
2008-04-20 16:48:15 +02:00
|
|
|
#endif
|
2003-11-10 00:36:11 +01:00
|
|
|
|
2004-09-26 20:00:49 +02:00
|
|
|
#include <util/base36.h>
|
|
|
|
|
|
|
|
#include <ostream>
|
2003-11-10 00:36:11 +01:00
|
|
|
using namespace luabind;
|
|
|
|
|
2004-09-26 20:00:49 +02:00
|
|
|
static std::ostream&
|
|
|
|
operator<<(std::ostream& stream, const ship& sh)
|
|
|
|
{
|
|
|
|
stream << sh.name;
|
|
|
|
stream << " (" << itoa36(sh.no) << ")";
|
|
|
|
stream << ", " << sh.type->name;
|
|
|
|
stream << " size " << sh.size;
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
operator==(const ship& a, const ship& sh)
|
|
|
|
{
|
|
|
|
return a.no==sh.no;
|
|
|
|
}
|
|
|
|
|
2004-12-22 23:02:31 +01:00
|
|
|
static ship *
|
|
|
|
add_ship(const char * sname, region& r)
|
|
|
|
{
|
|
|
|
const ship_type * stype = st_find(sname);
|
|
|
|
ship * sh = new_ship(stype, NULL, &r);
|
|
|
|
sh->size = stype->construction->maxsize;
|
|
|
|
return sh;
|
|
|
|
}
|
|
|
|
|
2007-02-07 18:58:31 +01:00
|
|
|
static int
|
|
|
|
ship_maxsize(const ship& s) {
|
|
|
|
return s.type->construction->maxsize;
|
|
|
|
}
|
|
|
|
|
2005-01-13 13:42:36 +01:00
|
|
|
const char *
|
|
|
|
ship_gettype(const ship& s) {
|
|
|
|
return s.type->name[0];
|
|
|
|
}
|
|
|
|
|
2006-07-25 11:57:47 +02:00
|
|
|
int
|
|
|
|
ship_getweight(const ship& s) {
|
|
|
|
int w, c;
|
|
|
|
getshipweight(&s, &w, &c);
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ship_getcapacity(const ship& s) {
|
|
|
|
return shipcapacity(&s);
|
|
|
|
}
|
2005-01-13 13:42:36 +01:00
|
|
|
|
2007-12-17 18:55:51 +01:00
|
|
|
static void
|
|
|
|
ship_setregion(ship& sh, region& r)
|
|
|
|
{
|
|
|
|
move_ship(&sh, sh.region, &r, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static region *
|
|
|
|
ship_getregion(const ship& sh)
|
|
|
|
{
|
|
|
|
return sh.region;
|
|
|
|
}
|
|
|
|
|
2003-11-10 00:36:11 +01:00
|
|
|
void
|
|
|
|
bind_ship(lua_State * L)
|
|
|
|
{
|
|
|
|
module(L)[
|
|
|
|
def("get_ship", &findship),
|
2004-12-22 23:02:31 +01:00
|
|
|
def("add_ship", &add_ship),
|
2003-11-10 00:36:11 +01:00
|
|
|
|
|
|
|
class_<struct ship>("ship")
|
2004-09-26 20:00:49 +02:00
|
|
|
.def(self == ship())
|
|
|
|
.def(tostring(self))
|
2005-01-13 13:42:36 +01:00
|
|
|
.property("type", &ship_gettype)
|
2006-07-25 11:57:47 +02:00
|
|
|
.property("weight", &ship_getweight)
|
|
|
|
.property("capacity", &ship_getcapacity)
|
2007-02-07 18:58:31 +01:00
|
|
|
.property("maxsize", &ship_maxsize)
|
2003-11-10 00:36:11 +01:00
|
|
|
.def_readonly("name", &ship::name)
|
2007-12-17 18:55:51 +01:00
|
|
|
.property("region", &ship_getregion, &ship_setregion)
|
2003-11-10 00:36:11 +01:00
|
|
|
.def_readonly("id", &ship::no)
|
|
|
|
.def_readonly("info", &ship::display)
|
|
|
|
.def_readwrite("damage", &ship::damage)
|
|
|
|
.def_readwrite("size", &ship::size)
|
2004-06-16 01:29:27 +02:00
|
|
|
.def_readwrite("coast", &ship::coast)
|
2005-11-26 16:28:11 +01:00
|
|
|
.property("objects", &eressea::get_objects<ship>)
|
2003-11-10 00:36:11 +01:00
|
|
|
];
|
|
|
|
}
|