2003-11-10 00:36:11 +01:00
|
|
|
|
#include <config.h>
|
|
|
|
|
#include <eressea.h>
|
2003-12-14 11:02:29 +01:00
|
|
|
|
#include "list.h"
|
2003-11-10 00:36:11 +01:00
|
|
|
|
|
|
|
|
|
// kernel includes
|
2004-04-11 01:21:58 +02:00
|
|
|
|
#include <kernel/plane.h>
|
|
|
|
|
#include <kernel/region.h>
|
|
|
|
|
#include <kernel/unit.h>
|
|
|
|
|
#include <kernel/building.h>
|
|
|
|
|
#include <kernel/ship.h>
|
2003-11-10 00:36:11 +01:00
|
|
|
|
|
|
|
|
|
// lua includes
|
|
|
|
|
#include <lua.hpp>
|
|
|
|
|
#include <luabind/luabind.hpp>
|
2004-09-05 16:08:10 +02:00
|
|
|
|
#include <luabind/operator.hpp>
|
2003-11-10 00:36:11 +01:00
|
|
|
|
#include <luabind/iterator_policy.hpp>
|
|
|
|
|
|
2004-04-11 18:16:26 +02:00
|
|
|
|
#include <ostream>
|
2003-11-10 00:36:11 +01:00
|
|
|
|
using namespace luabind;
|
|
|
|
|
|
2004-06-26 22:51:19 +02:00
|
|
|
|
static eressea::list<region *>
|
2003-11-10 00:36:11 +01:00
|
|
|
|
get_regions(void) {
|
2004-06-26 22:51:19 +02:00
|
|
|
|
return eressea::list<region *>(regions);
|
2003-11-10 00:36:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
2004-06-26 22:51:19 +02:00
|
|
|
|
static eressea::list<unit *>
|
2003-11-10 00:36:11 +01:00
|
|
|
|
region_units(const region& r) {
|
2004-06-26 22:51:19 +02:00
|
|
|
|
return eressea::list<unit *>(r.units);
|
2003-11-10 00:36:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
2004-06-26 22:51:19 +02:00
|
|
|
|
static eressea::list<building *>
|
2003-11-10 00:36:11 +01:00
|
|
|
|
region_buildings(const region& r) {
|
2004-06-26 22:51:19 +02:00
|
|
|
|
return eressea::list<building *>(r.buildings);
|
2003-11-10 00:36:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
2004-06-26 22:51:19 +02:00
|
|
|
|
static eressea::list<ship *>
|
2003-11-10 00:36:11 +01:00
|
|
|
|
region_ships(const region& r) {
|
2004-06-26 22:51:19 +02:00
|
|
|
|
return eressea::list<ship *>(r.ships);
|
2003-11-10 00:36:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
region_setname(region& r, const char * name) {
|
|
|
|
|
if (r.land) rsetname((&r), name);
|
|
|
|
|
}
|
|
|
|
|
|
2003-12-14 20:17:59 +01:00
|
|
|
|
static const char *
|
|
|
|
|
region_getterrain(const region& r) {
|
|
|
|
|
return terrain[r.terrain].name;
|
|
|
|
|
}
|
|
|
|
|
|
2003-11-10 00:36:11 +01:00
|
|
|
|
static const char *
|
|
|
|
|
region_getname(const region& r) {
|
|
|
|
|
if (r.land) return r.land->name;
|
2003-12-14 11:02:29 +01:00
|
|
|
|
return terrain[r.terrain].name;
|
2003-11-10 00:36:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
region_setinfo(region& r, const char * info) {
|
2003-12-14 11:02:29 +01:00
|
|
|
|
set_string(&r.display, info);
|
2003-11-10 00:36:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
|
region_getinfo(const region& r) {
|
2003-12-14 11:02:29 +01:00
|
|
|
|
return r.display;
|
2003-11-10 00:36:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
2004-04-11 01:21:58 +02:00
|
|
|
|
static int
|
|
|
|
|
region_plane(const region& r)
|
|
|
|
|
{
|
|
|
|
|
if (r.planep==NULL) return 0;
|
|
|
|
|
return r.planep->id;
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-11 02:45:12 +02:00
|
|
|
|
static void
|
|
|
|
|
region_addnotice(region& r, const char * str)
|
|
|
|
|
{
|
|
|
|
|
addmessage(&r, NULL, str, MSG_MESSAGE, ML_IMPORTANT);
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-11 18:16:26 +02:00
|
|
|
|
static std::ostream&
|
|
|
|
|
operator<<(std::ostream& stream, region& r)
|
|
|
|
|
{
|
|
|
|
|
stream << regionname(&r, NULL) << ", " << region_getterrain(r);
|
|
|
|
|
return stream;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
operator==(const region& a, const region&b)
|
|
|
|
|
{
|
|
|
|
|
return a.x==b.x && a.y==b.y;
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-30 14:09:45 +02:00
|
|
|
|
static bool
|
|
|
|
|
region_getflag(const region& r, int bit)
|
|
|
|
|
{
|
|
|
|
|
if (r.flags & (1<<bit)) return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
region_setflag(region& r, int bit, bool set)
|
|
|
|
|
{
|
|
|
|
|
if (set) r.flags |= (1<<bit);
|
|
|
|
|
else r.flags &= ~(1<<bit);
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-31 12:27:33 +02:00
|
|
|
|
static region *
|
|
|
|
|
terraform_region(int x, int y, const char * tname)
|
|
|
|
|
{
|
|
|
|
|
terrain_t t;
|
|
|
|
|
|
|
|
|
|
if (tname==NULL) {
|
|
|
|
|
t = NOTERRAIN;
|
|
|
|
|
} else {
|
|
|
|
|
for (t=0;t!=MAXTERRAINS;++t) {
|
|
|
|
|
if (strcmp(terrain[t].name, tname)==0) break;
|
|
|
|
|
}
|
|
|
|
|
if (t==MAXTERRAINS) return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
region * r = findregion(x, y);
|
|
|
|
|
if (t==NOTERRAIN) {
|
|
|
|
|
if (r!=NULL) {
|
|
|
|
|
if (r->units!=NULL) {
|
|
|
|
|
// TODO: error message
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
terraform(r, T_FIREWALL);
|
|
|
|
|
// TODO: durch einen NULL-<2D>quivalenten terraintyp ersetzen
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
if (r==NULL) r = new_region(x, y);
|
|
|
|
|
terraform(r, t);
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
2004-06-16 01:29:27 +02:00
|
|
|
|
static region *
|
|
|
|
|
region_next(const region& r, int dir)
|
|
|
|
|
{
|
|
|
|
|
if (dir<0 || dir >=MAXDIRECTIONS) return NULL;
|
|
|
|
|
return r_connect(&r, (direction_t)dir);
|
|
|
|
|
}
|
|
|
|
|
|
2003-11-10 00:36:11 +01:00
|
|
|
|
void
|
|
|
|
|
bind_region(lua_State * L)
|
|
|
|
|
{
|
|
|
|
|
module(L)[
|
2003-12-14 11:02:29 +01:00
|
|
|
|
def("regions", &get_regions, return_stl_iterator),
|
2003-11-10 00:36:11 +01:00
|
|
|
|
def("get_region", &findregion),
|
2004-05-31 12:27:33 +02:00
|
|
|
|
def("terraform", &terraform_region),
|
2003-11-10 00:36:11 +01:00
|
|
|
|
|
|
|
|
|
class_<struct region>("region")
|
2004-04-11 18:16:26 +02:00
|
|
|
|
.def(tostring(self))
|
|
|
|
|
.def(self == region())
|
2003-11-10 00:36:11 +01:00
|
|
|
|
.property("name", ®ion_getname, ®ion_setname)
|
|
|
|
|
.property("info", ®ion_getinfo, ®ion_setinfo)
|
2003-12-14 20:17:59 +01:00
|
|
|
|
.property("terrain", ®ion_getterrain)
|
2004-04-11 02:45:12 +02:00
|
|
|
|
.def("add_notice", ®ion_addnotice)
|
2004-05-30 14:14:46 +02:00
|
|
|
|
.def("get_flag", ®ion_getflag)
|
|
|
|
|
.def("set_flag", ®ion_setflag)
|
2004-06-16 01:29:27 +02:00
|
|
|
|
.def("next", ®ion_next)
|
2003-11-10 00:36:11 +01:00
|
|
|
|
.def_readonly("x", ®ion::x)
|
|
|
|
|
.def_readonly("y", ®ion::y)
|
|
|
|
|
.def_readwrite("age", ®ion::age)
|
2004-04-11 01:21:58 +02:00
|
|
|
|
.property("plane_id", ®ion_plane)
|
2003-11-10 00:36:11 +01:00
|
|
|
|
.property("units", ®ion_units, return_stl_iterator)
|
|
|
|
|
.property("buildings", ®ion_buildings, return_stl_iterator)
|
|
|
|
|
.property("ships", ®ion_ships, return_stl_iterator)
|
|
|
|
|
];
|
|
|
|
|
}
|